procmail
[Top] [All Lists]

Re: encrypting the body?

1996-08-12 10:38:24
I have two mail accounts: one personal, one work-related.  They
are on different servers but both have procmail.

The thing I want to do is take SOME of the messages at the personal
account and send them encrypted to my work account.  PGP is not
available.

So, I want to do something like this to the header:

      formail -I "To: me(_at_)work(_dot_)account"

and something like this to the body:

      crypt key | uuencode filename

but how do I put these things into a single recipe?

First, if you *really* want to do something like this, then please
acquire and install "metamail", which is designed for doing things like
encoding files for e-mail.

You didn't say what the criteria for forwarding was, but I'll improvise.
Let's assume that any mail directly addressed to you, with with the word
"work" in the subject will be forwarded to your "work" account with the
body encrypted.

# First, set these handy variables
TRIGGER="work"
WORKADDR=me(_at_)work(_dot_)com

# More modern verisons of crypt look for the environment variable 
# "CrYpTkEy" if given the '-k' option.
CrYpTkEy="secret"       # choose an appropriate encryption key

# See if addressed *directly* to me, and ..
# ..has the trigger keyword # anywhere in the subject, and..
# ..has not already been forwarded
:0
* $ To:(.*[^a-z0-9])?$LOGNAME(@|[^0-9a-z]|$)
* $ Subject:.*$TRIGGER
* $!X-Loop: $LOGNAME(_at_)$HOST
{
    # Get a unique filename incase the file is actually uudecoded inplace
    UUFILE=`date +'mail.%Y.%m.%d-%H:%M:%S`

    # now let's encrypt the body
    :0fb
    | crypt -k | uuencode newmail $UUFILE

    # Now let's prepare the headers for forwarding the mail, and mark it
    # so we don't loop
    :0fh
    | formail   -I"Resent-To: $WORKADDR" \
                -I"X-Loop: $LOGNAME(_at_)$HOST"

    # Forward the mail onto my work address
    :0
    ! $WORKADDR
}

This recipe should to the trick; of course, you'll have to test it for
yourself.

To do encapsulations through e-mail correctly, you should use the MIME
standards.  The "mm" (MetaMail) package is freely available, and
implements a "uuencode" replacement called "mmencode".  Here is the
"rationale" of MIME (from its man page):

          Mimencode is intended to be a replacement for uuencode for
          mail and news use.  The reason is simple:  uuencode doesn't
          work very well in a number of circumstances and ways.  In
          particular, uuencode uses characters that don't translate
          well across all mail gateways (particularly ASCII <-> EBCDIC
          gateways).  Also, uuencode is not standard -- there are
          several variants floating around, encoding and decoding
          things in different and incompatible ways, with no
          "standard" on which to base an implementation.  Finally,
          uuencode does not generally work well in a pipe, although
          some variants have been modified to do so.  Mimencode
          implements the encodings which were defined for MIME as
          uuencode replacements, and should be considerably more
          robust for e-mail use.

Here's the same recipe, but modified to use "mimencode"

# First, set these handy variables
TRIGGER="work"
WORKADDR=me(_at_)work(_dot_)com

# More modern verisons of crypt look for the environment variable 
# "CrYpTkEy" if given the '-k' option.
CrYpTkEy="secret"       # choose an appropriate encryption key

# See if addressed *directly* to me, and ..
# ..has the trigger keyword # anywhere in the subject, and..
# ..has not already been forwarded
:0
* $ To:(.*[^a-z0-9])?$LOGNAME(@|[^0-9a-z]|$)
* $ Subject:.*$TRIGGER
* $!X-Loop: $LOGNAME(_at_)$HOST
{
    # now let's encrypt the body using mimencode
    :0fb
    |   echo "MIME-Version: 1.0" ; \
        echo "Content-Type: application/crypt" ; \
        echo "Content-transfer-encoding: base64" ; \
        echo "" ; \
        crypt -k | mimencode -b

    # Now let's prepare the headers for forwarding the mail, and mark it
    # so we don't loop
    :0fh
    | formail   -I"Resent-To: $WORKADDR" \
                -I"X-Loop: $LOGNAME(_at_)$HOST"

    # Forward the mail onto my work address
    :0
    ! $WORKADDR
}

G'luck.

_____________________________________________________________________
Alan Stebbens <stebbens(_at_)sgi(_dot_)com>      http://reality.sgi.com/stebbens
Digital TV, Silicon Interactive Group,  Silicon Graphics, Inc.  (SGI)
M/S:9L991,     2011 N. Shoreline Blvd.,     Mountain View, CA   94043
PGP Key Fingerprint: 94 A7 4B AB 1C F0 4D 92  DD BC B5 D7 11 A0 DC B3

<Prev in Thread] Current Thread [Next in Thread>
  • encrypting the body?, Kevin Kelleher
    • Re: encrypting the body?, Alan Stebbens <stebbens(_at_)anywhere(_dot_)engr(_dot_)sgi(_dot_)com> <=