Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3C9CC43461 for ; Mon, 3 May 2021 15:48:50 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 5C015610C8; Mon, 3 May 2021 15:48:50 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 0C241600CC for ; Mon, 3 May 2021 15:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620056930; bh=cPaNtBPskAhVZm/+tKuDAsP7oUmMn+wxj6hRcifk0nM=; h=From:List-Id:To:Subject:Date:In-Reply-To:References:From; b=AMufe7GDGagYx9zDC4N9zAd9wln18tlaNnTbOwqw7841fOONS7tB3/FtEmuLPeaVR VTB4FE/O41S6S+Zd+447OLNhjIlgRys7qOc8sDucGnqAU+oj0joplwUKHyDYwyXRTm d9zDzyrp0BX01PN5X1wRehtdpB+4Fh4FigKDXcQs= From: Konstantin Ryabitsev List-Id: To: signatures@kernel.org Subject: [PATCH 1/3] Add -f to "b4 mbox" to filter dupes Date: Mon, 3 May 2021 11:48:46 -0400 Message-Id: <20210503154848.28770-2-konstantin@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503154848.28770-1-konstantin@linuxfoundation.org> References: <20210503154848.28770-1-konstantin@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1620056902; h=from:subject; l=3127; bh=cPaNtBPskAhVZm/+tKuDAsP7oUmMn+wxj6hRcifk0nM=; b=Bqyu1UqqAIowT1GVD1+d1+6kFrtOT0WltraoKyG0SVmHTOXKxDPRaMV+TvpwJ0uAnxXHqMYXBQ3L 3QPUxJF/C1pmpewhQtHZobCKhSKjyy30bNPjY0yFzpeZ8Qig9s9f Content-Transfer-Encoding: 8bit When saving to a maildir, add option to filter out dupes. Note, that this requires going through the entire maildir to collect message-ids, so it's not going to be a great experience on large maildirs. Signed-off-by: Konstantin Ryabitsev --- b4/command.py | 2 ++ b4/mbox.py | 11 +++++++++-- man/b4.5 | 5 ++++- man/b4.5.rst | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/b4/command.py b/b4/command.py index 0c87df9..59fefbf 100644 --- a/b4/command.py +++ b/b4/command.py @@ -84,6 +84,8 @@ def cmd(): # b4 mbox sp_mbox = subparsers.add_parser('mbox', help='Download a thread as an mbox file') cmd_mbox_common_opts(sp_mbox) + sp_mbox.add_argument('-f', '--filter-dupes', dest='filterdupes', action='store_true', default=False, + help='When adding messages to existing maildir, filter out duplicates') sp_mbox.set_defaults(func=cmd_mbox) # b4 am diff --git a/b4/mbox.py b/b4/mbox.py index 226303e..d84d390 100644 --- a/b4/mbox.py +++ b/b4/mbox.py @@ -549,9 +549,16 @@ def main(cmdargs): and os.path.isdir(os.path.join(cmdargs.outdir, 'cur')) and os.path.isdir(os.path.join(cmdargs.outdir, 'tmp'))): mdr = mailbox.Maildir(cmdargs.outdir) + have_msgids = set() + added = 0 + if cmdargs.filterdupes: + for emsg in mdr: + have_msgids.add(b4.LoreMessage.get_clean_msgid(emsg)) for msg in mbx: - mdr.add(msg) - logger.info('Added to maildir %s', cmdargs.outdir) + if b4.LoreMessage.get_clean_msgid(msg) not in have_msgids: + added += 1 + mdr.add(msg) + logger.info('Added to %s messages to maildir %s', added, cmdargs.outdir) mbx.close() os.unlink(threadfile) return diff --git a/man/b4.5 b/man/b4.5 index 350c363..496525d 100644 --- a/man/b4.5 +++ b/man/b4.5 @@ -102,6 +102,9 @@ Instead of grabbing a thread from lore, process this mbox file .TP .B \-C\fP,\fB \-\-no\-cache Do not use local cache +.TP +.B \-f\fP,\fB \-\-filter\-dupes +When adding messages to existing maildir, filter out duplicates .UNINDENT .UNINDENT .sp @@ -341,7 +344,7 @@ Default configuration, with explanations: .ft C [b4] # Where to look up threads by message id - midmask = https://lore.kernel.org/r/%s\(aq + midmask = https://lore.kernel.org/r/%s # # When recording Link: trailers, use this mask linkmask = https://lore.kernel.org/r/%s diff --git a/man/b4.5.rst b/man/b4.5.rst index e21ed71..ee05675 100644 --- a/man/b4.5.rst +++ b/man/b4.5.rst @@ -63,6 +63,7 @@ optional arguments: -m LOCALMBOX, --use-local-mbox LOCALMBOX Instead of grabbing a thread from lore, process this mbox file -C, --no-cache Do not use local cache + -f, --filter-dupes When adding messages to existing maildir, filter out duplicates *Example*: b4 mbox 20200313231252.64999-1-keescook@chromium.org -- 2.31.1