[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / af / 3fa117f420b366807167e4acb844d7f2ccd95c
1 Return-Path: <jrollins@finestructure.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 olra.theworths.org (Postfix) with ESMTP id AAAD5431FB6\r
6         for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:54 -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: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 0aV0+jFu-QwN for <notmuch@notmuchmail.org>;\r
16         Wed, 23 May 2012 15:40:53 -0700 (PDT)\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
18         [131.215.239.19])\r
19         by olra.theworths.org (Postfix) with ESMTP id 77223431FC2\r
20         for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:50 -0700 (PDT)\r
21 Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
22         by fire-doxen-postvirus (Postfix) with ESMTP id 9C0ED32807F\r
23         for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:49 -0700 (PDT)\r
24 X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
25 Received: from finestructure.net (unknown [137.151.175.56])\r
26         (Authenticated sender: jrollins)\r
27         by fire-doxen-submit (Postfix) with ESMTP id 4CD91328080\r
28         for <notmuch@notmuchmail.org>; Wed, 23 May 2012 15:40:46 -0700 (PDT)\r
29 Received: by finestructure.net (Postfix, from userid 1000)\r
30         id F2C471E7; Wed, 23 May 2012 15:40:45 -0700 (PDT)\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>\r
33 Subject: [PATCH v4 2/7] cli: new crypto structure to store crypto contexts and parameters, and functions to support it\r
34 Date: Wed, 23 May 2012 15:40:38 -0700\r
35 Message-Id: <1337812843-14986-3-git-send-email-jrollins@finestructure.net>\r
36 X-Mailer: git-send-email 1.7.10\r
37 In-Reply-To: <1337812843-14986-2-git-send-email-jrollins@finestructure.net>\r
38 References: <1337812843-14986-1-git-send-email-jrollins@finestructure.net>\r
39         <1337812843-14986-2-git-send-email-jrollins@finestructure.net>\r
40 MIME-Version: 1.0\r
41 Content-Type: text/plain; charset=UTF-8\r
42 Content-Transfer-Encoding: 8bit\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Wed, 23 May 2012 22:40:55 -0000\r
56 \r
57 This new structure, notmuch_crypto_t, keeps all relevant crypto\r
58 contexts and parameters together, and will make it easier to pass the\r
59 stuff around and clean it up.  The name of the crypto context inside\r
60 this new struct will change, to reflect that it is actually a GPG\r
61 context, which is a sub type of Crypto context.  There are other types\r
62 of Crypto contexts (Pkcs7 in particular, which we hope to support) so\r
63 we want to be clear.\r
64 \r
65 The new crypto.c contains functions to return the proper context from\r
66 the struct for a given protocol (and initialize it if needed), and to\r
67 cleanup a struct by releasing the crypto contexts.\r
68 ---\r
69  Makefile.local   |    1 +\r
70  crypto.c         |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
71  notmuch-client.h |   11 +++++++++\r
72  3 files changed, 83 insertions(+)\r
73  create mode 100644 crypto.c\r
74 \r
75 diff --git a/Makefile.local b/Makefile.local\r
76 index 53b4a0d..a890df2 100644\r
77 --- a/Makefile.local\r
78 +++ b/Makefile.local\r
79 @@ -292,6 +292,7 @@ notmuch_client_srcs =               \\r
80         notmuch-time.c          \\r
81         query-string.c          \\r
82         mime-node.c             \\r
83 +       crypto.c                \\r
84         json.c\r
85  \r
86  notmuch_client_modules = $(notmuch_client_srcs:.c=.o)\r
87 diff --git a/crypto.c b/crypto.c\r
88 new file mode 100644\r
89 index 0000000..25c2d10\r
90 --- /dev/null\r
91 +++ b/crypto.c\r
92 @@ -0,0 +1,71 @@\r
93 +/* notmuch - Not much of an email program, (just index and search)\r
94 + *\r
95 + * Copyright © 2012 Jameson Rollins\r
96 + *\r
97 + * This program is free software: you can redistribute it and/or modify\r
98 + * it under the terms of the GNU General Public License as published by\r
99 + * the Free Software Foundation, either version 3 of the License, or\r
100 + * (at your option) any later version.\r
101 + *\r
102 + * This program is distributed in the hope that it will be useful,\r
103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
105 + * GNU General Public License for more details.\r
106 + *\r
107 + * You should have received a copy of the GNU General Public License\r
108 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
109 + *\r
110 + * Authors: Jameson Rollins <jrollins@finestructure.net>\r
111 + */\r
112 +\r
113 +#include "notmuch-client.h"\r
114 +\r
115 +/* for the specified protocol return the context pointer (initializing\r
116 + * if needed) */\r
117 +GMimeCryptoContext *\r
118 +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
119 +{\r
120 +    GMimeCryptoContext *cryptoctx = NULL;\r
121 +\r
122 +    /* As per RFC 1847 section 2.1: "the [protocol] value token is\r
123 +     * comprised of the type and sub-type tokens of the Content-Type".\r
124 +     * As per RFC 1521 section 2: "Content-Type values, subtypes, and\r
125 +     * parameter names as defined in this document are\r
126 +     * case-insensitive."  Thus, we use strcasecmp for the protocol.\r
127 +     */\r
128 +    if ((strcasecmp (protocol, "application/pgp-signature") == 0)\r
129 +       || (strcasecmp (protocol, "application/pgp-encrypted") == 0)) {\r
130 +       if (!crypto->gpgctx) {\r
131 +#ifdef GMIME_ATLEAST_26\r
132 +           /* TODO: GMimePasswordRequestFunc */\r
133 +           crypto->gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
134 +#else\r
135 +           GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
136 +           crypto->gpgctx = g_mime_gpg_context_new (session, "gpg");\r
137 +           g_object_unref (session);\r
138 +#endif\r
139 +           if (crypto->gpgctx) {\r
140 +               g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);\r
141 +           } else {\r
142 +               fprintf (stderr, "Failed to construct gpg context.\n");\r
143 +           }\r
144 +       }\r
145 +       cryptoctx = crypto->gpgctx;\r
146 +\r
147 +    } else {\r
148 +       fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
149 +    }\r
150 +\r
151 +    return cryptoctx;\r
152 +}\r
153 +\r
154 +int\r
155 +notmuch_crypto_cleanup (notmuch_crypto_t *crypto)\r
156 +{\r
157 +    if (crypto->gpgctx) {\r
158 +       g_object_unref(crypto->gpgctx);\r
159 +       crypto->gpgctx = NULL;\r
160 +    }\r
161 +\r
162 +    return 0;\r
163 +}\r
164 diff --git a/notmuch-client.h b/notmuch-client.h\r
165 index 337409f..a8b00ab 100644\r
166 --- a/notmuch-client.h\r
167 +++ b/notmuch-client.h\r
168 @@ -76,6 +76,11 @@ typedef struct notmuch_show_format {\r
169      const char *message_set_end;\r
170  } notmuch_show_format_t;\r
171  \r
172 +typedef struct notmuch_crypto {\r
173 +    GMimeCryptoContext* gpgctx;\r
174 +    notmuch_bool_t decrypt;\r
175 +} notmuch_crypto_t;\r
176 +\r
177  typedef struct notmuch_show_params {\r
178      notmuch_bool_t entire_thread;\r
179      notmuch_bool_t omit_excluded;\r
180 @@ -111,6 +116,12 @@ chomp_newline (char *str)\r
181         str[strlen(str)-1] = '\0';\r
182  }\r
183  \r
184 +GMimeCryptoContext *\r
185 +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);\r
186 +\r
187 +int\r
188 +notmuch_crypto_cleanup (notmuch_crypto_t *crypto);\r
189 +\r
190  int\r
191  notmuch_count_command (void *ctx, int argc, char *argv[]);\r
192  \r
193 -- \r
194 1.7.10\r
195 \r