diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-03-06 09:10:29 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-03-06 09:13:30 +0100 |
commit | d70f627c7a91e0aeed60c29e690be300c4008dab (patch) | |
tree | f6c7cedc87e60caf2d295598e6c92fe76a7f44aa | |
parent | e2efd81f0dc4f913c73a2494091f67c748001942 (diff) |
widgets/thread: use the headers object to access message headers
Avoid accessing the email directly.
-rw-r--r-- | alot/db/message.py | 3 | ||||
-rw-r--r-- | alot/widgets/thread.py | 18 |
2 files changed, 11 insertions, 10 deletions
diff --git a/alot/db/message.py b/alot/db/message.py index c0bdb398..f2752e19 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -370,6 +370,9 @@ class _MessageHeaders: def __init__(self, msg): self._msg = msg + def __contains__(self, key): + return key in self._msg + def __getitem__(self, key): if not key in self._msg: raise KeyError(key) diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index f6a0a9ea..dcbbd9da 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -56,9 +56,7 @@ class MessageSummaryWidget(urwid.WidgetWrap): super().__init__(line) def __str__(self): - mail = self.message.get_email() - - subj = mail.get_all('subject', ['']) + subj = self.message.headers['Subject'] subj = re.sub(r'\n\s+', r' ', ','.join(subj)) author, address = self.message.get_author() @@ -245,21 +243,21 @@ class MessageWidget(urwid.WidgetWrap): if val == self._display_all_headers: return - mail = self._message.get_email() + headers = self._message.headers lines = [] if val: # collect all header/value pairs in the order they appear - lines = list(mail.items()) + lines = list(headers.items()) else: # only a selection of headers should be displayed. # use order of the `headers` parameter for key in settings.get('displayed_headers'): - if key in mail: + if key in headers: if key.lower() in ['cc', 'bcc', 'to']: - lines.append((key, ', '.join(mail.get_all(key)))) + lines.append((key, ', '.join(headers[key]))) else: - for value in mail.get_all(key): + for value in headers[key]: lines.append((key, value)) elif key.lower() == 'tags': # TODO this should be in a separate widget @@ -274,8 +272,8 @@ class MessageWidget(urwid.WidgetWrap): # OpenPGP pseudo headers # TODO this should be in a separate widget - if mail[X_SIGNATURE_MESSAGE_HEADER]: - lines.append(('PGP-Signature', mail[X_SIGNATURE_MESSAGE_HEADER])) + if X_SIGNATURE_MESSAGE_HEADER in headers: + lines.append(('PGP-Signature', headers[X_SIGNATURE_MESSAGE_HEADER][0])) self._headers_wgt.set_headers(lines) |