Created
November 26, 2016 05:22
-
-
Save alexcu/6fdda829f45d6b3e313dfce78795837d to your computer and use it in GitHub Desktop.
Service to report spam to Apple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Implements phishing suggestions by Apple | |
-- http://www.apple.com/legal/more-resources/phishing/ | |
-- | |
using terms from application "Mail" | |
-- Strip the domain from an email address | |
on domainOf(address) | |
set atIndex to offset of "@" in address | |
set domain to strings (atIndex + 1) thru -1 of address | |
return domain | |
end domainOf | |
-- Get the selected message | |
tell application "Mail" | |
set spamMessageSelection to selection | |
end tell | |
-- No selected message terminates the script | |
if spamMessageSelection is {} then | |
display dialog "No message selected" | |
return | |
end if | |
-- Spam message itself | |
set spamMessage to item 1 of spamMessageSelection | |
-- Who to send email to | |
set reportTo to {} | |
set reportingPhishing to (the button returned of (display dialog "Report as phishing?" buttons {"Yes", "No"} default button 2 with title "Report...") is "Yes") | |
if reportingPhishing then | |
copy "reportphishing@apple.com" to the end of reportTo | |
end if | |
-- Add "spam@icloud.com" if sent to MobileMe or iCloud | |
repeat with spamRecipient in recipients of spamMessage | |
set spamRecipientAddress to the address of spamRecipient | |
set spamRecipientDomain to domainOf(spamRecipientAddress) | |
if {"icloud.com", "mac.com", "me.com"} contains spamRecipientDomain then | |
copy "abuse@icloud.com" to end of reportTo | |
exit repeat | |
end if | |
end repeat | |
-- Add "abuse@domain.com" to report list | |
set spamSenderAddress to extract address from sender of spamMessage | |
set spamSenderDomain to domainOf(spamSenderAddress) | |
copy "abuse@" & spamSenderDomain to the end of reportTo | |
-- Save the message to file | |
set tempEMLPath to "" & (path to temporary items as string) & (do shell script "uuidgen") & ".eml" as string | |
do shell script "touch " & quoted form of POSIX path of tempEMLPath | |
set tempEMLFile to open for access file tempEMLPath with write permission | |
set eof of tempEMLFile to 0 | |
write (source of spamMessage as string) to tempEMLFile starting at eof | |
close access tempEMLFile | |
-- Create the report mail | |
tell application "Mail" | |
set newMessageSubject to "Spam Report - " & subject of spamMessage | |
set newMessage to make new outgoing message with properties {subject:newMessageSubject, visible:true} | |
tell newMessage | |
-- Add recipients | |
repeat with i from 1 to count reportTo | |
make new to recipient at end of every to recipient with properties {address:item i of reportTo} | |
end repeat | |
-- Add EML attachment | |
make new attachment with properties {file name:tempEMLPath as alias} | |
end tell | |
end tell | |
-- Mark the message as junk | |
set junk mail status of spamMessage to true | |
end using terms from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment