Question

I use procmail to forward certain 'From' to a Gmail account

/home/user/.procmailrc

:0c
* !^FROM_MAILER
* ^From: .*aaa | bbb | ccc.*
! ^X-Loop: user@gmail\.com
| formail -k -X "From:" -X "Subject:" \
-I "To: user@gmail.com" \
-I "X-Loop: user@gmail.com"
:0
* ^From: .*aaa | bbb | ccc.*
$DEFAULT

This works fine but on my server inbox I also get an 'undelivered' mail

The mail system <"^X-Loop:"@my-name-server.com> (expanded from <"^X-Loop:">): unknown user: "^x-loop:"

How can I avoid this?

I've tried to delete these mails. This is not the best way.

Anyway It does not work.

:0B * <"\^X-Loop:"@my-name-server.com> 
/dev/null 
Was it helpful?

Solution

The recipe contains multiple syntax errors, but the bounce message comes because you lack an asterisk on one of the condition lines, which makes it an action line instead.

The general syntax of a Procmail recipe is

:0flags       # "prelude", with optional flags
* condition   # optional, can have zero conditions
* condition   # ...
action

The action can be a mailbox name, or ! followed by a destination mailbox to forward the message to, or | followed by a shell pipeline.

So your first recipe is "If not from mailer and matching From: ..., forward to ^X-Loop:.

The | formail ... line after that is then simply a syntax error and ignored, because it needs to come after a prelude line :0 and (optionally) some condition lines.

Additionally, the ^From: regex is clearly wrong. It will match From: .*aaa or bbb (with spaces on both sides, in any header, not just the From: header) or ccc.

Finally, the intent is apparently to actually forward the resulting message somewhere.

:0c
* ! ^FROM_MAILER
*   ^From:(.*\<)?(aaa|bbb|ccc)
* ! ^X-Loop: user@gmail\.com
| formail -I "X-Loop: user@gmail.com" | $SENDMAIL $SENDMAILFLAGS user@gmail.com

If you simply want to forward the incoming message, the other -X and -I and certainly -k options are superfluous or wrong. If they do accomplish something which is irrelevant for this question, maybe you need to add some or all of them back (and also remember to extract with -X any new headers you add with -I, as otherwise they will be suppressed; this sucks).

Your second recipe is also superfluous, unless you have more Procmail recipes later in the file which should specifically be bypassed for these messages. (If so, you will need to fix the From: regex there as well.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top