1 Return-Path: <five9a2@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 B45A5431FBC
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 17:35:12 -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 ypHYMU4q4yqe for <notmuch@notmuchmail.org>;
\r
11 Tue, 24 Nov 2009 17:35:12 -0800 (PST)
\r
12 Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com
\r
14 by olra.theworths.org (Postfix) with ESMTP id D0FE0431FC2
\r
15 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 17:35:11 -0800 (PST)
\r
16 Received: by mail-bw0-f224.google.com with SMTP id 24so5514914bwz.30
\r
17 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 17:35:11 -0800 (PST)
\r
18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
19 h=domainkey-signature:received:received:sender:from:to:cc:subject
\r
20 :date:message-id:x-mailer:in-reply-to:references;
\r
21 bh=ZwuYLICj5WOi56vRA5vpD22zPJ0OU2fik+/HhvuZnX4=;
\r
22 b=lD2s99vp6nNo1oVlz01oHKRPq9VUpp8xE23ATFlRuSY/AtJKhowdXKxcx1nX07xeiC
\r
23 4lwvS5/09ZDnCyBO5Tm4JZGOppPKI4lX2HF1f0F1ijkwIn5RQ3T644cngmeUxPmcpRJM
\r
24 qo8R4B249jvqHnZks5cdpCQpykQadlrex+0CA=
\r
25 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
\r
26 h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
28 b=bRIDD2dDu2cXUtH8Auvria0nF4Y7jFpPeuQLdwZ7/oNSsT4FE0lVef9zCg9UfErRRf
\r
29 irsZIH0zginzx1GJM7WVczvxyOcH375/1tYlkFCU1/YZDRewm2JKLcdl/tFLieEACz9w
\r
30 kPpjaTHUTTlk2JW5yXJbtJAHBKcrGqE1WZ92A=
\r
31 Received: by 10.204.10.8 with SMTP id n8mr6923194bkn.48.1259112911049;
\r
32 Tue, 24 Nov 2009 17:35:11 -0800 (PST)
\r
33 Received: from localhost.localdomain (vawpc43.ethz.ch [129.132.59.11])
\r
34 by mx.google.com with ESMTPS id 35sm7911394fkt.40.2009.11.24.17.35.09
\r
35 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
36 Tue, 24 Nov 2009 17:35:10 -0800 (PST)
\r
37 Sender: Jed Brown <five9a2@gmail.com>
\r
38 From: Jed Brown <jed@59A2.org>
\r
39 To: notmuch@notmuchmail.org
\r
40 Date: Wed, 25 Nov 2009 02:35:13 +0100
\r
41 Message-Id: <1259112914-19806-2-git-send-email-jed@59A2.org>
\r
42 X-Mailer: git-send-email 1.6.5.3
\r
43 In-Reply-To: <1259112914-19806-1-git-send-email-jed@59A2.org>
\r
44 References: <1259112914-19806-1-git-send-email-jed@59A2.org>
\r
45 Subject: [notmuch] [PATCH 1/2] notmuch-reply.c: accept the --format=default
\r
47 X-BeenThere: notmuch@notmuchmail.org
\r
48 X-Mailman-Version: 2.1.12
\r
50 List-Id: "Use and development of the notmuch mail system."
\r
51 <notmuch.notmuchmail.org>
\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
55 List-Post: <mailto:notmuch@notmuchmail.org>
\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
59 X-List-Received-Date: Wed, 25 Nov 2009 01:35:12 -0000
\r
61 This factors actual generation of the reply out of notmuch_reply_command
\r
62 into notmuch_reply_format_default(), in preparation for other --format=
\r
65 Signed-off-by: Jed Brown <jed@59A2.org>
\r
67 notmuch-reply.c | 121 +++++++++++++++++++++++++++++++++++-------------------
\r
68 1 files changed, 78 insertions(+), 43 deletions(-)
\r
70 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
71 index 65bd356..17eb38d 100644
\r
72 --- a/notmuch-reply.c
\r
73 +++ b/notmuch-reply.c
\r
75 #include "notmuch-client.h"
\r
76 #include "gmime-filter-reply.h"
\r
78 +static const struct {
\r
79 + const char *header;
\r
80 + const char *fallback;
\r
81 + GMimeRecipientType recipient_type;
\r
82 +} reply_to_map[] = {
\r
83 + { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO },
\r
84 + { "to", NULL, GMIME_RECIPIENT_TYPE_TO },
\r
85 + { "cc", NULL, GMIME_RECIPIENT_TYPE_CC },
\r
86 + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }
\r
90 reply_part_content (GMimeObject *part)
\r
92 @@ -182,58 +193,17 @@ add_recipients_for_string (GMimeMessage *message,
\r
93 return add_recipients_for_address_list (message, config, type, list);
\r
97 -notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
99 +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)
\r
101 - notmuch_config_t *config;
\r
102 - notmuch_database_t *notmuch;
\r
103 - notmuch_query_t *query;
\r
104 GMimeMessage *reply;
\r
105 - char *query_string;
\r
106 notmuch_messages_t *messages;
\r
107 notmuch_message_t *message;
\r
109 const char *subject, *recipients, *from_addr = NULL;
\r
110 const char *in_reply_to, *orig_references, *references;
\r
111 char *reply_headers;
\r
113 - const char *header;
\r
114 - const char *fallback;
\r
115 - GMimeRecipientType recipient_type;
\r
116 - } reply_to_map[] = {
\r
117 - { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO },
\r
118 - { "to", NULL, GMIME_RECIPIENT_TYPE_TO },
\r
119 - { "cc", NULL, GMIME_RECIPIENT_TYPE_CC },
\r
120 - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }
\r
124 - config = notmuch_config_open (ctx, NULL, NULL);
\r
125 - if (config == NULL)
\r
128 - query_string = query_string_from_args (ctx, argc, argv);
\r
129 - if (query_string == NULL) {
\r
130 - fprintf (stderr, "Out of memory\n");
\r
134 - if (*query_string == '\0') {
\r
135 - fprintf (stderr, "Error: notmuch reply requires at least one search term.\n");
\r
139 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
140 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
141 - if (notmuch == NULL)
\r
144 - query = notmuch_query_create (notmuch, query_string);
\r
145 - if (query == NULL) {
\r
146 - fprintf (stderr, "Out of memory\n");
\r
150 for (messages = notmuch_query_search_messages (query);
\r
151 notmuch_messages_has_more (messages);
\r
152 notmuch_messages_advance (messages))
\r
153 @@ -310,6 +280,71 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
155 notmuch_message_destroy (message);
\r
161 +notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
163 + notmuch_config_t *config;
\r
164 + notmuch_database_t *notmuch;
\r
165 + notmuch_query_t *query;
\r
166 + char *opt, *query_string;
\r
168 + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query);
\r
170 + reply_format_func = notmuch_reply_format_default;
\r
172 + for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
173 + if (strcmp (argv[i], "--") == 0) {
\r
177 + if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
\r
178 + opt = argv[i] + sizeof ("--format=") - 1;
\r
179 + if (strcmp (opt, "default") == 0) {
\r
180 + reply_format_func = notmuch_reply_format_default;
\r
182 + fprintf (stderr, "Invalid value for --format: %s\n", opt);
\r
186 + fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
194 + config = notmuch_config_open (ctx, NULL, NULL);
\r
195 + if (config == NULL)
\r
198 + query_string = query_string_from_args (ctx, argc, argv);
\r
199 + if (query_string == NULL) {
\r
200 + fprintf (stderr, "Out of memory\n");
\r
204 + if (*query_string == '\0') {
\r
205 + fprintf (stderr, "Error: notmuch reply requires at least one search term.\n");
\r
209 + notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
210 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
211 + if (notmuch == NULL)
\r
214 + query = notmuch_query_create (notmuch, query_string);
\r
215 + if (query == NULL) {
\r
216 + fprintf (stderr, "Out of memory\n");
\r
220 + if (reply_format_func (ctx, config, query) != 0)
\r
223 notmuch_query_destroy (query);
\r
224 notmuch_database_close (notmuch);
\r