重build信使文件

我运行一个邮件服务器,我有快递imap和pop3运行。 最近我把我的机器上的一些本地信息(以前用pop3下载)移动到服务器上,所以我可以使用imap。 我在Mac OS X 10.5.8上使用Mail.app来做到这一点。

这导致邮件服务器上的一系列文件如下所示:

1324697191.M91227P15574V000000000000CA00I0004B07D_556.hostname,S=5622:2,S 1324697192.M322096P15574V000000000000CA00I0004B07F_557.hostname,S=225691:2,RS 1324697196.M144018P15574V000000000000CA00I0004B081_558.hostname,S=7702:2,RS 1324697197.M715598P15574V000000000000CA00I0004B083_559.hostname,S=15741:2,S 1324697199.M327587P15574V000000000000CA00I0004B085_560.hostname,S=8744:2,RS 

这些消息的接收时间与上面列出的顺序相同:

 01/15/2010 01/09/2009 07/13/2010 02/21/2010 05/06/2010 

现在,这不是桌面邮件客户端的问题 – 他们只是获取所有消息,对它们进行sorting,一切都很好。 在这个主题上的几个谷歌search产生了线程,人们试图以正确的顺序得到他们的消息,并build议的补救措施是“在客户端sorting”。

不幸的是,在iOS 5.0.1上,邮件应用程序假定从imap服务器获得的消息的顺序已经按datesorting。 由于本示例中的消息具有与接收时间戳不匹配的文件名,而是其重新上传时间戳,这意味着消息在iOS设备上以错误的顺序出现。 为了解决这个问题,我必须通过点击“Load More Messages”button来加载所有的邮件。

我想简单地能够重build这些消息文件,使文件名中的时间戳(它看起来是时间段之前的第一组数字)匹配接收时间戳。 然后,他们会按照正确的顺序sorting,以便iOS设备尝试加载它们。 我不知道信使如何组织信息 – 我可以简单地写一个脚本来replace文件名中的第一组数字与消息接收时间的unix时间戳吗?

谢谢!

感谢@mailq。 事实certificate,除了在邮件文件名开头的时间戳之外,快递也会查看文件本身的修改时间戳。 我也必须将其设置为收到的时间戳。

这里有一个脚本,给定一堆消息,在重写文件名和修改时间以包含接收时间戳之后,将它们复制到输出目录。

 #!/usr/bin/env perl use Email::Simple; use Date::Parse; use Getopt::Long; use File::Path qw(make_path); use File::Copy qw(copy); use File::stat; my $outfolder = ""; $result = GetOptions("output-dir=s" => \$outfolder); # create directories if needed if (length($outfolder) > 0) { make_path($outfolder); } foreach my $file (@ARGV) { my $text = ""; # read file as one string { local $/=undef; open FILE, "$file" or die "Couldn't open file: $!"; binmode FILE; $text = <FILE>; close FILE; } # use Email::Simple to parse the Received header my $email = Email::Simple->new($text); my @received = $email->header("Received"); # Find the latest receive time my $latestTime = 0; my $latestTimeStr = ""; foreach my $r (@received) { if ($r =~ /[^;]*;(.*)$/) { my $time = str2time($1); if ($time > $latestTime) { $latestTime = $time; $latestTimeStr = $1; } } } # if this is a sent message, it doesn't have a received header. Use the # Date header instead. if ($latestTime == 0) { my $date = $email->header("Date"); my $time = str2time($date); if ($time > $latestTime) { $latestTime = $time; $latestTimeStr = $date; } } # If we found one, rename or tell about the rename if ($latestTime != 0) { if ($file =~ /([0-9]*)(\..*$)/) { my $newfilename = $latestTime . $2; if (length($outfolder) == 0) { print "Would Copy $file ($latestTimeStr) -> \n "; print "$newfilename\n"; } else { print "Copied $file ($latestTimeStr) -> \n "; print "$outfolder/$newfilename\n"; # use the latest received timestamp as the atime and mtime copy($file, "$outfolder/$newfilename"); utime($latestTime, $latestTime, "$outfolder/$newfilename"); } } } else { print "Couldn't find receive time for " . $file . "\n"; } } 

使用这样的脚本:

 perl rename.pl cur/* 

当你确信它会做正确的事情:

 perl rename.pl cur/* --output-dir cur_renamed 

那么你只需要将cur_renamedcur交换,删除你的courierimapuiddb文件,并可能重新启动你的电子邮件客户端。 对于我的iOS设备,我不得不删除邮件帐户,然后与iTunes重新同步以使其正确清除caching。