How to extract email addresses from DEVONthink database?

Hello,

I am using DEVONthink, amongst other things, to archive emails. There are currently 455,000 emails in one of the databases.

How can I extract the “from” address from all those messages and write them, together with the folder the message is in, in a flat text file? I need that so I can built a script of sorts to create server mail rules for MS Outlook (My Exchange rules were recently deleted :frowning: and I don’t want to manually put in about 500 of them again).

Thanks,
Chris.

You can extract the sender’s address via AppleScript:


tell application id "DNtp"
		set theSelection to the selection
		repeat with theRecord in theSelection
			set theMD to meta data of theRecord
			set theSender to |kMDItemAuthorEmailAddresses| of theMD
		end repeat
end tell

and, with the fading vigour of advancing years, I now tend to lazily fall back on generic functions, and write such things either in JS as:

(function () {
    'use strict';

    return Application('DEVONthink Pro')
        .selection()
        .map(x => x.metaData().kMDItemAuthorEmailAddresses)

})();

or, by analogy, in AS as:


tell application id "DNtp"
    script email
        on |λ|(x)
            |kMDItemAuthorEmailAddresses| of ¬
                ((meta data of x) as record)
        end |λ|
    end script
    
    my map(email, selection as list)
end tell


-- GENERIC FUNCTIONS --------------------------------------

-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
    tell mReturn(f)
        set lng to length of xs
        set lst to {}
        repeat with i from 1 to lng
            set end of lst to |λ|(item i of xs, i, xs)
        end repeat
        return lst
    end tell
end map

-- Lift 2nd class handler function into 
-- 1st class script wrapper 
-- mReturn :: Handler -> Script
on mReturn(f)
    if class of f is script then
        f
    else
        script
            property |λ| : f
        end script
    end if
end mReturn

Hello,

I’m absolutely new in using applescript. I tried to get work the script, but it didn’t work for me.

I marked the imported mails (from which I wanted to extract the sender address) and started the script - but nothing happened. What I could have done wrong?

Thanks a lot for help

Nikolaus

All 3 scripts are very basic examples, the output can be only viewed in the AppleScript Editor.app.