Re: [PATCH] Free the results of scandir()
[notmuch-archives.git] / 54 / b7cfc9d7fce4d25446ef3325981f4f5ff3608e
1 Return-Path: <markwalters1009@gmail.com>\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 02A20431FBF\r
6         for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 09:08:29 -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: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id cwDwq20dBPxd for <notmuch@notmuchmail.org>;\r
18         Sat,  4 Feb 2012 09:08:27 -0800 (PST)\r
19 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
20         [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 24AA2431FC3\r
23         for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 09:08:25 -0800 (PST)\r
24 Received: by mail-wi0-f181.google.com with SMTP id hi8so3640758wib.26\r
25         for <notmuch@notmuchmail.org>; Sat, 04 Feb 2012 09:08:25 -0800 (PST)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=6FgeDAOQkqBapGUGVdjGgyoHBM3DN9VZGdHUbIVkjAU=;\r
29         b=sf/QBsZD4qtJC6oQkw1HtzizYrvS35+l1+hvdVFQ0XX5yFCiMAtg1/SLYBNen3fFIZ\r
30         FnfbDWFlUKEtm77LigrC3l091uhlUY7PkzggYJsarb5ifO1DZmCXLxHOCSu2gvkX/YQs\r
31         G9GNUby6t7rBeoxiYUUPbmy3wmkzfceEnGCqA=\r
32 Received: by 10.180.14.129 with SMTP id p1mr18213105wic.16.1328375304987;\r
33         Sat, 04 Feb 2012 09:08:24 -0800 (PST)\r
34 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
35  [94.192.233.223])      by mx.google.com with ESMTPS id\r
36  cb8sm13984703wib.0.2012.02.04.09.08.23 (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Sat, 04 Feb 2012 09:08:24 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 1/2] cli: add --from option to reply to restrict guessing of\r
41         the From: header.\r
42 Date: Sat,  4 Feb 2012 17:09:09 +0000\r
43 Message-Id: <1328375350-10352-2-git-send-email-markwalters1009@gmail.com>\r
44 X-Mailer: git-send-email 1.7.2.3\r
45 In-Reply-To: <1328375350-10352-1-git-send-email-markwalters1009@gmail.com>\r
46 References: <1328375350-10352-1-git-send-email-markwalters1009@gmail.com>\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Sat, 04 Feb 2012 17:08:29 -0000\r
60 \r
61 Add an option --from= to notmuch-reply.c to restrict guessing of the\r
62 From: header. The existing logic looks as the main headers, then at\r
63 the delivery headers, and finally defaults to the config file address.\r
64 \r
65 This patch allows the user to restrict which of these guesses are\r
66 made.  Currently the supported values are:\r
67        default|fallback-all    current behaviour\r
68        fallback-received       fallback to delivery headers but not config file\r
69        fallback-none           only look at from/reply-to/to/cc/ headers\r
70        none                    From: header is always left empty\r
71 \r
72 If the code does not find an allowed address it outputs an empty From:\r
73 line and the caller can decide how to respond.\r
74 ---\r
75  notmuch-reply.c |   39 ++++++++++++++++++++++++++++++---------\r
76  1 files changed, 30 insertions(+), 9 deletions(-)\r
77 \r
78 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
79 index f55b1d2..f660749 100644\r
80 --- a/notmuch-reply.c\r
81 +++ b/notmuch-reply.c\r
82 @@ -24,6 +24,13 @@\r
83  #include "gmime-filter-reply.h"\r
84  #include "gmime-filter-headers.h"\r
85  \r
86 +enum {\r
87 +    FROM_FALLBACK_ALL,\r
88 +    FROM_FALLBACK_RECEIVED,\r
89 +    FROM_FALLBACK_NONE,\r
90 +    FROM_NONE\r
91 +};\r
92 +\r
93  static void\r
94  reply_headers_message_part (GMimeMessage *message);\r
95  \r
96 @@ -510,7 +517,8 @@ notmuch_reply_format_default(void *ctx,\r
97                              notmuch_config_t *config,\r
98                              notmuch_query_t *query,\r
99                              notmuch_show_params_t *params,\r
100 -                            notmuch_bool_t reply_all)\r
101 +                            notmuch_bool_t reply_all,\r
102 +                            int from_guess)\r
103  {\r
104      GMimeMessage *reply;\r
105      notmuch_messages_t *messages;\r
106 @@ -542,15 +550,19 @@ notmuch_reply_format_default(void *ctx,\r
107         from_addr = add_recipients_from_message (reply, config, message,\r
108                                                  reply_all);\r
109  \r
110 -       if (from_addr == NULL)\r
111 +       if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_RECEIVED))\r
112             from_addr = guess_from_received_header (config, message);\r
113  \r
114 -       if (from_addr == NULL)\r
115 +       if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_ALL ))\r
116             from_addr = notmuch_config_get_user_primary_email (config);\r
117  \r
118 -       from_addr = talloc_asprintf (ctx, "%s <%s>",\r
119 -                                    notmuch_config_get_user_name (config),\r
120 -                                    from_addr);\r
121 +       if ((from_addr != NULL) || (from_guess = FROM_NONE)) {\r
122 +           from_addr = talloc_asprintf (ctx, "%s <%s>",\r
123 +                                        notmuch_config_get_user_name (config),\r
124 +                                        from_addr);\r
125 +       } else {\r
126 +           from_addr = talloc_strdup (ctx, "");\r
127 +       }\r
128         g_mime_object_set_header (GMIME_OBJECT (reply),\r
129                                   "From", from_addr);\r
130  \r
131 @@ -590,7 +602,8 @@ notmuch_reply_format_headers_only(void *ctx,\r
132                                   notmuch_config_t *config,\r
133                                   notmuch_query_t *query,\r
134                                   unused (notmuch_show_params_t *params),\r
135 -                                 notmuch_bool_t reply_all)\r
136 +                                 notmuch_bool_t reply_all,\r
137 +                                 unused (int from_guess))\r
138  {\r
139      GMimeMessage *reply;\r
140      notmuch_messages_t *messages;\r
141 @@ -657,10 +670,11 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
142      notmuch_query_t *query;\r
143      char *query_string;\r
144      int opt_index, ret = 0;\r
145 -    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
146 +    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
147      notmuch_show_params_t params = { .part = -1 };\r
148      int format = FORMAT_DEFAULT;\r
149      int reply_all = TRUE;\r
150 +    int from_guess = FROM_FALLBACK_ALL;\r
151      notmuch_bool_t decrypt = FALSE;\r
152  \r
153      notmuch_opt_desc_t options[] = {\r
154 @@ -672,6 +686,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
155           (notmuch_keyword_t []){ { "all", TRUE },\r
156                                   { "sender", FALSE },\r
157                                   { 0, 0 } } },\r
158 +       { NOTMUCH_OPT_KEYWORD, &from_guess, "from", 'F',\r
159 +         (notmuch_keyword_t []){ { "default", FROM_FALLBACK_ALL },\r
160 +                                 { "fallback-all", FROM_FALLBACK_ALL },\r
161 +                                 { "fallback-received", FROM_FALLBACK_RECEIVED },\r
162 +                                 { "fallback-none", FROM_FALLBACK_NONE },\r
163 +                                 { "none", FROM_NONE },\r
164 +                                 { 0, 0 } } },\r
165         { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
166         { 0, 0, 0, 0, 0 }\r
167      };\r
168 @@ -732,7 +753,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
169         return 1;\r
170      }\r
171  \r
172 -    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
173 +    if (reply_format_func (ctx, config, query, &params, reply_all, from_guess) != 0)\r
174         return 1;\r
175  \r
176      notmuch_query_destroy (query);\r
177 -- \r
178 1.7.2.3\r
179 \r