diff options
-rw-r--r-- | alot/account.py | 4 | ||||
-rw-r--r-- | alot/commands/envelope.py | 6 | ||||
-rw-r--r-- | alot/crypto.py | 15 | ||||
-rw-r--r-- | alot/db/envelope.py | 1 |
4 files changed, 19 insertions, 7 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..b03cc2b8 100644 --- a/alot/crypto.py +++ b/alot/crypto.py @@ -17,10 +17,23 @@ 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) - return RFC3156_canonicalize(fp.getvalue()) + 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) + return as_string def _hash_algo_name(hash_algo): diff --git a/alot/db/envelope.py b/alot/db/envelope.py index c95428ea..c69d70ac 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 |