From: spencer@phoenix.Princeton.EDU (S. Spencer Sun)
Subject: Re: Attribution enhancement, maybe?
Reply-To: spencer@phoenix.princeton.edu (S. Spencer Sun)
Organization: Live Organ Transplants
Date: Wed, 19 Aug 1992 19:50:59 GMT

In article <Bt8wAo.74J@cs.dal.ca>, dinn@ug.cs.dal.ca (Michael 'Moose' Dinn) writes:
>In article <1992Aug19.182721.25194@das.harvard.edu> adam@flicker.uucp (Adam Shostack) writes:
>>Ok, heres an idea for an enhancement for the next version. Currently,
>>.elm/elmrc has a single line controlling attribution.  Since most of
>>my replies are done with r(eply) not g(roup reply), I leave this set
>>to "You wrote."  But when I send a group reply, I'd like this to
>>automatically change to "%s wrote:"
>
>Good idea.
>Could we also add something like %w for when the message was sent, %z for
>the subject of the message, etc., to these fields?
>
>That would make the attribution feature mich more interesting.

Here's how I get my attributions.  It includes the date and full From:
field of the original sender.  It could easily be adapted to do more than
it currently does though.  NOte that this works with /usr/ucb/mail also
if you set your EDITOR variable to point to mq and then ~e instead of ~v
(so that you don't have to set your VISUAL to point to mq, because
things besides mail use VISUAL)

1. Set your indent prefix in your elmrc.  ELM does the attribution, this
does the rest.
2. Set your editor variable in your elmrc to point to this script (I
call it mq which stands for m)ail q)uoter because it used to do the
quoting too, even though it no longer does)
3. Change the #! path to point to perl.
4. You'll have to modify the signature part unless you want it set up
the way I have it set up.  I have a directory called ~/.sigdir, which
contains numerous files, any one of which can be randomly selected and
used as my .signature file.  There is a file called INDEX which is a
list of all the files, create with "ls -1 > INDEX" and then delete the
line that contains INDEX on it (notice ls -1, not ls -l).  The signature
stuff is way at the bottom of the file.
5. You may want/have to change the definition of $tempfile.

#!/usr/princeton/bin/perl

$prefix="-> ";
$sigdir="$ENV{HOME}/.sigdir";
$sigindex="INDEX";

#
# Copy the file over to temporary file, because we're going to copy it
# back and write over the original file.  Note that since 0 = false
# and 1 = true, that's a && after the system() and not a || like you'd
# expect.
#
$ARGV[0] || die("No filename specified on command line");
$tempfile="/tmp/mq$$";
system("cp $ARGV[0] $tempfile") && die("Couldn't copy $ARGV[0] to $tempfile");

open(TEMPFILE, "$tempfile");
open(OUTFILE, ">$ARGV[0]");

#
# First we copy all the lines up to the first indent prefix (in case
# we're using Berkeley mail with the 'editheaders' option set)
#
while (<TEMPFILE>)
{
  last if /^${prefix}From /o;
  print OUTFILE;
}

#
# Now skip until the first line consisting of just an indent prefix.
# This deletes all the mail header lines.  Meanwhile, extract the
# name of the sender, and the date the mail was sent.
#
while (<TEMPFILE>)
{
  chop;
  last if /^${prefix}$/o;
  s/^${prefix}From: //o && ($from = $_);
  s/^${prefix}Date: //o && ($date = $_);
}

#
# Create the attribution line and print it out, breaking lines at the
# 75th column for nice output.  Then print the rest of the mail.
#

if ($from)
{
  if ($date)
  { $foo = "On $date, $from may or may not have written:"; }
  else
  { $foo = "$from may or may not have written:"; }
  @attrib = split(/[ \t\n]+/, $foo);
  $length = 0;
  do
  {
    $length += (length($attrib[0]) + 1);
    if ($length > 75)
    {
      print OUTFILE "\n";
      $length = 0;
    }
    print OUTFILE "$attrib[0] ";
  } while (shift(@attrib));
  print OUTFILE "\n$prefix \n";
  print OUTFILE while (<TEMPFILE>);
}

#
# Now print out the constant stuff in the sig.
#
print OUTFILE "\n-----\n";
print OUTFILE "sss/PU'94 Dept of CS (spencer@phoenix.princeton.edu/JvNCnet(spencer@jvnc.net)\n";
  
close(TEMPFILE);
unlink($tempfile) || print STDERR "Couldn't remove temporary file $tempfile\n";

#
# open the index file, select a random sig, and print it out
#
open(SIGS, "${sigdir}/${sigindex}");
@lines = <SIGS>;
close(SIGS);
srand(time^$$);
open(SIGFILE, "${sigdir}/$lines[rand @lines]");
print OUTFILE while (<SIGFILE>);
close(SIGFILE);

close (OUTFILE);

$ENV{VISUAL} && exec "/usr/ucb/vi", $ARGV[0];
print STDERR "No visual editor!  Using vi...\n";
(-x "/usr/ucb/vi") && exec "/usr/ucb/vi", $ARGV[0];
(-x "/usr/bin/vi") && exec "/usr/bin/vi", $ARGV[0];
print STDERR "Couldn't find /usr/ucb/vi or /usr/bin/vi.  Giving up\n";


----------- The opinions expressed in this article are solely mine. -----------
<Insert lame attempt at disclaimer humor>
sss/PU'94 Dept of CS (spencer@phoenix.princeton.edu)/JvNCnet (spencer@jvnc.net)
"'Rue the day'?  Who talks like that?"

Newsgroups: comp.mail.elm