Skip to content

Instantly share code, notes, and snippets.

@itst
Last active October 21, 2019 07:15
Show Gist options
  • Save itst/4e7d52df9cf17ee030ad330974e69178 to your computer and use it in GitHub Desktop.
Save itst/4e7d52df9cf17ee030ad330974e69178 to your computer and use it in GitHub Desktop.
To keep my IMAP account's inbox as small as possible, I move mails into yearly archives. I usually do that once every quarter. But if I don't, well then I have many mails to move. This AppleScript does the heavy lifting.
tell application "Mail"
set _a to imap account "sc@itst.net"
set _i to _a's mailbox "INBOX"
set _ms to (messages of _i)
set numLog to 50
set iteration to 1
set iterationMax to number of _ms
log iterationMax & " msgs to move"
repeat with _m in _ms
if (iteration mod numLog is 0) then
log iteration
end if
set _rd to date received of _m
if (year of _rd is 2019) then
move _m to _a's mailbox "z-Archiv/2019"
end if
set iteration to iteration + 1
end repeat
synchronize with _a
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment