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 and I don’t want to manually put in about 500 of them again).
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
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
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?