mhonarc-users

format=flowed

2002-05-01 22:33:48
I have created a version of "mhtxtplain.pl" which supports the flowed text 
format
(http://www.rfc-editor.org/rfc/rfc2646.txt).  The idea of this format is that,
unlike HTML, it looks just fine to people with plain text, but for mail readers 
that
support it, text, including quoted messages, can be reflowed for different line
lengths.  Lines that end with a space are considered to have a soft line break.

Let me know what you think of it.

I'm attaching a copy of the revised "mhtxtplain.pl", and you can also download 
it
at: http://personal.rdu.bellsouth.net/~kahirsch/mhtxtplain.pl

I have a demonstration of the output at:
http://personal.rdu.bellsouth.net/~kahirsch/maillist.html, using the ietf-822
mailing list as an example (this is the mailing list where the format was
developed).

Here are the highlights:
(1) define the HTML formatting for flowed quotes (all the MUAs seem to use 
something
like this):
(line 45 in revised mhtxtplain.pl)
$StartFlowedQuote = '<blockquote style=' .
 '"border-left: #0000ff solid 2px; margin-left: 5px; padding-left: 5px">' .
  "\n";
$EndFlowedQuote   = "</blockquote>\n";

(2) process the body
(line 303)
  if ($textformat eq 'flowed') {
    # experimental support for format=flowed Ken Hirsch (May 2002)
    # text/plain; format=flowed defined in RFC2646
    my $currdepth = 0;
    my $ret='';
    s!^</?x-flowed>\r?\n>!!mg; # we don't know why Eudora puts these in
    while (length($$data)) {
      $$data =~ /^((?:&gt;)*)/;
      my $qd = $1;
      if ($$data =~ s/^(.*(?:\n$qd(?!&gt;).*)*\n?)//) {
          # divide message into chunks by "quote-depth",
          # which is the number of leading > signs
          my $chunk = $1;
          $chunk =~ s/^$qd ?//mg; # N.B. also takes care of space-stuffing
          $chunk =~ s/^-- $/--/mg; # special case for '-- '
          if ($chunk =~ / \r?\n/) {
            # Treat this chunk as format=flowed
            # Lines that end with spaces are
            # considered to have soft line breaks.
            # Lines that end with no spaces are
            # considered to have hard line breaks.
            $chunk =~ s/(?<! )(\r?\n|\Z)/<br>$1/g;

          } else {
            # Treat this chunk as format=fixed
            if ($nonfixed) {
                $chunk =~ s/(\r?\n)/<br>$1/g;
                if ($keepspace) {
                    $chunk =~ s/^(.*)$/&preserve_space($1)/gem;
                }
            } else {
                $chunk = "<pre>\n" . $chunk . "</pre>\n";
            }
          }
          my $newdepth = length($qd)/length('&gt;');
          if ($currdepth < $newdepth) {
            $chunk = $StartFlowedQuote x ($newdepth - $currdepth) .  $chunk;
          } elsif ($currdepth > $newdepth) {
            $chunk = $EndFlowedQuote x ($currdepth - $newdepth) . $chunk;
          }
          $currdepth = $newdepth;
          $ret .= $chunk;
      } else {
        # I think the above regex will always match, but
        # I put this in here to catch any weird cases
        # so there's no infinite loop
        print STDERR "DEQUOTINGERROR($$data)\n";
        $ret .= $$data;
        last;
      }
    }
    if ($currdepth > 0) {
      $ret .= $EndFlowedQuote x $currdepth;
    }
    $$data = $ret;
  } else {


Attachment: mhtxtplain.pl
Description: Binary data

<Prev in Thread] Current Thread [Next in Thread>
  • format=flowed, Ken Hirsch <=