convert .eml to .mbox in win32

Discussion in 'Perl Misc' started by Mike James, Sep 20, 2003.

  1. Mike James

    Mike James Guest

    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 );
    }
     
    Mike James, Sep 20, 2003
    #1
    1. Advertisements


  2. You can just drag and drop EML files directly into Thunderbird no
    problem-o. Thunderbird could always import from Outlook and
    OutlookExpress with no addons required, not sure about Windows Live
    Mail, but if you export as EML Thunderbird has no problem with that
    filetype.
     
    Jonathan N. Little, Jun 10, 2014
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.