Annotation of pgp/contrib/mailx/mailer, revision 1.1.1.1

1.1       root        1: To: [email protected]
                      2: Subject: Re: Request for Mailer Scripts
                      3: Newsgroups: alt.security.pgp
                      4: In-Reply-To: <[email protected]>
                      5: Organization: Little to None
                      6: Cc: 
                      7: Message-Id: <[email protected]>
                      8: Date: Tue, 2 Mar 93 23:51:30 EST (-0500)
                      9: From: [email protected] (Rob Stampfli)
                     10: 
                     11: In article <[email protected]> you write:
                     12: >I am trying to collect mailer scripts for use with PGP!  Basically, if
                     13: >you have written a script to integrate PGP into some mailer, mailer
                     14: >agent, mail reader, news reader, or anything like that, please send me
                     15: >a copy of the script, any documentation you may have, and instructions
                     16: >for use.
                     17: 
                     18: Here is a shellscript that I use with the "mailx" mailer to send encrypted
                     19: messages under Unix.  Basically, to use this script, I have the following
                     20: command in my .mailrc file:  "set sendmail=/the/full/path/name/to/this/script"
                     21: This has the effect of causing mailx to invoke the script, rather then
                     22: /bin/mail as the Unix mailer.  In this respect, it can be used by any mailer
                     23: that can be made to pass off the to-be-mailed message to a script rather
                     24: than the /bin/mail program.  The script is written for the Korn Shell,
                     25: although it would be fairly trivial to modify it to work with the standard
                     26: Bourne Shell.  It looks for two special mail "addresses":
                     27:        enc=pgp_identifier
                     28:        sig=pgp_identifier
                     29: The first form "enc=pgp_identifier" or "encrypt=pgp_identifier" specifies
                     30: that the pgp public key uniquely identified by <pgp_identifier> be used to
                     31: encrypt the message.  The second "sig=pgp_identifier" specifies that the
                     32: secret key identified by <pgp_identifier> be used to sign the message.
                     33: Either or both can be used.  If enc is given, the message is encrypted,
                     34: optionally signed, ascii armored and delivered to the real mailer for
                     35: distribution.  If only sig is given, the message is signed in +clearsig
                     36: mode and the result passed on.  In any case, the header is exempt from
                     37: the process and is passed on intact.
                     38: 
                     39: To send an encrypted message, address the mail to both the recipient and
                     40: the mail address "enc=pgp_identifier".  Ditto to sign a message.  Mailx
                     41: allows use of a "bcc: " field (Blind copy-to), so the enc= or sig= can
                     42: be optionally specified there.
                     43: 
                     44: There are a few gotchas:  Since pgp grabs the first key that matches
                     45: the pgp_identifier, you can encrypt to the wrong key if you specify
                     46: pgp_identifier too loosely.  Also, if you break out of the script, it
                     47: delivers a null message.  
                     48: 
                     49: Without further ado, here is the script:
                     50: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                     51: #!/bin/ksh
                     52: # This script is invoked by adding the line "set sendmail=pgpmail" to your
                     53: # .mailrc file.  mailx then invokes pgpmail instead of /bin/mail to deliver
                     54: # email.  This script checks whether encryption, a signature, or both are
                     55: # specified, and automatically performs whatever is required.
                     56: #
                     57: # Modified 6-Mar-93 by [email protected] to include multiple recipients
                     58: #
                     59:  
                     60: trap "" 1 2 3                          # req'd since this can run in bg
                     61: exec 2>/dev/tty                                # can be "exec 2>/dev/null"
                     62: 
                     63: nl="" en="" sg=""
                     64: for i                                  # for each argument...
                     65: do
                     66:   case "$i" in                         # look for encryption specifier...
                     67: #     Unclear this will work
                     68: #  *encrypt=*) en="`sed 's/.*=//'`"    # this line req'd if SHELL=sh
                     69:   *encrypt=*)  en="$en ${i#*=}";;      # this line is faster if SHELL=ksh
                     70:   *enc=*)      en="$en ${i#*=}";;      # this line is faster if SHELL=ksh
                     71:   *sig=*)      sg="${i#*=}";;          # a pgp signature specification...
                     72:   *)           nl="$nl $i";;           # a real mail address...
                     73:   esac
                     74: done
                     75: 
                     76: [ X = "X$en" -a X = "X$sg" ] && exec /bin/rmail "$@"   # not a pgp request
                     77: 
                     78: [ Xy = "X$sg" -o Xyes = "X$sg" ] && sg="Robert E. Stampfli" # just for me...
                     79: 
                     80: # If we get here, encryption or sig *was* specified:
                     81: (
                     82:   OIFS="$IFS"                          # needed to preserve tabs in header
                     83:   IFS='
                     84: '
                     85:   while read x                         # read and process header intact
                     86:   do
                     87:     print - "$x"                       # ksh only -- for sh, use echo
                     88:     [ X = "X$x" ] && break
                     89:   done
                     90:   IFS="$OIFS"                          # reset field separators
                     91:   if [ X = "X$sg" ]; then              # no signature specified:
                     92:     pgp -feat "$en"                    #   encrypt the message...
                     93:   elif [ X = "X$en" ]; then            # no encrypt specified:
                     94:     sed -e 's/^From />From /' |                #   pre-convert mail glitcher...
                     95:     pgp -fast +clearsig=on -u "$sg"    #   sign msg in MIC-CLEAR mode...
                     96:   else                                 # both encrypt and sig specified:
                     97:     pgp -feast "$en" -u "$sg"          #   encrypt and sign armored...
                     98:   fi
                     99:   echo "Encryption phase completed" 1>&2
                    100: ) | /bin/rmail $nl
                    101: 
                    102: -- 
                    103: Rob Stampfli  [email protected]      The neat thing about standards:
                    104: 614-864-9377  HAM RADIO: [email protected]  There are so many to choose from.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.