cli/show: add content-disposition to structured output message parts

Help the clients decide how to display parts.

Test updates by Mark Walters <markwalters1009@gmail.com>.
One more test fix by db
This commit is contained in:
Jani Nikula 2017-02-26 20:33:48 +02:00 committed by David Bremner
parent 85caaaf861
commit ea20a932f1
7 changed files with 26 additions and 10 deletions

View file

@ -28,6 +28,7 @@ v2
v3 v3
- Replaced message.filename string with a list of filenames. - Replaced message.filename string with a list of filenames.
- Added part.content-disposition field.
Common non-terminals Common non-terminals
-------------------- --------------------
@ -79,6 +80,7 @@ part = {
sigstatus?: sigstatus, sigstatus?: sigstatus,
content-type: string, content-type: string,
content-disposition?: string,
content-id?: string, content-id?: string,
# if content-type starts with "multipart/": # if content-type starts with "multipart/":
content: [part*], content: [part*],

View file

@ -595,6 +595,7 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
GMimeObject *meta = node->envelope_part ? GMimeObject *meta = node->envelope_part ?
GMIME_OBJECT (node->envelope_part) : node->part; GMIME_OBJECT (node->envelope_part) : node->part;
GMimeContentType *content_type = g_mime_object_get_content_type (meta); GMimeContentType *content_type = g_mime_object_get_content_type (meta);
const char *disposition = _get_disposition (meta);
const char *cid = g_mime_object_get_content_id (meta); const char *cid = g_mime_object_get_content_id (meta);
const char *filename = GMIME_IS_PART (node->part) ? const char *filename = GMIME_IS_PART (node->part) ?
g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; g_mime_part_get_filename (GMIME_PART (node->part)) : NULL;
@ -624,6 +625,11 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
sp->map_key (sp, "content-type"); sp->map_key (sp, "content-type");
sp->string (sp, g_mime_content_type_to_string (content_type)); sp->string (sp, g_mime_content_type_to_string (content_type));
if (disposition) {
sp->map_key (sp, "content-disposition");
sp->string (sp, disposition);
}
if (cid) { if (cid) {
sp->map_key (sp, "content-id"); sp->map_key (sp, "content-id");
sp->string (sp, cid); sp->string (sp, cid);

View file

@ -48,7 +48,7 @@ output=$(notmuch show --format=json "id:$id")
filename=$(notmuch search --output=files "id:$id") filename=$(notmuch search --output=files "id:$id")
# Get length of README after base64-encoding, minus additional newline. # Get length of README after base64-encoding, minus additional newline.
attachment_length=$(( $(base64 $TEST_DIRECTORY/README | wc -c) - 1 )) 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-length\": $attachment_length, \"content-transfer-encoding\": \"base64\", \"content-disposition\": \"inline\", \"filename\": \"README\"}]}]}, []]]]"
test_begin_subtest "Search message: json, utf-8" 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\"" 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\""

View file

@ -39,7 +39,7 @@ output=$(notmuch show --format=sexp "id:$id")
filename=$(notmuch search --output=files "id:$id") filename=$(notmuch search --output=files "id:$id")
# Get length of README after base64-encoding, minus additional newline. # Get length of README after base64-encoding, minus additional newline.
attachment_length=$(( $(base64 $TEST_DIRECTORY/README | wc -c) - 1 )) 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-disposition \"inline\" :filename \"README\" :content-transfer-encoding \"base64\" :content-length $attachment_length))))) ())))"
test_begin_subtest "Search message: sexp, utf-8" 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\"" 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\""

View file

@ -348,11 +348,11 @@ cat <<EOF >EXPECTED
{"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "excluded": false, "filename": ["${MAIL_DIR}/multipart"], "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [ {"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "excluded": false, "filename": ["${MAIL_DIR}/multipart"], "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [
{"id": 1, "content-type": "multipart/signed", "content": [ {"id": 1, "content-type": "multipart/signed", "content": [
{"id": 2, "content-type": "multipart/mixed", "content": [ {"id": 2, "content-type": "multipart/mixed", "content": [
{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [ {"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html", "content-length": 71}, {"id": 5, "content-type": "text/html", "content-length": 71},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
{"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, {"id": 7, "content-type": "text/plain", "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"},
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]},
{"id": 9, "content-type": "application/pgp-signature", "content-length": 197}]}]} {"id": 9, "content-type": "application/pgp-signature", "content-length": 197}]}]}
EOF EOF
@ -363,11 +363,11 @@ notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OU
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
{"id": 1, "content-type": "multipart/signed", "content": [ {"id": 1, "content-type": "multipart/signed", "content": [
{"id": 2, "content-type": "multipart/mixed", "content": [ {"id": 2, "content-type": "multipart/mixed", "content": [
{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [ {"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html", "content-length": 71}, {"id": 5, "content-type": "text/html", "content-length": 71},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
{"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, {"id": 7, "content-type": "text/plain", "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"},
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]},
{"id": 9, "content-type": "application/pgp-signature", "content-length": 197}]} {"id": 9, "content-type": "application/pgp-signature", "content-length": 197}]}
EOF EOF
@ -377,11 +377,11 @@ test_begin_subtest "--format=json --part=2, multipart/mixed"
notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
{"id": 2, "content-type": "multipart/mixed", "content": [ {"id": 2, "content-type": "multipart/mixed", "content": [
{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [ {"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html", "content-length": 71}, {"id": 5, "content-type": "text/html", "content-length": 71},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
{"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, {"id": 7, "content-type": "text/plain", "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"},
{"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]} {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}
EOF EOF
test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)" test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
@ -389,7 +389,7 @@ test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=3, rfc822 part" test_begin_subtest "--format=json --part=3, rfc822 part"
notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
{"id": 4, "content-type": "multipart/alternative", "content": [ {"id": 4, "content-type": "multipart/alternative", "content": [
{"id": 5, "content-type": "text/html", "content-length": 71}, {"id": 5, "content-type": "text/html", "content-length": 71},
{"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]} {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}
@ -422,7 +422,11 @@ test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
test_begin_subtest "--format=json --part=7, inline attachment" test_begin_subtest "--format=json --part=7, inline attachment"
notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED cat <<EOF >EXPECTED
{"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"} {"id": 7,
"content-type": "text/plain",
"filename": "attachment",
"content": "This is a text attachment.\n",
"content-disposition": "attachment"}
EOF EOF
test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)" test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
@ -641,6 +645,7 @@ notmuch_json_show_sanitize <<EOF >EXPECTED
"content-type": "multipart/mixed", "content-type": "multipart/mixed",
"content": [{"id": 3, "content": [{"id": 3,
"content-type": "message/rfc822", "content-type": "message/rfc822",
"content-disposition": "inline",
"content": [{"headers": {"Subject": "html message", "content": [{"headers": {"Subject": "html message",
"From": "Carl Worth <cworth@cworth.org>", "From": "Carl Worth <cworth@cworth.org>",
"To": "cworth@cworth.org", "To": "cworth@cworth.org",
@ -655,6 +660,7 @@ notmuch_json_show_sanitize <<EOF >EXPECTED
"content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
{"id": 7, {"id": 7,
"content-type": "text/plain", "content-type": "text/plain",
"content-disposition": "attachment",
"filename": "attachment", "filename": "attachment",
"content": "This is a text attachment.\n"}, "content": "This is a text attachment.\n"},
{"id": 8, {"id": 8,

View file

@ -205,6 +205,7 @@ expected='[[[{"id": "XXXXX",
"content": "This is a test encrypted message.\n"}, "content": "This is a test encrypted message.\n"},
{"id": 5, {"id": 5,
"content-type": "application/octet-stream", "content-type": "application/octet-stream",
"content-disposition": "attachment",
"content-length": "NONZERO", "content-length": "NONZERO",
"content-transfer-encoding": "base64", "content-transfer-encoding": "base64",
"filename": "TESTATTACHMENT"}]}]}]}, "filename": "TESTATTACHMENT"}]}]}]},

View file

@ -69,6 +69,7 @@ expected='[[[{"id": "XXXXX",
"content-type": "text/plain", "content-type": "text/plain",
"content": "This is a test signed message.\n"}, "content": "This is a test signed message.\n"},
{"id": 3, {"id": 3,
"content-disposition": "attachment",
"content-length": "NONZERO", "content-length": "NONZERO",
"content-transfer-encoding": "base64", "content-transfer-encoding": "base64",
"content-type": "application/x-pkcs7-signature", "content-type": "application/x-pkcs7-signature",