Quantcast
Channel: DEVONtechnologies Community - Latest posts
Viewing all articles
Browse latest Browse all 16267

Same mail with different mail ids in mail.app when running Apple Scripts from DEVONthink 3

$
0
0

@chrillek

As to your problem: Perhaps you’re dealing with a mail thread here, consisting of two messages?

My first guess was, that the setting/threat thing might be the problem. But even without enabling the setting and choosing the single message, the problem occurs. But what’s really weird: The same message is send twice to the AppleScript script.

Modified in what way ?

Checking for the extension of the attachment. I’m only interested in PDF documents. The original code adds all attachments to DEVONthink.

If I select this mail entry, the selection list has two elements. In any case, the problem is not DT here, as it just works with the selection in Apple’s Mail.

Thanks for pointing that out. I was aware of that. I reached out to the community, in case someone had a similar problem with the mail.app before.

For now I check for duplicate mails reported by the mail.app. A quite ugly and somewhat imperformant implementation, but it works. Any suggestions to improve the code are highly welcome.

-- Import attachments of selected messages to DEVONthink.
-- Created by Christian Grunenberg on Fri May 18 2012.
-- Copyright (c) 2012-2020. All rights reserved.

tell application "Mail"
	try
		tell application id "DNtp"
			if not (exists current database) then error "No database is in use."
		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."
		set messageList to {}
		repeat with theMessage in theSelection
			set theSubject to subject of theMessage
			set theSender to sender of theMessage
			set theCurrentMessageItem to (theSender & theSubject)
			
			set theFoundItem to 0
			repeat with theMessageItem in messageList
				if (contents of theMessageItem) is equal to theCurrentMessageItem then
					set theFoundItem to 1
					exit repeat
				end if
			end repeat
			
			if theFoundItem = 1 then
				exit repeat
			end if
			
			set the |messageList| to the |messageList| & theCurrentMessageItem
			
			repeat with theAttachment in mail attachments of theMessage
				-- try
				if downloaded of theAttachment and (name of theAttachment ends with ".pdf") then
					set theFile to theFolder & (name of theAttachment)
					tell theAttachment to save in theFile
					tell application id "DNtp"
						set theAttachmentRecord to import theFile
						set URL of theAttachmentRecord to theSender
						perform smart rule trigger import event record theAttachmentRecord
					end tell
				end if
				-- end try
			end repeat
		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

Sounds a bit contrived – why not have Apple’s Mail retrieve the mail from the remote server?

I prefer to be not dependent on a single OS/Application. Some time ago I used Linux + Thunderbird. Switching to MacOS + Mail.app was easy for mails. I just needed to configure my internal mail server (IMAP). And for the “running cost”, I don’t like to be dependent on the external mail provider either - to paranoid. :slight_smile:


Viewing all articles
Browse latest Browse all 16267

Trending Articles