monsieur_champs has asked for the wisdom of the Perl Monks concerning the following question:


I'm working for a client that asked me to build something he can use to inspect a catch-all mailbox at his ISP linux box. My client is an organized and clever half-techie that understands little about perl and a lot about linux. He is using Debian stable distro, with perl 5.6.1 and a bunch of libs that I've asked him to install for my use.


I've choosen Mail::Box because of its stability and powerfull control and broad range of supported formats.

At development, everything goes fine, and Mail::Box::Manager uses Mail::Box::Maildir and Mail::Box::Message to create me an ideal world where all works as expected: messages go back and forth, and I can see and handle all requirements.

Production Hell

Things change a lot at production (I have little access to production, so please take it easy! -- this is a business requirement from my client). The same program that works at my development environment and performs quite well fails miserably when facing the 30_000 (yes, that's four zeros on the right hand) messages on a single maildir folder. My main problem is that I don't have a formal failure: Mail::Box just leave open() telling everybody that there is no messages at this maildir folder(?!?!). I'm really confused about this error and can't figure out a good way to tell if I'm missing something really important or just need a good afternoon of debugging Perl internals.

I've wrote the following code to try to expose the fail. Hope I've setted all erros at the maximum noise level. Comments and related cases are welcome. My client will make tests in one or two days, and I will have more information to complement this post then.

#!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Pod::Usage; use Mail::Box::Manager; my $options; GetOptions( 'mail-folder=s' => \$options->{folder}, 'dump-subject=s' => \$options->{dumpfile}, ); pod2usage( -message => "$0: syntax error: pay attention!\n\n", -exitval => 1, -verbose => 1, # Give "Synopsis" and "Arguments" -filehandle => \*STDERR, ) unless( ( $options->{folder} and -d $options->{folder} ) # or # ( $options->{dumpfile} and -f $options->{dumpfile} ) ); my $manager = new Mail::Box::Manager; my $folder; eval{ $folder = $manager->open( folder => $options->{folder}, create => 0, access => 'r', type => 'maildir', expand => 'LAZY', log => 'DEBUG', # adds a lot of noise trace => 'DEBUG', # adds a lot of noise ); }; die "Error opening maildir [$options->{folder}]: '$@'\n\n" if $@; print qq{Folder [} . $folder->name . qq{] aberto com [} . scalar @$folder . qq{] mensagens.\n\n}; if( $options->{dumpfile} ){ open DUMP, '>', $options->{dumpfile} or pod2usage( -message => qq{Can't create dumpfile: $!\n\n}, -exitval => 2, -verbose => 1, -filehandle => \*STDERR ); print( DUMP $_->subject(), $/ ) foreach @$folder; close DUMP or die qq{Can't close(!?!) dumpfile $options->{dumpfile}\n\n}; } # fi eval{ $folder->close }; die "Error closing maildir [".$folder->name."]: '$@'.\n\n" if $@; __END__ =pod =head1 NAME mail-box-test - Simple test to see if Mail::Box::Maildir is working +correctly. =head1 SYNOPSIS perl mail-box-test --mail-folder='/path/to/mail/dir/' [--dump-subjec +t=/path/to/subjects.txt] =head1 ARGUMENTS =over 4 =item --mail-folder <FOLDER> Points to the maildir you want to use for testing. No maildir means test failure, so please choose a maildir to test. =item --dump-subject <DUMPFILE> Force dumping of subject lines of a maildir to a specified file on the disk. =back =head1 DESCRIPTION This script tests a Mail::Box resource usage under linux for a client. I'm facing a funny problem when trying to open maildirs with more than 21,000 messages in it: Mail::Box is telling me its opening the maildir correctly but no messages are found inside it. =head1 AUTHOR Luis Campos de Carvalho, a.k.a. Monsieur Champs. mailto: monsieur_champs [at] yahoo [dot] com [dot] br =cut