# Be as robust as possible here.
faddrs = getaddresses(msg.get_all('from', []))
# Strip the nulls and bad emails.
faddrs = [x for x in faddrs if x[1].find('@') > 0]
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
else:
realname = email
# Remove domain from realname if it looks like an email address
realname = re.sub(r'@([^ .]+\.)+[^ .]+$', '---', realname)
change_header('From',
formataddr(('%s via %s' % (realname, mlist.real_name),
mlist.GetListEmail())),
mlist, msg, msgdata)
Comments