#!/usr/local/bin/perl # Edit above path to point to where perl is on your system. # # Wrapper for MHonArc to split mail archives into Year-Month directories ## Specify a package to protect variable names from MHonArc. package Run_MHonArc; ## Get name of list and path to mail file being processed from command line $list_name=$ARGV[0]; $mail_file=$ARGV[1]; if (!$list_name || !$mail_file) { print "usage: run_mhonarc.pl list_name full_mailfile_path\n"; } else { ## Edit to point at path to mhonarc $MHonArc = "/usr/local/bin/mhonarc"; ## Edit to point at archive directory on your webserver $archive_root = "/usr/local/www/data/mail"; ## Date stuff for directory name may need to be adjusted for your ## local flavor of localtime $month = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")[(localtime)[4]]; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; # Y2K proof - localtime returns 101 for the year 2001 ## Figure out output directory and create if it doesn't exist $out_dir = "$archive_root/$list_name/$year-$month"; if ( ! -e $out_dir ) { mkdir $out_dir, 0755 or die "Couldn't create $out_dir: $!\n"; } ## Define ARGV (ARGV is same across all packages). ## Edit options as required/desired. @args = ("-add", "-quiet", "-sort", "-reverse", "-outdir", "$out_dir", "$mail_file"); ## I use system() to fork MHonArc so I can return and unlink $mail_file $result = system($MHonArc, @args); ## Check to see if all went well before unlinking $mail_file if ($result == 0) { unlink $mail_file; } }