summaryrefslogtreecommitdiff
path: root/Lib/email/header.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-08-03 22:14:10 +0000
committerR. David Murray <rdmurray@bitdance.com>2010-08-03 22:14:10 +0000
commitc4e69cc1d84a8e025c6b1894b4749cda8bb1d156 (patch)
tree586e2b0cb340e1107e34f9e85217055dffc5a350 /Lib/email/header.py
parentdf7f2fd350c215d15faf14ed01838ae3420ac0ae (diff)
downloadcpython-git-c4e69cc1d84a8e025c6b1894b4749cda8bb1d156.tar.gz
#3196: if needed pad a short base64 encoded word before trying to decode.
The RFCs encourage following Postel's law: be liberal in what you accept. So if someone forgot to pad the base64 encoded word payload to an even four bytes, we add the padding before handing it to base64mime.decode. Previously, missing padding resulted in a HeaderParseError. Patch by Jason Williams.
Diffstat (limited to 'Lib/email/header.py')
-rw-r--r--Lib/email/header.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/email/header.py b/Lib/email/header.py
index c924d3a722..89c1391052 100644
--- a/Lib/email/header.py
+++ b/Lib/email/header.py
@@ -94,6 +94,9 @@ def decode_header(header):
word = email.quoprimime.header_decode(encoded_string)
decoded_words.append((word, charset))
elif encoding == 'b':
+ paderr = len(encoded_string) % 4 # Postel's law: add missing padding
+ if paderr:
+ encoded_string += '==='[:4 - paderr]
try:
word = email.base64mime.decode(encoded_string)
except binascii.Error: