#!/bin/cat $Id: FAQ.Dates.txt,v 1.13 2026/07/15 22:27:06 gilles Exp gilles $ This documentation is also available online at https://imapsync.lamiral.info/FAQ.d/ https://imapsync.lamiral.info/FAQ.d/FAQ.Dates.txt ======================================================================= Imapsync tips about dates. ======================================================================= Questions answered in this FAQ are: Q. We have found that the time and date displayed have been changed to the time at which the file was synchronized. What happened? Any fix? Q. Is there a way to set any message with "Date: (Invalid)" to a valid one like "Date: Thu, 1 Jun 2017 23:59:59 +0000"? ======================================================================= Q. We have found that the time and date displayed have been changed to the time at which the file was synchronized. What happened? Any fix? R. This is the case by default with some email readers like: - Outlook 2003 - Ipad - Iphone - spark https://sparkmailapp.com/ (iphone app) - Edison mail https://apps.apple.com/us/app/email-edison-mail/id922793622 (iphone app) - ... but not with: - Mutt - Thunderbird - Zimbra - Gmail First, a thing to keep in mind. Imapsync does not touch any byte of messages unless told to do so, for example with special and the rarely used options --regexmess or --pipemess. Messages on both parts should always be exactly identical because imapsync does a verbatim sync of all messages, by default. Now I explain the whole picture about dates of messages. There are several different dates attached to any message. First, there is the "Date:" header, which belongs to the message itself. You can see this "Date:" header line by asking "View->Message Source" in most email client software (Ctrl-u in Thunderbird). Most of the time, this "Date:" header date is set by the MUA, MUA stands for "Mail User Agent", the email software tool you use to write emails. The "Date:" header is required by the RFC822, as well as the "From:" header, the sender, so they should always be in any message. An MUA can be Outlook, Thunderbird, a webmail or Mutt etc. The "Date:" header is usually the date the message was last written or sent the first time, at the writer side. This "Date:" header line is never changed by any transfer or copy. If an email reader uses the "Date:" header for displaying the date of a message then no problem should arise. Another date is the "internal date". In IMAP, the internal date is handled by the imap server and normally it corresponds to the arrival date in the mailbox. This date is not part of the email message itself, it is a metadata kept by the imap server. The IMAP protocol allows the internal date to be set by an email IMAP client tool when a message is delivered by the imap APPEND command in a folder. This internal date can not be set otherwise, using the IMAP protocol. Plus, an APPEND command is done only once per message. If it is done twice, then two identical messages are now in the mailbox; we call them duplicates. Imapsync synchronizes these internal dates, by default, so internal dates on host2 should be the same as the internal dates on host1. If the internal dates are not identical, it means the destination server ignored the internal dates given by imapsync and decided to put its own, usually the current date and time of the transfer. Bad point for a perfect synchronization. If an email reader uses the internal date for displaying the date of a message then the sync date problem only occurs when the host2 imap server ignores the internal date given by imapsync during the APPEND imap command. It happens with some imap servers. Very bad luck. Back luck because it means you use both a bad email client with a bad imap server, in regard of this email message dates issue. There are also the "Received:" header lines. Each time a message travels a SMTP server, this one adds a "Received:" header line. Sometimes some email clients use the last "Received:" header date as the date of the message. And some IMAP servers software add a "Received:" line after and imap transfer. If those both conditions are met then the date displayed become the transfer date even if imapsync has done its best to keep all the dates synchronized. Bad luck again but this one is very rare. Solutions: a) Use another email client or configure it in order that it sorts messages by sent dates, the "Date:" header line. b) Use a imap server that respects the imap RFC and accepts the internal date set by imapsync. c) Try to understand why the email client software shows another date than the "Date:" header line. ======================================================================= Q. Is there a way to set any message with "Date: (Invalid)" to a valid one like "Date: Thu, 1 Jun 2017 23:59:59 +0000"? R. Yes, there is a way with option --regexmess First, let's select only messages with a buggy Date header: --search "HEADER Date Invalid" Second, let's change this line by a valid one, on windows: --regexmess "s{\A(.*?(?! ^$))^Date:\ \(Invalid\)(.*?)$}{$1Date: Thu, 1 Jun 2017 23:59:59 +0000}xms" on Unix (replaced enclosing double-quotes " by single quotes ' ): --regexmess 's{\A(.*?(?! ^$))^Date:\ \(Invalid\)(.*?)$}{$1Date: Thu, 1 Jun 2017 23:59:59 +0000}xms' ======================================================================= =======================================================================