2010-12-01 21:27:52 +01:00
|
|
|
#!/usr/bin/env bash
|
2010-06-10 08:48:03 +02:00
|
|
|
test_description="--format=json output"
|
2017-09-25 22:38:19 +02:00
|
|
|
. $(dirname "$0")/test-lib.sh || exit 1
|
2021-05-15 22:47:44 +02:00
|
|
|
. $(dirname "$0")/test-lib-emacs.sh || exit 1
|
2010-06-10 08:48:03 +02:00
|
|
|
|
2010-09-18 00:25:39 +02:00
|
|
|
test_begin_subtest "Show message: json"
|
2012-10-30 11:12:47 +01:00
|
|
|
add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[bcc]=\"test_suite+bcc@notmuchmail.org\"" "[reply-to]=\"test_suite+replyto@notmuchmail.org\"" "[body]=\"json-show-message\""
|
2010-09-21 01:13:15 +02:00
|
|
|
output=$(notmuch show --format=json "json-show-message")
|
2019-05-25 20:04:06 +02:00
|
|
|
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
|
2010-06-10 08:48:03 +02:00
|
|
|
|
2012-07-24 20:23:28 +02:00
|
|
|
# This should be the same output as above.
|
|
|
|
test_begin_subtest "Show message: json --body=true"
|
|
|
|
output=$(notmuch show --format=json --body=true "json-show-message")
|
2019-05-25 20:04:06 +02:00
|
|
|
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
|
2012-07-24 20:23:28 +02:00
|
|
|
|
|
|
|
test_begin_subtest "Show message: json --body=false"
|
|
|
|
output=$(notmuch show --format=json --body=false "json-show-message")
|
2019-05-25 20:04:06 +02:00
|
|
|
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Bcc\": \"test_suite+bcc@notmuchmail.org\", \"Reply-To\": \"test_suite+replyto@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}}, []]]]"
|
2012-07-24 20:23:28 +02:00
|
|
|
|
2010-09-18 00:25:39 +02:00
|
|
|
test_begin_subtest "Search message: json"
|
|
|
|
add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\""
|
2012-08-03 03:14:48 +02:00
|
|
|
output=$(notmuch search --format=json "json-search-message" | notmuch_search_sanitize)
|
2012-08-03 03:14:47 +02:00
|
|
|
test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
|
2012-07-23 12:39:46 +02:00
|
|
|
\"timestamp\": 946728000,
|
|
|
|
\"date_relative\": \"2000-01-01\",
|
|
|
|
\"matched\": 1,
|
|
|
|
\"total\": 1,
|
|
|
|
\"authors\": \"Notmuch Test Suite\",
|
|
|
|
\"subject\": \"json-search-subject\",
|
2013-10-24 17:19:08 +02:00
|
|
|
\"query\": [\"id:$gen_msg_id\", null],
|
2012-07-23 12:39:46 +02:00
|
|
|
\"tags\": [\"inbox\",
|
|
|
|
\"unread\"]}]"
|
2010-06-10 08:48:03 +02:00
|
|
|
|
2010-09-18 00:25:39 +02:00
|
|
|
test_begin_subtest "Show message: json, utf-8"
|
|
|
|
add_message "[subject]=\"json-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-show-méssage\""
|
2010-09-21 01:13:15 +02:00
|
|
|
output=$(notmuch show --format=json "jsön-show-méssage")
|
2019-05-25 20:04:06 +02:00
|
|
|
test_expect_equal_json "$output" "[[[{\"id\": \"${gen_msg_id}\", \"crypto\": {}, \"match\": true, \"excluded\": false, \"filename\": [\"${gen_msg_filename}\"], \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]"
|
2010-06-10 08:48:03 +02:00
|
|
|
|
2011-07-01 04:03:50 +02:00
|
|
|
test_begin_subtest "Show message: json, inline attachment filename"
|
|
|
|
subject='json-show-inline-attachment-filename'
|
|
|
|
id="json-show-inline-attachment-filename@notmuchmail.org"
|
2013-12-14 15:39:54 +01:00
|
|
|
emacs_fcc_message \
|
2011-07-01 04:03:50 +02:00
|
|
|
"$subject" \
|
|
|
|
'This is a test message with inline attachment with a filename' \
|
2017-09-25 22:38:29 +02:00
|
|
|
"(mml-attach-file \"$NOTMUCH_SRCDIR/test/README\" nil nil \"inline\")
|
2011-07-01 04:03:50 +02:00
|
|
|
(message-goto-eoh)
|
|
|
|
(insert \"Message-ID: <$id>\n\")"
|
|
|
|
output=$(notmuch show --format=json "id:$id")
|
|
|
|
filename=$(notmuch search --output=files "id:$id")
|
2012-12-15 04:06:45 +01:00
|
|
|
# Get length of README after base64-encoding, minus additional newline.
|
2017-09-25 22:38:29 +02:00
|
|
|
attachment_length=$(( $(base64 $NOTMUCH_SRCDIR/test/README | wc -c) - 1 ))
|
2019-05-25 20:04:06 +02:00
|
|
|
test_expect_equal_json "$output" "[[[{\"id\": \"$id\", \"crypto\": {}, \"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\"}]}]}, []]]]"
|
2011-07-01 04:03:50 +02:00
|
|
|
|
2010-09-18 00:25:39 +02:00
|
|
|
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\""
|
2012-08-03 03:14:48 +02:00
|
|
|
output=$(notmuch search --format=json "jsön-search-méssage" | notmuch_search_sanitize)
|
2012-08-03 03:14:47 +02:00
|
|
|
test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
|
2012-07-23 12:39:46 +02:00
|
|
|
\"timestamp\": 946728000,
|
|
|
|
\"date_relative\": \"2000-01-01\",
|
|
|
|
\"matched\": 1,
|
|
|
|
\"total\": 1,
|
|
|
|
\"authors\": \"Notmuch Test Suite\",
|
|
|
|
\"subject\": \"json-search-utf8-body-sübjéct\",
|
2013-10-24 17:19:08 +02:00
|
|
|
\"query\": [\"id:$gen_msg_id\", null],
|
2012-07-23 12:39:46 +02:00
|
|
|
\"tags\": [\"inbox\",
|
|
|
|
\"unread\"]}]"
|
2010-09-18 00:25:39 +02:00
|
|
|
|
2020-02-08 02:49:21 +01:00
|
|
|
test_begin_subtest "Search message: json, 64-bit timestamp"
|
2020-06-24 16:32:34 +02:00
|
|
|
if [ $NOTMUCH_HAVE_64BIT_TIME_T -ne 1 ]; then
|
|
|
|
test_subtest_known_broken
|
|
|
|
fi
|
2020-02-08 02:49:21 +01:00
|
|
|
add_message "[subject]=\"json-search-64bit-timestamp-subject\"" "[date]=\"Tue, 01 Jan 2999 12:00:00 -0000\"" "[body]=\"json-search-64bit-timestamp-message\""
|
|
|
|
output=$(notmuch search --format=json "json-search-64bit-timestamp-message" | notmuch_search_sanitize)
|
|
|
|
test_expect_equal_json "$output" "[{\"thread\": \"XXX\",
|
|
|
|
\"timestamp\": 32472187200,
|
|
|
|
\"date_relative\": \"the future\",
|
|
|
|
\"matched\": 1,
|
|
|
|
\"total\": 1,
|
|
|
|
\"authors\": \"Notmuch Test Suite\",
|
|
|
|
\"subject\": \"json-search-64bit-timestamp-subject\",
|
|
|
|
\"query\": [\"id:$gen_msg_id\", null],
|
|
|
|
\"tags\": [\"inbox\",
|
|
|
|
\"unread\"]}]"
|
|
|
|
|
2017-02-26 14:43:01 +01:00
|
|
|
test_begin_subtest "Format version: too low"
|
|
|
|
test_expect_code 20 "notmuch search --format-version=0 \\*"
|
2012-12-16 04:17:27 +01:00
|
|
|
|
2017-02-26 14:43:01 +01:00
|
|
|
test_begin_subtest "Format version: too high"
|
|
|
|
test_expect_code 21 "notmuch search --format-version=999 \\*"
|
2012-12-16 04:17:27 +01:00
|
|
|
|
2017-02-25 14:31:32 +01:00
|
|
|
test_begin_subtest "Show message: multiple filenames"
|
2017-06-04 14:32:29 +02:00
|
|
|
add_message '[id]=message-id@example.com [filename]=copy1 [date]="Fri, 05 Jan 2001 15:43:52 +0000"'
|
|
|
|
add_message '[id]=message-id@example.com [filename]=copy2 [date]="Fri, 05 Jan 2001 15:43:52 +0000"'
|
2017-02-25 14:31:32 +01:00
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"date_relative": "2001-01-05",
|
|
|
|
"excluded": false,
|
|
|
|
"filename": [
|
|
|
|
"${MAIL_DIR}/copy1",
|
|
|
|
"${MAIL_DIR}/copy2"
|
|
|
|
],
|
|
|
|
"headers": {
|
|
|
|
"Date": "Fri, 05 Jan 2001 15:43:52 +0000",
|
|
|
|
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
|
|
|
|
"Subject": "Show message: multiple filenames",
|
|
|
|
"To": "Notmuch Test Suite <test_suite@notmuchmail.org>"
|
|
|
|
},
|
|
|
|
"id": "message-id@example.com",
|
2019-05-25 20:04:06 +02:00
|
|
|
"crypto": {},
|
2017-02-25 14:31:32 +01:00
|
|
|
"match": true,
|
|
|
|
"tags": [
|
|
|
|
"inbox",
|
|
|
|
"unread"
|
|
|
|
],
|
|
|
|
"timestamp": 978709432
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
EOF
|
|
|
|
output=$(notmuch show --format=json --body=false id:message-id@example.com)
|
|
|
|
test_expect_equal_json "$output" "$(cat EXPECTED)"
|
|
|
|
|
|
|
|
test_begin_subtest "Show message: multiple filenames, format version 2"
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"date_relative": "2001-01-05",
|
|
|
|
"excluded": false,
|
|
|
|
"filename": "${MAIL_DIR}/copy1",
|
|
|
|
"headers": {
|
|
|
|
"Date": "Fri, 05 Jan 2001 15:43:52 +0000",
|
|
|
|
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
|
|
|
|
"Subject": "Show message: multiple filenames",
|
|
|
|
"To": "Notmuch Test Suite <test_suite@notmuchmail.org>"
|
|
|
|
},
|
|
|
|
"id": "message-id@example.com",
|
|
|
|
"match": true,
|
|
|
|
"tags": [
|
|
|
|
"inbox",
|
|
|
|
"unread"
|
|
|
|
],
|
|
|
|
"timestamp": 978709432
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
EOF
|
|
|
|
output=$(notmuch show --format=json --body=false --format-version=2 id:message-id@example.com)
|
|
|
|
test_expect_equal_json "$output" "$(cat EXPECTED)"
|
|
|
|
|
2010-06-10 08:48:03 +02:00
|
|
|
test_done
|