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 <test_suite@notmuchmail.org>\", \"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 <test_suite@notmuchmail.org>\", \"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 <test_suite@notmuchmail.org>\" :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 <test_suite@notmuchmail.org>\" :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