summaryrefslogtreecommitdiff
path: root/alot/crypto.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/crypto.py')
-rw-r--r--alot/crypto.py22
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