diff --git a/mailsummary/GNUmakefile b/mailsummary/GNUmakefile new file mode 100644 index 0000000..a4ffb93 --- /dev/null +++ b/mailsummary/GNUmakefile @@ -0,0 +1,27 @@ +include GNUmakevars + +all: mailsummary + +clean: + rm -f mailsummary *.bak + +distclean: clean + rm -f customize + +install: $(BINDIR) $(BINDIR)/mailsummary + +%: %.pl customize + sh ./customize < $< > $@ + chmod +x $@ + +%: %.sh customize + sh ./customize < $< > $@ + chmod +x $@ + +customize: configure + sh ./configure + +$(BINDIR): + mkdir -p $@ + +include GNUmakerules diff --git a/mailsummary/configure b/mailsummary/configure new file mode 100755 index 0000000..36e6f61 --- /dev/null +++ b/mailsummary/configure @@ -0,0 +1,26 @@ +#!/bin/sh +# +echo "#!/bin/sh" > customize +echo "sed \\" > customize +chmod +x customize + +################################################################ +# find a working perl: +# +for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5 +do + if $i -e 'exit ($] < 5.000)' + then + echo $i works + perl="$i" + break + fi +done +if [ -z "$perl" ] +then + could not find a working perl command, sorry. + exit 1 +fi +echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize + + diff --git a/mailsummary/mailsummary.pl b/mailsummary/mailsummary.pl new file mode 100755 index 0000000..de51476 --- /dev/null +++ b/mailsummary/mailsummary.pl @@ -0,0 +1,85 @@ +#!@@@perl@@@ + +%mon2num = ( + Jan => 1, + Feb => 2, + Mar => 3, + Apr => 4, + May => 5, + Jun => 6, + Jul => 7, + Aug => 8, + Sep => 9, + Oct => 10, + Nov => 11, + Dec => 12 +); +$header = 0; + +foreach $f (@ARGV) { + if (!open(F, $f)) {next}; + $header = 1; + $from = ""; + $date = ""; + $subject = ""; + $to = ""; + + while () { + if (/^From ([^ ]*) /) { + $from = $1; + $header = 1; + if (/ + (?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s)? + (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s + ([0-9]?[0-9])\s + ([0-9]?[0-9]:[0-9][0-9]:[0-9][0-9])\s + (19[0-9][0-9]) + /x) { + $date = sprintf("%04d-%02d-%02d %8s", $4, $mon2num{$1}, $2, $3); + } else { + $date = "XXXX-XX-XX XX:XX:XX"; + } + } elsif ($header && /^Date:/) { + # Thu, 22 May 1997 16:49:23 +0200 + if (/^Date:\s+ + (?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s+)? + ([0-9]?[0-9])\s + (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s + (19[0-9][0-9])\s+ + ([0-9]?[0-9]:[0-9][0-9]:[0-9][0-9])/x) { + $date = sprintf("%04d-%02d-%02d %8s", $3, $mon2num{$2}, $1, $4); + } elsif (/^Date:\s+ + (?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s+)? + ([0-9]?[0-9])\s + (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s + ([7-9][0-9])\s+ + ([0-9]?[0-9]:[0-9][0-9]:[0-9][0-9])/x) { + $date = sprintf("%04d-%02d-%02d %8s", 1900 + $3, $mon2num{$2}, $1, $4); + } else { + print "bad date: $_\n"; + } + } elsif ($header && /^To:/) { + if (/^To:\s+(.*)/) { + $to = $1; + } else { + print "bad to: $_\n"; + } + } elsif ($header && /^Subject:/) { + if (/^Subject:\s+(.*)/) { + $subject = $1; + } else { + print "bad subject: $_\n"; + } + } elsif ($header && /^From:/) { + if (/^From:\s+(.*)/) { + $from = $1; + } else { + print "bad from: $_\n"; + } + } elsif ($header && /^$/) { + print "$date\t$f\t$from\t$to\t$subject\n"; + $header=0; + } + } + close(F); +}