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