(* CRM114 Train Ham A menu script that will train message as spam in CRM114 and move to inbox Assumes no additional text added to message besides X-CRM114-Status Copyright © 2004 Leonard Lin Descended from Apple sample code, MacOSXHints code, random string handling snippets *) using terms from application "Mail" on perform mail action with messages theSelectedMessages (* Set command email and password *) set cmdEmail to "email@example.com" set cmdPasswd to "CRM114pwd" tell application "Mail" if (count of theSelectedMessages) is equal to 0 then display dialog "Please select a message in Mail first, then run this script again." else if (count of theSelectedMessages) is equal to 1 then set eachMessage to item 1 of theSelectedMessages set theSource to source of eachMessage set theSubject to subject of eachMessage my createMessageWithSource(theSource, theSubject, cmdEmail, cmdPasswd) (* move the ham message *) move eachMessage to inbox else display dialog "Please select only one message in Mail first, then run this script again." end if end tell end perform mail action with messages end using terms from on createMessageWithSource(theSource, theSubject, cmdEmail, cmdPasswd) (* Strip X-CRM114-Status line from headers *) set AppleScript's text item delimiters to " " set emailLineList to every text item in theSource set theSource to "" repeat with emailLine in emailLineList if emailLine does not start with "X-CRM114-Status: " then set theSource to theSource & " " & emailLine end if end repeat tell application "Mail" set newMessage to make new outgoing message tell newMessage make new to recipient at end of to recipients with properties {name:cmdEmail, address:cmdEmail} set visible to true (* take advantage of stupid applescript's extra \r *) set content to "command " & cmdPasswd & " nonspam" & theSource set subject to "CRM114 Training Ham [" & theSubject & "]" (* send message *) send newMessage end tell end tell end createMessageWithSource