"snoozing" with notmuch?
[notmuch-archives.git] / 84 / 6ab5fdff54a17911ad25d46a27d2fda5f004cf
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 897B06DE1902\r
6  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:07 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.036\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.036 tagged_above=-999 required=5\r
12  tests=[AWL=-0.036] 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 hYFM1wP90l94 for <notmuch@notmuchmail.org>;\r
16  Wed,  9 Dec 2015 19:40:05 -0800 (PST)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
18  by arlo.cworth.org (Postfix) with ESMTP id DC33B6DE0FF1\r
19  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:04 -0800 (PST)\r
20 Received: from fifthhorseman.net (unknown [38.109.115.130])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id EA284F984\r
22  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 22:40:03 -0500 (EST)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id A7A5220C13; Wed,  9 Dec 2015 22:40:03 -0500 (EST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH 2/9] Add a lazily-initialized crypto context to\r
28  notmuch_database_t\r
29 Date: Wed,  9 Dec 2015 22:39:39 -0500\r
30 Message-Id: <1449718786-28000-3-git-send-email-dkg@fifthhorseman.net>\r
31 X-Mailer: git-send-email 2.6.2\r
32 In-Reply-To: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net>\r
33 References: <1449718786-28000-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: Thu, 10 Dec 2015 03:40:08 -0000\r
47 \r
48 This is in large part a duplicate of parts of crypto.c, but that code\r
49 is in the client (outside the library), and we don't want to entangle\r
50 the libgmime API with the libnotmuch API.\r
51 \r
52 I welcome better proposals for how to share this code explicitly\r
53 between the library and the client.\r
54 ---\r
55  lib/database-private.h |  1 +\r
56  lib/database.cc        | 42 ++++++++++++++++++++++++++++++++++++++++++\r
57  lib/notmuch-private.h  |  8 ++++++++\r
58  3 files changed, 51 insertions(+)\r
59 \r
60 diff --git a/lib/database-private.h b/lib/database-private.h\r
61 index 3fb10f7..1bf76c5 100644\r
62 --- a/lib/database-private.h\r
63 +++ b/lib/database-private.h\r
64 @@ -171,6 +171,7 @@ struct _notmuch_database {\r
65       * notmuch_database_new_revision. */\r
66      unsigned long revision;\r
67      const char *uuid;\r
68 +    GMimeCryptoContext *gpg_crypto_ctx;\r
69  \r
70      Xapian::QueryParser *query_parser;\r
71      Xapian::TermGenerator *term_gen;\r
72 diff --git a/lib/database.cc b/lib/database.cc\r
73 index 3b342f1..13b0bad 100644\r
74 --- a/lib/database.cc\r
75 +++ b/lib/database.cc\r
76 @@ -995,6 +995,8 @@ notmuch_database_open_verbose (const char *path,\r
77         notmuch->uuid = talloc_strdup (\r
78             notmuch, notmuch->xapian_db->get_uuid ().c_str ());\r
79  \r
80 +       notmuch->gpg_crypto_ctx = NULL;\r
81 +       \r
82         notmuch->query_parser = new Xapian::QueryParser;\r
83         notmuch->term_gen = new Xapian::TermGenerator;\r
84         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
85 @@ -1090,6 +1092,11 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
86      delete notmuch->last_mod_range_processor;\r
87      notmuch->last_mod_range_processor = NULL;\r
88  \r
89 +    if (notmuch->gpg_crypto_ctx) {\r
90 +       g_object_unref (notmuch->gpg_crypto_ctx);\r
91 +       notmuch->gpg_crypto_ctx = NULL;\r
92 +    }\r
93 +    \r
94      return status;\r
95  }\r
96  \r
97 @@ -2386,6 +2393,41 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,\r
98      return status;\r
99  }\r
100  \r
101 +notmuch_private_status_t\r
102 +_notmuch_database_get_crypto_for_protocol (notmuch_database_t *notmuch,\r
103 +                                          const char *protocol,\r
104 +                                          GMimeCryptoContext **crypto_ctx)\r
105 +{\r
106 +    if (! protocol)\r
107 +       return NOTMUCH_PRIVATE_STATUS_MALFORMED_CRYPTO_PROTOCOL;\r
108 +    \r
109 +    /* As per RFC 1847 section 2.1: "the [protocol] value token is\r
110 +     * comprised of the type and sub-type tokens of the Content-Type".\r
111 +     * As per RFC 1521 section 2: "Content-Type values, subtypes, and\r
112 +     * parameter names as defined in this document are\r
113 +     * case-insensitive."  Thus, we use strcasecmp for the protocol.\r
114 +     */\r
115 +    if (strcasecmp (protocol, "application/pgp-signature") == 0 ||\r
116 +       strcasecmp (protocol, "application/pgp-encrypted") == 0) {\r
117 +       if (! notmuch->gpg_crypto_ctx) {\r
118 +           /* FIXME: how do we allow for configuring the gpg binary\r
119 +            * here? how would this config get into the library?  Is\r
120 +            * this an option we can set on the database object?  Or\r
121 +            * elsewhere?  */\r
122 +           notmuch->gpg_crypto_ctx = g_mime_gpg_context_new (NULL, "gpg");\r
123 +           if (! notmuch->gpg_crypto_ctx)\r
124 +               return NOTMUCH_PRIVATE_STATUS_FAILED_CRYPTO_CONTEXT_CREATION;\r
125 +\r
126 +           g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) notmuch->gpg_crypto_ctx, TRUE);\r
127 +           g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) notmuch->gpg_crypto_ctx, FALSE);\r
128 +       }\r
129 +       *crypto_ctx = notmuch->gpg_crypto_ctx;\r
130 +       return NOTMUCH_PRIVATE_STATUS_SUCCESS;\r
131 +    } else {\r
132 +       return NOTMUCH_PRIVATE_STATUS_UNKNOWN_CRYPTO_PROTOCOL;\r
133 +    }\r
134 +}\r
135 +\r
136  notmuch_status_t\r
137  notmuch_database_add_message (notmuch_database_t *notmuch,\r
138                               const char *filename,\r
139 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
140 index 5dd4770..f6fd36a 100644\r
141 --- a/lib/notmuch-private.h\r
142 +++ b/lib/notmuch-private.h\r
143 @@ -141,6 +141,9 @@ typedef enum _notmuch_private_status {\r
144      /* Then add our own private values. */\r
145      NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG = NOTMUCH_STATUS_LAST_STATUS,\r
146      NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND,\r
147 +    NOTMUCH_PRIVATE_STATUS_MALFORMED_CRYPTO_PROTOCOL,\r
148 +    NOTMUCH_PRIVATE_STATUS_FAILED_CRYPTO_CONTEXT_CREATION,\r
149 +    NOTMUCH_PRIVATE_STATUS_UNKNOWN_CRYPTO_PROTOCOL,\r
150  \r
151      NOTMUCH_PRIVATE_STATUS_LAST_STATUS\r
152  } notmuch_private_status_t;\r
153 @@ -239,6 +242,11 @@ _notmuch_database_filename_to_direntry (void *ctx,\r
154                                         notmuch_find_flags_t flags,\r
155                                         char **direntry);\r
156  \r
157 +notmuch_private_status_t\r
158 +_notmuch_database_get_crypto_for_protocol (notmuch_database_t *notmuch,\r
159 +                                          const char *protocol,\r
160 +                                          GMimeCryptoContext **crypto_ctx);\r
161 +\r
162  /* directory.cc */\r
163  \r
164  notmuch_directory_t *\r
165 -- \r
166 2.6.2\r
167 \r