Missing headers when forwarding html message as RFC822
[notmuch-archives.git] / b4 / 175a38b214e194ffbd547ee6a240799c28c752
1 Return-Path: <bremner@pivot.cs.unb.ca>\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 olra.theworths.org (Postfix) with ESMTP id CFAEA431FBC\r
6         for <notmuch@notmuchmail.org>; Thu, 24 Dec 2009 11:13:02 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id MSJXjDVi+q1h for <notmuch@notmuchmail.org>;\r
11         Thu, 24 Dec 2009 11:13:02 -0800 (PST)\r
12 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])\r
13         by olra.theworths.org (Postfix) with ESMTP id 25217431FAE\r
14         for <notmuch@notmuchmail.org>; Thu, 24 Dec 2009 11:13:02 -0800 (PST)\r
15 Received: from\r
16         fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net\r
17         ([142.167.182.194] helo=localhost)\r
18         by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)\r
19         (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)\r
20         id 1NNt7M-0008Lh-9k; Thu, 24 Dec 2009 15:13:00 -0400\r
21 Received: from bremner by localhost with local (Exim 4.71)\r
22         (envelope-from <bremner@pivot.cs.unb.ca>)\r
23         id 1NNt7G-000246-Po; Thu, 24 Dec 2009 15:12:54 -0400\r
24 From: david@tethera.net\r
25 To: notmuch@notmuchmail.org\r
26 Date: Thu, 24 Dec 2009 15:12:43 -0400\r
27 Message-Id: <1261681963-7878-1-git-send-email-david@tethera.net>\r
28 X-Mailer: git-send-email 1.6.5.7\r
29 In-Reply-To: <1261665534-2445-1-git-send-email-david@tethera.net>\r
30 References: <1261665534-2445-1-git-send-email-david@tethera.net>\r
31 X-Sender-Verified: bremner@pivot.cs.unb.ca\r
32 Cc: David Bremner <bremner@unb.ca>\r
33 Subject: [notmuch] [PATCH] notmuch.el: Refactor citation markup. Variables\r
34         for minimum size, button text.\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.12\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Thu, 24 Dec 2009 19:13:03 -0000\r
48 \r
49 From: David Bremner <bremner@unb.ca>\r
50 \r
51 This is a fairly intrusive rewrite.\r
52 \r
53 - I pulled the common code for the signature and citation case out\r
54   into a separate function. This is not so much shorter, but I think it\r
55   will be easier to maintain.\r
56 \r
57 - I replaced the sequence of (looking-at blah) (forward-line)  with a single\r
58   re-search-forward per citation.\r
59 \r
60 New variables\r
61 \r
62 - notmuch-show-signature-button-format, notmuch-show-citation-button-format\r
63   Allow customization of button text.\r
64 \r
65 - notmuch-show-citation-lines-min\r
66   Do not buttonize citations below the given threshold.\r
67 ---\r
68 \r
69 This is an updated (already!) version of the patch. It fixes 3\r
70 bugs. Let's forget they were my silly bugs, and be impressed with my\r
71 fixing :).  This version has a call to untabify on the whole region,\r
72 which is a bit annoying, but it avoids getting really fancy with the\r
73 regexp to match tabs as x-spaces. Another alternative would be to\r
74 convince indent-rigidly to only use spaces, but I didn't see an\r
75 immediate way to configure that.\r
76 \r
77 \r
78  notmuch.el |  133 ++++++++++++++++++++++++++++++++++++++---------------------\r
79  1 files changed, 86 insertions(+), 47 deletions(-)\r
80 \r
81 diff --git a/notmuch.el b/notmuch.el\r
82 index 97914f2..9707c25 100644\r
83 --- a/notmuch.el\r
84 +++ b/notmuch.el\r
85 @@ -92,9 +92,24 @@ for indentation at the beginning of the line. But notmuch will\r
86  move past the indentation when testing this pattern, (so that the\r
87  pattern can still test against the entire line).")\r
88  \r
89 +(defvar notmuch-show-signature-button-format \r
90 +  "[ %d-line hidden signature. Click/Enter to show ]"\r
91 +  "String used to construct button text for hidden signatures\r
92 +\r
93 +Can use up to one integer format parameter, i.e. %d")\r
94 +\r
95 +(defvar notmuch-show-citation-button-format \r
96 +  "[ %d-line hidden citation. Click/Enter to show ]"\r
97 +  "String used to construct button text for hidden citations.\r
98 +\r
99 +Can use up to one integer format parameter, i.e. %d")\r
100 +\r
101  (defvar notmuch-show-signature-lines-max 12\r
102    "Maximum length of signature that will be hidden by default.")\r
103  \r
104 +(defvar notmuch-show-citation-lines-min 4\r
105 +  "Minimum length of citation that will be hidden.")\r
106 +\r
107  (defvar notmuch-command "notmuch"\r
108    "Command to run the notmuch binary.")\r
109  \r
110 @@ -593,54 +608,78 @@ which this thread was originally shown."\r
111    'face 'notmuch-message-summary-face\r
112    :supertype 'notmuch-button-invisibility-toggle-type)\r
113  \r
114 +(defun notmuch-show-citation-regexp (depth)\r
115 +  "Build a regexp for matching citations at a given DEPTH (indent)"\r
116 +  (let ((line-regexp (format "[[:space:]]\\{%d\\}*>.*\n" depth)))\r
117 +    (concat "\\(?:^" line-regexp \r
118 +           "\\(?:[[:space:]]*\n" line-regexp\r
119 +           "\\)?\\)+")))\r
120 +\r
121 +(defun notmuch-show-region-to-button (beg end type prefix button-text)\r
122 +  "Auxilary function to do the actual making of overlays and buttons\r
123 +\r
124 +BEG and END are buffer locations. TYPE should a string, either\r
125 +\"citation\" or \"signature\". PREFIX is some arbitrary text to\r
126 +insert before the button, probably for indentation.  BUTTON-TEXT\r
127 +is what to put on the button."\r
128 +\r
129 +;; This uses some slightly tricky conversions between strings and\r
130 +;; symbols because of the way the button code works. Note that\r
131 +;; replacing intern-soft with make-symbol will cause this to fail, \r
132 +;; since the newly created symbol has no plist.\r
133 +\r
134 +  (let ((overlay (make-overlay beg end))\r
135 +       (invis-spec (make-symbol (concat "notmuch-" type "-region")))\r
136 +       (button-type (intern-soft (concat "notmuch-button-" \r
137 +                                         type "-toggle-type"))))\r
138 +    (add-to-invisibility-spec invis-spec)\r
139 +    (overlay-put overlay 'invisible invis-spec)\r
140 +    (goto-char (1+ end))\r
141 +    (save-excursion \r
142 +      (goto-char (1- beg))\r
143 +      (insert prefix)\r
144 +      (insert-button button-text\r
145 +                    'invisibility-spec invis-spec\r
146 +                    :type button-type)\r
147 +      )))\r
148 +\r
149 +                                                \r
150  (defun notmuch-show-markup-citations-region (beg end depth)\r
151 -  (goto-char beg)\r
152 -  (beginning-of-line)\r
153 -  (while (< (point) end)\r
154 -    (let ((beg-sub (point-marker))\r
155 -         (indent (make-string depth ? ))\r
156 -         (citation ">"))\r
157 -      (move-to-column depth)\r
158 -      (if (looking-at citation)\r
159 -         (progn\r
160 -           (while (looking-at citation)\r
161 -             (forward-line)\r
162 -             (move-to-column depth))\r
163 -           (let ((overlay (make-overlay beg-sub (point)))\r
164 -                  (invis-spec (make-symbol "notmuch-citation-region")))\r
165 -              (add-to-invisibility-spec invis-spec)\r
166 -             (overlay-put overlay 'invisible invis-spec)\r
167 -              (let ((p (point-marker))\r
168 -                    (cite-button-text\r
169 -                     (concat "["  (number-to-string (count-lines beg-sub (point)))\r
170 -                             "-line citation. Click/Enter to show.]")))\r
171 -                (goto-char (- beg-sub 1))\r
172 -                (insert (concat "\n" indent))\r
173 -                (insert-button cite-button-text\r
174 -                               'invisibility-spec invis-spec\r
175 -                               :type 'notmuch-button-citation-toggle-type)\r
176 -                (forward-line)\r
177 -              ))))\r
178 -      (move-to-column depth)\r
179 -      (if (looking-at notmuch-show-signature-regexp)\r
180 -         (let ((sig-lines (- (count-lines beg-sub end) 1)))\r
181 -           (if (<= sig-lines notmuch-show-signature-lines-max)\r
182 -               (progn\r
183 -                  (let ((invis-spec (make-symbol "notmuch-signature-region")))\r
184 -                    (add-to-invisibility-spec invis-spec)\r
185 -                    (overlay-put (make-overlay beg-sub end)\r
186 -                                 'invisible invis-spec)\r
187 -                  \r
188 -                    (goto-char (- beg-sub 1))\r
189 -                    (insert (concat "\n" indent))\r
190 -                    (let ((sig-button-text (concat "[" (number-to-string sig-lines)\r
191 -                                                   "-line signature. Click/Enter to show.]")))\r
192 -                      (insert-button sig-button-text 'invisibility-spec invis-spec\r
193 -                                     :type 'notmuch-button-signature-toggle-type)\r
194 -                     )\r
195 -                    (insert "\n")\r
196 -                    (goto-char end))))))\r
197 -      (forward-line))))\r
198 +  "Markup citations, and up to one signature in the given region"\r
199 +  ;; it would be nice if the untabify was not required, but \r
200 +  ;; that would require notmuch to indent with spaces.\r
201 +  (untabify beg end)\r
202 +  (let ((citation-regexp (notmuch-show-citation-regexp depth))\r
203 +       (signature-regexp (concat (format "^[[:space:]]\\{%d\\}" depth) \r
204 +                                 notmuch-show-signature-regexp))\r
205 +       (indent (concat "\n" (make-string depth ? ))))\r
206 +    (goto-char beg)\r
207 +    (beginning-of-line)\r
208 +    (while (and (< (point) end) \r
209 +               (re-search-forward citation-regexp end t))\r
210 +      (let* ((cite-start (match-beginning 0))\r
211 +            (cite-end  (match-end 0))\r
212 +            (cite-lines (count-lines cite-start cite-end)))\r
213 +       (if (>= cite-lines notmuch-show-citation-lines-min)\r
214 +           (notmuch-show-region-to-button \r
215 +            cite-start cite-end\r
216 +            "citation"\r
217 +            indent\r
218 +            (format notmuch-show-citation-button-format cite-lines)\r
219 +            ))))\r
220 +    (if (and (< (point) end) \r
221 +            (re-search-forward signature-regexp end t))\r
222 +       (let* ((sig-start (match-beginning 0))\r
223 +              (sig-end (match-end 0))\r
224 +              (sig-lines (1- (count-lines sig-start end))))\r
225 +         (if (<= sig-lines notmuch-show-signature-lines-max)\r
226 +             (notmuch-show-region-to-button \r
227 +              sig-start\r
228 +              end\r
229 +              "signature"\r
230 +              indent\r
231 +              (format notmuch-show-signature-button-format sig-lines)\r
232 +              ))))))\r
233  \r
234  (defun notmuch-show-markup-part (beg end depth)\r
235    (if (re-search-forward notmuch-show-part-begin-regexp nil t)\r
236 -- \r
237 1.6.5.7\r
238 \r