mail.app shows the wrong date for emails

I have a very long history of emails 30+ years. Some of my old emails are showed with the wrong date in mail.app.

Example:

These are the headers after anonymizing the data:

Received: from speedy.grolier.fr (speedy.grolier.fr [194.158.97.87]) by ns.calvacom.fr (8.7.3/8.6.9) with ESMTP id OAA21857 for <*@*>; Fri, 6 Sep 1996 14:02:35 +0200 (MET DST)
Received: from *.club-internet.fr (ppp-207-54.neuilly.club-internet.fr [194.117.207.54]) by speedy.grolier.fr (8.7.5/MGC-960516) with ESMTP id OAA16943 for <*@*>; Fri, 6 Sep 1996 14:00:14 +0200 (MET DST)
X-UIDL: 842012897.000
Message-Id: <*@speedy.grolier.fr>
From: "*" <*@*>
To: "*" <*@*>
Subject: Re: Faites-vous connaitre
Date: Fri, 6 Sep 1996 13:56:38 +0200
X-MSMail-Priority: Normal
X-Priority: 3
X-Mailer: Microsoft Internet Mail 4.70.1132
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"

below the body of the email.

So we can see that

  1. Received: has Fri, 6 Sep 1996 14:02:35 +0200 (MET DST) and Fri, 6 Sep 1996 14:00:14 +0200 (MET DST)
  2. Date: has Fri, 6 Sep 1996 13:56:38 +0200

The displayed date is email.app rendering

So I checked with mdls

mdls  ~/Library/Mail/path_to_email/857941.emlx | grep -i date
kMDItemFSContentChangeDate = 2020-10-02 02:10:10 +0000
kMDItemFSCreationDate      = 2015-10-13 04:27:22 +0000

no useful data about the email itself. Let's check with mdimport

mdimport -t -d3  ~/Library/Mail/path_to_email/857941.emlx | grep -i date
    "_kMDItemContentChangeDate" = "2020-10-02 02:10:10 +0000";
    "_kMDItemCreationDate" = "2015-10-13 04:27:22 +0000";
    "_kMDItemExpirationDate" = "<null>";
    "com_apple_mail_dateLastViewed" = "2020-10-02 02:10:10 +0000";
    "com_apple_mail_dateReceived" = "2005-07-16 15:58:43 +0000";
    kMDItemContentCreationDate = "1996-09-06 11:56:38 +0000";
    kMDItemContentModificationDate = "2020-10-02 02:10:10 +0000";
    kMDItemDateAdded = "2020-10-02 02:10:11 +0000";
    kMDItemLastUsedDate = "2020-10-02 02:10:10 +0000";
    kMDItemTextContent = " cut the body of email ";

So I can see that "com_apple_mail_dateReceived" = "2005-07-16 15:58:43 +0000"; is the date retained by mail.app to display the date in the UI.

Now I'm trying to understand how to change that.

Even after doing a mdimport -i ~/Library/Mail/path_to_email/857941.emlx, the date doesn't change in com_apple_mail_dateReceived.

I'm testing on this mail, but I have thousands of emails in the same state with the wrong com_apple_mail_dateReceived.

Update

Using Catalina, the emlx files do not help anymore because the mails are now in a private DB. The issue now is how to change the metadata contained in this DB when they are wrong.

Update 2

Ok I probably understood where the wrong date is coming from. In the emlx file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>conversation-id</key>
    <integer>378100</integer>
    <key>date-last-viewed</key>
    <integer>1601614618</integer>
    <key>date-received</key>
    <integer>1121529523</integer>
    <key>flags</key>
    <integer>9160621057</integer>
    <key>remote-id</key>
    <string>21</string>
</dict>
</plist>

Then let's try to convert the Epoch date to a normal date.

% date -r 1121529523
Dim 17 jul 2005 00:58:43 JST

So now, we need to figure out if we change the date of the emlx file and try to reimport it, if it fixes the DB.


So… it almost looks like a bug from Mail.app

I tried to modify manually the file to have the right date in the plist and with the right content-size at the top. And the new import converted it back to the date of 2005. I sent a bug report to Apple about it.