From owner-freebsd-questions@FreeBSD.ORG Sun Oct 23 23:27:15 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A10AB16A41F for ; Sun, 23 Oct 2005 23:27:15 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from aiolos.otenet.gr (aiolos.otenet.gr [195.170.0.93]) by mx1.FreeBSD.org (Postfix) with ESMTP id E536143D46 for ; Sun, 23 Oct 2005 23:27:14 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from flame.pc (patr530-a216.otenet.gr [212.205.215.216]) by aiolos.otenet.gr (8.13.4/8.13.4/Debian-1) with ESMTP id j9NNR7G6006349; Mon, 24 Oct 2005 02:27:08 +0300 Received: from flame.pc (flame [127.0.0.1]) by flame.pc (8.13.4/8.13.4) with ESMTP id j9NNPVvl001787; Mon, 24 Oct 2005 02:25:31 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by flame.pc (8.13.4/8.13.4/Submit) id j9NNPUNg001786; Mon, 24 Oct 2005 02:25:30 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Mon, 24 Oct 2005 02:25:30 +0300 From: Giorgos Keramidas To: stan Message-ID: <20051023232530.GA1753@flame.pc> References: <20051023190951.GA25702@teddy.fas.com> <20051023200717.GB82057@slackbox.xs4all.nl> <20051023214939.GB30009@teddy.fas.com> <20051023221317.GA1211@flame.pc> <20051023231103.GE31109@teddy.fas.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051023231103.GE31109@teddy.fas.com> Cc: freebsd-questions@freebsd.org Subject: Re: procmail/formail syntax question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Oct 2005 23:27:15 -0000 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 wrote: >On Mon, Oct 24, 2005 at 01:13:18AM +0300, Giorgos Keramidas wrote: >>On 2005-10-23 17:49, stan 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 ; Sun, 23 Oct 2005 19:11:03 -0400 % Date: Sun, 23 Oct 2005 19:11:03 -0400 % From: stan % -To: Giorgos Keramidas % +To: [STAN] Giorgos Keramidas % Subject: Re: procmail/formail syntax question % Message-ID: <20051023231103.GE31109@teddy.fas.com> % References: <20051023190951.GA25702@teddy.fas.com> <20051023200717.GB82057@slackbox.xs4all.nl> <20051023214939.GB30009@teddy.fas.com> <20051023221317.GA1211@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