Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
get & store all attachments in a mailbox directory
#!/usr/bin/perl -w
use strict;
use Mail::MboxParser;
use constant MAILBOX_DIR => "/var/mail/mymailboxdir";
use constant STORAGE_DIR => "/data";
if ( -z MAILBOX_DIR ) {
print STDERR "no mail.\n";
exit;
}
my $mb = Mail::MboxParser->new( MAILBOX_DIR, decode => 'ALL' );
print `date`;
my $msgnum = 1;
for my $msg ($mb->get_messages) {
print "\nmessage: $msgnum ";
$msgnum++;
print $msg->header->{subject} if defined $msg->header->{subject};
print "\n";
my $mapping = $msg->get_attachments;
for my $filename (keys %$mapping) {
print " * storing $filename ...\n";
$msg->store_attachment( $mapping->{$filename},
path => STORAGE_DIR )
}
}
print "\n-----------------------------\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.