On Wed, 26 May 2004, Graham Trott wrote:
Date: Wed, 26 May 2004 09:11:59 +0100 From: Graham Trott gt@pobox.com To: main@lists.alug.org.uk Subject: [ALUG] Writing a bash filter
Hi all you bash experts...
I'm trying to write a mail filter shell script to be used from KMail, whereby each incoming mail message will be piped through it. The filter needs to read each line of the message and then write it back suitably modified.
I'm having difficulty with the basics of shell scripting. From what I understand, "read x" will deal with each line as it's piped in, and "echo $x" will generate the output stream for the return pipe. (Are there better alternatives?) But how can I tell when the message has finished? I can't look for empty lines because these occur in the middle of messages.
Can anyone suggest a simple filter script that will take an arbitrary file, line by line, from standard input and pass it on to standard output?
Are you mad? Messing with mailboxes in this way will make strong men weep! There's things such as file locking, and file permissions, to be considered and you may lose all your e-mails or make them all unreadable.
Take a long and careful look at procmail this may be able to do what you want directly or it can call an external program.
The end of a mail message is signalled by a blank line followed by "From" end of file, I think, but procmail will split them for you, write a log and do all other needful things.
Leon Stedman. (Not a bash expert!)