Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / e7 / 1a0e21cc908ba219d80ef4cd9d4a384e9832a8
1 Return-Path: <mir@spieleck.de>\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 62699431FB6\r
6         for <notmuch@notmuchmail.org>; Sat, 16 Apr 2011 15:44:15 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id sIE0dYLLuWHK for <notmuch@notmuchmail.org>;\r
16         Sat, 16 Apr 2011 15:44:11 -0700 (PDT)\r
17 Received: from spieleck.de (mx.spieleck.de [213.95.6.62])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 4925F431FB5\r
21         for <notmuch@notmuchmail.org>; Sat, 16 Apr 2011 15:44:11 -0700 (PDT)\r
22 Received: from turtur.spieleck.de (unknown [212.114.251.147])\r
23         by spieleck.de (spieleck.de Postfix) with ESMTP id E486AD80AF;\r
24         Sun, 17 Apr 2011 00:44:06 +0200 (CEST)\r
25 Received: by turtur.spieleck.de (Postfix, from userid 1000)\r
26         id 1395D378F; Sun, 17 Apr 2011 00:44:06 +0200 (CEST)\r
27 From: Michael Radziej <mir@spieleck.de>\r
28 To: Florian Friesdorf <flo@chaoflow.net>, notmuch@notmuchmail.org\r
29 Subject: Re: (auto-)tagging sent messages\r
30 In-Reply-To: <8739ll8dkv.fsf@eve.chaoflow.net>\r
31 References: <8739ll8dkv.fsf@eve.chaoflow.net>\r
32 User-Agent: Notmuch/0.5-63-g62725a5 (http://notmuchmail.org) Emacs/23.3.1\r
33         (x86_64-unknown-linux-gnu)\r
34 Date: Sun, 17 Apr 2011 00:44:06 +0200\r
35 Message-ID: <87mxjphl55.fsf@spieleck.de>\r
36 MIME-Version: 1.0\r
37 Content-Type: multipart/mixed; boundary="=-=-="\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sat, 16 Apr 2011 22:44:16 -0000\r
51 \r
52 --=-=-=\r
53 \r
54 Hi Florian!\r
55 \r
56 On Thu, 14 Apr 2011 10:03:12 +0200, Florian Friesdorf <flo@chaoflow.net> wrote:\r
57 > Further, for certain mails I sent (like this one ) I would like a\r
58 > WAITING tag (or similar) in order to indicate that I am waiting for an\r
59 > answer. Currently I set this manually. Could this be achieved through\r
60 > some indicators via message mode or similar means? e.g.:\r
61 \r
62 I use a X-Wait header (like X-Wait: 2, meaning to wait for 2 days). If\r
63 there is no activity in the thread within time, it receives additional tags\r
64 "late" and "inbox". If an answer to a waiting mail arrives, it receives a tag "expected".\r
65 \r
66 Here's some python code that does the tagging (I haven't tested it):\r
67 \r
68 \r
69 --=-=-=\r
70 Content-Type: text/x-python\r
71 Content-Disposition: inline; filename=tagging-wait.py\r
72 Content-Description: python code\r
73 \r
74 import notmuch, re, time\r
75 \r
76 MY_ADDR = 'my email address'\r
77 \r
78 db =  notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)\r
79 \r
80 def query(qstring):\r
81     return db.create_query(qstring).search_messages()\r
82 \r
83 def query_threads(qstring):\r
84     return db.create_query(qstring).search_threads()\r
85 \r
86 def timeout(msg):\r
87     try:\r
88         wait_days = msg.get_header('X-Wait')\r
89         if wait_days:\r
90             wait_days = int(wait_days)\r
91             return time.time() > msg.get_date() + 24 * 60 * 60 * int(wait_days)\r
92     except ValueError:\r
93         return False\r
94 \r
95 def run():\r
96     new_thread_ids = set(t.get_thread_id() for t in query_threads('tag:new'))\r
97     new_thread_clause = '(%s)' % " or ".join("thread:%s" % t for t in new_thread_ids)\r
98 \r
99     # checking all "wait" and "late" threads\r
100     for msg in query('tag:wait'):\r
101         thread_id = msg.get_thread_id()\r
102         if thread_id in new_thread_ids:\r
103             msg.remove_tag('wait')\r
104             msg.remove_tag('late')\r
105             for new_msg in query('thread:%s and tag:new' % thread_id):\r
106                 new_msg.add_tag('expected')\r
107         else:\r
108             if 'late' not in msg.get_tags() and timeout(msg):\r
109                 msg.add_tag('late')\r
110                 msg.add_tag('inbox')\r
111                 msg.remove_tag('wait')\r
112 \r
113     # handle sent messages\r
114     for msg in query('tag:new and (tag:sent or from:%s)' % MY_ADDR):\r
115         msg.add_tag('sent')\r
116         if msg.get_header('X-Wait'):\r
117             msg.add_tag('wait')\r
118 \r
119 --=-=-=\r
120 \r
121 \r
122 \r
123 Kind regards\r
124 \r
125 Michael Radziej\r
126 \r
127 --=-=-=--\r