diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-06-16 11:57:56 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-07-22 19:32:53 +0100 |
commit | c3bd2b2bb514892b1f1a8f123ccea8c2460ec321 (patch) | |
tree | cf8f66ebc5e5327d1d435686e04dbfbc58d5833e /alot | |
parent | d6b03bb33338733a8b175d97393ce5289e72e231 (diff) |
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
Diffstat (limited to 'alot')
-rw-r--r-- | alot/crypto.py | 22 |
1 files changed, 11 insertions, 11 deletions
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 |