import argparse as _argparse
import email as _email
+import email.header as _email_header
import email.message as _email_message
import email.policy as _email_policy
import email.utils as _email_utils
return _os_path.join(hash[:2], hash[2:])
+def get_commit_message(message):
+ """Unwrap and decode the message subject for use as a commit message."""
+ commit_message = message.get('Subject', '<no subject>')
+ commit_message = _FOLDING_WHITESPACE_REGEX.sub(' ', commit_message)
+ commit_message = ''.join(
+ str(decoded, charset) for decoded, charset
+ in _email_header.decode_header(commit_message))
+ return commit_message
+
+
def get_author(message):
"""Create a pygit2.Signature for the message author."""
author_name, author_email = _email_utils.parseaddr(
message_id = message.get('Message-ID', '')
path = message_id_path(message_id=message_id)
_LOG.info('deliver {} to {}'.format(message_id, path))
- commit_message = message.get('Subject', '<no subject>')
- if '\n' in commit_message:
- commit_message = _FOLDING_WHITESPACE_REGEX.sub(' ', commit_message)
+ commit_message = get_commit_message(message=message)
author = get_author(message=message)
repository = _pygit2.Repository(_os_path.curdir)
append(