summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-02-10 15:43:39 +0100
committerAnton Khirnov <anton@khirnov.net>2021-02-10 16:04:29 +0100
commit8670bddb27bb634c286ab47172bb9c82db3678ac (patch)
treecdda0b27c948309e40c6224ecfef3d33f7b2dc69
parent5081b4459bab07ab0552fdda5ffed4a8d32b4142 (diff)
commands/thread: stop calling get_email in ForwardCommand
Serialize the message and deserialize it again to avoid modifying it.
-rw-r--r--alot/commands/thread.py25
1 files 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