Applescript在Mail.app中存档电子邮件

时间:2009-11-12 21:56:07

标签: email applescript

我需要为Mail.app编写一个Applescript,它会将我收件箱中的所有邮件和已发送邮件的日期超过特定天数,并将它们移动到“我的Mac”或本地文件夹中的相应文件夹中。 / p>

这是我的IMAP帐户的原因有120天的配额限制,我宁愿自动将我的电子邮件“存档”到本地文件夹,而不是手动执行。

1 个答案:

答案 0 :(得分:0)

到目前为止你尝试了什么?你的问题很广泛。以下内容可以帮助您入门:

property secondsIn120Days : 10368000

tell application "Mail"

    set theInbox to inbox

    set dateToday to current date

    set firstMessage to 1
    set lastMessage to (get count of messages in theInbox)

    repeat with thisMessage from lastMessage to firstMessage by -1
        set currentMessage to message thisMessage of theInbox
        set messageDate to date received of currentMessage

        set timeDifference to dateToday - messageDate

        if timeDifference ≥ secondsIn120Days then

            (* In answer to your comment, any folder you create to archive
            messages is going to be in the "On My Mac" directory. But say you
             create a Smart Mailbox called "Mail Archive"  then all you should 
            need are these lines... *)

            set archiveMailbox to (mailbox ("Mail Archive" as string))
            move currentMessage to archiveMailbox

        end if
    end repeat
end tell

更新:在代码中添加了对评论的回复。