2009-11-12 100 views
0

我需要爲Mail.app編寫一個Applescript,它會將我的收件箱中的所有郵件和發送的郵件超過特定天數並將它們移到相應的文件夾中「在我的Mac「或本地文件夾。Applescript在Mail.app中存檔電子郵件

這是我IMAP帳戶的原因有120天的配額限制,我寧願將我的電子郵件「歸檔」到本地文件夾而不是手動執行。

回答

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 

更新:添加了對代碼中的註釋的響應。

+0

我見過這個:http://www.doughellmann.com/projects/MailArchiveByDate/。基本上我想這樣做,但沒有按月分類。我希望它只是在一個頂級文件夾中。 – churnd 2009-11-18 15:14:45

+0

您創建的用於歸檔郵件的任何文件夾都將位於「我的Mac」目錄中。但是,假設你創建一個名爲「Mail Archive」的智能郵箱,那麼你應該需要的就是這些行......「將archiveMailbox設置爲(mailbox(郵件存檔)作爲字符串))\ r將currentMessage移動到archiveMailbox」查看上面的更新代碼正確的格式。 – 2009-11-18 20:24:53

相關問題