Subject: | threadStart() chokes on dummy messages in thread |
I can't rule out this is just because I'm using threadStart() in a wrong
way, but then my code works flawlessly on all but 2-3 out of 50.000
messages. From my glances at the module code, I'd say it should never
call $thread->message->timestamp on a Mail::Message::Dummy, but that's
exactly what seems to happen:
[15:47] newsadm@Trinidad:~/tmp/fschlich/mail__box/archivertest$
../archiver.pl archiver.mbox
DEBUG: 9e5625740808020105t7c05a7fm3ecff68b303fd392@mail.gmail.com
ERROR: You cannot take the head of a dummy message
Can't call method "recvstamp" on an undefined value at
/usr/share/perl5/Mail/Message.pm line 259, <GEN3> line 18 (#1)
(F) You used the syntax of a method call, but the slot filled by the
object reference or package name contains an undefined value. Something
like this will reproduce the error:
$BADREF = undef;
process $BADREF 1,2,3;
$BADREF->process(1,2,3);
Uncaught exception from user code:
Can't call method "recvstamp" on an undefined value at
/usr/share/perl5/Mail/Message.pm line 259, <GEN3> line 18.
Mail::Message::timestamp('Mail::Message::Dummy=HASH(0x8837878)')
called at /usr/share/perl5/Mail/Box/Thread/Manager.pm line 147
Mail::Box::Thread::Manager::threadStart('Mail::Box::Thread::Manager=HASH(0x87f5a88)',
'Mail::Box::Mbox::Message=HASH(0x87f31f4)') called at ../archiver.pl line 30
Please find my code (archiver.pl) and an mbox with a stripped-down
version of an offending message
(archiver.mbox) attached.
Florian
Subject: | archiver.mbox |
Message body not shown because it is not plain text.
Subject: | archiver.pl |
#!/usr/bin/perl -w
use Mail::Box::Manager;
use strict;
use diagnostics;
# archiver.pl
# walks over new messages, and if a tag can be identified, archive the whole thread
$|=1;
my $seen_file = 'seen.mbox';
my $new_file = $ARGV[0];
(-s $new_file) || die "can't find $new_file -- is it an mbox?\n";
my $mgr = Mail::Box::Manager->new;
my $seen_folder = $mgr->open(folder => $seen_file, access => 'rw', create => 1) or die "cannot open folder $seen_file: $!\n";
my $new_folder = $mgr->open(folder => $new_file, access => 'rw') or die "cannot open folder $new_file: $!\n";
my $threads = $mgr->threads(folders => [$seen_folder,$new_folder]);
# examine new mail in turn
foreach my $newmsg ($new_folder->messages) {
next if $newmsg->isDeleted or $newmsg->isDummy;
print "DEBUG: ", $newmsg->messageId, "\n";
# find the start of the thread this new message is in
my $threadstart = $threads->threadStart($newmsg);
print "DEBUG: ...not reached...\n";
# take alle messages in thread
my @thread = $threadstart->threadMessages;
my %tags = ();
# examine thread starting from last message
while (my $msg = pop @thread) {
my $subject = $msg->head->study('subject');
if ($subject) { # spam might not have a subject...
$subject = $subject->decodedBody(); # ?iso-88..? in subject...
while ($subject =~ /\[(\d+)\]/g) {
$tags{$1} = 1;
}
#...
}
# test BODY
# ...
# stop if we've found a tag
last if (scalar keys %tags);
}
# save result
}