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 BB3A0431FAF for ; Mon, 6 Aug 2012 09:47:14 -0700 (PDT) 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 9Ml6I0dPifku for ; Mon, 6 Aug 2012 09:47:12 -0700 (PDT) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id C4E72431FAE for ; Mon, 6 Aug 2012 09:47:12 -0700 (PDT) X-AuditID: 1209190f-b7f306d0000008b4-f7-501ff5109266 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id B5.37.02228.015FF105; Mon, 6 Aug 2012 12:47:12 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q76GlBka016635; Mon, 6 Aug 2012 12:47:12 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q76GlAQo018537 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 6 Aug 2012 12:47:11 -0400 (EDT) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1SyQSU-00035Y-CK; Mon, 06 Aug 2012 12:47:10 -0400 Date: Mon, 6 Aug 2012 12:47:10 -0400 From: Austin Clements To: Peter Wang Subject: Re: [PATCH 1/4] show: indicate length of omitted body content (json) Message-ID: <20120806164710.GK22601@mit.edu> References: <1344151345-25411-1-git-send-email-novalazy@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1344151345-25411-1-git-send-email-novalazy@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgleLIzCtJLcpLzFFi42IRYrdT1xX4Kh9g0LlY3OL6zZnMFs9b9zI5 MHnsnHWX3ePZqlvMAUxRXDYpqTmZZalF+nYJXBnLju5gLDgkUrFxxzbWBsYmgS5GTg4JAROJ vYvXsEDYYhIX7q1nA7GFBPYxSrx9odTFyAVkr2eU6FtwiBXCOcEk8fjnJKiqJYwSC1blgNgs AioSlxdPYQSx2QQ0JLbtXw5miwgoS/z59QysnllAWuLb72amLkYODmEBX4nLl8tAwrwCOhLN X04wg4SFBJwkJj+1gwgLSpyc+YQFolNL4sa/l2CdIFOW/+MACXMKOEvM3NQPViIKdMCUk9vY JjAKzULSPQtJ9yyE7gWMzKsYZVNyq3RzEzNzilOTdYuTE/PyUot0TfRyM0v0UlNKNzGCAppT kn8H47eDSocYBTgYlXh4nXrkA4RYE8uKK3MPMUpyMCmJ8sa+AwrxJeWnVGYkFmfEF5XmpBYf YpTgYFYS4a1ZCJTjTUmsrEotyodJSXOwKInzXk256S8kkJ5YkpqdmlqQWgSTleHgUJLgVf4C 1ChYlJqeWpGWmVOCkGbi4AQZzgM0/NdnkOHFBYm5xZnpEPlTjIpS4rxiIM0CIImM0jy4XljC ecUoDvSKMEQVDzBZwXW/AhrMBDTYW14OZHBJIkJKCphkfjUar+A+k5nIP1FG5yPTLUn/grdy C/YqnfVJudTx4WLJ2T2neybIc2m+czhaWcT3RGBy1rpD/k0rlj94Hvxtuib3mRfrfYslNq9K WX6rbCLz1qVbeLxcBSQlPlVvS23pKZyaZ798jrHVfG8Ro9VzW67w/eziWPP9re0dvuN3Juw/ ebGj4GCJEktxRqKhFnNRcSIAWwXwSxMDAAA= Cc: notmuch@notmuchmail.org 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, 06 Aug 2012 16:47:14 -0000 What's the overall goal of adding this? Are you planning to add size information to one of the frontends? Quoth Peter Wang on Aug 05 at 5:22 pm: > 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. You mentioned elsewhere that the content-length returned is an estimate. If that's the case, this comment should say as much. Is it actually the case, though? g_mime_part_get_content_object is remarkably poorly documented for such an important function, but based on format_part_raw, it seems like the content-length your code returns will be exactly the number of bytes returned by the raw format for a leaf part. > + 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); > + } Do wrapper or stream need to be g_object_unref'd? Any idea what the performance overhead of this is? I'm just curious. It might be approximately nothing, since GMime's parser is eager. > } > } else if (GMIME_IS_MULTIPART (node->part)) { > sp->map_key (sp, "content");