From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 5E2366DE20DE for ; Sun, 26 Feb 2017 10:33:59 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.173 X-Spam-Level: X-Spam-Status: No, score=-0.173 tagged_above=-999 required=5 tests=[AWL=-0.153, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J8NQpvvrvjx9 for ; Sun, 26 Feb 2017 10:33:57 -0800 (PST) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by arlo.cworth.org (Postfix) with ESMTPS id 136906DE20D6 for ; Sun, 26 Feb 2017 10:33:56 -0800 (PST) Received: by mail-lf0-f47.google.com with SMTP id a6so2604323lfa.0 for ; Sun, 26 Feb 2017 10:33:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nikula-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SrtldTE7e2hJCplUCpuxqbhcpbfXkJMa+LyYOX2Lh8g=; b=ZYyJY1R49DHqEnruO3/U5INKRIGJqj/ZSXZPgshnGBU7fmCKUVYRRCM8t39VloZnVe oceVXfDtcf/1I4ciVSO+KXZCtEKousEnfp9nuXafNmCuGoyPB2uiivZ+SZshlR9Vy1Tv ZgVAPBLDC86rUfgPcFrsJARQYB6tkmQhBqx3wMHH5KP8zKbYtZw79QpTX5pxn4vOgef6 h/7nmCWrYuVuaHa77B/LhM6a815X84+BhniQPpE8j0zuOt7cRrYnsRWeQqRG+4jkuoM2 RzAWPlTHkujvbOIxPCkYzfIjw/K6D3No6SH4Fjl8D3xZozaOD9G8ZQFTQB6ZABSLTCju B51w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SrtldTE7e2hJCplUCpuxqbhcpbfXkJMa+LyYOX2Lh8g=; b=BI79dSMfdm65wuo38uKpcpYI1Y2WmXlc3ace6gpNIrPq5SVIvR0V/Fcge9mmZFfTkb QuFwDn21eAvkPD/86RVqq521f5QDD/y2sdVtfxOJzZ98oGy4XjN7tY+AQeg4pnItESZp Ml2h8isn4fMFnX/LSSG89rKE+H/mdkc/C04MrM3h5XFFgdJffr6re9Yr5oAHjzxG53o8 Zu10RR+QSzd4pB9AdirlpP9M2PZI+TBZQidRCTMRIVEljW5WQbG1OKsBHpECDTgcxAZw vECd8aKT5+RNNw0xIjMQsfe1ffHrzE9WkE388kF0EJtN3Mf92ZVpR5QkE9ZXrR6d6OeR c8Ww== X-Gm-Message-State: AMke39mV7rFXmURFWnOb8FREaIO4S8NivG9QOVG/3IEM9Fn+Gn3pH58y101XdHbF9Zuk+w== X-Received: by 10.46.72.2 with SMTP id v2mr3131132lja.5.1488134034366; Sun, 26 Feb 2017 10:33:54 -0800 (PST) Received: from localhost (mobile-access-bcee80-14.dhcp.inet.fi. [188.238.128.14]) by smtp.gmail.com with ESMTPSA id d16sm3430847lfj.28.2017.02.26.10.33.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 26 Feb 2017 10:33:53 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2 2/2] cli/show: add content-disposition to structured output message parts Date: Sun, 26 Feb 2017 20:33:48 +0200 Message-Id: <20170226183348.30470-2-jani@nikula.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170226183348.30470-1-jani@nikula.org> References: <20170226183348.30470-1-jani@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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: Sun, 26 Feb 2017 18:33:59 -0000 Help the clients decide how to display parts. Test updates by Mark Walters . --- devel/schemata | 2 ++ notmuch-show.c | 6 ++++++ test/T160-json.sh | 2 +- test/T170-sexp.sh | 2 +- test/T190-multipart.sh | 22 ++++++++++++++-------- test/T350-crypto.sh | 1 + 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/devel/schemata b/devel/schemata index 6dede7a453d7..00ebb7a6e714 100644 --- a/devel/schemata +++ b/devel/schemata @@ -28,6 +28,7 @@ v2 v3 - Replaced message.filename string with a list of filenames. +- Added part.content-disposition field. Common non-terminals -------------------- @@ -79,6 +80,7 @@ part = { sigstatus?: sigstatus, content-type: string, + content-disposition?: string, content-id?: string, # if content-type starts with "multipart/": content: [part*], diff --git a/notmuch-show.c b/notmuch-show.c index 7630f49dbc59..744b62727c26 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -595,6 +595,7 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, GMimeObject *meta = node->envelope_part ? GMIME_OBJECT (node->envelope_part) : node->part; 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 *filename = GMIME_IS_PART (node->part) ? 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->string (sp, g_mime_content_type_to_string (content_type)); + if (disposition) { + sp->map_key (sp, "content-disposition"); + sp->string (sp, disposition); + } + if (cid) { sp->map_key (sp, "content-id"); sp->string (sp, cid); diff --git a/test/T160-json.sh b/test/T160-json.sh index 85b9b41f314c..5a954e3baf0d 100755 --- a/test/T160-json.sh +++ b/test/T160-json.sh @@ -48,7 +48,7 @@ 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-length\": $attachment_length, \"content-transfer-encoding\": \"base64\", \"content-disposition\": \"inline\", \"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 07113c0ad9a2..40e5e21d62cc 100755 --- a/test/T170-sexp.sh +++ b/test/T170-sexp.sh @@ -39,7 +39,7 @@ 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-disposition \"inline\" :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\"" diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh index 18eb7b839ac0..a31d61e2aa20 100755 --- a/test/T190-multipart.sh +++ b/test/T190-multipart.sh @@ -348,11 +348,11 @@ cat <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 ", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [ {"id": 1, "content-type": "multipart/signed", "content": [ {"id": 2, "content-type": "multipart/mixed", "content": [ -{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth ", "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 ", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 4, "content-type": "multipart/alternative", "content": [ {"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": 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": 9, "content-type": "application/pgp-signature", "content-length": 197}]}]} EOF @@ -363,11 +363,11 @@ notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OU cat <EXPECTED {"id": 1, "content-type": "multipart/signed", "content": [ {"id": 2, "content-type": "multipart/mixed", "content": [ -{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth ", "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 ", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 4, "content-type": "multipart/alternative", "content": [ {"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": 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": 9, "content-type": "application/pgp-signature", "content-length": 197}]} 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 cat <EXPECTED {"id": 2, "content-type": "multipart/mixed", "content": [ -{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth ", "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 ", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 4, "content-type": "multipart/alternative", "content": [ {"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": 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"}]} EOF 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" notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT cat <EXPECTED -{"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth ", "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 ", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [ {"id": 4, "content-type": "multipart/alternative", "content": [ {"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"}]}]}]} @@ -422,7 +422,11 @@ test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)" test_begin_subtest "--format=json --part=7, inline attachment" notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT cat <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 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)" @@ -641,6 +645,7 @@ notmuch_json_show_sanitize <EXPECTED "content-type": "multipart/mixed", "content": [{"id": 3, "content-type": "message/rfc822", + "content-disposition": "inline", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth ", "To": "cworth@cworth.org", @@ -655,6 +660,7 @@ notmuch_json_show_sanitize <EXPECTED "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, {"id": 7, "content-type": "text/plain", + "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"}, {"id": 8, diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh index 14b215a3c0a6..b15f4fbe7760 100755 --- a/test/T350-crypto.sh +++ b/test/T350-crypto.sh @@ -205,6 +205,7 @@ expected='[[[{"id": "XXXXX", "content": "This is a test encrypted message.\n"}, {"id": 5, "content-type": "application/octet-stream", + "content-disposition": "attachment", "content-length": "NONZERO", "content-transfer-encoding": "base64", "filename": "TESTATTACHMENT"}]}]}]}, -- 2.11.0