From 632e7b4248c37863d5bb16db9da6c13350726d0d Mon Sep 17 00:00:00 2001
From: Stuart Gathman <stuart@gathman.org>
Date: Wed, 9 Jan 2008 20:15:49 +0000
Subject: [PATCH] Handle unquoted fullname when parsing email.
---
Milter/utils.py | 21 +++++++++++++++++++++
TODO | 5 +++++
bms.py | 10 +++++++---
3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/Milter/utils.py b/Milter/utils.py
index 68496b7..6006b75 100644
--- a/Milter/utils.py
+++ b/Milter/utils.py
@@ -4,6 +4,8 @@ import socket
import email.Errors
from fnmatch import fnmatchcase
from email.Header import decode_header
+#import email.Utils
+import rfc822
ip4re = re.compile(r'^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$')
@@ -40,6 +42,25 @@ def iniplist(ipaddr,iplist):
return True
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@viagra.com <foo@example.com>')
+ ('spam@viagra.com', 'foo@example.com')
+ """
+ #return email.Utils.parseaddr(t)
+ res = rfc822.parseaddr(t)
+ if not res[0]:
+ pos = t.find('<')
+ if pos > 0:
+ return rfc822.parseaddr('"%s" %s' % (t[:pos].strip(),t[pos:]))
+ return res
+
+
def parse_addr(t):
"""Split email into user,domain.
diff --git a/TODO b/TODO
index 76de62c..fca3293 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,8 @@
+Add parseaddr test case for 'foo@bar.com <baz@barf.biz>'
+
+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.
diff --git a/bms.py b/bms.py
index 084afc5..f52d283 100644
--- a/bms.py
+++ b/bms.py
@@ -1,6 +1,9 @@
#!/usr/bin/env python
# A simple milter that has grown quite a bit.
# $Log$
+# 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.
#
@@ -171,11 +174,12 @@ import gc
import anydbm
import Milter.dsn as dsn
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 fnmatch import fnmatchcase
-from email.Utils import getaddresses,parseaddr
+from email.Utils import getaddresses
# Import gossip if available
try:
@@ -563,7 +567,7 @@ class SPFPolicy(object):
from Milter.cache import AddrCache
cbv_cache = AddrCache(renew=7)
-auto_whitelist = AddrCache(renew=30)
+auto_whitelist = AddrCache(renew=60)
blacklist = AddrCache(renew=30)
class bmsMilter(Milter.Milter):
--
GitLab