#!/usr/bin/perl # # Crude archive converter from Majordomo to Sympa # requires an argument: the path to the Majordomo list archive directory # creates the Sympa compatible log.* files # written by Petr Prazak # 23/10/2001 : [Mathieu Peltier] Fixed typo ($mailcout) use File::Find; my $separator = "\n------- CUT --- CUT\n\n"; my $header = "\n------- THIS IS A RFC934 COMPLIANT DIGEST\n\n"; my $outdir = ""; my $total = 0; #total converted messages my $arg = $ARGV[0]; if (-d $arg) { print "Processing the directory $arg\n"; my $pth = $arg . "/*"; @filelist = glob($pth); foreach $file ( @filelist ) { next if ($file =~ /^\./); process_file($file) if ( -f $file && -r $file) ; } print "\nConverted $total messages in total.\n"; } elsif (-r $arg) { process_file($arg); } else { print STDERR "Bad argument $arg, not a file or directory\n"; } sub process_file { my $mj_file = shift; my $year, $month, $list; $mj_file =~ /^(.+)\.(\d+)(\d\d)$/ || die "The filename $mj_file is not in the expected format" ; $list = $1; $year = $2; if ($year < 100) { # two digit format $year += ($year > 50)? 1900: 2000; } $month = $3; $list =~ s/(.*)\/(.+)/\2/; my $outfile = $outdir . "log.$year$month"; print "Converting Majordomo archive for the list $list, year $year, month $month "; print "to the file $outfile\n"; open FH, "<$mj_file" || die "Cannot open $mj_file: $!"; open OUT, ">$outfile" || die "Cannot create output file $outfile: $!"; print OUT $header; my $first = 0; my $mailcount = 0; while() { if (/^From /) { if ($first) { print OUT $separator; } else { $first = 1; } ++$mailcount; } print OUT $_; } close FH; print OUT $separator if ($mailcount > 0); close OUT; $total += $mailcount; print "Converted $mailcount messages.\n"; }