summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2014-01-21 16:18:15 -0200
committerdrebs <drebs@leap.se>2014-01-21 16:35:12 -0200
commit8a7492940f23b6308f15f8f11b960702e00f3684 (patch)
tree709de2f74e568638de58d836ea857bac4619472c
parent19b7d01f3022a9dd8553ce4b260f8987f0eb9858 (diff)
Prevent double base64 encoding of attachments when signing (#5014).
-rw-r--r--mail/changes/bug_5014_fix-attachment-processing-when-signing1
-rw-r--r--mail/src/leap/mail/smtp/rfc3156.py28
2 files changed, 21 insertions, 8 deletions
diff --git a/mail/changes/bug_5014_fix-attachment-processing-when-signing b/mail/changes/bug_5014_fix-attachment-processing-when-signing
new file mode 100644
index 00000000..c12e35ef
--- /dev/null
+++ b/mail/changes/bug_5014_fix-attachment-processing-when-signing
@@ -0,0 +1 @@
+ o Correctly process attachments when signing. Fixes #5014.
diff --git a/mail/src/leap/mail/smtp/rfc3156.py b/mail/src/leap/mail/smtp/rfc3156.py
index 97395316..2c6d4a7e 100644
--- a/mail/src/leap/mail/smtp/rfc3156.py
+++ b/mail/src/leap/mail/smtp/rfc3156.py
@@ -24,6 +24,7 @@ import base64
from abc import ABCMeta, abstractmethod
from StringIO import StringIO
+from twisted.python import log
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email import errors
@@ -145,14 +146,25 @@ def encode_base64(msg):
:param msg: The non-multipart message to be encoded.
:type msg: email.message.Message
"""
- orig = msg.get_payload()
- encdata = _bencode(orig)
- msg.set_payload(encdata)
- # replace or set the Content-Transfer-Encoding header.
- try:
- msg.replace_header('Content-Transfer-Encoding', 'base64')
- except KeyError:
- msg['Content-Transfer-Encoding'] = 'base64'
+ encoding = msg.get('Content-Transfer-Encoding', None)
+ # XXX Python's email module can only decode quoted-printable, base64 and
+ # uuencoded data, so we might have to implement other decoding schemes in
+ # order to support RFC 3156 properly and correctly calculate signatures
+ # for multipart attachments (eg. 7bit or 8bit encoded attachments). For
+ # now, if content is already encoded as base64 or if it is encoded with
+ # some unknown encoding, we just pass.
+ if encoding is None or encoding.lower() in ['quoted-printable',
+ 'x-uuencode', 'uue', 'x-uue']:
+ orig = msg.get_payload(decode=True)
+ encdata = _bencode(orig)
+ msg.set_payload(encdata)
+ # replace or set the Content-Transfer-Encoding header.
+ try:
+ msg.replace_header('Content-Transfer-Encoding', 'base64')
+ except KeyError:
+ msg['Content-Transfer-Encoding'] = 'base64'
+ elif encoding is not 'base64':
+ log.err('Unknown content-transfer-encoding: %s' % encoding)
def encode_base64_rec(msg):