From 8670bddb27bb634c286ab47172bb9c82db3678ac Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 10 Feb 2021 15:43:39 +0100 Subject: commands/thread: stop calling get_email in ForwardCommand Serialize the message and deserialize it again to avoid modifying it. --- alot/commands/thread.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 1d694f94..ea468bc0 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -316,32 +316,29 @@ class ForwardCommand(Command): """forward message""" repeatable = True - def __init__(self, message=None, attach=True, spawn=None, **kwargs): + def __init__(self, attach=True, spawn=None, **kwargs): """ - :param message: message to forward (defaults to selected message) - :type message: `alot.db.message.Message` :param attach: attach original mail instead of inline quoting its body :type attach: bool :param spawn: force spawning of editor in a new terminal :type spawn: bool """ - self.message = message self.inline = not attach self.force_spawn = spawn super().__init__(**kwargs) async def apply(self, ui): - # get message to forward if not given in constructor - if not self.message: - self.message = ui.current_buffer.get_selected_message() - mail = self.message.get_email() + message = ui.current_buffer.get_selected_message() + mail = email.message_from_bytes(message.as_bytes(), + policy = email.policy.SMTP) - envelope = Envelope(passed=self.message) + envelope = Envelope(passed = message) if self.inline: # inline mode # set body text - name, address = self.message.get_author() - timestamp = self.message.date + name, address = message.get_author() + timestamp = message.date + qf = settings.get_hook('forward_prefix') if qf: quote = qf(name, address, timestamp, @@ -352,15 +349,15 @@ class ForwardCommand(Command): mailcontent = quote quotehook = settings.get_hook('text_quote') if quotehook: - mailcontent += quotehook(self.message.get_body_text()) + mailcontent += quotehook(message.get_body_text()) else: quote_prefix = settings.get('quote_prefix') - for line in self.message.get_body_text().splitlines(): + for line in message.get_body_text().splitlines(): mailcontent += quote_prefix + line + '\n' envelope.body = mailcontent - for a in self.message.iter_attachments(): + for a in message.iter_attachments(): envelope.attach(a) else: # attach original mode -- cgit v1.2.3