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