[PATCH 08/11] cli: add thread recipients to search output
[notmuch-archives.git] / fe / 2206bec742e00e86d2cbbf47bbaf02405b4978
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 8EDBD429E36\r
6         for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:40:33 -0800 (PST)\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 7zq2XD+I9xIo for <notmuch@notmuchmail.org>;\r
17         Thu, 12 Jan 2012 13:40:31 -0800 (PST)\r
18 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
19  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
20  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
21  D762A429E29    for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:40:28 -0800\r
22  (PST)\r
23 Received: by wgbds11 with SMTP id ds11so2216570wgb.2\r
24         for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:40:27 -0800 (PST)\r
25 Received: by 10.180.82.41 with SMTP id f9mr9639028wiy.7.1326404427630;\r
26         Thu, 12 Jan 2012 13:40:27 -0800 (PST)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id hv1sm1886746wib.1.2012.01.12.13.40.25\r
30         (version=SSLv3 cipher=OTHER); Thu, 12 Jan 2012 13:40:26 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH v4 1/5] cli: slightly refactor "notmuch reply" address\r
34         scanning functions\r
35 Date: Thu, 12 Jan 2012 23:40:15 +0200\r
36 Message-Id:\r
37  <9935c31d8727331b442ce266ae22469243b85f36.1326403905.git.jani@nikula.org>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <cover.1326403905.git.jani@nikula.org>\r
40 References: <cover.1326403905.git.jani@nikula.org>\r
41 In-Reply-To: <cover.1326403905.git.jani@nikula.org>\r
42 References: <cover.1325794371.git.jani@nikula.org>\r
43         <cover.1326403905.git.jani@nikula.org>\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Thu, 12 Jan 2012 21:40:34 -0000\r
57 \r
58 Slightly refactor "notmuch reply" recipient and user from address scanning\r
59 functions in preparation for reply-to-sender feature.\r
60 \r
61 Add support for not adding messages at all (just scan for user from\r
62 address), and returning the number of messages added.\r
63 \r
64 No externally visible functional changes.\r
65 \r
66 Signed-off-by: Jani Nikula <jani@nikula.org>\r
67 ---\r
68  notmuch-reply.c |   74 ++++++++++++++++++++++++++++--------------------------\r
69  1 files changed, 38 insertions(+), 36 deletions(-)\r
70 \r
71 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
72 index 000f6da..4fae66f 100644\r
73 --- a/notmuch-reply.c\r
74 +++ b/notmuch-reply.c\r
75 @@ -168,22 +168,28 @@ address_is_users (const char *address, notmuch_config_t *config)\r
76      return 0;\r
77  }\r
78  \r
79 -/* For each address in 'list' that is not configured as one of the\r
80 - * user's addresses in 'config', add that address to 'message' as an\r
81 - * address of 'type'.\r
82 +/* Scan addresses in 'list'.\r
83   *\r
84 - * The first address encountered that *is* the user's address will be\r
85 - * returned, (otherwise NULL is returned).\r
86 + * If 'message' is non-NULL, then for each address in 'list' that is not\r
87 + * configured as one of the user's addresses in 'config', add that address to\r
88 + * 'message' as an address of 'type'.\r
89 + *\r
90 + * If 'user_from' is non-NULL and *user_from is NULL, the first address\r
91 + * encountered in 'list' that *is* the user's address will be set to *user_from.\r
92 + *\r
93 + * Return the number of addresses added to 'message'. (If 'message' is NULL, the\r
94 + * function returns 0 by definition.)\r
95   */\r
96 -static const char *\r
97 -add_recipients_for_address_list (GMimeMessage *message,\r
98 -                                notmuch_config_t *config,\r
99 -                                GMimeRecipientType type,\r
100 -                                InternetAddressList *list)\r
101 +static unsigned int\r
102 +scan_address_list (InternetAddressList *list,\r
103 +                  notmuch_config_t *config,\r
104 +                  GMimeMessage *message,\r
105 +                  GMimeRecipientType type,\r
106 +                  const char **user_from)\r
107  {\r
108      InternetAddress *address;\r
109      int i;\r
110 -    const char *ret = NULL;\r
111 +    unsigned int n = 0;\r
112  \r
113      for (i = 0; i < internet_address_list_length (list); i++) {\r
114         address = internet_address_list_get_address (list, i);\r
115 @@ -196,8 +202,7 @@ add_recipients_for_address_list (GMimeMessage *message,\r
116             if (group_list == NULL)\r
117                 continue;\r
118  \r
119 -           add_recipients_for_address_list (message, config,\r
120 -                                            type, group_list);\r
121 +           n += scan_address_list (group_list, config, message, type, NULL);\r
122         } else {\r
123             InternetAddressMailbox *mailbox;\r
124             const char *name;\r
125 @@ -209,40 +214,40 @@ add_recipients_for_address_list (GMimeMessage *message,\r
126             addr = internet_address_mailbox_get_addr (mailbox);\r
127  \r
128             if (address_is_users (addr, config)) {\r
129 -               if (ret == NULL)\r
130 -                   ret = addr;\r
131 -           } else {\r
132 +               if (user_from && *user_from == NULL)\r
133 +                   *user_from = addr;\r
134 +           } else if (message) {\r
135                 g_mime_message_add_recipient (message, type, name, addr);\r
136 +               n++;\r
137             }\r
138         }\r
139      }\r
140  \r
141 -    return ret;\r
142 +    return n;\r
143  }\r
144  \r
145 -/* For each address in 'recipients' that is not configured as one of\r
146 - * the user's addresses in 'config', add that address to 'message' as\r
147 - * an address of 'type'.\r
148 +/* Scan addresses in 'recipients'.\r
149   *\r
150 - * The first address encountered that *is* the user's address will be\r
151 - * returned, (otherwise NULL is returned).\r
152 + * See the documentation of scan_address_list() above. This function does\r
153 + * exactly the same, but converts 'recipients' to an InternetAddressList first.\r
154   */\r
155 -static const char *\r
156 -add_recipients_for_string (GMimeMessage *message,\r
157 -                          notmuch_config_t *config,\r
158 -                          GMimeRecipientType type,\r
159 -                          const char *recipients)\r
160 +static unsigned int\r
161 +scan_address_string (const char *recipients,\r
162 +                    notmuch_config_t *config,\r
163 +                    GMimeMessage *message,\r
164 +                    GMimeRecipientType type,\r
165 +                    const char **user_from)\r
166  {\r
167      InternetAddressList *list;\r
168  \r
169      if (recipients == NULL)\r
170 -       return NULL;\r
171 +       return 0;\r
172  \r
173      list = internet_address_list_parse_string (recipients);\r
174      if (list == NULL)\r
175 -       return NULL;\r
176 +       return 0;\r
177  \r
178 -    return add_recipients_for_address_list (message, config, type, list);\r
179 +    return scan_address_list (list, config, message, type, user_from);\r
180  }\r
181  \r
182  /* Does the address in the Reply-To header of 'message' already appear\r
183 @@ -324,7 +329,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
184      }\r
185  \r
186      for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
187 -       const char *addr, *recipients;\r
188 +       const char *recipients;\r
189  \r
190         recipients = notmuch_message_get_header (message,\r
191                                                  reply_to_map[i].header);\r
192 @@ -332,11 +337,8 @@ add_recipients_from_message (GMimeMessage *reply,\r
193             recipients = notmuch_message_get_header (message,\r
194                                                      reply_to_map[i].fallback);\r
195  \r
196 -       addr = add_recipients_for_string (reply, config,\r
197 -                                         reply_to_map[i].recipient_type,\r
198 -                                         recipients);\r
199 -       if (from_addr == NULL)\r
200 -           from_addr = addr;\r
201 +       scan_address_string (recipients, config, reply,\r
202 +                            reply_to_map[i].recipient_type, &from_addr);\r
203      }\r
204  \r
205      return from_addr;\r
206 -- \r
207 1.7.5.4\r
208 \r