From 9da1e985eaf41c7cfd15da4d631a9b3925293328 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Sun, 5 Aug 2012 17:22:22 +1000 Subject: [PATCH] [PATCH 1/4] show: indicate length of omitted body content (json) --- 5c/7222e7e5e5d3894e9e2407aca18030c3568486 | 106 ++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 5c/7222e7e5e5d3894e9e2407aca18030c3568486 diff --git a/5c/7222e7e5e5d3894e9e2407aca18030c3568486 b/5c/7222e7e5e5d3894e9e2407aca18030c3568486 new file mode 100644 index 000000000..c2e87c3af --- /dev/null +++ b/5c/7222e7e5e5d3894e9e2407aca18030c3568486 @@ -0,0 +1,106 @@ +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 04C01431FAF + for ; Sun, 5 Aug 2012 00:22:42 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, 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 EwfJmW2X-tWq for ; + Sun, 5 Aug 2012 00:22:41 -0700 (PDT) +Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com + [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 804DC431FAE + for ; Sun, 5 Aug 2012 00:22:41 -0700 (PDT) +Received: by pbbro8 with SMTP id ro8so3935886pbb.26 + for ; Sun, 05 Aug 2012 00:22:40 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer; + bh=PJUe6fnrljYh20/N+hiZ/B+9DabpRSOCgbWic7ASyCs=; + b=lb4dtVfgmmPABIyTQhoi8XqgivAhopEMuuTdDGT+qFWZNIPF+e4luWReVi0IFfiP3c + PVpNjVSoq0Y8XlqstNnuIZ2RSv90cL8dmgdOaSdYo+TzW+iXlGg4WmVQotZhHHd0O6L0 + TW8tPlc0J8athoTix2n23pbANaCEyKyLcnHSFj09NnAgnIn4Zo7RVQw/QNbBSUOJf1Vu + ZYSeBm+ooPMjALezXUhzce/FENFljGk9H2xuMaO9omDvbshXhOW1hujmR3N8z0Pke1N2 + COoi/0q5MLjfzC7pnnxvoZ/z3QPr3viwhiMhHRcIJbUNk8TW/95dDNEJ28Ne7K8TEWk2 + SOFQ== +Received: by 10.68.239.164 with SMTP id vt4mr706718pbc.118.1344151360697; + Sun, 05 Aug 2012 00:22:40 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id of4sm6404538pbb.51.2012.08.05.00.22.37 + (version=TLSv1/SSLv3 cipher=OTHER); + Sun, 05 Aug 2012 00:22:39 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH 1/4] show: indicate length of omitted body content (json) +Date: Sun, 5 Aug 2012 17:22:22 +1000 +Message-Id: <1344151345-25411-1-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.4.4 +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: Sun, 05 Aug 2012 07:22:42 -0000 + +If a leaf part's body content is omitted, return the content length in +--format=json output. This information may be used by the consumer, +e.g. to decide whether to download a large attachment over a slow link. +--- + devel/schemata | 5 ++++- + notmuch-show.c | 8 ++++++++ + 2 files changed, 12 insertions(+), 1 deletions(-) + +diff --git a/devel/schemata b/devel/schemata +index 9cb25f5..3df2764 100644 +--- a/devel/schemata ++++ b/devel/schemata +@@ -69,7 +69,10 @@ part = { + # A leaf part's body content is optional, but may be included if + # it can be correctly encoded as a string. Consumers should use + # this in preference to fetching the part content separately. +- content?: string ++ content?: string, ++ # If a leaf part's body content is not included, the content-length ++ # may be included instead. ++ content-length?: int + } + + # The headers of a message or part (format_headers_json with reply = FALSE) +diff --git a/notmuch-show.c b/notmuch-show.c +index 3556293..5c54257 100644 +--- a/notmuch-show.c ++++ b/notmuch-show.c +@@ -664,6 +664,14 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, + sp->map_key (sp, "content"); + sp->string_len (sp, (char *) part_content->data, part_content->len); + g_object_unref (stream_memory); ++ } else { ++ GMimeDataWrapper *wrapper = g_mime_part_get_content_object (GMIME_PART (node->part)); ++ GMimeStream *stream = g_mime_data_wrapper_get_stream (wrapper); ++ ssize_t length = g_mime_stream_length (stream); ++ if (length >= 0) { ++ sp->map_key (sp, "content-length"); ++ sp->integer (sp, length); ++ } + } + } else if (GMIME_IS_MULTIPART (node->part)) { + sp->map_key (sp, "content"); +-- +1.7.4.4 + -- 2.26.2