Re: [PATCH 1/2] cli: abstract common config get/set code
[notmuch-archives.git] / 1c / 80e539eea2272a14c298156407f05411f72f98
1 Return-Path: <bgamari.foss@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 1EA24429E20\r
6         for <notmuch@notmuchmail.org>; Fri, 11 Mar 2011 06:56:41 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.099\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.099 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_NONE=-0.0001] 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 XjaoytiQKOfj for <notmuch@notmuchmail.org>;\r
17         Fri, 11 Mar 2011 06:56:40 -0800 (PST)\r
18 Received: from mail-vx0-f181.google.com (mail-vx0-f181.google.com\r
19         [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 28C4A431FB5\r
22         for <notmuch@notmuchmail.org>; Fri, 11 Mar 2011 06:56:40 -0800 (PST)\r
23 Received: by vxb39 with SMTP id 39so2701671vxb.26\r
24         for <notmuch@notmuchmail.org>; Fri, 11 Mar 2011 06:56:37 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=domainkey-signature:from:to:subject:in-reply-to:references\r
27         :user-agent:date:message-id:mime-version:content-type;\r
28         bh=TOViimB8BR70eTnd4hpGJ6B1knXVdPry07KKg7s/Svw=;\r
29         b=Ml3zjbo+kwKh6pOAuLy92VCIRZWECdVsnBatEar5X2b9JTaCp9T0MyrHwrAR+QE9sg\r
30         FLUMmDtdzDRf6cM6BrKUE0iUrnMRl1NF+y/1RTw2b5/13ytBe1IDZ5XfptUwKqohD+nc\r
31         ZmTQtxRqySI0v8gRHlKJ8ALjGd5Z3GwmIFFzc=\r
32 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
33         h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
34         :mime-version:content-type;\r
35         b=gbLQ3445oTFu05SlqS6bX+fWX4qGT13y43K9AVk/+lU4Y4EP24GiCyqzt8GmbEtxuA\r
36         LHbJ0RC9mrsIiN+O9JjbHY59rP1Czcrd7Z5+BW4U3l2E1pAW4PkRpwvx7R+TGfvljzS3\r
37         Ik+WOUaJ2P5ZOJ+O4qRmquk8nhCamb2zxIOJY=\r
38 Received: by 10.52.175.104 with SMTP id bz8mr3218507vdc.143.1299855397843;\r
39         Fri, 11 Mar 2011 06:56:37 -0800 (PST)\r
40 Received: from localhost (pool-72-79-214-225.spfdma.east.verizon.net\r
41         [72.79.214.225])\r
42         by mx.google.com with ESMTPS id r20sm1572824vcf.34.2011.03.11.06.56.17\r
43         (version=TLSv1/SSLv3 cipher=OTHER);\r
44         Fri, 11 Mar 2011 06:56:34 -0800 (PST)\r
45 From: Ben Gamari <bgamari.foss@gmail.com>\r
46 To: Michal Sojka <sojkam1@fel.cvut.cz>, notmuch <notmuch@notmuchmail.org>\r
47 Subject: Re: My mail configuration\r
48 In-Reply-To: <87oc5o0w8a.fsf@resox.2x.cz>\r
49 References: <87tyfu3k5a.fsf@gmail.com> <87oc5o0w8a.fsf@resox.2x.cz>\r
50 User-Agent: Notmuch/0.5-64-gdd23272 (http://notmuchmail.org) Emacs/23.1.1\r
51         (x86_64-pc-linux-gnu)\r
52 Date: Fri, 11 Mar 2011 09:55:37 -0500\r
53 Message-ID: <877hc5yady.fsf@gmail.com>\r
54 MIME-Version: 1.0\r
55 Content-Type: text/plain; charset=us-ascii\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Fri, 11 Mar 2011 14:56:41 -0000\r
69 \r
70 On Sun, 06 Mar 2011 22:34:13 +0100, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
71 > Hi Ben,\r
72\r
73 > thanks for sharing your setup.\r
74\r
75 No worries.\r
76 \r
77 > It seems really interesting and probably\r
78 > useful for many people. I'd propose to put it to wiki at\r
79 > http://notmuchmail.org/initial_tagging/.\r
80\r
81 Done.\r
82 \r
83 > When compared to shell scripts for initial tagging, this seems to be\r
84 > much faster because of freezing all new messages and thawing them after\r
85 > all tagging is done.\r
86\r
87 Indeed, IMHO the python bindings are perfect for this sort of\r
88 application.\r
89 \r
90 > Also the handling of watch and unseen tag is interesting.\r
91\r
92 The watch tag is one of the defining points of my workflow. I deal with\r
93 a lot of lists although generally I'm interested in very few threads\r
94 from each. The watch tag makes it very easy to find and follow relevant\r
95 discussions.\r
96 \r
97 Just to make sure everyone understands what is happening here, the\r
98 workflow works as follows,\r
99 \r
100  1) When a message starting a new thread is encountered it is marked as\r
101     "unseen"\r
102 \r
103  2) I look at the "unseen" tag, marking threads of interest with "watch"\r
104 \r
105  3) When a message comes in associated with an existing thread marked\r
106     with "watch" it is marked with "inbox", otherwise it is ignored\r
107 \r
108 In other words, the "unseen" tag is an indicator of whether I have\r
109 evaluated the message for interest. I use the standard "unread" tag to\r
110 mark whether I have read the contents of the message.\r
111 \r
112 > The only thing I missed in your email is the definition of tag_search().\r
113 > You probably define it in notmuch_utils similarly to this:\r
114\r
115 Doh, thanks for pointing that out. Your tag_search implementation\r
116 matches mine almost verbatim. For the record I have included\r
117 notmuch_utils.py below.\r
118 \r
119 > Here I would suggest to add parentheses around %s like:\r
120\r
121 >      tag_search(db, '( %s ) and tag:new' % filter, *tags)\r
122\r
123 > I use the 'or' operator in a few of my filters and without the\r
124 > parentheses the query would be interpreted incorrectly.\r
125\r
126 Good point. Thanks!\r
127 \r
128 - Ben\r
129 \r
130 \r
131 --8<---------------cut here---------------start------------->8---\r
132 import notmuch\r
133 import logging\r
134 \r
135 def tag_message(msg, *tags):\r
136         msg.freeze()\r
137         for tag in tags:\r
138                 if tag[0] == '+':\r
139                         msg.add_tag(tag[1:])\r
140                 elif tag[0] == '-':\r
141                         msg.remove_tag(tag[1:])\r
142                 else:\r
143                         msg.add_tag(tag)\r
144         msg.thaw()\r
145 \r
146 def tag_search(db, search, *tags):\r
147         q = notmuch.Query(db, search)\r
148         count = 0\r
149         for msg in q.search_messages():\r
150                 count += 1\r
151                 tag_message(msg, *tags)\r
152 \r
153         if count > 0:\r
154                 logging.debug('Tagging %d messages with (%s)' % (count, ' '.join(tags)))\r
155 \r
156 --8<---------------cut here---------------end--------------->8---\r