Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

header_checks PREPEND

1,302 views
Skip to first unread message

ni...@javacat.f2s.com

unread,
Nov 1, 2006, 5:03:42 AM11/1/06
to
Hi,

Im looking to prepend [SPAM] to the Subject: of mails that come in with a preassigned X-SpamReason: value of 1..4.

main.cf:header_checks = pcre:/etc/postfix/header_checks

And in header_checks:
/X-SpamReason: Yes, hits=([1..4]\.[0-9]*).*required/ PREPEND Subject: [SPAM]

However this is overwriting the Subject completely, and Im just getting [SPAM] in the Subject of the mail
once its received.

Any idea what I could be doing wrong ?

postfix-2.1.5-4.2.RHEL4

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
debug_peer_level = 5
header_checks = pcre:/etc/postfix/header_checks
html_directory = no
inet_interfaces = all
local_recipient_maps =
local_transport = error:local mail delivery is disabled
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = postfix.hpcds.com
mynetworks = a.b.c.d
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.1.5/README_FILES
relay_domains = hash:/etc/postfix/relay_domains
relay_recipient_maps = hash:/etc/postfix/relay_recipients
sample_directory = /usr/share/doc/postfix-2.1.5/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual


Thanks,
Nick .

Sandy Drobic

unread,
Nov 1, 2006, 5:51:36 AM11/1/06
to
ni...@javacat.f2s.com wrote:
> Hi,
>
> Im looking to prepend [SPAM] to the Subject: of mails that come in with a preassigned X-SpamReason: value of 1..4.
>
> main.cf:header_checks = pcre:/etc/postfix/header_checks
>
> And in header_checks:
> /X-SpamReason: Yes, hits=([1..4]\.[0-9]*).*required/ PREPEND Subject: [SPAM]
>
> However this is overwriting the Subject completely, and Im just getting [SPAM] in the Subject of the mail
> once its received.
>
> Any idea what I could be doing wrong ?

Prepend sets a new Subject header here. This is better done by your filter
software. Header_checks can't set a subject header in relation to another
check on x-spamreason.

You either need a filter for that or do it directly in your spamfilter.

Sandy
--
List replies only please!
Please address PMs to: news-reply2 (@) japantest (.) homelinux (.) com

ni...@javacat.f2s.com

unread,
Nov 1, 2006, 6:04:14 AM11/1/06
to
Quoting Sandy Drobic <postfi...@japantest.homelinux.com>:

> ni...@javacat.f2s.com wrote:
> > Hi,
> >
> > Im looking to prepend [SPAM] to the Subject: of mails that come in with a preassigned X-SpamReason: value of 1..4.
> >
> > main.cf:header_checks = pcre:/etc/postfix/header_checks
> >
> > And in header_checks:
> > /X-SpamReason: Yes, hits=([1..4]\.[0-9]*).*required/ PREPEND Subject: [SPAM]
> >
> > However this is overwriting the Subject completely, and Im just getting [SPAM] in the Subject of the mail
> > once its received.
> >
> > Any idea what I could be doing wrong ?
>
> Prepend sets a new Subject header here. This is better done by your filter
> software. Header_checks can't set a subject header in relation to another
> check on x-spamreason.
>
> You either need a filter for that or do it directly in your spamfilter.

I see, thanks for the explanation.

Nick .


mouss

unread,
Nov 1, 2006, 8:03:36 AM11/1/06
to

you can use procmail|maildrop with formail|reformail.

it is possible to with postfix but that would be overkill (run a
specific smtpd as a content_filter, using the FILTER statement in place
of your PREPEND. then that smtpd will have its own cleanup to modify the
subject).

That said, subject rewrite is more or less ugly. sometimes, a site
misclassifies a message and tag the subject, then the recipient replies
to forwards it... I already seen customer requests with a spam tag in
the subject! fortunately, I don't rely on the subject...

An alternative is to prepend specific headers. For recipients using
imap, you can deliver to a Junk folder. Pop users can set filters on
their MUAs based on the headers you prepend.

ni...@javacat.f2s.com

unread,
Nov 1, 2006, 8:35:02 AM11/1/06
to
Quoting mouss <use...@free.fr>:

> ni...@javacat.f2s.com wrote:
> > Quoting Sandy Drobic <postfi...@japantest.homelinux.com>:
> >
> >
> >> ni...@javacat.f2s.com wrote:
> >>
> >>> Hi,
> >>>
> >>> Im looking to prepend [SPAM] to the Subject: of mails that come in with a preassigned X-SpamReason: value of 1..4.
> >>>
> >>> main.cf:header_checks = pcre:/etc/postfix/header_checks
> >>>
> >>> And in header_checks:
> >>> /X-SpamReason: Yes, hits=([1..4]\.[0-9]*).*required/ PREPEND Subject: [SPAM]
> >>>
> >>> However this is overwriting the Subject completely, and Im just getting [SPAM] in the Subject of the mail
> >>> once its received.
> >>>
> >>> Any idea what I could be doing wrong ?
> >>>
> >> Prepend sets a new Subject header here. This is better done by your filter
> >> software. Header_checks can't set a subject header in relation to another
> >> check on x-spamreason.
> >>
> >> You either need a filter for that or do it directly in your spamfilter.
> >>
> >
> > I see, thanks for the explanation.
> >
>
> you can use procmail|maildrop with formail|reformail.
>
> it is possible to with postfix but that would be overkill (run a
> specific smtpd as a content_filter, using the FILTER statement in place
> of your PREPEND. then that smtpd will have its own cleanup to modify the
> subject).
>

The postfix server in question simply passes inbound valid mail to our exchange server
and passes outbound mail to an external mail service run by messagelabs, messagelabs
then passes it on to the outside world.

It's the messagelabs server that puts in the X-SpamReason header. I need to catch
this X-SpamReason value and if it's >0 & <= 4 do nothing with it, just pass it
onto exchange.

If the X-SpamReason header value is > 4 & < 7 prepend the subject with [SPAM] and
pass it to exchange as normal, letting the user set a rule in outlook for this if
they wish.

X-SpamReason > 7 will result in the mail getting redirected to a quarantine address
in exchange.

I've tried to google software that will let me do this, but I'm not having much luck.
I had thought about setting up my own content_filter but like yourself I considered it
overkill.

Would procmail/maildrop work with the situation I described above ? I don't have any
experience of procmail or maildrop.

If anyone knows any software which will do what I'd appreciate a heads up. We aren't doing
our own spam/virus scanning so I can't rewrite the subject with spamassassin.

Thanks,
Nick .

mouss

unread,
Nov 1, 2006, 11:16:21 AM11/1/06
to
ni...@javacat.f2s.com wrote:
> The postfix server in question simply passes inbound valid mail to our exchange server
> and passes outbound mail to an external mail service run by messagelabs, messagelabs
> then passes it on to the outside world.
>
> It's the messagelabs server that puts in the X-SpamReason header. I need to catch
> this X-SpamReason value and if it's >0 & <= 4 do nothing with it, just pass it
> onto exchange.
>
> If the X-SpamReason header value is > 4 & < 7 prepend the subject with [SPAM] and
> pass it to exchange as normal, letting the user set a rule in outlook for this if
> they wish.
>
> X-SpamReason > 7 will result in the mail getting redirected to a quarantine address
> in exchange.
>
> I've tried to google software that will let me do this, but I'm not having much luck.
> I had thought about setting up my own content_filter but like yourself I considered it
> overkill.
>
> Would procmail/maildrop work with the situation I described above ? I don't have any
> experience of procmail or maildrop.
>
>

yes. Here is a summary (with maildrop)
- use transports to deliver mail for @domain.example to maildrop
- maildrop
* checks the spam header.
* maildrop gets the subject
* if spam, maildrop runs reformail to change the subject
* maildrop forwards mail to f...@done.domain.example
- use transports to forward @done.domain.example to your exchange server
- use generic to rewrite @done.domain.example to @domain.example

but this sounds like "trying to avoid a content_filter at all expenses"!
see below.


> If anyone knows any software which will do what I'd appreciate a heads up. We aren't doing
> our own spam/virus scanning so I can't rewrite the subject with spamassassin.
>
>

you could run SA with just one rule: match the X-SpamReason header and
score it enough to trigger sbject rewrite. but there is no need to use
SA just for this.

Instead,
- write a script to check the spam header and modify the subject accordinly
- use smtpprox to run the script

If you are not confortable writing scripts or maildrop/procmail recipes,
here is a postfix-only way. Convoluted but...


- add an smtpd (let's say on 127.0.0.1:10099) and a corresponding
cleanup to your master.cf. This cleanup has a header check that always
tags the subject:
/^Subject: (.*)/ REPLACE Subject: [Spam] $1

- In the "standard" header_checks, use
/X-SpamReason: Yes, hits=([1..4]\.[0-9]*).*required/ FILTER
scan:[127.0.0.1]:10099
where scan is defined as a filtering transport in master.cf

- the smtpd on 10099 has no content_filter, does no unknown recipient
validation, ... (see the FILTER_README for examples of configuration.
copy options of the smtpd on 10025 from there).


Nick Lunt

unread,
Nov 1, 2006, 1:44:49 PM11/1/06
to

Mouss, I can't thank you enough for taking the time to explain all that.
It's very much appreciated.

Nick .

0 new messages