[opensuse] Postfix: howto block CC-overloaded mail (regular expression)
Hello, I have a question about Postfix header checks and regular expressions. In my main.cf I have: header_checks = regexp:/etc/postfix/maps/header_checks and in header_checks I have: /^[To|Cc]:.*,.*,.*,.*,.*,.*,.*,.*,.*,.*$/ REJECT Too many recipients. Please use BCC. I *think* that this means: * Check for a header that starts with either "To" or "Cc". * any string, followed by a comma (email address separator) * check for 9 comma's or 10 strings (addresses) In other words, if you send me an email and you over-abuse the To or CC-field, your mail will be rejected with the message "Too many recipients. Please use BCC." I want to do this because I'm tired of educating always the same people. I don't want emails (usually chain mail or "funny powerpoints") where the receipient list is longer than the actual message. Even if it's from family. Unfortunately, it doesn't seem to work. Mail with more than 10 people in the CC is still getting trough. What's wrong here? -- Amedee -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 12/18/2008 at 4:44 PM, "Amedee Van Gasse"
wrote: Hello, I have a question about Postfix header checks and regular expressions. In my main.cf I have:
header_checks = regexp:/etc/postfix/maps/header_checks
and in header_checks I have:
/^[To|Cc]:.*,.*,.*,.*,.*,.*,.*,.*,.*,.*$/ REJECT Too many recipients. Please use BCC.
What's wrong here?
.* is catching as much as possible... so from the beginning to the end of the string. then there is no comma left, so the regex does not match. you'll probably need something slightly more complex, like (fully untested and out of my empty head): /^[To|Cc]:[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,.*$/ The last one I left intentionally on .*, as at this point we don't care about more commas anymore. Maybe somebody else can give you even nicer ideas, maybe this one does not work at all, maybe it deletes all your mail. Dominique -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Amedee Van Gasse wrote:
Hello,
I have a question about Postfix header checks and regular expressions. In my main.cf I have:
header_checks = regexp:/etc/postfix/maps/header_checks
and in header_checks I have:
/^[To|Cc]:.*,.*,.*,.*,.*,.*,.*,.*,.*,.*$/ REJECT Too many recipients. Please use BCC.
I *think* that this means: * Check for a header that starts with either "To" or "Cc". * any string, followed by a comma (email address separator) * check for 9 comma's or 10 strings (addresses)
In other words, if you send me an email and you over-abuse the To or CC-field, your mail will be rejected with the message "Too many recipients. Please use BCC."
I want to do this because I'm tired of educating always the same people. I don't want emails (usually chain mail or "funny powerpoints") where the receipient list is longer than the actual message. Even if it's from family.
Unfortunately, it doesn't seem to work. Mail with more than 10 people in the CC is still getting trough.
Try this instead: /^(To|Cc):([^,]+,){9}/i REJECT Too many [] = character class () = grouping /Per -- /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thu, December 18, 2008 16:55, Per Jessen wrote:
Amedee Van Gasse wrote:
Hello,
I have a question about Postfix header checks and regular expressions. In my main.cf I have:
header_checks = regexp:/etc/postfix/maps/header_checks
and in header_checks I have:
/^[To|Cc]:.*,.*,.*,.*,.*,.*,.*,.*,.*,.*$/ REJECT Too many recipients. Please use BCC.
I *think* that this means: * Check for a header that starts with either "To" or "Cc". * any string, followed by a comma (email address separator) * check for 9 comma's or 10 strings (addresses)
In other words, if you send me an email and you over-abuse the To or CC-field, your mail will be rejected with the message "Too many recipients. Please use BCC."
I want to do this because I'm tired of educating always the same people. I don't want emails (usually chain mail or "funny powerpoints") where the receipient list is longer than the actual message. Even if it's from family.
Unfortunately, it doesn't seem to work. Mail with more than 10 people in the CC is still getting trough.
Try this instead:
/^(To|Cc):([^,]+,){9}/i REJECT Too many
[] = character class () = grouping
Thanks all. I forgot that a regex is greedy. And thank you Per for optimizing. I'm going to test now. -- Amedee -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, December 19, 2008 11:13, Amedee Van Gasse wrote:
On Thu, December 18, 2008 16:55, Per Jessen wrote:
Amedee Van Gasse wrote:
Hello,
I have a question about Postfix header checks and regular expressions. In my main.cf I have:
header_checks = regexp:/etc/postfix/maps/header_checks
and in header_checks I have:
/^[To|Cc]:.*,.*,.*,.*,.*,.*,.*,.*,.*,.*$/ REJECT Too many recipients. Please use BCC.
I *think* that this means: * Check for a header that starts with either "To" or "Cc". * any string, followed by a comma (email address separator) * check for 9 comma's or 10 strings (addresses)
In other words, if you send me an email and you over-abuse the To or CC-field, your mail will be rejected with the message "Too many recipients. Please use BCC."
I want to do this because I'm tired of educating always the same people. I don't want emails (usually chain mail or "funny powerpoints") where the receipient list is longer than the actual message. Even if it's from family.
Unfortunately, it doesn't seem to work. Mail with more than 10 people in the CC is still getting trough.
Try this instead:
/^(To|Cc):([^,]+,){9}/i REJECT Too many
[] = character class () = grouping
Thanks all. I forgot that a regex is greedy. And thank you Per for optimizing.
I'm going to test now.
Thanks all, it worked. The sender gets a nice message: Server replied: 550 5.7.1 Too many recipients. Please use BCC. -- Amedee -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Amedee Van Gasse wrote:
Try this instead:
/^(To|Cc):([^,]+,){9}/i REJECT Too many
[] = character class () = grouping
Thanks all. I forgot that a regex is greedy. And thank you Per for optimizing.
I'm going to test now.
Thanks all, it worked. The sender gets a nice message:
Server replied: 550 5.7.1 Too many recipients. Please use BCC.
Good stuff - I think the main issue was the regex greediness, plus the square brackets you had around 'to|cc'. /Per -- /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (3)
-
Amedee Van Gasse
-
Dominique Leuenberger
-
Per Jessen