我正在使用Mail::POP3Client的简单性,并希望提取最新n
消息的标题(我的代码中为 5)。这将是一个网页脚本,并在页面加载时下载并解析了最新的 5 封电子邮件(他们的主题和发件人)但是现在我从 7 月收到一些各种各样的电子邮件,而不是我最近的 5 封电子邮件(我在 7 月之前有很多电子邮件以及)。显然my $email_count = $pop->Count;
只是计数而不是索引类型的值?
for (my $i = $email_count; $i >= $email_count-5; $i--) {
foreach ($pop->Head($i)) {
if (/^(From):\s+/i) { $FROM = $_; }
if (/^(Subject):\s+/i) { $SUBJECT = $_; }
if (/^(Date):\s+/i) {
$TIME = $_;
$TIME =~ s/Date: (.*)/$1/;
my $tstamp = str2time($TIME);
# $TIME = $tstamp;
$TIME = scalar localtime($tstamp);
my @fromsubj;
$fromsubj[0] = $FROM;
$fromsubj[1] = $SUBJECT;
$subject{$TIME} = [@fromsubj];
}
}
print "Index: $i \n";
}
print Dumper(%subject);
print "\n";
print Dumper(%from);
print "Mails $email_count to ".($email_count-5);
输出:
Index: 4030
Index: 4029
Index: 4028
Index: 4027
Index: 4026
Index: 4025
$VAR1 = 'Thu Jul 26 09:01:07 2012';
$VAR2 = [
'From: Person one ',
'Subject: Fwd: test '
];
$VAR3 = 'Tue Jul 24 15:09:43 2012';
$VAR4 = [
'From: person two ',
'Subject: subj '
];
(And so on)
....
Count 4030 4020
我怎样才能只提取最新的电子邮件?POP/this 模块是否有可能,如果不是,我可以使用什么来代替?