crashmeister

Q: Mail rule script stopping after one message?

I have a script for moving some SENT messages to a specific folder. It executes via a rule that triggers whenever any message is received. Sometimes, only one message is moved at a time and I do not know why. The script should move all relevant messages in the 'repeat' loop.

 

Script:

using terms from application "Mail"

  on perform mail action with messages theSelectedMessages for rule theRule

       set messageList to {}

       set x to messages in mailbox "Sent Messages" in account "xxx"

       set messageList to x

       set x to messages in mailbox "Sent Messages" in account "yyy"

       set messageList to messageList & x

       set x to messages in mailbox "Sent Messages" in account "zzz"

       set messageList to messageList & x

       repeat with i from 1 to count items in messageList

       set msg to item i of messageList

       if all headers of msg contains "VC:" or all headers of msg contains "HOA:" then

                 set mailbox of msg to mailbox "VC-HOA" of mailbox "Local"

       end if

  end repeat

  end perform mail action with messages

end using terms from

 

Thanks.

iMac, OS X El Capitan (10.11.3)

Posted on Sep 19, 2016 2:41 PM