From c784afbdbed77155dd90904809003c90e9b43e76 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Mon, 8 Jun 2020 13:55:22 -0400 Subject: Fix bug with threading when cover ref is missing When the cover letter is missing and we're starting in the middle of the thread, do not discard messages in the mbox that come before the msgid that we want. Reported-by: Linus Torvalds Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index fe0a8a1..06bc33e 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -1928,8 +1928,12 @@ def save_strict_thread(in_mbx, out_mbx, msgid): logger.debug('Looking at: %s', c_msgid) refs = set() - for ref in msg.get('References', msg.get('In-Reply-To', '')).split(): - ref = ref.strip().strip('<>') + msgrefs = list() + if msg.get('In-Reply-To', None): + msgrefs += email.utils.getaddresses([str(x) for x in msg.get_all('in-reply-to', [])]) + if msg.get('References', None): + msgrefs += email.utils.getaddresses([str(x) for x in msg.get_all('references', [])]) + for ref in set([x[1] for x in msgrefs]): if ref in got or ref in want: want.add(c_msgid) elif len(ref): @@ -1950,6 +1954,11 @@ def save_strict_thread(in_mbx, out_mbx, msgid): # Add all these to want want.update(maybe[c_msgid]) maybe.pop(c_msgid) + # Add all maybes that have the same ref into want + for ref in refs: + if ref in maybe: + want.update(maybe[ref]) + maybe.pop(ref) # Remove any entries not in "seen" (missing messages) for c_msgid in set(want): -- cgit v1.2.3