Perl question
Martin Duclos
tchitow-PkbjNfxxIARBDgjK7y7TUQ at public.gmane.org
Sun Apr 3 20:45:22 UTC 2005
Hi all,
I know this is a little off topic but I could sure use some help with this.
I'm trying to take mail messages and parse them one by one form different
mailboxes. The mail message are all individual message in
/home/user/Maildir. I want to load the message and then extract all the
attachments from it to drop them to a directory. What I have to far is
below. I always get an number of attachments of zero while there are in fact
multiple attachments in each message. Any ideas would be greatly
appreceated.
Martin
#!/usr/bin/perl
use strict;
use Mail::Audit qw(Attach);
my($srcDir) = "./src";
my($destDir) = "./dest";
my($trash) = "./trash";
#sanity check and create if not exist
die "Source directory isn't valid!" unless -d $srcDir;
mkdir( $destDir, 0755 ) unless( -d $destDir );
mkdir( $trash, 0755 ) unless( -d $trash );
my(@allFiles) = <$srcDir/*>;
foreach( @allFiles ){
if( -f $_){
print "Processing file $_\n";
open FILE, $_ or die "Can't open file $_. $!.";
my(@fileContents);
while(<FILE>){
chomp;
push( @fileContents, $_ );
}
foreach( @fileContents ){
print $_;
}
my($mail) = Mail::Audit->new(data=>\@fileContents);
print $mail->num_attachments . "\n";
my($attachments) = $mail->attachments;
foreach( @$attachments){
$_->save($destDir);
}
}
}
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list