From 541bd8aec1f67834c42bc2e5df14c1f73c569082 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 6 Dec 2013 17:45:21 -0400 Subject: pep8 cleanup --- src/leap/mail/smtp/rfc3156.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/leap/mail/smtp/rfc3156.py') diff --git a/src/leap/mail/smtp/rfc3156.py b/src/leap/mail/smtp/rfc3156.py index dd48475..b0288b4 100644 --- a/src/leap/mail/smtp/rfc3156.py +++ b/src/leap/mail/smtp/rfc3156.py @@ -361,7 +361,7 @@ class PGPSignature(MIMEApplication): """ def __init__(self, _data, name='signature.asc'): MIMEApplication.__init__(self, _data, 'pgp-signature', - _encoder=lambda x: x, name=name) + encoder=lambda x: x, name=name) self.add_header('Content-Description', 'OpenPGP Digital Signature') -- cgit v1.2.3 From 8547783e7fe517772d610b0ae73b0b6be6450e98 Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 19 Dec 2013 23:45:39 -0200 Subject: Fix tests and bug introduced in 541bd8aec1f67834c42bc2e5df14c1f73c569082. --- src/leap/mail/smtp/rfc3156.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/leap/mail/smtp/rfc3156.py') diff --git a/src/leap/mail/smtp/rfc3156.py b/src/leap/mail/smtp/rfc3156.py index b0288b4..9739531 100644 --- a/src/leap/mail/smtp/rfc3156.py +++ b/src/leap/mail/smtp/rfc3156.py @@ -361,7 +361,7 @@ class PGPSignature(MIMEApplication): """ def __init__(self, _data, name='signature.asc'): MIMEApplication.__init__(self, _data, 'pgp-signature', - encoder=lambda x: x, name=name) + _encoder=lambda x: x, name=name) self.add_header('Content-Description', 'OpenPGP Digital Signature') -- cgit v1.2.3 From 379f7fd742d1e79a575f0f723bcddb01cc611067 Mon Sep 17 00:00:00 2001 From: drebs Date: Tue, 21 Jan 2014 16:18:15 -0200 Subject: Prevent double base64 encoding of attachments when signing (#5014). --- src/leap/mail/smtp/rfc3156.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/leap/mail/smtp/rfc3156.py') diff --git a/src/leap/mail/smtp/rfc3156.py b/src/leap/mail/smtp/rfc3156.py index 9739531..2c6d4a7 100644 --- a/src/leap/mail/smtp/rfc3156.py +++ b/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): -- cgit v1.2.3 From 8b7c63dd7369eff2262b6f2a2d574f46a67657a0 Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 23 Jan 2014 15:34:28 -0200 Subject: Handle upper and lowercase base64 encoded outgoing attachments. --- src/leap/mail/smtp/rfc3156.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/leap/mail/smtp/rfc3156.py') diff --git a/src/leap/mail/smtp/rfc3156.py b/src/leap/mail/smtp/rfc3156.py index 2c6d4a7..62a0675 100644 --- a/src/leap/mail/smtp/rfc3156.py +++ b/src/leap/mail/smtp/rfc3156.py @@ -147,14 +147,15 @@ def encode_base64(msg): :type msg: email.message.Message """ encoding = msg.get('Content-Transfer-Encoding', None) + if encoding is not None: + encoding = encoding.lower() # 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']: + if encoding in [None, 'quoted-printable', 'x-uuencode', 'uue', 'x-uue']: orig = msg.get_payload(decode=True) encdata = _bencode(orig) msg.set_payload(encdata) -- cgit v1.2.3