2

I'm struggling to get procmail to first transform, and then forward, a received email. Here's what I'd like to do:

:0 f
| ~/bin/encryptemail.pl | mail foobar@gmail.com

That is, I want to run the encryptemail.pl script on the body of email that I receive, and then forward the encrypted email to foobar@gmail.com .

Piping the output to mail sort of works, except that the forwarded email is wrapped in a second set of headers.

I'd like to cleanly forward the encrypted email so that the body of the original email has been replaced with the encrypted content.

1

I'd take a look at the recipes on the Procmail Documentation Project website, specifically this recipe: 15.7 Forwarding sensitive messages in encrypted format.

  #   by [alan]
  #   See if addressed *directly* to me, and ..
  #   ..has not already been forwarded

  KEY             = "TheMagic"
  FORWARD_EMAIL   = "foo@example.com"

  :0
  *$   ^To:.*$LOGNAME(@|[^0-9a-z]|$)
  *$ ! ^$MYXLOOP
  {
      # now let's encrypt the body using mimencode

      :0 fbw
      |   echo "MIME-Version: 1.0" ;                              \
          echo "Content-Type: application/crypt" ;                \
          echo "Content-transfer-encoding: base64" ;              \
          echo "" ;                                               \
          crypt $KEY | mimencode -b

      #   Now let's prepare the headers for forwarding the mail,
      #   and mark it so we don't loop

      :0 fhw
      | $FORMAIL   -I"Resent-To: $FORWARD_EMAIL" -I"$MYXLOOP"

      :0
      ! $FORWARD_EMAIL

  }    

Instead of calling this line:

crypt $KEY | mimencode -b

You should be able to substitute your call in it's place:

~/bin/encryptemail.pl | mimencode -b
  • Thanks! I'm actually trying to encrypt them with GnuPG using Mike Cardwell's gpgit script. I think that there's some conflict, in that gpgit wants to process the whole message, headers and all, but the procmail script you gave me is snipping off the headers and passing through the body. – loseeka Jun 25 '13 at 19:41
  • Right it's doing the body, but I'd look through the other recipes, there are other examples that might fit your needs. – slm Jun 25 '13 at 19:49
1

If you could change your script to accept and pass on (i.e. simply copy) the headers, you could do this:

:0
| ~/bin/encryptemail.pl | sendmail -oi foobar@gmail.com

Equivalently, first replace the body, then send the whole modified message:

:0fb
| ~/bin/encryptemail.pl
:0
! foobar@gmail.com

The f flag cannot meaningfully be used on a delivering recipe; it instructs Procmail to replace the message (or, with the b flag too, the body) with the output from the commands you pipe to, and continue processing with the thusly modified message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.