0

I have Postfix installed and configured to pass mail to Procmail. I have Procmail configured to pass the email to a Python script. I also notice that Procmail is placing a copy of the same email into a file at /var/spool/mail/<username>. I don't want a copy of the message to be retained there or anywhere on the server. Is there a way to configure Procmail to drop the message after it is sent to the Python script?

In my .procmailrc configured like so:

:0Wc:
| env python3 /home/user/python/script.py
:0
* ^From:.*@.*
/dev/null

This however does not work. The message still ends up /var/spool/mail/<username>.

tripleee
  • 1,416
  • 3
  • 15
  • 24
Dave
  • 155
  • 1
  • 1
  • 6
  • Your second recipe should certainly have delivered to `/dev/null` regardless of the outcome of the first. If it didn't, there is an error somewhere, but without seeing Procmail's log file, it's impossible to say more. Perhaps see also http://www.iki.fi/era/mail/procmail-debug.html – tripleee Feb 10 '21 at 07:23
  • Belatedly, if you want to do something unconditionally, just don't put a condition at all. `^From:.*@.*` looks like you are desperately trying to match all messages, but if that's the case, taking it out will match even the ones which don't have a `From:` header with a `@` somewhere in it. (Also, the trailing `.*` is superfluous.) – tripleee Dec 31 '21 at 06:10

1 Answers1

2

This is exactly how Procmail operates out of the box. Recipes are executed sequentially until a delivering action is taken, or until we run out of recipes, and deliver to $DEFAULT. Writing to a mailbox, piping to a command, or forwarding to a different recipient are all delivering actions.

However, your first recipe has a c flag, which explicitly disables this behavior, and causes another delivery to be attempted even after this action completes.

In so many words, take out the c flag (and probably the second colon, too; or name an explicit lock file after it).

The old (not so) mini-FAQ has a section about locking which coincidentally also has a passage about your main question, and a discussion of "deliveredness".

tripleee
  • 1,416
  • 3
  • 15
  • 24