From 6a0ba55dc339b67afa363771525110c575fe6f62 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Nov 2021 16:13:43 +0100 Subject: commands/thread: refactor adding mail-followup-to header Move it to a separate function, simplify flow control. --- alot/commands/thread.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/alot/commands/thread.py b/alot/commands/thread.py index cba0af65..400d4774 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -185,6 +185,18 @@ class ReplyCommand(Command): references.append('<%s>' % message.id) return ' '.join(references) + def _mail_followup_to(self, recipients): + if not settings.get('followup_to'): + return None + + lists = settings.get('mailinglists') + + # check if any recipient address matches a known mailing list + if any(addr in lists for n, addr in getaddresses(recipients)): + followupto = ', '.join(recipients) + logging.debug('mail followup to: %s', followupto) + return followupto + async def apply(self, ui): message = ui.current_buffer.get_selected_message() @@ -280,22 +292,17 @@ class ReplyCommand(Command): # Finally setup the 'To' header headers[HDR.TO] = to - # if any of the recipients is a mailinglist that we are subscribed to, - # set Mail-Followup-To header so that duplicates are avoided - if settings.get('followup_to'): - # to and cc are already cleared of our own address - allrecipients = [to] + cc - lists = settings.get('mailinglists') - # check if any recipient address matches a known mailing list - if any(addr in lists for n, addr in getaddresses(allrecipients)): - followupto = ', '.join(allrecipients) - logging.debug('mail followup to: %s', followupto) - headers[HDR.MAIL_FOLLOWUP_TO] = followupto - # set In-Reply-To + References headers headers[HDR.IN_REPLY_TO] = '<%s>' % message.id headers[HDR.REFERENCES] = self._reply_references(message) + # if any of the recipients is a mailinglist that we are subscribed to, + # set Mail-Followup-To header so that duplicates are avoided + # to and cc are already cleared of our own address + mft = self._mail_followup_to([to] + cc) + if mft: + headers[HDR.MAIL_FOLLOWUP_TO] = mft + # construct the envelope envelope = Envelope(headers = headers, bodytext = mailcontent, account = account, replied = message) -- cgit v1.2.3