Commit c200b533 authored by Arkadiusz Hiler's avatar Arkadiusz Hiler

parsemail: Extract email and name parsing to a helper

Signed-off-by: Arkadiusz Hiler's avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent b7e7844d
......@@ -141,9 +141,7 @@ def find_project(mail):
return project
def find_author(mail):
from_header = clean_header(mail.get('From'))
def extract_email_and_name(header):
(name, email) = (None, None)
# tuple of (regex, fn)
......@@ -161,18 +159,27 @@ def find_author(mail):
]
for regex, fn in from_res:
match = regex.match(from_header)
match = regex.match(header)
if match:
(name, email) = fn(match.groups())
break
if email is None:
raise Exception("Could not parse From: header")
if email is not None:
email = email.strip()
email = email.strip()
if name is not None:
name = name.strip()
return (name, email)
def find_author(mail):
from_header = clean_header(mail.get('From'))
(name, email) = extract_email_and_name(from_header)
if email is None:
raise Exception("Could not parse From: header")
save_required = False
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment