From 307a5e4da3877c944be296b278ab59b7c70e24b7 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Fri, 9 May 2014 12:19:29 -0700 Subject: Handle missing From: header addresses for DMARC mitigation actions. (LP: #1318025) --- Mailman/Handlers/CookHeaders.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Mailman') diff --git a/Mailman/Handlers/CookHeaders.py b/Mailman/Handlers/CookHeaders.py index c6f25044..78701850 100755 --- a/Mailman/Handlers/CookHeaders.py +++ b/Mailman/Handlers/CookHeaders.py @@ -120,7 +120,16 @@ def process(mlist, msg, msgdata): mlist, msg, msgdata, repl=False) # Do we change the from so the list takes ownership of the email if (msgdata.get('from_is_list') or mlist.from_is_list) and not fasttrack: - realname, email = parseaddr(msg['from']) + # Be as robust as possible here. + faddrs = getaddresses(msg.get_all('from', [])) + if len(faddrs) == 1: + realname, email = o_from = faddrs[0] + else: + # No From: or multiple addresses. Just punt and take + # the get_sender result. + realname = '' + email = msgdata['original_sender'] + o_from = (realname, email) if not realname: if mlist.isMember(email): realname = mlist.getMemberName(email) or email @@ -128,8 +137,6 @@ def process(mlist, msg, msgdata): realname = email # Remove domain from realname if it looks like an email address realname = re.sub(r'@([^ .]+\.)+[^ .]+$', '---', realname) - # Remember the original From: here for adding to Reply-To: below. - o_from = parseaddr(msg['from']) change_header('From', formataddr(('%s via %s' % (realname, mlist.real_name), mlist.GetListEmail())), -- cgit v1.2.3