[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Grep only mail headers via STDIN?



On Fri, Mar 05, 2004 at 10:37:01AM +0100, Jens Benecke wrote:
> Hi,
> 
> I want to create a script that greps for a specific mail header coming from
> STDIN. "mailgrep" and "mboxgrep" don't work, they need files to work on,
> but the mail comes via STDIN.
> 
> So I need to write something like
> 
> | condredirect spam@mydomain.lan egrep "^X-Spam-Flag: YES" 
> 
> BUT where grep would "exit 1;" and not search any further when it encounters
> the first empty line (the end of the mail headers)
> 
> 
> Backgroud: I want to filter SPAM but I don't want to filter attached SPAM
> that people forward to me to analyze. So I can't just grep for
> "X-Spam-Flag:".

A grepish program that doesn't work on stdin sounds odd.  Have you tried
using '-' as the filename?  From grepmail(1) on woody:

         If no mailbox is specified, takes input from stdin,
         which can be compressed or not. grepmail's behavior is
         undefined when ASCII and binary data is piped together
         as input.

Otherwise, if mailgrep et al otherwise work, you might consider fixing them
(i.e., hack the source) to support input on stdin.

Ken

-- 
Ken Irving, Research Analyst, fnkci@uaf.edu, 907-474-6152
Water and Environmental Research Center
Institute of Northern Engineering
University of Alaska, Fairbanks



Reply to: