Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 54 / 243170397e33a8ee6d2838d29ee5cc7e452862
1 Return-Path: <markwalters1009@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id 9C72B6DE0948\r
6  for <notmuch@notmuchmail.org>; Sat, 13 Jun 2015 00:44:16 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.41\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.41 tagged_above=-999 required=5 tests=[AWL=0.980,\r
12  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13  FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,\r
14  RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
15  RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled\r
16 Received: from arlo.cworth.org ([127.0.0.1])\r
17  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
18  with ESMTP id DAgOJFcHsPwG for <notmuch@notmuchmail.org>;\r
19  Sat, 13 Jun 2015 00:44:14 -0700 (PDT)\r
20 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
21  [209.85.212.173])\r
22  by arlo.cworth.org (Postfix) with ESMTPS id 67FF66DE0350\r
23  for <notmuch@notmuchmail.org>; Sat, 13 Jun 2015 00:44:14 -0700 (PDT)\r
24 Received: by wiwd19 with SMTP id d19so34117023wiw.0\r
25  for <notmuch@notmuchmail.org>; Sat, 13 Jun 2015 00:44:12 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27  h=from:to:cc:subject:date:message-id;\r
28  bh=8QrAgou++3N5Yl3bLob4/AprJuHkpadF3X94L929pLo=;\r
29  b=lAv8THr7YB/TS+YT95dOeObBsD5lhh6cJ1tk+4MHvZML+0SsL9pM5I/eiSwJm0ip48\r
30  2KBkwm1zc9U5dmp/eYbHXnmoPOPgAYB2cBBcsEmPFQ+73ERetM+rx7+u4KDLj0IceVKv\r
31  2KRA5UCulSLPVkckS7Ql35V6qbVYjDLBWWUJGounWeKashmCEUHA56URs+cktSQZkfAd\r
32  A8plS3zKVGtDRB3RpckGiAgHNbRIrANko00Mps0D2iY/SkvclhBu7uu9utkqnQ6HmLzV\r
33  JH9LVcVcE2gsB1HSB/3wfnZcU1jJXYlAGQ8LvqM/f3nqUe4nwA/1L/ujRVJ8MLAh36eW\r
34  LwHw==\r
35 X-Received: by 10.180.106.137 with SMTP id gu9mr14027504wib.54.1434181450995; \r
36  Sat, 13 Jun 2015 00:44:10 -0700 (PDT)\r
37 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
38  by mx.google.com with ESMTPSA id m4sm7747594wjb.37.2015.06.13.00.44.10\r
39  (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
40  Sat, 13 Jun 2015 00:44:10 -0700 (PDT)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [RFC PATCH] emacs: show: show attachment size\r
44 Date: Sat, 13 Jun 2015 08:44:06 +0100\r
45 Message-Id: <1434181446-5701-1-git-send-email-markwalters1009@gmail.com>\r
46 X-Mailer: git-send-email 2.1.4\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.18\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51  <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Sat, 13 Jun 2015 07:44:16 -0000\r
60 \r
61 Display the attachment size in kB or MB in the part button. This uses\r
62 the content-length header and guesses the actual size from that, so\r
63 the value will be close but not exact.\r
64 ---\r
65 \r
66 This patch adds some text to the part button saying how big the part\r
67 is. This is particularly useful when running notmuch over ssh but may\r
68 be informative anyway.\r
69 \r
70 One particular question is am I putting sizes on the correct parts?\r
71 This patch puts a size on all parts where we know the size and it is\r
72 not hidden ( part buttons of the form [ text/html (hidden) (30kB) ]\r
73 looked messy).\r
74 \r
75 There are a couple of caveats with the patch. First the size is\r
76 approximate. This is because gmime/notmuch only outputs the encoded\r
77 size. We guess the true size is roughly 3/4 the encoded size if it is\r
78 base64 encoded and the encoded size otherwise. (See\r
79 id:20120807232414.GA22132@hili.localdomain and Austin's reply.)\r
80 \r
81 Secondly, lots of tests fail. This is expected as the output for any\r
82 message with attachment has changed. I thought I would see whether\r
83 people liked the idea, and which parts people think need a size before\r
84 fixing them.\r
85 \r
86 Best wishes\r
87 \r
88 Mark\r
89 \r
90 \r
91 \r
92 emacs/notmuch-show.el | 26 +++++++++++++++++++++++++-\r
93  1 file changed, 25 insertions(+), 1 deletion(-)\r
94 \r
95 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
96 index 2a53461..f26e2f8 100644\r
97 --- a/emacs/notmuch-show.el\r
98 +++ b/emacs/notmuch-show.el\r
99 @@ -488,6 +488,25 @@ (define-button-type 'notmuch-show-part-button-type\r
100    'face 'message-mml\r
101    :supertype 'notmuch-button-type)\r
102  \r
103 +(defun notmuch-show-part-pretty-size (part)\r
104 +  "Return a nicely formatted string of the approximate part size in kB or MB if known"\r
105 +  ;; We guess the size from the encoded length (which is all\r
106 +  ;; gmime tells us). If it is base64 encoded the size will be\r
107 +  ;; approximately 3/4 of the encoded size, otherwise (e.g. if it\r
108 +  ;; is quoted printable) the size is probably pretty close to\r
109 +  ;; the encoded size.\r
110 +  (let ((approx-size (if (string= (plist-get part :content-transfer-encoding) "base64")\r
111 +                        (/ (* (plist-get part :content-length) 3) 4)\r
112 +                      (plist-get part :content-length))))\r
113 +    (cond ((not approx-size)\r
114 +          nil)\r
115 +         ((< approx-size 1000000)\r
116 +          (format " (%s kB)" (1+ (/ approx-size 1000))))\r
117 +         ((< approx-size 10000000)\r
118 +          (format " (%s.%s MB)" (/ approx-size 1000000) (% (/ approx-size 100000) 10)))\r
119 +         (t\r
120 +          (format " (%s MB)" (/ approx-size 1000000))))))\r
121 +\r
122  (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)\r
123    (let ((button)\r
124         (base-label (concat (when name (concat name ": "))\r
125 @@ -948,11 +967,16 @@ (defun notmuch-show-insert-bodypart (msg part depth &optional hide)\r
126                     (> notmuch-show-max-text-part-size 0)\r
127                     (> (length (plist-get part :content)) notmuch-show-max-text-part-size)))\r
128          (beg (point))\r
129 +        (pretty-size (unless hide (notmuch-show-part-pretty-size part)))\r
130          ;; We omit the part button for the first (or only) part if\r
131          ;; this is text/plain, or HIDE is 'no-buttons.\r
132          (button (unless (or (equal hide 'no-buttons)\r
133                              (and (string= mime-type "text/plain") (<= nth 1)))\r
134 -                  (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))\r
135 +                  (notmuch-show-insert-part-header nth\r
136 +                                                   mime-type\r
137 +                                                   content-type\r
138 +                                                   (plist-get part :filename)\r
139 +                                                   pretty-size)))\r
140          ;; Hide the part initially if HIDE is t, or if it is too long\r
141          ;; and we have a button to allow toggling (thus reply which\r
142          ;; uses 'no-buttons automatically includes long parts)\r
143 -- \r
144 2.1.4\r
145 \r