Re: Emacs: Crypto: How to get automatic encryption?
[notmuch-archives.git] / ea / a8502c6a3ede481e08b4b6b39812a5358b6574
1 Return-Path: <Sebastian@SSpaeth.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 A2FF4431FBC\r
6         for <notmuch@notmuchmail.org>; Fri, 22 Jan 2010 07:26:21 -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.432\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.432 tagged_above=-999 required=5 tests=[AWL=0.431, \r
12         BAYES_50=0.001] autolearn=ham\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 DtnvFv47Uvmj for <notmuch@notmuchmail.org>;\r
16         Fri, 22 Jan 2010 07:26:20 -0800 (PST)\r
17 Received: from homiemail-a19.g.dreamhost.com (caiajhbdcaid.dreamhost.com\r
18         [208.97.132.83])\r
19         by olra.theworths.org (Postfix) with ESMTP id CB17C431FAE\r
20         for <notmuch@notmuchmail.org>; Fri, 22 Jan 2010 07:26:20 -0800 (PST)\r
21 Received: from localhost.localdomain (unknown [84.55.198.58])\r
22         by homiemail-a19.g.dreamhost.com (Postfix) with ESMTPA id 696CC604014; \r
23         Fri, 22 Jan 2010 07:26:18 -0800 (PST)\r
24 From: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
25 To: notmuch@notmuchmail.org\r
26 Date: Fri, 22 Jan 2010 16:26:11 +0100\r
27 Message-Id: <1264173971-11879-1-git-send-email-Sebastian@SSpaeth.de>\r
28 X-Mailer: git-send-email 1.6.3.3\r
29 Subject: [notmuch] [PATCH] Make the date parser nicer\r
30 X-BeenThere: notmuch@notmuchmail.org\r
31 X-Mailman-Version: 2.1.13\r
32 Precedence: list\r
33 List-Id: "Use and development of the notmuch mail system."\r
34         <notmuch.notmuchmail.org>\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
36         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
38 List-Post: <mailto:notmuch@notmuchmail.org>\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
42 X-List-Received-Date: Fri, 22 Jan 2010 15:26:21 -0000\r
43 \r
44 Currently we have to enter mail dates as timestamps. This approach does 2 things: it requires the prefix 'date:' and it allows timestamps to be specified as YYYY, YYYYMM or YYYYMMDD. So a notmuch show date:2005..20060512 will find all mails from 2005-01-01 until 2006-05-12. The code is probably not in a proper location yet and needs to be shoved around by someone more knowledgable than me. My C++ skills are somewhat,... lacking...\r
45 \r
46 Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
47 ---\r
48  lib/database.cc |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-\r
49  1 files changed, 93 insertions(+), 1 deletions(-)\r
50 \r
51 diff --git a/lib/database.cc b/lib/database.cc\r
52 index 5b12320..102a6ff 100644\r
53 --- a/lib/database.cc\r
54 +++ b/lib/database.cc\r
55 @@ -494,6 +494,97 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
56      return NOTMUCH_STATUS_SUCCESS;\r
57  }\r
58  \r
59 +struct MaildateValueRangeProcessor : public Xapian::ValueRangeProcessor {\r
60 +    MaildateValueRangeProcessor() {}\r
61 +\r
62 +    Xapian::valueno operator()(std::string &begin, std::string &end) {\r
63 +        if (begin.substr(0, 5) != "date:")\r
64 +            return Xapian::BAD_VALUENO;\r
65 +        begin.erase(0, 5);\r
66 +\r
67 +       // Parse the begin date to time_t\r
68 +       struct tm *timeinfo;\r
69 +       time_t begintime, endtime;\r
70 +       //const char * startptr;\r
71 +       int year, month, day;\r
72 +\r
73 +       if (begin.size() == 8) {\r
74 +         int no_items;\r
75 +         no_items = sscanf(begin.c_str(), "%4i%2i%2i", &year, &month, &day);\r
76 +         if (no_items != 3)\r
77 +           return Xapian::BAD_VALUENO;\r
78 +       } else if (begin.size() == 6) {\r
79 +         int no_items;\r
80 +         day = 1;\r
81 +         no_items = sscanf(begin.c_str(), "%4i%2i", &year, &month);\r
82 +         if (no_items != 2)\r
83 +           return Xapian::BAD_VALUENO;\r
84 +       } else if (begin.size() == 4) {\r
85 +         int no_items;\r
86 +         day = 1;\r
87 +         month = 1;\r
88 +         no_items = sscanf(begin.c_str(), "%4i", &year);\r
89 +         if (no_items != 1)\r
90 +           return Xapian::BAD_VALUENO;\r
91 +       } else {\r
92 +         // no expected time format\r
93 +         return Xapian::BAD_VALUENO;\r
94 +       }\r
95 +\r
96 +       begintime = time(NULL);\r
97 +       timeinfo = localtime( &begintime );\r
98 +       timeinfo -> tm_year = year - 1900;\r
99 +       timeinfo -> tm_mon = month - 1;\r
100 +       fprintf (stderr, "Startdate %d %d %d\n",year,month,day);\r
101 +       timeinfo -> tm_mday = day;\r
102 +       begintime = mktime ( timeinfo );\r
103 +\r
104 +       if (begintime == -1)\r
105 +         // no valid time format\r
106 +         return Xapian::BAD_VALUENO;\r
107 +\r
108 +       if (end.size() == 8) {\r
109 +         int no_items;\r
110 +         no_items = sscanf(end.c_str(), "%4i%2i%2i", &year, &month, &day);\r
111 +         if (no_items != 3)\r
112 +           return Xapian::BAD_VALUENO;\r
113 +       } else if (end.size() == 6) {\r
114 +         int no_items;\r
115 +         day = 31;\r
116 +         no_items = sscanf(end.c_str(), "%4i%2i", &year, &month);\r
117 +         if (no_items != 2)\r
118 +           return Xapian::BAD_VALUENO;\r
119 +       } else if (end.size() == 4) {\r
120 +         int no_items;\r
121 +         day = 31;\r
122 +         month = 12;\r
123 +         no_items = sscanf(end.c_str(), "%4i", &year);\r
124 +         if (no_items != 1)\r
125 +           return Xapian::BAD_VALUENO;\r
126 +       } else {\r
127 +         // no expected time format\r
128 +         return Xapian::BAD_VALUENO;\r
129 +       }\r
130 +\r
131 +       timeinfo = localtime( &begintime );\r
132 +       timeinfo -> tm_year = year - 1900;\r
133 +       timeinfo -> tm_mon = month - 1;\r
134 +       fprintf (stderr, "Enddate %d %d %d\n",year,month,day);\r
135 +       timeinfo -> tm_mday = day;\r
136 +       endtime = mktime ( timeinfo );\r
137 +       //XXX: plus 1 day to make the last day inclusive??\r
138 +\r
139 +       if (endtime == -1)\r
140 +         // no valid time format\r
141 +         return Xapian::BAD_VALUENO;\r
142 +       \r
143 +       begin.assign(Xapian::sortable_serialise(begintime));\r
144 +       end.assign(Xapian::sortable_serialise(endtime));\r
145 +\r
146 +        return NOTMUCH_VALUE_TIMESTAMP;\r
147 +    }\r
148 +};\r
149 +\r
150  notmuch_database_t *\r
151  notmuch_database_open (const char *path,\r
152                        notmuch_database_mode_t mode)\r
153 @@ -570,7 +661,8 @@ notmuch_database_open (const char *path,\r
154         notmuch->query_parser = new Xapian::QueryParser;\r
155         notmuch->term_gen = new Xapian::TermGenerator;\r
156         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
157 -       notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP, "date:", true);\r
158 +       notmuch->value_range_processor = new MaildateValueRangeProcessor();\r
159 +         // (NOTMUCH_VALUE_TIMESTAMP);\r
160  \r
161         notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
162         notmuch->query_parser->set_database (*notmuch->xapian_db);\r
163 -- \r
164 1.6.3.3\r
165 \r