From: Mark Walters Date: Sat, 13 Jun 2015 07:44:06 +0000 (+0100) Subject: [RFC PATCH] emacs: show: show attachment size X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8cf3bb2706f006bdf4ffc8f6615cff5fbf94d252;p=notmuch-archives.git [RFC PATCH] emacs: show: show attachment size --- diff --git a/54/243170397e33a8ee6d2838d29ee5cc7e452862 b/54/243170397e33a8ee6d2838d29ee5cc7e452862 new file mode 100644 index 000000000..5b8591ab4 --- /dev/null +++ b/54/243170397e33a8ee6d2838d29ee5cc7e452862 @@ -0,0 +1,145 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 9C72B6DE0948 + for ; Sat, 13 Jun 2015 00:44:16 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.41 +X-Spam-Level: +X-Spam-Status: No, score=0.41 tagged_above=-999 required=5 tests=[AWL=0.980, + DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, + RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] 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 DAgOJFcHsPwG for ; + Sat, 13 Jun 2015 00:44:14 -0700 (PDT) +Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com + [209.85.212.173]) + by arlo.cworth.org (Postfix) with ESMTPS id 67FF66DE0350 + for ; Sat, 13 Jun 2015 00:44:14 -0700 (PDT) +Received: by wiwd19 with SMTP id d19so34117023wiw.0 + for ; Sat, 13 Jun 2015 00:44:12 -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; + bh=8QrAgou++3N5Yl3bLob4/AprJuHkpadF3X94L929pLo=; + b=lAv8THr7YB/TS+YT95dOeObBsD5lhh6cJ1tk+4MHvZML+0SsL9pM5I/eiSwJm0ip48 + 2KBkwm1zc9U5dmp/eYbHXnmoPOPgAYB2cBBcsEmPFQ+73ERetM+rx7+u4KDLj0IceVKv + 2KRA5UCulSLPVkckS7Ql35V6qbVYjDLBWWUJGounWeKashmCEUHA56URs+cktSQZkfAd + A8plS3zKVGtDRB3RpckGiAgHNbRIrANko00Mps0D2iY/SkvclhBu7uu9utkqnQ6HmLzV + JH9LVcVcE2gsB1HSB/3wfnZcU1jJXYlAGQ8LvqM/f3nqUe4nwA/1L/ujRVJ8MLAh36eW + LwHw== +X-Received: by 10.180.106.137 with SMTP id gu9mr14027504wib.54.1434181450995; + Sat, 13 Jun 2015 00:44:10 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id m4sm7747594wjb.37.2015.06.13.00.44.10 + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 13 Jun 2015 00:44:10 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [RFC PATCH] emacs: show: show attachment size +Date: Sat, 13 Jun 2015 08:44:06 +0100 +Message-Id: <1434181446-5701-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 2.1.4 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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: Sat, 13 Jun 2015 07:44:16 -0000 + +Display the attachment size in kB or MB in the part button. This uses +the content-length header and guesses the actual size from that, so +the value will be close but not exact. +--- + +This patch adds some text to the part button saying how big the part +is. This is particularly useful when running notmuch over ssh but may +be informative anyway. + +One particular question is am I putting sizes on the correct parts? +This patch puts a size on all parts where we know the size and it is +not hidden ( part buttons of the form [ text/html (hidden) (30kB) ] +looked messy). + +There are a couple of caveats with the patch. First the size is +approximate. This is because gmime/notmuch only outputs the encoded +size. We guess the true size is roughly 3/4 the encoded size if it is +base64 encoded and the encoded size otherwise. (See +id:20120807232414.GA22132@hili.localdomain and Austin's reply.) + +Secondly, lots of tests fail. This is expected as the output for any +message with attachment has changed. I thought I would see whether +people liked the idea, and which parts people think need a size before +fixing them. + +Best wishes + +Mark + + + +emacs/notmuch-show.el | 26 +++++++++++++++++++++++++- + 1 file changed, 25 insertions(+), 1 deletion(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 2a53461..f26e2f8 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -488,6 +488,25 @@ (define-button-type 'notmuch-show-part-button-type + 'face 'message-mml + :supertype 'notmuch-button-type) + ++(defun notmuch-show-part-pretty-size (part) ++ "Return a nicely formatted string of the approximate part size in kB or MB if known" ++ ;; We guess the size from the encoded length (which is all ++ ;; gmime tells us). If it is base64 encoded the size will be ++ ;; approximately 3/4 of the encoded size, otherwise (e.g. if it ++ ;; is quoted printable) the size is probably pretty close to ++ ;; the encoded size. ++ (let ((approx-size (if (string= (plist-get part :content-transfer-encoding) "base64") ++ (/ (* (plist-get part :content-length) 3) 4) ++ (plist-get part :content-length)))) ++ (cond ((not approx-size) ++ nil) ++ ((< approx-size 1000000) ++ (format " (%s kB)" (1+ (/ approx-size 1000)))) ++ ((< approx-size 10000000) ++ (format " (%s.%s MB)" (/ approx-size 1000000) (% (/ approx-size 100000) 10))) ++ (t ++ (format " (%s MB)" (/ approx-size 1000000)))))) ++ + (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment) + (let ((button) + (base-label (concat (when name (concat name ": ")) +@@ -948,11 +967,16 @@ (defun notmuch-show-insert-bodypart (msg part depth &optional hide) + (> notmuch-show-max-text-part-size 0) + (> (length (plist-get part :content)) notmuch-show-max-text-part-size))) + (beg (point)) ++ (pretty-size (unless hide (notmuch-show-part-pretty-size part))) + ;; We omit the part button for the first (or only) part if + ;; this is text/plain, or HIDE is 'no-buttons. + (button (unless (or (equal hide 'no-buttons) + (and (string= mime-type "text/plain") (<= nth 1))) +- (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))) ++ (notmuch-show-insert-part-header nth ++ mime-type ++ content-type ++ (plist-get part :filename) ++ pretty-size))) + ;; Hide the part initially if HIDE is t, or if it is too long + ;; and we have a button to allow toggling (thus reply which + ;; uses 'no-buttons automatically includes long parts) +-- +2.1.4 +