Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fcbc27f2a | |||
| e5bf1aee09 | |||
| 5df3a80f7b | |||
| df67ee9147 | |||
| 593384d610 | |||
| 1280f1360e | |||
| 3e1e528abe | |||
| 04ce8f81b9 | |||
| bc390e69b9 | |||
| c07ed917ab | |||
| a14d676fb6 | |||
| 600e3dfbfb | |||
| 8cfa03bbc4 | |||
| 28a0e551bd | |||
| be3f463450 | |||
| a420148b1e | |||
| f4465ea816 | |||
| 1845876665 | |||
| cee6bc3bea | |||
| 71403de50e | |||
| 017784b5a7 | |||
| 632e7b4248 | |||
| 10f4f2613e | |||
| 69369c3b2a | |||
| 5386e08ca5 | |||
| d0fe3b0b84 | |||
| 670e97cb79 | |||
| 6397b7027f | |||
| 94ce032559 | |||
| 91230381cb | |||
| 46ed3ddbcb | |||
| 6048fe6e8c | |||
| d225384829 | |||
| a84f6aa574 | |||
| 344e8f0a0a | |||
| 1fa4b72c84 |
@@ -1,8 +1,8 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
|
|||||||
General Public License applies to most of the Free Software
|
General Public License applies to most of the Free Software
|
||||||
Foundation's software and to any other program whose authors commit to
|
Foundation's software and to any other program whose authors commit to
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
the GNU Library General Public License instead.) You can apply it to
|
the GNU Lesser General Public License instead.) You can apply it to
|
||||||
your programs, too.
|
your programs, too.
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
@@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all.
|
|||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
|
|||||||
License. (Exception: if the Program itself is interactive but
|
License. (Exception: if the Program itself is interactive but
|
||||||
does not normally print such an announcement, your work based on
|
does not normally print such an announcement, your work based on
|
||||||
the Program is not required to print an announcement.)
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
These requirements apply to the modified work as a whole. If
|
||||||
identifiable sections of that work are not derived from the Program,
|
identifiable sections of that work are not derived from the Program,
|
||||||
and can be reasonably considered independent and separate works in
|
and can be reasonably considered independent and separate works in
|
||||||
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
|
|||||||
access to copy the source code from the same place counts as
|
access to copy the source code from the same place counts as
|
||||||
distribution of the source code, even though third parties are not
|
distribution of the source code, even though third parties are not
|
||||||
compelled to copy the source along with the object code.
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
except as expressly provided under this License. Any attempt
|
except as expressly provided under this License. Any attempt
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
@@ -225,7 +225,7 @@ impose that choice.
|
|||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
This section is intended to make thoroughly clear what is believed to
|
||||||
be a consequence of the rest of this License.
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
original copyright holder who places the Program under this License
|
original copyright holder who places the Program under this License
|
||||||
@@ -278,7 +278,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|||||||
POSSIBILITY OF SUCH DAMAGES.
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
If you develop a new program, and you want it to be of the greatest
|
||||||
@@ -303,10 +303,9 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License along
|
||||||
along with this program; if not, write to the Free Software
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
@@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
|
|||||||
This General Public License does not permit incorporating your program into
|
This General Public License does not permit incorporating your program into
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
consider it more useful to permit linking proprietary applications with the
|
consider it more useful to permit linking proprietary applications with the
|
||||||
library. If this is what you want to do, use the GNU Library General
|
library. If this is what you want to do, use the GNU Lesser General
|
||||||
Public License instead of this License.
|
Public License instead of this License.
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ real, usable Python extension.
|
|||||||
|
|
||||||
Other contributors (in random order):
|
Other contributors (in random order):
|
||||||
|
|
||||||
|
Dwayne Litzenberger, B.A.Sc.
|
||||||
|
for library_dirs patch to compile on Debian
|
||||||
Dave MacQuigg
|
Dave MacQuigg
|
||||||
for noticing that smfi_insheader wasn't supported, and creating
|
for noticing that smfi_insheader wasn't supported, and creating
|
||||||
a template to help first time pymilter users create their own milter.
|
a template to help first time pymilter users create their own milter.
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ wish to install pydspam.
|
|||||||
For basic pymilter you'll need:
|
For basic pymilter you'll need:
|
||||||
|
|
||||||
python-2.4
|
python-2.4
|
||||||
milter-0.8.7
|
milter-0.8.10
|
||||||
sendmail-8.13.x (with milter support enabled)
|
sendmail-8.13.x (with milter support enabled)
|
||||||
|
|
||||||
and for SPF you'll need:
|
and for SPF you'll need:
|
||||||
|
|
||||||
pydns-2.3.0-2.4
|
pydns-2.3.3-2.4
|
||||||
pyspf-2.0.3-2.py24
|
pyspf-2.0.5-1.py24
|
||||||
|
|
||||||
and for SRS you'll need:
|
and for SRS you'll need:
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ Start milter and pysrs with "service milter start", "service pysrs start".
|
|||||||
Tail /var/log/milter/milter.log while SMTP clients connect to your
|
Tail /var/log/milter/milter.log while SMTP clients connect to your
|
||||||
sendmail instance. This should show you what the milter is doing.
|
sendmail instance. This should show you what the milter is doing.
|
||||||
|
|
||||||
By default, milter-0.8.7 rejects on SPF fail.
|
By default, milter-0.8.10 rejects on SPF fail.
|
||||||
|
|
||||||
Step four. Tweaking the basic config.
|
Step four. Tweaking the basic config.
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -184,8 +184,10 @@ def runmilter(name,socketname,timeout = 0):
|
|||||||
print "Removing %s" % fname
|
print "Removing %s" % fname
|
||||||
try:
|
try:
|
||||||
os.unlink(fname)
|
os.unlink(fname)
|
||||||
except:
|
except os.error, x:
|
||||||
pass
|
import errno
|
||||||
|
if x.errno != errno.ENOENT:
|
||||||
|
raise milter.error(x)
|
||||||
|
|
||||||
# The default flags set include everything
|
# The default flags set include everything
|
||||||
# milter.set_flags(milter.ADDHDRS)
|
# milter.set_flags(milter.ADDHDRS)
|
||||||
|
|||||||
+34
-19
@@ -10,6 +10,14 @@
|
|||||||
# CBV results.
|
# CBV results.
|
||||||
#
|
#
|
||||||
# $Log$
|
# $Log$
|
||||||
|
# Revision 1.8 2007/09/03 16:18:45 customdesigned
|
||||||
|
# Delete unparseable timestamps when loading address cache. These have
|
||||||
|
# arisen because of failure to parse MAIL FROM properly. Will have to
|
||||||
|
# tighten up MAIL FROM parsing to match RFC.
|
||||||
|
#
|
||||||
|
# Revision 1.7 2007/01/25 22:47:26 customdesigned
|
||||||
|
# Persist blacklisting from delayed DSNs.
|
||||||
|
#
|
||||||
# Revision 1.6 2007/01/19 23:31:38 customdesigned
|
# Revision 1.6 2007/01/19 23:31:38 customdesigned
|
||||||
# Move parse_header to Milter.utils.
|
# Move parse_header to Milter.utils.
|
||||||
# Test case for delayed DSN parsing.
|
# Test case for delayed DSN parsing.
|
||||||
@@ -66,13 +74,17 @@ class AddrCache(object):
|
|||||||
for ln in fp:
|
for ln in fp:
|
||||||
try:
|
try:
|
||||||
rcpt,ts = ln.strip().split(None,1)
|
rcpt,ts = ln.strip().split(None,1)
|
||||||
l = time.strptime(ts,AddrCache.time_format)
|
try:
|
||||||
t = time.mktime(l)
|
l = time.strptime(ts,AddrCache.time_format)
|
||||||
if t < too_old:
|
t = time.mktime(l)
|
||||||
changed = True
|
if t < too_old:
|
||||||
continue
|
changed = True
|
||||||
cache[rcpt.lower()] = (t,None)
|
continue
|
||||||
except:
|
cache[rcpt.lower()] = (t,None)
|
||||||
|
except: # unparsable timestamp - likely garbage
|
||||||
|
changed = True
|
||||||
|
continue
|
||||||
|
except: # manual entry (no timestamp)
|
||||||
cache[ln.strip().lower()] = (now,None)
|
cache[ln.strip().lower()] = (now,None)
|
||||||
wfp.write(ln)
|
wfp.write(ln)
|
||||||
if changed:
|
if changed:
|
||||||
@@ -82,8 +94,10 @@ class AddrCache(object):
|
|||||||
except IOError:
|
except IOError:
|
||||||
lock.unlock()
|
lock.unlock()
|
||||||
|
|
||||||
def has_key(self,sender):
|
def has_precise_key(self,sender):
|
||||||
"True if sender is cached and has not expired."
|
"""True if precise sender is cached and has not expired. Don't
|
||||||
|
try looking up wildcard entries.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
lsender = sender and sender.lower()
|
lsender = sender and sender.lower()
|
||||||
ts,res = self.cache[lsender]
|
ts,res = self.cache[lsender]
|
||||||
@@ -91,16 +105,17 @@ class AddrCache(object):
|
|||||||
if not ts or ts > too_old:
|
if not ts or ts > too_old:
|
||||||
return True
|
return True
|
||||||
del self.cache[lsender]
|
del self.cache[lsender]
|
||||||
try:
|
except KeyError: pass
|
||||||
user,host = sender.split('@',1)
|
return False
|
||||||
return self.has_key(host)
|
|
||||||
except ValueError:
|
def has_key(self,sender):
|
||||||
pass
|
"True if sender is cached and has not expired."
|
||||||
except KeyError:
|
if self.has_precise_key(sender):
|
||||||
try:
|
return True
|
||||||
user,host = sender.split('@',1)
|
try:
|
||||||
return self.has_key(host)
|
user,host = sender.split('@',1)
|
||||||
except: pass
|
return self.has_precise_key(host)
|
||||||
|
except: pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
__contains__ = has_key
|
__contains__ = has_key
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
# provide a higher level interface to pydns
|
||||||
|
|
||||||
|
import DNS
|
||||||
|
from DNS import DNSError
|
||||||
|
|
||||||
|
MAX_CNAME = 10
|
||||||
|
|
||||||
|
def DNSLookup(name, qtype):
|
||||||
|
try:
|
||||||
|
req = DNS.DnsRequest(name, qtype=qtype)
|
||||||
|
resp = req.req()
|
||||||
|
#resp.show()
|
||||||
|
# key k: ('wayforward.net', 'A'), value v
|
||||||
|
# FIXME: pydns returns AAAA RR as 16 byte binary string, but
|
||||||
|
# A RR as dotted quad. For consistency, this driver should
|
||||||
|
# return both as binary string.
|
||||||
|
return [((a['name'], a['typename']), a['data']) for a in resp.answers]
|
||||||
|
except IOError, x:
|
||||||
|
raise DNSError, str(x)
|
||||||
|
|
||||||
|
class Session(object):
|
||||||
|
"""A Session object has a simple cache with no TTL that is valid
|
||||||
|
for a single "session", for example an SMTP conversation."""
|
||||||
|
def __init__(self):
|
||||||
|
self.cache = {}
|
||||||
|
|
||||||
|
# We have to be careful which additional DNS RRs we cache. For
|
||||||
|
# instance, PTR records are controlled by the connecting IP, and they
|
||||||
|
# could poison our local cache with bogus A and MX records.
|
||||||
|
|
||||||
|
SAFE2CACHE = {
|
||||||
|
('MX','A'): None,
|
||||||
|
('MX','MX'): None,
|
||||||
|
('CNAME','A'): None,
|
||||||
|
('CNAME','CNAME'): None,
|
||||||
|
('A','A'): None,
|
||||||
|
('AAAA','AAAA'): None,
|
||||||
|
('PTR','PTR'): None,
|
||||||
|
('TXT','TXT'): None,
|
||||||
|
('SPF','SPF'): None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def dns(self, name, qtype, cnames=None):
|
||||||
|
"""DNS query.
|
||||||
|
|
||||||
|
If the result is in cache, return that. Otherwise pull the
|
||||||
|
result from DNS, and cache ALL answers, so additional info
|
||||||
|
is available for further queries later.
|
||||||
|
|
||||||
|
CNAMEs are followed.
|
||||||
|
|
||||||
|
If there is no data, [] is returned.
|
||||||
|
|
||||||
|
pre: qtype in ['A', 'AAAA', 'MX', 'PTR', 'TXT', 'SPF']
|
||||||
|
post: isinstance(__return__, types.ListType)
|
||||||
|
"""
|
||||||
|
result = self.cache.get( (name, qtype) )
|
||||||
|
cname = None
|
||||||
|
|
||||||
|
if not result:
|
||||||
|
safe2cache = Session.SAFE2CACHE
|
||||||
|
for k, v in DNSLookup(name, qtype):
|
||||||
|
if k == (name, 'CNAME'):
|
||||||
|
cname = v
|
||||||
|
if (qtype,k[1]) in safe2cache:
|
||||||
|
self.cache.setdefault(k, []).append(v)
|
||||||
|
result = self.cache.get( (name, qtype), [])
|
||||||
|
if not result and cname:
|
||||||
|
if not cnames:
|
||||||
|
cnames = {}
|
||||||
|
elif len(cnames) >= MAX_CNAME:
|
||||||
|
#return result # if too many == NX_DOMAIN
|
||||||
|
raise DNSError('Length of CNAME chain exceeds %d' % MAX_CNAME)
|
||||||
|
cnames[name] = cname
|
||||||
|
if cname in cnames:
|
||||||
|
raise DNSError, 'CNAME loop'
|
||||||
|
result = self.dns(cname, qtype, cnames=cnames)
|
||||||
|
return result
|
||||||
|
|
||||||
|
DNS.DiscoverNameServers()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
s = Session()
|
||||||
|
for n,t in zip(*[iter(sys.argv[1:])]*2):
|
||||||
|
print n,t
|
||||||
|
print s.dns(n,t)
|
||||||
+49
-24
@@ -5,6 +5,12 @@
|
|||||||
# Send DSNs, do call back verification,
|
# Send DSNs, do call back verification,
|
||||||
# and generate DSN messages from a template
|
# and generate DSN messages from a template
|
||||||
# $Log$
|
# $Log$
|
||||||
|
# Revision 1.15 2007/09/24 20:13:26 customdesigned
|
||||||
|
# Remove explicit spf dependency.
|
||||||
|
#
|
||||||
|
# Revision 1.14 2007/03/03 18:19:40 customdesigned
|
||||||
|
# Handle DNS error sending DSN.
|
||||||
|
#
|
||||||
# Revision 1.13 2007/01/04 18:01:11 customdesigned
|
# Revision 1.13 2007/01/04 18:01:11 customdesigned
|
||||||
# Do plain CBV when template missing.
|
# Do plain CBV when template missing.
|
||||||
#
|
#
|
||||||
@@ -19,22 +25,22 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import smtplib
|
import smtplib
|
||||||
import spf
|
|
||||||
import socket
|
import socket
|
||||||
from email.Message import Message
|
from email.Message import Message
|
||||||
import Milter
|
import Milter
|
||||||
import time
|
import time
|
||||||
|
import dns
|
||||||
|
|
||||||
def send_dsn(mailfrom,receiver,msg=None,timeout=600):
|
def send_dsn(mailfrom,receiver,msg=None,timeout=600,session=None):
|
||||||
"""Send DSN. If msg is None, do callback verification.
|
"""Send DSN. If msg is None, do callback verification.
|
||||||
Mailfrom is original sender we are sending DSN or CBV to.
|
Mailfrom is original sender we are sending DSN or CBV to.
|
||||||
Receiver is the MTA sending the DSN.
|
Receiver is the MTA sending the DSN.
|
||||||
Return None for success or (code,msg) for failure."""
|
Return None for success or (code,msg) for failure."""
|
||||||
user,domain = mailfrom.split('@')
|
user,domain = mailfrom.split('@')
|
||||||
|
if not session: session = dns.Session()
|
||||||
try:
|
try:
|
||||||
q = spf.query(None,None,None)
|
mxlist = session.dns(domain,'MX')
|
||||||
mxlist = q.dns(domain,'MX')
|
except dns.DNSError:
|
||||||
except spf.TempError:
|
|
||||||
return (450,'DNS Timeout: %s MX'%domain) # temp error
|
return (450,'DNS Timeout: %s MX'%domain) # temp error
|
||||||
if not mxlist:
|
if not mxlist:
|
||||||
mxlist = (0,domain), # fallback to A record when no MX
|
mxlist = (0,domain), # fallback to A record when no MX
|
||||||
@@ -86,23 +92,41 @@ def send_dsn(mailfrom,receiver,msg=None,timeout=600):
|
|||||||
return (450,'No MX response within %f minutes'%(timeout/60.0))
|
return (450,'No MX response within %f minutes'%(timeout/60.0))
|
||||||
return (450,'No MX servers available') # temp error
|
return (450,'No MX servers available') # temp error
|
||||||
|
|
||||||
def create_msg(q,rcptlist,origmsg=None,template=None):
|
class Vars: pass
|
||||||
"Create a DSN message from a template. Template must be '\n' separated."
|
|
||||||
|
# NOTE: Caller can pass an object to create_msg that in a typical milter
|
||||||
|
# collects things like heloname or sender anyway.
|
||||||
|
def create_msg(v,rcptlist=None,origmsg=None,template=None):
|
||||||
|
"""Create a DSN message from a template. Template must be '\n' separated.
|
||||||
|
v - an object whose attributes are used for substitutions. Must
|
||||||
|
have sender and receiver attributes at a minimum.
|
||||||
|
rcptlist - used to set v.rcpt if given
|
||||||
|
origmsg - used to set v.subject and v.spf_result if given
|
||||||
|
template - a '\n' separated string with python '%(name)s' substitutions.
|
||||||
|
"""
|
||||||
if not template:
|
if not template:
|
||||||
return None
|
return None
|
||||||
heloname = q.h
|
if hasattr(v,'perm_error'):
|
||||||
sender = q.s
|
# likely to be an spf.query, try translating for backward compatibility
|
||||||
connectip = q.i
|
q = v
|
||||||
receiver = q.r
|
v = Vars()
|
||||||
sender_domain = q.o
|
try:
|
||||||
result = q.result
|
v.heloname = q.h
|
||||||
perm_error = q.perm_error
|
v.sender = q.s
|
||||||
rcpt = '\n\t'.join(rcptlist)
|
v.connectip = q.i
|
||||||
try: subject = origmsg['Subject']
|
v.receiver = q.r
|
||||||
except: subject = '(none)'
|
v.sender_domain = q.o
|
||||||
try:
|
v.result = q.result
|
||||||
spf_result = origmsg['Received-SPF']
|
v.perm_error = q.perm_error
|
||||||
except: spf_result = None
|
except: v = q
|
||||||
|
if rcptlist:
|
||||||
|
v.rcpt = '\n\t'.join(rcptlist)
|
||||||
|
if origmsg:
|
||||||
|
try: v.subject = origmsg['Subject']
|
||||||
|
except: v.subject = '(none)'
|
||||||
|
try:
|
||||||
|
v.spf_result = origmsg['Received-SPF']
|
||||||
|
except: v.spf_result = None
|
||||||
|
|
||||||
msg = Message()
|
msg = Message()
|
||||||
|
|
||||||
@@ -112,18 +136,19 @@ def create_msg(q,rcptlist,origmsg=None,template=None):
|
|||||||
hdrs,body = template.split('\n\n',1)
|
hdrs,body = template.split('\n\n',1)
|
||||||
for ln in hdrs.splitlines():
|
for ln in hdrs.splitlines():
|
||||||
name,val = ln.split(':',1)
|
name,val = ln.split(':',1)
|
||||||
msg.add_header(name,(val % locals()).strip())
|
msg.add_header(name,(val % v.__dict__).strip())
|
||||||
msg.set_payload(body % locals())
|
msg.set_payload(body % v.__dict__)
|
||||||
# add headers if missing from old template
|
# add headers if missing from old template
|
||||||
if 'to' not in msg:
|
if 'to' not in msg:
|
||||||
msg.add_header('To',sender)
|
msg.add_header('To',v.sender)
|
||||||
if 'from' not in msg:
|
if 'from' not in msg:
|
||||||
msg.add_header('From','postmaster@%s'%receiver)
|
msg.add_header('From','postmaster@%s'%v.receiver)
|
||||||
if 'auto-submitted' not in msg:
|
if 'auto-submitted' not in msg:
|
||||||
msg.add_header('Auto-Submitted','auto-generated')
|
msg.add_header('Auto-Submitted','auto-generated')
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
import spf
|
||||||
q = spf.query('192.168.9.50',
|
q = spf.query('192.168.9.50',
|
||||||
'SRS0=pmeHL=RH==stuart@example.com',
|
'SRS0=pmeHL=RH==stuart@example.com',
|
||||||
'red.example.com',receiver='mail.example.com')
|
'red.example.com',receiver='mail.example.com')
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import socket
|
|||||||
import email.Errors
|
import email.Errors
|
||||||
from fnmatch import fnmatchcase
|
from fnmatch import fnmatchcase
|
||||||
from email.Header import decode_header
|
from email.Header import decode_header
|
||||||
|
#import email.Utils
|
||||||
|
import rfc822
|
||||||
|
|
||||||
ip4re = re.compile(r'^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$')
|
ip4re = re.compile(r'^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$')
|
||||||
|
|
||||||
@@ -40,6 +42,44 @@ def iniplist(ipaddr,iplist):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def parseaddr(t):
|
||||||
|
"""Split email into Fullname and address.
|
||||||
|
|
||||||
|
>>> parseaddr('user@example.com')
|
||||||
|
('', 'user@example.com')
|
||||||
|
>>> parseaddr('"Full Name" <foo@example.com>')
|
||||||
|
('Full Name', 'foo@example.com')
|
||||||
|
>>> parseaddr('spam@spammer.com <foo@example.com>')
|
||||||
|
('spam@spammer.com', 'foo@example.com')
|
||||||
|
>>> parseaddr('God@heaven <@hop1.org,@hop2.net:jeff@spec.org>')
|
||||||
|
('God@heaven', 'jeff@spec.org')
|
||||||
|
>>> parseaddr('Real Name ((comment)) <addr...@example.com>')
|
||||||
|
('Real Name', 'addr...@example.com')
|
||||||
|
>>> parseaddr('a(WRONG)@b')
|
||||||
|
('WRONG', 'a@b')
|
||||||
|
"""
|
||||||
|
#return email.Utils.parseaddr(t)
|
||||||
|
res = rfc822.parseaddr(t)
|
||||||
|
# dirty fix for some broken cases
|
||||||
|
if not res[0]:
|
||||||
|
pos = t.find('<')
|
||||||
|
if pos > 0 and t[-1] == '>':
|
||||||
|
addrspec = t[pos+1:-1]
|
||||||
|
pos1 = addrspec.rfind(':')
|
||||||
|
if pos1 > 0:
|
||||||
|
addrspec = addrspec[pos1+1:]
|
||||||
|
return rfc822.parseaddr('"%s" <%s>' % (t[:pos].strip(),addrspec))
|
||||||
|
if not res[1]:
|
||||||
|
pos = t.find('<')
|
||||||
|
if pos > 0 and t[-1] == '>':
|
||||||
|
addrspec = t[pos+1:-1]
|
||||||
|
pos1 = addrspec.rfind(':')
|
||||||
|
if pos1 > 0:
|
||||||
|
addrspec = addrspec[pos1+1:]
|
||||||
|
return rfc822.parseaddr('%s<%s>' % (t[:pos].strip(),addrspec))
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
def parse_addr(t):
|
def parse_addr(t):
|
||||||
"""Split email into user,domain.
|
"""Split email into user,domain.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
Here is a history of user visible changes to Python milter.
|
See pymilter.spec for recent history.
|
||||||
|
|
||||||
|
Here is a history of older changes to Python milter.
|
||||||
0.8.8 move AddrCache, parse_addr, iniplist, parse_header to Milter package
|
0.8.8 move AddrCache, parse_addr, iniplist, parse_header to Milter package
|
||||||
fix plock for missing source and can't change owner/group
|
fix plock for missing source and can't change owner/group
|
||||||
add sample spfmilter.py milter
|
add sample spfmilter.py milter
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
Don't match dynamic ptr in bestguess.
|
Check ESMTP NOTIFY before sending real DSNs. Just use CBV if DSNs are
|
||||||
|
not wanted.
|
||||||
|
|
||||||
|
Support CBV to local domains and cache results so that invalid users
|
||||||
|
can be rejected without maintaining valid user lists.
|
||||||
|
|
||||||
|
Now that we blacklist IPs for too many bad rcpts, delay SPF until RCPT TO.
|
||||||
|
|
||||||
When content filtering is not installed, reject BLACKLISTed MFROM
|
When content filtering is not installed, reject BLACKLISTed MFROM
|
||||||
immediately. There is no use waiting until EOM.
|
immediately. There is no use waiting until EOM.
|
||||||
@@ -10,7 +16,8 @@ MTA. The mail is flagged external, so we don't list example.com in
|
|||||||
internal_domains (or we would get "spam from self"). But, if we try to do a
|
internal_domains (or we would get "spam from self"). But, if we try to do a
|
||||||
CBV, we get "fraudulent MX", because the MX is ourself! So we need to
|
CBV, we get "fraudulent MX", because the MX is ourself! So we need to
|
||||||
avoid doing CBV on such domains. Currently, we try to make sure the SPF
|
avoid doing CBV on such domains. Currently, we try to make sure the SPF
|
||||||
policies don't do CBV.
|
policies don't do CBV. The real solution is for users to use SMTP AUTH,
|
||||||
|
but some of them are stubborn.
|
||||||
|
|
||||||
We now don't check internal domains for incoming mail if there is an
|
We now don't check internal domains for incoming mail if there is an
|
||||||
SPF record.
|
SPF record.
|
||||||
@@ -75,10 +82,6 @@ Whitelisted senders from trusted relay get PROBATION. Need to extracted
|
|||||||
SPF result from headers - and in the case of mail internal to relay
|
SPF result from headers - and in the case of mail internal to relay
|
||||||
(e.g. bmsi.com), supply 'pass' result.
|
(e.g. bmsi.com), supply 'pass' result.
|
||||||
|
|
||||||
For selected domains, check rcpts via CBV before accepting mail. Cache
|
|
||||||
results. This will kick out dictonary attacks against a mail domain
|
|
||||||
behind a gateway sooner.
|
|
||||||
|
|
||||||
Add auto-blacklisted senders to blacklist.log with timestamp.
|
Add auto-blacklisted senders to blacklist.log with timestamp.
|
||||||
Add emails blacklisted via CBV so that they are remembered across milter
|
Add emails blacklisted via CBV so that they are remembered across milter
|
||||||
restarts.
|
restarts.
|
||||||
@@ -95,8 +98,6 @@ e.g. verizon.net).
|
|||||||
Allow verified hostnames for trusted_relay. E.g. HELO name that
|
Allow verified hostnames for trusted_relay. E.g. HELO name that
|
||||||
passes SPF.
|
passes SPF.
|
||||||
|
|
||||||
Table of sendmail macros for documentation.
|
|
||||||
|
|
||||||
When do we get two hello calls? STARTTLS is one reason.
|
When do we get two hello calls? STARTTLS is one reason.
|
||||||
|
|
||||||
Option: accept mail from auto-whitelisted senders even with spf-fail,
|
Option: accept mail from auto-whitelisted senders even with spf-fail,
|
||||||
@@ -178,6 +179,18 @@ Need a test module to feed sample messages to a milter though a live
|
|||||||
sendmail and SMTP. The mockup currently used is probably not very accurate,
|
sendmail and SMTP. The mockup currently used is probably not very accurate,
|
||||||
and doesn't test the threading code.
|
and doesn't test the threading code.
|
||||||
|
|
||||||
|
DONE Table of sendmail macros for documentation. In API docs on milter.org.
|
||||||
|
|
||||||
|
DONE For selected domains, check rcpts via CBV before accepting mail. Cache
|
||||||
|
results. This will kick out dictonary attacks against a mail domain
|
||||||
|
behind a gateway sooner.
|
||||||
|
|
||||||
|
DONE Convert DSN to REJECT unless sender gets SPF pass or best guess pass. Make
|
||||||
|
configurable by SPF result with NOTSPAM policy (reject or deliver without DSN).
|
||||||
|
Maybe policy should be NODSN - still verify sender with CBV.
|
||||||
|
|
||||||
|
DONE Add parseaddr test case for 'foo@bar.com <baz@barf.biz>'
|
||||||
|
|
||||||
DONE Require signed MFROM for all incoming bounces when signing all outgoing
|
DONE Require signed MFROM for all incoming bounces when signing all outgoing
|
||||||
mail - except from trusted relays.
|
mail - except from trusted relays.
|
||||||
|
|
||||||
@@ -224,3 +237,4 @@ data structure as autowhitelist.log.
|
|||||||
|
|
||||||
DONE Backup copies for outgoing/incoming mail.
|
DONE Backup copies for outgoing/incoming mail.
|
||||||
|
|
||||||
|
DONE Don't match dynamic ptr in bestguess.
|
||||||
|
|||||||
@@ -1,6 +1,55 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# A simple milter that has grown quite a bit.
|
# A simple milter that has grown quite a bit.
|
||||||
# $Log$
|
# $Log$
|
||||||
|
# Revision 1.126 2008/08/18 17:47:57 customdesigned
|
||||||
|
# Log rcpt for SRS rejections.
|
||||||
|
#
|
||||||
|
# Revision 1.125 2008/08/06 00:52:38 customdesigned
|
||||||
|
# CBV policy sends no DSN. DSN policy sends DSN.
|
||||||
|
#
|
||||||
|
# Revision 1.124 2008/08/05 18:04:06 customdesigned
|
||||||
|
# Send quarantine DSN to SPF PASS only.
|
||||||
|
#
|
||||||
|
# Revision 1.123 2008/07/29 21:59:29 customdesigned
|
||||||
|
# Parse ESMTP params
|
||||||
|
#
|
||||||
|
# Revision 1.122 2008/05/08 21:35:56 customdesigned
|
||||||
|
# Allow explicitly whitelisted email from banned_users.
|
||||||
|
#
|
||||||
|
# Revision 1.121 2008/04/10 14:59:35 customdesigned
|
||||||
|
# Configure gossip TTL.
|
||||||
|
#
|
||||||
|
# Revision 1.120 2008/04/02 18:59:14 customdesigned
|
||||||
|
# Release 0.8.10
|
||||||
|
#
|
||||||
|
# Revision 1.119 2008/04/01 00:13:10 customdesigned
|
||||||
|
# Do not CBV whitelisted addresses. We already know they are good.
|
||||||
|
#
|
||||||
|
# Revision 1.118 2008/01/09 20:15:49 customdesigned
|
||||||
|
# Handle unquoted fullname when parsing email.
|
||||||
|
#
|
||||||
|
# Revision 1.117 2007/11/29 14:35:17 customdesigned
|
||||||
|
# Packaging tweaks.
|
||||||
|
#
|
||||||
|
# Revision 1.116 2007/11/01 20:09:14 customdesigned
|
||||||
|
# Support temperror policy in access.
|
||||||
|
#
|
||||||
|
# Revision 1.115 2007/10/10 18:23:54 customdesigned
|
||||||
|
# Send quarantine DSN to SPF pass (official or guessed) only.
|
||||||
|
# Reject blacklisted email too big for dspam.
|
||||||
|
#
|
||||||
|
# Revision 1.114 2007/10/10 18:07:50 customdesigned
|
||||||
|
# Check porn keywords in From header field.
|
||||||
|
#
|
||||||
|
# Revision 1.113 2007/09/25 16:37:26 customdesigned
|
||||||
|
# Tested on RH7
|
||||||
|
#
|
||||||
|
# Revision 1.112 2007/09/13 14:51:03 customdesigned
|
||||||
|
# Report domain on reputation reject.
|
||||||
|
#
|
||||||
|
# Revision 1.111 2007/07/25 17:14:59 customdesigned
|
||||||
|
# Move milter apps to /usr/lib/pymilter
|
||||||
|
#
|
||||||
# Revision 1.110 2007/07/02 03:06:10 customdesigned
|
# Revision 1.110 2007/07/02 03:06:10 customdesigned
|
||||||
# Ban ips on bad mailfrom offenses as well as bad rcpts.
|
# Ban ips on bad mailfrom offenses as well as bad rcpts.
|
||||||
#
|
#
|
||||||
@@ -152,17 +201,19 @@ import gc
|
|||||||
import anydbm
|
import anydbm
|
||||||
import Milter.dsn as dsn
|
import Milter.dsn as dsn
|
||||||
from Milter.dynip import is_dynip as dynip
|
from Milter.dynip import is_dynip as dynip
|
||||||
from Milter.utils import iniplist,parse_addr,parse_header,ip4re,addr2bin
|
from Milter.utils import \
|
||||||
|
iniplist,parse_addr,parse_header,ip4re,addr2bin,parseaddr
|
||||||
from Milter.config import MilterConfigParser
|
from Milter.config import MilterConfigParser
|
||||||
|
|
||||||
from fnmatch import fnmatchcase
|
from fnmatch import fnmatchcase
|
||||||
from email.Utils import getaddresses,parseaddr
|
from email.Utils import getaddresses
|
||||||
|
|
||||||
# Import gossip if available
|
# Import gossip if available
|
||||||
try:
|
try:
|
||||||
import gossip
|
import gossip
|
||||||
import gossip.client
|
import gossip.client
|
||||||
import gossip.server
|
import gossip.server
|
||||||
|
gossip_node = None
|
||||||
except: gossip = None
|
except: gossip = None
|
||||||
|
|
||||||
# Import pysrs if available
|
# Import pysrs if available
|
||||||
@@ -244,6 +295,7 @@ hello_blacklist = ()
|
|||||||
smart_alias = {}
|
smart_alias = {}
|
||||||
dspam_dict = None
|
dspam_dict = None
|
||||||
dspam_users = {}
|
dspam_users = {}
|
||||||
|
dspam_train = {}
|
||||||
dspam_userdir = None
|
dspam_userdir = None
|
||||||
dspam_exempt = {}
|
dspam_exempt = {}
|
||||||
dspam_whitelist = {}
|
dspam_whitelist = {}
|
||||||
@@ -277,6 +329,7 @@ milter_log = logging.getLogger('milter')
|
|||||||
def read_config(list):
|
def read_config(list):
|
||||||
cp = MilterConfigParser({
|
cp = MilterConfigParser({
|
||||||
'tempdir': "/var/log/milter/save",
|
'tempdir': "/var/log/milter/save",
|
||||||
|
'datadir': "/var/log/milter",
|
||||||
'socket': "/var/run/milter/pythonsock",
|
'socket': "/var/run/milter/pythonsock",
|
||||||
'timeout': '600',
|
'timeout': '600',
|
||||||
'scan_html': 'no',
|
'scan_html': 'no',
|
||||||
@@ -296,6 +349,7 @@ def read_config(list):
|
|||||||
})
|
})
|
||||||
cp.read(list)
|
cp.read(list)
|
||||||
if cp.has_option('milter','datadir'):
|
if cp.has_option('milter','datadir'):
|
||||||
|
print "chdir:",cp.get('milter','datadir')
|
||||||
os.chdir(cp.get('milter','datadir'))
|
os.chdir(cp.get('milter','datadir'))
|
||||||
|
|
||||||
# milter section
|
# milter section
|
||||||
@@ -373,6 +427,7 @@ def read_config(list):
|
|||||||
dspam_users = cp.getaddrdict('dspam','dspam_users')
|
dspam_users = cp.getaddrdict('dspam','dspam_users')
|
||||||
dspam_userdir = cp.getdefault('dspam','dspam_userdir')
|
dspam_userdir = cp.getdefault('dspam','dspam_userdir')
|
||||||
dspam_screener = cp.getlist('dspam','dspam_screener')
|
dspam_screener = cp.getlist('dspam','dspam_screener')
|
||||||
|
dspam_train = set(cp.getlist('dspam','dspam_train'))
|
||||||
dspam_reject = cp.getlist('dspam','dspam_reject')
|
dspam_reject = cp.getlist('dspam','dspam_reject')
|
||||||
dspam_internal = cp.getboolean('dspam','dspam_internal')
|
dspam_internal = cp.getboolean('dspam','dspam_internal')
|
||||||
if cp.has_option('dspam','dspam_sizelimit'):
|
if cp.has_option('dspam','dspam_sizelimit'):
|
||||||
@@ -420,7 +475,7 @@ def read_config(list):
|
|||||||
banned_users = cp.getlist('srs','banned_users')
|
banned_users = cp.getlist('srs','banned_users')
|
||||||
|
|
||||||
if gossip:
|
if gossip:
|
||||||
global gossip_node
|
global gossip_node, gossip_ttl
|
||||||
if cp.has_option('gossip','server'):
|
if cp.has_option('gossip','server'):
|
||||||
server = cp.get('gossip','server')
|
server = cp.get('gossip','server')
|
||||||
host,port = gossip.splitaddr(server)
|
host,port = gossip.splitaddr(server)
|
||||||
@@ -430,6 +485,10 @@ def read_config(list):
|
|||||||
for p in cp.getlist('gossip','peers'):
|
for p in cp.getlist('gossip','peers'):
|
||||||
host,port = gossip.splitaddr(p)
|
host,port = gossip.splitaddr(p)
|
||||||
gossip_node.peers.append(gossip.server.Peer(host,port))
|
gossip_node.peers.append(gossip.server.Peer(host,port))
|
||||||
|
if cp.has_option('gossip','ttl'):
|
||||||
|
gossip_ttl = cp.getint('gossip','ttl')
|
||||||
|
else:
|
||||||
|
gossip_ttl = 1
|
||||||
|
|
||||||
def findsrs(fp):
|
def findsrs(fp):
|
||||||
lastln = None
|
lastln = None
|
||||||
@@ -453,6 +512,12 @@ def findsrs(fp):
|
|||||||
lastln = ln
|
lastln = ln
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def param2dict(str):
|
||||||
|
pairs = [x.split('=',1) for x in str]
|
||||||
|
for e in pairs:
|
||||||
|
if len(e) < 2: e.append(None)
|
||||||
|
return dict([(k.upper(),v) for k,v in pairs])
|
||||||
|
|
||||||
class SPFPolicy(object):
|
class SPFPolicy(object):
|
||||||
"Get SPF policy by result from sendmail style access file."
|
"Get SPF policy by result from sendmail style access file."
|
||||||
def __init__(self,sender):
|
def __init__(self,sender):
|
||||||
@@ -525,6 +590,12 @@ class SPFPolicy(object):
|
|||||||
policy = 'REJECT'
|
policy = 'REJECT'
|
||||||
return policy
|
return policy
|
||||||
|
|
||||||
|
def getTempErrorPolicy(self):
|
||||||
|
policy = self.getPolicy('spf-temperror:')
|
||||||
|
if not policy:
|
||||||
|
policy = 'REJECT'
|
||||||
|
return policy
|
||||||
|
|
||||||
def getPassPolicy(self):
|
def getPassPolicy(self):
|
||||||
policy = self.getPolicy('spf-pass:')
|
policy = self.getPolicy('spf-pass:')
|
||||||
if not policy:
|
if not policy:
|
||||||
@@ -534,11 +605,8 @@ class SPFPolicy(object):
|
|||||||
from Milter.cache import AddrCache
|
from Milter.cache import AddrCache
|
||||||
|
|
||||||
cbv_cache = AddrCache(renew=7)
|
cbv_cache = AddrCache(renew=7)
|
||||||
cbv_cache.load('send_dsn.log',age=30)
|
auto_whitelist = AddrCache(renew=60)
|
||||||
auto_whitelist = AddrCache(renew=30)
|
|
||||||
auto_whitelist.load('auto_whitelist.log',age=120)
|
|
||||||
blacklist = AddrCache(renew=30)
|
blacklist = AddrCache(renew=30)
|
||||||
blacklist.load('blacklist.log',age=60)
|
|
||||||
|
|
||||||
class bmsMilter(Milter.Milter):
|
class bmsMilter(Milter.Milter):
|
||||||
"""Milter to replace attachments poisonous to Windows with a WARNING message,
|
"""Milter to replace attachments poisonous to Windows with a WARNING message,
|
||||||
@@ -675,6 +743,9 @@ class bmsMilter(Milter.Milter):
|
|||||||
# of each message.
|
# of each message.
|
||||||
def envfrom(self,f,*str):
|
def envfrom(self,f,*str):
|
||||||
self.log("mail from",f,str)
|
self.log("mail from",f,str)
|
||||||
|
#param = param2dict(str)
|
||||||
|
#self.envid = param.get('ENVID',None)
|
||||||
|
#self.mail_param = param
|
||||||
self.fp = StringIO.StringIO()
|
self.fp = StringIO.StringIO()
|
||||||
self.tempname = None
|
self.tempname = None
|
||||||
self.mailfrom = f
|
self.mailfrom = f
|
||||||
@@ -717,9 +788,9 @@ class bmsMilter(Milter.Milter):
|
|||||||
|
|
||||||
self.user = self.getsymval('{auth_authen}')
|
self.user = self.getsymval('{auth_authen}')
|
||||||
if self.user:
|
if self.user:
|
||||||
# Very simple SMTP AUTH policy by defaul:
|
# Very simple SMTP AUTH policy by default:
|
||||||
# any successful authentication is considered INTERNAL
|
# any successful authentication is considered INTERNAL
|
||||||
# FIXME: configure allowed MAIL FROM by user
|
# Detailed authorization policy is configured in the access file below.
|
||||||
self.internal_connection = True
|
self.internal_connection = True
|
||||||
self.log(
|
self.log(
|
||||||
"SMTP AUTH:",self.user, self.getsymval('{auth_type}'),
|
"SMTP AUTH:",self.user, self.getsymval('{auth_type}'),
|
||||||
@@ -805,6 +876,8 @@ class bmsMilter(Milter.Milter):
|
|||||||
else:
|
else:
|
||||||
self.dspam = False
|
self.dspam = False
|
||||||
self.log("PROBATION",self.canon_from)
|
self.log("PROBATION",self.canon_from)
|
||||||
|
if res not in ('permerror','softfail'):
|
||||||
|
self.cbv_needed = None
|
||||||
elif cbv_cache.has_key(self.canon_from) and cbv_cache[self.canon_from] \
|
elif cbv_cache.has_key(self.canon_from) and cbv_cache[self.canon_from] \
|
||||||
or domain in blacklist:
|
or domain in blacklist:
|
||||||
if not self.internal_connection:
|
if not self.internal_connection:
|
||||||
@@ -824,7 +897,8 @@ class bmsMilter(Milter.Milter):
|
|||||||
else:
|
else:
|
||||||
global gossip
|
global gossip
|
||||||
if gossip and domain and rc == Milter.CONTINUE \
|
if gossip and domain and rc == Milter.CONTINUE \
|
||||||
and not (self.internal_connection or self.trusted_relay):
|
and not (self.internal_connection or self.trusted_relay) \
|
||||||
|
and gossip_node:
|
||||||
if self.spf and self.spf.result == 'pass':
|
if self.spf and self.spf.result == 'pass':
|
||||||
qual = 'SPF'
|
qual = 'SPF'
|
||||||
elif res == 'pass':
|
elif res == 'pass':
|
||||||
@@ -846,6 +920,7 @@ class bmsMilter(Milter.Milter):
|
|||||||
self.reputation = int(a[-2])
|
self.reputation = int(a[-2])
|
||||||
self.confidence = int(a[-1])
|
self.confidence = int(a[-1])
|
||||||
self.umis = umis
|
self.umis = umis
|
||||||
|
self.from_domain = domain
|
||||||
# We would like to reject on bad reputation here, but we
|
# We would like to reject on bad reputation here, but we
|
||||||
# need to give special consideration to postmaster. So
|
# need to give special consideration to postmaster. So
|
||||||
# we have to wait until envrcpt(). Perhaps an especially
|
# we have to wait until envrcpt(). Perhaps an especially
|
||||||
@@ -878,13 +953,22 @@ class bmsMilter(Milter.Milter):
|
|||||||
res,code,txt = q.check()
|
res,code,txt = q.check()
|
||||||
q.result = res
|
q.result = res
|
||||||
if res in ('unknown','permerror') and q.perm_error and q.perm_error.ext:
|
if res in ('unknown','permerror') and q.perm_error and q.perm_error.ext:
|
||||||
self.cbv_needed = (q,res) # report SPF syntax error to sender
|
self.cbv_needed = (q,'permerror') # report SPF syntax error to sender
|
||||||
res,code,txt = q.perm_error.ext # extended (lax processing) result
|
res,code,txt = q.perm_error.ext # extended (lax processing) result
|
||||||
txt = 'EXT: ' + txt
|
txt = 'EXT: ' + txt
|
||||||
p = SPFPolicy(q.s)
|
p = SPFPolicy(q.s)
|
||||||
# FIXME: try:finally to close policy db, or reuse with lock
|
# FIXME: try:finally to close policy db, or reuse with lock
|
||||||
|
if res in ('error','temperror'):
|
||||||
|
if self.need_cbv(p.getTempErrorPolicy(),q,'temperror'):
|
||||||
|
self.log('TEMPFAIL: SPF %s %i %s' % (res,code,txt))
|
||||||
|
self.setreply(str(code),'4.3.0',txt,
|
||||||
|
'We cannot accept your email until the DNS server for %s' % q.o,
|
||||||
|
'is operational for TXT record queries.'
|
||||||
|
)
|
||||||
|
return Milter.TEMPFAIL
|
||||||
|
res,code,txt = 'none',250,'EXT: ignoring DNS error'
|
||||||
hres = None
|
hres = None
|
||||||
if res not in ('pass','error','temperror'):
|
if res != 'pass':
|
||||||
if self.mailfrom != '<>':
|
if self.mailfrom != '<>':
|
||||||
# check hello name via spf unless spf pass
|
# check hello name via spf unless spf pass
|
||||||
h = spf.query(self.connectip,'',self.hello_name,receiver=receiver)
|
h = spf.query(self.connectip,'',self.hello_name,receiver=receiver)
|
||||||
@@ -929,11 +1013,9 @@ class bmsMilter(Milter.Milter):
|
|||||||
and hres != 'pass':
|
and hres != 'pass':
|
||||||
# this bad boy has no credentials whatsoever
|
# this bad boy has no credentials whatsoever
|
||||||
policy = p.getNonePolicy()
|
policy = p.getNonePolicy()
|
||||||
if policy == 'CBV':
|
if policy in ('CBV','DNS'):
|
||||||
if self.mailfrom != '<>':
|
self.offenses = 3 # ban ip if any bad recipient
|
||||||
self.cbv_needed = (q,ores) # accept, but inform sender via DSN
|
if self.need_cbv(policy,q,'strike3'):
|
||||||
self.offenses = 3 # ban ip if any bad recipient
|
|
||||||
elif policy != 'OK':
|
|
||||||
self.log('REJECT: no PTR, HELO or SPF')
|
self.log('REJECT: no PTR, HELO or SPF')
|
||||||
self.setreply('550','5.7.1',
|
self.setreply('550','5.7.1',
|
||||||
"You must have a valid HELO or publish SPF: http://www.openspf.org ",
|
"You must have a valid HELO or publish SPF: http://www.openspf.org ",
|
||||||
@@ -942,13 +1024,9 @@ class bmsMilter(Milter.Milter):
|
|||||||
"that contain your IP don't count), an invalid or dynamic HELO, ",
|
"that contain your IP don't count), an invalid or dynamic HELO, ",
|
||||||
"and no SPF record."
|
"and no SPF record."
|
||||||
)
|
)
|
||||||
return Milter.REJECT
|
return self.offense() # ban ip if too many bad MFROMs
|
||||||
if res in ('deny', 'fail'):
|
if res in ('deny', 'fail'):
|
||||||
policy = p.getFailPolicy()
|
if self.need_cbv(p.getFailPolicy(),q,'fail'):
|
||||||
if policy == 'CBV':
|
|
||||||
if self.mailfrom != '<>':
|
|
||||||
self.cbv_needed = (q,res)
|
|
||||||
elif policy != 'OK':
|
|
||||||
self.log('REJECT: SPF %s %i %s' % (res,code,txt))
|
self.log('REJECT: SPF %s %i %s' % (res,code,txt))
|
||||||
self.setreply(str(code),'5.7.1',txt)
|
self.setreply(str(code),'5.7.1',txt)
|
||||||
# A proper SPF fail error message would read:
|
# A proper SPF fail error message would read:
|
||||||
@@ -956,11 +1034,7 @@ class bmsMilter(Milter.Milter):
|
|||||||
# "forged.org" in the sender address. Contact <postmaster@forged.org>.
|
# "forged.org" in the sender address. Contact <postmaster@forged.org>.
|
||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
if res == 'softfail':
|
if res == 'softfail':
|
||||||
policy = p.getSoftfailPolicy()
|
if self.need_cbv(p.getSoftfailPolicy(),q,'softfail'):
|
||||||
if policy == 'CBV':
|
|
||||||
if self.mailfrom != '<>':
|
|
||||||
self.cbv_needed = (q,res)
|
|
||||||
elif policy != 'OK':
|
|
||||||
self.log('REJECT: SPF %s %i %s' % (res,code,txt))
|
self.log('REJECT: SPF %s %i %s' % (res,code,txt))
|
||||||
self.setreply('550','5.7.1',
|
self.setreply('550','5.7.1',
|
||||||
'SPF softfail: If you get this Delivery Status Notice, your email',
|
'SPF softfail: If you get this Delivery Status Notice, your email',
|
||||||
@@ -971,12 +1045,7 @@ class bmsMilter(Milter.Milter):
|
|||||||
)
|
)
|
||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
if res == 'neutral':
|
if res == 'neutral':
|
||||||
policy = p.getNeutralPolicy()
|
if self.need_cbv(p.getNeutralPolicy(),q,'neutral'):
|
||||||
if policy == 'CBV':
|
|
||||||
if self.mailfrom != '<>':
|
|
||||||
self.cbv_needed = (q,res)
|
|
||||||
# FIXME: this makes Received-SPF show wrong result
|
|
||||||
elif policy != 'OK':
|
|
||||||
self.log('REJECT: SPF neutral for',q.s)
|
self.log('REJECT: SPF neutral for',q.s)
|
||||||
self.setreply('550','5.7.1',
|
self.setreply('550','5.7.1',
|
||||||
'mail from %s must pass SPF: http://openspf.org/why.html' % q.o,
|
'mail from %s must pass SPF: http://openspf.org/why.html' % q.o,
|
||||||
@@ -988,11 +1057,7 @@ class bmsMilter(Milter.Milter):
|
|||||||
)
|
)
|
||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
if res in ('unknown','permerror'):
|
if res in ('unknown','permerror'):
|
||||||
policy = p.getPermErrorPolicy()
|
if self.need_cbv(p.getPermErrorPolicy(),q,'permerror'):
|
||||||
if policy == 'CBV':
|
|
||||||
if self.mailfrom != '<>':
|
|
||||||
self.cbv_needed = (q,res)
|
|
||||||
elif policy != 'OK':
|
|
||||||
self.log('REJECT: SPF %s %i %s' % (res,code,txt))
|
self.log('REJECT: SPF %s %i %s' % (res,code,txt))
|
||||||
# latest SPF draft recommends 5.5.2 instead of 5.7.1
|
# latest SPF draft recommends 5.5.2 instead of 5.7.1
|
||||||
self.setreply(str(code),'5.5.2',txt,
|
self.setreply(str(code),'5.5.2',txt,
|
||||||
@@ -1000,10 +1065,6 @@ class bmsMilter(Milter.Milter):
|
|||||||
'We cannot accept mail from %s until this is corrected.' % q.o
|
'We cannot accept mail from %s until this is corrected.' % q.o
|
||||||
)
|
)
|
||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
if res in ('error','temperror'):
|
|
||||||
self.log('TEMPFAIL: SPF %s %i %s' % (res,code,txt))
|
|
||||||
self.setreply(str(code),'4.3.0',txt)
|
|
||||||
return Milter.TEMPFAIL
|
|
||||||
kv = {}
|
kv = {}
|
||||||
if hres and q.h != q.o:
|
if hres and q.h != q.o:
|
||||||
kv['helo_spf'] = hres
|
kv['helo_spf'] = hres
|
||||||
@@ -1019,6 +1080,15 @@ class bmsMilter(Milter.Milter):
|
|||||||
# track header mods separately from body mods - so use only
|
# track header mods separately from body mods - so use only
|
||||||
# in emergencies.
|
# in emergencies.
|
||||||
def envrcpt(self,to,*str):
|
def envrcpt(self,to,*str):
|
||||||
|
try:
|
||||||
|
param = param2dict(str)
|
||||||
|
self.notify = param.get('NOTIFY','FAILURE,DELAY').upper().split(',')
|
||||||
|
if 'NEVER' in self.notify: self.notify = ()
|
||||||
|
#self.rcpt_param = param
|
||||||
|
except:
|
||||||
|
self.log("REJECT: invalid PARAM:",to,str)
|
||||||
|
self.setreply('550','5.7.1','Invalid SRS signature')
|
||||||
|
return Milter.REJECT
|
||||||
# mail to MAILER-DAEMON is generally spam that bounced
|
# mail to MAILER-DAEMON is generally spam that bounced
|
||||||
if to.startswith('<MAILER-DAEMON@'):
|
if to.startswith('<MAILER-DAEMON@'):
|
||||||
self.log('REJECT: RCPT TO:',to,str)
|
self.log('REJECT: RCPT TO:',to,str)
|
||||||
@@ -1057,10 +1127,13 @@ class bmsMilter(Milter.Milter):
|
|||||||
self.setreply('550','5.7.1','Invalid SES signature')
|
self.setreply('550','5.7.1','Invalid SES signature')
|
||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
# reject for certain recipients are delayed until after DATA
|
# reject for certain recipients are delayed until after DATA
|
||||||
if srs_reject_spoofed \
|
if auto_whitelist.has_precise_key(self.canon_from):
|
||||||
and not user.lower() in ('postmaster','abuse'):
|
self.log("WHITELIST: DSN from",self.canon_from)
|
||||||
return self.forged_bounce()
|
else:
|
||||||
self.data_allowed = not srs_reject_spoofed
|
if srs_reject_spoofed \
|
||||||
|
and user.lower() not in ('postmaster','abuse'):
|
||||||
|
return self.forged_bounce(to)
|
||||||
|
self.data_allowed = not srs_reject_spoofed
|
||||||
|
|
||||||
if not self.internal_connection and domain in private_relay:
|
if not self.internal_connection and domain in private_relay:
|
||||||
self.log('REJECT: RELAY:',to)
|
self.log('REJECT: RELAY:',to)
|
||||||
@@ -1083,7 +1156,7 @@ class bmsMilter(Milter.Milter):
|
|||||||
self.log('REJECT: RCPT TO:',to,str)
|
self.log('REJECT: RCPT TO:',to,str)
|
||||||
if gossip and self.umis:
|
if gossip and self.umis:
|
||||||
gossip_node.feedback(self.umis,1)
|
gossip_node.feedback(self.umis,1)
|
||||||
self.umis = None
|
self.umis = None
|
||||||
return self.offense()
|
return self.offense()
|
||||||
# FIXME: should dspam_exempt be case insensitive?
|
# FIXME: should dspam_exempt be case insensitive?
|
||||||
if user in block_forward.get(domain,()):
|
if user in block_forward.get(domain,()):
|
||||||
@@ -1096,9 +1169,10 @@ class bmsMilter(Milter.Milter):
|
|||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
self.dspam = False
|
self.dspam = False
|
||||||
if userl != 'postmaster' and self.umis \
|
if userl != 'postmaster' and self.umis \
|
||||||
and self.reputation < -50 and self.confidence > 1:
|
and self.reputation < -50 and self.confidence > 3:
|
||||||
|
domain = self.from_domain
|
||||||
self.log('REJECT: REPUTATION, rcpt to',to,str)
|
self.log('REJECT: REPUTATION, rcpt to',to,str)
|
||||||
self.setreply('550','5.7.1','Your domain has been sending mostly spam')
|
self.setreply('550','5.7.1','%s has been sending mostly spam'%domain)
|
||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
|
|
||||||
if domain in hide_path:
|
if domain in hide_path:
|
||||||
@@ -1172,7 +1246,14 @@ class bmsMilter(Milter.Milter):
|
|||||||
# original sender (encoded in Message-ID) is blacklisted
|
# original sender (encoded in Message-ID) is blacklisted
|
||||||
|
|
||||||
elif lname == 'from':
|
elif lname == 'from':
|
||||||
name,email = parseaddr(val)
|
fname,email = parseaddr(val)
|
||||||
|
# check for porn keywords
|
||||||
|
lval = fname.lower().strip()
|
||||||
|
for w in porn_words:
|
||||||
|
if lval.find(w) >= 0:
|
||||||
|
self.log('REJECT: %s: %s' % (name,val))
|
||||||
|
self.setreply('550','5.7.1','Watch your language')
|
||||||
|
return Milter.REJECT
|
||||||
if email.lower().startswith('postmaster@'):
|
if email.lower().startswith('postmaster@'):
|
||||||
# Yes, if From header comes last, this might not help much.
|
# Yes, if From header comes last, this might not help much.
|
||||||
# But this is a heuristic - if MTAs would send proper DSNs in
|
# But this is a heuristic - if MTAs would send proper DSNs in
|
||||||
@@ -1193,9 +1274,9 @@ class bmsMilter(Milter.Milter):
|
|||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
return Milter.CONTINUE
|
return Milter.CONTINUE
|
||||||
|
|
||||||
def forged_bounce(self):
|
def forged_bounce(self,rcpt='-'):
|
||||||
if self.mailfrom != '<>':
|
if self.mailfrom != '<>':
|
||||||
self.log("REJECT: bogus DSN")
|
self.log("REJECT: bogus DSN",rcpt)
|
||||||
self.setreply('550','5.7.1',
|
self.setreply('550','5.7.1',
|
||||||
"I do not accept normal mail from %s." % self.mailfrom.split('@')[0],
|
"I do not accept normal mail from %s." % self.mailfrom.split('@')[0],
|
||||||
"All such mail has turned out to be Delivery Status Notifications",
|
"All such mail has turned out to be Delivery Status Notifications",
|
||||||
@@ -1203,7 +1284,7 @@ class bmsMilter(Milter.Milter):
|
|||||||
"you need to. Use another MAIL FROM if you need to send me mail."
|
"you need to. Use another MAIL FROM if you need to send me mail."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.log('REJECT: bounce with no SRS encoding')
|
self.log('REJECT: bounce with no SRS encoding',rcpt)
|
||||||
self.setreply('550','5.7.1',
|
self.setreply('550','5.7.1',
|
||||||
"I did not send you that message. Please consider implementing SPF",
|
"I did not send you that message. Please consider implementing SPF",
|
||||||
"(http://openspf.org) to avoid bouncing mail to spoofed senders.",
|
"(http://openspf.org) to avoid bouncing mail to spoofed senders.",
|
||||||
@@ -1413,6 +1494,12 @@ class bmsMilter(Milter.Milter):
|
|||||||
elif not self.internal_connection or dspam_internal:
|
elif not self.internal_connection or dspam_internal:
|
||||||
if len(txt) > dspam_sizelimit:
|
if len(txt) > dspam_sizelimit:
|
||||||
self.log("Large message:",len(txt))
|
self.log("Large message:",len(txt))
|
||||||
|
if self.blacklist:
|
||||||
|
self.log('REJECT: BLACKLISTED')
|
||||||
|
self.setreply('550','5.7.1',
|
||||||
|
'%s has been blacklisted.'%self.canon_from)
|
||||||
|
self.fp = None
|
||||||
|
return Milter.REJECT
|
||||||
return False
|
return False
|
||||||
if user == 'honeypot' and Dspam.VERSION >= '1.1.9':
|
if user == 'honeypot' and Dspam.VERSION >= '1.1.9':
|
||||||
keep = False # keep honeypot mail
|
keep = False # keep honeypot mail
|
||||||
@@ -1424,9 +1511,12 @@ class bmsMilter(Milter.Milter):
|
|||||||
return False
|
return False
|
||||||
if self.spf and self.mailfrom != '<>':
|
if self.spf and self.mailfrom != '<>':
|
||||||
# check that sender accepts quarantine DSN
|
# check that sender accepts quarantine DSN
|
||||||
msg = mime.message_from_file(StringIO.StringIO(txt))
|
if self.spf.result == 'pass':
|
||||||
rc = self.send_dsn(self.spf,msg,'quarantine')
|
msg = mime.message_from_file(StringIO.StringIO(txt))
|
||||||
del msg
|
rc = self.send_dsn(self.spf,msg,'quarantine')
|
||||||
|
del msg
|
||||||
|
else:
|
||||||
|
rc = self.send_dsn(self.spf)
|
||||||
if rc != Milter.CONTINUE:
|
if rc != Milter.CONTINUE:
|
||||||
return rc
|
return rc
|
||||||
ds.check_spam(user,txt,self.recipients,quarantine=True,
|
ds.check_spam(user,txt,self.recipients,quarantine=True,
|
||||||
@@ -1444,8 +1534,13 @@ class bmsMilter(Milter.Milter):
|
|||||||
elif self.blacklist:
|
elif self.blacklist:
|
||||||
txt = ds.check_spam(user,txt,self.recipients,
|
txt = ds.check_spam(user,txt,self.recipients,
|
||||||
force_result=dspam.DSR_ISSPAM)
|
force_result=dspam.DSR_ISSPAM)
|
||||||
else:
|
elif user in dspam_train:
|
||||||
txt = ds.check_spam(user,txt,self.recipients)
|
txt = ds.check_spam(user,txt,self.recipients)
|
||||||
|
else:
|
||||||
|
txt = ds.check_spam(user,txt,self.recipients,classify=True)
|
||||||
|
if txt:
|
||||||
|
self.add_header("X-DSpam-Score",'%f' % ds.probability)
|
||||||
|
return False
|
||||||
if not txt:
|
if not txt:
|
||||||
# DISCARD if quarrantined for any recipient. It
|
# DISCARD if quarrantined for any recipient. It
|
||||||
# will be resent to all recipients if they submit
|
# will be resent to all recipients if they submit
|
||||||
@@ -1476,7 +1571,7 @@ class bmsMilter(Milter.Milter):
|
|||||||
ds.check_spam(screener,txt,self.recipients,
|
ds.check_spam(screener,txt,self.recipients,
|
||||||
force_result=dspam.DSR_ISINNOCENT)
|
force_result=dspam.DSR_ISINNOCENT)
|
||||||
return False
|
return False
|
||||||
if self.reject_spam:
|
if self.reject_spam and self.spf.result != 'pass':
|
||||||
self.log("DSPAM:",screener,
|
self.log("DSPAM:",screener,
|
||||||
'REJECT: X-DSpam-Score: %f' % ds.probability)
|
'REJECT: X-DSpam-Score: %f' % ds.probability)
|
||||||
self.setreply('550','5.7.1','Your Message looks spammy')
|
self.setreply('550','5.7.1','Your Message looks spammy')
|
||||||
@@ -1486,12 +1581,18 @@ class bmsMilter(Milter.Milter):
|
|||||||
if self.spf and self.mailfrom != '<>':
|
if self.spf and self.mailfrom != '<>':
|
||||||
# check that sender accepts quarantine DSN
|
# check that sender accepts quarantine DSN
|
||||||
self.fp.seek(0)
|
self.fp.seek(0)
|
||||||
msg = mime.message_from_file(self.fp)
|
if self.spf.result == 'pass' or self.cbv_needed:
|
||||||
rc = self.send_dsn(self.spf,msg,'quarantine')
|
msg = mime.message_from_file(self.fp)
|
||||||
|
if self.spf.result == 'pass':
|
||||||
|
rc = self.send_dsn(self.spf,msg,'quarantine')
|
||||||
|
else:
|
||||||
|
rc = self.do_needed_cbv(msg)
|
||||||
|
del msg
|
||||||
|
else:
|
||||||
|
rc = self.send_dsn(self.spf)
|
||||||
if rc != Milter.CONTINUE:
|
if rc != Milter.CONTINUE:
|
||||||
self.fp = None
|
self.fp = None
|
||||||
return rc
|
return rc
|
||||||
del msg
|
|
||||||
if not ds.check_spam(screener,txt,self.recipients,classify=True):
|
if not ds.check_spam(screener,txt,self.recipients,classify=True):
|
||||||
self.fp = None
|
self.fp = None
|
||||||
return Milter.DISCARD
|
return Milter.DISCARD
|
||||||
@@ -1534,6 +1635,22 @@ class bmsMilter(Milter.Milter):
|
|||||||
quarantine=False)
|
quarantine=False)
|
||||||
self.log("TRAINSPAM:",screener,'X-Dspam-Score: %f' % ds.probability)
|
self.log("TRAINSPAM:",screener,'X-Dspam-Score: %f' % ds.probability)
|
||||||
|
|
||||||
|
def do_needed_cbv(self,msg):
|
||||||
|
q,template_name = self.cbv_needed
|
||||||
|
rc = self.send_dsn(q,msg,template_name)
|
||||||
|
self.cbv_needed = None
|
||||||
|
return rc
|
||||||
|
|
||||||
|
def need_cbv(self,policy,q,tname):
|
||||||
|
if policy == 'CBV':
|
||||||
|
if self.mailfrom != '<>' and not self.cbv_needed:
|
||||||
|
self.cbv_needed = (q,None)
|
||||||
|
elif policy == 'DSN':
|
||||||
|
if self.mailfrom != '<>' and not self.cbv_needed:
|
||||||
|
self.cbv_needed = (q,tname)
|
||||||
|
elif policy != 'OK': return True
|
||||||
|
return False
|
||||||
|
|
||||||
def eom(self):
|
def eom(self):
|
||||||
if not self.fp:
|
if not self.fp:
|
||||||
return Milter.ACCEPT # no message collected - so no eom processing
|
return Milter.ACCEPT # no message collected - so no eom processing
|
||||||
@@ -1654,22 +1771,12 @@ class bmsMilter(Milter.Milter):
|
|||||||
except Milter.error:
|
except Milter.error:
|
||||||
self.addheader(name,val) # older sendmail can't insheader
|
self.addheader(name,val) # older sendmail can't insheader
|
||||||
|
|
||||||
# do not send CBV to internal domains (since we'll just get
|
# Do not send CBV to internal domains (since we'll just get
|
||||||
# the "Fraudulent MX" error).
|
# the "Fraudulent MX" error). Whitelisted senders clearly do not
|
||||||
|
# need CBV. However, whitelisted domains might (to discover
|
||||||
|
# bogus localparts). Need a way to tell the difference.
|
||||||
if self.cbv_needed and not self.internal_domain:
|
if self.cbv_needed and not self.internal_domain:
|
||||||
q,res = self.cbv_needed
|
rc = self.do_needed_cbv(msg)
|
||||||
if res == 'softfail':
|
|
||||||
template_name = 'softfail'
|
|
||||||
elif res in ('fail','deny'):
|
|
||||||
template_name = 'fail'
|
|
||||||
elif res in ('unknown','permerror'):
|
|
||||||
template_name = 'permerror'
|
|
||||||
elif res == 'neutral':
|
|
||||||
template_name = 'neutral'
|
|
||||||
else:
|
|
||||||
template_name = 'strike3'
|
|
||||||
rc = self.send_dsn(q,msg,template_name)
|
|
||||||
self.cbv_needed = None
|
|
||||||
if rc == Milter.REJECT:
|
if rc == Milter.REJECT:
|
||||||
# Do not feedback here, because feedback should only occur
|
# Do not feedback here, because feedback should only occur
|
||||||
# for messages that have gone to DATA. Reputation lets us
|
# for messages that have gone to DATA. Reputation lets us
|
||||||
@@ -1737,22 +1844,24 @@ class bmsMilter(Milter.Milter):
|
|||||||
out.close()
|
out.close()
|
||||||
return Milter.TEMPFAIL
|
return Milter.TEMPFAIL
|
||||||
|
|
||||||
def send_dsn(self,q,msg,template_name):
|
def send_dsn(self,q,msg=None,template_name=None):
|
||||||
sender = q.s
|
sender = q.s
|
||||||
cached = cbv_cache.has_key(sender)
|
cached = cbv_cache.has_key(sender)
|
||||||
if cached:
|
if cached:
|
||||||
self.log('CBV:',sender,'(cached)')
|
self.log('CBV:',sender,'(cached)')
|
||||||
res = cbv_cache[sender]
|
res = cbv_cache[sender]
|
||||||
else:
|
else:
|
||||||
fname = template_name+'.txt'
|
m = None
|
||||||
try:
|
if template_name:
|
||||||
template = file(template_name+'.txt').read()
|
fname = template_name+'.txt'
|
||||||
self.log('CBV:',sender,'Using:',fname)
|
try:
|
||||||
except IOError:
|
template = file(template_name+'.txt').read()
|
||||||
template = None
|
m = dsn.create_msg(q,self.recipients,msg,template)
|
||||||
|
self.log('CBV:',sender,'Using:',fname)
|
||||||
|
except IOError: pass
|
||||||
|
if not m:
|
||||||
self.log('CBV:',sender,'PLAIN')
|
self.log('CBV:',sender,'PLAIN')
|
||||||
m = dsn.create_msg(q,self.recipients,msg,template)
|
else:
|
||||||
if m:
|
|
||||||
if srs:
|
if srs:
|
||||||
# Add SRS coded sender to various headers. When (incorrectly)
|
# Add SRS coded sender to various headers. When (incorrectly)
|
||||||
# replying to our DSN, any of these which are preserved
|
# replying to our DSN, any of these which are preserved
|
||||||
@@ -1776,7 +1885,10 @@ class bmsMilter(Milter.Milter):
|
|||||||
return Milter.TEMPFAIL
|
return Milter.TEMPFAIL
|
||||||
cbv_cache[sender] = res
|
cbv_cache[sender] = res
|
||||||
self.log('REJECT:',desc)
|
self.log('REJECT:',desc)
|
||||||
self.setreply('550','5.7.1',*desc.splitlines())
|
try:
|
||||||
|
self.setreply('550','5.7.1',*desc.splitlines())
|
||||||
|
except TypeError:
|
||||||
|
self.setreply('550','5.7.1',"Callback failure")
|
||||||
return Milter.REJECT
|
return Milter.REJECT
|
||||||
cbv_cache[sender] = res
|
cbv_cache[sender] = res
|
||||||
return Milter.CONTINUE
|
return Milter.CONTINUE
|
||||||
@@ -1824,6 +1936,10 @@ def main():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
read_config(["/etc/mail/pymilter.cfg","milter.cfg"])
|
read_config(["/etc/mail/pymilter.cfg","milter.cfg"])
|
||||||
|
|
||||||
|
cbv_cache.load('send_dsn.log',age=30)
|
||||||
|
auto_whitelist.load('auto_whitelist.log',age=120)
|
||||||
|
blacklist.load('blacklist.log',age=60)
|
||||||
|
|
||||||
if dspam_dict:
|
if dspam_dict:
|
||||||
import dspam # low level spam check
|
import dspam # low level spam check
|
||||||
if dspam_userdir:
|
if dspam_userdir:
|
||||||
|
|||||||
@@ -2,6 +2,47 @@ Title: Recent Changes
|
|||||||
|
|
||||||
<h2> Recent Changes </h2>
|
<h2> Recent Changes </h2>
|
||||||
|
|
||||||
|
<h3> 0.8.10 </h3>
|
||||||
|
|
||||||
|
SRS rejections now log the recipient.
|
||||||
|
I have finally implemented plain CBV (no DSN). The CBV policy
|
||||||
|
will do a plain CBV from now on, and the DSN policy is required
|
||||||
|
if you want to send a DSN.
|
||||||
|
I started checking the MAIL FROM fullname (human readable part
|
||||||
|
of an email) for porn keywords. There is now a banned IP database.
|
||||||
|
IPs are banned for too many bad MAIL FROMs or RCPT TOs, and remain banned
|
||||||
|
for 7 days.
|
||||||
|
|
||||||
|
<h3> 0.8.9 </h3>
|
||||||
|
|
||||||
|
I use the <code>%ifarch</code> hack to build milter and milter-spf
|
||||||
|
packages as noarch, while pymilter is built as native.
|
||||||
|
|
||||||
|
I removed the spf dependency from dsn.py, so pymilter can be used without
|
||||||
|
installing pyspf, and added a Milter.dns module to let python milters do
|
||||||
|
general DNS lookups without loading pyspf.
|
||||||
|
|
||||||
|
<h3> 0.8.8 </h3>
|
||||||
|
|
||||||
|
Programs do not belong in the /var/log directory. I moved the
|
||||||
|
milter apps to /usr/lib/pymilter. Since having the programs and
|
||||||
|
data in the same directory is convenient for debugging, it will
|
||||||
|
still use an executable present in the datadir.
|
||||||
|
|
||||||
|
Several general utility classes and functions are now in the Milter package
|
||||||
|
for possible use by other python milters. In addition to the trivial example
|
||||||
|
milter, a simple SPF only milter is included as a realistic example.
|
||||||
|
|
||||||
|
The spec file now build 3 RPMs:
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li> pymilter is the milter module and Milter package for use by all python
|
||||||
|
milters.
|
||||||
|
<li> milter is the all-singing, all-dancing python milter application, with
|
||||||
|
supporting <code>/etc/init.d</code>, logrotate and other scripts.
|
||||||
|
<li> milter-spf is the simple SPF only milter application.
|
||||||
|
</ul>
|
||||||
|
|
||||||
<h3> 0.8.7 </h3>
|
<h3> 0.8.7 </h3>
|
||||||
|
|
||||||
The spf module has been moved to the
|
The spf module has been moved to the
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ Title: Credits
|
|||||||
<a href="mailto:Jim Niemira <urmane@urmane.org>">Jim Niemira</a>
|
<a href="mailto:Jim Niemira <urmane@urmane.org>">Jim Niemira</a>
|
||||||
wrote the original C module and some quick
|
wrote the original C module and some quick
|
||||||
and dirty python to use it.
|
and dirty python to use it.
|
||||||
<a href="mailto:Stuart Gathman <stuart@bmsi.com>">Stuart D. Gathman</a>
|
<a href="http://gathman.org/vitae">Stuart D. Gathman</a>
|
||||||
took that kludge and added threading and context objects to it, wrote a proper
|
took that kludge and added threading and context objects to it, wrote a proper
|
||||||
OO wrapper (Milter.py) that handles attachments, did lots of testing, packaged
|
OO wrapper (Milter.py) that handles attachments, did lots of testing, packaged
|
||||||
it with distutils, and generally transformed it from a quick hack to a
|
it with distutils, and generally transformed it from a quick hack to a
|
||||||
|
|||||||
+102
-145
@@ -4,8 +4,7 @@ Title: Python Milter Mail Policy
|
|||||||
|
|
||||||
These are the policies implemented by the <code>bms.py</code> milter
|
These are the policies implemented by the <code>bms.py</code> milter
|
||||||
application. The milter and Milter modules do not implement any policies
|
application. The milter and Milter modules do not implement any policies
|
||||||
by themselves. Eventually, I'll get the bms.py milter moved to its
|
by themselves.
|
||||||
own package.
|
|
||||||
|
|
||||||
<h3> Classify connection </h3>
|
<h3> Classify connection </h3>
|
||||||
|
|
||||||
@@ -77,161 +76,119 @@ altered accordingly.
|
|||||||
|
|
||||||
<h2> SPF check </h2>
|
<h2> SPF check </h2>
|
||||||
|
|
||||||
Finally, the MAIL FROM, connect IP, and HELO name are checked against
|
The MAIL FROM, connect IP, and HELO name are checked against
|
||||||
any SPF records published via DNS for the alleged sender (MAIL FROM).
|
any SPF records published via DNS for the alleged sender (MAIL FROM)
|
||||||
If there is no SPF record, we check for a local substitute under the
|
to determine the official SPF policy result.
|
||||||
domain defined in the <code>[spf]delegate</code> configuration.
|
The offical SPF result is then logged in the Received-SPF header field,
|
||||||
Further checks depend on the result.
|
but certain results are subjected to further processing to create
|
||||||
|
an effective result for policy purposes.
|
||||||
|
|
||||||
<table border=1>
|
If the official result is 'none', we try to turn it into an effective result of
|
||||||
<tr><th>NONE</th><td>
|
'pass' or 'fail'. First, we check for a local substitute SPF record
|
||||||
If there is no SPF record (official or delegated), then we
|
under the domain defined in the <code>[spf]delegate</code> configuration.
|
||||||
initiate a "three strikes and your out" regime, which looks for
|
It is often useful to add local SPF records for correspondents that are
|
||||||
<b>some</b> form of validated identification.
|
too clueless to add their own. If there is no local substitute, we use a "best
|
||||||
<ol>
|
guess" SPF record of "v=spf1 a/24 mx/24 ptr" for MAIL FROM or "v=spf1 a/24
|
||||||
<li>We try a "best guess" SPF record of "v=spf1 a/24 mx/24 ptr". If this
|
mx/24" for HELO. In addition, a HELO that is a subdomain of MAIL FROM and
|
||||||
passes, good.
|
resolves to the connect IP results in an effective result of 'pass'.
|
||||||
<li> We try to validate the HELO name. First check for an SPF record.
|
|
||||||
Otherwise, check whether the connect IP matches any A record for
|
If there is no local SPF record, and the effective result is still not
|
||||||
the HELO name, or any A record for any MX name for the HELO name,
|
'pass', we check for either a valid HELO name or a valid PTR record for
|
||||||
or is at least in the same /24 subnet as any of the above.
|
the connect IP. A valid HELO or PTR cannot look like a dynamic name
|
||||||
(In other words, a HELO SPF "best guess" of "v=spf1 a/24 mx/24".)
|
as determined by the heuristic in <code>Milter.dynip</code>.
|
||||||
If so, good. We consider the HELO validated. If the HELO SPF
|
|
||||||
check fails, we reject the email.
|
If HELO has an SPF record, and the result is anything but pass, we reject
|
||||||
</ol>
|
the connection:
|
||||||
<pre>
|
<pre>
|
||||||
2005Jul30 19:45:16 [93991] connect from [221.200.41.54] at ('221.200.41.54', 3581) EXTERNAL DYN
|
2005Jul30 19:45:16 [93991] connect from [221.200.41.54] at ('221.200.41.54', 3581) EXTERNAL DYN
|
||||||
2005Jul30 19:45:18 [93991] hello from adelphia.net
|
2005Jul30 19:45:18 [93991] hello from adelphia.net
|
||||||
2005Jul30 19:45:19 [93991] mail from <wendy.stubbsua@link-it.com> ()
|
2005Jul30 19:45:19 [93991] mail from <wendy.stubbsua@link-it.com> ()
|
||||||
2005Jul30 19:45:19 [93991] REJECT: hello SPF: fail 550 access denied
|
2005Jul30 19:45:19 [93991] REJECT: hello SPF: fail 550 access denied
|
||||||
</pre>
|
</pre>
|
||||||
<ol>
|
Note that HELO does not have any forwarding issues like MAIL FROM, and so
|
||||||
<li> If there is a validated PTR name, and it doesn't look
|
any result other than 'pass' or 'none' should be treated like 'fail'.
|
||||||
like a dynamic name, good. We consider the connection validated.
|
|
||||||
</ol>
|
|
||||||
If any of the above can be validated, we continue on.
|
|
||||||
If none of the above can be validated, and the <code>[SPF]reject_noptr</code>
|
|
||||||
option is true, we reject the message immediately with the explanation
|
|
||||||
that we need some form of valid identification before we accept an email.
|
|
||||||
If <code>[SPF]reject_noptr</code> is false, we flag the message as
|
|
||||||
needing Call Back Validation.
|
|
||||||
The Call Back Valildation sends a DSN to the purported sender informing
|
|
||||||
them of the lack of identification. If the message is legitimate, the
|
|
||||||
sender needs to know that their email setup is broken and should be corrected.
|
|
||||||
If the message is forged, the sender is informed of the forgery,
|
|
||||||
and their need to publish an SPF record or at least use a valid HELO name.
|
|
||||||
If the purported sender does not accept the DSN,
|
|
||||||
then the message is rejected. The CBV status is cached to avoid
|
|
||||||
annoying the purported sender with too many DSNs. Currently, the DSN
|
|
||||||
is repeated to the same sender once per month.
|
|
||||||
<p>
|
|
||||||
In this example, although 3com.com has no SPF record, we assume that
|
|
||||||
any legitimate mail from them will at least have a valid HELO or PTR.
|
|
||||||
<pre>
|
|
||||||
2005Jul30 23:52:03 [96777] connect from [222.252.233.200] at ('222.252.233.200', 29934) EXTERNAL DYN
|
|
||||||
2005Jul30 23:52:03 [96777] hello from 3mail.3com.com
|
|
||||||
2005Jul30 23:52:04 [96777] mail from <etec_nic_family@3mail.3com.com> ()
|
|
||||||
2005Jul30 23:52:04 [96777] REJECT: no PTR, HELO or SPF
|
|
||||||
</pre>
|
|
||||||
</td></tr>
|
|
||||||
|
|
||||||
<tr><th>PASS</th><td>
|
Only if nothing about the SMTP envelope can be validated does the effective
|
||||||
A pass result normally lets the email continue on, but the domain is
|
result remain 'none. I call this the "3 strikes" rule.
|
||||||
tracked for reputation (and may be blocked), and may skip content scanning if
|
|
||||||
it matches a whitelist.
|
|
||||||
<pre>
|
|
||||||
2005Jul24 17:44:26 [2104] mail from <gnucash-devel-bounces@gnucash.org> ('SIZE=4410',)
|
|
||||||
2005Jul24 17:44:26 [2104] Received-SPF: pass (mail.bmsi.com: domain of gnucash.org
|
|
||||||
designates 204.107.200.65 as permitted sender)
|
|
||||||
client-ip=204.107.200.65; envelope-from=gnucash-devel-bounces@gnucash.org; helo=cvs.gnucash.org;
|
|
||||||
</pre>
|
|
||||||
</td></tr>
|
|
||||||
|
|
||||||
<tr><th>NEUTRAL</th><td>
|
If the official result is 'permerror' (a syntax error in the sender's
|
||||||
A neutral result normally lets the email continue on, but the domain is not
|
policy), we use the 'lax' option in pyspf to try various heuristics to guess
|
||||||
tracked for reputation or matched against any whitelists.
|
what they really meant. For instance, the invalid mechanism "ip:1.2.3.4" is
|
||||||
Highly forged domains listed in <code>[SPF]reject_neutral</code> are
|
treated as "ip4:1.2.3.4". The result of lax processing is then used
|
||||||
rejected.
|
as the effective result for policy purposes.
|
||||||
<pre>
|
|
||||||
2005Jul24 17:41:37 [2070] connect from cp500627-a.dbsch1.nb.home.nl at ('84.27.225.3', 3465) EXTERNAL
|
|
||||||
2005Jul24 17:41:37 [2070] hello from cp500627-a.dbsch1.nb.home.nl
|
|
||||||
2005Jul24 17:41:38 [2070] mail from <nwarjejkw@yahoo.com> ()
|
|
||||||
2005Jul24 17:41:38 [2070] REJECT: SPF neutral for nwarjejkw@yahoo.com
|
|
||||||
</pre>
|
|
||||||
</td></tr>
|
|
||||||
|
|
||||||
<tr><th>SOFTFAIL</th><td>
|
With an effective SPF result in hand, we consult the sendmail access
|
||||||
A softfail result normally lets the email continue on, but the domain is not
|
database to find our receiver policy for the sender.
|
||||||
tracked for reputation or matched against any whitelists. Furthermore,
|
|
||||||
the message is flagged as needing Call Back Validation,
|
|
||||||
and the highly forged domains listed in <code>[SPF]reject_neutral</code> are
|
|
||||||
rejected as well.
|
|
||||||
<p>
|
|
||||||
At present, we also require a valid HELO or PTR to avoid rejecting
|
|
||||||
a softfail. But this should probably change to only require a
|
|
||||||
successful CBV.
|
|
||||||
<p>
|
|
||||||
The Call Back Valildation sends a DSN to the purported sender informing
|
|
||||||
them of the softfail. If the message is legitimate, the sender needs
|
|
||||||
to know about the softfail so that their email setup can be corrected.
|
|
||||||
If the message is forged, the sender is informed of the forgery, confirming
|
|
||||||
that SPF is protecting their reputation and encouraging a rapid transition
|
|
||||||
to a strict policy. If the purported sender does not accept the DSN,
|
|
||||||
then the message is rejected. The CBV status is cached to avoid
|
|
||||||
annoying the purported sender with too many DSNs. Currently, the DSN
|
|
||||||
is repeated to the same sender once per month.
|
|
||||||
<pre>
|
|
||||||
2005Jul24 15:41:33 [801] mail from <Aitp@horafeliz.com> ()
|
|
||||||
2005Jul24 15:41:33 [801] Received-SPF: softfail (mail.bmsi.com: transitioning domain of horafeliz.com
|
|
||||||
does not designate 221.184.83.185 as permitted sender)
|
|
||||||
client-ip=221.184.83.185; envelope-from=Aitp@horafeliz.com;
|
|
||||||
helo=p8185-ipad30funabasi.chiba.ocn.ne.jp;
|
|
||||||
2005Jul24 15:41:33 [801] rcpt to <david@example.com> ()
|
|
||||||
2005Jul24 15:41:35 [801] Subject: Microsoft, Adobe, Macromedia, Corel software. Up to 80% discount.
|
|
||||||
2005Jul24 15:41:35 [801] X-Mailer: Microsoft Outlook, Build 10.0.2605
|
|
||||||
2005Jul24 15:41:35 [801] CBV: Aitp@horafeliz.com
|
|
||||||
2005Jul24 15:41:38 [801] REJECT: CBV: 550 <Aitp@horafeliz.com>: User unknown
|
|
||||||
</pre>
|
|
||||||
</td></tr>
|
|
||||||
|
|
||||||
<tr><th>FAIL</th><td>
|
<table border=1>
|
||||||
The message is rejected with a reference the SPF why page.
|
<tr><th>REJECT</th><td>
|
||||||
<pre>
|
Reject the sender with a 550 5.7.1 SMTP code. The SMTP rejection
|
||||||
2005Jul30 19:53:27 [94070] connect from [212.70.52.16] at ('212.70.52.16', 3192) EXTERNAL DYN
|
includes a detailed description of the problem.
|
||||||
2005Jul30 19:53:27 [94070] hello from winzip.com
|
|
||||||
2005Jul30 19:53:27 [94070] mail from <dan@winzip.com> ()
|
|
||||||
2005Jul30 19:53:27 [94070] REJECT: SPF fail 550 SPF fail:
|
|
||||||
see http://openspf.com/why.html?sender=dan@winzip.com&ip=212.70.52.16
|
|
||||||
</pre>
|
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
<tr><th>CBV</th><td>
|
||||||
<tr><th>PERMERROR</th><td>
|
Do a Call Back Validation by connecting to an MX of the sender
|
||||||
Permanent errors were called "unknown", and are still show that way
|
and checking that using the sender as the RCPT TO is not rejected.
|
||||||
in the log. The message is rejected. Previously, we enabled "lax" parsing
|
We quit the CBV connection before actualling sending a message.
|
||||||
of the SPF record, but rejecting is better because it informs the
|
If the CBV is rejected, our SMTP connection is rejected with the
|
||||||
sender about their problem. The next milter version will
|
same error code and message. CBV results are cached.
|
||||||
look for a local substitute SPF record (as for a missing SPF record)
|
|
||||||
before rejecting. This will inform the sender of their problem, but
|
|
||||||
also let the receiver install a temporary workaround.
|
|
||||||
<pre>
|
|
||||||
2005Jul24 18:05:37 [2312] mail from <b-mihdbcgaacaa-becibijh-000-@msg.euxiphipops.com> ()
|
|
||||||
2005Jul24 18:05:37 [2312] REJECT: SPF unknown 550 SPF Permanent Error:
|
|
||||||
include mechanism missing domain: include
|
|
||||||
</pre>
|
|
||||||
The SPF record for msg.euxiphipops.com looked like this at the time of the
|
|
||||||
above error:
|
|
||||||
<pre>
|
|
||||||
msg.euxiphipops.com TXT "v=spf1 mx ptr a include"
|
|
||||||
</pre>
|
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
<tr><th>DSN</th><td>
|
||||||
<tr><th>TEMPERROR</th><td>
|
Do a Call Back Validation by connecting to an MX of the sender
|
||||||
Temporary errors result in a 451 "Try again later" response. The sender
|
and checking that using the sender as the RCPT TO is not rejected.
|
||||||
should retry the message at a later time.
|
Unlike a CBV, we continue on to data and send a detailed message
|
||||||
<pre>
|
explaining the problem. This can be useful for reporting PermError
|
||||||
2005Jul24 07:33:13 [29846] mail from <quickenloans@rate.quicken.com> ('SIZE=73775', 'BODY=8BITMIME')
|
or SoftFail to the sender. Keep in mind that for any result other
|
||||||
2005Jul24 07:33:43 [29846] TEMPFAIL: SPF error 450 SPF Temporary Error: DNS Timeout
|
than 'pass', the sender could be forged, and your DSN could annoy the
|
||||||
</pre>
|
wrong person. However, a SoftFail result is requesting such feedback
|
||||||
|
for debugging and a PermError result needs to be fixed by the sender ASAP
|
||||||
|
whether forged or not. DSN results are cached so that senders are
|
||||||
|
annoyed only weekly.
|
||||||
|
</td></tr>
|
||||||
|
<tr><th>OK</th><td>
|
||||||
|
Accept the sender. The message may still be rejected via reputation
|
||||||
|
or content filtering.
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<h3> SPF policy syntax </h3>
|
||||||
|
|
||||||
|
First, the full sender is checked:
|
||||||
|
<pre>
|
||||||
|
SPF-Fail:abeb@adelphia.net DSN
|
||||||
|
</pre>
|
||||||
|
This says to accept mail from that adelphia.net user despite the
|
||||||
|
SPF fail, but only after annoying them with a DSN about their ISP's broken
|
||||||
|
policy.
|
||||||
|
|
||||||
|
If there is no match on the full sender, the domain is checked:
|
||||||
|
<pre>
|
||||||
|
SPF-Neutral:aol.com REJECT
|
||||||
|
</pre>
|
||||||
|
This says to reject mail from AOL with an SPF result of neutral.
|
||||||
|
This means AOL users can't use their AOL address with another mail service
|
||||||
|
to send us mail. This is good because the other mail service is
|
||||||
|
likely a badly configured greeting card site or a virus.
|
||||||
|
|
||||||
|
Finally, a default policy for the result is checked. While there are program
|
||||||
|
defaults, you should have defaults in the access database for SPF results:
|
||||||
|
<pre>
|
||||||
|
SPF-Neutral: CBV
|
||||||
|
SPF-Softfail: DSN
|
||||||
|
SPF-PermError: DSN
|
||||||
|
SPF-TempError: REJECT
|
||||||
|
SPF-None: REJECT
|
||||||
|
SPF-Fail: REJECT
|
||||||
|
SPF-Pass: OK
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h2> Reputation </h2>
|
||||||
|
|
||||||
|
If the sender has not been rejected by this point, and if a GOSSiP server is
|
||||||
|
configured, we consult GOSSiP for the reputation score of the sender and
|
||||||
|
SPF result. The score is a number from -100 to 100 with a confidence
|
||||||
|
percentage from 0 to 100. A really bad reputation (less than -50 with
|
||||||
|
confidence greater than 3) is rejected. Note that the reputation is tracked
|
||||||
|
independently for each SPF result and sender combination. So aol.com:neutral
|
||||||
|
might have a really bad reputation, while aol.com:pass would be ok.
|
||||||
|
Furthermore, when a sender finally publishes an SPF policy and starts
|
||||||
|
getting SPF pass, their reputation is effectively reset.
|
||||||
|
|||||||
+14
-2
@@ -1,4 +1,6 @@
|
|||||||
[milter]
|
[milter]
|
||||||
|
# the directory with log and data files
|
||||||
|
datadir = /var/log/milter
|
||||||
# the socket used to communicate with sendmail. Must match sendmail.cf
|
# the socket used to communicate with sendmail. Must match sendmail.cf
|
||||||
socket=/var/run/milter/pythonsock
|
socket=/var/run/milter/pythonsock
|
||||||
# where to save original copies of defanged and failed messages
|
# where to save original copies of defanged and failed messages
|
||||||
@@ -25,7 +27,10 @@ internal_connect = 192.168.0.0/16,127.*
|
|||||||
;trusted_relay = 1.2.3.4, 66.12.34.56
|
;trusted_relay = 1.2.3.4, 66.12.34.56
|
||||||
|
|
||||||
# Relaying to these domains is allowed from internal connections only.
|
# Relaying to these domains is allowed from internal connections only.
|
||||||
;private_relay = mycorp.com
|
# You might want to restrict aol.com, for instance, so that stupid
|
||||||
|
# users don't forward their spam to aol for filtering and get your MTA
|
||||||
|
# blacklisted by aol.
|
||||||
|
;private_relay = aol.com, yahoo.com
|
||||||
|
|
||||||
# Reject external senders with hello names no legit external sender would use.
|
# Reject external senders with hello names no legit external sender would use.
|
||||||
# SPF will do this also, but listing your own domain and mailserver here
|
# SPF will do this also, but listing your own domain and mailserver here
|
||||||
@@ -57,7 +62,7 @@ porn_words = penis, breast, pussy, horse cock, porn, xenical, diet pill, d1ck,
|
|||||||
p-e-n-i-s, hydrocodone, vicodin, xanax, vicod1n, x@nax, diazepam,
|
p-e-n-i-s, hydrocodone, vicodin, xanax, vicod1n, x@nax, diazepam,
|
||||||
v1@gra, xan@x, cialis, ci@lis, frëe, xãnax, valíum, vãlium, via-gra,
|
v1@gra, xan@x, cialis, ci@lis, frëe, xãnax, valíum, vãlium, via-gra,
|
||||||
x@n3x, vicod3n, penís, c0d1n, phentermine, en1arge, dip1oma, v1codin,
|
x@n3x, vicod3n, penís, c0d1n, phentermine, en1arge, dip1oma, v1codin,
|
||||||
valium, rolex, sexual, fuck, adv1t
|
valium, rolex, sexual, fuck, adv1t, vgaira, medz, acai berry
|
||||||
# reject mail with these case sensitive strings in the subject
|
# reject mail with these case sensitive strings in the subject
|
||||||
spam_words = $$$, !!!, XXX, FREE, HGH
|
spam_words = $$$, !!!, XXX, FREE, HGH
|
||||||
# attachments with these extensions will be replaced with a warning
|
# attachments with these extensions will be replaced with a warning
|
||||||
@@ -186,6 +191,11 @@ blind = 1
|
|||||||
|
|
||||||
# Map email addresses and aliases to dspam users
|
# Map email addresses and aliases to dspam users
|
||||||
;dspam_users=david,goliath,spam,falsepositive
|
;dspam_users=david,goliath,spam,falsepositive
|
||||||
|
# List dspam users which train on all delivered messages, as opposed to
|
||||||
|
# "train on error" which trains only when a spam or falsepositive is reported.
|
||||||
|
# Training mode will build the dictionary faster, but requires close attention
|
||||||
|
# so as not to miss any spam or false positives.
|
||||||
|
;dspam_train=goliath
|
||||||
;david=david@foocorp.com,david.yelnetz@foocorp.com,david@bar.foocorp.com
|
;david=david@foocorp.com,david.yelnetz@foocorp.com,david@bar.foocorp.com
|
||||||
;goliath=giant@foocorp.com,goliath.philistine@foocorp.com
|
;goliath=giant@foocorp.com,goliath.philistine@foocorp.com
|
||||||
# address to forward spam to. milter will process these and not deliver
|
# address to forward spam to. milter will process these and not deliver
|
||||||
@@ -211,6 +221,8 @@ blind = 1
|
|||||||
# Use a dedicated GOSSiP server. If not specified, a local database
|
# Use a dedicated GOSSiP server. If not specified, a local database
|
||||||
# will be used.
|
# will be used.
|
||||||
;server=host:11900
|
;server=host:11900
|
||||||
|
# To include peers of a peer in reputation, set ttl=2
|
||||||
|
;ttl=1
|
||||||
# If a local database is used, also consult these GOSSiP servers about
|
# If a local database is used, also consult these GOSSiP servers about
|
||||||
# domains. Peer reputation is also tracked as to how often they
|
# domains. Peer reputation is also tracked as to how often they
|
||||||
# agree with us, and weighted accordingly.
|
# agree with us, and weighted accordingly.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pidof() {
|
|||||||
# Source function library.
|
# Source function library.
|
||||||
. /etc/rc.d/init.d/functions
|
. /etc/rc.d/init.d/functions
|
||||||
|
|
||||||
[ -x /var/log/milter/start.sh ] || exit 0
|
[ -x /usr/lib/pymilter/start.sh ] || exit 0
|
||||||
|
|
||||||
RETVAL=0
|
RETVAL=0
|
||||||
prog="milter"
|
prog="milter"
|
||||||
@@ -36,7 +36,7 @@ start() {
|
|||||||
mkdir -p /var/run/milter
|
mkdir -p /var/run/milter
|
||||||
chown mail:mail /var/run/milter
|
chown mail:mail /var/run/milter
|
||||||
fi
|
fi
|
||||||
daemon --check milter --user mail /var/log/milter/start.sh milter bms
|
daemon --check milter --user mail /usr/lib/pymilter/start.sh milter bms
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
echo
|
echo
|
||||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/milter
|
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/milter
|
||||||
@@ -46,7 +46,7 @@ start() {
|
|||||||
stop() {
|
stop() {
|
||||||
# Stop daemons.
|
# Stop daemons.
|
||||||
echo -n "Shutting down $prog: "
|
echo -n "Shutting down $prog: "
|
||||||
killproc milter
|
killproc -d 9 milter
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
echo
|
echo
|
||||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/milter
|
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/milter
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ pidof() {
|
|||||||
# Source function library.
|
# Source function library.
|
||||||
. /etc/rc.d/init.d/functions
|
. /etc/rc.d/init.d/functions
|
||||||
|
|
||||||
[ -x /var/log/milter/start.sh ] || exit 0
|
[ -x /usr/lib/pymilter/start.sh ] || exit 0
|
||||||
|
|
||||||
RETVAL=0
|
RETVAL=0
|
||||||
prog="milter"
|
prog="milter"
|
||||||
@@ -36,7 +36,7 @@ start() {
|
|||||||
mkdir -p /var/run/milter
|
mkdir -p /var/run/milter
|
||||||
chown mail:mail /var/run/milter
|
chown mail:mail /var/run/milter
|
||||||
fi
|
fi
|
||||||
daemon --check milter --user mail /var/log/milter/start.sh milter bms
|
daemon --check milter --user mail /usr/lib/pymilter/start.sh milter bms
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
echo
|
echo
|
||||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/milter
|
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/milter
|
||||||
|
|||||||
+16
-12
@@ -1,19 +1,20 @@
|
|||||||
/* Copyright (C) 2001 James Niemira (niemira@colltech.com, urmane@urmane.org)
|
/* Copyright (C) 2001 James Niemira (niemira@colltech.com, urmane@urmane.org)
|
||||||
* Portions Copyright (C) 2001,2002,2003,2004 Stuart Gathman (stuart@bmsi.com)
|
* Portions Copyright (C) 2001,2002,2003,2004,2005,2006,2007
|
||||||
|
* Stuart Gathman (stuart@bmsi.com)
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* modify it under the terms of the GNU General Public License
|
* under the terms of the GNU General Public License as published by the
|
||||||
* as published by the Free Software Foundation; either version 2
|
* Free Software Foundation, either version 2 of the License, or (at your
|
||||||
* of the License, or (at your option) any later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* GNU General Public License for more details.
|
* General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License along
|
||||||
* along with this program; if not, write to the Free Software
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* milterContext object and thread interface contributed by
|
* milterContext object and thread interface contributed by
|
||||||
* Stuart D. Gathman <stuart@bmsi.com>
|
* Stuart D. Gathman <stuart@bmsi.com>
|
||||||
@@ -34,6 +35,9 @@ $ python setup.py help
|
|||||||
libraries=["milter","smutil","resolv"]
|
libraries=["milter","smutil","resolv"]
|
||||||
|
|
||||||
* $Log$
|
* $Log$
|
||||||
|
* Revision 1.10 2006/02/12 02:00:42 customdesigned
|
||||||
|
* Resolve FIXME for wrap_close.
|
||||||
|
*
|
||||||
* Revision 1.9 2005/12/23 21:46:36 customdesigned
|
* Revision 1.9 2005/12/23 21:46:36 customdesigned
|
||||||
* Compile on sendmail-8.12 (ifdef SMFIR_INSHEADER)
|
* Compile on sendmail-8.12 (ifdef SMFIR_INSHEADER)
|
||||||
*
|
*
|
||||||
|
|||||||
+120
-72
@@ -1,6 +1,10 @@
|
|||||||
%define name pymilter
|
# This spec file contains 2 noarch packages in addition to the pymilter
|
||||||
%define version 0.8.8
|
# module. To compile all three on 32-bit Intel, use:
|
||||||
%define release 1
|
# rpmbuild -ba --target=i386,noarch pymilter.spec
|
||||||
|
|
||||||
|
%define __python python2.4
|
||||||
|
%define version 0.8.10
|
||||||
|
%define release 2%{?dist}.py24
|
||||||
# what version of RH are we building for?
|
# what version of RH are we building for?
|
||||||
%define redhat7 0
|
%define redhat7 0
|
||||||
|
|
||||||
@@ -18,22 +22,19 @@
|
|||||||
%define sysvinit milter.rc
|
%define sysvinit milter.rc
|
||||||
%endif
|
%endif
|
||||||
# RH9, other systems (single ps line per process)
|
# RH9, other systems (single ps line per process)
|
||||||
%ifos Linux
|
|
||||||
%define python python
|
|
||||||
%else
|
|
||||||
%define python python
|
|
||||||
%endif
|
|
||||||
%ifos aix4.1
|
%ifos aix4.1
|
||||||
%define libdir /var/log/milter
|
%define libdir /var/log/milter
|
||||||
%else
|
%else
|
||||||
%define libdir /usr/lib/pymilter
|
%define libdir /usr/lib/pymilter
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
Summary: Python interface to sendmail milter API
|
%ifarch noarch
|
||||||
Name: %{name}
|
Name: milter
|
||||||
|
Group: Applications/System
|
||||||
|
Summary: BMS spam and reputation milter
|
||||||
Version: %{version}
|
Version: %{version}
|
||||||
Release: %{release}
|
Release: %{release}
|
||||||
Source: %{name}-%{version}.tar.gz
|
Source: pymilter-%{version}.tar.gz
|
||||||
#Patch: %{name}-%{version}.patch
|
#Patch: %{name}-%{version}.patch
|
||||||
License: GPL
|
License: GPL
|
||||||
Group: Development/Libraries
|
Group: Development/Libraries
|
||||||
@@ -42,22 +43,10 @@ Prefix: %{_prefix}
|
|||||||
Vendor: Stuart D. Gathman <stuart@bmsi.com>
|
Vendor: Stuart D. Gathman <stuart@bmsi.com>
|
||||||
Packager: Stuart D. Gathman <stuart@bmsi.com>
|
Packager: Stuart D. Gathman <stuart@bmsi.com>
|
||||||
Url: http://www.bmsi.com/python/milter.html
|
Url: http://www.bmsi.com/python/milter.html
|
||||||
Requires: %{python} >= 2.4, sendmail >= 8.13
|
Requires: %{__python} >= 2.4, pyspf >= 2.0.4, pymilter
|
||||||
%ifos Linux
|
%ifos Linux
|
||||||
Requires: chkconfig
|
Requires: chkconfig
|
||||||
%endif
|
%endif
|
||||||
BuildRequires: %{python}-devel >= 2.4, sendmail-devel >= 8.13
|
|
||||||
|
|
||||||
%description
|
|
||||||
This is a python extension module to enable python scripts to
|
|
||||||
attach to sendmail's libmilter functionality. Additional python
|
|
||||||
modules provide for navigating and modifying MIME parts, sending
|
|
||||||
DSNs, and doing CBV.
|
|
||||||
|
|
||||||
%package -n milter
|
|
||||||
Group: Applications/System
|
|
||||||
Summary: BMS spam and reputation milter
|
|
||||||
Requires: pyspf >= 2.0.4
|
|
||||||
|
|
||||||
%description -n milter
|
%description -n milter
|
||||||
A complex but effective spam filtering, SPF checking, and reputation tracking
|
A complex but effective spam filtering, SPF checking, and reputation tracking
|
||||||
@@ -66,28 +55,19 @@ mail application. It uses pydspam if installed for bayesian filtering.
|
|||||||
%package spf
|
%package spf
|
||||||
Group: Applications/System
|
Group: Applications/System
|
||||||
Summary: BMS spam and reputation milter
|
Summary: BMS spam and reputation milter
|
||||||
Requires: pyspf >= 2.0.4
|
Requires: pyspf >= 2.0.4, pymilter
|
||||||
|
Obsoletes: pymilter-spf
|
||||||
|
|
||||||
%description spf
|
%description spf
|
||||||
A simple mail filter to add Received-SPF headers and reject forged mail.
|
A simple mail filter to add Received-SPF headers and reject forged mail.
|
||||||
Rejection policy is configured via sendmail access file.
|
Rejection policy is configured via sendmail access file.
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup
|
%setup -n pymilter-%{version}
|
||||||
#patch -p0 -b .bms
|
#patch -p0 -b .bms
|
||||||
|
|
||||||
%build
|
|
||||||
%if %{redhat7}
|
|
||||||
LDFLAGS="-s"
|
|
||||||
%else # Redhat builds debug packages after 7.3
|
|
||||||
LDFLAGS="-g"
|
|
||||||
%endif
|
|
||||||
env CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$LDFLAGS" %{python} setup.py build
|
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf $RPM_BUILD_ROOT
|
rm -rf $RPM_BUILD_ROOT
|
||||||
%{python} setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES
|
|
||||||
grep '.pyc$' INSTALLED_FILES | sed -e 's/c$/o/' >>INSTALLED_FILES
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/var/log/milter
|
mkdir -p $RPM_BUILD_ROOT/var/log/milter
|
||||||
mkdir -p $RPM_BUILD_ROOT/etc/mail
|
mkdir -p $RPM_BUILD_ROOT/etc/mail
|
||||||
mkdir $RPM_BUILD_ROOT/var/log/milter/save
|
mkdir $RPM_BUILD_ROOT/var/log/milter/save
|
||||||
@@ -105,7 +85,7 @@ cat >$RPM_BUILD_ROOT/etc/logrotate.d/milter <<'EOF'
|
|||||||
compress
|
compress
|
||||||
}
|
}
|
||||||
/var/log/milter/banned_ips {
|
/var/log/milter/banned_ips {
|
||||||
rotate 3
|
rotate 7
|
||||||
daily
|
daily
|
||||||
copytruncate
|
copytruncate
|
||||||
}
|
}
|
||||||
@@ -127,23 +107,14 @@ find /var/log/milter/save -mtime +7 | xargs $R rm
|
|||||||
EOF
|
EOF
|
||||||
chmod a+x $RPM_BUILD_ROOT/etc/cron.daily/milter
|
chmod a+x $RPM_BUILD_ROOT/etc/cron.daily/milter
|
||||||
|
|
||||||
%ifos aix4.1
|
%ifnos aix4.1
|
||||||
cat >$RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
|
|
||||||
#!/bin/sh
|
|
||||||
cd /var/log/milter
|
|
||||||
# uncomment to enable sgmlop if installed
|
|
||||||
#export PYTHONPATH=/usr/local/lib/python2.1/site-packages
|
|
||||||
exec /usr/local/bin/python bms.py >>milter.log 2>&1
|
|
||||||
EOF
|
|
||||||
%else
|
|
||||||
cp start.sh $RPM_BUILD_ROOT%{libdir}
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
|
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
|
||||||
cp %{sysvinit} $RPM_BUILD_ROOT/etc/rc.d/init.d/milter
|
cp %{sysvinit} $RPM_BUILD_ROOT/etc/rc.d/init.d/milter
|
||||||
cp spfmilter.rc $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter
|
cp spfmilter.rc $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter
|
||||||
ed $RPM_BUILD_ROOT/etc/rc.d/init.d/milter <<'EOF'
|
ed $RPM_BUILD_ROOT/etc/rc.d/init.d/milter <<'EOF'
|
||||||
/^python=/
|
/^python=/
|
||||||
c
|
c
|
||||||
python="%{python}"
|
python="%{__python}"
|
||||||
.
|
.
|
||||||
w
|
w
|
||||||
q
|
q
|
||||||
@@ -151,23 +122,13 @@ EOF
|
|||||||
ed $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter <<'EOF'
|
ed $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter <<'EOF'
|
||||||
/^python=/
|
/^python=/
|
||||||
c
|
c
|
||||||
python="%{python}"
|
python="%{__python}"
|
||||||
.
|
.
|
||||||
w
|
w
|
||||||
q
|
q
|
||||||
EOF
|
EOF
|
||||||
ed $RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
|
%endif # aix4.1
|
||||||
/^python=/
|
|
||||||
c
|
|
||||||
python="%{python}"
|
|
||||||
.
|
|
||||||
w
|
|
||||||
q
|
|
||||||
EOF
|
|
||||||
%endif
|
|
||||||
chmod a+x $RPM_BUILD_ROOT%{libdir}/start.sh
|
|
||||||
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/var/run/milter
|
|
||||||
mkdir -p $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack
|
mkdir -p $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack
|
||||||
cp -p rhsbl.m4 $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack
|
cp -p rhsbl.m4 $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack
|
||||||
|
|
||||||
@@ -179,7 +140,7 @@ mkssys -s milter -p %{libdir}/start.sh -u 25 -S -n 15 -f 9 -G mail || :
|
|||||||
if [ $1 = 0 ]; then
|
if [ $1 = 0 ]; then
|
||||||
rmssys -s milter || :
|
rmssys -s milter || :
|
||||||
fi
|
fi
|
||||||
%else
|
%else # not aix4.1
|
||||||
%post -n milter
|
%post -n milter
|
||||||
#echo "pythonsock has moved to /var/run/milter, update /etc/mail/sendmail.cf"
|
#echo "pythonsock has moved to /var/run/milter, update /etc/mail/sendmail.cf"
|
||||||
/sbin/chkconfig --add milter
|
/sbin/chkconfig --add milter
|
||||||
@@ -196,17 +157,9 @@ fi
|
|||||||
if [ $1 = 0 ]; then
|
if [ $1 = 0 ]; then
|
||||||
/sbin/chkconfig --del spfmilter
|
/sbin/chkconfig --del spfmilter
|
||||||
fi
|
fi
|
||||||
%endif
|
%endif # aix4.1
|
||||||
|
|
||||||
%clean
|
%files
|
||||||
rm -rf $RPM_BUILD_ROOT
|
|
||||||
|
|
||||||
%files -f INSTALLED_FILES
|
|
||||||
%defattr(-,root,root)
|
|
||||||
%doc README HOWTO ChangeLog NEWS TODO CREDITS sample.py milter-template.py
|
|
||||||
%config %{libdir}/start.sh
|
|
||||||
|
|
||||||
%files -n milter
|
|
||||||
%defattr(-,root,root)
|
%defattr(-,root,root)
|
||||||
/etc/logrotate.d/milter
|
/etc/logrotate.d/milter
|
||||||
/etc/cron.daily/milter
|
/etc/cron.daily/milter
|
||||||
@@ -219,13 +172,13 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
%dir /var/log/milter
|
%dir /var/log/milter
|
||||||
%dir /var/log/milter/save
|
%dir /var/log/milter/save
|
||||||
%config %{libdir}/bms.py
|
%config %{libdir}/bms.py
|
||||||
%{libdir}/bms.py?
|
|
||||||
%config(noreplace) /var/log/milter/strike3.txt
|
%config(noreplace) /var/log/milter/strike3.txt
|
||||||
%config(noreplace) /var/log/milter/softfail.txt
|
%config(noreplace) /var/log/milter/softfail.txt
|
||||||
%config(noreplace) /var/log/milter/fail.txt
|
%config(noreplace) /var/log/milter/fail.txt
|
||||||
%config(noreplace) /var/log/milter/neutral.txt
|
%config(noreplace) /var/log/milter/neutral.txt
|
||||||
%config(noreplace) /var/log/milter/quarantine.txt
|
%config(noreplace) /var/log/milter/quarantine.txt
|
||||||
%config(noreplace) /var/log/milter/permerror.txt
|
%config(noreplace) /var/log/milter/permerror.txt
|
||||||
|
%config(noreplace) /var/log/milter/temperror.txt
|
||||||
%config(noreplace) /etc/mail/pymilter.cfg
|
%config(noreplace) /etc/mail/pymilter.cfg
|
||||||
/usr/share/sendmail-cf/hack/rhsbl.m4
|
/usr/share/sendmail-cf/hack/rhsbl.m4
|
||||||
|
|
||||||
@@ -236,7 +189,101 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
%config(noreplace) /etc/mail/spfmilter.cfg
|
%config(noreplace) /etc/mail/spfmilter.cfg
|
||||||
/etc/rc.d/init.d/spfmilter
|
/etc/rc.d/init.d/spfmilter
|
||||||
|
|
||||||
|
%else # not noarch
|
||||||
|
|
||||||
|
%define name pymilter
|
||||||
|
Summary: Python interface to sendmail milter API
|
||||||
|
Name: %{name}
|
||||||
|
Version: %{version}
|
||||||
|
Release: %{release}
|
||||||
|
Source: %{name}-%{version}.tar.gz
|
||||||
|
#Patch: %{name}-%{version}.patch
|
||||||
|
License: GPL
|
||||||
|
Group: Development/Libraries
|
||||||
|
BuildRoot: %{_tmppath}/%{name}-buildroot
|
||||||
|
Prefix: %{_prefix}
|
||||||
|
Vendor: Stuart D. Gathman <stuart@bmsi.com>
|
||||||
|
Packager: Stuart D. Gathman <stuart@bmsi.com>
|
||||||
|
Url: http://www.bmsi.com/python/milter.html
|
||||||
|
Requires: %{__python} >= 2.4, sendmail >= 8.13
|
||||||
|
BuildRequires: %{__python}-devel >= 2.4, sendmail-devel >= 8.13
|
||||||
|
|
||||||
|
%description
|
||||||
|
This is a python extension module to enable python scripts to
|
||||||
|
attach to sendmail's libmilter functionality. Additional python
|
||||||
|
modules provide for navigating and modifying MIME parts, sending
|
||||||
|
DSNs, and doing CBV.
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup
|
||||||
|
#patch -p0 -b .bms
|
||||||
|
|
||||||
|
%build
|
||||||
|
%if %{redhat7}
|
||||||
|
LDFLAGS="-s"
|
||||||
|
%else # Redhat builds debug packages after 7.3
|
||||||
|
LDFLAGS="-g"
|
||||||
|
%endif
|
||||||
|
env CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$LDFLAGS" %{__python} setup.py build
|
||||||
|
|
||||||
|
%install
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
%{__python} setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES
|
||||||
|
mkdir -p $RPM_BUILD_ROOT/var/run/milter
|
||||||
|
mkdir -p $RPM_BUILD_ROOT%{libdir}
|
||||||
|
%ifos aix4.1
|
||||||
|
cat >$RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
|
||||||
|
#!/bin/sh
|
||||||
|
cd /var/log/milter
|
||||||
|
# uncomment to enable sgmlop if installed
|
||||||
|
#export PYTHONPATH=/usr/local/lib/python2.1/site-packages
|
||||||
|
exec /usr/local/bin/python bms.py >>milter.log 2>&1
|
||||||
|
EOF
|
||||||
|
%else # not aix4.1
|
||||||
|
cp start.sh $RPM_BUILD_ROOT%{libdir}
|
||||||
|
ed $RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
|
||||||
|
/^python=/
|
||||||
|
c
|
||||||
|
python="%{__python}"
|
||||||
|
.
|
||||||
|
w
|
||||||
|
q
|
||||||
|
EOF
|
||||||
|
%endif
|
||||||
|
chmod a+x $RPM_BUILD_ROOT%{libdir}/start.sh
|
||||||
|
%if !%{redhat7}
|
||||||
|
#grep '.pyc$' INSTALLED_FILES | sed -e 's/c$/o/' >>INSTALLED_FILES
|
||||||
|
%endif
|
||||||
|
|
||||||
|
# start.sh is used by spfmilter and milter, and could be used by
|
||||||
|
# other milters running on redhat
|
||||||
|
%files -f INSTALLED_FILES
|
||||||
|
%defattr(-,root,root)
|
||||||
|
%doc README HOWTO ChangeLog NEWS TODO CREDITS sample.py milter-template.py
|
||||||
|
%config %{libdir}/start.sh
|
||||||
|
%dir %attr(0755,mail,mail) /var/run/milter
|
||||||
|
|
||||||
|
%endif # noarch
|
||||||
|
|
||||||
|
%clean
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Aug 25 2008 Stuart Gathman <stuart@bmsi.com> 0.8.10-2
|
||||||
|
- /var/run/milter directory must be owned by mail
|
||||||
|
* Mon Aug 25 2008 Stuart Gathman <stuart@bmsi.com> 0.8.10-1
|
||||||
|
- log rcpt for SRS rejections
|
||||||
|
- improved parsing into email and fullname (still 2 self test failures)
|
||||||
|
- implement no-DSN CBV, reduce full DSNs
|
||||||
|
- check for porn words in MAIL FROM fullname
|
||||||
|
- ban IP for too many bad MAIL FROMs or RCPT TOs
|
||||||
|
- temperror policy in access
|
||||||
|
- no CBV for whitelisted MAIL FROM except permerror, softfail
|
||||||
|
- Allow explicitly whitelisted email from banned_users.
|
||||||
|
- configure gossip TTL
|
||||||
|
* Mon Sep 24 2007 Stuart Gathman <stuart@bmsi.com> 0.8.9-1
|
||||||
|
- Use %ifarch hack to build milter and milter-spf packages as noarch
|
||||||
|
- Remove spf dependency from dsn.py, add dns.py
|
||||||
* Fri Jan 05 2007 Stuart Gathman <stuart@bmsi.com> 0.8.8-1
|
* Fri Jan 05 2007 Stuart Gathman <stuart@bmsi.com> 0.8.8-1
|
||||||
- move AddrCache, parse_addr, iniplist to Milter package
|
- move AddrCache, parse_addr, iniplist to Milter package
|
||||||
- move parse_header to Milter.utils
|
- move parse_header to Milter.utils
|
||||||
@@ -252,6 +299,7 @@ rm -rf $RPM_BUILD_ROOT
|
|||||||
- SPF moved to pyspf RPM
|
- SPF moved to pyspf RPM
|
||||||
- wiretap archive option
|
- wiretap archive option
|
||||||
- Do plain CBV if missing template
|
- Do plain CBV if missing template
|
||||||
|
- SMTP AUTH policy in access
|
||||||
* Tue May 23 2006 Stuart Gathman <stuart@bmsi.com> 0.8.6-2
|
* Tue May 23 2006 Stuart Gathman <stuart@bmsi.com> 0.8.6-2
|
||||||
- Support CBV timeout
|
- Support CBV timeout
|
||||||
- Support fail template, headers in templates
|
- Support fail template, headers in templates
|
||||||
@@ -22,19 +22,6 @@ their quarantined mail and may notice your message. If your message is
|
|||||||
important, please contact them via other means. You may also try sending
|
important, please contact them via other means. You may also try sending
|
||||||
them a simple plain text message.
|
them a simple plain text message.
|
||||||
|
|
||||||
If you never sent the above message, then your domain, %(sender_domain)s,
|
|
||||||
was forged - i.e. used without your knowlege or authorization by
|
|
||||||
someone attempting to steal your mail identity. This is a very
|
|
||||||
serious problem, and you need to provide authentication for your
|
|
||||||
SMTP (email) servers to prevent criminals from forging your
|
|
||||||
domain. The simplest step is usually to publish an SPF record
|
|
||||||
with your Sender Policy.
|
|
||||||
|
|
||||||
For more information, see: http://www.openspf.org
|
|
||||||
|
|
||||||
Your mail admin needs to publish a strict SPF record so that I can reject
|
|
||||||
those forgeries instead of bugging you with them.
|
|
||||||
|
|
||||||
If you need further assistance, please do not hesitate to contact me.
|
If you need further assistance, please do not hesitate to contact me.
|
||||||
|
|
||||||
Kind regards,
|
Kind regards,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from distutils.core import setup, Extension
|
|||||||
# on slackware and debian, leave it out entirely. It depends
|
# on slackware and debian, leave it out entirely. It depends
|
||||||
# on how libmilter was built by the sendmail package.
|
# on how libmilter was built by the sendmail package.
|
||||||
libs = ["milter", "smutil"]
|
libs = ["milter", "smutil"]
|
||||||
|
libdirs = ["/usr/lib/libmilter"] # needed for Debian
|
||||||
|
|
||||||
# patch distutils if it can't cope with the "classifiers" or
|
# patch distutils if it can't cope with the "classifiers" or
|
||||||
# "download_url" keywords
|
# "download_url" keywords
|
||||||
@@ -15,7 +16,7 @@ if sys.version < '2.2.3':
|
|||||||
DistributionMetadata.download_url = None
|
DistributionMetadata.download_url = None
|
||||||
|
|
||||||
# NOTE: importing Milter to obtain version fails when milter.so not built
|
# NOTE: importing Milter to obtain version fails when milter.so not built
|
||||||
setup(name = "pymilter", version = '0.8.8',
|
setup(name = "pymilter", version = '0.8.10',
|
||||||
description="Python interface to sendmail milter API",
|
description="Python interface to sendmail milter API",
|
||||||
long_description="""\
|
long_description="""\
|
||||||
This is a python extension module to enable python scripts to
|
This is a python extension module to enable python scripts to
|
||||||
@@ -33,6 +34,7 @@ sending DSNs or doing CBVs.
|
|||||||
packages = ['Milter'],
|
packages = ['Milter'],
|
||||||
ext_modules=[
|
ext_modules=[
|
||||||
Extension("milter", ["miltermodule.c"],
|
Extension("milter", ["miltermodule.c"],
|
||||||
|
library_dirs=libdirs,
|
||||||
libraries=libs,
|
libraries=libs,
|
||||||
# set MAX_ML_REPLY to 1 for sendmail < 8.13
|
# set MAX_ML_REPLY to 1 for sendmail < 8.13
|
||||||
define_macros = [ ('MAX_ML_REPLY',32) ]
|
define_macros = [ ('MAX_ML_REPLY',32) ]
|
||||||
|
|||||||
@@ -10,7 +10,5 @@ else
|
|||||||
cd /usr/lib/pymilter
|
cd /usr/lib/pymilter
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd /var/log/milter
|
${python} ${script}.py &
|
||||||
exec >>${appname}.log 2>&1
|
|
||||||
${python} ${appname}.py &
|
|
||||||
echo $! >/var/run/milter/${appname}.pid
|
echo $! >/var/run/milter/${appname}.pid
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
To: %(sender)s
|
||||||
|
From: postmaster@%(receiver)s
|
||||||
|
Subject: Critical DNS configuration error
|
||||||
|
Auto-Submitted: auto-generated (configuration error)
|
||||||
|
|
||||||
|
This is an automatically generated Delivery Status Notification.
|
||||||
|
|
||||||
|
THIS IS A WARNING MESSAGE ONLY.
|
||||||
|
|
||||||
|
YOU DO *NOT* NEED TO RESEND YOUR MESSAGE.
|
||||||
|
|
||||||
|
Delivery to the following recipients has been delayed.
|
||||||
|
|
||||||
|
%(rcpt)s
|
||||||
|
|
||||||
|
Subject: %(subject)s
|
||||||
|
Received-SPF: %(spf_result)s
|
||||||
|
|
||||||
|
Your DNS server is not responding to TXT queries. In other words,
|
||||||
|
it is BROKEN. You need to get somebody to fix it ASAP. We
|
||||||
|
are attempting to do TXT queries to see if you have an SPF record.
|
||||||
|
|
||||||
|
See http://openspf.org
|
||||||
|
|
||||||
|
We are sending you this message to alert you to the fact that
|
||||||
|
you have problems with your DNS.
|
||||||
|
|
||||||
|
If you need further assistance, please do not hesitate to
|
||||||
|
contact me again.
|
||||||
|
|
||||||
|
Kind regards,
|
||||||
|
|
||||||
|
postmaster@%(receiver)s
|
||||||
+1
-1
@@ -44,7 +44,7 @@ class TestMilter(bms.bmsMilter):
|
|||||||
self._msg[field] = value
|
self._msg[field] = value
|
||||||
self.headerschanged = True
|
self.headerschanged = True
|
||||||
|
|
||||||
def addheader(self,field,value):
|
def addheader(self,field,value,idx=-1):
|
||||||
if not self._body:
|
if not self._body:
|
||||||
raise IOError,"addheader not called from eom()"
|
raise IOError,"addheader not called from eom()"
|
||||||
self.log('addheader: %s=%s' % (field,value))
|
self.log('addheader: %s=%s' % (field,value))
|
||||||
|
|||||||
Reference in New Issue
Block a user