3. Using the list as a UNIX alias file

        This section explains how to use the directory as an alias list
on a UNIX system, in conjunction with the "mail" program. This
arrangement enables you to use a code instead of the address in the mail
command. If you don't have UNIX, ignore this section. If you use a
command other than "mail" to send messages, you will have to figure out
how to adapt the mechanism described here to your mailer in order to
gain any benefit from this section. (There are other mailers that run on
some UNIX systems, for example "elm", "pine", and "smash". I know very
little about them, but they are unlikely to use the same format for
aliases.) The first paragraph gives a summary of what to do; if you
don't understand the terms, the rest of this section gives more details.
At the end, I describe one other useful feature of the UNIX mail
program. Some other systems have similar capabilities, but I don't know
how they work.

        Warning: The shell script does not work on Red Hat Linux.

        The procedure described below is quite simple, but does involve
passing the directory through a shell script (which is provided here).

        Once you have the aliasing system st up, you will be able to
send email to a person on the list by using an abbreviated form of the
person's name rather than the full email address. For example, the
abbreviated form of my name is "PhillipsNC", and you will be able to
email to me with the command "mail PhillipsNC" instead of
"mail ncp_9117@darkwing.uoregon.OMITthisedu". The abbreviations are
generated by the shell script (a type of computer program made up of
UNIX commands) "MakeAlias", and generally consist of the family name
(first letter capitalized), followed by one or occasionally more
initials. (There are a few exceptions to this rule, usually relating to
very long names or to organizations; they are identified by the shell
script "CheckAlias".) You can modify them to suit yourself with any
editor. Be careful, however: an alias may not work if it matches the
first, last, or account name of any user on your system. (That is why I
put initials in the aliases.)

        The following one time setup is required: Save the two shell
scripts (kindly provided by Igor Markov) at the end of this section in
files called "MakeAlias" and "CheckAlias" respectively (these names
appear at the beginning of each one). Then execute the commands
"chmod u+x MakeAlias" and "chmod u+x CheckAlias". (Here, and elsewhere,
you are perfectly free to use file names other than those suggested
here. Indeed, Igor Markov called these programs "2ali" and "chka"
respectively. Note, however, that they will under certain circumstances
give error messages, and the error messages in the versions here assume
the programs have the names used here.)

        Each time you receive a new directory:
        (1) Save it to a file called "List".
        (2) Edit this file to remove all mail headers and any other line
that does not start "# " and does not contain an email address. (No such
lines should be present, but I might have made a mistake. You do not
need to carefully check the file for this.)
        (3) Make sure the file "AliasList" does not exist.
        (4) Give the command "sh MakeAlias List AliasList". This creates
an alias list suitable for use with the UNIX mail program, with
computer-generated aliases usually consisting of the family name (initial
letter capitalized), followed by the initials provided in the entry (also
capitalized if they were capitalized in the entry).
        (5) (Optional) Give the command "sh CheckAlias List" to get a
list of any entries treated unusually by the alias creation program.
(For example, excessively long family names will be truncated and most
non-alphabetic characters will be deleted.)
        (6) Attach the file "AliasList" (created by the previous command)
to the end of your .mailrc file (or replace the old version if you have
already done this). Note that you no longer need the file "AliasList".

        You can update your alias list after each new update in the same
way. Again, it is necessary to delete the mailing information attached
to the beginning of the update, but it is not necessary to remove
announcements or any other line starting with "# ". You should also
delete any duplicated aliases.

        For those who aren't familiar with the terms used above: A UNIX
account should come equipped with a file called ".mailrc". (Note that
the "ls" command ignores files whose names start with a period; use
"ls -a" to see them. Other such files in your account probably include
".login" and ".cshrc".) If you don't have such a file, you can always
create one. Your account probably came with a "standard" .mailrc file,
made up by your system manager. This file sets a number of defaults in
the mail program: how much of the mail header you see, which editor you
get if you decide to switch to the editor in the middle of typing a
message, what happens to undeleted mail when you finish reading mail,
etc. Here is the beginning of may .mailrc file (all except my alias
list):

# @(#)Mailrc 1.3 88/02/08 SMI;
set editmessagewindow
set alwaysignore
set askcc
set autoprint
set hold
set indentprefix="> "
set metoo
set record=/usr/spool/mail/phillips
set cmd="lpr -p &"
set crt=15
set EDITOR=/usr/ucb/vi
set PAGER="cat -s | more -22 -c"
set prompt="{Mail}& "
set SHELL=/bin/csh
set VISUAL=/usr/ucb/vi
set folder=email
set outfolder
ignore apparently-to date errors-to from id in-reply-to \
         message-id precedence received references remailed-date \
         remailed-from return-path sent-by status via


(I have changed a few things in it, so it is not quite the same as what
I was originally given.)

        To use the file generated by the shell script as an alias list
in this file, run the directory through the shell script as described
above, and attach the output to the end of the .mailrc file, being sure
you don't delete what was already there by accident. I have discovered
(by trial and error; no documentation that I have found mentions this)
that the symbol #, followed by a blank, can be used as a comment
indicator in the .mailrc file. Thus, any part of a line following the
combination "# " (#, blank) will be ignored. The shell scripts below
simply copy such lines from the directory to the alias file (so that you
know who is who). However, when a file is saved from mail, some lines of
mailing information are also saved, and they must be removed.
Any parts of the header that (presumably due to my error) do not start
with the combination "# " must also be removed.  Finally, if you are
saving an update, you should remove the old version of any duplicated
aliases. (This will occur when an update includes a change of address.
If you don't, you will end up, at least on my system, sending messages
to both the old and new addresses.) (Note: At least one person, Bill
Arveson, has found that the blank following the symbol # is not
needed.)

        Now the file is ready for use. The entry for me will say:

alias PhillipsNC   ncp_9117@darkwing.uoregon.OMITthisedu

(The address has been munged to defeat spammers' address harvesters.)
This says that the command "mail PhillipsNC" will do the same thing as
"mail ncp_9117@darkwing.uoregon.OMITthisedu". If you don't like the
abbreviation, all you have to do is replace "PhillipsNC" by something
else in the .mailrc file, using your favorite editor. (There is no
reason you should like the abbreviations; they are a compromise
intended to be at least usable by everybody.) One word of warning: on
at least one system (at the Mittag-Leffler Institute) I got into trouble
with an alias that matched the login name or real last name of some
other user.

        Here are the shell scripts. Please observe the instructions in
the headers to these two programs. (Innocuous looking shell scripts can
be fiddled so that they do nasty things like deleting all your files.)

MakeAlias:
==========================CUT HERE======================================
#!/bin/sh

# MakeAlias, Igor Markov, Mar 15, 1994 (with name change by N. C. Phillips)

# Run this program only if you received it directly
# from N. Christopher Phillips <
# or Igor Markov               <imarkov@math.ucla.edu>
# you may make modifications to this program for personal use,
#                                    BUT not re-distribute it.

AWK=gawk
# AWK=awk
# AWK=gawk
# AWK=nawk

if [ "$2 " = " " ]; then
   echo "To run: MakeAlias InputFile OutputFile"
   echo "This program converts directory files into alias lists"
   exit 1
fi

if [ ! -f $1 ]; then
    echo "File <"$1"> does not exist!"
    exit 1
fi 

echo " Convert directory from <$1> into an alias file <$2>..."
\rm -f $2 > /dev/null 2>&1
sed "/^[ *-~]/ s/([ -'*-~]*)//g" $1 | ( $AWK '
/^#|^ *#|^$|^ *$/
$0 !~ /^#|^ *#/{if (NF>1) 
                {LINE="#"; for (i=1;i<NF;i++) LINE=sprintf("%s %s",LINE,$i);
                 print LINE; S=""; F=1;
                 if ($0 ~ ",")
                       for(i=1;i<NF;i++)
                       { S=sprintf("%s%s",S,$i); if ($i ~ ",") {F=i;i=NF} }
                 else S=$1;
                 L=length(S);
                 if (substr(S,L,1)==",") S=substr(S,1,L-1);
                 ALIAS=sprintf("%.12s",S);
                 for (i=F++; F<NF; F++) ALIAS=sprintf("%s%.1s",ALIAS,$F);
                 if (ALIASES[ALIAS]++!=0)
                 ALIAS=sprintf("%s%d",ALIAS,ALIASES[ALIAS]);
                 printf("alias %-20s %s \n",ALIAS,$NF); }}
END{}' | sed "/^alias/ s/[!-$&-*,:;[-^{-~]//g" > $2 ) 2> /dev/null && echo " Done" || echo " Error !"
\rm -f tmp$$ > /dev/null 2>&1
==========================CUT HERE======================================

CheckAlias:
==========================CUT HERE======================================
#!/bin/sh

# CheckAlias, Igor Markov, Mar 15, 1994 (with name change by N. C. Phillips)

# Run this program only if you received it directly
# from N. Christopher Phillips <ncp_9117@darkwing.uoregon.OMITthisedu>
# (delete "_9117" and also make the obvious omission)
# or Igor Markov               <imarkov@math.ucla.edu>
# you may make modifications to this program for personal use,
#                                    BUT not re-distribute it.


AWK=gawk
# AWK=awk
# AWK=gawk
# AWK=nawk

if [ "$1 " = " " ]; then
   echo "To run: CheckAlias DirFile "
   echo "This program warns about potential problems with MakeAlias"
   exit 1
fi

if [ ! -f $1 ]; then
    echo "File <"$1"> does not exist!"
    exit 1
fi 

$AWK ' { LN++ }
$0 !~ /^#|^ *#/ { if (NF>1)
                  {  if ( $NF ~ /[!-$&-*,:;?[-^`{-~]/)
              print sprintf("Line%.4d / Suspicious email address: %s ",LN,$NF); 
                     S=""; F=1;
                     if ($0 ~ ",") for (i=1; i<NF; i++)
                         { S=sprintf("%s%s",S,$i); if ($i ~ ",") {F=i;i=NF} }
                     else S=$1;
                     L=length(S); if (substr(S,L,1)==",") S=substr(S,1,L-1);
                     ALIAS=sprintf("%.12s",S);
                     for (i=F++; F<NF; F++) ALIAS=sprintf("%s%.1s",ALIAS,$F);
                     if ( length(S) > 12 ) 
         print sprintf("Line%.4d / Last name truncated: %s -> %s",LN,S,ALIAS);
                     if ( ALIAS ~ /[!-$&-*,:;@[-^`{-~]/)
         print sprintf("Line%.4d / Funny characters will be deleted from alias: %s ",LN,ALIAS);
                  }
                }   
' $1 2> /dev/null && echo " Done" || echo " Error !"
==========================CUT HERE======================================

        Here is the other comment on UNIX mail referred to above.

        I have noticed that a number of people send copies of their
messages to themselves as well as to the intended recipient. On a UNIX
system, it is possible to do this automatically, instead of entering
your name on the "Cc: " list every time you send a message. If you put
the lines:

set folder=<directory>
set record=<filename>

in your .mailrc file, then a copy of every outgoing message will be put
in a file with the given name in the given directory. You can read the
messages you put there with the mail program via the command

mail -f <directory>/<filename>

Of course, if you are in the directory, you don't have to include it in
the command.
        I use instead the .mailrc line

set record=~/.mail

The effect of this is to put a copy of every outgoing message back into
my incoming mail. To use this device, you need to figure out the name of
the file containing your incoming mail. One warning, however: on many
systems, the incoming mail is very rarely backed up. To combat this
problem, I have also installed the following file in my home directory,
under the name ".logout":

#### This .logout file will be executed when you sign off (if you use csh).

## Uncomment this line if you want your screen cleared when you sign off.
clear ; sleep 1
/usr/bin/cp /usr/spool/mail/phillips ~/reserve/UnreadMail

The last line copies my incoming mailbox to a file (which will be
overwritten if it already exists) called UnreadMail in the directory
(which must already exist) called reserve, every time I logout.