1 Return-Path: <Sebastian@SSpaeth.de>
\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 B0CB74196F4
\r
6 for <notmuch@notmuchmail.org>; Tue, 6 Apr 2010 00:12:55 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham
\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 eKN1ALxbBb7b for <notmuch@notmuchmail.org>;
\r
16 Tue, 6 Apr 2010 00:12:54 -0700 (PDT)
\r
17 Received: from homiemail-a19.g.dreamhost.com (caiajhbdcaid.dreamhost.com
\r
19 by olra.theworths.org (Postfix) with ESMTP id 634434196F0
\r
20 for <notmuch@notmuchmail.org>; Tue, 6 Apr 2010 00:12:54 -0700 (PDT)
\r
21 Received: from localhost.localdomain (mtec-hg-docking-1-dhcp-204.ethz.ch
\r
23 by homiemail-a19.g.dreamhost.com (Postfix) with ESMTPA id 5308260405D;
\r
24 Tue, 6 Apr 2010 00:12:53 -0700 (PDT)
\r
25 From: Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [PATCH 1/2] notmuch-reply: Add support for replying only to sender
\r
28 Date: Tue, 6 Apr 2010 09:12:45 +0200
\r
29 Message-Id: <1270537966-19324-1-git-send-email-Sebastian@SSpaeth.de>
\r
30 X-Mailer: git-send-email 1.6.3.3
\r
31 In-Reply-To: <87mxxhgims.fsf@SSpaeth.de>
\r
32 References: <87mxxhgims.fsf@SSpaeth.de>
\r
33 Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.13
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Tue, 06 Apr 2010 07:12:55 -0000
\r
48 From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
\r
50 This patch add --recipient=all|sender option
\r
52 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
\r
54 notmuch-client.h | 2 +
\r
55 notmuch-reply.c | 55 ++++++++++++++++++++++++++++++++++++++++-------------
\r
56 2 files changed, 43 insertions(+), 14 deletions(-)
\r
58 diff --git a/notmuch-client.h b/notmuch-client.h
\r
59 index d36b9ec..3ca4b32 100644
\r
60 --- a/notmuch-client.h
\r
61 +++ b/notmuch-client.h
\r
63 #define STRNCMP_LITERAL(var, literal) \
\r
64 strncmp ((var), (literal), sizeof (literal) - 1)
\r
66 +#define NOTMUCH_REPLY_ALL 0x1
\r
67 +#define NOTMUCH_REPLY_SENDER_ONLY 0x2
\r
69 chomp_newline (char *str)
\r
71 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
72 index 6c15536..e8a0820 100644
\r
73 --- a/notmuch-reply.c
\r
74 +++ b/notmuch-reply.c
\r
75 @@ -232,20 +232,37 @@ reply_to_header_is_redundant (notmuch_message_t *message)
\r
77 add_recipients_from_message (GMimeMessage *reply,
\r
78 notmuch_config_t *config,
\r
79 - notmuch_message_t *message)
\r
80 + notmuch_message_t *message,
\r
81 + int reply_options)
\r
84 + struct reply_to_map {
\r
86 const char *fallback;
\r
87 GMimeRecipientType recipient_type;
\r
88 - } reply_to_map[] = {
\r
90 + const char *from_addr = NULL;
\r
92 + struct reply_to_map *reply_to_map;
\r
94 + struct reply_to_map reply_to_map_all[] = {
\r
95 { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO },
\r
96 { "to", NULL, GMIME_RECIPIENT_TYPE_TO },
\r
97 { "cc", NULL, GMIME_RECIPIENT_TYPE_CC },
\r
98 - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }
\r
99 + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC },
\r
100 + { NULL, NULL, 0 }
\r
102 - const char *from_addr = NULL;
\r
105 + /* we try from first and then reply-to */
\r
106 + struct reply_to_map reply_to_map_sender[] = {
\r
107 + { "from", "reply-to", GMIME_RECIPIENT_TYPE_TO },
\r
108 + { NULL, NULL, 0 }
\r
111 + if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) {
\r
112 + reply_to_map = reply_to_map_sender;
\r
114 + reply_to_map = reply_to_map_all;
\r
117 /* Some mailing lists munge the Reply-To header despite it being A Bad
\r
118 * Thing, see http://www.unicom.com/pw/reply-to-harmful.html
\r
119 @@ -263,7 +280,7 @@ add_recipients_from_message (GMimeMessage *reply,
\r
120 reply_to_map[0].fallback = NULL;
\r
123 - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
\r
124 + for (i = 0; reply_to_map[i].header; i++) {
\r
125 const char *addr, *recipients;
\r
127 recipients = notmuch_message_get_header (message,
\r
128 @@ -283,7 +300,7 @@ add_recipients_from_message (GMimeMessage *reply,
\r
132 -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
\r
133 +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)
\r
135 GMimeMessage *reply;
\r
136 notmuch_messages_t *messages;
\r
137 @@ -311,7 +328,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
\r
138 subject = talloc_asprintf (ctx, "Re: %s", subject);
\r
139 g_mime_message_set_subject (reply, subject);
\r
141 - from_addr = add_recipients_from_message (reply, config, message);
\r
142 + from_addr = add_recipients_from_message (reply, config, message, reply_options);
\r
144 if (from_addr == NULL)
\r
145 from_addr = notmuch_config_get_user_primary_email (config);
\r
146 @@ -359,7 +376,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
\r
148 /* This format is currently tuned for a git send-email --notmuch hook */
\r
150 -notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
\r
151 +notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)
\r
153 GMimeMessage *reply;
\r
154 notmuch_messages_t *messages;
\r
155 @@ -399,7 +416,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q
\r
156 g_mime_object_set_header (GMIME_OBJECT (reply),
\r
157 "References", references);
\r
159 - (void)add_recipients_from_message (reply, config, message);
\r
160 + (void)add_recipients_from_message (reply, config, message, reply_options);
\r
162 g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",
\r
163 notmuch_config_get_user_primary_email (config));
\r
164 @@ -423,8 +440,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
165 notmuch_database_t *notmuch;
\r
166 notmuch_query_t *query;
\r
167 char *opt, *query_string;
\r
169 - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query);
\r
170 + int i, ret = 0, reply_to = NOTMUCH_REPLY_ALL;
\r
171 + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options);
\r
173 reply_format_func = notmuch_reply_format_default;
\r
175 @@ -443,6 +460,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
176 fprintf (stderr, "Invalid value for --format: %s\n", opt);
\r
179 + } else if (STRNCMP_LITERAL (argv[i], "--recipient=") == 0) {
\r
180 + opt = argv[i] + sizeof ("--recipient=") - 1;
\r
181 + if (strcmp (opt, "all") == 0) {
\r
182 + reply_to = NOTMUCH_REPLY_ALL;
\r
183 + } else if (strcmp (opt, "sender") == 0) {
\r
184 + reply_to = NOTMUCH_REPLY_SENDER_ONLY;
\r
186 + fprintf (stderr, "Invalid value for --recipient: %s\n", opt);
\r
190 fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
192 @@ -478,7 +505,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
196 - if (reply_format_func (ctx, config, query) != 0)
\r
197 + if (reply_format_func (ctx, config, query, reply_to) != 0)
\r
200 notmuch_query_destroy (query);
\r