Incorrect Received Date

Incorrect Received Date

8 Comments 🕔16:16, 25.Oct 2009

Recently, we upgraded one of our internal Mac servers from 10.5.8 to Snow Leopard. While on the surface, this upgrade seemed to have successfully completed, users started experiencing strange issues with mail items; specifically, with the Apple Mail client and messages showing a received date of 11/26/2020.

Our stellar IT staff investigated this, and determined that it somewhere during the upgrade our mail store became corrupt. This corruption specifically happened when Snow Leopard began upgrading mail to the dovecot system. Our engineers contacted Apple, but unfortunately, they were unable to assist and needed to escalate our trouble ticket to advanced server support with a turnaround time of three to four business days. Completely unacceptable in my book, but luckily, one our engineers was able to find a great post in the Apple Support Discussion Forums.

In the interest of assisting others with this possible problem, I have posted what our engineers deemed the best method for correcting the issue. Please note, this solution differs slightly from the support discussion page as we have tens of thousands of email messages in each subfolder; therefore, there is an extra command that needs to be run to avoid the dreaded “Argument list too long” error message from the terminal.

Follow the steps below in order:

  1. Download and install xcode onto the server in question
  2. From the terminal:
    perl -MCPAN -e shell
    install File::Touch
  3. Stop mail service
  4. Save the following script to a file titled “”

    use strict;
    use warnings;
    use MIME::Parser;
    use MIME::Entity;
    use MIME::Body;
    use Date::Parse;
    use File::Touch;
    if( !@ARGV )
    die( “No arguments provided.\n” );

    if( !-d( “/var/tmp/set_date” ) )
    system( “mkdir /var/tmp/set_date” );

    foreach my $arg ( @ARGV )
    if(!-e $arg || !-f $arg)
    print( STDERR “File $arg not found or not a file\n”);
    process( $arg );

    sub process
    my $file = shift @_;
    print “Processing $file “;
    my $parser = new MIME::Parser;
    my $entity = $parser->parse_open( $file );
    my $header = $entity->head;
    my $date = $header->get(‘Date’);
    print(“with date $date… “);
    my $time = str2time($date);
    my $touch = File::Touch->new(mtime => $time, no_create => 1);
    if( $touch->touch( $file ) )
    print( “ok\n” );
    print( “failed.\n” );


  5. Save the aforementioned file on the server to /bin/
  6. chmod 775 /bin/
  7. cd /var/spool/imap/dovecot/mail/USERS MAIL DIR/cur/
  8. sudo *
  9. cd ..
    sudo rm dovecot.index*
    sudo rm subscri*
  10. cd .Sent\ Items/cur/
    repeat steps 7 and 8 for each mailbox in the directory (.Sent Items, .Drafts, etc…)
  11. Repeat steps 6 through 9 for all mail users
  12. Start Mail services

Please note: iPhone users may need to remove and re-add mail accounts to clear the cache of bad dates.

Now, in the event that you receive the following error in terminal when executing the commend “Argument list too long,” please modify your statement to this [find . -name ‘*’ -print0 | sudo xargs -0] without the brackets.


  1. 🕔 9:36, 20.Jan 2010

    Luis Rojas


    This is a great article, but is there a solution that does not involve the following:

    perl -MCPAN -e shell
    install File::Touch

    the reason i ask, is because currently i can’t have the server connected to the net and thus i cant install something that gets pulled… is there another way to update CPAN or install this component without using the internet?

  2. 🕔 10:30, 20.Jan 2010

    VG_Labs Author

    You can always download the module from another machine and install on the server, however, you always run the risk of dependency hell.

    Touch is only needed if you have many, many files you are looking to change the date on. The perl script is there to automate the process. In our example, we had over 10,000 messages needing to be repaired. If you only have a few, you could easily run the script manually for each mail item.

  3. 🕔 14:23, 20.Jan 2010

    Luis Rojas

    I have over 5 years of email waiting to be fixed, perhaps i will replace Touch with SetFile -m

  4. 🕔 14:34, 20.Jan 2010

    VG_Labs Author

    SetFile -m may work, but I suggest if you haven’t already done so, taking a look at the Discussion Thread on Apple’s site about this very problem. It can be found here:

    If you need additional assistance, let us know.

  5. 🕔 6:19, 01.Feb 2010


    We have experienced this problem as well but I note that the dates in squirrel mail are fine.

  6. 🕔 20:34, 01.Feb 2010

    VG_Labs Author

    Yes, this is true. Both SquirrelMail and RoundCube show the correct dates. In fact, Mozilla Thunderbird will show the correct received dates as well. Another possible solution is to move the messages to a local folder in Thunderbird and then move the back to the IMAP folder on the server, however, while this solution has worked for us in the past, it did not work in this particular situation. Thanks for additional info! ~VGLabs

  7. 🕔 4:49, 14.Jun 2010

    Car radio install

    Great article Thank you so much!

  8. 🕔 4:20, 11.Sep 2010

    visitor analytics

    intruiging article.. I like your perspective on this subject. Although there are a few points I diverge on I think you did a great job purposing your review. GJ.

Write a Comment 

Your email address will not be published. Required fields are marked *