Import of selected and formatted mails from Mail


by using DevonThink Pro public beta, I tried to import selected mails from Mail application with the appropriate script delivered with DevonThink Pro. But all format is lost, so HTML or otherwise formatted mails are terrible and not really readable.

I looked at the script code, it makes “create record … typ:txt…plain text:…” so it seems to create a plain text document. Whow must I modify this script to create rtf documents (or html documents) ?



I tried using the script too and have gone back to “services” .rtf format instead. A script that would capture HTLM formatted emails would be very nice.


I am using Mail Act-On and it would be great to have a working applescript that could be tied to a “rule” so that it could be used with mail Act-On!

hnbeck & ChemBob:

Pretty quick workaround for formatted Mail message capture (including images):

When I come across an email that I’l like to put into my DTP database, I double-click to open it, press Cmd-A to select all, then drag it down to the DT Pro icon in my Dock. It goes to the group you’ve designated (in DTP preferences) to receive new content.

Doesn’t work if you drag the ‘name’ bar to the DTP icon, so, unfortunately, it doesn’t do multiple items at once.

I’d really like to get something to work in AppleScript.

Here is what I have right now:

set item_body to (theHeaders as string) & return & (theContent as styled text)

tell application "DEVONthink Pro" to create record with {name:theSubject, type:rtf, date:theDate, URL:theSender, rich text:item_body}

But even though I’ve set type to RTF and specified rich text content, the script still creates a plain text message. I assume that I am either doing something wrong, or DTP still doesn’t support what I’m trying to do. I don’t know which…

OK. I think I know what the problem is. Mail provides either the plain text contents of the message as “content” or the raw source as “source” so when calling from mail there is no way to get just the styled text. If one gets the source the styled text is included as HTML, but so is the original message without the HTML encoding.

A proper script would test if there is HTML in the message and then only return what is between the HTML start and end tags, or if there is no HTML, just produce plain text.

But that is beyond by scripting capabilities…

And mine. But I don’t think one has to worry about whether the message is formatted or not.

Conceptually, how about a script that performs automatically the equivalent of the sequence that I described above, on a user-selected group or Mailbox?

Don’t know if Mail has the scripting hooks to open one of the selected group, select all, send the rich text to DEVONthink Pro, close the email, move to the next and so on until finished with the selected messages (or Mailbox).

I suppose one could write a script to “select all” and then copy to the clipboard. The rest would be the same as the “save selection” script. This shouldn’t be hard, and should work with any mail message. One could even modify it to have the same meta-data capabilities as the current mail script …

I’ll have to think about this.