tags:

views:

34

answers:

1

I'm using the Perl module Mail::Box::Manager to read messages from a Maildir and move them into another directory. Once the script has finishing processing the mail messages in the Maildir it appears to also remove the cur/ and new/ Maildir directories and the Maildir files/directories need to be recreated.

I don't want the script removing the folders and having to recreate the Maildir structure.

I have something simple like:

#!/usr/bin/perl
use Mail::Box::Manager;

my $cnt = 0;
my $mgr = Mail::Box::Manager->new;
my $folder = $mgr->open( folder => '/home/vmail/mailfolder/',
                     access => 'rw',
                     type => 'maildir',
                     log => 'DEBUG',
                    );

foreach my $msg ( $folder->messages ) {
    # ... doing some processing of $msg here, then, move the mail for storage

    my $filename = $msg->filename || "NA";
    $filename =~ m#(.*)/new/(.*)$#;

    $mgr->moveMessage("/dir/$filename", 
                      $folder->message($cnt), 
                      create => 1 );
    $cnt++;
}

$folder->close();

Any suggestions greatly received. Thanks.

+5  A: 

Add

remove_when_empty => 0,

to the $mgr->open call.

cjm
Thanks, worked a treat.
Imo
Am I missing something or is that undocumented? I didn't see it under the options for open().
brian d foy
@brian d foy, the docs for `open` say "For a description of the folder options, see the options to the constructor [Mail::Box::new()](http://search.cpan.org/perldoc?Mail::Box#Constructors) for each type of mail box." `remove_when_empty` is described there.
cjm