Mac OS: Automator-script for saving mails to auto-generated folders

1

I am looking into automator and need it to help me out with the following simple task:

I need to have the attachments of a number of messages, which are sorted in a folder in Mail, downloaded and saved to folders which are named by the email address of the sender.

If possible I would like a transcript of the mail saved along with the attachments (could possible be done by printing a pdf?)

I never really used automator, but currently I have set up an action to "Get specified Mail Items", which is hooked up to the right folder in mail and I have set up a "Get attachments from mail message", but I need to find out how to name folders by the sender names and how to save to these folders.

funkylaundry

Posted 2011-11-04T11:55:51.210

Reputation: 185

Answers

0

You're probably better off using Applescript or something similar that allows you more control over manipulating the properties of the individual messages.

EDIT: Took a lot more trial and error than i thought it would, but you should be able to select a batch of messages, run this script, and have it spit out folders for each sender in whatever folder you specify at the outset. It doesn't do logging, but perhaps its enough to get you started.

I'll also note that the save [attachment] in [attachmentPath] command is broke in Lion on 10.7 and 10.7.1 (I think its both), but appears to be fixed in 10.7.2, based on what I've been reading. So YMMV if you're not running 10.7.2.

EDIT Again: More Revisions... now we won't create folders for messages that don't have attachments...

tell application "Mail"
    set selectedMessages to selection

    set destinationFolder to choose folder with prompt "Pick a Destination"

    repeat with currentMessage in selectedMessages
        repeat 1 times
            set msgSender to sender of currentMessage
            set msgAttachments to mail attachments of currentMessage
            if (msgAttachments is equal to {}) then
                exit repeat
            end if
            tell application "Finder"
                if not (exists folder msgSender of destinationFolder) then
                    set senderFolder to (make new folder at destinationFolder with properties {name:msgSender})
                else
                    set senderFolder to (folder msgSender of destinationFolder)
                end if
            end tell

            repeat with currentAttachment in msgAttachments
                if (downloaded of currentAttachment is true) then
                    set currentAttachmentPath to (senderFolder as string) & (name of currentAttachment)
                    save currentAttachment in currentAttachmentPath
                end if
            end repeat
        end repeat
    end repeat

end tell

peelman

Posted 2011-11-04T11:55:51.210

Reputation: 4 580