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 7F4A4C43460 for ; Mon, 3 May 2021 21:53:35 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 59D08611CD; Mon, 3 May 2021 21:53:35 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 0D31F610FB for ; Mon, 3 May 2021 21:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620078815; bh=+vq4Qz/NADDThijHeRFwFHTUucPmcAlOUujepsIoRaQ=; h=From:List-Id:To:Subject:Date:In-Reply-To:References:From; b=auCGbBesmQjdRs5Q6+5WM4SqWn3jmxxaM+2IHsNk4uo6pPiN+9syRT6C1oXZmzf+w N6ZE6QOCKA2FE28OcmaWeTjbI7GtzUqo0YRlsm+Wfc9aAyazDg7VFj0fBXqmFx67CO 42ZZKJtxa4EQMQjFMnvq0WR+WdqT4dgNywgQsZq4= 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 17:53:31 -0400 Message-Id: <20210503215333.141462-2-konstantin@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210503215333.141462-1-konstantin@linuxfoundation.org> References: <20210503215333.141462-1-konstantin@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; h=from:subject; l=3127; bh=+vq4Qz/NADDThijHeRFwFHTUucPmcAlOUujepsIoRaQ=; b=owGbwMvMwCG27YjM47CUmTmMp9WSGBImFKy+qLJr6mU/fe3ndu+nbLR4ou93orFOR/v1pIt3Xeae WaK0raOUhUGMg0FWTJGlbF/spqDChx5y6T2mMHNYmUCGMHBxCsBEljszMjz6d+nBQp881cKvf4JyNR P5GdjXMDebvn13K7N0j5N5KyvDH94fHwNrO1/lP98uP6Hs6ha1AkF7o4lHLpqqu97TnBXJwwcA 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.30.2