From 46aad9005a504caf2894090bf245a9fdda61ea0e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 20 Nov 2021 15:34:04 +0100 Subject: commands/thread: do not construct the Envelope until right before compose It is cleaner to construct it with all the headers known, rather than modify it progressively. --- 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 16f25366..e84def23 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -196,9 +196,9 @@ class ReplyCommand(Command): for line in message.get_body_text().splitlines(): mailcontent += quote_prefix + line + '\n' - envelope = Envelope(bodytext = mailcontent, replied = message) + headers = {} - envelope.add(HDR.SUBJECT, self._reply_subject(message)) + headers[HDR.SUBJECT] = self._reply_subject(message) # set From-header and sending account try: @@ -206,8 +206,7 @@ class ReplyCommand(Command): except AssertionError as e: ui.notify(str(e), priority='error') return - envelope.add(HDR.FROM, from_header) - envelope.account = account + headers[HDR.FROM] = from_header # set To sender = (message.headers.get(HDR.REPLY_TO) or @@ -246,7 +245,7 @@ class ReplyCommand(Command): # copy cc for group-replies if HDR.CC in message.headers: cc = clear_my_address(account, message.headers.get_all(HDR.CC)) - envelope.add(HDR.CC, ', '.join(cc)) + headers[HDR.CC] = ', '.join(cc) to = ', '.join(ensure_unique_address(recipients)) logging.debug('reply to: %s', to) @@ -267,7 +266,7 @@ class ReplyCommand(Command): logging.debug('mail list reply to: %s', to) # Finally setup the 'To' header - envelope.add(HDR.TO, to) + 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 @@ -279,10 +278,10 @@ class ReplyCommand(Command): if any(addr in lists for n, addr in getaddresses(allrecipients)): followupto = ', '.join(allrecipients) logging.debug('mail followup to: %s', followupto) - envelope.add(HDR.MAIL_FOLLOWUP_TO, followupto) + headers[HDR.MAIL_FOLLOWUP_TO] = followupto # set In-Reply-To header - envelope.add(HDR.IN_REPLY_TO, '<%s>' % message.id) + headers[HDR.IN_REPLY_TO] = '<%s>' % message.id # set References header old_references = message.headers.get(HDR.REFERENCES) @@ -292,9 +291,13 @@ class ReplyCommand(Command): if len(old_references) > 8: references = old_references[:1] + references references.append('<%s>' % message.id) - envelope.add(HDR.REFERENCES, ' '.join(references)) + headers[HDR.REFERENCES] = ' '.join(references) else: - envelope.add(HDR.REFERENCES, '<%s>' % message.id) + headers[HDR.REFERENCES] = '<%s>' % message.id + + # construct the envelope + envelope = Envelope(headers = headers, bodytext = mailcontent, + account = account, replied = message) # continue to compose await ui.apply_command(ComposeCommand(envelope=envelope, -- cgit v1.2.3