Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 74 / d0549dd8cdc86ab2ff987008c9880d900924fd
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 0CB8D4916AE\r
6         for <notmuch@notmuchmail.org>; Wed, 10 Mar 2010 08:31:54 -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: -5.186\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-5.186 tagged_above=-999 required=5 tests=[AWL=1.413,\r
12         BAYES_00=-2.599, 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 J5LAZKI3sq37 for <notmuch@notmuchmail.org>;\r
16         Wed, 10 Mar 2010 08:31:51 -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 350884916B5\r
19         for <notmuch@notmuchmail.org>; Wed, 10 Mar 2010 08:31:50 -0800 (PST)\r
20 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247])\r
21         by e23smtp07.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2AGVV6r010202\r
22         for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:31:31 +1100\r
23 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139])\r
24         by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
25         o2AGPhwl1630298\r
26         for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:25:44 +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         o2AGVTOn008214\r
30         for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:31:30 +1100\r
31 Received: from localhost.localdomain ([9.124.221.30])\r
32         by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
33         o2AGVSYe008190; Thu, 11 Mar 2010 03:31:28 +1100\r
34 From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
35 To: cworth@cworth.org\r
36 Date: Wed, 10 Mar 2010 22:01:25 +0530\r
37 Message-Id:\r
38  <1268238686-13605-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
39 X-Mailer: git-send-email 1.7.0.2.157.gb7e7f\r
40 In-Reply-To: <87zl2hic7d.fsf@yoom.home.cworth.org>\r
41 References: <87zl2hic7d.fsf@yoom.home.cworth.org>\r
42 Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>, notmuch@notmuchmail.org\r
43 Subject: [notmuch] [PATCH -V3 1/2] notmuch-reply: Add support for replying\r
44         only to sender\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Wed, 10 Mar 2010 16:31:54 -0000\r
58 \r
59 From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
60 \r
61 This patch add --recipient=all|sender option\r
62 \r
63 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
64 ---\r
65  notmuch-client.h |    2 +\r
66  notmuch-reply.c  |   55 ++++++++++++++++++++++++++++++++++++++++-------------\r
67  2 files changed, 43 insertions(+), 14 deletions(-)\r
68 \r
69 diff --git a/notmuch-client.h b/notmuch-client.h\r
70 index c80b39c..26fdb4a 100644\r
71 --- a/notmuch-client.h\r
72 +++ b/notmuch-client.h\r
73 @@ -70,6 +70,8 @@\r
74  #define STRNCMP_LITERAL(var, literal) \\r
75      strncmp ((var), (literal), sizeof (literal) - 1)\r
76  \r
77 +#define NOTMUCH_REPLY_ALL   0x1\r
78 +#define NOTMUCH_REPLY_SENDER_ONLY 0x2\r
79  static inline void\r
80  chomp_newline (char *str)\r
81  {\r
82 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
83 index 6c15536..e8a0820 100644\r
84 --- a/notmuch-reply.c\r
85 +++ b/notmuch-reply.c\r
86 @@ -232,20 +232,37 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
87  static const char *\r
88  add_recipients_from_message (GMimeMessage *reply,\r
89                              notmuch_config_t *config,\r
90 -                            notmuch_message_t *message)\r
91 +                            notmuch_message_t *message,\r
92 +                            int reply_options)\r
93  {\r
94 -    struct {\r
95 +    struct reply_to_map {\r
96         const char *header;\r
97         const char *fallback;\r
98         GMimeRecipientType recipient_type;\r
99 -    } reply_to_map[] = {\r
100 +    } ;\r
101 +    const char *from_addr = NULL;\r
102 +    unsigned int i;\r
103 +    struct reply_to_map *reply_to_map;\r
104 +\r
105 +    struct reply_to_map reply_to_map_all[] = {\r
106         { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },\r
107         { "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },\r
108         { "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },\r
109 -       { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }\r
110 +       { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC },\r
111 +       {  NULL,        NULL, 0 }\r
112      };\r
113 -    const char *from_addr = NULL;\r
114 -    unsigned int i;\r
115 +\r
116 +    /* we try from first and then reply-to */\r
117 +    struct reply_to_map reply_to_map_sender[] = {\r
118 +       { "from", "reply-to", GMIME_RECIPIENT_TYPE_TO  },\r
119 +       {  NULL,        NULL, 0 }\r
120 +    };\r
121 +\r
122 +    if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) {\r
123 +       reply_to_map = reply_to_map_sender;\r
124 +    } else {\r
125 +       reply_to_map = reply_to_map_all;\r
126 +    }\r
127  \r
128      /* Some mailing lists munge the Reply-To header despite it being A Bad\r
129       * Thing, see http://www.unicom.com/pw/reply-to-harmful.html\r
130 @@ -263,7 +280,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
131         reply_to_map[0].fallback = NULL;\r
132      }\r
133  \r
134 -    for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
135 +    for (i = 0; reply_to_map[i].header; i++) {\r
136         const char *addr, *recipients;\r
137  \r
138         recipients = notmuch_message_get_header (message,\r
139 @@ -283,7 +300,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
140  }\r
141  \r
142  static int\r
143 -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
144 +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)\r
145  {\r
146      GMimeMessage *reply;\r
147      notmuch_messages_t *messages;\r
148 @@ -311,7 +328,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
149             subject = talloc_asprintf (ctx, "Re: %s", subject);\r
150         g_mime_message_set_subject (reply, subject);\r
151  \r
152 -       from_addr = add_recipients_from_message (reply, config, message);\r
153 +       from_addr = add_recipients_from_message (reply, config, message, reply_options);\r
154  \r
155         if (from_addr == NULL)\r
156             from_addr = notmuch_config_get_user_primary_email (config);\r
157 @@ -359,7 +376,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
158  \r
159  /* This format is currently tuned for a git send-email --notmuch hook */\r
160  static int\r
161 -notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
162 +notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)\r
163  {\r
164      GMimeMessage *reply;\r
165      notmuch_messages_t *messages;\r
166 @@ -399,7 +416,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q\r
167         g_mime_object_set_header (GMIME_OBJECT (reply),\r
168                                   "References", references);\r
169  \r
170 -       (void)add_recipients_from_message (reply, config, message);\r
171 +       (void)add_recipients_from_message (reply, config, message, reply_options);\r
172  \r
173         g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",\r
174                            notmuch_config_get_user_primary_email (config));\r
175 @@ -423,8 +440,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
176      notmuch_database_t *notmuch;\r
177      notmuch_query_t *query;\r
178      char *opt, *query_string;\r
179 -    int i, ret = 0;\r
180 -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query);\r
181 +    int i, ret = 0, reply_to = NOTMUCH_REPLY_ALL;\r
182 +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options);\r
183  \r
184      reply_format_func = notmuch_reply_format_default;\r
185  \r
186 @@ -443,6 +460,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
187                 fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
188                 return 1;\r
189             }\r
190 +       } else if (STRNCMP_LITERAL (argv[i], "--recipient=") == 0) {\r
191 +           opt = argv[i] + sizeof ("--recipient=") - 1;\r
192 +           if (strcmp (opt, "all") == 0) {\r
193 +               reply_to = NOTMUCH_REPLY_ALL;\r
194 +           } else if (strcmp (opt, "sender") == 0) {\r
195 +               reply_to = NOTMUCH_REPLY_SENDER_ONLY;\r
196 +           } else {\r
197 +               fprintf (stderr, "Invalid value for --recipient: %s\n", opt);\r
198 +               return 1;\r
199 +           }\r
200         } else {\r
201             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
202             return 1;\r
203 @@ -478,7 +505,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
204         return 1;\r
205      }\r
206  \r
207 -    if (reply_format_func (ctx, config, query) != 0)\r
208 +    if (reply_format_func (ctx, config, query, reply_to) != 0)\r
209         return 1;\r
210  \r
211      notmuch_query_destroy (query);\r
212 -- \r
213 1.7.0.2.157.gb7e7f\r
214 \r