(* CRM114 Smart Training v1.1 === A menu script that will train message as spam/ham in CRM114 and and either delete or move to the inbox as appropriate. INSTALL --- Place this file in you Mail.app Scripts Folder. For more information on customizing hot keys: http://docs.info.apple.com/article.html?artnum=135236 Set the cmdEmail and cmdPasswd variables to your email and CRM114 password. USAGE --- Select a single message and run the script (default hot-key: Shift-S). If the selected email is in the inbox it will be trained as spam and moved to the trash. If the selected email is in any other mailbox, it will be trained as ham and moved to the inbox. Pretty naive for a 'smart' trainer, but it works for 99%+ of the cases and is much less susceptible to the slippy finger effect (accidental mistraining). NOTES --- Assumes no additional text is added to message besides X-CRM114 headers. That is the mailfilter.cf is configured as follows: :add_headers: /yes/ :add_verbose_stats: /no/ :add_extra_stuff: /no/ :spam_flag_subject_string: // Here's an example procmailrc setup: (dashes prepended b/c AppleScript is retarded) -- :0fw: .msgid.lock -- * < 250000 -- | /usr/bin/crm -u $FILTER_PATH mailfilter.crm -- :0 -- * ^X-CRM114-Status: SPAM.* -- $SPAM_FOLDER -- :0 -- * ^X-CRM114-Action: -- $TRAINING_FOLDER 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 variables *) set cmdEmail to "email@example.com" set cmdPasswd to "CRM114passwd" 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 set mbox to name of mailbox of eachMessage (* If INBOX, set to classify as spam, else classify as ham *) if mbox is equal to "INBOX" then set cmd to "spam" else set cmd to "nonspam" end if my createMessageWithSource(theSource, theSubject, cmdEmail, cmdPasswd, cmd) (* Move spam to trash, ham to inbox *) if cmd is equal to "spam" then move eachMessage to trash mailbox else move eachMessage to inbox end if 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, cmd) (* 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: " or "X-CRM114-Version: " 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 & " " & cmd & theSource set subject to "CRM114 training " & cmd & " [" & theSubject & "]" (* send message *) send newMessage end tell end tell end createMessageWithSource