[PATCH 2/2] cli: mime node: abstract decryption and signature verification
[notmuch-archives.git] / 8a / 058e415e3a48e43a06c74a6bebbf2891b76075
1 Return-Path: <m.walters@qmul.ac.uk>\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 3786C431FAF\r
6         for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 11:06:57 -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: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 ldqmnheLicv9 for <notmuch@notmuchmail.org>;\r
17         Sat,  4 Feb 2012 11:06:56 -0800 (PST)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 1B346431FAE\r
22         for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 11:06:56 -0800 (PST)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1Rtkwj-0001wS-Gq; Sat, 04 Feb 2012 19:06:52 +0000\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
28         helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1Rtkwj-0002Sp-0w; Sat, 04 Feb 2012 19:06:49 +0000\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH 1/2] cli: add --from option to reply to restrict guessing\r
35         of the From: header.\r
36 In-Reply-To: <87lioio4wx.fsf@nikula.org>\r
37 References: <1328375350-10352-1-git-send-email-markwalters1009@gmail.com>\r
38         <1328375350-10352-2-git-send-email-markwalters1009@gmail.com>\r
39         <87lioio4wx.fsf@nikula.org>\r
40 User-Agent: Notmuch/0.11+152~ge29a32b (http://notmuchmail.org) Emacs/23.2.1\r
41         (i486-pc-linux-gnu)\r
42 Date: Sat, 04 Feb 2012 19:07:59 +0000\r
43 Message-ID: <87k442h0xc.fsf@qmul.ac.uk>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 X-Sender-Host-Address: 94.192.233.223\r
47 X-QM-SPAM-Info: Sender has good ham record.  :)\r
48 X-QM-Body-MD5: 8b51cd1e9fa2de4fa0dd70298a1ea87c (of first 20000 bytes)\r
49 X-SpamAssassin-Score: -1.8\r
50 X-SpamAssassin-SpamBar: -\r
51 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
52         determine if it is\r
53         spam. We require at least 5.0 points to mark a message as spam.\r
54         This message scored -1.8 points.\r
55         Summary of the scoring: \r
56         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
57         *      medium trust\r
58         *      [138.37.6.40 listed in list.dnswl.org]\r
59         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
60         provider *      (markwalters1009[at]gmail.com)\r
61         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
62         *      domain\r
63         *  0.5 AWL AWL: From: address is in the auto white-list\r
64 X-QM-Scan-Virus: ClamAV says the message is clean\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Sat, 04 Feb 2012 19:06:57 -0000\r
78 \r
79 \r
80 On Sat, 04 Feb 2012 19:59:58 +0200, Jani Nikula <jani@nikula.org> wrote:\r
81 > On Sat,  4 Feb 2012 17:09:09 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
82 > > Add an option --from= to notmuch-reply.c to restrict guessing of the\r
83 > > From: header. The existing logic looks as the main headers, then at\r
84 > > the delivery headers, and finally defaults to the config file address.\r
85 > > \r
86 > > This patch allows the user to restrict which of these guesses are\r
87 > > made.  Currently the supported values are:\r
88 > >        default|fallback-all    current behaviour\r
89 > >        fallback-received       fallback to delivery headers but not config file\r
90 > >        fallback-none               only look at from/reply-to/to/cc/ headers\r
91 > >        none                From: header is always left empty\r
92\r
93 > As discussed on IRC, --from=primary is a natural extension to always use\r
94 > the primary address from config, but that can be a later patch.\r
95 \r
96 Ok, I will probably add that.\r
97 \r
98 > > \r
99 > > If the code does not find an allowed address it outputs an empty From:\r
100 > > line and the caller can decide how to respond.\r
101 > > ---\r
102 > >  notmuch-reply.c |   39 ++++++++++++++++++++++++++++++---------\r
103 > >  1 files changed, 30 insertions(+), 9 deletions(-)\r
104 > > \r
105 > > diff --git a/notmuch-reply.c b/notmuch-reply.c\r
106 > > index f55b1d2..f660749 100644\r
107 > > --- a/notmuch-reply.c\r
108 > > +++ b/notmuch-reply.c\r
109 > > @@ -24,6 +24,13 @@\r
110 > >  #include "gmime-filter-reply.h"\r
111 > >  #include "gmime-filter-headers.h"\r
112 > >  \r
113\r
114 > I think it would be good to have a comment here reminding later\r
115 > developers that the order matters in this enum.\r
116 \r
117 Have fixed\r
118 \r
119 > > +enum {\r
120 > > +    FROM_FALLBACK_ALL,\r
121 > > +    FROM_FALLBACK_RECEIVED,\r
122 > > +    FROM_FALLBACK_NONE,\r
123 > > +    FROM_NONE\r
124 > > +};\r
125 > > +\r
126 > >  static void\r
127 > >  reply_headers_message_part (GMimeMessage *message);\r
128 > >  \r
129 > > @@ -510,7 +517,8 @@ notmuch_reply_format_default(void *ctx,\r
130 > >                          notmuch_config_t *config,\r
131 > >                          notmuch_query_t *query,\r
132 > >                          notmuch_show_params_t *params,\r
133 > > -                        notmuch_bool_t reply_all)\r
134 > > +                        notmuch_bool_t reply_all,\r
135 > > +                        int from_guess)\r
136\r
137 > Hrmh, I'd like this to sound more deterministic than\r
138 > "guessing". from_select? from_use? from?\r
139 \r
140 I have gone for from_select.\r
141 \r
142 > >  {\r
143 > >      GMimeMessage *reply;\r
144 > >      notmuch_messages_t *messages;\r
145 > > @@ -542,15 +550,19 @@ notmuch_reply_format_default(void *ctx,\r
146 > >     from_addr = add_recipients_from_message (reply, config, message,\r
147 > >                                              reply_all);\r
148 > >  \r
149 > > -   if (from_addr == NULL)\r
150 > > +   if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_RECEIVED))\r
151\r
152 > Please drop the extra braces here and below.\r
153 \r
154 Have fixed. (Indeed in a sense this was a bug see below!)\r
155\r
156 > >         from_addr = guess_from_received_header (config, message);\r
157 > >  \r
158 > > -   if (from_addr == NULL)\r
159 > > +   if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_ALL ))\r
160 > >         from_addr = notmuch_config_get_user_primary_email (config);\r
161 > >  \r
162 > > -   from_addr = talloc_asprintf (ctx, "%s <%s>",\r
163 > > -                                notmuch_config_get_user_name (config),\r
164 > > -                                from_addr);\r
165 > > +   if ((from_addr != NULL) || (from_guess = FROM_NONE)) {\r
166\r
167 > Should that be (from_addr != NULL && from_guess != FROM_NONE)?\r
168 > Definitely the assignment is an error!\r
169 \r
170 You are quite right. And if I didn't have the superfluous brackets the\r
171 compiler would probably have given a warning. I have fixed it.\r
172 \r
173\r
174 > > +       from_addr = talloc_asprintf (ctx, "%s <%s>",\r
175 > > +                                    notmuch_config_get_user_name (config),\r
176 > > +                                    from_addr);\r
177 > > +   } else {\r
178 > > +       from_addr = talloc_strdup (ctx, "");\r
179 > > +   }\r
180 > >     g_mime_object_set_header (GMIME_OBJECT (reply),\r
181 > >                               "From", from_addr);\r
182 > >  \r
183 > > @@ -590,7 +602,8 @@ notmuch_reply_format_headers_only(void *ctx,\r
184 > >                               notmuch_config_t *config,\r
185 > >                               notmuch_query_t *query,\r
186 > >                               unused (notmuch_show_params_t *params),\r
187 > > -                             notmuch_bool_t reply_all)\r
188 > > +                             notmuch_bool_t reply_all,\r
189 > > +                             unused (int from_guess))\r
190 > >  {\r
191 > >      GMimeMessage *reply;\r
192 > >      notmuch_messages_t *messages;\r
193 > > @@ -657,10 +670,11 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
194 > >      notmuch_query_t *query;\r
195 > >      char *query_string;\r
196 > >      int opt_index, ret = 0;\r
197 > > -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
198 > > +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all, int from_guess);\r
199 > >      notmuch_show_params_t params = { .part = -1 };\r
200 > >      int format = FORMAT_DEFAULT;\r
201 > >      int reply_all = TRUE;\r
202 > > +    int from_guess = FROM_FALLBACK_ALL;\r
203 > >      notmuch_bool_t decrypt = FALSE;\r
204 > >  \r
205 > >      notmuch_opt_desc_t options[] = {\r
206 > > @@ -672,6 +686,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
207 > >       (notmuch_keyword_t []){ { "all", TRUE },\r
208 > >                               { "sender", FALSE },\r
209 > >                               { 0, 0 } } },\r
210 > > +   { NOTMUCH_OPT_KEYWORD, &from_guess, "from", 'F',\r
211 > > +     (notmuch_keyword_t []){ { "default", FROM_FALLBACK_ALL },\r
212 > > +                             { "fallback-all", FROM_FALLBACK_ALL },\r
213 > > +                             { "fallback-received", FROM_FALLBACK_RECEIVED },\r
214 > > +                             { "fallback-none", FROM_FALLBACK_NONE },\r
215 > > +                             { "none", FROM_NONE },\r
216 > > +                             { 0, 0 } } },\r
217 > >     { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
218 > >     { 0, 0, 0, 0, 0 }\r
219 > >      };\r
220 > > @@ -732,7 +753,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
221 > >     return 1;\r
222 > >      }\r
223 > >  \r
224 > > -    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
225 > > +    if (reply_format_func (ctx, config, query, &params, reply_all, from_guess) != 0)\r
226 > >     return 1;\r
227 > >  \r
228 > >      notmuch_query_destroy (query);\r
229 > > -- \r
230 > > 1.7.2.3\r
231 > > \r
232 > > _______________________________________________\r
233 > > notmuch mailing list\r
234 > > notmuch@notmuchmail.org\r
235 > > http://notmuchmail.org/mailman/listinfo/notmuch\r