From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 239B0431FC9 for ; Mon, 3 Feb 2014 02:47:00 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ln8ktshn5u+r for ; Mon, 3 Feb 2014 02:46:49 -0800 (PST) Received: from qmta04.westchester.pa.mail.comcast.net (qmta04.westchester.pa.mail.comcast.net [76.96.62.40]) by olra.theworths.org (Postfix) with ESMTP id 4EC40431FDB for ; Mon, 3 Feb 2014 02:46:49 -0800 (PST) Received: from omta04.westchester.pa.mail.comcast.net ([76.96.62.35]) by qmta04.westchester.pa.mail.comcast.net with comcast id Mmlh1n0010ldTLk54mmoVz; Mon, 03 Feb 2014 10:46:48 +0000 Received: from odin.tremily.us ([24.18.63.50]) by omta04.westchester.pa.mail.comcast.net with comcast id Mmmm1n00L152l3L01mmnZn; Mon, 03 Feb 2014 10:46:48 +0000 Received: from mjolnir.tremily.us (unknown [192.168.0.140]) by odin.tremily.us (Postfix) with ESMTPS id BE048FB4C6B; Mon, 3 Feb 2014 02:46:45 -0800 (PST) Received: (nullmailer pid 31479 invoked by uid 1000); Mon, 03 Feb 2014 10:45:48 -0000 From: "W. Trevor King" To: notmuch@notmuchmail.org Subject: [PATCH 1/2] notmuch-show: Add content-description output pair Date: Mon, 3 Feb 2014 02:45:33 -0800 Message-Id: <4a916b4f80f5cc9b28ddbb9c3eecdabf914d9641.1391423201.git.wking@tremily.us> X-Mailer: git-send-email 1.8.5.2.8.g0f6c0d1 In-Reply-To: References: <877g9chbay.fsf@qmul.ac.uk> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20121106; t=1391424408; bh=6cQ+kT34X70UTPaNzC5yeyXhvb2vocR8UUhEtebGZfs=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-Id:MIME-Version:Content-Type; b=Dwo4azb+U3UirA7HukqlGEXyc+7K8W6T9BRICJJhdh83P0M9MzGMiicsNbVX1/QeJ NPq/BTLbNGdG+jcOLDtLYn0txamrld2gvQprWPYtCnj3qaYclW3qhjmF/Am8oOQnoN /ZSK93gtb3cC3YJf0FpbhPZFob5pG27kjcgGSQe5eNrwl73fWb8i464DrPgY7KmcEZ a4phVdPZgFP818naSUkQ2TbpngTmBojPLvb9EwHylfxnitMZ6gOMCXcjlsW2hCcdBX w2GagqA1qKVNm5Y2vLVbWSSBMtGvq4/yGf2ip+pXjkKsNccgYZyzLTdwK2I78ghu7y Nu9c2H2Y63J1A== X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Feb 2014 10:47:00 -0000 Parse and display the Content-Description header [1,2] so UIs rendering message parts have easy access to description strings. Extracting the value is a two-step process (extract [3] and decode [4]). [1]: http://tools.ietf.org/html/rfc2045#section-8 [2]: http://tools.ietf.org/html/rfc2183#section-3 [3]: https://developer.gnome.org/gmime/stable/GMimeObject.html#g-mime-object-get-header [4]: https://developer.gnome.org/gmime/stable/gmime-gmime-utils.html#g-mime-utils-header-decode-text --- NEWS | 2 ++ notmuch-show.c | 8 ++++++++ test/T160-json.sh | 4 ++-- test/T170-sexp.sh | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 65679eb..0f7b1c8 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ Command-Line Interface The old format is still available with `--format=sup`. +`notmuch show` now includes envelope Content-Description headers. + Notmuch 0.17 (2013-12-30) ========================= diff --git a/notmuch-show.c b/notmuch-show.c index d416fbd..a604227 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -659,6 +659,9 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, GMIME_OBJECT (node->envelope_part) : node->part; GMimeContentType *content_type = g_mime_object_get_content_type (meta); const char *cid = g_mime_object_get_content_id (meta); + const char *encoded_description = g_mime_object_get_header (meta, "content-description"); + const char *description = encoded_description ? + g_mime_utils_header_decode_text (encoded_description) : NULL; const char *filename = GMIME_IS_PART (node->part) ? g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; int nclose = 0; @@ -692,6 +695,11 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, sp->string (sp, cid); } + if (description) { + sp->map_key (sp, "content-description"); + sp->string (sp, description); + } + if (filename) { sp->map_key (sp, "filename"); sp->string (sp, filename); diff --git a/test/T160-json.sh b/test/T160-json.sh index c1cf649..53f40ef 100755 --- a/test/T160-json.sh +++ b/test/T160-json.sh @@ -41,14 +41,14 @@ id="json-show-inline-attachment-filename@notmuchmail.org" emacs_fcc_message \ "$subject" \ 'This is a test message with inline attachment with a filename' \ - "(mml-attach-file \"$TEST_DIRECTORY/README\" nil nil \"inline\") + "(mml-attach-file \"$TEST_DIRECTORY/README\" nil \"Test README\" \"inline\") (message-goto-eoh) (insert \"Message-ID: <$id>\n\")" output=$(notmuch show --format=json "id:$id") filename=$(notmuch search --output=files "id:$id") # Get length of README after base64-encoding, minus additional newline. attachment_length=$(( $(base64 $TEST_DIRECTORY/README | wc -c) - 1 )) -test_expect_equal_json "$output" "[[[{\"id\": \"$id\", \"match\": true, \"excluded\": false, \"filename\": \"$filename\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\"], \"headers\": {\"Subject\": \"$subject\", \"From\": \"Notmuch Test Suite \", \"To\": \"test_suite@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"multipart/mixed\", \"content\": [{\"id\": 2, \"content-type\": \"text/plain\", \"content\": \"This is a test message with inline attachment with a filename\"}, {\"id\": 3, \"content-type\": \"application/octet-stream\", \"content-length\": $attachment_length, \"content-transfer-encoding\": \"base64\", \"filename\": \"README\"}]}]}, []]]]" +test_expect_equal_json "$output" "[[[{\"id\": \"$id\", \"match\": true, \"excluded\": false, \"filename\": \"$filename\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\"], \"headers\": {\"Subject\": \"$subject\", \"From\": \"Notmuch Test Suite \", \"To\": \"test_suite@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"multipart/mixed\", \"content\": [{\"id\": 2, \"content-type\": \"text/plain\", \"content\": \"This is a test message with inline attachment with a filename\"}, {\"id\": 3, \"content-type\": \"application/octet-stream\", \"content-description\": \"Test README\", \"content-length\": $attachment_length, \"content-transfer-encoding\": \"base64\", \"filename\": \"README\"}]}]}, []]]]" test_begin_subtest "Search message: json, utf-8" add_message "[subject]=\"json-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\"" diff --git a/test/T170-sexp.sh b/test/T170-sexp.sh index 667e319..1c087d6 100755 --- a/test/T170-sexp.sh +++ b/test/T170-sexp.sh @@ -32,14 +32,14 @@ id="sexp-show-inline-attachment-filename@notmuchmail.org" emacs_fcc_message \ "$subject" \ 'This is a test message with inline attachment with a filename' \ - "(mml-attach-file \"$TEST_DIRECTORY/README\" nil nil \"inline\") + "(mml-attach-file \"$TEST_DIRECTORY/README\" nil \"Test README\" \"inline\") (message-goto-eoh) (insert \"Message-ID: <$id>\n\")" output=$(notmuch show --format=sexp "id:$id") filename=$(notmuch search --output=files "id:$id") # Get length of README after base64-encoding, minus additional newline. attachment_length=$(( $(base64 $TEST_DIRECTORY/README | wc -c) - 1 )) -test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename \"$filename\" :timestamp 946728000 :date_relative \"2000-01-01\" :tags (\"inbox\") :headers (:Subject \"sexp-show-inline-attachment-filename\" :From \"Notmuch Test Suite \" :To \"test_suite@notmuchmail.org\" :Date \"Sat, 01 Jan 2000 12:00:00 +0000\") :body ((:id 1 :content-type \"multipart/mixed\" :content ((:id 2 :content-type \"text/plain\" :content \"This is a test message with inline attachment with a filename\") (:id 3 :content-type \"application/octet-stream\" :filename \"README\" :content-transfer-encoding \"base64\" :content-length $attachment_length))))) ())))" +test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename \"$filename\" :timestamp 946728000 :date_relative \"2000-01-01\" :tags (\"inbox\") :headers (:Subject \"sexp-show-inline-attachment-filename\" :From \"Notmuch Test Suite \" :To \"test_suite@notmuchmail.org\" :Date \"Sat, 01 Jan 2000 12:00:00 +0000\") :body ((:id 1 :content-type \"multipart/mixed\" :content ((:id 2 :content-type \"text/plain\" :content \"This is a test message with inline attachment with a filename\") (:id 3 :content-type \"application/octet-stream\" :content-description \"Test README\" :filename \"README\" :content-transfer-encoding \"base64\" :content-length $attachment_length))))) ())))" test_begin_subtest "Search message: sexp, utf-8" add_message "[subject]=\"sexp-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\"" -- 1.8.5.2.8.g0f6c0d1