LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-02-2008, 02:17 PM   #1
bahadirtonguc
LQ Newbie
 
Registered: Jul 2006
Location: Istanbul
Distribution: Ubuntu
Posts: 13

Rep: Reputation: 0
Postfix "Content Filter" setup to reject emails with too many recipients in TO: field


Dear all,

I am willing to setup a content filter to reject messages with too many recipients in TO: or CC: fiels but to let for BCC:

This way suppose I may avoid mistakes such as putting all the recipients in TO: or CC: fields instead of BCC: so this way they wont ever see each other.

(Some of my colleagues had done it quite a few times in the past and exposed all our private address book to every recipient.)

Appreciate your help

Regards
Bahadir
 
Old 11-16-2008, 05:08 PM   #2
bahadirtonguc
LQ Newbie
 
Registered: Jul 2006
Location: Istanbul
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
It's quite strange that nobody could reply however I helped myself reading a lot about this question and would like to share with others:

in header_checks, write a regexp like below which regret not working and needs a bit modification

/^To:[/.*/@/.*/]{5}$

Don't know where I am doing wrong but feels like very close to the answer though
 
Old 11-16-2008, 05:23 PM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
You probably need to work in a delimiter between emails as well
 
Old 11-16-2008, 06:57 PM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Here's a pcre regexp that matches at least 5 '@' in the To header:
Code:
^To: ([^@]*@){5,}
Note that if you reject such messages, you will also be filtering incoming messages
from the outside, so for example you would reject mail addressed to you and four other recipients.

Last edited by Berhanie; 11-16-2008 at 07:06 PM.
 
Old 11-17-2008, 04:41 AM   #5
bahadirtonguc
LQ Newbie
 
Registered: Jul 2006
Location: Istanbul
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
It aint working mate. Still can successfully send any kind of messages outbound. By the way, I dont use this server for inbound traffic so not concerned about filtering incoming messages.
 
Old 11-17-2008, 07:50 AM   #6
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
In that case, you should post your header_checks file, so people can see what's not working. Your file should look something like this:
Code:
/^To: ([^@]*@){5,}.*/      ACTION
I tested the expression in my first post with pcretest. For postfix, I think you
need to match the entire line (i.e. header), which is why you need the ".*" at the end. I haven't tested it with postfix, so you might have
to improve it.
 
1 members found this post helpful.
Old 11-17-2008, 09:41 AM   #7
bahadirtonguc
LQ Newbie
 
Registered: Jul 2006
Location: Istanbul
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
Here is the solution :

/^To: (.*@.*){5,}/ REJECT too many recipients
/^Cc: (.*@.*){5,}/ REJECT too many recipients
 
0 members found this post helpful.
Old 11-17-2008, 10:32 AM   #8
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
You're welcome.
 
Old 11-17-2008, 03:26 PM   #9
bahadirtonguc
LQ Newbie
 
Registered: Jul 2006
Location: Istanbul
Distribution: Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 0
Berhanine, thanks for your help but regret it did not work out. So I posted the correct syntax
 
Old 11-17-2008, 04:40 PM   #10
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Quote:
but regret it did not work out
Hi, bahadirtonguc. In the course of this thread, you went from writing a nonsensical regular expression at the beginning to solving your own problem by the end. So, I would say that it did work out. Good job!
 
Old 05-27-2010, 02:07 AM   #11
akelder
Member
 
Registered: Jan 2007
Distribution: debian on servers, ubuntu on desktops/laptops
Posts: 45

Rep: Reputation: 16
worked for me

I realize this is an old post, but just wanted to report what worked for me, in case someone else is looking to do this.

Berhanie's solution worked, here's my config.

/etc/postfix/main.cf:

Code:
# restrict based on message header content 
header_checks = pcre:/etc/postfix/header_checks
/etc/postfix/header_checks:

Code:
/^To:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.
/^Cc:([^@]*@){10,}/	REJECT Sorry, your message has too many recepients.
On the other hand, bahadirtonguc regex caused Postfix to choke:

Quote:
Out: 220 my.sweet.mx ESMTP Postfix (No UCE)
In: HELO some.other.mx
Out: 250 my.sweet.mx
In: MAIL FROM:<other@example.com>
Out: 250 2.1.0 Ok
In: RCPT TO:<me@example.com>
Out: 250 2.1.5 Ok
In: DATA
Out: 354 End data with <CR><LF>.<CR><LF>
Out: 451 4.3.0 Error: queue file write error
In: QUIT
Out: 221 2.0.0 Bye
/var/log/mail.err:

Quote:
May 26 20:17:00 my.sweet.mx postfix/cleanup[14318]: fatal: pcre map /etc/postfix/header_checks, line 2: matched text exceeds buffer limit
--
Reject an email message with too many recipients with Postfix

Last edited by akelder; 06-03-2010 at 11:16 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix: reject emails for list of recipient domains zaheer99 Linux - Server 3 11-11-2016 10:23 AM
Postfix: how to reject incoming mail as in Sendmail's "error:nouser"? Zippy1970 Linux - Server 24 10-01-2008 08:20 AM
It that possible to use the default "main.cf" setup the Postfix? goonfui_wong Linux - Networking 3 06-22-2005 07:32 AM
content filter in postfix jrafalek Linux - Software 0 04-05-2005 04:19 PM
Evolution 1.4 : Cannot send mail ("No recipients defined") Obi-Wan_Kenobi Linux - Software 3 11-25-2003 02:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration