--- /dev/null
+Return-Path: <keevan@fastmail.fm>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 7AD99429E50\r
+ for <notmuch@notmuchmail.org>; Wed, 4 Sep 2013 19:14:08 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 5MAEuF5xbkvK for <notmuch@notmuchmail.org>;\r
+ Wed, 4 Sep 2013 19:14:03 -0700 (PDT)\r
+Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com\r
+ [66.111.4.27])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id C0DAF429E4C\r
+ for <notmuch@notmuchmail.org>; Wed, 4 Sep 2013 19:14:02 -0700 (PDT)\r
+Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41])\r
+ by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 89F812113C;\r
+ Wed, 4 Sep 2013 22:06:34 -0400 (EDT)\r
+Received: from frontend2 ([10.202.2.161])\r
+ by compute1.internal (MEProxy); Wed, 04 Sep 2013 22:06:34 -0400\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=8t8.us; h=from:to\r
+ :cc:subject:date:message-id:in-reply-to:references; s=mesmtp;\r
+ bh=NwXtEP9eSENBMPi85MxvEbbVmQg=; b=YVisTZ6Ahnge0sY2tXn3DZ4OK0uN\r
+ Hu9OA6kC3JO9Cmf3XXpj/k385rGOCV/H/9dMZhW3stkNSHOmy4NnEJvtcbMjF/bQ\r
+ SVoDuoJfj54J3Pbj2IoK2GVNPxblriNmTSDnWYBfU8F2TFCyyYlCBLJ8nAB21rEj\r
+ 4RKvkoogqHeDqXE=\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=\r
+ messagingengine.com; h=from:to:cc:subject:date:message-id\r
+ :in-reply-to:references; s=smtpout; bh=NwXtEP9eSENBMPi85MxvEbbVm\r
+ Qg=; b=llgO6YCC45vnB/CwRbtiEheD7weA/LdNtUc93121FGu5BY6CpxxMct70N\r
+ XXUvw0E1XmHgVkmXQQeQFvH6GQk80e0/gt3soh+tfNlyKENQ1AGcSsdorMVsVJsG\r
+ O1cKAGNK9oDvIHgFCi9gQM5jeF6dsbgt76S+/Z8BssaUWjdYA4=\r
+X-Sasl-enc: WE7t0EeN3frTUXWxsuElr80nUavLFJk0cjUDWF1+0LJl 1378346793\r
+Received: from localhost (unknown [97.125.94.9])\r
+ by mail.messagingengine.com (Postfix) with ESMTPA id 9A7806804FA;\r
+ Wed, 4 Sep 2013 22:06:33 -0400 (EDT)\r
+From: Kevin McCarthy <kevin@8t8.us>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] notmuch-mutt: use notmuch --duplicate flag\r
+Date: Wed, 4 Sep 2013 19:05:50 -0700\r
+Message-Id: <1378346751-25548-2-git-send-email-kevin@8t8.us>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <1378346751-25548-1-git-send-email-kevin@8t8.us>\r
+References: <1378346751-25548-1-git-send-email-kevin@8t8.us>\r
+Cc: zack@upsilon.cc\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 05 Sep 2013 02:14:08 -0000\r
+\r
+Change notmuch-mutt to use the new --duplicate=1 flag for duplicate\r
+removal. This will remove duplicates based on message-id at the\r
+notmuch level. Previously we were using fdupes or generating sha sums\r
+after the search.\r
+\r
+This version will be faster, but will enable the possibility of hiding\r
+search results due to accidental/malicious duplicate message-ids.\r
+---\r
+ contrib/notmuch-mutt/README | 5 ---\r
+ contrib/notmuch-mutt/notmuch-mutt | 64 +++++++--------------------------------\r
+ 2 files changed, 11 insertions(+), 58 deletions(-)\r
+\r
+diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README\r
+index e00035c..382ac91 100644\r
+--- a/contrib/notmuch-mutt/README\r
++++ b/contrib/notmuch-mutt/README\r
+@@ -41,11 +41,6 @@ To *run* notmuch-mutt you will need Perl with the following libraries:\r
+ (Debian package: libstring-shellquote-perl)\r
+ - Term::ReadLine <http://search.cpan.org/~hayashi/Term-ReadLine-Gnu/>\r
+ (Debian package: libterm-readline-gnu-perl)\r
+-- File::Which <http://search.cpan.org/dist/File-Which/>\r
+- (Debian package: libfile-which-perl)\r
+-\r
+-The --remove-dups option will use fdupes <https://code.google.com/p/fdupes/>\r
+-if it is installed. Version fdupes-1.50-PR2 or higher is required.\r
+ \r
+ To *build* notmuch-mutt documentation you will need:\r
+ \r
+diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt\r
+index 00c5ef8..c69b35c 100755\r
+--- a/contrib/notmuch-mutt/notmuch-mutt\r
++++ b/contrib/notmuch-mutt/notmuch-mutt\r
+@@ -18,8 +18,6 @@ use Mail::Box::Maildir;\r
+ use Pod::Usage;\r
+ use String::ShellQuote;\r
+ use Term::ReadLine;\r
+-use Digest::SHA;\r
+-use File::Which;\r
+ \r
+ \r
+ my $xdg_cache_dir = "$ENV{HOME}/.cache";\r
+@@ -36,65 +34,22 @@ sub empty_maildir($) {\r
+ $folder->close();\r
+ }\r
+ \r
+-# Match files by size and SHA-256; then delete duplicates\r
+-sub builtin_remove_dups($) {\r
+- my ($maildir) = @_;\r
+- my (%size_to_files, %sha_to_files);\r
+-\r
+- # Group files by matching sizes\r
+- foreach my $file (glob("$maildir/cur/*")) {\r
+- my $size = -s $file;\r
+- push(@{$size_to_files{$size}}, $file) if $size;\r
+- }\r
+-\r
+- foreach my $same_size_files (values %size_to_files) {\r
+- # Don't run sha unless there is another file of the same size\r
+- next if scalar(@$same_size_files) < 2;\r
+- %sha_to_files = ();\r
+-\r
+- # Group files with matching sizes by SHA-256\r
+- foreach my $file (@$same_size_files) {\r
+- open(my $fh, '<', $file) or next;\r
+- binmode($fh);\r
+- my $sha256hash = Digest::SHA->new(256)->addfile($fh)->hexdigest;\r
+- close($fh);\r
+-\r
+- push(@{$sha_to_files{$sha256hash}}, $file);\r
+- }\r
+-\r
+- # Remove duplicates\r
+- foreach my $same_sha_files (values %sha_to_files) {\r
+- next if scalar(@$same_sha_files) < 2;\r
+- unlink(@{$same_sha_files}[1..$#$same_sha_files]);\r
+- }\r
+- }\r
+-}\r
+-\r
+-# Use either fdupes or the built-in scanner to detect and remove duplicate\r
+-# search results in the maildir\r
+-sub remove_duplicates($) {\r
+- my ($maildir) = @_;\r
+-\r
+- my $fdupes = which("fdupes");\r
+- if ($fdupes) {\r
+- system("$fdupes --hardlinks --symlinks --delete --noprompt"\r
+- . " --quiet $maildir/cur/ > /dev/null");\r
+- } else {\r
+- builtin_remove_dups($maildir);\r
+- }\r
+-}\r
+-\r
+ # search($maildir, $remove_dups, $query)\r
+ # search mails according to $query with notmuch; store results in $maildir\r
+ sub search($$$) {\r
+ my ($maildir, $remove_dups, $query) = @_;\r
++ my $dup_option = "";\r
++\r
+ $query = shell_quote($query);\r
+ \r
++ if ($remove_dups) {\r
++ $dup_option = "--duplicate=1";\r
++ }\r
++\r
+ empty_maildir($maildir);\r
+- system("notmuch search --output=files $query"\r
++ system("notmuch search --output=files $dup_option $query"\r
+ . " | sed -e 's: :\\\\ :g'"\r
+ . " | xargs --no-run-if-empty ln -s -t $maildir/cur/");\r
+- remove_duplicates($maildir) if ($remove_dups);\r
+ }\r
+ \r
+ sub prompt($$) {\r
+@@ -252,7 +207,10 @@ Instead of using command line search terms, prompt the user for them (only for\r
+ \r
+ =item --remove-dups\r
+ \r
+-Remove duplicates from search results.\r
++Remove emails with duplicate message-ids from search results. (Passes\r
++--duplicate=1 to notmuch search command.) Note this can hide search\r
++results if an email accidentally or maliciously uses the same message-id\r
++as a different email.\r
+ \r
+ =item -h\r
+ \r
+-- \r
+1.8.4.rc3\r
+\r