Scripting Mail, MailTags to Devonthink?

I use MailTags heavily with Apple’s Mail.app. I’ve had no trouble using the Devonthink mail conduit to add email into a database. Let’s say I have email tagged with either a project or a keyword. It’s simple enough to make a smart mailbox for this and add any messages I want, by hand to the devonthink database.

What I would like to do is somehow automate the process of an applescript which either runs automatically every 24-36 hours (or whatever time interval I set), and then takes all the messages tagged with @projectName or @Keyword, and adds them to a devonthink database/directory of my choice, IF THEY ARE NOT ALREADY PRESENT.

I don’t want endless duplicates, I would just like to be able to find any pieces of email that pertain to a specific project or keyword, and file them into whatever database/directory I want to store them in, inside devonthink, without creating duplicates, replicants or copies of them (the script won’t keep re-importing the same messages over and over, just the new ones, since the last time it was run).

If this script could run automatically that would be great, if that’s too complex and it’s something that I could just map to a MailActOn rule, that’s equally alright.

I am essentially looking for something to simplify the process of manually selecting mail to add to devonthink and automating the task, if it contains a keyword, project (some mailtag data or message date) that I want.

How would I go about doing this? Is it possible? It seems like it should be. There is another mailbox database whose name escapes me at the moment, which features an automatic sync that does exactly this (copies over any new message that fit a certain criteria, to the database, every X hours).

Thank you for any insights.

The good news is that even if you do not automate this process, DTPO will not duplicate messages that have already been imported into the database. DTPO will only import new (to the database) messages and the log window will report all instances of emails that are already in the database.

The bad news is that DTPO will not update existing messages that are already in the database, so if you assign or change the MailTags metadata after the message(s) has/have been imported, those changes will not be reflected in the DTPO database.

A bit of an old topic, I know, but still actual.

What I do not understand from the posts above is whether DT(PO) will save the Mail Tag tags. When opening with shft-cmd-o then won’t show in the mail window.

The nicest thing would be for DT to recognize the Mail Tag tags and add them as tags, same for projects.

Is that possible?

Here is my experience using DTPO and beta releases of MailTags (Snow Leopard Compatibility Release 5 was just made public today). Using the DTPO Mail pluging to add messages to DTPO will add MailTags as DTPO tags. No other method that I have tried (dragging a message, using the supplied script, or selecting the body of the message or typing Cmd-Shift-0) will add the tags. The MailTags Projects info is not added in any circumstance as I don’t believe MailTags writes this data to Open Meta tags.

You’re right, didn’t know it would work using the plugin. Now to find a way to implement this in a mail rule…

BTW, I noticed that the project name is saved in the Spotlight comments field. So it’s also visible there in DT(PO)