#! /usr/bin/perl # # ezmlm-to-mbox # use Date::Parse; use Date::Format; use strict; use warnings; my $state = 3; my $body = 0; my ($line, $msg, $timestr); while ($line = <>) { if ($state == 3 && $line =~ /^From qmail-return-\@list.cr.yp.to/) { $state = 1; next; } if ($state == 1) { if ($line =~ /^> /) { $state = 2; } else { next; } } if ($state == 2) { if (!$body && $line eq "> \n") { $body = 1; } if ($line =~ /^$/) { $state = 3; $body = 0; next; } elsif (!$body && $line =~ /^> Date: (.*)$/) { $timestr = ctime(str2time($1), "GMT"); } elsif ($body && $line =~ /^> >*From /) { $msg .= ">"; } $msg .= substr($line, 2); next; } if ($state == 3) { if ($line =~ /^To: qmail-get.(\d+)\@list.cr.yp.to$/) { print "From qmail\@list.cr.yp.to ", $timestr, $msg; $msg = ""; } next; } die "PARSE ERROR: $line\n"; } exit 0;