SUMMARY 2: Signatures in mailtool

From: Marcus Filipsson (
Date: Thu Jun 22 1995 - 13:25:09 CDT

X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Content-Lines: 120

Since my first summary was way to premature, here's a more complete summary.

Original question:
How do I include a signature in mailtool?

I got LOADS of answers, with many different suggestions.
Thank you all who responded:

I hope I didn't forget anyone. Anyway, here's the summary:

Five (!) different solutions:
1. Use the Template menu in mailtool

Create a $HOME/.signature with your signature in it.
Use Edit | Properties | Template to add .signature as a template.
Use Include | Template to add a signature at the cursor in each mail.

This works, but is a bit tiresome. And it doesn't handle mail from the shell prompt.

2. Bind a key to echo your signature

Create a $HOME/.signature with your signature in it.
Modify (or create) $HOME/.textswrc by adding these line:

# Add signature if R3 pushed:
cat $HOME/.signature

Remember to comment out any previous definition of KEY_RIGHT(3) in .textswrc
This will echo you signature each time you press "Scroll Lock".

It works fine, but it would be nice to include it automatically...

3. A short shell script

I received a few different versions of scripts which just cat a signature to the end of each mail.
One of the more elaborate versions are added as attachment
"". This script adds a signature only if the address has an "@" in
 it, i.e. the mail is external. It can also add fortune to your mail.
Here's how you use it:

Create a $HOME/.signature with your signature in it.
Save the script as
Add this line to $HOME/.mailrc:

set sendmail=/your/home/bin/

This works for plain mails, but not for sun attachments, since the signature
 will just be appended at the very end of the whole lot.

4. A long perl script

The perl script is attached to this mail as "signmail.perl". Use it like this:

Create a $HOME/.signature with your signature in it.
Save the script as signmail.perl.
You need perl (of course), in this case in /usr/local/bin.
Add this line to $HOME/.mailrc:

set sendmail=/your/home/bin/signmail.perl

This is a very nice solution, and the one I chose. It adds the signature to the
end of each mail, before all the attachments. It has one limitation though, which I discovered:
There mustn't be any long lines with ------- in your mail
 (no more than 9 hyphens in a row) or the signature will be inserted there.
This is because such lines are used to separate the attachments.

5. Joes Mailtool

>From I got info on his solution, a more complete package called Joes Mailtool.
I quote from the description:

 You may startle about those two Scripts with a total Size of 16 kB, but this
is what you get from it:
-- Most Mails (unless you use cryptographic Signatures heavily) will be
   composed and sent *exactly* the Way you do it now - no additional Fuss
   to be made.
-- Does .signature's and fancy Headers; You can have separate Signatures
   for JoesMailtool and "the Rest" (think of Newsreaders with their Line
   Limit on Signatures)
-- You can run ROT13 and ispell on the outgoing Mail (and choose whether
   you ROT13 first and .sig later or vice versa ;-)
-- You have a full Range of PGP and RIPEM Processing at your Choice

I haven't tried it myself due to lack of time, but I recommend that you check it out.
Get automatic info by sending a mail to, or get the tool from

Have fun!


Marcus Filipsson, Research Engineer Email:
Tel: +46-(0)46-108449 Fax: +46-(0)46-104210
Dept. of Linguistics, Lund University WWW:
Helgonabacken 12, 223 62 Lund, SWEDEN
X-Sun-Data-Type: shell-script
X-Sun-Content-Lines: 55

#! /bin/sh
# @(#)fmt_mail 1.5 89/03/17 SMI
# modified to add signatures - Bruce Barnett
# modified to add headers - Gary Parker
# modified to add a fortune to signature - Gary Parker
# modified to run with the Solaris grep - Earl Manning
# Create a new fortune file for append to signature
#if [ -f ${HOME}/.fortdat ]; then
# rm ${HOME}/.fortdat
#if [ -x /usr/games/fortune ]; then
# /usr/games/fortune -s >${HOME}/.fortdat
# Test to see if everything is local, if local then no signature
for i
do name=$i
# Add custom headers if they exist. Comment out if not wanted.
#cat ${HOME}/.mymailheaders - | \
# Don't mess with this stuff ...
#solves problem of read line discarding leading blanks which are necessary
#for correct interpretation of continuation lines in mail headers
while read line
        echo "$line"
        case $line in
        "") break ;;
cat) | \
# taken out on 12-6-94 because could not send uuencode messages
#fmt -s -80) | \
# Add signature if it exists. Comment out otherwise.
(if `echo $name | grep -s "@" > /dev/null `
        then cat - ${HOME}/.signature
        else cat -
fi) | \
# Add fortune to end if it exists. Comment out otherwise.
#cat - ${HOME}/.fortdat | \
# Don't mess with this either
/usr/lib/sendmail "$@"
X-Sun-Data-Type: default-app
X-Sun-Data-Name: signmail.perl
X-Sun-Content-Lines: 156

# What Goes On Here
# At the very simplest, this program accepts data on STDIN from MailTool,
# appends the user's $HOME/.signature file to the stream, and pipes the
# whole mess to sendmail.
# However, enclosures are a sticky point. Therefore, the program must
# not simply append the signature, but must determine where it should
# append the signature without corrupting any enclosures in the message.
# If a person sends a message and adds an enclosure(s), the signature is
# appended into the main message body (which is, actually, the first enclosure
# in the message.) If the sender sends an enclosure without any message
# body, the program detects this and simply creates an additional enclosure
# for the signature file. It seems to work.
# To activate this program via mailtool, add the following line to your
# .mailrc file:
# set sendmail=/path/to/signmail
# Copyright (c) 1994 Clay Luther. August 1994.
# This software is protected under the GNU Software License Agreement.


# Version 1.0
# Version 1.1 - fixed to work with perl5; fixed tainted variable problem

$SIGFILE = $ENV{'HOME'} . "/.signature";
# ^^^^^^^^^^^ at least that's where most are

$LF = "\n";
$MARKER = "----------";

$ARGUMENTS = join(' ', @ARGV);

$LINES = &sigLines();

# Setup the environment
$ENV{'PATH'} = ''; # '/bin:/usr/bin';
$ENV{'SHELL'} = '/bin/sh';
$ENV{'IFS'} = '' if $ENV{'IFS'} ne '';
@INC = $INC[$#INC - 1];
die "Perl library is writable by world!!!\n" if $< && -W $INC[0];

# Untaint the arguments
$ARGUMENTS =~ /^([\w.]*)$/;

open(MAIL, "| /usr/lib/sendmail -oi -t $ARGUMENTS") || die "can't fork: $!\n";

while (<STDIN>)
  $SAVE_ = $_;
  if ($HEADERS)
    if (/^Content-Type:\s*X-sun-attachment/) { $HERALDENCLOSURE = 1; }
    if (/^\n/)
      print MAIL "X-Signmail: $VERSION. A Mailtool extension by Clay Luther.\n";
      $HEADERS = 0;
      if (/^X-Sun-Data-Name: text/)
      elsif (/^$MARKER/)
        if ($FOUNDMAINTEXT)
          $HERALDENCLOSURE = 0;
      elsif (/^X-Sun-Content-Lines:/)
          if ($1)
            local($tlines) = $1 + $LINES + 2;
            $SAVE_ = "X-Sun-Content-Lines: $tlines\n";
  print MAIL $SAVE_;


close(MAIL) || die "pipe exited $?\n";

exit 0;


sub printSignature
  if (-r $SIGFILE)
    if (open(SIGNATURE, "<$SIGFILE"))
        print MAIL $LF . $MARKER . $LF;
        print MAIL "X-Sun-Data-Type: text\n";
        print MAIL "X-Sun-Data-Description: text\n";
        print MAIL "X-Sun-Data-Name: signature\n";
        print MAIL "X-Sun-Charset: us-ascii\n";
        print MAIL "X-Sun-Content-Lines: $LINES\n\n";
        print MAIL "\n\n";
      while (<SIGNATURE>) { print MAIL $_; }

sub sigLines
  if (! -r $SIGFILE) { return 0; }
  open(SF,"<$SIGFILE") || return 0;
  local($cnt) = 0;
  while (<SF>) { $cnt++; }
  return $cnt;

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:27 CDT