summaryrefslogtreecommitdiffhomepage
path: root/gbp
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-08-05 20:46:58 -0300
committerGuido Günther <agx@sigxcpu.org>2017-08-05 21:55:37 -0300
commitc4bc6561c788f71b5131d0bd8e92478e83808200 (patch)
tree51fba32aca3114a6897e11b271ee29d3b038056c /gbp
parent2320e1969145546688a6cd06d82fbeed78897046 (diff)
pq: don't eagerly encode email headers
Python3 changed behaviour and does not try us-ascii before the given encoding so open code this in pq to avoid patch churn due to changed email header encodings.
Diffstat (limited to 'gbp')
-rw-r--r--gbp/scripts/common/pq.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index ce05a99c..e9502ea3 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -148,23 +148,31 @@ def write_patch_file(filename, commit_info, diff):
# Git compat: put name in quotes if special characters found
if re.search("[,.@()\[\]\\\:;]", name):
name = '"%s"' % name
- from_header = Header(name.encode('utf-8'), charset, 77, 'from')
- from_header.append(email.encode('utf-8'))
+ from_header = Header(header_name='from')
+ try:
+ from_header.append(name, 'us-ascii')
+ except UnicodeDecodeError:
+ from_header.append(name, charset)
+ from_header.append('<%s>' % email)
msg['From'] = from_header
date = commit_info['author'].datetime
datestr = date.strftime('%a, %-d %b %Y %H:%M:%S %z')
- msg['Date'] = Header(datestr.encode('utf-8'), charset, 77, 'date')
- msg['Subject'] = Header(commit_info['subject'].encode('utf-8'),
- charset, 77, 'subject')
+ msg['Date'] = Header(datestr, 'us-ascii', 'date')
+ subject_header = Header(header_name='subject')
+ try:
+ subject_header.append(commit_info['subject'], 'us-ascii')
+ except UnicodeDecodeError:
+ subject_header.append(commit_info['subject'], charset)
+ msg['Subject'] = subject_header
# Write message body
if commit_info['body']:
# Strip extra linefeeds
body = commit_info['body'].rstrip() + '\n'
try:
- msg.set_payload(body.encode('ascii'))
+ msg.set_payload(body.encode('us-ascii'))
except UnicodeDecodeError:
msg.set_payload(body, charset)
- patch.write(msg.as_string(unixfrom=False).encode('utf-8'))
+ patch.write(msg.as_string(unixfrom=False, maxheaderlen=77).encode('utf-8'))
# Write diff
patch.write(b'---\n')