]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
gnus-art.el (gnus-article-browse-html-save-cid-content, gnus-article-browse-html...
[gnu-emacs] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
31
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
45
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
53
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
58
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
63
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
68
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
74
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
79
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
84
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
89
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
94
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
99
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
104
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
109
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
114
115 (defcustom gnus-ignored-headers
116 (mapcar
117 (lambda (header)
118 (concat "^" header ":"))
119 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
120 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
121 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
122 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
123 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
124 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
125 "X-Attribution" "X-Originating-IP" "Delivered-To"
126 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
127 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
128 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
129 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
130 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
131 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
132 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
133 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
134 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
135 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
136 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
137 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
138 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
139 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
140 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
141 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
142 "List-[A-Za-z]+" "X-Listprocessor-Version"
143 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
144 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
145 "X-Received" "Content-length" "X-precedence"
146 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
147 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
148 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
149 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
150 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
151 "X-Content-length" "X-Posting-Agent" "Original-Received"
152 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
153 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
154 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
155 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
156 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
157 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
158 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
159 "Envelope-Sender" "Envelope-Recipients"))
160 "*All headers that start with this regexp will be hidden.
161 This variable can also be a list of regexps of headers to be ignored.
162 If `gnus-visible-headers' is non-nil, this variable will be ignored."
163 :type '(choice regexp
164 (repeat regexp))
165 :group 'gnus-article-hiding)
166
167 (defcustom gnus-visible-headers
168 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
169 "*All headers that do not match this regexp will be hidden.
170 This variable can also be a list of regexp of headers to remain visible.
171 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
172 :type '(choice
173 (repeat :value-to-internal (lambda (widget value)
174 (custom-split-regexp-maybe value))
175 :match (lambda (widget value)
176 (or (stringp value)
177 (widget-editable-list-match widget value)))
178 regexp)
179 (const :tag "Use gnus-ignored-headers" nil)
180 regexp)
181 :group 'gnus-article-hiding)
182
183 (defcustom gnus-sorted-header-list
184 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
185 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
186 "*This variable is a list of regular expressions.
187 If it is non-nil, headers that match the regular expressions will
188 be placed first in the article buffer in the sequence specified by
189 this list."
190 :type '(repeat regexp)
191 :group 'gnus-article-hiding)
192
193 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
194 "Headers that are only to be displayed if they have interesting data.
195 Possible values in this list are:
196
197 'empty Headers with no content.
198 'newsgroups Newsgroup identical to Gnus group.
199 'to-address To identical to To-address.
200 'to-list To identical to To-list.
201 'cc-list CC identical to To-list.
202 'followup-to Followup-to identical to Newsgroups.
203 'reply-to Reply-to identical to From.
204 'date Date less than four days old.
205 'long-to To and/or Cc longer than 1024 characters.
206 'many-to Multiple To and/or Cc."
207 :type '(set (const :tag "Headers with no content." empty)
208 (const :tag "Newsgroups identical to Gnus group." newsgroups)
209 (const :tag "To identical to To-address." to-address)
210 (const :tag "To identical to To-list." to-list)
211 (const :tag "CC identical to To-list." cc-list)
212 (const :tag "Followup-to identical to Newsgroups." followup-to)
213 (const :tag "Reply-to identical to From." reply-to)
214 (const :tag "Date less than four days old." date)
215 (const :tag "To and/or Cc longer than 1024 characters." long-to)
216 (const :tag "Multiple To and/or Cc headers." many-to))
217 :group 'gnus-article-hiding)
218
219 (defcustom gnus-article-skip-boring nil
220 "Skip over text that is not worth reading.
221 By default, if you set this t, then Gnus will display citations and
222 signatures, but will never scroll down to show you a page consisting
223 only of boring text. Boring text is controlled by
224 `gnus-article-boring-faces'."
225 :version "22.1"
226 :type 'boolean
227 :group 'gnus-article-hiding)
228
229 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
230 "Regexp matching signature separator.
231 This can also be a list of regexps. In that case, it will be checked
232 from head to tail looking for a separator. Searches will be done from
233 the end of the buffer."
234 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
235 (regexp)
236 (repeat :tag "List of regexp" regexp))
237 :group 'gnus-article-signature)
238
239 (defcustom gnus-signature-limit nil
240 "Provide a limit to what is considered a signature.
241 If it is a number, no signature may not be longer (in characters) than
242 that number. If it is a floating point number, no signature may be
243 longer (in lines) than that number. If it is a function, the function
244 will be called without any parameters, and if it returns nil, there is
245 no signature in the buffer. If it is a string, it will be used as a
246 regexp. If it matches, the text in question is not a signature.
247
248 This can also be a list of the above values."
249 :type '(choice (const nil)
250 (integer :value 200)
251 (number :value 4.0)
252 function
253 (regexp :value ".*"))
254 :group 'gnus-article-signature)
255
256 (defcustom gnus-hidden-properties
257 (if (featurep 'xemacs)
258 ;; `intangible' is evil, but I keep it here in case it's useful.
259 '(invisible t intangible t)
260 ;; Emacs's command loop moves point out of invisible text anyway, so
261 ;; `intangible' is clearly not needed there.
262 '(invisible t))
263 "Property list to use for hiding text."
264 :type 'sexp
265 :group 'gnus-article-hiding)
266
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo \
275 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
276 ; uncompface; } | icontopbm | ee -")
277 (if (gnus-image-type-available-p 'pbm)
278 'gnus-display-x-face-in-from
279 "{ echo \
280 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
281 ; uncompface; } | icontopbm | display -"))
282 "*String or function to be executed to display an X-Face header.
283 If it is a string, the command will be executed in a sub-shell
284 asynchronously. The compressed face will be piped to this command."
285 :type `(choice string
286 (function-item gnus-display-x-face-in-from)
287 function)
288 :version "21.1"
289 :group 'gnus-picon
290 :group 'gnus-article-washing)
291
292 (defcustom gnus-article-x-face-too-ugly nil
293 "Regexp matching posters whose face shouldn't be shown automatically."
294 :type '(choice regexp (const nil))
295 :group 'gnus-article-washing)
296
297 (defcustom gnus-article-banner-alist nil
298 "Banner alist for stripping.
299 For example,
300 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
301 :version "21.1"
302 :type '(repeat (cons symbol regexp))
303 :group 'gnus-article-washing)
304
305 (gnus-define-group-parameter
306 banner
307 :variable-document
308 "Alist of regexps (to match group names) and banner."
309 :variable-group gnus-article-washing
310 :parameter-type
311 '(choice :tag "Banner"
312 :value nil
313 (const :tag "Remove signature" signature)
314 (symbol :tag "Item in `gnus-article-banner-alist'" none)
315 regexp
316 (const :tag "None" nil))
317 :parameter-document
318 "If non-nil, specify how to remove `banners' from articles.
319
320 Symbol `signature' means to remove signatures delimited by
321 `gnus-signature-separator'. Any other symbol is used to look up a
322 regular expression to match the banner in `gnus-article-banner-alist'.
323 A string is used as a regular expression to match the banner
324 directly.")
325
326 (defcustom gnus-article-address-banner-alist nil
327 "Alist of mail addresses and banners.
328 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
329 to match a mail address in the From: header, BANNER is one of a symbol
330 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
331 If ADDRESS matches author's mail address, it will remove things like
332 advertisements. For example:
333
334 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
335 "
336 :type '(repeat
337 (cons
338 (regexp :tag "Address")
339 (choice :tag "Banner" :value nil
340 (const :tag "Remove signature" signature)
341 (symbol :tag "Item in `gnus-article-banner-alist'" none)
342 regexp
343 (const :tag "None" nil))))
344 :version "22.1"
345 :group 'gnus-article-washing)
346
347 (defmacro gnus-emphasis-custom-with-format (&rest body)
348 `(let ((format "\
349 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
350 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
351 ,@body))
352
353 (defun gnus-emphasis-custom-value-to-external (value)
354 (gnus-emphasis-custom-with-format
355 (if (consp (car value))
356 (list (format format (car (car value)) (cdr (car value)))
357 2
358 (if (nth 1 value) 2 3)
359 (nth 2 value))
360 value)))
361
362 (defun gnus-emphasis-custom-value-to-internal (value)
363 (gnus-emphasis-custom-with-format
364 (let ((regexp (concat "\\`"
365 (format (regexp-quote format)
366 "\\([^()]+\\)" "\\([^()]+\\)")
367 "\\'"))
368 pattern)
369 (if (string-match regexp (setq pattern (car value)))
370 (list (cons (match-string 1 pattern) (match-string 2 pattern))
371 (= (nth 2 value) 2)
372 (nth 3 value))
373 value))))
374
375 (defcustom gnus-emphasis-alist
376 (let ((types
377 '(("\\*" "\\*" bold nil 2)
378 ("_" "_" underline)
379 ("/" "/" italic)
380 ("_/" "/_" underline-italic)
381 ("_\\*" "\\*_" underline-bold)
382 ("\\*/" "/\\*" bold-italic)
383 ("_\\*/" "/\\*_" underline-bold-italic))))
384 (nconc
385 (gnus-emphasis-custom-with-format
386 (mapcar (lambda (spec)
387 (list (format format (car spec) (cadr spec))
388 (or (nth 3 spec) 2)
389 (or (nth 4 spec) 3)
390 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
391 types))
392 '(;; I've never seen anyone use this strikethru convention whereas I've
393 ;; several times seen it triggered by normal text. --Stef
394 ;; Miles suggests that this form is sometimes used but for italics,
395 ;; so maybe we should map it to `italic'.
396 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
397 ;; 2 3 gnus-emphasis-strikethru)
398 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
399 2 3 gnus-emphasis-underline))))
400 "*Alist that says how to fontify certain phrases.
401 Each item looks like this:
402
403 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
404
405 The first element is a regular expression to be matched. The second
406 is a number that says what regular expression grouping used to find
407 the entire emphasized word. The third is a number that says what
408 regexp grouping should be displayed and highlighted. The fourth
409 is the face used for highlighting."
410 :type
411 '(repeat
412 (menu-choice
413 :format "%[Customizing Style%]\n%v"
414 :indent 2
415 (group :tag "Default"
416 :value ("" 0 0 default)
417 :value-create
418 (lambda (widget)
419 (let ((value (widget-get
420 (cadr (widget-get (widget-get widget :parent)
421 :args))
422 :value)))
423 (if (not (eq (nth 2 value) 'default))
424 (widget-put
425 widget
426 :value
427 (gnus-emphasis-custom-value-to-external value))))
428 (widget-group-value-create widget))
429 regexp
430 (integer :format "Match group: %v")
431 (integer :format "Emphasize group: %v")
432 face)
433 (group :tag "Simple"
434 :value (("_" . "_") nil default)
435 (cons :format "%v"
436 (regexp :format "Start regexp: %v")
437 (regexp :format "End regexp: %v"))
438 (boolean :format "Show start and end patterns: %[%v%]\n"
439 :on " On " :off " Off ")
440 face)))
441 :get (lambda (symbol)
442 (mapcar 'gnus-emphasis-custom-value-to-internal
443 (default-value symbol)))
444 :set (lambda (symbol value)
445 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
446 value)))
447 :group 'gnus-article-emphasis)
448
449 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
450 "A regexp to describe whitespace which should not be emphasized.
451 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
452 The former avoids underlining of leading and trailing whitespace,
453 and the latter avoids underlining any whitespace at all."
454 :version "21.1"
455 :group 'gnus-article-emphasis
456 :type 'regexp)
457
458 (defface gnus-emphasis-bold '((t (:bold t)))
459 "Face used for displaying strong emphasized text (*word*)."
460 :group 'gnus-article-emphasis)
461
462 (defface gnus-emphasis-italic '((t (:italic t)))
463 "Face used for displaying italic emphasized text (/word/)."
464 :group 'gnus-article-emphasis)
465
466 (defface gnus-emphasis-underline '((t (:underline t)))
467 "Face used for displaying underlined emphasized text (_word_)."
468 :group 'gnus-article-emphasis)
469
470 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
471 "Face used for displaying underlined bold emphasized text (_*word*_)."
472 :group 'gnus-article-emphasis)
473
474 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
475 "Face used for displaying underlined italic emphasized text (_/word/_)."
476 :group 'gnus-article-emphasis)
477
478 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
479 "Face used for displaying bold italic emphasized text (/*word*/)."
480 :group 'gnus-article-emphasis)
481
482 (defface gnus-emphasis-underline-bold-italic
483 '((t (:bold t :italic t :underline t)))
484 "Face used for displaying underlined bold italic emphasized text.
485 Example: (_/*word*/_)."
486 :group 'gnus-article-emphasis)
487
488 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
489 '((t (:strikethru t)))
490 '((t (:strike-through t))))
491 "Face used for displaying strike-through text (-word-)."
492 :group 'gnus-article-emphasis)
493
494 (defface gnus-emphasis-highlight-words
495 '((t (:background "black" :foreground "yellow")))
496 "Face used for displaying highlighted words."
497 :group 'gnus-article-emphasis)
498
499 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
500 "Format for display of Date headers in article bodies.
501 See `format-time-string' for the possible values.
502
503 The variable can also be function, which should return a complete Date
504 header. The function is called with one argument, the time, which can
505 be fed to `format-time-string'."
506 :type '(choice string function)
507 :link '(custom-manual "(gnus)Article Date")
508 :group 'gnus-article-washing)
509
510 (defcustom gnus-save-all-headers t
511 "*If non-nil, don't remove any headers before saving.
512 This will be overridden by the `:headers' property that the symbol of
513 the saver function, which is specified by `gnus-default-article-saver',
514 might have."
515 :group 'gnus-article-saving
516 :type 'boolean)
517
518 (defcustom gnus-prompt-before-saving 'always
519 "*This variable says how much prompting is to be done when saving articles.
520 If it is nil, no prompting will be done, and the articles will be
521 saved to the default files. If this variable is `always', each and
522 every article that is saved will be preceded by a prompt, even when
523 saving large batches of articles. If this variable is neither nil not
524 `always', there the user will be prompted once for a file name for
525 each invocation of the saving commands."
526 :group 'gnus-article-saving
527 :type '(choice (item always)
528 (item :tag "never" nil)
529 (sexp :tag "once" :format "%t\n" :value t)))
530
531 (defcustom gnus-saved-headers gnus-visible-headers
532 "Headers to keep if `gnus-save-all-headers' is nil.
533 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
534 If that variable is nil, however, all headers that match this regexp
535 will be kept while the rest will be deleted before saving. This and
536 `gnus-save-all-headers' will be overridden by the `:headers' property
537 that the symbol of the saver function, which is specified by
538 `gnus-default-article-saver', might have."
539 :group 'gnus-article-saving
540 :type 'regexp)
541
542 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
543 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
544 "A function to save articles in your favorite format.
545 The function will be called by way of the `gnus-summary-save-article'
546 command, and friends such as `gnus-summary-save-article-rmail'.
547
548 Gnus provides the following functions:
549
550 * gnus-summary-save-in-rmail (Rmail format)
551 * gnus-summary-save-in-mail (Unix mail format)
552 * gnus-summary-save-in-folder (MH folder)
553 * gnus-summary-save-in-file (article format)
554 * gnus-summary-save-body-in-file (article body)
555 * gnus-summary-save-in-vm (use VM's folder format)
556 * gnus-summary-write-to-file (article format -- overwrite)
557 * gnus-summary-write-body-to-file (article body -- overwrite)
558 * gnus-summary-save-in-pipe (article format)
559
560 The symbol of each function may have the following properties:
561
562 * :decode
563 The value non-nil means save decoded articles. This is meaningful
564 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
565 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
566 `gnus-summary-save-in-pipe'.
567
568 * :function
569 The value specifies an alternative function which appends, not
570 overwrites, articles to a file. This implies that when saving many
571 articles at a time, `gnus-prompt-before-saving' is bound to t and all
572 articles are saved in a single file. This is meaningful only with
573 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
574
575 * :headers
576 The value specifies the symbol of a variable of which the value
577 specifies headers to be saved. If it is omitted,
578 `gnus-save-all-headers' and `gnus-saved-headers' control what
579 headers should be saved."
580 :group 'gnus-article-saving
581 :type '(radio (function-item gnus-summary-save-in-rmail)
582 (function-item gnus-summary-save-in-mail)
583 (function-item gnus-summary-save-in-folder)
584 (function-item gnus-summary-save-in-file)
585 (function-item gnus-summary-save-body-in-file)
586 (function-item gnus-summary-save-in-vm)
587 (function-item gnus-summary-write-to-file)
588 (function-item gnus-summary-write-body-to-file)
589 (function-item gnus-summary-save-in-pipe)
590 (function)))
591
592 (defcustom gnus-article-save-coding-system
593 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
594 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
595 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
596 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
597 "Coding system used to save decoded articles to a file.
598
599 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
600 which can safely encode any characters in text. This is used by the
601 commands including:
602
603 * gnus-summary-save-article-file
604 * gnus-summary-save-article-body-file
605 * gnus-summary-write-article-file
606 * gnus-summary-write-article-body-file
607
608 and the functions to which you may set `gnus-default-article-saver':
609
610 * gnus-summary-save-in-file
611 * gnus-summary-save-body-in-file
612 * gnus-summary-write-to-file
613 * gnus-summary-write-body-to-file
614
615 Those commands and functions save just text displayed in the article
616 buffer to a file if the value of this variable is non-nil. Note that
617 buttonized MIME parts will be lost in a saved file in that case.
618 Otherwise, raw articles will be saved."
619 :group 'gnus-article-saving
620 :type `(choice
621 :format "%{%t%}:\n %[Value Menu%] %v"
622 (const :tag "Save raw articles" nil)
623 ,@(delq nil
624 (mapcar
625 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
626 '((const :tag "UTF-8" utf-8)
627 (const :tag "iso-2022-7bit" iso-2022-7bit)
628 (const :tag "Emacs internal" emacs-mule)
629 (const :tag "escape-quoted" escape-quoted))))
630 (symbol :tag "Coding system")))
631
632 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Rmail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
637
638 (defcustom gnus-mail-save-name 'gnus-plain-save-name
639 "A function generating a file name to save articles in Unix mail format.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
641 :group 'gnus-article-saving
642 :type 'function)
643
644 (defcustom gnus-folder-save-name 'gnus-folder-save-name
645 "A function generating a file name to save articles in MH folder.
646 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
647 :group 'gnus-article-saving
648 :type 'function)
649
650 (defcustom gnus-file-save-name 'gnus-numeric-save-name
651 "A function generating a file name to save articles in article format.
652 The function is called with NEWSGROUP, HEADERS, and optional
653 LAST-FILE."
654 :group 'gnus-article-saving
655 :type 'function)
656
657 (defcustom gnus-split-methods
658 '((gnus-article-archive-name)
659 (gnus-article-nndoc-name))
660 "*Variable used to suggest where articles are to be saved.
661 For instance, if you would like to save articles related to Gnus in
662 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
663 you could set this variable to something like:
664
665 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
666 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
667
668 This variable is an alist where the key is the match and the
669 value is a list of possible files to save in if the match is
670 non-nil.
671
672 If the match is a string, it is used as a regexp match on the
673 article. If the match is a symbol, that symbol will be funcalled
674 from the buffer of the article to be saved with the newsgroup as the
675 parameter. If it is a list, it will be evalled in the same buffer.
676
677 If this form or function returns a string, this string will be used as a
678 possible file name; and if it returns a non-nil list, that list will be
679 used as possible file names."
680 :group 'gnus-article-saving
681 :type '(repeat (choice (list :value (fun) function)
682 (cons :value ("" "") regexp (repeat string))
683 (sexp :value nil))))
684
685 (defcustom gnus-page-delimiter "^\^L"
686 "*Regexp describing what to use as article page delimiters.
687 The default value is \"^\^L\", which is a form linefeed at the
688 beginning of a line."
689 :type 'regexp
690 :group 'gnus-article-various)
691
692 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
693 "*The format specification for the article mode line.
694 See `gnus-summary-mode-line-format' for a closer description.
695
696 The following additional specs are available:
697
698 %w The article washing status.
699 %m The number of MIME parts in the article."
700 :version "24.1"
701 :type 'string
702 :group 'gnus-article-various)
703
704 (defcustom gnus-article-mode-hook nil
705 "*A hook for Gnus article mode."
706 :type 'hook
707 :group 'gnus-article-various)
708
709 (when (featurep 'xemacs)
710 ;; Extracted from gnus-xmas-define in order to preserve user settings
711 (when (fboundp 'turn-off-scroll-in-place)
712 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
713 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
714 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
715
716 (defcustom gnus-article-menu-hook nil
717 "*Hook run after the creation of the article mode menu."
718 :type 'hook
719 :group 'gnus-article-various)
720
721 (defcustom gnus-article-prepare-hook nil
722 "*A hook called after an article has been prepared in the article buffer."
723 :type 'hook
724 :group 'gnus-article-various)
725
726 (defcustom gnus-copy-article-ignored-headers nil
727 "List of headers to be removed when copying an article.
728 Each element is a regular expression."
729 :version "23.1" ;; No Gnus
730 :type '(repeat regexp)
731 :group 'gnus-article-various)
732
733 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
734 "Gnus 5.10 (Emacs 22.1)")
735
736 (defface gnus-button
737 '((t (:weight bold)))
738 "Face used for highlighting a button in the article buffer."
739 :group 'gnus-article-buttons)
740
741 (defcustom gnus-article-button-face 'gnus-button
742 "Face used for highlighting buttons in the article buffer.
743
744 An article button is a piece of text that you can activate by pressing
745 `RET' or `mouse-2' above it."
746 :type 'face
747 :group 'gnus-article-buttons)
748
749 (defcustom gnus-article-mouse-face 'highlight
750 "Face used for mouse highlighting in the article buffer.
751
752 Article buttons will be displayed in this face when the cursor is
753 above them."
754 :type 'face
755 :group 'gnus-article-buttons)
756
757 (defcustom gnus-signature-face 'gnus-signature
758 "Face used for highlighting a signature in the article buffer.
759 Obsolete; use the face `gnus-signature' for customizations instead."
760 :type 'face
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
763
764 (defface gnus-signature
765 '((t
766 (:italic t)))
767 "Face used for highlighting a signature in the article buffer."
768 :group 'gnus-article-highlight
769 :group 'gnus-article-signature)
770 ;; backward-compatibility alias
771 (put 'gnus-signature-face 'face-alias 'gnus-signature)
772 (put 'gnus-signature-face 'obsolete-face "22.1")
773
774 (defface gnus-header-from
775 '((((class color)
776 (background dark))
777 (:foreground "PaleGreen1"))
778 (((class color)
779 (background light))
780 (:foreground "red3"))
781 (t
782 (:italic t)))
783 "Face used for displaying from headers."
784 :group 'gnus-article-headers
785 :group 'gnus-article-highlight)
786 ;; backward-compatibility alias
787 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
788 (put 'gnus-header-from-face 'obsolete-face "22.1")
789
790 (defface gnus-header-subject
791 '((((class color)
792 (background dark))
793 (:foreground "SeaGreen1"))
794 (((class color)
795 (background light))
796 (:foreground "red4"))
797 (t
798 (:bold t :italic t)))
799 "Face used for displaying subject headers."
800 :group 'gnus-article-headers
801 :group 'gnus-article-highlight)
802 ;; backward-compatibility alias
803 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
804 (put 'gnus-header-subject-face 'obsolete-face "22.1")
805
806 (defface gnus-header-newsgroups
807 '((((class color)
808 (background dark))
809 (:foreground "yellow" :italic t))
810 (((class color)
811 (background light))
812 (:foreground "MidnightBlue" :italic t))
813 (t
814 (:italic t)))
815 "Face used for displaying newsgroups headers.
816 In the default setup this face is only used for crossposted
817 articles."
818 :group 'gnus-article-headers
819 :group 'gnus-article-highlight)
820 ;; backward-compatibility alias
821 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
822 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
823
824 (defface gnus-header-name
825 '((((class color)
826 (background dark))
827 (:foreground "SpringGreen2"))
828 (((class color)
829 (background light))
830 (:foreground "maroon"))
831 (t
832 (:bold t)))
833 "Face used for displaying header names."
834 :group 'gnus-article-headers
835 :group 'gnus-article-highlight)
836 ;; backward-compatibility alias
837 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
838 (put 'gnus-header-name-face 'obsolete-face "22.1")
839
840 (defface gnus-header-content
841 '((((class color)
842 (background dark))
843 (:foreground "SpringGreen1" :italic t))
844 (((class color)
845 (background light))
846 (:foreground "indianred4" :italic t))
847 (t
848 (:italic t))) "Face used for displaying header content."
849 :group 'gnus-article-headers
850 :group 'gnus-article-highlight)
851 ;; backward-compatibility alias
852 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
853 (put 'gnus-header-content-face 'obsolete-face "22.1")
854
855 (defcustom gnus-header-face-alist
856 '(("From" nil gnus-header-from)
857 ("Subject" nil gnus-header-subject)
858 ("Newsgroups:.*," nil gnus-header-newsgroups)
859 ("" gnus-header-name gnus-header-content))
860 "*Controls highlighting of article headers.
861
862 An alist of the form (HEADER NAME CONTENT).
863
864 HEADER is a regular expression which should match the name of a
865 header and NAME and CONTENT are either face names or nil.
866
867 The name of each header field will be displayed using the face
868 specified by the first element in the list where HEADER matches
869 the header name and NAME is non-nil. Similarly, the content will
870 be displayed by the first non-nil matching CONTENT face."
871 :group 'gnus-article-headers
872 :group 'gnus-article-highlight
873 :type '(repeat (list (regexp :tag "Header")
874 (choice :tag "Name"
875 (item :tag "skip" nil)
876 (face :value default))
877 (choice :tag "Content"
878 (item :tag "skip" nil)
879 (face :value default)))))
880
881 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
882 '((xface . (:face gnus-x-face)))
883 '((pbm . (:face gnus-x-face))
884 (png . nil)))
885 "Alist of image types and properties applied to Face and X-Face images.
886 Here are examples:
887
888 ;; Specify the altitude of Face images in the From header.
889 \(setq gnus-face-properties-alist
890 '((pbm . (:face gnus-x-face :ascent 80))
891 (png . (:ascent 80))))
892
893 ;; Show Face images as pressed buttons.
894 \(setq gnus-face-properties-alist
895 '((pbm . (:face gnus-x-face :relief -2))
896 (png . (:relief -2))))
897
898 See the manual for the valid properties for various image types.
899 Currently, `pbm' is used for X-Face images and `png' is used for Face
900 images in Emacs. Only the `:face' property is effective on the `xface'
901 image type in XEmacs if it is built with the libcompface library."
902 :version "23.1" ;; No Gnus
903 :group 'gnus-article-headers
904 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
905
906 (defcustom gnus-article-decode-hook
907 '(article-decode-charset article-decode-encoded-words
908 article-decode-group-name article-decode-idna-rhs)
909 "*Hook run to decode charsets in articles."
910 :group 'gnus-article-headers
911 :type 'hook)
912
913 (defcustom gnus-display-mime-function 'gnus-display-mime
914 "Function to display MIME articles."
915 :group 'gnus-article-mime
916 :type 'function)
917
918 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
919 "Function used to decode headers.")
920
921 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
922 "Function used to decode addresses.")
923
924 (defvar gnus-article-dumbquotes-map
925 '((?\200 "EUR")
926 (?\202 ",")
927 (?\203 "f")
928 (?\204 ",,")
929 (?\205 "...")
930 (?\213 "<")
931 (?\214 "OE")
932 (?\221 "`")
933 (?\222 "'")
934 (?\223 "``")
935 (?\224 "\"")
936 (?\225 "*")
937 (?\226 "-")
938 (?\227 "--")
939 (?\230 "~")
940 (?\231 "(TM)")
941 (?\233 ">")
942 (?\234 "oe")
943 (?\264 "'"))
944 "Table for MS-to-Latin1 translation.")
945
946 (defcustom gnus-ignored-mime-types nil
947 "List of MIME types that should be ignored by Gnus."
948 :version "21.1"
949 :group 'gnus-article-mime
950 :type '(repeat regexp))
951
952 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
953 "List of MIME types that should not be given buttons when rendered inline.
954 See also `gnus-buttonized-mime-types' which may override this variable.
955 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
956 :version "21.1"
957 :group 'gnus-article-mime
958 :type '(repeat regexp))
959
960 (defcustom gnus-buttonized-mime-types nil
961 "List of MIME types that should be given buttons when rendered inline.
962 If set, this variable overrides `gnus-unbuttonized-mime-types'.
963 To see e.g. security buttons you could set this to
964 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
965 this list to display radio buttons that allow you to choose one of two
966 media types those mails include. See also `mm-discouraged-alternatives'.
967 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
968 :version "22.1"
969 :group 'gnus-article-mime
970 :type '(repeat regexp))
971
972 (defcustom gnus-inhibit-mime-unbuttonizing nil
973 "If non-nil, all MIME parts get buttons.
974 When nil (the default value), then some MIME parts do not get buttons,
975 as described by the variables `gnus-buttonized-mime-types' and
976 `gnus-unbuttonized-mime-types'."
977 :version "22.1"
978 :group 'gnus-article-mime
979 :type 'boolean)
980
981 (defcustom gnus-body-boundary-delimiter "_"
982 "String used to delimit header and body.
983 This variable is used by `gnus-article-treat-body-boundary' which can
984 be controlled by `gnus-treat-body-boundary'."
985 :version "22.1"
986 :group 'gnus-article-various
987 :type '(choice (item :tag "None" :value nil)
988 string))
989
990 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
991 "/usr/share/picons")
992 "Defines the location of the faces database.
993 For information on obtaining this database of pretty pictures, please
994 see http://www.cs.indiana.edu/picons/ftp/index.html"
995 :version "22.1"
996 :type '(repeat directory)
997 :link '(url-link :tag "download"
998 "http://www.cs.indiana.edu/picons/ftp/index.html")
999 :link '(custom-manual "(gnus)Picons")
1000 :group 'gnus-picon)
1001
1002 (defun gnus-picons-installed-p ()
1003 "Say whether picons are installed on your machine."
1004 (let ((installed nil))
1005 (dolist (database gnus-picon-databases)
1006 (when (file-exists-p database)
1007 (setq installed t)))
1008 installed))
1009
1010 (defcustom gnus-article-mime-part-function nil
1011 "Function called with a MIME handle as the argument.
1012 This is meant for people who want to do something automatic based
1013 on parts -- for instance, adding Vcard info to a database."
1014 :group 'gnus-article-mime
1015 :type '(choice (const nil)
1016 function))
1017
1018 (defcustom gnus-mime-multipart-functions nil
1019 "An alist of MIME types to functions to display them."
1020 :version "21.1"
1021 :group 'gnus-article-mime
1022 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1023
1024 (defcustom gnus-article-date-headers '(combined-lapsed)
1025 "A list of Date header formats to display.
1026 Valid formats are `ut' (universal time), `local' (local time
1027 zone), `english' (readable English), `lapsed' (elapsed time),
1028 `combined-lapsed' (both the original date and the elapsed time),
1029 `original' (the original date header), `iso8601' (ISO8601
1030 format), and `user-defined' (a user-defined format defined by the
1031 `gnus-article-time-format' variable).
1032
1033 You have as many date headers as you want in the article buffer.
1034 Some of these headers are updated automatically. See
1035 `gnus-article-update-date-headers' for details."
1036 :version "24.1"
1037 :group 'gnus-article-headers
1038 :type '(set
1039 (const :tag "Universal time (UT)" ut)
1040 (const :tag "Local time zone" local)
1041 (const :tag "Readable English" english)
1042 (const :tag "Elapsed time" lapsed)
1043 (const :tag "Original and elapsed time" combined-lapsed)
1044 (const :tag "Original date header" original)
1045 (const :tag "ISO8601 format" iso8601)
1046 (const :tag "User-defined" user-defined)))
1047
1048 (defcustom gnus-article-update-date-headers nil
1049 "A number that says how often to update the date header (in seconds).
1050 If nil, don't update it at all."
1051 :version "24.1"
1052 :group 'gnus-article-headers
1053 :type '(choice
1054 (item :tag "Don't update" :value nil)
1055 integer))
1056
1057 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1058 "Function called with a MIME handle as the argument.
1059 This is meant for people who want to view first matched part.
1060 For `undisplayed-alternative' (default), the first undisplayed
1061 part or alternative part is used. For `undisplayed', the first
1062 undisplayed part is used. For a function, the first part which
1063 the function return t is used. For nil, the first part is
1064 used."
1065 :version "21.1"
1066 :group 'gnus-article-mime
1067 :type '(choice
1068 (item :tag "first" :value nil)
1069 (item :tag "undisplayed" :value undisplayed)
1070 (item :tag "undisplayed or alternative"
1071 :value undisplayed-alternative)
1072 (function)))
1073
1074 (defcustom gnus-mime-action-alist
1075 '(("save to file" . gnus-mime-save-part)
1076 ("save and strip" . gnus-mime-save-part-and-strip)
1077 ("replace with file" . gnus-mime-replace-part)
1078 ("delete part" . gnus-mime-delete-part)
1079 ("display as text" . gnus-mime-inline-part)
1080 ("view the part" . gnus-mime-view-part)
1081 ("pipe to command" . gnus-mime-pipe-part)
1082 ("toggle display" . gnus-article-press-button)
1083 ("toggle display" . gnus-article-view-part-as-charset)
1084 ("view as type" . gnus-mime-view-part-as-type)
1085 ("view internally" . gnus-mime-view-part-internally)
1086 ("view externally" . gnus-mime-view-part-externally))
1087 "An alist of actions that run on the MIME attachment."
1088 :group 'gnus-article-mime
1089 :type '(repeat (cons (string :tag "name")
1090 (function))))
1091
1092 (defcustom gnus-auto-select-part 1
1093 "Advance to next MIME part when deleting or stripping parts.
1094
1095 When 0, point will be placed on the same part as before. When
1096 positive (negative), move point forward (backwards) this many
1097 parts. When nil, redisplay article."
1098 :version "23.1" ;; No Gnus
1099 :group 'gnus-article-mime
1100 :type '(choice (const nil :tag "Redisplay article.")
1101 (const 1 :tag "Next part.")
1102 (const 0 :tag "Current part.")
1103 integer))
1104
1105 ;;;
1106 ;;; The treatment variables
1107 ;;;
1108
1109 (defvar gnus-part-display-hook nil
1110 "Hook called on parts that are to receive treatment.")
1111
1112 (defvar gnus-article-treat-custom
1113 '(choice (const :tag "Off" nil)
1114 (const :tag "On" t)
1115 (const :tag "Header" head)
1116 (const :tag "First" first)
1117 (const :tag "Last" last)
1118 (integer :tag "Less")
1119 (repeat :tag "Groups" regexp)
1120 (sexp :tag "Predicate")))
1121
1122 (defvar gnus-article-treat-head-custom
1123 '(choice (const :tag "Off" nil)
1124 (const :tag "Header" head)))
1125
1126 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1127 "text/x-patch" "text/html")
1128 "Part types eligible for treatment.")
1129
1130 (defvar gnus-inhibit-treatment nil
1131 "Whether to inhibit treatment.")
1132
1133 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1134 "Highlight the signature.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1140 (put 'gnus-treat-highlight-signature 'highlight t)
1141
1142 (defcustom gnus-treat-buttonize 100000
1143 "Add buttons.
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate. See Info node `(gnus)Customizing Articles'."
1146 :group 'gnus-article-treat
1147 :link '(custom-manual "(gnus)Customizing Articles")
1148 :type gnus-article-treat-custom)
1149 (put 'gnus-treat-buttonize 'highlight t)
1150
1151 (defcustom gnus-treat-buttonize-head 'head
1152 "Add buttons to the head.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-head-custom)
1158 (put 'gnus-treat-buttonize-head 'highlight t)
1159
1160 (defcustom gnus-treat-date 'head
1161 "Display dates according to the `gnus-article-date-headers' variable.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :version "24.1"
1165 :group 'gnus-article-treat
1166 :link '(custom-manual "(gnus)Customizing Articles")
1167 :type gnus-article-treat-head-custom)
1168
1169 (defcustom gnus-treat-emphasize 50000
1170 "Emphasize text.
1171 Valid values are nil, t, `head', `first', `last', an integer or a
1172 predicate. See Info node `(gnus)Customizing Articles'."
1173 :group 'gnus-article-treat
1174 :link '(custom-manual "(gnus)Customizing Articles")
1175 :type gnus-article-treat-custom)
1176 (put 'gnus-treat-emphasize 'highlight t)
1177
1178 (defcustom gnus-treat-strip-cr nil
1179 "Remove carriage returns.
1180 Valid values are nil, t, `head', `first', `last', an integer or a
1181 predicate. See Info node `(gnus)Customizing Articles'."
1182 :version "22.1"
1183 :group 'gnus-article-treat
1184 :link '(custom-manual "(gnus)Customizing Articles")
1185 :type gnus-article-treat-custom)
1186
1187 (defcustom gnus-treat-unsplit-urls nil
1188 "Remove newlines from within URLs.
1189 Valid values are nil, t, `head', `first', `last', an integer or a
1190 predicate. See Info node `(gnus)Customizing Articles'."
1191 :version "22.1"
1192 :group 'gnus-article-treat
1193 :link '(custom-manual "(gnus)Customizing Articles")
1194 :type gnus-article-treat-custom)
1195
1196 (defcustom gnus-treat-leading-whitespace nil
1197 "Remove leading whitespace in headers.
1198 Valid values are nil, t, `head', `first', `last', an integer or a
1199 predicate. See Info node `(gnus)Customizing Articles'."
1200 :version "22.1"
1201 :group 'gnus-article-treat
1202 :link '(custom-manual "(gnus)Customizing Articles")
1203 :type gnus-article-treat-custom)
1204
1205 (defcustom gnus-treat-hide-headers 'head
1206 "Hide headers.
1207 Valid values are nil, t, `head', `first', `last', an integer or a
1208 predicate. See Info node `(gnus)Customizing Articles'."
1209 :group 'gnus-article-treat
1210 :link '(custom-manual "(gnus)Customizing Articles")
1211 :type gnus-article-treat-head-custom)
1212
1213 (defcustom gnus-treat-hide-boring-headers nil
1214 "Hide boring headers.
1215 Valid values are nil, t, `head', `first', `last', an integer or a
1216 predicate. See Info node `(gnus)Customizing Articles'."
1217 :group 'gnus-article-treat
1218 :link '(custom-manual "(gnus)Customizing Articles")
1219 :type gnus-article-treat-head-custom)
1220
1221 (defcustom gnus-treat-hide-signature nil
1222 "Hide the signature.
1223 Valid values are nil, t, `head', `first', `last', an integer or a
1224 predicate. See Info node `(gnus)Customizing Articles'."
1225 :group 'gnus-article-treat
1226 :link '(custom-manual "(gnus)Customizing Articles")
1227 :type gnus-article-treat-custom)
1228
1229 (defcustom gnus-treat-fill-article nil
1230 "Fill the article.
1231 Valid values are nil, t, `head', `first', `last', an integer or a
1232 predicate. See Info node `(gnus)Customizing Articles'."
1233 :group 'gnus-article-treat
1234 :link '(custom-manual "(gnus)Customizing Articles")
1235 :type gnus-article-treat-custom)
1236
1237 (defcustom gnus-treat-hide-citation nil
1238 "Hide cited text.
1239 Valid values are nil, t, `head', `first', `last', an integer or a
1240 predicate. See Info node `(gnus)Customizing Articles'.
1241
1242 See `gnus-article-highlight-citation' for variables used to
1243 control what it hides."
1244 :group 'gnus-article-treat
1245 :link '(custom-manual "(gnus)Customizing Articles")
1246 :type gnus-article-treat-custom)
1247
1248 (defcustom gnus-treat-hide-citation-maybe nil
1249 "Hide cited text according to certain conditions.
1250 Valid values are nil, t, `head', `first', `last', an integer or a
1251 predicate. See Info node `(gnus)Customizing Articles'.
1252
1253 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1254 how to control what it hides."
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-custom)
1258
1259 (defcustom gnus-treat-strip-list-identifiers 'head
1260 "Strip list identifiers from `gnus-list-identifiers`.
1261 Valid values are nil, t, `head', `first', `last', an integer or a
1262 predicate. See Info node `(gnus)Customizing Articles'."
1263 :version "21.1"
1264 :group 'gnus-article-treat
1265 :link '(custom-manual "(gnus)Customizing Articles")
1266 :type gnus-article-treat-custom)
1267
1268 (gnus-define-group-parameter
1269 list-identifier
1270 :variable-document
1271 "Alist of regexps and correspondent identifiers."
1272 :variable-group gnus-article-washing
1273 :parameter-type
1274 '(choice :tag "Identifier"
1275 :value nil
1276 (symbol :tag "Item in `gnus-list-identifiers'" none)
1277 regexp
1278 (const :tag "None" nil))
1279 :parameter-document
1280 "If non-nil, specify how to remove `identifiers' from articles' subject.
1281
1282 Any symbol is used to look up a regular expression to match the
1283 banner in `gnus-list-identifiers'. A string is used as a regular
1284 expression to match the identifier directly.")
1285
1286 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1287 "Gnus 5.10 (Emacs 22.1)")
1288
1289 (defcustom gnus-treat-strip-pem nil
1290 "Strip PEM signatures.
1291 Valid values are nil, t, `head', `first', `last', an integer or a
1292 predicate. See Info node `(gnus)Customizing Articles'."
1293 :group 'gnus-article-treat
1294 :link '(custom-manual "(gnus)Customizing Articles")
1295 :type gnus-article-treat-custom)
1296
1297 (defcustom gnus-treat-strip-banner t
1298 "Strip banners from articles.
1299 The banner to be stripped is specified in the `banner' group parameter.
1300 Valid values are nil, t, `head', `first', `last', an integer or a
1301 predicate. See Info node `(gnus)Customizing Articles'."
1302 :group 'gnus-article-treat
1303 :link '(custom-manual "(gnus)Customizing Articles")
1304 :type gnus-article-treat-custom)
1305
1306 (defcustom gnus-treat-highlight-headers 'head
1307 "Highlight the headers.
1308 Valid values are nil, t, `head', `first', `last', an integer or a
1309 predicate. See Info node `(gnus)Customizing Articles'."
1310 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :type gnus-article-treat-head-custom)
1313 (put 'gnus-treat-highlight-headers 'highlight t)
1314
1315 (defcustom gnus-treat-highlight-citation t
1316 "Highlight cited text.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate. See Info node `(gnus)Customizing Articles'."
1319 :group 'gnus-article-treat
1320 :link '(custom-manual "(gnus)Customizing Articles")
1321 :type gnus-article-treat-custom)
1322 (put 'gnus-treat-highlight-citation 'highlight t)
1323
1324 (defcustom gnus-treat-strip-headers-in-body t
1325 "Strip the X-No-Archive header line from the beginning of the body.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'."
1328 :version "21.1"
1329 :group 'gnus-article-treat
1330 :link '(custom-manual "(gnus)Customizing Articles")
1331 :type gnus-article-treat-custom)
1332
1333 (defcustom gnus-treat-strip-trailing-blank-lines nil
1334 "Strip trailing blank lines.
1335 Valid values are nil, t, `head', `first', `last', an integer or a
1336 predicate. See Info node `(gnus)Customizing Articles'.
1337
1338 When set to t, it also strips trailing blanks in all MIME parts.
1339 Consider to use `last' instead."
1340 :group 'gnus-article-treat
1341 :link '(custom-manual "(gnus)Customizing Articles")
1342 :type gnus-article-treat-custom)
1343
1344 (defcustom gnus-treat-strip-leading-blank-lines nil
1345 "Strip leading blank lines.
1346 Valid values are nil, t, `head', `first', `last', an integer or a
1347 predicate. See Info node `(gnus)Customizing Articles'.
1348
1349 When set to t, it also strips trailing blanks in all MIME parts."
1350 :group 'gnus-article-treat
1351 :link '(custom-manual "(gnus)Customizing Articles")
1352 :type gnus-article-treat-custom)
1353
1354 (defcustom gnus-treat-strip-multiple-blank-lines nil
1355 "Strip multiple blank lines.
1356 Valid values are nil, t, `head', `first', `last', an integer or a
1357 predicate. See Info node `(gnus)Customizing Articles'."
1358 :group 'gnus-article-treat
1359 :link '(custom-manual "(gnus)Customizing Articles")
1360 :type gnus-article-treat-custom)
1361
1362 (defcustom gnus-treat-unfold-headers 'head
1363 "Unfold folded header lines.
1364 Valid values are nil, t, `head', `first', `last', an integer or a
1365 predicate. See Info node `(gnus)Customizing Articles'."
1366 :version "22.1"
1367 :group 'gnus-article-treat
1368 :link '(custom-manual "(gnus)Customizing Articles")
1369 :type gnus-article-treat-custom)
1370
1371 (defcustom gnus-article-unfold-long-headers nil
1372 "If non-nil, allow unfolding headers even if the header is long.
1373 If it is a regexp, only long headers matching this regexp are unfolded.
1374 If it is t, all long headers are unfolded.
1375
1376 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1377 :version "23.1" ;; No Gnus
1378 :group 'gnus-article-treat
1379 :type '(choice (const nil)
1380 (const :tag "all" t)
1381 (regexp)))
1382
1383 (defcustom gnus-treat-fold-headers nil
1384 "Fold headers.
1385 Valid values are nil, t, `head', `first', `last', an integer or a
1386 predicate. See Info node `(gnus)Customizing Articles'."
1387 :version "22.1"
1388 :group 'gnus-article-treat
1389 :link '(custom-manual "(gnus)Customizing Articles")
1390 :type gnus-article-treat-custom)
1391
1392 (defcustom gnus-treat-fold-newsgroups 'head
1393 "Fold the Newsgroups and Followup-To headers.
1394 Valid values are nil, t, `head', `first', `last', an integer or a
1395 predicate. See Info node `(gnus)Customizing Articles'."
1396 :version "22.1"
1397 :group 'gnus-article-treat
1398 :link '(custom-manual "(gnus)Customizing Articles")
1399 :type gnus-article-treat-custom)
1400
1401 (defcustom gnus-treat-overstrike t
1402 "Treat overstrike highlighting.
1403 Valid values are nil, t, `head', `first', `last', an integer or a
1404 predicate. See Info node `(gnus)Customizing Articles'."
1405 :group 'gnus-article-treat
1406 :link '(custom-manual "(gnus)Customizing Articles")
1407 :type gnus-article-treat-custom)
1408 (put 'gnus-treat-overstrike 'highlight t)
1409
1410 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1411 "Treat ANSI SGR control sequences.
1412 Valid values are nil, t, `head', `first', `last', an integer or a
1413 predicate. See Info node `(gnus)Customizing Articles'."
1414 :group 'gnus-article-treat
1415 :link '(custom-manual "(gnus)Customizing Articles")
1416 :type gnus-article-treat-custom)
1417
1418 (make-obsolete-variable 'gnus-treat-display-xface
1419 'gnus-treat-display-x-face "Emacs 22.1")
1420
1421 (defcustom gnus-treat-display-x-face
1422 (and (not noninteractive)
1423 (gnus-image-type-available-p 'xbm)
1424 (if (featurep 'xemacs)
1425 (featurep 'xface)
1426 (condition-case nil
1427 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1428 (executable-find "icontopbm"))
1429 ;; shell-command-to-string may signal an error, e.g. if
1430 ;; shell-file-name is not found.
1431 (error nil)))
1432 'head)
1433 "Display X-Face headers.
1434 Valid values are nil and `head'.
1435 See Info node `(gnus)Customizing Articles' and Info node
1436 `(gnus)X-Face' for details."
1437 :group 'gnus-article-treat
1438 :version "21.1"
1439 :link '(custom-manual "(gnus)Customizing Articles")
1440 :link '(custom-manual "(gnus)X-Face")
1441 :type gnus-article-treat-head-custom
1442 :set (lambda (symbol value)
1443 (set-default
1444 symbol
1445 (cond ((or (boundp symbol) (get symbol 'saved-value))
1446 value)
1447 ((boundp 'gnus-treat-display-xface)
1448 (message "\
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450 use gnus-treat-display-x-face instead")
1451 (default-value 'gnus-treat-display-xface))
1452 ((get 'gnus-treat-display-xface 'saved-value)
1453 (message "\
1454 ** gnus-treat-display-xface is an obsolete variable;\
1455 use gnus-treat-display-x-face instead")
1456 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1457 (t
1458 value)))))
1459 (put 'gnus-treat-display-x-face 'highlight t)
1460
1461 (defcustom gnus-treat-display-face
1462 (and (not noninteractive)
1463 (gnus-image-type-available-p 'png)
1464 'head)
1465 "Display Face headers.
1466 Valid values are nil, t, `head', `first', `last', an integer or a
1467 predicate. See Info node `(gnus)Customizing Articles' and Info
1468 node `(gnus)Face' for details."
1469 :group 'gnus-article-treat
1470 :version "22.1"
1471 :link '(custom-manual "(gnus)Customizing Articles")
1472 :link '(custom-manual "(gnus)X-Face")
1473 :type gnus-article-treat-head-custom)
1474 (put 'gnus-treat-display-face 'highlight t)
1475
1476 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1477 "Display smileys.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate. See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Smileys' for details."
1481 :group 'gnus-article-treat
1482 :version "21.1"
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Smileys")
1485 :type gnus-article-treat-custom)
1486 (put 'gnus-treat-display-smileys 'highlight t)
1487
1488 (defcustom gnus-treat-from-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1491 'head nil)
1492 "Display picons in the From header.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496 :version "22.1"
1497 :group 'gnus-article-treat
1498 :group 'gnus-picon
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-from-picon 'highlight t)
1503
1504 (defcustom gnus-treat-mail-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1507 'head nil)
1508 "Display picons in To and Cc headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512 :version "22.1"
1513 :group 'gnus-article-treat
1514 :group 'gnus-picon
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-mail-picon 'highlight t)
1519
1520 (defcustom gnus-treat-newsgroups-picon
1521 (if (and (gnus-image-type-available-p 'xpm)
1522 (gnus-picons-installed-p))
1523 'head nil)
1524 "Display picons in the Newsgroups and Followup-To headers.
1525 Valid values are nil, t, `head', `first', `last', an integer or a
1526 predicate. See Info node `(gnus)Customizing Articles' and Info
1527 node `(gnus)Picons' for details."
1528 :version "22.1"
1529 :group 'gnus-article-treat
1530 :group 'gnus-picon
1531 :link '(custom-manual "(gnus)Customizing Articles")
1532 :link '(custom-manual "(gnus)Picons")
1533 :type gnus-article-treat-head-custom)
1534 (put 'gnus-treat-newsgroups-picon 'highlight t)
1535
1536 (defcustom gnus-treat-from-gravatar nil
1537 "Display gravatars in the From header.
1538 Valid values are nil, t, `head', `first', `last', an integer or a
1539 predicate. See Info node `(gnus)Customizing Articles' and Info
1540 node `(gnus)Gravatars' for details."
1541 :version "24.1"
1542 :group 'gnus-article-treat
1543 :group 'gnus-gravatar
1544 :link '(custom-manual "(gnus)Customizing Articles")
1545 :link '(custom-manual "(gnus)Gravatars")
1546 :type gnus-article-treat-head-custom)
1547 (put 'gnus-treat-from-gravatar 'highlight t)
1548
1549 (defcustom gnus-treat-mail-gravatar nil
1550 "Display gravatars in To and Cc headers.
1551 Valid values are nil, t, `head', `first', `last', an integer or a
1552 predicate. See Info node `(gnus)Customizing Articles' and Info
1553 node `(gnus)Gravatars' for details."
1554 :version "24.1"
1555 :group 'gnus-article-treat
1556 :group 'gnus-gravatar
1557 :link '(custom-manual "(gnus)Customizing Articles")
1558 :link '(custom-manual "(gnus)Gravatars")
1559 :type gnus-article-treat-head-custom)
1560 (put 'gnus-treat-mail-gravatar 'highlight t)
1561
1562 (defcustom gnus-treat-body-boundary
1563 (if (or gnus-treat-newsgroups-picon
1564 gnus-treat-mail-picon
1565 gnus-treat-from-picon
1566 gnus-treat-from-gravatar
1567 gnus-treat-mail-gravatar)
1568 ;; If there's much decoration, the user might prefer a boundary.
1569 'head
1570 nil)
1571 "Draw a boundary at the end of the headers.
1572 Valid values are nil and `head'.
1573 See Info node `(gnus)Customizing Articles' for details."
1574 :version "22.1"
1575 :group 'gnus-article-treat
1576 :link '(custom-manual "(gnus)Customizing Articles")
1577 :type gnus-article-treat-head-custom)
1578
1579 (defcustom gnus-treat-capitalize-sentences nil
1580 "Capitalize sentence-starting words.
1581 Valid values are nil, t, `head', `first', `last', an integer or a
1582 predicate. See Info node `(gnus)Customizing Articles'."
1583 :version "21.1"
1584 :group 'gnus-article-treat
1585 :link '(custom-manual "(gnus)Customizing Articles")
1586 :type gnus-article-treat-custom)
1587
1588 (defcustom gnus-treat-wash-html nil
1589 "Format as HTML.
1590 Valid values are nil, t, `head', `first', `last', an integer or a
1591 predicate. See Info node `(gnus)Customizing Articles'."
1592 :version "22.1"
1593 :group 'gnus-article-treat
1594 :link '(custom-manual "(gnus)Customizing Articles")
1595 :type gnus-article-treat-custom)
1596
1597 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1598 "Fill long lines.
1599 Valid values are nil, t, `head', `first', `last', an integer or a
1600 predicate. See Info node `(gnus)Customizing Articles'."
1601 :version "24.1"
1602 :group 'gnus-article-treat
1603 :link '(custom-manual "(gnus)Customizing Articles")
1604 :type gnus-article-treat-custom)
1605
1606 (defcustom gnus-treat-x-pgp-sig nil
1607 "Verify X-PGP-Sig.
1608 To automatically treat X-PGP-Sig, set it to head.
1609 Valid values are nil, t, `head', `first', `last', an integer or a
1610 predicate. See Info node `(gnus)Customizing Articles'."
1611 :version "22.1"
1612 :group 'gnus-article-treat
1613 :group 'mime-security
1614 :link '(custom-manual "(gnus)Customizing Articles")
1615 :type gnus-article-treat-custom)
1616
1617 (defvar gnus-article-encrypt-protocol-alist
1618 '(("PGP" . mml2015-self-encrypt)))
1619
1620 ;; Set to nil if more than one protocol added to
1621 ;; gnus-article-encrypt-protocol-alist.
1622 (defcustom gnus-article-encrypt-protocol "PGP"
1623 "The protocol used for encrypt articles.
1624 It is a string, such as \"PGP\". If nil, ask user."
1625 :version "22.1"
1626 :type 'string
1627 :group 'mime-security)
1628
1629 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1630 (mm-coding-system-p 'utf-8)
1631 (executable-find idna-program))
1632 "Whether IDNA decoding of headers is used when viewing messages.
1633 This requires GNU Libidn, and by default only enabled if it is found."
1634 :version "22.1"
1635 :group 'gnus-article-headers
1636 :type 'boolean)
1637
1638 (defcustom gnus-article-over-scroll nil
1639 "If non-nil, allow scrolling the article buffer even when there no more text."
1640 :version "22.1"
1641 :group 'gnus-article
1642 :type 'boolean)
1643
1644 (defcustom gnus-inhibit-images nil
1645 "Non-nil means inhibit displaying of images inline in the article body."
1646 :version "24.1"
1647 :group 'gnus-article
1648 :type 'boolean)
1649
1650 (defcustom gnus-blocked-images 'gnus-block-private-groups
1651 "Images that have URLs matching this regexp will be blocked.
1652 This can also be a function to be evaluated. If so, it will be
1653 called with the group name as the parameter, and should return a
1654 regexp."
1655 :version "24.1"
1656 :group 'gnus-art
1657 :type '(choice regexp function))
1658
1659 ;;; Internal variables
1660
1661 (defvar gnus-english-month-names
1662 '("January" "February" "March" "April" "May" "June" "July" "August"
1663 "September" "October" "November" "December"))
1664
1665 (defvar article-goto-body-goes-to-point-min-p nil)
1666 (defvar gnus-article-wash-types nil)
1667 (defvar gnus-article-emphasis-alist nil)
1668 (defvar gnus-article-image-alist nil)
1669
1670 (defvar gnus-article-mime-handle-alist-1 nil)
1671 (defvar gnus-treatment-function-alist
1672 '((gnus-treat-strip-cr gnus-article-remove-cr)
1673 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1674 (gnus-treat-strip-banner gnus-article-strip-banner)
1675 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1676 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1677 (gnus-treat-buttonize gnus-article-add-buttons)
1678 (gnus-treat-fill-article gnus-article-fill-cited-article)
1679 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1680 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1681 (gnus-treat-display-x-face gnus-article-display-x-face)
1682 (gnus-treat-display-face gnus-article-display-face)
1683 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1684 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1685 (gnus-treat-hide-signature gnus-article-hide-signature)
1686 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1687 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1688 (gnus-treat-from-picon gnus-treat-from-picon)
1689 (gnus-treat-mail-picon gnus-treat-mail-picon)
1690 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1691 (gnus-treat-strip-pem gnus-article-hide-pem)
1692 (gnus-treat-date gnus-article-treat-date)
1693 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1694 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1695 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1696 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1697 (gnus-treat-strip-trailing-blank-lines
1698 gnus-article-remove-trailing-blank-lines)
1699 (gnus-treat-strip-leading-blank-lines
1700 gnus-article-strip-leading-blank-lines)
1701 (gnus-treat-strip-multiple-blank-lines
1702 gnus-article-strip-multiple-blank-lines)
1703 (gnus-treat-overstrike gnus-article-treat-overstrike)
1704 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1705 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1706 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1707 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1708 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1709 (gnus-treat-display-smileys gnus-treat-smiley)
1710 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1711 (gnus-treat-wash-html gnus-article-wash-html)
1712 (gnus-treat-emphasize gnus-article-emphasize)
1713 (gnus-treat-hide-citation gnus-article-hide-citation)
1714 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1715 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1716 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1717
1718 (defvar gnus-article-mime-handle-alist nil)
1719 (defvar article-lapsed-timer nil)
1720 (defvar gnus-article-current-summary nil)
1721
1722 (defvar gnus-article-mode-syntax-table
1723 (let ((table (copy-syntax-table text-mode-syntax-table)))
1724 ;; This causes the citation match run O(2^n).
1725 ;; (modify-syntax-entry ?- "w" table)
1726 (modify-syntax-entry ?> ")<" table)
1727 (modify-syntax-entry ?< "(>" table)
1728 ;; make M-. in article buffers work for `foo' strings
1729 (modify-syntax-entry ?' " " table)
1730 (modify-syntax-entry ?` " " table)
1731 table)
1732 "Syntax table used in article mode buffers.
1733 Initialized from `text-mode-syntax-table.")
1734
1735 (defvar gnus-save-article-buffer nil)
1736
1737 (defvar gnus-number-of-articles-to-be-saved nil)
1738
1739 (defvar gnus-inhibit-hiding nil)
1740
1741 (defvar gnus-article-edit-mode nil)
1742
1743 ;;; Macros for dealing with the article buffer.
1744
1745 (defmacro gnus-with-article-headers (&rest forms)
1746 `(with-current-buffer gnus-article-buffer
1747 (save-restriction
1748 (let ((inhibit-read-only t)
1749 (inhibit-point-motion-hooks t)
1750 (case-fold-search t))
1751 (article-narrow-to-head)
1752 ,@forms))))
1753
1754 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1755 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1756
1757 (defmacro gnus-with-article-buffer (&rest forms)
1758 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1759 (with-current-buffer gnus-article-buffer
1760 (let ((inhibit-read-only t))
1761 ,@forms))))
1762
1763 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1764 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1765
1766 (defun gnus-article-goto-header (header)
1767 "Go to HEADER, which is a regular expression."
1768 (re-search-forward (concat "^\\(" header "\\):") nil t))
1769
1770 (defsubst gnus-article-hide-text (b e props)
1771 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1772 (gnus-add-text-properties-when 'article-type nil b e props)
1773 (when (memq 'intangible props)
1774 (put-text-property
1775 (max (1- b) (point-min))
1776 b 'intangible (cddr (memq 'intangible props)))))
1777
1778 (defsubst gnus-article-unhide-text (b e)
1779 "Remove hidden text properties from region between B and E."
1780 (remove-text-properties b e gnus-hidden-properties)
1781 (when (memq 'intangible gnus-hidden-properties)
1782 (put-text-property (max (1- b) (point-min))
1783 b 'intangible nil)))
1784
1785 (defun gnus-article-hide-text-type (b e type)
1786 "Hide text of TYPE between B and E."
1787 (gnus-add-wash-type type)
1788 (gnus-article-hide-text
1789 b e (cons 'article-type (cons type gnus-hidden-properties))))
1790
1791 (defun gnus-article-unhide-text-type (b e type)
1792 "Unhide text of TYPE between B and E."
1793 (gnus-delete-wash-type type)
1794 (remove-text-properties
1795 b e (cons 'article-type (cons type gnus-hidden-properties)))
1796 (when (memq 'intangible gnus-hidden-properties)
1797 (put-text-property (max (1- b) (point-min))
1798 b 'intangible nil)))
1799
1800 (defun gnus-article-delete-text-of-type (type)
1801 "Delete text of TYPE in the current buffer."
1802 (save-excursion
1803 (let ((b (point-min)))
1804 (if (eq type 'multipart)
1805 ;; Remove MIME buttons associated with multipart/alternative parts.
1806 (progn
1807 (goto-char b)
1808 (while (if (get-text-property (point) 'gnus-part)
1809 (setq b (point))
1810 (when (setq b (next-single-property-change (point)
1811 'gnus-part))
1812 (goto-char b)
1813 t))
1814 (end-of-line)
1815 (skip-chars-forward "\n")
1816 (when (eq (get-text-property b 'article-type) 'multipart)
1817 (delete-region b (point)))))
1818 (while (setq b (text-property-any b (point-max) 'article-type type))
1819 (delete-region
1820 b (or (text-property-not-all b (point-max) 'article-type type)
1821 (point-max))))))))
1822
1823 (defun gnus-article-delete-invisible-text ()
1824 "Delete all invisible text in the current buffer."
1825 (save-excursion
1826 (let ((b (point-min)))
1827 (while (setq b (text-property-any b (point-max) 'invisible t))
1828 (delete-region
1829 b (or (text-property-not-all b (point-max) 'invisible t)
1830 (point-max)))))))
1831
1832 (defsubst gnus-article-header-rank ()
1833 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1834 (let ((list gnus-sorted-header-list)
1835 (i 1))
1836 (while list
1837 (if (looking-at (car list))
1838 (setq list nil)
1839 (setq list (cdr list))
1840 (incf i)))
1841 i))
1842
1843 (defun article-hide-headers (&optional arg delete)
1844 "Hide unwanted headers and possibly sort them as well."
1845 (interactive)
1846 ;; This function might be inhibited.
1847 (unless gnus-inhibit-hiding
1848 (let ((inhibit-read-only t)
1849 (case-fold-search t)
1850 (max (1+ (length gnus-sorted-header-list)))
1851 (inhibit-point-motion-hooks t)
1852 (cur (current-buffer))
1853 ignored visible beg)
1854 (save-excursion
1855 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1856 ;; group parameters, so we should go to the summary buffer.
1857 (when (prog1
1858 (condition-case nil
1859 (progn (set-buffer gnus-summary-buffer) t)
1860 (error nil))
1861 (setq ignored (when (not gnus-visible-headers)
1862 (cond ((stringp gnus-ignored-headers)
1863 gnus-ignored-headers)
1864 ((listp gnus-ignored-headers)
1865 (mapconcat 'identity
1866 gnus-ignored-headers
1867 "\\|"))))
1868 visible (cond ((stringp gnus-visible-headers)
1869 gnus-visible-headers)
1870 ((and gnus-visible-headers
1871 (listp gnus-visible-headers))
1872 (mapconcat 'identity
1873 gnus-visible-headers
1874 "\\|")))))
1875 (set-buffer cur))
1876 (save-restriction
1877 ;; First we narrow to just the headers.
1878 (article-narrow-to-head)
1879 ;; Hide any "From " lines at the beginning of (mail) articles.
1880 (while (looking-at "From ")
1881 (forward-line 1))
1882 (unless (bobp)
1883 (delete-region (point-min) (point)))
1884 ;; Then treat the rest of the header lines.
1885 ;; Then we use the two regular expressions
1886 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1887 ;; select which header lines is to remain visible in the
1888 ;; article buffer.
1889 (while (re-search-forward "^[^ \t:]*:" nil t)
1890 (beginning-of-line)
1891 ;; Mark the rank of the header.
1892 (put-text-property
1893 (point) (1+ (point)) 'message-rank
1894 (if (or (and visible (looking-at visible))
1895 (and ignored
1896 (not (looking-at ignored))))
1897 (gnus-article-header-rank)
1898 (+ 2 max)))
1899 (forward-line 1))
1900 (message-sort-headers-1)
1901 (when (setq beg (text-property-any
1902 (point-min) (point-max) 'message-rank (+ 2 max)))
1903 ;; We delete the unwanted headers.
1904 (gnus-add-wash-type 'headers)
1905 (add-text-properties (point-min) (+ 5 (point-min))
1906 '(article-type headers dummy-invisible t))
1907 (delete-region beg (point-max))))))))
1908
1909 (defun article-hide-boring-headers (&optional arg)
1910 "Toggle hiding of headers that aren't very interesting.
1911 If given a negative prefix, always show; if given a positive prefix,
1912 always hide."
1913 (interactive (gnus-article-hidden-arg))
1914 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1915 (not gnus-show-all-headers))
1916 (save-excursion
1917 (save-restriction
1918 (let ((inhibit-read-only t)
1919 (inhibit-point-motion-hooks t))
1920 (article-narrow-to-head)
1921 (dolist (elem gnus-boring-article-headers)
1922 (goto-char (point-min))
1923 (cond
1924 ;; Hide empty headers.
1925 ((eq elem 'empty)
1926 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1927 (forward-line -1)
1928 (gnus-article-hide-text-type
1929 (point-at-bol)
1930 (progn
1931 (end-of-line)
1932 (if (re-search-forward "^[^ \t]" nil t)
1933 (match-beginning 0)
1934 (point-max)))
1935 'boring-headers)))
1936 ;; Hide boring Newsgroups header.
1937 ((eq elem 'newsgroups)
1938 (when (gnus-string-equal
1939 (gnus-fetch-field "newsgroups")
1940 (gnus-group-real-name
1941 (if (boundp 'gnus-newsgroup-name)
1942 gnus-newsgroup-name
1943 "")))
1944 (gnus-article-hide-header "newsgroups")))
1945 ((eq elem 'to-address)
1946 (let ((to (message-fetch-field "to"))
1947 (to-address
1948 (gnus-parameter-to-address
1949 (if (boundp 'gnus-newsgroup-name)
1950 gnus-newsgroup-name ""))))
1951 (when (and to to-address
1952 (ignore-errors
1953 (gnus-string-equal
1954 ;; only one address in To
1955 (nth 1 (mail-extract-address-components to))
1956 to-address)))
1957 (gnus-article-hide-header "to"))))
1958 ((eq elem 'to-list)
1959 (let ((to (message-fetch-field "to"))
1960 (to-list
1961 (gnus-parameter-to-list
1962 (if (boundp 'gnus-newsgroup-name)
1963 gnus-newsgroup-name ""))))
1964 (when (and to to-list
1965 (ignore-errors
1966 (gnus-string-equal
1967 ;; only one address in To
1968 (nth 1 (mail-extract-address-components to))
1969 to-list)))
1970 (gnus-article-hide-header "to"))))
1971 ((eq elem 'cc-list)
1972 (let ((cc (message-fetch-field "cc"))
1973 (to-list
1974 (gnus-parameter-to-list
1975 (if (boundp 'gnus-newsgroup-name)
1976 gnus-newsgroup-name ""))))
1977 (when (and cc to-list
1978 (ignore-errors
1979 (gnus-string-equal
1980 ;; only one address in CC
1981 (nth 1 (mail-extract-address-components cc))
1982 to-list)))
1983 (gnus-article-hide-header "cc"))))
1984 ((eq elem 'followup-to)
1985 (when (gnus-string-equal
1986 (message-fetch-field "followup-to")
1987 (message-fetch-field "newsgroups"))
1988 (gnus-article-hide-header "followup-to")))
1989 ((eq elem 'reply-to)
1990 (if (gnus-group-find-parameter
1991 gnus-newsgroup-name 'broken-reply-to)
1992 (gnus-article-hide-header "reply-to")
1993 (let ((from (message-fetch-field "from"))
1994 (reply-to (message-fetch-field "reply-to")))
1995 (when
1996 (and
1997 from reply-to
1998 (ignore-errors
1999 (equal
2000 (sort (mapcar
2001 (lambda (x) (downcase (cadr x)))
2002 (mail-extract-address-components from t))
2003 'string<)
2004 (sort (mapcar
2005 (lambda (x) (downcase (cadr x)))
2006 (mail-extract-address-components reply-to t))
2007 'string<))))
2008 (gnus-article-hide-header "reply-to")))))
2009 ((eq elem 'date)
2010 (let ((date (with-current-buffer gnus-original-article-buffer
2011 ;; If date in `gnus-article-buffer' is localized
2012 ;; (`gnus-treat-date-user-defined'),
2013 ;; `days-between' might fail.
2014 (message-fetch-field "date"))))
2015 (when (and date
2016 (< (days-between (current-time-string) date)
2017 4))
2018 (gnus-article-hide-header "date"))))
2019 ((eq elem 'long-to)
2020 (let ((to (message-fetch-field "to"))
2021 (cc (message-fetch-field "cc")))
2022 (when (> (length to) 1024)
2023 (gnus-article-hide-header "to"))
2024 (when (> (length cc) 1024)
2025 (gnus-article-hide-header "cc"))))
2026 ((eq elem 'many-to)
2027 (let ((to-count 0)
2028 (cc-count 0))
2029 (goto-char (point-min))
2030 (while (re-search-forward "^to:" nil t)
2031 (setq to-count (1+ to-count)))
2032 (when (> to-count 1)
2033 (while (> to-count 0)
2034 (goto-char (point-min))
2035 (save-restriction
2036 (re-search-forward "^to:" nil nil to-count)
2037 (forward-line -1)
2038 (narrow-to-region (point) (point-max))
2039 (gnus-article-hide-header "to"))
2040 (setq to-count (1- to-count))))
2041 (goto-char (point-min))
2042 (while (re-search-forward "^cc:" nil t)
2043 (setq cc-count (1+ cc-count)))
2044 (when (> cc-count 1)
2045 (while (> cc-count 0)
2046 (goto-char (point-min))
2047 (save-restriction
2048 (re-search-forward "^cc:" nil nil cc-count)
2049 (forward-line -1)
2050 (narrow-to-region (point) (point-max))
2051 (gnus-article-hide-header "cc"))
2052 (setq cc-count (1- cc-count)))))))))))))
2053
2054 (defun gnus-article-hide-header (header)
2055 (save-excursion
2056 (goto-char (point-min))
2057 (when (re-search-forward (concat "^" header ":") nil t)
2058 (gnus-article-hide-text-type
2059 (point-at-bol)
2060 (progn
2061 (end-of-line)
2062 (if (re-search-forward "^[^ \t]" nil t)
2063 (match-beginning 0)
2064 (point-max)))
2065 'boring-headers))))
2066
2067 (defvar gnus-article-normalized-header-length 40
2068 "Length of normalized headers.")
2069
2070 (defun article-normalize-headers ()
2071 "Make all header lines 40 characters long."
2072 (interactive)
2073 (let ((inhibit-read-only t)
2074 column)
2075 (save-excursion
2076 (save-restriction
2077 (article-narrow-to-head)
2078 (while (not (eobp))
2079 (cond
2080 ((< (setq column (- (point-at-eol) (point)))
2081 gnus-article-normalized-header-length)
2082 (end-of-line)
2083 (insert (make-string
2084 (- gnus-article-normalized-header-length column)
2085 ? )))
2086 ((> column gnus-article-normalized-header-length)
2087 (gnus-put-text-property
2088 (progn
2089 (forward-char gnus-article-normalized-header-length)
2090 (point))
2091 (point-at-eol)
2092 'invisible t))
2093 (t
2094 ;; Do nothing.
2095 ))
2096 (forward-line 1))))))
2097
2098 (defun article-treat-dumbquotes ()
2099 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2100 Note that this function guesses whether a character is a sm*rtq**t* or
2101 not, so it should only be used interactively.
2102
2103 Sm*rtq**t*s are M****s***'s unilateral extension to the
2104 iso-8859-1 character map in an attempt to provide more quoting
2105 characters. If you see something like \\222 or \\264 where
2106 you're expecting some kind of apostrophe or quotation mark, then
2107 try this wash."
2108 (interactive)
2109 (article-translate-strings gnus-article-dumbquotes-map))
2110
2111 (defvar org-entities)
2112
2113 (defun article-treat-non-ascii ()
2114 "Translate many Unicode characters into their ASCII equivalents."
2115 (interactive)
2116 (require 'org-entities)
2117 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2118 (dolist (elem org-entities)
2119 (when (and (listp elem)
2120 (= (length (nth 6 elem)) 1))
2121 (if (featurep 'xemacs)
2122 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2123 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2124 (save-excursion
2125 (when (article-goto-body)
2126 (let ((inhibit-read-only t)
2127 replace props)
2128 (while (not (eobp))
2129 (if (not (setq replace (if (featurep 'xemacs)
2130 (get-char-table (following-char) table)
2131 (aref table (following-char)))))
2132 (forward-char 1)
2133 (if (prog1
2134 (setq props (text-properties-at (point)))
2135 (delete-char 1))
2136 (add-text-properties (point) (progn (insert replace) (point))
2137 props)
2138 (insert replace)))))))))
2139
2140 (defun article-translate-strings (map)
2141 "Translate all string in the body of the article according to MAP.
2142 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2143 (save-excursion
2144 (when (article-goto-body)
2145 (let ((inhibit-read-only t))
2146 (dolist (elem map)
2147 (let ((from (car elem))
2148 (to (cadr elem)))
2149 (save-excursion
2150 (if (stringp from)
2151 (while (search-forward from nil t)
2152 (replace-match to))
2153 (while (not (eobp))
2154 (if (eq (following-char) from)
2155 (progn
2156 (delete-char 1)
2157 (insert to))
2158 (forward-char 1)))))))))))
2159
2160 (defun article-treat-overstrike ()
2161 "Translate overstrikes into bold text."
2162 (interactive)
2163 (save-excursion
2164 (when (article-goto-body)
2165 (let ((inhibit-read-only t))
2166 (while (search-forward "\b" nil t)
2167 (let ((next (char-after))
2168 (previous (char-after (- (point) 2))))
2169 ;; We do the boldification/underlining by hiding the
2170 ;; overstrikes and putting the proper text property
2171 ;; on the letters.
2172 (cond
2173 ((eq next previous)
2174 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2175 (put-text-property (point) (1+ (point)) 'face 'bold))
2176 ((eq next ?_)
2177 (gnus-article-hide-text-type
2178 (1- (point)) (1+ (point)) 'overstrike)
2179 (put-text-property
2180 (- (point) 2) (1- (point)) 'face 'underline))
2181 ((eq previous ?_)
2182 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2183 (put-text-property
2184 (point) (1+ (point)) 'face 'underline)))))))))
2185
2186 (defun article-treat-ansi-sequences ()
2187 "Translate ANSI SGR control sequences into overlays or extents."
2188 (interactive)
2189 (save-excursion
2190 (when (article-goto-body)
2191 (let ((inhibit-read-only t))
2192 (ansi-color-apply-on-region (point) (point-max))))))
2193
2194 (defun gnus-article-treat-unfold-headers ()
2195 "Unfold folded message headers.
2196 Only the headers that fit into the current window width will be
2197 unfolded."
2198 (interactive)
2199 (gnus-with-article-headers
2200 (let (length)
2201 (while (not (eobp))
2202 (save-restriction
2203 (mail-header-narrow-to-field)
2204 (let* ((header (buffer-string))
2205 (unfoldable
2206 (or (equal gnus-article-unfold-long-headers t)
2207 (and (stringp gnus-article-unfold-long-headers)
2208 (string-match gnus-article-unfold-long-headers
2209 header)))))
2210 (with-temp-buffer
2211 (insert header)
2212 (goto-char (point-min))
2213 (while (re-search-forward "\n[\t ]" nil t)
2214 (replace-match " " t t)))
2215 (setq length (- (point-max) (point-min) 1))
2216 (when (or unfoldable
2217 (< length (window-width)))
2218 (while (re-search-forward "\n[\t ]" nil t)
2219 (replace-match " " t t))))
2220 (goto-char (point-max)))))))
2221
2222 (defun gnus-article-treat-fold-headers ()
2223 "Fold message headers."
2224 (interactive)
2225 (gnus-with-article-headers
2226 (while (not (eobp))
2227 (save-restriction
2228 (mail-header-narrow-to-field)
2229 (mail-header-fold-field)
2230 (goto-char (point-max))))))
2231
2232 (defun gnus-treat-smiley ()
2233 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2234 (interactive)
2235 (gnus-with-article-buffer
2236 (if (memq 'smiley gnus-article-wash-types)
2237 (gnus-delete-images 'smiley)
2238 (article-goto-body)
2239 (let ((images (smiley-region (point) (point-max))))
2240 (when images
2241 (gnus-add-wash-type 'smiley)
2242 (dolist (image images)
2243 (gnus-add-image 'smiley image)))))))
2244
2245 (defun gnus-article-remove-images ()
2246 "Remove all images from the article buffer."
2247 (interactive)
2248 (gnus-with-article-buffer
2249 (save-restriction
2250 (widen)
2251 (dolist (elem gnus-article-image-alist)
2252 (gnus-delete-images (car elem))))))
2253
2254 (autoload 'w3m-toggle-inline-images "w3m")
2255
2256 (defun gnus-article-show-images ()
2257 "Show any images that are in the HTML-rendered article buffer.
2258 This only works if the article in question is HTML."
2259 (interactive)
2260 (gnus-with-article-buffer
2261 (save-restriction
2262 (widen)
2263 (if (eq mm-text-html-renderer 'w3m)
2264 (let ((mm-inline-text-html-with-images nil))
2265 (w3m-toggle-inline-images))
2266 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2267 'image-displayer))
2268 (destructuring-bind (start end function) region
2269 (funcall function (get-text-property start 'image-url)
2270 start end)))))))
2271
2272 (defun gnus-article-treat-fold-newsgroups ()
2273 "Unfold folded message headers.
2274 Only the headers that fit into the current window width will be
2275 unfolded."
2276 (interactive)
2277 (gnus-with-article-headers
2278 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2279 (save-restriction
2280 (mail-header-narrow-to-field)
2281 (while (re-search-forward ", *" nil t)
2282 (replace-match ", " t t))
2283 (mail-header-fold-field)
2284 (goto-char (point-max))))))
2285
2286 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2287 "Value of `truncate-lines' in Gnus Article buffer.
2288 Valid values are nil, t, `head', `first', `last', an integer or a
2289 predicate. See Info node `(gnus)Customizing Articles'."
2290 :version "23.1" ;; No Gnus
2291 :group 'gnus-article
2292 ;; :link '(custom-manual "(gnus)Customizing Articles")
2293 :type 'boolean)
2294
2295 (defun gnus-article-toggle-truncate-lines (&optional arg)
2296 "Toggle whether to fold or truncate long lines in article the buffer.
2297 If ARG is non-nil and not a number, toggle
2298 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2299 long lines if and only if arg is positive."
2300 (interactive "P")
2301 (cond
2302 ((and (numberp arg) (> arg 0))
2303 (setq gnus-article-truncate-lines t))
2304 ((numberp arg)
2305 (setq gnus-article-truncate-lines nil))
2306 (arg
2307 (setq gnus-article-truncate-lines
2308 (not gnus-article-truncate-lines))))
2309 (gnus-with-article-buffer
2310 (cond
2311 ((and (numberp arg) (> arg 0))
2312 (setq truncate-lines nil))
2313 ((numberp arg)
2314 (setq truncate-lines t)))
2315 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2316 ;; `toggle-truncate-lines' needs an argument.
2317 (toggle-truncate-lines)))
2318
2319 (defun gnus-article-treat-body-boundary ()
2320 "Place a boundary line at the end of the headers."
2321 (interactive)
2322 (when (and gnus-body-boundary-delimiter
2323 (> (length gnus-body-boundary-delimiter) 0))
2324 (gnus-with-article-headers
2325 (goto-char (point-max))
2326 (let ((start (point)))
2327 (insert "X-Boundary: ")
2328 (gnus-add-text-properties start (point) '(invisible t intangible t))
2329 (insert (let (str (max (window-width)))
2330 (if (featurep 'xemacs)
2331 (setq max (1- max)))
2332 (while (>= max (length str))
2333 (setq str (concat str gnus-body-boundary-delimiter)))
2334 (substring str 0 max))
2335 "\n")
2336 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2337
2338 (defun article-fill-long-lines ()
2339 "Fill lines that are wider than the window width."
2340 (interactive)
2341 (save-excursion
2342 (let ((inhibit-read-only t)
2343 (width (window-width (get-buffer-window (current-buffer)))))
2344 (save-restriction
2345 (article-goto-body)
2346 (let ((adaptive-fill-mode nil)) ;Why? -sm
2347 (while (not (eobp))
2348 (end-of-line)
2349 (when (>= (current-column) (min fill-column width))
2350 (narrow-to-region (min (1+ (point)) (point-max))
2351 (point-at-bol))
2352 (let ((goback (point-marker)))
2353 (fill-paragraph nil)
2354 (goto-char (marker-position goback)))
2355 (widen))
2356 (forward-line 1)))))))
2357
2358 (defun article-capitalize-sentences ()
2359 "Capitalize the first word in each sentence."
2360 (interactive)
2361 (save-excursion
2362 (let ((inhibit-read-only t)
2363 (paragraph-start "^[\n\^L]"))
2364 (article-goto-body)
2365 (while (not (eobp))
2366 (capitalize-word 1)
2367 (forward-sentence)))))
2368
2369 (defun article-remove-cr ()
2370 "Remove trailing CRs and then translate remaining CRs into LFs."
2371 (interactive)
2372 (save-excursion
2373 (let ((inhibit-read-only t))
2374 (goto-char (point-min))
2375 (while (re-search-forward "\r+$" nil t)
2376 (replace-match "" t t))
2377 (goto-char (point-min))
2378 (while (search-forward "\r" nil t)
2379 (replace-match "\n" t t)))))
2380
2381 (defun article-remove-trailing-blank-lines ()
2382 "Remove all trailing blank lines from the article."
2383 (interactive)
2384 (save-excursion
2385 (let ((inhibit-read-only t))
2386 (goto-char (point-max))
2387 (delete-region
2388 (point)
2389 (progn
2390 (while (and (not (bobp))
2391 (looking-at "^[ \t]*$")
2392 (not (gnus-annotation-in-region-p
2393 (point) (point-at-eol))))
2394 (forward-line -1))
2395 (forward-line 1)
2396 (point))))))
2397
2398 (defvar gnus-face-properties-alist)
2399
2400 (defun article-display-face (&optional force)
2401 "Display any Face headers in the header."
2402 (interactive (list 'force))
2403 (let ((wash-face-p buffer-read-only))
2404 (gnus-with-article-headers
2405 ;; When displaying parts, this function can be called several times on
2406 ;; the same article, without any intended toggle semantic (as typing `W
2407 ;; D d' would have). So face deletion must occur only when we come from
2408 ;; an interactive command, that is when the *Article* buffer is
2409 ;; read-only.
2410 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2411 (gnus-delete-images 'face)
2412 (let ((from (message-fetch-field "from"))
2413 face faces)
2414 (save-current-buffer
2415 (when (and wash-face-p
2416 (gnus-buffer-live-p gnus-original-article-buffer)
2417 (not (re-search-forward "^Face:[\t ]*" nil t)))
2418 (set-buffer gnus-original-article-buffer))
2419 (save-restriction
2420 (mail-narrow-to-head)
2421 (when (or force
2422 ;; Check whether this face is censored.
2423 (not (and gnus-article-x-face-too-ugly
2424 (or from
2425 (setq from (message-fetch-field "from")))
2426 (string-match gnus-article-x-face-too-ugly
2427 from))))
2428 (while (gnus-article-goto-header "Face")
2429 (push (mail-header-field-value) faces)))))
2430 (when faces
2431 (goto-char (point-min))
2432 (let (png image)
2433 (unless (setq from (gnus-article-goto-header "from"))
2434 (insert "From:")
2435 (setq from (point))
2436 (insert " [no `from' set]\n"))
2437 (while faces
2438 (when (setq png (gnus-convert-face-to-png (pop faces)))
2439 (setq image
2440 (apply 'gnus-create-image png 'png t
2441 (cdr (assq 'png gnus-face-properties-alist))))
2442 (goto-char from)
2443 (when image
2444 (gnus-add-wash-type 'face)
2445 (gnus-add-image 'face image)
2446 (gnus-put-image image nil 'face)))))))))))
2447
2448 (defun article-display-x-face (&optional force)
2449 "Look for an X-Face header and display it if present."
2450 (interactive (list 'force))
2451 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2452 (gnus-with-article-headers
2453 ;; Delete the old process, if any.
2454 (when (process-status "article-x-face")
2455 (delete-process "article-x-face"))
2456 ;; See the comment in `article-display-face'.
2457 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2458 ;; We have already displayed X-Faces, so we remove them
2459 ;; instead.
2460 (gnus-delete-images 'xface)
2461 ;; Display X-Faces.
2462 (let ((from (message-fetch-field "from"))
2463 x-faces face)
2464 (save-current-buffer
2465 (when (and wash-face-p
2466 (gnus-buffer-live-p gnus-original-article-buffer)
2467 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2468 ;; If type `W f', use gnus-original-article-buffer,
2469 ;; otherwise use the current buffer because displaying
2470 ;; RFC822 parts calls this function too.
2471 (set-buffer gnus-original-article-buffer))
2472 (save-restriction
2473 (mail-narrow-to-head)
2474 (and gnus-article-x-face-command
2475 (or force
2476 ;; Check whether this face is censored.
2477 (not (and gnus-article-x-face-too-ugly
2478 (or from
2479 (setq from (message-fetch-field "from")))
2480 (string-match gnus-article-x-face-too-ugly
2481 from))))
2482 (while (gnus-article-goto-header "X-Face")
2483 (push (mail-header-field-value) x-faces)))))
2484 (when x-faces
2485 ;; We display the face.
2486 (cond ((functionp gnus-article-x-face-command)
2487 ;; The command is a lisp function, so we call it.
2488 (mapc gnus-article-x-face-command x-faces))
2489 ((stringp gnus-article-x-face-command)
2490 ;; The command is a string, so we interpret the command
2491 ;; as a, well, command, and fork it off.
2492 (let ((process-connection-type nil))
2493 (gnus-set-process-query-on-exit-flag
2494 (start-process
2495 "article-x-face" nil shell-file-name
2496 shell-command-switch gnus-article-x-face-command)
2497 nil)
2498 ;; Sending multiple EOFs to xv doesn't work,
2499 ;; so we only do a single external face.
2500 (with-temp-buffer
2501 (insert (car x-faces))
2502 (process-send-region "article-x-face"
2503 (point-min) (point-max)))
2504 (process-send-eof "article-x-face")))
2505 (t
2506 (error "`%s' set to `%s' is not a function"
2507 gnus-article-x-face-command
2508 'gnus-article-x-face-command)))))))))
2509
2510 (defun article-decode-mime-words ()
2511 "Decode all MIME-encoded words in the article."
2512 (interactive)
2513 (gnus-with-article-buffer
2514 (let ((inhibit-point-motion-hooks t)
2515 (mail-parse-charset gnus-newsgroup-charset)
2516 (mail-parse-ignored-charsets
2517 (with-current-buffer gnus-summary-buffer
2518 gnus-newsgroup-ignored-charsets)))
2519 (mail-decode-encoded-word-region (point-min) (point-max)))))
2520
2521 (defun article-decode-charset (&optional prompt)
2522 "Decode charset-encoded text in the article.
2523 If PROMPT (the prefix), prompt for a coding system to use."
2524 (interactive "P")
2525 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2526 (inhibit-read-only t)
2527 (mail-parse-charset gnus-newsgroup-charset)
2528 (mail-parse-ignored-charsets
2529 (save-excursion (condition-case nil
2530 (set-buffer gnus-summary-buffer)
2531 (error))
2532 gnus-newsgroup-ignored-charsets))
2533 ct cte ctl charset format)
2534 (save-excursion
2535 (save-restriction
2536 (article-narrow-to-head)
2537 (setq ct (message-fetch-field "Content-Type" t)
2538 cte (message-fetch-field "Content-Transfer-Encoding" t)
2539 ctl (and ct (mail-header-parse-content-type ct))
2540 charset (cond
2541 (prompt
2542 (mm-read-coding-system "Charset to decode: "))
2543 (ctl
2544 (mail-content-type-get ctl 'charset)))
2545 format (and ctl (mail-content-type-get ctl 'format)))
2546 (when cte
2547 (setq cte (mail-header-strip cte)))
2548 (if (and ctl (not (string-match "/" (car ctl))))
2549 (setq ctl nil))
2550 (goto-char (point-max)))
2551 (forward-line 1)
2552 (save-restriction
2553 (narrow-to-region (point) (point-max))
2554 (when (and (eq mail-parse-charset 'gnus-decoded)
2555 (eq (mm-body-7-or-8) '8bit))
2556 ;; The text code could have been decoded.
2557 (setq charset mail-parse-charset))
2558 (when (and (or (not ctl)
2559 (equal (car ctl) "text/plain"))
2560 (not format)) ;; article with format will decode later.
2561 (mm-decode-body
2562 charset (and cte (intern (downcase
2563 (gnus-strip-whitespace cte))))
2564 (car ctl)))))))
2565
2566 (defun article-decode-encoded-words ()
2567 "Remove encoded-word encoding from headers."
2568 (let ((inhibit-point-motion-hooks t)
2569 (mail-parse-charset gnus-newsgroup-charset)
2570 (mail-parse-ignored-charsets
2571 (save-excursion (condition-case nil
2572 (set-buffer gnus-summary-buffer)
2573 (error))
2574 gnus-newsgroup-ignored-charsets))
2575 (inhibit-read-only t)
2576 end start)
2577 (goto-char (point-min))
2578 (when (search-forward "\n\n" nil 'move)
2579 (forward-line -1))
2580 (setq end (point))
2581 (while (not (bobp))
2582 (while (progn
2583 (forward-line -1)
2584 (and (not (bobp))
2585 (memq (char-after) '(?\t ? )))))
2586 (setq start (point))
2587 (if (looking-at "\
2588 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2589 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2590 (funcall gnus-decode-address-function start end)
2591 (funcall gnus-decode-header-function start end))
2592 (goto-char (setq end start)))))
2593
2594 (defun article-decode-group-name ()
2595 "Decode group names in Newsgroups, Followup-To and Xref headers."
2596 (let ((inhibit-point-motion-hooks t)
2597 (inhibit-read-only t)
2598 (method (gnus-find-method-for-group gnus-newsgroup-name))
2599 regexp)
2600 (when (and (or gnus-group-name-charset-method-alist
2601 gnus-group-name-charset-group-alist)
2602 (gnus-buffer-live-p gnus-original-article-buffer))
2603 (save-restriction
2604 (article-narrow-to-head)
2605 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2606 (with-current-buffer gnus-original-article-buffer
2607 (goto-char (point-min)))
2608 (setq regexp (concat "^" header
2609 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2610 (while (re-search-forward regexp nil t)
2611 (replace-match (save-match-data
2612 (gnus-decode-newsgroups
2613 ;; XXX how to use data in article buffer?
2614 (with-current-buffer gnus-original-article-buffer
2615 (re-search-forward regexp nil t)
2616 (match-string 1))
2617 gnus-newsgroup-name method))
2618 t t nil 1))
2619 (goto-char (point-min)))))))
2620
2621 (autoload 'idna-to-unicode "idna")
2622
2623 (defun article-decode-idna-rhs ()
2624 "Decode IDNA strings in RHS in various headers in current buffer.
2625 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2626 Mail-Reply-To: and Mail-Followup-To:."
2627 (when gnus-use-idna
2628 (save-restriction
2629 (let ((inhibit-point-motion-hooks t)
2630 (inhibit-read-only t))
2631 (article-narrow-to-head)
2632 (goto-char (point-min))
2633 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2634 (let (ace unicode)
2635 (when (save-match-data
2636 (and (setq ace (match-string 1))
2637 (save-excursion
2638 (and (re-search-backward "^[^ \t]" nil t)
2639 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2640 (setq unicode (idna-to-unicode ace))))
2641 (unless (string= ace unicode)
2642 (replace-match unicode nil nil nil 1)))))))))
2643
2644 (defun article-de-quoted-unreadable (&optional force read-charset)
2645 "Translate a quoted-printable-encoded article.
2646 If FORCE, decode the article whether it is marked as quoted-printable
2647 or not.
2648 If READ-CHARSET, ask for a coding system."
2649 (interactive (list 'force current-prefix-arg))
2650 (save-excursion
2651 (let ((inhibit-read-only t) type charset)
2652 (if (gnus-buffer-live-p gnus-original-article-buffer)
2653 (with-current-buffer gnus-original-article-buffer
2654 (setq type
2655 (gnus-fetch-field "content-transfer-encoding"))
2656 (let* ((ct (gnus-fetch-field "content-type"))
2657 (ctl (and ct (mail-header-parse-content-type ct))))
2658 (setq charset (and ctl
2659 (mail-content-type-get ctl 'charset)))
2660 (if (stringp charset)
2661 (setq charset (intern (downcase charset)))))))
2662 (if read-charset
2663 (setq charset (mm-read-coding-system "Charset: " charset)))
2664 (unless charset
2665 (setq charset gnus-newsgroup-charset))
2666 (when (or force
2667 (and type (let ((case-fold-search t))
2668 (string-match "quoted-printable" type))))
2669 (article-goto-body)
2670 (quoted-printable-decode-region
2671 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2672
2673 (defun article-de-base64-unreadable (&optional force read-charset)
2674 "Translate a base64 article.
2675 If FORCE, decode the article whether it is marked as base64 not.
2676 If READ-CHARSET, ask for a coding system."
2677 (interactive (list 'force current-prefix-arg))
2678 (save-excursion
2679 (let ((inhibit-read-only t) type charset)
2680 (if (gnus-buffer-live-p gnus-original-article-buffer)
2681 (with-current-buffer gnus-original-article-buffer
2682 (setq type
2683 (gnus-fetch-field "content-transfer-encoding"))
2684 (let* ((ct (gnus-fetch-field "content-type"))
2685 (ctl (and ct (mail-header-parse-content-type ct))))
2686 (setq charset (and ctl
2687 (mail-content-type-get ctl 'charset)))
2688 (if (stringp charset)
2689 (setq charset (intern (downcase charset)))))))
2690 (if read-charset
2691 (setq charset (mm-read-coding-system "Charset: " charset)))
2692 (unless charset
2693 (setq charset gnus-newsgroup-charset))
2694 (when (or force
2695 (and type (let ((case-fold-search t))
2696 (string-match "base64" type))))
2697 (article-goto-body)
2698 (save-restriction
2699 (narrow-to-region (point) (point-max))
2700 (base64-decode-region (point-min) (point-max))
2701 (mm-decode-coding-region
2702 (point-min) (point-max)
2703 (mm-charset-to-coding-system charset nil t)))))))
2704
2705 (eval-when-compile
2706 (require 'rfc1843))
2707
2708 (defun article-decode-HZ ()
2709 "Translate a HZ-encoded article."
2710 (interactive)
2711 (require 'rfc1843)
2712 (save-excursion
2713 (let ((inhibit-read-only t))
2714 (rfc1843-decode-region (point-min) (point-max)))))
2715
2716 (defun article-unsplit-urls ()
2717 "Remove the newlines that some other mailers insert into URLs."
2718 (interactive)
2719 (save-excursion
2720 (let ((inhibit-read-only t))
2721 (goto-char (point-min))
2722 (while (re-search-forward
2723 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2724 (replace-match "\\1\\3" t)))
2725 (when (gmm-called-interactively-p 'any)
2726 (gnus-treat-article nil))))
2727
2728 (defun article-wash-html ()
2729 "Format an HTML article."
2730 (interactive)
2731 (let ((handles nil)
2732 (buffer-read-only nil))
2733 (when (gnus-buffer-live-p gnus-original-article-buffer)
2734 (with-current-buffer gnus-original-article-buffer
2735 (setq handles (mm-dissect-buffer t t))))
2736 (article-goto-body)
2737 (delete-region (point) (point-max))
2738 (mm-enable-multibyte)
2739 (mm-inline-text-html handles)))
2740
2741 (defvar gnus-article-browse-html-temp-list nil
2742 "List of temporary files created by `gnus-article-browse-html-parts'.
2743 Internal variable.")
2744
2745 (defcustom gnus-article-browse-delete-temp 'ask
2746 "What to do with temporary files from `gnus-article-browse-html-parts'.
2747 If nil, don't delete temporary files. If it is t, delete them on
2748 exit from the summary buffer. If it is the symbol `file', query
2749 on each file, if it is `ask' ask once when exiting from the
2750 summary buffer."
2751 :group 'gnus-article
2752 :version "23.1" ;; No Gnus
2753 :type '(choice (const :tag "Don't delete" nil)
2754 (const :tag "Don't ask" t)
2755 (const :tag "Ask" ask)
2756 (const :tag "Ask for each file" file)))
2757
2758 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2759
2760 (defun gnus-article-browse-delete-temp-files (&optional how)
2761 "Delete temp-files created by `gnus-article-browse-html-parts'."
2762 (when (and gnus-article-browse-html-temp-list
2763 (progn
2764 (or how (setq how gnus-article-browse-delete-temp))
2765 (if (eq how 'ask)
2766 (let ((files (length gnus-article-browse-html-temp-list)))
2767 (or (gnus-y-or-n-p
2768 (if (= files 1)
2769 "Delete the temporary HTML file? "
2770 (format "Delete all %s temporary HTML files? "
2771 files)))
2772 (setq gnus-article-browse-html-temp-list nil)))
2773 how)))
2774 (dolist (file gnus-article-browse-html-temp-list)
2775 (cond ((file-directory-p file)
2776 (when (or (not (eq how 'file))
2777 (gnus-y-or-n-p
2778 (format
2779 "Delete temporary HTML file(s) in directory `%s'? "
2780 (file-name-as-directory file))))
2781 (gnus-delete-directory file)))
2782 ((file-exists-p file)
2783 (when (or (not (eq how 'file))
2784 (gnus-y-or-n-p
2785 (format "Delete temporary HTML file `%s'? " file)))
2786 (delete-file file)))))
2787 ;; Also remove file from the list when not deleted or if file doesn't
2788 ;; exist anymore.
2789 (setq gnus-article-browse-html-temp-list nil))
2790 gnus-article-browse-html-temp-list)
2791
2792 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2793 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2794 Return file name."
2795 (save-match-data
2796 (let (file type)
2797 (catch 'found
2798 (dolist (handle handles)
2799 (cond
2800 ((not (listp handle)))
2801 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2802 ;; may create.
2803 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2804 ((equal (mm-handle-media-supertype handle) "multipart")
2805 (when (setq file (gnus-article-browse-html-save-cid-content
2806 cid handle directory))
2807 (throw 'found file)))
2808 ((equal (concat "<" cid ">") (mm-handle-id handle))
2809 (setq file (or (mm-handle-filename handle)
2810 (concat
2811 (make-temp-name "cid")
2812 (car (rassoc (car (mm-handle-type handle))
2813 mailcap-mime-extensions)))))
2814 (mm-save-part-to-file handle (expand-file-name file directory))
2815 (throw 'found (concat (file-name-nondirectory
2816 (directory-file-name directory))
2817 "/" file)))))))))
2818
2819 (defun gnus-article-browse-html-parts (list &optional header)
2820 "View all \"text/html\" parts from LIST.
2821 Recurse into multiparts. The optional HEADER that should be a decoded
2822 message header will be added to the bodies of the \"text/html\" parts."
2823 ;; Internal function used by `gnus-article-browse-html-article'.
2824 (let (type file charset content cid-dir tmp-file showed)
2825 ;; Find and show the html-parts.
2826 (dolist (handle list)
2827 ;; If HTML, show it:
2828 (cond ((not (listp handle)))
2829 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2830 (and (equal (car type) "message/external-body")
2831 (or header
2832 (setq file (mm-handle-filename handle)))
2833 (or (mm-handle-cache handle)
2834 (condition-case code
2835 (progn (mm-extern-cache-contents handle) t)
2836 (error
2837 (gnus-message 3 "%s" (error-message-string code))
2838 (when (>= gnus-verbose 3) (sit-for 2))
2839 nil)))
2840 (progn
2841 (setq handle (mm-handle-cache handle)
2842 type (mm-handle-type handle))
2843 (equal (car type) "text/html"))))
2844 (setq charset (mail-content-type-get type 'charset)
2845 content (mm-get-part handle))
2846 (with-temp-buffer
2847 (if (eq charset 'gnus-decoded)
2848 (mm-enable-multibyte)
2849 (mm-disable-multibyte))
2850 (insert content)
2851 ;; remove <base>
2852 (let ((case-fold-search t))
2853 (goto-char (point-min))
2854 (when (and (search-forward "<head>" nil t)
2855 (progn
2856 (save-restriction
2857 (narrow-to-region
2858 (point)
2859 (or (search-forward "</head>" nil t) (point)))
2860 (goto-char (point-min)))
2861 (re-search-forward
2862 "[\t\n ]*<base[\t\n ]+[^>]+>[\t\n ]*" nil t)))
2863 (replace-match "\n")))
2864 ;; resolve cid contents
2865 (let ((case-fold-search t)
2866 cid-file)
2867 (goto-char (point-min))
2868 (while (re-search-forward "\
2869 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2870 nil t)
2871 (unless cid-dir
2872 (setq cid-dir (mm-make-temp-file "cid" t))
2873 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2874 (setq file nil
2875 content nil)
2876 (when (setq cid-file
2877 (gnus-article-browse-html-save-cid-content
2878 (match-string 2)
2879 (with-current-buffer gnus-article-buffer
2880 gnus-article-mime-handles)
2881 cid-dir))
2882 (replace-match cid-file nil nil nil 1))))
2883 (unless content (setq content (buffer-string))))
2884 (when (or charset header (not file))
2885 (setq tmp-file (mm-make-temp-file
2886 ;; Do we need to care for 8.3 filenames?
2887 "mm-" nil ".html")))
2888 ;; Add a meta html tag to specify charset and a header.
2889 (cond
2890 (header
2891 (let (title eheader body hcharset coding)
2892 (with-temp-buffer
2893 (mm-enable-multibyte)
2894 (setq case-fold-search t)
2895 (insert header "\n")
2896 (setq title (message-fetch-field "subject"))
2897 (goto-char (point-min))
2898 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2899 nil t)
2900 (replace-match (cond ((match-beginning 1) "&lt;")
2901 ((match-beginning 2) "&gt;")
2902 ((match-beginning 3) "&amp;")
2903 (t "<br>\n"))))
2904 (goto-char (point-min))
2905 (while (re-search-forward "^[\t ]+" nil t)
2906 (dotimes (i (prog1
2907 (current-column)
2908 (delete-region (match-beginning 0)
2909 (match-end 0))))
2910 (insert "&nbsp;")))
2911 (goto-char (point-min))
2912 (insert "<div align=\"left\">\n")
2913 (goto-char (point-max))
2914 (insert "</div>\n<hr>\n")
2915 ;; We have to examine charset one by one since
2916 ;; charset specified in parts might be different.
2917 (if (eq charset 'gnus-decoded)
2918 (setq charset 'utf-8
2919 eheader (mm-encode-coding-string (buffer-string)
2920 charset)
2921 title (when title
2922 (mm-encode-coding-string title charset))
2923 body (mm-encode-coding-string content charset))
2924 (setq hcharset (mm-find-mime-charset-region (point-min)
2925 (point-max)))
2926 (cond ((= (length hcharset) 1)
2927 (setq hcharset (car hcharset)
2928 coding (mm-charset-to-coding-system
2929 hcharset nil t)))
2930 ((> (length hcharset) 1)
2931 (setq hcharset 'utf-8
2932 coding hcharset)))
2933 (if coding
2934 (if charset
2935 (progn
2936 (setq body
2937 (mm-charset-to-coding-system charset
2938 nil t))
2939 (if (eq coding body)
2940 (setq eheader (mm-encode-coding-string
2941 (buffer-string) coding)
2942 title (when title
2943 (mm-encode-coding-string
2944 title coding))
2945 body content)
2946 (setq charset 'utf-8
2947 eheader (mm-encode-coding-string
2948 (buffer-string) charset)
2949 title (when title
2950 (mm-encode-coding-string
2951 title charset))
2952 body (mm-encode-coding-string
2953 (mm-decode-coding-string
2954 content body)
2955 charset))))
2956 (setq charset hcharset
2957 eheader (mm-encode-coding-string
2958 (buffer-string) coding)
2959 title (when title
2960 (mm-encode-coding-string
2961 title coding))
2962 body content))
2963 (setq eheader (mm-string-as-unibyte (buffer-string))
2964 body content)))
2965 (erase-buffer)
2966 (mm-disable-multibyte)
2967 (insert body)
2968 (when charset
2969 (mm-add-meta-html-tag handle charset t))
2970 (when title
2971 (goto-char (point-min))
2972 (unless (search-forward "<title>" nil t)
2973 (re-search-forward "<head>\\s-*" nil t)
2974 (insert "<title>" title "</title>\n")))
2975 (goto-char (point-min))
2976 (or (re-search-forward
2977 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2978 (re-search-forward
2979 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2980 (insert eheader)
2981 (mm-write-region (point-min) (point-max)
2982 tmp-file nil nil nil 'binary t))))
2983 (charset
2984 (mm-with-unibyte-buffer
2985 (insert (if (eq charset 'gnus-decoded)
2986 (mm-encode-coding-string content
2987 (setq charset 'utf-8))
2988 content))
2989 (if (or (mm-add-meta-html-tag handle charset)
2990 (not file))
2991 (mm-write-region (point-min) (point-max)
2992 tmp-file nil nil nil 'binary t)
2993 (setq tmp-file nil))))
2994 (tmp-file
2995 (mm-save-part-to-file handle tmp-file)))
2996 (when tmp-file
2997 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2998 (add-hook 'gnus-summary-prepare-exit-hook
2999 'gnus-article-browse-delete-temp-files)
3000 (add-hook 'gnus-exit-gnus-hook
3001 (lambda ()
3002 (gnus-article-browse-delete-temp-files t)))
3003 ;; FIXME: Warn if there's an <img> tag?
3004 (browse-url-of-file (or tmp-file (expand-file-name file)))
3005 (setq showed t))
3006 ;; If multipart, recurse
3007 ((equal (mm-handle-media-supertype handle) "multipart")
3008 (when (gnus-article-browse-html-parts handle header)
3009 (setq showed t)))
3010 ((equal (mm-handle-media-type handle) "message/rfc822")
3011 (mm-with-multibyte-buffer
3012 (mm-insert-part handle)
3013 (setq handle (mm-dissect-buffer t t))
3014 (when (and (bufferp (car handle))
3015 (stringp (car (mm-handle-type handle))))
3016 (setq handle (list handle)))
3017 (when header
3018 (article-decode-encoded-words)
3019 (let ((gnus-visible-headers
3020 (or (get 'gnus-visible-headers 'standard-value)
3021 gnus-visible-headers)))
3022 (article-hide-headers))
3023 (goto-char (point-min))
3024 (search-forward "\n\n" nil 'move)
3025 (skip-chars-backward "\t\n ")
3026 (setq header (buffer-substring (point-min) (point)))))
3027 (when (prog1
3028 (gnus-article-browse-html-parts handle header)
3029 (mm-destroy-parts handle))
3030 (setq showed t)))))
3031 showed))
3032
3033 (defun gnus-article-browse-html-article (&optional arg)
3034 "View \"text/html\" parts of the current article with a WWW browser.
3035 Inline images embedded in a message using the cid scheme, as they are
3036 generally considered to be safe, will be processed properly.
3037 The message header is added to the beginning of every html part unless
3038 the prefix argument ARG is given.
3039
3040 Warning: Spammers use links to images (using the http scheme) in HTML
3041 articles to verify whether you have read the message. As
3042 `gnus-article-browse-html-article' passes the HTML content to the
3043 browser without eliminating these \"web bugs\" you should only
3044 use it for mails from trusted senders.
3045
3046 If you always want to display HTML parts in the browser, set
3047 `mm-text-html-renderer' to nil.
3048
3049 This command creates temporary files to pass HTML contents including
3050 images if any to the browser, and deletes them when exiting the group
3051 \(if you want)."
3052 ;; Cf. `mm-w3m-safe-url-regexp'
3053 (interactive "P")
3054 (if arg
3055 (gnus-summary-show-article)
3056 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3057 gnus-visible-headers))
3058 ;; As we insert a <hr>, there's no need for the body boundary.
3059 (gnus-treat-body-boundary nil))
3060 (gnus-summary-show-article)))
3061 (with-current-buffer gnus-article-buffer
3062 (let ((header (unless arg
3063 (save-restriction
3064 (widen)
3065 (buffer-substring-no-properties
3066 (goto-char (point-min))
3067 (if (search-forward "\n\n" nil t)
3068 (match-beginning 0)
3069 (goto-char (point-max))
3070 (skip-chars-backward "\t\n ")
3071 (point))))))
3072 parts)
3073 (set-buffer gnus-original-article-buffer)
3074 (setq parts (mm-dissect-buffer t t))
3075 ;; If singlepart, enforce a list.
3076 (when (and (bufferp (car parts))
3077 (stringp (car (mm-handle-type parts))))
3078 (setq parts (list parts)))
3079 ;; Process the list
3080 (unless (gnus-article-browse-html-parts parts header)
3081 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3082 (mm-destroy-parts parts)
3083 (unless arg
3084 (gnus-summary-show-article)))))
3085
3086 (defun article-hide-list-identifiers ()
3087 "Remove list identifies from the Subject header.
3088 The `gnus-list-identifiers' variable specifies what to do."
3089 (interactive)
3090 (let ((inhibit-point-motion-hooks t)
3091 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3092 (inhibit-read-only t))
3093 (when regexp
3094 (save-excursion
3095 (save-restriction
3096 (article-narrow-to-head)
3097 (goto-char (point-min))
3098 (while (re-search-forward
3099 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3100 nil t)
3101 (delete-region (match-beginning 2) (match-end 0))
3102 (beginning-of-line))
3103 (when (re-search-forward
3104 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3105 (delete-region (match-beginning 1) (match-end 1))))))))
3106
3107 (defun article-hide-pem (&optional arg)
3108 "Toggle hiding of any PEM headers and signatures in the current article.
3109 If given a negative prefix, always show; if given a positive prefix,
3110 always hide."
3111 (interactive (gnus-article-hidden-arg))
3112 (unless (gnus-article-check-hidden-text 'pem arg)
3113 (save-excursion
3114 (let ((inhibit-read-only t) end)
3115 (goto-char (point-min))
3116 ;; Hide the horrendously ugly "header".
3117 (when (and (search-forward
3118 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3119 nil t)
3120 (setq end (1+ (match-beginning 0))))
3121 (gnus-add-wash-type 'pem)
3122 (gnus-article-hide-text-type
3123 end
3124 (if (search-forward "\n\n" nil t)
3125 (match-end 0)
3126 (point-max))
3127 'pem)
3128 ;; Hide the trailer as well
3129 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3130 nil t)
3131 (gnus-article-hide-text-type
3132 (match-beginning 0) (match-end 0) 'pem)))))))
3133
3134 (defun article-strip-banner ()
3135 "Strip the banners specified by the `banner' group parameter and by
3136 `gnus-article-address-banner-alist'."
3137 (interactive)
3138 (save-excursion
3139 (save-restriction
3140 (let ((inhibit-point-motion-hooks t))
3141 (when (gnus-parameter-banner gnus-newsgroup-name)
3142 (article-really-strip-banner
3143 (gnus-parameter-banner gnus-newsgroup-name)))
3144 (when gnus-article-address-banner-alist
3145 ;; Note that the From header is decoded here, so it is
3146 ;; required that the *-extract-address-components function
3147 ;; supports non-ASCII text.
3148 (let ((from (save-restriction
3149 (widen)
3150 (article-narrow-to-head)
3151 (mail-fetch-field "from"))))
3152 (when (and from
3153 (setq from
3154 (cadr (funcall gnus-extract-address-components
3155 from))))
3156 (catch 'found
3157 (dolist (pair gnus-article-address-banner-alist)
3158 (when (string-match (car pair) from)
3159 (throw 'found
3160 (article-really-strip-banner (cdr pair)))))))))))))
3161
3162 (defun article-really-strip-banner (banner)
3163 "Strip the banner specified by the argument."
3164 (save-excursion
3165 (save-restriction
3166 (let ((inhibit-point-motion-hooks t)
3167 (gnus-signature-limit nil)
3168 (inhibit-read-only t))
3169 (article-goto-body)
3170 (cond
3171 ((eq banner 'signature)
3172 (when (gnus-article-narrow-to-signature)
3173 (widen)
3174 (forward-line -1)
3175 (delete-region (point) (point-max))))
3176 ((symbolp banner)
3177 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3178 (while (re-search-forward banner nil t)
3179 (delete-region (match-beginning 0) (match-end 0)))))
3180 ((stringp banner)
3181 (while (re-search-forward banner nil t)
3182 (delete-region (match-beginning 0) (match-end 0)))))))))
3183
3184 (defun article-babel ()
3185 "Translate article using an online translation service."
3186 (interactive)
3187 (require 'babel)
3188 (gnus-with-article-buffer
3189 (when (article-goto-body)
3190 (let* ((start (point))
3191 (end (point-max))
3192 (orig (buffer-substring start end))
3193 (trans (babel-as-string orig)))
3194 (save-restriction
3195 (narrow-to-region start end)
3196 (delete-region start end)
3197 (insert trans))))))
3198
3199 (defun article-hide-signature (&optional arg)
3200 "Hide the signature in the current article.
3201 If given a negative prefix, always show; if given a positive prefix,
3202 always hide."
3203 (interactive (gnus-article-hidden-arg))
3204 (unless (gnus-article-check-hidden-text 'signature arg)
3205 (save-excursion
3206 (save-restriction
3207 (let ((inhibit-read-only t))
3208 (when (gnus-article-narrow-to-signature)
3209 (gnus-article-hide-text-type
3210 (point-min) (point-max) 'signature))))))
3211 (gnus-set-mode-line 'article))
3212
3213 (defun article-strip-headers-in-body ()
3214 "Strip offensive headers from bodies."
3215 (interactive)
3216 (save-excursion
3217 (article-goto-body)
3218 (let ((case-fold-search t))
3219 (when (looking-at "x-no-archive:")
3220 (gnus-delete-line)))))
3221
3222 (defun article-strip-leading-blank-lines ()
3223 "Remove all blank lines from the beginning of the article."
3224 (interactive)
3225 (save-excursion
3226 (let ((inhibit-point-motion-hooks t)
3227 (inhibit-read-only t))
3228 (when (article-goto-body)
3229 (while (and (not (eobp))
3230 (looking-at "[ \t]*$"))
3231 (gnus-delete-line))))))
3232
3233 (defun article-narrow-to-head ()
3234 "Narrow the buffer to the head of the message.
3235 Point is left at the beginning of the narrowed-to region."
3236 (narrow-to-region
3237 (goto-char (point-min))
3238 (cond
3239 ;; Absolutely no headers displayed.
3240 ((looking-at "\n")
3241 (point))
3242 ;; Normal headers.
3243 ((search-forward "\n\n" nil 1)
3244 (1- (point)))
3245 ;; Nothing but headers.
3246 (t
3247 (point-max))))
3248 (goto-char (point-min)))
3249
3250 (defun article-goto-body ()
3251 "Place point at the start of the body."
3252 (goto-char (point-min))
3253 (cond
3254 ;; This variable is only bound when dealing with separate
3255 ;; MIME body parts.
3256 (article-goto-body-goes-to-point-min-p
3257 t)
3258 ((search-forward "\n\n" nil t)
3259 t)
3260 (t
3261 (goto-char (point-max))
3262 nil)))
3263
3264 (defun article-strip-multiple-blank-lines ()
3265 "Replace consecutive blank lines with one empty line."
3266 (interactive)
3267 (save-excursion
3268 (let ((inhibit-point-motion-hooks t)
3269 (inhibit-read-only t))
3270 ;; First make all blank lines empty.
3271 (article-goto-body)
3272 (while (re-search-forward "^[ \t]+$" nil t)
3273 (unless (gnus-annotation-in-region-p
3274 (match-beginning 0) (match-end 0))
3275 (replace-match "" nil t)))
3276 ;; Then replace multiple empty lines with a single empty line.
3277 (article-goto-body)
3278 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3279 (unless (gnus-annotation-in-region-p
3280 (match-beginning 0) (match-end 0))
3281 (delete-region (match-beginning 1) (match-end 1)))))))
3282
3283 (defun article-strip-leading-space ()
3284 "Remove all white space from the beginning of the lines in the article."
3285 (interactive)
3286 (save-excursion
3287 (let ((inhibit-point-motion-hooks t)
3288 (inhibit-read-only t))
3289 (article-goto-body)
3290 (while (re-search-forward "^[ \t]+" nil t)
3291 (replace-match "" t t)))))
3292
3293 (defun article-strip-trailing-space ()
3294 "Remove all white space from the end of the lines in the article."
3295 (interactive)
3296 (save-excursion
3297 (let ((inhibit-point-motion-hooks t)
3298 (inhibit-read-only t))
3299 (article-goto-body)
3300 (while (re-search-forward "[ \t]+$" nil t)
3301 (replace-match "" t t)))))
3302
3303 (defun article-strip-blank-lines ()
3304 "Strip leading, trailing and multiple blank lines."
3305 (interactive)
3306 (article-strip-leading-blank-lines)
3307 (article-remove-trailing-blank-lines)
3308 (article-strip-multiple-blank-lines))
3309
3310 (defun article-strip-all-blank-lines ()
3311 "Strip all blank lines."
3312 (interactive)
3313 (save-excursion
3314 (let ((inhibit-point-motion-hooks t)
3315 (inhibit-read-only t))
3316 (article-goto-body)
3317 (while (re-search-forward "^[ \t]*\n" nil t)
3318 (replace-match "" t t)))))
3319
3320 (defun gnus-article-narrow-to-signature ()
3321 "Narrow to the signature; return t if a signature is found, else nil."
3322 (let ((inhibit-point-motion-hooks t))
3323 (when (gnus-article-search-signature)
3324 (forward-line 1)
3325 ;; Check whether we have some limits to what we consider
3326 ;; to be a signature.
3327 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3328 (list gnus-signature-limit)))
3329 limit limited)
3330 (while (setq limit (pop limits))
3331 (if (or (and (integerp limit)
3332 (< (- (point-max) (point)) limit))
3333 (and (floatp limit)
3334 (< (count-lines (point) (point-max)) limit))
3335 (and (functionp limit)
3336 (funcall limit))
3337 (and (stringp limit)
3338 (not (re-search-forward limit nil t))))
3339 () ; This limit did not succeed.
3340 (setq limited t
3341 limits nil)))
3342 (unless limited
3343 (narrow-to-region (point) (point-max))
3344 t)))))
3345
3346 (defun gnus-article-search-signature ()
3347 "Search the current buffer for the signature separator.
3348 Put point at the beginning of the signature separator."
3349 (let ((cur (point)))
3350 (goto-char (point-max))
3351 (if (if (stringp gnus-signature-separator)
3352 (re-search-backward gnus-signature-separator nil t)
3353 (let ((seps gnus-signature-separator))
3354 (while (and seps
3355 (not (re-search-backward (car seps) nil t)))
3356 (pop seps))
3357 seps))
3358 t
3359 (goto-char cur)
3360 nil)))
3361
3362 (defun gnus-article-hidden-arg ()
3363 "Return the current prefix arg as a number, or 0 if no prefix."
3364 (list (if current-prefix-arg
3365 (prefix-numeric-value current-prefix-arg)
3366 0)))
3367
3368 (defun gnus-article-check-hidden-text (type arg)
3369 "Return nil if hiding is necessary.
3370 Arg can be nil or a number. nil and positive means hide, negative
3371 means show, 0 means toggle."
3372 (save-excursion
3373 (save-restriction
3374 (let ((hide (gnus-article-hidden-text-p type)))
3375 (cond
3376 ((or (null arg)
3377 (> arg 0))
3378 nil)
3379 ((< arg 0)
3380 (gnus-article-show-hidden-text type)
3381 t)
3382 (t
3383 (if (eq hide 'hidden)
3384 (progn
3385 (gnus-article-show-hidden-text type)
3386 t)
3387 nil)))))))
3388
3389 (defun gnus-article-hidden-text-p (type)
3390 "Say whether the current buffer contains hidden text of type TYPE."
3391 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3392 (while (and pos
3393 (not (get-text-property pos 'invisible))
3394 (not (get-text-property pos 'dummy-invisible)))
3395 (setq pos
3396 (text-property-any (1+ pos) (point-max) 'article-type type)))
3397 (if pos
3398 'hidden
3399 nil)))
3400
3401 (defun gnus-article-show-hidden-text (type &optional dummy)
3402 "Show all hidden text of type TYPE.
3403 Originally it is hide instead of DUMMY."
3404 (let ((inhibit-read-only t)
3405 (inhibit-point-motion-hooks t))
3406 (gnus-remove-text-properties-when
3407 'article-type type
3408 (point-min) (point-max)
3409 (cons 'article-type (cons type
3410 gnus-hidden-properties)))
3411 (gnus-delete-wash-type type)))
3412
3413 (defconst article-time-units
3414 `((year . ,(* 365.25 24 60 60))
3415 (week . ,(* 7 24 60 60))
3416 (day . ,(* 24 60 60))
3417 (hour . ,(* 60 60))
3418 (minute . 60)
3419 (second . 1))
3420 "Mapping from time units to seconds.")
3421
3422 (defun gnus-article-forward-header ()
3423 "Move point to the start of the next header.
3424 If the current header is a continuation header, this can be several
3425 lines forward."
3426 (let ((ended nil))
3427 (while (not ended)
3428 (forward-line 1)
3429 (if (looking-at "[ \t]+[^ \t]")
3430 (forward-line 1)
3431 (setq ended t)))))
3432
3433 (defun article-treat-date ()
3434 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3435 (with-current-buffer gnus-summary-buffer
3436 gnus-article-date-headers)
3437 gnus-article-date-headers)
3438 t))
3439
3440 (defun article-date-ut (&optional type highlight date-position)
3441 "Convert DATE date to TYPE in the current article.
3442 The default type is `ut'. See `gnus-article-date-headers' for
3443 possible values."
3444 (interactive (list 'ut t))
3445 (let* ((case-fold-search t)
3446 (inhibit-read-only t)
3447 (inhibit-point-motion-hooks t)
3448 (first t)
3449 (visible-date (mail-fetch-field "Date"))
3450 pos date bface eface)
3451 (save-excursion
3452 (if date-position
3453 (progn
3454 (goto-char date-position)
3455 (setq date (get-text-property (point) 'original-date))
3456 (when (looking-at "[^:]+:[\t ]*")
3457 (setq bface (get-text-property (match-beginning 0) 'face)
3458 eface (get-text-property (match-end 0) 'face)))
3459 (delete-region (point)
3460 (progn
3461 (gnus-article-forward-header)
3462 (point)))
3463 (article-transform-date date type bface eface))
3464 (save-restriction
3465 (widen)
3466 (goto-char (point-min))
3467 (while (or (get-text-property (setq pos (point)) 'original-date)
3468 (and (setq pos (next-single-property-change
3469 (point) 'original-date))
3470 (goto-char pos)))
3471 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3472 (1+ (match-beginning 0))
3473 (point-max)))
3474 (while (setq pos (text-property-not-all pos (point-max)
3475 'gnus-date-type nil))
3476 (setq date (get-text-property pos 'original-date))
3477 (goto-char pos)
3478 (when (looking-at "[^:]+:[\t ]*")
3479 (setq bface (get-text-property (match-beginning 0) 'face)
3480 eface (get-text-property (match-end 0) 'face)))
3481 (delete-region pos (or (text-property-any pos (point-max)
3482 'gnus-date-type nil)
3483 (point-max))))
3484 (unless date ;; the 1st time
3485 (goto-char (point-min))
3486 (while (re-search-forward "^Date:[\t ]*" nil t)
3487 (setq date (get-text-property (match-beginning 0)
3488 'original-date)
3489 bface (get-text-property (match-beginning 0) 'face)
3490 eface (get-text-property (match-end 0) 'face))
3491 (delete-region (point-at-bol) (progn
3492 (gnus-article-forward-header)
3493 (point)))))
3494 (when (and (not date)
3495 visible-date)
3496 (setq date visible-date))
3497 (when date
3498 (article-transform-date date type bface eface))
3499 (goto-char (point-max))
3500 (widen)))))))
3501
3502 (defun article-transform-date (date type bface eface)
3503 (dolist (this-type (cond
3504 ((null type)
3505 (list 'ut))
3506 ((atom type)
3507 (list type))
3508 (t
3509 type)))
3510 (goto-char
3511 (prog1
3512 (point)
3513 (add-text-properties
3514 (point)
3515 (progn
3516 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3517 (point))
3518 (list 'original-date date 'gnus-date-type this-type))))
3519 ;; Do highlighting.
3520 (when (looking-at
3521 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3522 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3523 (when (match-beginning 2)
3524 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3525 (while (and (zerop (forward-line 1))
3526 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3527 (when (match-beginning 1)
3528 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3529
3530 (defun article-make-date-line (date type)
3531 "Return a DATE line of TYPE."
3532 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3533 combined-lapsed))
3534 (error "Unknown conversion type: %s" type))
3535 (condition-case ()
3536 (let ((time (ignore-errors (date-to-time date))))
3537 (cond
3538 ;; Convert to the local timezone.
3539 ((eq type 'local)
3540 (concat "Date: " (message-make-date time)))
3541 ;; Convert to Universal Time.
3542 ((eq type 'ut)
3543 (concat "Date: "
3544 (substring
3545 (message-make-date
3546 (let* ((e (parse-time-string date))
3547 (tm (apply 'encode-time e))
3548 (ms (car tm))
3549 (ls (- (cadr tm) (car (current-time-zone time)))))
3550 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3551 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3552 (t (list ms ls)))))
3553 0 -5)
3554 "UT"))
3555 ;; Get the original date from the article.
3556 ((eq type 'original)
3557 (concat "Date: " (if (string-match "\n+$" date)
3558 (substring date 0 (match-beginning 0))
3559 date)))
3560 ;; Let the user define the format.
3561 ((eq type 'user-defined)
3562 (let ((format (or (condition-case nil
3563 (with-current-buffer gnus-summary-buffer
3564 gnus-article-time-format)
3565 (error nil))
3566 gnus-article-time-format)))
3567 (if (functionp format)
3568 (funcall format time)
3569 (concat "Date: " (format-time-string format time)))))
3570 ;; ISO 8601.
3571 ((eq type 'iso8601)
3572 (let ((tz (car (current-time-zone time))))
3573 (concat
3574 "Date: "
3575 (format-time-string "%Y%m%dT%H%M%S" time)
3576 (format "%s%02d%02d"
3577 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3578 (/ (% (abs tz) 3600) 60)))))
3579 ;; Do a lapsed format.
3580 ((eq type 'lapsed)
3581 (concat "Date: " (article-lapsed-string time)))
3582 ;; A combined date/lapsed format.
3583 ((eq type 'combined-lapsed)
3584 (let ((date-string (article-make-date-line date 'original))
3585 (segments 3)
3586 lapsed-string)
3587 (while (and
3588 time
3589 (setq lapsed-string
3590 (concat " (" (article-lapsed-string time segments) ")"))
3591 (> (+ (length date-string)
3592 (length lapsed-string))
3593 (+ fill-column 6))
3594 (> segments 0))
3595 (setq segments (1- segments)))
3596 (if (> segments 0)
3597 (concat date-string lapsed-string)
3598 date-string)))
3599 ;; Display the date in proper English
3600 ((eq type 'english)
3601 (let ((dtime (decode-time time)))
3602 (concat
3603 "Date: the "
3604 (number-to-string (nth 3 dtime))
3605 (let ((digit (% (nth 3 dtime) 10)))
3606 (cond
3607 ((memq (nth 3 dtime) '(11 12 13)) "th")
3608 ((= digit 1) "st")
3609 ((= digit 2) "nd")
3610 ((= digit 3) "rd")
3611 (t "th")))
3612 " of "
3613 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3614 " "
3615 (number-to-string (nth 5 dtime))
3616 " at "
3617 (format "%02d" (nth 2 dtime))
3618 ":"
3619 (format "%02d" (nth 1 dtime)))))))
3620 (foo
3621 (format "Date: %s (from Gnus)" date))))
3622
3623 (defun article-lapsed-string (time &optional max-segments)
3624 ;; If the date is seriously mangled, the timezone functions are
3625 ;; liable to bug out, so we ignore all errors.
3626 (let* ((now (current-time))
3627 (real-time (subtract-time now time))
3628 (real-sec (and real-time
3629 (+ (* (float (car real-time)) 65536)
3630 (cadr real-time))))
3631 (sec (and real-time (abs real-sec)))
3632 (segments 0)
3633 num prev)
3634 (unless max-segments
3635 (setq max-segments (length article-time-units)))
3636 (cond
3637 ((null real-time)
3638 "Unknown")
3639 ((zerop sec)
3640 "Now")
3641 (t
3642 (concat
3643 ;; This is a bit convoluted, but basically we go
3644 ;; through the time units for years, weeks, etc,
3645 ;; and divide things to see whether that results
3646 ;; in positive answers.
3647 (mapconcat
3648 (lambda (unit)
3649 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3650 (>= segments max-segments))
3651 ;; The (remaining) seconds are too few to
3652 ;; be divided into this time unit.
3653 ""
3654 ;; It's big enough, so we output it.
3655 (setq sec (- sec (* num (cdr unit))))
3656 (prog1
3657 (concat (if prev ", " "") (int-to-string
3658 (floor num))
3659 " " (symbol-name (car unit))
3660 (if (> num 1) "s" ""))
3661 (setq prev t
3662 segments (1+ segments)))))
3663 article-time-units "")
3664 ;; If dates are odd, then it might appear like the
3665 ;; article was sent in the future.
3666 (if (> real-sec 0)
3667 " ago"
3668 " in the future"))))))
3669
3670 (defun article-date-local (&optional highlight)
3671 "Convert the current article date to the local timezone."
3672 (interactive (list t))
3673 (article-date-ut 'local highlight))
3674
3675 (defun article-date-english (&optional highlight)
3676 "Convert the current article date to something that is proper English."
3677 (interactive (list t))
3678 (article-date-ut 'english highlight))
3679
3680 (defun article-date-original (&optional highlight)
3681 "Convert the current article date to what it was originally.
3682 This is only useful if you have used some other date conversion
3683 function and want to see what the date was before converting."
3684 (interactive (list t))
3685 (article-date-ut 'original highlight))
3686
3687 (defun article-date-lapsed (&optional highlight)
3688 "Convert the current article date to time lapsed since it was sent."
3689 (interactive (list t))
3690 (article-date-ut 'lapsed highlight))
3691
3692 (defun article-date-combined-lapsed (&optional highlight)
3693 "Convert the current article date to time lapsed since it was sent."
3694 (interactive (list t))
3695 (article-date-ut 'combined-lapsed highlight))
3696
3697 (defun article-update-date-lapsed ()
3698 "Function to be run from a timer to update the lapsed time line."
3699 (save-match-data
3700 (let ((buffer (current-buffer)))
3701 (ignore-errors
3702 (walk-windows
3703 (lambda (w)
3704 (set-buffer (window-buffer w))
3705 (when (derived-mode-p 'gnus-article-mode)
3706 (let ((old-line (count-lines (point-min) (point)))
3707 (old-column (- (point) (line-beginning-position)))
3708 (window-start (window-start w))
3709 (pos (point-min))
3710 type next end)
3711 (while (setq pos (text-property-not-all pos (point-max)
3712 'gnus-date-type nil))
3713 (setq next (or (next-single-property-change pos
3714 'gnus-date-type)
3715 (point-max)))
3716 (setq type (get-text-property pos 'gnus-date-type))
3717 (when (memq type '(lapsed combined-lapsed user-defined))
3718 (article-date-ut type t pos)
3719 (setq end (or (next-single-property-change pos
3720 'gnus-date-type)
3721 (point-max)))
3722 (when window-start
3723 (if (/= window-start next)
3724 (setq window-start nil)
3725 (set-window-start w end)))
3726 (setq next end))
3727 (setq pos next))
3728 (goto-char (point-min))
3729 (when (> old-column 0)
3730 (setq old-line (1- old-line)))
3731 (forward-line old-line)
3732 (end-of-line)
3733 (when (> (current-column) old-column)
3734 (beginning-of-line)
3735 (forward-char old-column)))))
3736 nil 'visible))
3737 (set-buffer buffer))))
3738
3739 (defun gnus-start-date-timer (&optional n)
3740 "Start a timer to update the Date headers in the article buffers.
3741 The numerical prefix says how frequently (in seconds) the function
3742 is to run."
3743 (interactive "p")
3744 (unless n
3745 (setq n 1))
3746 (gnus-stop-date-timer)
3747 (setq article-lapsed-timer
3748 (run-at-time 1 n 'article-update-date-lapsed)))
3749
3750 (defun gnus-stop-date-timer ()
3751 "Stop the Date timer."
3752 (interactive)
3753 (when article-lapsed-timer
3754 (nnheader-cancel-timer article-lapsed-timer)
3755 (setq article-lapsed-timer nil)))
3756
3757 (defun article-date-user (&optional highlight)
3758 "Convert the current article date to the user-defined format.
3759 This format is defined by the `gnus-article-time-format' variable."
3760 (interactive (list t))
3761 (article-date-ut 'user highlight))
3762
3763 (defun article-date-iso8601 (&optional highlight)
3764 "Convert the current article date to ISO8601."
3765 (interactive (list t))
3766 (article-date-ut 'iso8601 highlight))
3767
3768 (defmacro gnus-article-save-original-date (&rest forms)
3769 "Save the original date as a text property and evaluate FORMS."
3770 `(let* ((case-fold-search t)
3771 (start (progn
3772 (goto-char (point-min))
3773 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3774 (not (bolp)))
3775 (match-end 0))))
3776 (date (when (and start
3777 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3778 nil t))
3779 (buffer-substring-no-properties start
3780 (match-beginning 0)))))
3781 (goto-char (point-max))
3782 (skip-chars-backward "\n")
3783 (put-text-property (point-min) (point) 'original-date date)
3784 ,@forms
3785 (goto-char (point-max))
3786 (skip-chars-backward "\n")
3787 (put-text-property (point-min) (point) 'original-date date)))
3788
3789 ;; (defun article-show-all ()
3790 ;; "Show all hidden text in the article buffer."
3791 ;; (interactive)
3792 ;; (save-excursion
3793 ;; (let ((inhibit-read-only t))
3794 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3795
3796 (defun article-remove-leading-whitespace ()
3797 "Remove excessive whitespace from all headers."
3798 (interactive)
3799 (save-excursion
3800 (save-restriction
3801 (let ((inhibit-read-only t))
3802 (article-narrow-to-head)
3803 (goto-char (point-min))
3804 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3805 (delete-region (match-beginning 1) (match-end 1)))))))
3806
3807 (defun article-emphasize (&optional arg)
3808 "Emphasize text according to `gnus-emphasis-alist'."
3809 (interactive (gnus-article-hidden-arg))
3810 (unless (gnus-article-check-hidden-text 'emphasis arg)
3811 (save-excursion
3812 (let ((alist (or
3813 (condition-case nil
3814 (with-current-buffer gnus-summary-buffer
3815 gnus-article-emphasis-alist)
3816 (error))
3817 gnus-emphasis-alist))
3818 (inhibit-read-only t)
3819 (props (append '(article-type emphasis)
3820 gnus-hidden-properties))
3821 regexp elem beg invisible visible face)
3822 (article-goto-body)
3823 (setq beg (point))
3824 (while (setq elem (pop alist))
3825 (goto-char beg)
3826 (setq regexp (car elem)
3827 invisible (nth 1 elem)
3828 visible (nth 2 elem)
3829 face (nth 3 elem))
3830 (while (re-search-forward regexp nil t)
3831 (when (and (match-beginning visible) (match-beginning invisible))
3832 (gnus-article-hide-text
3833 (match-beginning invisible) (match-end invisible) props)
3834 (gnus-article-unhide-text-type
3835 (match-beginning visible) (match-end visible) 'emphasis)
3836 (gnus-put-overlay-excluding-newlines
3837 (match-beginning visible) (match-end visible) 'face face)
3838 (gnus-add-wash-type 'emphasis)
3839 (goto-char (match-end invisible)))))))))
3840
3841 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3842 "Setup newsgroup emphasis alist."
3843 (unless gnus-article-emphasis-alist
3844 (let ((name (and gnus-newsgroup-name
3845 (gnus-group-real-name gnus-newsgroup-name))))
3846 (make-local-variable 'gnus-article-emphasis-alist)
3847 (setq gnus-article-emphasis-alist
3848 (nconc
3849 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3850 (while (setq elem (pop alist))
3851 (when (and name (string-match (car elem) name))
3852 (setq alist nil
3853 highlight (copy-sequence (cdr elem)))))
3854 highlight)
3855 (copy-sequence highlight-words)
3856 (if gnus-newsgroup-name
3857 (copy-sequence (gnus-group-find-parameter
3858 gnus-newsgroup-name 'highlight-words t)))
3859 gnus-emphasis-alist)))))
3860
3861 (defvar gnus-summary-article-menu)
3862 (defvar gnus-summary-post-menu)
3863
3864 ;;; Saving functions.
3865
3866 (defun gnus-article-save (save-buffer file &optional num)
3867 "Save the currently selected article."
3868 (when (or (get gnus-default-article-saver :headers)
3869 (not gnus-save-all-headers))
3870 ;; Remove headers according to `gnus-saved-headers' or the value
3871 ;; of the `:headers' property that the saver function might have.
3872 (let ((gnus-visible-headers
3873 (or (symbol-value (get gnus-default-article-saver :headers))
3874 gnus-saved-headers gnus-visible-headers))
3875 ;; Ignore group parameter. See `article-hide-headers'.
3876 (gnus-summary-buffer nil))
3877 (with-current-buffer save-buffer
3878 (article-hide-headers 1 t))))
3879 (save-window-excursion
3880 (if (not gnus-default-article-saver)
3881 (error "No default saver is defined")
3882 ;; !!! Magic! The saving functions all save
3883 ;; `gnus-save-article-buffer' (or so they think), but we
3884 ;; bind that variable to our save-buffer.
3885 (set-buffer gnus-article-buffer)
3886 (let* ((gnus-save-article-buffer save-buffer)
3887 (filename
3888 (cond
3889 ((not gnus-prompt-before-saving) 'default)
3890 ((eq gnus-prompt-before-saving 'always) nil)
3891 (t file)))
3892 (gnus-number-of-articles-to-be-saved
3893 (when (eq gnus-prompt-before-saving t)
3894 num))) ; Magic
3895 (set-buffer gnus-article-current-summary)
3896 (funcall gnus-default-article-saver filename)))))
3897
3898 (defun gnus-read-save-file-name (prompt &optional filename
3899 function group headers variable
3900 dir-var)
3901 (let ((default-name
3902 (funcall function group headers (symbol-value variable)))
3903 result)
3904 (setq result
3905 (expand-file-name
3906 (cond
3907 ((eq filename 'default)
3908 default-name)
3909 ((eq filename t)
3910 default-name)
3911 (filename filename)
3912 (t
3913 (when (symbol-value dir-var)
3914 (setq default-name (expand-file-name
3915 (file-name-nondirectory default-name)
3916 (symbol-value dir-var))))
3917 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3918 (prompt
3919 (format prompt
3920 (if (and gnus-number-of-articles-to-be-saved
3921 (> gnus-number-of-articles-to-be-saved 1))
3922 (format "these %d articles"
3923 gnus-number-of-articles-to-be-saved)
3924 "this article")))
3925 (file
3926 ;; Let the split methods have their say.
3927 (cond
3928 ;; No split name was found.
3929 ((null split-name)
3930 (read-file-name
3931 (concat prompt " (default "
3932 (file-name-nondirectory default-name) "): ")
3933 (file-name-directory default-name)
3934 default-name))
3935 ;; A single group name is returned.
3936 ((stringp split-name)
3937 (setq default-name
3938 (funcall function split-name headers
3939 (symbol-value variable)))
3940 (read-file-name
3941 (concat prompt " (default "
3942 (file-name-nondirectory default-name) "): ")
3943 (file-name-directory default-name)
3944 default-name))
3945 ;; A single split name was found
3946 ((= 1 (length split-name))
3947 (let* ((name (expand-file-name
3948 (car split-name)
3949 gnus-article-save-directory))
3950 (dir (cond ((file-directory-p name)
3951 (file-name-as-directory name))
3952 ((file-exists-p name) name)
3953 (t gnus-article-save-directory))))
3954 (read-file-name
3955 (concat prompt " (default " name "): ")
3956 dir name)))
3957 ;; A list of splits was found.
3958 (t
3959 (setq split-name (nreverse split-name))
3960 (let (result)
3961 (let ((file-name-history
3962 (nconc split-name file-name-history)))
3963 (setq result
3964 (expand-file-name
3965 (read-file-name
3966 (concat prompt " (`M-p' for defaults): ")
3967 gnus-article-save-directory
3968 (car split-name))
3969 gnus-article-save-directory)))
3970 (car (push result file-name-history)))))))
3971 ;; Create the directory.
3972 (gnus-make-directory (file-name-directory file))
3973 ;; If we have read a directory, we append the default file name.
3974 (when (file-directory-p file)
3975 (setq file (expand-file-name (file-name-nondirectory
3976 default-name)
3977 (file-name-as-directory file))))
3978 ;; Possibly translate some characters.
3979 (nnheader-translate-file-chars file))))))
3980 (gnus-make-directory (file-name-directory result))
3981 (when variable
3982 (set variable result))
3983 (when dir-var
3984 (set dir-var (file-name-directory result)))
3985 result))
3986
3987 (defun gnus-article-archive-name (group)
3988 "Return the first instance of an \"Archive-name\" in the current buffer."
3989 (let ((case-fold-search t))
3990 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3991 (nnheader-concat gnus-article-save-directory
3992 (match-string 1)))))
3993
3994 (defun gnus-article-nndoc-name (group)
3995 "If GROUP is an nndoc group, return the name of the parent group."
3996 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3997 (gnus-group-get-parameter group 'save-article-group)))
3998
3999 (defun gnus-summary-save-in-rmail (&optional filename)
4000 "Append this article to Rmail file.
4001 Optional argument FILENAME specifies file name.
4002 Directory to save to is default to `gnus-article-save-directory'."
4003 (setq filename (gnus-read-save-file-name
4004 "Save %s in rmail file" filename
4005 gnus-rmail-save-name gnus-newsgroup-name
4006 gnus-current-headers 'gnus-newsgroup-last-rmail))
4007 (with-current-buffer gnus-save-article-buffer
4008 (save-excursion
4009 (save-restriction
4010 (widen)
4011 ;; Note that unlike gnus-summary-save-in-mail, there is no
4012 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4013 ;; not use Babyl.
4014 (gnus-output-to-rmail filename))))
4015 filename)
4016
4017 (defun gnus-summary-save-in-mail (&optional filename)
4018 "Append this article to Unix mail file.
4019 Optional argument FILENAME specifies file name.
4020 Directory to save to is default to `gnus-article-save-directory'."
4021 (setq filename (gnus-read-save-file-name
4022 "Save %s in Unix mail file" filename
4023 gnus-mail-save-name gnus-newsgroup-name
4024 gnus-current-headers 'gnus-newsgroup-last-mail))
4025 (with-current-buffer gnus-save-article-buffer
4026 (save-excursion
4027 (save-restriction
4028 (widen)
4029 (if (and (file-readable-p filename)
4030 (file-regular-p filename)
4031 (mail-file-babyl-p filename))
4032 (gnus-output-to-rmail filename)
4033 (gnus-output-to-mail filename)))))
4034 filename)
4035
4036 (put 'gnus-summary-save-in-file :decode t)
4037 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4038 (defun gnus-summary-save-in-file (&optional filename overwrite)
4039 "Append this article to file.
4040 Optional argument FILENAME specifies file name.
4041 Directory to save to is default to `gnus-article-save-directory'."
4042 (setq filename (gnus-read-save-file-name
4043 "Save %s in file" filename
4044 gnus-file-save-name gnus-newsgroup-name
4045 gnus-current-headers 'gnus-newsgroup-last-file))
4046 (with-current-buffer gnus-save-article-buffer
4047 (save-excursion
4048 (save-restriction
4049 (widen)
4050 (when (and overwrite
4051 (file-exists-p filename))
4052 (delete-file filename))
4053 (gnus-output-to-file filename))))
4054 filename)
4055
4056 (put 'gnus-summary-write-to-file :decode t)
4057 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4058 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4059 (defun gnus-summary-write-to-file (&optional filename)
4060 "Write this article to a file, overwriting it if the file exists.
4061 Optional argument FILENAME specifies file name.
4062 The directory to save in defaults to `gnus-article-save-directory'."
4063 (setq filename (gnus-read-save-file-name
4064 "Save %s in file" filename
4065 gnus-file-save-name gnus-newsgroup-name
4066 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4067 (gnus-summary-save-in-file filename t))
4068
4069 (put 'gnus-summary-save-body-in-file :decode t)
4070 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4071 "Append this article body to a file.
4072 Optional argument FILENAME specifies file name.
4073 The directory to save in defaults to `gnus-article-save-directory'."
4074 (setq filename (gnus-read-save-file-name
4075 "Save %s body in file" filename
4076 gnus-file-save-name gnus-newsgroup-name
4077 gnus-current-headers 'gnus-newsgroup-last-file))
4078 (with-current-buffer gnus-save-article-buffer
4079 (save-excursion
4080 (save-restriction
4081 (widen)
4082 (when (article-goto-body)
4083 (narrow-to-region (point) (point-max)))
4084 (when (and overwrite
4085 (file-exists-p filename))
4086 (delete-file filename))
4087 (gnus-output-to-file filename))))
4088 filename)
4089
4090 (put 'gnus-summary-write-body-to-file :decode t)
4091 (put 'gnus-summary-write-body-to-file
4092 :function 'gnus-summary-save-body-in-file)
4093 (defun gnus-summary-write-body-to-file (&optional filename)
4094 "Write this article body to a file, overwriting it if the file exists.
4095 Optional argument FILENAME specifies file name.
4096 The directory to save in defaults to `gnus-article-save-directory'."
4097 (setq filename (gnus-read-save-file-name
4098 "Save %s body in file" filename
4099 gnus-file-save-name gnus-newsgroup-name
4100 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4101 (gnus-summary-save-body-in-file filename t))
4102
4103 (put 'gnus-summary-save-in-pipe :decode t)
4104 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4105 (defun gnus-summary-save-in-pipe (&optional command raw)
4106 "Pipe this article to subprocess COMMAND.
4107 Valid values for COMMAND include:
4108 a string
4109 The executable command name and possibly arguments.
4110 nil
4111 You will be prompted for the command in the minibuffer.
4112 the symbol `default'
4113 It will be replaced with the command which the variable
4114 `gnus-summary-pipe-output-default-command' holds or the command
4115 last used for saving.
4116 Non-nil value for RAW overrides `:decode' and `:headers' properties
4117 and the raw article including all headers will be piped."
4118 (let ((article (gnus-summary-article-number))
4119 (decode (unless raw
4120 (get 'gnus-summary-save-in-pipe :decode)))
4121 save-buffer default)
4122 (if article
4123 (if (vectorp (gnus-summary-article-header article))
4124 (save-current-buffer
4125 (gnus-summary-select-article decode decode nil article)
4126 (insert-buffer-substring
4127 (prog1
4128 (if decode
4129 gnus-article-buffer
4130 gnus-original-article-buffer)
4131 (setq save-buffer
4132 (nnheader-set-temp-buffer " *Gnus Save*"))))
4133 ;; Remove unwanted headers.
4134 (when (and (not raw)
4135 (or (get 'gnus-summary-save-in-pipe :headers)
4136 (not gnus-save-all-headers)))
4137 (let ((gnus-visible-headers
4138 (or (symbol-value (get 'gnus-summary-save-in-pipe
4139 :headers))
4140 gnus-saved-headers gnus-visible-headers))
4141 (gnus-summary-buffer nil))
4142 (article-hide-headers 1 t))))
4143 (error "%d is not a real article" article))
4144 (error "No article to pipe"))
4145 (setq default (or gnus-summary-pipe-output-default-command
4146 gnus-last-shell-command))
4147 (unless (stringp command)
4148 (setq command
4149 (if (and (eq command 'default) default)
4150 default
4151 (gnus-read-shell-command "Shell command on this article: "
4152 default))))
4153 (when (string-equal command "")
4154 (if default
4155 (setq command default)
4156 (error "A command is required")))
4157 (with-current-buffer save-buffer
4158 (save-restriction
4159 (widen)
4160 (shell-command-on-region (point-min) (point-max) command nil)))
4161 (gnus-kill-buffer save-buffer))
4162 (setq gnus-summary-pipe-output-default-command command))
4163
4164 (defun gnus-summary-pipe-to-muttprint (&optional command)
4165 "Pipe this article to muttprint."
4166 (unless (stringp command)
4167 (setq command (read-string
4168 "Print using command: " gnus-summary-muttprint-program
4169 nil gnus-summary-muttprint-program)))
4170 (let ((gnus-summary-pipe-output-default-command
4171 gnus-summary-pipe-output-default-command))
4172 (gnus-summary-save-in-pipe command))
4173 (setq gnus-summary-muttprint-program command))
4174
4175 ;;; Article file names when saving.
4176
4177 (defun gnus-capitalize-newsgroup (newsgroup)
4178 "Capitalize NEWSGROUP name."
4179 (when (not (zerop (length newsgroup)))
4180 (concat (char-to-string (upcase (aref newsgroup 0)))
4181 (substring newsgroup 1))))
4182
4183 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4184 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4185 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4186 Otherwise, it is like ~/News/news/group/num."
4187 (let ((default
4188 (expand-file-name
4189 (concat (if (gnus-use-long-file-name 'not-save)
4190 (gnus-capitalize-newsgroup newsgroup)
4191 (gnus-newsgroup-directory-form newsgroup))
4192 "/" (int-to-string (mail-header-number headers)))
4193 gnus-article-save-directory)))
4194 (if (and last-file
4195 (string-equal (file-name-directory default)
4196 (file-name-directory last-file))
4197 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4198 default
4199 (or last-file default))))
4200
4201 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4202 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4203 If variable `gnus-use-long-file-name' is non-nil, it is
4204 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4205 (let ((default
4206 (expand-file-name
4207 (concat (if (gnus-use-long-file-name 'not-save)
4208 newsgroup
4209 (gnus-newsgroup-directory-form newsgroup))
4210 "/" (int-to-string (mail-header-number headers)))
4211 gnus-article-save-directory)))
4212 (if (and last-file
4213 (string-equal (file-name-directory default)
4214 (file-name-directory last-file))
4215 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4216 default
4217 (or last-file default))))
4218
4219 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4220 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4221 If variable `gnus-use-long-file-name' is non-nil, it is
4222 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4223 (or last-file
4224 (expand-file-name
4225 (if (gnus-use-long-file-name 'not-save)
4226 newsgroup
4227 (file-relative-name
4228 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4229 default-directory))
4230 gnus-article-save-directory)))
4231
4232 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4233 "Generate file name from sender."
4234 (let ((from (mail-header-from headers)))
4235 (expand-file-name
4236 (if (and from (string-match "\\([^ <]+\\)@" from))
4237 (match-string 1 from)
4238 "nobody")
4239 gnus-article-save-directory)))
4240
4241 (defun article-verify-x-pgp-sig ()
4242 "Verify X-PGP-Sig."
4243 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4244 (interactive)
4245 (if (gnus-buffer-live-p gnus-original-article-buffer)
4246 (let ((sig (with-current-buffer gnus-original-article-buffer
4247 (gnus-fetch-field "X-PGP-Sig")))
4248 items info headers)
4249 (when (and sig
4250 mml2015-use
4251 (mml2015-clear-verify-function))
4252 (with-temp-buffer
4253 (insert-buffer-substring gnus-original-article-buffer)
4254 (setq items (split-string sig))
4255 (message-narrow-to-head)
4256 (let ((inhibit-point-motion-hooks t)
4257 (case-fold-search t))
4258 ;; Don't verify multiple headers.
4259 (setq headers (mapconcat (lambda (header)
4260 (concat header ": "
4261 (mail-fetch-field header)
4262 "\n"))
4263 (split-string (nth 1 items) ",") "")))
4264 (delete-region (point-min) (point-max))
4265 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4266 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4267 (insert headers)
4268 (widen)
4269 (forward-line)
4270 (while (not (eobp))
4271 (if (looking-at "^-")
4272 (insert "- "))
4273 (forward-line))
4274 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4275 (insert "Version: " (car items) "\n\n")
4276 (insert (mapconcat 'identity (cddr items) "\n"))
4277 (insert "\n-----END PGP SIGNATURE-----\n")
4278 (let ((mm-security-handle (list (format "multipart/signed"))))
4279 (mml2015-clean-buffer)
4280 (let ((coding-system-for-write (or gnus-newsgroup-charset
4281 'iso-8859-1)))
4282 (funcall (mml2015-clear-verify-function)))
4283 (setq info
4284 (or (mm-handle-multipart-ctl-parameter
4285 mm-security-handle 'gnus-details)
4286 (mm-handle-multipart-ctl-parameter
4287 mm-security-handle 'gnus-info)))))
4288 (when info
4289 (let ((inhibit-read-only t) bface eface)
4290 (save-restriction
4291 (message-narrow-to-head)
4292 (goto-char (point-max))
4293 (forward-line -1)
4294 (setq bface (get-text-property (point-at-bol) 'face)
4295 eface (get-text-property (1- (point-at-eol)) 'face))
4296 (message-remove-header "X-Gnus-PGP-Verify")
4297 (if (re-search-forward "^X-PGP-Sig:" nil t)
4298 (forward-line)
4299 (goto-char (point-max)))
4300 (narrow-to-region (point) (point))
4301 (insert "X-Gnus-PGP-Verify: " info "\n")
4302 (goto-char (point-min))
4303 (forward-line)
4304 (while (not (eobp))
4305 (if (not (looking-at "^[ \t]"))
4306 (insert " "))
4307 (forward-line))
4308 ;; Do highlighting.
4309 (goto-char (point-min))
4310 (when (looking-at "\\([^:]+\\): *")
4311 (put-text-property (match-beginning 1) (1+ (match-end 1))
4312 'face bface)
4313 (put-text-property (match-end 0) (point-max)
4314 'face eface)))))))))
4315
4316 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4317
4318 (defun article-verify-cancel-lock ()
4319 "Verify Cancel-Lock header."
4320 (interactive)
4321 (if (gnus-buffer-live-p gnus-original-article-buffer)
4322 (canlock-verify gnus-original-article-buffer)))
4323
4324 (eval-and-compile
4325 (mapc
4326 (lambda (func)
4327 (let (afunc gfunc)
4328 (if (consp func)
4329 (setq afunc (car func)
4330 gfunc (cdr func))
4331 (setq afunc func
4332 gfunc (intern (format "gnus-%s" func))))
4333 (defalias gfunc
4334 (when (fboundp afunc)
4335 `(lambda (&optional interactive &rest args)
4336 ,(documentation afunc t)
4337 (interactive (list t))
4338 (with-current-buffer gnus-article-buffer
4339 (if interactive
4340 (call-interactively ',afunc)
4341 (apply ',afunc args))))))))
4342 '(article-hide-headers
4343 article-verify-x-pgp-sig
4344 article-verify-cancel-lock
4345 article-hide-boring-headers
4346 article-treat-overstrike
4347 article-treat-ansi-sequences
4348 article-fill-long-lines
4349 article-capitalize-sentences
4350 article-remove-cr
4351 article-remove-leading-whitespace
4352 article-display-x-face
4353 article-display-face
4354 article-de-quoted-unreadable
4355 article-de-base64-unreadable
4356 article-decode-HZ
4357 article-wash-html
4358 article-unsplit-urls
4359 article-hide-list-identifiers
4360 article-strip-banner
4361 article-babel
4362 article-hide-pem
4363 article-hide-signature
4364 article-strip-headers-in-body
4365 article-remove-trailing-blank-lines
4366 article-strip-leading-blank-lines
4367 article-strip-multiple-blank-lines
4368 article-strip-leading-space
4369 article-strip-trailing-space
4370 article-strip-blank-lines
4371 article-strip-all-blank-lines
4372 article-date-local
4373 article-date-english
4374 article-date-iso8601
4375 article-date-original
4376 article-treat-date
4377 article-date-ut
4378 article-decode-mime-words
4379 article-decode-charset
4380 article-decode-encoded-words
4381 article-date-user
4382 article-date-lapsed
4383 article-date-combined-lapsed
4384 article-emphasize
4385 article-treat-dumbquotes
4386 article-treat-non-ascii
4387 article-normalize-headers
4388 ;;(article-show-all . gnus-article-show-all-headers)
4389 )))
4390 \f
4391 ;;;
4392 ;;; Gnus article mode
4393 ;;;
4394
4395 (put 'gnus-article-mode 'mode-class 'special)
4396
4397 (set-keymap-parent gnus-article-mode-map widget-keymap)
4398
4399 (gnus-define-keys gnus-article-mode-map
4400 " " gnus-article-goto-next-page
4401 [?\S-\ ] gnus-article-goto-prev-page
4402 "\177" gnus-article-goto-prev-page
4403 [delete] gnus-article-goto-prev-page
4404 "\C-c^" gnus-article-refer-article
4405 "h" gnus-article-show-summary
4406 "s" gnus-article-show-summary
4407 "\C-c\C-m" gnus-article-mail
4408 "?" gnus-article-describe-briefly
4409 "<" beginning-of-buffer
4410 ">" end-of-buffer
4411 "\C-c\C-i" gnus-info-find-node
4412 "\C-c\C-b" gnus-bug
4413 "R" gnus-article-reply-with-original
4414 "F" gnus-article-followup-with-original
4415 "\C-hk" gnus-article-describe-key
4416 "\C-hc" gnus-article-describe-key-briefly
4417 "\C-hb" gnus-article-describe-bindings
4418
4419 "e" gnus-article-read-summary-keys
4420 "\C-d" gnus-article-read-summary-keys
4421 "\M-*" gnus-article-read-summary-keys
4422 "\M-#" gnus-article-read-summary-keys
4423 "\M-^" gnus-article-read-summary-keys
4424 "\M-g" gnus-article-read-summary-keys)
4425
4426 (substitute-key-definition
4427 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4428
4429 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4430 "W" gnus-article-wide-reply-with-original)
4431 (if (featurep 'xemacs)
4432 (set-keymap-default-binding gnus-article-send-map
4433 'gnus-article-read-summary-send-keys)
4434 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4435
4436 (defun gnus-article-make-menu-bar ()
4437 (unless (boundp 'gnus-article-commands-menu)
4438 (gnus-summary-make-menu-bar))
4439 (unless (boundp 'gnus-article-article-menu)
4440 (easy-menu-define
4441 gnus-article-article-menu gnus-article-mode-map ""
4442 '("Article"
4443 ["Scroll forwards" gnus-article-goto-next-page t]
4444 ["Scroll backwards" gnus-article-goto-prev-page t]
4445 ["Show summary" gnus-article-show-summary t]
4446 ["Fetch Message-ID at point" gnus-article-refer-article t]
4447 ["Mail to address at point" gnus-article-mail t]
4448 ["Send a bug report" gnus-bug t]))
4449
4450 (easy-menu-define
4451 gnus-article-treatment-menu gnus-article-mode-map ""
4452 ;; Fixme: this should use :active (and maybe :visible).
4453 '("Treatment"
4454 ["Hide headers" gnus-article-hide-headers t]
4455 ["Hide signature" gnus-article-hide-signature t]
4456 ["Hide citation" gnus-article-hide-citation t]
4457 ["Treat overstrike" gnus-article-treat-overstrike t]
4458 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4459 ["Remove carriage return" gnus-article-remove-cr t]
4460 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4461 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4462 ["Remove base64" gnus-article-de-base64-unreadable t]
4463 ["Treat html" gnus-article-wash-html t]
4464 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4465 ["Decode HZ" gnus-article-decode-HZ t]))
4466
4467 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4468
4469 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4470
4471 (gnus-run-hooks 'gnus-article-menu-hook)))
4472
4473 (defvar bookmark-make-record-function)
4474 (defvar shr-put-image-function)
4475
4476 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4477 "Major mode for displaying an article.
4478
4479 All normal editing commands are switched off.
4480
4481 The following commands are available in addition to all summary mode
4482 commands:
4483 \\<gnus-article-mode-map>
4484 \\[gnus-article-next-page]\t Scroll the article one page forwards
4485 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4486 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4487 \\[gnus-article-show-summary]\t Display the summary buffer
4488 \\[gnus-article-mail]\t Send a reply to the address near point
4489 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4490 \\[gnus-info-find-node]\t Go to the Gnus info node"
4491 (gnus-simplify-mode-line)
4492 (make-local-variable 'minor-mode-alist)
4493 (when (gnus-visual-p 'article-menu 'menu)
4494 (gnus-article-make-menu-bar)
4495 (when gnus-summary-tool-bar-map
4496 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4497 (gnus-update-format-specifications nil 'article-mode)
4498 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4499 (set (make-local-variable 'gnus-page-broken) nil)
4500 (make-local-variable 'gnus-article-current-summary)
4501 (make-local-variable 'gnus-article-mime-handles)
4502 (make-local-variable 'gnus-article-decoded-p)
4503 (make-local-variable 'gnus-article-mime-handle-alist)
4504 (make-local-variable 'gnus-article-wash-types)
4505 (make-local-variable 'gnus-article-image-alist)
4506 (make-local-variable 'gnus-article-charset)
4507 (make-local-variable 'gnus-article-ignored-charsets)
4508 (set (make-local-variable 'bookmark-make-record-function)
4509 'gnus-summary-bookmark-make-record)
4510 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4511 ;; face.
4512 (set (make-local-variable 'nobreak-char-display) nil)
4513 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4514 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4515 (setq cursor-in-non-selected-windows nil)
4516 (gnus-set-default-directory)
4517 (buffer-disable-undo)
4518 (setq buffer-read-only t
4519 show-trailing-whitespace nil)
4520 (mm-enable-multibyte))
4521
4522 (defun gnus-article-setup-buffer ()
4523 "Initialize the article buffer."
4524 (let* ((name (if gnus-single-article-buffer "*Article*"
4525 (concat "*Article "
4526 (gnus-group-decoded-name gnus-newsgroup-name)
4527 "*")))
4528 (original
4529 (progn (string-match "\\*Article" name)
4530 (concat " *Original Article"
4531 (substring name (match-end 0))))))
4532 (setq gnus-article-buffer name)
4533 (setq gnus-original-article-buffer original)
4534 (setq gnus-article-mime-handle-alist nil)
4535 (with-current-buffer gnus-summary-buffer
4536 ;; This might be a variable local to the summary buffer.
4537 (unless gnus-single-article-buffer
4538 (setq gnus-article-buffer name)
4539 (setq gnus-original-article-buffer original)
4540 (gnus-set-global-variables)))
4541 (gnus-article-setup-highlight-words)
4542 ;; Init original article buffer.
4543 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4544 (mm-enable-multibyte)
4545 (setq major-mode 'gnus-original-article-mode)
4546 (make-local-variable 'gnus-original-article))
4547 (if (and (get-buffer name)
4548 (with-current-buffer name
4549 (if gnus-article-edit-mode
4550 (if (y-or-n-p "Article mode edit in progress; discard? ")
4551 (progn
4552 (set-buffer-modified-p nil)
4553 (gnus-kill-buffer name)
4554 (message "")
4555 nil)
4556 (error "Action aborted"))
4557 t)))
4558 (let ((summary gnus-summary-buffer))
4559 (with-current-buffer name
4560 (set (make-local-variable 'gnus-article-edit-mode) nil)
4561 (gnus-article-stop-animations)
4562 (when gnus-article-mime-handles
4563 (mm-destroy-parts gnus-article-mime-handles)
4564 (setq gnus-article-mime-handles nil))
4565 ;; Set it to nil in article-buffer!
4566 (setq gnus-article-mime-handle-alist nil)
4567 (buffer-disable-undo)
4568 (setq buffer-read-only t)
4569 (unless (derived-mode-p 'gnus-article-mode)
4570 (gnus-article-mode))
4571 (set (make-local-variable 'gnus-summary-buffer) summary)
4572 (setq truncate-lines gnus-article-truncate-lines)
4573 (current-buffer)))
4574 (let ((summary gnus-summary-buffer))
4575 (with-current-buffer (gnus-get-buffer-create name)
4576 (gnus-article-mode)
4577 (setq truncate-lines gnus-article-truncate-lines)
4578 (set (make-local-variable 'gnus-summary-buffer) summary)
4579 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4580 (when article-lapsed-timer
4581 (gnus-stop-date-timer))
4582 (when gnus-article-update-date-headers
4583 (gnus-start-date-timer gnus-article-update-date-headers))
4584 (current-buffer))))))
4585
4586 (defun gnus-article-stop-animations ()
4587 (dolist (timer (and (boundp 'timer-list)
4588 timer-list))
4589 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4590 (cancel-timer timer))))
4591
4592 (defun gnus-stop-downloads ()
4593 (when (boundp 'url-queue)
4594 (set (intern "url-queue" obarray) nil)))
4595
4596 ;; Set article window start at LINE, where LINE is the number of lines
4597 ;; from the head of the article.
4598 (defun gnus-article-set-window-start (&optional line)
4599 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4600 (when article-window
4601 (set-window-start
4602 article-window
4603 (with-current-buffer gnus-article-buffer
4604 (goto-char (point-min))
4605 (if (not line)
4606 (point-min)
4607 (gnus-message 6 "Moved to bookmark")
4608 (search-forward "\n\n" nil t)
4609 (forward-line line)
4610 (point)))))))
4611
4612 (defun gnus-article-prepare (article &optional all-headers header)
4613 "Prepare ARTICLE in article mode buffer.
4614 ARTICLE should either be an article number or a Message-ID.
4615 If ARTICLE is an id, HEADER should be the article headers.
4616 If ALL-HEADERS is non-nil, no headers are hidden."
4617 (save-excursion
4618 ;; Make sure we start in a summary buffer.
4619 (unless (derived-mode-p 'gnus-summary-mode)
4620 (set-buffer gnus-summary-buffer))
4621 (setq gnus-summary-buffer (current-buffer))
4622 (let* ((gnus-article (if header (mail-header-number header) article))
4623 (summary-buffer (current-buffer))
4624 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4625 (group gnus-newsgroup-name)
4626 result)
4627 (save-excursion
4628 (gnus-article-setup-buffer)
4629 (set-buffer gnus-article-buffer)
4630 ;; Deactivate active regions.
4631 (when (and (boundp 'transient-mark-mode)
4632 transient-mark-mode)
4633 (setq mark-active nil))
4634 (if (not (setq result (let ((inhibit-read-only t))
4635 (gnus-request-article-this-buffer
4636 article group))))
4637 ;; There is no such article.
4638 (save-excursion
4639 (when (and (numberp article)
4640 (not (memq article gnus-newsgroup-sparse)))
4641 (setq gnus-article-current
4642 (cons gnus-newsgroup-name article))
4643 (set-buffer gnus-summary-buffer)
4644 (setq gnus-current-article article)
4645 (if (and (memq article gnus-newsgroup-undownloaded)
4646 (not (gnus-online (gnus-find-method-for-group
4647 gnus-newsgroup-name))))
4648 (progn
4649 (gnus-summary-set-agent-mark article)
4650 (message "Message marked for downloading"))
4651 (gnus-summary-mark-article article gnus-canceled-mark)
4652 (unless (memq article gnus-newsgroup-sparse)
4653 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4654 (if (or (eq result 'pseudo)
4655 (eq result 'nneething))
4656 (progn
4657 (with-current-buffer summary-buffer
4658 (push article gnus-newsgroup-history)
4659 (setq gnus-last-article gnus-current-article
4660 gnus-current-article 0
4661 gnus-current-headers nil
4662 gnus-article-current nil)
4663 (if (eq result 'nneething)
4664 (gnus-configure-windows 'summary)
4665 (gnus-configure-windows 'article))
4666 (gnus-set-global-variables))
4667 (let ((gnus-article-mime-handle-alist-1
4668 gnus-article-mime-handle-alist))
4669 (gnus-set-mode-line 'article)))
4670 ;; The result from the `request' was an actual article -
4671 ;; or at least some text that is now displayed in the
4672 ;; article buffer.
4673 (when (and (numberp article)
4674 (not (eq article gnus-current-article)))
4675 ;; Seems like a new article has been selected.
4676 ;; `gnus-current-article' must be an article number.
4677 (with-current-buffer summary-buffer
4678 (push article gnus-newsgroup-history)
4679 (setq gnus-last-article gnus-current-article
4680 gnus-current-article article
4681 gnus-current-headers
4682 (gnus-summary-article-header gnus-current-article)
4683 gnus-article-current
4684 (cons gnus-newsgroup-name gnus-current-article))
4685 (unless (vectorp gnus-current-headers)
4686 (setq gnus-current-headers nil))
4687 (gnus-summary-goto-subject gnus-current-article)
4688 (when (gnus-summary-show-thread)
4689 ;; If the summary buffer really was folded, the
4690 ;; previous goto may not actually have gone to
4691 ;; the right article, but the thread root instead.
4692 ;; So we go again.
4693 (gnus-summary-goto-subject gnus-current-article))
4694 (gnus-run-hooks 'gnus-mark-article-hook)
4695 (gnus-set-mode-line 'summary)
4696 (when (gnus-visual-p 'article-highlight 'highlight)
4697 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4698 ;; Set the global newsgroup variables here.
4699 (gnus-set-global-variables)
4700 (setq gnus-have-all-headers
4701 (or all-headers gnus-show-all-headers))))
4702 (save-excursion
4703 (gnus-configure-windows 'article))
4704 (when (or (numberp article)
4705 (stringp article))
4706 (gnus-article-prepare-display)
4707 ;; Do page break.
4708 (goto-char (point-min))
4709 (when gnus-break-pages
4710 (gnus-narrow-to-page)))
4711 (let ((gnus-article-mime-handle-alist-1
4712 gnus-article-mime-handle-alist))
4713 (gnus-set-mode-line 'article))
4714 (article-goto-body)
4715 (unless (bobp)
4716 (forward-line -1))
4717 (set-window-point (get-buffer-window (current-buffer)) (point))
4718 (gnus-configure-windows 'article)
4719 (gnus-run-hooks 'gnus-article-prepare-hook)
4720 t))))))
4721
4722 ;;;###autoload
4723 (defun gnus-article-prepare-display ()
4724 "Make the current buffer look like a nice article."
4725 ;; Hooks for getting information from the article.
4726 ;; This hook must be called before being narrowed.
4727 (let ((gnus-article-buffer (current-buffer))
4728 buffer-read-only
4729 (inhibit-read-only t))
4730 (unless (derived-mode-p 'gnus-article-mode)
4731 (gnus-article-mode))
4732 (setq buffer-read-only nil
4733 gnus-article-wash-types nil
4734 gnus-article-image-alist nil)
4735 (gnus-run-hooks 'gnus-tmp-internal-hook)
4736 (when gnus-display-mime-function
4737 (funcall gnus-display-mime-function))
4738 ;; Add attachment buttons to the header.
4739 (when gnus-mime-display-attachment-buttons-in-header
4740 (gnus-mime-buttonize-attachments-in-header))))
4741
4742 ;;;
4743 ;;; Gnus Sticky Article Mode
4744 ;;;
4745
4746 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4747 "Mode for sticky articles."
4748 ;; Release bindings that won't work.
4749 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4750 gnus-sticky-article-mode-map)
4751 (substitute-key-definition 'gnus-article-refer-article 'undefined
4752 gnus-sticky-article-mode-map)
4753 (dolist (k '("e" "h" "s" "F" "R"))
4754 (define-key gnus-sticky-article-mode-map k nil))
4755 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4756 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4757 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4758 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4759
4760 (defun gnus-sticky-article (arg)
4761 "Make the current article sticky.
4762 If a prefix ARG is given, ask for a name for this sticky article buffer."
4763 (interactive "P")
4764 (gnus-summary-show-thread)
4765 (gnus-summary-select-article nil nil 'pseudo)
4766 (let (new-art-buf-name)
4767 (gnus-eval-in-buffer-window gnus-article-buffer
4768 (setq new-art-buf-name
4769 (concat
4770 "*Sticky Article: "
4771 (if arg
4772 (read-from-minibuffer "Sticky article buffer name: ")
4773 (gnus-with-article-headers
4774 (gnus-article-goto-header "subject")
4775 (setq new-art-buf-name
4776 (buffer-substring-no-properties
4777 (line-beginning-position) (line-end-position)))
4778 (goto-char (point-min))
4779 (gnus-article-goto-header "from")
4780 (setq new-art-buf-name
4781 (concat
4782 new-art-buf-name ", "
4783 (buffer-substring-no-properties
4784 (line-beginning-position) (line-end-position))))
4785 (goto-char (point-min))
4786 (gnus-article-goto-header "date")
4787 (setq new-art-buf-name
4788 (concat
4789 new-art-buf-name ", "
4790 (buffer-substring-no-properties
4791 (line-beginning-position) (line-end-position))))))
4792 "*"))
4793 (if (and (gnus-buffer-live-p new-art-buf-name)
4794 (with-current-buffer new-art-buf-name
4795 (derived-mode-p 'gnus-sticky-article-mode)))
4796 (switch-to-buffer new-art-buf-name)
4797 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4798 (gnus-sticky-article-mode))
4799 (setq gnus-article-buffer new-art-buf-name))
4800 (gnus-summary-recenter)
4801 (gnus-summary-position-point))
4802
4803 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4804 "Kill the given sticky article BUFFER.
4805 If none is given, assume the current buffer and kill it if it has
4806 `gnus-sticky-article-mode'."
4807 (interactive)
4808 (unless buffer
4809 (setq buffer (current-buffer)))
4810 (with-current-buffer buffer
4811 (when (derived-mode-p 'gnus-sticky-article-mode)
4812 (gnus-kill-buffer buffer))))
4813
4814 (defun gnus-kill-sticky-article-buffers (arg)
4815 "Kill all sticky article buffers.
4816 If a prefix ARG is given, ask for confirmation."
4817 (interactive "P")
4818 (dolist (buf (gnus-buffers))
4819 (with-current-buffer buf
4820 (when (derived-mode-p 'gnus-sticky-article-mode)
4821 (if (not arg)
4822 (gnus-kill-buffer buf)
4823 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4824 (gnus-kill-buffer buf)))))))
4825
4826 ;;;
4827 ;;; Gnus MIME viewing functions
4828 ;;;
4829
4830 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4831 "Format of the MIME buttons.
4832
4833 Valid specifiers include:
4834 %t The MIME type
4835 %T MIME type, along with additional info
4836 %n The `name' parameter
4837 %d The description, if any
4838 %l The length of the encoded part
4839 %p The part identifier number
4840 %e Dots if the part isn't displayed
4841
4842 General format specifiers can also be used. See Info node
4843 `(gnus)Formatting Variables'.")
4844
4845 (defvar gnus-mime-button-line-format-alist
4846 '((?t gnus-tmp-type ?s)
4847 (?T gnus-tmp-type-long ?s)
4848 (?n gnus-tmp-name ?s)
4849 (?d gnus-tmp-description ?s)
4850 (?p gnus-tmp-id ?s)
4851 (?l gnus-tmp-length ?d)
4852 (?e gnus-tmp-dots ?s)))
4853
4854 (defvar gnus-mime-button-commands
4855 '((gnus-article-press-button "\r" "Toggle Display")
4856 (gnus-mime-view-part "v" "View Interactively...")
4857 (gnus-mime-view-part-as-type "t" "View As Type...")
4858 (gnus-mime-view-part-as-charset "C" "View As charset...")
4859 (gnus-mime-save-part "o" "Save...")
4860 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4861 (gnus-mime-replace-part "r" "Replace part")
4862 (gnus-mime-delete-part "d" "Delete part")
4863 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4864 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4865 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4866 (gnus-mime-view-part-externally "e" "View Externally")
4867 (gnus-mime-print-part "p" "Print")
4868 (gnus-mime-pipe-part "|" "Pipe To Command...")
4869 (gnus-mime-action-on-part "." "Take action on the part...")))
4870
4871 (defun gnus-article-mime-part-status ()
4872 (if gnus-article-mime-handle-alist-1
4873 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4874 " (1 part)"
4875 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4876 ""))
4877
4878 (defvar gnus-mime-button-map
4879 (let ((map (make-sparse-keymap)))
4880 (define-key map gnus-mouse-2 'gnus-article-push-button)
4881 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4882 (dolist (c gnus-mime-button-commands)
4883 (define-key map (cadr c) (car c)))
4884 map))
4885
4886 (easy-menu-define
4887 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4888 `("MIME Part"
4889 ,@(mapcar (lambda (c)
4890 (vector (caddr c) (car c) :active t))
4891 gnus-mime-button-commands)))
4892
4893 (defvar gnus-url-button-commands
4894 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4895
4896 (defvar gnus-url-button-map
4897 (let ((map (make-sparse-keymap)))
4898 (dolist (c gnus-url-button-commands)
4899 (define-key map (cadr c) (car c)))
4900 map))
4901
4902 (easy-menu-define
4903 gnus-url-button-menu gnus-url-button-map "URL button menu."
4904 `("Url Button"
4905 ,@(mapcar (lambda (c)
4906 (vector (caddr c) (car c) :active t))
4907 gnus-url-button-commands)))
4908
4909 (defmacro gnus-bind-safe-url-regexp (&rest body)
4910 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4911 `(let ((mm-w3m-safe-url-regexp
4912 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4913 (gnus-buffer-live-p
4914 gnus-article-current-summary))
4915 (with-current-buffer gnus-article-current-summary
4916 gnus-newsgroup-name)
4917 gnus-newsgroup-name)))
4918 (if (cond ((not group)
4919 ;; Maybe we're in a mml-preview buffer
4920 ;; and no group is selected.
4921 t)
4922 ((stringp gnus-safe-html-newsgroups)
4923 (string-match gnus-safe-html-newsgroups group))
4924 ((consp gnus-safe-html-newsgroups)
4925 (member group gnus-safe-html-newsgroups)))
4926 nil
4927 mm-w3m-safe-url-regexp))))
4928 ,@body))
4929
4930 (defun gnus-mime-button-menu (event prefix)
4931 "Construct a context-sensitive menu of MIME commands."
4932 (interactive "e\nP")
4933 (save-window-excursion
4934 (let ((pos (event-start event)))
4935 (select-window (posn-window pos))
4936 (goto-char (posn-point pos))
4937 (gnus-article-check-buffer)
4938 (popup-menu gnus-mime-button-menu nil prefix))))
4939
4940 (defun gnus-mime-view-all-parts (&optional handles)
4941 "View all the MIME parts."
4942 (interactive)
4943 (with-current-buffer gnus-article-buffer
4944 (let ((handles (or handles gnus-article-mime-handles))
4945 (mail-parse-charset gnus-newsgroup-charset)
4946 (mail-parse-ignored-charsets
4947 (with-current-buffer gnus-summary-buffer
4948 gnus-newsgroup-ignored-charsets)))
4949 (when handles
4950 (mm-remove-parts handles)
4951 (goto-char (point-min))
4952 (or (search-forward "\n\n") (goto-char (point-max)))
4953 (let ((inhibit-read-only t))
4954 (delete-region (point) (point-max))
4955 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4956
4957 (defun gnus-article-jump-to-part (n)
4958 "Jump to MIME part N."
4959 (interactive "P")
4960 (let ((parts (with-current-buffer gnus-article-buffer
4961 (length gnus-article-mime-handle-alist))))
4962 (when (zerop parts)
4963 (error "No such part"))
4964 (pop-to-buffer gnus-article-buffer)
4965 (or n
4966 (setq n (if (= parts 1)
4967 1
4968 (read-number (format "Jump to part (1..%s): " parts)))))
4969 (unless (and (integerp n) (<= n parts) (>= n 1))
4970 (setq n
4971 (progn
4972 (gnus-message 7 "Invalid part `%s', using %s instead."
4973 n parts)
4974 parts)))
4975 (gnus-message 9 "Jumping to part %s." n)
4976 (cond ((>= gnus-auto-select-part 1)
4977 (while (and (<= n parts)
4978 (not (gnus-article-goto-part n)))
4979 (setq n (1+ n))))
4980 ((< gnus-auto-select-part 0)
4981 (while (and (>= n 1)
4982 (not (gnus-article-goto-part n)))
4983 (setq n (1- n))))
4984 (t
4985 (gnus-article-goto-part n)))))
4986
4987 (defvar gnus-mime-buttonized-part-id nil
4988 "ID of a mime part that should be buttonized.
4989 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4990
4991 (eval-when-compile
4992 (defsubst gnus-article-edit-part (handles &optional current-id)
4993 "Edit an article in order to delete a mime part.
4994 This function is exclusively used by `gnus-mime-save-part-and-strip'
4995 and `gnus-mime-delete-part', and not provided at run-time normally."
4996 (gnus-article-edit-article
4997 `(lambda ()
4998 (buffer-disable-undo)
4999 (let ((mail-parse-charset (or gnus-article-charset
5000 ',gnus-newsgroup-charset))
5001 (mail-parse-ignored-charsets
5002 (or gnus-article-ignored-charsets
5003 ',gnus-newsgroup-ignored-charsets))
5004 (mbl mml-buffer-list))
5005 (setq mml-buffer-list nil)
5006 ;; A new text must be inserted before deleting existing ones
5007 ;; at the end so as not to move existing markers of which
5008 ;; the insertion type is t.
5009 (delete-region
5010 (point-min)
5011 (prog1
5012 (goto-char (point-max))
5013 (insert-buffer-substring gnus-original-article-buffer)))
5014 (mime-to-mml ',handles)
5015 (setq gnus-article-mime-handles nil)
5016 (let ((mbl1 mml-buffer-list))
5017 (setq mml-buffer-list mbl)
5018 (set (make-local-variable 'mml-buffer-list) mbl1))
5019 (gnus-make-local-hook 'kill-buffer-hook)
5020 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5021 `(lambda (no-highlight)
5022 (let ((mail-parse-charset (or gnus-article-charset
5023 ',gnus-newsgroup-charset))
5024 (message-options message-options)
5025 (message-options-set-recipient)
5026 (mail-parse-ignored-charsets
5027 (or gnus-article-ignored-charsets
5028 ',gnus-newsgroup-ignored-charsets)))
5029 (mml-to-mime)
5030 (mml-destroy-buffers)
5031 (remove-hook 'kill-buffer-hook
5032 'mml-destroy-buffers t)
5033 (kill-local-variable 'mml-buffer-list))
5034 (gnus-summary-edit-article-done
5035 ,(or (mail-header-references gnus-current-headers) "")
5036 ,(gnus-group-read-only-p)
5037 ,gnus-summary-buffer no-highlight))
5038 t)
5039 ;; Force buttonizing this part.
5040 (let ((gnus-mime-buttonized-part-id current-id))
5041 (gnus-article-edit-done))
5042 (gnus-configure-windows 'article)
5043 (when (and current-id (integerp gnus-auto-select-part))
5044 (gnus-article-jump-to-part
5045 (min (max (+ current-id gnus-auto-select-part) 1)
5046 (with-current-buffer gnus-article-buffer
5047 (length gnus-article-mime-handle-alist)))))))
5048
5049 (defun gnus-mime-replace-part (file)
5050 "Replace MIME part under point with an external body."
5051 ;; Useful if file has already been saved to disk
5052 (interactive
5053 (list
5054 (read-file-name "Replace MIME part with file: "
5055 (or mm-default-directory default-directory)
5056 nil nil)))
5057 (gnus-mime-save-part-and-strip file))
5058
5059 (defun gnus-mime-save-part-and-strip (&optional file)
5060 "Save the MIME part under point then replace it with an external body.
5061 If FILE is given, use it for the external part."
5062 (interactive)
5063 (gnus-article-check-buffer)
5064 (when (gnus-group-read-only-p)
5065 (error "The current group does not support deleting of parts"))
5066 (when (mm-complicated-handles gnus-article-mime-handles)
5067 (error "\
5068 The current article has a complicated MIME structure, giving up..."))
5069 (let* ((data (get-text-property (point) 'gnus-data))
5070 (id (get-text-property (point) 'gnus-part))
5071 param
5072 (handles gnus-article-mime-handles))
5073 (unless file
5074 (setq file
5075 (and data (mm-save-part data "Delete MIME part and save to: "))))
5076 (when file
5077 (with-current-buffer (mm-handle-buffer data)
5078 (erase-buffer)
5079 (insert "Content-Type: " (mm-handle-media-type data))
5080 (mml-insert-parameter-string (cdr (mm-handle-type data))
5081 '(charset))
5082 ;; Add a filename for the sake of saving the part again.
5083 (mml-insert-parameter
5084 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5085 (insert "\n")
5086 (insert "Content-ID: " (message-make-message-id) "\n")
5087 (insert "Content-Transfer-Encoding: binary\n")
5088 (insert "\n"))
5089 (setcdr data
5090 (cdr (mm-make-handle nil
5091 `("message/external-body"
5092 (access-type . "LOCAL-FILE")
5093 (name . ,file)))))
5094 ;; (set-buffer gnus-summary-buffer)
5095 (gnus-article-edit-part handles id))))
5096
5097 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5098 ;; parts...>') but with stripping would be nice.
5099
5100 (defun gnus-mime-delete-part ()
5101 "Delete the MIME part under point.
5102 Replace it with some information about the removed part."
5103 (interactive)
5104 (gnus-article-check-buffer)
5105 (when (gnus-group-read-only-p)
5106 (error "The current group does not support deleting of parts"))
5107 (when (mm-complicated-handles gnus-article-mime-handles)
5108 (error "\
5109 The current article has a complicated MIME structure, giving up..."))
5110 (when (or gnus-expert-user
5111 (gnus-yes-or-no-p "\
5112 Deleting parts may malfunction or destroy the article; continue? "))
5113 (let* ((data (get-text-property (point) 'gnus-data))
5114 (id (get-text-property (point) 'gnus-part))
5115 (handles gnus-article-mime-handles)
5116 (description
5117 (let ((desc (mm-handle-description data)))
5118 (when desc
5119 (mail-decode-encoded-word-string desc))))
5120 (filename (or (mm-handle-filename data) "(none)"))
5121 (type (mm-handle-media-type data)))
5122 (unless data
5123 (error "No MIME part under point"))
5124 (with-current-buffer (mm-handle-buffer data)
5125 (let ((bsize (buffer-size)))
5126 (erase-buffer)
5127 (insert
5128 (concat
5129 ",----\n"
5130 "| The following attachment has been deleted:\n"
5131 "|\n"
5132 "| Type: " type "\n"
5133 "| Filename: " filename "\n"
5134 "| Size (encoded): " (format "%s byte%s\n"
5135 bsize (if (= bsize 1)
5136 ""
5137 "s"))
5138 (when description
5139 (concat "| Description: " description "\n"))
5140 "`----\n"))
5141 (setcdr data
5142 (cdr (mm-make-handle
5143 nil `("text/plain" (charset . gnus-decoded)) nil nil
5144 (list "attachment")
5145 (format "Deleted attachment (%s bytes)" bsize))))))
5146 ;; (set-buffer gnus-summary-buffer)
5147 (gnus-article-edit-part handles id))))
5148
5149 (defun gnus-mime-save-part ()
5150 "Save the MIME part under point."
5151 (interactive)
5152 (gnus-article-check-buffer)
5153 (let ((data (get-text-property (point) 'gnus-data)))
5154 (when data
5155 (mm-save-part data))))
5156
5157 (defun gnus-mime-pipe-part (&optional cmd)
5158 "Pipe the MIME part under point to a process.
5159 Use CMD as the process."
5160 (interactive)
5161 (gnus-article-check-buffer)
5162 (let ((data (get-text-property (point) 'gnus-data)))
5163 (when data
5164 (mm-pipe-part data cmd))))
5165
5166 (defun gnus-mime-view-part ()
5167 "Interactively choose a viewing method for the MIME part under point."
5168 (interactive)
5169 (gnus-article-check-buffer)
5170 (let ((data (get-text-property (point) 'gnus-data)))
5171 (when data
5172 (setq gnus-article-mime-handles
5173 (mm-merge-handles
5174 gnus-article-mime-handles (setq data (copy-sequence data))))
5175 (mm-interactively-view-part data))))
5176
5177 (defun gnus-mime-view-part-as-type-internal ()
5178 (gnus-article-check-buffer)
5179 (let* ((handle (get-text-property (point) 'gnus-data))
5180 (name (or
5181 ;; Content-Type: foo/bar; name=...
5182 (mail-content-type-get (mm-handle-type handle) 'name)
5183 ;; Content-Disposition: attachment; filename=...
5184 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5185 (def-type (and name (mm-default-file-encoding name))))
5186 (or (and def-type (cons def-type 0))
5187 (and handle
5188 (equal (mm-handle-media-supertype handle) "text")
5189 '("text/plain" . 0))
5190 '("application/octet-stream" . 0))))
5191
5192 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5193 "Choose a MIME media type, and view the part as such.
5194 If non-nil, PRED is a predicate to use during completion to limit the
5195 available media-types."
5196 (interactive)
5197 (unless mime-type
5198 (setq mime-type
5199 (let ((default (gnus-mime-view-part-as-type-internal)))
5200 (gnus-completing-read
5201 "View as MIME type"
5202 (if pred
5203 (gnus-remove-if-not pred (mailcap-mime-types))
5204 (mailcap-mime-types))
5205 nil nil nil
5206 (car default)))))
5207 (gnus-article-check-buffer)
5208 (let ((handle (get-text-property (point) 'gnus-data)))
5209 (when handle
5210 (when (equal (mm-handle-media-type handle) "message/external-body")
5211 (unless (mm-handle-cache handle)
5212 (mm-extern-cache-contents handle))
5213 (setq handle (mm-handle-cache handle)))
5214 (setq handle
5215 (mm-make-handle (mm-handle-buffer handle)
5216 (cons mime-type (cdr (mm-handle-type handle)))
5217 (mm-handle-encoding handle)
5218 (mm-handle-undisplayer handle)
5219 (mm-handle-disposition handle)
5220 (mm-handle-description handle)
5221 nil
5222 (mm-handle-id handle)))
5223 (setq gnus-article-mime-handles
5224 (mm-merge-handles gnus-article-mime-handles handle))
5225 (when (mm-handle-displayed-p handle)
5226 (mm-remove-part handle))
5227 (gnus-mm-display-part handle))))
5228
5229 (defun gnus-mime-copy-part (&optional handle arg)
5230 "Put the MIME part under point into a new buffer.
5231 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5232 are decompressed."
5233 (interactive (list nil current-prefix-arg))
5234 (gnus-article-check-buffer)
5235 (unless handle
5236 (setq handle (get-text-property (point) 'gnus-data)))
5237 (when handle
5238 (let ((filename (mm-handle-filename handle))
5239 contents dont-decode charset coding-system)
5240 (mm-with-unibyte-buffer
5241 (mm-insert-part handle)
5242 (setq contents (or (condition-case nil
5243 (mm-decompress-buffer filename nil 'sig)
5244 (error
5245 (setq dont-decode t)
5246 nil))
5247 (buffer-string))))
5248 (setq filename (cond (filename (file-name-nondirectory filename))
5249 (dont-decode "*raw data*")
5250 (t "*decoded*")))
5251 (cond
5252 (dont-decode)
5253 ((not arg)
5254 (unless (setq charset (mail-content-type-get
5255 (mm-handle-type handle) 'charset))
5256 (unless (setq coding-system (mm-with-unibyte-buffer
5257 (insert contents)
5258 (mm-find-buffer-file-coding-system)))
5259 (setq charset gnus-newsgroup-charset))))
5260 ((numberp arg)
5261 (setq charset (or (cdr (assq arg
5262 gnus-summary-show-article-charset-alist))
5263 (mm-read-coding-system "Charset: ")))))
5264 (switch-to-buffer (generate-new-buffer filename))
5265 (if (or coding-system
5266 (and charset
5267 (setq coding-system (mm-charset-to-coding-system
5268 charset nil t))
5269 (not (eq coding-system 'ascii))))
5270 (progn
5271 (mm-enable-multibyte)
5272 (insert (mm-decode-coding-string contents coding-system))
5273 (setq buffer-file-coding-system
5274 (if (boundp 'last-coding-system-used)
5275 (symbol-value 'last-coding-system-used)
5276 coding-system)))
5277 (mm-disable-multibyte)
5278 (insert contents)
5279 (setq buffer-file-coding-system mm-binary-coding-system))
5280 ;; We do it this way to make `normal-mode' set the appropriate mode.
5281 (unwind-protect
5282 (progn
5283 (setq buffer-file-name (expand-file-name filename))
5284 (normal-mode))
5285 (setq buffer-file-name nil))
5286 (goto-char (point-min)))))
5287
5288 (defun gnus-mime-print-part (&optional handle filename)
5289 "Print the MIME part under point."
5290 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5291 (gnus-article-check-buffer)
5292 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5293 (contents (and handle (mm-get-part handle)))
5294 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5295 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5296 (when contents
5297 (if printer
5298 (unwind-protect
5299 (progn
5300 (mm-save-part-to-file handle file)
5301 (call-process shell-file-name nil
5302 (generate-new-buffer " *mm*")
5303 nil
5304 shell-command-switch
5305 (mm-mailcap-command
5306 printer file (mm-handle-type handle))))
5307 (delete-file file))
5308 (with-temp-buffer
5309 (insert contents)
5310 (gnus-print-buffer))
5311 (ps-despool filename)))))
5312
5313 (defun gnus-mime-inline-part (&optional handle arg)
5314 "Insert the MIME part under point into the current buffer.
5315 Compressed files like .gz and .bz2 are decompressed."
5316 (interactive (list nil current-prefix-arg))
5317 (gnus-article-check-buffer)
5318 (let* ((inhibit-read-only t)
5319 (b (point))
5320 (btn ;; position where the MIME button exists
5321 (if handle
5322 (if (eq handle (get-text-property b 'gnus-data))
5323 b
5324 (article-goto-body)
5325 (or (text-property-any (point) (point-max) 'gnus-data handle)
5326 (text-property-any (point-min) (point) 'gnus-data handle)))
5327 (setq handle (get-text-property b 'gnus-data))
5328 b))
5329 start contents charset coding-system)
5330 (when handle
5331 (when (= b (prog1
5332 btn
5333 (setq start (next-single-property-change btn 'gnus-data
5334 nil (point-max))
5335 btn (previous-single-property-change start
5336 'gnus-data))))
5337 (setq b btn))
5338 (if (and (not arg) (mm-handle-undisplayer handle))
5339 (mm-remove-part handle)
5340 (mm-with-unibyte-buffer
5341 (mm-insert-part handle)
5342 (setq contents
5343 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5344 (buffer-string))))
5345 (cond
5346 ((not arg)
5347 (unless (setq charset (mail-content-type-get
5348 (mm-handle-type handle) 'charset))
5349 (unless (setq coding-system
5350 (mm-with-unibyte-buffer
5351 (insert contents)
5352 (mm-find-buffer-file-coding-system)))
5353 (setq charset gnus-newsgroup-charset))))
5354 ((numberp arg)
5355 (if (mm-handle-undisplayer handle)
5356 (mm-remove-part handle))
5357 (setq charset
5358 (or (cdr (assq arg
5359 gnus-summary-show-article-charset-alist))
5360 (mm-read-coding-system "Charset: "))))
5361 ((mm-handle-undisplayer handle)
5362 (mm-remove-part handle)))
5363 (goto-char start)
5364 (unless (bolp)
5365 ;; This is a header button.
5366 (forward-line 1))
5367 (mm-display-inline handle))
5368 ;; Toggle the button appearance between `[button]...' and `[button]'.
5369 (goto-char btn)
5370 (let ((displayed-p (mm-handle-displayed-p handle)))
5371 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5372 (list displayed-p))
5373 (if (featurep 'emacs)
5374 (delete-region
5375 (point)
5376 (next-single-property-change (point) 'gnus-data nil (point-max)))
5377 (let* ((end (next-single-property-change (point) 'gnus-data))
5378 (annots (annotations-at (or end (point-max)))))
5379 (delete-region (point)
5380 (if end
5381 (if annots (1+ end) end)
5382 (point-max)))
5383 (dolist (annot annots)
5384 (set-extent-endpoints annot (point) (point)))))
5385 (setq start (point))
5386 (if (search-backward "\n\n" nil t)
5387 (progn
5388 (goto-char start)
5389 (unless (or displayed-p (eolp))
5390 ;; Add extra newline.
5391 (insert (propertize (buffer-substring (1- start) start)
5392 'gnus-undeletable t))))
5393 ;; We're in the article header.
5394 (delete-char -1)
5395 (dolist (ovl (gnus-overlays-in btn (point)))
5396 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5397 (gnus-overlay-put ovl 'face nil))
5398 (save-restriction
5399 (message-narrow-to-field)
5400 (let ((gnus-treatment-function-alist
5401 '((gnus-treat-highlight-headers
5402 gnus-article-highlight-headers))))
5403 (gnus-treat-article 'head)))))
5404 (goto-char b))))
5405
5406 (defun gnus-mime-set-charset-parameters (handle charset)
5407 "Set CHARSET to parameters in HANDLE.
5408 CHARSET may either be a string or a symbol."
5409 (unless (stringp charset)
5410 (setq charset (symbol-name charset)))
5411 (if (stringp (car handle))
5412 (dolist (h (cdr handle))
5413 (gnus-mime-set-charset-parameters h charset))
5414 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5415 "message/external-body")
5416 (progn
5417 (unless (mm-handle-cache handle)
5418 (mm-extern-cache-contents handle))
5419 (mm-handle-cache handle))
5420 handle)))
5421 (param (assq 'charset (cdr type))))
5422 (if param
5423 (setcdr param charset)
5424 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5425
5426 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5427 "Insert the MIME part under point into the current buffer using the
5428 specified charset."
5429 (interactive (list nil current-prefix-arg))
5430 (gnus-article-check-buffer)
5431 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5432 (fun (get-text-property (point) 'gnus-callback))
5433 (gnus-newsgroup-ignored-charsets 'gnus-all)
5434 charset form preferred parts)
5435 (when handle
5436 (when (prog1
5437 (and fun
5438 (setq charset
5439 (or (cdr (assq
5440 arg
5441 gnus-summary-show-article-charset-alist))
5442 (mm-read-coding-system "Charset: "))))
5443 (if (mm-handle-undisplayer handle)
5444 (mm-remove-part handle)))
5445 (gnus-mime-set-charset-parameters handle charset)
5446 (when (and (consp (setq form (cdr-safe fun)))
5447 (setq form (ignore-errors
5448 (assq 'gnus-mime-display-alternative form)))
5449 (setq preferred (caddr form))
5450 (progn
5451 (when (eq (car preferred) 'quote)
5452 (setq preferred (cadr preferred)))
5453 (not (equal preferred
5454 (get-text-property (point) 'gnus-data))))
5455 (setq parts (get-text-property (point) 'gnus-part))
5456 (setq parts (cdr (assq parts
5457 gnus-article-mime-handle-alist)))
5458 (equal (mm-handle-media-type parts) "multipart/alternative")
5459 (setq parts (reverse (cdr parts))))
5460 (setcar (cddr form)
5461 (list 'quote (or (cadr (member preferred parts))
5462 (car parts)))))
5463 (funcall fun handle)))))
5464
5465 (defun gnus-mime-view-part-externally (&optional handle)
5466 "View the MIME part under point with an external viewer."
5467 (interactive)
5468 (gnus-article-check-buffer)
5469 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5470 (mm-user-display-methods nil)
5471 (mm-inlined-types nil)
5472 (mail-parse-charset gnus-newsgroup-charset)
5473 (mail-parse-ignored-charsets
5474 (with-current-buffer gnus-summary-buffer
5475 gnus-newsgroup-ignored-charsets))
5476 (type (mm-handle-media-type handle))
5477 (method (mailcap-mime-info type))
5478 (mm-enable-external t))
5479 (if (not (stringp method))
5480 (gnus-mime-view-part-as-type
5481 nil (lambda (type) (stringp (mailcap-mime-info type))))
5482 (when handle
5483 (mm-display-part handle nil t)))))
5484
5485 (defun gnus-mime-view-part-internally (&optional handle)
5486 "View the MIME part under point with an internal viewer.
5487 If no internal viewer is available, use an external viewer."
5488 (interactive)
5489 (gnus-article-check-buffer)
5490 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5491 (mm-inlined-types '(".*"))
5492 (mm-inline-large-images t)
5493 (mail-parse-charset gnus-newsgroup-charset)
5494 (mail-parse-ignored-charsets
5495 (with-current-buffer gnus-summary-buffer
5496 gnus-newsgroup-ignored-charsets))
5497 (inhibit-read-only t))
5498 (if (not (mm-inlinable-p handle))
5499 (gnus-mime-view-part-as-type
5500 nil (lambda (type) (mm-inlinable-p handle type)))
5501 (when handle
5502 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5503
5504 (defun gnus-mime-action-on-part (&optional action)
5505 "Do something with the MIME attachment at \(point\)."
5506 (interactive
5507 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5508 (gnus-article-check-buffer)
5509 (let ((action-pair (assoc action gnus-mime-action-alist)))
5510 (if action-pair
5511 (funcall (cdr action-pair)))))
5512
5513 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5514 "Call FUNCTION on MIME part N.
5515 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5516 If INTERACTIVE, call FUNCTION interactively."
5517 (let (window frame)
5518 ;; Check whether the article is displayed.
5519 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5520 (setq window (get-buffer-window gnus-article-buffer t))
5521 (frame-visible-p (setq frame (window-frame window))))
5522 (error "No article is displayed"))
5523 (with-current-buffer gnus-article-buffer
5524 ;; Check whether the article displays the right contents.
5525 (unless (with-current-buffer gnus-summary-buffer
5526 (eq gnus-current-article (gnus-summary-article-number)))
5527 (error "You should select the right article first"))
5528 (if n
5529 (setq n (prefix-numeric-value n))
5530 (let ((pt (point)))
5531 (setq n (or (get-text-property pt 'gnus-part)
5532 (and (not (bobp))
5533 (get-text-property (1- pt) 'gnus-part))
5534 (get-text-property (prog2
5535 (forward-line 1)
5536 (point)
5537 (goto-char pt))
5538 'gnus-part)
5539 (get-text-property
5540 (or (and (setq pt (previous-single-property-change
5541 pt 'gnus-part))
5542 (1- pt))
5543 (next-single-property-change (point) 'gnus-part)
5544 (point))
5545 'gnus-part)
5546 1))))
5547 ;; Check whether the specified part exists.
5548 (when (> n (length gnus-article-mime-handle-alist))
5549 (error "No such part")))
5550 (unless
5551 (progn
5552 ;; To select the window is needed so that the cursor
5553 ;; might be visible on the MIME button.
5554 (select-window (prog1
5555 window
5556 (setq window (selected-window))
5557 ;; Article may be displayed in the other frame.
5558 (gnus-select-frame-set-input-focus
5559 (prog1
5560 frame
5561 (setq frame (selected-frame))))))
5562 (when (gnus-article-goto-part n)
5563 ;; We point the cursor and the arrow at the MIME button
5564 ;; when the `function' prompt the user for something.
5565 (unless (and (pos-visible-in-window-p)
5566 (> (count-lines (point) (window-end))
5567 (/ (1- (window-height)) 3)))
5568 (recenter (/ (1- (window-height)) 3)))
5569 (let ((cursor-in-non-selected-windows t)
5570 (overlay-arrow-string "=>")
5571 (overlay-arrow-position (point-marker)))
5572 (unwind-protect
5573 (cond
5574 ((and no-handle interactive)
5575 (call-interactively function))
5576 (no-handle
5577 (funcall function))
5578 (interactive
5579 (call-interactively
5580 function (get-text-property (point) 'gnus-data)))
5581 (t
5582 (funcall function
5583 (get-text-property (point) 'gnus-data))))
5584 (set-marker overlay-arrow-position nil)
5585 (unless gnus-auto-select-part
5586 (gnus-select-frame-set-input-focus frame)
5587 (select-window window))))
5588 t))
5589 (if gnus-inhibit-mime-unbuttonizing
5590 ;; This is the default though the program shouldn't reach here.
5591 (error "No such part")
5592 ;; The part which doesn't have the MIME button is selected.
5593 ;; So, we display all the buttons and redo it.
5594 (let ((gnus-inhibit-mime-unbuttonizing t))
5595 (gnus-summary-show-article)
5596 (gnus-article-part-wrapper n function no-handle))))))
5597
5598 (defun gnus-article-pipe-part (n)
5599 "Pipe MIME part N, which is the numerical prefix."
5600 (interactive "P")
5601 (gnus-article-part-wrapper n 'mm-pipe-part))
5602
5603 (defun gnus-article-save-part (n)
5604 "Save MIME part N, which is the numerical prefix."
5605 (interactive "P")
5606 (gnus-article-part-wrapper n 'mm-save-part))
5607
5608 (defun gnus-article-interactively-view-part (n)
5609 "View MIME part N interactively, which is the numerical prefix."
5610 (interactive "P")
5611 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5612
5613 (defun gnus-article-copy-part (n)
5614 "Copy MIME part N, which is the numerical prefix."
5615 (interactive "P")
5616 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5617
5618 (defun gnus-article-view-part-as-charset (n)
5619 "View MIME part N using a specified charset.
5620 N is the numerical prefix."
5621 (interactive "P")
5622 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5623
5624 (defun gnus-article-view-part-externally (n)
5625 "View MIME part N externally, which is the numerical prefix."
5626 (interactive "P")
5627 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5628
5629 (defun gnus-article-inline-part (n)
5630 "Inline MIME part N, which is the numerical prefix."
5631 (interactive "P")
5632 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5633
5634 (defun gnus-article-save-part-and-strip (n)
5635 "Save MIME part N and replace it with an external body.
5636 N is the numerical prefix."
5637 (interactive "P")
5638 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5639
5640 (defun gnus-article-replace-part (n)
5641 "Replace MIME part N with an external body.
5642 N is the numerical prefix."
5643 (interactive "P")
5644 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5645
5646 (defun gnus-article-delete-part (n)
5647 "Delete MIME part N and add some information about the removed part.
5648 N is the numerical prefix."
5649 (interactive "P")
5650 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5651
5652 (defun gnus-article-view-part-as-type (n)
5653 "Choose a MIME media type, and view part N as such.
5654 N is the numerical prefix."
5655 (interactive "P")
5656 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5657
5658 (defun gnus-article-mime-match-handle-first (condition)
5659 (if condition
5660 (let (n)
5661 (dolist (ihandle gnus-article-mime-handle-alist)
5662 (if (and (cond
5663 ((functionp condition)
5664 (funcall condition (cdr ihandle)))
5665 ((eq condition 'undisplayed)
5666 (not (or (mm-handle-undisplayer (cdr ihandle))
5667 (equal (mm-handle-media-type (cdr ihandle))
5668 "multipart/alternative"))))
5669 ((eq condition 'undisplayed-alternative)
5670 (not (mm-handle-undisplayer (cdr ihandle))))
5671 (t t))
5672 (gnus-article-goto-part (car ihandle))
5673 (or (not n) (< (car ihandle) n)))
5674 (setq n (car ihandle))))
5675 (or n 1))
5676 1))
5677
5678 (defun gnus-article-view-part (&optional n)
5679 "View MIME part N, which is the numerical prefix.
5680 If the part is already shown, hide the part. If N is nil, view
5681 all parts."
5682 (interactive "P")
5683 (with-current-buffer gnus-article-buffer
5684 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5685 gnus-article-mime-match-handle-function)))
5686 (when (> n (length gnus-article-mime-handle-alist))
5687 (error "No such part"))
5688 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5689 (when (gnus-article-goto-part n)
5690 (if (equal (car handle) "multipart/alternative")
5691 (progn
5692 (beginning-of-line) ;; Make it toggle subparts
5693 (gnus-article-press-button))
5694 (when (eq (gnus-mm-display-part handle) 'internal)
5695 (gnus-set-window-start)))))))
5696
5697 (defsubst gnus-article-mime-total-parts ()
5698 (if (bufferp (car gnus-article-mime-handles))
5699 1 ;; single part
5700 (1- (length gnus-article-mime-handles))))
5701
5702 (defun gnus-mm-display-part (handle)
5703 "Display HANDLE and fix MIME button."
5704 (let ((id (get-text-property (point) 'gnus-part))
5705 (point (point))
5706 (inhibit-read-only t)
5707 (window (selected-window))
5708 (mail-parse-charset gnus-newsgroup-charset)
5709 (mail-parse-ignored-charsets
5710 (if (gnus-buffer-live-p gnus-summary-buffer)
5711 (with-current-buffer gnus-summary-buffer
5712 gnus-newsgroup-ignored-charsets)
5713 nil))
5714 start retval)
5715 (unwind-protect
5716 (progn
5717 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5718 (when win
5719 (select-window win)
5720 (goto-char point)))
5721 (setq start (next-single-property-change point 'gnus-data
5722 nil (point-max))
5723 point (previous-single-property-change start 'gnus-data))
5724 (if (mm-handle-displayed-p handle)
5725 ;; This will remove the part.
5726 (setq retval (mm-display-part handle))
5727 (let ((part (or (and (mm-inlinable-p handle)
5728 (mm-inlined-p handle)
5729 t)
5730 (with-temp-buffer
5731 (gnus-bind-safe-url-regexp
5732 (setq retval (mm-display-part handle)))
5733 (unless (zerop (buffer-size))
5734 (buffer-string))))))
5735 (goto-char start)
5736 (unless (bolp)
5737 ;; This is a header button.
5738 (forward-line 1))
5739 (cond ((stringp part)
5740 (save-restriction
5741 (narrow-to-region (point)
5742 (progn
5743 (insert part)
5744 (unless (bolp) (insert "\n"))
5745 (point)))
5746 (gnus-treat-article nil id
5747 (gnus-article-mime-total-parts)
5748 (mm-handle-media-type handle))
5749 (mm-handle-set-undisplayer
5750 handle
5751 `(lambda ()
5752 (let ((inhibit-read-only t))
5753 (delete-region ,(copy-marker (point-min) t)
5754 ,(point-max-marker)))))))
5755 (part
5756 (mm-display-inline handle))))))
5757 (goto-char point)
5758 ;; Toggle the button appearance between `[button]...' and `[button]'.
5759 (let ((displayed-p (mm-handle-displayed-p handle)))
5760 (gnus-insert-mime-button handle id (list displayed-p))
5761 (if (featurep 'emacs)
5762 (delete-region
5763 (point)
5764 (next-single-property-change (point) 'gnus-data nil (point-max)))
5765 (let* ((end (next-single-property-change (point) 'gnus-data))
5766 (annots (annotations-at (or end (point-max)))))
5767 (delete-region (point)
5768 (if end
5769 (if annots (1+ end) end)
5770 (point-max)))
5771 (dolist (annot annots)
5772 (set-extent-endpoints annot (point) (point)))))
5773 (setq start (point))
5774 (if (search-backward "\n\n" nil t)
5775 (progn
5776 (goto-char start)
5777 (unless (or displayed-p (eolp))
5778 ;; Add extra newline.
5779 (insert (propertize (buffer-substring (1- start) start)
5780 'gnus-undeletable t))))
5781 ;; We're in the article header.
5782 (delete-char -1)
5783 (dolist (ovl (gnus-overlays-in point (point)))
5784 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5785 (gnus-overlay-put ovl 'face nil))
5786 (save-restriction
5787 (message-narrow-to-field)
5788 (let ((gnus-treatment-function-alist
5789 '((gnus-treat-highlight-headers
5790 gnus-article-highlight-headers))))
5791 (gnus-treat-article 'head)))))
5792 (goto-char point)
5793 (if (window-live-p window)
5794 (select-window window)))
5795 retval))
5796
5797 (defun gnus-article-goto-part (n)
5798 "Go to MIME part N."
5799 (when gnus-break-pages
5800 (widen))
5801 (article-goto-body)
5802 (prog1
5803 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5804 ;; There may be header buttons.
5805 (text-property-any (point-min) (point) 'gnus-part n)))
5806 part handle end next handles)
5807 (when start
5808 (goto-char start)
5809 (if (setq handle (get-text-property start 'gnus-data))
5810 start
5811 ;; Go to the displayed subpart, assuming this is
5812 ;; multipart/alternative.
5813 (setq part start
5814 end (point-at-eol))
5815 (while (and (not handle)
5816 part
5817 (< part end)
5818 (setq next (text-property-not-all part end
5819 'gnus-data nil)))
5820 (setq part next
5821 handle (get-text-property part 'gnus-data))
5822 (push (cons handle part) handles)
5823 (unless (mm-handle-displayed-p handle)
5824 (setq handle nil
5825 part (text-property-any part end 'gnus-data nil))))
5826 (unless handle
5827 ;; No subpart is displayed, so we find preferred one.
5828 (setq part
5829 (cdr (assq (mm-preferred-alternative
5830 (nreverse (mapcar 'car handles)))
5831 handles))))
5832 (if part
5833 (goto-char (1+ part))
5834 start))))
5835 (when gnus-break-pages
5836 (gnus-narrow-to-page))))
5837
5838 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5839 (let ((gnus-tmp-name
5840 (or (mm-handle-filename handle)
5841 (mail-content-type-get (mm-handle-type handle) 'url)
5842 ""))
5843 (gnus-tmp-type (mm-handle-media-type handle))
5844 (gnus-tmp-description (or (mm-handle-description handle) ""))
5845 (gnus-tmp-dots
5846 (if (if displayed (car displayed)
5847 (mm-handle-displayed-p handle))
5848 "" "..."))
5849 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5850 (buffer-size)))
5851 gnus-tmp-type-long b e)
5852 (when (string-match ".*/" gnus-tmp-name)
5853 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5854 (setq gnus-tmp-type-long (concat gnus-tmp-type
5855 (and (not (equal gnus-tmp-name ""))
5856 (concat "; " gnus-tmp-name))))
5857 (unless (equal gnus-tmp-description "")
5858 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5859 (setq b (point))
5860 (gnus-eval-format
5861 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5862 `(keymap ,gnus-mime-button-map
5863 gnus-callback gnus-mm-display-part
5864 gnus-part ,gnus-tmp-id
5865 article-type annotation
5866 gnus-data ,handle
5867 rear-nonsticky t))
5868 (setq e (if (bolp)
5869 ;; Exclude a newline.
5870 (1- (point))
5871 (point)))
5872 (when gnus-article-button-face
5873 (gnus-overlay-put (gnus-make-overlay b e nil t)
5874 'face gnus-article-button-face))
5875 (widget-convert-button
5876 'link b e
5877 :mime-handle handle
5878 :action 'gnus-widget-press-button
5879 :button-keymap gnus-mime-button-map
5880 :help-echo
5881 (lambda (widget)
5882 ;; Needed to properly clear the message due to a bug in
5883 ;; wid-edit (XEmacs only).
5884 (if (boundp 'help-echo-owns-message)
5885 (setq help-echo-owns-message t))
5886 (format
5887 "%S: %s the MIME part; %S: more options"
5888 (aref gnus-mouse-2 0)
5889 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5890 "hide" "show")
5891 (aref gnus-down-mouse-3 0))))))
5892
5893 (defun gnus-widget-press-button (elems el)
5894 (goto-char (widget-get elems :from))
5895 (gnus-article-press-button))
5896
5897 (defvar gnus-displaying-mime nil)
5898
5899 (defun gnus-display-mime (&optional ihandles)
5900 "Display the MIME parts."
5901 (save-excursion
5902 (save-selected-window
5903 (let ((window (get-buffer-window gnus-article-buffer))
5904 (point (point)))
5905 (when window
5906 (select-window window)
5907 ;; We have to do this since selecting the window
5908 ;; may change the point. So we set the window point.
5909 (set-window-point window point)))
5910 (let ((handles ihandles)
5911 (inhibit-read-only t)
5912 handle)
5913 (cond (handles)
5914 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5915 (when gnus-article-emulate-mime
5916 (mm-uu-dissect-text-parts handles)))
5917 (gnus-article-emulate-mime
5918 (setq handles (mm-uu-dissect))))
5919 (when (and (not ihandles)
5920 (not gnus-displaying-mime))
5921 ;; Top-level call; we clean up.
5922 (when gnus-article-mime-handles
5923 (mm-destroy-parts gnus-article-mime-handles)
5924 (setq gnus-article-mime-handle-alist nil));; A trick.
5925 (setq gnus-article-mime-handles handles)
5926 ;; We allow users to glean info from the handles.
5927 (when gnus-article-mime-part-function
5928 (gnus-mime-part-function handles)))
5929 (if (and handles
5930 (or (not (stringp (car handles)))
5931 (cdr handles)))
5932 (progn
5933 (when (and (not ihandles)
5934 (not gnus-displaying-mime))
5935 ;; Clean up for mime parts.
5936 (article-goto-body)
5937 (delete-region (point) (point-max)))
5938 (let ((gnus-displaying-mime t))
5939 (gnus-mime-display-part handles)))
5940 (save-restriction
5941 (article-goto-body)
5942 (narrow-to-region (point) (point-max))
5943 (gnus-treat-article nil 1 1 "text/plain")
5944 (widen)))
5945 (unless ihandles
5946 ;; Highlight the headers.
5947 (save-excursion
5948 (save-restriction
5949 (article-goto-body)
5950 (narrow-to-region (point-min) (point))
5951 (gnus-article-save-original-date
5952 (gnus-treat-article 'head)))))))
5953 ;; Cope with broken MIME messages.
5954 (goto-char (point-max))
5955 (unless (bolp)
5956 (insert "\n"))))
5957
5958 (defcustom gnus-mime-display-multipart-as-mixed nil
5959 "Display \"multipart\" parts as \"multipart/mixed\".
5960
5961 If t, it overrides nil values of
5962 `gnus-mime-display-multipart-alternative-as-mixed' and
5963 `gnus-mime-display-multipart-related-as-mixed'."
5964 :group 'gnus-article-mime
5965 :type 'boolean)
5966
5967 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5968 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5969 :version "22.1"
5970 :group 'gnus-article-mime
5971 :type 'boolean)
5972
5973 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5974 "Display \"multipart/related\" parts as \"multipart/mixed\".
5975
5976 If displaying \"text/html\" is discouraged \(see
5977 `mm-discouraged-alternatives'\) images or other material inside a
5978 \"multipart/related\" part might be overlooked when this variable is nil."
5979 :version "22.1"
5980 :group 'gnus-article-mime
5981 :type 'boolean)
5982
5983 (defcustom gnus-mime-display-attachment-buttons-in-header t
5984 "Add attachment buttons in the end of the header of an article.
5985 Since MIME attachments tend to be put at the end of an article, we may
5986 overlook them if there is a huge body. This option offers you a copy
5987 of all non-inlinable MIME parts as buttons shown in front of an article.
5988 If nil, don't show those extra buttons."
5989 :version "24.5"
5990 :group 'gnus-article-mime
5991 :type 'boolean)
5992
5993 (defun gnus-mime-display-part (handle)
5994 (cond
5995 ;; Maybe a broken MIME message.
5996 ((null handle))
5997 ;; Single part.
5998 ((not (stringp (car handle)))
5999 (gnus-mime-display-single handle))
6000 ;; User-defined multipart
6001 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6002 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6003 handle))
6004 ;; multipart/alternative
6005 ((and (equal (car handle) "multipart/alternative")
6006 (not (or gnus-mime-display-multipart-as-mixed
6007 gnus-mime-display-multipart-alternative-as-mixed)))
6008 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6009 (push (cons id handle) gnus-article-mime-handle-alist)
6010 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6011 ;; multipart/related
6012 ((and (equal (car handle) "multipart/related")
6013 (not (or gnus-mime-display-multipart-as-mixed
6014 gnus-mime-display-multipart-related-as-mixed)))
6015 (gnus-mime-display-part (cadr handle)))
6016 ((equal (car handle) "multipart/signed")
6017 (gnus-add-wash-type 'signed)
6018 (gnus-mime-display-security handle))
6019 ((equal (car handle) "multipart/encrypted")
6020 (gnus-add-wash-type 'encrypted)
6021 (gnus-mime-display-security handle))
6022 ;; Other multiparts are handled like multipart/mixed.
6023 (t
6024 (gnus-mime-display-mixed (cdr handle)))))
6025
6026 (defun gnus-mime-part-function (handles)
6027 (if (stringp (car handles))
6028 (mapcar 'gnus-mime-part-function (cdr handles))
6029 (funcall gnus-article-mime-part-function handles)))
6030
6031 (defun gnus-mime-display-mixed (handles)
6032 (mapcar 'gnus-mime-display-part handles))
6033
6034 (defun gnus-mime-display-single (handle)
6035 (let ((type (mm-handle-media-type handle))
6036 (ignored gnus-ignored-mime-types)
6037 (not-attachment t)
6038 display text)
6039 (catch 'ignored
6040 (progn
6041 (while ignored
6042 (when (string-match (pop ignored) type)
6043 (throw 'ignored nil)))
6044 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6045 (with-current-buffer gnus-summary-buffer
6046 gnus-inhibit-images)
6047 gnus-inhibit-images)
6048 (string-match "\\`image/" type)))
6049 (setq not-attachment
6050 (and (not (mm-inline-override-p handle))
6051 (or (not (mm-handle-disposition handle))
6052 (equal (car (mm-handle-disposition handle))
6053 "inline")
6054 (mm-attachment-override-p handle))))
6055 (mm-automatic-display-p handle)
6056 (or (and
6057 (mm-inlinable-p handle)
6058 (mm-inlined-p handle))
6059 (mm-automatic-external-display-p type)))
6060 (setq display t)
6061 (when (equal (mm-handle-media-supertype handle) "text")
6062 (setq text t)))
6063 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6064 beg)
6065 (unless id
6066 (setq id (1+ (length gnus-article-mime-handle-alist)))
6067 (push (cons id handle) gnus-article-mime-handle-alist))
6068 (when (and display
6069 (equal (mm-handle-media-supertype handle) "message"))
6070 (insert-char
6071 ?\n
6072 (cond ((not (bolp)) 2)
6073 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6074 (t 1))))
6075 (when (or (not display)
6076 (not (gnus-unbuttonized-mime-type-p type))
6077 (eq id gnus-mime-buttonized-part-id))
6078 (gnus-insert-mime-button
6079 handle id (list (or display (and not-attachment text)))))
6080 (setq beg (point))
6081 (cond
6082 (display
6083 (let ((mail-parse-charset gnus-newsgroup-charset)
6084 (mail-parse-ignored-charsets
6085 (save-excursion (condition-case ()
6086 (set-buffer gnus-summary-buffer)
6087 (error))
6088 gnus-newsgroup-ignored-charsets)))
6089 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6090 ((and text not-attachment)
6091 (mm-display-inline handle)))
6092 (goto-char (point-max))
6093 (if (string-match "\\`image/" type)
6094 (gnus-article-insert-newline)
6095 (if (prog1
6096 (= (skip-chars-backward "\n") -1)
6097 (forward-char 1))
6098 (gnus-article-insert-newline)
6099 (put-text-property (point) (point-max) 'gnus-undeletable t))
6100 (goto-char (point-max)))
6101 ;; Do highlighting.
6102 (save-excursion
6103 (save-restriction
6104 (narrow-to-region beg (point))
6105 (if (eq handle gnus-article-mime-handles)
6106 ;; The format=flowed case.
6107 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6108 ;; Don't count signature parts that are never displayed.
6109 ;; The part number should be re-calculated supposing this
6110 ;; might be a message/rfc822 part.
6111 (let (handles)
6112 (dolist (part gnus-article-mime-handles)
6113 (unless (or (stringp part)
6114 (equal (car (mm-handle-type part))
6115 "application/pgp-signature"))
6116 (push part handles)))
6117 (gnus-treat-article
6118 nil (length (memq handle handles)) (length handles)
6119 (mm-handle-media-type handle)))))))))))
6120
6121 (defun gnus-unbuttonized-mime-type-p (type)
6122 "Say whether TYPE is to be unbuttonized."
6123 (unless gnus-inhibit-mime-unbuttonizing
6124 (when (catch 'found
6125 (let ((types gnus-unbuttonized-mime-types))
6126 (while types
6127 (when (string-match (pop types) type)
6128 (throw 'found t)))))
6129 (not (catch 'found
6130 (let ((types gnus-buttonized-mime-types))
6131 (while types
6132 (when (string-match (pop types) type)
6133 (throw 'found t)))))))))
6134
6135 (defun gnus-article-insert-newline ()
6136 "Insert a newline, but mark it as undeletable."
6137 (gnus-put-text-property
6138 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6139
6140 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6141 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6142 (ihandles handles)
6143 (point (point))
6144 handle (inhibit-read-only t) from props begend not-pref)
6145 (save-window-excursion
6146 (save-restriction
6147 (when ibegend
6148 (narrow-to-region (car ibegend)
6149 (or (cdr ibegend)
6150 (progn
6151 (goto-char (car ibegend))
6152 (forward-line 2)
6153 (point))))
6154 (delete-region (point-min) (point-max))
6155 (mm-remove-parts handles))
6156 (setq begend (list (point-marker)))
6157 ;; Do the toggle.
6158 (unless (setq not-pref (cadr (member preferred ihandles)))
6159 (setq not-pref (car ihandles)))
6160 (when (or ibegend
6161 (not preferred)
6162 (not (gnus-unbuttonized-mime-type-p
6163 "multipart/alternative")))
6164 (gnus-add-text-properties
6165 (setq from (point))
6166 (progn
6167 (insert (format "%d. " id))
6168 (point))
6169 `(gnus-callback
6170 (lambda (handles)
6171 (unless ,(not ibegend)
6172 (setq gnus-article-mime-handle-alist
6173 ',gnus-article-mime-handle-alist))
6174 (gnus-mime-display-alternative
6175 ',ihandles ',not-pref ',begend ,id))
6176 keymap ,gnus-mime-button-map
6177 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6178 face ,gnus-article-button-face
6179 gnus-part ,id
6180 article-type multipart
6181 rear-nonsticky t))
6182 (widget-convert-button 'link from (point)
6183 :action 'gnus-widget-press-button
6184 :button-keymap gnus-widget-button-keymap)
6185 ;; Do the handles
6186 (while (setq handle (pop handles))
6187 (gnus-add-text-properties
6188 (setq from (point))
6189 (progn
6190 (insert (format "(%c) %-18s"
6191 (if (equal handle preferred) ?* ? )
6192 (mm-handle-media-type handle)))
6193 (point))
6194 `(gnus-callback
6195 (lambda (handles)
6196 (unless ,(not ibegend)
6197 (setq gnus-article-mime-handle-alist
6198 ',gnus-article-mime-handle-alist))
6199 (gnus-mime-display-alternative
6200 ',ihandles ',handle ',begend ,id))
6201 keymap ,gnus-mime-button-map
6202 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6203 face ,gnus-article-button-face
6204 gnus-part ,id
6205 gnus-data ,handle
6206 rear-nonsticky t))
6207 (widget-convert-button 'link from (point)
6208 :action 'gnus-widget-press-button
6209 :button-keymap gnus-widget-button-keymap)
6210 (insert " "))
6211 (insert "\n\n"))
6212 (when preferred
6213 (if (stringp (car preferred))
6214 (gnus-display-mime preferred)
6215 (let ((mail-parse-charset gnus-newsgroup-charset)
6216 (mail-parse-ignored-charsets
6217 (with-current-buffer gnus-summary-buffer
6218 gnus-newsgroup-ignored-charsets)))
6219 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6220 ;; Do highlighting.
6221 (save-excursion
6222 (save-restriction
6223 (narrow-to-region (car begend) (point-max))
6224 (gnus-treat-article
6225 nil (length gnus-article-mime-handle-alist)
6226 (gnus-article-mime-total-parts)
6227 (mm-handle-media-type preferred))))))
6228 (goto-char (point-max))
6229 (setcdr begend (point-marker)))))
6230 (when ibegend
6231 (goto-char point)))
6232 ;; Redraw attachment buttons in the header.
6233 (when gnus-mime-display-attachment-buttons-in-header
6234 (gnus-mime-buttonize-attachments-in-header)))
6235
6236 (defconst gnus-article-wash-status-strings
6237 (let ((alist '((cite "c" "Possible hidden citation text"
6238 " " "All citation text visible")
6239 (headers "h" "Hidden headers"
6240 " " "All headers visible.")
6241 (pgp "p" "Encrypted or signed message status hidden"
6242 " " "No hidden encryption nor digital signature status")
6243 (signature "s" "Signature has been hidden"
6244 " " "Signature is visible")
6245 (overstrike "o" "Overstrike (^H) characters applied"
6246 " " "No overstrike characters applied")
6247 (emphasis "e" "/*_Emphasis_*/ characters applied"
6248 " " "No /*_emphasis_*/ characters applied")))
6249 result)
6250 (dolist (entry alist result)
6251 (let ((key (nth 0 entry))
6252 (on (copy-sequence (nth 1 entry)))
6253 (on-help (nth 2 entry))
6254 (off (copy-sequence (nth 3 entry)))
6255 (off-help (nth 4 entry)))
6256 (put-text-property 0 1 'help-echo on-help on)
6257 (put-text-property 0 1 'help-echo off-help off)
6258 (push (list key on off) result))))
6259 "Alist of strings describing wash status in the mode line.
6260 Each entry has the form (KEY ON OF), where the KEY is a symbol
6261 representing the particular washing function, ON is the string to use
6262 in the article mode line when the washing function is active, and OFF
6263 is the string to use when it is inactive.")
6264
6265 (defun gnus-article-wash-status-entry (key value)
6266 (let ((entry (assoc key gnus-article-wash-status-strings)))
6267 (if value (nth 1 entry) (nth 2 entry))))
6268
6269 (defun gnus-article-wash-status ()
6270 "Return a string which display status of article washing."
6271 (with-current-buffer gnus-article-buffer
6272 (let ((cite (memq 'cite gnus-article-wash-types))
6273 (headers (memq 'headers gnus-article-wash-types))
6274 (boring (memq 'boring-headers gnus-article-wash-types))
6275 (pgp (memq 'pgp gnus-article-wash-types))
6276 (pem (memq 'pem gnus-article-wash-types))
6277 (signed (memq 'signed gnus-article-wash-types))
6278 (encrypted (memq 'encrypted gnus-article-wash-types))
6279 (signature (memq 'signature gnus-article-wash-types))
6280 (overstrike (memq 'overstrike gnus-article-wash-types))
6281 (emphasis (memq 'emphasis gnus-article-wash-types)))
6282 (concat
6283 (gnus-article-wash-status-entry 'cite cite)
6284 (gnus-article-wash-status-entry 'headers (or headers boring))
6285 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6286 (gnus-article-wash-status-entry 'signature signature)
6287 (gnus-article-wash-status-entry 'overstrike overstrike)
6288 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6289
6290 (defun gnus-add-wash-type (type)
6291 "Add a washing of TYPE to the current status."
6292 (add-to-list 'gnus-article-wash-types type))
6293
6294 (defun gnus-delete-wash-type (type)
6295 "Add a washing of TYPE to the current status."
6296 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6297
6298 (defun gnus-add-image (category image)
6299 "Add IMAGE of CATEGORY to the list of displayed images."
6300 (let ((entry (assq category gnus-article-image-alist)))
6301 (unless entry
6302 (setq entry (list category))
6303 (push entry gnus-article-image-alist))
6304 (nconc entry (list image))))
6305
6306 (defun gnus-delete-images (category)
6307 "Delete all images in CATEGORY."
6308 (let ((entry (assq category gnus-article-image-alist)))
6309 (dolist (image (cdr entry))
6310 (gnus-remove-image image category))
6311 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6312 (gnus-delete-wash-type category)))
6313
6314 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6315
6316 (defun gnus-article-maybe-hide-headers ()
6317 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6318 Provided for backwards compatibility."
6319 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6320 (not (with-current-buffer gnus-summary-buffer
6321 gnus-have-all-headers)))
6322 (not gnus-inhibit-hiding))
6323 (gnus-article-hide-headers)))
6324
6325 (declare-function shr-put-image "shr" (data alt &optional flags))
6326
6327 (defun gnus-shr-put-image (data alt &optional flags)
6328 "Put image DATA with a string ALT. Enable image to be deleted."
6329 (let ((image (if flags
6330 (shr-put-image data (propertize (or alt "*")
6331 'gnus-image-category 'shr)
6332 flags)
6333 ;; Old `shr-put-image' doesn't take the optional `flags'
6334 ;; argument.
6335 (shr-put-image data (propertize (or alt "*")
6336 'gnus-image-category 'shr)))))
6337 (when image
6338 (gnus-add-image 'shr image))))
6339
6340 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6341 "Show attachments as buttons in the end of the header of an article.
6342 This function toggles the display when called interactively. Note that
6343 buttons to be added to the header are only the ones that aren't inlined
6344 in the body. Use `gnus-header-face-alist' to highlight buttons."
6345 (interactive (list t))
6346 (gnus-with-article-buffer
6347 (gmm-labels
6348 ;; Function that returns a flattened version of
6349 ;; `gnus-article-mime-handle-alist'.
6350 ((flattened-alist
6351 (&optional alist id all)
6352 (if alist
6353 (let ((i 1) newid flat)
6354 (dolist (handle alist flat)
6355 (setq newid (append id (list i))
6356 i (1+ i))
6357 (if (stringp (car handle))
6358 (setq flat (nconc flat (flattened-alist (cdr handle)
6359 newid all)))
6360 (delq (rassq handle all) all)
6361 (setq flat (nconc flat (list (cons newid handle)))))))
6362 (let ((flat (list nil)))
6363 ;; Assume that elements of `gnus-article-mime-handle-alist'
6364 ;; are in the decreasing order, but unnumbered subsidiaries
6365 ;; in each element are in the increasing order.
6366 (dolist (handle (reverse gnus-article-mime-handle-alist))
6367 (if (stringp (cadr handle))
6368 (setq flat (nconc flat (flattened-alist (cddr handle)
6369 (list (car handle))
6370 flat)))
6371 (delq (rassq (cdr handle) flat) flat)
6372 (setq flat (nconc flat (list (cons (list (car handle))
6373 (cdr handle)))))))
6374 (setq flat (cdr flat))
6375 (mapc (lambda (handle)
6376 (if (cdar handle)
6377 ;; This is a hidden (i.e. unnumbered) handle.
6378 (progn
6379 (setcar handle
6380 (1+ (caar gnus-article-mime-handle-alist)))
6381 (push handle gnus-article-mime-handle-alist))
6382 (setcar handle (caar handle))))
6383 flat)
6384 flat))))
6385 (let ((case-fold-search t) buttons handle type st)
6386 (save-excursion
6387 (save-restriction
6388 (widen)
6389 (article-narrow-to-head)
6390 ;; Header buttons exist?
6391 (while (and (not buttons)
6392 (re-search-forward "^attachments?:[\n ]+" nil t))
6393 (when (get-char-property (match-end 0)
6394 'gnus-button-attachment-extra)
6395 (setq buttons (match-beginning 0))))
6396 (widen)
6397 (when buttons
6398 ;; Delete header buttons.
6399 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6400 (match-beginning 0)
6401 (point-max))))
6402 (unless (and interactive buttons)
6403 ;; Find buttons.
6404 (setq buttons nil)
6405 (dolist (button (flattened-alist))
6406 (setq handle (cdr button)
6407 type (mm-handle-media-type handle))
6408 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6409 (with-current-buffer gnus-summary-buffer
6410 gnus-inhibit-images)
6411 gnus-inhibit-images)
6412 (string-match "\\`image/" type))
6413 (mm-inline-override-p handle)
6414 (and (mm-handle-disposition handle)
6415 (not (equal (car (mm-handle-disposition handle))
6416 "inline"))
6417 (not (mm-attachment-override-p handle)))
6418 (not (mm-automatic-display-p handle))
6419 (not (or (and (mm-inlinable-p handle)
6420 (mm-inlined-p handle))
6421 (mm-automatic-external-display-p type))))
6422 (push button buttons)))
6423 (when buttons
6424 ;; Add header buttons.
6425 (article-goto-body)
6426 (forward-line -1)
6427 (narrow-to-region (point) (point))
6428 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6429 (dolist (button (nreverse buttons))
6430 (setq st (point))
6431 (insert " ")
6432 (mm-handle-set-undisplayer
6433 (setq handle (copy-sequence (cdr button))) nil)
6434 (gnus-insert-mime-button handle (car button))
6435 (skip-chars-backward "\t\n ")
6436 (delete-region (point) (point-max))
6437 (when (> (current-column) (window-width))
6438 (goto-char st)
6439 (insert "\n")
6440 (end-of-line)))
6441 (insert "\n")
6442 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6443 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6444 (gnus-overlay-put ovl 'face nil))
6445 (let ((gnus-treatment-function-alist
6446 '((gnus-treat-highlight-headers
6447 gnus-article-highlight-headers))))
6448 (gnus-treat-article 'head))))))))))
6449
6450 ;;; Article savers.
6451
6452 (defun gnus-output-to-file (file-name)
6453 "Append the current article to a file named FILE-NAME.
6454 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6455 text and used as the value of the coding cookie which is added to the
6456 top of a file. Otherwise, this function saves a raw article without
6457 the coding cookie."
6458 (let* ((artbuf (current-buffer))
6459 (file-name-coding-system nnmail-pathname-coding-system)
6460 (coding gnus-article-save-coding-system)
6461 (coding-system-for-read (if coding
6462 nil ;; Rely on the coding cookie.
6463 mm-text-coding-system))
6464 (coding-system-for-write (or coding
6465 mm-text-coding-system-for-write
6466 mm-text-coding-system))
6467 (exists (file-exists-p file-name)))
6468 (with-temp-buffer
6469 (when exists
6470 (insert-file-contents file-name)
6471 (goto-char (point-min))
6472 ;; Remove the existing coding cookie.
6473 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6474 (delete-region (match-beginning 0) (match-end 0))))
6475 (goto-char (point-max))
6476 (insert-buffer-substring artbuf)
6477 ;; Append newline at end of the buffer as separator, and then
6478 ;; save it to file.
6479 (goto-char (point-max))
6480 (insert "\n")
6481 (when coding
6482 ;; If the coding system is not suitable to encode the text,
6483 ;; ask a user for a proper one.
6484 (when (fboundp 'select-safe-coding-system)
6485 (setq coding (coding-system-base
6486 (save-window-excursion
6487 (select-safe-coding-system (point-min) (point-max)
6488 coding))))
6489 (setq coding-system-for-write
6490 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6491 coding)))
6492 (goto-char (point-min))
6493 ;; Add the coding cookie.
6494 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6495 coding-system-for-write)))
6496 (if exists
6497 (progn
6498 (write-region (point-min) (point-max) file-name nil 'no-message)
6499 (message "Appended to %s" file-name))
6500 (write-region (point-min) (point-max) file-name))))
6501 t)
6502
6503 (defun gnus-narrow-to-page (&optional arg)
6504 "Narrow the article buffer to a page.
6505 If given a numerical ARG, move forward ARG pages."
6506 (interactive "P")
6507 (setq arg (if arg (prefix-numeric-value arg) 0))
6508 (with-current-buffer gnus-article-buffer
6509 (widen)
6510 ;; Remove any old next/prev buttons.
6511 (when (gnus-visual-p 'page-marker)
6512 (let ((inhibit-read-only t))
6513 (gnus-remove-text-with-property 'gnus-prev)
6514 (gnus-remove-text-with-property 'gnus-next)))
6515 (let (st nd pt)
6516 (when (save-excursion
6517 (cond ((< arg 0)
6518 (if (re-search-backward page-delimiter nil 'move (abs arg))
6519 (prog1
6520 (setq nd (match-beginning 0)
6521 pt nd)
6522 (when (re-search-backward page-delimiter nil t)
6523 (setq st (match-end 0))))
6524 (when (re-search-forward page-delimiter nil t)
6525 (setq nd (match-beginning 0)
6526 pt (point-min)))))
6527 ((> arg 0)
6528 (if (re-search-forward page-delimiter nil 'move arg)
6529 (prog1
6530 (setq st (match-end 0)
6531 pt st)
6532 (when (re-search-forward page-delimiter nil t)
6533 (setq nd (match-beginning 0))))
6534 (when (re-search-backward page-delimiter nil t)
6535 (setq st (match-end 0)
6536 pt (point-max)))))
6537 (t
6538 (when (re-search-backward page-delimiter nil t)
6539 (goto-char (setq st (match-end 0))))
6540 (when (re-search-forward page-delimiter nil t)
6541 (setq nd (match-beginning 0)))
6542 (or st nd))))
6543 (setq gnus-page-broken t)
6544 (when pt (goto-char pt))
6545 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6546 (when (gnus-visual-p 'page-marker)
6547 (save-excursion
6548 (when nd
6549 (goto-char nd)
6550 (gnus-insert-next-page-button))
6551 (when st
6552 (goto-char st)
6553 (gnus-insert-prev-page-button))))))))
6554
6555 ;; Article mode commands
6556
6557 (defun gnus-article-goto-next-page ()
6558 "Show the next page of the article."
6559 (interactive)
6560 (when (gnus-article-next-page)
6561 (goto-char (point-min))
6562 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6563
6564
6565 (defun gnus-article-goto-prev-page ()
6566 "Show the previous page of the article."
6567 (interactive)
6568 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6569 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6570 (gnus-article-prev-page nil)))
6571
6572 ;; This is cleaner but currently breaks `gnus-pick-mode':
6573 ;;
6574 ;; (defun gnus-article-goto-next-page ()
6575 ;; "Show the next page of the article."
6576 ;; (interactive)
6577 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6578 ;; (gnus-summary-next-page)))
6579 ;;
6580 ;; (defun gnus-article-goto-prev-page ()
6581 ;; "Show the next page of the article."
6582 ;; (interactive)
6583 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6584 ;; (gnus-summary-prev-page)))
6585
6586 (defun gnus-article-next-page (&optional lines)
6587 "Show the next page of the current article.
6588 If end of article, return non-nil. Otherwise return nil.
6589 Argument LINES specifies lines to be scrolled up."
6590 (interactive "p")
6591 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6592 (if (and (not (and gnus-article-over-scroll
6593 (> (count-lines (window-start) (point-max))
6594 (if (featurep 'xemacs)
6595 (or lines (1- (window-height)))
6596 (+ (or lines (1- (window-height))) scroll-margin)))))
6597 (save-excursion
6598 (end-of-line)
6599 (and (pos-visible-in-window-p) ;Not continuation line.
6600 (>= (point) (point-max)))))
6601 ;; Nothing in this page.
6602 (if (or (not gnus-page-broken)
6603 (save-excursion
6604 (save-restriction
6605 (widen)
6606 (forward-line)
6607 (eobp)))) ;Real end-of-buffer?
6608 (progn
6609 (when gnus-article-over-scroll
6610 (gnus-article-next-page-1 lines))
6611 t) ;Nothing more.
6612 (gnus-narrow-to-page 1) ;Go to next page.
6613 nil)
6614 ;; More in this page.
6615 (gnus-article-next-page-1 lines)
6616 nil))
6617
6618 (defun gnus-article-beginning-of-window ()
6619 "Move point to the beginning of the window.
6620 In Emacs, the point is placed at the line number which `scroll-margin'
6621 specifies."
6622 (if (featurep 'xemacs)
6623 (move-to-window-line 0)
6624 ;; There is an obscure bug in Emacs that makes it impossible to
6625 ;; scroll past big pictures in the article buffer. Try to fix
6626 ;; this by adding a sanity check by counting the lines visible.
6627 (when (> (count-lines (window-start) (window-end)) 30)
6628 (move-to-window-line
6629 (min (max 0 scroll-margin)
6630 (max 1 (- (window-height)
6631 (if mode-line-format 1 0)
6632 (if header-line-format 1 0)
6633 2)))))))
6634
6635 (defun gnus-article-next-page-1 (lines)
6636 (condition-case ()
6637 (let ((scroll-in-place nil)
6638 (auto-window-vscroll nil))
6639 (scroll-up lines))
6640 (end-of-buffer
6641 ;; Long lines may cause an end-of-buffer error.
6642 (goto-char (point-max))))
6643 (gnus-article-beginning-of-window))
6644
6645 (defun gnus-article-prev-page (&optional lines)
6646 "Show previous page of current article.
6647 Argument LINES specifies lines to be scrolled down."
6648 (interactive "p")
6649 (move-to-window-line 0)
6650 (if (and gnus-page-broken
6651 (bobp)
6652 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6653 (progn
6654 (gnus-narrow-to-page -1) ;Go to previous page.
6655 (goto-char (point-max))
6656 (recenter (if gnus-article-over-scroll
6657 (if lines
6658 (max (if (featurep 'xemacs)
6659 lines
6660 (+ lines scroll-margin))
6661 3)
6662 (- (window-height) 2))
6663 -1)))
6664 (prog1
6665 (condition-case ()
6666 (let ((scroll-in-place nil))
6667 (scroll-down lines))
6668 (beginning-of-buffer
6669 (goto-char (point-min))))
6670 (gnus-article-beginning-of-window))))
6671
6672 (defun gnus-article-only-boring-p ()
6673 "Decide whether there is only boring text remaining in the article.
6674 Something \"interesting\" is a word of at least two letters that does
6675 not have a face in `gnus-article-boring-faces'."
6676 (when (and gnus-article-skip-boring
6677 (boundp 'gnus-article-boring-faces)
6678 (symbol-value 'gnus-article-boring-faces))
6679 (save-excursion
6680 (let ((inhibit-point-motion-hooks t))
6681 (catch 'only-boring
6682 (while (re-search-forward "\\b\\w\\w" nil t)
6683 (forward-char -1)
6684 (when (not (gnus-intersection
6685 (gnus-faces-at (point))
6686 (symbol-value 'gnus-article-boring-faces)))
6687 (throw 'only-boring nil)))
6688 (throw 'only-boring t))))))
6689
6690 (defun gnus-article-refer-article ()
6691 "Read article specified by message-id around point."
6692 (interactive)
6693 (save-excursion
6694 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6695 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6696 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6697 (let ((msg-id (concat "<" (match-string 0) ">")))
6698 (set-buffer gnus-summary-buffer)
6699 (gnus-summary-refer-article msg-id))
6700 (error "No references around point"))))
6701
6702 (defun gnus-article-show-summary ()
6703 "Reconfigure windows to show summary buffer."
6704 (interactive)
6705 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6706 (error "There is no summary buffer for this article buffer")
6707 (gnus-article-set-globals)
6708 (gnus-configure-windows 'article)
6709 (gnus-summary-goto-subject gnus-current-article)
6710 (gnus-summary-position-point)))
6711
6712 (defun gnus-article-describe-briefly ()
6713 "Describe article mode commands briefly."
6714 (interactive)
6715 (gnus-message 6 "%s" (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
6716
6717 (defun gnus-article-check-buffer ()
6718 "Beep if not in an article buffer."
6719 (unless (derived-mode-p 'gnus-article-mode)
6720 (error "Command invoked outside of a Gnus article buffer")))
6721
6722 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6723 "Read a summary buffer key sequence and execute it from the article buffer."
6724 (interactive "P")
6725 (gnus-article-check-buffer)
6726 (let ((nosaves
6727 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6728 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6729 "=" "^" "\M-^" "|"))
6730 (nosave-but-article
6731 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6732 "An" "Ap" [?A (meta return)] [?A delete]))
6733 (nosave-in-article
6734 '("AS" "\C-d"))
6735 (up-to-top
6736 '("n" "Gn" "p" "Gp"))
6737 keys new-sum-point)
6738 (with-current-buffer gnus-article-current-summary
6739 (let (gnus-pick-mode)
6740 (setq unread-command-events (nconc unread-command-events
6741 (list (or key last-command-event)))
6742 keys (if (featurep 'xemacs)
6743 (events-to-keys (read-key-sequence nil t))
6744 (read-key-sequence nil t)))))
6745
6746 (message "")
6747
6748 (cond
6749 ((eq (aref keys (1- (length keys))) ?\C-h)
6750 (gnus-article-describe-bindings (substring keys 0 -1)))
6751 ((or (member keys nosaves)
6752 (member keys nosave-but-article)
6753 (member keys nosave-in-article))
6754 (let (func)
6755 (save-window-excursion
6756 (pop-to-buffer gnus-article-current-summary)
6757 ;; We disable the pick minor mode commands.
6758 (let (gnus-pick-mode)
6759 (setq func (key-binding keys t))))
6760 (if (or (not func)
6761 (numberp func))
6762 (ding)
6763 (unless (member keys nosave-in-article)
6764 (set-buffer gnus-article-current-summary))
6765 (when (and (symbolp func)
6766 (get func 'disabled))
6767 (error "Function %s disabled" func))
6768 (call-interactively func)
6769 (setq new-sum-point (point)))
6770 (when (member keys nosave-but-article)
6771 (pop-to-buffer gnus-article-buffer))))
6772 (t
6773 ;; These commands should restore window configuration.
6774 (let ((obuf (current-buffer))
6775 (owin (current-window-configuration))
6776 win func in-buffer selected new-sum-start new-sum-hscroll err)
6777 (cond (not-restore-window
6778 (pop-to-buffer gnus-article-current-summary)
6779 (setq win (selected-window)))
6780 ((setq win (get-buffer-window gnus-article-current-summary))
6781 (select-window win))
6782 (t
6783 (let ((summary-buffer gnus-article-current-summary))
6784 (gnus-configure-windows 'article)
6785 (unless (setq win (get-buffer-window summary-buffer 'visible))
6786 (let ((gnus-buffer-configuration
6787 '((article ((vertical 1.0
6788 (summary 0.25 point)
6789 (article 1.0)))))))
6790 (gnus-configure-windows 'article))
6791 (setq win (get-buffer-window summary-buffer 'visible)))
6792 (gnus-select-frame-set-input-focus (window-frame win))
6793 (select-window win))))
6794 (setq in-buffer (current-buffer))
6795 ;; We disable the pick minor mode commands.
6796 (setq func (let (gnus-pick-mode)
6797 (key-binding keys t)))
6798 (when (get func 'disabled)
6799 (error "Function %s disabled" func))
6800 (if (and func
6801 (functionp func)
6802 (condition-case code
6803 (progn
6804 (call-interactively func)
6805 t)
6806 (error
6807 (setq err code)
6808 nil)))
6809 (progn
6810 (when (eq win (selected-window))
6811 (setq new-sum-point (point)
6812 new-sum-start (window-start win)
6813 new-sum-hscroll (window-hscroll win)))
6814 (when (or (eq in-buffer (current-buffer))
6815 (when (eq obuf (current-buffer))
6816 (set-buffer in-buffer)
6817 t))
6818 (setq selected (ignore-errors (gnus-summary-select-article)))
6819 (set-buffer obuf)
6820 (unless not-restore-window
6821 (set-window-configuration owin))
6822 (when (and (eq selected 'old)
6823 new-sum-point)
6824 (set-window-start (get-buffer-window (current-buffer))
6825 1)
6826 (set-window-point (get-buffer-window (current-buffer))
6827 (if (article-goto-body)
6828 (1- (point))
6829 (point))))
6830 (when (and (not not-restore-window)
6831 new-sum-point
6832 (window-live-p win)
6833 (with-current-buffer (window-buffer win)
6834 (derived-mode-p 'gnus-summary-mode)))
6835 (set-window-point win new-sum-point)
6836 (set-window-start win new-sum-start)
6837 (set-window-hscroll win new-sum-hscroll))))
6838 (set-window-configuration owin)
6839 (if err
6840 (signal (car err) (cdr err))
6841 (ding))))))))
6842
6843 (defun gnus-article-read-summary-send-keys ()
6844 (interactive)
6845 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6846 (gnus-article-read-summary-keys)))
6847
6848 (defun gnus-article-describe-key (key)
6849 "Display documentation of the function invoked by KEY.
6850 KEY is a string or a vector."
6851 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6852 (read-key-sequence "Describe key: "))))
6853 (gnus-article-check-buffer)
6854 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6855 gnus-article-read-summary-send-keys))
6856 (with-current-buffer gnus-article-current-summary
6857 (setq unread-command-events
6858 (if (featurep 'xemacs)
6859 (append key nil)
6860 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6861 (list 'meta (- x 128))
6862 x))
6863 key)))
6864 (let ((cursor-in-echo-area t)
6865 gnus-pick-mode)
6866 (describe-key (read-key-sequence nil t))))
6867 (describe-key key)))
6868
6869 (defun gnus-article-describe-key-briefly (key &optional insert)
6870 "Display documentation of the function invoked by KEY.
6871 KEY is a string or a vector."
6872 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6873 (read-key-sequence "Describe key: "))
6874 current-prefix-arg))
6875 (gnus-article-check-buffer)
6876 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6877 gnus-article-read-summary-send-keys))
6878 (with-current-buffer gnus-article-current-summary
6879 (setq unread-command-events
6880 (if (featurep 'xemacs)
6881 (append key nil)
6882 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6883 (list 'meta (- x 128))
6884 x))
6885 key)))
6886 (let ((cursor-in-echo-area t)
6887 gnus-pick-mode)
6888 (describe-key-briefly (read-key-sequence nil t) insert)))
6889 (describe-key-briefly key insert)))
6890
6891 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6892 (defvar gnus-agent-summary-mode)
6893 (defvar gnus-draft-mode)
6894 (defvar help-xref-stack-item)
6895
6896 (defun gnus-article-describe-bindings (&optional prefix)
6897 "Show a list of all defined keys, and their definitions.
6898 The optional argument PREFIX, if non-nil, should be a key sequence;
6899 then we display only bindings that start with that prefix."
6900 (interactive)
6901 (gnus-article-check-buffer)
6902 (let ((keymap (copy-keymap gnus-article-mode-map))
6903 (map (copy-keymap gnus-article-send-map))
6904 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6905 parent agent draft)
6906 (define-key keymap "S" map)
6907 (define-key map [t] nil)
6908 (with-current-buffer gnus-article-current-summary
6909 (set-keymap-parent
6910 keymap
6911 (if (setq parent (keymap-parent gnus-article-mode-map))
6912 (prog1
6913 (setq parent (copy-keymap parent))
6914 (set-keymap-parent parent (current-local-map)))
6915 (current-local-map)))
6916 (set-keymap-parent map (key-binding "S"))
6917 (let (key def gnus-pick-mode)
6918 (while sumkeys
6919 (setq key (pop sumkeys))
6920 (cond ((and (vectorp key) (= (length key) 1)
6921 (consp (setq def (aref key 0)))
6922 (numberp (car def)) (numberp (cdr def)))
6923 (when (< (max (car def) (cdr def)) 128)
6924 (setq sumkeys
6925 (append (mapcar
6926 #'vector
6927 (nreverse (gnus-uncompress-range def)))
6928 sumkeys))))
6929 ((setq def (key-binding key))
6930 (unless (eq def 'undefined)
6931 (define-key keymap key def))))))
6932 (when (boundp 'gnus-agent-summary-mode)
6933 (setq agent gnus-agent-summary-mode))
6934 (when (boundp 'gnus-draft-mode)
6935 (setq draft gnus-draft-mode)))
6936 (with-temp-buffer
6937 (use-local-map keymap)
6938 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6939 (set (make-local-variable 'gnus-draft-mode) draft)
6940 (describe-bindings prefix))
6941 (let ((item `((lambda (prefix)
6942 (with-current-buffer ,(current-buffer)
6943 (gnus-article-describe-bindings prefix)))
6944 ,prefix)))
6945 ;; Loading `help-mode' here is necessary if `describe-bindings'
6946 ;; is replaced with something, e.g. `helm-descbinds'.
6947 (require 'help-mode)
6948 (with-current-buffer (let (help-xref-following) (help-buffer))
6949 (setq help-xref-stack-item item)))))
6950
6951 (defun gnus-article-reply-with-original (&optional wide)
6952 "Start composing a reply mail to the current message.
6953 The text in the region will be yanked. If the region isn't active,
6954 the entire article will be yanked."
6955 (interactive)
6956 (let ((article (cdr gnus-article-current))
6957 contents)
6958 (if (not (gnus-region-active-p))
6959 (with-current-buffer gnus-summary-buffer
6960 (gnus-summary-reply (list (list article)) wide))
6961 (setq contents (buffer-substring (point) (mark t)))
6962 ;; Deactivate active regions.
6963 (when (and (boundp 'transient-mark-mode)
6964 transient-mark-mode)
6965 (setq mark-active nil))
6966 (with-current-buffer gnus-summary-buffer
6967 (gnus-summary-reply
6968 (list (list article contents)) wide)))))
6969
6970 (defun gnus-article-wide-reply-with-original ()
6971 "Start composing a wide reply mail to the current message.
6972 The text in the region will be yanked. If the region isn't active,
6973 the entire article will be yanked."
6974 (interactive)
6975 (gnus-article-reply-with-original t))
6976
6977 (defun gnus-article-followup-with-original ()
6978 "Compose a followup to the current article.
6979 The text in the region will be yanked. If the region isn't active,
6980 the entire article will be yanked."
6981 (interactive)
6982 (let ((article (cdr gnus-article-current))
6983 contents)
6984 (if (not (gnus-region-active-p))
6985 (with-current-buffer gnus-summary-buffer
6986 (gnus-summary-followup (list (list article))))
6987 (setq contents (buffer-substring (point) (mark t)))
6988 ;; Deactivate active regions.
6989 (when (and (boundp 'transient-mark-mode)
6990 transient-mark-mode)
6991 (setq mark-active nil))
6992 (with-current-buffer gnus-summary-buffer
6993 (gnus-summary-followup
6994 (list (list article contents)))))))
6995
6996 (defun gnus-article-hide (&optional arg force)
6997 "Hide all the gruft in the current article.
6998 This means that signatures, cited text and (some) headers will be
6999 hidden.
7000 If given a prefix, show the hidden text instead."
7001 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7002 (gnus-article-hide-headers arg)
7003 (gnus-article-hide-list-identifiers arg)
7004 (gnus-article-hide-citation-maybe arg force)
7005 (gnus-article-hide-signature arg))
7006
7007 (defun gnus-check-group-server ()
7008 ;; Make sure the connection to the server is alive.
7009 (unless (gnus-server-opened
7010 (gnus-find-method-for-group gnus-newsgroup-name))
7011 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7012 (gnus-request-group gnus-newsgroup-name t)))
7013
7014 (eval-when-compile
7015 (autoload 'nneething-get-file-name "nneething"))
7016
7017 (defun gnus-request-article-this-buffer (article group)
7018 "Get an article and insert it into this buffer."
7019 (let (do-update-line sparse-header)
7020 (prog1
7021 (save-excursion
7022 (erase-buffer)
7023 (gnus-kill-all-overlays)
7024 (setq group (or group gnus-newsgroup-name))
7025
7026 ;; Using `gnus-request-article' directly will insert the article into
7027 ;; `nntp-server-buffer' - so we'll save some time by not having to
7028 ;; copy it from the server buffer into the article buffer.
7029
7030 ;; We only request an article by message-id when we do not have the
7031 ;; headers for it, so we'll have to get those.
7032 (when (stringp article)
7033 (gnus-read-header article))
7034
7035 ;; If the article number is negative, that means that this article
7036 ;; doesn't belong in this newsgroup (possibly), so we find its
7037 ;; message-id and request it by id instead of number.
7038 (when (and (numberp article)
7039 gnus-summary-buffer
7040 (get-buffer gnus-summary-buffer)
7041 (gnus-buffer-exists-p gnus-summary-buffer))
7042 (with-current-buffer gnus-summary-buffer
7043 (let ((header (gnus-summary-article-header article)))
7044 (when (< article 0)
7045 (cond
7046 ((memq article gnus-newsgroup-sparse)
7047 ;; This is a sparse gap article.
7048 (setq do-update-line article)
7049 (setq article (mail-header-id header))
7050 (setq sparse-header (gnus-read-header article))
7051 (setq gnus-newsgroup-sparse
7052 (delq article gnus-newsgroup-sparse)))
7053 ((vectorp header)
7054 ;; It's a real article.
7055 (setq article (mail-header-id header)))
7056 (t
7057 ;; It is an extracted pseudo-article.
7058 (setq article 'pseudo)
7059 (gnus-request-pseudo-article header))))
7060
7061 (let ((method (gnus-find-method-for-group
7062 gnus-newsgroup-name)))
7063 (when (and (eq (car method) 'nneething)
7064 (vectorp header))
7065 (let ((dir (nneething-get-file-name
7066 (mail-header-id header))))
7067 (when (and (stringp dir)
7068 (file-directory-p dir))
7069 (setq article 'nneething)
7070 (gnus-group-enter-directory dir))))))))
7071
7072 (cond
7073 ;; Refuse to select canceled articles.
7074 ((and (numberp article)
7075 gnus-summary-buffer
7076 (get-buffer gnus-summary-buffer)
7077 (gnus-buffer-exists-p gnus-summary-buffer)
7078 (eq (cdr (with-current-buffer gnus-summary-buffer
7079 (assq article gnus-newsgroup-reads)))
7080 gnus-canceled-mark))
7081 nil)
7082 ;; We first check `gnus-original-article-buffer'.
7083 ((and (get-buffer gnus-original-article-buffer)
7084 (numberp article)
7085 (with-current-buffer gnus-original-article-buffer
7086 (and (equal (car gnus-original-article) group)
7087 (eq (cdr gnus-original-article) article))))
7088 ;; `insert-buffer-substring' would incorrectly use the
7089 ;; equivalent of string-make-multibyte which amount to decoding
7090 ;; with locale-coding-system, causing failure of
7091 ;; subsequent decoding.
7092 (insert (mm-string-to-multibyte
7093 (with-current-buffer gnus-original-article-buffer
7094 (buffer-substring (point-min) (point-max)))))
7095 'article)
7096 ;; Check the backlog.
7097 ((and gnus-keep-backlog
7098 (gnus-backlog-request-article group article (current-buffer)))
7099 'article)
7100 ;; Check asynchronous pre-fetch.
7101 ((gnus-async-request-fetched-article group article (current-buffer))
7102 (gnus-async-prefetch-next group article gnus-summary-buffer)
7103 (when (and (numberp article) gnus-keep-backlog)
7104 (gnus-backlog-enter-article group article (current-buffer)))
7105 'article)
7106 ;; Check the cache.
7107 ((and gnus-use-cache
7108 (numberp article)
7109 (gnus-cache-request-article article group))
7110 'article)
7111 ;; Check the agent cache.
7112 ((gnus-agent-request-article article group)
7113 'article)
7114 ;; Get the article and put into the article buffer.
7115 ((or (stringp article)
7116 (numberp article))
7117 (let ((gnus-override-method gnus-override-method)
7118 (methods (and (stringp article)
7119 (with-current-buffer gnus-summary-buffer
7120 (gnus-refer-article-methods))))
7121 (backend (car (gnus-find-method-for-group
7122 gnus-newsgroup-name)))
7123 result
7124 (inhibit-read-only t))
7125 (when (and (null gnus-override-method)
7126 methods)
7127 (setq gnus-override-method (pop methods)))
7128 (while (not result)
7129 (erase-buffer)
7130 (gnus-kill-all-overlays)
7131 (let ((gnus-newsgroup-name group))
7132 (gnus-check-group-server))
7133 (cond
7134 ((gnus-request-article article group (current-buffer))
7135 (when (numberp article)
7136 (gnus-async-prefetch-next group article
7137 gnus-summary-buffer)
7138 (when gnus-keep-backlog
7139 (gnus-backlog-enter-article
7140 group article (current-buffer)))
7141 (when (and gnus-agent
7142 (gnus-agent-group-covered-p group))
7143 (gnus-agent-store-article article group)))
7144 (setq result 'article))
7145 (methods
7146 (setq gnus-override-method (pop methods)))
7147 ((not (string-match "^400 "
7148 (nnheader-get-report backend)))
7149 ;; If we get 400 server disconnect, reconnect and
7150 ;; retry; otherwise, assume the article has expired.
7151 (setq result 'done))))
7152 (and (eq result 'article) 'article)))
7153 ;; It was a pseudo.
7154 (t article)))
7155
7156 ;; Associate this article with the current summary buffer.
7157 (setq gnus-article-current-summary gnus-summary-buffer)
7158
7159 ;; Take the article from the original article buffer
7160 ;; and place it in the buffer it's supposed to be in.
7161 (when (and (get-buffer gnus-article-buffer)
7162 (equal (buffer-name (current-buffer))
7163 (buffer-name (get-buffer gnus-article-buffer))))
7164 (save-excursion
7165 (if (get-buffer gnus-original-article-buffer)
7166 (set-buffer gnus-original-article-buffer)
7167 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7168 (buffer-disable-undo)
7169 (setq major-mode 'gnus-original-article-mode)
7170 (setq buffer-read-only t))
7171 (let ((inhibit-read-only t))
7172 (erase-buffer)
7173 (insert-buffer-substring gnus-article-buffer))
7174 (setq gnus-original-article (cons group article)))
7175
7176 ;; Decode charsets.
7177 (run-hooks 'gnus-article-decode-hook)
7178 ;; Mark article as decoded or not.
7179 (setq gnus-article-decoded-p gnus-article-decode-hook))
7180
7181 ;; Update sparse articles.
7182 (when (and do-update-line
7183 (or (numberp article)
7184 (stringp article)))
7185 (let ((buf (current-buffer)))
7186 (set-buffer gnus-summary-buffer)
7187 (gnus-summary-update-article do-update-line sparse-header)
7188 (gnus-summary-goto-subject do-update-line nil t)
7189 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7190 (point))
7191 (set-buffer buf))))))
7192
7193 (defun gnus-block-private-groups (group)
7194 (if (or (gnus-news-group-p group)
7195 (gnus-member-of-valid 'global group))
7196 ;; Block nothing in news groups.
7197 nil
7198 ;; Block everything anywhere else.
7199 "."))
7200
7201 (defun gnus-blocked-images ()
7202 (if (functionp gnus-blocked-images)
7203 (funcall gnus-blocked-images gnus-newsgroup-name)
7204 gnus-blocked-images))
7205
7206 ;;;
7207 ;;; Article editing
7208 ;;;
7209
7210 (defcustom gnus-article-edit-mode-hook nil
7211 "Hook run in article edit mode buffers."
7212 :group 'gnus-article-various
7213 :type 'hook)
7214
7215 (defvar gnus-article-edit-done-function nil)
7216
7217 (defvar gnus-article-edit-mode-map nil)
7218
7219 ;; Should we be using derived.el for this?
7220 (unless gnus-article-edit-mode-map
7221 (setq gnus-article-edit-mode-map (make-keymap))
7222 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7223
7224 (gnus-define-keys gnus-article-edit-mode-map
7225 "\C-c?" describe-mode
7226 "\C-c\C-c" gnus-article-edit-done
7227 "\C-c\C-k" gnus-article-edit-exit
7228 "\C-c\C-f\C-t" message-goto-to
7229 "\C-c\C-f\C-o" message-goto-from
7230 "\C-c\C-f\C-b" message-goto-bcc
7231 ;;"\C-c\C-f\C-w" message-goto-fcc
7232 "\C-c\C-f\C-c" message-goto-cc
7233 "\C-c\C-f\C-s" message-goto-subject
7234 "\C-c\C-f\C-r" message-goto-reply-to
7235 "\C-c\C-f\C-n" message-goto-newsgroups
7236 "\C-c\C-f\C-d" message-goto-distribution
7237 "\C-c\C-f\C-f" message-goto-followup-to
7238 "\C-c\C-f\C-m" message-goto-mail-followup-to
7239 "\C-c\C-f\C-k" message-goto-keywords
7240 "\C-c\C-f\C-u" message-goto-summary
7241 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7242 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7243 "\C-c\C-b" message-goto-body
7244 "\C-c\C-i" message-goto-signature
7245
7246 "\C-c\C-t" message-insert-to
7247 "\C-c\C-n" message-insert-newsgroups
7248 "\C-c\C-o" message-sort-headers
7249 "\C-c\C-e" message-elide-region
7250 "\C-c\C-v" message-delete-not-region
7251 "\C-c\C-z" message-kill-to-signature
7252 "\M-\r" message-newline-and-reformat
7253 "\C-c\C-a" mml-attach-file
7254 "\C-a" message-beginning-of-line
7255 "\t" message-tab
7256 "\M-;" comment-region)
7257
7258 (gnus-define-keys (gnus-article-edit-wash-map
7259 "\C-c\C-w" gnus-article-edit-mode-map)
7260 "f" gnus-article-edit-full-stops))
7261
7262 (easy-menu-define
7263 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7264 '("Field"
7265 ["Fetch To" message-insert-to t]
7266 ["Fetch Newsgroups" message-insert-newsgroups t]
7267 "----"
7268 ["To" message-goto-to t]
7269 ["From" message-goto-from t]
7270 ["Subject" message-goto-subject t]
7271 ["Cc" message-goto-cc t]
7272 ["Reply-To" message-goto-reply-to t]
7273 ["Summary" message-goto-summary t]
7274 ["Keywords" message-goto-keywords t]
7275 ["Newsgroups" message-goto-newsgroups t]
7276 ["Followup-To" message-goto-followup-to t]
7277 ["Mail-Followup-To" message-goto-mail-followup-to t]
7278 ["Distribution" message-goto-distribution t]
7279 ["Body" message-goto-body t]
7280 ["Signature" message-goto-signature t]))
7281
7282 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7283 "Major mode for editing articles.
7284 This is an extended text-mode.
7285
7286 \\{gnus-article-edit-mode-map}"
7287 (make-local-variable 'gnus-article-edit-done-function)
7288 (make-local-variable 'gnus-prev-winconf)
7289 (set (make-local-variable 'font-lock-defaults)
7290 '(message-font-lock-keywords t))
7291 (set (make-local-variable 'mail-header-separator) "")
7292 (set (make-local-variable 'gnus-article-edit-mode) t)
7293 (easy-menu-add message-mode-field-menu message-mode-map)
7294 (mml-mode)
7295 (setq buffer-read-only nil)
7296 (buffer-enable-undo)
7297 (widen))
7298
7299 (defun gnus-article-edit (&optional force)
7300 "Edit the current article.
7301 This will have permanent effect only in mail groups.
7302 If FORCE is non-nil, allow editing of articles even in read-only
7303 groups."
7304 (interactive "P")
7305 (when (and (not force)
7306 (gnus-group-read-only-p))
7307 (error "The current newsgroup does not support article editing"))
7308 (gnus-article-date-original)
7309 (gnus-article-edit-article
7310 'ignore
7311 `(lambda (no-highlight)
7312 'ignore
7313 (gnus-summary-edit-article-done
7314 ,(or (mail-header-references gnus-current-headers) "")
7315 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7316
7317 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7318 "Start editing the contents of the current article buffer."
7319 (let ((winconf (current-window-configuration)))
7320 (set-buffer gnus-article-buffer)
7321 (let ((message-auto-save-directory
7322 ;; Don't associate the article buffer with a draft file.
7323 nil))
7324 (gnus-article-edit-mode))
7325 (funcall start-func)
7326 (set-buffer-modified-p nil)
7327 (gnus-configure-windows 'edit-article)
7328 (setq gnus-article-edit-done-function exit-func)
7329 (setq gnus-prev-winconf winconf)
7330 (unless quiet
7331 (gnus-message 6 "C-c C-c to end edits"))))
7332
7333 (defun gnus-article-edit-done (&optional arg)
7334 "Update the article edits and exit."
7335 (interactive "P")
7336 (let ((func gnus-article-edit-done-function)
7337 (buf (current-buffer))
7338 (start (window-start))
7339 (p (point))
7340 (winconf gnus-prev-winconf))
7341 (widen) ;; Widen it in case that users narrowed the buffer.
7342 (funcall func arg)
7343 (set-buffer buf)
7344 ;; The cache and backlog have to be flushed somewhat.
7345 (when gnus-keep-backlog
7346 (gnus-backlog-remove-article
7347 (car gnus-article-current) (cdr gnus-article-current)))
7348 ;; Flush original article as well.
7349 (gnus-flush-original-article-buffer)
7350 (when gnus-use-cache
7351 (gnus-cache-update-article
7352 (car gnus-article-current) (cdr gnus-article-current)))
7353 ;; We remove all text props from the article buffer.
7354 (kill-all-local-variables)
7355 (set-text-properties (point-min) (point-max) nil)
7356 (gnus-article-mode)
7357 (set-window-configuration winconf)
7358 (set-buffer buf)
7359 (set-window-start (get-buffer-window buf) start)
7360 (set-window-point (get-buffer-window buf) (point)))
7361 (gnus-summary-show-article))
7362
7363 (defun gnus-flush-original-article-buffer ()
7364 (when (get-buffer gnus-original-article-buffer)
7365 (with-current-buffer gnus-original-article-buffer
7366 (setq gnus-original-article nil))))
7367
7368 (defun gnus-article-edit-exit ()
7369 "Exit the article editing without updating."
7370 (interactive)
7371 (when (or (not (buffer-modified-p))
7372 (yes-or-no-p "Article modified; kill anyway? "))
7373 (let ((curbuf (current-buffer))
7374 (p (point))
7375 (window-start (window-start)))
7376 (erase-buffer)
7377 (if (gnus-buffer-live-p gnus-original-article-buffer)
7378 (insert-buffer-substring gnus-original-article-buffer))
7379 (let ((winconf gnus-prev-winconf))
7380 (kill-all-local-variables)
7381 (gnus-article-mode)
7382 (set-window-configuration winconf)
7383 ;; Tippy-toe some to make sure that point remains where it was.
7384 (save-current-buffer
7385 (set-buffer curbuf)
7386 (set-window-start (get-buffer-window (current-buffer)) window-start)
7387 (goto-char p))))
7388 (gnus-summary-show-article)))
7389
7390 (defun gnus-article-edit-full-stops ()
7391 "Interactively repair spacing at end of sentences."
7392 (interactive)
7393 (save-excursion
7394 (goto-char (point-min))
7395 (search-forward-regexp "^$" nil t)
7396 (let ((case-fold-search nil))
7397 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7398
7399 ;;;
7400 ;;; Article highlights
7401 ;;;
7402
7403 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7404
7405 ;;; Internal Variables:
7406
7407 (defcustom gnus-button-url-regexp
7408 (concat
7409 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7410 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7411 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7412 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7413 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7414 (punct "!?:;.,"))
7415 (concat
7416 "\\(?:"
7417 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7418 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7419 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7420 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7421 "\\|"
7422 "[" chars punct "]+" "[" chars "]"
7423 "\\)"))
7424 (concat ;; XEmacs 21.4 doesn't support POSIX.
7425 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7426 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7427 "\\)")
7428 "Regular expression that matches URLs."
7429 :version "24.4"
7430 :group 'gnus-article-buttons
7431 :type 'regexp)
7432
7433 (defcustom gnus-button-valid-fqdn-regexp
7434 message-valid-fqdn-regexp
7435 "Regular expression that matches a valid FQDN."
7436 :version "22.1"
7437 :group 'gnus-article-buttons
7438 :type 'regexp)
7439
7440 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7441 (defcustom gnus-button-valid-localpart-regexp
7442 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7443 "Regular expression that matches a localpart of mail addresses or MIDs."
7444 :version "22.1"
7445 :group 'gnus-article-buttons
7446 :type 'regexp)
7447
7448 (defcustom gnus-button-man-handler 'manual-entry
7449 "Function to use for displaying man pages.
7450 The function must take at least one argument with a string naming the
7451 man page."
7452 :version "22.1"
7453 :type '(choice (function-item :tag "Man" manual-entry)
7454 (function-item :tag "Woman" woman)
7455 (function :tag "Other"))
7456 :group 'gnus-article-buttons)
7457
7458 (defcustom gnus-button-mid-or-mail-regexp
7459 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7460 gnus-button-valid-fqdn-regexp
7461 ">?\\)\\b")
7462 "Regular expression that matches a message ID or a mail address."
7463 :version "22.1"
7464 :group 'gnus-article-buttons
7465 :type 'regexp)
7466
7467 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7468 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7469 Strings like this can be either a message ID or a mail address. If it is one
7470 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7471 message ID or a mail address, respectively. If this variable is set to the
7472 symbol `ask', always query the user what do do. If it is a function, this
7473 function will be called with the string as its only argument. The function
7474 must return `mid', `mail', `invalid' or `ask'."
7475 :version "22.1"
7476 :group 'gnus-article-buttons
7477 :type '(choice (function-item :tag "Heuristic function"
7478 gnus-button-mid-or-mail-heuristic)
7479 (const ask)
7480 (const mid)
7481 (const mail)))
7482
7483 (defcustom gnus-button-mid-or-mail-heuristic-alist
7484 '((-10.0 . ".+\\$.+@")
7485 (-10.0 . "#")
7486 (-10.0 . "\\*")
7487 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7488 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7489 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7490 (-1.0 . "^[^a-z]+@")
7491 ;;
7492 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7493 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7494 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7495 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7496 ;;
7497 (-2.0 . "^[0-9]")
7498 (-1.0 . "^[0-9][0-9]")
7499 ;;
7500 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7501 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7502 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7503 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7504 ;;
7505 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7506 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7507 ;; "[0-9]{8,}.*\@"
7508 (-3.0
7509 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7510 ;; "[0-9]{12,}.*\@"
7511 ;; compensation for TDMA dated mail addresses:
7512 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7513 ;;
7514 (-20.0 . "\\.fsf@") ;; Gnus
7515 (-20.0 . "^slrn")
7516 (-20.0 . "^Pine")
7517 (-20.0 . "^alpine\\.")
7518 (-20.0 . "_-_") ;; Subject change in thread
7519 ;;
7520 (-20.0 . "\\.ln@") ;; leafnode
7521 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7522 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7523 ;;
7524 ;; (5.0 . "") ;; $local_part_len <= 7
7525 (10.0 . "^[^0-9]+@")
7526 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7527 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7528 (3.0 . "\@stud")
7529 ;;
7530 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7531 ;;
7532 (0.5 . "^[A-Z][a-z]")
7533 (0.5 . "^[A-Z][a-z][a-z]")
7534 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7535 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7536 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7537
7538 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7539 address. The REGEXP is processed with `case-fold-search' set to nil."
7540 :version "22.1"
7541 :group 'gnus-article-buttons
7542 :type '(repeat (cons (number :tag "Rate")
7543 (regexp :tag "Regexp"))))
7544
7545 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7546 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7547 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7548 address, `ask' if unsure and `invalid' if the string is invalid."
7549 (let ((case-fold-search nil)
7550 (list gnus-button-mid-or-mail-heuristic-alist)
7551 (result 0) rate regexp lpartlen elem)
7552 (setq lpartlen
7553 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7554 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7555 ;; Certain special cases...
7556 (when (string-match
7557 (concat
7558 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7559 "^[0-9]+\\.[0-9]+@compuserve\\|"
7560 "@public\\.gmane\\.org")
7561 mid-or-mail)
7562 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7563 (setq result 'mail))
7564 (when (string-match "@.*@\\| " mid-or-mail)
7565 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7566 (setq result 'invalid))
7567 ;; Nothing more to do, if result is not a number here...
7568 (when (numberp result)
7569 (while list
7570 (setq elem (car list)
7571 rate (car elem)
7572 regexp (cdr elem)
7573 list (cdr list))
7574 (when (string-match regexp mid-or-mail)
7575 (setq result (+ result rate))
7576 (gnus-message
7577 9 "`%s' matched `%s', rate `%s', result `%s'."
7578 mid-or-mail regexp rate result)))
7579 (when (<= lpartlen 7)
7580 (setq result (+ result 5.0))
7581 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7582 mid-or-mail result))
7583 (when (>= lpartlen 12)
7584 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7585 (cond
7586 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7587 ;; Long local part should contain realname if e-mail address,
7588 ;; too many digits: message-id.
7589 ;; $score -= 5.0 + 0.1 * $local_part_len;
7590 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7591 (setq result (+ result rate))
7592 (gnus-message
7593 9 "Many digits in `%s', rate `%s', result `%s'."
7594 mid-or-mail rate result))
7595 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7596 mid-or-mail)
7597 ;; Too few vowels [^aeiouy]{4,}.*\@
7598 (setq result (+ result -5.0))
7599 (gnus-message
7600 9 "Few vowels in `%s', rate `%s', result `%s'."
7601 mid-or-mail -5.0 result))
7602 (t
7603 (setq result (+ result 5.0))
7604 (gnus-message
7605 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7606 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7607 ;; Maybe we should make this a customizable alist: (condition . 'result)
7608 (cond
7609 ((symbolp result) result)
7610 ;; Now convert number into proper results:
7611 ((< result -10.0) 'mid)
7612 ((> result 10.0) 'mail)
7613 (t 'ask))))
7614
7615 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7616 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7617 (url-mid (concat "news" ":" mid-or-mail))
7618 (url-mailto (concat "mailto" ":" mid-or-mail)))
7619 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7620 (when (fboundp pref)
7621 (setq guessed
7622 ;; get rid of surrounding angles...
7623 (funcall pref
7624 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7625 (if (or (eq 'mid guessed) (eq 'mail guessed))
7626 (setq pref guessed)
7627 (setq pref 'ask)))
7628 (if (eq pref 'ask)
7629 (save-window-excursion
7630 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7631 (setq pref 'mail)
7632 (setq pref 'mid))))
7633 (cond ((eq pref 'mid)
7634 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7635 (gnus-button-handle-news url-mid))
7636 ((eq pref 'mail)
7637 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7638 (gnus-url-mailto url-mailto))
7639 (t (gnus-message 3 "Invalid string.")))))
7640
7641 (defun gnus-button-handle-custom (fun arg)
7642 "Call function FUN on argument ARG.
7643 Both FUN and ARG are supposed to be strings. ARG will be passed
7644 as a symbol to FUN."
7645 (funcall (intern fun)
7646 (if (string-match "^customize-apropos" fun)
7647 arg
7648 (intern arg))))
7649
7650 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7651
7652 (defun gnus-button-handle-describe-function (url)
7653 "Call `describe-function' when pushing the corresponding URL button."
7654 (describe-function
7655 (intern
7656 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7657
7658 (defun gnus-button-handle-describe-variable (url)
7659 "Call `describe-variable' when pushing the corresponding URL button."
7660 (describe-variable
7661 (intern
7662 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7663
7664 (defun gnus-button-handle-symbol (url)
7665 "Display help on variable or function.
7666 Calls `describe-variable' or `describe-function'."
7667 (let ((sym (intern url)))
7668 (cond
7669 ((fboundp sym) (describe-function sym))
7670 ((boundp sym) (describe-variable sym))
7671 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7672
7673 (defun gnus-button-handle-describe-key (url)
7674 "Call `describe-key' when pushing the corresponding URL button."
7675 (let* ((key-string
7676 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7677 (keys (ignore-errors (eval `(kbd ,key-string)))))
7678 (if keys
7679 (describe-key keys)
7680 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7681
7682 (defun gnus-button-handle-apropos (url)
7683 "Call `apropos' when pushing the corresponding URL button."
7684 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7685
7686 (defun gnus-button-handle-apropos-command (url)
7687 "Call `apropos' when pushing the corresponding URL button."
7688 (apropos-command
7689 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7690
7691 (defun gnus-button-handle-apropos-variable (url)
7692 "Call `apropos' when pushing the corresponding URL button."
7693 (funcall
7694 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7695 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7696
7697 (defun gnus-button-handle-apropos-documentation (url)
7698 "Call `apropos' when pushing the corresponding URL button."
7699 (funcall
7700 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7701 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7702
7703 (defun gnus-button-handle-library (url)
7704 "Call `locate-library' when pushing the corresponding URL button."
7705 (gnus-message 9 "url=`%s'" url)
7706 (let* ((lib (locate-library url))
7707 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7708 (if (not lib)
7709 (gnus-message 1 "Cannot locale library `%s'." url)
7710 (find-file-read-only file))))
7711
7712 (defcustom gnus-button-man-level 5
7713 "*Integer that says how many man-related buttons Gnus will show.
7714 The higher the number, the more buttons will appear and the more false
7715 positives are possible. Note that you can set this variable local to
7716 specific groups. Setting it higher in Unix groups is probably a good idea.
7717 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7718 how to set variables in specific groups."
7719 :version "22.1"
7720 :group 'gnus-article-buttons
7721 :link '(custom-manual "(gnus)Group Parameters")
7722 :type 'integer)
7723
7724 (defcustom gnus-button-emacs-level 5
7725 "*Integer that says how many emacs-related buttons Gnus will show.
7726 The higher the number, the more buttons will appear and the more false
7727 positives are possible. Note that you can set this variable local to
7728 specific groups. Setting it higher in Emacs or Gnus related groups is
7729 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7730 `gnus-parameters' on how to set variables in specific groups."
7731 :version "22.1"
7732 :group 'gnus-article-buttons
7733 :link '(custom-manual "(gnus)Group Parameters")
7734 :type 'integer)
7735
7736 (defcustom gnus-button-message-level 5
7737 "*Integer that says how many buttons for news or mail messages will appear.
7738 The higher the number, the more buttons will appear and the more false
7739 positives are possible."
7740 ;; mail addresses, MIDs, URLs for news, ...
7741 :version "22.1"
7742 :group 'gnus-article-buttons
7743 :type 'integer)
7744
7745 (defcustom gnus-button-browse-level 5
7746 "*Integer that says how many buttons for browsing will appear.
7747 The higher the number, the more buttons will appear and the more false
7748 positives are possible."
7749 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7750 :version "22.1"
7751 :group 'gnus-article-buttons
7752 :type 'integer)
7753
7754 (defcustom gnus-button-alist
7755 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7756 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7757 ((concat "\\b\\(nntp\\|news\\):\\("
7758 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7759 0 t gnus-button-handle-news 2)
7760 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7761 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7762 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7763 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7764 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7765 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7766 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7767 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7768 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7769 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7770 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7771 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7772 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7773 ;; RFC 2368 (The mailto URL scheme)
7774 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7775 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7776 ("\\bmailto:\\([^ \n\t]+\\)"
7777 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7778 ;; Info Konqueror style <info:/foo/bar baz>.
7779 ;; Must come before " Gnus home-grown style".
7780 ("\\binfo://?\\([^'\">\n\t]+\\)"
7781 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7782 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7783 ("\\binfo://\\([^'\">\n\t ]+\\)"
7784 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7785 ;; Info GNOME style <info:foo#bar_baz>
7786 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7787 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7788 ;; Info KDE style <info:(foo)bar baz>
7789 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7790 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7791 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7792 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7793 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
7794 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7795 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7796 ;; This is custom
7797 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7798 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7799 ;; Emacs help commands
7800 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7801 ;; regexp doesn't match arguments containing ` '.
7802 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7803 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7804 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7805 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7806 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7807 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7808 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7809 ;; The following entries may lead to many false positives so don't enable
7810 ;; them by default (use a high button level).
7811 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7812 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7813 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7814 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7815 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7816 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7817 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7818 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7819 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7820 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7821 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7822 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7823 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7824 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7825 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7826 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7827 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7828 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7829 ;; Unlike the other regexps we really have to require quoting
7830 ;; here to determine where it ends.
7831 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7832 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7833 ("<URL: *\\([^\n<>]*\\)>"
7834 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7835 ;; RFC 2396 (2.4.3., delims) ...
7836 ("\"URL: *\\([^\n\"]*\\)\""
7837 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7838 ;; Raw URLs.
7839 (gnus-button-url-regexp
7840 0 (>= gnus-button-browse-level 0) browse-url 0)
7841 ;; man pages
7842 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7843 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7844 gnus-button-handle-man 1)
7845 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7846 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7847 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7848 gnus-button-handle-man 1)
7849 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7850 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7851 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7852 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7853 ;; Recognizing patches to .el files. This is somewhat obscure,
7854 ;; but considering the percentage of Gnus users who hack Emacs
7855 ;; Lisp files...
7856 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7857 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7858 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7859 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7860 ;; MID or mail: To avoid too many false positives we don't try to catch
7861 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7862 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7863 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7864 ;; so that non-ambiguous entries (see above) match first.
7865 (gnus-button-mid-or-mail-regexp
7866 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7867 "*Alist of regexps matching buttons in article bodies.
7868
7869 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7870 REGEXP: is the string (case insensitive) matching text around the button (can
7871 also be Lisp expression evaluating to a string),
7872 BUTTON: is the number of the regexp grouping actually matching the button,
7873 FORM: is a Lisp expression which must eval to true for the button to
7874 be added,
7875 CALLBACK: is the function to call when the user push this button, and each
7876 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7877
7878 CALLBACK can also be a variable, in that case the value of that
7879 variable it the real callback function."
7880 :group 'gnus-article-buttons
7881 :type '(repeat (list (choice regexp variable sexp)
7882 (integer :tag "Button")
7883 (sexp :tag "Form")
7884 (function :tag "Callback")
7885 (repeat :tag "Par"
7886 :inline t
7887 (integer :tag "Regexp group")))))
7888 (put 'gnus-button-alist 'risky-local-variable t)
7889
7890 (defcustom gnus-header-button-alist
7891 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7892 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7893 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7894 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7895 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7896 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7897 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7898 0 (>= gnus-button-browse-level 0) browse-url 0)
7899 ("^Subject:" gnus-button-url-regexp
7900 0 (>= gnus-button-browse-level 0) browse-url 0)
7901 ("^[^:]+:" gnus-button-url-regexp
7902 0 (>= gnus-button-browse-level 0) browse-url 0)
7903 ("^OpenPGP:.*url=" gnus-button-url-regexp
7904 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7905 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7906 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7907 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7908 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7909 "*Alist of headers and regexps to match buttons in article heads.
7910
7911 This alist is very similar to `gnus-button-alist', except that each
7912 alist has an additional HEADER element first in each entry:
7913
7914 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7915
7916 HEADER is a regexp to match a header. For a fuller explanation, see
7917 `gnus-button-alist'."
7918 :group 'gnus-article-buttons
7919 :group 'gnus-article-headers
7920 :type '(repeat (list (regexp :tag "Header")
7921 (choice regexp variable)
7922 (integer :tag "Button")
7923 (sexp :tag "Form")
7924 (function :tag "Callback")
7925 (repeat :tag "Par"
7926 :inline t
7927 (integer :tag "Regexp group")))))
7928 (put 'gnus-header-button-alist 'risky-local-variable t)
7929
7930 ;;; Commands:
7931
7932 (defun gnus-article-push-button (event)
7933 "Check text under the mouse pointer for a callback function.
7934 If the text under the mouse pointer has a `gnus-callback' property,
7935 call it with the value of the `gnus-data' text property."
7936 (interactive "e")
7937 (set-buffer (window-buffer (posn-window (event-start event))))
7938 (let* ((pos (posn-point (event-start event)))
7939 (data (get-text-property pos 'gnus-data))
7940 (fun (get-text-property pos 'gnus-callback)))
7941 (goto-char pos)
7942 (when fun
7943 (funcall fun data))))
7944
7945 (defun gnus-article-press-button ()
7946 "Check text at point for a callback function.
7947 If the text at point has a `gnus-callback' property,
7948 call it with the value of the `gnus-data' text property."
7949 (interactive)
7950 (let ((data (get-text-property (point) 'gnus-data))
7951 (fun (get-text-property (point) 'gnus-callback)))
7952 (when fun
7953 (funcall fun data))))
7954
7955 (defun gnus-article-highlight (&optional force)
7956 "Highlight current article.
7957 This function calls `gnus-article-highlight-headers',
7958 `gnus-article-highlight-citation',
7959 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7960 do the highlighting. See the documentation for those functions."
7961 (interactive (list 'force))
7962 (gnus-article-highlight-headers)
7963 (gnus-article-highlight-citation force)
7964 (gnus-article-highlight-signature)
7965 (gnus-article-add-buttons)
7966 (gnus-article-add-buttons-to-head))
7967
7968 (defun gnus-article-highlight-some (&optional force)
7969 "Highlight current article.
7970 This function calls `gnus-article-highlight-headers',
7971 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7972 do the highlighting. See the documentation for those functions."
7973 (interactive (list 'force))
7974 (gnus-article-highlight-headers)
7975 (gnus-article-highlight-signature)
7976 (gnus-article-add-buttons))
7977
7978 (defun gnus-article-highlight-headers ()
7979 "Highlight article headers as specified by `gnus-header-face-alist'."
7980 (interactive)
7981 (gnus-with-article-headers
7982 (let (regexp header-face field-face from hpoints fpoints)
7983 (dolist (entry gnus-header-face-alist)
7984 (goto-char (point-min))
7985 (setq regexp (concat "^\\("
7986 (if (string-equal "" (nth 0 entry))
7987 "[^\t ]"
7988 (nth 0 entry))
7989 "\\)")
7990 header-face (nth 1 entry)
7991 field-face (nth 2 entry))
7992 (while (and (re-search-forward regexp nil t)
7993 (not (eobp)))
7994 (beginning-of-line)
7995 (setq from (point))
7996 (unless (search-forward ":" nil t)
7997 (forward-char 1))
7998 (when (and header-face
7999 (not (memq (point) hpoints)))
8000 (push (point) hpoints)
8001 (gnus-put-text-property from (point) 'face header-face))
8002 (when (and field-face
8003 (not (memq (setq from (point)) fpoints)))
8004 (push from fpoints)
8005 (if (re-search-forward "^[^ \t]" nil t)
8006 (forward-char -2)
8007 (goto-char (point-max)))
8008 (gnus-put-text-property from (point) 'face field-face)))))))
8009
8010 (defun gnus-article-highlight-signature ()
8011 "Highlight the signature in an article.
8012 It does this by highlighting everything after
8013 `gnus-signature-separator' using the face `gnus-signature'."
8014 (interactive)
8015 (gnus-with-article-buffer
8016 (let ((inhibit-point-motion-hooks t))
8017 (save-restriction
8018 (when (and gnus-signature-face
8019 (gnus-article-narrow-to-signature))
8020 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8021 'face gnus-signature-face)
8022 (widen)
8023 (gnus-article-search-signature)
8024 (let ((start (match-beginning 0))
8025 (end (set-marker (make-marker) (1+ (match-end 0)))))
8026 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8027 end)))))))
8028
8029 (defun gnus-button-in-region-p (b e prop)
8030 "Say whether PROP exists in the region."
8031 (text-property-not-all b e prop nil))
8032
8033 (defun gnus-article-add-buttons ()
8034 "Find external references in the article and make buttons of them.
8035 \"External references\" are things like Message-IDs and URLs, as
8036 specified by `gnus-button-alist'."
8037 (interactive)
8038 (gnus-with-article-buffer
8039 (let ((inhibit-point-motion-hooks t)
8040 (case-fold-search t)
8041 (alist gnus-button-alist)
8042 beg entry regexp)
8043 ;; We skip the headers.
8044 (article-goto-body)
8045 (setq beg (point))
8046 (while (setq entry (pop alist))
8047 (setq regexp (eval (car entry)))
8048 (goto-char beg)
8049 (while (re-search-forward regexp nil t)
8050 (let ((start (match-beginning (nth 1 entry)))
8051 (end (match-end (nth 1 entry)))
8052 (from (match-beginning 0)))
8053 (when (and (eval (nth 2 entry))
8054 (not (gnus-button-in-region-p
8055 start end 'gnus-callback)))
8056 ;; That optional form returned non-nil, so we add the
8057 ;; button.
8058 (setq from (set-marker (make-marker) from))
8059 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8060 (gnus-article-extend-url-button from start end))
8061 (gnus-article-add-button start end
8062 'gnus-button-push (list from entry))
8063 (gnus-put-text-property
8064 start end
8065 'gnus-string (buffer-substring-no-properties
8066 start end))))))))))
8067
8068 (defun gnus-article-extend-url-button (beg start end)
8069 "Extend url button if url is folded into two or more lines.
8070 Return non-nil if button is extended. BEG is a marker that points to
8071 the beginning position of a text containing url. START and END are
8072 the endpoints of a url button before it is extended. The concatenated
8073 url is put as the `gnus-button-url' overlay property on the button."
8074 (let ((opoint (point))
8075 (points (list start end))
8076 url delim regexp)
8077 (prog1
8078 (when (and (progn
8079 (goto-char end)
8080 (not (looking-at "[\t ]*[\">]")))
8081 (progn
8082 (goto-char start)
8083 (string-match
8084 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8085 (buffer-substring (point-at-bol) start)))
8086 (progn
8087 (setq url (list (buffer-substring start end))
8088 delim (if (match-beginning 1) ">" "\""))
8089 (beginning-of-line)
8090 (setq regexp (concat
8091 (when (and (looking-at
8092 message-cite-prefix-regexp)
8093 (< (match-end 0) start))
8094 (regexp-quote (match-string 0)))
8095 "\
8096 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8097 delim "\\)"))
8098 (while (progn
8099 (forward-line 1)
8100 (and (looking-at regexp)
8101 (prog1
8102 (match-beginning 1)
8103 (push (or (match-string 2)
8104 (match-string 1))
8105 url)
8106 (push (setq end (or (match-end 2)
8107 (match-end 1)))
8108 points)
8109 (push (or (match-beginning 2)
8110 (match-beginning 1))
8111 points)))))
8112 (match-beginning 2)))
8113 (let (gnus-article-mouse-face widget-mouse-face)
8114 (while points
8115 (gnus-article-add-button (pop points) (pop points)
8116 'gnus-button-push
8117 (list beg (assq 'gnus-button-url-regexp
8118 gnus-button-alist)))))
8119 (let ((overlay (gnus-make-overlay start end)))
8120 (gnus-overlay-put overlay 'evaporate t)
8121 (gnus-overlay-put overlay 'gnus-button-url
8122 (list (mapconcat 'identity (nreverse url) "")))
8123 (when gnus-article-mouse-face
8124 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8125 t)
8126 (goto-char opoint))))
8127
8128 ;; Add buttons to the head of an article.
8129 (defun gnus-article-add-buttons-to-head ()
8130 "Add buttons to the head of the article."
8131 (interactive)
8132 (gnus-with-article-headers
8133 (let (beg end)
8134 (dolist (entry gnus-header-button-alist)
8135 ;; Each alist entry.
8136 (goto-char (point-min))
8137 (while (re-search-forward (car entry) nil t)
8138 ;; Each header matching the entry.
8139 (setq beg (match-beginning 0))
8140 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8141 (match-beginning 0))
8142 (point-max)))
8143 (goto-char beg)
8144 (while (re-search-forward (eval (nth 1 entry)) end t)
8145 ;; Each match within a header.
8146 (let* ((entry (cdr entry))
8147 (start (match-beginning (nth 1 entry)))
8148 (end (match-end (nth 1 entry)))
8149 (form (nth 2 entry)))
8150 (goto-char (match-end 0))
8151 (when (eval form)
8152 (gnus-article-add-button
8153 start end (nth 3 entry)
8154 (buffer-substring (match-beginning (nth 4 entry))
8155 (match-end (nth 4 entry)))))))
8156 (goto-char end))))))
8157
8158 ;;; External functions:
8159
8160 (defun gnus-article-add-button (from to fun &optional data text)
8161 "Create a button between FROM and TO with callback FUN and data DATA."
8162 (when gnus-article-button-face
8163 (gnus-overlay-put (gnus-make-overlay from to nil t)
8164 'face gnus-article-button-face))
8165 (gnus-add-text-properties
8166 from to
8167 (nconc (and gnus-article-mouse-face
8168 (list gnus-mouse-face-prop gnus-article-mouse-face))
8169 (list 'gnus-callback fun)
8170 (and data (list 'gnus-data data))))
8171 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8172 :help-echo (or text "Follow the link")
8173 :keymap gnus-url-button-map
8174 :button-keymap gnus-widget-button-keymap))
8175
8176 (defun gnus-article-copy-string ()
8177 "Copy the string in the button to the kill ring."
8178 (interactive)
8179 (gnus-article-check-buffer)
8180 (let ((data (get-text-property (point) 'gnus-string)))
8181 (when data
8182 (with-temp-buffer
8183 (insert data)
8184 (copy-region-as-kill (point-min) (point-max))
8185 (message "Copied %s" data)))))
8186
8187 ;;; Internal functions:
8188
8189 (defun gnus-article-set-globals ()
8190 (with-current-buffer gnus-summary-buffer
8191 (gnus-set-global-variables)))
8192
8193 (defun gnus-signature-toggle (end)
8194 (gnus-with-article-buffer
8195 (let ((inhibit-point-motion-hooks t))
8196 (if (text-property-any end (point-max) 'article-type 'signature)
8197 (progn
8198 (gnus-delete-wash-type 'signature)
8199 (gnus-remove-text-properties-when
8200 'article-type 'signature end (point-max)
8201 (cons 'article-type (cons 'signature
8202 gnus-hidden-properties))))
8203 (gnus-add-wash-type 'signature)
8204 (gnus-add-text-properties-when
8205 'article-type nil end (point-max)
8206 (cons 'article-type (cons 'signature
8207 gnus-hidden-properties)))))
8208 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8209 (gnus-set-mode-line 'article))))
8210
8211 (defun gnus-button-push (marker-and-entry)
8212 ;; Push button starting at MARKER.
8213 (save-excursion
8214 (let* ((marker (car marker-and-entry))
8215 (entry (cadr marker-and-entry))
8216 (regexp (car entry))
8217 (inhibit-point-motion-hooks t))
8218 (goto-char marker)
8219 ;; This is obviously true, or something bad is happening :)
8220 ;; But we need it to have the match-data
8221 (when (looking-at (or (if (symbolp regexp)
8222 (symbol-value regexp)
8223 regexp)))
8224 (let ((fun (nth 3 entry))
8225 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8226 (get-char-property marker 'gnus-button-url))
8227 (mapcar (lambda (group)
8228 (let ((string (match-string group)))
8229 (set-text-properties
8230 0 (length string) nil string)
8231 string))
8232 (nthcdr 4 entry)))))
8233
8234 (cond
8235 ((fboundp fun)
8236 (apply fun args))
8237 ((and (boundp fun)
8238 (fboundp (symbol-value fun)))
8239 (apply (symbol-value fun) args))
8240 (t
8241 (gnus-message 1 "You must define `%S' to use this button"
8242 (cons fun args)))))))))
8243
8244 (defun gnus-parse-news-url (url)
8245 (let (scheme server port group message-id articles)
8246 (with-temp-buffer
8247 (insert url)
8248 (goto-char (point-min))
8249 (when (looking-at "\\([A-Za-z]+\\):")
8250 (setq scheme (match-string 1))
8251 (goto-char (match-end 0)))
8252 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8253 (setq server (match-string 1))
8254 (setq port (if (stringp (match-string 3))
8255 (string-to-number (match-string 3))
8256 (match-string 3)))
8257 (goto-char (match-end 0)))
8258
8259 (cond
8260 ((looking-at "\\(.*@.*\\)")
8261 (setq message-id (match-string 1)))
8262 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8263 (setq group (match-string 1)
8264 articles (split-string (match-string 2) "-")))
8265 ((looking-at "\\([^/]+\\)/?")
8266 (setq group (match-string 1)))
8267 (t
8268 (error "Unknown news URL syntax"))))
8269 (list scheme server port group message-id articles)))
8270
8271 (defun gnus-button-handle-news (url)
8272 "Fetch a news URL."
8273 (destructuring-bind (scheme server port group message-id articles)
8274 (gnus-parse-news-url url)
8275 (cond
8276 (message-id
8277 (with-current-buffer gnus-summary-buffer
8278 (if server
8279 (let ((gnus-refer-article-method
8280 (nconc (list (list 'nntp server))
8281 gnus-refer-article-method))
8282 (nntp-port-number (or port "nntp")))
8283 (gnus-message 7 "Fetching %s with %s"
8284 message-id gnus-refer-article-method)
8285 (gnus-summary-refer-article message-id))
8286 (gnus-summary-refer-article message-id))))
8287 (group
8288 (gnus-button-fetch-group url)))))
8289
8290 (defun gnus-button-patch (library line)
8291 "Visit an Emacs Lisp library LIBRARY on line LINE."
8292 (interactive)
8293 (let ((file (locate-library (file-name-nondirectory library))))
8294 (unless file
8295 (error "Couldn't find library %s" library))
8296 (find-file file)
8297 (goto-char (point-min))
8298 (forward-line (1- (string-to-number line)))))
8299
8300 (defun gnus-button-handle-man (url)
8301 "Fetch a man page."
8302 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8303 (when (eq gnus-button-man-handler 'woman)
8304 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8305 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8306 (funcall gnus-button-man-handler url))
8307
8308 (defun gnus-button-handle-info-url (url)
8309 "Fetch an info URL."
8310 (setq url (mm-subst-char-in-string ?+ ?\ url))
8311 (cond
8312 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8313 (gnus-info-find-node
8314 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8315 "Gnus")
8316 ")" (gnus-url-unhex-string (match-string 2 url)))))
8317 ((string-match "([^)\"]+)[^\"]+" url)
8318 (setq url
8319 (gnus-replace-in-string
8320 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8321 (gnus-info-find-node url))
8322 (t (error "Can't parse %s" url))))
8323
8324 (defun gnus-button-handle-info-url-gnome (url)
8325 "Fetch GNOME style info URL."
8326 (setq url (mm-subst-char-in-string ?_ ?\ url))
8327 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8328 (gnus-info-find-node
8329 (concat "("
8330 (gnus-url-unhex-string
8331 (match-string 1 url))
8332 ")"
8333 (or (gnus-url-unhex-string
8334 (match-string 2 url))
8335 "Top")))
8336 (error "Can't parse %s" url)))
8337
8338 (defun gnus-button-handle-info-url-kde (url)
8339 "Fetch KDE style info URL."
8340 (gnus-info-find-node (gnus-url-unhex-string url)))
8341
8342 ;; (info) will autoload info.el
8343 (declare-function Info-menu "info" (menu-item &optional fork))
8344 (declare-function Info-index-next "info" (num))
8345
8346 (defun gnus-button-handle-info-keystrokes (url)
8347 "Call `info' when pushing the corresponding URL button."
8348 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8349 (let (node indx comma)
8350 (if (string-match
8351 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8352 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8353 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8354 "\\(?:[ \t\n,]*\\)\\)?")
8355 url)
8356 (setq node (match-string 2 url)
8357 indx (match-string 3 url))
8358 (error "Can't parse %s" url))
8359 (info)
8360 (Info-directory)
8361 (Info-menu node)
8362 (when (> (length indx) 0)
8363 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8364 "\\([ \t\n,]*\\)")
8365 indx)
8366 (setq comma (match-string 2 indx))
8367 (setq indx (match-string 1 indx))
8368 (Info-index indx)
8369 (when comma
8370 (dotimes (i (with-temp-buffer
8371 (insert comma)
8372 ;; Note: the XEmacs version of `how-many' takes
8373 ;; no optional argument.
8374 (goto-char (point-min))
8375 (how-many ",")))
8376 (Info-index-next 1)))
8377 nil)))
8378
8379 (autoload 'pgg-snarf-keys-region "pgg")
8380 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8381 (declare-function pgg-display-output-buffer "pgg" (start end status))
8382
8383 (defun gnus-button-openpgp (url)
8384 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8385 (with-temp-buffer
8386 (mm-url-insert-file-contents-external url)
8387 (pgg-snarf-keys-region (point-min) (point-max))
8388 (pgg-display-output-buffer nil nil nil)))
8389
8390 (defun gnus-button-message-id (message-id)
8391 "Fetch MESSAGE-ID."
8392 (with-current-buffer gnus-summary-buffer
8393 (gnus-summary-refer-article message-id)))
8394
8395 (defun gnus-button-fetch-group (address &rest ignore)
8396 "Fetch GROUP specified by ADDRESS."
8397 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8398 address)
8399 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8400 ;; for nntp:// and news://
8401 (setq address (match-string 3 address)))
8402 (if (not (string-match "[:/]" address))
8403 ;; This is just a simple group url.
8404 (gnus-group-read-ephemeral-group address gnus-select-method)
8405 (if (not
8406 (string-match
8407 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8408 address))
8409 (error "Can't parse %s" address)
8410 (gnus-group-read-ephemeral-group
8411 (match-string 4 address)
8412 `(nntp ,(match-string 1 address)
8413 (nntp-address ,(match-string 1 address))
8414 (nntp-port-number ,(if (match-end 3)
8415 (match-string 3 address)
8416 "nntp")))
8417 nil nil nil
8418 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8419
8420 (defun gnus-url-parse-query-string (query &optional downcase)
8421 (let (retval pairs cur key val)
8422 (setq pairs (split-string query "&"))
8423 (while pairs
8424 (setq cur (car pairs)
8425 pairs (cdr pairs))
8426 (if (not (string-match "=" cur))
8427 nil ; Grace
8428 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8429 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8430 (if downcase
8431 (setq key (downcase key)))
8432 (setq cur (assoc key retval))
8433 (if cur
8434 (setcdr cur (cons val (cdr cur)))
8435 (setq retval (cons (list key val) retval)))))
8436 retval))
8437
8438 (defun gnus-url-mailto (url)
8439 ;; Send mail to someone
8440 (setq url (replace-regexp-in-string "\n" " " url))
8441 (when (string-match "mailto:/*\\(.*\\)" url)
8442 (setq url (substring url (match-beginning 1) nil)))
8443 (let (to args subject func)
8444 (setq args (gnus-url-parse-query-string
8445 (if (string-match "^\\?" url)
8446 (substring url 1)
8447 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8448 (concat "to=" (match-string 1 url) "&"
8449 (match-string 2 url))
8450 (concat "to=" url))))
8451 subject (cdr-safe (assoc "subject" args)))
8452 (gnus-msg-mail)
8453 (while args
8454 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8455 (if (fboundp func)
8456 (funcall func)
8457 (message-position-on-field (caar args)))
8458 (insert (gnus-replace-in-string
8459 (mapconcat 'identity (reverse (cdar args)) ", ")
8460 "\r\n" "\n" t))
8461 (setq args (cdr args)))
8462 (if subject
8463 (message-goto-body)
8464 (message-goto-subject))))
8465
8466 (defun gnus-button-embedded-url (address)
8467 "Activate ADDRESS with `browse-url'."
8468 (browse-url (gnus-strip-whitespace address)))
8469
8470 ;;; Next/prev buttons in the article buffer.
8471
8472 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8473 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8474
8475 (defvar gnus-prev-page-map
8476 (let ((map (make-sparse-keymap)))
8477 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8478 (define-key map "\r" 'gnus-button-prev-page)
8479 map))
8480
8481 (defvar gnus-next-page-map
8482 (let ((map (make-sparse-keymap)))
8483 (define-key map gnus-mouse-2 'gnus-button-next-page)
8484 (define-key map "\r" 'gnus-button-next-page)
8485 map))
8486
8487 (defun gnus-insert-prev-page-button ()
8488 (let ((b (point)) e
8489 (inhibit-read-only t))
8490 (gnus-eval-format
8491 gnus-prev-page-line-format nil
8492 `(keymap ,gnus-prev-page-map
8493 gnus-prev t
8494 gnus-callback gnus-article-button-prev-page
8495 article-type annotation))
8496 (setq e (if (bolp)
8497 ;; Exclude a newline.
8498 (1- (point))
8499 (point)))
8500 (when gnus-article-button-face
8501 (gnus-overlay-put (gnus-make-overlay b e nil t)
8502 'face gnus-article-button-face))
8503 (widget-convert-button
8504 'link b e
8505 :action 'gnus-button-prev-page
8506 :button-keymap gnus-prev-page-map)))
8507
8508 (defun gnus-button-next-page (&optional args more-args)
8509 "Go to the next page."
8510 (interactive)
8511 (let ((win (selected-window)))
8512 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8513 (gnus-article-next-page)
8514 (select-window win)))
8515
8516 (defun gnus-button-prev-page (&optional args more-args)
8517 "Go to the prev page."
8518 (interactive)
8519 (let ((win (selected-window)))
8520 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8521 (gnus-article-prev-page)
8522 (select-window win)))
8523
8524 (defun gnus-insert-next-page-button ()
8525 (let ((b (point)) e
8526 (inhibit-read-only t))
8527 (gnus-eval-format gnus-next-page-line-format nil
8528 `(keymap ,gnus-next-page-map
8529 gnus-next t
8530 gnus-callback gnus-article-button-next-page
8531 article-type annotation))
8532 (setq e (if (bolp)
8533 ;; Exclude a newline.
8534 (1- (point))
8535 (point)))
8536 (when gnus-article-button-face
8537 (gnus-overlay-put (gnus-make-overlay b e nil t)
8538 'face gnus-article-button-face))
8539 (widget-convert-button
8540 'link b e
8541 :action 'gnus-button-next-page
8542 :button-keymap gnus-next-page-map)))
8543
8544 (defun gnus-article-button-next-page (arg)
8545 "Go to the next page."
8546 (interactive "P")
8547 (let ((win (selected-window)))
8548 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8549 (gnus-article-next-page)
8550 (select-window win)))
8551
8552 (defun gnus-article-button-prev-page (arg)
8553 "Go to the prev page."
8554 (interactive "P")
8555 (let ((win (selected-window)))
8556 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8557 (gnus-article-prev-page)
8558 (select-window win)))
8559
8560 (defvar gnus-decode-header-methods
8561 '(mail-decode-encoded-word-region)
8562 "List of methods used to decode headers.
8563
8564 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8565 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8566 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8567 whose names match REGEXP.
8568
8569 For example:
8570 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8571 mail-decode-encoded-word-region
8572 (\"chinese\" . rfc1843-decode-region))
8573 ")
8574
8575 (defvar gnus-decode-header-methods-cache nil)
8576
8577 (defun gnus-multi-decode-header (start end)
8578 "Apply the functions from `gnus-encoded-word-methods' that match."
8579 (unless (and gnus-decode-header-methods-cache
8580 (eq gnus-newsgroup-name
8581 (car gnus-decode-header-methods-cache)))
8582 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8583 (dolist (x gnus-decode-header-methods)
8584 (if (symbolp x)
8585 (nconc gnus-decode-header-methods-cache (list x))
8586 (if (and gnus-newsgroup-name
8587 (string-match (car x) gnus-newsgroup-name))
8588 (nconc gnus-decode-header-methods-cache
8589 (list (cdr x)))))))
8590 (let ((xlist gnus-decode-header-methods-cache))
8591 (pop xlist)
8592 (save-restriction
8593 (narrow-to-region start end)
8594 (while xlist
8595 (funcall (pop xlist) (point-min) (point-max))))))
8596
8597 ;;;
8598 ;;; Treatment top-level handling.
8599 ;;;
8600
8601 (defvar gnus-inhibit-article-treatments nil)
8602
8603 (defun gnus-treat-article (gnus-treat-condition
8604 &optional part-number total-parts gnus-treat-type)
8605 (let ((gnus-treat-length (- (point-max) (point-min)))
8606 (alist gnus-treatment-function-alist)
8607 (article-goto-body-goes-to-point-min-p t)
8608 (treated-type
8609 (or (not gnus-treat-type)
8610 (catch 'found
8611 (let ((list gnus-article-treat-types))
8612 (while list
8613 (when (string-match (pop list) gnus-treat-type)
8614 (throw 'found t)))))))
8615 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8616 val elem)
8617 (gnus-run-hooks 'gnus-part-display-hook)
8618 (dolist (elem alist)
8619 (setq val
8620 (save-excursion
8621 (when (gnus-buffer-live-p gnus-summary-buffer)
8622 (set-buffer gnus-summary-buffer))
8623 (symbol-value (car elem))))
8624 (when (and (or (consp val)
8625 treated-type)
8626 (or (not gnus-inhibit-article-treatments)
8627 (eq gnus-treat-condition 'head))
8628 (gnus-treat-predicate val)
8629 (or (not (get (car elem) 'highlight))
8630 highlightp))
8631 (save-restriction
8632 (funcall (cadr elem)))))))
8633
8634 ;; Dynamic variables.
8635 (defvar part-number)
8636 (defvar total-parts)
8637 (defvar gnus-treat-type)
8638 (defvar gnus-treat-condition)
8639 (defvar gnus-treat-length)
8640
8641 (defun gnus-treat-predicate (val)
8642 (cond
8643 ((null val)
8644 nil)
8645 (gnus-treat-condition
8646 (eq gnus-treat-condition val))
8647 ((and (listp val)
8648 (stringp (car val)))
8649 (apply 'gnus-or (mapcar `(lambda (s)
8650 (string-match s ,(or gnus-newsgroup-name "")))
8651 val)))
8652 ((listp val)
8653 (let ((pred (pop val)))
8654 (cond
8655 ((eq pred 'or)
8656 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8657 ((eq pred 'and)
8658 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8659 ((eq pred 'not)
8660 (not (gnus-treat-predicate (car val))))
8661 ((eq pred 'typep)
8662 (equal (car val) gnus-treat-type))
8663 ((functionp pred)
8664 (funcall pred))
8665 (t
8666 (error "%S is not a valid predicate" pred)))))
8667 ((eq val t)
8668 t)
8669 ((eq val 'head)
8670 nil)
8671 ((eq val 'first)
8672 (eq part-number 1))
8673 ((eq val 'last)
8674 (eq part-number total-parts))
8675 ((numberp val)
8676 (< gnus-treat-length val))
8677 (t
8678 (error "%S is not a valid value" val))))
8679
8680 (defun gnus-article-encrypt-body (protocol &optional n)
8681 "Encrypt the article body."
8682 (interactive
8683 (list
8684 (or gnus-article-encrypt-protocol
8685 (gnus-completing-read "Encrypt protocol"
8686 (mapcar 'car gnus-article-encrypt-protocol-alist)
8687 t))
8688 current-prefix-arg))
8689 ;; User might hit `K E' instead of `K e', so prompt once.
8690 (when (and gnus-article-encrypt-protocol
8691 gnus-novice-user)
8692 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8693 (error "Encrypt aborted")))
8694 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8695 (unless func
8696 (error "Can't find the encrypt protocol %s" protocol))
8697 (if (member gnus-newsgroup-name '("nndraft:delayed"
8698 "nndraft:drafts"
8699 "nndraft:queue"))
8700 (error "Can't encrypt the article in group %s"
8701 gnus-newsgroup-name))
8702 (gnus-summary-iterate n
8703 (with-current-buffer gnus-summary-buffer
8704 (let ((mail-parse-charset gnus-newsgroup-charset)
8705 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8706 (summary-buffer gnus-summary-buffer)
8707 references point)
8708 (gnus-set-global-variables)
8709 (when (gnus-group-read-only-p)
8710 (error "The current newsgroup does not support article encrypt"))
8711 (gnus-summary-show-article t)
8712 (setq references
8713 (or (mail-header-references gnus-current-headers) ""))
8714 (set-buffer gnus-article-buffer)
8715 (let* ((inhibit-read-only t)
8716 (headers
8717 (mapcar (lambda (field)
8718 (and (save-restriction
8719 (message-narrow-to-head)
8720 (goto-char (point-min))
8721 (search-forward field nil t))
8722 (prog2
8723 (message-narrow-to-field)
8724 (buffer-string)
8725 (delete-region (point-min) (point-max))
8726 (widen))))
8727 '("Content-Type:" "Content-Transfer-Encoding:"
8728 "Content-Disposition:"))))
8729 (message-narrow-to-head)
8730 (message-remove-header "MIME-Version")
8731 (goto-char (point-max))
8732 (setq point (point))
8733 (insert (apply 'concat headers))
8734 (widen)
8735 (narrow-to-region point (point-max))
8736 (let ((message-options message-options))
8737 (message-options-set 'message-sender user-mail-address)
8738 (message-options-set 'message-recipients user-mail-address)
8739 (message-options-set 'message-sign-encrypt 'not)
8740 (funcall func))
8741 (goto-char (point-min))
8742 (insert "MIME-Version: 1.0\n")
8743 (widen)
8744 (gnus-summary-edit-article-done
8745 references nil summary-buffer t))
8746 (when gnus-keep-backlog
8747 (gnus-backlog-remove-article
8748 (car gnus-article-current) (cdr gnus-article-current)))
8749 (gnus-flush-original-article-buffer)
8750 (when gnus-use-cache
8751 (gnus-cache-update-article
8752 (car gnus-article-current) (cdr gnus-article-current))))))))
8753
8754 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8755 "The following specs can be used:
8756 %t The security MIME type
8757 %i Additional info
8758 %d Details
8759 %D Details if button is pressed")
8760
8761 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8762 "The following specs can be used:
8763 %t The security MIME type
8764 %i Additional info
8765 %d Details
8766 %D Details if button is pressed")
8767
8768 (defvar gnus-mime-security-button-line-format-alist
8769 '((?t gnus-tmp-type ?s)
8770 (?i gnus-tmp-info ?s)
8771 (?d gnus-tmp-details ?s)
8772 (?D gnus-tmp-pressed-details ?s)))
8773
8774 (defvar gnus-mime-security-button-commands
8775 '((gnus-article-press-button "\r" "Show Detail")
8776 (undefined "v")
8777 (undefined "t")
8778 (undefined "C")
8779 (gnus-mime-security-save-part "o" "Save...")
8780 (undefined "\C-o")
8781 (undefined "r")
8782 (undefined "d")
8783 (undefined "c")
8784 (undefined "i")
8785 (undefined "E")
8786 (undefined "e")
8787 (undefined "p")
8788 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8789 (undefined ".")))
8790
8791 (defvar gnus-mime-security-button-map
8792 (let ((map (make-sparse-keymap)))
8793 (define-key map gnus-mouse-2 'gnus-article-push-button)
8794 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8795 (dolist (c gnus-mime-security-button-commands)
8796 (define-key map (cadr c) (car c)))
8797 map))
8798
8799 (easy-menu-define
8800 gnus-mime-security-button-menu gnus-mime-security-button-map
8801 "Security button menu."
8802 `("Security Part"
8803 ,@(delq nil
8804 (mapcar (lambda (c)
8805 (unless (eq (car c) 'undefined)
8806 (vector (caddr c) (car c) :active t)))
8807 gnus-mime-security-button-commands))))
8808
8809 (defun gnus-mime-security-button-menu (event prefix)
8810 "Construct a context-sensitive menu of security commands."
8811 (interactive "e\nP")
8812 (save-window-excursion
8813 (let ((pos (event-start event)))
8814 (select-window (posn-window pos))
8815 (goto-char (posn-point pos))
8816 (gnus-article-check-buffer)
8817 (popup-menu gnus-mime-security-button-menu nil prefix))))
8818
8819 (defvar gnus-mime-security-details-buffer nil)
8820
8821 (defvar gnus-mime-security-button-pressed nil)
8822
8823 (defvar gnus-mime-security-show-details-inline t
8824 "If non-nil, show details in the article buffer.")
8825
8826 (defun gnus-mime-security-verify-or-decrypt (handle)
8827 (mm-remove-parts (cdr handle))
8828 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8829 point (inhibit-read-only t))
8830 (if region
8831 (goto-char (car region)))
8832 (setq point (point))
8833 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8834 (let* ((mm-verify-option 'known)
8835 (mm-decrypt-option 'known)
8836 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8837 (unless (eq nparts (cdr handle))
8838 (mm-destroy-parts (cdr handle))
8839 (setcdr handle nparts))))
8840 (gnus-mime-display-security handle)
8841 (when region
8842 (delete-region (point) (cdr region))
8843 (set-marker (car region) nil)
8844 (set-marker (cdr region) nil))
8845 (goto-char point)))
8846
8847 (defun gnus-mime-security-show-details (handle)
8848 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8849 (if (not details)
8850 (gnus-message 5 "No details.")
8851 (if gnus-mime-security-show-details-inline
8852 (let ((gnus-mime-security-button-pressed
8853 (not (get-text-property (point) 'gnus-mime-details)))
8854 (gnus-mime-security-button-line-format
8855 (get-text-property (point) 'gnus-line-format))
8856 (inhibit-read-only t))
8857 (forward-char -1)
8858 (while (eq (get-text-property (point) 'gnus-line-format)
8859 gnus-mime-security-button-line-format)
8860 (forward-char -1))
8861 (forward-char)
8862 (save-restriction
8863 (narrow-to-region (point) (point))
8864 (gnus-insert-mime-security-button handle))
8865 (delete-region (point)
8866 (or (text-property-not-all
8867 (point) (point-max)
8868 'gnus-line-format
8869 gnus-mime-security-button-line-format)
8870 (point-max))))
8871 ;; Not inlined.
8872 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8873 (with-current-buffer gnus-mime-security-details-buffer
8874 (erase-buffer)
8875 t)
8876 (setq gnus-mime-security-details-buffer
8877 (gnus-get-buffer-create "*MIME Security Details*")))
8878 (with-current-buffer gnus-mime-security-details-buffer
8879 (insert details)
8880 (goto-char (point-min)))
8881 (pop-to-buffer gnus-mime-security-details-buffer)))))
8882
8883 (defun gnus-mime-security-press-button (handle)
8884 (save-excursion
8885 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8886 (gnus-mime-security-show-details handle)
8887 (gnus-mime-security-verify-or-decrypt handle))))
8888
8889 (defun gnus-insert-mime-security-button (handle &optional displayed)
8890 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8891 (gnus-tmp-type
8892 (concat
8893 (or (nth 2 (assoc protocol mm-verify-function-alist))
8894 (nth 2 (assoc protocol mm-decrypt-function-alist))
8895 "Unknown")
8896 (if (equal (car handle) "multipart/signed")
8897 " Signed" " Encrypted")
8898 " Part"))
8899 (gnus-tmp-info
8900 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8901 "Undecided"))
8902 (gnus-tmp-details
8903 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8904 gnus-tmp-pressed-details
8905 b e)
8906 (setq gnus-tmp-details
8907 (if gnus-tmp-details
8908 (concat "\n" gnus-tmp-details)
8909 ""))
8910 (setq gnus-tmp-pressed-details
8911 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8912 (unless (bolp)
8913 (insert "\n"))
8914 (setq b (point))
8915 (gnus-eval-format
8916 gnus-mime-security-button-line-format
8917 gnus-mime-security-button-line-format-alist
8918 `(keymap ,gnus-mime-security-button-map
8919 gnus-callback gnus-mime-security-press-button
8920 gnus-line-format ,gnus-mime-security-button-line-format
8921 gnus-mime-details ,gnus-mime-security-button-pressed
8922 article-type annotation
8923 gnus-data ,handle))
8924 (setq e (if (bolp)
8925 ;; Exclude a newline.
8926 (1- (point))
8927 (point)))
8928 (when gnus-article-button-face
8929 (gnus-overlay-put (gnus-make-overlay b e nil t)
8930 'face gnus-article-button-face))
8931 (widget-convert-button
8932 'link b e
8933 :mime-handle handle
8934 :action 'gnus-widget-press-button
8935 :button-keymap gnus-mime-security-button-map
8936 :help-echo
8937 (lambda (widget)
8938 ;; Needed to properly clear the message due to a bug in
8939 ;; wid-edit (XEmacs only).
8940 (when (boundp 'help-echo-owns-message)
8941 (setq help-echo-owns-message t))
8942 (format
8943 "%S: show detail; %S: more options"
8944 (aref gnus-mouse-2 0)
8945 (aref gnus-down-mouse-3 0))))))
8946
8947 (defun gnus-mime-display-security (handle)
8948 (save-restriction
8949 (narrow-to-region (point) (point))
8950 (unless (gnus-unbuttonized-mime-type-p (car handle))
8951 (gnus-insert-mime-security-button handle))
8952 (gnus-mime-display-part (cadr handle))
8953 (unless (bolp)
8954 (insert "\n"))
8955 (unless (gnus-unbuttonized-mime-type-p (car handle))
8956 (let ((gnus-mime-security-button-line-format
8957 gnus-mime-security-button-end-line-format))
8958 (gnus-insert-mime-security-button handle)))
8959 (mm-set-handle-multipart-parameter
8960 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8961 (goto-char (point-max))))
8962
8963 (defun gnus-mime-security-run-function (function)
8964 "Run FUNCTION with the security part under point."
8965 (gnus-article-check-buffer)
8966 (let ((data (get-text-property (point) 'gnus-data))
8967 buffer handle)
8968 (when (and (stringp (car-safe data))
8969 (setq buffer (mm-handle-multipart-original-buffer data))
8970 (setq handle (cadr data)))
8971 (if (bufferp (mm-handle-buffer handle))
8972 (progn
8973 (setq handle (cons buffer (copy-sequence (cdr handle))))
8974 (mm-handle-set-undisplayer handle nil))
8975 (setq handle (mm-make-handle
8976 buffer
8977 (mm-handle-multipart-ctl-parameter handle 'protocol)
8978 nil nil nil nil nil nil)))
8979 (funcall function handle))))
8980
8981 (defun gnus-mime-security-save-part ()
8982 "Save the security part under point."
8983 (interactive)
8984 (gnus-mime-security-run-function 'mm-save-part))
8985
8986 (defun gnus-mime-security-pipe-part ()
8987 "Pipe the security part under point to a process."
8988 (interactive)
8989 (gnus-mime-security-run-function 'mm-pipe-part))
8990
8991 (gnus-ems-redefine)
8992
8993 (provide 'gnus-art)
8994
8995 (run-hooks 'gnus-art-load-hook)
8996
8997 ;;; gnus-art.el ends here