[PATCH v2 3/3] reply: Use RFC 2822/MIME wholly for text format template
Previously, reply's default text format used an odd mix of RFC 2045 MIME encoding for the reply template's body and some made-up RFC 2822-like UTF-8 format for the headers. The intent was to present the headers to the user in a nice, un-encoded format, but this assumed that whatever ultimately sent the email would RFC 2047-encode the headers, while at the same time the body was already RFC 2045 encoded, so it assumed that whatever sent the email would *not* re-encode the body. This can be fixed by either producing a fully decoded UTF-8 reply template, or a fully encoded MIME-compliant RFC 2822 message. This patch does the latter because it is a) Well-defined by RFC 2822 and MIME (while any UTF-8 format would be ad hoc). b) Ready to be piped to sendmail. The point of the text format is to be minimal, so a user should be able to pop up the template in whatever editor they want, edit it, and push it to sendmail. c) Consistent with frontend capabilities. If a frontend has the smarts to RFC 2047 encode the headers before sending the mail, it probably has the smarts to RFC 2047 decode them before presenting the template to a user for editing. Also, as far as I know, nothing automated consumes the reply text format, so changing this should not cause serious problems. (And if anything does still consume this format, it probably gets these encoding issues wrong anyway.) --- Makefile.local |1 - gmime-filter-headers.c | 263 -- gmime-filter-headers.h | 69 man/man1/notmuch-reply.1 |2 +- notmuch-reply.c | 15 +-- test/reply |9 +- test/reply-to-sender |4 +- 7 files changed, 12 insertions(+), 351 deletions(-) delete mode 100644 gmime-filter-headers.c delete mode 100644 gmime-filter-headers.h diff --git a/Makefile.local b/Makefile.local index 84043fe..b7cd266 100644 --- a/Makefile.local +++ b/Makefile.local @@ -255,7 +255,6 @@ notmuch_client_srcs = \ command-line-arguments.c\ debugger.c \ gmime-filter-reply.c\ - gmime-filter-headers.c \ hooks.c \ notmuch.c \ notmuch-config.c\ diff --git a/gmime-filter-headers.c b/gmime-filter-headers.c deleted file mode 100644 index 7db3779..000 --- a/gmime-filter-headers.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright ? 2009 Keith Packard - * Copyright ? 2010 Michal Sojka - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#include "gmime-filter-headers.h" -#include -#include -#include -#include -#include - -/** - * SECTION: gmime-filter-headers - * @title: GMimeFilterHeaders - * @short_description: Add/remove headers markers - * - * A #GMimeFilter for decoding rfc2047 encoded headers to UTF-8 - **/ - - -static void g_mime_filter_headers_class_init (GMimeFilterHeadersClass *klass); -static void g_mime_filter_headers_init (GMimeFilterHeaders *filter, GMimeFilterHeadersClass *klass); -static void g_mime_filter_headers_finalize (GObject *object); - -static GMimeFilter *filter_copy (GMimeFilter *filter); -static void filter_filter (GMimeFilter *filter, char *in, size_t len, size_t prespace, - char **out, size_t *outlen, size_t *outprespace); -static void filter_complete (GMimeFilter *filter, char *in, size_t len, size_t prespace, -char **out, size_t *outlen, size_t *outprespace); -static void filter_reset (GMimeFilter *filter); - - -static GMimeFilterClass *parent_class = NULL; - -GType -g_mime_filter_headers_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GMimeFilterHeadersClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) g_mime_filter_headers_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GMimeFilterHeaders), - 0,/* n_preallocs */ - (GInstanceInitFunc) g_mime_filter_headers_init, - NULL/*
[PATCH v2 2/3] reply: Remove extraneous space from generated References
Previously, the References header code seemed to assume notmuch_message_get_header would return NULL if the header was not present, but it actually returns "". As a result of this, it was inserting an unnecessary space when concatenating an empty or missing original references header with the new reference. This shows up in only two tests because the text reply format later passes the whole reply template through g_mime_filter_headers, which has the side effect of stripping out this extra space. --- notmuch-reply.c | 14 -- test/multipart |2 +- test/reply |2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 3b2b58d..0f3b9cd 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -537,12 +537,14 @@ create_reply_message(void *ctx, "In-Reply-To", in_reply_to); orig_references = notmuch_message_get_header (message, "references"); -references = talloc_asprintf (ctx, "%s%s%s", - orig_references ? orig_references : "", - orig_references ? " " : "", - in_reply_to); -g_mime_object_set_header (GMIME_OBJECT (reply), - "References", references); +if (orig_references) { + references = talloc_asprintf (ctx, "%s%s%s", + *orig_references ? orig_references : "", + *orig_references ? " " : "", + in_reply_to); + g_mime_object_set_header (GMIME_OBJECT (reply), + "References", references); +} return reply; } diff --git a/test/multipart b/test/multipart index c974226..2033023 100755 --- a/test/multipart +++ b/test/multipart @@ -599,7 +599,7 @@ cat", - "References": " <87liy5ap00.fsf at yoom.home.cworth.org>"}, + "References": "<87liy5ap00.fsf at yoom.home.cworth.org>"}, "original": {"id": "X", "match": false, "excluded": false, diff --git a/test/reply b/test/reply index c877ffe..a85ebe5 100755 --- a/test/reply +++ b/test/reply @@ -242,7 +242,7 @@ test_expect_equal_json "$output" ' "reply-headers": { "From": "Notmuch Test Suite ", "In-reply-to": "<'${gen_msg_id}'>", -"References": " <'${gen_msg_id}'>", +"References": "<'${gen_msg_id}'>", "Subject": "Re: \u00e0\u00df\u00e7", "To": "\u2603 " } -- 1.7.10.4
[PATCH v2 1/3] reply: Test replying to messages with RFC 2047-encoded headers
--- test/reply | 56 1 file changed, 56 insertions(+) diff --git a/test/reply b/test/reply index ee5d361..c877ffe 100755 --- a/test/reply +++ b/test/reply @@ -193,4 +193,60 @@ References: <${gen_msg_id}> On Tue, 05 Jan 2010 15:43:56 -, Sender wrote: > From guessing" +test_begin_subtest "Reply with RFC 2047-encoded headers" +add_message '[subject]="=?iso-8859-1?q?=e0=df=e7?="' \ + '[from]="=?utf-8?q?=e2=98=83?= "' \ + '[date]="Tue, 05 Jan 2010 15:43:56 -"' \ + '[body]="Encoding"' + +output=$(notmuch reply id:${gen_msg_id}) +test_expect_equal "$output" "\ +From: Notmuch Test Suite +Subject: Re: ??? +To: ? +In-Reply-To: <${gen_msg_id}> +References: <${gen_msg_id}> + +On Tue, 05 Jan 2010 15:43:56 -, ? wrote: +> Encoding" + +test_begin_subtest "Reply with RFC 2047-encoded headers (JSON)" +output=$(notmuch reply --format=json id:${gen_msg_id}) +test_expect_equal_json "$output" ' +{ +"original": { +"body": [ +{ +"content": "Encoding\n", +"content-type": "text/plain", +"id": 1 +} +], +"date_relative": "2010-01-05", +"excluded": false, +"filename": "'${MAIL_DIR}'/msg-012", +"headers": { +"Date": "Tue, 05 Jan 2010 15:43:56 +", +"From": "\u2603 ", +"Subject": "\u00e0\u00df\u00e7", +"To": "Notmuch Test Suite " +}, +"id": "'${gen_msg_id}'", +"match": false, +"tags": [ +"inbox", +"unread" +], +"timestamp": 1262706236 +}, +"reply-headers": { +"From": "Notmuch Test Suite ", +"In-reply-to": "<'${gen_msg_id}'>", +"References": " <'${gen_msg_id}'>", +"Subject": "Re: \u00e0\u00df\u00e7", +"To": "\u2603 " +} +}' + + test_done -- 1.7.10.4
[PATCH v2 0/3] Clean up reply's encoding story
This is v2 of id:1376332839-22825-1-git-send-email-amdragon at mit.edu. This fixes an unintentional temporary test breakage and two typos in the last patch's commit message. There's no version diff from v1 because the final trees are the same.
[PATCH] test: Make symbol-test depend on libnotmuch.so
Austin Clements writes: > Without this > $ make -j test > intermittently fails and > $ make clean; make test/symbol-test > always fails (not that anybody would do the latter). pushed, d
[PATCH 3/6] reply: Document the reason for g_mime_filter_headers
Austin Clements writes: > Given how long it took me to figure out why we pass the reply headers > through g_mime_filter_headers, it's worth a comment. > --- Pushed the first 3 patches in the series. d