Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 67 / fe92092f0a4274aa6d7e5db8b3a51c59023f31
1 Return-Path: <dkg@fifthhorseman.net>\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 arlo.cworth.org (Postfix) with ESMTP id 8CF656DE0352\r
6  for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 18:02:54 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.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 arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id sDTmN_8vcF_I for <notmuch@notmuchmail.org>;\r
16  Fri,  8 Apr 2016 18:02:46 -0700 (PDT)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
18  by arlo.cworth.org (Postfix) with ESMTP id C5C906DE02C6\r
19  for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 18:02:38 -0700 (PDT)\r
20 Received: from fifthhorseman.net (unknown [201.140.212.132])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id AE52510085\r
22  for <notmuch@notmuchmail.org>; Fri,  8 Apr 2016 21:02:36 -0400 (EDT)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id 06C0A200A9; Fri,  8 Apr 2016 22:02:35 -0300 (ART)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v3 5/7] Introduce _notmuch_message_has_term()\r
28 Date: Fri,  8 Apr 2016 22:02:32 -0300\r
29 Message-Id: <1460163754-22994-5-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.8.0.rc3\r
31 In-Reply-To: <1460163754-22994-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1459445693-3900-1-git-send-email-dkg@fifthhorseman.net>\r
33  <1460163754-22994-1-git-send-email-dkg@fifthhorseman.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sat, 09 Apr 2016 01:02:54 -0000\r
47 \r
48 It can be useful to easily tell if a given message has a given term\r
49 associated with it.\r
50 ---\r
51  lib/message.cc        | 35 +++++++++++++++++++++++++++++++++++\r
52  lib/notmuch-private.h |  6 ++++++\r
53  2 files changed, 41 insertions(+)\r
54 \r
55 diff --git a/lib/message.cc b/lib/message.cc\r
56 index 435b78a..2399ab3 100644\r
57 --- a/lib/message.cc\r
58 +++ b/lib/message.cc\r
59 @@ -1217,6 +1217,41 @@ _notmuch_message_remove_term (notmuch_message_t *message,\r
60      return NOTMUCH_PRIVATE_STATUS_SUCCESS;\r
61  }\r
62  \r
63 +notmuch_private_status_t\r
64 +_notmuch_message_has_term (notmuch_message_t *message,\r
65 +                          const char *prefix_name,\r
66 +                          const char *value,\r
67 +                          notmuch_bool_t *result)\r
68 +{\r
69 +    char *term;\r
70 +    notmuch_bool_t out = FALSE;\r
71 +    notmuch_private_status_t status = NOTMUCH_PRIVATE_STATUS_SUCCESS;\r
72 +\r
73 +    if (value == NULL)\r
74 +       return NOTMUCH_PRIVATE_STATUS_NULL_POINTER;\r
75 +\r
76 +    term = talloc_asprintf (message, "%s%s",\r
77 +                           _find_prefix (prefix_name), value);\r
78 +\r
79 +    if (strlen (term) > NOTMUCH_TERM_MAX)\r
80 +       return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG;\r
81 +\r
82 +    try {\r
83 +       /* Look for the exact term */\r
84 +       Xapian::TermIterator i = message->doc.termlist_begin ();\r
85 +       i.skip_to (term);\r
86 +       if (i != message->doc.termlist_end () &&\r
87 +           !strcmp ((*i).c_str (), term))\r
88 +           out = TRUE;\r
89 +    } catch (Xapian::Error &error) {\r
90 +       status = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;\r
91 +    }\r
92 +    talloc_free (term);\r
93 +\r
94 +    *result = out;\r
95 +    return status;\r
96 +}\r
97 +\r
98  notmuch_status_t\r
99  notmuch_message_add_tag (notmuch_message_t *message, const char *tag)\r
100  {\r
101 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
102 index d95bf31..9280797 100644\r
103 --- a/lib/notmuch-private.h\r
104 +++ b/lib/notmuch-private.h\r
105 @@ -280,6 +280,12 @@ _notmuch_message_remove_term (notmuch_message_t *message,\r
106                               const char *value);\r
107  \r
108  notmuch_private_status_t\r
109 +_notmuch_message_has_term (notmuch_message_t *message,\r
110 +                          const char *prefix_name,\r
111 +                          const char *value,\r
112 +                          notmuch_bool_t *result);\r
113 +\r
114 +notmuch_private_status_t\r
115  _notmuch_message_gen_terms (notmuch_message_t *message,\r
116                             const char *prefix_name,\r
117                             const char *text);\r
118 -- \r
119 2.8.0.rc3\r
120 \r