summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-11-20 16:47:44 +0100
committerAnton Khirnov <anton@khirnov.net>2021-11-20 16:47:44 +0100
commitf2a92d0123240e41493215adcc2e0dfa9e7fadbb (patch)
treec3266d18ab6f17d4e192f831f54386ccd5c28b52
parent9b14a9f95ccaffc1eac08d184cea5d7a6804c4fc (diff)
commands/thread: construct the reply body in its own function
-rw-r--r--alot/commands/thread.py47
1 files 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