From c3bd2b2bb514892b1f1a8f123ccea8c2460ec321 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sat, 16 Jun 2012 11:57:56 +0100 Subject: fix issue with non-multipart messages msg.get_boundary will return None in those cases, so we cannot concatenate this with str untested. Also, Generator.flatten(msg) causes msg to generate a boundary string. So we don't need to call msg.as_string separately in case we get the boundary after flattening cf issue #469 --- alot/crypto.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'alot') diff --git a/alot/crypto.py b/alot/crypto.py index b03cc2b8..97d13292 100644 --- a/alot/crypto.py +++ b/alot/crypto.py @@ -6,6 +6,7 @@ import re from email.generator import Generator from cStringIO import StringIO from alot.errors import GPGProblem +from email.mime.multipart import MIMEMultipart import gpgme @@ -17,22 +18,21 @@ def email_as_string(mail): :param mail: email to convert to string :rtype: str """ - # Get the boundary for later. Before being able to call get_boundary(), we - # need to serialize the mail to string once. - mail.as_string() - boundary = mail.get_boundary() - fp = StringIO() g = Generator(fp, mangle_from_=False) g.flatten(mail) as_string = RFC3156_canonicalize(fp.getvalue()) - # Workaround for http://bugs.python.org/issue14983: - # Insert a newline before the outer mail boundary so that other mail - # clients (like KMail, Claws-Mail, mutt, …) can verify the signature when - # sending an email which contains attachments. - as_string = re.sub(r'--\n--' + boundary, - '--\n\n--' + boundary, as_string, flags=re.MULTILINE) + if isinstance(mail, MIMEMultipart): + # Get the boundary for later + boundary = mail.get_boundary() + + # Workaround for http://bugs.python.org/issue14983: + # Insert a newline before the outer mail boundary so that other mail + # clients (like KMail, Claws-Mail, mutt, …) can verify the signature when + # sending an email which contains attachments. + as_string = re.sub(r'--\n--' + boundary, + '--\n\n--' + boundary, as_string, flags=re.MULTILINE) return as_string -- cgit v1.2.3