set ExcludeList to {"Keep", "Trash", "Sent Messages", "Drafts", "Deleted Messages", "Archive"} -- mailboxes you don't want to search set DestinFolderName to "Archive" -- mailbox to move messages to. If you want to just delete them, leave it blank. set StaleTime to 160 -- days old the message must be before moved or deleted set ShowMailboxesProgress to true -- determines if you want the "Processing" box displayed for each mailbox tell application "Mail" set everyAccount to every account -- Get acount-specific mailboxes repeat with eachAccount in everyAccount set everyMailbox to every mailbox of eachAccount set accountName to the name of eachAccount repeat with theMailbox in everyMailbox set currentMailbox to theMailbox set mailboxName to the name of currentMailbox if mailboxName is not in ExcludeList then if ShowMailboxesProgress then display dialog "Processing folder " & mailboxName & " in account " & accountName end if try set messages_list to every message of mailbox mailboxName repeat with i from 1 to number of items in messages_list set theMessage to item i of messages_list set difference to ((current date) - (date sent of theMessage)) div days if difference is greater than StaleTime then if DestinFolderName is not equal to "" then move theMessage to mailbox DestinFolderName else delete theMessage end if end if end repeat end try end if end repeat end repeat -- Get global mailboxes repeat with theMailbox in every mailbox set currentMailbox to theMailbox set mailboxName to the name of currentMailbox if mailboxName is not in ExcludeList then if ShowMailboxesProgress then display dialog "Processing folder " & mailboxName end if try set messages_list to every message of mailbox mailboxName repeat with i from 1 to number of items in messages_list set theMessage to item i of messages_list set s to the subject of theMessage set difference to ((current date) - (date sent of theMessage)) div days if difference is greater than StaleTime then if DestinFolderName is not equal to "" then move theMessage to mailbox DestinFolderName else delete theMessage end if end if end repeat end try end if end repeat display dialog "Finished!" end tell