From owner-freebsd-questions Wed Dec 18 6: 6:24 2002 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 C4C2037B401 for ; Wed, 18 Dec 2002 06:06:22 -0800 (PST) Received: from smtp.infracaninophile.co.uk (smtp.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8A2AE43ED4 for ; Wed, 18 Dec 2002 06:06:21 -0800 (PST) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [IPv6:::1]) by smtp.infracaninophile.co.uk (8.12.6/8.12.6) with ESMTP id gBIE6FQn075049 for ; Wed, 18 Dec 2002 14:06:15 GMT (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost) by happy-idiot-talk.infracaninophile.co.uk (8.12.6/8.12.6/Submit) id gBIE6Ae7075048 for freebsd-questions@FreeBSD.ORG; Wed, 18 Dec 2002 14:06:10 GMT Date: Wed, 18 Dec 2002 14:06:10 +0000 From: Matthew Seaman To: FreeBSD Questions Subject: Re: Getting Perl scripts to work as mail filters Message-ID: <20021218140610.GB74300@happy-idiot-talk.infracaninophi> Mail-Followup-To: Matthew Seaman , FreeBSD Questions References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.1i X-Spam-Status: No, hits=-3.0 required=5.0 tests=IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_00_01, USER_AGENT,USER_AGENT_MUTT version=2.43 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Wed, Dec 18, 2002 at 02:46:14PM +0100, Mxsmanic wrote: > What do I have to do to make a simple Perl script filter incoming mail for a > mailbox? I wrote a script that just reads standard input and writes it to > standard output, then put it in my home directory, then changes > /etc/mail/aliases to point to it, like this: > > mymail: "|/usr/home/mymail/perlfilter" > > But when I actually send mail to this address, it just disappears--no error > message, nothing. When I execute the same program by hand, it works fine. > If I remove the alias, the mail is delivered just fine, too. What am I > missing?? The Perl program has 755 for permissions and has mymail:users as > its userid and group. The first line points to the location of Perl in the > usual way. I am at a loss for ideas as to why this isn't working. The > sendmail manual seems to indicate that it just pipes the e-mail message into > this script, then delivers whatever comes out of standard output, but it > doesn't seem to work. I believe that sendmail will consider the e-mail to have been delivered if it can pipe it into your script and the script returns a successful exit code. It won't treat the script as a filter: that is, it won't read the script's output and treat that as a message to deliver. Anything your script writes to stdout will be silently discarded. If you want that re-mailing effect then you're going to have to make the script fire up another instance of sendmail, and pipe the output message from the perl script into sendmail yourself. Beware of mail loops though --- make sure you modify the 'To:' header of the message as it passes through the filter sufficiently that it doesn't hit the alias expansion again. Alternatively, take a look at procmail(8) which can be used to pass a message through a filter program and then re-send it to a new address. Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message