[notmuch] [PATCH -V2] notmuch-reply: Add support for replying only to sender
[notmuch-archives.git] / a9 / 203ddf144c2a0f72e6ff35e0fb018854570ed5
1 Return-Path: <aneesh.kumar@linux.vnet.ibm.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 52D61431FBF\r
6         for <notmuch@notmuchmail.org>; Sat,  5 Dec 2009 01:38:08 -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 vJrfds3Kd2tW for <notmuch@notmuchmail.org>;\r
11         Sat,  5 Dec 2009 01:38:07 -0800 (PST)\r
12 Received: from e23smtp08.au.ibm.com (e23smtp08.au.ibm.com [202.81.31.141])\r
13         by olra.theworths.org (Postfix) with ESMTP id 56302431FBC\r
14         for <notmuch@notmuchmail.org>; Sat,  5 Dec 2009 01:38:07 -0800 (PST)\r
15 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247])\r
16         by e23smtp08.au.ibm.com (8.14.3/8.13.1) with ESMTP id nB5Kc5Ro028850\r
17         for <notmuch@notmuchmail.org>; Sun, 6 Dec 2009 07:38:05 +1100\r
18 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139])\r
19         by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
20         nB59YJlZ1589450\r
21         for <notmuch@notmuchmail.org>; Sat, 5 Dec 2009 20:34:21 +1100\r
22 Received: from d23av04.au.ibm.com (loopback [127.0.0.1])\r
23         by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
24         nB59c2Kt007326\r
25         for <notmuch@notmuchmail.org>; Sat, 5 Dec 2009 20:38:02 +1100\r
26 Received: from localhost.localdomain ([9.77.207.152])\r
27         by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
28         nB59c0n6007312; Sat, 5 Dec 2009 20:38:00 +1100\r
29 From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
30 To: cworth@cworth.org, aneesh.kumar@linux.vnet.ibm.com\r
31 Date: Sat,  5 Dec 2009 15:07:58 +0530\r
32 Message-Id:\r
33  <1260005878-18500-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
34 X-Mailer: git-send-email 1.6.5.2.74.g610f9\r
35 In-Reply-To:\r
36  <1259830005-3439-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
37 References: <1259830005-3439-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
38 Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>, notmuch@notmuchmail.org\r
39 Subject: [notmuch] [PATCH -V2] notmuch-reply: Add support for replying only\r
40         to sender\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.12\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sat, 05 Dec 2009 09:38:08 -0000\r
54 \r
55 From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
56 \r
57 This patch add --format=sender-only option.\r
58 \r
59 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
60 ---\r
61  notmuch-reply.c |   54 ++++++++++++++++++++++++++++++++++++++++--------------\r
62  1 files changed, 40 insertions(+), 14 deletions(-)\r
63 \r
64 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
65 index 0cda72d..859b725 100644\r
66 --- a/notmuch-reply.c\r
67 +++ b/notmuch-reply.c\r
68 @@ -23,15 +23,23 @@\r
69  #include "notmuch-client.h"\r
70  #include "gmime-filter-reply.h"\r
71  \r
72 -static const struct {\r
73 +struct reply_map {\r
74      const char *header;\r
75      const char *fallback;\r
76      GMimeRecipientType recipient_type;\r
77 -} reply_to_map[] = {\r
78 +};\r
79 +\r
80 +static const struct reply_map reply_to_all_map[] = {\r
81      { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },\r
82      { "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },\r
83      { "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },\r
84 -    { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }\r
85 +    { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC },\r
86 +    { NULL,         NULL, 0}\r
87 +};\r
88 +\r
89 +static const struct reply_map reply_to_sender_map[] = {\r
90 +    { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },\r
91 +    { NULL,         NULL, 0}\r
92  };\r
93  \r
94  static void\r
95 @@ -200,7 +208,8 @@ add_recipients_for_string (GMimeMessage *message,\r
96  }\r
97  \r
98  static int\r
99 -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
100 +__notmuch_reply(void *ctx, notmuch_config_t *config,\r
101 +               notmuch_query_t *query, const struct reply_map *map)\r
102  {\r
103      GMimeMessage *reply;\r
104      notmuch_messages_t *messages;\r
105 @@ -229,17 +238,19 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
106             subject = talloc_asprintf (ctx, "Re: %s", subject);\r
107         g_mime_message_set_subject (reply, subject);\r
108  \r
109 -       for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
110 +       for (i = 0;; i++) {\r
111             const char *addr;\r
112  \r
113 +           if (!map[i].header)\r
114 +                   break;\r
115             recipients = notmuch_message_get_header (message,\r
116 -                                                    reply_to_map[i].header);\r
117 -           if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)\r
118 +                                                   map[i].header);\r
119 +           if ((recipients == NULL || recipients[0] == '\0') && map[i].fallback)\r
120                 recipients = notmuch_message_get_header (message,\r
121 -                                                        reply_to_map[i].fallback);\r
122 +                                                        map[i].fallback);\r
123  \r
124             addr = add_recipients_for_string (reply, config,\r
125 -                                             reply_to_map[i].recipient_type,\r
126 +                                             map[i].recipient_type,\r
127                                               recipients);\r
128             if (from_addr == NULL)\r
129                 from_addr = addr;\r
130 @@ -289,6 +300,12 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
131      return 0;\r
132  }\r
133  \r
134 +static int\r
135 +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
136 +{\r
137 +       return __notmuch_reply(ctx, config, query, reply_to_all_map);\r
138 +}\r
139 +\r
140  /* This format is currently tuned for a git send-email --notmuch hook */\r
141  static int\r
142  notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
143 @@ -332,17 +349,18 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q\r
144         g_mime_object_set_header (GMIME_OBJECT (reply),\r
145                                   "References", references);\r
146  \r
147 -       for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
148 +       for (i = 0; i < ARRAY_SIZE (reply_to_all_map); i++) {\r
149             const char *addr;\r
150  \r
151             recipients = notmuch_message_get_header (message,\r
152 -                                                    reply_to_map[i].header);\r
153 -           if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)\r
154 +                                                    reply_to_all_map[i].header);\r
155 +           if ((recipients == NULL || recipients[0] == '\0') &&\r
156 +                                       reply_to_all_map[i].fallback)\r
157                 recipients = notmuch_message_get_header (message,\r
158 -                                                        reply_to_map[i].fallback);\r
159 +                                                reply_to_all_map[i].fallback);\r
160  \r
161             addr = add_recipients_for_string (reply, config,\r
162 -                                             reply_to_map[i].recipient_type,\r
163 +                                             reply_to_all_map[i].recipient_type,\r
164                                               recipients);\r
165         }\r
166  \r
167 @@ -361,6 +379,12 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q\r
168      return 0;\r
169  }\r
170  \r
171 +static int\r
172 +notmuch_reply_format_sender_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
173 +{\r
174 +       return __notmuch_reply(ctx, config, query, reply_to_sender_map);\r
175 +}\r
176 +\r
177  int\r
178  notmuch_reply_command (void *ctx, int argc, char *argv[])\r
179  {\r
180 @@ -384,6 +408,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
181                 reply_format_func = notmuch_reply_format_default;\r
182             } else if (strcmp (opt, "headers-only") == 0) {\r
183                 reply_format_func = notmuch_reply_format_headers_only;\r
184 +           } else if (strcmp (opt, "sender-only") == 0) {\r
185 +               reply_format_func = notmuch_reply_format_sender_only;\r
186             } else {\r
187                 fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
188                 return 1;\r
189 -- \r
190 1.6.5.2.74.g610f9\r
191 \r