1 Return-Path: <five9a2@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 261A7431FC0
\r
6 for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 15:19:04 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id 4bEw6aR4LoT4 for <notmuch@notmuchmail.org>;
\r
11 Sat, 28 Nov 2009 15:19:03 -0800 (PST)
\r
12 Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com
\r
14 by olra.theworths.org (Postfix) with ESMTP id C2ADA431FAE
\r
15 for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 15:19:02 -0800 (PST)
\r
16 Received: by bwz24 with SMTP id 24so1833687bwz.30
\r
17 for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 15:19:01 -0800 (PST)
\r
18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
19 h=domainkey-signature:received:received:sender:from:to:cc:subject
\r
20 :date:message-id:x-mailer:in-reply-to:references;
\r
21 bh=HatAbY1NBt3HZDnXUYT5BVIWNQgJKbHjtfbfHQb1j1U=;
\r
22 b=jm8OSXTNnY52IPdlXaSzdSwRYaDIUCWm60zzGmopVGtzXoITvRBvuykr3nexq+42LK
\r
23 u47h+5sVzlO45618ZouP1VbC/KZof7TYUTt2DZggq9fK9wFUGjmb8PB+w/2vPzAW61OF
\r
24 3dq1Y0Bc1cSUttEgi8sYJzr/E8How8sLGwADA=
\r
25 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
\r
26 h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
28 b=v0rvFd9cpllvuS6Ri7XPrU2ZEt0Tr5QNw3IOYS5K9IGjmz1iyHWd0TJ5VifMiqB28l
\r
29 UxxADc3MW61I1oY5wv79vRzCfUXjalhljf2rrDDhra0aEw9LajRpKva4uZjuw7PnYkpQ
\r
30 roPQyGMIHDKkuzMPXSVIa4k//gvOtf+t+vohM=
\r
31 Received: by 10.204.156.218 with SMTP id y26mr2642483bkw.205.1259450341846;
\r
32 Sat, 28 Nov 2009 15:19:01 -0800 (PST)
\r
33 Received: from localhost.localdomain (vawpc43.ethz.ch [129.132.59.11])
\r
34 by mx.google.com with ESMTPS id 15sm965320fxm.14.2009.11.28.15.19.00
\r
35 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
36 Sat, 28 Nov 2009 15:19:01 -0800 (PST)
\r
37 Sender: Jed Brown <five9a2@gmail.com>
\r
38 From: Jed Brown <jed@59A2.org>
\r
39 To: cworth@cworth.org
\r
40 Date: Sun, 29 Nov 2009 00:19:35 +0100
\r
41 Message-Id: <1259450376-24523-1-git-send-email-jed@59A2.org>
\r
42 X-Mailer: git-send-email 1.6.5.3
\r
43 In-Reply-To: <87r5ripfy2.fsf@yoom.home.cworth.org>
\r
44 References: <87r5ripfy2.fsf@yoom.home.cworth.org>
\r
45 Cc: notmuch@notmuchmail.org
\r
46 Subject: [notmuch] [PATCH 1/2] notmuch-reply.c: factor adding recipients
\r
47 into common function
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.12
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Sat, 28 Nov 2009 23:19:04 -0000
\r
62 add_recipients_from_message, in order to isolate more sophisticated
\r
65 Signed-off-by: Jed Brown <jed@59A2.org>
\r
67 notmuch-reply.c | 88 ++++++++++++++++++++++++++++---------------------------
\r
68 1 files changed, 45 insertions(+), 43 deletions(-)
\r
70 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
71 index 9ca1236..b91a830 100644
\r
72 --- a/notmuch-reply.c
\r
73 +++ b/notmuch-reply.c
\r
75 #include "notmuch-client.h"
\r
76 #include "gmime-filter-reply.h"
\r
78 -static const struct {
\r
79 - const char *header;
\r
80 - const char *fallback;
\r
81 - GMimeRecipientType recipient_type;
\r
82 -} reply_to_map[] = {
\r
83 - { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO },
\r
84 - { "to", NULL, GMIME_RECIPIENT_TYPE_TO },
\r
85 - { "cc", NULL, GMIME_RECIPIENT_TYPE_CC },
\r
86 - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }
\r
90 reply_part_content (GMimeObject *part)
\r
92 @@ -193,16 +182,56 @@ add_recipients_for_string (GMimeMessage *message,
\r
93 return add_recipients_for_address_list (message, config, type, list);
\r
96 +/* Augments the recipients of reply from the headers of message.
\r
98 + * If any of the user's addresses were found in these headers, the first
\r
99 + * of these returned, otherwise NULL is returned.
\r
101 +static const char *
\r
102 +add_recipients_from_message (GMimeMessage *reply,
\r
103 + notmuch_config_t *config,
\r
104 + notmuch_message_t *message)
\r
106 + static const struct {
\r
107 + const char *header;
\r
108 + const char *fallback;
\r
109 + GMimeRecipientType recipient_type;
\r
110 + } reply_to_map[] = {
\r
111 + { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO },
\r
112 + { "to", NULL, GMIME_RECIPIENT_TYPE_TO },
\r
113 + { "cc", NULL, GMIME_RECIPIENT_TYPE_CC },
\r
114 + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }
\r
116 + const char *from_addr = NULL;
\r
119 + for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
\r
120 + const char *addr, *recipients;
\r
122 + recipients = notmuch_message_get_header (message,
\r
123 + reply_to_map[i].header);
\r
124 + if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)
\r
125 + recipients = notmuch_message_get_header (message,
\r
126 + reply_to_map[i].fallback);
\r
128 + addr = add_recipients_for_string (reply, config,
\r
129 + reply_to_map[i].recipient_type,
\r
131 + if (from_addr == NULL)
\r
132 + from_addr = addr;
\r
134 + return from_addr;
\r
138 notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
\r
140 GMimeMessage *reply;
\r
141 notmuch_messages_t *messages;
\r
142 notmuch_message_t *message;
\r
143 - const char *subject, *recipients, *from_addr = NULL;
\r
144 + const char *subject, *from_addr = NULL;
\r
145 const char *in_reply_to, *orig_references, *references;
\r
146 char *reply_headers;
\r
149 for (messages = notmuch_query_search_messages (query);
\r
150 notmuch_messages_has_more (messages);
\r
151 @@ -223,21 +252,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
\r
152 subject = talloc_asprintf (ctx, "Re: %s", subject);
\r
153 g_mime_message_set_subject (reply, subject);
\r
155 - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
\r
156 - const char *addr;
\r
158 - recipients = notmuch_message_get_header (message,
\r
159 - reply_to_map[i].header);
\r
160 - if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)
\r
161 - recipients = notmuch_message_get_header (message,
\r
162 - reply_to_map[i].fallback);
\r
164 - addr = add_recipients_for_string (reply, config,
\r
165 - reply_to_map[i].recipient_type,
\r
167 - if (from_addr == NULL)
\r
168 - from_addr = addr;
\r
170 + from_addr = add_recipients_from_message (reply, config, message);
\r
172 if (from_addr == NULL)
\r
173 from_addr = notmuch_config_get_user_primary_email (config);
\r
174 @@ -290,9 +305,8 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q
\r
175 GMimeMessage *reply;
\r
176 notmuch_messages_t *messages;
\r
177 notmuch_message_t *message;
\r
178 - const char *recipients, *in_reply_to, *orig_references, *references;
\r
179 + const char *in_reply_to, *orig_references, *references;
\r
180 char *reply_headers;
\r
183 for (messages = notmuch_query_search_messages (query);
\r
184 notmuch_messages_has_more (messages);
\r
185 @@ -326,19 +340,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q
\r
186 g_mime_object_set_header (GMIME_OBJECT (reply),
\r
187 "References", references);
\r
189 - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
\r
190 - const char *addr;
\r
192 - recipients = notmuch_message_get_header (message,
\r
193 - reply_to_map[i].header);
\r
194 - if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)
\r
195 - recipients = notmuch_message_get_header (message,
\r
196 - reply_to_map[i].fallback);
\r
198 - addr = add_recipients_for_string (reply, config,
\r
199 - reply_to_map[i].recipient_type,
\r
202 + (void)add_recipients_from_message (reply, config, message);
\r
204 g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",
\r
205 notmuch_config_get_user_primary_email (config));
\r