[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

inverted quoting



Dear list,

It seems to me that quoted replies in emails are somewhat backwards.
The following as an example:

| > > Instead of having higher levels of indentation for text that
| > > came first
| >
| > it would make a lot more sense to reverse the indentation,
|
| especially when archiving mails that aren't going to be used by
| a MUA to correspond.

I'd say for a web archive, the following would make a lot more
sense:

| Text tha came first does not get indented, but instead serves to
| as the main text and anchor
|
|   for text which is in reply to the email, which is quotes
|
|     which makes it a lot more obvious to the eye.

This allows a reader to easily skip interjections simply by not
following indentation levels, and with the proper bit of
XHTML/JavaScript/CSS, replies could even become foldable.

I had a brief look at mhonarc and found the plugin architecture that
makes mhonarc a really cool tool.

Unfortunately, my Perl-skills are non-existent. Fortunately, my
girlfriend knows the language a bit better, and so she threw
together the attached script yesterday, which takes a message and
outputs HTML which does the inversion. It is proof-of-concept and
several rough edges need to be smoothed out.

Do you think it is possible to write a mhonarc plugin on the basis
of this logic? Would anyone like to give it a shot?

-- 
martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:"; net@madduck
 
obviously i was either onto something, or on something.
                                 -- larry wall on the creation of perl
 
spamtraps: madduck.bogus@xxxxxxxxxxx
#!/usr/bin/perl -w
#
# mail2html-invert - converts a mail to HTML and inverts the quoting
#
# Copyright © 2008 Penny Leach <penny at mjollnir.org>
# Released under the GPLv2
#

use strict;
use warnings;
use Text::Quoted;
use HTML::Entities;

# configurable bits
my $printblockquotes = 1; # change this to 0 if you want <p class="leveln"> instead of <blockquote><blockquote> etc
my $title = 'email';      # this could helpfully extract the names in the email or such



my $raw;           # raw body of message
my $bodystarted;   # flag for end of headers
my @newstructure;  # post-processed structure
my $maxlevel = 0;  # for inverting indenting

print <<EOH;
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html>
    <head>
        <title>$title</title>
    </head>
    <body>
        <p class="headers">

EOH

while (<STDIN>) {
    if (/^$/ && !$bodystarted) { # empty line, start processing body after this
        $bodystarted = 1;
        print "</p>\n"; # end the paragraph containing headers
        next;
    }

    unless ($bodystarted) { # if we're still processing headers, just print them
        chomp;
        print encode_entities($_) . "<br />\n";
        next;
    }

    $raw .= $_;
}

# convert the raw body to some whack datastructure provide but Text::Quoted
my $structure = extract($raw);

foreach my $item (@$structure) {
    # process the weird format we have and turn it into something sensible and flatter
    handleitem($item);
}

# each 'item' is basically one lump of text with an indent level, which we invert
foreach my $item (@newstructure) {
    my $invertedlevel = $maxlevel - $item->{level};
    my $escaped = encode_entities($item->{text});
    unless ($printblockquotes) {
        print '<p class="level' . $invertedlevel . '">' . $escaped . '</p>' . "\n";
        next;
    }
    my $pre = '';
    my $post = '';
    for (1..$invertedlevel) { $pre .= '<blockquote>'; $post .= '</blockquote>'; }
    print $pre . '<p>' . $escaped . '</p>' .  $post . "\n";

}

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


# --------------------------------------------------

# extract gives us back a weird structure that contains an array of either hashes or arrays
# flatten it and add it into @newstructure with an indent level
sub handleitem {
    my $item = shift;
    my $level = shift || 0;
    $maxlevel = $level if $maxlevel < $level;
    if (ref $item eq 'HASH') {
        return if $item->{empty};
        push @newstructure, { 'text' => $item->{text}, 'level' => $level};
    }
    elsif (ref $item eq 'ARRAY') {
        foreach my $newitem (@$item) {
            handleitem($newitem, $level+1);
        }
    }
}

Attachment: digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/)


[Index of Archives]     [Bugtraq]     [Yosemite News]     [Mhonarc Home]