Extract attachments from archived emails

Hi

I have archived all my email into DT, and would extract the attachments directly into DT. I have found some old long treads, but they did not sem to adress my question.

How can I extract the attachments (preferrably not the logos etc, but I could live with this) from the archived emails in DT?

Thanks.

You can drag and drop attachments from the imported emails to have them as separate documents.

Thanks. That helps. But I was looking for a batch processing of all enrolled in a specific group / database.

Also: can I search for emails with attachment?

You could define a smart group – there’s an attachment placeholder. As described in the Fine Manual.

My email import is based on the applescript provided by Devonthink (Add attachments to DEVONthink)

Click to see script
-- 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."
			set theGroup to preferred import destination
		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
			set theSender to the sender of theMessage
			repeat with theAttachment in mail attachments of theMessage
				try
					if downloaded of theAttachment then
						set theFile to theFolder & (name of theAttachment)
						tell theAttachment to save in theFile
						tell application id "DNtp"
							set theAttachmentRecord to import theFile to theGroup
							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
``

This sounds what I am looking for - But I do not find anything in the manual or in the dialog box to create a smart group using these Placeholders (I found Appendix - Placeholder)?

Could you give me an example for that smart group? Thanks.

OK - I think I saw that script in another thread as well. But where can I find it (I see, that you link to it in your reply - thanks)? I don’t find it in the Scripts Menu. Also: Do I have to run this script instead of the “archive” of emails? How do I do tthis?

Sorry about these newbie questions - I jumped into DT land and am trying to find my bearing.

It’s in the global script menu when you’re in Apple Mail.
However it doesn’t process already imported emails in DEVONthink.

By the way, attachments are indexed when possible. Have you tried searching for text in an attachment?

Hmm. OK - I am in Apple Mail - foreground app. Where can I find the Global Script Menu?

I do not have anything like “Scripts” in Apple Mail. And when I switch to Devonthink, I do not see the script mentioned in the Script Menu. It seems, that it is not my day…

True - they are! great! But I still would have them as standalone documents to make it easier to work with them.

It’s not part of any specific application’s menus.
Look for the s-shaped scroll icon in the menubar. The contents will change relative to the application you’re in.

Well - normally I love Bartender…… It was in the hidden Menu from Bartender and I always confused it with the Script item in Devonthink…

So the "Add mailbox(es) & attachments to DEVONthink does the same as the “archive mailbox” from DT, only tthat it also imports and adds the attachments to the same database - correct?

I tried it, and the attachment are extracted, but the log says “failed” and no further info.

Did you import an email that’s already in DT?

OK - I deleted all emails again, and tried: No luck.

But: I than thought - hm - does DEVONthink has Full Disk Access? BINGO. Gave it Full Disk Access and it works.

Thanks a lot.

Now I can get the attachments and the emails in - but I had the option “Group Copnversation Threads” enabled in DT, which is not doe when importing from Apple Mail using the global script.

Is there any way of achieving this, As I like this grouping a lot and would like to keep it.

Alternative: do the grouping into Converssations afterwards?

Conversation threading currently can’t be done by an automatic process in DEVONthink post-import.
Threading would happen when using the View > Import sidebar or Apple Mail plugin.

If you use this script, the email and the attachments will be stored in their own group. You will end up with a duplicate email as this process creates a different UUID than the mail plugin.

On a side note: email threading is not a precise operation due to the lack of standards and individual implementations over the years.

Thanks for the clarifications. I will probably archive the emails from DT, and a second time, from elected folders, import from Mail using the script.

One last question: I know now, how I can find emails with an attachment in a smart group - but is it possible, to create a smart group with all emails with attachments of a certain type?

Thanks a lot for your patience.

You’re welcome.
The type of attachment isn’t a criterion. Only the attachement count.

Side question: I think I’ve messed up with something, but don’t know what.
I can’t find the “s” Script in the menu bar.
I also use Bartender, but I can’t see the s in the hidden bar.
It doesn’t show up in any App I use.

When I’m on DT I see the s in the menu of the App, not in “global” menu bar.

How do I restore it?

If it’s not showing… and it would be farther to the right in the menu bar, it can be toggled on and off in Script Editor’s Preferences > General > Script Menu…

1 Like

Done. Thank you!