我设法使这个 AppleScript 工作。它基本上在我的收件箱中搜索我的所有帐户,然后选择来自特定地址的任何超过 14 天的邮件。然后它继续将这些过滤后的每一条消息移动到指定的邮箱。
set ExcludeList to {"Trash", "Sent", "Drafts", "Deleted Messages", "Archive", "Junk", "Notes"} -- mailboxes you don't want to search
set SenderList to {"events@goldstar.com", "hello@touchofmodern.com", "staples@e.staples.com", "deals@livingsocial.com"} -- email addresses of senders you want to remove old emails for
set DestinationFolderName to "Old_Newsletters" -- mailbox to move messages to. If you want to just delete them, leave it blank.
set StaleTime to 14 -- 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
set current_date to current date
set _msgs_to_move to {}
tell application "Mail"
set everyAccount to every account where enabled is true
-- Get acount-specific mailboxes
repeat with eachAccount in everyAccount
set accountName to the name of eachAccount
set currentMailbox to mailbox "INBOX" of eachAccount
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
repeat with SenderToRemove in SenderList
set messages_list to (every message of currentMailbox whose sender ends with "<" & SenderToRemove & ">")
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 DestinationFolderName is not equal to "" then
move theMessage to mailbox DestinationFolderName of account "BlueStar Studios"
else
delete theMessage
end if
end if
end repeat
end repeat
end try
end if
end repeat
display dialog "Finished!"
end tell
它似乎工作得很好。但是,运行需要很长时间。因为它单独移动每个过滤的消息。有没有办法在重复时制作要移动的邮件列表,然后一次性将整个邮件列表移动到另一个文件夹?
另外,如果这有什么不同,我正在运行 10.7.5。