automating import of specific mailbox into specific group in

hi

i am wondering if it is possible to automate the importing of a specific mailbox from mail into a specific group in DTPO, i.e. as soon as a new mail arrives in a specific mailbox it will be imported to the group in DTPO (ideally even if DTPO isn’t running, i.e. using the Sorter)?

I am aware of the ‘add mailboxes to DT’ and ‘add messages to DT’ scripts, but these are run manually, is there a way of automating them and amending them so that the message goes to a specific group?

Also I am aware of the script ‘Mail Rule Action Import’ discussed here:

http://macscripter.net/viewtopic.php?id=29548

But am not sure how to use/automate this.

I would be grateful for any help in getting this setup right

thanks

nick

Here’s an example, not properly tested but at least it gives you a starting point:


-- Mail Rule Action Import to DEVONthink Pro (Office).
-- Created by Christian Grunenberg on Mon Apr 19 2004.
-- Modified by Annard Brouwer on Mon Oct 20 2008.
-- Copyright © 2004-2009 DEVONtechnologies LLC. All rights reserved.

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

-- entry point
using terms from application "Mail"
	-- You can use the name of the rule to specify the group path for import.
	on perform mail action with messages theMessages for rule theRule
		set ruleName to name of theRule
		repeat with theMessage in theMessages
			my importMessage(theMessage, ruleName)
		end repeat
	end perform mail action with messages
end using terms from

on importMessage(theMessage, groupPath)
	local filePath, theDateReceived, theSender, theSubject, msgSrc, msgURL, msgFilename, msgFile, msgFileRef, msgRecord
	
	set filePath to path to temporary items from user domain as string
	tell application "Mail"
		try
			-- some necessary bits of the message
			set theDateReceived to the date received of theMessage
			set theSender to the sender of theMessage
			set theSubject to subject of theMessage
			if theSubject is equal to "" then set theSubject to pNoSubjectString
			set msgURL to "message:%3C" & (message id of theMessage) & "%3E"
			
			-- Write the message data to a file			
			set msgSrc to source of theMessage
			set msgFilename to id of theMessage & ".eml"
			set msgFile to filePath & msgFilename
			set msgFileRef to open for access msgFile with write permission
			try
				write msgSrc starting at 0 to msgFileRef
				close access msgFileRef
			on error errMsg number errNo
				close access msgFileRef
				log errMsg
				error errMsg number errNo
			end try
			
			-- import the file (QuickLook will take care of the display)
			tell application id "com.devon-technologies.thinkpro2"
				-- If you want to specify a group, use the name of the rule to do
				-- so and uncomment the comments in the following 2 lines.
				set someGroup to get record at groupPath
				set msgRecord to import (POSIX path of msgFile) to someGroup
				tell msgRecord
					set the addition date to theDateReceived
					set unread to true
				end tell
				if URL of msgRecord does not start with "mailto" then
					-- no mail import plugin, so set the most important bits here
					tell msgRecord
						set name to theSubject
						set creation date to theDateReceived
						set URL to msgURL
						set comment to "From: " & theSender
					end tell
				end if
			end tell
			-- remove temporary file
			tell application "Finder" to delete msgFile
		on error errMsg number errNo
			do shell script "logger -i '" & errMsg & "'" with altering line endings
			error errMsg number errNo
		end try
	end tell
end importMessage

Is there anyway to automate this so that I can archive the emails already in existing folders. For example, this script does not seem to function if I read the email in Apple Mail while DTPO is closed. I also dont think it works after my existing mail rule has already sent it to an apple mail folder. I would prefer to simply index my mail folders from apple mail, but I also dont seem to be able to do that because the attachments are separate from the email messages in the apple mail folders i would potentially index.

Is there a better way to automatically sync my existing apple mail folders with their attachments to specific groups in DTPO?

Thanks!

I’m afraid there isn’t.

Hopefully one day once the beta version has become more stable, some additional effort will go towards making this possible. I am not proficient in applescript or using automator but it seems like this should not be the impossible dream. This functionality would go a long ways towards leveraging the mail archival and search features of devonthink which from my examination of it so far looks to be the best in class information manager thats out.

I am very pleased with assortment of new pre-made templates and examples in the data additions to Devon! Thank you for this, but I would again ask the same question about automated additions of mail that meet very simple conditions (they are filed to a given folder). Is there any technical means to achieve automatic import of these messages into Devon office? If not instant at least every hour maybe?

If someone needs to write automator or applescript to make this happen I would be happy to pay whatever hourly rate it takes to accomplish this, this feature is very important to me. Does it not exist because it is not technically feasible at this time, or only because no one has done it yet?

I have played played around with Annard’s script above (thanks). I am no expert but it would not work for me.
This is a compilation of the original Add message to DTPO script and the suggestion above that does work for me. I have simply added in a line which specifies the uuid of the database. There is a script to identify the UUID of the database in this forum.

Anyhow it works for now - any my mail messages are being filed as they arrive which is cool.

Funnily enough the set unread to true line doesn’t work. I don’t know why.
Suggestions from wiser people?

-- Mail Rule Action Import to DEVONthink Pro (Office).
-- Created by Christian Grunenberg on Mon Apr 19 2004.
-- Modified by Annard Brouwer on Mon Oct 20 2008.
-- Modified by Steve Harris May 5, 2010
-- Copyright © 2004-2009 DEVONtechnologies LLC. All rights reserved.

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

-- entry point
using terms from application "Mail"
	-- You can use the name of the rule to specify the group path for import.
	on perform mail action with messages theMessages for rule theRule
		set ruleName to name of theRule
		
		repeat with thisMessage in theMessages
		
			my importMessage(thisMessage)
			
			
		end repeat
	end perform mail action with messages
end using terms from

on importMessage(theMessage)
	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
			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 incoming group of (get database with uuid "019DD23C-8845-4195-8B41-8F3AA9726406")
				--set unread of theRecord to true
			end tell
		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

worked great for me, thanks!

This is working over here. Which version of Mac OS X do you use and which view does the frontmost window of DEVONthink use?