From: Austin Clements Date: Mon, 20 Feb 2012 00:26:26 +0000 (+1900) Subject: [PATCH v2 4/8] show: Unify JSON header output for messages and message parts X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=d16a5adc8bacee1f1e613ba9b8842ad4efe0bd18;p=notmuch-archives.git [PATCH v2 4/8] show: Unify JSON header output for messages and message parts --- diff --git a/c4/7cfe6e4b8b91c5fef64a338753c60f30182bce b/c4/7cfe6e4b8b91c5fef64a338753c60f30182bce new file mode 100644 index 000000000..f07cb56c7 --- /dev/null +++ b/c4/7cfe6e4b8b91c5fef64a338753c60f30182bce @@ -0,0 +1,324 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id A9C91431FAF + for ; Sun, 19 Feb 2012 16:26:46 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 NrhqZWEpbVuw for ; + Sun, 19 Feb 2012 16:26:42 -0800 (PST) +Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU + [18.7.68.34]) + by olra.theworths.org (Postfix) with ESMTP id E51B8431FC9 + for ; Sun, 19 Feb 2012 16:26:36 -0800 (PST) +X-AuditID: 12074422-b7fd66d0000008f9-c4-4f41933cae99 +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP + id 90.06.02297.C33914F4; Sun, 19 Feb 2012 19:26:36 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q1K0QakW024839; + Sun, 19 Feb 2012 19:26:36 -0500 +Received: from drake.mit.edu + (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [209.6.116.242]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q1K0QYbI000309 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sun, 19 Feb 2012 19:26:35 -0500 (EST) +Received: from amthrax by drake.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1RzH5N-0001yL-Lt; Sun, 19 Feb 2012 19:26:33 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: + [PATCH v2 4/8] show: Unify JSON header output for messages and message parts +Date: Sun, 19 Feb 2012 19:26:26 -0500 +Message-Id: <1329697590-7404-5-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.7.3 +In-Reply-To: <1329697590-7404-1-git-send-email-amdragon@mit.edu> +References: <1329240823-7856-1-git-send-email-amdragon@mit.edu> + <1329697590-7404-1-git-send-email-amdragon@mit.edu> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFuphleLIzCtJLcpLzFFi42IR4hTV1rWZ7OhvsKJD1+L6zZnMFm9WzmN1 + YPI4/HUhi8ezVbeYA5iiuGxSUnMyy1KL9O0SuDI+dgUUHEmvOPEuuoHxZUQXIyeHhICJxNOr + s1ggbDGJC/fWs3UxcnEICexjlHi4/gArhLOBUeJX9y0mCOc+k8TiPUtZIJz5jBK/f35gBeln + E9CQ2LZ/OSOILSIgLbHz7mywOLOAlcThq5vAbGGBeon/azcA1XBwsAioSpxcYQgS5hWwl3j0 + 5yMTxBkKEudWn2MHKeEUcJBYvcMVJCwkUCpx5MkWJohyQYmTM5+wgJQwC6hLrJ8nBLFIXqJ5 + 62zmCYxCs5BUzUKomoWkagEj8ypG2ZTcKt3cxMyc4tRk3eLkxLy81CJdU73czBK91JTSTYyg + gGZ3UdrB+POg0iFGAQ5GJR5eyTIHfyHWxLLiytxDjJIcTEqivKcmOPoL8SXlp1RmJBZnxBeV + 5qQWH2KU4GBWEuFdYA+U401JrKxKLcqHSUlzsCiJ86prvfMTEkhPLEnNTk0tSC2CycpwcChJ + 8O6aBNQoWJSanlqRlplTgpBm4uAEGc4DNPwaSA1vcUFibnFmOkT+FKMux4FPzy8wCrHk5eel + Sonz7gcpEgApyijNg5sDS0SvGMWB3hLmTQOp4gEmMbhJr4CWMAEt4RWyA1lSkoiQkmpgVE7e + 5z5hX19j49kYzddTuT9mb3jYd6lg2w+76PYQ2XrVXzNPfU9sdUmpfBeus7niptfvhZqdiip2 + +7S2/5JkUGCdmnLp8mn2Dbks13Na/jOlzF2le4v/faDKquJd12bu7+wUclX6KvEgNvSBdser + g/stjpoGpM64Munt1fvMuS8v/4lmSzohqMRSnJFoqMVcVJwIANSSrb4fAwAA +Cc: tomi.ollila@iki.fi +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, 20 Feb 2012 00:26:47 -0000 + +This has three ramifications: +- Blank To and Cc headers are no longer output for messages. +- Dates are now canonicalized for messages, which means they always + have a day of the week and GMT is printed +0000 (never -0000) +- Invalid From message headers are handled slightly differently, since + they get parsed by GMime now instead of notmuch. +--- + notmuch-show.c | 35 +++-------------------------------- + test/crypto | 35 ++++++++++++++--------------------- + test/emacs | 4 ++-- + test/json | 6 +++--- + test/maildir-sync | 2 -- + test/multipart | 2 +- + 6 files changed, 23 insertions(+), 61 deletions(-) + +diff --git a/notmuch-show.c b/notmuch-show.c +index 9ca9882..209ff45 100644 +--- a/notmuch-show.c ++++ b/notmuch-show.c +@@ -291,36 +291,7 @@ format_headers_message_part_text (GMimeMessage *message) + } + + static void +-format_headers_json (const void *ctx, notmuch_message_t *message) +-{ +- const char *headers[] = { +- "Subject", "From", "To", "Cc", "Bcc", "Date" +- }; +- const char *name, *value; +- unsigned int i; +- int first_header = 1; +- void *ctx_quote = talloc_new (ctx); +- +- for (i = 0; i < ARRAY_SIZE (headers); i++) { +- name = headers[i]; +- value = notmuch_message_get_header (message, name); +- if (value) +- { +- if (!first_header) +- fputs (", ", stdout); +- first_header = 0; +- +- printf ("%s: %s", +- json_quote_str (ctx_quote, name), +- json_quote_str (ctx_quote, value)); +- } +- } +- +- talloc_free (ctx_quote); +-} +- +-static void +-format_headers_message_part_json (GMimeMessage *message) ++format_headers_json (GMimeMessage *message) + { + void *ctx = talloc_new (NULL); + void *ctx_quote = talloc_new (ctx); +@@ -690,7 +661,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) + format_message_json (ctx, node->envelope_file); + + printf ("\"headers\": {"); +- format_headers_json (ctx, node->envelope_file); ++ format_headers_json (GMIME_MESSAGE (node->part)); + printf ("}"); + + printf (", \"body\": ["); +@@ -778,7 +749,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) + + if (GMIME_IS_MESSAGE (node->part)) { + printf ("\"headers\": {"); +- format_headers_message_part_json (GMIME_MESSAGE (node->part)); ++ format_headers_json (GMIME_MESSAGE (node->part)); + printf ("}"); + + printf (", \"body\": ["); +diff --git a/test/crypto b/test/crypto +index 1dbb60a..7e774c8 100755 +--- a/test/crypto ++++ b/test/crypto +@@ -50,9 +50,8 @@ expected='[[[{"id": "XXXXX", + "headers": {"Subject": "test signed message 001", + "From": "Notmuch Test Suite ", + "To": "test_suite@notmuchmail.org", +- "Cc": "", +- "Bcc": "", +- "Date": "01 Jan 2000 12:00:00 -0000"}, ++ "Date": "Sat, ++ 01 Jan 2000 12:00:00 +0000"}, + "body": [{"id": 1, + "sigstatus": [{"status": "good", + "fingerprint": "'$FINGERPRINT'", +@@ -84,9 +83,8 @@ expected='[[[{"id": "XXXXX", + "headers": {"Subject": "test signed message 001", + "From": "Notmuch Test Suite ", + "To": "test_suite@notmuchmail.org", +- "Cc": "", +- "Bcc": "", +- "Date": "01 Jan 2000 12:00:00 -0000"}, ++ "Date": "Sat, ++ 01 Jan 2000 12:00:00 +0000"}, + "body": [{"id": 1, + "sigstatus": [{"status": "good", + "fingerprint": "'$FINGERPRINT'", +@@ -120,9 +118,8 @@ expected='[[[{"id": "XXXXX", + "headers": {"Subject": "test signed message 001", + "From": "Notmuch Test Suite ", + "To": "test_suite@notmuchmail.org", +- "Cc": "", +- "Bcc": "", +- "Date": "01 Jan 2000 12:00:00 -0000"}, ++ "Date": "Sat, ++ 01 Jan 2000 12:00:00 +0000"}, + "body": [{"id": 1, + "sigstatus": [{"status": "error", + "keyid": "'$(echo $FINGERPRINT | cut -c 25-)'", +@@ -194,9 +191,8 @@ expected='[[[{"id": "XXXXX", + "headers": {"Subject": "test encrypted message 001", + "From": "Notmuch Test Suite ", + "To": "test_suite@notmuchmail.org", +- "Cc": "", +- "Bcc": "", +- "Date": "01 Jan 2000 12:00:00 -0000"}, ++ "Date": "Sat, ++ 01 Jan 2000 12:00:00 +0000"}, + "body": [{"id": 1, + "encstatus": [{"status": "good"}], + "sigstatus": [], +@@ -249,9 +245,8 @@ expected='[[[{"id": "XXXXX", + "headers": {"Subject": "test encrypted message 001", + "From": "Notmuch Test Suite ", + "To": "test_suite@notmuchmail.org", +- "Cc": "", +- "Bcc": "", +- "Date": "01 Jan 2000 12:00:00 -0000"}, ++ "Date": "Sat, ++ 01 Jan 2000 12:00:00 +0000"}, + "body": [{"id": 1, + "encstatus": [{"status": "bad"}], + "content-type": "multipart/encrypted", +@@ -284,9 +279,8 @@ expected='[[[{"id": "XXXXX", + "headers": {"Subject": "test encrypted message 002", + "From": "Notmuch Test Suite ", + "To": "test_suite@notmuchmail.org", +- "Cc": "", +- "Bcc": "", +- "Date": "01 Jan 2000 12:00:00 -0000"}, ++ "Date": "Sat, ++ 01 Jan 2000 12:00:00 +0000"}, + "body": [{"id": 1, + "encstatus": [{"status": "good"}], + "sigstatus": [{"status": "good", +@@ -339,9 +333,8 @@ expected='[[[{"id": "XXXXX", + "headers": {"Subject": "test signed message 001", + "From": "Notmuch Test Suite ", + "To": "test_suite@notmuchmail.org", +- "Cc": "", +- "Bcc": "", +- "Date": "01 Jan 2000 12:00:00 -0000"}, ++ "Date": "Sat, ++ 01 Jan 2000 12:00:00 +0000"}, + "body": [{"id": 1, + "sigstatus": [{"status": "error", + "keyid": "6D92612D94E46381", +diff --git a/test/emacs b/test/emacs +index b74cfa9..d4a8d30 100755 +--- a/test/emacs ++++ b/test/emacs +@@ -78,7 +78,7 @@ thread=$(notmuch search --output=threads subject:message-with-invalid-from) + test_emacs "(notmuch-show \"$thread\") + (test-output)" + cat <EXPECTED +-Invalid " From (2001-01-05) (inbox) ++"Invalid " (2001-01-05) (inbox) + Subject: message-with-invalid-from + To: Notmuch Test Suite + Date: Fri, 05 Jan 2001 15:43:57 +0000 +@@ -411,7 +411,7 @@ test_emacs '(notmuch-show "id:\"bought\"") + (reverse-region (point-min) (point-max)) + (test-output)' + cat <EXPECTED +-Sat, 01 Jan 2000 12:00:00 -0000 ++Sat, 01 Jan 2000 12:00:00 +0000 + Some One + Some One Else + Notmuch +diff --git a/test/json b/test/json +index 7df4380..1bdffd2 100755 +--- a/test/json ++++ b/test/json +@@ -5,7 +5,7 @@ test_description="--format=json output" + test_begin_subtest "Show message: json" + add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-show-message\"" + output=$(notmuch show --format=json "json-show-message") +-test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite \", \"To\": \"Notmuch Test Suite \", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 -0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]" ++test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite \", \"To\": \"Notmuch Test Suite \", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]" + + 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\"" +@@ -22,7 +22,7 @@ test_expect_equal "$output" "[{\"thread\": \"XXX\", + 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\"" + output=$(notmuch show --format=json "jsön-show-méssage") +-test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"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 \", \"To\": \"Notmuch Test Suite \", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 -0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]" ++test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"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 \", \"To\": \"Notmuch Test Suite \", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]" + + test_begin_subtest "Show message: json, inline attachment filename" + subject='json-show-inline-attachment-filename' +@@ -35,7 +35,7 @@ emacs_deliver_message \ + (insert \"Message-ID: <$id>\n\")" + output=$(notmuch show --format=json "id:$id") + filename=$(notmuch search --output=files "id:$id") +-test_expect_equal "$output" "[[[{\"id\": \"$id\", \"match\": true, \"filename\": \"$filename\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\"], \"headers\": {\"Subject\": \"$subject\", \"From\": \"Notmuch Test Suite \", \"To\": \"test_suite@notmuchmail.org\", \"Cc\": \"\", \"Bcc\": \"\", \"Date\": \"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\"}]}]}, []]]]" ++test_expect_equal "$output" "[[[{\"id\": \"$id\", \"match\": true, \"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\", \"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/maildir-sync b/test/maildir-sync +index d5872a5..1ee2db0 100755 +--- a/test/maildir-sync ++++ b/test/maildir-sync +@@ -53,8 +53,6 @@ test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite", + "headers": {"Subject": "Adding replied tag", + "From": "Notmuch Test Suite ", + "To": "Notmuch Test Suite ", +-"Cc": "", +-"Bcc": "", + "Date": "Fri, + 05 Jan 2001 15:43:57 +0000"}, + "body": [{"id": 1, +diff --git a/test/multipart b/test/multipart +index 4d14804..a3036b4 100755 +--- a/test/multipart ++++ b/test/multipart +@@ -322,7 +322,7 @@ notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' | s + echo >>OUTPUT # expect *no* newline at end of output + cat <EXPECTED + +-{"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "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", "Cc": "", "Bcc": "", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [ ++{"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "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": [ +-- +1.7.7.3 +