繁体   English   中英

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

[英]Applescript to archive email in Mail.app

我需要为Mail.app编写一个Applescript,它将收件箱中的所有邮件和已发送超过特定天数的已发送邮件,然后将它们分别移至“我的Mac”上的文件夹或本地文件夹中。

之所以成为我的IMAP帐户,是因为它有120天的配额限制,所以我宁愿将电子邮件自动“存档”到本地文件夹,也不必手动进行。

你试过什么了? 您的问题非常广泛。 以下内容将帮助您入门:

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

更新:添加了对代码中注释的响应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM