[RFC PATCH] test: add devel/test-in-docker.sh
[notmuch-archives.git] / ee / 980266331ced4f76e83c88ec555569839ca1d4
1 Return-Path: <kushal.kumaran@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 5A524431FB6\r
6         for <notmuch@notmuchmail.org>; Tue,  4 Dec 2012 01:42:58 -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.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, 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 tBvTCPWgo2bO for <notmuch@notmuchmail.org>;\r
17         Tue,  4 Dec 2012 01:42:57 -0800 (PST)\r
18 Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com\r
19         [209.85.220.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id A5C23431FAE\r
22         for <notmuch@notmuchmail.org>; Tue,  4 Dec 2012 01:42:57 -0800 (PST)\r
23 Received: by mail-pa0-f53.google.com with SMTP id hz1so2720336pad.26\r
24         for <notmuch@notmuchmail.org>; Tue, 04 Dec 2012 01:42:56 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=sender:from:to:subject:user-agent:date:message-id:mime-version\r
27         :content-type; bh=DtnATiaPfUta2NiUFCsfruTt4XpISb+275heM/CvfeI=;\r
28         b=DSEOS+sa77FEdGTIi4uAwfRcoHOfofPn3lhCSShjN7AmPaGqovqgh5MPoJT0zItbNP\r
29         H2z3DZdYVKRfMLIM1qTlFQxJLWczw3UhMP+fHt9AhiefqwtJ6fHgOlfCrJ29t1bYu6ZY\r
30         GqNJo0Qny/SpsbR+/Lar2Cjnf05PxbBiisV+S2RjOrj32wyqN5sRE5ln3+YBNZrGXKFR\r
31         5MqJWg84E9VND9gmRBwSWRPR9kN+34iuVxwgXi1dhLksFIQWaSFIYGk2KmruwR+rNmIF\r
32         0YK1M+L42Vj5u5R6TgHyA9ejff/lv+aNTbJKh6FYkbcY2USgespBQ6wiDtZgm9EbDSI+\r
33         xHFw==\r
34 Received: by 10.68.232.195 with SMTP id tq3mr37183050pbc.70.1354614176862;\r
35         Tue, 04 Dec 2012 01:42:56 -0800 (PST)\r
36 Received: from nitrogen ([117.219.4.209])\r
37         by mx.google.com with ESMTPS id ay5sm534700pab.1.2012.12.04.01.42.54\r
38         (version=TLSv1/SSLv3 cipher=OTHER);\r
39         Tue, 04 Dec 2012 01:42:56 -0800 (PST)\r
40 Sender: Kushal Kumaran <kushal.kumaran@gmail.com>\r
41 Received: by nitrogen (Postfix, from userid 1000)\r
42         id 230581201C1; Tue,  4 Dec 2012 15:12:50 +0530 (IST)\r
43 From: Kushal Kumaran <kushal.kumaran+notmuch@gmail.com>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: using the List-Post header to reply to mailing lists\r
46 User-Agent: Notmuch/0.14+83~gae459a3 (http://notmuchmail.org) Emacs/24.1.1\r
47         (x86_64-pc-linux-gnu)\r
48 Date: Tue, 04 Dec 2012 15:12:50 +0530\r
49 Message-ID: <50bdc5a0.8557420a.08a9.324b@mx.google.com>\r
50 MIME-Version: 1.0\r
51 Content-Type: text/plain\r
52 X-BeenThere: notmuch@notmuchmail.org\r
53 X-Mailman-Version: 2.1.13\r
54 Precedence: list\r
55 List-Id: "Use and development of the notmuch mail system."\r
56         <notmuch.notmuchmail.org>\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
60 List-Post: <mailto:notmuch@notmuchmail.org>\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
64 X-List-Received-Date: Tue, 04 Dec 2012 09:42:58 -0000\r
65 \r
66 Hi,\r
67 \r
68 I've been using notmuch with emacs for a while now.  I subscribe to a\r
69 few mailing lists where Reply-To-All is severely frowned upon, so I\r
70 wanted to be able to use the List-Post header (RFC2369) when replying to\r
71 mailing list posts.  I've hacked notmuch-reply.c for my purposes, but I\r
72 was wondering how other people manage.\r
73 \r
74 As it stands, this patch is entirely unsuitable for merging.  At least\r
75 the following issues will need to be resolved first:\r
76 \r
77 - should an additional command-line option be added to invoke this\r
78   behaviour?  My personal preference is to just use the List-Post header\r
79   whenever possible, if --reply-to=all is not given.\r
80 \r
81 - should anything be done if the List-Post header has a URL which is not\r
82   a mailto: URL (start a web browser?).  None of the mailing lists I'm\r
83   subscribed to puts anything other than mailto.  The patch ignores the\r
84   header if the URL is not a mailto.\r
85 \r
86 - needs tests\r
87 \r
88 - needs documentation\r
89 \r
90 If anyone has alternatives to doing this kind of URL parsing, I'm\r
91 interested.  Comments regarding my pathetic knowledge of gmime are also\r
92 welcome.  If no one things notmuch needs this functionality, I will just\r
93 hold on to it for my personal use.\r
94 \r
95 ---\r
96  notmuch-reply.c |   68 ++++++++++++++++++++++++++++++++++++++++++++++++-------\r
97  1 file changed, 60 insertions(+), 8 deletions(-)\r
98 \r
99 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
100 index e60a264..82f5a35 100644\r
101 --- a/notmuch-reply.c\r
102 +++ b/notmuch-reply.c\r
103 @@ -172,6 +172,11 @@ address_is_users (const char *address, notmuch_config_t *config)\r
104      return address_match (address, config, STRING_IS_USER_ADDRESS) != NULL;\r
105  }\r
106 \r
107 +typedef enum {\r
108 +    rfc822,\r
109 +    url\r
110 +} address_format_t;\r
111 +\r
112  /* Scan addresses in 'list'.\r
113   *\r
114   * If 'message' is non-NULL, then for each address in 'list' that is\r
115 @@ -231,6 +236,37 @@ scan_address_list (InternetAddressList *list,\r
116      return n;\r
117  }\r
118 \r
119 +InternetAddressList *list_post_url_to_address_list(const char *header_value) {\r
120 +    size_t recipients_len = strlen(header_value);\r
121 +    size_t list_post_prefix_len = strlen("<mailto:");\r
122 +    char *list_post_url;\r
123 +    InternetAddressList *list;\r
124 +    InternetAddress *list_post_addr;\r
125 +\r
126 +    recipients_len = strlen(header_value);\r
127 +\r
128 +    if (strncmp(header_value, "<mailto:", list_post_prefix_len) != 0) {\r
129 +       return NULL;\r
130 +    }\r
131 +\r
132 +    if (header_value[recipients_len - 1] != '>') {\r
133 +       return NULL;\r
134 +    }\r
135 +\r
136 +    list_post_url = xstrdup(header_value);\r
137 +    list_post_url[recipients_len - 1] = '\0';\r
138 +    list_post_addr = internet_address_mailbox_new(NULL, list_post_url +\r
139 +                                                 list_post_prefix_len);\r
140 +    list = internet_address_list_new();\r
141 +    if (list == NULL) {\r
142 +       return NULL;\r
143 +    }\r
144 +    internet_address_list_add(list, list_post_addr);\r
145 +    free(list_post_url);\r
146 +\r
147 +    return list;\r
148 +}\r
149 +\r
150  /* Scan addresses in 'recipients'.\r
151   *\r
152   * See the documentation of scan_address_list() above. This function\r
153 @@ -242,6 +278,7 @@ scan_address_string (const char *recipients,\r
154                      notmuch_config_t *config,\r
155                      GMimeMessage *message,\r
156                      GMimeRecipientType type,\r
157 +                    address_format_t format,\r
158                      const char **user_from)\r
159  {\r
160      InternetAddressList *list;\r
161 @@ -249,9 +286,21 @@ scan_address_string (const char *recipients,\r
162      if (recipients == NULL)\r
163         return 0;\r
164 \r
165 -    list = internet_address_list_parse_string (recipients);\r
166 -    if (list == NULL)\r
167 -       return 0;\r
168 +    switch (format) {\r
169 +    case rfc822:\r
170 +       list = internet_address_list_parse_string (recipients);\r
171 +       if (list == NULL)\r
172 +           return 0;\r
173 +\r
174 +       break;\r
175 +\r
176 +    case url:\r
177 +       list = list_post_url_to_address_list (recipients);\r
178 +       if (list == NULL)\r
179 +           return 0;\r
180 +\r
181 +       break;\r
182 +    }\r
183 \r
184      return scan_address_list (list, config, message, type, user_from);\r
185  }\r
186 @@ -317,11 +366,13 @@ add_recipients_from_message (GMimeMessage *reply,\r
187         const char *header;\r
188         const char *fallback;\r
189         GMimeRecipientType recipient_type;\r
190 +       address_format_t format;\r
191      } reply_to_map[] = {\r
192 -       { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },\r
193 -       { "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },\r
194 -       { "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },\r
195 -       { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }\r
196 +       { "list-post",  NULL, GMIME_RECIPIENT_TYPE_TO,  url },\r
197 +       { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO,  rfc822  },\r
198 +       { "to",         NULL, GMIME_RECIPIENT_TYPE_TO,  rfc822  },\r
199 +       { "cc",         NULL, GMIME_RECIPIENT_TYPE_CC,  rfc822  },\r
200 +       { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC, rfc822  }\r
201      };\r
202      const char *from_addr = NULL;\r
203      unsigned int i;\r
204 @@ -353,7 +404,8 @@ add_recipients_from_message (GMimeMessage *reply,\r
205                                                      reply_to_map[i].fallback);\r
206 \r
207         n += scan_address_string (recipients, config, reply,\r
208 -                                 reply_to_map[i].recipient_type, &from_addr);\r
209 +                                 reply_to_map[i].recipient_type,\r
210 +                                 reply_to_map[i].format, &from_addr);\r
211 \r
212         if (!reply_all && n) {\r
213             /* Stop adding new recipients in reply-to-sender mode if\r
214 [ 2-line signature. Click/Enter to show. ]\r
215 -- \r
216 1.7.10.4\r