From f5f723eada40036f74a022c2d9c7b6ac51efb63a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Nov 2021 15:55:19 +0100 Subject: commands/thread: refactor setting reply references Move it to its own function, simplify the flow control. Expand the arbitrary references limit to 16 in total. --- alot/commands/thread.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/alot/commands/thread.py b/alot/commands/thread.py index e84def23..cba0af65 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -173,6 +173,18 @@ class ReplyCommand(Command): return bool(self._force_list_reply) + def _reply_references(self, message): + old_references = message.headers.get(HDR.REFERENCES) + references = [] + + if old_references: + references = old_references.split() + # limit to 16 references, including the one we add + del references[1:-14] + + references.append('<%s>' % message.id) + return ' '.join(references) + async def apply(self, ui): message = ui.current_buffer.get_selected_message() @@ -280,20 +292,9 @@ class ReplyCommand(Command): logging.debug('mail followup to: %s', followupto) headers[HDR.MAIL_FOLLOWUP_TO] = followupto - # set In-Reply-To header + # set In-Reply-To + References headers headers[HDR.IN_REPLY_TO] = '<%s>' % message.id - - # set References header - old_references = message.headers.get(HDR.REFERENCES) - if old_references: - old_references = old_references.split() - references = old_references[-8:] - if len(old_references) > 8: - references = old_references[:1] + references - references.append('<%s>' % message.id) - headers[HDR.REFERENCES] = ' '.join(references) - else: - headers[HDR.REFERENCES] = '<%s>' % message.id + headers[HDR.REFERENCES] = self._reply_references(message) # construct the envelope envelope = Envelope(headers = headers, bodytext = mailcontent, -- cgit v1.2.3