Procmail/Formail, help extracting a header and writing to file
Procmail/Formail, help extracting a header and writing to file
am 17.08.2006 13:27:08 von Steve
I'm asking this question without filly investigating Procmail/Formail
for this solution because I'm being hit quite hard with hundreds of
spam messages per hour, so please accept my apologies for not
trying/testing first...
I would like to be able to extract the address from Sendmail's
'X-Original-To' header and append it to a file. The message should
then be delivered as normal.
Can anyone help please?
Many thanks,
Steve
Re: Procmail/Formail, help extracting a header and writing to file
am 18.08.2006 03:07:00 von Garen Erdoisa
Steve wrote:
> I'm asking this question without filly investigating Procmail/Formail
> for this solution because I'm being hit quite hard with hundreds of
> spam messages per hour, so please accept my apologies for not
> trying/testing first...
>
> I would like to be able to extract the address from Sendmail's
> 'X-Original-To' header and append it to a file. The message should
> then be delivered as normal.
>
> Can anyone help please?
>
> Many thanks,
> Steve
>
# Define a newline character for use in procmail log entries.
NL="
"
# Extract the contents of the X-Original-To: header and save it in a
# variable
:0
* ^X-Original-To: \/.*
{
ORIGINALTO=${MATCH}
# Example of how to log the contents of the ORIGINALTO variable in the
# procmail log file
LOG="[$$]$_: ORIGINALTO=${ORIGINALTO}${NL}"
# Append the contents of the ORIGINALTO variable to a cache file in
# the home directory. Note the backtics that launch an embedded
# shell script here. Using LOG as the variable name here is just
# a convenience. Any variable name could be used for this but would
# end up with an empty string because the output of the script is being
# written to a file in this case instead of captured by the variable.
LOG=`echo "${ORIGINALTO}" >>${HOME}/original-to.cache`
}
--
Garen
Re: Procmail/Formail, help extracting a header and writing to file
am 18.08.2006 07:41:12 von AK
Steve wrote:
> I'm asking this question without filly investigating Procmail/Formail
> for this solution because I'm being hit quite hard with hundreds of
> spam messages per hour, so please accept my apologies for not
> trying/testing first...
>
> I would like to be able to extract the address from Sendmail's
> 'X-Original-To' header and append it to a file. The message should
> then be delivered as normal.
>
> Can anyone help please?
>
> Many thanks,
> Steve
>
filename="somefile"
variable_content=`formail -X "X-Original-To"`
variable_line=`formail -x "X-Original-To"`
The below may or may not work. You would need to play/test.
`echo "$variable_content" >> $filename`
`echo "$variable_line" >> $filename`
AK
Re: Procmail/Formail, help extracting a header and writing to file
am 21.08.2006 13:03:53 von Steve
Thanks for your help Garen, but there is one problem - I'm getting a
"recipe incomplete" error. This is what I have:
:0
* ^X-Original-To: \/.*
{
ORIGINALTO=${MATCH}
LOG=`echo "${ORIGINALTO}" >>
${HOME}/.procmail/original-to.cache`
}
It looks ok to me, and works ok too - any ideas what is wrong?
Thanks,
Steve :)
> # Define a newline character for use in procmail log entries.
> NL="
> "
>
> # Extract the contents of the X-Original-To: header and save it in a
> # variable
> :0
> * ^X-Original-To: \/.*
> {
> ORIGINALTO=${MATCH}
>
> # Example of how to log the contents of the ORIGINALTO variable in the
> # procmail log file
> LOG="[$$]$_: ORIGINALTO=${ORIGINALTO}${NL}"
>
> # Append the contents of the ORIGINALTO variable to a cache file in
> # the home directory. Note the backtics that launch an embedded
> # shell script here. Using LOG as the variable name here is just
> # a convenience. Any variable name could be used for this but would
> # end up with an empty string because the output of the script is being
> # written to a file in this case instead of captured by the variable.
> LOG=`echo "${ORIGINALTO}" >>${HOME}/original-to.cache`
>
> }
>
> --
> Garen
Re: Procmail/Formail, help extracting a header and writing to file
am 22.08.2006 14:59:26 von Steve
Sorry, my bad. The recipe does work properly - it was another recipe
further on that failed.
Cheers,
Steve :)