mail-uplift fix regex
[ipreg/sccs2rcs2cvs2git.git] / ipreg-mail-uplift
1 #!/usr/bin/perl
2
3 # reformat from MH to mbox
4
5 use warnings;
6 use strict;
7
8 sub shite { die "ipreg-mail-uplift: @_: $!\n"; }
9 sub shit { die "ipreg-mail-uplift: @_\n"; }
10
11 my $mailbox = qr{(?:ip-reg/)?(?:inbox|hostmaster|misc|pending|z|
12 latin-american|mail/support|
13 ipreg/inbox|pending/ip-reg|ip-reg):\d+}x;
14
15 for my $f (<ipreg-mail/Institutions/*>) {
16 next unless -f $f;
17 next if $f =~ m{\.new$};
18 print "processing $f\n";
19 open my $in, '<', $f
20 or shite "open < $f";
21 my @f = <$in>;
22 for (my $i = 0; $i < @f; $i++) {
23 if ($f[$i] =~ s{
24 ^(?:[+][+][+]|From)\s+
25 ([a-z]+[0-9]*[ ] # user
26 [A-Z][a-z][a-z][ ] # day
27 [A-Z][a-z][a-z])\s+ # mon
28 ([0-9]+)\s+ # date
29 ([0-9][0-9]:[0-9][0-9]:[0-9][0-9][ ] # time
30 [A-Z][A-Z][A-Z][ ] # zone
31 [12][0-9][0-9][0-9])\s*$ # year
32 }{sprintf "From %s %2d %s\n", $1, $2, $3}xe) {
33 splice @f, $i++, 0, "\n" if $i > 0 && $f[$i] !~ m{^\n$};
34 my $j = $i + 1;
35 $j++ while $f[$j] =~ m{^$|^From |^[(]Message $mailbox[)]$|^>>> $mailbox$};
36 splice @f, $i + 1, $j - $i - 1;
37 } else {
38 $f[$i] =~ s{^From }{>From };
39 }
40 }
41 open my $out, '>', "$f.new"
42 or shite "open > $f.new";
43 print $out @f;
44 }