From bafb9559e74fdf3246b76f3f765c6783406804e8 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Fri, 10 Apr 2020 16:26:41 -0400 Subject: Backport improvements to strict thread saving Do a better job saving a strict thread when the cover letter is in the middle of the mailbox instead of at the very beginning. Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index e947b44..eba06cb 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -1365,20 +1365,27 @@ def save_strict_thread(in_mbx, out_mbx, msgid): want = {msgid} got = set() seen = set() + maybe = dict() while True: for msg in in_mbx: c_msgid = LoreMessage.get_clean_msgid(msg) seen.add(c_msgid) if c_msgid in got: continue + logger.debug('Looking at: %s', c_msgid) - refs = list() + refs = set() for ref in msg.get('References', msg.get('In-Reply-To', '')).split(): ref = ref.strip().strip('<>') if ref in got or ref in want: want.add(c_msgid) elif len(ref): - refs.append(ref) + refs.add(ref) + if c_msgid not in want: + if ref not in maybe: + maybe[ref] = set() + logger.debug('Going into maybe: %s->%s', ref, c_msgid) + maybe[ref].add(c_msgid) if c_msgid in want: out_mbx.add(msg) @@ -1386,10 +1393,14 @@ def save_strict_thread(in_mbx, out_mbx, msgid): want.update(refs) want.discard(c_msgid) logger.debug('Kept in thread: %s', c_msgid) + if c_msgid in maybe: + # Add all these to want + want.update(maybe[c_msgid]) + maybe.pop(c_msgid) # Remove any entries not in "seen" (missing messages) for c_msgid in set(want): - if c_msgid not in seen: + if c_msgid not in seen or c_msgid in got: want.remove(c_msgid) if not len(want): break -- cgit v1.2.3