diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-07-22 19:34:25 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-07-22 19:34:25 +0100 |
commit | 3c2395c6f894e21206ff263478072ad6bca68ea5 (patch) | |
tree | 5e94542d156ddcc6ce67d86122f72074eaac6658 | |
parent | acfaf1f9b8a4ad6b6e8cc1f6b56da0c0afbc76cf (diff) | |
parent | 3a9db2e595eb6f00ef575bbf9c5ddf73466ade16 (diff) |
Merge branch '0.3.1-fix-gpg-attachments-469'
-rw-r--r-- | alot/account.py | 4 | ||||
-rw-r--r-- | alot/commands/envelope.py | 6 | ||||
-rw-r--r-- | alot/crypto.py | 19 | ||||
-rw-r--r-- | alot/db/attachment.py | 9 | ||||
-rw-r--r-- | alot/db/envelope.py | 3 |
5 files changed, 31 insertions, 10 deletions
diff --git a/alot/account.py b/alot/account.py index a08be7ec..6bee5706 100644 --- a/alot/account.py +++ b/alot/account.py @@ -4,7 +4,6 @@ import mailbox import logging import time -import email import os import glob @@ -153,7 +152,6 @@ class SendmailAccount(Account): self.cmd = cmd def send_mail(self, mail): - mail['Date'] = email.utils.formatdate(time.time(), True) cmdlist = split_commandstring(self.cmd) def cb(out): @@ -168,7 +166,7 @@ class SendmailAccount(Account): logging.error(failure.value.stderr) raise SendingMailFailed(errmsg) - d = call_cmd_async(cmdlist, stdin=crypto.email_as_string(mail)) + d = call_cmd_async(cmdlist, stdin=mail) d.addCallback(cb) d.addErrback(errb) return d diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 58baaaed..7f6bcc37 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -100,7 +100,7 @@ class SaveCommand(Command): # store mail locally # add Date header mail['Date'] = email.Utils.formatdate(localtime=True) - path = account.store_draft_mail(mail) + path = account.store_draft_mail(crypto.email_as_string(mail)) ui.notify('draft saved successfully') # add mail to index if maildir path available @@ -142,6 +142,8 @@ class SendCommand(Command): try: mail = envelope.construct_mail() + mail['Date'] = email.Utils.formatdate(localtime=True) + mail = crypto.email_as_string(mail) except GPGProblem, e: ui.clear_notify([clearme]) ui.notify(e.message, priority='error') @@ -160,8 +162,6 @@ class SendCommand(Command): ui.notify('mail sent successfully') # store mail locally # add Date header - if 'Date' not in mail: - mail['Date'] = email.Utils.formatdate(localtime=True) path = account.store_sent_mail(mail) # add mail to index if maildir path available if path is not None: diff --git a/alot/crypto.py b/alot/crypto.py index 134aa597..d672b9a1 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 @@ -18,9 +19,23 @@ def email_as_string(mail): :rtype: str """ fp = StringIO() - g = Generator(fp, mangle_from_=False) + g = Generator(fp, mangle_from_=False, maxheaderlen=78) g.flatten(mail) - return RFC3156_canonicalize(fp.getvalue()) + as_string = RFC3156_canonicalize(fp.getvalue()) + + 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'--(\r\n)--' + boundary, + '--\g<1>\g<1>--' + boundary, + as_string, flags=re.MULTILINE) + + return as_string def _hash_algo_name(hash_algo): diff --git a/alot/db/attachment.py b/alot/db/attachment.py index 2083dedd..2f8b37dc 100644 --- a/alot/db/attachment.py +++ b/alot/db/attachment.py @@ -4,6 +4,8 @@ import os import tempfile import email.charset as charset +from email.header import Header +from copy import deepcopy charset.add_charset('utf-8', charset.QP, charset.QP, 'utf-8') import alot.helper as helper from alot.helper import string_decode @@ -81,4 +83,9 @@ class Attachment(object): def get_mime_representation(self): """returns mime part that constitutes this attachment""" - return self.part + part = deepcopy(self.part) + cd = self.part['Content-Disposition'] + del part['Content-Disposition'] + part['Content-Disposition'] = Header(cd, maxlinelen=78, + header_name='Content-Disposition') + return part diff --git a/alot/db/envelope.py b/alot/db/envelope.py index c95428ea..f464ebae 100644 --- a/alot/db/envelope.py +++ b/alot/db/envelope.py @@ -15,6 +15,7 @@ from alot import __version__ import logging import alot.helper as helper import alot.crypto as crypto +import gpgme from alot.settings import settings from alot.errors import GPGProblem @@ -159,7 +160,7 @@ class Envelope(object): if self.sign: plaintext = crypto.email_as_string(inner_msg) - logging.info('signing plaintext: ' + plaintext) + logging.debug('signing plaintext: ' + plaintext) try: signatures, signature_str = crypto.detached_signature_for( |