Posted By

pdxmph on 07/07/10


Tagged

Archive-Mail-by-Year-and-Month


Versions (?)

Snippet 48


 / Published in: AppleScript
 

  1. using terms from application "Mail"
  2. on perform mail action with messages theMessages for rule theRule
  3. tell application "Mail"
  4. repeat with thisMessage in theMessages
  5. set msgDate to date received of thisMessage
  6. set msgMonth to month of msgDate as integer
  7. set msgYear to year of msgDate as integer
  8. set msgQuarter to ((round ((msgMonth - 1) / 3) rounding down) + 1)
  9. set msgAccount to name of account of mailbox of thisMessage
  10. set msgMailbox to name of mailbox of thisMessage
  11.  
  12. set mboxName to "Archive/" & msgYear & "/" & msgMonth
  13.  
  14.  
  15. tell account msgAccount
  16. try
  17. set mbox to mailbox named mboxName
  18. get name of mbox
  19. on error
  20. make new mailbox with properties {name:mboxName}
  21. set mbox to mailbox named mboxName
  22. end try
  23. move thisMessage to mbox
  24. end tell
  25. end repeat
  26. end tell
  27. end perform mail action with messages
  28. end using terms from

Report this snippet  

You need to login to post a comment.