mirror of
https://kernel.googlesource.com/pub/scm/linux/kernel/git/tglx/remail.git
synced 2024-11-22 04:12:38 +01:00
remail: Use email.utils.get_addresses()
Replace more historical homebrewn parsing Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
parent
893b9510db
commit
88f8e48b13
2 changed files with 4 additions and 37 deletions
|
@ -5,7 +5,7 @@
|
||||||
# Mail message related code
|
# Mail message related code
|
||||||
|
|
||||||
from email.utils import make_msgid, formatdate, parseaddr
|
from email.utils import make_msgid, formatdate, parseaddr
|
||||||
from email.header import Header, decode_header
|
from email.header import Header
|
||||||
from email import message_from_string, message_from_bytes
|
from email import message_from_string, message_from_bytes
|
||||||
from email.generator import Generator
|
from email.generator import Generator
|
||||||
from email.message import Message, EmailMessage
|
from email.message import Message, EmailMessage
|
||||||
|
@ -152,37 +152,6 @@ def get_raw_email_addr(addr):
|
||||||
'''
|
'''
|
||||||
return parseaddr(addr)[1]
|
return parseaddr(addr)[1]
|
||||||
|
|
||||||
re_compress_space = re.compile('\s+')
|
|
||||||
|
|
||||||
def decode_hdr(hdr):
|
|
||||||
'''
|
|
||||||
Decode a mail header with encoding
|
|
||||||
'''
|
|
||||||
elm = decode_header(hdr.strip())
|
|
||||||
res = ''
|
|
||||||
for txt, enc in elm:
|
|
||||||
# Groan ....
|
|
||||||
if enc:
|
|
||||||
res += ' ' + txt.decode(enc)
|
|
||||||
elif isinstance(txt, str):
|
|
||||||
res += ' ' + txt
|
|
||||||
else:
|
|
||||||
res += ' ' + txt.decode('ascii')
|
|
||||||
return re_compress_space.sub(' ', res).strip()
|
|
||||||
|
|
||||||
def decode_addrs(hdr):
|
|
||||||
'''
|
|
||||||
Decode mail addresses from a header and handle encondings
|
|
||||||
'''
|
|
||||||
addrs = []
|
|
||||||
if not hdr:
|
|
||||||
return addrs
|
|
||||||
parts = re_compress_space.sub(' ', hdr).split(',')
|
|
||||||
for p in parts:
|
|
||||||
addr = decode_hdr(p)
|
|
||||||
addrs.append(addr)
|
|
||||||
return addrs
|
|
||||||
|
|
||||||
re_noquote = re.compile('[a-zA-Z0-9_\- ]+')
|
re_noquote = re.compile('[a-zA-Z0-9_\- ]+')
|
||||||
|
|
||||||
def encode_addr(fulladdr):
|
def encode_addr(fulladdr):
|
||||||
|
|
|
@ -6,15 +6,15 @@
|
||||||
|
|
||||||
from remail.mail import msg_set_header, msg_force_msg_id, send_mail
|
from remail.mail import msg_set_header, msg_force_msg_id, send_mail
|
||||||
from remail.mail import msg_sanitize_incoming, msg_is_autoreply
|
from remail.mail import msg_sanitize_incoming, msg_is_autoreply
|
||||||
from remail.mail import get_raw_email_addr, decode_addrs
|
|
||||||
from remail.mail import msg_from_string, sender_info
|
from remail.mail import msg_from_string, sender_info
|
||||||
|
from remail.mail import get_raw_email_addr
|
||||||
|
|
||||||
from remail.smime import smime_crypt, RemailSmimeException
|
from remail.smime import smime_crypt, RemailSmimeException
|
||||||
from remail.gpg import gpg_crypt, RemailGPGException
|
from remail.gpg import gpg_crypt, RemailGPGException
|
||||||
from remail.tracking import account_tracking
|
from remail.tracking import account_tracking
|
||||||
from remail.config import accounts_config, gpg_config, smime_config
|
from remail.config import accounts_config, gpg_config, smime_config
|
||||||
|
|
||||||
from email.utils import make_msgid, formatdate
|
from email.utils import make_msgid, formatdate, getaddresses
|
||||||
from email.policy import EmailPolicy
|
from email.policy import EmailPolicy
|
||||||
from flufl.bounce import all_failures
|
from flufl.bounce import all_failures
|
||||||
|
|
||||||
|
@ -303,10 +303,8 @@ class maillist(object):
|
||||||
|
|
||||||
def get_destination(self, msg):
|
def get_destination(self, msg):
|
||||||
# Handle the case where someone put several addresses on To:
|
# Handle the case where someone put several addresses on To:
|
||||||
addrs = decode_addrs(msg['To'])
|
|
||||||
|
|
||||||
for addr in addrs:
|
for name, to in getaddresses(msg.get_all('To', [])):
|
||||||
to = get_raw_email_addr(addr)
|
|
||||||
dest = self.config.listaddrs.get_destination(to, self.config.admins,
|
dest = self.config.listaddrs.get_destination(to, self.config.admins,
|
||||||
self.config.subscribers)
|
self.config.subscribers)
|
||||||
if dest:
|
if dest:
|
||||||
|
|
Loading…
Reference in a new issue