apple script update a rule for mail, to sort e.g. newsletter

206 views Asked by At

Is it possible to use apple script in mail to sort newsletter by updating a rule when I put a email for training in a specific mail folder?

  1. in mail is a folder named "trainNewsletter"
  2. in mail / rules is a rule "Newsletter" witch move mails into the folder "Newsletter" with
  3. specific from-mail-address
  4. if there is a mail in the inbox witch from-mail-address is not in the rule "Newsletter" the mail stays in the inbox
  5. I move the mail to the folder "trainNewsletter" an the script add the from-mail-address to the rule
  6. next time I get an mail with this from-mail-address it moves direkt to the folder "Newsletter"
1

There are 1 answers

0
ShooTerKo On

I'm not sure if moving the mail to another folder will trigger the rule appended to this folder, but maybe you can trigger this rule manually if needed:

Save this as a new mail rule and connect it to your folder trainNewsletter, it should get the email's sender and add it as a from is equal to-rule condition to your rule Newsletter:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with thisMessage in theMessages
                -- getting the sender of the email
                set theSender to sender of thisMessage

                -- setting the sender as a rule condition of rule "Newsletter"
                tell rule "Newsletter"
                    make new rule condition with properties {header:"", expression:theSender, rule type:from header, qualifier:equal to value}
                end tell

            end repeat
        end tell
    end perform mail action with messages
end using terms from

Enjoy, Michael / Hamburg