#!/usr/bin/perl -w # Usage: md2mb.pl input_maildir output_mbox # # An example: # mkdir ~/mbox # md2mb.pl ~/mail/Sent ~/mbox/Sent # # (c) Iain Cuthbertson 2005 my $input_maildir = $ARGV[0]; my $output_mbox = $ARGV[1]; opendir(MAILDIR, "$input_maildir/cur") || die("Could not open $input_maildir/cur"); my @mail_files = grep {!(/^\.\.?$/) && -f "$input_maildir/cur/$_"} readdir(MAILDIR); rewinddir(MAILDIR); close(MAILDIR); open(MBOX, ">>$output_mbox") || die("Could not open $output_mbox for writing"); foreach my $file (sort @mail_files) { my $working_file = "$input_maildir/cur/$file"; open(MAILFILE, "$working_file") || die("Could not open $working_file"); @mailfile = ; close(MAILFILE); my $email = "postmaster"; my $date = "Wed Apr 20 22:21:51 2005"; print MBOX "From $email $date\n"; foreach $mbox_line (@mailfile) { print MBOX $mbox_line; } } close(MBOX);