简单的收件箱归档脚本为苹果的邮件

[2011年7月4日更新:这篇文章中的脚本已经更新稍微要解决一个错误在Mac OS X 10.7.0 Apple Mail您可以使用版本历史这个脚本的要点页面什么改变了我已经测试了下面的版本10.6.8和10.7.0。)

我使用一个非常简单的邮箱在Apple Mail结构在每一个我的IMAP账户,我创建了一个“档案”邮箱一天一次,我将所有unflagged,从每个读取消息收件箱到相应的归档邮箱账户。

这里有一个AppleScript这个收件箱全面自动化它假设每个IMAP帐户(包括mac账户)存档邮箱。

-- The following should be one long line:
set _description to "All unflagged, read messages in each IMAP account 
    inbox will be moved to the “Archive” mailbox corresponding to that  
    accountThis 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 imap accounts
        set _acct_name to name of _acct
        set _inbox to _acct's mailbox "INBOX"
        try
            set _archive_box to _acct's mailbox "Archive"
        on error
            display alert "No “Archive” mailbox found for account “" & ¬
                _acct_name & "”."
            return -- Stop the script
        end try

        -- Begin update for OS X 10.7.0
        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 update for 10.7.0

    end repeat
end tell

关键是让它尽可能容易让我的收件箱未读标记信息以外的一切东西。

注:

  • 这是一个很好的例子使用谁的clause to create a filtered reference to a list of items that meet certain criteria — in this case, the read, unflagged messages of each inboxMail’s scripting support also allows us to move the entire list of messages en masse即we don’t need to loop through each message in the inboxes one at a time to find the read unflagged ones, and we don’t need to move them one at a time to the Archive mailboxes.

  • The script itself seems to run pretty fast in my use (mainly because of the aforementioned point that it doesn’t loop through messages one at a time), but it might take a few seconds for Mail to finish moving the messages out of your inboxesUse Mail’s Activity Viewer to watch the progress of the messages being moved.

  • If you’d instead prefer to move messages to a mailbox on your Mac rather than on your IMAP server, just change this line:

    移动_msg_list _archive_box

    类似的:

    移动_msg_list邮箱“归档邮箱名称”

    或者,如果它是一个sub-mailbox层次结构:

    _msg_list搬到邮箱“顶级邮箱/归档邮箱名称”