Page 1 of 1

Changing filename of *.eml files in finder

PostPosted: Sun Apr 12, 2020 7:29 am
by luponero
Hi there BrainsTrust,

I am filing MS Outlook mail into Finder by dragging the MS Outlook mail items into Finder. I then want to use Hazel to change the file name. I'd like the rename the file with pattern: date name extension...which I have figured out successfully :D

With the date pattern I'd like to use the date the mail was sent to me (data from MS Outlook) and this does not seem to be an option even if I look in the "Other" area and look at all the attributes.

Is there a way to do this? I have tried all date options to no avail. Any help will be appreciated.

Regards luponero :?:

Re: Changing filename of *.eml files in finder

PostPosted: Mon Apr 13, 2020 9:01 am
by Mr_Noodle
You can try using "Contents contain match" and try to match it in the contents of the file. Try using Hazel's preview function to see if the file's contents are available there.

Changing filename of *.eml files in finder

PostPosted: Sat Apr 18, 2020 11:06 pm
by luponero
Thanks Mr Noodle...that worked.

As I am now trying to be more creative I am also trying to incorporate the email addresses (to and from) into the filename. I have tried every "other" attribute for renaming but nothing picks up the information I need.

Any tips from the brainstrust?

Thank in advance

Re: Changing filename of *.eml files in finder

PostPosted: Mon Apr 20, 2020 9:48 am
by Mr_Noodle
Is it available to extract from the contents?

Re: Changing filename of *.eml files in finder

PostPosted: Fri Apr 24, 2020 11:56 pm
by luponero
Mr_Noodle wrote:Is it available to extract from the contents?

Unfortunately I can't see any addresses from the contents. I am not sure why :?:

I have tried to use the "other" naming conventions to no avail. I just can' locate or extract an email address.

Re: Changing filename of *.eml files in finder

PostPosted: Mon Apr 27, 2020 10:13 am
by Mr_Noodle
In that case you may need to use a script.

Re: Changing filename of *.eml files in finder

PostPosted: Mon Apr 27, 2020 7:04 pm
by luponero
Mr_Noodle wrote:In that case you may need to use a script.

Thanks. I'll see what I can work out. Never tried a script but always happy to learn.

Re: Changing filename of *.eml files in finder

PostPosted: Tue Sep 01, 2020 5:44 pm
by nm1
luponero wrote:
Mr_Noodle wrote:In that case you may need to use a script.

Thanks. I'll see what I can work out. Never tried a script but always happy to learn.


You can use the following AppleScript to capture the header information into their own variables, which you can then use in Hazel to name the file as you like:

Code: Select all
set pFile to quoted form of (POSIX path of theFile)
   set {mDate, mSubject, mFrom, mTo} to every paragraph of (do shell script "cat " & pFile & " | grep -e Date: -e Subject: -e From: -e To:")


In terms of the Sent/Received timestamp, you can either use Hazel's functionality to turn the mDate variable into timestamp format, or else you can do it with AppleScript:

Code: Select all
-- trim mDate beginning at char 12 to end of line
   set mDate to trim(mDate, 12)
   set mTime to trim(mDate, 13)
   set mFrom to trim(mFrom, 7)
   
   -- capture elements of mDate into components
   set {mDay, mMonth, mYear} to every word of mDate
   set theDate to mMonth & space & mDay & space & mYear
   
   --capture elements of mTime into components
   set AppleScript's text item delimiters to ":"
   set {h, m, s} to every word of mTime
   set theTime to h & m & s

Re: Changing filename of *.eml files in finder

PostPosted: Sat Jun 29, 2024 3:55 am
by HelloHazel
Hi there,

Something similar here, I would like to drag and drop an email from Apple Mail to a folder, and have it automatically renamed according to the date received, to be able to sort them historically.

Image

It doesn't work: the date added by hazel is always 0001-12-31

I tried with multiple emails, accounts, with both Apple Mail and Outlook

I don't know how to code, so could someone guide me on how to resolve the issue. It seems that hazel was designed to do it.

Thanks.

Re: Changing filename of *.eml files in finder

PostPosted: Mon Jul 01, 2024 8:49 am
by Mr_Noodle
Have you checked the date received? Select the file in Finder and do Get Info. Do you see the Date Received in the More Info section?

Re: Changing filename of *.eml files in finder

PostPosted: Mon Jul 01, 2024 4:32 pm
by HelloHazel
Mr_Noodle wrote:Have you checked the date received? Select the file in Finder and do Get Info. Do you see the Date Received in the More Info section?


The date received displayed in the email when opened in Apple Mail or using Quicklook is correct i.e. 31 July 2014

Regarding Get Info for the eml file, in the "More Info" section, I can see only "Content created: 1 July 2024 at 21:28"

Also, "name" of the sender is not added when the file is renamed.

I get "0001-12-31 - - news.eml"

Re: Changing filename of *.eml files in finder

PostPosted: Tue Jul 02, 2024 8:38 am
by Mr_Noodle
If it doesn't appear in the Get Info, then the info is not available to Hazel. Are you able to search for that eml file using Spotlight? Try searching for some text in the email that is unique.

Re: Changing filename of *.eml files in finder

PostPosted: Wed Jul 03, 2024 2:40 am
by HelloHazel
Mr_Noodle wrote:If it doesn't appear in the Get Info, then the info is not available to Hazel. Are you able to search for that eml file using Spotlight? Try searching for some text in the email that is unique.

A Spotlight search doesn't show the file. Neither based on file name, nor on file content.

I googled the topic, and Spotlight doesnt search for eml files in general.

Re: Changing filename of *.eml files in finder

PostPosted: Wed Jul 03, 2024 8:41 am
by Mr_Noodle
You'll have to use a script like above then as it's not data provided to Hazel by default.