From: W. Trevor King Date: Fri, 7 Nov 2014 07:56:47 +0000 (-0800) Subject: ssoma-mda: Decode RFC-2047-encoded From: headers X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2368ff68826074056150b2d21a66ac2ad76370db;p=ssoma-mda.git ssoma-mda: Decode RFC-2047-encoded From: headers The examples in RFC 2047 have an encoded name, but an ASCII email address [1]. Make sure we handle that appropriately. [1]: http://tools.ietf.org/html/rfc2047#section-8 --- diff --git a/ssoma-mda b/ssoma-mda index f02b1b1..d3b5406 100755 --- a/ssoma-mda +++ b/ssoma-mda @@ -249,11 +249,26 @@ def get_commit_message(message): def get_author(message): - """Create a pygit2.Signature for the message author.""" + """Create a pygit2.Signature for the message author. + + >>> author = get_author(message={ + ... 'From': '=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= ', + ... 'Date': 'Fri, 21 Nov 1997 09:55:06 -0600', + ... }) + >>> author.name + 'Keld Jørn Simonsen' + >>> author.email + 'keld@dkuug.dk' + >>> author.time + 880127706 + >>> author.offset + 1080 + """ author_name, author_email = _email_utils.parseaddr( message['From']) if not author_name: author_name = author_email.split('@')[0] + author_name = _decode_header(string=author_name) date = message['Date'] datetime = _email_utils.parsedate_to_datetime(date) time = int(datetime.timestamp()) @@ -265,7 +280,8 @@ def get_author(message): name=author_name, email=author_email, time=time, - offset=offset) + offset=offset, + encoding=_COMMIT_MESSAGE_ENCODING) def deliver(message=None, message_bytes=None, **kwargs):