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