Fix dates via IMAP on messages

Darren Pilgrim darren.pilgrim at bitfreak.org
Wed Jul 19 05:33:11 UTC 2006


Lyndon Nerenberg wrote:
>> All of my new mail is fine (I run my mailserver now) but my mail from 
>> about 7-10 years ago is all the date of the migration. Is there any 
>> program out there that will read the headers of the mail and change 
>> the server-date of the files? I've tried imapsync with 
>> -syncinternaldate, to see if it read headers, but it doesn't. I just 
>> want to be able to run the command on the user/imap server of choice, 
>> and have it read all the mail headers, and set the creation dates 
>> properly on the mails (all via IMAP).
> 
> I'm not aware of a tool that will do this, but writing a program to 
> handle this is trivial. All it needs to do is read the message until you 
> find the date header, parse the date, then call utimes() to update the 
> file's mtime.

It's far from trivial using the Date header.  When I had to do the same 
post-migration Maildir fix-up David is talking about, I found the format 
of the Date: header varied so widely that I ended up with tens of 
thousands (out of an archive of ~300k emails) of messages whose Date 
headers stumped the date-grokking functions in Perl and Visual Basic.

What *is* pretty standard is the timestamps in Received headers.  I 
don't have any messages on hand that were relayed through qmail, but 
Postfix, Sendmail and a handful of common Windows "enterprise" mail 
servers all use the same format[1] and place it immediately at the only 
semi-colon in the header.  Since the "Date" on IMAP messages is the 
message creation time, not the Date header, on most IMAP servers, the 
timestamp in the top-most Received header is usually pretty close to the 
date of actual message delivery.

[1] "%e %b %Y %T" in strftime(3) parlance.

-- 
Darren Pilgrim



More information about the freebsd-isp mailing list