M
Mike James
Hi, I'm working with some code I copied from here:
http://www.usethesource.com/articles/02/06/17/1957223.shtml
My system: WinXP Home, ActiveState Perl 5.6.1, operated by Perl newbie...
The script is supposed to descend into sub-folders, read *.eml messages,
then concatenate them into .mbox files. The problem is that the script
doesn't descend into the sub-folders. Instead, it only operates on the
files (and folders) in the folder where the script is located.
Here's the script for convert.pl:
sub convert
{
my ($file) = @_;
my $from = '';
my $date = '';
my $message = '';
my $stop_looking = 0;
open OE, "<$file";
while ()
{
my $line;
chomp;
$line = $_;
$message .= $_ . "\n";
if ( $stop_looking == 0 )
{
if ( $line =~ /(From:.*\<(.*)\>)/ )
{
$from = $2;
}
else
{
if ( $line =~ /(From: ([^\<]*))/ )
{
$from = $2;
}
}
if ( $line =~ /Date: (.*)/ )
{
$date = $1;
if ( $date =~ /(\w{3}), (\d+) (\w{3}) (\d{4}) (\d\d:
\d\d:\d\d)/ )
{
my ($dow, $day, $month, $year, $time) = ($1,
$2,$3,$4,$5);
if ( $day =~ /0(\d)/ )
{
$day = " $1";
}
$date = "$dow $month $day $time $year";
}
}
if ( $line =~ /X-UIDL:/ )
{
$message = "\n\nFrom $from $date\n" . $message;
$stop_looking = 1;
}
}
}
close OE;
return $message;
}
sub convert_folder
{
my ($folder) = @_;
my @files = glob "$folder/*.eml";
open MBOX, ">$folder.mbox";
foreach my $file (@files)
{
print "File $file...\n";
print MBOX convert( $file );
}
close MBOX;
}
my @folders = glob '*';
foreach my $folder (@folders)
{
print "Converting $folder...\n";
convert_folder( $folder );
}
http://www.usethesource.com/articles/02/06/17/1957223.shtml
My system: WinXP Home, ActiveState Perl 5.6.1, operated by Perl newbie...
The script is supposed to descend into sub-folders, read *.eml messages,
then concatenate them into .mbox files. The problem is that the script
doesn't descend into the sub-folders. Instead, it only operates on the
files (and folders) in the folder where the script is located.
Here's the script for convert.pl:
sub convert
{
my ($file) = @_;
my $from = '';
my $date = '';
my $message = '';
my $stop_looking = 0;
open OE, "<$file";
while ()
{
my $line;
chomp;
$line = $_;
$message .= $_ . "\n";
if ( $stop_looking == 0 )
{
if ( $line =~ /(From:.*\<(.*)\>)/ )
{
$from = $2;
}
else
{
if ( $line =~ /(From: ([^\<]*))/ )
{
$from = $2;
}
}
if ( $line =~ /Date: (.*)/ )
{
$date = $1;
if ( $date =~ /(\w{3}), (\d+) (\w{3}) (\d{4}) (\d\d:
\d\d:\d\d)/ )
{
my ($dow, $day, $month, $year, $time) = ($1,
$2,$3,$4,$5);
if ( $day =~ /0(\d)/ )
{
$day = " $1";
}
$date = "$dow $month $day $time $year";
}
}
if ( $line =~ /X-UIDL:/ )
{
$message = "\n\nFrom $from $date\n" . $message;
$stop_looking = 1;
}
}
}
close OE;
return $message;
}
sub convert_folder
{
my ($folder) = @_;
my @files = glob "$folder/*.eml";
open MBOX, ">$folder.mbox";
foreach my $file (@files)
{
print "File $file...\n";
print MBOX convert( $file );
}
close MBOX;
}
my @folders = glob '*';
foreach my $folder (@folders)
{
print "Converting $folder...\n";
convert_folder( $folder );
}