views:

423

answers:

1

I need to write an Applescript for Mail.app that will take all messages in my Inbox and Sent Messages that are older than a certain # of days and move them into respective folders "On My Mac", or local folders.

The reason for this being my IMAP account has a 120 day quota limit, and I'd rather automate "archiving" my email to a local folder rather than doing it manually.

A: 

What have you tried so far? Your question is very broad. The following should get you started:

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

UPDATE: Added response to comments in the code.

Philip Regan
I have seen this: http://www.doughellmann.com/projects/MailArchiveByDate/. Basically I want to do that but without categorizing it by month. I want it to just all be in one top level folder.
churnd
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)) \r move currentMessage to archiveMailbox" See updated code above for proper formatting.
Philip Regan