Synch to No Gnus 200409220305.
[elisp/gnus.git-] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;      MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;      Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (require 'static)
34   (defvar tool-bar-map))
35
36 (require 'path-util)
37 (require 'gnus)
38 (require 'gnus-sum)
39 (require 'gnus-spec)
40 (require 'gnus-int)
41 (require 'gnus-win)
42 (require 'alist)
43 (require 'mime-view)
44 (when (static-if (featurep 'xemacs)
45           (console-on-window-system-p)
46         window-system)
47   (require 'mime-image))
48 (require 'wid-edit)
49
50 ;; Avoid byte-compile warnings.
51 (eval-when-compile
52   (require 'mm-bodies)
53   (require 'mail-parse)
54   (require 'mm-decode)
55   (require 'mm-view)
56   (require 'mm-uu))
57
58 (require 'message)
59
60 (autoload 'gnus-msg-mail "gnus-msg" nil t)
61 (autoload 'gnus-button-mailto "gnus-msg")
62 (autoload 'gnus-button-reply "gnus-msg" nil t)
63 (autoload 'ansi-color-apply-on-region "ansi-color")
64
65 (defgroup gnus-article nil
66   "Article display."
67   :link '(custom-manual "(gnus)Article Buffer")
68   :group 'gnus)
69
70 (defgroup gnus-article-treat nil
71   "Treating article parts."
72   :link '(custom-manual "(gnus)Article Hiding")
73   :group 'gnus-article)
74
75 (defgroup gnus-article-hiding nil
76   "Hiding article parts."
77   :link '(custom-manual "(gnus)Article Hiding")
78   :group 'gnus-article)
79
80 (defgroup gnus-article-highlight nil
81   "Article highlighting."
82   :link '(custom-manual "(gnus)Article Highlighting")
83   :group 'gnus-article
84   :group 'gnus-visual)
85
86 (defgroup gnus-article-signature nil
87   "Article signatures."
88   :link '(custom-manual "(gnus)Article Signature")
89   :group 'gnus-article)
90
91 (defgroup gnus-article-headers nil
92   "Article headers."
93   :link '(custom-manual "(gnus)Hiding Headers")
94   :group 'gnus-article)
95
96 (defgroup gnus-article-washing nil
97   "Special commands on articles."
98   :link '(custom-manual "(gnus)Article Washing")
99   :group 'gnus-article)
100
101 (defgroup gnus-article-emphasis nil
102   "Fontisizing articles."
103   :link '(custom-manual "(gnus)Article Fontisizing")
104   :group 'gnus-article)
105
106 (defgroup gnus-article-saving nil
107   "Saving articles."
108   :link '(custom-manual "(gnus)Saving Articles")
109   :group 'gnus-article)
110
111 (defgroup gnus-article-mime nil
112   "Worshiping the MIME wonder."
113   :link '(custom-manual "(gnus)Using MIME")
114   :group 'gnus-article)
115
116 (defgroup gnus-article-buttons nil
117   "Pushable buttons in the article buffer."
118   :link '(custom-manual "(gnus)Article Buttons")
119   :group 'gnus-article)
120
121 (defgroup gnus-article-various nil
122   "Other article options."
123   :link '(custom-manual "(gnus)Misc Article")
124   :group 'gnus-article)
125
126 (defcustom gnus-ignored-headers
127   (mapcar
128    (lambda (header)
129      (concat "^" header ":"))
130    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
131      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
132      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
133      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
134      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
135      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
136      "X-Attribution" "X-Originating-IP" "Delivered-To"
137      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
138      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
139      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
140      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
141      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
142      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
143      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
144      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
145      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
146      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
147      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
148      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
149      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
150      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
151      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
152      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
153      "List-[A-Za-z]+" "X-Listprocessor-Version"
154      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
155      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
156      "X-Received" "Content-length" "X-precedence"
157      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
158      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
159      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
160      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
161      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
162      "X-Content-length" "X-Posting-Agent" "Original-Received"
163      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
164      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
165      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
166      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
167      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
168   "*All headers that start with this regexp will be hidden.
169 This variable can also be a list of regexps of headers to be ignored.
170 If `gnus-visible-headers' is non-nil, this variable will be ignored."
171   :type '(choice :custom-show nil
172                  regexp
173                  (repeat regexp))
174   :group 'gnus-article-hiding)
175
176 (defcustom gnus-visible-headers
177   "^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:\\|^X-Sent:"
178   "*All headers that do not match this regexp will be hidden.
179 This variable can also be a list of regexp of headers to remain visible.
180 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
181   :type '(repeat :value-to-internal (lambda (widget value)
182                                       (custom-split-regexp-maybe value))
183                  :match (lambda (widget value)
184                           (or (stringp value)
185                               (widget-editable-list-match widget value)))
186                  regexp)
187   :group 'gnus-article-hiding)
188
189 (defcustom gnus-sorted-header-list
190   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
191     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
192   "*This variable is a list of regular expressions.
193 If it is non-nil, headers that match the regular expressions will
194 be placed first in the article buffer in the sequence specified by
195 this list."
196   :type '(repeat regexp)
197   :group 'gnus-article-hiding)
198
199 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
200   "Headers that are only to be displayed if they have interesting data.
201 Possible values in this list are:
202
203   'empty       Headers with no content.
204   'newsgroups  Newsgroup identical to Gnus group.
205   'to-address  To identical to To-address.
206   'to-list     To identical to To-list.
207   'cc-list     CC identical to To-list.
208   'followup-to Followup-to identical to Newsgroups.
209   'reply-to    Reply-to identical to From.
210   'date        Date less than four days old.
211   'long-to     To and/or Cc longer than 1024 characters.
212   'many-to     Multiple To and/or Cc."
213   :type '(set (const :tag "Headers with no content." empty)
214               (const :tag "Newsgroups identical to Gnus group." newsgroups)
215               (const :tag "To identical to To-address." to-address)
216               (const :tag "To identical to To-list." to-list)
217               (const :tag "CC identical to To-list." cc-list)
218               (const :tag "Followup-to identical to Newsgroups." followup-to)
219               (const :tag "Reply-to identical to From." reply-to)
220               (const :tag "Date less than four days old." date)
221               (const :tag "To and/or Cc longer than 1024 characters." long-to)
222               (const :tag "Multiple To and/or Cc headers." many-to))
223   :group 'gnus-article-hiding)
224
225 (defcustom gnus-article-skip-boring nil
226   "Skip over text that is not worth reading.
227 By default, if you set this t, then Gnus will display citations and
228 signatures, but will never scroll down to show you a page consisting
229 only of boring text.  Boring text is controlled by
230 `gnus-article-boring-faces'."
231   :version "21.4"
232   :type 'boolean
233   :group 'gnus-article-hiding)
234
235 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
236   "Regexp matching signature separator.
237 This can also be a list of regexps.  In that case, it will be checked
238 from head to tail looking for a separator.  Searches will be done from
239 the end of the buffer."
240   :type '(repeat string)
241   :group 'gnus-article-signature)
242
243 (defcustom gnus-signature-limit nil
244   "Provide a limit to what is considered a signature.
245 If it is a number, no signature may not be longer (in characters) than
246 that number.  If it is a floating point number, no signature may be
247 longer (in lines) than that number.  If it is a function, the function
248 will be called without any parameters, and if it returns nil, there is
249 no signature in the buffer.  If it is a string, it will be used as a
250 regexp.  If it matches, the text in question is not a signature.
251
252 This can also be a list of the above values."
253   :type '(choice (integer :value 200)
254                  (number :value 4.0)
255                  (function :value fun)
256                  (regexp :value ".*"))
257   :group 'gnus-article-signature)
258
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260   "Property list to use for hiding text."
261   :type 'sexp
262   :group 'gnus-article-hiding)
263
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267   (cond
268    (noninteractive
269     'ignore)
270    ((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 '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -"))
275    ((gnus-image-type-available-p 'pbm)
276     'gnus-display-x-face-in-from)
277    ((and window-system
278          (module-installed-p 'x-face-mule))
279     'x-face-mule-gnus-article-display-x-face)
280    (t
281     "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
282 display -"))
283   "*String or function to be executed to display an X-Face header.
284 If it is a string, the command will be executed in a sub-shell
285 asynchronously.  The compressed face will be piped to this command."
286   :type `(choice
287           ,@(let ((x-face-mule (if (featurep 'xemacs)
288                                    nil
289                                  (module-installed-p 'x-face-mule))))
290               (delq nil
291                     (list
292                      'string
293                      (if (or (gnus-image-type-available-p 'xface)
294                              (gnus-image-type-available-p 'pbm))
295                          '(function-item gnus-display-x-face-in-from))
296                      (if x-face-mule
297                          '(function-item
298                            x-face-mule-gnus-article-display-x-face))
299                      'function))))
300   :version "21.1"
301   :group 'gnus-picon
302   :group 'gnus-article-washing)
303
304 (defcustom gnus-article-x-face-too-ugly nil
305   "Regexp matching posters whose face shouldn't be shown automatically."
306   :type '(choice regexp (const nil))
307   :group 'gnus-article-washing)
308
309 (defcustom gnus-article-banner-alist nil
310   "Banner alist for stripping.
311 For example,
312      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
313   :version "21.1"
314   :type '(repeat (cons symbol regexp))
315   :group 'gnus-article-washing)
316
317 (gnus-define-group-parameter
318  banner
319  :variable-document
320  "Alist of regexps (to match group names) and banner."
321  :variable-group gnus-article-washing
322  :parameter-type
323  '(choice :tag "Banner"
324           :value nil
325           (const :tag "Remove signature" signature)
326           (symbol :tag "Item in `gnus-article-banner-alist'" none)
327           regexp
328           (const :tag "None" nil))
329  :parameter-document
330  "If non-nil, specify how to remove `banners' from articles.
331
332 Symbol `signature' means to remove signatures delimited by
333 `gnus-signature-separator'.  Any other symbol is used to look up a
334 regular expression to match the banner in `gnus-article-banner-alist'.
335 A string is used as a regular expression to match the banner
336 directly.")
337
338 (defcustom gnus-article-address-banner-alist nil
339   "Alist of mail addresses and banners.
340 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
341 to match a mail address in the From: header, BANNER is one of a symbol
342 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
343 If ADDRESS matches author's mail address, it will remove things like
344 advertisements.  For example:
345
346 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
347 "
348   :type '(repeat
349           (cons
350            (regexp :tag "Address")
351            (choice :tag "Banner" :value nil
352                    (const :tag "Remove signature" signature)
353                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
354                    regexp
355                    (const :tag "None" nil))))
356   :group 'gnus-article-washing)
357
358 (defcustom gnus-emphasis-alist
359   (let ((format
360          "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
361         (types
362          '(("\\*" "\\*" bold)
363            ("_" "_" underline)
364            ("/" "/" italic)
365            ("_/" "/_" underline-italic)
366            ("_\\*" "\\*_" underline-bold)
367            ("\\*/" "/\\*" bold-italic)
368            ("_\\*/" "/\\*_" underline-bold-italic))))
369     `(,@(mapcar
370          (lambda (spec)
371            (list
372             (format format (car spec) (car (cdr spec)))
373             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
374          types)
375         ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
376          2 3 gnus-emphasis-underline)))
377   "*Alist that says how to fontify certain phrases.
378 Each item looks like this:
379
380   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
381
382 The first element is a regular expression to be matched.  The second
383 is a number that says what regular expression grouping used to find
384 the entire emphasized word.  The third is a number that says what
385 regexp grouping should be displayed and highlighted.  The fourth
386 is the face used for highlighting."
387   :type '(repeat (list :value ("" 0 0 default)
388                        regexp
389                        (integer :tag "Match group")
390                        (integer :tag "Emphasize group")
391                        face))
392   :group 'gnus-article-emphasis)
393
394 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
395   "A regexp to describe whitespace which should not be emphasized.
396 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
397 The former avoids underlining of leading and trailing whitespace,
398 and the latter avoids underlining any whitespace at all."
399   :version "21.1"
400   :group 'gnus-article-emphasis
401   :type 'regexp)
402
403 (defface gnus-emphasis-bold '((t (:bold t)))
404   "Face used for displaying strong emphasized text (*word*)."
405   :group 'gnus-article-emphasis)
406
407 (defface gnus-emphasis-italic '((t (:italic t)))
408   "Face used for displaying italic emphasized text (/word/)."
409   :group 'gnus-article-emphasis)
410
411 (defface gnus-emphasis-underline '((t (:underline t)))
412   "Face used for displaying underlined emphasized text (_word_)."
413   :group 'gnus-article-emphasis)
414
415 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
416   "Face used for displaying underlined bold emphasized text (_*word*_)."
417   :group 'gnus-article-emphasis)
418
419 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
420   "Face used for displaying underlined italic emphasized text (_/word/_)."
421   :group 'gnus-article-emphasis)
422
423 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
424   "Face used for displaying bold italic emphasized text (/*word*/)."
425   :group 'gnus-article-emphasis)
426
427 (defface gnus-emphasis-underline-bold-italic
428   '((t (:bold t :italic t :underline t)))
429   "Face used for displaying underlined bold italic emphasized text.
430 Example: (_/*word*/_)."
431   :group 'gnus-article-emphasis)
432
433 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
434                                       '((t (:strikethru t)))
435                                     '((t (:strike-through t))))
436   "Face used for displaying strike-through text (-word-)."
437   :group 'gnus-article-emphasis)
438
439 (defface gnus-emphasis-highlight-words
440   '((t (:background "black" :foreground "yellow")))
441   "Face used for displaying highlighted words."
442   :group 'gnus-article-emphasis)
443
444 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
445   "Format for display of Date headers in article bodies.
446 See `format-time-string' for the possible values.
447
448 The variable can also be function, which should return a complete Date
449 header.  The function is called with one argument, the time, which can
450 be fed to `format-time-string'."
451   :type '(choice string function)
452   :link '(custom-manual "(gnus)Article Date")
453   :group 'gnus-article-washing)
454
455 (eval-and-compile
456   (autoload 'mail-extract-address-components "mail-extr"))
457
458 (defcustom gnus-save-all-headers t
459   "*If non-nil, don't remove any headers before saving."
460   :group 'gnus-article-saving
461   :type 'boolean)
462
463 (defcustom gnus-prompt-before-saving 'always
464   "*This variable says how much prompting is to be done when saving articles.
465 If it is nil, no prompting will be done, and the articles will be
466 saved to the default files.  If this variable is `always', each and
467 every article that is saved will be preceded by a prompt, even when
468 saving large batches of articles.  If this variable is neither nil not
469 `always', there the user will be prompted once for a file name for
470 each invocation of the saving commands."
471   :group 'gnus-article-saving
472   :type '(choice (item always)
473                  (item :tag "never" nil)
474                  (sexp :tag "once" :format "%t\n" :value t)))
475
476 (defcustom gnus-saved-headers gnus-visible-headers
477   "Headers to keep if `gnus-save-all-headers' is nil.
478 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
479 If that variable is nil, however, all headers that match this regexp
480 will be kept while the rest will be deleted before saving."
481   :group 'gnus-article-saving
482   :type 'regexp)
483
484 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
485   "A function to save articles in your favourite format.
486 The function must be interactively callable (in other words, it must
487 be an Emacs command).
488
489 Gnus provides the following functions:
490
491 * gnus-summary-save-in-rmail (Rmail format)
492 * gnus-summary-save-in-mail (Unix mail format)
493 * gnus-summary-save-in-folder (MH folder)
494 * gnus-summary-save-in-file (article format)
495 * gnus-summary-save-body-in-file (article body)
496 * gnus-summary-save-in-vm (use VM's folder format)
497 * gnus-summary-write-to-file (article format -- overwrite)."
498   :group 'gnus-article-saving
499   :type '(radio (function-item gnus-summary-save-in-rmail)
500                 (function-item gnus-summary-save-in-mail)
501                 (function-item gnus-summary-save-in-folder)
502                 (function-item gnus-summary-save-in-file)
503                 (function-item gnus-summary-save-body-in-file)
504                 (function-item gnus-summary-save-in-vm)
505                 (function-item gnus-summary-write-to-file)))
506
507 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
508   "A function generating a file name to save articles in Rmail format.
509 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
510   :group 'gnus-article-saving
511   :type 'function)
512
513 (defcustom gnus-mail-save-name 'gnus-plain-save-name
514   "A function generating a file name to save articles in Unix mail format.
515 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
516   :group 'gnus-article-saving
517   :type 'function)
518
519 (defcustom gnus-folder-save-name 'gnus-folder-save-name
520   "A function generating a file name to save articles in MH folder.
521 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
522   :group 'gnus-article-saving
523   :type 'function)
524
525 (defcustom gnus-file-save-name 'gnus-numeric-save-name
526   "A function generating a file name to save articles in article format.
527 The function is called with NEWSGROUP, HEADERS, and optional
528 LAST-FILE."
529   :group 'gnus-article-saving
530   :type 'function)
531
532 (defcustom gnus-split-methods
533   '((gnus-article-archive-name)
534     (gnus-article-nndoc-name))
535   "*Variable used to suggest where articles are to be saved.
536 For instance, if you would like to save articles related to Gnus in
537 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
538 you could set this variable to something like:
539
540  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
541    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
542
543 This variable is an alist where the where the key is the match and the
544 value is a list of possible files to save in if the match is non-nil.
545
546 If the match is a string, it is used as a regexp match on the
547 article.  If the match is a symbol, that symbol will be funcalled
548 from the buffer of the article to be saved with the newsgroup as the
549 parameter.  If it is a list, it will be evaled in the same buffer.
550
551 If this form or function returns a string, this string will be used as
552 a possible file name; and if it returns a non-nil list, that list will
553 be used as possible file names."
554   :group 'gnus-article-saving
555   :type '(repeat (choice (list :value (fun) function)
556                          (cons :value ("" "") regexp (repeat string))
557                          (sexp :value nil))))
558
559 (defcustom gnus-article-display-method-for-mime
560   'gnus-article-display-mime-message
561   "Function to display a MIME message.
562 The function is called from the article buffer."
563   :group 'gnus-article-mime
564   :type 'function)
565
566 (defcustom gnus-article-display-method-for-traditional
567   'gnus-article-display-traditional-message
568   "*Function to display a traditional message.
569 The function is called from the article buffer."
570   :group 'gnus-article-mime
571   :type 'function)
572
573 (defcustom gnus-page-delimiter "^\^L"
574   "*Regexp describing what to use as article page delimiters.
575 The default value is \"^\^L\", which is a form linefeed at the
576 beginning of a line."
577   :type 'regexp
578   :group 'gnus-article-various)
579
580 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
581   "*The format specification for the article mode line.
582 See `gnus-summary-mode-line-format' for a closer description.
583
584 The following additional specs are available:
585
586 %w  The article washing status.
587 %m  The number of MIME parts in the article."
588   :type 'string
589   :group 'gnus-article-various)
590
591 (defcustom gnus-article-mode-hook nil
592   "*A hook for Gnus article mode."
593   :type 'hook
594   :group 'gnus-article-various)
595
596 (when (featurep 'xemacs)
597   ;; Extracted from gnus-xmas-define in order to preserve user settings
598   (when (fboundp 'turn-off-scroll-in-place)
599     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
600   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
601   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
602
603 (defcustom gnus-article-menu-hook nil
604   "*Hook run after the creation of the article mode menu."
605   :type 'hook
606   :group 'gnus-article-various)
607
608 (defcustom gnus-article-prepare-hook nil
609   "*A hook called after an article has been prepared in the article buffer."
610   :type 'hook
611   :group 'gnus-article-various)
612
613 (make-obsolete-variable 'gnus-article-hide-pgp-hook
614                         "This variable is obsolete in Gnus 5.10.")
615
616 (defcustom gnus-article-button-face 'bold
617   "Face used for highlighting buttons in the article buffer.
618
619 An article button is a piece of text that you can activate by pressing
620 `RET' or `mouse-2' above it."
621   :type 'face
622   :group 'gnus-article-buttons)
623
624 (defcustom gnus-article-mouse-face 'highlight
625   "Face used for mouse highlighting in the article buffer.
626
627 Article buttons will be displayed in this face when the cursor is
628 above them."
629   :type 'face
630   :group 'gnus-article-buttons)
631
632 (defcustom gnus-signature-face 'gnus-signature-face
633   "Face used for highlighting a signature in the article buffer.
634 Obsolete; use the face `gnus-signature-face' for customizations instead."
635   :type 'face
636   :group 'gnus-article-highlight
637   :group 'gnus-article-signature)
638
639 (defface gnus-signature-face
640   '((t
641      (:italic t)))
642   "Face used for highlighting a signature in the article buffer."
643   :group 'gnus-article-highlight
644   :group 'gnus-article-signature)
645
646 (defface gnus-header-from-face
647   '((((class color)
648       (background dark))
649      (:foreground "spring green"))
650     (((class color)
651       (background light))
652      (:foreground "red3"))
653     (t
654      (:italic t)))
655   "Face used for displaying from headers."
656   :group 'gnus-article-headers
657   :group 'gnus-article-highlight)
658
659 (defface gnus-header-subject-face
660   '((((class color)
661       (background dark))
662      (:foreground "SeaGreen3"))
663     (((class color)
664       (background light))
665      (:foreground "red4"))
666     (t
667      (:bold t :italic t)))
668   "Face used for displaying subject headers."
669   :group 'gnus-article-headers
670   :group 'gnus-article-highlight)
671
672 (defface gnus-header-newsgroups-face
673   '((((class color)
674       (background dark))
675      (:foreground "yellow" :italic t))
676     (((class color)
677       (background light))
678      (:foreground "MidnightBlue" :italic t))
679     (t
680      (:italic t)))
681   "Face used for displaying newsgroups headers.
682 In the default setup this face is only used for crossposted
683 articles."
684   :group 'gnus-article-headers
685   :group 'gnus-article-highlight)
686
687 (defface gnus-header-name-face
688   '((((class color)
689       (background dark))
690      (:foreground "SeaGreen"))
691     (((class color)
692       (background light))
693      (:foreground "maroon"))
694     (t
695      (:bold t)))
696   "Face used for displaying header names."
697   :group 'gnus-article-headers
698   :group 'gnus-article-highlight)
699
700 (defface gnus-header-content-face
701   '((((class color)
702       (background dark))
703      (:foreground "forest green" :italic t))
704     (((class color)
705       (background light))
706      (:foreground "indianred4" :italic t))
707     (t
708      (:italic t)))
709   "Face used for displaying header content."
710   :group 'gnus-article-headers
711   :group 'gnus-article-highlight)
712
713 (defcustom gnus-header-face-alist
714   '(("From" nil gnus-header-from-face)
715     ("Subject" nil gnus-header-subject-face)
716     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
717     ("" gnus-header-name-face gnus-header-content-face))
718   "*Controls highlighting of article headers.
719
720 An alist of the form (HEADER NAME CONTENT).
721
722 HEADER is a regular expression which should match the name of a
723 header and NAME and CONTENT are either face names or nil.
724
725 The name of each header field will be displayed using the face
726 specified by the first element in the list where HEADER matches
727 the header name and NAME is non-nil.  Similarly, the content will
728 be displayed by the first non-nil matching CONTENT face."
729   :group 'gnus-article-headers
730   :group 'gnus-article-highlight
731   :type '(repeat (list (regexp :tag "Header")
732                        (choice :tag "Name"
733                                (item :tag "skip" nil)
734                                (face :value default))
735                        (choice :tag "Content"
736                                (item :tag "skip" nil)
737                                (face :value default)))))
738
739 (defcustom gnus-article-decode-hook
740   '(article-decode-group-name article-decode-idna-rhs)
741   "*Hook run to decode charsets in articles."
742   :group 'gnus-article-headers
743   :type 'hook)
744
745 (defcustom gnus-display-mime-function 'gnus-display-mime
746   "Function to display MIME articles."
747   :group 'gnus-article-mime
748   :type 'function)
749
750 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
751   "Function used to decode headers.")
752
753 (defvar gnus-article-dumbquotes-map
754   '(("\200" "EUR")
755     ("\202" ",")
756     ("\203" "f")
757     ("\204" ",,")
758     ("\205" "...")
759     ("\213" "<")
760     ("\214" "OE")
761     ("\221" "`")
762     ("\222" "'")
763     ("\223" "``")
764     ("\224" "\"")
765     ("\225" "*")
766     ("\226" "-")
767     ("\227" "--")
768     ("\230" "~")
769     ("\231" "(TM)")
770     ("\233" ">")
771     ("\234" "oe")
772     ("\264" "'"))
773   "Table for MS-to-Latin1 translation.")
774
775 (defcustom gnus-ignored-mime-types nil
776   "List of MIME types that should be ignored by Gnus."
777   :version "21.1"
778   :group 'gnus-article-mime
779   :type '(repeat regexp))
780
781 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
782   "List of MIME types that should not be given buttons when rendered inline.
783 See also `gnus-buttonized-mime-types' which may override this variable.
784 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
785   :version "21.1"
786   :group 'gnus-article-mime
787   :type '(repeat regexp))
788
789 (defcustom gnus-buttonized-mime-types nil
790   "List of MIME types that should be given buttons when rendered inline.
791 If set, this variable overrides `gnus-unbuttonized-mime-types'.
792 To see e.g. security buttons you could set this to
793 `(\"multipart/signed\")'.
794 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
795   :version "21.4"
796   :group 'gnus-article-mime
797   :type '(repeat regexp))
798
799 (defcustom gnus-inhibit-mime-unbuttonizing nil
800   "If non-nil, all MIME parts get buttons.
801 When nil (the default value), then some MIME parts do not get buttons,
802 as described by the variables `gnus-buttonized-mime-types' and
803 `gnus-unbuttonized-mime-types'."
804   :version "21.4"
805   :group 'gnus-article-mime
806   :type 'boolean)
807
808 (defcustom gnus-body-boundary-delimiter "_"
809   "String used to delimit header and body.
810 This variable is used by `gnus-article-treat-body-boundary' which can
811 be controlled by `gnus-treat-body-boundary'."
812   :version "21.4"
813   :group 'gnus-article-various
814   :type '(choice (item :tag "None" :value nil)
815                  string))
816
817 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
818                                   "/usr/share/picons")
819   "Defines the location of the faces database.
820 For information on obtaining this database of pretty pictures, please
821 see http://www.cs.indiana.edu/picons/ftp/index.html"
822   :version "21.4"
823   :type '(repeat directory)
824   :link '(url-link :tag "download"
825                    "http://www.cs.indiana.edu/picons/ftp/index.html")
826   :link '(custom-manual "(gnus)Picons")
827   :group 'gnus-picon)
828
829 (defun gnus-picons-installed-p ()
830   "Say whether picons are installed on your machine."
831   (let ((installed nil))
832     (dolist (database gnus-picon-databases)
833       (when (file-exists-p database)
834         (setq installed t)))
835     installed))
836
837 (defcustom gnus-article-mime-part-function nil
838   "Function called with a MIME handle as the argument.
839 This is meant for people who want to do something automatic based
840 on parts -- for instance, adding Vcard info to a database."
841   :group 'gnus-article-mime
842   :type 'function)
843
844 (defcustom gnus-mime-multipart-functions nil
845   "An alist of MIME types to functions to display them."
846   :version "21.1"
847   :group 'gnus-article-mime
848   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
849
850 (defcustom gnus-article-date-lapsed-new-header nil
851   "Whether the X-Sent and Date headers can coexist.
852 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
853 either replace the old \"Date:\" header (if this variable is nil), or
854 be added below it (otherwise)."
855   :version "21.1"
856   :group 'gnus-article-headers
857   :type 'boolean)
858
859 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
860   "Function called with a MIME handle as the argument.
861 This is meant for people who want to view first matched part.
862 For `undisplayed-alternative' (default), the first undisplayed
863 part or alternative part is used.  For `undisplayed', the first
864 undisplayed part is used.  For a function, the first part which
865 the function return t is used.  For nil, the first part is
866 used."
867   :version "21.1"
868   :group 'gnus-article-mime
869   :type '(choice
870           (item :tag "first" :value nil)
871           (item :tag "undisplayed" :value undisplayed)
872           (item :tag "undisplayed or alternative"
873                 :value undisplayed-alternative)
874           (function)))
875
876 (defcustom gnus-mime-action-alist
877   '(("save to file" . gnus-mime-save-part)
878     ("save and strip" . gnus-mime-save-part-and-strip)
879     ("delete part" . gnus-mime-delete-part)
880     ("display as text" . gnus-mime-inline-part)
881     ("view the part" . gnus-mime-view-part)
882     ("pipe to command" . gnus-mime-pipe-part)
883     ("toggle display" . gnus-article-press-button)
884     ("toggle display" . gnus-article-view-part-as-charset)
885     ("view as type" . gnus-mime-view-part-as-type)
886     ("view internally" . gnus-mime-view-part-internally)
887     ("view externally" . gnus-mime-view-part-externally))
888   "An alist of actions that run on the MIME attachment."
889   :group 'gnus-article-mime
890   :type '(repeat (cons (string :tag "name")
891                        (function))))
892
893 ;;;
894 ;;; The treatment variables
895 ;;;
896
897 (defvar gnus-part-display-hook nil
898   "Hook called on parts that are to receive treatment.")
899
900 (defvar gnus-article-treat-custom
901   '(choice (const :tag "Off" nil)
902            (const :tag "On" t)
903            (const :tag "Header" head)
904            (const :tag "Last" last)
905            (const :tag "Mime" mime)
906            (integer :tag "Less")
907            (repeat :tag "Groups" regexp)
908            (sexp :tag "Predicate")))
909
910 (defvar gnus-article-treat-head-custom
911   '(choice (const :tag "Off" nil)
912            (const :tag "Header" head)))
913
914 (defvar gnus-article-treat-types '("text/plain")
915   "Parts to treat.")
916
917 (defvar gnus-inhibit-treatment nil
918   "Whether to inhibit treatment.")
919
920 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
921   "Highlight the signature.
922 Valid values are nil, t, `head', `last', an integer or a predicate.
923 See Info node `(gnus)Customizing Articles'."
924   :group 'gnus-article-treat
925   :link '(custom-manual "(gnus)Customizing Articles")
926   :type gnus-article-treat-custom)
927 (put 'gnus-treat-highlight-signature 'highlight t)
928
929 (defcustom gnus-treat-buttonize 100000
930   "Add buttons.
931 Valid values are nil, t, `head', `last', an integer or a predicate.
932 See Info node `(gnus)Customizing Articles'."
933   :group 'gnus-article-treat
934   :link '(custom-manual "(gnus)Customizing Articles")
935   :type gnus-article-treat-custom)
936 (put 'gnus-treat-buttonize 'highlight t)
937
938 (defcustom gnus-treat-buttonize-head 'head
939   "Add buttons to the head.
940 Valid values are nil, t, `head', `last', an integer or a predicate.
941 See Info node `(gnus)Customizing Articles' for details."
942   :group 'gnus-article-treat
943   :link '(custom-manual "(gnus)Customizing Articles")
944   :type gnus-article-treat-head-custom)
945 (put 'gnus-treat-buttonize-head 'highlight t)
946
947 (defcustom gnus-treat-emphasize
948   (and (or window-system
949            (featurep 'xemacs))
950        50000)
951   "Emphasize text.
952 Valid values are nil, t, `head', `last', an integer or a predicate.
953 See Info node `(gnus)Customizing Articles' for details."
954   :group 'gnus-article-treat
955   :link '(custom-manual "(gnus)Customizing Articles")
956   :type gnus-article-treat-custom)
957 (put 'gnus-treat-emphasize 'highlight t)
958
959 (defcustom gnus-treat-strip-cr nil
960   "Remove carriage returns.
961 Valid values are nil, t, `head', `last', an integer or a predicate.
962 See Info node `(gnus)Customizing Articles' for details."
963   :version "21.4"
964   :group 'gnus-article-treat
965   :link '(custom-manual "(gnus)Customizing Articles")
966   :type gnus-article-treat-custom)
967
968 (defcustom gnus-treat-unsplit-urls nil
969   "Remove newlines from within URLs.
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See Info node `(gnus)Customizing Articles' for details."
972   :group 'gnus-article-treat
973   :link '(custom-manual "(gnus)Customizing Articles")
974   :type gnus-article-treat-custom)
975
976 (defcustom gnus-treat-leading-whitespace nil
977   "Remove leading whitespace in headers.
978 Valid values are nil, t, `head', `last', an integer or a predicate.
979 See Info node `(gnus)Customizing Articles' for details."
980   :version "21.4"
981   :group 'gnus-article-treat
982   :link '(custom-manual "(gnus)Customizing Articles")
983   :type gnus-article-treat-custom)
984
985 (defcustom gnus-treat-hide-headers 'head
986   "Hide headers.
987 Valid values are nil, t, `head', `last', an integer or a predicate.
988 See Info node `(gnus)Customizing Articles' for details."
989   :group 'gnus-article-treat
990   :link '(custom-manual "(gnus)Customizing Articles")
991   :type gnus-article-treat-head-custom)
992
993 (defcustom gnus-treat-hide-boring-headers nil
994   "Hide boring headers.
995 Valid values are nil, t, `head', `last', an integer or a predicate.
996 See Info node `(gnus)Customizing Articles' for details."
997   :group 'gnus-article-treat
998   :link '(custom-manual "(gnus)Customizing Articles")
999   :type gnus-article-treat-head-custom)
1000
1001 (defcustom gnus-treat-hide-signature nil
1002   "Hide the signature.
1003 Valid values are nil, t, `head', `last', an integer or a predicate.
1004 See Info node `(gnus)Customizing Articles' for details."
1005   :group 'gnus-article-treat
1006   :link '(custom-manual "(gnus)Customizing Articles")
1007   :type gnus-article-treat-custom)
1008
1009 (defcustom gnus-treat-fill-article nil
1010   "Fill the article.
1011 Valid values are nil, t, `head', `last', an integer or a predicate.
1012 See Info node `(gnus)Customizing Articles' for details."
1013   :group 'gnus-article-treat
1014   :link '(custom-manual "(gnus)Customizing Articles")
1015   :type gnus-article-treat-custom)
1016
1017 (defcustom gnus-treat-hide-citation nil
1018   "Hide cited text.
1019 Valid values are nil, t, `head', `last', an integer or a predicate.
1020 See Info node `(gnus)Customizing Articles' for details."
1021   :group 'gnus-article-treat
1022   :link '(custom-manual "(gnus)Customizing Articles")
1023   :type gnus-article-treat-custom)
1024
1025 (defcustom gnus-treat-hide-citation-maybe nil
1026   "Hide cited text.
1027 Valid values are nil, t, `head', `last', an integer or a predicate.
1028 See Info node `(gnus)Customizing Articles' for details."
1029   :group 'gnus-article-treat
1030   :link '(custom-manual "(gnus)Customizing Articles")
1031   :type gnus-article-treat-custom)
1032
1033 (defcustom gnus-treat-strip-list-identifiers 'head
1034   "Strip list identifiers from `gnus-list-identifiers`.
1035 Valid values are nil, t, `head', `last', an integer or a predicate.
1036 See Info node `(gnus)Customizing Articles' for details."
1037   :version "21.1"
1038   :group 'gnus-article-treat
1039   :link '(custom-manual "(gnus)Customizing Articles")
1040   :type gnus-article-treat-custom)
1041
1042 (make-obsolete-variable 'gnus-treat-strip-pgp
1043                         "This option is obsolete in Gnus 5.10.")
1044
1045 (defcustom gnus-treat-strip-pem nil
1046   "Strip PEM signatures.
1047 Valid values are nil, t, `head', `last', an integer or a predicate.
1048 See Info node `(gnus)Customizing Articles' for details."
1049   :group 'gnus-article-treat
1050   :link '(custom-manual "(gnus)Customizing Articles")
1051   :type gnus-article-treat-custom)
1052
1053 (defcustom gnus-treat-strip-banner t
1054   "Strip banners from articles.
1055 The banner to be stripped is specified in the `banner' group parameter.
1056 Valid values are nil, t, `head', `last', an integer or a predicate.
1057 See Info node `(gnus)Customizing Articles' for details."
1058   :group 'gnus-article-treat
1059   :link '(custom-manual "(gnus)Customizing Articles")
1060   :type gnus-article-treat-custom)
1061
1062 (defcustom gnus-treat-highlight-headers 'head
1063   "Highlight the headers.
1064 Valid values are nil, t, `head', `last', an integer or a predicate.
1065 See Info node `(gnus)Customizing Articles' for details."
1066   :group 'gnus-article-treat
1067   :link '(custom-manual "(gnus)Customizing Articles")
1068   :type gnus-article-treat-head-custom)
1069 (put 'gnus-treat-highlight-headers 'highlight t)
1070
1071 (defcustom gnus-treat-highlight-citation t
1072   "Highlight cited text.
1073 Valid values are nil, t, `head', `last', an integer or a predicate.
1074 See Info node `(gnus)Customizing Articles' for details."
1075   :group 'gnus-article-treat
1076   :link '(custom-manual "(gnus)Customizing Articles")
1077   :type gnus-article-treat-custom)
1078 (put 'gnus-treat-highlight-citation 'highlight t)
1079
1080 (defcustom gnus-treat-date-ut nil
1081   "Display the Date in UT (GMT).
1082 Valid values are nil, t, `head', `last', an integer or a predicate.
1083 See Info node `(gnus)Customizing Articles' for details."
1084   :group 'gnus-article-treat
1085   :link '(custom-manual "(gnus)Customizing Articles")
1086   :type gnus-article-treat-head-custom)
1087
1088 (defcustom gnus-treat-date-local nil
1089   "Display the Date in the local timezone.
1090 Valid values are nil, t, `head', `last', an integer or a predicate.
1091 See Info node `(gnus)Customizing Articles' for details."
1092   :group 'gnus-article-treat
1093   :link '(custom-manual "(gnus)Customizing Articles")
1094   :type gnus-article-treat-head-custom)
1095
1096 (defcustom gnus-treat-date-english nil
1097   "Display the Date in a format that can be read aloud in English.
1098 Valid values are nil, t, `head', `last', an integer or a predicate.
1099 See Info node `(gnus)Customizing Articles' for details."
1100   :version "21.4"
1101   :group 'gnus-article-treat
1102   :link '(custom-manual "(gnus)Customizing Articles")
1103   :type gnus-article-treat-head-custom)
1104
1105 (defcustom gnus-treat-date-lapsed nil
1106   "Display the Date header in a way that says how much time has elapsed.
1107 Valid values are nil, t, `head', `last', an integer or a predicate.
1108 See Info node `(gnus)Customizing Articles' for details."
1109   :group 'gnus-article-treat
1110   :link '(custom-manual "(gnus)Customizing Articles")
1111   :type gnus-article-treat-head-custom)
1112
1113 (defcustom gnus-treat-date-original nil
1114   "Display the date in the original timezone.
1115 Valid values are nil, t, `head', `last', an integer or a predicate.
1116 See Info node `(gnus)Customizing Articles' for details."
1117   :group 'gnus-article-treat
1118   :link '(custom-manual "(gnus)Customizing Articles")
1119   :type gnus-article-treat-head-custom)
1120
1121 (defcustom gnus-treat-date-iso8601 nil
1122   "Display the date in the ISO8601 format.
1123 Valid values are nil, t, `head', `last', an integer or a predicate.
1124 See Info node `(gnus)Customizing Articles' for details."
1125   :version "21.1"
1126   :group 'gnus-article-treat
1127   :link '(custom-manual "(gnus)Customizing Articles")
1128   :type gnus-article-treat-head-custom)
1129
1130 (defcustom gnus-treat-date-user-defined nil
1131   "Display the date in a user-defined format.
1132 The format is defined by the `gnus-article-time-format' variable.
1133 Valid values are nil, t, `head', `last', an integer or a predicate.
1134 See Info node `(gnus)Customizing Articles' for details."
1135   :group 'gnus-article-treat
1136   :link '(custom-manual "(gnus)Customizing Articles")
1137   :type gnus-article-treat-head-custom)
1138
1139 (defcustom gnus-treat-strip-headers-in-body t
1140   "Strip the X-No-Archive header line from the beginning of the body.
1141 Valid values are nil, t, `head', `last', an integer or a predicate.
1142 See Info node `(gnus)Customizing Articles' for details."
1143   :version "21.1"
1144   :group 'gnus-article-treat
1145   :link '(custom-manual "(gnus)Customizing Articles")
1146   :type gnus-article-treat-custom)
1147
1148 (defcustom gnus-treat-strip-trailing-blank-lines nil
1149   "Strip trailing blank lines.
1150 Valid values are nil, t, `head', `last', an integer or a predicate.
1151 See Info node `(gnus)Customizing Articles' for details."
1152   :group 'gnus-article-treat
1153   :link '(custom-manual "(gnus)Customizing Articles")
1154   :type gnus-article-treat-custom)
1155
1156 (defcustom gnus-treat-strip-leading-blank-lines nil
1157   "Strip leading blank lines.
1158 Valid values are nil, t, `head', `last', an integer or a predicate.
1159 See Info node `(gnus)Customizing Articles' for details."
1160   :group 'gnus-article-treat
1161   :link '(custom-manual "(gnus)Customizing Articles")
1162   :type gnus-article-treat-custom)
1163
1164 (defcustom gnus-treat-strip-multiple-blank-lines nil
1165   "Strip multiple blank lines.
1166 Valid values are nil, t, `head', `last', an integer or a predicate.
1167 See Info node `(gnus)Customizing Articles' for details."
1168   :group 'gnus-article-treat
1169   :link '(custom-manual "(gnus)Customizing Articles")
1170   :type gnus-article-treat-custom)
1171
1172 (defcustom gnus-treat-unfold-headers 'head
1173   "Unfold folded header lines.
1174 Valid values are nil, t, `head', `last', an integer or a predicate.
1175 See Info node `(gnus)Customizing Articles' for details."
1176   :group 'gnus-article-treat
1177   :link '(custom-manual "(gnus)Customizing Articles")
1178   :type gnus-article-treat-custom)
1179
1180 (defcustom gnus-treat-fold-headers nil
1181   "Fold headers.
1182 Valid values are nil, t, `head', `last', an integer or a predicate.
1183 See Info node `(gnus)Customizing Articles' for details."
1184   :version "21.4"
1185   :group 'gnus-article-treat
1186   :link '(custom-manual "(gnus)Customizing Articles")
1187   :type gnus-article-treat-custom)
1188
1189 (defcustom gnus-treat-fold-newsgroups 'head
1190   "Fold the Newsgroups and Followup-To headers.
1191 Valid values are nil, t, `head', `last', an integer or a predicate.
1192 See Info node `(gnus)Customizing Articles' for details."
1193   :version "21.4"
1194   :group 'gnus-article-treat
1195   :link '(custom-manual "(gnus)Customizing Articles")
1196   :type gnus-article-treat-custom)
1197
1198 (defcustom gnus-treat-overstrike t
1199   "Treat overstrike highlighting.
1200 Valid values are nil, t, `head', `last', an integer or a predicate.
1201 See Info node `(gnus)Customizing Articles' for details."
1202   :group 'gnus-article-treat
1203   :link '(custom-manual "(gnus)Customizing Articles")
1204   :type gnus-article-treat-custom)
1205 (put 'gnus-treat-overstrike 'highlight t)
1206
1207 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1208   "Treat ANSI SGR control sequences.
1209 Valid values are nil, t, `head', `last', an integer or a predicate.
1210 See Info node `(gnus)Customizing Articles' for details."
1211   :group 'gnus-article-treat
1212   :link '(custom-manual "(gnus)Customizing Articles")
1213   :type gnus-article-treat-custom)
1214
1215 (make-obsolete-variable 'gnus-treat-display-xface
1216                         'gnus-treat-display-x-face)
1217
1218 (defcustom gnus-treat-display-x-face
1219   (and (not noninteractive)
1220        (or (eq gnus-article-x-face-command
1221                'x-face-mule-gnus-article-display-x-face)
1222            (and (fboundp 'image-type-available-p)
1223                 (image-type-available-p 'xbm)
1224                 (string-match "^0x" (shell-command-to-string "uncompface"))
1225                 (executable-find "icontopbm"))
1226            (and (featurep 'xemacs)
1227                 (featurep 'xface)))
1228        'head)
1229   "Display X-Face headers.
1230 Valid values are nil, t, `head', `last', an integer or a predicate.
1231 See Info node `(gnus)Customizing Articles' and Info node
1232 `(gnus)X-Face' for details."
1233   :group 'gnus-article-treat
1234   :version "21.1"
1235   :link '(custom-manual "(gnus)Customizing Articles")
1236   :link '(custom-manual "(gnus)X-Face")
1237   :type gnus-article-treat-head-custom
1238   :set (lambda (symbol value)
1239          (set-default
1240           symbol
1241           (cond ((or (boundp symbol) (get symbol 'saved-value))
1242                  value)
1243                 ((boundp 'gnus-treat-display-xface)
1244                  (message "\
1245 ** gnus-treat-display-xface is an obsolete variable;\
1246  use gnus-treat-display-x-face instead")
1247                  (default-value 'gnus-treat-display-xface))
1248                 ((get 'gnus-treat-display-xface 'saved-value)
1249                  (message "\
1250 ** gnus-treat-display-xface is an obsolete variable;\
1251  use gnus-treat-display-x-face instead")
1252                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1253                 (t
1254                  value)))))
1255 (put 'gnus-treat-display-x-face 'highlight t)
1256
1257 (defcustom gnus-article-should-use-smiley-mule
1258   (not (or (featurep 'xemacs)
1259            (gnus-image-type-available-p 'xpm)
1260            (gnus-image-type-available-p 'pbm)))
1261   "Non-nil means use `smiley-mule' to show smileys rather than `smiley'.
1262 `smiley-mule' is boundled in BITMAP-MULE package.  You can set it to t
1263 even if your Emacs supports images.  It has no effect on XEmacs."
1264   :group 'gnus-article-various
1265   :type 'boolean
1266   :get (lambda (symbol)
1267          (and (not noninteractive)
1268               (default-value symbol)
1269               (not (featurep 'xemacs))
1270               (module-installed-p 'smiley-mule)
1271               t))
1272   :set (lambda (symbol value)
1273          (set-default symbol (and (not noninteractive)
1274                                   value
1275                                   (not (featurep 'xemacs))
1276                                   (module-installed-p 'smiley-mule)
1277                                   t))))
1278
1279 (defvar gnus-article-smiley-mule-loaded-p nil
1280   "Internal variable used to say whether `smiley-mule' is loaded (whether
1281 smiley functions are not overridden by `smiley').")
1282
1283 (defcustom gnus-treat-display-face
1284   (and (not noninteractive)
1285        (or (and (fboundp 'image-type-available-p)
1286                 (image-type-available-p 'png))
1287            (and (featurep 'xemacs)
1288                 (featurep 'png)))
1289        'head)
1290   "Display Face headers.
1291 Valid values are nil, t, `head', `last', an integer or a predicate.
1292 See Info node `(gnus)Customizing Articles' and Info node
1293 `(gnus)X-Face' for details."
1294   :group 'gnus-article-treat
1295   :version "21.4"
1296   :link '(custom-manual "(gnus)Customizing Articles")
1297   :link '(custom-manual "(gnus)X-Face")
1298   :type gnus-article-treat-head-custom)
1299 (put 'gnus-treat-display-face 'highlight t)
1300
1301 (defcustom gnus-treat-display-smileys
1302   (if (and (not noninteractive)
1303            (or (and (featurep 'xemacs)
1304                     (featurep 'xpm))
1305                (gnus-image-type-available-p 'xpm)
1306                (gnus-image-type-available-p 'pbm)
1307                (and (not (featurep 'xemacs))
1308                     window-system
1309                     (module-installed-p 'smiley-mule))))
1310       t
1311     nil)
1312   "Display smileys.
1313 Valid values are nil, t, `head', `last', an integer or a predicate.
1314 See Info node `(gnus)Customizing Articles' and Info node
1315 `(gnus)Smileys' for details."
1316   :group 'gnus-article-treat
1317   :version "21.1"
1318   :link '(custom-manual "(gnus)Customizing Articles")
1319   :link '(custom-manual "(gnus)Smileys")
1320   :type gnus-article-treat-custom)
1321 (put 'gnus-treat-display-smileys 'highlight t)
1322
1323 (defcustom gnus-treat-from-picon
1324   (if (and (gnus-image-type-available-p 'xpm)
1325            (gnus-picons-installed-p))
1326       'head nil)
1327   "Display picons in the From header.
1328 Valid values are nil, t, `head', `last', an integer or a predicate.
1329 See Info node `(gnus)Customizing Articles' and Info node
1330 `(gnus)Picons' for details."
1331   :group 'gnus-article-treat
1332   :group 'gnus-picon
1333   :link '(custom-manual "(gnus)Customizing Articles")
1334   :link '(custom-manual "(gnus)Picons")
1335   :type gnus-article-treat-head-custom)
1336 (put 'gnus-treat-from-picon 'highlight t)
1337
1338 (defcustom gnus-treat-mail-picon
1339   (if (and (gnus-image-type-available-p 'xpm)
1340            (gnus-picons-installed-p))
1341       'head nil)
1342   "Display picons in To and Cc headers.
1343 Valid values are nil, t, `head', `last', an integer or a predicate.
1344 See Info node `(gnus)Customizing Articles' and Info node
1345 `(gnus)Picons' for details."
1346   :group 'gnus-article-treat
1347   :group 'gnus-picon
1348   :link '(custom-manual "(gnus)Customizing Articles")
1349   :link '(custom-manual "(gnus)Picons")
1350   :type gnus-article-treat-head-custom)
1351 (put 'gnus-treat-mail-picon 'highlight t)
1352
1353 (defcustom gnus-treat-newsgroups-picon
1354   (if (and (gnus-image-type-available-p 'xpm)
1355            (gnus-picons-installed-p))
1356       'head nil)
1357   "Display picons in the Newsgroups and Followup-To headers.
1358 Valid values are nil, t, `head', `last', an integer or a predicate.
1359 See Info node `(gnus)Customizing Articles' and Info node
1360 `(gnus)Picons' for details."
1361   :version "21.4"
1362   :group 'gnus-article-treat
1363   :group 'gnus-picon
1364   :link '(custom-manual "(gnus)Customizing Articles")
1365   :link '(custom-manual "(gnus)Picons")
1366   :type gnus-article-treat-head-custom)
1367 (put 'gnus-treat-newsgroups-picon 'highlight t)
1368
1369 (defcustom gnus-treat-body-boundary
1370   (if (or gnus-treat-newsgroups-picon
1371           gnus-treat-mail-picon
1372           gnus-treat-from-picon)
1373       'head nil)
1374   "Draw a boundary at the end of the headers.
1375 Valid values are nil and `head'.
1376 See Info node `(gnus)Customizing Articles' for details."
1377   :version "21.4"
1378   :group 'gnus-article-treat
1379   :link '(custom-manual "(gnus)Customizing Articles")
1380   :type gnus-article-treat-head-custom)
1381
1382 (defcustom gnus-treat-capitalize-sentences nil
1383   "Capitalize sentence-starting words.
1384 Valid values are nil, t, `head', `last', an integer or a predicate.
1385 See Info node `(gnus)Customizing Articles' for details."
1386   :version "21.1"
1387   :group 'gnus-article-treat
1388   :link '(custom-manual "(gnus)Customizing Articles")
1389   :type gnus-article-treat-custom)
1390
1391 (defcustom gnus-treat-wash-html nil
1392   "Format as HTML.
1393 Valid values are nil, t, `head', `last', an integer or a predicate.
1394 See Info node `(gnus)Customizing Articles' for details."
1395   :version "21.4"
1396   :group 'gnus-article-treat
1397   :link '(custom-manual "(gnus)Customizing Articles")
1398   :type gnus-article-treat-custom)
1399
1400 (defcustom gnus-treat-fill-long-lines nil
1401   "Fill long lines.
1402 Valid values are nil, t, `head', `last', an integer or a predicate.
1403 See Info node `(gnus)Customizing Articles' for details."
1404   :group 'gnus-article-treat
1405   :link '(custom-manual "(gnus)Customizing Articles")
1406   :type gnus-article-treat-custom)
1407
1408 (defcustom gnus-treat-play-sounds nil
1409   "Play sounds.
1410 Valid values are nil, t, `head', `last', an integer or a predicate.
1411 See Info node `(gnus)Customizing Articles' for details."
1412   :version "21.1"
1413   :group 'gnus-article-treat
1414   :link '(custom-manual "(gnus)Customizing Articles")
1415   :type gnus-article-treat-custom)
1416
1417 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1418   "Decode an article as `default-mime-charset'.  For instance, if you want to
1419 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1420 you could set this variable to something like: nil for don't decode, t for
1421 decode the body, '(or header t) for the whole article, etc."
1422   :group 'gnus-article-treat
1423   :type '(radio (const :tag "Off" nil)
1424                 (const :tag "Decode body" t)
1425                 (const :tag "Decode all" (or head t))))
1426
1427 (defcustom gnus-treat-translate nil
1428   "Translate articles from one language to another.
1429 Valid values are nil, t, `head', `last', an integer or a predicate.
1430 See Info node `(gnus)Customizing Articles' for details."
1431   :version "21.1"
1432   :group 'gnus-article-treat
1433   :link '(custom-manual "(gnus)Customizing Articles")
1434   :type gnus-article-treat-custom)
1435
1436 (defcustom gnus-treat-x-pgp-sig nil
1437   "Verify X-PGP-Sig.
1438 To automatically treat X-PGP-Sig, set it to head.
1439 Valid values are nil, t, `head', `last', an integer or a predicate.
1440 See Info node `(gnus)Customizing Articles' for details."
1441   :group 'gnus-article-treat
1442   :group 'mime-security
1443   :type gnus-article-treat-custom)
1444
1445 (defcustom gnus-treat-monafy nil
1446   "Display body part with mona font.
1447 Valid values are nil, t, `head', `last', an integer or a predicate.
1448 See Info node `(gnus)Customizing Articles' for details."
1449   :group 'gnus-article-treat
1450   :group 'mime-security
1451   :link '(custom-manual "(gnus)Customizing Articles")
1452   :type gnus-article-treat-custom)
1453
1454 (defvar gnus-article-encrypt-protocol-alist
1455   '(("PGP" . mml2015-self-encrypt)))
1456
1457 ;; Set to nil if more than one protocol added to
1458 ;; gnus-article-encrypt-protocol-alist.
1459 (defcustom gnus-article-encrypt-protocol "PGP"
1460   "The protocol used for encrypt articles.
1461 It is a string, such as \"PGP\". If nil, ask user."
1462   :version "21.4"
1463   :type 'string
1464   :group 'mime-security)
1465
1466 (defvar gnus-article-wash-function nil
1467   "Function used for converting HTML into text.")
1468
1469 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1470                               (mm-coding-system-p 'utf-8)
1471                               (executable-find idna-program))
1472   "Whether IDNA decoding of headers is used when viewing messages.
1473 This requires GNU Libidn, and by default only enabled if it is found."
1474   :version "21.4"
1475   :group 'gnus-article-headers
1476   :type 'boolean)
1477
1478 (defcustom gnus-article-over-scroll nil
1479   "If non-nil, allow scrolling the article buffer even when there no more text."
1480   :version "21.4"
1481   :group 'gnus-article
1482   :type 'boolean)
1483
1484 ;;; Internal variables
1485
1486 (defvar gnus-english-month-names
1487   '("January" "February" "March" "April" "May" "June" "July" "August"
1488     "September" "October" "November" "December"))
1489
1490 (defvar gnus-button-regexp nil)
1491 (defvar gnus-button-marker-list nil)
1492 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1493
1494 (defvar gnus-button-last nil)
1495 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1496
1497 (defvar article-goto-body-goes-to-point-min-p nil)
1498 (defvar gnus-article-wash-types nil)
1499 (defvar gnus-article-emphasis-alist nil)
1500 (defvar gnus-article-image-alist nil)
1501
1502 (defvar gnus-article-mime-handle-alist-1 nil)
1503 (defvar gnus-treatment-function-alist
1504   '((gnus-treat-decode-article-as-default-mime-charset
1505      gnus-article-decode-article-as-default-mime-charset)
1506     (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1507     (gnus-treat-monafy gnus-article-monafy)
1508     (gnus-treat-strip-banner gnus-article-strip-banner)
1509     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1510     (gnus-treat-buttonize gnus-article-add-buttons)
1511     (gnus-treat-fill-article gnus-article-fill-cited-article)
1512     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1513     (gnus-treat-strip-cr gnus-article-remove-cr)
1514     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1515     (gnus-treat-date-ut gnus-article-date-ut)
1516     (gnus-treat-date-local gnus-article-date-local)
1517     (gnus-treat-date-english gnus-article-date-english)
1518     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1519     (gnus-treat-date-original gnus-article-date-original)
1520     (gnus-treat-date-user-defined gnus-article-date-user)
1521     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1522     (gnus-treat-display-face gnus-article-display-face)
1523     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1524     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1525     (gnus-treat-hide-signature gnus-article-hide-signature)
1526     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1527     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1528     (gnus-treat-strip-pem gnus-article-hide-pem)
1529     (gnus-treat-from-picon gnus-treat-from-picon)
1530     (gnus-treat-mail-picon gnus-treat-mail-picon)
1531     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1532     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1533     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1534     (gnus-treat-strip-trailing-blank-lines
1535      gnus-article-remove-trailing-blank-lines)
1536     (gnus-treat-strip-leading-blank-lines
1537      gnus-article-strip-leading-blank-lines)
1538     (gnus-treat-strip-multiple-blank-lines
1539      gnus-article-strip-multiple-blank-lines)
1540     (gnus-treat-overstrike gnus-article-treat-overstrike)
1541     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1542     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1543     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1544     ;; Displaying X-Face should be done after unfolding headers
1545     ;; to protect bitmap lines.
1546     (gnus-treat-display-x-face gnus-article-display-x-face)
1547     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1548     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1549     (gnus-treat-display-smileys gnus-treat-smiley)
1550     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1551     (gnus-treat-wash-html gnus-article-wash-html)
1552     (gnus-treat-emphasize gnus-article-emphasize)
1553     (gnus-treat-hide-citation gnus-article-hide-citation)
1554     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1555     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1556     (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1557     (gnus-treat-play-sounds gnus-earcon-display)))
1558
1559 (defvar gnus-article-mime-handle-alist nil)
1560 (defvar article-lapsed-timer nil)
1561 (defvar gnus-article-current-summary nil)
1562
1563 (defvar gnus-article-mode-syntax-table
1564   (let ((table (copy-syntax-table text-mode-syntax-table)))
1565     ;; This causes the citation match run O(2^n).
1566     ;; (modify-syntax-entry ?- "w" table)
1567     (modify-syntax-entry ?> ")<" table)
1568     (modify-syntax-entry ?< "(>" table)
1569     ;; make M-. in article buffers work for `foo' strings
1570     (modify-syntax-entry ?' " " table)
1571     (modify-syntax-entry ?` " " table)
1572     table)
1573   "Syntax table used in article mode buffers.
1574 Initialized from `text-mode-syntax-table.")
1575
1576 (defvar gnus-save-article-buffer nil)
1577
1578 (defvar gnus-article-mode-line-format-alist
1579   (nconc '((?w (gnus-article-wash-status) ?s)
1580            (?m (gnus-article-mime-part-status) ?s))
1581          gnus-summary-mode-line-format-alist))
1582
1583 (defvar gnus-number-of-articles-to-be-saved nil)
1584
1585 (defvar gnus-inhibit-hiding nil)
1586
1587 (defvar gnus-article-edit-mode nil)
1588
1589 ;;; Macros for dealing with the article buffer.
1590
1591 (defmacro gnus-with-article-headers (&rest forms)
1592   `(save-excursion
1593      (set-buffer gnus-article-buffer)
1594      (save-restriction
1595        (let ((inhibit-read-only t)
1596              (inhibit-point-motion-hooks t)
1597              (case-fold-search t))
1598          (article-narrow-to-head)
1599          ,@forms))))
1600
1601 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1602 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1603
1604 (defmacro gnus-with-article-buffer (&rest forms)
1605   `(save-excursion
1606      (set-buffer gnus-article-buffer)
1607      (let ((inhibit-read-only t))
1608        ,@forms)))
1609
1610 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1611 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1612
1613 (defun gnus-article-goto-header (header)
1614   "Go to HEADER, which is a regular expression."
1615   (re-search-forward (concat "^\\(" header "\\):") nil t))
1616
1617 (defsubst gnus-article-hide-text (b e props)
1618   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1619   (gnus-add-text-properties-when 'article-type nil b e props)
1620   (when (memq 'intangible props)
1621     (put-text-property
1622      (max (1- b) (point-min))
1623      b 'intangible (cddr (memq 'intangible props)))))
1624
1625 (defsubst gnus-article-unhide-text (b e)
1626   "Remove hidden text properties from region between B and E."
1627   (remove-text-properties b e gnus-hidden-properties)
1628   (when (memq 'intangible gnus-hidden-properties)
1629     (put-text-property (max (1- b) (point-min))
1630                        b 'intangible nil)))
1631
1632 (defun gnus-article-hide-text-type (b e type)
1633   "Hide text of TYPE between B and E."
1634   (gnus-add-wash-type type)
1635   (gnus-article-hide-text
1636    b e (cons 'article-type (cons type gnus-hidden-properties))))
1637
1638 (defun gnus-article-unhide-text-type (b e type)
1639   "Unhide text of TYPE between B and E."
1640   (gnus-delete-wash-type type)
1641   (remove-text-properties
1642    b e (cons 'article-type (cons type gnus-hidden-properties)))
1643   (when (memq 'intangible gnus-hidden-properties)
1644     (put-text-property (max (1- b) (point-min))
1645                        b 'intangible nil)))
1646
1647 (defun gnus-article-hide-text-of-type (type)
1648   "Hide text of TYPE in the current buffer."
1649   (save-excursion
1650     (let ((b (point-min))
1651           (e (point-max)))
1652       (while (setq b (text-property-any b e 'article-type type))
1653         (add-text-properties b (incf b) gnus-hidden-properties)))))
1654
1655 (defun gnus-article-delete-text-of-type (type)
1656   "Delete text of TYPE in the current buffer."
1657   (save-excursion
1658     (let ((b (point-min)))
1659       (while (setq b (text-property-any b (point-max) 'article-type type))
1660         (delete-region
1661          b (or (text-property-not-all b (point-max) 'article-type type)
1662                (point-max)))))))
1663
1664 (defun gnus-article-delete-invisible-text ()
1665   "Delete all invisible text in the current buffer."
1666   (save-excursion
1667     (let ((b (point-min)))
1668       (while (setq b (text-property-any b (point-max) 'invisible t))
1669         (delete-region
1670          b (or (text-property-not-all b (point-max) 'invisible t)
1671                (point-max)))))))
1672
1673 (defun gnus-article-text-type-exists-p (type)
1674   "Say whether any text of type TYPE exists in the buffer."
1675   (text-property-any (point-min) (point-max) 'article-type type))
1676
1677 (defsubst gnus-article-header-rank ()
1678   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1679   (let ((list gnus-sorted-header-list)
1680         (i 1))
1681     (while list
1682       (if (looking-at (car list))
1683           (setq list nil)
1684         (setq list (cdr list))
1685         (incf i)))
1686       i))
1687
1688 (defun article-hide-headers (&optional arg delete)
1689   "Hide unwanted headers and possibly sort them as well."
1690   (interactive (gnus-article-hidden-arg))
1691   ;; Lars said that this function might be inhibited.
1692   (if (gnus-article-check-hidden-text 'headers arg)
1693       (progn
1694         ;; Show boring headers as well.
1695         (gnus-article-show-hidden-text 'boring-headers)
1696         (when (eq 1 (point-min))
1697           (set-window-start (get-buffer-window (current-buffer)) 1)))
1698     (unless gnus-inhibit-hiding
1699       (let ((inhibit-read-only t)
1700             (case-fold-search t)
1701             (max (1+ (length gnus-sorted-header-list)))
1702             (inhibit-point-motion-hooks t)
1703             (cur (current-buffer))
1704             ignored visible beg)
1705         (save-excursion
1706           ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1707           ;; group parameters, so we should go to the summary buffer.
1708           (when (prog1
1709                     (condition-case nil
1710                         (progn (set-buffer gnus-summary-buffer) t)
1711                       (error nil))
1712                   (setq ignored (when (not gnus-visible-headers)
1713                                   (cond ((stringp gnus-ignored-headers)
1714                                          gnus-ignored-headers)
1715                                         ((listp gnus-ignored-headers)
1716                                          (mapconcat 'identity
1717                                                     gnus-ignored-headers
1718                                                     "\\|"))))
1719                         visible (cond ((stringp gnus-visible-headers)
1720                                        gnus-visible-headers)
1721                                       ((and gnus-visible-headers
1722                                             (listp gnus-visible-headers))
1723                                        (mapconcat 'identity
1724                                                   gnus-visible-headers
1725                                                   "\\|")))))
1726             (set-buffer cur))
1727           (save-restriction
1728             ;; First we narrow to just the headers.
1729             (article-narrow-to-head)
1730             ;; Hide any "From " lines at the beginning of (mail) articles.
1731             (while (looking-at "From ")
1732               (forward-line 1))
1733             (unless (bobp)
1734               (if delete
1735                   (delete-region (point-min) (point))
1736                 (gnus-article-hide-text (point-min) (point)
1737                                         (nconc (list 'article-type 'headers)
1738                                                gnus-hidden-properties))))
1739             ;; Then treat the rest of the header lines.
1740             ;; Then we use the two regular expressions
1741             ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1742             ;; select which header lines is to remain visible in the
1743             ;; article buffer.
1744             (while (re-search-forward "^[^ \t:]*:" nil t)
1745               (beginning-of-line)
1746               ;; Mark the rank of the header.
1747               (put-text-property
1748                (point) (1+ (point)) 'message-rank
1749                (if (or (and visible (looking-at visible))
1750                        (and ignored
1751                             (not (looking-at ignored))))
1752                    (gnus-article-header-rank)
1753                  (+ 2 max)))
1754               (forward-line 1))
1755             (message-sort-headers-1)
1756             (when (setq beg (text-property-any
1757                              (point-min) (point-max) 'message-rank (+ 2 max)))
1758               ;; We delete or make invisible the unwanted headers.
1759               (gnus-add-wash-type 'headers)
1760               (if delete
1761                   (progn
1762                     (add-text-properties
1763                      (point-min) (+ 5 (point-min))
1764                      '(article-type headers dummy-invisible t))
1765                     (delete-region beg (point-max)))
1766                 (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
1767
1768 (defun article-hide-boring-headers (&optional arg)
1769   "Toggle hiding of headers that aren't very interesting.
1770 If given a negative prefix, always show; if given a positive prefix,
1771 always hide."
1772   (interactive (gnus-article-hidden-arg))
1773   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1774              (not gnus-show-all-headers))
1775     (save-excursion
1776       (save-restriction
1777         (let ((inhibit-read-only t)
1778               (list gnus-boring-article-headers)
1779               (inhibit-point-motion-hooks t)
1780               elem)
1781           (article-narrow-to-head)
1782           (while list
1783             (setq elem (pop list))
1784             (goto-char (point-min))
1785             (cond
1786              ;; Hide empty headers.
1787              ((eq elem 'empty)
1788               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1789                 (forward-line -1)
1790                 (gnus-article-hide-text-type
1791                  (point-at-bol)
1792                  (progn
1793                    (end-of-line)
1794                    (if (re-search-forward "^[^ \t]" nil t)
1795                        (match-beginning 0)
1796                      (point-max)))
1797                  'boring-headers)))
1798              ;; Hide boring Newsgroups header.
1799              ((eq elem 'newsgroups)
1800               (when (gnus-string-equal
1801                      (gnus-fetch-field "newsgroups")
1802                      (gnus-group-real-name
1803                       (if (boundp 'gnus-newsgroup-name)
1804                           gnus-newsgroup-name
1805                         "")))
1806                 (gnus-article-hide-header "newsgroups")))
1807              ((eq elem 'to-address)
1808               (let ((to (message-fetch-field "to"))
1809                     (to-address
1810                      (gnus-parameter-to-address
1811                       (if (boundp 'gnus-newsgroup-name)
1812                           gnus-newsgroup-name ""))))
1813                 (when (and to to-address
1814                            (ignore-errors
1815                              (gnus-string-equal
1816                               ;; only one address in To
1817                               (nth 1 (mail-extract-address-components to))
1818                               to-address)))
1819                   (gnus-article-hide-header "to"))))
1820              ((eq elem 'to-list)
1821               (let ((to (message-fetch-field "to"))
1822                     (to-list
1823                      (gnus-parameter-to-list
1824                       (if (boundp 'gnus-newsgroup-name)
1825                           gnus-newsgroup-name ""))))
1826                 (when (and to to-list
1827                            (ignore-errors
1828                              (gnus-string-equal
1829                               ;; only one address in To
1830                               (nth 1 (mail-extract-address-components to))
1831                               to-list)))
1832                   (gnus-article-hide-header "to"))))
1833              ((eq elem 'cc-list)
1834               (let ((cc (message-fetch-field "cc"))
1835                     (to-list
1836                      (gnus-parameter-to-list
1837                       (if (boundp 'gnus-newsgroup-name)
1838                           gnus-newsgroup-name ""))))
1839                 (when (and cc to-list
1840                            (ignore-errors
1841                              (gnus-string-equal
1842                               ;; only one address in CC
1843                               (nth 1 (mail-extract-address-components cc))
1844                               to-list)))
1845                   (gnus-article-hide-header "cc"))))
1846              ((eq elem 'followup-to)
1847               (when (gnus-string-equal
1848                      (message-fetch-field "followup-to")
1849                      (message-fetch-field "newsgroups"))
1850                 (gnus-article-hide-header "followup-to")))
1851              ((eq elem 'reply-to)
1852               (if (gnus-group-find-parameter
1853                    gnus-newsgroup-name 'broken-reply-to)
1854                   (gnus-article-hide-header "reply-to")
1855                 (let ((from (message-fetch-field "from"))
1856                       (reply-to (message-fetch-field "reply-to")))
1857                   (when
1858                       (and
1859                        from reply-to
1860                        (ignore-errors
1861                          (equal
1862                           (sort (mapcar
1863                                  (lambda (x) (downcase (cadr x)))
1864                                  (mail-extract-address-components from t))
1865                                 'string<)
1866                           (sort (mapcar
1867                                  (lambda (x) (downcase (cadr x)))
1868                                  (mail-extract-address-components reply-to t))
1869                                 'string<))))
1870                     (gnus-article-hide-header "reply-to")))))
1871              ((eq elem 'date)
1872               (let ((date (message-fetch-field "date")))
1873                 (when (and date
1874                            (< (days-between (current-time-string) date)
1875                               4))
1876                   (gnus-article-hide-header "date"))))
1877              ((eq elem 'long-to)
1878               (let ((to (message-fetch-field "to"))
1879                     (cc (message-fetch-field "cc")))
1880                 (when (> (length to) 1024)
1881                   (gnus-article-hide-header "to"))
1882                 (when (> (length cc) 1024)
1883                   (gnus-article-hide-header "cc"))))
1884              ((eq elem 'many-to)
1885               (let ((to-count 0)
1886                     (cc-count 0))
1887                 (goto-char (point-min))
1888                 (while (re-search-forward "^to:" nil t)
1889                   (setq to-count (1+ to-count)))
1890                 (when (> to-count 1)
1891                   (while (> to-count 0)
1892                     (goto-char (point-min))
1893                     (save-restriction
1894                       (re-search-forward "^to:" nil nil to-count)
1895                       (forward-line -1)
1896                       (narrow-to-region (point) (point-max))
1897                       (gnus-article-hide-header "to"))
1898                     (setq to-count (1- to-count))))
1899                 (goto-char (point-min))
1900                 (while (re-search-forward "^cc:" nil t)
1901                   (setq cc-count (1+ cc-count)))
1902                 (when (> cc-count 1)
1903                   (while (> cc-count 0)
1904                     (goto-char (point-min))
1905                     (save-restriction
1906                       (re-search-forward "^cc:" nil nil cc-count)
1907                       (forward-line -1)
1908                       (narrow-to-region (point) (point-max))
1909                       (gnus-article-hide-header "cc"))
1910                     (setq cc-count (1- cc-count)))))))))))))
1911
1912 (defun gnus-article-hide-header (header)
1913   (save-excursion
1914     (goto-char (point-min))
1915     (when (re-search-forward (concat "^" header ":") nil t)
1916       (gnus-article-hide-text-type
1917        (point-at-bol)
1918        (progn
1919          (end-of-line)
1920          (if (re-search-forward "^[^ \t]" nil t)
1921              (match-beginning 0)
1922            (point-max)))
1923        'boring-headers))))
1924
1925 (defvar gnus-article-normalized-header-length 40
1926   "Length of normalized headers.")
1927
1928 (defun article-normalize-headers ()
1929   "Make all header lines 40 characters long."
1930   (interactive)
1931   (let ((inhibit-read-only t)
1932         column)
1933     (save-excursion
1934       (save-restriction
1935         (article-narrow-to-head)
1936         (while (not (eobp))
1937           (cond
1938            ((< (setq column (- (point-at-eol) (point)))
1939                gnus-article-normalized-header-length)
1940             (end-of-line)
1941             (insert (make-string
1942                      (- gnus-article-normalized-header-length column)
1943                      ? )))
1944            ((> column gnus-article-normalized-header-length)
1945             (gnus-put-text-property
1946              (progn
1947                (forward-char gnus-article-normalized-header-length)
1948                (point))
1949              (point-at-eol)
1950              'invisible t))
1951            (t
1952             ;; Do nothing.
1953             ))
1954           (forward-line 1))))))
1955
1956 (defun article-treat-dumbquotes ()
1957   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1958 Note that this function guesses whether a character is a sm*rtq**t* or
1959 not, so it should only be used interactively.
1960
1961 Sm*rtq**t*s are M****s***'s unilateral extension to the
1962 iso-8859-1 character map in an attempt to provide more quoting
1963 characters.  If you see something like \\222 or \\264 where
1964 you're expecting some kind of apostrophe or quotation mark, then
1965 try this wash."
1966   (interactive)
1967   (article-translate-strings gnus-article-dumbquotes-map))
1968
1969 (defun article-translate-characters (from to)
1970   "Translate all characters in the body of the article according to FROM and TO.
1971 FROM is a string of characters to translate from; to is a string of
1972 characters to translate to."
1973   (save-excursion
1974     (when (article-goto-body)
1975       (let ((inhibit-read-only t)
1976             (x (make-string 225 ?x))
1977             (i -1))
1978         (while (< (incf i) (length x))
1979           (aset x i i))
1980         (setq i 0)
1981         (while (< i (length from))
1982           (aset x (aref from i) (aref to i))
1983           (incf i))
1984         (translate-region (point) (point-max) x)))))
1985
1986 (defun article-translate-strings (map)
1987   "Translate all string in the body of the article according to MAP.
1988 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1989   (save-excursion
1990     (when (article-goto-body)
1991       (let ((inhibit-read-only t)
1992             elem)
1993         (while (setq elem (pop map))
1994           (save-excursion
1995             (while (search-forward (car elem) nil t)
1996               (replace-match (cadr elem)))))))))
1997
1998 (defun article-treat-overstrike ()
1999   "Translate overstrikes into bold text."
2000   (interactive)
2001   (save-excursion
2002     (when (article-goto-body)
2003       (let ((inhibit-read-only t))
2004         (while (search-forward "\b" nil t)
2005           (let ((next (char-after))
2006                 start end previous)
2007             (backward-char 2)
2008             (setq start (point)
2009                   previous (char-after))
2010             (forward-char 3)
2011             (setq end (point))
2012             (backward-char)
2013             ;; We do the boldification/underlining by hiding the
2014             ;; overstrikes and putting the proper text property
2015             ;; on the letters.
2016             (cond
2017              ((eq next previous)
2018               (gnus-article-hide-text-type start (point) 'overstrike)
2019               (put-text-property (point) end 'face 'bold))
2020              ((eq next ?_)
2021               (gnus-article-hide-text-type
2022                (1- (point)) (1+ (point)) 'overstrike)
2023               (put-text-property
2024                start (1- (point)) 'face 'underline))
2025              ((eq previous ?_)
2026               (gnus-article-hide-text-type start (point) 'overstrike)
2027               (put-text-property
2028                (point) end 'face 'underline)))))))))
2029
2030 (defun article-treat-ansi-sequences ()
2031   "Translate ANSI SGR control sequences into overlays or extents."
2032   (interactive)
2033   (save-excursion
2034     (when (article-goto-body)
2035       (let ((inhibit-read-only t))
2036         (ansi-color-apply-on-region (point) (point-max))))))
2037
2038 (defun gnus-article-treat-unfold-headers ()
2039   "Unfold folded message headers.
2040 Only the headers that fit into the current window width will be
2041 unfolded."
2042   (interactive)
2043   (gnus-with-article-headers
2044     (let (length)
2045       (while (not (eobp))
2046         (save-restriction
2047           (mail-header-narrow-to-field)
2048           (let ((header (buffer-string)))
2049             (with-temp-buffer
2050               (insert header)
2051               (goto-char (point-min))
2052               (while (re-search-forward "\n[\t ]" nil t)
2053                 (replace-match " " t t)))
2054             (setq length (- (point-max) (point-min) 1)))
2055           (when (< length (window-width))
2056             (while (re-search-forward "\n[\t ]" nil t)
2057               (replace-match " " t t)))
2058           (goto-char (point-max)))))))
2059
2060 (defun gnus-article-treat-fold-headers ()
2061   "Fold message headers."
2062   (interactive)
2063   (gnus-with-article-headers
2064     (while (not (eobp))
2065       (save-restriction
2066         (mail-header-narrow-to-field)
2067         (mail-header-fold-field)
2068         (goto-char (point-max))))))
2069
2070 (defun gnus-treat-smiley ()
2071   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2072   (interactive)
2073   (unless (featurep 'xemacs)
2074     (when (and (not gnus-article-should-use-smiley-mule)
2075                gnus-article-smiley-mule-loaded-p)
2076       (load "smiley" nil t)
2077       (setq gnus-article-smiley-mule-loaded-p nil))
2078     (when (and gnus-article-should-use-smiley-mule
2079                (not gnus-article-smiley-mule-loaded-p))
2080       (load "smiley-mule" nil t)
2081       (setq gnus-article-smiley-mule-loaded-p t)))
2082   (gnus-with-article-buffer
2083     (if (memq 'smiley gnus-article-wash-types)
2084         (gnus-delete-images 'smiley)
2085       (article-goto-body)
2086       (let ((images (smiley-region (point) (point-max))))
2087         (when images
2088           (gnus-add-wash-type 'smiley)
2089           (dolist (image images)
2090             (gnus-add-image 'smiley image)))))))
2091
2092 (defun gnus-article-remove-images ()
2093   "Remove all images from the article buffer."
2094   (interactive)
2095   (gnus-with-article-buffer
2096     (dolist (elem gnus-article-image-alist)
2097       (gnus-delete-images (car elem)))))
2098
2099 (defun gnus-article-treat-fold-newsgroups ()
2100   "Unfold folded message headers.
2101 Only the headers that fit into the current window width will be
2102 unfolded."
2103   (interactive)
2104   (gnus-with-article-headers
2105     (while (gnus-article-goto-header "newsgroups\\|followup-to")
2106       (save-restriction
2107         (mail-header-narrow-to-field)
2108         (while (re-search-forward ", *" nil t)
2109           (replace-match ", " t t))
2110         (mail-header-fold-field)
2111         (goto-char (point-max))))))
2112
2113 (defun gnus-article-treat-body-boundary ()
2114   "Place a boundary line at the end of the headers."
2115   (interactive)
2116   (when (and gnus-body-boundary-delimiter
2117              (> (length gnus-body-boundary-delimiter) 0))
2118     (gnus-with-article-headers
2119       (goto-char (point-max))
2120       (let ((start (point)))
2121         (insert "X-Boundary: ")
2122         (gnus-add-text-properties start (point) '(invisible t intangible t))
2123         (insert (let (str)
2124                   (while (>= (1- (window-width)) (length str))
2125                     (setq str (concat str gnus-body-boundary-delimiter)))
2126                   (substring str 0 (1- (window-width))))
2127                 "\n")
2128         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2129
2130 (defun article-fill-long-lines ()
2131   "Fill lines that are wider than the window width."
2132   (interactive)
2133   (save-excursion
2134     (let ((inhibit-read-only t)
2135           (width (window-width (get-buffer-window (current-buffer)))))
2136       (save-restriction
2137         (article-goto-body)
2138         (let ((adaptive-fill-mode nil)) ;Why?  -sm
2139           (while (not (eobp))
2140             (end-of-line)
2141             (when (>= (current-column) (min fill-column width))
2142               (narrow-to-region (min (1+ (point)) (point-max))
2143                                 (point-at-bol))
2144               (let ((goback (point-marker)))
2145                 (fill-paragraph nil)
2146                 (goto-char (marker-position goback)))
2147               (widen))
2148             (forward-line 1)))))))
2149
2150 (defun article-capitalize-sentences ()
2151   "Capitalize the first word in each sentence."
2152   (interactive)
2153   (save-excursion
2154     (let ((inhibit-read-only t)
2155           (paragraph-start "^[\n\^L]"))
2156       (article-goto-body)
2157       (while (not (eobp))
2158         (capitalize-word 1)
2159         (forward-sentence)))))
2160
2161 (defun article-remove-cr ()
2162   "Remove trailing CRs and then translate remaining CRs into LFs."
2163   (interactive)
2164   (save-excursion
2165     (let ((inhibit-read-only t))
2166       (goto-char (point-min))
2167       (while (re-search-forward "\r+$" nil t)
2168         (replace-match "" t t))
2169       (goto-char (point-min))
2170       (while (search-forward "\r" nil t)
2171         (replace-match "\n" t t)))))
2172
2173 (defun article-remove-trailing-blank-lines ()
2174   "Remove all trailing blank lines from the article."
2175   (interactive)
2176   (save-excursion
2177     (let ((inhibit-read-only t))
2178       (goto-char (point-max))
2179       (delete-region
2180        (point)
2181        (progn
2182          (while (and (not (bobp))
2183                      (looking-at "^[ \t]*$")
2184                      (not (gnus-annotation-in-region-p
2185                            (point) (point-at-eol))))
2186            (forward-line -1))
2187          (forward-line 1)
2188          (point))))))
2189
2190 (eval-when-compile
2191   (defvar gnus-face-properties-alist))
2192
2193 (defun article-display-face ()
2194   "Display any Face headers in the header."
2195   (interactive)
2196   (let ((wash-face-p buffer-read-only))
2197     (gnus-with-article-headers
2198       ;; When displaying parts, this function can be called several times on
2199       ;; the same article, without any intended toggle semantic (as typing `W
2200       ;; D d' would have). So face deletion must occur only when we come from
2201       ;; an interactive command, that is when the *Article* buffer is
2202       ;; read-only.
2203       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2204           (gnus-delete-images 'face)
2205         (let (face faces)
2206           (save-excursion
2207             (when (and wash-face-p
2208                        (progn
2209                          (goto-char (point-min))
2210                          (not (re-search-forward "^Face:[\t ]*" nil t)))
2211                        (gnus-buffer-live-p gnus-original-article-buffer))
2212               (set-buffer gnus-original-article-buffer))
2213             (save-restriction
2214               (mail-narrow-to-head)
2215               (while (gnus-article-goto-header "Face")
2216                 (setq faces (nconc faces (list (mail-header-field-value)))))))
2217           (while (setq face (pop faces))
2218             (let ((png (gnus-convert-face-to-png face))
2219                   image)
2220               (when png
2221                 (setq image
2222                       (apply 'gnus-create-image png 'png t
2223                              (cdr (assq 'png gnus-face-properties-alist))))
2224                 (gnus-article-goto-header "from")
2225                 (when (bobp)
2226                   (insert "From: [no `from' set]\n")
2227                   (forward-char -17))
2228                 (gnus-add-wash-type 'face)
2229                 (gnus-add-image 'face image)
2230                 (gnus-put-image image nil 'face))))))
2231       )))
2232
2233 (defun article-display-x-face (&optional force)
2234   "Look for an X-Face header and display it if present."
2235   (interactive (list 'force))
2236   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2237     (gnus-with-article-headers
2238       ;; Delete the old process, if any.
2239       (when (process-status "article-x-face")
2240         (delete-process "article-x-face"))
2241       ;; See the comment in `article-display-face'.
2242       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2243           ;; We have already displayed X-Faces, so we remove them
2244           ;; instead.
2245           (gnus-delete-images 'xface)
2246         ;; Display X-Faces.
2247         (let (x-faces from face)
2248           (save-excursion
2249             (when (and wash-face-p
2250                        (progn
2251                          (goto-char (point-min))
2252                          (not (re-search-forward
2253                                "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2254                        (gnus-buffer-live-p gnus-original-article-buffer))
2255               ;; If type `W f', use gnus-original-article-buffer,
2256               ;; otherwise use the current buffer because displaying
2257               ;; RFC822 parts calls this function too.
2258               (set-buffer gnus-original-article-buffer))
2259             (save-restriction
2260               (mail-narrow-to-head)
2261               (while (gnus-article-goto-header "X-Face")
2262                 (push (mail-header-field-value) x-faces))
2263               (setq from (message-fetch-field "from"))))
2264           ;; Sending multiple EOFs to xv doesn't work, so we only do a
2265           ;; single external face.
2266           (when (stringp gnus-article-x-face-command)
2267             (setq x-faces (list (car x-faces))))
2268           (while (and (setq face (pop x-faces))
2269                       gnus-article-x-face-command
2270                       (or force
2271                           ;; Check whether this face is censored.
2272                           (not gnus-article-x-face-too-ugly)
2273                           (and gnus-article-x-face-too-ugly from
2274                                (not (string-match gnus-article-x-face-too-ugly
2275                                                   from)))))
2276             ;; We display the face.
2277             (cond ((stringp gnus-article-x-face-command)
2278                    ;; The command is a string, so we interpret the command
2279                    ;; as a, well, command, and fork it off.
2280                    (let ((process-connection-type nil))
2281                      (process-kill-without-query
2282                       (start-process
2283                        "article-x-face" nil shell-file-name
2284                        shell-command-switch gnus-article-x-face-command))
2285                      (with-temp-buffer
2286                        (insert face)
2287                        (process-send-region "article-x-face"
2288                                             (point-min) (point-max)))
2289                      (process-send-eof "article-x-face")))
2290                   ((functionp gnus-article-x-face-command)
2291                    ;; The command is a lisp function, so we call it.
2292                    (funcall gnus-article-x-face-command face))
2293                   (t
2294                    (error "%s is not a function"
2295                           gnus-article-x-face-command)))))))))
2296
2297 (defun article-decode-mime-words ()
2298   "Decode all MIME-encoded words in the article."
2299   (interactive)
2300   (gnus-with-article-buffer
2301     (let ((inhibit-point-motion-hooks t)
2302           (mail-parse-charset gnus-newsgroup-charset)
2303           (mail-parse-ignored-charsets
2304            (with-current-buffer gnus-summary-buffer
2305              gnus-newsgroup-ignored-charsets)))
2306       (mail-decode-encoded-word-region (point-min) (point-max)))))
2307
2308 (defun article-decode-charset (&optional prompt)
2309   "Decode charset-encoded text in the article.
2310 If PROMPT (the prefix), prompt for a coding system to use."
2311   (interactive "P")
2312   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2313         (inhibit-read-only t)
2314         (mail-parse-charset gnus-newsgroup-charset)
2315         (mail-parse-ignored-charsets
2316          (save-excursion (condition-case nil
2317                              (set-buffer gnus-summary-buffer)
2318                            (error))
2319                          gnus-newsgroup-ignored-charsets))
2320         ct cte ctl charset format)
2321     (save-excursion
2322       (save-restriction
2323         (article-narrow-to-head)
2324         (setq ct (message-fetch-field "Content-Type" t)
2325               cte (message-fetch-field "Content-Transfer-Encoding" t)
2326               ctl (and ct (ignore-errors
2327                             (mail-header-parse-content-type ct)))
2328               charset (cond
2329                        (prompt
2330                         (mm-read-coding-system "Charset to decode: "))
2331                        (ctl
2332                         (mail-content-type-get ctl 'charset)))
2333               format (and ctl (mail-content-type-get ctl 'format)))
2334         (when cte
2335           (setq cte (mail-header-strip cte)))
2336         (if (and ctl (not (string-match "/" (car ctl))))
2337             (setq ctl nil))
2338         (goto-char (point-max)))
2339       (forward-line 1)
2340       (save-restriction
2341         (narrow-to-region (point) (point-max))
2342         (when (and (eq mail-parse-charset 'gnus-decoded)
2343                    (eq (mm-body-7-or-8) '8bit))
2344           ;; The text code could have been decoded.
2345           (setq charset mail-parse-charset))
2346         (when (and (or (not ctl)
2347                        (equal (car ctl) "text/plain"))
2348                    (not format)) ;; article with format will decode later.
2349           (mm-decode-body
2350            charset (and cte (intern (downcase
2351                                      (gnus-strip-whitespace cte))))
2352            (car ctl)))))))
2353
2354 (defun article-decode-encoded-words ()
2355   "Remove encoded-word encoding from headers."
2356   (let ((charset (save-excursion
2357                    (set-buffer gnus-summary-buffer)
2358                    default-mime-charset))
2359         (inhibit-read-only t))
2360     (mime-decode-header-in-buffer charset)))
2361
2362 (defun article-decode-group-name ()
2363   "Decode group names in `Newsgroups:'."
2364   (let ((inhibit-point-motion-hooks t)
2365         (inhibit-read-only t)
2366         (method (gnus-find-method-for-group gnus-newsgroup-name)))
2367     (when (and (or gnus-group-name-charset-method-alist
2368                    gnus-group-name-charset-group-alist)
2369                (gnus-buffer-live-p gnus-original-article-buffer))
2370       (save-restriction
2371         (article-narrow-to-head)
2372         (with-current-buffer gnus-original-article-buffer
2373           (goto-char (point-min)))
2374         (while (re-search-forward
2375                 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2376           (replace-match (save-match-data
2377                            (gnus-decode-newsgroups
2378                             ;; XXX how to use data in article buffer?
2379                             (with-current-buffer gnus-original-article-buffer
2380                               (re-search-forward
2381                                "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2382                                nil t)
2383                               (match-string 1))
2384                             gnus-newsgroup-name method))
2385                          t t nil 1))
2386         (goto-char (point-min))
2387         (with-current-buffer gnus-original-article-buffer
2388           (goto-char (point-min)))
2389         (while (re-search-forward
2390                 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2391           (replace-match (save-match-data
2392                            (gnus-decode-newsgroups
2393                             ;; XXX how to use data in article buffer?
2394                             (with-current-buffer gnus-original-article-buffer
2395                               (re-search-forward
2396                                "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2397                                nil t)
2398                               (match-string 1))
2399                             gnus-newsgroup-name method))
2400                          t t nil 1))))))
2401
2402 (autoload 'idna-to-unicode "idna")
2403
2404 (defun article-decode-idna-rhs ()
2405   "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2406   (when gnus-use-idna
2407     (save-restriction
2408       (let ((inhibit-point-motion-hooks t)
2409             (inhibit-read-only t))
2410         (article-narrow-to-head)
2411         (goto-char (point-min))
2412         (while (re-search-forward "@.*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2413           (let (ace unicode)
2414             (when (save-match-data
2415                     (and (setq ace (match-string 1))
2416                          (save-excursion
2417                            (and (re-search-backward "^[^ \t]" nil t)
2418                                 (looking-at "From\\|To\\|Cc")))
2419                          (setq unicode (idna-to-unicode ace))))
2420               (unless (string= ace unicode)
2421                 (replace-match unicode nil nil nil 1)))))))))
2422
2423 (defun article-de-quoted-unreadable (&optional force read-charset)
2424   "Translate a quoted-printable-encoded article.
2425 If FORCE, decode the article whether it is marked as quoted-printable
2426 or not.
2427 If READ-CHARSET, ask for a coding system."
2428   (interactive (list 'force current-prefix-arg))
2429   (save-excursion
2430     (let ((inhibit-read-only t) type charset)
2431       (if (gnus-buffer-live-p gnus-original-article-buffer)
2432           (with-current-buffer gnus-original-article-buffer
2433             (setq type
2434                   (gnus-fetch-field "content-transfer-encoding"))
2435             (let* ((ct (gnus-fetch-field "content-type"))
2436                    (ctl (and ct
2437                              (ignore-errors
2438                                (mail-header-parse-content-type ct)))))
2439               (setq charset (and ctl
2440                                  (mail-content-type-get ctl 'charset)))
2441               (if (stringp charset)
2442                   (setq charset (intern (downcase charset)))))))
2443       (if read-charset
2444           (setq charset (mm-read-coding-system "Charset: " charset)))
2445       (unless charset
2446         (setq charset gnus-newsgroup-charset))
2447       (when (or force
2448                 (and type (let ((case-fold-search t))
2449                             (string-match "quoted-printable" type))))
2450         (article-goto-body)
2451         (quoted-printable-decode-region
2452          (point) (point-max) (mm-charset-to-coding-system charset))))))
2453
2454 (defun article-de-base64-unreadable (&optional force read-charset)
2455   "Translate a base64 article.
2456 If FORCE, decode the article whether it is marked as base64 not.
2457 If READ-CHARSET, ask for a coding system."
2458   (interactive (list 'force current-prefix-arg))
2459   (save-excursion
2460     (let ((inhibit-read-only t) type charset)
2461       (if (gnus-buffer-live-p gnus-original-article-buffer)
2462           (with-current-buffer gnus-original-article-buffer
2463             (setq type
2464                   (gnus-fetch-field "content-transfer-encoding"))
2465             (let* ((ct (gnus-fetch-field "content-type"))
2466                    (ctl (and ct
2467                              (ignore-errors
2468                                (mail-header-parse-content-type ct)))))
2469               (setq charset (and ctl
2470                                  (mail-content-type-get ctl 'charset)))
2471               (if (stringp charset)
2472                   (setq charset (intern (downcase charset)))))))
2473       (if read-charset
2474           (setq charset (mm-read-coding-system "Charset: " charset)))
2475       (unless charset
2476         (setq charset gnus-newsgroup-charset))
2477       (when (or force
2478                 (and type (let ((case-fold-search t))
2479                             (string-match "base64" type))))
2480         (article-goto-body)
2481         (save-restriction
2482           (narrow-to-region (point) (point-max))
2483           (base64-decode-region (point-min) (point-max))
2484           (mm-decode-coding-region
2485            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2486
2487 (eval-when-compile
2488   (require 'rfc1843))
2489
2490 (defun article-decode-HZ ()
2491   "Translate a HZ-encoded article."
2492   (interactive)
2493   (require 'rfc1843)
2494   (save-excursion
2495     (let ((inhibit-read-only t))
2496       (rfc1843-decode-region (point-min) (point-max)))))
2497
2498 (defun article-unsplit-urls ()
2499   "Remove the newlines that some other mailers insert into URLs."
2500   (interactive)
2501   (save-excursion
2502     (let ((inhibit-read-only t))
2503       (goto-char (point-min))
2504       (while (re-search-forward
2505               "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2506         (replace-match "\\1\\3" t)))
2507     (when (interactive-p)
2508       (gnus-treat-article nil))))
2509
2510
2511 (defun article-wash-html (&optional read-charset)
2512   "Format an HTML article.
2513 If READ-CHARSET, ask for a coding system."
2514   (interactive "P")
2515   (save-excursion
2516     (let ((inhibit-read-only t)
2517           charset)
2518       (when (gnus-buffer-live-p gnus-original-article-buffer)
2519         (with-current-buffer gnus-original-article-buffer
2520           (let* ((ct (gnus-fetch-field "content-type"))
2521                  (ctl (and ct
2522                            (ignore-errors
2523                              (mail-header-parse-content-type ct)))))
2524             (setq charset (and ctl
2525                                (mail-content-type-get ctl 'charset)))
2526             (when (stringp charset)
2527               (setq charset (intern (downcase charset)))))))
2528       (when read-charset
2529         (setq charset (mm-read-coding-system "Charset: " charset)))
2530       (unless charset
2531         (setq charset gnus-newsgroup-charset))
2532       (article-goto-body)
2533       (save-window-excursion
2534         (save-restriction
2535           (narrow-to-region (point) (point-max))
2536           (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2537                  (entry (assq func mm-text-html-washer-alist)))
2538             (when entry
2539               (setq func (cdr entry)))
2540             (cond
2541              ((functionp func)
2542               (funcall func))
2543              (t
2544               (apply (car func) (cdr func))))))))))
2545
2546 (defun gnus-article-wash-html-with-w3 ()
2547   "Wash the current buffer with w3."
2548   (mm-setup-w3)
2549   (let ((w3-strict-width (window-width))
2550         (url-standalone-mode t)
2551         (url-gateway-unplugged t)
2552         (w3-honor-stylesheets nil))
2553     (condition-case ()
2554         (w3-region (point-min) (point-max))
2555       (error))))
2556
2557 (defun gnus-article-wash-html-with-w3m ()
2558   "Wash the current buffer with emacs-w3m."
2559   (mm-setup-w3m)
2560   (save-restriction
2561     (narrow-to-region (point) (point-max))
2562     (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2563           w3m-force-redisplay)
2564       (w3m-region (point-min) (point-max)))
2565     (when (and mm-inline-text-html-with-w3m-keymap
2566                (boundp 'w3m-minor-mode-map)
2567                w3m-minor-mode-map)
2568       (add-text-properties
2569        (point-min) (point-max)
2570        (list 'keymap w3m-minor-mode-map
2571              ;; Put the mark meaning this part was rendered by emacs-w3m.
2572              'mm-inline-text-html-with-w3m t)))))
2573
2574 (defun article-hide-list-identifiers ()
2575   "Remove list identifies from the Subject header.
2576 The `gnus-list-identifiers' variable specifies what to do."
2577   (interactive)
2578   (let ((inhibit-point-motion-hooks t)
2579         (regexp (if (consp gnus-list-identifiers)
2580                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2581                   gnus-list-identifiers))
2582         (inhibit-read-only t))
2583     (when regexp
2584       (save-excursion
2585         (save-restriction
2586           (article-narrow-to-head)
2587           (goto-char (point-min))
2588           (while (re-search-forward
2589                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2590                   nil t)
2591             (delete-region (match-beginning 2) (match-end 0))
2592             (beginning-of-line))
2593           (when (re-search-forward
2594                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2595             (delete-region (match-beginning 1) (match-end 1))))))))
2596
2597 (defun article-hide-pem (&optional arg)
2598   "Toggle hiding of any PEM headers and signatures in the current article.
2599 If given a negative prefix, always show; if given a positive prefix,
2600 always hide."
2601   (interactive (gnus-article-hidden-arg))
2602   (unless (gnus-article-check-hidden-text 'pem arg)
2603     (save-excursion
2604       (let ((inhibit-read-only t) end)
2605         (goto-char (point-min))
2606         ;; Hide the horrendously ugly "header".
2607         (when (and (search-forward
2608                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2609                     nil t)
2610                    (setq end (1+ (match-beginning 0))))
2611           (gnus-add-wash-type 'pem)
2612           (gnus-article-hide-text-type
2613            end
2614            (if (search-forward "\n\n" nil t)
2615                (match-end 0)
2616              (point-max))
2617            'pem)
2618           ;; Hide the trailer as well
2619           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2620                                 nil t)
2621             (gnus-article-hide-text-type
2622              (match-beginning 0) (match-end 0) 'pem)))))))
2623
2624 (defun article-strip-banner ()
2625   "Strip the banners specified by the `banner' group parameter and by
2626 `gnus-article-address-banner-alist'."
2627   (interactive)
2628   (save-excursion
2629     (save-restriction
2630       (let ((inhibit-point-motion-hooks t))
2631         (when (gnus-parameter-banner gnus-newsgroup-name)
2632           (article-really-strip-banner
2633            (gnus-parameter-banner gnus-newsgroup-name)))
2634         (when gnus-article-address-banner-alist
2635           ;; It is necessary to encode from fields before checking,
2636           ;; because `mail-header-parse-addresses' does not work
2637           ;; (reliably) on decoded headers.  And more, it is
2638           ;; impossible to use `gnus-fetch-original-field' here,
2639           ;; because `article-strip-banner' may be called in draft
2640           ;; buffers to preview them.
2641           (let ((from (save-restriction
2642                         (widen)
2643                         (article-narrow-to-head)
2644                         (mail-fetch-field "from"))))
2645             (when (and from
2646                        (setq from
2647                              (caar (mail-header-parse-addresses
2648                                     (mail-encode-encoded-word-string from)))))
2649               (catch 'found
2650                 (dolist (pair gnus-article-address-banner-alist)
2651                   (when (string-match (car pair) from)
2652                     (throw 'found
2653                            (article-really-strip-banner (cdr pair)))))))))))))
2654
2655 (defun article-really-strip-banner (banner)
2656   "Strip the banner specified by the argument."
2657   (save-excursion
2658     (save-restriction
2659       (let ((inhibit-point-motion-hooks t)
2660             (gnus-signature-limit nil)
2661             (inhibit-read-only t))
2662         (article-goto-body)
2663         (cond
2664          ((eq banner 'signature)
2665           (when (gnus-article-narrow-to-signature)
2666             (widen)
2667             (forward-line -1)
2668             (delete-region (point) (point-max))))
2669          ((symbolp banner)
2670           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2671               (while (re-search-forward banner nil t)
2672                 (delete-region (match-beginning 0) (match-end 0)))))
2673          ((stringp banner)
2674           (while (re-search-forward banner nil t)
2675             (delete-region (match-beginning 0) (match-end 0)))))))))
2676
2677 (defun article-babel ()
2678   "Translate article using an online translation service."
2679   (interactive)
2680   (require 'babel)
2681   (gnus-with-article-buffer
2682     (when (article-goto-body)
2683       (let* ((start (point))
2684              (end (point-max))
2685              (orig (buffer-substring start end))
2686              (trans (babel-as-string orig)))
2687         (save-restriction
2688           (narrow-to-region start end)
2689           (delete-region start end)
2690           (insert trans))))))
2691
2692 (defun article-hide-signature (&optional arg)
2693   "Hide the signature in the current article.
2694 If given a negative prefix, always show; if given a positive prefix,
2695 always hide."
2696   (interactive (gnus-article-hidden-arg))
2697   (save-excursion
2698     (save-restriction
2699       (if (interactive-p)
2700           (progn
2701             (widen)
2702             (article-goto-body))
2703         (goto-char (point-min)))
2704       (unless (gnus-article-check-hidden-text 'signature arg)
2705         (let ((inhibit-read-only t)
2706               (button (point)))
2707           (while (setq button (text-property-any button (point-max)
2708                                                  'gnus-callback
2709                                                  'gnus-signature-toggle))
2710             (setq button (text-property-not-all button (point-max)
2711                                                 'gnus-callback
2712                                                 'gnus-signature-toggle))
2713             (when (and button (not (eobp)))
2714               (gnus-article-hide-text-type
2715                (1+ button)
2716                (next-single-property-change (1+ button) 'mime-view-entity
2717                                             nil (point-max))
2718                'signature)))))))
2719   (gnus-set-mode-line 'article))
2720
2721 (defun article-strip-headers-in-body ()
2722   "Strip offensive headers from bodies."
2723   (interactive)
2724   (save-excursion
2725     (article-goto-body)
2726     (let ((case-fold-search t))
2727       (when (looking-at "x-no-archive:")
2728         (gnus-delete-line)))))
2729
2730 (defun article-strip-leading-blank-lines ()
2731   "Remove all blank lines from the beginning of the article."
2732   (interactive)
2733   (save-excursion
2734     (let ((inhibit-point-motion-hooks t)
2735           (inhibit-read-only t))
2736       (when (article-goto-body)
2737         (while (and (not (eobp))
2738                     (looking-at "[ \t]*$"))
2739           (gnus-delete-line))))))
2740
2741 (defun article-narrow-to-head ()
2742   "Narrow the buffer to the head of the message.
2743 Point is left at the beginning of the narrowed-to region."
2744   (narrow-to-region
2745    (goto-char (point-min))
2746    (if (search-forward "\n\n" nil 1)
2747        (1- (point))
2748      (point-max)))
2749   (goto-char (point-min)))
2750
2751 (defun article-goto-body ()
2752   "Place point at the start of the body."
2753   (goto-char (point-min))
2754   (cond
2755    ;; This variable is only bound when dealing with separate
2756    ;; MIME body parts.
2757    (article-goto-body-goes-to-point-min-p
2758     t)
2759    ((search-forward "\n\n" nil t)
2760     t)
2761    (t
2762     (goto-char (point-max))
2763     nil)))
2764
2765 (defun article-strip-multiple-blank-lines ()
2766   "Replace consecutive blank lines with one empty line."
2767   (interactive)
2768   (save-excursion
2769     (let ((inhibit-point-motion-hooks t)
2770           (inhibit-read-only t))
2771       ;; First make all blank lines empty.
2772       (article-goto-body)
2773       (while (re-search-forward "^[ \t]+$" nil t)
2774         (unless (gnus-annotation-in-region-p
2775                  (match-beginning 0) (match-end 0))
2776           (replace-match "" nil t)))
2777       ;; Then replace multiple empty lines with a single empty line.
2778       (article-goto-body)
2779       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2780         (unless (gnus-annotation-in-region-p
2781                  (match-beginning 0) (match-end 0))
2782           (delete-region (match-beginning 1) (match-end 1)))))))
2783
2784 (defun article-strip-leading-space ()
2785   "Remove all white space from the beginning of the lines in the article."
2786   (interactive)
2787   (save-excursion
2788     (let ((inhibit-point-motion-hooks t)
2789           (inhibit-read-only t))
2790       (article-goto-body)
2791       (while (re-search-forward "^[ \t]+" nil t)
2792         (replace-match "" t t)))))
2793
2794 (defun article-strip-trailing-space ()
2795   "Remove all white space from the end of the lines in the article."
2796   (interactive)
2797   (save-excursion
2798     (let ((inhibit-point-motion-hooks t)
2799           (inhibit-read-only t))
2800       (article-goto-body)
2801       (while (re-search-forward "[ \t]+$" nil t)
2802         (replace-match "" t t)))))
2803
2804 (defun article-strip-blank-lines ()
2805   "Strip leading, trailing and multiple blank lines."
2806   (interactive)
2807   (article-strip-leading-blank-lines)
2808   (article-remove-trailing-blank-lines)
2809   (article-strip-multiple-blank-lines))
2810
2811 (defun article-strip-all-blank-lines ()
2812   "Strip all blank lines."
2813   (interactive)
2814   (save-excursion
2815     (let ((inhibit-point-motion-hooks t)
2816           (inhibit-read-only t))
2817       (article-goto-body)
2818       (while (re-search-forward "^[ \t]*\n" nil t)
2819         (replace-match "" t t)))))
2820
2821 (defun gnus-article-narrow-to-signature ()
2822   "Narrow to the signature; return t if a signature is found, else nil."
2823   (let ((inhibit-point-motion-hooks t))
2824     (when (gnus-article-search-signature)
2825       (forward-line 1)
2826       ;; Check whether we have some limits to what we consider
2827       ;; to be a signature.
2828       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2829                       (list gnus-signature-limit)))
2830             limit limited)
2831         (while (setq limit (pop limits))
2832           (if (or (and (integerp limit)
2833                        (< (- (point-max) (point)) limit))
2834                   (and (floatp limit)
2835                        (< (count-lines (point) (point-max)) limit))
2836                   (and (functionp limit)
2837                        (funcall limit))
2838                   (and (stringp limit)
2839                        (not (re-search-forward limit nil t))))
2840               ()                        ; This limit did not succeed.
2841             (setq limited t
2842                   limits nil)))
2843         (unless limited
2844           (narrow-to-region (point) (point-max))
2845           t)))))
2846
2847 (defun gnus-article-search-signature ()
2848   "Search the current buffer for the signature separator.
2849 Put point at the beginning of the signature separator."
2850   (let ((cur (point)))
2851     (goto-char (point-max))
2852     (if (if (stringp gnus-signature-separator)
2853             (re-search-backward gnus-signature-separator nil t)
2854           (let ((seps gnus-signature-separator))
2855             (while (and seps
2856                         (not (re-search-backward (car seps) nil t)))
2857               (pop seps))
2858             seps))
2859         t
2860       (goto-char cur)
2861       nil)))
2862
2863 (defun gnus-article-hidden-arg ()
2864   "Return the current prefix arg as a number, or 0 if no prefix."
2865   (list (if current-prefix-arg
2866             (prefix-numeric-value current-prefix-arg)
2867           0)))
2868
2869 (defun gnus-article-check-hidden-text (type arg)
2870   "Return nil if hiding is necessary.
2871 Arg can be nil or a number.  nil and positive means hide, negative
2872 means show, 0 means toggle."
2873   (save-excursion
2874     (save-restriction
2875       (let ((hide (gnus-article-hidden-text-p type)))
2876         (cond
2877          ((or (null arg)
2878               (> arg 0))
2879           nil)
2880          ((< arg 0)
2881           (gnus-article-show-hidden-text type)
2882           t)
2883          (t
2884           (if (eq hide 'hidden)
2885               (progn
2886                 (gnus-article-show-hidden-text type)
2887                 t)
2888             nil)))))))
2889
2890 (defun gnus-article-hidden-text-p (type)
2891   "Say whether the current buffer contains hidden text of type TYPE."
2892   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2893     (while (and pos
2894                 (not (get-text-property pos 'invisible))
2895                 (not (get-text-property pos 'dummy-invisible)))
2896       (setq pos
2897             (text-property-any (1+ pos) (point-max) 'article-type type)))
2898     (if pos
2899         'hidden
2900       nil)))
2901
2902 (defun gnus-article-show-hidden-text (type &optional dummy)
2903   "Show all hidden text of type TYPE.
2904 Originally it is hide instead of DUMMY."
2905   (let ((inhibit-read-only t)
2906         (inhibit-point-motion-hooks t))
2907     (gnus-remove-text-properties-when
2908      'article-type type
2909      (point-min) (point-max)
2910      (cons 'article-type (cons type
2911                                gnus-hidden-properties)))
2912     (gnus-delete-wash-type type)))
2913
2914 (defconst article-time-units
2915   `((year . ,(* 365.25 24 60 60))
2916     (week . ,(* 7 24 60 60))
2917     (day . ,(* 24 60 60))
2918     (hour . ,(* 60 60))
2919     (minute . 60)
2920     (second . 1))
2921   "Mapping from time units to seconds.")
2922
2923 (defun gnus-article-forward-header ()
2924   "Move point to the start of the next header.
2925 If the current header is a continuation header, this can be several
2926 lines forward."
2927   (let ((ended nil))
2928     (while (not ended)
2929       (forward-line 1)
2930       (if (looking-at "[ \t]+[^ \t]")
2931           (forward-line 1)
2932         (setq ended t)))))
2933
2934 (defun article-date-ut (&optional type highlight header)
2935   "Convert DATE date to universal time in the current article.
2936 If TYPE is `local', convert to local time; if it is `lapsed', output
2937 how much time has lapsed since DATE.  For `lapsed', the value of
2938 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2939 should replace the \"Date:\" one, or should be added below it."
2940   (interactive (list 'ut t))
2941   (let* ((header (or header
2942                      (and (eq 1 (point-min))
2943                           (mail-header-date (save-excursion
2944                                               (set-buffer gnus-summary-buffer)
2945                                               gnus-current-headers)))
2946                      (message-fetch-field "date")
2947                      ""))
2948          (date (if (vectorp header) (mail-header-date header)
2949                  header))
2950          (inhibit-point-motion-hooks t)
2951          bface eface date-pos)
2952     (when (and date (not (string= date "")))
2953       (save-excursion
2954         (save-restriction
2955           (article-narrow-to-head)
2956           (when (or (and (eq type 'lapsed)
2957                          gnus-article-date-lapsed-new-header
2958                          ;; Attempt to get the face of X-Sent first.
2959                          (re-search-forward "^X-Sent:[ \t]" nil t))
2960                     (re-search-forward "^Date:[ \t]" nil t)
2961                     ;; If Date is missing, try again for X-Sent.
2962                     (re-search-forward "^X-Sent:[ \t]" nil t))
2963             (setq bface (get-text-property (point-at-bol) 'face)
2964                   date (or (get-text-property (point-at-bol)
2965                                               'original-date)
2966                            date)
2967                   eface (get-text-property (1- (point-at-eol))
2968                                            'face)))
2969           (let ((inhibit-read-only t))
2970             ;; Delete any old X-Sent headers.
2971             (when (setq date-pos
2972                         (text-property-any (point-min) (point-max)
2973                                            'article-date-lapsed t))
2974               (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2975               (delete-region (match-beginning 0)
2976                              (progn (forward-line 1) (point))))
2977             (goto-char (point-min))
2978             ;; Delete any old Date headers.
2979             (while (re-search-forward "^Date:[ \t]" nil t)
2980               (unless date-pos
2981                 (setq date-pos (match-beginning 0)))
2982               (unless (and (eq type 'lapsed)
2983                            gnus-article-date-lapsed-new-header)
2984                 (delete-region (match-beginning 0)
2985                                (progn (message-next-header) (point)))))
2986             (if date-pos
2987                 (progn
2988                   (goto-char date-pos)
2989                   (unless (bolp)
2990                     ;; Possibly, Date has been deleted.
2991                     (insert "\n"))
2992                   (when (and (eq type 'lapsed)
2993                              gnus-article-date-lapsed-new-header
2994                              (looking-at "Date:"))
2995                     (forward-line 1)))
2996               (goto-char (point-min)))
2997             (insert (article-make-date-line date type))
2998             (when (eq type 'lapsed)
2999               (put-text-property (point-at-bol) (point)
3000                                  'article-date-lapsed t))
3001             (insert "\n")
3002             (forward-line -1)
3003             ;; Do highlighting.
3004             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3005               (add-text-properties (match-beginning 1) (1+ (match-end 1))
3006                                    (list 'original-date date 'face bface))
3007               (put-text-property (match-beginning 2) (match-end 2)
3008                                  'face eface))))))))
3009
3010 (defun article-make-date-line (date type)
3011   "Return a DATE line of TYPE."
3012   (unless (memq type '(local ut original user iso8601 lapsed english))
3013     (error "Unknown conversion type: %s" type))
3014   (condition-case ()
3015       (let ((time (date-to-time date)))
3016         (cond
3017          ;; Convert to the local timezone.
3018          ((eq type 'local)
3019           (concat "Date: " (message-make-date time)))
3020          ;; Convert to Universal Time.
3021          ((eq type 'ut)
3022           (concat "Date: "
3023                   (substring
3024                    (message-make-date
3025                     (let* ((e (parse-time-string date))
3026                            (tm (apply 'encode-time e))
3027                            (ms (car tm))
3028                            (ls (- (cadr tm) (car (current-time-zone time)))))
3029                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3030                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3031                             (t (list ms ls)))))
3032                    0 -5)
3033                   "UT"))
3034          ;; Get the original date from the article.
3035          ((eq type 'original)
3036           (concat "Date: " (if (string-match "\n+$" date)
3037                                (substring date 0 (match-beginning 0))
3038                              date)))
3039          ;; Let the user define the format.
3040          ((eq type 'user)
3041           (let ((format (or (condition-case nil
3042                                 (with-current-buffer gnus-summary-buffer
3043                                   gnus-article-time-format)
3044                               (error nil))
3045                             gnus-article-time-format)))
3046             (if (functionp format)
3047                 (funcall format time)
3048               (concat "Date: " (format-time-string format time)))))
3049          ;; ISO 8601.
3050          ((eq type 'iso8601)
3051           (let ((tz (car (current-time-zone time))))
3052             (concat
3053              "Date: "
3054              (format-time-string "%Y%m%dT%H%M%S" time)
3055              (format "%s%02d%02d"
3056                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3057                      (/ (% (abs tz) 3600) 60)))))
3058          ;; Do an X-Sent lapsed format.
3059          ((eq type 'lapsed)
3060           ;; If the date is seriously mangled, the timezone functions are
3061           ;; liable to bug out, so we ignore all errors.
3062           (let* ((now (current-time))
3063                  (real-time (subtract-time now time))
3064                  (real-sec (and real-time
3065                                 (+ (* (float (car real-time)) 65536)
3066                                    (cadr real-time))))
3067                  (sec (and real-time (abs real-sec)))
3068                  num prev)
3069             (cond
3070              ((null real-time)
3071               "X-Sent: Unknown")
3072              ((zerop sec)
3073               "X-Sent: Now")
3074              (t
3075               (concat
3076                "X-Sent: "
3077                ;; This is a bit convoluted, but basically we go
3078                ;; through the time units for years, weeks, etc,
3079                ;; and divide things to see whether that results
3080                ;; in positive answers.
3081                (mapconcat
3082                 (lambda (unit)
3083                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3084                       ;; The (remaining) seconds are too few to
3085                       ;; be divided into this time unit.
3086                       ""
3087                     ;; It's big enough, so we output it.
3088                     (setq sec (- sec (* num (cdr unit))))
3089                     (prog1
3090                         (concat (if prev ", " "") (int-to-string
3091                                                    (floor num))
3092                                 " " (symbol-name (car unit))
3093                                 (if (> num 1) "s" ""))
3094                       (setq prev t))))
3095                 article-time-units "")
3096                ;; If dates are odd, then it might appear like the
3097                ;; article was sent in the future.
3098                (if (> real-sec 0)
3099                    " ago"
3100                  " in the future"))))))
3101          ;; Display the date in proper English
3102          ((eq type 'english)
3103           (let ((dtime (decode-time time)))
3104             (concat
3105              "Date: the "
3106              (number-to-string (nth 3 dtime))
3107              (let ((digit (% (nth 3 dtime) 10)))
3108                (cond
3109                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3110                 ((= digit 1) "st")
3111                 ((= digit 2) "nd")
3112                 ((= digit 3) "rd")
3113                 (t "th")))
3114              " of "
3115              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3116              " "
3117              (number-to-string (nth 5 dtime))
3118              " at "
3119              (format "%02d" (nth 2 dtime))
3120              ":"
3121              (format "%02d" (nth 1 dtime)))))))
3122     (error
3123      (format "Date: %s (from T-gnus)" date))))
3124
3125 (defun article-date-local (&optional highlight)
3126   "Convert the current article date to the local timezone."
3127   (interactive (list t))
3128   (article-date-ut 'local highlight))
3129
3130 (defun article-date-english (&optional highlight)
3131   "Convert the current article date to something that is proper English."
3132   (interactive (list t))
3133   (article-date-ut 'english highlight))
3134
3135 (defun article-date-original (&optional highlight)
3136   "Convert the current article date to what it was originally.
3137 This is only useful if you have used some other date conversion
3138 function and want to see what the date was before converting."
3139   (interactive (list t))
3140   (article-date-ut 'original highlight))
3141
3142 (defun article-date-lapsed (&optional highlight)
3143   "Convert the current article date to time lapsed since it was sent."
3144   (interactive (list t))
3145   (article-date-ut 'lapsed highlight))
3146
3147 (defun article-update-date-lapsed ()
3148   "Function to be run from a timer to update the lapsed time line."
3149   (let (deactivate-mark)
3150     (save-excursion
3151       (ignore-errors
3152         (walk-windows
3153          (lambda (w)
3154            (set-buffer (window-buffer w))
3155            (when (eq major-mode 'gnus-article-mode)
3156              (let ((mark (point-marker)))
3157                (goto-char (point-min))
3158                (when (re-search-forward "^X-Sent:" nil t)
3159                  (article-date-lapsed t))
3160                (goto-char (marker-position mark))
3161                (move-marker mark nil))))
3162          nil 'visible)))))
3163
3164 (defun gnus-start-date-timer (&optional n)
3165   "Start a timer to update the X-Sent header in the article buffers.
3166 The numerical prefix says how frequently (in seconds) the function
3167 is to run."
3168   (interactive "p")
3169   (unless n
3170     (setq n 1))
3171   (gnus-stop-date-timer)
3172   (setq article-lapsed-timer
3173         (run-at-time 1 n 'article-update-date-lapsed)))
3174
3175 (defun gnus-stop-date-timer ()
3176   "Stop the X-Sent timer."
3177   (interactive)
3178   (when article-lapsed-timer
3179     (nnheader-cancel-timer article-lapsed-timer)
3180     (setq article-lapsed-timer nil)))
3181
3182 (defun article-date-user (&optional highlight)
3183   "Convert the current article date to the user-defined format.
3184 This format is defined by the `gnus-article-time-format' variable."
3185   (interactive (list t))
3186   (article-date-ut 'user highlight))
3187
3188 (defun article-date-iso8601 (&optional highlight)
3189   "Convert the current article date to ISO8601."
3190   (interactive (list t))
3191   (article-date-ut 'iso8601 highlight))
3192
3193 ;; (defun article-show-all ()
3194 ;;   "Show all hidden text in the article buffer."
3195 ;;   (interactive)
3196 ;;   (save-excursion
3197 ;;     (widen)
3198 ;;     (let ((inhibit-read-only t))
3199 ;;       (gnus-article-unhide-text (point-min) (point-max))
3200 ;;       (gnus-remove-text-with-property 'gnus-prev)
3201 ;;       (gnus-remove-text-with-property 'gnus-next))))
3202
3203 (defun article-show-all-headers ()
3204   "Show all hidden headers in the article buffer."
3205   (interactive)
3206   (save-excursion
3207     (save-restriction
3208       (widen)
3209       (article-narrow-to-head)
3210       (let ((inhibit-read-only t))
3211         (gnus-article-unhide-text (point-min) (point-max))))))
3212
3213 (defun article-remove-leading-whitespace ()
3214   "Remove excessive whitespace from all headers."
3215   (interactive)
3216   (save-excursion
3217     (save-restriction
3218       (let ((inhibit-read-only t))
3219         (article-narrow-to-head)
3220         (goto-char (point-min))
3221         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3222           (delete-region (match-beginning 1) (match-end 1)))))))
3223
3224 (defun article-emphasize (&optional arg)
3225   "Emphasize text according to `gnus-emphasis-alist'."
3226   (interactive (gnus-article-hidden-arg))
3227   (unless (gnus-article-check-hidden-text 'emphasis arg)
3228     (save-excursion
3229       (let ((alist (or
3230                     (condition-case nil
3231                         (with-current-buffer gnus-summary-buffer
3232                           gnus-article-emphasis-alist)
3233                       (error))
3234                     gnus-emphasis-alist))
3235             (inhibit-read-only t)
3236             (props (append '(article-type emphasis)
3237                            gnus-hidden-properties))
3238             regexp elem beg invisible visible face)
3239         (article-goto-body)
3240         (setq beg (point))
3241         (while (setq elem (pop alist))
3242           (goto-char beg)
3243           (setq regexp (car elem)
3244                 invisible (nth 1 elem)
3245                 visible (nth 2 elem)
3246                 face (nth 3 elem))
3247           (while (re-search-forward regexp nil t)
3248             (when (and (match-beginning visible) (match-beginning invisible))
3249               (gnus-article-hide-text
3250                (match-beginning invisible) (match-end invisible) props)
3251               (gnus-article-unhide-text-type
3252                (match-beginning visible) (match-end visible) 'emphasis)
3253               (gnus-put-overlay-excluding-newlines
3254                (match-beginning visible) (match-end visible) 'face face)
3255               (gnus-add-wash-type 'emphasis)
3256               (goto-char (match-end invisible)))))))))
3257
3258 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3259   "Setup newsgroup emphasis alist."
3260   (unless gnus-article-emphasis-alist
3261     (let ((name (and gnus-newsgroup-name
3262                      (gnus-group-real-name gnus-newsgroup-name))))
3263       (make-local-variable 'gnus-article-emphasis-alist)
3264       (setq gnus-article-emphasis-alist
3265             (nconc
3266              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3267                (while (setq elem (pop alist))
3268                  (when (and name (string-match (car elem) name))
3269                    (setq alist nil
3270                          highlight (copy-sequence (cdr elem)))))
3271                highlight)
3272              (copy-sequence highlight-words)
3273              (if gnus-newsgroup-name
3274                  (copy-sequence (gnus-group-find-parameter
3275                                  gnus-newsgroup-name 'highlight-words t)))
3276              gnus-emphasis-alist)))))
3277
3278 (eval-when-compile
3279   (defvar gnus-summary-article-menu)
3280   (defvar gnus-summary-post-menu))
3281
3282 ;;; Saving functions.
3283
3284 (defun gnus-article-save (save-buffer file &optional num)
3285   "Save the currently selected article."
3286   (unless gnus-save-all-headers
3287     ;; Remove headers according to `gnus-saved-headers'.
3288     (let ((gnus-visible-headers
3289            (or gnus-saved-headers gnus-visible-headers))
3290           (gnus-article-buffer save-buffer))
3291       (save-excursion
3292         (set-buffer save-buffer)
3293         (article-hide-headers 1 t))))
3294   (save-window-excursion
3295     (if (not gnus-default-article-saver)
3296         (error "No default saver is defined")
3297       ;; !!! Magic!  The saving functions all save
3298       ;; `gnus-save-article-buffer' (or so they think), but we
3299       ;; bind that variable to our save-buffer.
3300       (set-buffer gnus-article-buffer)
3301       (let* ((gnus-save-article-buffer save-buffer)
3302              (filename
3303               (cond
3304                ((not gnus-prompt-before-saving) 'default)
3305                ((eq gnus-prompt-before-saving 'always) nil)
3306                (t file)))
3307              (gnus-number-of-articles-to-be-saved
3308               (when (eq gnus-prompt-before-saving t)
3309                 num)))                  ; Magic
3310         (set-buffer gnus-article-current-summary)
3311         (funcall gnus-default-article-saver filename)))))
3312
3313 (defun gnus-read-save-file-name (prompt &optional filename
3314                                         function group headers variable)
3315   (let ((default-name
3316           (funcall function group headers (symbol-value variable)))
3317         result)
3318     (setq result
3319           (expand-file-name
3320            (cond
3321             ((eq filename 'default)
3322              default-name)
3323             ((eq filename t)
3324              default-name)
3325             (filename filename)
3326             (t
3327              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3328                     (prompt
3329                      (format prompt
3330                              (if (and gnus-number-of-articles-to-be-saved
3331                                       (> gnus-number-of-articles-to-be-saved 1))
3332                                  (format "these %d articles"
3333                                          gnus-number-of-articles-to-be-saved)
3334                                "this article")))
3335                     (file
3336                      ;; Let the split methods have their say.
3337                      (cond
3338                       ;; No split name was found.
3339                       ((null split-name)
3340                        (read-file-name
3341                         (concat prompt " (default "
3342                                 (file-name-nondirectory default-name) ") ")
3343                         (file-name-directory default-name)
3344                         default-name))
3345                       ;; A single group name is returned.
3346                       ((stringp split-name)
3347                        (setq default-name
3348                              (funcall function split-name headers
3349                                       (symbol-value variable)))
3350                        (read-file-name
3351                         (concat prompt " (default "
3352                                 (file-name-nondirectory default-name) ") ")
3353                         (file-name-directory default-name)
3354                         default-name))
3355                       ;; A single split name was found
3356                       ((= 1 (length split-name))
3357                        (let* ((name (expand-file-name
3358                                      (car split-name)
3359                                      gnus-article-save-directory))
3360                               (dir (cond ((file-directory-p name)
3361                                           (file-name-as-directory name))
3362                                          ((file-exists-p name) name)
3363                                          (t gnus-article-save-directory))))
3364                          (read-file-name
3365                           (concat prompt " (default " name ") ")
3366                           dir name)))
3367                       ;; A list of splits was found.
3368                       (t
3369                        (setq split-name (nreverse split-name))
3370                        (let (result)
3371                          (let ((file-name-history
3372                                 (nconc split-name file-name-history)))
3373                            (setq result
3374                                  (expand-file-name
3375                                   (read-file-name
3376                                    (concat prompt " (`M-p' for defaults) ")
3377                                    gnus-article-save-directory
3378                                    (car split-name))
3379                                   gnus-article-save-directory)))
3380                          (car (push result file-name-history)))))))
3381                ;; Create the directory.
3382                (gnus-make-directory (file-name-directory file))
3383                ;; If we have read a directory, we append the default file name.
3384                (when (file-directory-p file)
3385                  (setq file (expand-file-name (file-name-nondirectory
3386                                                default-name)
3387                                               (file-name-as-directory file))))
3388                ;; Possibly translate some characters.
3389                (nnheader-translate-file-chars file))))))
3390     (gnus-make-directory (file-name-directory result))
3391     (set variable result)))
3392
3393 (defun gnus-article-archive-name (group)
3394   "Return the first instance of an \"Archive-name\" in the current buffer."
3395   (let ((case-fold-search t))
3396     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3397       (nnheader-concat gnus-article-save-directory
3398                        (match-string 1)))))
3399
3400 (defun gnus-article-nndoc-name (group)
3401   "If GROUP is an nndoc group, return the name of the parent group."
3402   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3403     (gnus-group-get-parameter group 'save-article-group)))
3404
3405 (defun gnus-summary-save-in-rmail (&optional filename)
3406   "Append this article to Rmail file.
3407 Optional argument FILENAME specifies file name.
3408 Directory to save to is default to `gnus-article-save-directory'."
3409   (setq filename (gnus-read-save-file-name
3410                   "Save %s in rmail file:" filename
3411                   gnus-rmail-save-name gnus-newsgroup-name
3412                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3413   (gnus-eval-in-buffer-window gnus-save-article-buffer
3414     (save-excursion
3415       (save-restriction
3416         (widen)
3417         (gnus-output-to-rmail filename))))
3418   filename)
3419
3420 (defun gnus-summary-save-in-mail (&optional filename)
3421   "Append this article to Unix mail file.
3422 Optional argument FILENAME specifies file name.
3423 Directory to save to is default to `gnus-article-save-directory'."
3424   (setq filename (gnus-read-save-file-name
3425                   "Save %s in Unix mail file:" filename
3426                   gnus-mail-save-name gnus-newsgroup-name
3427                   gnus-current-headers 'gnus-newsgroup-last-mail))
3428   (gnus-eval-in-buffer-window gnus-save-article-buffer
3429     (save-excursion
3430       (save-restriction
3431         (widen)
3432         (if (and (file-readable-p filename)
3433                  (file-regular-p filename)
3434                  (mail-file-babyl-p filename))
3435             (rmail-output-to-rmail-file filename t)
3436           (gnus-output-to-mail filename)))))
3437   filename)
3438
3439 (defun gnus-summary-save-in-file (&optional filename overwrite)
3440   "Append this article to file.
3441 Optional argument FILENAME specifies file name.
3442 Directory to save to is default to `gnus-article-save-directory'."
3443   (setq filename (gnus-read-save-file-name
3444                   "Save %s in file:" filename
3445                   gnus-file-save-name gnus-newsgroup-name
3446                   gnus-current-headers 'gnus-newsgroup-last-file))
3447   (gnus-eval-in-buffer-window gnus-save-article-buffer
3448     (save-excursion
3449       (save-restriction
3450         (widen)
3451         (when (and overwrite
3452                    (file-exists-p filename))
3453           (delete-file filename))
3454         (gnus-output-to-file filename))))
3455   filename)
3456
3457 (defun gnus-summary-write-to-file (&optional filename)
3458   "Write this article to a file, overwriting it if the file exists.
3459 Optional argument FILENAME specifies file name.
3460 The directory to save in defaults to `gnus-article-save-directory'."
3461   (gnus-summary-save-in-file nil t))
3462
3463 (defun gnus-summary-save-body-in-file (&optional filename)
3464   "Append this article body to a file.
3465 Optional argument FILENAME specifies file name.
3466 The directory to save in defaults to `gnus-article-save-directory'."
3467   (setq filename (gnus-read-save-file-name
3468                   "Save %s body in file:" filename
3469                   gnus-file-save-name gnus-newsgroup-name
3470                   gnus-current-headers 'gnus-newsgroup-last-file))
3471   (gnus-eval-in-buffer-window gnus-save-article-buffer
3472     (save-excursion
3473       (save-restriction
3474         (widen)
3475         (when (article-goto-body)
3476           (narrow-to-region (point) (point-max)))
3477         (gnus-output-to-file filename))))
3478   filename)
3479
3480 (defun gnus-summary-save-in-pipe (&optional command)
3481   "Pipe this article to subprocess."
3482   (setq command
3483         (cond ((and (eq command 'default)
3484                     gnus-last-shell-command)
3485                gnus-last-shell-command)
3486               ((stringp command)
3487                command)
3488               (t (read-string
3489                   (format
3490                    "Shell command on %s: "
3491                    (if (and gnus-number-of-articles-to-be-saved
3492                             (> gnus-number-of-articles-to-be-saved 1))
3493                        (format "these %d articles"
3494                                gnus-number-of-articles-to-be-saved)
3495                      "this article"))
3496                   gnus-last-shell-command))))
3497   (when (string-equal command "")
3498     (if gnus-last-shell-command
3499         (setq command gnus-last-shell-command)
3500       (error "A command is required")))
3501   (gnus-eval-in-buffer-window gnus-article-buffer
3502     (save-restriction
3503       (widen)
3504       (shell-command-on-region (point-min) (point-max) command nil)))
3505   (setq gnus-last-shell-command command))
3506
3507 (defun gnus-summary-pipe-to-muttprint (&optional command)
3508   "Pipe this article to muttprint."
3509   (setq command (read-string
3510                  "Print using command: " gnus-summary-muttprint-program
3511                  nil gnus-summary-muttprint-program))
3512   (gnus-summary-save-in-pipe command))
3513
3514 ;;; Article file names when saving.
3515
3516 (defun gnus-capitalize-newsgroup (newsgroup)
3517   "Capitalize NEWSGROUP name."
3518   (when (not (zerop (length newsgroup)))
3519     (concat (char-to-string (upcase (aref newsgroup 0)))
3520             (substring newsgroup 1))))
3521
3522 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3523   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3524 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3525 Otherwise, it is like ~/News/news/group/num."
3526   (let ((default
3527           (expand-file-name
3528            (concat (if (gnus-use-long-file-name 'not-save)
3529                        (gnus-capitalize-newsgroup newsgroup)
3530                      (gnus-newsgroup-directory-form newsgroup))
3531                    "/" (int-to-string (mail-header-number headers)))
3532            gnus-article-save-directory)))
3533     (if (and last-file
3534              (string-equal (file-name-directory default)
3535                            (file-name-directory last-file))
3536              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3537         default
3538       (or last-file default))))
3539
3540 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3541   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3542 If variable `gnus-use-long-file-name' is non-nil, it is
3543 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3544   (let ((default
3545           (expand-file-name
3546            (concat (if (gnus-use-long-file-name 'not-save)
3547                        newsgroup
3548                      (gnus-newsgroup-directory-form newsgroup))
3549                    "/" (int-to-string (mail-header-number headers)))
3550            gnus-article-save-directory)))
3551     (if (and last-file
3552              (string-equal (file-name-directory default)
3553                            (file-name-directory last-file))
3554              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3555         default
3556       (or last-file default))))
3557
3558 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3559   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3560 If variable `gnus-use-long-file-name' is non-nil, it is
3561 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3562   (or last-file
3563       (expand-file-name
3564        (if (gnus-use-long-file-name 'not-save)
3565            newsgroup
3566          (file-relative-name
3567           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3568           default-directory))
3569        gnus-article-save-directory)))
3570
3571 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3572   "Generate file name from sender."
3573   (let ((from (mail-header-from headers)))
3574     (expand-file-name
3575      (if (and from (string-match "\\([^ <]+\\)@" from))
3576          (match-string 1 from)
3577        "nobody")
3578      gnus-article-save-directory)))
3579
3580 (defun article-verify-x-pgp-sig ()
3581   "Verify X-PGP-Sig."
3582   (interactive)
3583   (if (gnus-buffer-live-p gnus-original-article-buffer)
3584       (let ((sig (with-current-buffer gnus-original-article-buffer
3585                    (gnus-fetch-field "X-PGP-Sig")))
3586             items info headers)
3587         (when (and sig
3588                    mml2015-use
3589                    (mml2015-clear-verify-function))
3590           (with-temp-buffer
3591             (insert-buffer-substring gnus-original-article-buffer)
3592             (setq items (split-string sig))
3593             (message-narrow-to-head)
3594             (let ((inhibit-point-motion-hooks t)
3595                   (case-fold-search t))
3596               ;; Don't verify multiple headers.
3597               (setq headers (mapconcat (lambda (header)
3598                                          (concat header ": "
3599                                                  (mail-fetch-field header)
3600                                                  "\n"))
3601                                        (split-string (nth 1 items) ",") "")))
3602             (delete-region (point-min) (point-max))
3603             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3604             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3605             (insert headers)
3606             (widen)
3607             (forward-line)
3608             (while (not (eobp))
3609               (if (looking-at "^-")
3610                   (insert "- "))
3611               (forward-line))
3612             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3613             (insert "Version: " (car items) "\n\n")
3614             (insert (mapconcat 'identity (cddr items) "\n"))
3615             (insert "\n-----END PGP SIGNATURE-----\n")
3616             (let ((mm-security-handle (list (format "multipart/signed"))))
3617               (mml2015-clean-buffer)
3618               (let ((coding-system-for-write (or gnus-newsgroup-charset
3619                                                  'iso-8859-1)))
3620                 (funcall (mml2015-clear-verify-function)))
3621               (setq info
3622                     (or (mm-handle-multipart-ctl-parameter
3623                          mm-security-handle 'gnus-details)
3624                         (mm-handle-multipart-ctl-parameter
3625                          mm-security-handle 'gnus-info)))))
3626           (when info
3627             (let ((inhibit-read-only t) bface eface)
3628               (save-restriction
3629                 (message-narrow-to-head)
3630                 (goto-char (point-max))
3631                 (forward-line -1)
3632                 (setq bface (get-text-property (point-at-bol) 'face)
3633                       eface (get-text-property (1- (point-at-eol)) 'face))
3634                 (message-remove-header "X-Gnus-PGP-Verify")
3635                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3636                     (forward-line)
3637                   (goto-char (point-max)))
3638                 (narrow-to-region (point) (point))
3639                 (insert "X-Gnus-PGP-Verify: " info "\n")
3640                 (goto-char (point-min))
3641                 (forward-line)
3642                 (while (not (eobp))
3643                   (if (not (looking-at "^[ \t]"))
3644                       (insert " "))
3645                   (forward-line))
3646                 ;; Do highlighting.
3647                 (goto-char (point-min))
3648                 (when (looking-at "\\([^:]+\\): *")
3649                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3650                                      'face bface)
3651                   (put-text-property (match-end 0) (point-max)
3652                                      'face eface)))))))))
3653
3654 (defun article-verify-cancel-lock ()
3655   "Verify Cancel-Lock header."
3656   (interactive)
3657   (if (gnus-buffer-live-p gnus-original-article-buffer)
3658       (canlock-verify gnus-original-article-buffer)))
3659
3660 (defun article-monafy ()
3661   "Display body part with mona font."
3662   (interactive)
3663   (unless (if (featurep 'xemacs)
3664               (find-face 'gnus-mona-face)
3665             (facep 'gnus-mona-face))
3666     (require 'navi2ch-mona)
3667     (set-face-font (make-face 'gnus-mona-face) navi2ch-mona-font))
3668   (save-excursion
3669     (let ((inhibit-read-only t))
3670       (article-goto-body)
3671       (gnus-overlay-put
3672        (gnus-make-overlay (point) (point-max))
3673        'face 'gnus-mona-face))))
3674
3675 (eval-and-compile
3676   (mapcar
3677    (lambda (func)
3678      (let (afunc gfunc)
3679        (if (consp func)
3680            (setq afunc (car func)
3681                  gfunc (cdr func))
3682          (setq afunc func
3683                gfunc (intern (format "gnus-%s" func))))
3684        (defalias gfunc
3685          (when (fboundp afunc)
3686            `(lambda (&optional interactive &rest args)
3687               ,(documentation afunc t)
3688               (interactive (list t))
3689               (save-excursion
3690                 (set-buffer gnus-article-buffer)
3691                 (if interactive
3692                     (call-interactively ',afunc)
3693                   (apply ',afunc args))))))))
3694    '(article-hide-headers
3695      article-verify-x-pgp-sig
3696      article-verify-cancel-lock
3697      article-monafy
3698      article-hide-boring-headers
3699      article-treat-overstrike
3700      article-treat-ansi-sequences
3701      article-fill-long-lines
3702      article-capitalize-sentences
3703      article-remove-cr
3704      article-remove-leading-whitespace
3705      article-display-x-face
3706      article-display-face
3707      article-de-quoted-unreadable
3708      article-de-base64-unreadable
3709      article-decode-HZ
3710      article-wash-html
3711      article-unsplit-urls
3712      article-hide-list-identifiers
3713      article-strip-banner
3714      article-babel
3715      article-hide-pem
3716      article-hide-signature
3717      article-strip-headers-in-body
3718      article-remove-trailing-blank-lines
3719      article-strip-leading-blank-lines
3720      article-strip-multiple-blank-lines
3721      article-strip-leading-space
3722      article-strip-trailing-space
3723      article-strip-blank-lines
3724      article-strip-all-blank-lines
3725      article-date-local
3726      article-date-english
3727      article-date-iso8601
3728      article-date-original
3729      article-date-ut
3730      article-decode-mime-words
3731      article-decode-charset
3732      article-decode-encoded-words
3733      article-date-user
3734      article-date-lapsed
3735      article-emphasize
3736      article-treat-dumbquotes
3737      article-normalize-headers
3738      (article-show-all-headers . gnus-article-show-all-headers)
3739 ;;      (article-show-all . gnus-article-show-all)
3740      )))
3741 \f
3742 ;;;
3743 ;;; Gnus article mode
3744 ;;;
3745
3746 (put 'gnus-article-mode 'mode-class 'special)
3747
3748 (gnus-define-keys gnus-article-mode-map
3749   " " gnus-article-goto-next-page
3750   "\177" gnus-article-goto-prev-page
3751   [delete] gnus-article-goto-prev-page
3752   [backspace] gnus-article-goto-prev-page
3753   "\C-c^" gnus-article-refer-article
3754   "h" gnus-article-show-summary
3755   "s" gnus-article-show-summary
3756   "\C-c\C-m" gnus-article-mail
3757   "?" gnus-article-describe-briefly
3758   "e" gnus-summary-edit-article
3759   "<" beginning-of-buffer
3760   ">" end-of-buffer
3761   "\C-c\C-i" gnus-info-find-node
3762   "\C-c\C-b" gnus-bug
3763   "R" gnus-article-reply-with-original
3764   "F" gnus-article-followup-with-original
3765   "\C-hk" gnus-article-describe-key
3766   "\C-hc" gnus-article-describe-key-briefly
3767
3768   "\C-d" gnus-article-read-summary-keys
3769   "\M-*" gnus-article-read-summary-keys
3770   "\M-#" gnus-article-read-summary-keys
3771   "\M-^" gnus-article-read-summary-keys
3772   "\M-g" gnus-article-read-summary-keys)
3773
3774 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3775 (let (keys)
3776   (let ((key 32))
3777     (while (<= key 127)
3778       (push (char-to-string key) keys)
3779       (incf key))
3780     (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3781       (setq key (car elem))
3782       (when (and (> (length key) 0)
3783                  (not (eq 'menu-bar (aref key 0)))
3784                  (symbolp (lookup-key gnus-summary-mode-map key)))
3785         (push key keys))))
3786   (dolist (key keys)
3787     (unless (lookup-key gnus-article-mode-map key)
3788       (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3789
3790 (defun gnus-article-make-menu-bar ()
3791   (unless (boundp 'gnus-article-commands-menu)
3792     (gnus-summary-make-menu-bar))
3793   (gnus-turn-off-edit-menu 'article)
3794   (unless (boundp 'gnus-article-article-menu)
3795     (easy-menu-define
3796      gnus-article-article-menu gnus-article-mode-map ""
3797      '("Article"
3798        ["Scroll forwards" gnus-article-goto-next-page t]
3799        ["Scroll backwards" gnus-article-goto-prev-page t]
3800        ["Show summary" gnus-article-show-summary t]
3801        ["Fetch Message-ID at point" gnus-article-refer-article t]
3802        ["Mail to address at point" gnus-article-mail t]
3803        ["Send a bug report" gnus-bug t]))
3804
3805     (easy-menu-define
3806      gnus-article-treatment-menu gnus-article-mode-map ""
3807      ;; Fixme: this should use :active (and maybe :visible).
3808      '("Treatment"
3809        ["Hide headers" gnus-article-hide-headers t]
3810        ["Hide signature" gnus-article-hide-signature t]
3811        ["Hide citation" gnus-article-hide-citation t]
3812        ["Treat overstrike" gnus-article-treat-overstrike t]
3813        ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3814        ["Remove carriage return" gnus-article-remove-cr t]
3815        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3816        ["Treat html" gnus-article-wash-html t]
3817        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3818        ["Decode HZ" gnus-article-decode-HZ t]))
3819
3820     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3821
3822     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3823
3824     (gnus-run-hooks 'gnus-article-menu-hook)))
3825
3826 (defun gnus-article-mode ()
3827   "Major mode for displaying an article.
3828
3829 All normal editing commands are switched off.
3830
3831 The following commands are available in addition to all summary mode
3832 commands:
3833 \\<gnus-article-mode-map>
3834 \\[gnus-article-next-page]\t Scroll the article one page forwards
3835 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3836 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3837 \\[gnus-article-show-summary]\t Display the summary buffer
3838 \\[gnus-article-mail]\t Send a reply to the address near point
3839 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3840 \\[gnus-info-find-node]\t Go to the Gnus info node"
3841   (interactive)
3842   (gnus-simplify-mode-line)
3843   (setq mode-name "Article")
3844   (setq major-mode 'gnus-article-mode)
3845   (make-local-variable 'minor-mode-alist)
3846   (unless (assq 'gnus-show-mime minor-mode-alist)
3847     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3848   (use-local-map gnus-article-mode-map)
3849   (when (gnus-visual-p 'article-menu 'menu)
3850     (gnus-article-make-menu-bar)
3851     (when gnus-summary-tool-bar-map
3852       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3853   (gnus-update-format-specifications nil 'article-mode)
3854   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3855   (set (make-local-variable 'gnus-page-broken) nil)
3856   (make-local-variable 'gnus-button-marker-list)
3857   (make-local-variable 'gnus-article-current-summary)
3858   (make-local-variable 'gnus-article-mime-handles)
3859   (make-local-variable 'gnus-article-decoded-p)
3860   (make-local-variable 'gnus-article-mime-handle-alist)
3861   (make-local-variable 'gnus-article-wash-types)
3862   (make-local-variable 'gnus-article-image-alist)
3863   (make-local-variable 'gnus-article-charset)
3864   (make-local-variable 'gnus-article-ignored-charsets)
3865   (gnus-set-default-directory)
3866   (buffer-disable-undo)
3867   (setq buffer-read-only t
3868         show-trailing-whitespace nil)
3869   (set-syntax-table gnus-article-mode-syntax-table)
3870   (gnus-run-hooks 'gnus-article-mode-hook))
3871
3872 (defun gnus-article-setup-buffer ()
3873   "Initialize the article buffer."
3874   (let* ((name (if gnus-single-article-buffer "*Article*"
3875                  (concat "*Article " gnus-newsgroup-name "*")))
3876          (original
3877           (progn (string-match "\\*Article" name)
3878                  (concat " *Original Article"
3879                          (substring name (match-end 0))))))
3880     (setq gnus-article-buffer name)
3881     (setq gnus-original-article-buffer original)
3882     (setq gnus-article-mime-handle-alist nil)
3883     ;; This might be a variable local to the summary buffer.
3884     (unless gnus-single-article-buffer
3885       (save-excursion
3886         (set-buffer gnus-summary-buffer)
3887         (setq gnus-article-buffer name)
3888         (setq gnus-original-article-buffer original)
3889         (gnus-set-global-variables)))
3890     (gnus-article-setup-highlight-words)
3891     ;; Init original article buffer.
3892     (save-excursion
3893       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3894       (set-buffer-multibyte t)
3895       (setq major-mode 'gnus-original-article-mode)
3896       (make-local-variable 'gnus-original-article))
3897     (if (get-buffer name)
3898         (save-excursion
3899           (set-buffer name)
3900           (when (and gnus-article-edit-mode
3901                      (buffer-modified-p)
3902                      (not
3903                       (y-or-n-p "Article mode edit in progress; discard? ")))
3904             (error "Action aborted"))
3905           (set (make-local-variable 'gnus-article-edit-mode) nil)
3906           (buffer-disable-undo)
3907           (setq buffer-read-only t)
3908           ;; This list just keeps growing if we don't reset it.
3909           (setq gnus-button-marker-list nil)
3910           (unless (eq major-mode 'gnus-article-mode)
3911             (gnus-article-mode))
3912           (current-buffer))
3913       (save-excursion
3914         (set-buffer (gnus-get-buffer-create name))
3915         (gnus-article-mode)
3916         (make-local-variable 'gnus-summary-buffer)
3917         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3918         (current-buffer)))))
3919
3920 ;; Set article window start at LINE, where LINE is the number of lines
3921 ;; from the head of the article.
3922 (defun gnus-article-set-window-start (&optional line)
3923   (set-window-start
3924    (gnus-get-buffer-window gnus-article-buffer t)
3925    (save-excursion
3926      (set-buffer gnus-article-buffer)
3927      (goto-char (point-min))
3928      (if (not line)
3929          (point-min)
3930        (gnus-message 6 "Moved to bookmark")
3931        (search-forward "\n\n" nil t)
3932        (forward-line line)
3933        (point)))))
3934
3935 ;;; @@ article filters
3936 ;;;
3937
3938 (defun gnus-article-display-mime-message ()
3939   "Article display method for MIME message."
3940   ;; called from `gnus-original-article-buffer'.
3941   (let (charset all-headers)
3942     (with-current-buffer gnus-summary-buffer
3943       (setq charset default-mime-charset
3944             all-headers gnus-have-all-headers))
3945     (make-local-variable 'default-mime-charset)
3946     (setq default-mime-charset charset)
3947     (with-current-buffer (get-buffer-create gnus-article-buffer)
3948       (make-local-variable 'default-mime-charset)
3949       (setq default-mime-charset charset))
3950     (mime-display-message mime-message-structure
3951                           gnus-article-buffer nil gnus-article-mode-map)
3952     (when all-headers
3953       (gnus-article-hide-headers nil -1)))
3954   (run-hooks 'gnus-mime-article-prepare-hook))
3955
3956 (defun gnus-article-display-traditional-message ()
3957   "Article display method for traditional message."
3958   (set-buffer gnus-article-buffer)
3959   (let ((inhibit-read-only t))
3960     (erase-buffer)
3961     (insert-buffer-substring gnus-original-article-buffer)))
3962
3963 (defun gnus-article-make-full-mail-header (&optional number charset)
3964   "Create a new mail header structure in a raw article buffer."
3965   (unless (and number charset)
3966     (save-current-buffer
3967       (set-buffer gnus-summary-buffer)
3968       (unless number
3969         (setq number (or (cdr gnus-article-current) 0)))
3970       (unless charset
3971         (setq charset (or default-mime-charset 'x-ctext)))))
3972   (goto-char (point-min))
3973   (let ((header-end (if (search-forward "\n\n" nil t)
3974                         (1- (point))
3975                       (goto-char (point-max))))
3976         (chars (- (point-max) (point)))
3977         (lines (count-lines (point) (point-max)))
3978         (default-mime-charset charset)
3979         xref)
3980     (narrow-to-region (point-min) header-end)
3981     (setq xref (std11-fetch-field "xref"))
3982     (prog1
3983         (make-full-mail-header
3984          number
3985          (std11-fetch-field "subject")
3986          (std11-fetch-field "from")
3987          (std11-fetch-field "date")
3988          (std11-fetch-field "message-id")
3989          (std11-fetch-field "references")
3990          chars
3991          lines
3992          (when xref (concat "Xref: " xref)))
3993       (widen))))
3994
3995 (defun gnus-article-prepare (article &optional all-headers header)
3996   "Prepare ARTICLE in article mode buffer.
3997 ARTICLE should either be an article number or a Message-ID.
3998 If ARTICLE is an id, HEADER should be the article headers.
3999 If ALL-HEADERS is non-nil, no headers are hidden."
4000   (save-excursion
4001     ;; Make sure we start in a summary buffer.
4002     (unless (eq major-mode 'gnus-summary-mode)
4003       (set-buffer gnus-summary-buffer))
4004     (setq gnus-summary-buffer (current-buffer))
4005     (let* ((gnus-article (if header (mail-header-number header) article))
4006            (summary-buffer (current-buffer))
4007            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4008            (group gnus-newsgroup-name)
4009            result)
4010       (save-excursion
4011         (gnus-article-setup-buffer)
4012         (set-buffer gnus-article-buffer)
4013         ;; Deactivate active regions.
4014         (when (and (boundp 'transient-mark-mode)
4015                    transient-mark-mode)
4016           (setq mark-active nil))
4017         (if (not (setq result (let ((inhibit-read-only t))
4018                                 (gnus-request-article-this-buffer
4019                                  article group))))
4020             ;; There is no such article.
4021             (save-excursion
4022               (when (and (numberp article)
4023                          (not (memq article gnus-newsgroup-sparse)))
4024                 (setq gnus-article-current
4025                       (cons gnus-newsgroup-name article))
4026                 (set-buffer gnus-summary-buffer)
4027                 (setq gnus-current-article article)
4028                 (if (and (memq article gnus-newsgroup-undownloaded)
4029                          (not (gnus-online (gnus-find-method-for-group
4030                                             gnus-newsgroup-name))))
4031                     (progn
4032                       (gnus-summary-set-agent-mark article)
4033                       (message "Message marked for downloading"))
4034                   (gnus-summary-mark-article article gnus-canceled-mark)
4035                   (unless (memq article gnus-newsgroup-sparse)
4036                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
4037           (if (or (eq result 'pseudo)
4038                   (eq result 'nneething))
4039               (progn
4040                 (save-excursion
4041                   (set-buffer summary-buffer)
4042                   (push article gnus-newsgroup-history)
4043                   (setq gnus-last-article gnus-current-article
4044                         gnus-current-article 0
4045                         gnus-current-headers nil
4046                         gnus-article-current nil)
4047                   (if (eq result 'nneething)
4048                       (gnus-configure-windows 'summary)
4049                     (gnus-configure-windows 'article))
4050                   (gnus-set-global-variables))
4051                 (let ((gnus-article-mime-handle-alist-1
4052                        gnus-article-mime-handle-alist))
4053                   (gnus-set-mode-line 'article)))
4054             ;; The result from the `request' was an actual article -
4055             ;; or at least some text that is now displayed in the
4056             ;; article buffer.
4057             (when (and (numberp article)
4058                        (not (eq article gnus-current-article)))
4059               ;; Seems like a new article has been selected.
4060               ;; `gnus-current-article' must be an article number.
4061               (save-excursion
4062                 (set-buffer summary-buffer)
4063                 (push article gnus-newsgroup-history)
4064                 (setq gnus-last-article gnus-current-article
4065                       gnus-current-article article
4066                       gnus-current-headers
4067                       (gnus-summary-article-header gnus-current-article)
4068                       gnus-article-current
4069                       (cons gnus-newsgroup-name gnus-current-article))
4070                 (unless (vectorp gnus-current-headers)
4071                   (setq gnus-current-headers nil))
4072                 (gnus-summary-goto-subject gnus-current-article)
4073                 (when (gnus-summary-show-thread)
4074                   ;; If the summary buffer really was folded, the
4075                   ;; previous goto may not actually have gone to
4076                   ;; the right article, but the thread root instead.
4077                   ;; So we go again.
4078                   (gnus-summary-goto-subject gnus-current-article))
4079                 (gnus-run-hooks 'gnus-mark-article-hook)
4080                 (gnus-set-mode-line 'summary)
4081                 (when (gnus-visual-p 'article-highlight 'highlight)
4082                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
4083                 ;; Set the global newsgroup variables here.
4084                 (gnus-set-global-variables)
4085                 (setq gnus-have-all-headers
4086                       (or all-headers gnus-show-all-headers))))
4087             (save-excursion
4088               (gnus-configure-windows 'article))
4089             (when (or (numberp article)
4090                       (stringp article))
4091               (gnus-article-prepare-display)
4092               ;; Do page break.
4093               (goto-char (point-min))
4094               (when gnus-break-pages
4095                 (gnus-narrow-to-page)))
4096             (let ((gnus-article-mime-handle-alist-1
4097                    gnus-article-mime-handle-alist))
4098               (gnus-set-mode-line 'article))
4099             (article-goto-body)
4100             (unless (bobp)
4101               (forward-line -1))
4102             (set-window-point (get-buffer-window (current-buffer)) (point))
4103             (gnus-configure-windows 'article)
4104             t))))))
4105
4106 (defun gnus-article-prepare-mime-display (&optional number)
4107   (goto-char (point-min))
4108   (when (re-search-forward "^[^\t ]+:" nil t)
4109     (goto-char (match-beginning 0)))
4110   (let ((entity (if (eq 1 (point-min))
4111                     (get-text-property 1 'mime-view-entity)
4112                   (get-text-property (point) 'mime-view-entity)))
4113         last-entity child-entity next type)
4114     (setq child-entity (mime-entity-children entity))
4115     (if child-entity
4116         (setq last-entity (nth (1- (length child-entity))
4117                                child-entity))
4118       (setq last-entity entity))
4119     (save-restriction
4120       (narrow-to-region (point)
4121                         (if (search-forward "\n\n" nil t)
4122                             (point)
4123                           (point-max)))
4124       (gnus-treat-article 'head)
4125       (put-text-property (point-min) (point-max) 'article-treated-header t)
4126       (goto-char (point-max)))
4127     (while (and (not (eobp)) entity)
4128       (setq next (set-marker
4129                   (make-marker)
4130                   (next-single-property-change (point) 'mime-view-entity
4131                                                nil (point-max))))
4132       (let ((types (mime-entity-content-type entity)))
4133         (while (eq 'multipart (mime-content-type-primary-type types))
4134           (setq entity (car (mime-entity-children entity))
4135                 types (mime-entity-content-type entity)))
4136         (when types
4137           (setq type (format "%s/%s"
4138                              (mime-content-type-primary-type types)
4139                              (mime-content-type-subtype types)))))
4140       (if (string-equal type "message/rfc822")
4141           (progn
4142             (setq next (point))
4143             (let ((children (mime-entity-children entity))
4144                   last-children)
4145               (when children
4146                 (setq last-children (nth (1- (length children)) children))
4147                 (while
4148                     (and
4149                      (not (eq last-children
4150                               (get-text-property next 'mime-view-entity)))
4151                      (setq next
4152                            (next-single-property-change next
4153                                                         'mime-view-entity
4154                                                         nil (point-max)))))))
4155             (setq next (next-single-property-change next 'mime-view-entity
4156                                                     nil (point-max)))
4157             (save-restriction
4158               (narrow-to-region (point) next)
4159               (gnus-article-prepare-mime-display)
4160               (goto-char (point-max)))
4161             (setq entity (get-text-property (point) 'mime-view-entity)))
4162         (save-restriction
4163           (narrow-to-region (point) next)
4164           ;; Kludge. We have to count true number, but for now,
4165           ;; part number is here only to achieve `last'.
4166           (gnus-treat-article nil 1
4167                               (if (eq entity last-entity)
4168                                   1 2)
4169                               type)
4170           (goto-char (point-max)))
4171         (setq entity (get-text-property next 'mime-view-entity))))))
4172
4173 ;;;###autoload
4174 (defun gnus-article-prepare-display ()
4175   "Make the current buffer look like a nice article."
4176   (let ((gnus-article-buffer (current-buffer))
4177         buffer-read-only
4178         (inhibit-read-only t))
4179     (unless (eq major-mode 'gnus-article-mode)
4180       (gnus-article-mode))
4181     (setq buffer-read-only nil
4182           gnus-button-marker-list nil
4183           gnus-article-wash-types nil
4184           gnus-article-image-alist nil)
4185     (save-restriction
4186       (widen)
4187       (static-if (featurep 'xemacs)
4188           (map-extents (lambda (extent maparg) (delete-extent extent)))
4189         (let ((lists (overlay-lists)))
4190           (dolist (overlay (nconc (car lists) (cdr lists)))
4191             (delete-overlay overlay)))))
4192     (gnus-run-hooks 'gnus-tmp-internal-hook))
4193   (let ((show-mime (unless (member gnus-newsgroup-name '("nndraft:delayed"
4194                                                          "nndraft:drafts"))
4195                      gnus-show-mime))
4196         (inhibit-read-only t))
4197     (set-buffer gnus-original-article-buffer)
4198     ;; Display message.
4199     (setq mime-message-structure gnus-current-headers)
4200     (mime-buffer-entity-set-buffer-internal mime-message-structure
4201                                             gnus-original-article-buffer)
4202     (mime-entity-set-representation-type-internal mime-message-structure
4203                                                   'mime-buffer-entity)
4204     (luna-send mime-message-structure 'initialize-instance
4205                mime-message-structure)
4206     (if show-mime
4207         (let (mime-display-header-hook mime-display-text/plain-hook)
4208           (funcall gnus-article-display-method-for-mime))
4209       (funcall gnus-article-display-method-for-traditional))
4210     ;; Call the treatment functions.
4211     (save-restriction
4212       (widen)
4213       (if show-mime
4214           (gnus-article-prepare-mime-display)
4215         (narrow-to-region (goto-char (point-min))
4216                           (if (search-forward "\n\n" nil t)
4217                               (point)
4218                             (point-max)))
4219         (gnus-treat-article 'head)
4220         (put-text-property (point-min) (point-max) 'article-treated-header t)
4221         (goto-char (point-max))
4222         (widen)
4223         (narrow-to-region (point) (point-max))
4224         (gnus-treat-article nil))
4225       (put-text-property (point-min) (point-max) 'read-only nil)))
4226   (gnus-run-hooks 'gnus-article-prepare-hook))
4227
4228 (defun gnus-article-decode-article-as-default-mime-charset ()
4229   "Decode an article as `default-mime-charset'.  It won't work if the
4230 value of the variable `gnus-show-mime' is non-nil."
4231   (unless (or gnus-show-mime
4232               (member gnus-newsgroup-name '("nndraft:delayed"
4233                                             "nndraft:drafts")))
4234     (set (make-local-variable 'default-mime-charset)
4235          (with-current-buffer gnus-summary-buffer
4236            default-mime-charset))
4237     (decode-mime-charset-region (point-min) (point-max)
4238                                 default-mime-charset)))
4239
4240 ;;;
4241 ;;; Gnus MIME viewing functions
4242 ;;;
4243
4244 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4245   "Format of the MIME buttons.
4246
4247 Valid specifiers include:
4248 %t  The MIME type
4249 %T  MIME type, along with additional info
4250 %n  The `name' parameter
4251 %d  The description, if any
4252 %l  The length of the encoded part
4253 %p  The part identifier number
4254 %e  Dots if the part isn't displayed
4255
4256 General format specifiers can also be used.  See Info node
4257 `(gnus)Formatting Variables'.")
4258
4259 (defvar gnus-mime-button-line-format-alist
4260   '((?t gnus-tmp-type ?s)
4261     (?T gnus-tmp-type-long ?s)
4262     (?n gnus-tmp-name ?s)
4263     (?d gnus-tmp-description ?s)
4264     (?p gnus-tmp-id ?s)
4265     (?l gnus-tmp-length ?d)
4266     (?e gnus-tmp-dots ?s)))
4267
4268 (defvar gnus-mime-button-commands
4269   '((gnus-article-press-button "\r" "Toggle Display")
4270     (gnus-mime-view-part "v" "View Interactively...")
4271     (gnus-mime-view-part-as-type "t" "View As Type...")
4272     (gnus-mime-view-part-as-charset "C" "View As charset...")
4273     (gnus-mime-save-part "o" "Save...")
4274     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4275     (gnus-mime-delete-part "d" "Delete part")
4276     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4277     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4278     (gnus-mime-view-part-internally "E" "View Internally")
4279     (gnus-mime-view-part-externally "e" "View Externally")
4280     (gnus-mime-print-part "p" "Print")
4281     (gnus-mime-pipe-part "|" "Pipe To Command...")
4282     (gnus-mime-action-on-part "." "Take action on the part...")))
4283
4284 (defun gnus-article-mime-part-status ()
4285   (with-current-buffer gnus-article-buffer
4286     (let ((entity (get-text-property (point-min) 'mime-view-entity))
4287           children)
4288       (if (and entity
4289                (setq children (mime-entity-children entity))
4290                (setq children (length children)))
4291           (if (eq 1 children)
4292               " (1 part)"
4293             (format " (%d parts)" children))
4294         ""))))
4295
4296 (defvar gnus-mime-button-map
4297   (let ((map (make-sparse-keymap)))
4298     (define-key map gnus-mouse-2 'gnus-article-push-button)
4299     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4300     (dolist (c gnus-mime-button-commands)
4301       (define-key map (cadr c) (car c)))
4302     map))
4303
4304 (easy-menu-define
4305   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4306   `("MIME Part"
4307     ,@(mapcar (lambda (c)
4308                 (vector (caddr c) (car c) :enable t))
4309               gnus-mime-button-commands)))
4310
4311 (defun gnus-mime-button-menu (event prefix)
4312  "Construct a context-sensitive menu of MIME commands."
4313  (interactive "e\nP")
4314  (save-window-excursion
4315    (let ((pos (event-start event)))
4316      (select-window (posn-window pos))
4317      (goto-char (posn-point pos))
4318      (gnus-article-check-buffer)
4319      (popup-menu gnus-mime-button-menu nil prefix))))
4320
4321 (defun gnus-mime-view-all-parts (&optional handles)
4322   "View all the MIME parts."
4323   (interactive)
4324   (with-current-buffer gnus-article-buffer
4325     (let ((handles (or handles gnus-article-mime-handles))
4326           (mail-parse-charset gnus-newsgroup-charset)
4327           (mail-parse-ignored-charsets
4328            (with-current-buffer gnus-summary-buffer
4329              gnus-newsgroup-ignored-charsets)))
4330       (when handles
4331         (mm-remove-parts handles)
4332         (goto-char (point-min))
4333         (or (search-forward "\n\n") (goto-char (point-max)))
4334         (let ((inhibit-read-only t))
4335           (delete-region (point) (point-max))
4336           (mm-display-parts handles))))))
4337
4338 (eval-when-compile
4339   (defsubst gnus-article-edit-part (handles)
4340     "Edit an article in order to delete a mime part.
4341 This function is exclusively used by `gnus-mime-save-part-and-strip'
4342 and `gnus-mime-delete-part', and not provided at run-time normally."
4343     (gnus-article-edit-article
4344      `(lambda ()
4345         (erase-buffer)
4346         (let ((mail-parse-charset (or gnus-article-charset
4347                                       ',gnus-newsgroup-charset))
4348               (mail-parse-ignored-charsets
4349                (or gnus-article-ignored-charsets
4350                    ',gnus-newsgroup-ignored-charsets))
4351               (mbl mml-buffer-list))
4352           (setq mml-buffer-list nil)
4353           (insert-buffer gnus-original-article-buffer)
4354           (mime-to-mml ',handles)
4355           (setq gnus-article-mime-handles nil)
4356           (let ((mbl1 mml-buffer-list))
4357             (setq mml-buffer-list mbl)
4358             (set (make-local-variable 'mml-buffer-list) mbl1))
4359           (gnus-make-local-hook 'kill-buffer-hook)
4360           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4361      `(lambda (no-highlight)
4362         (let ((mail-parse-charset (or gnus-article-charset
4363                                       ',gnus-newsgroup-charset))
4364               (message-options message-options)
4365               (message-options-set-recipient)
4366               (mail-parse-ignored-charsets
4367                (or gnus-article-ignored-charsets
4368                    ',gnus-newsgroup-ignored-charsets)))
4369           (mml-to-mime)
4370           (mml-destroy-buffers)
4371           (remove-hook 'kill-buffer-hook
4372                        'mml-destroy-buffers t)
4373           (kill-local-variable 'mml-buffer-list))
4374         (gnus-summary-edit-article-done
4375          ,(or (mail-header-references gnus-current-headers) "")
4376          ,(gnus-group-read-only-p)
4377          ,gnus-summary-buffer no-highlight)))
4378     (gnus-article-edit-done)
4379     (gnus-summary-expand-window)
4380     (gnus-summary-show-article)))
4381
4382 (defun gnus-mime-save-part-and-strip ()
4383   "Save the MIME part under point then replace it with an external body."
4384   (interactive)
4385   (gnus-article-check-buffer)
4386   (when (gnus-group-read-only-p)
4387     (error "The current group does not support deleting of parts"))
4388   (when (mm-complicated-handles gnus-article-mime-handles)
4389     (error "\
4390 The current article has a complicated MIME structure, giving up..."))
4391   (when (gnus-yes-or-no-p "\
4392 Deleting parts may malfunction or destroy the article; continue? ")
4393     (let* ((data (get-text-property (point) 'gnus-data))
4394            file param
4395            (handles gnus-article-mime-handles))
4396       (setq file (and data (mm-save-part data)))
4397       (when file
4398         (with-current-buffer (mm-handle-buffer data)
4399           (erase-buffer)
4400           (insert "Content-Type: " (mm-handle-media-type data))
4401           (mml-insert-parameter-string (cdr (mm-handle-type data))
4402                                        '(charset))
4403           (insert "\n")
4404           (insert "Content-ID: " (message-make-message-id) "\n")
4405           (insert "Content-Transfer-Encoding: binary\n")
4406           (insert "\n"))
4407         (setcdr data
4408                 (cdr (mm-make-handle nil
4409                                      `("message/external-body"
4410                                        (access-type . "LOCAL-FILE")
4411                                        (name . ,file)))))
4412         (set-buffer gnus-summary-buffer)
4413         (gnus-article-edit-part handles)))))
4414
4415 (defun gnus-mime-delete-part ()
4416   "Delete the MIME part under point.
4417 Replace it with some information about the removed part."
4418   (interactive)
4419   (gnus-article-check-buffer)
4420   (when (gnus-group-read-only-p)
4421     (error "The current group does not support deleting of parts"))
4422   (when (mm-complicated-handles gnus-article-mime-handles)
4423     (error "\
4424 The current article has a complicated MIME structure, giving up..."))
4425   (when (gnus-yes-or-no-p "\
4426 Deleting parts may malfunction or destroy the article; continue? ")
4427     (let* ((data (get-text-property (point) 'gnus-data))
4428            (handles gnus-article-mime-handles)
4429            (none "(none)")
4430            (description
4431             (or
4432              (mail-decode-encoded-word-string (or (mm-handle-description data)
4433                                                   none))))
4434            (filename
4435             (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4436                 none))
4437            (type (mm-handle-media-type data)))
4438       (unless data
4439         (error "No MIME part under point"))
4440       (with-current-buffer (mm-handle-buffer data)
4441         (let ((bsize (format "%s" (buffer-size))))
4442           (erase-buffer)
4443           (insert
4444            (concat
4445             ",----\n"
4446             "| The following attachment has been deleted:\n"
4447             "|\n"
4448             "| Type:           " type "\n"
4449             "| Filename:       " filename "\n"
4450             "| Size (encoded): " bsize " Byte\n"
4451             "| Description:    " description "\n"
4452             "`----\n"))
4453           (setcdr data
4454                   (cdr (mm-make-handle
4455                         nil `("text/plain") nil nil
4456                         (list "attachment")
4457                         (format "Deleted attachment (%s bytes)" bsize))))))
4458       (set-buffer gnus-summary-buffer)
4459       (gnus-article-edit-part handles))))
4460
4461 (defun gnus-mime-save-part ()
4462   "Save the MIME part under point."
4463   (interactive)
4464   (gnus-article-check-buffer)
4465   (let ((data (get-text-property (point) 'gnus-data)))
4466     (when data
4467       (mm-save-part data))))
4468
4469 (defun gnus-mime-pipe-part ()
4470   "Pipe the MIME part under point to a process."
4471   (interactive)
4472   (gnus-article-check-buffer)
4473   (let ((data (get-text-property (point) 'gnus-data)))
4474     (when data
4475       (mm-pipe-part data))))
4476
4477 (defun gnus-mime-view-part ()
4478   "Interactively choose a viewing method for the MIME part under point."
4479   (interactive)
4480   (gnus-article-check-buffer)
4481   (let ((data (get-text-property (point) 'gnus-data)))
4482     (when data
4483       (setq gnus-article-mime-handles
4484             (mm-merge-handles
4485              gnus-article-mime-handles (setq data (copy-sequence data))))
4486       (mm-interactively-view-part data))))
4487
4488 (defun gnus-mime-view-part-as-type-internal ()
4489   (gnus-article-check-buffer)
4490   (let* ((name (mail-content-type-get
4491                 (mm-handle-type (get-text-property (point) 'gnus-data))
4492                 'name))
4493          (def-type (and name (mm-default-file-encoding name))))
4494     (and def-type (cons def-type 0))))
4495
4496 (defun gnus-mime-view-part-as-type (&optional mime-type)
4497   "Choose a MIME media type, and view the part as such."
4498   (interactive)
4499   (unless mime-type
4500     (setq mime-type (completing-read
4501                      "View as MIME type: "
4502                      (mapcar #'list (mailcap-mime-types))
4503                      nil nil
4504                      (gnus-mime-view-part-as-type-internal))))
4505   (gnus-article-check-buffer)
4506   (let ((handle (get-text-property (point) 'gnus-data)))
4507     (when handle
4508       (setq handle
4509             (mm-make-handle (mm-handle-buffer handle)
4510                             (cons mime-type (cdr (mm-handle-type handle)))
4511                             (mm-handle-encoding handle)
4512                             (mm-handle-undisplayer handle)
4513                             (mm-handle-disposition handle)
4514                             (mm-handle-description handle)
4515                             nil
4516                             (mm-handle-id handle)))
4517       (setq gnus-article-mime-handles
4518             (mm-merge-handles gnus-article-mime-handles handle))
4519       (gnus-mm-display-part handle))))
4520
4521 (eval-when-compile
4522   (require 'jka-compr))
4523
4524 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4525 ;; emacs can do that itself.
4526 ;;
4527 (defun gnus-mime-jka-compr-maybe-uncompress ()
4528   "Uncompress the current buffer if `auto-compression-mode' is enabled.
4529 The uncompress method used is derived from `buffer-file-name'."
4530   (when (and (fboundp 'jka-compr-installed-p)
4531              (jka-compr-installed-p))
4532     (let ((info (jka-compr-get-compression-info buffer-file-name)))
4533       (when info
4534         (let ((basename (file-name-nondirectory buffer-file-name))
4535               (args     (jka-compr-info-uncompress-args    info))
4536               (prog     (jka-compr-info-uncompress-program info))
4537               (message  (jka-compr-info-uncompress-message info))
4538               (err-file (jka-compr-make-temp-name)))
4539           (if message
4540               (message "%s %s..." message basename))
4541           (unwind-protect
4542               (unless (memq (apply 'call-process-region
4543                                    (point-min) (point-max)
4544                                    prog
4545                                    t (list t err-file) nil
4546                                    args)
4547                             jka-compr-acceptable-retval-list)
4548                 (jka-compr-error prog args basename message err-file))
4549             (jka-compr-delete-temp-file err-file)))))))
4550
4551 (defun gnus-mime-copy-part (&optional handle)
4552   "Put the MIME part under point into a new buffer.
4553 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4554 are decompressed."
4555   (interactive)
4556   (gnus-article-check-buffer)
4557   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4558          (contents (and handle (mm-get-part handle)))
4559          (base (and handle
4560                     (file-name-nondirectory
4561                      (or
4562                       (mail-content-type-get (mm-handle-type handle) 'name)
4563                       (mail-content-type-get (mm-handle-disposition handle)
4564                                              'filename)
4565                       "*decoded*"))))
4566          (buffer (and base (generate-new-buffer base))))
4567     (when contents
4568       (switch-to-buffer buffer)
4569       (insert contents)
4570       ;; We do it this way to make `normal-mode' set the appropriate mode.
4571       (unwind-protect
4572           (progn
4573             (setq buffer-file-name (expand-file-name base))
4574             (gnus-mime-jka-compr-maybe-uncompress)
4575             (normal-mode))
4576         (setq buffer-file-name nil))
4577       (goto-char (point-min)))))
4578
4579 (defun gnus-mime-print-part (&optional handle filename)
4580   "Print the MIME part under point."
4581   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4582   (gnus-article-check-buffer)
4583   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4584          (contents (and handle (mm-get-part handle)))
4585          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4586          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4587     (when contents
4588         (if printer
4589             (unwind-protect
4590                 (progn
4591                   (mm-save-part-to-file handle file)
4592                   (call-process shell-file-name nil
4593                                 (generate-new-buffer " *mm*")
4594                                 nil
4595                                 shell-command-switch
4596                                 (mm-mailcap-command
4597                                  printer file (mm-handle-type handle))))
4598               (delete-file file))
4599           (with-temp-buffer
4600             (insert contents)
4601             (gnus-print-buffer))
4602           (ps-despool filename)))))
4603
4604 (defun gnus-mime-inline-part (&optional handle arg)
4605   "Insert the MIME part under point into the current buffer."
4606   (interactive (list nil current-prefix-arg))
4607   (gnus-article-check-buffer)
4608   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4609          contents charset
4610          (b (point))
4611          (inhibit-read-only t))
4612     (when handle
4613       (if (and (not arg) (mm-handle-undisplayer handle))
4614           (mm-remove-part handle)
4615         (setq contents (mm-get-part handle))
4616         (cond
4617          ((not arg)
4618           (setq charset (or (mail-content-type-get
4619                              (mm-handle-type handle) 'charset)
4620                             gnus-newsgroup-charset)))
4621          ((numberp arg)
4622           (if (mm-handle-undisplayer handle)
4623               (mm-remove-part handle))
4624           (setq charset
4625                 (or (cdr (assq arg
4626                                gnus-summary-show-article-charset-alist))
4627                     (mm-read-coding-system "Charset: ")))))
4628         (forward-line 2)
4629         (mm-insert-inline handle
4630                           (if (and charset
4631                                    (setq charset (mm-charset-to-coding-system
4632                                                   charset))
4633                                    (not (eq charset 'ascii)))
4634                               (mm-decode-coding-string contents charset)
4635                             contents))
4636         (goto-char b)))))
4637
4638 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4639   "Insert the MIME part under point into the current buffer using the
4640 specified charset."
4641   (interactive (list nil current-prefix-arg))
4642   (gnus-article-check-buffer)
4643   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4644          contents charset
4645          (b (point))
4646          (inhibit-read-only t))
4647     (when handle
4648       (if (mm-handle-undisplayer handle)
4649           (mm-remove-part handle))
4650       (let ((gnus-newsgroup-charset
4651              (or (cdr (assq arg
4652                             gnus-summary-show-article-charset-alist))
4653                  (mm-read-coding-system "Charset: ")))
4654             (gnus-newsgroup-ignored-charsets 'gnus-all))
4655         (gnus-article-press-button)))))
4656
4657 (defun gnus-mime-view-part-externally (&optional handle)
4658   "View the MIME part under point with an external viewer."
4659   (interactive)
4660   (gnus-article-check-buffer)
4661   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4662          (mm-user-display-methods nil)
4663          (mm-inlined-types nil)
4664          (mail-parse-charset gnus-newsgroup-charset)
4665          (mail-parse-ignored-charsets
4666           (with-current-buffer gnus-summary-buffer
4667             gnus-newsgroup-ignored-charsets)))
4668     (when handle
4669       (if (mm-handle-undisplayer handle)
4670           (mm-remove-part handle)
4671         (mm-display-part handle)))))
4672
4673 (defun gnus-mime-view-part-internally (&optional handle)
4674   "View the MIME part under point with an internal viewer.
4675 If no internal viewer is available, use an external viewer."
4676   (interactive)
4677   (gnus-article-check-buffer)
4678   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4679          (mm-inlined-types '(".*"))
4680          (mm-inline-large-images t)
4681          (mail-parse-charset gnus-newsgroup-charset)
4682          (mail-parse-ignored-charsets
4683           (with-current-buffer gnus-summary-buffer
4684             gnus-newsgroup-ignored-charsets))
4685          (inhibit-read-only t))
4686     (when handle
4687       (if (mm-handle-undisplayer handle)
4688           (mm-remove-part handle)
4689         (mm-display-part handle)))))
4690
4691 (defun gnus-mime-action-on-part (&optional action)
4692   "Do something with the MIME attachment at \(point\)."
4693   (interactive
4694    (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4695   (gnus-article-check-buffer)
4696   (let ((action-pair (assoc action gnus-mime-action-alist)))
4697     (if action-pair
4698         (funcall (cdr action-pair)))))
4699
4700 (defun gnus-article-part-wrapper (n function)
4701   (with-current-buffer gnus-article-buffer
4702     (when (> n (length gnus-article-mime-handle-alist))
4703       (error "No such part"))
4704     (gnus-article-goto-part n)
4705     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4706       (funcall function handle))))
4707
4708 (defun gnus-article-pipe-part (n)
4709   "Pipe MIME part N, which is the numerical prefix."
4710   (interactive "p")
4711   (gnus-article-part-wrapper n 'mm-pipe-part))
4712
4713 (defun gnus-article-save-part (n)
4714   "Save MIME part N, which is the numerical prefix."
4715   (interactive "p")
4716   (gnus-article-part-wrapper n 'mm-save-part))
4717
4718 (defun gnus-article-interactively-view-part (n)
4719   "View MIME part N interactively, which is the numerical prefix."
4720   (interactive "p")
4721   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4722
4723 (defun gnus-article-copy-part (n)
4724   "Copy MIME part N, which is the numerical prefix."
4725   (interactive "p")
4726   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4727
4728 (defun gnus-article-view-part-as-charset (n)
4729   "View MIME part N using a specified charset.
4730 N is the numerical prefix."
4731   (interactive "p")
4732   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4733
4734 (defun gnus-article-view-part-externally (n)
4735   "View MIME part N externally, which is the numerical prefix."
4736   (interactive "p")
4737   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4738
4739 (defun gnus-article-inline-part (n)
4740   "Inline MIME part N, which is the numerical prefix."
4741   (interactive "p")
4742   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4743
4744 (defun gnus-article-mime-match-handle-first (condition)
4745   (if condition
4746       (let ((alist gnus-article-mime-handle-alist) ihandle n)
4747         (while (setq ihandle (pop alist))
4748           (if (and (cond
4749                     ((functionp condition)
4750                      (funcall condition (cdr ihandle)))
4751                     ((eq condition 'undisplayed)
4752                      (not (or (mm-handle-undisplayer (cdr ihandle))
4753                               (equal (mm-handle-media-type (cdr ihandle))
4754                                      "multipart/alternative"))))
4755                     ((eq condition 'undisplayed-alternative)
4756                      (not (mm-handle-undisplayer (cdr ihandle))))
4757                     (t t))
4758                    (gnus-article-goto-part (car ihandle))
4759                    (or (not n) (< (car ihandle) n)))
4760               (setq n (car ihandle))))
4761         (or n 1))
4762     1))
4763
4764 (defun gnus-article-view-part (&optional n)
4765   "View MIME part N, which is the numerical prefix."
4766   (interactive "P")
4767   (with-current-buffer gnus-article-buffer
4768     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4769                              gnus-article-mime-match-handle-function)))
4770     (when (> n (length gnus-article-mime-handle-alist))
4771       (error "No such part"))
4772     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4773       (when (gnus-article-goto-part n)
4774         (if (equal (car handle) "multipart/alternative")
4775             (gnus-article-press-button)
4776           (when (eq (gnus-mm-display-part handle) 'internal)
4777             (gnus-set-window-start)))))))
4778
4779 (defsubst gnus-article-mime-total-parts ()
4780   (if (bufferp (car gnus-article-mime-handles))
4781       1 ;; single part
4782     (1- (length gnus-article-mime-handles))))
4783
4784 (defun gnus-mm-display-part (handle)
4785   "Display HANDLE and fix MIME button."
4786   (let ((id (get-text-property (point) 'gnus-part))
4787         (point (point))
4788         (inhibit-read-only t))
4789     (forward-line 1)
4790     (prog1
4791         (let ((window (selected-window))
4792               (mail-parse-charset gnus-newsgroup-charset)
4793               (mail-parse-ignored-charsets
4794                (if (gnus-buffer-live-p gnus-summary-buffer)
4795                    (with-current-buffer gnus-summary-buffer
4796                      gnus-newsgroup-ignored-charsets)
4797                  nil)))
4798           (save-excursion
4799             (unwind-protect
4800                 (let ((win (gnus-get-buffer-window (current-buffer) t))
4801                       (beg (point)))
4802                   (when win
4803                     (select-window win))
4804                   (goto-char point)
4805                   (forward-line)
4806                   (if (mm-handle-displayed-p handle)
4807                       ;; This will remove the part.
4808                       (mm-display-part handle)
4809                     (save-restriction
4810                       (narrow-to-region (point)
4811                                         (if (eobp) (point) (1+ (point))))
4812                       (mm-display-part handle)
4813                       ;; We narrow to the part itself and
4814                       ;; then call the treatment functions.
4815                       (goto-char (point-min))
4816                       (forward-line 1)
4817                       (narrow-to-region (point) (point-max))
4818                       (gnus-treat-article
4819                        nil id
4820                        (gnus-article-mime-total-parts)
4821                        (mm-handle-media-type handle)))))
4822               (if (window-live-p window)
4823                   (select-window window)))))
4824       (goto-char point)
4825       (gnus-delete-line)
4826       (gnus-insert-mime-button
4827        handle id (list (mm-handle-displayed-p handle)))
4828       (goto-char point))))
4829
4830 (defun gnus-article-goto-part (n)
4831   "Go to MIME part N."
4832   (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4833
4834 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4835   (let ((gnus-tmp-name
4836          (or (mail-content-type-get (mm-handle-type handle) 'name)
4837              (mail-content-type-get (mm-handle-disposition handle) 'filename)
4838              (mail-content-type-get (mm-handle-type handle) 'url)
4839              ""))
4840         (gnus-tmp-type (mm-handle-media-type handle))
4841         (gnus-tmp-description
4842          (mail-decode-encoded-word-string (or (mm-handle-description handle)
4843                                               "")))
4844         (gnus-tmp-dots
4845          (if (if displayed (car displayed)
4846                (mm-handle-displayed-p handle))
4847              "" "..."))
4848         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4849                            (buffer-size)))
4850         gnus-tmp-type-long b e)
4851     (when (string-match ".*/" gnus-tmp-name)
4852       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4853     (setq gnus-tmp-type-long (concat gnus-tmp-type
4854                                      (and (not (equal gnus-tmp-name ""))
4855                                           (concat "; " gnus-tmp-name))))
4856     (unless (equal gnus-tmp-description "")
4857       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4858     (unless (bolp)
4859       (insert "\n"))
4860     (setq b (point))
4861     (gnus-eval-format
4862      gnus-mime-button-line-format gnus-mime-button-line-format-alist
4863      `(keymap ,gnus-mime-button-map
4864               gnus-callback gnus-mm-display-part
4865               gnus-part ,gnus-tmp-id
4866               article-type annotation
4867               gnus-data ,handle))
4868     (setq e (if (bolp)
4869                 ;; Exclude a newline.
4870                 (1- (point))
4871               (point)))
4872     (widget-convert-button
4873      'link b e
4874      :mime-handle handle
4875      :action 'gnus-widget-press-button
4876      :button-keymap gnus-mime-button-map
4877      :help-echo
4878      (lambda (widget/window &optional overlay pos)
4879        ;; Needed to properly clear the message due to a bug in
4880        ;; wid-edit (XEmacs only).
4881        (if (boundp 'help-echo-owns-message)
4882            (setq help-echo-owns-message t))
4883        (format
4884         "%S: %s the MIME part; %S: more options"
4885         (aref gnus-mouse-2 0)
4886         ;; XEmacs will get a single widget arg; Emacs 21 will get
4887         ;; window, overlay, position.
4888         (if (mm-handle-displayed-p
4889              (if overlay
4890                  (with-current-buffer (gnus-overlay-buffer overlay)
4891                    (widget-get (widget-at (gnus-overlay-start overlay))
4892                                :mime-handle))
4893                (widget-get widget/window :mime-handle)))
4894             "hide" "show")
4895         (aref gnus-down-mouse-3 0))))))
4896
4897 (defun gnus-widget-press-button (elems el)
4898   (goto-char (widget-get elems :from))
4899   (gnus-article-press-button))
4900
4901 (defvar gnus-displaying-mime nil)
4902
4903 (defun gnus-display-mime (&optional ihandles)
4904   "Display the MIME parts."
4905   (save-excursion
4906     (save-selected-window
4907       (let ((window (get-buffer-window gnus-article-buffer))
4908             (point (point)))
4909         (when window
4910           (select-window window)
4911           ;; We have to do this since selecting the window
4912           ;; may change the point.  So we set the window point.
4913           (set-window-point window point)))
4914       (let* ((handles (or ihandles
4915                           (mm-dissect-buffer nil gnus-article-loose-mime)
4916                           (and gnus-article-emulate-mime
4917                                (mm-uu-dissect))))
4918              (inhibit-read-only t) handle name type b e display)
4919         (when (and (not ihandles)
4920                    (not gnus-displaying-mime))
4921           ;; Top-level call; we clean up.
4922           (when gnus-article-mime-handles
4923             (mm-destroy-parts gnus-article-mime-handles)
4924             (setq gnus-article-mime-handle-alist nil));; A trick.
4925           (setq gnus-article-mime-handles handles)
4926           ;; We allow users to glean info from the handles.
4927           (when gnus-article-mime-part-function
4928             (gnus-mime-part-function handles)))
4929         (if (and handles
4930                  (or (not (stringp (car handles)))
4931                      (cdr handles)))
4932             (progn
4933               (when (and (not ihandles)
4934                          (not gnus-displaying-mime))
4935                 ;; Clean up for mime parts.
4936                 (article-goto-body)
4937                 (delete-region (point) (point-max)))
4938               (let ((gnus-displaying-mime t))
4939                 (gnus-mime-display-part handles)))
4940           (save-restriction
4941             (article-goto-body)
4942             (narrow-to-region (point) (point-max))
4943             (gnus-treat-article nil 1 1)
4944             (widen)))
4945         (unless ihandles
4946           ;; Highlight the headers.
4947           (save-excursion
4948             (save-restriction
4949               (article-goto-body)
4950               (narrow-to-region (point-min) (point))
4951               (gnus-treat-article 'head))))))))
4952
4953 (defcustom gnus-mime-display-multipart-as-mixed nil
4954   "Display \"multipart\" parts as  \"multipart/mixed\".
4955
4956 If t, it overrides nil values of
4957 `gnus-mime-display-multipart-alternative-as-mixed' and
4958 `gnus-mime-display-multipart-related-as-mixed'."
4959   :group 'gnus-article-mime
4960   :type 'boolean)
4961
4962 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4963   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
4964   :version "21.4"
4965   :group 'gnus-article-mime
4966   :type 'boolean)
4967
4968 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4969   "Display \"multipart/related\" parts as  \"multipart/mixed\".
4970
4971 If displaying \"text/html\" is discouraged \(see
4972 `mm-discouraged-alternatives'\) images or other material inside a
4973 \"multipart/related\" part might be overlooked when this variable is nil."
4974   :version "21.4"
4975   :group 'gnus-article-mime
4976   :type 'boolean)
4977
4978 (defun gnus-mime-display-part (handle)
4979   (cond
4980    ;; Single part.
4981    ((not (stringp (car handle)))
4982     (gnus-mime-display-single handle))
4983    ;; User-defined multipart
4984    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4985     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4986              handle))
4987    ;; multipart/alternative
4988    ((and (equal (car handle) "multipart/alternative")
4989          (not (or gnus-mime-display-multipart-as-mixed
4990                   gnus-mime-display-multipart-alternative-as-mixed)))
4991     (let ((id (1+ (length gnus-article-mime-handle-alist))))
4992       (push (cons id handle) gnus-article-mime-handle-alist)
4993       (gnus-mime-display-alternative (cdr handle) nil nil id)))
4994    ;; multipart/related
4995    ((and (equal (car handle) "multipart/related")
4996          (not (or gnus-mime-display-multipart-as-mixed
4997                   gnus-mime-display-multipart-related-as-mixed)))
4998     ;;;!!!We should find the start part, but we just default
4999     ;;;!!!to the first part.
5000     ;;(gnus-mime-display-part (cadr handle))
5001     ;;;!!! Most multipart/related is an HTML message plus images.
5002     ;;;!!! Unfortunately we are unable to let W3 display those
5003     ;;;!!! included images, so we just display it as a mixed multipart.
5004     ;;(gnus-mime-display-mixed (cdr handle))
5005     ;;;!!! No, w3 can display everything just fine.
5006     (gnus-mime-display-part (cadr handle)))
5007    ((equal (car handle) "multipart/signed")
5008     (gnus-add-wash-type 'signed)
5009     (gnus-mime-display-security handle))
5010    ((equal (car handle) "multipart/encrypted")
5011     (gnus-add-wash-type 'encrypted)
5012     (gnus-mime-display-security handle))
5013    ;; Other multiparts are handled like multipart/mixed.
5014    (t
5015     (gnus-mime-display-mixed (cdr handle)))))
5016
5017 (defun gnus-mime-part-function (handles)
5018   (if (stringp (car handles))
5019       (mapcar 'gnus-mime-part-function (cdr handles))
5020     (funcall gnus-article-mime-part-function handles)))
5021
5022 (defun gnus-mime-display-mixed (handles)
5023   (mapcar 'gnus-mime-display-part handles))
5024
5025 (defun gnus-mime-display-single (handle)
5026   (let ((type (mm-handle-media-type handle))
5027         (ignored gnus-ignored-mime-types)
5028         (not-attachment t)
5029         (move nil)
5030         display text)
5031     (catch 'ignored
5032       (progn
5033         (while ignored
5034           (when (string-match (pop ignored) type)
5035             (throw 'ignored nil)))
5036         (if (and (setq not-attachment
5037                        (and (not (mm-inline-override-p handle))
5038                             (or (not (mm-handle-disposition handle))
5039                                 (equal (car (mm-handle-disposition handle))
5040                                        "inline")
5041                                 (mm-attachment-override-p handle))))
5042                  (mm-automatic-display-p handle)
5043                  (or (and
5044                       (mm-inlinable-p handle)
5045                       (mm-inlined-p handle))
5046                      (mm-automatic-external-display-p type)))
5047             (setq display t)
5048           (when (equal (mm-handle-media-supertype handle) "text")
5049             (setq text t)))
5050         (let ((id (1+ (length gnus-article-mime-handle-alist)))
5051               beg)
5052           (push (cons id handle) gnus-article-mime-handle-alist)
5053           (when (or (not display)
5054                     (not (gnus-unbuttonized-mime-type-p type)))
5055             (gnus-insert-mime-button
5056              handle id (list (or display (and not-attachment text))))
5057             (gnus-article-insert-newline)
5058             ;; Remember modify the number of forward lines.
5059             (setq move t))
5060           (setq beg (point))
5061           (cond
5062            (display
5063             (when move
5064               (forward-line -1)
5065               (setq beg (point)))
5066             (let ((mail-parse-charset gnus-newsgroup-charset)
5067                   (mail-parse-ignored-charsets
5068                    (save-excursion (condition-case ()
5069                                        (set-buffer gnus-summary-buffer)
5070                                      (error))
5071                                    gnus-newsgroup-ignored-charsets)))
5072               (mm-display-part handle t))
5073             (goto-char (point-max)))
5074            ((and text not-attachment)
5075             (when move
5076               (forward-line -1)
5077               (setq beg (point)))
5078             (gnus-article-insert-newline)
5079             (mm-insert-inline handle (mm-get-part handle))
5080             (goto-char (point-max))))
5081           ;; Do highlighting.
5082           (save-excursion
5083             (save-restriction
5084               (narrow-to-region beg (point))
5085               (gnus-treat-article
5086                nil id
5087                (gnus-article-mime-total-parts)
5088                (mm-handle-media-type handle)))))))))
5089
5090 (defun gnus-unbuttonized-mime-type-p (type)
5091   "Say whether TYPE is to be unbuttonized."
5092   (unless gnus-inhibit-mime-unbuttonizing
5093     (when (catch 'found
5094             (let ((types gnus-unbuttonized-mime-types))
5095               (while types
5096                 (when (string-match (pop types) type)
5097                   (throw 'found t)))))
5098       (not (catch 'found
5099              (let ((types gnus-buttonized-mime-types))
5100                (while types
5101                  (when (string-match (pop types) type)
5102                    (throw 'found t)))))))))
5103
5104 (defun gnus-article-insert-newline ()
5105   "Insert a newline, but mark it as undeletable."
5106   (gnus-put-text-property
5107    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5108
5109 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5110   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5111          (ihandles handles)
5112          (point (point))
5113          handle (inhibit-read-only t) from props begend not-pref)
5114     (save-window-excursion
5115       (save-restriction
5116         (when ibegend
5117           (narrow-to-region (car ibegend)
5118                             (or (cdr ibegend)
5119                                 (progn
5120                                   (goto-char (car ibegend))
5121                                   (forward-line 2)
5122                                   (point))))
5123           (delete-region (point-min) (point-max))
5124           (mm-remove-parts handles))
5125         (setq begend (list (point-marker)))
5126         ;; Do the toggle.
5127         (unless (setq not-pref (cadr (member preferred ihandles)))
5128           (setq not-pref (car ihandles)))
5129         (when (or ibegend
5130                   (not preferred)
5131                   (not (gnus-unbuttonized-mime-type-p
5132                         "multipart/alternative")))
5133           (gnus-add-text-properties
5134            (setq from (point))
5135            (progn
5136              (insert (format "%d.  " id))
5137              (point))
5138            `(gnus-callback
5139              (lambda (handles)
5140                (unless ,(not ibegend)
5141                  (setq gnus-article-mime-handle-alist
5142                        ',gnus-article-mime-handle-alist))
5143                (gnus-mime-display-alternative
5144                 ',ihandles ',not-pref ',begend ,id))
5145              keymap ,gnus-mime-button-map
5146              ,gnus-mouse-face-prop ,gnus-article-mouse-face
5147              face ,gnus-article-button-face
5148              gnus-part ,id
5149              gnus-data ,handle))
5150           (widget-convert-button 'link from (point)
5151                                  :action 'gnus-widget-press-button
5152                                  :button-keymap gnus-widget-button-keymap)
5153           ;; Do the handles
5154           (while (setq handle (pop handles))
5155             (gnus-add-text-properties
5156              (setq from (point))
5157              (progn
5158                (insert (format "(%c) %-18s"
5159                                (if (equal handle preferred) ?* ? )
5160                                (mm-handle-media-type handle)))
5161                (point))
5162              `(gnus-callback
5163                (lambda (handles)
5164                  (unless ,(not ibegend)
5165                    (setq gnus-article-mime-handle-alist
5166                          ',gnus-article-mime-handle-alist))
5167                  (gnus-mime-display-alternative
5168                   ',ihandles ',handle ',begend ,id))
5169                keymap ,gnus-mime-button-map
5170                ,gnus-mouse-face-prop ,gnus-article-mouse-face
5171                face ,gnus-article-button-face
5172                gnus-part ,id
5173                gnus-data ,handle))
5174             (widget-convert-button 'link from (point)
5175                                    :action 'gnus-widget-press-button
5176                                    :button-keymap gnus-widget-button-keymap)
5177             (insert "  "))
5178           (insert "\n\n"))
5179         (when preferred
5180           (if (stringp (car preferred))
5181               (gnus-display-mime preferred)
5182             (let ((mail-parse-charset gnus-newsgroup-charset)
5183                   (mail-parse-ignored-charsets
5184                    (with-current-buffer gnus-summary-buffer
5185                      gnus-newsgroup-ignored-charsets)))
5186               (mm-display-part preferred)
5187               ;; Do highlighting.
5188               (save-excursion
5189                 (save-restriction
5190                   (narrow-to-region (car begend) (point-max))
5191                   (gnus-treat-article
5192                    nil (length gnus-article-mime-handle-alist)
5193                    (gnus-article-mime-total-parts)
5194                    (mm-handle-media-type handle))))))
5195           (goto-char (point-max))
5196           (setcdr begend (point-marker)))))
5197     (when ibegend
5198       (goto-char point))))
5199
5200 (defconst gnus-article-wash-status-strings
5201   (let ((alist '((cite "c" "Possible hidden citation text"
5202                        " " "All citation text visible")
5203                  (headers "h" "Hidden headers"
5204                           " " "All headers visible.")
5205                  (pgp "p" "Encrypted or signed message status hidden"
5206                       " " "No hidden encryption nor digital signature status")
5207                  (signature "s" "Signature has been hidden"
5208                             " " "Signature is visible")
5209                  (overstrike "o" "Overstrike (^H) characters applied"
5210                              " " "No overstrike characters applied")
5211                  (gnus-show-mime "m" "Mime processing is activated"
5212                                  " " "Mime processing is not activated")
5213                  (emphasis "e" "/*_Emphasis_*/ characters applied"
5214                            " " "No /*_emphasis_*/ characters applied")))
5215         result)
5216     (dolist (entry alist result)
5217       (let ((key (nth 0 entry))
5218             (on (copy-sequence (nth 1 entry)))
5219             (on-help (nth 2 entry))
5220             (off (copy-sequence (nth 3 entry)))
5221             (off-help (nth 4 entry)))
5222         (put-text-property 0 1 'help-echo on-help on)
5223         (put-text-property 0 1 'help-echo off-help off)
5224         (push (list key on off) result))))
5225   "Alist of strings describing wash status in the mode line.
5226 Each entry has the form (KEY ON OF), where the KEY is a symbol
5227 representing the particular washing function, ON is the string to use
5228 in the article mode line when the washing function is active, and OFF
5229 is the string to use when it is inactive.")
5230
5231 (defun gnus-article-wash-status-entry (key value)
5232   (let ((entry (assoc key gnus-article-wash-status-strings)))
5233     (if value (nth 1 entry) (nth 2 entry))))
5234
5235 (defun gnus-article-wash-status ()
5236   "Return a string which display status of article washing."
5237   (with-current-buffer gnus-article-buffer
5238     (let ((cite (memq 'cite gnus-article-wash-types))
5239           (headers (memq 'headers gnus-article-wash-types))
5240           (boring (memq 'boring-headers gnus-article-wash-types))
5241           (pgp (memq 'pgp gnus-article-wash-types))
5242           (pem (memq 'pem gnus-article-wash-types))
5243           (signed (memq 'signed gnus-article-wash-types))
5244           (encrypted (memq 'encrypted gnus-article-wash-types))
5245           (signature (memq 'signature gnus-article-wash-types))
5246           (overstrike (memq 'overstrike gnus-article-wash-types))
5247           (emphasis (memq 'emphasis gnus-article-wash-types)))
5248       (concat
5249        (gnus-article-wash-status-entry 'cite cite)
5250        (gnus-article-wash-status-entry 'headers (or headers boring))
5251        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5252        (gnus-article-wash-status-entry 'signature signature)
5253        (gnus-article-wash-status-entry 'overstrike overstrike)
5254        (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
5255        (gnus-article-wash-status-entry 'emphasis emphasis)))))
5256
5257 (defun gnus-add-wash-type (type)
5258   "Add a washing of TYPE to the current status."
5259   (add-to-list 'gnus-article-wash-types type))
5260
5261 (defun gnus-delete-wash-type (type)
5262   "Add a washing of TYPE to the current status."
5263   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5264
5265 (defun gnus-add-image (category image)
5266   "Add IMAGE of CATEGORY to the list of displayed images."
5267   (let ((entry (assq category gnus-article-image-alist)))
5268     (unless entry
5269       (setq entry (list category))
5270       (push entry gnus-article-image-alist))
5271     (nconc entry (list image))))
5272
5273 (defun gnus-delete-images (category)
5274   "Delete all images in CATEGORY."
5275   (let ((entry (assq category gnus-article-image-alist)))
5276     (dolist (image (cdr entry))
5277       (gnus-remove-image image category))
5278     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5279     (gnus-delete-wash-type category)))
5280
5281 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5282
5283 (defun gnus-article-maybe-hide-headers ()
5284   "Hide unwanted headers if `gnus-have-all-headers' is nil.
5285 Provided for backwards compatibility."
5286   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5287                  (not (with-current-buffer gnus-summary-buffer
5288                         gnus-have-all-headers)))
5289              (not gnus-inhibit-hiding))
5290     (gnus-article-hide-headers)))
5291
5292 ;;; Article savers.
5293
5294 (defun gnus-output-to-file (file-name)
5295   "Append the current article to a file named FILE-NAME."
5296   (let ((artbuf (current-buffer)))
5297     (with-temp-buffer
5298       (insert-buffer-substring artbuf)
5299       ;; Append newline at end of the buffer as separator, and then
5300       ;; save it to file.
5301       (goto-char (point-max))
5302       (insert "\n")
5303       (let ((file-name-coding-system nnmail-pathname-coding-system))
5304         (write-region-as-binary (point-min) (point-max) file-name 'append))
5305       t)))
5306
5307 (defun gnus-narrow-to-page (&optional arg)
5308   "Narrow the article buffer to a page.
5309 If given a numerical ARG, move forward ARG pages."
5310   (interactive "P")
5311   (setq arg (if arg (prefix-numeric-value arg) 0))
5312   (save-excursion
5313     (set-buffer gnus-article-buffer)
5314     (goto-char (point-min))
5315     (widen)
5316     ;; Remove any old next/prev buttons.
5317     (when (gnus-visual-p 'page-marker)
5318       (let ((inhibit-read-only t))
5319         (gnus-remove-text-with-property 'gnus-prev)
5320         (gnus-remove-text-with-property 'gnus-next)))
5321     (if
5322         (cond ((< arg 0)
5323                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5324               ((> arg 0)
5325                (re-search-forward page-delimiter nil 'move arg)))
5326         (goto-char (match-end 0))
5327       (save-excursion
5328         (goto-char (point-min))
5329         (setq gnus-page-broken
5330               (and (re-search-forward page-delimiter nil t) t))))
5331     (when gnus-page-broken
5332       (narrow-to-region
5333        (point)
5334        (if (re-search-forward page-delimiter nil 'move)
5335            (match-beginning 0)
5336          (point)))
5337       (when (and (gnus-visual-p 'page-marker)
5338                  (> (point-min) (save-restriction (widen) (point-min))))
5339         (save-excursion
5340           (goto-char (point-min))
5341           (gnus-insert-prev-page-button)))
5342       (when (and (gnus-visual-p 'page-marker)
5343                  (< (+ (point-max) 2) (buffer-size)))
5344         (save-excursion
5345           (goto-char (point-max))
5346           (gnus-insert-next-page-button))))))
5347
5348 ;; Article mode commands
5349
5350 (defun gnus-article-goto-next-page ()
5351   "Show the next page of the article."
5352   (interactive)
5353   (when (gnus-article-next-page)
5354     (goto-char (point-min))
5355     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5356
5357
5358 (defun gnus-article-goto-prev-page ()
5359   "Show the previous page of the article."
5360   (interactive)
5361   (if (bobp)
5362       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5363     (gnus-article-prev-page nil)))
5364
5365 ;; This is cleaner but currently breaks `gnus-pick-mode':
5366 ;;
5367 ;; (defun gnus-article-goto-next-page ()
5368 ;;   "Show the next page of the article."
5369 ;;   (interactive)
5370 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
5371 ;;     (gnus-summary-next-page)))
5372 ;;
5373 ;; (defun gnus-article-goto-prev-page ()
5374 ;;   "Show the next page of the article."
5375 ;;   (interactive)
5376 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
5377 ;;     (gnus-summary-prev-page)))
5378
5379 (defun gnus-article-next-page (&optional lines)
5380   "Show the next page of the current article.
5381 If end of article, return non-nil.  Otherwise return nil.
5382 Argument LINES specifies lines to be scrolled up."
5383   (interactive "p")
5384   (move-to-window-line -1)
5385   (if (save-excursion
5386         (end-of-line)
5387         (and (pos-visible-in-window-p)  ;Not continuation line.
5388              (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5389       ;; Nothing in this page.
5390       (if (or (not gnus-page-broken)
5391               (save-excursion
5392                 (save-restriction
5393                   (widen)
5394                   (forward-line)
5395                   (eobp)))) ;Real end-of-buffer?
5396           (progn
5397             (when gnus-article-over-scroll
5398               (gnus-article-next-page-1 lines))
5399             t)                  ;Nothing more.
5400         (gnus-narrow-to-page 1)         ;Go to next page.
5401         nil)
5402     ;; More in this page.
5403     (gnus-article-next-page-1 lines)
5404     nil))
5405
5406 (defun gnus-article-next-page-1 (lines)
5407   (let ((scroll-in-place nil))
5408     (condition-case ()
5409         (scroll-up lines)
5410       (end-of-buffer
5411        ;; Long lines may cause an end-of-buffer error.
5412        (goto-char (point-max)))))
5413   (move-to-window-line 0))
5414
5415 (defun gnus-article-prev-page (&optional lines)
5416   "Show previous page of current article.
5417 Argument LINES specifies lines to be scrolled down."
5418   (interactive "p")
5419   (move-to-window-line 0)
5420   (if (and gnus-page-broken
5421            (bobp)
5422            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5423       (progn
5424         (gnus-narrow-to-page -1)        ;Go to previous page.
5425         (goto-char (point-max))
5426         (recenter -1))
5427     (let ((scroll-in-place nil))
5428       (prog1
5429           (condition-case ()
5430               (scroll-down lines)
5431             (beginning-of-buffer
5432              (goto-char (point-min))))
5433         (move-to-window-line 0)))))
5434
5435 (defun gnus-article-only-boring-p ()
5436   "Decide whether there is only boring text remaining in the article.
5437 Something \"interesting\" is a word of at least two letters that does
5438 not have a face in `gnus-article-boring-faces'."
5439   (when (and gnus-article-skip-boring
5440              (boundp 'gnus-article-boring-faces)
5441              (symbol-value 'gnus-article-boring-faces))
5442     (save-excursion
5443       (catch 'only-boring
5444         (while (re-search-forward "\\b\\w\\w" nil t)
5445           (forward-char -1)
5446           (when (not (gnus-intersection
5447                       (gnus-faces-at (point))
5448                       (symbol-value 'gnus-article-boring-faces)))
5449             (throw 'only-boring nil)))
5450         (throw 'only-boring t)))))
5451
5452 (defun gnus-article-refer-article ()
5453   "Read article specified by message-id around point."
5454   (interactive)
5455   (save-excursion
5456     (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5457     (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5458     (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5459         (let ((msg-id (concat "<" (match-string 0) ">")))
5460           (set-buffer gnus-summary-buffer)
5461           (gnus-summary-refer-article msg-id))
5462       (error "No references around point"))))
5463
5464 (defun gnus-article-show-summary ()
5465   "Reconfigure windows to show summary buffer."
5466   (interactive)
5467   (if (not (gnus-buffer-live-p gnus-summary-buffer))
5468       (error "There is no summary buffer for this article buffer")
5469     (gnus-article-set-globals)
5470     (gnus-configure-windows 'article)
5471     (gnus-summary-goto-subject gnus-current-article)
5472     (gnus-summary-position-point)))
5473
5474 (defun gnus-article-describe-briefly ()
5475   "Describe article mode commands briefly."
5476   (interactive)
5477   (gnus-message 6 (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")))
5478
5479 (defun gnus-article-summary-command ()
5480   "Execute the last keystroke in the summary buffer."
5481   (interactive)
5482   (let ((obuf (current-buffer))
5483         (owin (current-window-configuration))
5484         func)
5485     (switch-to-buffer gnus-article-current-summary 'norecord)
5486     (setq func (lookup-key (current-local-map) (this-command-keys)))
5487     (call-interactively func)
5488     (set-buffer obuf)
5489     (set-window-configuration owin)
5490     (set-window-point (get-buffer-window (current-buffer)) (point))))
5491
5492 (defun gnus-article-summary-command-nosave ()
5493   "Execute the last keystroke in the summary buffer."
5494   (interactive)
5495   (let (func)
5496     (pop-to-buffer gnus-article-current-summary 'norecord)
5497     (setq func (lookup-key (current-local-map) (this-command-keys)))
5498     (call-interactively func)))
5499
5500 (defun gnus-article-check-buffer ()
5501   "Beep if not in an article buffer."
5502   (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5503     (error "Command invoked outside of a Gnus article buffer")))
5504
5505 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5506   "Read a summary buffer key sequence and execute it from the article buffer."
5507   (interactive "P")
5508   (gnus-article-check-buffer)
5509   (let ((nosaves
5510          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
5511            "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5512            "=" "^" "\M-^" "|"))
5513         (nosave-but-article
5514          '("A\r"))
5515         (nosave-in-article
5516          '("\C-d"))
5517         (up-to-top
5518          '("n" "Gn" "p" "Gp"))
5519         keys new-sum-point)
5520     (save-excursion
5521       (set-buffer gnus-article-current-summary)
5522       (let (gnus-pick-mode)
5523         (push (or key last-command-event) unread-command-events)
5524         (setq keys (static-if (featurep 'xemacs)
5525                        (events-to-keys (read-key-sequence nil))
5526                      (read-key-sequence nil)))))
5527     (message "")
5528
5529     (if (or (member keys nosaves)
5530             (member keys nosave-but-article)
5531             (member keys nosave-in-article))
5532         (let (func)
5533           (save-window-excursion
5534             (pop-to-buffer gnus-article-current-summary 'norecord)
5535             ;; We disable the pick minor mode commands.
5536             (let (gnus-pick-mode)
5537               (setq func (lookup-key (current-local-map) keys))))
5538           (if (or (not func)
5539                   (numberp func))
5540               (ding)
5541             (unless (member keys nosave-in-article)
5542               (set-buffer gnus-article-current-summary))
5543             (call-interactively func)
5544             (setq new-sum-point (point)))
5545           (when (member keys nosave-but-article)
5546             (pop-to-buffer gnus-article-buffer 'norecord)))
5547       ;; These commands should restore window configuration.
5548       (let ((obuf (current-buffer))
5549             (owin (current-window-configuration))
5550             (opoint (point))
5551             win func in-buffer selected new-sum-start new-sum-hscroll)
5552         (cond (not-restore-window
5553                (pop-to-buffer gnus-article-current-summary 'norecord))
5554               ((setq win (get-buffer-window gnus-article-current-summary))
5555                (select-window win))
5556               (t
5557                (switch-to-buffer gnus-article-current-summary 'norecord)))
5558         (setq in-buffer (current-buffer))
5559         ;; We disable the pick minor mode commands.
5560         (if (and (setq func (let (gnus-pick-mode)
5561                               (lookup-key (current-local-map) keys)))
5562                  (functionp func))
5563             (progn
5564               (call-interactively func)
5565               (when (eq win (selected-window))
5566                 (setq new-sum-point (point)
5567                       new-sum-start (window-start win)
5568                       new-sum-hscroll (window-hscroll win))
5569               (when (eq in-buffer (current-buffer))
5570                 (setq selected (gnus-summary-select-article))
5571                 (set-buffer obuf)
5572                 (unless not-restore-window
5573                   (set-window-configuration owin))
5574                 (when (eq selected 'old)
5575                   (article-goto-body)
5576                   (set-window-start (get-buffer-window (current-buffer))
5577                                     1)
5578                   (set-window-point (get-buffer-window (current-buffer))
5579                                     (point)))
5580                 (when (and (not not-restore-window)
5581                            new-sum-point)
5582                   (set-window-point win new-sum-point)
5583                   (set-window-start win new-sum-start)
5584                   (set-window-hscroll win new-sum-hscroll)))))
5585           (set-window-configuration owin)
5586           (ding))))))
5587
5588 (defun gnus-article-describe-key (key)
5589   "Display documentation of the function invoked by KEY.  KEY is a string."
5590   (interactive "kDescribe key: ")
5591   (gnus-article-check-buffer)
5592   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5593       (save-excursion
5594         (set-buffer gnus-article-current-summary)
5595         (let (gnus-pick-mode)
5596           (if (featurep 'xemacs)
5597               (progn
5598                 (push (elt key 0) unread-command-events)
5599                 (setq key (events-to-keys
5600                            (read-key-sequence "Describe key: "))))
5601             (setq unread-command-events
5602                   (mapcar
5603                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5604                    key))
5605             (setq key (read-key-sequence "Describe key: "))))
5606         (describe-key key))
5607     (describe-key key)))
5608
5609 (defun gnus-article-describe-key-briefly (key &optional insert)
5610   "Display documentation of the function invoked by KEY.  KEY is a string."
5611   (interactive "kDescribe key: \nP")
5612   (gnus-article-check-buffer)
5613   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5614       (save-excursion
5615         (set-buffer gnus-article-current-summary)
5616         (let (gnus-pick-mode)
5617           (if (featurep 'xemacs)
5618               (progn
5619                 (push (elt key 0) unread-command-events)
5620                 (setq key (events-to-keys
5621                            (read-key-sequence "Describe key: "))))
5622             (setq unread-command-events
5623                   (mapcar
5624                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5625                    key))
5626             (setq key (read-key-sequence "Describe key: "))))
5627         (describe-key-briefly key insert))
5628     (describe-key-briefly key insert)))
5629
5630 (defun gnus-article-reply-with-original (&optional wide)
5631   "Start composing a reply mail to the current message.
5632 The text in the region will be yanked.  If the region isn't active,
5633 the entire article will be yanked."
5634   (interactive "P")
5635   (let ((article (cdr gnus-article-current))
5636         contents)
5637     (if (not (gnus-region-active-p))
5638         (with-current-buffer gnus-summary-buffer
5639           (gnus-summary-reply (list (list article)) wide))
5640       (setq contents (buffer-substring (point) (mark t)))
5641       ;; Deactivate active regions.
5642       (when (and (boundp 'transient-mark-mode)
5643                  transient-mark-mode)
5644         (setq mark-active nil))
5645       (with-current-buffer gnus-summary-buffer
5646         (gnus-summary-reply
5647          (list (list article contents)) wide)))))
5648
5649 (defun gnus-article-followup-with-original ()
5650   "Compose a followup to the current article.
5651 The text in the region will be yanked.  If the region isn't active,
5652 the entire article will be yanked."
5653   (interactive)
5654   (let ((article (cdr gnus-article-current))
5655         contents)
5656       (if (not (gnus-region-active-p))
5657           (with-current-buffer gnus-summary-buffer
5658             (gnus-summary-followup (list (list article))))
5659         (setq contents (buffer-substring (point) (mark t)))
5660         ;; Deactivate active regions.
5661         (when (and (boundp 'transient-mark-mode)
5662                    transient-mark-mode)
5663           (setq mark-active nil))
5664         (with-current-buffer gnus-summary-buffer
5665           (gnus-summary-followup
5666            (list (list article contents)))))))
5667
5668 (defun gnus-article-hide (&optional arg force)
5669   "Hide all the gruft in the current article.
5670 This means that signatures, cited text and (some) headers will be
5671 hidden.
5672 If given a prefix, show the hidden text instead."
5673   (interactive (append (gnus-article-hidden-arg) (list 'force)))
5674   (gnus-article-hide-headers arg)
5675   (gnus-article-hide-list-identifiers arg)
5676   (gnus-article-hide-citation-maybe arg force)
5677   (gnus-article-hide-signature arg))
5678
5679 (defun gnus-article-maybe-highlight ()
5680   "Do some article highlighting if article highlighting is requested."
5681   (when (gnus-visual-p 'article-highlight 'highlight)
5682     (gnus-article-highlight-some)))
5683
5684 (defun gnus-check-group-server ()
5685   ;; Make sure the connection to the server is alive.
5686   (unless (gnus-server-opened
5687            (gnus-find-method-for-group gnus-newsgroup-name))
5688     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5689     (gnus-request-group gnus-newsgroup-name t)))
5690
5691 (eval-when-compile
5692   (autoload 'nneething-get-file-name "nneething"))
5693
5694 (defun gnus-request-article-this-buffer (article group)
5695   "Get an article and insert it into this buffer."
5696   (let (do-update-line sparse-header)
5697     (prog1
5698         (save-excursion
5699           (erase-buffer)
5700           (gnus-kill-all-overlays)
5701           (setq group (or group gnus-newsgroup-name))
5702
5703           ;; Using `gnus-request-article' directly will insert the article into
5704           ;; `nntp-server-buffer' - so we'll save some time by not having to
5705           ;; copy it from the server buffer into the article buffer.
5706
5707           ;; We only request an article by message-id when we do not have the
5708           ;; headers for it, so we'll have to get those.
5709           (when (stringp article)
5710             (gnus-read-header article))
5711
5712           ;; If the article number is negative, that means that this article
5713           ;; doesn't belong in this newsgroup (possibly), so we find its
5714           ;; message-id and request it by id instead of number.
5715           (when (and (numberp article)
5716                      gnus-summary-buffer
5717                      (get-buffer gnus-summary-buffer)
5718                      (gnus-buffer-exists-p gnus-summary-buffer))
5719             (save-excursion
5720               (set-buffer gnus-summary-buffer)
5721               (let ((header (gnus-summary-article-header article)))
5722                 (when (< article 0)
5723                   (cond
5724                    ((memq article gnus-newsgroup-sparse)
5725                     ;; This is a sparse gap article.
5726                     (setq do-update-line article)
5727                     (setq article (mail-header-id header))
5728                     (setq sparse-header (gnus-read-header article))
5729                     (setq gnus-newsgroup-sparse
5730                           (delq article gnus-newsgroup-sparse)))
5731                    ((vectorp header)
5732                     ;; It's a real article.
5733                     (setq article (mail-header-id header)))
5734                    (t
5735                     ;; It is an extracted pseudo-article.
5736                     (setq article 'pseudo)
5737                     (gnus-request-pseudo-article header))))
5738
5739                 (let ((method (gnus-find-method-for-group
5740                                gnus-newsgroup-name)))
5741                   (when (and (eq (car method) 'nneething)
5742                              (vectorp header))
5743                     (let ((dir (nneething-get-file-name
5744                                 (mail-header-id header))))
5745                       (when (and (stringp dir)
5746                                  (file-directory-p dir))
5747                         (setq article 'nneething)
5748                         (gnus-group-enter-directory dir))))))))
5749
5750           (cond
5751            ;; Refuse to select canceled articles.
5752            ((and (numberp article)
5753                  gnus-summary-buffer
5754                  (get-buffer gnus-summary-buffer)
5755                  (gnus-buffer-exists-p gnus-summary-buffer)
5756                  (eq (cdr (with-current-buffer gnus-summary-buffer
5757                             (assq article gnus-newsgroup-reads)))
5758                      gnus-canceled-mark))
5759             nil)
5760            ;; We first check `gnus-original-article-buffer'.
5761            ((and (get-buffer gnus-original-article-buffer)
5762                  (numberp article)
5763                  (with-current-buffer gnus-original-article-buffer
5764                    (and (equal (car gnus-original-article) group)
5765                         (eq (cdr gnus-original-article) article))))
5766             (insert-buffer-substring gnus-original-article-buffer)
5767             'article)
5768            ;; Check the backlog.
5769            ((and gnus-keep-backlog
5770                  (gnus-backlog-request-article group article (current-buffer)))
5771             'article)
5772            ;; Check asynchronous pre-fetch.
5773            ((gnus-async-request-fetched-article group article (current-buffer))
5774             (gnus-async-prefetch-next group article gnus-summary-buffer)
5775             (when (and (numberp article) gnus-keep-backlog)
5776               (gnus-backlog-enter-article group article (current-buffer)))
5777             'article)
5778            ;; Check the cache.
5779            ((and gnus-use-cache
5780                  (numberp article)
5781                  (gnus-cache-request-article article group))
5782             'article)
5783            ;; Check the agent cache.
5784            ((gnus-agent-request-article article group)
5785             'article)
5786            ;; Get the article and put into the article buffer.
5787            ((or (stringp article)
5788                 (numberp article))
5789             (let ((gnus-override-method gnus-override-method)
5790                   (methods (and (stringp article)
5791                                 gnus-refer-article-method))
5792                   (backend (car (gnus-find-method-for-group
5793                                  gnus-newsgroup-name)))
5794                   result
5795                   (inhibit-read-only t))
5796               (if (or (not (listp methods))
5797                       (and (symbolp (car methods))
5798                            (assq (car methods) nnoo-definition-alist)))
5799                   (setq methods (list methods)))
5800               (when (and (null gnus-override-method)
5801                          methods)
5802                 (setq gnus-override-method (pop methods)))
5803               (while (not result)
5804                 (when (eq gnus-override-method 'current)
5805                   (setq gnus-override-method
5806                         (with-current-buffer gnus-summary-buffer
5807                           gnus-current-select-method)))
5808                 (erase-buffer)
5809                 (gnus-kill-all-overlays)
5810                 (let ((gnus-newsgroup-name group))
5811                   (gnus-check-group-server))
5812                 (cond
5813                  ((gnus-request-article article group (current-buffer))
5814                   (when (numberp article)
5815                     (gnus-async-prefetch-next group article
5816                                               gnus-summary-buffer)
5817                     (when gnus-keep-backlog
5818                       (gnus-backlog-enter-article
5819                        group article (current-buffer))))
5820                   (setq result 'article))
5821                  (methods
5822                   (setq gnus-override-method (pop methods)))
5823                  ((not (string-match "^400 "
5824                                      (nnheader-get-report backend)))
5825                   ;; If we get 400 server disconnect, reconnect and
5826                   ;; retry; otherwise, assume the article has expired.
5827                   (setq result 'done))))
5828               (and (eq result 'article) 'article)))
5829            ;; It was a pseudo.
5830            (t article)))
5831
5832       ;; Associate this article with the current summary buffer.
5833       (setq gnus-article-current-summary gnus-summary-buffer)
5834
5835       ;; Take the article from the original article buffer
5836       ;; and place it in the buffer it's supposed to be in.
5837       (when (and (get-buffer gnus-article-buffer)
5838                  (equal (buffer-name (current-buffer))
5839                         (buffer-name (get-buffer gnus-article-buffer))))
5840         (save-excursion
5841           (if (get-buffer gnus-original-article-buffer)
5842               (set-buffer gnus-original-article-buffer)
5843             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5844             (buffer-disable-undo)
5845             (setq major-mode 'gnus-original-article-mode)
5846             (setq buffer-read-only t))
5847           (let ((inhibit-read-only t))
5848             (erase-buffer)
5849             (insert-buffer-substring gnus-article-buffer))
5850           (setq gnus-original-article (cons group article)))
5851
5852         ;; Decode charsets.
5853         (run-hooks 'gnus-article-decode-hook)
5854         ;; Mark article as decoded or not.
5855         (setq gnus-article-decoded-p gnus-article-decode-hook))
5856
5857       ;; Update sparse articles.
5858       (when (and do-update-line
5859                  (or (numberp article)
5860                      (stringp article)))
5861         (let ((buf (current-buffer)))
5862           (set-buffer gnus-summary-buffer)
5863           (gnus-summary-update-article do-update-line sparse-header)
5864           (gnus-summary-goto-subject do-update-line nil t)
5865           (set-window-point (gnus-get-buffer-window (current-buffer) t)
5866                             (point))
5867           (set-buffer buf))))))
5868
5869 ;;;
5870 ;;; Article editing
5871 ;;;
5872
5873 (defcustom gnus-article-edit-mode-hook nil
5874   "Hook run in article edit mode buffers."
5875   :group 'gnus-article-various
5876   :type 'hook)
5877
5878 (defcustom gnus-article-edit-article-setup-function
5879   'gnus-article-mime-edit-article-setup
5880   "Function called to setup an editing article buffer."
5881   :group 'gnus-article-various
5882   :type 'function)
5883
5884 (defvar gnus-article-edit-done-function nil)
5885
5886 (defvar gnus-article-edit-mode-map nil)
5887
5888 ;; Should we be using derived.el for this?
5889 (unless gnus-article-edit-mode-map
5890   (setq gnus-article-edit-mode-map (make-keymap))
5891   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5892
5893   (gnus-define-keys gnus-article-edit-mode-map
5894     "\C-c?"    describe-mode
5895     "\C-c\C-c" gnus-article-edit-done
5896     "\C-c\C-k" gnus-article-edit-exit
5897     "\C-c\C-f\C-t" message-goto-to
5898     "\C-c\C-f\C-o" message-goto-from
5899     "\C-c\C-f\C-b" message-goto-bcc
5900     ;;"\C-c\C-f\C-w" message-goto-fcc
5901     "\C-c\C-f\C-c" message-goto-cc
5902     "\C-c\C-f\C-s" message-goto-subject
5903     "\C-c\C-f\C-r" message-goto-reply-to
5904     "\C-c\C-f\C-n" message-goto-newsgroups
5905     "\C-c\C-f\C-d" message-goto-distribution
5906     "\C-c\C-f\C-f" message-goto-followup-to
5907     "\C-c\C-f\C-m" message-goto-mail-followup-to
5908     "\C-c\C-f\C-k" message-goto-keywords
5909     "\C-c\C-f\C-u" message-goto-summary
5910     "\C-c\C-f\C-i" message-insert-or-toggle-importance
5911     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5912     "\C-c\C-b" message-goto-body
5913     "\C-c\C-i" message-goto-signature
5914
5915     "\C-c\C-t" message-insert-to
5916     "\C-c\C-n" message-insert-newsgroups
5917     "\C-c\C-o" message-sort-headers
5918     "\C-c\C-e" message-elide-region
5919     "\C-c\C-v" message-delete-not-region
5920     "\C-c\C-z" message-kill-to-signature
5921     "\M-\r" message-newline-and-reformat
5922     "\C-c\C-a" mml-attach-file
5923     "\C-a" message-beginning-of-line
5924     "\t" message-tab
5925     "\M-;" comment-region)
5926
5927   (gnus-define-keys (gnus-article-edit-wash-map
5928                      "\C-c\C-w" gnus-article-edit-mode-map)
5929     "f" gnus-article-edit-full-stops))
5930
5931 (easy-menu-define
5932   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5933   '("Field"
5934     ["Fetch To" message-insert-to t]
5935     ["Fetch Newsgroups" message-insert-newsgroups t]
5936     "----"
5937     ["To" message-goto-to t]
5938     ["From" message-goto-from t]
5939     ["Subject" message-goto-subject t]
5940     ["Cc" message-goto-cc t]
5941     ["Reply-To" message-goto-reply-to t]
5942     ["Summary" message-goto-summary t]
5943     ["Keywords" message-goto-keywords t]
5944     ["Newsgroups" message-goto-newsgroups t]
5945     ["Followup-To" message-goto-followup-to t]
5946     ["Mail-Followup-To" message-goto-mail-followup-to t]
5947     ["Distribution" message-goto-distribution t]
5948     ["Body" message-goto-body t]
5949     ["Signature" message-goto-signature t]))
5950
5951 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
5952   "Major mode for editing articles.
5953 This is an extended text-mode.
5954
5955 \\{gnus-article-edit-mode-map}"
5956   (make-local-variable 'gnus-article-edit-done-function)
5957   (make-local-variable 'gnus-prev-winconf)
5958   (set (make-local-variable 'font-lock-defaults)
5959        '(message-font-lock-keywords t))
5960   (set (make-local-variable 'mail-header-separator) "")
5961   (set (make-local-variable 'gnus-article-edit-mode) t)
5962   (easy-menu-add message-mode-field-menu message-mode-map)
5963   (setq buffer-read-only nil)
5964   (buffer-enable-undo)
5965   (widen))
5966
5967 (defun gnus-article-edit (&optional force)
5968   "Edit the current article.
5969 This will have permanent effect only in mail groups.
5970 If FORCE is non-nil, allow editing of articles even in read-only
5971 groups."
5972   (interactive "P")
5973   (when (and (not force)
5974              (gnus-group-read-only-p))
5975     (error "The current newsgroup does not support article editing"))
5976   (gnus-article-date-original)
5977   (gnus-article-edit-article
5978    'ignore
5979    `(lambda (no-highlight)
5980       'ignore
5981       (gnus-summary-edit-article-done
5982        ,(or (mail-header-references gnus-current-headers) "")
5983        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5984
5985 (defun gnus-article-edit-article (start-func exit-func)
5986   "Start editing the contents of the current article buffer."
5987   (let ((winconf (current-window-configuration)))
5988     (set-buffer gnus-article-buffer)
5989     (gnus-article-edit-mode)
5990     (funcall start-func)
5991     (set-buffer-modified-p nil)
5992     (gnus-configure-windows 'edit-article)
5993     (setq gnus-article-edit-done-function exit-func)
5994     (setq gnus-prev-winconf winconf)
5995     (when gnus-article-edit-article-setup-function
5996       (funcall gnus-article-edit-article-setup-function))
5997     (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
5998
5999 (defun gnus-article-edit-done (&optional arg)
6000   "Update the article edits and exit."
6001   (interactive "P")
6002   (let ((func gnus-article-edit-done-function)
6003         (buf (current-buffer))
6004         (start (window-start))
6005         (p (point))
6006         (winconf gnus-prev-winconf))
6007     (remove-hook 'gnus-article-mode-hook
6008                  'gnus-article-mime-edit-article-unwind)
6009     (widen) ;; Widen it in case that users narrowed the buffer.
6010     (funcall func arg)
6011     (set-buffer buf)
6012     ;; The cache and backlog have to be flushed somewhat.
6013     (when gnus-keep-backlog
6014       (gnus-backlog-remove-article
6015        (car gnus-article-current) (cdr gnus-article-current)))
6016     ;; Flush original article as well.
6017     (save-excursion
6018       (when (get-buffer gnus-original-article-buffer)
6019         (set-buffer gnus-original-article-buffer)
6020         (setq gnus-original-article nil)))
6021     (when gnus-use-cache
6022       (gnus-cache-update-article
6023        (car gnus-article-current) (cdr gnus-article-current)))
6024     ;; We remove all text props from the article buffer.
6025     (kill-all-local-variables)
6026     (set-text-properties (point-min) (point-max) nil)
6027     (gnus-article-mode)
6028     (set-window-configuration winconf)
6029     (set-buffer buf)
6030     (set-window-start (get-buffer-window buf) start)
6031     (set-window-point (get-buffer-window buf) (point)))
6032   (gnus-summary-show-article))
6033
6034 (defun gnus-article-edit-exit ()
6035   "Exit the article editing without updating."
6036   (interactive)
6037   (when (or (not (buffer-modified-p))
6038             (yes-or-no-p "Article modified; kill anyway? "))
6039     (let ((curbuf (current-buffer))
6040           (p (point))
6041           (window-start (window-start)))
6042       (erase-buffer)
6043       (if (gnus-buffer-live-p gnus-original-article-buffer)
6044           (insert-buffer-substring gnus-original-article-buffer))
6045       (let ((winconf gnus-prev-winconf))
6046         (kill-all-local-variables)
6047         (gnus-article-mode)
6048         (set-window-configuration winconf)
6049         ;; Tippy-toe some to make sure that point remains where it was.
6050         (save-current-buffer
6051           (set-buffer curbuf)
6052           (set-window-start (get-buffer-window (current-buffer)) window-start)
6053           (goto-char p))))
6054     (gnus-summary-show-article)))
6055
6056 (defun gnus-article-edit-full-stops ()
6057   "Interactively repair spacing at end of sentences."
6058   (interactive)
6059   (save-excursion
6060     (goto-char (point-min))
6061     (search-forward-regexp "^$" nil t)
6062     (let ((case-fold-search nil))
6063       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6064
6065 ;;;
6066 ;;; Article editing with MIME-Edit
6067 ;;;
6068
6069 (defcustom gnus-article-mime-edit-article-setup-hook nil
6070   "Hook run after setting up a MIME editing article buffer."
6071   :group 'gnus-article-various
6072   :type 'hook)
6073
6074 (defun gnus-article-mime-edit-article-unwind ()
6075   "Unwind `gnus-article-buffer' if article editing was given up."
6076   (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6077   (when (featurep 'font-lock)
6078     (setq font-lock-defaults nil)
6079     (font-lock-mode -1))
6080   (when mime-edit-mode-flag
6081     (mime-edit-exit 'nomime 'no-error)
6082     (message "")))
6083
6084 (defun gnus-article-mime-edit-article-setup ()
6085   "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
6086 after replacing with the original article."
6087   (setq gnus-show-mime t)
6088   (setq gnus-article-edit-done-function
6089         `(lambda (&rest args)
6090            (when mime-edit-mode-flag
6091              (let (mime-edit-insert-user-agent-field)
6092                (mime-edit-exit))
6093              (message ""))
6094            (goto-char (point-min))
6095            (let (case-fold-search)
6096              (when (re-search-forward
6097                     (format "^%s$" (regexp-quote mail-header-separator))
6098                     nil t)
6099                (replace-match "")))
6100            (apply ,gnus-article-edit-done-function args)
6101            (insert
6102             (prog1
6103                 (buffer-substring-no-properties (point-min) (point-max))
6104               (set-buffer (get-buffer-create gnus-original-article-buffer))
6105               (erase-buffer)))
6106            (setq gnus-current-headers (gnus-article-make-full-mail-header))
6107            (set-buffer gnus-article-buffer)
6108            (gnus-article-prepare-display)))
6109   (substitute-key-definition 'gnus-article-edit-done
6110                              'gnus-article-mime-edit-done
6111                              gnus-article-edit-mode-map)
6112   (substitute-key-definition 'gnus-article-edit-exit
6113                              'gnus-article-mime-edit-exit
6114                              gnus-article-edit-mode-map)
6115   (erase-buffer)
6116   (insert-buffer-substring gnus-original-article-buffer)
6117   (unless (member (with-current-buffer gnus-summary-buffer
6118                     gnus-newsgroup-name)
6119                   '("nndraft:delayed" "nndraft:drafts"))
6120     (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
6121       (fset 'mime-edit-decode-single-part-in-buffer
6122             (lambda (&rest args)
6123               (if (let ((content-type (car args)))
6124                     (and (eq 'message (mime-content-type-primary-type
6125                                        content-type))
6126                          (eq 'rfc822 (mime-content-type-subtype
6127                                       content-type))))
6128                   (setcar (cdr args) 'not-decode-text))
6129               (apply ofn args)))
6130       (unwind-protect
6131           (mime-edit-again)
6132         (fset 'mime-edit-decode-single-part-in-buffer ofn))))
6133   (when (featurep 'font-lock)
6134     (set (make-local-variable 'font-lock-defaults)
6135          '(message-font-lock-keywords t))
6136     (font-lock-set-defaults)
6137     (turn-on-font-lock))
6138   (set-buffer-modified-p nil)
6139   (delete-other-windows)
6140   (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6141   (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
6142
6143 (defun gnus-article-mime-edit-done (&optional arg)
6144   "Update the article MIME edits and exit."
6145   (interactive "P")
6146   (when (featurep 'font-lock)
6147     (setq font-lock-defaults nil)
6148     (font-lock-mode -1))
6149   (let ((inhibit-read-only t))
6150     (gnus-article-edit-done arg)))
6151
6152 (defun gnus-article-mime-edit-exit ()
6153   "Exit the article MIME editing without updating."
6154   (interactive)
6155   (when (or (not (buffer-modified-p))
6156             (yes-or-no-p "Article modified; kill anyway? "))
6157     (when (featurep 'font-lock)
6158       (setq font-lock-defaults nil)
6159       (font-lock-mode -1))
6160     (when mime-edit-mode-flag
6161       (let (mime-edit-insert-user-agent-field)
6162         (mime-edit-exit))
6163       (message ""))
6164     (goto-char (point-min))
6165     (let (case-fold-search)
6166       (when (re-search-forward
6167              (format "^%s$" (regexp-quote mail-header-separator)) nil t)
6168         (replace-match "")))
6169     (let ((winconf gnus-prev-winconf))
6170       (insert (prog1
6171                   (buffer-substring-no-properties (point-min) (point-max))
6172                 (set-buffer (get-buffer-create gnus-original-article-buffer))
6173                 (erase-buffer)))
6174       (setq gnus-current-headers (gnus-article-make-full-mail-header))
6175       (set-buffer gnus-article-buffer)
6176       (gnus-article-prepare-display)
6177       (set-window-configuration winconf))))
6178
6179 ;;;
6180 ;;; Article highlights
6181 ;;;
6182
6183 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6184
6185 ;;; Internal Variables:
6186
6187 (defcustom gnus-button-url-regexp
6188   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6189       "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)"
6190     "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)\\)")
6191   "Regular expression that matches URLs."
6192   :group 'gnus-article-buttons
6193   :type 'regexp)
6194
6195 (defcustom gnus-button-valid-fqdn-regexp
6196   message-valid-fqdn-regexp
6197   "Regular expression that matches a valid FQDN."
6198   :version "21.4"
6199   :group 'gnus-article-buttons
6200   :type 'regexp)
6201
6202 (defcustom gnus-button-man-handler 'manual-entry
6203   "Function to use for displaying man pages.
6204 The function must take at least one argument with a string naming the
6205 man page."
6206   :version "21.4"
6207   :type '(choice (function-item :tag "Man" manual-entry)
6208                  (function-item :tag "Woman" woman)
6209                  (function :tag "Other"))
6210   :group 'gnus-article-buttons)
6211
6212 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6213   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6214 If the default site is too slow, try to find a CTAN mirror, see
6215 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
6216 the variable `gnus-button-handle-ctan'."
6217   :version "21.4"
6218   :group 'gnus-article-buttons
6219   :link '(custom-manual "(gnus)Group Parameters")
6220   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6221                  (const "http://tug.ctan.org/tex-archive/")
6222                  (const "http://www.dante.de/CTAN/")
6223                  (string :tag "Other")))
6224
6225 (defcustom gnus-button-ctan-handler 'browse-url
6226   "Function to use for displaying CTAN links.
6227 The function must take one argument, the string naming the URL."
6228   :version "21.4"
6229   :type '(choice (function-item :tag "Browse Url" browse-url)
6230                  (function :tag "Other"))
6231   :group 'gnus-article-buttons)
6232
6233 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6234   "Bogus strings removed from CTAN URLs."
6235   :version "21.4"
6236   :group 'gnus-article-buttons
6237   :type '(choice (const "^/?tex-archive/\\|/")
6238                  (regexp :tag "Other")))
6239
6240 (defcustom gnus-button-ctan-directory-regexp
6241   (concat
6242    "\\(?:"
6243    "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
6244    "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
6245    "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
6246    "\\)")
6247   "Regular expression for ctan directories.
6248 It should match all directories in the top level of `gnus-ctan-url'."
6249   :version "21.4"
6250   :group 'gnus-article-buttons
6251   :type 'regexp)
6252
6253 (defcustom gnus-button-mid-or-mail-regexp
6254   (concat "\\b\\(<?[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*@"
6255           ;; Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6256           gnus-button-valid-fqdn-regexp
6257           ">?\\)\\b")
6258   "Regular expression that matches a message ID or a mail address."
6259   :version "21.4"
6260   :group 'gnus-article-buttons
6261   :type 'regexp)
6262
6263 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6264   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6265 Strings like this can be either a message ID or a mail address.  If it is one
6266 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6267 message ID or a mail address, respectively.  If this variable is set to the
6268 symbol `ask', always query the user what do do.  If it is a function, this
6269 function will be called with the string as it's only argument.  The function
6270 must return `mid', `mail', `invalid' or `ask'."
6271   :version "21.4"
6272   :group 'gnus-article-buttons
6273   :type '(choice (function-item :tag "Heuristic function"
6274                                 gnus-button-mid-or-mail-heuristic)
6275                  (const ask)
6276                  (const mid)
6277                  (const mail)))
6278
6279 (defcustom gnus-button-mid-or-mail-heuristic-alist
6280   '((-10.0 . ".+\\$.+@")
6281     (-10.0 . "#")
6282     (-10.0 . "\\*")
6283     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
6284     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6285     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6286     (-1.0  . "^[^a-z]+@")
6287     ;;
6288     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6289     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6290     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
6291     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6292     ;;
6293     (-2.0  . "^[0-9]")
6294     (-1.0  . "^[0-9][0-9]")
6295     ;;
6296     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6297     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6298     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6299     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6300     ;;
6301     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6302     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6303     ;;       "[0-9]{8,}.*\@"
6304     (-3.0
6305      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6306     ;; "[0-9]{12,}.*\@"
6307     ;; compensation for TDMA dated mail addresses:
6308     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6309     ;;
6310     (-20.0 . "\\.fsf@") ;; Gnus
6311     (-20.0 . "^slrn")
6312     (-20.0 . "^Pine")
6313     (-20.0 . "_-_") ;; Subject change in thread
6314     ;;
6315     (-20.0 . "\\.ln@") ;; leafnode
6316     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6317     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6318     ;;
6319     ;; (5.0 . "") ;; $local_part_len <= 7
6320     (10.0  . "^[^0-9]+@")
6321     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6322     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6323     (3.0   . "\@stud")
6324     ;;
6325     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
6326     ;;
6327     (0.5   . "^[A-Z][a-z]")
6328     (0.5   . "^[A-Z][a-z][a-z]")
6329     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6330     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6331   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6332
6333 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6334 address.  The REGEXP is processed with `case-fold-search' set to nil."
6335   :version "21.4"
6336   :group 'gnus-article-buttons
6337   :type '(repeat (cons (number :tag "Rate")
6338                        (regexp :tag "Regexp"))))
6339
6340 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6341   "Guess whether MID-OR-MAIL is a message ID or a mail address.
6342 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6343 address, `ask' if unsure and `invalid' if the string is invalid."
6344   (let ((case-fold-search nil)
6345         (list gnus-button-mid-or-mail-heuristic-alist)
6346         (result 0) rate regexp lpartlen elem)
6347     (setq lpartlen
6348           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6349     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6350     ;; Certain special cases...
6351     (when (string-match
6352            (concat
6353             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6354             "^[0-9]+\\.[0-9]+@compuserve\\|"
6355             "@public\\.gmane\\.org")
6356            mid-or-mail)
6357       (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6358       (setq result 'mail))
6359     (when (string-match "@.*@\\| " mid-or-mail)
6360       (gnus-message 8 "`%s' is invalid." mid-or-mail)
6361       (setq result 'invalid))
6362     ;; Nothing more to do, if result is not a number here...
6363     (when (numberp result)
6364       (while list
6365         (setq elem (car list)
6366               rate (car elem)
6367               regexp (cdr elem)
6368               list (cdr list))
6369         (when (string-match regexp mid-or-mail)
6370           (setq result (+ result rate))
6371           (gnus-message
6372            9 "`%s' matched `%s', rate `%s', result `%s'."
6373            mid-or-mail regexp rate result)))
6374       (when (<= lpartlen 7)
6375         (setq result (+ result 5.0))
6376         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6377                       mid-or-mail result))
6378       (when (>= lpartlen 12)
6379         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6380         (cond
6381          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6382           ;; Long local part should contain realname if e-mail address,
6383           ;; too many digits: message-id.
6384           ;; $score -= 5.0 + 0.1 * $local_part_len;
6385           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6386           (setq result (+ result rate))
6387           (gnus-message
6388            9 "Many digits in `%s', rate `%s', result `%s'."
6389            mid-or-mail rate result))
6390          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6391                         mid-or-mail)
6392           ;; Too few vowels [^aeiouy]{4,}.*\@
6393           (setq result (+ result -5.0))
6394           (gnus-message
6395            9 "Few vowels in `%s', rate `%s', result `%s'."
6396            mid-or-mail -5.0 result))
6397          (t
6398           (setq result (+ result 5.0))
6399           (gnus-message
6400            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6401     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6402     ;; Maybe we should make this a customizable alist: (condition . 'result)
6403     (cond
6404      ((symbolp result) result)
6405      ;; Now convert number into proper results:
6406      ((< result -10.0) 'mid)
6407      ((> result  10.0) 'mail)
6408      (t 'ask))))
6409
6410 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6411   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6412          (url-mid (concat "news" ":" mid-or-mail))
6413          (url-mailto (concat "mailto" ":" mid-or-mail)))
6414     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6415     (when (fboundp pref)
6416       (setq guessed
6417             ;; get rid of surrounding angles...
6418             (funcall pref
6419                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6420       (if (or (eq 'mid guessed) (eq 'mail guessed))
6421           (setq pref guessed)
6422         (setq pref 'ask)))
6423     (if (eq pref 'ask)
6424         (save-window-excursion
6425           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6426               (setq pref 'mail)
6427             (setq pref 'mid))))
6428     (cond ((eq pref 'mid)
6429            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6430            (gnus-button-handle-news url-mid))
6431           ((eq pref 'mail)
6432            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
6433            (gnus-url-mailto url-mailto))
6434           (t (gnus-message 3 "Invalid string.")))))
6435
6436 (defun gnus-button-handle-custom (url)
6437   "Follow a Custom URL."
6438   (customize-apropos (gnus-url-unhex-string url)))
6439
6440 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6441
6442 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6443 ;; stuff?
6444
6445 (defun gnus-button-handle-describe-function (url)
6446   "Call `describe-function' when pushing the corresponding URL button."
6447   (describe-function
6448    (intern
6449     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6450
6451 (defun gnus-button-handle-describe-variable (url)
6452   "Call `describe-variable' when pushing the corresponding URL button."
6453   (describe-variable
6454    (intern
6455     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6456
6457 (defun gnus-button-handle-symbol (url)
6458 "Display help on variable or function.
6459 Calls `describe-variable' or `describe-function'."
6460   (let ((sym (intern url)))
6461     (cond
6462      ((fboundp sym) (describe-function sym))
6463      ((boundp sym) (describe-variable sym))
6464      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6465
6466 (defun gnus-button-handle-describe-key (url)
6467   "Call `describe-key' when pushing the corresponding URL button."
6468   (let* ((key-string
6469           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6470          (keys (ignore-errors (eval `(kbd ,key-string)))))
6471     (if keys
6472         (describe-key keys)
6473       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6474
6475 (defun gnus-button-handle-apropos (url)
6476   "Call `apropos' when pushing the corresponding URL button."
6477   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6478
6479 (defun gnus-button-handle-apropos-command (url)
6480   "Call `apropos' when pushing the corresponding URL button."
6481   (apropos-command
6482    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6483
6484 (defun gnus-button-handle-apropos-variable (url)
6485   "Call `apropos' when pushing the corresponding URL button."
6486   (funcall
6487    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6488    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6489
6490 (defun gnus-button-handle-apropos-documentation (url)
6491   "Call `apropos' when pushing the corresponding URL button."
6492   (funcall
6493    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6494    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6495
6496 (defun gnus-button-handle-library (url)
6497   "Call `locate-library' when pushing the corresponding URL button."
6498   (gnus-message 9 "url=`%s'" url)
6499   (let* ((lib (locate-library url))
6500          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6501     (if (not lib)
6502         (gnus-message 1 "Cannot locale library `%s'." url)
6503       (find-file-read-only file))))
6504
6505 (defun gnus-button-handle-ctan (url)
6506   "Call `browse-url' when pushing a CTAN URL button."
6507   (funcall
6508    gnus-button-ctan-handler
6509    (concat
6510     gnus-ctan-url
6511     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6512
6513 (defcustom gnus-button-tex-level 5
6514   "*Integer that says how many TeX-related buttons Gnus will show.
6515 The higher the number, the more buttons will appear and the more false
6516 positives are possible.  Note that you can set this variable local to
6517 specific groups.  Setting it higher in TeX groups is probably a good idea.
6518 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6519 how to set variables in specific groups."
6520   :version "21.4"
6521   :group 'gnus-article-buttons
6522   :link '(custom-manual "(gnus)Group Parameters")
6523   :type 'integer)
6524
6525 (defcustom gnus-button-man-level 5
6526   "*Integer that says how many man-related buttons Gnus will show.
6527 The higher the number, the more buttons will appear and the more false
6528 positives are possible.  Note that you can set this variable local to
6529 specific groups.  Setting it higher in Unix groups is probably a good idea.
6530 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6531 how to set variables in specific groups."
6532   :version "21.4"
6533   :group 'gnus-article-buttons
6534   :link '(custom-manual "(gnus)Group Parameters")
6535   :type 'integer)
6536
6537 (defcustom gnus-button-emacs-level 5
6538   "*Integer that says how many emacs-related buttons Gnus will show.
6539 The higher the number, the more buttons will appear and the more false
6540 positives are possible.  Note that you can set this variable local to
6541 specific groups.  Setting it higher in Emacs or Gnus related groups is
6542 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
6543 `gnus-parameters' on how to set variables in specific groups."
6544   :version "21.4"
6545   :group 'gnus-article-buttons
6546   :link '(custom-manual "(gnus)Group Parameters")
6547   :type 'integer)
6548
6549 (defcustom gnus-button-message-level 5
6550   "*Integer that says how many buttons for news or mail messages will appear.
6551 The higher the number, the more buttons will appear and the more false
6552 positives are possible."
6553   ;; mail addresses, MIDs, URLs for news, ...
6554   :version "21.4"
6555   :group 'gnus-article-buttons
6556   :type 'integer)
6557
6558 (defcustom gnus-button-browse-level 5
6559   "*Integer that says how many buttons for browsing will appear.
6560 The higher the number, the more buttons will appear and the more false
6561 positives are possible."
6562   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6563   :version "21.4"
6564   :group 'gnus-article-buttons
6565   :type 'integer)
6566
6567 (defcustom gnus-button-alist
6568   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6569      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6570     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
6571      gnus-button-handle-news 2)
6572     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6573      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6574     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6575      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6576     ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6577     ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6578      0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6579     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6580      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6581     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6582      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6583     ;; RFC 2368 (The mailto URL scheme)
6584     ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6585      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6586     ("\\bmailto:\\([^ \n\t]+\\)"
6587      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6588     ;; CTAN
6589     ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6590              gnus-button-ctan-directory-regexp
6591              "[^][>)!;:,'\n\t ]+\\)")
6592      0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6593     ((concat "\\btex-archive/\\("
6594              gnus-button-ctan-directory-regexp
6595              "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6596      1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6597     ((concat
6598       "\\b\\("
6599       gnus-button-ctan-directory-regexp
6600       "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6601      1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6602     ;; This is info (home-grown style) <info://foo/bar+baz>
6603     ("\\binfo://\\([^'\">\n\t ]+\\)"
6604      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6605     ;; Info GNOME style <info:foo#bar_baz>
6606     ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6607      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6608     ;; Info KDE style <info:(foo)bar baz>
6609     ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6610      1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6611     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6612      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6613     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6614      ;; Info links like `C-h i d m CC Mode RET'
6615      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6616     ;; This is custom
6617     ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6618      0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6619     ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6620      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6621     ;; Emacs help commands
6622     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6623      ;; regexp doesn't match arguments containing ` '.
6624      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6625     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6626      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6627     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6628      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6629     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6630      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6631     ;; The following entries may lead to many false positives so don't enable
6632     ;; them by default (use a high button level).
6633     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6634      ;; Exclude [.?] for URLs in gmane.emacs.cvs
6635      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6636     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6637      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6638     ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6639      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6640     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6641      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6642     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6643      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6644     ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6645      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6646     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6647      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6648     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6649      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6650     ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6651      ;; Unlike the other regexps we really have to require quoting
6652      ;; here to determine where it ends.
6653      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6654     ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6655     ("<URL: *\\([^<>]*\\)>"
6656      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6657     ;; RFC 2396 (2.4.3., delims) ...
6658     ("\"URL: *\\([^\"]*\\)\""
6659      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6660     ;; RFC 2396 (2.4.3., delims) ...
6661     ("\"URL: *\\([^\"]*\\)\""
6662      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6663     ;; Raw URLs.
6664     (gnus-button-url-regexp
6665      0 (>= gnus-button-browse-level 0) browse-url 0)
6666     ;; man pages
6667     ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6668      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6669      gnus-button-handle-man 1)
6670     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6671     ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6672      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6673      gnus-button-handle-man 1)
6674     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6675     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6676     ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6677      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6678     ;; MID or mail: To avoid too many false positives we don't try to catch
6679     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
6680     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
6681     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
6682     ;; so that non-ambiguous entries (see above) match first.
6683     (gnus-button-mid-or-mail-regexp
6684      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6685   "*Alist of regexps matching buttons in article bodies.
6686
6687 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6688 REGEXP: is the string (case insensitive) matching text around the button (can
6689 also be Lisp expression evaluating to a string),
6690 BUTTON: is the number of the regexp grouping actually matching the button,
6691 FORM: is a Lisp expression which must eval to true for the button to
6692 be added,
6693 CALLBACK: is the function to call when the user push this button, and each
6694 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6695
6696 CALLBACK can also be a variable, in that case the value of that
6697 variable it the real callback function."
6698   :group 'gnus-article-buttons
6699   :type '(repeat (list (choice regexp variable sexp)
6700                        (integer :tag "Button")
6701                        (sexp :tag "Form")
6702                        (function :tag "Callback")
6703                        (repeat :tag "Par"
6704                                :inline t
6705                                (integer :tag "Regexp group")))))
6706
6707 (defcustom gnus-header-button-alist
6708   '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6709      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6710     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6711      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6712     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6713      0 (>= gnus-button-message-level 0) gnus-button-mailto 0)
6714     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6715      0 (>= gnus-button-browse-level 0) browse-url 0)
6716     ("^Subject:" gnus-button-url-regexp
6717      0 (>= gnus-button-browse-level 0) browse-url 0)
6718     ("^[^:]+:" gnus-button-url-regexp
6719      0 (>= gnus-button-browse-level 0) browse-url 0)
6720     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6721      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6722     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6723      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6724   "*Alist of headers and regexps to match buttons in article heads.
6725
6726 This alist is very similar to `gnus-button-alist', except that each
6727 alist has an additional HEADER element first in each entry:
6728
6729 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6730
6731 HEADER is a regexp to match a header.  For a fuller explanation, see
6732 `gnus-button-alist'."
6733   :group 'gnus-article-buttons
6734   :group 'gnus-article-headers
6735   :type '(repeat (list (regexp :tag "Header")
6736                        (choice regexp variable)
6737                        (integer :tag "Button")
6738                        (sexp :tag "Form")
6739                        (function :tag "Callback")
6740                        (repeat :tag "Par"
6741                                :inline t
6742                                (integer :tag "Regexp group")))))
6743
6744 ;;; Commands:
6745
6746 (defun gnus-article-push-button (event)
6747   "Check text under the mouse pointer for a callback function.
6748 If the text under the mouse pointer has a `gnus-callback' property,
6749 call it with the value of the `gnus-data' text property."
6750   (interactive "e")
6751   (set-buffer (window-buffer (posn-window (event-start event))))
6752   (let* ((pos (posn-point (event-start event)))
6753          (data (get-text-property pos 'gnus-data))
6754          (fun (get-text-property pos 'gnus-callback)))
6755     (goto-char pos)
6756     (when fun
6757       (funcall fun data))))
6758
6759 (defun gnus-article-press-button ()
6760   "Check text at point for a callback function.
6761 If the text at point has a `gnus-callback' property,
6762 call it with the value of the `gnus-data' text property."
6763   (interactive)
6764   (let ((data (get-text-property (point) 'gnus-data))
6765         (fun (get-text-property (point) 'gnus-callback)))
6766     (when fun
6767       (funcall fun data))))
6768
6769 (defun gnus-article-prev-button (n)
6770   "Move point to N buttons backward.
6771 If N is negative, move forward instead."
6772   (interactive "p")
6773   (gnus-article-next-button (- n)))
6774
6775 (defun gnus-article-next-button (n)
6776   "Move point to N buttons forward.
6777 If N is negative, move backward instead."
6778   (interactive "p")
6779   (let ((function (if (< n 0) 'previous-single-property-change
6780                     'next-single-property-change))
6781         (inhibit-point-motion-hooks t)
6782         (backward (< n 0))
6783         (limit (if (< n 0) (point-min) (point-max))))
6784     (setq n (abs n))
6785     (while (and (not (= limit (point)))
6786                 (> n 0))
6787       ;; Skip past the current button.
6788       (when (get-text-property (point) 'gnus-callback)
6789         (goto-char (funcall function (point) 'gnus-callback nil limit)))
6790       ;; Go to the next (or previous) button.
6791       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
6792       ;; Put point at the start of the button.
6793       (when (and backward (not (get-text-property (point) 'gnus-callback)))
6794         (goto-char (funcall function (point) 'gnus-callback nil limit)))
6795       ;; Skip past intangible buttons.
6796       (when (get-text-property (point) 'intangible)
6797         (incf n))
6798       (decf n))
6799     (unless (zerop n)
6800       (gnus-message 5 "No more buttons"))
6801     n))
6802
6803 (defun gnus-article-highlight (&optional force)
6804   "Highlight current article.
6805 This function calls `gnus-article-highlight-headers',
6806 `gnus-article-highlight-citation',
6807 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6808 do the highlighting.  See the documentation for those functions."
6809   (interactive (list 'force))
6810   (gnus-article-highlight-headers)
6811   (gnus-article-highlight-citation force)
6812   (gnus-article-highlight-signature)
6813   (gnus-article-add-buttons force)
6814   (gnus-article-add-buttons-to-head))
6815
6816 (defun gnus-article-highlight-some (&optional force)
6817   "Highlight current article.
6818 This function calls `gnus-article-highlight-headers',
6819 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6820 do the highlighting.  See the documentation for those functions."
6821   (interactive (list 'force))
6822   (gnus-article-highlight-headers)
6823   (gnus-article-highlight-signature)
6824   (gnus-article-add-buttons))
6825
6826 (defun gnus-article-highlight-headers ()
6827   "Highlight article headers as specified by `gnus-header-face-alist'."
6828   (interactive)
6829   (gnus-with-article-headers
6830     (let ((alist gnus-header-face-alist)
6831           entry regexp header-face field-face from hpoints fpoints)
6832       (while (setq entry (pop alist))
6833         (goto-char (point-min))
6834         (setq regexp (concat "^\\("
6835                              (if (string-equal "" (nth 0 entry))
6836                                  "[^\t ]"
6837                                (nth 0 entry))
6838                              "\\)")
6839               header-face (nth 1 entry)
6840               field-face (nth 2 entry))
6841         (while (and (re-search-forward regexp nil t)
6842                     (not (eobp)))
6843           (beginning-of-line)
6844           (setq from (point))
6845           (unless (search-forward ":" nil t)
6846             (forward-char 1))
6847           (when (and header-face
6848                      (not (memq (point) hpoints)))
6849             (push (point) hpoints)
6850             (gnus-put-text-property from (point) 'face header-face))
6851           (when (and field-face
6852                      (not (memq (setq from (point)) fpoints)))
6853             (push from fpoints)
6854             (if (re-search-forward "^[^ \t]" nil t)
6855                 (forward-char -2)
6856               (goto-char (point-max)))
6857             (gnus-put-text-property from (point) 'face field-face)))))))
6858
6859 (defun gnus-article-highlight-signature ()
6860   "Highlight the signature in an article.
6861 It does this by highlighting everything after
6862 `gnus-signature-separator' using `gnus-signature-face'."
6863   (interactive)
6864   (when gnus-signature-face
6865     (gnus-with-article-buffer
6866       (let ((inhibit-point-motion-hooks t))
6867         (save-restriction
6868           (when (gnus-article-narrow-to-signature)
6869             (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6870                               'face gnus-signature-face)))))))
6871
6872 (defun gnus-article-buttonize-signature ()
6873   "Add button to the signature."
6874   (interactive)
6875   (save-excursion
6876     (set-buffer gnus-article-buffer)
6877     (let ((inhibit-read-only t)
6878           (inhibit-point-motion-hooks t))
6879       (when (gnus-article-search-signature)
6880         (gnus-article-add-button (match-beginning 0) (match-end 0)
6881                                  'gnus-signature-toggle
6882                                  (set-marker (make-marker)
6883                                              (1+ (match-end 0))))))))
6884
6885 (defun gnus-button-in-region-p (b e prop)
6886   "Say whether PROP exists in the region."
6887   (text-property-not-all b e prop nil))
6888
6889 (defun gnus-article-add-buttons (&optional force)
6890   "Find external references in the article and make buttons of them.
6891 \"External references\" are things like Message-IDs and URLs, as
6892 specified by `gnus-button-alist'."
6893   (interactive (list 'force))
6894   (gnus-with-article-buffer
6895     (let ((inhibit-point-motion-hooks t)
6896           (case-fold-search t)
6897           (alist gnus-button-alist)
6898           beg entry regexp)
6899       ;; Remove all old markers.
6900       (let (marker entry new-list)
6901         (while (setq marker (pop gnus-button-marker-list))
6902           (if (or (< marker (point-min)) (>= marker (point-max)))
6903               (push marker new-list)
6904             (goto-char marker)
6905             (when (setq entry (gnus-button-entry))
6906               (put-text-property (match-beginning (nth 1 entry))
6907                                  (match-end (nth 1 entry))
6908                                  'gnus-callback nil))
6909             (set-marker marker nil)))
6910         (setq gnus-button-marker-list new-list))
6911       ;; We skip the headers.
6912       (article-goto-body)
6913       (setq beg (point))
6914       (while (setq entry (pop alist))
6915         (setq regexp (eval (car entry)))
6916         (goto-char beg)
6917         (while (re-search-forward regexp nil t)
6918           (let* ((start (and entry (match-beginning (nth 1 entry))))
6919                  (end (and entry (match-end (nth 1 entry))))
6920                  (from (match-beginning 0)))
6921             (when (and (or (eq t (nth 2 entry))
6922                            (eval (nth 2 entry)))
6923                        (not (gnus-button-in-region-p
6924                              start end 'gnus-callback)))
6925               ;; That optional form returned non-nil, so we add the
6926               ;; button.
6927               (gnus-article-add-button
6928                start end 'gnus-button-push
6929                (car (push (set-marker (make-marker) from)
6930                           gnus-button-marker-list))))))))))
6931
6932 ;; Add buttons to the head of an article.
6933 (defun gnus-article-add-buttons-to-head ()
6934   "Add buttons to the head of the article."
6935   (interactive)
6936   (gnus-with-article-headers
6937     (let ((alist gnus-header-button-alist)
6938           entry beg end)
6939       (while alist
6940         ;; Each alist entry.
6941         (setq entry (pop alist))
6942         (goto-char (point-min))
6943         (while (re-search-forward (car entry) nil t)
6944           ;; Each header matching the entry.
6945           (setq beg (match-beginning 0))
6946           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6947                              (match-beginning 0))
6948                         (point-max)))
6949           (goto-char beg)
6950           (while (re-search-forward (eval (nth 1 entry)) end t)
6951             ;; Each match within a header.
6952             (let* ((entry (cdr entry))
6953                    (start (match-beginning (nth 1 entry)))
6954                    (end (match-end (nth 1 entry)))
6955                    (form (nth 2 entry)))
6956               (goto-char (match-end 0))
6957               (when (eval form)
6958                 (gnus-article-add-button
6959                  start end (nth 3 entry)
6960                  (buffer-substring (match-beginning (nth 4 entry))
6961                                    (match-end (nth 4 entry)))))))
6962           (goto-char end))))))
6963
6964 ;;; External functions:
6965
6966 (defun gnus-article-add-button (from to fun &optional data)
6967   "Create a button between FROM and TO with callback FUN and data DATA."
6968   (when gnus-article-button-face
6969     (gnus-overlay-put (gnus-make-overlay from to)
6970                       'face gnus-article-button-face))
6971   (gnus-add-text-properties
6972    from to
6973    (nconc (and gnus-article-mouse-face
6974                (list gnus-mouse-face-prop gnus-article-mouse-face))
6975           (list 'gnus-callback fun)
6976           (and data (list 'gnus-data data))))
6977   (widget-convert-button 'link from to :action 'gnus-widget-press-button
6978                          :button-keymap gnus-widget-button-keymap))
6979
6980 ;;; Internal functions:
6981
6982 (defun gnus-article-set-globals ()
6983   (with-current-buffer gnus-summary-buffer
6984     (gnus-set-global-variables)))
6985
6986 (defun gnus-signature-toggle (end)
6987   (gnus-with-article-buffer
6988     (let ((inhibit-point-motion-hooks t)
6989           (limit (next-single-property-change end 'mime-view-entity
6990                                               nil (point-max))))
6991       (if (text-property-any end limit 'article-type 'signature)
6992           (progn
6993             (gnus-delete-wash-type 'signature)
6994             (gnus-remove-text-properties-when
6995              'article-type 'signature end limit
6996              (cons 'article-type (cons 'signature
6997                                        gnus-hidden-properties))))
6998         (gnus-add-wash-type 'signature)
6999         (gnus-add-text-properties-when
7000          'article-type nil end limit
7001          (cons 'article-type (cons 'signature
7002                                    gnus-hidden-properties)))))
7003     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7004       (gnus-set-mode-line 'article))))
7005
7006 (defun gnus-button-entry ()
7007   ;; Return the first entry in `gnus-button-alist' matching this place.
7008   (let ((alist gnus-button-alist)
7009         (entry nil))
7010     (while alist
7011       (setq entry (pop alist))
7012       (if (looking-at (eval (car entry)))
7013           (setq alist nil)
7014         (setq entry nil)))
7015     entry))
7016
7017 (defun gnus-button-push (marker)
7018   ;; Push button starting at MARKER.
7019   (save-excursion
7020     (goto-char marker)
7021     (let* ((entry (gnus-button-entry))
7022            (inhibit-point-motion-hooks t)
7023            (fun (nth 3 entry))
7024            (args (mapcar (lambda (group)
7025                            (let ((string (match-string group)))
7026                              (set-text-properties
7027                               0 (length string) nil string)
7028                              string))
7029                          (nthcdr 4 entry))))
7030       (cond
7031        ((fboundp fun)
7032         (apply fun args))
7033        ((and (boundp fun)
7034              (fboundp (symbol-value fun)))
7035         (apply (symbol-value fun) args))
7036        (t
7037         (gnus-message 1 "You must define `%S' to use this button"
7038                       (cons fun args)))))))
7039
7040 (defun gnus-parse-news-url (url)
7041   (let (scheme server group message-id articles)
7042     (with-temp-buffer
7043       (insert url)
7044       (goto-char (point-min))
7045       (when (looking-at "\\([A-Za-z]+\\):")
7046         (setq scheme (match-string 1))
7047         (goto-char (match-end 0)))
7048       (when (looking-at "//\\([^/]+\\)/")
7049         (setq server (match-string 1))
7050         (goto-char (match-end 0)))
7051
7052       (cond
7053        ((looking-at "\\(.*@.*\\)")
7054         (setq message-id (match-string 1)))
7055        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7056         (setq group (match-string 1)
7057               articles (split-string (match-string 2) "-")))
7058        ((looking-at "\\([^/]+\\)/?")
7059         (setq group (match-string 1)))
7060        (t
7061         (error "Unknown news URL syntax"))))
7062     (list scheme server group message-id articles)))
7063
7064 (defun gnus-button-handle-news (url)
7065   "Fetch a news URL."
7066   (destructuring-bind (scheme server group message-id articles)
7067       (gnus-parse-news-url url)
7068     (cond
7069      (message-id
7070       (save-excursion
7071         (set-buffer gnus-summary-buffer)
7072         (if server
7073             (let ((gnus-refer-article-method (list (list 'nntp server))))
7074               (gnus-summary-refer-article message-id))
7075           (gnus-summary-refer-article message-id))))
7076      (group
7077       (gnus-button-fetch-group url)))))
7078
7079 (defun gnus-button-handle-man (url)
7080   "Fetch a man page."
7081   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7082   (when (eq gnus-button-man-handler 'woman)
7083     (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7084   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7085   (funcall gnus-button-man-handler url))
7086
7087 (defun gnus-button-handle-info-url (url)
7088   "Fetch an info URL."
7089   (setq url (mm-subst-char-in-string ?+ ?\  url))
7090   (cond
7091    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7092     (gnus-info-find-node
7093      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7094                      "Gnus")
7095              ")" (gnus-url-unhex-string (match-string 2 url)))))
7096    ((string-match "([^)\"]+)[^\"]+" url)
7097     (setq url
7098           (gnus-replace-in-string
7099            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7100     (gnus-info-find-node url))
7101    (t (error "Can't parse %s" url))))
7102
7103 (defun gnus-button-handle-info-url-gnome (url)
7104   "Fetch GNOME style info URL."
7105   (setq url (mm-subst-char-in-string ?_ ?\  url))
7106   (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7107       (gnus-info-find-node
7108        (concat "("
7109                (gnus-url-unhex-string 
7110                  (match-string 1 url))
7111                ")"
7112                (or (gnus-url-unhex-string 
7113                     (match-string 2 url))
7114                    "Top")))
7115     (error "Can't parse %s" url)))
7116
7117 (defun gnus-button-handle-info-url-kde (url)
7118   "Fetch KDE style info URL."
7119   (gnus-info-find-node (gnus-url-unhex-string url)))
7120
7121 (defun gnus-button-handle-info-keystrokes (url)
7122   "Call `info' when pushing the corresponding URL button."
7123   ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7124   (info)
7125   (Info-directory)
7126   (Info-menu url))
7127
7128 (defun gnus-button-message-id (message-id)
7129   "Fetch MESSAGE-ID."
7130   (with-current-buffer gnus-summary-buffer
7131     (gnus-summary-refer-article message-id)))
7132
7133 (defun gnus-button-fetch-group (address)
7134   "Fetch GROUP specified by ADDRESS."
7135   (if (not (string-match "[:/]" address))
7136       ;; This is just a simple group url.
7137       (gnus-group-read-ephemeral-group address gnus-select-method)
7138     (if (not
7139          (string-match
7140           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7141           address))
7142         (error "Can't parse %s" address)
7143       (gnus-group-read-ephemeral-group
7144        (match-string 4 address)
7145        `(nntp ,(match-string 1 address)
7146               (nntp-address ,(match-string 1 address))
7147               (nntp-port-number ,(if (match-end 3)
7148                                      (match-string 3 address)
7149                                    "nntp")))
7150        nil nil nil
7151        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
7152
7153 (defun gnus-url-parse-query-string (query &optional downcase)
7154   (let (retval pairs cur key val)
7155     (setq pairs (split-string query "&"))
7156     (while pairs
7157       (setq cur (car pairs)
7158             pairs (cdr pairs))
7159       (if (not (string-match "=" cur))
7160           nil                           ; Grace
7161         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7162               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7163         (if downcase
7164             (setq key (downcase key)))
7165         (setq cur (assoc key retval))
7166         (if cur
7167             (setcdr cur (cons val (cdr cur)))
7168           (setq retval (cons (list key val) retval)))))
7169     retval))
7170
7171 (defun gnus-url-mailto (url)
7172   ;; Send mail to someone
7173   (when (string-match "mailto:/*\\(.*\\)" url)
7174     (setq url (substring url (match-beginning 1) nil)))
7175   (let (to args subject func)
7176     (setq args (gnus-url-parse-query-string
7177                 (if (string-match "^\\?" url)
7178                     (substring url 1)
7179                   (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7180                       (concat "to=" (match-string 1 url) "&"
7181                               (match-string 2 url))
7182                     (concat "to=" url)))
7183                 t)
7184           subject (cdr-safe (assoc "subject" args)))
7185     (gnus-msg-mail)
7186     (while args
7187       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7188       (if (fboundp func)
7189           (funcall func)
7190         (message-position-on-field (caar args)))
7191       (insert (gnus-replace-in-string
7192                (mapconcat 'identity (reverse (cdar args)) ", ")
7193                "\r\n" "\n" t))
7194       (setq args (cdr args)))
7195     (if subject
7196         (message-goto-body)
7197       (message-goto-subject))))
7198
7199 (defun gnus-button-embedded-url (address)
7200   "Activate ADDRESS with `browse-url'."
7201   (browse-url (gnus-strip-whitespace address)))
7202
7203 ;;; Next/prev buttons in the article buffer.
7204
7205 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7206 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7207
7208 (defvar gnus-prev-page-map
7209   (let ((map (make-sparse-keymap)))
7210     (define-key map gnus-mouse-2 'gnus-button-prev-page)
7211     (define-key map "\r" 'gnus-button-prev-page)
7212     map))
7213
7214 (defvar gnus-next-page-map
7215   (let ((map (make-sparse-keymap)))
7216     (unless (>= emacs-major-version 21)
7217       ;; XEmacs doesn't care.
7218       (set-keymap-parent map gnus-article-mode-map))
7219     (define-key map gnus-mouse-2 'gnus-button-next-page)
7220     (define-key map "\r" 'gnus-button-next-page)
7221     map))
7222
7223 (defun gnus-insert-prev-page-button ()
7224   (let ((b (point))
7225         (inhibit-read-only t)
7226         (situation (get-text-property (point-min) 'mime-view-situation)))
7227     (gnus-eval-format
7228      gnus-prev-page-line-format nil
7229      `(keymap ,gnus-prev-page-map
7230          gnus-prev t
7231          gnus-callback gnus-article-button-prev-page
7232          article-type annotation
7233          mime-view-situation ,situation))
7234     (widget-convert-button
7235      'link b (if (bolp)
7236                  ;; Exclude a newline.
7237                  (1- (point))
7238                (point))
7239      :action 'gnus-button-prev-page
7240      :button-keymap gnus-prev-page-map)))
7241
7242 (defun gnus-button-next-page (&optional args more-args)
7243   "Go to the next page."
7244   (interactive)
7245   (let ((win (selected-window)))
7246     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7247     (gnus-article-next-page)
7248     (select-window win)))
7249
7250 (defun gnus-button-prev-page (&optional args more-args)
7251   "Go to the prev page."
7252   (interactive)
7253   (let ((win (selected-window)))
7254     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7255     (gnus-article-prev-page)
7256     (select-window win)))
7257
7258 (defun gnus-insert-next-page-button ()
7259   (let ((b (point))
7260         (inhibit-read-only t)
7261         (situation (get-text-property (point-min) 'mime-view-situation)))
7262     (gnus-eval-format gnus-next-page-line-format nil
7263                       `(keymap ,gnus-next-page-map
7264                           gnus-next t
7265                           gnus-callback gnus-article-button-next-page
7266                           article-type annotation
7267                           mime-view-situation ,situation))
7268     (widget-convert-button
7269      'link b (if (bolp)
7270                  ;; Exclude a newline.
7271                  (1- (point))
7272                (point))
7273      :action 'gnus-button-next-page
7274      :button-keymap gnus-next-page-map)))
7275
7276 (defun gnus-article-button-next-page (arg)
7277   "Go to the next page."
7278   (interactive "P")
7279   (let ((win (selected-window)))
7280     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7281     (gnus-article-next-page)
7282     (select-window win)))
7283
7284 (defun gnus-article-button-prev-page (arg)
7285   "Go to the prev page."
7286   (interactive "P")
7287   (let ((win (selected-window)))
7288     (select-window (gnus-get-buffer-window gnus-article-buffer t))
7289     (gnus-article-prev-page)
7290     (select-window win)))
7291
7292 (defvar gnus-decode-header-methods
7293   '(mail-decode-encoded-word-region)
7294   "List of methods used to decode headers.
7295
7296 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
7297 is FUNCTION, FUNCTION will be applied to all newsgroups.  If item is a
7298 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7299 whose names match REGEXP.
7300
7301 For example:
7302 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7303  mail-decode-encoded-word-region
7304  (\"chinese\" . rfc1843-decode-region))
7305 ")
7306
7307 (defvar gnus-decode-header-methods-cache nil)
7308
7309 (defun gnus-multi-decode-header (start end)
7310   "Apply the functions from `gnus-encoded-word-methods' that match."
7311   (unless (and gnus-decode-header-methods-cache
7312                (eq gnus-newsgroup-name
7313                    (car gnus-decode-header-methods-cache)))
7314     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7315     (mapcar (lambda (x)
7316               (if (symbolp x)
7317                   (nconc gnus-decode-header-methods-cache (list x))
7318                 (if (and gnus-newsgroup-name
7319                          (string-match (car x) gnus-newsgroup-name))
7320                     (nconc gnus-decode-header-methods-cache
7321                            (list (cdr x))))))
7322             gnus-decode-header-methods))
7323   (let ((xlist gnus-decode-header-methods-cache))
7324     (pop xlist)
7325     (save-restriction
7326       (narrow-to-region start end)
7327       (while xlist
7328         (funcall (pop xlist) (point-min) (point-max))))))
7329
7330 ;;;
7331 ;;; Treatment top-level handling.
7332 ;;;
7333
7334 (defun gnus-treat-article (condition &optional part-number total-parts type)
7335   (let ((length (- (point-max) (point-min)))
7336         (alist gnus-treatment-function-alist)
7337         (article-goto-body-goes-to-point-min-p t)
7338         (treated-type
7339          (or (not type)
7340              (catch 'found
7341                (let ((list gnus-article-treat-types))
7342                  (while list
7343                    (when (string-match (pop list) type)
7344                      (throw 'found t)))))))
7345         (highlightp (gnus-visual-p 'article-highlight 'highlight))
7346         (entity (static-unless (featurep 'xemacs)
7347                   (when (eq 'head condition)
7348                     (get-text-property (point-min) 'mime-view-entity))))
7349         val elem buttonized)
7350     (gnus-run-hooks 'gnus-part-display-hook)
7351     (unless gnus-inhibit-treatment
7352       (dolist (elem alist)
7353         (setq val
7354               (save-excursion
7355                 (when (gnus-buffer-live-p gnus-summary-buffer)
7356                   (set-buffer gnus-summary-buffer))
7357                 (symbol-value (car elem))))
7358         (when (and (or (consp val)
7359                        treated-type)
7360                    (gnus-treat-predicate val)
7361                    (or (not (get (car elem) 'highlight))
7362                        highlightp))
7363           (when (and (not buttonized)
7364                      (memq (car elem)
7365                            '(gnus-treat-hide-signature
7366                              gnus-treat-highlight-signature)))
7367             (gnus-article-buttonize-signature)
7368             (setq buttonized t))
7369           (save-restriction
7370             (funcall (cadr elem)))))
7371       ;; FSF Emacsen does not inherit the existing text properties
7372       ;; in the new text, so we should do it for `mime-view-entity'.
7373       (static-unless (featurep 'xemacs)
7374         (when entity
7375           (put-text-property (point-min) (point-max)
7376                              'mime-view-entity entity))))))
7377
7378 ;; Dynamic variables.
7379 (eval-when-compile
7380   (defvar part-number)
7381   (defvar total-parts)
7382   (defvar type)
7383   (defvar condition)
7384   (defvar length))
7385
7386 (defun gnus-treat-predicate (val)
7387   (cond
7388    ((null val)
7389     nil)
7390    ((and (listp val)
7391          (stringp (car val)))
7392     (apply 'gnus-or (mapcar `(lambda (s)
7393                                (string-match s ,(or gnus-newsgroup-name "")))
7394                             val)))
7395    ((listp val)
7396     (let ((pred (pop val)))
7397       (cond
7398        ((eq pred 'or)
7399         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7400        ((eq pred 'and)
7401         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7402        ((eq pred 'not)
7403         (not (gnus-treat-predicate (car val))))
7404        ((eq pred 'typep)
7405         (equal (car val) type))
7406        (t
7407         (error "%S is not a valid predicate" pred)))))
7408    ((eq val 'mime)
7409     gnus-show-mime)
7410    (condition
7411     (eq condition val))
7412    ((eq val t)
7413     t)
7414    ((eq val 'head)
7415     nil)
7416    ((eq val 'last)
7417     (eq part-number total-parts))
7418    ((numberp val)
7419     (< length val))
7420    (t
7421     (error "%S is not a valid value" val))))
7422
7423 (defun gnus-article-encrypt-body (protocol &optional n)
7424   "Encrypt the article body."
7425   (interactive
7426    (list
7427     (or gnus-article-encrypt-protocol
7428         (completing-read "Encrypt protocol: "
7429                          gnus-article-encrypt-protocol-alist
7430                          nil t))
7431     current-prefix-arg))
7432   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7433     (unless func
7434       (error (format "Can't find the encrypt protocol %s" protocol)))
7435     (if (member gnus-newsgroup-name '("nndraft:delayed"
7436                                       "nndraft:drafts"
7437                                       "nndraft:queue"))
7438         (error "Can't encrypt the article in group %s"
7439                gnus-newsgroup-name))
7440     (gnus-summary-iterate n
7441       (save-excursion
7442         (set-buffer gnus-summary-buffer)
7443         (let ((mail-parse-charset gnus-newsgroup-charset)
7444               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7445               (summary-buffer gnus-summary-buffer)
7446               references point)
7447           (gnus-set-global-variables)
7448           (when (gnus-group-read-only-p)
7449             (error "The current newsgroup does not support article encrypt"))
7450           (gnus-summary-show-article t)
7451           (setq references
7452                 (or (mail-header-references gnus-current-headers) ""))
7453           (set-buffer gnus-article-buffer)
7454           (let* ((inhibit-read-only t)
7455                  (headers
7456                   (mapcar (lambda (field)
7457                             (and (save-restriction
7458                                    (message-narrow-to-head)
7459                                    (goto-char (point-min))
7460                                    (search-forward field nil t))
7461                                  (prog2
7462                                      (message-narrow-to-field)
7463                                      (buffer-string)
7464                                    (delete-region (point-min) (point-max))
7465                                    (widen))))
7466                           '("Content-Type:" "Content-Transfer-Encoding:"
7467                             "Content-Disposition:"))))
7468             (message-narrow-to-head)
7469             (message-remove-header "MIME-Version")
7470             (goto-char (point-max))
7471             (setq point (point))
7472             (insert (apply 'concat headers))
7473             (widen)
7474             (narrow-to-region point (point-max))
7475             (let ((message-options message-options))
7476               (message-options-set 'message-sender user-mail-address)
7477               (message-options-set 'message-recipients user-mail-address)
7478               (message-options-set 'message-sign-encrypt 'not)
7479               (funcall func))
7480             (goto-char (point-min))
7481             (insert "MIME-Version: 1.0\n")
7482             (widen)
7483             (gnus-summary-edit-article-done
7484              references nil summary-buffer t))
7485           (when gnus-keep-backlog
7486             (gnus-backlog-remove-article
7487              (car gnus-article-current) (cdr gnus-article-current)))
7488           (save-excursion
7489             (when (get-buffer gnus-original-article-buffer)
7490               (set-buffer gnus-original-article-buffer)
7491               (setq gnus-original-article nil)))
7492           (when gnus-use-cache
7493             (gnus-cache-update-article
7494              (car gnus-article-current) (cdr gnus-article-current))))))))
7495
7496 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7497   "The following specs can be used:
7498 %t  The security MIME type
7499 %i  Additional info
7500 %d  Details
7501 %D  Details if button is pressed")
7502
7503 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7504   "The following specs can be used:
7505 %t  The security MIME type
7506 %i  Additional info
7507 %d  Details
7508 %D  Details if button is pressed")
7509
7510 (defvar gnus-mime-security-button-line-format-alist
7511   '((?t gnus-tmp-type ?s)
7512     (?i gnus-tmp-info ?s)
7513     (?d gnus-tmp-details ?s)
7514     (?D gnus-tmp-pressed-details ?s)))
7515
7516 (defvar gnus-mime-security-button-map
7517   (let ((map (make-sparse-keymap)))
7518     (define-key map gnus-mouse-2 'gnus-article-push-button)
7519     (define-key map "\r" 'gnus-article-press-button)
7520     map))
7521
7522 (defvar gnus-mime-security-details-buffer nil)
7523
7524 (defvar gnus-mime-security-button-pressed nil)
7525
7526 (defvar gnus-mime-security-show-details-inline t
7527   "If non-nil, show details in the article buffer.")
7528
7529 (defun gnus-mime-security-verify-or-decrypt (handle)
7530   (mm-remove-parts (cdr handle))
7531   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7532         point (inhibit-read-only t))
7533     (if region
7534         (goto-char (car region)))
7535     (save-restriction
7536       (narrow-to-region (point) (point))
7537       (with-current-buffer (mm-handle-multipart-original-buffer handle)
7538         (let* ((mm-verify-option 'known)
7539                (mm-decrypt-option 'known)
7540                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7541           (unless (eq nparts (cdr handle))
7542             (mm-destroy-parts (cdr handle))
7543             (setcdr handle nparts))))
7544       (setq point (point))
7545       (gnus-mime-display-security handle)
7546       (goto-char (point-max)))
7547     (when region
7548       (delete-region (point) (cdr region))
7549       (set-marker (car region) nil)
7550       (set-marker (cdr region) nil))
7551     (goto-char point)))
7552
7553 (defun gnus-mime-security-show-details (handle)
7554   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7555     (if (not details)
7556         (gnus-message 5 "No details.")
7557       (if gnus-mime-security-show-details-inline
7558           (let ((gnus-mime-security-button-pressed
7559                  (not (get-text-property (point) 'gnus-mime-details)))
7560                 (gnus-mime-security-button-line-format
7561                  (get-text-property (point) 'gnus-line-format))
7562                 (inhibit-read-only t))
7563             (forward-char -1)
7564             (while (eq (get-text-property (point) 'gnus-line-format)
7565                        gnus-mime-security-button-line-format)
7566               (forward-char -1))
7567             (forward-char)
7568             (save-restriction
7569               (narrow-to-region (point) (point))
7570               (gnus-insert-mime-security-button handle))
7571             (delete-region (point)
7572                            (or (text-property-not-all
7573                                 (point) (point-max)
7574                                 'gnus-line-format
7575                                 gnus-mime-security-button-line-format)
7576                                (point-max))))
7577         ;; Not inlined.
7578         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7579             (with-current-buffer gnus-mime-security-details-buffer
7580               (erase-buffer)
7581               t)
7582           (setq gnus-mime-security-details-buffer
7583                 (gnus-get-buffer-create "*MIME Security Details*")))
7584         (with-current-buffer gnus-mime-security-details-buffer
7585           (insert details)
7586           (goto-char (point-min)))
7587         (pop-to-buffer gnus-mime-security-details-buffer)))))
7588
7589 (defun gnus-mime-security-press-button (handle)
7590   (save-excursion
7591     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7592         (gnus-mime-security-show-details handle)
7593       (gnus-mime-security-verify-or-decrypt handle))))
7594
7595 (defun gnus-insert-mime-security-button (handle &optional displayed)
7596   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7597          (gnus-tmp-type
7598           (concat
7599            (or (nth 2 (assoc protocol mm-verify-function-alist))
7600                (nth 2 (assoc protocol mm-decrypt-function-alist))
7601                "Unknown")
7602            (if (equal (car handle) "multipart/signed")
7603                " Signed" " Encrypted")
7604            " Part"))
7605          (gnus-tmp-info
7606           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7607               "Undecided"))
7608          (gnus-tmp-details
7609           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7610          gnus-tmp-pressed-details
7611          b e)
7612     (setq gnus-tmp-details
7613           (if gnus-tmp-details
7614               (concat "\n" gnus-tmp-details)
7615             ""))
7616     (setq gnus-tmp-pressed-details
7617           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7618     (unless (bolp)
7619       (insert "\n"))
7620     (setq b (point))
7621     (gnus-eval-format
7622      gnus-mime-security-button-line-format
7623      gnus-mime-security-button-line-format-alist
7624      `(keymap ,gnus-mime-security-button-map
7625          gnus-callback gnus-mime-security-press-button
7626          gnus-line-format ,gnus-mime-security-button-line-format
7627          gnus-mime-details ,gnus-mime-security-button-pressed
7628          article-type annotation
7629          gnus-data ,handle))
7630     (setq e (if (bolp)
7631                 ;; Exclude a newline.
7632                 (1- (point))
7633               (point)))
7634     (widget-convert-button
7635      'link b e
7636      :mime-handle handle
7637      :action 'gnus-widget-press-button
7638      :button-keymap gnus-mime-security-button-map
7639      :help-echo
7640      (lambda (widget/window &optional overlay pos)
7641        ;; Needed to properly clear the message due to a bug in
7642        ;; wid-edit (XEmacs only).
7643        (when (boundp 'help-echo-owns-message)
7644          (setq help-echo-owns-message t))
7645        (format
7646         "%S: show detail"
7647         (aref gnus-mouse-2 0))))))
7648
7649 (defun gnus-mime-display-security (handle)
7650   (save-restriction
7651     (narrow-to-region (point) (point))
7652     (unless (gnus-unbuttonized-mime-type-p (car handle))
7653       (gnus-insert-mime-security-button handle))
7654     (gnus-mime-display-mixed (cdr handle))
7655     (unless (bolp)
7656       (insert "\n"))
7657     (unless (gnus-unbuttonized-mime-type-p (car handle))
7658       (let ((gnus-mime-security-button-line-format
7659              gnus-mime-security-button-end-line-format))
7660         (gnus-insert-mime-security-button handle)))
7661     (mm-set-handle-multipart-parameter
7662      handle 'gnus-region
7663      (cons (set-marker (make-marker) (point-min))
7664            (set-marker (make-marker) (point-max))))))
7665
7666
7667 ;;; @ for mime-view
7668 ;;;
7669
7670 (defun gnus-article-header-presentation-method (entity situation)
7671   (mime-insert-header entity)
7672   (article-decode-group-name))
7673
7674 (set-alist 'mime-header-presentation-method-alist
7675            'gnus-original-article-mode
7676            #'gnus-article-header-presentation-method)
7677
7678 (defun gnus-mime-preview-quitting-method ()
7679   (mime-preview-kill-buffer)
7680   (delete-other-windows)
7681   (gnus-article-show-summary)
7682   (gnus-summary-select-article gnus-show-all-headers t))
7683
7684 (set-alist 'mime-preview-quitting-method-alist
7685            'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
7686
7687 (set-alist 'mime-preview-following-method-alist
7688            'gnus-original-article-mode #'gnus-following-method)
7689
7690 (set-alist 'mime-preview-over-to-previous-method-alist
7691            'gnus-original-article-mode
7692            (lambda ()
7693              (if (> (point-min) 1)
7694                  (gnus-article-prev-page)
7695                (gnus-article-read-summary-keys
7696                 nil (gnus-character-to-event ?P)))))
7697
7698 (set-alist 'mime-preview-over-to-next-method-alist
7699            'gnus-original-article-mode'
7700            (lambda ()
7701              (if (< (point-max) (buffer-size))
7702                  (gnus-article-next-page)
7703                (gnus-article-read-summary-keys
7704                 nil (gnus-character-to-event ?N)))))
7705
7706
7707 ;;; @ end
7708 ;;;
7709
7710 (gnus-ems-redefine)
7711
7712 (provide 'gnus-art)
7713
7714 (run-hooks 'gnus-art-load-hook)
7715
7716 ;;; gnus-art.el ends here