1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#!/usr/bin/perl -T
# On Windows, the test mailbox must be have lines which are
# separated by CRLFs. The mbox.src which is supplied is UNIX-style,
# so only has LF line-terminations. In this script, this is
# translated. The Content-Length of the messages is updated too.
use strict;
use warnings;
use lib qw(. .. tests);
use Tools;
use Test::More tests => 1;
use FileHandle;
my $crlf = "\015\012";
open SRC, '<', $unixsrc or die "Cannot open $unixsrc to read: $!\n";
binmode SRC;
open DEST, '>', $winsrc or die "Cannot open $winsrc for writing: $!\n";
select DEST;
binmode DEST;
until(eof SRC)
{
my ($lines, $bytes);
HEADER:
while(<SRC>)
{ s/[\012\015]*$/$crlf/;
if( m/^Content-Length\: / ) {$bytes = $' +0}
elsif( m/^Lines\: / ) {$lines = $' +0}
elsif( m/^\s*$/ )
{ # End of header
if(defined $bytes && defined $lines)
{ $bytes += $lines;
print "Content-Length: $bytes\015\012";
}
print "Lines: $lines$crlf"
if defined $lines;
print $crlf;
last HEADER;
}
else {print}
}
BODY:
while(<SRC>)
{ s/[\012\015]*$/$crlf/;
print;
last BODY if m/^From /;
}
}
die "Errors in reading $unixsrc" unless close SRC;
die "Errors in writing $winsrc" unless close DEST;
pass("Folder conversion complete");
|