Debian Codegraph @

contrib/mail-alias

raw symbols SCIP
1 #!/bin/sh
2 #
3 # nn-expand-mail-alias -- expands aliases from ~/.mailrc file for nn.
4 #
5 # To use, put the following in your ~/.nn/init file:
6 #
7 # set mail-alias-expander nn-expand-mail-alias
8 # and put this file somewhere in your path, making it executable. I use
9 # set mail-alias-expander /usr/local/lib/nn-expand-mail-alias
10 # but the choice is up to you.
11 #
12 # Written by Scott Hannahs, Bitter National Magnet Lab, MIT, August 1991
13 # Complaints, comments, ideas to [email protected]
14 # Tested on Silicon Graphics, IRIX 3.3.1
15 #
16 # Minor banging by <[email protected]> to handle alias value fields
17 # which contain doublequote characters, e.g.
18 #
19 # alias Foo "Foobar the Great <[email protected]>"
20 #
21 # (the doublequotes are stripped in the expansion), and to handle multiple
22 # spaces after the token "alias".
23 #
24 # Also added some error detection and signal traps; tested on SunOS 4.1.1.
25 #
26 # Exit codes: 0 -- normal termination
27 # 1 -- parm error
28 # 2 -- file does not exist
29 # 3 -- trap
30 #
31 # Thanks to bug reports from
32 # Andy Jacobs and others
33 #
34 if [ z$1 = z ]; then
35 myname=`basename $0`
36 echo "$myname: usage is $myname workfile"
37 exit 1
38 fi
39
40 if [ ! -f $1 ]; then
41 myname=`basename $0`
42 echo "$myname: $1 does not exist or is a directory"
43 exit 2
44 fi
45
46 TMP_DIR=/usr/tmp
47
48 trap "rm -f ${TMP_DIR}/nn.alias.$$ ; exit 3" 0 1 2 3 15
49
50 ALIAS_LIST=""
51 ADDRESS_LIST="`head -1 $1 | sed -e s/To://`"
52 until [ "$ALIAS_LIST" = "$ADDRESS_LIST" ] ; do
53 ALIAS_LIST="`echo "$ADDRESS_LIST"| sed -e 's/,/ /g' `"
54 ADDRESS_LIST=""
55 for ALIAS in $ALIAS_LIST ; do
56 ADDRESS=`grep '^[ ]*alias[ ][ ]*'"$ALIAS"'[ ]' ${HOME}/.mailrc |\
57 sed -e s/'^[ ]*alias[ ][ ]*'"$ALIAS"'[ ][ ]*'// |\
58 sed -e s/'"'//g`
59 if [ "$ADDRESS" ] ; then
60 ADDRESS_LIST="$ADDRESS_LIST $ADDRESS"
61 else
62 ADDRESS_LIST="$ADDRESS_LIST $ALIAS"
63 # for elm alias expansion use the following line instead of the previous.
64 # ADDRESS_LIST="$ADDRESS_LIST "`elm -c "$ALIAS" | cut -f3 -d\ `
65 fi
66 done
67 done
68 echo "To:${ADDRESS_LIST}" > ${TMP_DIR}/nn.alias.$$
69 tail +2 $1 >> ${TMP_DIR}/nn.alias.$$
70 mv -f ${TMP_DIR}/nn.alias.$$ $1
71
72 exit 0