emailapplescriptaction-mailbox

AppleScript to add multiple address from selected message to given rule


Want to Select Multiple messages in Mail.app, then 1.move them to a folder "AdvertRule" 2.Add Condition (sender's email address) to existing rule "TestRule 23"

Results from Code

  1. works perfectly
  2. Partial, wud add condition to the rule, x times if x number of messages selected, and all emails addresses in same condition as in ( a@aa.com b@bb.com c@cc.com)

Wondering if can be helped to get 1 email address for each condition in the Rule

even better if has error correction (wud not form a new Condition if it already exists)

Tx in advance

(*
Based on
https://apple.stackexchange.com/questions/149008/in-mail-app-get-list-of-recipients-for-just-one-of-the-many-email-accounts
https://discussions.apple.com/thread/7319379
Move selected Messages to another Folder
*)
tell application "Mail"
    set theSenderList to {}
    set target_account to "Exchange"
    set target_mailbox to "AdvertRule"
    set theMessages to the selected messages of message viewer 0
    repeat with aMessage in theMessages
        set end of theSenderList to (extract address from sender of aMessage)
        set oldDelimits to AppleScript's text item delimiters
        set AppleScript's text item delimiters to "     "
        set theSender to (theSenderList as string)
        set AppleScript's text item delimiters to oldDelimits
    end repeat
    set r to rule "TestRule 23"
    set s to selection
    if s is not "" then
        repeat with currentMessage in s
            move currentMessage to (first mailbox whose name is target_mailbox) of account target_account
            tell r
                make new rule condition at end of rule conditions with properties {expression:theSender, qualifier:does contain value, rule type:from header}
            end tell
        end repeat
    end if
end tell


Solution

  • Hey after reading thru the applescript for beginners After getting Sender List, then add rule with every sender in the sender list, then with every message in selection, move the message

    That shud work