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