Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 69 / 965dc749b22e510ebdd371eb5c6e87bc5f0353
1 Return-Path: <jani@nikula.org>\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 AC8E5431FD0\r
6         for <notmuch@notmuchmail.org>; Sat, 30 Mar 2013 06:53:31 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id Vl88RcfBsffd for <notmuch@notmuchmail.org>;\r
17         Sat, 30 Mar 2013 06:53:30 -0700 (PDT)\r
18 Received: from mail-la0-f51.google.com (mail-la0-f51.google.com\r
19         [209.85.215.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id C7B97431FCB\r
22         for <notmuch@notmuchmail.org>; Sat, 30 Mar 2013 06:53:25 -0700 (PDT)\r
23 Received: by mail-la0-f51.google.com with SMTP id fo13so1102591lab.24\r
24         for <notmuch@notmuchmail.org>; Sat, 30 Mar 2013 06:53:24 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
28         :references:in-reply-to:references:x-gm-message-state;\r
29         bh=SwrNsEqSmwXHzGNbU4XbN6z6+yPRyKFVMjubIs0Arhw=;\r
30         b=isfFVhxRgnhT9J2hys1r4yehLciJJmnv3+EeboACGMazxf/xsfD0m1mDvCySp8wpkH\r
31         jyrXzAnrczDr5Wjhxfya09MRCZ3BuGkZKwZBEmMlR8BZ7h92jL1Ngz7Ev5x9lXSXerdD\r
32         MFREfeOiGdB8QEsYhUKZrDgni4+sMnUzizzOCF8d8V0LkB6D3zAJUmQTkgYQ1qwhNUW6\r
33         TA/wPds9C32A3IajIp/1/H/ujmnfQMJ6rQRDasqBhYF0un58HpQLVxAHwo+3B8PbB6bO\r
34         MgWBNs7HbL1KTIq5ZkfxCcw8+hwQ1L8LuzzZLOQ56oRw/j2ZG5YWlkyZZaWhox2Ko+to\r
35         gdSg==\r
36 X-Received: by 10.112.3.198 with SMTP id e6mr2889294lbe.118.1364651602924;\r
37         Sat, 30 Mar 2013 06:53:22 -0700 (PDT)\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
39         [80.223.81.27])\r
40         by mx.google.com with ESMTPS id m2sm2639033lbz.7.2013.03.30.06.53.21\r
41         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
42         Sat, 30 Mar 2013 06:53:22 -0700 (PDT)\r
43 From: Jani Nikula <jani@nikula.org>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: [PATCH v2 1/3] cli: crypto: abstract gpg context creation for clarity\r
46 Date: Sat, 30 Mar 2013 15:53:15 +0200\r
47 Message-Id:\r
48  <2dab662da71c9f5740a21a2c148ecf9c855cc81e.1364651359.git.jani@nikula.org>\r
49 X-Mailer: git-send-email 1.7.10.4\r
50 In-Reply-To: <cover.1364651359.git.jani@nikula.org>\r
51 References: <cover.1364651359.git.jani@nikula.org>\r
52 In-Reply-To: <cover.1364651359.git.jani@nikula.org>\r
53 References: <cover.1364651359.git.jani@nikula.org>\r
54 X-Gm-Message-State:\r
55  ALoCoQn3Kmj2G0nGehcJjA93FXRvUpvoRmAn6piRYeapx6sRVLkVc0KpZhO6Pe5TB2uWzkP46EsG\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Sat, 30 Mar 2013 13:53:32 -0000\r
69 \r
70 The code filled with #ifdef GMIME_ATLEAST_26 is difficult to\r
71 read. Abstract gpg context creation into a function, with separate\r
72 implementations for GMime 2.4 and 2.6, to clarify the code.\r
73 \r
74 There should be no functional changes.\r
75 ---\r
76  crypto.c |   66 ++++++++++++++++++++++++++++++++++++++++++++------------------\r
77  1 file changed, 47 insertions(+), 19 deletions(-)\r
78 \r
79 diff --git a/crypto.c b/crypto.c\r
80 index cb361e1..9736517 100644\r
81 --- a/crypto.c\r
82 +++ b/crypto.c\r
83 @@ -20,6 +20,48 @@\r
84  \r
85  #include "notmuch-client.h"\r
86  \r
87 +#ifdef GMIME_ATLEAST_26\r
88 +\r
89 +/* Create a GPG context (GMime 2.6) */\r
90 +static notmuch_crypto_context_t *\r
91 +create_gpg_context (void)\r
92 +{\r
93 +    notmuch_crypto_context_t *gpgctx;\r
94 +\r
95 +    /* TODO: GMimePasswordRequestFunc */\r
96 +    gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
97 +    if (! gpgctx)\r
98 +       return NULL;\r
99 +\r
100 +    g_mime_gpg_context_set_use_agent ((GMimeGpgContext *) gpgctx, TRUE);\r
101 +    g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);\r
102 +\r
103 +    return gpgctx;\r
104 +}\r
105 +\r
106 +#else /* GMIME_ATLEAST_26 */\r
107 +\r
108 +/* Create a GPG context (GMime 2.4) */\r
109 +static notmuch_crypto_context_t *\r
110 +create_gpg_context (void)\r
111 +{\r
112 +    GMimeSession *session;\r
113 +    notmuch_crypto_context_t *gpgctx;\r
114 +\r
115 +    session = g_object_new (g_mime_session_get_type (), NULL);\r
116 +    gpgctx = g_mime_gpg_context_new (session, "gpg");\r
117 +    g_object_unref (session);\r
118 +\r
119 +    if (! gpgctx)\r
120 +       return NULL;\r
121 +\r
122 +    g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) gpgctx, FALSE);\r
123 +\r
124 +    return gpgctx;\r
125 +}\r
126 +\r
127 +#endif /* GMIME_ATLEAST_26 */\r
128 +\r
129  /* for the specified protocol return the context pointer (initializing\r
130   * if needed) */\r
131  notmuch_crypto_context_t *\r
132 @@ -33,28 +75,14 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
133       * parameter names as defined in this document are\r
134       * case-insensitive."  Thus, we use strcasecmp for the protocol.\r
135       */\r
136 -    if ((strcasecmp (protocol, "application/pgp-signature") == 0)\r
137 -       || (strcasecmp (protocol, "application/pgp-encrypted") == 0)) {\r
138 -       if (!crypto->gpgctx) {\r
139 -#ifdef GMIME_ATLEAST_26\r
140 -           /* TODO: GMimePasswordRequestFunc */\r
141 -           crypto->gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
142 -#else\r
143 -           GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
144 -           crypto->gpgctx = g_mime_gpg_context_new (session, "gpg");\r
145 -           g_object_unref (session);\r
146 -#endif\r
147 -           if (crypto->gpgctx) {\r
148 -#ifdef GMIME_ATLEAST_26\r
149 -               g_mime_gpg_context_set_use_agent ((GMimeGpgContext*) crypto->gpgctx, TRUE);\r
150 -#endif\r
151 -               g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);\r
152 -           } else {\r
153 +    if (strcasecmp (protocol, "application/pgp-signature") == 0 ||\r
154 +       strcasecmp (protocol, "application/pgp-encrypted") == 0) {\r
155 +       if (! crypto->gpgctx) {\r
156 +           crypto->gpgctx = create_gpg_context ();\r
157 +           if (! crypto->gpgctx)\r
158                 fprintf (stderr, "Failed to construct gpg context.\n");\r
159 -           }\r
160         }\r
161         cryptoctx = crypto->gpgctx;\r
162 -\r
163      } else {\r
164         fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
165      }\r
166 -- \r
167 1.7.10.4\r
168 \r