I am running two different email servers using Postfix and Dovecot. Some of my users have accounts on both servers and sometimes transfer emails from one to the other through their email client. When they do so, the email is showing up on the new server with the time stamp of when it was transferred instead of the original time.

I assume this is because the email is going back into the Postfix queue like it is a new message. Is there a way I can have it maintain the original timestamp?

This is using IMAP and emails are stored in the Maildir format on both servers.


Here is a Perl script that sets the file date to the value in the Date: line in the message header. http://www.athensfbc.com/public/fix_msg_dates

Usage: fix_msg_dates.pl <path to message directory>


| improve this answer | |
  • Thank you for this. I did use a similar script to fix the time stamps on the emails but it doesn't fix the ongoing issue unless I set it up as a cron job. I believe I would also need to delete dovecot's cache files. Even so, most mail clients will download the message and not recheck the date of emails each time it connects to the server so the date would still be wrong in the client that moved the email or downloaded the message before the cron job ran. – drewag Apr 14 '14 at 15:36
  • Just in case someone else experiences this, I had to move the file out of the Maildir folder hierarchy and then move it back in for the date change to take effect on my Mail client (Apple Mail). – Ryan H. Dec 31 '16 at 22:26

Are you using Maildir storage with IMAP? If so, it should possible to just move the messages into the new folders. It should also be possible to use a mail client to copy between the two IMAP folders.

It is important the the messages have a Date header, as this is usually the preferred date. Some clients will prefer the Delivery-date instead. If all else fails, they may used the date the message appeared in the folder. As long the messages have a Date header, then the dates should remain the same.

Emailing between the two servers will reinject the messages into the mail stream and result in the Date headers being replaced.

EDIT: My experience with Dovecot and Thuderbird indicates that as long as the Date headers exist, the date doesn't change when a file is moved using IMAP. If the Date headers are absent, then the date is set to the date the file shows up in Thunderbird. IMap internal date value is specified in RFC-3501 Internet Message Access Protocol section 2.3.3. Based on my reading of the RFC, I would expect the Delivery-date header to be the significant header.

If you are moving files using IMap, Postfix is irrelevant as it is not involved. Postfix will only be involved if the messages are being mailed between servers.

| improve this answer | |
  • Both of the servers are indeed using Maildir with IMAP. (I added that information to my original question). So are you basically saying that this is not possible because the mail client is in effect "emailing between the two servers"? – drewag Apr 12 '14 at 20:08
  • @drewag Due to your inclusion of Postfix it is not clear how the messages are being moved. I have update my response and included a pointer to the relevant RFC if the messages are moved using IMAP – BillThor Apr 13 '14 at 14:24
  • The email itself is not getting modified (the date sent header is still correct). If I set my email client to use date sent instead of date received, everything works great. It is when using the date received that the date seems to get reset. If I am not mistaken, the date received is part of the IMAP protocol and therefore it is Dovecot that is causing the issue. On the other hand, I don't see how Dovecot could know the original received time so I'm not sure this is possible. – drewag Apr 13 '14 at 16:49
  • @drewag Their are two headers which can be used to get the original recieved time: Date-delivered or the Received headers. Date-delivered is added by Exim, but I don't know if Postfix does the same. Each server which receives the message should add a Received header. This is described in the RFCs. – BillThor Apr 14 '14 at 1:11
  • Thank you for the help so far. All of the received headers are still correct and no header has the date the the mail client is displaying. The only place I can find that references that date with the email is the epoch in the email's file name on the server and the timestamp of the file. That leads me to believe that there is something in the IMAP protocol that is telling the client the received date and dovecot is using either the file name or the timestamp of the file to decide what time it was received. – drewag Apr 14 '14 at 2:12

I discovered my answer here: http://www.dovecot.org/list/dovecot/2008-July/032165.html

When transferring email from one server to another, an IMAP client must use the APPEND command. This command has an optional date parameter that communicates the "internal" or "received" to the new server. However, this being an optional parameters, clients are not required to send it, and if left out, the specification states that it should default to the current time. That is what happened in my case, the mail client did not report the original internal time.

The discussion also clarifies that Dovecot uses the timestamp on the file to report the internal time. So if I want to correct the received time after the fact, I could set the timestamp on the file and then delete the cache files.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.