Handle unquoted fullname when parsing email.
This commit is contained in:
1 parent
10f4f2613e
commit
632e7b4248
3 files changed
+33
-3
No files matched your search
@@ -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('[email protected]')
|
||||
('', '[email protected]')
|
||||
>>> parseaddr('"Full Name" <[email protected]>')
|
||||
('Full Name', '[email protected]')
|
||||
>>> parseaddr('[email protected] <[email protected]>')
|
||||
('[email protected]', '[email protected]')
|
||||
"""
|
||||
#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.
|
||||
|
||||
|
||||
Reference in new issue
Block a user