
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:
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”);
next;
}
process( $arg );
}
sub process
{
my $file = shift @_;
print “Processing $file “;
my $parser = new MIME::Parser;
$parser->output_under(“/var/tmp”);
$parser->output_prefix(“msg”);
$parser->extract_nested_messages(0);
$parser->decode_bodies(0);
my $entity = $parser->parse_open( $file );
my $header = $entity->head;
my $date = $header->get(‘Date’);
chomp($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” );
}
else
{
print( “failed.\n” );
}
}
exit(0);
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 maildatefix.pl commend “Argument list too long,” please modify your statement to this [find . -name '*' -print0 | sudo xargs -0 maidatefix.pl] without the brackets.