From f2a92d0123240e41493215adcc2e0dfa9e7fadbb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Nov 2021 16:47:44 +0100 Subject: commands/thread: construct the reply body in its own function --- alot/commands/thread.py | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 09b18a8b..5b9d527b 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -197,6 +197,28 @@ class ReplyCommand(Command): logging.debug('mail followup to: %s', followupto) return followupto + def _build_body_text(self, message, ui): + name, address = message.get_author() + timestamp = message.date + qf = settings.get_hook('reply_prefix') + if qf: + mail = email.message_from_bytes(message.as_bytes(), + policy = email.policy.SMTP) + quotestring = qf(name, address, timestamp, + message=mail, ui=ui, dbm=ui.dbman) + else: + quotestring = 'Quoting %s (%s)\n' % (name or address, timestamp) + mailcontent = quotestring + quotehook = settings.get_hook('text_quote') + if quotehook: + mailcontent += quotehook(message.get_body_text()) + else: + quote_prefix = settings.get('quote_prefix') + for line in message.get_body_text().splitlines(): + mailcontent += quote_prefix + line + '\n' + + return mailcontent + def _determine_recipients(self, message, account): # set To sender = (message.headers.get(HDR.REPLY_TO) or @@ -260,26 +282,7 @@ class ReplyCommand(Command): async def apply(self, ui): message = ui.current_buffer.get_selected_message() - # set body text - name, address = message.get_author() - timestamp = message.date - qf = settings.get_hook('reply_prefix') - if qf: - mail = email.message_from_bytes(message.as_bytes(), - policy = email.policy.SMTP) - quotestring = qf(name, address, timestamp, - message=mail, ui=ui, dbm=ui.dbman) - else: - quotestring = 'Quoting %s (%s)\n' % (name or address, timestamp) - mailcontent = quotestring - quotehook = settings.get_hook('text_quote') - if quotehook: - mailcontent += quotehook(message.get_body_text()) - else: - quote_prefix = settings.get('quote_prefix') - for line in message.get_body_text().splitlines(): - mailcontent += quote_prefix + line + '\n' - + # construct reply headers headers = {} headers[HDR.SUBJECT] = self._reply_subject(message) @@ -309,8 +312,10 @@ class ReplyCommand(Command): if mft: headers[HDR.MAIL_FOLLOWUP_TO] = mft + body_text = self._build_body_text(message, ui) + # construct the envelope - envelope = Envelope(headers = headers, bodytext = mailcontent, + envelope = Envelope(headers = headers, bodytext = body_text, account = account, replied = message) # continue to compose -- cgit v1.2.3