-
-
Save cuberoot/1196125 to your computer and use it in GitHub Desktop.
Simple Inbox Archiving Script for Apple Mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set _description to "All unflagged, read messages in each IMAP account inbox will be moved to the “Archive” mailbox corresponding to that account. All POP inboxes will be moved to a mailbox on this Mac called 'Archive (<Account Name>)'. This action is not undoable." | |
tell application "Mail" | |
display alert "Archive read messages from IMAP inboxes?" buttons ¬ | |
{"Cancel", "Archive"} cancel button 1 message _description | |
repeat with _acct in pop accounts | |
if (enabled of _acct) then | |
set _acct_name to name of _acct | |
set _archive_box to (mailbox (("Archive (" & _acct_name & ")") as string)) | |
set _inbox to _acct's mailbox "INBOX" | |
get mailboxes of _acct | |
set _msgs_to_move to (a reference to ¬ | |
(every message of _inbox ¬ | |
whose flagged status is false and read status is true)) | |
set _msg_list to contents of _msgs_to_move | |
if (_msg_list's length > 0) then | |
move _msgs_to_move to _archive_box | |
end if | |
end if | |
end repeat | |
repeat with _acct in imap accounts | |
if (enabled of _acct) then | |
set _acct_name to name of _acct | |
get mailboxes of _acct | |
set _inbox to _acct's mailbox "INBOX" | |
try | |
set _archive_box to _acct's mailbox "Archive" | |
on error | |
try | |
set _archive_box to _acct's mailbox "[Gmail]/All Mail" | |
on error | |
display alert "No “Archive” mailbox found for account “" & ¬ | |
_acct_name & "”." | |
return -- Stop the script | |
end try | |
end try | |
set _msgs_to_move to (a reference to ¬ | |
(every message of _inbox ¬ | |
whose flagged status is false and read status is true)) | |
set _msg_list to contents of _msgs_to_move | |
if (_msg_list's length > 0) then | |
move _msgs_to_move to _archive_box | |
end if | |
end if | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment