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