#!/usr/bin/perl -w
#
# msgconvert:
#
# Convert .MSG files (made by Outlook (Express)) to multipart MIME messages.
#
use Email::Outlook::Message;
use Email::Sender::Transport::Mbox;
use Getopt::Long;
use Pod::Usage;
use File::Basename;
use vars qw($VERSION);
$VERSION = "0.904";
# Setup command line processing.
my $verbose = '';
my $mboxfile = '';
my $help = ''; # Print help message and exit.
GetOptions(
'mbox=s' => \$mboxfile,
'verbose' => \$verbose,
'help|?' => \$help) or pod2usage(2);
pod2usage(1) if $help;
# Check file names
defined $ARGV[0] or pod2usage(2);
my $using_mbox = $mboxfile ne '';
my $transport;
if ($using_mbox) {
$transport = Email::Sender::Transport::Mbox->new({ filename => $mboxfile });
}
foreach my $file (@ARGV) {
my $msg = new Email::Outlook::Message($file, $verbose);
my $mail = $msg->to_email_mime;
if ($using_mbox) {
$transport->send($mail->as_string, { from => $mail->header('From') || '' });
} else {
my $basename = fileparse($file, qr/\.msg/i);
my $outfile = "$basename.eml";
open OUT, ">:utf8", $outfile
or die "Can't open $outfile for writing: $!";
binmode(OUT, ":utf8");
print OUT $mail->as_string;
close OUT;
}
}
阅读(742) | 评论(0) | 转发(0) |