Re: Hi all
[notmuch-archives.git] / 76 / bfffdcb713d2a536fd40061190adde023e4340
1 Return-Path: <stefanha@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id A898F431FB6\r
6         for <notmuch@notmuchmail.org>; Tue,  9 Oct 2012 12:49:20 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id aWvFdWJmTwEG for <notmuch@notmuchmail.org>;\r
17         Tue,  9 Oct 2012 12:49:20 -0700 (PDT)\r
18 Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
19  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
20  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
21  C7E9F431FAF    for <notmuch@notmuchmail.org>; Tue,  9 Oct 2012 12:49:19 -0700\r
22  (PDT)\r
23 Received: by mail-wg0-f45.google.com with SMTP id dq12so4044646wgb.2\r
24         for <notmuch@notmuchmail.org>; Tue, 09 Oct 2012 12:49:17 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:x-mailer;\r
27         bh=eGTr6bXGDPR0O3B7tETppbKf3l0vR+T5gyfqvFsnriU=;\r
28         b=ca40/7bBhUaPitrkV5H4p1GpE5wuZlGKXq2x0LzprvtWWMplG0bFjE7ws9d2eaQ5/U\r
29         saAHAUQz/n8r/V4zfAgUQr8zhGMoY7G5En2N85HiZPCS74QwjAVumUm2BGZ6n/7WBU8v\r
30         td46augJSXNfYTyzGkeNJJ+EMuVJzSlWMA53UW1WRGmyK7ib3+H67UmcdFFwg75JjUOX\r
31         eUfawimie2yfQv+zZ94FIxtibcAd9XDgUyMOfj+AUUk+RoPH0lDuaxtOODbrKYj6xpYL\r
32         lcbux1EzYGWyB+4uHIebwAJKphhmy32sAMqOvFletRabdR7LZeXooeUeu0TmgVaUCcRe\r
33         Omyw==\r
34 Received: by 10.180.97.35 with SMTP id dx3mr7003456wib.14.1349812157102;\r
35         Tue, 09 Oct 2012 12:49:17 -0700 (PDT)\r
36 Received: from localhost (188-194-252-80-dynip.superkabel.de.\r
37  [188.194.252.80])      by mx.google.com with ESMTPS id\r
38  dm3sm29786895wib.3.2012.10.09.12.49.15 (version=TLSv1/SSLv3 cipher=OTHER);\r
39         Tue, 09 Oct 2012 12:49:15 -0700 (PDT)\r
40 From: Stefan Hajnoczi <stefanha@gmail.com>\r
41 To: notmuch@notmuchmail.org\r
42 Subject: [PATCH] notmuch-mutt: add --whole-thread flag\r
43 Date: Tue,  9 Oct 2012 21:48:26 +0200\r
44 Message-Id: <1349812106-26916-1-git-send-email-stefanha@gmail.com>\r
45 X-Mailer: git-send-email 1.7.11.4\r
46 X-Mailman-Approved-At: Tue, 09 Oct 2012 22:15:03 -0700\r
47 Cc: Stefan Hajnoczi <stefanha@gmail.com>, Stefano Zacchiroli <zack@upsilon.cc>\r
48 X-BeenThere: notmuch@notmuchmail.org\r
49 X-Mailman-Version: 2.1.13\r
50 Precedence: list\r
51 List-Id: "Use and development of the notmuch mail system."\r
52         <notmuch.notmuchmail.org>\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
56 List-Post: <mailto:notmuch@notmuchmail.org>\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
60 X-List-Received-Date: Tue, 09 Oct 2012 19:49:20 -0000\r
61 \r
62 It can be useful to manipulate tags on an entire thread instead of just\r
63 a single message.  For example:\r
64 \r
65   # Mark entire thread unread\r
66   notmuch-mutt tag --whole-thread -- -unread < MAIL\r
67 \r
68 Add the --whole-thread flag which first looks up the thread for a given\r
69 message and then applies the tag action on the entire thread.\r
70 \r
71 Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>\r
72 ---\r
73 Warning: I don't really know Perl :)\r
74 \r
75 It would be nice if notmuch's query syntax could match threads.  Then\r
76 core notmuch CLI could perform this operation in a single command:\r
77 \r
78   # Mark entire thread unread given a single Message-ID\r
79   notmuch tag thread-contains(id:1234@foo.com) -- -unread\r
80 \r
81 Since the core cannot do this query today this patch bolts it on top for\r
82 "notmuch-mutt tag".\r
83 \r
84  contrib/notmuch-mutt/notmuch-mutt | 38 +++++++++++++++++++++++++++-----------\r
85  1 file changed, 27 insertions(+), 11 deletions(-)\r
86 \r
87 diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmuch-mutt\r
88 index d14709d..8529940 100755\r
89 --- a/contrib/notmuch-mutt/notmuch-mutt\r
90 +++ b/contrib/notmuch-mutt/notmuch-mutt\r
91 @@ -125,6 +125,14 @@ sub get_message_id() {\r
92      return $1;\r
93  }\r
94  \r
95 +sub get_thread_id($) {\r
96 +    my ($mid) = @_;\r
97 +    my $search_cmd = 'notmuch search --output=threads '\r
98 +                    . shell_quote("id:$mid");\r
99 +    `$search_cmd` =~ /^thread:(.*)$/;\r
100 +    return $1;\r
101 +}\r
102 +\r
103  sub search_action($$$@) {\r
104      my ($interactive, $results_dir, $remove_dups, @params) = @_;\r
105  \r
106 @@ -141,20 +149,26 @@ sub search_action($$$@) {\r
107  sub thread_action($$@) {\r
108      my ($results_dir, $remove_dups, @params) = @_;\r
109  \r
110 -    my $mid = get_message_id();\r
111 -    my $search_cmd = 'notmuch search --output=threads ' . shell_quote("id:$mid");\r
112 -    my $tid = `$search_cmd`;   # get thread id\r
113 -    chomp($tid);\r
114 +    my $tid = get_thread_id(get_message_id());\r
115  \r
116 -    search($results_dir, $remove_dups, $tid);\r
117 +    search($results_dir, $remove_dups, "thread:$tid");\r
118  }\r
119  \r
120 -sub tag_action(@) {\r
121 +sub tag_action($@) {\r
122 +    my ($whole_thread, @params) = @_;\r
123      my $mid = get_message_id();\r
124  \r
125 -    system("notmuch tag "\r
126 -          . shell_quote(join(' ', @_))\r
127 -          . " id:$mid");\r
128 +    if ($whole_thread) {\r
129 +       my $tid = get_thread_id($mid);\r
130 +\r
131 +       system("notmuch tag "\r
132 +               . shell_quote(join(' ', @params))\r
133 +               . " thread:$tid");\r
134 +    } else {\r
135 +       system("notmuch tag "\r
136 +               . shell_quote(join(' ', @params))\r
137 +               . " id:$mid");\r
138 +    }\r
139  }\r
140  \r
141  sub die_usage() {\r
142 @@ -170,12 +184,14 @@ sub main() {\r
143      my $interactive = 0;\r
144      my $help_needed = 0;\r
145      my $remove_dups = 0;\r
146 +    my $whole_thread = 0;\r
147  \r
148      my $getopt = GetOptions(\r
149         "h|help" => \$help_needed,\r
150         "o|output-dir=s" => \$results_dir,\r
151         "p|prompt" => \$interactive,\r
152 -       "r|remove-dups" => \$remove_dups);\r
153 +       "r|remove-dups" => \$remove_dups,\r
154 +       "w|whole-thread" => \$whole_thread);\r
155      if (! $getopt || $#ARGV < 0) { die_usage() };\r
156      my ($action, @params) = ($ARGV[0], @ARGV[1..$#ARGV]);\r
157  \r
158 @@ -193,7 +209,7 @@ sub main() {\r
159      } elsif ($action eq "thread") {\r
160         thread_action($results_dir, $remove_dups, @params);\r
161      } elsif ($action eq "tag") {\r
162 -       tag_action(@params);\r
163 +       tag_action($whole_thread, @params);\r
164      } else {\r
165         die_usage();\r
166      }\r
167 -- \r
168 1.7.11.4\r
169 \r