From 01d334f81b8b3d29c034d559f93339a274efb199 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Thu, 20 May 2021 10:40:39 -0400 Subject: Fix a crash on incomplete/missing threads Properly handle situation where we can get a None as well as an empty message list. Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 13 ++++++++++--- b4/mbox.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index bc669fe..443b0cf 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -219,6 +219,8 @@ class LoreMailbox: continue # Try to backfill from that project backfills = get_pi_thread_by_msgid(patch.msgid, useproject=projmap[entry[1]]) + if not backfills: + return was = len(self.msgid_map) for msg in backfills: self.add_message(msg) @@ -610,7 +612,11 @@ class LoreSeries: else: checkmark, trailers, critical = lmsg.get_attestation_trailers(attpolicy, maxdays) - logger.info(' %s %s', checkmark, lmsg.get_am_subject()) + if checkmark: + logger.info(' %s %s', checkmark, lmsg.get_am_subject()) + else: + logger.info(' %s', lmsg.get_am_subject()) + for trailer in trailers: logger.info(' %s', trailer) @@ -1016,6 +1022,7 @@ class LoreMessage: if self.msg.get('dkim-signature') and config['attestation-check-dkim'] == 'yes': self._load_dkim_attestors() + logger.debug('Attestors: %s', len(self._attestors)) return self._attestors def _load_dkim_attestors(self) -> None: @@ -2074,7 +2081,7 @@ def get_pi_thread_by_url(t_mbx_url, nocache=False): msgs = list() cachedir = get_cache_file(t_mbx_url, 'pi.msgs') if os.path.exists(cachedir) and not nocache: - logger.info('Using cached copy: %s', cachedir) + logger.debug('Using cached copy: %s', cachedir) for msg in os.listdir(cachedir): with open(os.path.join(cachedir, msg), 'rb') as fh: msgs.append(email.message_from_binary_file(fh)) @@ -2123,7 +2130,7 @@ def get_pi_thread_by_msgid(msgid, useproject=None, nocache=False): logger.debug('t_mbx_url=%s', t_mbx_url) msgs = get_pi_thread_by_url(t_mbx_url, nocache=nocache) - if not len(msgs): + if not msgs: return None strict = get_strict_thread(msgs, msgid) diff --git a/b4/mbox.py b/b4/mbox.py index 850558f..724e956 100644 --- a/b4/mbox.py +++ b/b4/mbox.py @@ -501,7 +501,7 @@ def main(cmdargs): sys.exit(1) msgs = b4.get_pi_thread_by_msgid(msgid, useproject=cmdargs.useproject, nocache=cmdargs.nocache) - if not len(msgs): + if not msgs: return else: if cmdargs.localmbox == '-': -- cgit v1.2.3