"UUID already in database" for emails imported from Apple Mail

DT3 (for mac) is frequently throwing “UUID already in database” errors for items when I try to move them from the DT3 inbox to a DT3 database.

The error occurs both when they’re manually dragged or moved via Applescript.

It seems to occur only on items which originated in Apple Mail.

Importing an already imported email could cause such messages (or trying to move an email into a database containing this email alread). How do you exactly import and move the items?

1. The emails are added to the inbox via a rule in Apple Mail which runs this AppleScript.

    property pDatabasePath : ""

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

    using terms from application "Mail"
    	on perform mail action with messages theMessages for rule theRule
    		-- Location of destination groups.
    		set pMessageLocation to "/" & (name of theRule)
    		-- set pAttachmentLocation to pMessageLocation & "/Attachments"
		tell application id "DNtp"
			if pDatabasePath is "" then
				set destination_database to inbox
				set destination_database to open database pDatabasePath -- Ensure that the database is open
			end if
			set message_group to create location pMessageLocation in destination_database
			-- set attachment_group to create location pAttachmentLocation in destination_database
		end tell
		tell application "Mail"
			set theFolder to (POSIX path of (path to temporary items))
			repeat with theMessage in theMessages
					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 "DNtp" to set message_group to create location theSubject in destination_database
					tell application id "DNtp" to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(not theReadFlag)} in message_group
					repeat with theAttachment in mail attachments of theMessage
						set theFile to theFolder & (name of theAttachment)
						tell theAttachment to save in theFile
						tell application id "DNtp"
							set theAttachmentRecord to import theFile to message_group
							set unread of theAttachmentRecord to (not theReadFlag)
							set URL of theAttachmentRecord to theSender
						end tell
					end repeat
				end try
			end repeat
		end tell
	end perform mail action with messages
end using terms from

2. A set of smart-rules in the inbox then automatically files the emails into the relevant database, based on the presence of @[string] in the subject. For example, if the email has “@tax” in the subject, then it’ll be filed into the Tax database.


This action causes the error message as an email with the same message ID exists already in the destination database. This could e.g. happen if the rule in Apple Mail is performed several times on the same emails (but Apple Mail’s rule handling is in my experience although not always reliable).

What would be a more reliable way of accomplishing this?


  1. Automatically copy emails (including attachments) into DevonThink from Apple Mail
  2. Automatically file them into the relevant DB based on the presence of pre-defined strings in the subject? (e.g. “@tax” goes to the Tax db etc)

Note: I have a dedicated email address in Apple Mail - just for DevonThink. Any email received at that address should be automatically added to DT.

The rules in Apple Mail are still the best automatic option. How often does the error happen?