I moved a bunch of emails using imap over to the server. When they loaded onto the sever the date modified is the same date for all the emails. So when I am using imap in mac mail it displays all of my emails as coming in on Sept. 30th.
The header of the emails contain the correct date so roundcube displays the correct date because I think it is pulling the information from the header.
Mac mail and other mail programs are pulling the information from the date created, modified and/or accessed. (I am not sure which one so I changed them all)
I manually was able to change the date modified, created, and accessed to match the header sent date, but it is a lot of work to do that for 2000 emails.
Do you know of a way I can change the modified and created date as a batch that will make them match the header date inside each email file?
Anyway to do it through cron?
I can use bash in Ubuntu or use windows either one will work.
The header in the file looks like this:
Return-Path: <[email protected]>
From: <[email protected]>
To: <[email protected]>
Cc: "Mike" <[email protected]>
Subject: Example Subject
Date: Mon, 29 Sep 2014 10:23:34 -0400
Message-ID: <[email protected]>
MIME-Version: 1.0
The date line by itself:
Date: Mon, 29 Sep 2014 10:23:34 -0400
First, cd
to the directory where the files are. Then run:
for f in *
do
touch -d "$(sed -n 's/^Date://p' "$f" | head -n1)" "$f"
done
The above uses sed
to extract the "Date:" information from the file and then uses touch
to assign that date to the file.
This was tested using GNU tools. Mac OSX tools sometimes differ.