Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 0b / 50f086e54d275c8173814af30ccbe9c0e53eff
1 Return-Path: <Sebastian@SSpaeth.de>\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 B0CB74196F4\r
6         for <notmuch@notmuchmail.org>; Tue,  6 Apr 2010 00:12:55 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham\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 eKN1ALxbBb7b for <notmuch@notmuchmail.org>;\r
16         Tue,  6 Apr 2010 00:12:54 -0700 (PDT)\r
17 Received: from homiemail-a19.g.dreamhost.com (caiajhbdcaid.dreamhost.com\r
18         [208.97.132.83])\r
19         by olra.theworths.org (Postfix) with ESMTP id 634434196F0\r
20         for <notmuch@notmuchmail.org>; Tue,  6 Apr 2010 00:12:54 -0700 (PDT)\r
21 Received: from localhost.localdomain (mtec-hg-docking-1-dhcp-204.ethz.ch\r
22         [129.132.133.204])\r
23         by homiemail-a19.g.dreamhost.com (Postfix) with ESMTPA id 5308260405D; \r
24         Tue,  6 Apr 2010 00:12:53 -0700 (PDT)\r
25 From: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [PATCH 1/2] notmuch-reply: Add support for replying only to sender\r
28 Date: Tue,  6 Apr 2010 09:12:45 +0200\r
29 Message-Id: <1270537966-19324-1-git-send-email-Sebastian@SSpaeth.de>\r
30 X-Mailer: git-send-email 1.6.3.3\r
31 In-Reply-To: <87mxxhgims.fsf@SSpaeth.de>\r
32 References: <87mxxhgims.fsf@SSpaeth.de>\r
33 Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Tue, 06 Apr 2010 07:12:55 -0000\r
47 \r
48 From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
49 \r
50 This patch add --recipient=all|sender option\r
51 \r
52 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
53 ---\r
54  notmuch-client.h |    2 +\r
55  notmuch-reply.c  |   55 ++++++++++++++++++++++++++++++++++++++++-------------\r
56  2 files changed, 43 insertions(+), 14 deletions(-)\r
57 \r
58 diff --git a/notmuch-client.h b/notmuch-client.h\r
59 index d36b9ec..3ca4b32 100644\r
60 --- a/notmuch-client.h\r
61 +++ b/notmuch-client.h\r
62 @@ -73,6 +73,8 @@\r
63  #define STRNCMP_LITERAL(var, literal) \\r
64      strncmp ((var), (literal), sizeof (literal) - 1)\r
65  \r
66 +#define NOTMUCH_REPLY_ALL   0x1\r
67 +#define NOTMUCH_REPLY_SENDER_ONLY 0x2\r
68  static inline void\r
69  chomp_newline (char *str)\r
70  {\r
71 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
72 index 6c15536..e8a0820 100644\r
73 --- a/notmuch-reply.c\r
74 +++ b/notmuch-reply.c\r
75 @@ -232,20 +232,37 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
76  static const char *\r
77  add_recipients_from_message (GMimeMessage *reply,\r
78                              notmuch_config_t *config,\r
79 -                            notmuch_message_t *message)\r
80 +                            notmuch_message_t *message,\r
81 +                            int reply_options)\r
82  {\r
83 -    struct {\r
84 +    struct reply_to_map {\r
85         const char *header;\r
86         const char *fallback;\r
87         GMimeRecipientType recipient_type;\r
88 -    } reply_to_map[] = {\r
89 +    } ;\r
90 +    const char *from_addr = NULL;\r
91 +    unsigned int i;\r
92 +    struct reply_to_map *reply_to_map;\r
93 +\r
94 +    struct reply_to_map reply_to_map_all[] = {\r
95         { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },\r
96         { "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },\r
97         { "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },\r
98 -       { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }\r
99 +       { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC },\r
100 +       {  NULL,        NULL, 0 }\r
101      };\r
102 -    const char *from_addr = NULL;\r
103 -    unsigned int i;\r
104 +\r
105 +    /* we try from first and then reply-to */\r
106 +    struct reply_to_map reply_to_map_sender[] = {\r
107 +       { "from", "reply-to", GMIME_RECIPIENT_TYPE_TO  },\r
108 +       {  NULL,        NULL, 0 }\r
109 +    };\r
110 +\r
111 +    if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) {\r
112 +       reply_to_map = reply_to_map_sender;\r
113 +    } else {\r
114 +       reply_to_map = reply_to_map_all;\r
115 +    }\r
116  \r
117      /* Some mailing lists munge the Reply-To header despite it being A Bad\r
118       * Thing, see http://www.unicom.com/pw/reply-to-harmful.html\r
119 @@ -263,7 +280,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
120         reply_to_map[0].fallback = NULL;\r
121      }\r
122  \r
123 -    for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
124 +    for (i = 0; reply_to_map[i].header; i++) {\r
125         const char *addr, *recipients;\r
126  \r
127         recipients = notmuch_message_get_header (message,\r
128 @@ -283,7 +300,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
129  }\r
130  \r
131  static int\r
132 -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
133 +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)\r
134  {\r
135      GMimeMessage *reply;\r
136      notmuch_messages_t *messages;\r
137 @@ -311,7 +328,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
138             subject = talloc_asprintf (ctx, "Re: %s", subject);\r
139         g_mime_message_set_subject (reply, subject);\r
140  \r
141 -       from_addr = add_recipients_from_message (reply, config, message);\r
142 +       from_addr = add_recipients_from_message (reply, config, message, reply_options);\r
143  \r
144         if (from_addr == NULL)\r
145             from_addr = notmuch_config_get_user_primary_email (config);\r
146 @@ -359,7 +376,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
147  \r
148  /* This format is currently tuned for a git send-email --notmuch hook */\r
149  static int\r
150 -notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
151 +notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options)\r
152  {\r
153      GMimeMessage *reply;\r
154      notmuch_messages_t *messages;\r
155 @@ -399,7 +416,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q\r
156         g_mime_object_set_header (GMIME_OBJECT (reply),\r
157                                   "References", references);\r
158  \r
159 -       (void)add_recipients_from_message (reply, config, message);\r
160 +       (void)add_recipients_from_message (reply, config, message, reply_options);\r
161  \r
162         g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",\r
163                            notmuch_config_get_user_primary_email (config));\r
164 @@ -423,8 +440,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
165      notmuch_database_t *notmuch;\r
166      notmuch_query_t *query;\r
167      char *opt, *query_string;\r
168 -    int i, ret = 0;\r
169 -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query);\r
170 +    int i, ret = 0, reply_to = NOTMUCH_REPLY_ALL;\r
171 +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options);\r
172  \r
173      reply_format_func = notmuch_reply_format_default;\r
174  \r
175 @@ -443,6 +460,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
176                 fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
177                 return 1;\r
178             }\r
179 +       } else if (STRNCMP_LITERAL (argv[i], "--recipient=") == 0) {\r
180 +           opt = argv[i] + sizeof ("--recipient=") - 1;\r
181 +           if (strcmp (opt, "all") == 0) {\r
182 +               reply_to = NOTMUCH_REPLY_ALL;\r
183 +           } else if (strcmp (opt, "sender") == 0) {\r
184 +               reply_to = NOTMUCH_REPLY_SENDER_ONLY;\r
185 +           } else {\r
186 +               fprintf (stderr, "Invalid value for --recipient: %s\n", opt);\r
187 +               return 1;\r
188 +           }\r
189         } else {\r
190             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
191             return 1;\r
192 @@ -478,7 +505,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
193         return 1;\r
194      }\r
195  \r
196 -    if (reply_format_func (ctx, config, query) != 0)\r
197 +    if (reply_format_func (ctx, config, query, reply_to) != 0)\r
198         return 1;\r
199  \r
200      notmuch_query_destroy (query);\r
201 -- \r
202 1.6.3.3\r
203 \r