Send OSX Mail with MailTags (Indev) to specific Databa DTPO

I have read through the boards and cannot find the answer to this. This should be simple to do. Use the Devon Script in Apple Mail Rules, OSX MacMail (10.9.2) with MailTags (4.0) to auto import to DTPO with the MailTags intact so that the mail gets sorted into the proper database. As an example, lets say there are 2 databases in DTPO, lets call them ‘DB 1’ and ‘DB 2’, and I create the keyword ‘important 1’ in MacMail using MailTags. I’d like those mails with that keyword to go into ‘DB2’ Email folder in DTPO. The problem is that the MailTags get stripped when coming into DTPO so that any rule I have in DTPO is useless. The mail gets in DTPO, but only into the Global Inbox, and since the MailTag from MacMail is stripped I have to manually put it into the Database of my choice.

I did notice that the engine in the DEVON Conduit (loaded when I install the Add-Ons) is for ‘SnowLeopard’, although I am running the latest DEVON V 2.7.7 and I am wondering if that has anything to do with it and if that is outdated, what is that installing from the latest V of DTPO.

Any ideas on if this seemingly obvious use of this program is possible and how it should be done?

Thanks.

Thanks for the reply Korm. I am a novice script writer, so messing around with them is only something I do if I am totally comfortable with it. In this case, not so much. Mind boggling that DTPO doesn’t include something like this in there scripts. Personally I don’t care if I use MailTags or another way to tag them, but I have may clients with many projects and I bought DTPO because I thought it had this capability, i.e. auto import and auto sort my mail once I tagged in in MacMail.

Again, I appreciate the response.

Hold on a second. I scratched my original reply.

Against my better judgment I installed MailTags 4, added keywords to a message, and (a) dragged the email into DEVONthink Pro Office, and (b) also used the DEVONthink import script, and © used the mail rule. In each case, the keywords came across as tags.

(There are several other threads in the forum that also indicate this should work.)

At the time of writing this, and it doesn’t look like this is going to change in Yosemite, Mail.app does not include support of tagging email messages in Mail.app. It shouldn’t be a surprise that it is unlikely that DEVONthink will write Mail.app scripts with tag capability when Apple has not included message tagging in Mail.app.

Like korm, I gave up on MailTags long ago as it created far more problems for me than what it was worth. However, I recall that there was a preference in MailTags to write OpenMeta tags when exporting emails. I didn’t have any problems with emails imported into DEVONthink losing their tags that were applied with MailTags. That doesn’t mean that something hasn’t changed with MailTags 4 to break this. Have you contacted Indev support about this? They might be able to help you to get their product to work with other software.

See MailTags 4 > Preferences

(Now, I’m deleting this beast - even testing for a while caused mail file headaches and crashes.)

Korm,
from what I am seeing seeing in this land other threads, this function seems to be random. I am running MT 4 as well and my tags don’t port over to DTPO.
Again, I thank you and the others for your responses. Looks like I have to wait for some kind of patch, or find a more stable program than DTPO to do my work in.

Disappointed. Thanks all.

The issues discussed in this thread do not indicate stability problems in DEVONthink Pro Office. They do indicate problems in trying to attach attributes and actions to messages in Mail, and having them carry over under another application.

I understand your disappointment, but disagree with part of your conclusion. :slight_smile:

Bill,
I have an aversion to software writers putting blame on other pieces of software, especially when the first piece of software is specifically written to work with the second. That said, I find it hard to believe that this is not a common demand and one that can’t be fixed. Simply put, to have tagged Mail (from MacMail) be auto imported into specific DBs in DTPO. I don’t care if I use MailTags or a script for tagging that Devon writes, but a huge part of my day is spent getting mail associated with specific projects into my DTPO.

Anything that can make this happen, without me having to drag and drop is welcome.

I’m not a software developer. I’ve been a heavy user of DEVONthink since it appeared.

As some of our users noted in this thread, Apple itself has been pretty light in approaching tags in Mail. There’s likely a good reason for that.

I have for years used Mail menu commands in Mailbox or Message inserted by the Mail plugin of DEVONthink Pro Office to send selected items to a specific group location in an open DEVONthink database. As I’ve configured Preferences > Import - Destination to Select group, a HUD will pop up allowing me to choose the destination of the selected items.

I don’t need to add tags to the items selected this way, and then come up with a scheme to file items by tag. Instead, I can directly capture the messages to a location in a database.

I can select multiple messages to go to a location by scrolling through a list and Command-clicking the ones to be copied. Or I can do a search in Mail and select the results for capture to a database. Or I could aggregate selected items into a Mailbox and periodically capture its contents to a database.

Note: As previously captured messages will not be duplicated in a subsequent capture procedure, I set Preferences > Email - Messages: by checking “Previously imported will become replicants”.

I’m a fan of kludges, which can accomplish an objective that’s not directly attainable by an application. But my approach here seems much more straightforward than the one you are trying to implement. Rather than select and tag items, then try to auto file them based on tag, I select them and directly file them into a database.

As already noted, Apples support for tags for emails is non-existent so far, so don’t blame DEVONthink.

But, if you had a script, that would send (export) emails from Apple Mail to a predefined location in a predefined DEVONthink database and would also add a predefined tag(s) to the .eml, that’s exported to DEVONthink … would that help you?

To be clear, predefined means, that the database, the location and the tag(s) would have to be set in the script, before you would run it on selected messages or call up via a rule in Apple Mail.
(I saw from other posts from you, that you already use such a script without the tagging part.)

Berndm,
What you describe would be a solution to what I am looking for.
If I could use a template of that script to just change the DB the mail is sent to, I could reuse that with a simple tweak for each DB. And assuming that could be done, I could assign that script to run based on criteria I set up in MacMail Rules.

Yes, that would help a great deal.

I know MacMail is not rock solid when it comes to its rules and such, but I do find that if I force the rules to run once in a while, they do get followed. This is a lot better than having to individually move mail by D’n’D or other methods as I receive about 50 emails a day that need to be parsed into different projects.

Thanks again to all those that have contributed to this thread. And if there are any others that have solutions, please post, as I know these things are not always one-size-fits-all.

Ok, the script is a modified version of this script, Christian Grunenberg from DEVONtechnologies very kindly and patiently helped me with that. I run different versions of this script on messages in Apple Mail from a KeyboardMaestro palette or by calling the script via LaunchBar. You can also have a rule execute it.

I only added the tagging part for you. Please note my comments below, but first here’s the script:

-- Import selected Mail messages & attachments to DEVONthink Pro.
-- Created by Christian Grunenberg on Mon Mar 05 2012.
-- Copyright (c) 2012-2013. All rights reserved.

-- POSIX path of destination database
property pDatabasePath : "/Users/me/Documents/DEVONthinkPro/datenbanken/mail.dtBase2"

-- this string is used when the message subject is empty
property pNoSubjectString : "(no subject)"

tell application "Mail"
	try
		-- Location of destination groups.
		set pEmailLocation to "/in/projectx"
		set pMessageLocation to pEmailLocation
		set pAttachmentLocation to "/Anhaenge"
		
		tell application id "com.devon-technologies.thinkpro2"
			if not (exists current database) then error "No database is in use."
			
			if pDatabasePath is "" then
				set destination_database to inbox
			else
				set destination_database to open database pDatabasePath -- Ensure that the database is open
			end if
			set email_group to create location pEmailLocation in destination_database
			set message_group to create location pMessageLocation in destination_database
			set attachment_group to create location pAttachmentLocation in destination_database
		end tell
		
		set theSelection to the selection
		set theFolder to (POSIX path of (path to temporary items))
		if the length of theSelection is less than 1 then error "One or more messages must be selected."
		repeat with theMessage in theSelection
			my importMessage(theMessage, theFolder, email_group, message_group, attachment_group)
		end repeat
	on error error_message number error_number
		if error_number is not -128 then display alert "Mail" message error_message as warning
	end try
end tell

on importMessage(theMessage, theFolder, theEmailGroup, theMessageGroup, theAttachmentGroup)
	tell application "Mail"
		try
			tell theMessage
				set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
			end tell
			if theSubject is equal to "" then set theSubject to pNoSubjectString
			set theAttachmentCount to count of mail attachments of theMessage
			tell application id "com.devon-technologies.thinkpro2"
				set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in theMessageGroup
				set unread of theRecord to (not theReadFlag)
				set label of theRecord to 5
				set tags of theRecord to (tags of theRecord) & "exampletag1" & "exampletag2"
			end tell
			repeat with theAttachment in mail attachments of theMessage
				set theFile to theFolder & (name of theAttachment)
				tell theAttachment to save in theFile
				tell application id "com.devon-technologies.thinkpro2"
					set theAttachmentRecord to import theFile to theAttachmentGroup
					set unread of theAttachmentRecord to (not theReadFlag)
					set URL of theAttachmentRecord to theSender
				end tell
			end repeat
			move theMessage to mailbox named "DEVONthink"
		on error error_message number error_number
			if error_number is not -128 then display alert "Mail" message error_message as warning
		end try
	end tell
end importMessage

You have to modify these lines:

Replace this with the correct path to your database and the databases name and your username:


property pDatabasePath : "/Users/me/Documents/DEVONthinkPro/datenbanken/mail.dtBase2"

Replace this with the path to your target folder in the database. In my example “in” is a group on the root level of the database and “projectx” is a subgroup of this.


set pEmailLocation to "/in/projectx"

Replace this with the path in your database, that you want the attachments to be filed to (yes, the attachments will be exorted to DEVONthink separately too with this script, unless you modify the script):


set pAttachmentLocation to “/Attachments"

Replace “exampletag1” and “exampletag2” with your tags and add a third or remove the second, depending on how many tags you want:


set tags of theRecord to (tags of theRecord) & "exampletag1" & "exampletag2"

PS: As I understand that command also imports existing tags, but I am not sure!
PPS: If you want to assign no tag(s) simply delete this line.

This sets the status of the message in DEVONthink to “read”:


set unread of theRecord to (not theReadFlag)

This sets the label for the message to the 5th label in > DEVONthink Pro Office>preferences > colors > labels. If you don’t want to label the message, simply delete that line:

set label of theRecord to 5

This moves the exported message to a folder in Apple Mail called “DEVONthink”, which I created. I did so, so that I do not export messages more than once (avoid duplicates) and because I do not keep messages in Apple Mail, therefore it is ok for me, when the messages are moved from their original location after exporting.
You must evaluate yourself, if that makes sense to you or if you export by date to avoid exporting messages over and over again. Another option would be, to apply a color to exported messages or to flag them within Apple Mail, either via the rule or manually or by modifying this script.
If you do not want the messages to be moved within Apple Mail, I think you just can delete that line.


move theMessage to mailbox named "DEVONthink"

I hope I have it all covered. I am by no means capable of AppleScript, but feel free to ask, if you have any questions and I hope the good people on this board will help us. :smiley:


PS: If you want to apply this script via a rule in Apple Mail to incoming messages, please note, that there could be problems with POP-accounts since the release of OS10.8. Apple has changed something there. I assume, they have not fixed it since then.
On incoming emails from IMAP it works just fine as well of course on existing emails.

Berndm,
Thank you. I will give this a try. And this is the reason I love these boards,
IF I may be so bold to say Vielen Danke vor Alles. (Bei deinem script und ihre name glaube ich du sprechst Deutsch.)

Again, thank you.