mhonarc-users

can $ENV(DESCRIPTION) be sticky?

2000-12-15 00:10:35
I'm developing a majordomo-mhonarc-htdig system http://beta.wfn.org/months.html
I want to add an automatically built line in each new message page, like:
   <meta name=description value="some excellent summary of the article">

So, I wrote the perl script below that parses the whole message, 
builds what it thinks is a good summary, 
sets an environment variable called DESCRIPTION
and then runs mhonarc on the temporary file with the whole message.

mhonarc has in its .mrc file:

<MsgPgBegin>
...
<meta name="description" content="$ENV(DESCRIPTION)$">
...
</MsgPgBegin>

The first time I run this, everything works well - the environment
variable is evaluated and inserted into the message file.

The second time I add a message to a directory, mhonarc edits the first
message file as well as creating the second one (presumably to change the
'next item by date' on the first one) and sets $ENV(DESCRIPTION)$ for BOTH
message pages to the description of the last message.

The third time, it edits the 2nd and 3rd pages, setting DESCRIPTION to the
summary of the 3rd message.

Does anyone have any suggestions on:
a) how I can make $ENV(DESCRIPTION)$ 'sticky', that is only evaluated in
   the new message, and after that not re-evaluated?
b) another way I can do this

Thank you
Michael de Beer
madebeer(_at_)igc(_dot_)org

#!/usr/bin/perl -w

# parse message to get environment variable before passing whole message
# and environment var to mhonarc
# in mrc file: <meta name="description" content="$ENV(DESCRIPTION)$">

# extra feature: sets the outdir to format like 2001/02 (for monthly archives)

# if you want to process a whole mail folder like this, run it like
# formail -s process_one_mail3.pl < mailfolder

my $outdir = shift;

my $myhome = '/home/root204';
my $base = $myhome . '/htdocs';
my $mode = 0777;

# Here I parse the mail message, looking for a good summary.
# Different messages will have different looking 'good' summaries.
# On the news releases I saw, most of the good summaries ended with a period, 
followed by
# a blank line.  This isn't perfect, but it worked for most of them. 

my $description = '';
my $old_sep = $/;
$/ = "";
my ($i);

my $tmpfile = "/tmp/pom.$$";
open (TMP, ">$tmpfile") or die "could not open $tmp";
while(<>) {
    # store a copy of the file 
    print TMP $_;
    next if $i++ lt 1;
    next if ( length($description) gt 200 );

    # grab following paragraph if we have one short but good paragraph.
    next unless ( $description or (! /^[^ ]: /  and /(\.|\?)"?\s*$/ ));
    $description .= $_;
    # remove stupid bylines 
    $description =~ s/---+[^-]*---+//g;
    # be sure to remove <>"\ from the description, or it could mess up HTML
    $description =~ tr/"/'/;
    $description =~ s (\<|\>) ()g;
};
close (TMP) or die "could not open $tmp";  
$/ = $old_sep;
$ENV{DESCRIPTION} = substr ( $description, 0,600);
#debugging
#print $ENV{DESCRIPTION};
#print 'H' x 50,"\n";

if (! defined $outdir) { 
  my ($sec,$min,$hour,$mday,$MM,$year,$wday,$yday,$isdst) = localtime(time);
  my $YY = 1900 + $year;
  $MM++;
  -d "$base/$YY" or mkdir "$base/$YY", $mode;
  $outdir = "$base/$YY/$MM"
}
-d $outdir or mkdir $outdir, $mode or die "cannot make $outdir";

my $mhonarc = "$myhome/mh/bin/mhonarc"; 
my @mh_args = qw{-add -rcfile /home/root204/htdocs/wfn.mrc -outdir};
push @mh_args, $outdir, $tmpfile;
system($mhonarc, @mh_args);
unlink $tmpfile;

<Prev in Thread] Current Thread [Next in Thread>