Submit mail to Spamcop with Mail.app and Applescript

Oct 31, '03 08:37:00AM

Contributed by: Greedo

Looking for a quick way to submit your spam to Spamcop? It's a bit of a pain in Mail.app, because they expect the email to have all the headers visible, and you have to unindent the commenting that Mail.app automatically adds to forwarded email.

The following script takes care of both requirements. All you need to do is change the first three lines of the script to match your settings. The first line should be your unique Spamcop submission address. The second, "markAsJunk," lets the script not only submit the email to Spamcop, but also mark it as junk mail in Mail.app. The third setting, "sendImmediately," lets you decide if you want to verify the email you are sending to Spamcop before you send it.


set spamcopAddress to "submit._______@spam.spamcop.net"
set markAsJunk to false
set sendImmediately to false

tell application "Mail"
  set junkBox to junk mailbox
  set selectedMessages to the selection
  repeat with thisMessage in selectedMessages
    set thisSubject to the subject of thisMessage
    set thisSource to the source of thisMessage
    
    if markAsJunk then
      set is junk mail of thisMessage to true
      set the mailbox of thisMessage to junkBox
    end if
    
    set newMessage to make new outgoing message with properties ¬
     {subject:"SPAM-FWD: " & thisSubject, content:thisSource & return}
    tell newMessage
      set visible to true
      make new to recipient at end of to recipients with properties ¬
       {name:"Spamcop Reporting", address:spamcopAddress}
    end tell
    
    if sendImmediately then
      send newMessage
    else
      activate
      set theResult to display dialog "Send message?" buttons ¬
       {"Yes", "No"} default button 1
      set sendNow to button returned of theResult
      if sendNow is equal to "Yes" then
        send newMessage
      else
        delete newMessage
      end if
    end if 
  end repeat
end tell
[robg adds: To get this script to compile under 10.3, I had to change set is junk mail of thisMessage to true to read set junk mail status of thisMessage to true in the if markAsJunk then routine. I don't have SpamCop, so I haven't actually tested the script itself.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20031027155608671