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