From b7218c384ba4b3fd8a2c057a0033f023fadc6686 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Tue, 9 Oct 2012 21:48:26 +0200 Subject: [PATCH] [PATCH] notmuch-mutt: add --whole-thread flag --- 76/bfffdcb713d2a536fd40061190adde023e4340 | 169 ++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 76/bfffdcb713d2a536fd40061190adde023e4340 diff --git a/76/bfffdcb713d2a536fd40061190adde023e4340 b/76/bfffdcb713d2a536fd40061190adde023e4340 new file mode 100644 index 000000000..e578774f3 --- /dev/null +++ b/76/bfffdcb713d2a536fd40061190adde023e4340 @@ -0,0 +1,169 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id A898F431FB6 + for ; Tue, 9 Oct 2012 12:49:20 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id aWvFdWJmTwEG for ; + Tue, 9 Oct 2012 12:49:20 -0700 (PDT) +Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com + [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + C7E9F431FAF for ; Tue, 9 Oct 2012 12:49:19 -0700 + (PDT) +Received: by mail-wg0-f45.google.com with SMTP id dq12so4044646wgb.2 + for ; Tue, 09 Oct 2012 12:49:17 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer; + bh=eGTr6bXGDPR0O3B7tETppbKf3l0vR+T5gyfqvFsnriU=; + b=ca40/7bBhUaPitrkV5H4p1GpE5wuZlGKXq2x0LzprvtWWMplG0bFjE7ws9d2eaQ5/U + saAHAUQz/n8r/V4zfAgUQr8zhGMoY7G5En2N85HiZPCS74QwjAVumUm2BGZ6n/7WBU8v + td46augJSXNfYTyzGkeNJJ+EMuVJzSlWMA53UW1WRGmyK7ib3+H67UmcdFFwg75JjUOX + eUfawimie2yfQv+zZ94FIxtibcAd9XDgUyMOfj+AUUk+RoPH0lDuaxtOODbrKYj6xpYL + lcbux1EzYGWyB+4uHIebwAJKphhmy32sAMqOvFletRabdR7LZeXooeUeu0TmgVaUCcRe + Omyw== +Received: by 10.180.97.35 with SMTP id dx3mr7003456wib.14.1349812157102; + Tue, 09 Oct 2012 12:49:17 -0700 (PDT) +Received: from localhost (188-194-252-80-dynip.superkabel.de. + [188.194.252.80]) by mx.google.com with ESMTPS id + dm3sm29786895wib.3.2012.10.09.12.49.15 (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 09 Oct 2012 12:49:15 -0700 (PDT) +From: Stefan Hajnoczi +To: notmuch@notmuchmail.org +Subject: [PATCH] notmuch-mutt: add --whole-thread flag +Date: Tue, 9 Oct 2012 21:48:26 +0200 +Message-Id: <1349812106-26916-1-git-send-email-stefanha@gmail.com> +X-Mailer: git-send-email 1.7.11.4 +X-Mailman-Approved-At: Tue, 09 Oct 2012 22:15:03 -0700 +Cc: Stefan Hajnoczi , Stefano Zacchiroli +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 09 Oct 2012 19:49:20 -0000 + +It can be useful to manipulate tags on an entire thread instead of just +a single message. For example: + + # Mark entire thread unread + notmuch-mutt tag --whole-thread -- -unread < MAIL + +Add the --whole-thread flag which first looks up the thread for a given +message and then applies the tag action on the entire thread. + +Signed-off-by: Stefan Hajnoczi +--- +Warning: I don't really know Perl :) + +It would be nice if notmuch's query syntax could match threads. Then +core notmuch CLI could perform this operation in a single command: + + # Mark entire thread unread given a single Message-ID + notmuch tag thread-contains(id:1234@foo.com) -- -unread + +Since the core cannot do this query today this patch bolts it on top for +"notmuch-mutt tag". + + contrib/notmuch-mutt/notmuch-mutt | 38 +++++++++++++++++++++++++++----------- + 1 file changed, 27 insertions(+), 11 deletions(-) + +diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt +index d14709d..8529940 100755 +--- a/contrib/notmuch-mutt/notmuch-mutt ++++ b/contrib/notmuch-mutt/notmuch-mutt +@@ -125,6 +125,14 @@ sub get_message_id() { + return $1; + } + ++sub get_thread_id($) { ++ my ($mid) = @_; ++ my $search_cmd = 'notmuch search --output=threads ' ++ . shell_quote("id:$mid"); ++ `$search_cmd` =~ /^thread:(.*)$/; ++ return $1; ++} ++ + sub search_action($$$@) { + my ($interactive, $results_dir, $remove_dups, @params) = @_; + +@@ -141,20 +149,26 @@ sub search_action($$$@) { + sub thread_action($$@) { + my ($results_dir, $remove_dups, @params) = @_; + +- my $mid = get_message_id(); +- my $search_cmd = 'notmuch search --output=threads ' . shell_quote("id:$mid"); +- my $tid = `$search_cmd`; # get thread id +- chomp($tid); ++ my $tid = get_thread_id(get_message_id()); + +- search($results_dir, $remove_dups, $tid); ++ search($results_dir, $remove_dups, "thread:$tid"); + } + +-sub tag_action(@) { ++sub tag_action($@) { ++ my ($whole_thread, @params) = @_; + my $mid = get_message_id(); + +- system("notmuch tag " +- . shell_quote(join(' ', @_)) +- . " id:$mid"); ++ if ($whole_thread) { ++ my $tid = get_thread_id($mid); ++ ++ system("notmuch tag " ++ . shell_quote(join(' ', @params)) ++ . " thread:$tid"); ++ } else { ++ system("notmuch tag " ++ . shell_quote(join(' ', @params)) ++ . " id:$mid"); ++ } + } + + sub die_usage() { +@@ -170,12 +184,14 @@ sub main() { + my $interactive = 0; + my $help_needed = 0; + my $remove_dups = 0; ++ my $whole_thread = 0; + + my $getopt = GetOptions( + "h|help" => \$help_needed, + "o|output-dir=s" => \$results_dir, + "p|prompt" => \$interactive, +- "r|remove-dups" => \$remove_dups); ++ "r|remove-dups" => \$remove_dups, ++ "w|whole-thread" => \$whole_thread); + if (! $getopt || $#ARGV < 0) { die_usage() }; + my ($action, @params) = ($ARGV[0], @ARGV[1..$#ARGV]); + +@@ -193,7 +209,7 @@ sub main() { + } elsif ($action eq "thread") { + thread_action($results_dir, $remove_dups, @params); + } elsif ($action eq "tag") { +- tag_action(@params); ++ tag_action($whole_thread, @params); + } else { + die_usage(); + } +-- +1.7.11.4 + -- 2.26.2