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