1 Return-Path: <amthrax@drake.mit.edu>
\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 71FA0431FC9
\r
6 for <notmuch@notmuchmail.org>; Tue, 27 Mar 2012 14:59:59 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\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 utyCg75NaQGk for <notmuch@notmuchmail.org>;
\r
16 Tue, 27 Mar 2012 14:59:58 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id A5301431FB6
\r
20 for <notmuch@notmuchmail.org>; Tue, 27 Mar 2012 14:59:57 -0700 (PDT)
\r
21 X-AuditID: 12074424-b7fae6d000000906-c2-4f72385bd73c
\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 2B.23.02310.B58327F4; Tue, 27 Mar 2012 17:59:55 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q2RLxtPW022941;
\r
27 Tue, 27 Mar 2012 17:59:55 -0400
\r
28 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q2RLxsUg014142
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Tue, 27 Mar 2012 17:59:55 -0400 (EDT)
\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amthrax@drake.mit.edu>)
\r
36 id 1SCeQk-0008Vp-HB; Tue, 27 Mar 2012 17:59:54 -0400
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v2 1/3] show/reply: Unify the code that extracts text parts
\r
40 Date: Tue, 27 Mar 2012 17:59:50 -0400
\r
41 Message-Id: <1332885592-32668-2-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.7.9.1
\r
43 In-Reply-To: <1332885592-32668-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1332473647-9133-1-git-send-email-amdragon@mit.edu>
\r
45 <1332885592-32668-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixCmqrRttUeRvsPOKtcX1mzOZHRg9nq26
\r
48 xRzAGMVlk5Kak1mWWqRvl8CV8fLgMfaCZToV0xfPYW1gvKHSxcjJISFgIjFr8Q82CFtM4sK9
\r
49 9UA2F4eQwD5GiSNb5rBDOBsYJbo/HoRyjjNJXP18khXCmc8o8fnkO0aQfjYBDYlt+5eD2SIC
\r
50 0hI7784GKuLgYBZQk/jTBbZOWMBb4tab76wgNouAqsSvvk3MIDavgIPExfc3GSHOUJB4tu44
\r
51 E4jNKeAocXXXGzBbSKBM4s6l06wTGPkXMDKsYpRNya3SzU3MzClOTdYtTk7My0st0jXXy80s
\r
52 0UtNKd3ECAobdheVHYzNh5QOMQpwMCrx8CozFPkLsSaWFVfmHmKU5GBSEuVVMAUK8SXlp1Rm
\r
53 JBZnxBeV5qQWH2KU4GBWEuHVjir0F+JNSaysSi3Kh0lJc7AoifNqaL3zExJITyxJzU5NLUgt
\r
54 gsnKcHAoSfC2mQMNFSxKTU+tSMvMKUFIM3FwggznARr+2Qyohre4IDG3ODMdIn+KUVFKnHcO
\r
55 SLMASCKjNA+uFxbXrxjFgV4R5l0JUsUDTAlw3a+ABjMBDV5yJB9kcEkiQkqqgbE9r+IVq5Rz
\r
56 oabrx0OLTk5xuOoXwDBbcpup1IKttVst/1795C+e9//Msg8hSxUfcM+Jcfy9tfpGl+DFevGz
\r
57 7zdc/54muX1i5/t1qvvm5LNveWesauF0+Vj6ZtXgsEXKm6bc4WcLMOsvOfhGO3h+cdf2tScu
\r
58 pWkdtM9rq/yv0GbUt87w0uKe+SJKLMUZiYZazEXFiQChUUDwxgIAAA==
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Tue, 27 Mar 2012 21:59:59 -0000
\r
73 Previously, show and reply had separate implementations of decoding
\r
74 and printing text parts. Now both use show's implementation, which
\r
75 was more complete. Show's implementation has been extended with an
\r
76 option to add reply quoting to the extracted part (this is implemented
\r
77 as a named flag to avoid naked booleans, even though it's the only
\r
80 notmuch-client.h | 8 ++++++++
\r
81 notmuch-reply.c | 28 ++++------------------------
\r
82 notmuch-show.c | 23 +++++++++++++++++++----
\r
83 3 files changed, 31 insertions(+), 28 deletions(-)
\r
85 diff --git a/notmuch-client.h b/notmuch-client.h
\r
86 index fa04fa2..203ac49 100644
\r
87 --- a/notmuch-client.h
\r
88 +++ b/notmuch-client.h
\r
89 @@ -197,6 +197,14 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);
\r
91 format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);
\r
94 + NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,
\r
95 +} notmuch_show_text_part_flags;
\r
98 +show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
\r
99 + notmuch_show_text_part_flags flags);
\r
102 json_quote_chararray (const void *ctx, const char *str, const size_t len);
\r
104 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
105 index e2b6c25..2f5ed3d 100644
\r
106 --- a/notmuch-reply.c
\r
107 +++ b/notmuch-reply.c
\r
111 #include "notmuch-client.h"
\r
112 -#include "gmime-filter-reply.h"
\r
113 #include "gmime-filter-headers.h"
\r
116 @@ -106,29 +105,10 @@ reply_part_content (GMimeObject *part)
\r
117 else if (g_mime_content_type_is_type (content_type, "text", "*") &&
\r
118 !g_mime_content_type_is_type (content_type, "text", "html"))
\r
120 - GMimeStream *stream_stdout = NULL, *stream_filter = NULL;
\r
121 - GMimeDataWrapper *wrapper;
\r
122 - const char *charset;
\r
124 - charset = g_mime_object_get_content_type_parameter (part, "charset");
\r
125 - stream_stdout = g_mime_stream_file_new (stdout);
\r
126 - if (stream_stdout) {
\r
127 - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
\r
128 - stream_filter = g_mime_stream_filter_new(stream_stdout);
\r
130 - g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter),
\r
131 - g_mime_filter_charset_new(charset, "UTF-8"));
\r
134 - g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter),
\r
135 - g_mime_filter_reply_new(TRUE));
\r
136 - wrapper = g_mime_part_get_content_object (GMIME_PART (part));
\r
137 - if (wrapper && stream_filter)
\r
138 - g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
\r
139 - if (stream_filter)
\r
140 - g_object_unref(stream_filter);
\r
141 - if (stream_stdout)
\r
142 - g_object_unref(stream_stdout);
\r
143 + GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
\r
144 + g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
\r
145 + show_text_part_content (part, stream_stdout, NOTMUCH_SHOW_TEXT_PART_REPLY);
\r
146 + g_object_unref(stream_stdout);
\r
150 diff --git a/notmuch-show.c b/notmuch-show.c
\r
151 index ff9d427..0bf5e21 100644
\r
152 --- a/notmuch-show.c
\r
153 +++ b/notmuch-show.c
\r
157 #include "notmuch-client.h"
\r
158 +#include "gmime-filter-reply.h"
\r
160 static notmuch_status_t
\r
161 format_part_text (const void *ctx, mime_node_t *node,
\r
162 @@ -247,13 +248,17 @@ format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t repl
\r
164 /* Write a MIME text part out to the given stream.
\r
166 + * If (flags & NOTMUCH_SHOW_TEXT_PART_REPLY), this prepends "> " to
\r
167 + * each output line.
\r
169 * Both line-ending conversion (CRLF->LF) and charset conversion ( ->
\r
170 * UTF-8) will be performed, so it is inappropriate to call this
\r
171 * function with a non-text part. Doing so will trigger an internal
\r
175 -show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
\r
177 +show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
\r
178 + notmuch_show_text_part_flags flags)
\r
180 GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
\r
181 GMimeStream *stream_filter = NULL;
\r
182 @@ -286,6 +291,16 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
\r
186 + if (flags & NOTMUCH_SHOW_TEXT_PART_REPLY) {
\r
187 + GMimeFilter *reply_filter;
\r
188 + reply_filter = g_mime_filter_reply_new (TRUE);
\r
189 + if (reply_filter) {
\r
190 + g_mime_stream_filter_add (GMIME_STREAM_FILTER (stream_filter),
\r
192 + g_object_unref (reply_filter);
\r
196 wrapper = g_mime_part_get_content_object (GMIME_PART (part));
\r
197 if (wrapper && stream_filter)
\r
198 g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
\r
199 @@ -532,7 +547,7 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
201 GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
\r
202 g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
\r
203 - show_text_part_content (node->part, stream_stdout);
\r
204 + show_text_part_content (node->part, stream_stdout, 0);
\r
205 g_object_unref(stream_stdout);
\r
207 printf ("Non-text part: %s\n",
\r
208 @@ -624,7 +639,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
209 } else if (g_mime_content_type_is_type (content_type, "text", "*")) {
\r
210 GMimeStream *stream_memory = g_mime_stream_mem_new ();
\r
211 GByteArray *part_content;
\r
212 - show_text_part_content (node->part, stream_memory);
\r
213 + show_text_part_content (node->part, stream_memory, 0);
\r
214 part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
\r
216 printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len));
\r