Re: Qn about a interesting but slight mis-use of mhonarc

2002-05-01 02:33:07
Wow, sounds great.  Are you interested in sharing what you
have got so far?

=v= Okay, I've put the rough cut script below.  It's got a lot
of stuff hardcoded into it, and does hacky things like grabbing
info out of comments that is better gotten from variables.  I'm
working on a rewrite that uses and also does other
fancy things, but this is what I whipped together in one hour.

I know what you mean about the archiving.  I was thinking
about starting small and say only allowing 20 msgs on the
front page, move everything else to a sub folder?

=v= Well, as I mentioned, I envision working from two message
folders, one for archive-worthy messages and the other for
ephemeral ones.  I suspect I'll just get rid of the ephemeral
ones with rmm, <EXPIREAGE>, or <EXPIREDATE>.  The archive-worthy
ones I'm thinking of dealing by using <MULTIPG> and <IDXSIZE>,
and basing the blog "index.html" page on just the first thread
index page.

How are you authenticating the user?

=v= Well, since I'm the only user I have full control over what
ends up in the message folders. :^)  My script shows an example
approach to a feedback mechanism via a "mailto:"; URL, but
getting the comments into the message folders and into the blog
is something you'll need to do with procmail or somesuch.

=v= (As an aside, according to RFC2368 you could in theory make
"Comments" links with URLs like this:


But that won't work in the real world, since you can't rely on
browsers to support "References" or "In-Reply-To".  A workaround
is to embed the message number in the address, though this will
mean more convolutions at the receiving end:


I've put an example of this hack in my script.)

=v= Since stuff is hardcoded in the script, I'll list the
assumptions up front:

  o You are currently in the web directory where ephemeral
    messages have already been converted with MHonArc.
  o The files have the default msg%%%%%.html filenames.
  o You're using this script to create a index.html file
    with all the messages in it, blog-style.

Blogs usually have "Posted by," "Permalink," and "Comments"
under each message.  None of these are in the design goals
of this particular script, but I've tossed them in for kicks.
The "Posted by" address is ROT13-encrypted.  I've replaced
the "Permalink" with an "Ephemeralink," but it's ultimately
pointless.  "Comments" is implemented as described above.



open STDOUT, ">index.html" or die "Can't redirect stdout";

'<html><head><title>Experimental Blog of Ephemeralities</title></head>
<h1>Experimental Blog of Ephemeralities</h1>
<table border=0 cellpadding=1 width=100%>';

# Blogs typically present messages in reverse order.
my @msglist = reverse <msg*.html>;

foreach $msgfile (@msglist) {
    print STDERR "[Converting $msgfile]...\n";
    my %header = {};
    my $is_print = 0;
    my $msgnum = $msgfile;
    $msgnum =~ s/^msg//;
    $msgnum =~ s/\.html$//;
    my $subject = "";
    open MSG_FILE, $msgfile;
    foreach (<MSG_FILE>) {
        if (/^<!--X-(Date|From-R13|Subject): (.*) -->$/) {
            $header{$1} = $2;
        } elsif (/^<!--X-Body-of-Message-->$/) {
'<tr bgcolor="#666666">
<td><table border=0 cellpadding=0 width=100%><tr valign=top>
<td width=80%><font face="Garamond" color="#CCFFCC">&nbsp;',
$header{'Subject'}, '</td>
<td align=right><font color="#CCFFCC" size=-2><nobr>',
$header{'Date'}, '</font>&nbsp;</nobr></td></tr></table></td></tr>
            $is_print = 1;
        } elsif (/^<!--X-Body-of-Message-End-->$/) {
            $is_print = 0;
        } elsif ($is_print) {
            print $_;
    ($subject = $header{'Subject'}) =~ s/^R(E|e):\s*//;
    # This isn't robust; it should use URL-encoding.
    $subject =~ s/\s/%20/g;
'<font face="Arial, Helvetica, sans-serif" size=-2>Posted by ',
$header{'From-R13'}, '
<a href="', $msgfile, '"
<a href="mailto:blog+',
$msgnum, '', $subject, '"
    close MSG_FILE;

print "</table></body></html>\n";