i want to configure the option of hypermail but i'm not an experimented
in perl
in the hypermail.pl and in the line
usage unless getopts('pim:d:');
what i have to type ?
i'm on a mac and my mail is in bigBrother:Courrier:Inbox

the script

#!/usr/bin/perl
#
# This program is a work-alike of the 'hypermail' program originally
written
# by Kevin Hughes <[EMAIL PROTECTED]>.  This is written because of problems

# with version 1.02 of hypermail and no new version being available.
#
# This doesn't have all the functionality of the original hypermail
(though
# it may eventually).

use Getopt::Std;

usage unless getopts('pim:d:');
     # -m "file to be read in"
     # -d "directory to put stuff in"
     # -i if the file is to be read from STDIN
     # -p show progress

sub usage{
 print "  usage: hypermail.pl -pi [-m \"mailbox\"] [-d \"target
dir\"]\n";
 print "options: -d : Target directory for saving HTML files\n";
 print "         -i : Read in mail archive from STDIN\n";
 print "         -m : Read in mail archive from \"mailbox\"\n";
 print "         -p : Show progress\n";
 exit;
}

$PROG = 0;
$PROG = 1 if defined $opt_p;

usage unless(defined $opt_d); # We have to have some place to do the
output
usage if(defined $opt_i && defined $opt_m);  # Make sure they don't have

both options
usage unless(defined $opt_i || defined $opt_m); # but make sure they
have at least one

if (defined $opt_i){
 open IN,"<&STDIN" || die "Can't duplicate STDOUT: $!\n";
}

if (defined $opt_m){
 open IN, $opt_m || die "Can't open $opt_m for reading: $!\n";
}

# Some global variables

$NAME = "hypermail.pl";
$VERSION = "1.00";

# Some sorting subroutines that will be useful later

sub by_date{
 ($aday,$amon,$adate,$atime,$ayear) = split /\s+/, $$a{'date'};
 ($ahour,$amin,$asec) = split /:/, $atime;
 ($bday,$bmon,$bdate,$btime,$byear) = split /\s+/, $$b{'date'};
 ($bhour,$bmin,$bsec) = split /:/, $btime;
 # Change the month into a numerical problem.  If only the months
 # were alphabetically arranged this would be so much easier!
 $amon = 1 if $amon eq 'Jan'; $amon = 2 if $amon eq 'Feb';
 $amon = 3 if $amon eq 'Mar'; $amon = 4 if $amon eq 'Apr';
 $amon = 5 if $amon eq 'May'; $amon = 6 if $amon eq 'Jun';
 $amon = 7 if $amon eq 'Jul'; $amon = 8 if $amon eq 'Aug';
 $amon = 9 if $amon eq 'Sep'; $amon = 10 if $amon eq 'Oct';
 $amon = 11 if $amon eq 'Nov'; $amon = 12 if $amon eq 'Dec';
 $bmon = 1 if $bmon eq 'Jan'; $bmon = 2 if $bmon eq 'Feb';
 $bmon = 3 if $bmon eq 'Mar'; $bmon = 4 if $bmon eq 'Apr';
 $bmon = 5 if $bmon eq 'May'; $bmon = 6 if $bmon eq 'Jun';
 $bmon = 7 if $bmon eq 'Jul'; $bmon = 8 if $bmon eq 'Aug';
 $bmon = 9 if $bmon eq 'Sep'; $bmon = 10 if $bmon eq 'Oct';
 $bmon = 11 if $bmon eq 'Nov'; $bmon = 12 if $bmon eq 'Dec';
 $ayear <=> $byear || $amon <=> $bmon || $adate <=> $bdate ||
 $ahour <=> $bhour || $amin <=> $bmin || $asec  <=> $bsec;
}

sub by_subject{
 # This is lame.  I should be able to do this more elegantly (like
somehow
 # referencing the 'by_date' sub up there) but don't know how and don't
 # want to take the time to futz around with this right now.
 ($aday,$amon,$adate,$atime,$ayear) = split /\s+/, $$a{'date'};
 ($ahour,$amin,$asec) = split /:/, $atime;
 ($bday,$bmon,$bdate,$btime,$byear) = split /\s+/, $$b{'date'};
 ($bhour,$bmin,$bsec) = split /:/, $btime;
 # Change the month into a numerical problem.  If only the months
 # were alphabetically arranged this would be so much easier!
 $amon = 1 if $amon eq 'Jan';    $amon = 2 if $amon eq 'Feb';
 $amon = 3 if $amon eq 'Mar';    $amon = 4 if $amon eq 'Apr';
 $amon = 5 if $amon eq 'May';    $amon = 6 if $amon eq 'Jun';
 $amon = 7 if $amon eq 'Jul';    $amon = 8 if $amon eq 'Aug';
 $amon = 9 if $amon eq 'Sep';    $amon = 10 if $amon eq 'Oct';
 $amon = 11 if $amon eq 'Nov';   $amon = 12 if $amon eq 'Dec';
 $bmon = 1 if $bmon eq 'Jan';    $bmon = 2 if $bmon eq 'Feb';
 $bmon = 3 if $bmon eq 'Mar';    $bmon = 4 if $bmon eq 'Apr';
 $bmon = 5 if $bmon eq 'May';    $bmon = 6 if $bmon eq 'Jun';
 $bmon = 7 if $bmon eq 'Jul';    $bmon = 8 if $bmon eq 'Aug';
 $bmon = 9 if $bmon eq 'Sep';    $bmon = 10 if $bmon eq 'Oct';
 $bmon = 11 if $bmon eq 'Nov';   $bmon = 12 if $bmon eq 'Dec';
 $$a{'subject'} cmp $$b{'subject'} || # Sort by subject first, then date

 $ayear <=> $byear || $amon <=> $bmon || $adate <=> $bdate ||
 $ahour <=> $bhour || $amin <=> $bmin || $asec  <=> $bsec;
}

sub by_author{
 # This is lame.  I should be able to do this more elegantly (like
somehow
 # referencing the 'by_date' sub up there) but don't know how and don't
 # want to take the time to futz around with this right now.
 ($aday,$amon,$adate,$atime,$ayear) = split /\s+/, $$a{'date'};
 ($ahour,$amin,$asec) = split /:/, $atime;
 ($bday,$bmon,$bdate,$btime,$byear) = split /\s+/, $$b{'date'};
 ($bhour,$bmin,$bsec) = split /:/, $btime;
 # Change the month into a numerical problem.  If only the months
 # were alphabetically arranged this would be so much easier!
 $amon = 1 if $amon eq 'Jan';    $amon = 2 if $amon eq 'Feb';
 $amon = 3 if $amon eq 'Mar';    $amon = 4 if $amon eq 'Apr';
 $amon = 5 if $amon eq 'May';    $amon = 6 if $amon eq 'Jun';
 $amon = 7 if $amon eq 'Jul';    $amon = 8 if $amon eq 'Aug';
 $amon = 9 if $amon eq 'Sep';    $amon = 10 if $amon eq 'Oct';
 $amon = 11 if $amon eq 'Nov';   $amon = 12 if $amon eq 'Dec';
 $bmon = 1 if $bmon eq 'Jan';    $bmon = 2 if $bmon eq 'Feb';
 $bmon = 3 if $bmon eq 'Mar';    $bmon = 4 if $bmon eq 'Apr';
 $bmon = 5 if $bmon eq 'May';    $bmon = 6 if $bmon eq 'Jun';
 $bmon = 7 if $bmon eq 'Jul';    $bmon = 8 if $bmon eq 'Aug';
 $bmon = 9 if $bmon eq 'Sep';    $bmon = 10 if $bmon eq 'Oct';
 $bmon = 11 if $bmon eq 'Nov';   $bmon = 12 if $bmon eq 'Dec';
 $$a{'r_name'} cmp $$b{'r_name'} || # Sort by subject first, then date
 $ayear <=> $byear || $amon <=> $bmon || $adate <=> $bdate ||
 $ahour <=> $bhour || $amin <=> $bmin || $asec  <=> $bsec;
}

$first_time = 1;

{
 local $/ = "\nFrom ";  # Localising this change of variable.

 $h = 1;

 while(<IN>){
  next if $h++ == 1; # Gets rid of having the first element be blank
  chomp;
  s/From $//;
  print "$_\n---\n" if $DEBUG;
  print "<" if $PROG;
  $i++ if $PROG;
  print "\n" if $i > 75;
  $i = 0 if $i > 75;
  push @messages,$_;
 }
}

$i=0;

print "\n$#messages messages in archive\n" if $PROG;

#
# Ok, we've got all the messages in a large array.  We'll go through
each
# message and grab some information out of it that will be useful later
#

foreach $num (0 .. $#messages){
 #
 # We'll have one global array called @index.  This will be an array of
 # references to anonymous hashes.  These hashes will have the following

 # keys:
 #
 # 'subject'  - The subject of the messages
 # 'r_name'  - The full real names of the e-mailers
 # 'addr'  - The address for the sender of each e-mail
 # 'date'  - The date for each e-mail
 # 'sent_dates' - The date the e-mail says it was sent
 # 'body'  - The actual body of the e-mails.
 # 'filename' - The name for the html file

 $index[$num]{'filename'} = $num . ".html";
 $index[$num]{'date'} = $1 if $messages[$num] =~ /^[^\s]+\s+(.+)/;
 $begin_date = $1 if $num == 0;
 $end_date = $1 if $num == $#messages;
 $index[$num]{'sent_date'} = $1 if $messages[$num]=~ /^Date: (.*)$/m;
 $index[$num]{'subject'} = $1 if $messages[$num] =~ /^Subject: (.*)$/m;
 $index[$num]{'subject'} = '*NO SUBJECT*' if $index[$num]{'subject'} =~
/^\s*$/;
 if($messages[$num] =~ /^From: (.+) (<.+@(.+\.)+(.+))>?/m){
  $index[$num]{'r_name'} = $1;
  $index[$num]{'addr'} = $2;
 } elsif($messages[$num] =~ /^From: <?(.+@(.+\.)+(.+))>?\s+\((.*)\)/m){
  $index[$num]{'r_name'} = $4;
  $index[$num]{'addr'} = $1;
 } elsif($messages[$num] =~ /^From: <?(.+@(.+\.)+(.+))>?/m){
  $index[$num]{'r_name'} = 'NONE';
  $index[$num]{'addr'} = $1;
 }
 $index[$num]{'r_name'} =~ s/^\"//;
 $index[$num]{'r_name'} =~ s/\"$//;
 # We split the entire message into an array
 my @lines = split /\n/, $messages[$num];
 # We shift the first line off of it so $blank will have a non-zero
value
 $blank = shift @lines;
 # Then we shift until we get to the first blank line (which means we've

 # reached the message body).
 while($blank !~ /^$/){
  $blank = shift @lines;
 }
 # Then we take the rest of the array and put it into a string.
 $index[$num]{'body'} = join "\n", @lines;
}

#
# Some test code here.
#

#print "dates - $#dates\n";
#
#foreach $num (0 .. $#messages){
# print "$r_names[$num] sent e-mail with $subjects[$num] \n\t";
# print "as a subject on $dates[$num]\n--\n";
#}

#
# Now we print out the individual messages
#
foreach $num (0 .. $#messages){
 $filename = $opt_d . "/" . $index[$num]{'filename'};
 open(OUT,">$filename") || warn "Can't open $filename for writing:
$!\n";
 print OUT "<HTML>\n<HEAD><TITLE> archive: $index[$num]{'subject'}
</TITLE></HEAD>\n";
 print OUT "<BODY>\n";
 print OUT "<H1>$index[$num]{'subject'}</H1>\n";
 $index[$num]{'addr'} =~ s/</\(/g;
 $index[$num]{'addr'} =~ s/>/\)/g;
 print OUT "<I>";
 print OUT "$index[$num]{'r_name'}" unless $index[$num]{'r_name'} eq
'NONE';
 print OUT " $index[$num]{'addr'}</I><BR>\n";
 print OUT "<I>$index[$num]{'sent_date'}</I>\n<P>\n<ul>\n";
 print OUT "<LI> <B>Messages sorted by:</B> <a href=\"date.html#$num\">[

date ]</a>";
 print OUT "<a href=\"subject.html#$num\">[ subject ]</a>";
 print OUT "<a href=\"author.html#$num\">[ author ]</a>\n";
 print OUT "<LI> <B>Next message:</B> <a href=\"";
 print OUT $num+1 . ".html\">";
 print OUT $index[$num+1]{'r_name'} unless $index[$num+1]{'r_name'} eq
'NONE';
 print OUT " \"" . $index[$num+1]{'subject'} . "\"</a>\n";
 print OUT "<LI> <B>Previous message:</B> <a href=\"" unless $num == 0;
 print OUT $num-1 . ".html\">" unless $num == 0;
 print OUT $index[$num-1]{'r_name'} unless $index[$num-1]{'r_name'} eq
'NONE';
 print OUT " \"" . $index[$num-1]{'subject'} . "\"</a>\n"  unless $num
== 0;
 print OUT "</UL>\n<HR>\n<PRE>\n";
 print OUT "$index[$num]{'body'}\n</PRE>\n<HR>\n<P>\n<UL>\n";
 print OUT "<LI> <B>Next message:</B> <a href=\"" unless $num ==
$#messages;
 print OUT $num+1 . ".html\">" unless $num == $#messages;
 print OUT $index[$num+1]{'r_name'} unless $index[$num+1]{'r_name'} eq
'NONE';
 print OUT " \"" . $index[$num+1]{'subject'} . "\"</a>\n" unless $num ==

$#messages;
 print OUT "<LI> <B>Previous message:</B> <a href=\"" unless $num == 0;
 print OUT $num-1 . ".html\">" unless $num == 0;
 print OUT $index[$num-1]{'r_name'} unless $index[$num-1]{'r_name'} eq
'NONE';
 print OUT " \"" . $index[$num-1]{'subject'} . "\"</a>\n" unless $num ==

0;
 print OUT "</UL>\n</BODY></HTML>";
 print ">" if $PROG;
 $i++ if $PROG;
 print "\n" if $i > 75;
 $i = 0 if $i > 75;
}

#
# Now that we've got the individual messages printed out, let's compile
# the indicies.
#
$i = 0;

$filename = $opt_d . "/date.html";
open(OUT,">$filename") || warn "Can't open $filename for writing: $!\n";

print OUT "<HTML>\n<HEAD><TITLE>Archive by
Date</TITLE></HEAD>\n<BODY>\n";
print OUT "<a name=\"start\"><H1>Archive by Date</H1></a>\n<ul>\n";
print OUT "<li> <B><a href=\"#end\">Most recent messages</a></B>\n";
print OUT "<li> <B>Messages sorted by:</b> <a
href=\"subject.html#start\">";
print OUT "[ subject ]</a><a href=\"author.html#start\">[ author
]</a></b>\n";
print OUT "<li> <B><a href=\"..\">Other mail archives</a></b>\n</ul>\n";

print OUT "<b>Starting:</b> <i>$begin_date</i><br>\n";
print OUT "<b>Ending:</b> <i>$end_date</i><br>\n";
print OUT "<b>Messages:</b> $#messages\n<P>\n<ul>";

print "\n" if $PROG;

# Do a little sorting here
foreach $elem (sort by_date @index){
 print "d" if $PROG;
 $i++ if $PROG;
 print "\n" if $i > 75;
 $i = 0 if $i > 75;
 next unless defined $$elem{'subject'};
 print OUT "<LI> <a href=\"$$elem{'filename'}\">";
 print OUT "<B>$$elem{'subject'}</B></A> ";
 $anchor = $1 if $$elem{'filename'} =~ /(\d+).html/;
 print OUT "<a name=\"$anchor\"><I>";
 print OUT $$elem{'r_name'} unless $$elem{'r_name'} eq 'NONE';
 print OUT $$elem{'addr'} if $$elem{'r_name'} eq 'NONE';
 print OUT "</I></A>\n";
}

print OUT "</ul>\n";
print OUT "<a name=\"end\"><B>Last message date:</B></a>
<I>$end_date</I><BR>\n";
print OUT "<B>Archived on:</B> <I>" . localtime() . "</i>\n<P>\n";
print OUT "<UL>\n<li> <B>Messages sorted by:</b> <a
href=\"subject.html#start\">";
print OUT "[ subject ]</a><a href=\"author.html#start\">[ author
]</a>\n";
print OUT "<li> <B><a href=\"..\">Other mail archives</a></b>\n</ul>\n";

print OUT "<P>\n<HR>\n<I>This archive was generated by <a
href=\"http://morpho.dar.net/~northrup/hypermail.html\";>$NAME
$VERSION</a>\n";
print OUT "</BODY>\n</HTML>\n";

# And we'll symlink the index.html file to the date.html file unless
there's
# already an index.html file there.  If we wanted to get rid of anything

that
# wasn't a symlink, we could use '-l' for the test.

$indexfile = $opt_d . "/index.html";
unless(-e $indexfile){
 symlink "date.html",  $indexfile;
 print "\nSymlink added for index.html\n" if $PROG;
}

# Now for subjects

print "\n" if $PROG;
$i = 0;

$filename = $opt_d . "/subject.html";
open(OUT,">$filename") || warn "Can't open $filename for writing: $!\n";

print OUT "<HTML>\n<HEAD><TITLE>Archive by
Subject</TITLE></HEAD>\n<BODY>\n";
print OUT "<a name=\"start\"><H1>Archive by Subject</H1></a>\n<ul>\n";
print OUT "<li> <B><a href=\"#end\">Most recent messages</a></B>\n";
print OUT "<li> <B>Messages sorted by:</b> <a
href=\"subject.html#start\">";
print OUT "[ subject ]</a><a href=\"author.html#start\">[ author
]</a>\n";
print OUT "<li> <B><a href=\"..\">Other mail archives</a></b>\n</ul>\n";

print OUT "<b>Starting:</b> <i>$begin_date</i><br>\n";
print OUT "<b>Ending:</b> <i>$end_date</i><br>\n";
print OUT "<b>Messages:</b> $#messages\n<P>\n<ul>";

# Do a little sorting here

# Got to get rid of the annoying 're:' and 'Re:' and leading spaces
# in the Subject:s (we're not that worried about
foreach $elem (@index){
 $$elem{'subject'} =~ s/^\s*(re:\s*)?//ig;
}

foreach $elem (sort by_subject @index){
 print "s" if $PROG;
 next unless defined $$elem{'addr'};
 $i++ if $PROG;
 print "\n" if $i > 75;
 $i = 0 if $i > 75;
 if($cur_sub ne $$elem{'subject'}){
  print OUT " </UL>\n" if defined $cur_sub;
  print OUT " <LI> <B>$$elem{'subject'}</B>\n <ul>";
  $cur_sub = $$elem{'subject'};
 }
 $num = $1 if $$elem{'filename'} =~ /(.*).html/;
 print OUT "  <LI> <a href=\"$$elem{'filename'}\">";
 print OUT $$elem{'r_name'} unless $$elem{'r_name'} eq 'NONE';
 print OUT $$elem{'addr'} if $$elem{'r_name'} eq 'NONE';
 print OUT "</a> <a name=\"$num\"><I>$$elem{'date'}</I></a>\n";
}

print OUT "</ul>\n</ul>\n";
print OUT "<a name=\"end\"><B>Last message date:</B></a>
<I>$end_date</I><BR>\n";
print OUT "<B>Archived on:</B> <I>" . localtime() . "</i>\n<P>\n";
print OUT "<UL>\n<li> <B>Messages sorted by:</b> <a
href=\"subject.html#start\">";
print OUT "[ subject ]</a><a href=\"author.html#start\">[ author
]</a>\n";
print OUT "<li> <B><a href=\"..\">Other mail archives</a></b>\n</ul>\n";

print OUT "<P>\n<HR>\n<I>This archive was generated by <a
href=\"http://morpho.dar.net/~northrup/hypermail.html\";>$NAME
$VERSION</a>\n";
print OUT "</BODY>\n</HTML>\n";

# Now for authors

print "\n" if $PROG;
$i = 0;

$filename = $opt_d . "/author.html";
open(OUT,">$filename") || warn "Can't open $filename for writing: $!\n";

print OUT "<HTML>\n<HEAD><TITLE>Archive by
Author</TITLE></HEAD>\n<BODY>\n";
print OUT "<a name=\"start\"><H1>Archive by Author</H1></a>\n<ul>\n";
print OUT "<li> <B><a href=\"#end\">Most recent messages</a></B>\n";
print OUT "<li> <B>Messages sorted by:</b> <a
href=\"date.html#start\">";
print OUT "[ date ]</a><a href=\"subject.html#start\">[ subject
]</a>\n";
print OUT "<li> <B><a href=\"..\">Other mail archives</a></b>\n</ul>\n";

print OUT "<b>Starting:</b> <i>$begin_date</i><br>\n";
print OUT "<b>Ending:</b> <i>$end_date</i><br>\n";
print OUT "<b>Messages:</b> $#messages\n<P>\n<ul>";

# Do a replacement for all the people who only have 'NONE' as a name

foreach $elem (@index){ $$elem{'r_name'} = $$elem{'addr'} if
$$elem{'r_name'} eq 'NONE'}

# Do a little sorting here

foreach $elem (sort by_author @index){
 print "a" if $PROG;
 next unless defined $$elem{'addr'};
 $i++ if $PROG;
 print "\n" if $i > 75;
 $i = 0 if $i > 75;
# $$elem{'r_name'} = $$elem{'addr'} if $$elem{'r_name'} eq 'NONE';
 if($cur_auth ne $$elem{'r_name'}){
  print OUT " </UL>\n" if defined $cur_auth;
  print OUT " <LI> <B>$$elem{'r_name'}</B>\n <ul>";
  $cur_auth = $$elem{'r_name'};
 }
 $num = $1 if $$elem{'filename'} =~ /(.*).html/;
 print OUT "  <LI> <a href=\"$$elem{'filename'}\">";
 print OUT $$elem{'subject'};
 print OUT "</a> <a name=\"$num\"><I>$$elem{'date'}</I></a>\n";
}

print OUT " </ul>\n</ul>\n";
print OUT "<a name=\"end\"><B>Last message date:</B></a>
<I>$end_date</I><BR>\n";
print OUT "<B>Archived on:</B> <I>" . localtime() . "</i>\n<P>\n";
print OUT "<UL>\n<li> <B>Messages sorted by:</b> <a
href=\"date.html#start\">";
print OUT "[ date ]</a><a href=\"subject.html#start\">[ subject
]</a>\n";
print OUT "<li> <B><a href=\"..\">Other mail archives</a></b>\n</ul>\n";

print OUT "<P>\n<HR>\n<I>This archive was generated by <a
href=\"http://morpho.dar.net/~northrup/hypermail.html\";>$NAME
$VERSION</a>\n";
print OUT "</BODY>\n</HTML>\n";

print "\n" if defined $opt_p;




Reply via email to