Backlinks for emails

From what I understand email archived using the mail plugin doesn’t contain a link back to the original email in Mail. I found a reference to the Applescript “Add message(s) to DEVONthink Message Link” which works but I think it would be nice to have this functionality for all imported messages.

(Please let me know if I missed something and there is actually a way to get back to the original message in Mail)

Correct, they contain a link which can be used to directly reply.

If you want a link that opens the original message instead of a reply message you could use this script Correct url of eml records, I think.

Or you could use this script to open the original message

-- Open original mail

tell application id "DNtp"
		set theRecords to selected records
		if theRecords = {} then error "Please select some mail records"
		repeat with thisRecord in theRecords
			set theURL to URL of thisRecord
			if theURL starts with "mailto:" then
				set theTextItems to my tid(theURL, "in-reply-to=")
				if theTextItems ≠ {} then
					set theOriginalMessageURL to ("message://" & item 2 of theTextItems) as string
					do shell script "open " & quoted form of theOriginalMessageURL
					error "Can't get original message URL"
				end if
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

on tid(theText, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theTextItems to text items of theText
	set AppleScript's text item delimiters to d
	return theTextItems
end tid

Thanks, that will work perfectly for me.

1 Like