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