Actually, I think I will try to do this without Hazel involved in the process, I realise it will probably involve a heavy dose of AppleScript, which I know little about…
Looking at it now. A similar one I have been testing is Mail Archiver X. But these software's both cost 40$. I would love to avoid spending the cash, was hoping KM would be able to achieve this...
This does not do exactly what you asked for, but it does move Mail to Evernote.
You might take a look at this script by Veritrope to see if it is of any use to you.
I have never used it, so I can't vouch for it.
I will look at this and see how I can use it. I thought I'd need another apple script to determine the right emails. But turns out you can make a smart folder. So that should make it easier.
set theDate to current date
set theDate to theDate - (365 * days)
tell application "Mail"
set msgList to messages of inbox whose date sent > theDate
end tell
BUT. If you're working on a very large mailbox Mail will grind to a halt and take forever to return a result.
Looks like it handles attachments fine, but I have NOT tested it.
Just open up the script and search for "attach" and you will find a number of hits.
Here's the main handler for attachments:
--ATTACHMENT PROCESSING
on attachment_process(thisMessage, n)
tell application "Mail"
--MAKE SURE TEXT ITEM DELIMITERS ARE DEFAULT
set AppleScript's text item delimiters to ""
--TEMP FILES PROCESSED ON THE DESKTOP
set ExportFolder to ((path to desktop folder) & "Temp Export From Mail:") as string
set SaveLoc to my f_exists(ExportFolder)
--PROCESS THE ATTACHMENTS
set theAttachments to thisMessage's mail attachments
set attCount to 0
repeat with theAttachment in theAttachments
set theFileName to ExportFolder & theAttachment's name
try
save theAttachment in file theFileName
end try
tell application "Evernote"
tell n to append attachment file theFileName
end tell
--SILENT DELETE OF TEMP FILE
set trash_Folder to path to trash folder from user domain
do shell script "mv " & quoted form of POSIX path of theFileName & space & quoted form of POSIX path of trash_Folder
end repeat
--SILENT DELETE OF TEMP FOLDER
set success to my trashfolder(SaveLoc)
end tell
end attachment_process
I think not using a smart folder (which gave me wrong results, included things from June 2015 - possibly because the thread spreads a few months? not sure why) maybe not be the best way to go about it, but your script looks promising.
Since I am planning to run this every 24 hours (on a headless system during the night), it shouldn't be too bad?
I have exported all mail up until yesterday 1 year ago in one big swoop with a trial version of Mail Archiver X, so the mailbox isn't too massive.
How do I connect both scripts in KM or where do I add these lines in the script provided?