procmail/formail syntax question

Giorgos Keramidas keramida at ceid.upatras.gr
Sun Oct 23 16:27:15 PDT 2005


Please do *not* remove the mailing list from the Cc: header, unless
there is a very good reason (i.e. confidential information in the
message text).

On 2005-10-23 19:11, stan <stanb at panix.com> wrote:
>On Mon, Oct 24, 2005 at 01:13:18AM +0300, Giorgos Keramidas wrote:
>>On 2005-10-23 17:49, stan <stanb at panix.com> wrote:
>>>On Sun, Oct 23, 2005 at 10:07:17PM +0200, Roland Smith wrote:
>>>>On Sun, Oct 23, 2005 at 03:09:51PM -0400, stan wrote:
>>>>> I'm trying to get procmail to rewrite the TO: header. I've tried something like:
>>>>>
>>>>> TO=`formail -xTo:`
>>
>> 	:0 Hf
>> 	* X-Virus-Status: Yes
>> 	| sed -e 's/^[sS]ubject:[[:space:]]\+/Subject: [virus] '
>
> Mmm, we are close here I put in:
>
> # test
> :0 Hf
> | sed -e 's/^[tT]o:[[:space:]]\+/To: [STAN] '
>
> (Unconditional to test the action).

That's plainly wrong.  The "To:" header will contain broken crap instead
of a recipient address.  Just *DON'T* do that.  Try to modify the
"Subject:" instead.  I'm positively sure than even the crapware from a
well-known Redmond-based company can filter based on the subject of
individual posts.

> But I got this error in the procmail logfile:
>
> sed: 1: "s/^[tT]o:[[:space:]]\+/ ...": unescaped newline inside substitute pattern

It may be that procmail does weird things with the regexp string or that
procmail doesn't accept extended regexps (I think I remember finding out
about this one a while ago).  Let's see:

% flame:/home/keramida$ cd /tmp/stan/
% flame:/tmp/stan$ ls -l
% total 6
% -rw-------  1 keramida  wheel  - 4109 Oct 24 02:13 mbox
% flame:/tmp/stan$ cat > procmailrc
% :0 Hf
% | sed -e 's/^[tT]o:[[:space:]]\+/To: [STAN] '
% flame:/tmp/stan$ formail -s procmail /tmp/stan/procmailrc < mbox | grep -i to:
% sed: 1: "s/^[tT]o:[[:space:]]\+/ ...": unescaped newline inside substitute pattern
% flame:/tmp/stan$

When I avoid using the \+ trick, it works fine:

% flame:/tmp/stan$ cat > procmailrc
% :0 Hf
% | sed -e 's/^[tT][oO]:[[:space:]][[:space:]]*\([^[:space:]]\)/To: [STAN] \1/'
%
% :0
% /tmp/stan/newbox
% flame:/tmp/stan$ formail -s procmail /tmp/stan/procmailrc < mbox
% flame:/tmp/stan$ ls -l
% total 14
% -rw-------  1 keramida  wheel  - 4109 Oct 24 02:13 mbox
% -rw-------  1 keramida  wheel  - 4116 Oct 24 02:20 newbox
% -rw-rw-r--  1 keramida  wheel  -  105 Oct 24 02:19 procmailrc
% flame:/tmp/stan$ diff -u mbox newbox
% --- mbox        Mon Oct 24 02:13:03 2005
% +++ newbox      Mon Oct 24 02:20:05 2005
% @@ -36,7 +36,7 @@
%         for <keramida at ceid.upatras.gr>; Sun, 23 Oct 2005 19:11:03 -0400
%  Date: Sun, 23 Oct 2005 19:11:03 -0400
%  From: stan <stanb at panix.com>
% -To: Giorgos Keramidas <keramida at ceid.upatras.gr>
% +To: [STAN] Giorgos Keramidas <keramida at ceid.upatras.gr>
%  Subject: Re: procmail/formail syntax question
%  Message-ID: <20051023231103.GE31109 at teddy.fas.com>
%  References: <20051023190951.GA25702 at teddy.fas.com> <20051023200717.GB82057 at slackbox.xs4all.nl> <20051023214939.GB30009 at teddy.fas.com> <20051023221317.GA1211 at flame.pc>

So it *does* work, using plain regexps and not extended regexps and it
changes the To: header as expected (even though that's wrong, as I said
above).

- Giorgos



More information about the freebsd-questions mailing list