From a741ac644bf77eb7deb61ba0e1eecb30a1c77268 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 13 May 2021 10:05:51 +0200 Subject: commands/thread:ReplyCommand: factor out building reply subject --- alot/commands/thread.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/alot/commands/thread.py b/alot/commands/thread.py index b00cbd68..7ac7dd93 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -153,6 +153,18 @@ class ReplyCommand(Command): self.force_spawn = spawn super().__init__(**kwargs) + def _reply_subject(self, message): + subject = message.headers.get('Subject') or '' + reply_subject_hook = settings.get_hook('reply_subject') + if reply_subject_hook: + subject = reply_subject_hook(subject) + else: + rsp = settings.get('reply_subject_prefix') + if not subject.lower().startswith(('re:', rsp.lower())): + subject = rsp + subject + + return subject + async def apply(self, ui): message = ui.current_buffer.get_selected_message() mail = message.get_email() @@ -177,16 +189,7 @@ class ReplyCommand(Command): envelope = Envelope(bodytext = mailcontent, replied = message) - # copy subject - subject = message.headers.get('Subject') or '' - reply_subject_hook = settings.get_hook('reply_subject') - if reply_subject_hook: - subject = reply_subject_hook(subject) - else: - rsp = settings.get('reply_subject_prefix') - if not subject.lower().startswith(('re:', rsp.lower())): - subject = rsp + subject - envelope.add('Subject', subject) + envelope.add('Subject', self._reply_subject(message)) # Auto-detect ML auto_replyto_mailinglist = settings.get('auto_replyto_mailinglist') -- cgit v1.2.3