我设法让这个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。
答案 0 :(得分:0)
尝试使用像这样的过滤器参考表单:
set d to (current date) - 14 * days
tell application "Mail"
repeat with a in (get accounts where enabled is true)
move (messages of mailbox "INBOX" of account a where date sent < d and (sender ends with "<events@goldstar.com>" or sender ends with "<hello@touchofmodern.com>")) to mailbox "Old_Newsletters" of account "BlueStar Studios"
end repeat
end tell