summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-05-13 10:12:48 +0200
committerAnton Khirnov <anton@khirnov.net>2021-05-13 11:36:57 +0200
commiteef2d7d1521c88b689794a0bceedc40e93711a3e (patch)
tree958933fbbfacb51b101e1e15e0a69442629b4d75
parent4d143150ba1764ada71a07d1c97408caac1d24b7 (diff)
commands/thread:ReplyCommand: use the message headers object for building reply
-rw-r--r--alot/commands/thread.py23
-rw-r--r--alot/db/message.py7
2 files changed, 19 insertions, 11 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 06cc6666..7d2180a6 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -208,13 +208,13 @@ class ReplyCommand(Command):
envelope.account = account
# set To
- sender = mail['Reply-To'] or mail['From']
+ sender = message.headers.get('Reply-To') or message.headers.get('From') or ''
sender_address = parseaddr(sender)[1]
cc = []
# check if reply is to self sent message
if account.matches_address(sender_address):
- recipients = mail.get_all('To', [])
+ recipients = message.headers.get_all('To')
emsg = 'Replying to own message, set recipients to: %s' \
% recipients
logging.debug(emsg)
@@ -224,25 +224,25 @@ class ReplyCommand(Command):
if self.groupreply:
# make sure that our own address is not included
# if the message was self-sent, then our address is not included
- MFT = mail.get_all('Mail-Followup-To', [])
+ MFT = message.headers.get_all('Mail-Followup-To')
followupto = clear_my_address(account, MFT)
if followupto and settings.get('honor_followup_to'):
logging.debug('honor followup to: %s', ', '.join(followupto))
recipients = followupto
# since Mail-Followup-To was set, ignore the Cc header
else:
- if sender != mail['From']:
- recipients.append(mail['From'])
+ if sender != message.headers.get('From'):
+ recipients.append(message.headers.get('From'))
# append To addresses if not replying to self sent message
if not account.matches_address(sender_address):
cleared = clear_my_address(account,
- mail.get_all('To', []))
+ message.headers.get_all('To'))
recipients.extend(cleared)
# copy cc for group-replies
- if 'Cc' in mail:
- cc = clear_my_address(account, mail.get_all('Cc', []))
+ if 'Cc' in message.headers:
+ cc = clear_my_address(account, message.headers.get_all('Cc'))
envelope.add('Cc', ', '.join(cc))
to = ', '.join(ensure_unique_address(recipients))
@@ -253,12 +253,13 @@ class ReplyCommand(Command):
# Reply-To is standart reply target RFC 2822:, RFC 1036: 2.2.1
# X-BeenThere is needed by sourceforge ML also winehq
# X-Mailing-List is also standart and is used by git-send-mail
- to = mail['Reply-To'] or mail['X-BeenThere'] or mail['X-Mailing-List']
+ to = message.headers.get('Reply-To') or message.headers.get('X-BeenThere') or \
+ message.headers.get('X-Mailing-List')
# Some mail server (gmail) will not resend you own mail, so you
# have to deal with the one in sent
if to is None:
- to = mail['To']
+ to = message.headers['To']
logging.debug('mail list reply to: %s', to)
# Cleaning the 'To' in this case
if envelope.get('To') is not None:
@@ -283,7 +284,7 @@ class ReplyCommand(Command):
envelope.add('In-Reply-To', '<%s>' % message.id)
# set References header
- old_references = mail.get('References', '')
+ old_references = message.headers.get('References')
if old_references:
old_references = old_references.split()
references = old_references[-8:]
diff --git a/alot/db/message.py b/alot/db/message.py
index d849c91b..df6f8b1c 100644
--- a/alot/db/message.py
+++ b/alot/db/message.py
@@ -74,6 +74,13 @@ class _MessageHeaders:
"""
return self._msg.get(key)
+ def get_all(self, key):
+ """
+ Get the list of all values of the header with the name equal to key,
+ empty list of the header is not present.
+ """
+ return self._msg.get_all(key, [])
+
def keys(self):
return self._msg.keys()