At 03:37 AM 8/18/99 , era eriksson wrote:
On Mon, 16 Aug 1999 13:46:26 -0700, Gregory Sutter
<gsutter(_at_)pobox(_dot_)com>
wrote:
> Does anyone have a set of recipes that will correctly format Microsoft
> Outlook mail? Outlook, in typical Microsoft form, cannot quote
> correctly. It also encourages upside-down replys. This bugs the crap
> out of me.
Something like this maybe?
[...]
No idea about the recipe for match, but here's a (recursive, perl 5) perl
script to do what you want...
I've set it up for cc:mail, but it should be very easy to modify for other
uses. It's probably grossly inefficient, but I haven't taken much time at it..
jon
#!/usr/pkg/bin/perl
#
# fixccmqoute.pl,
#
# Copyright (C) 1999 Jonathan J. Miner
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# $Id: fixccmqoute.pl,v 1.6 1999/08/19 22:52:51 jmx Exp $
# Jon Miner <miner(_at_)doit(_dot_)wisc(_dot_)edu>
#
@hdr = ();
@message = ();
@newmsg = ();
$reply_sep = "_ Reply Separator _";
$subject_Prefix = "Subject:"
$author_prefix = "Author:";
$date_prefix = "Date:";
$message_changed = 0;
$RCSiD = '$Id: fixccmqoute.pl,v 1.6 1999/08/19 22:52:51 jmx Exp $';
# First suck in the headers.
while (<STDIN>) {
s/\n//;
last if (/^$/);
push (@hdr,$_);
}
# Now, suck in the actual NEW content.
while (<STDIN>) {
# If we see a reply separator, bail.
last if (/$reply_sep/);
s/\n//;
push ( @newmsg,$_);
}
# Remove leading and trailing blank spaces (they annoy me).
$#newmsg-- while ($newmsg[$#newmsg] =~ /^\s*$/);
shift (@newmsg) while ($newmsg[0] =~ /^\s*$/);
if (/$reply_sep/) {
# Only append a header if we actually do something.
$message_changed = 1;
# Suck in all the responses.
@message = message();
}
# Print the headers.
print "$_\n" foreach (@hdr);
# Add a header if we actually did something.
print "X-Autoconverted-quoting: $RCSiD\n" if ($message_changed);
# The obligitry post-header newline.
print "\n"
# print all the quoted messages.
print "$_\n" foreach (@message);
# separate response with a space.
print "\n";
# Print the response.
print "$_\n" foreach (@newmsg);
sub message {
# Make sure we dan't have a namespace problem.
my @msg = ();
my @quote = ();
my $subject = "";
my $from = "";
my $date = "";
# Grab the subject line (ccMail).
$subject = <STDIN>;
# Grab the from line (ccMail).
$from = <STDIN>;
# Grab the date line (ccMail).
$date = <STDIN>;
# kill the newlines.
chomp($subject);
chomp($from);
chomp($date);
# Parse out the real subject.
$subject =~ s/^$subject_prefix\s+(Re(\[\d+\])?:)?[ ]?//;
$subject =~ s/\s+$//;
# try to find the author's name.
$from =~ s/^$author_prefix\s+\"?([^"<]*)\"?.*/$1/;
$from =~ s/\s+$//;
# Rearrange the date (ccMail).
$date =~ s/^$date_prefix\s+(\S+) (.*)/$2 $1/;
$date =~ s/\s+$//;
# Such in the message
while (<STDIN>) {
# Stop when sigdashes are detected (even stupid "--" sigdashes).
if (/^-- ?$/) {
# suck in until EOF or the next reply is found.
while (<STDIN>) {
last if (/$reply_sep/);
}
}
last if (/$reply_sep/);
s/\n//;
# Add the line to current message (with a "> " in front).
push ( @msg,"> $_");
}
# Remove leading and trailing blank spaces.
$#msg-- while ($msg[$#msg] =~ /^>*\s*$/);
shift (@msg) while ($msg[0] =~ /^>*\s*$/);
# If we found another reply, recurse.
if (/$reply_sep/) {
my @tmp = message();
# Add a ">" in front of the reply text.
push (@quote, ">$_") foreach (@tmp);
# Add a nice little Attribution.
@msg = ("At $date $from wrote about $subject:", @quote, @msg);
} else {
# Add a nice little Attribution.
@msg = ("At $date $from wrote about $subject:", @msg);
}
return (@msg);
}
# vim: set cindent autoindent:
--
Jonathan J. Miner----------------------|
miner(_at_)doit(_dot_)wisc(_dot_)edu
Network Systems Technology | 608/262.9655
Division of Information Technology | 3149 Computer Science
University of Wisconsin, Madison | 1210 W. Dayton St.