ssoma-mda: Decode RFC-2047-encoded From: headers
authorW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 07:56:47 +0000 (23:56 -0800)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 07:56:47 +0000 (23:56 -0800)
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

ssoma-mda

index f02b1b147dc768d17e1f6214df78e18ea5156523..d3b54063eb40abae52e97cf7bccda842e44ece02 100755 (executable)
--- 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?= <keld@dkuug.dk>',
+    ...     '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):