Synch with `t-gnus-6_14' and Gnus.
[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 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;;      MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;;      Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'static))
32
33 (require 'path-util)
34 (require 'gnus)
35 (require 'gnus-sum)
36 (require 'gnus-spec)
37 (require 'gnus-int)
38 (require 'alist)
39 (require 'mime-view)
40 (require 'wid-edit)
41
42 ;; Avoid byte-compile warnings.
43 (eval-when-compile
44   (require 'mm-bodies)
45   (require 'mail-parse)
46   (require 'mm-decode)
47   (require 'mm-view)
48   (require 'mm-uu)
49   )
50
51 (defgroup gnus-article nil
52   "Article display."
53   :link '(custom-manual "(gnus)The Article Buffer")
54   :group 'gnus)
55
56 (defgroup gnus-article-treat nil
57   "Treating article parts."
58   :link '(custom-manual "(gnus)Article Hiding")
59   :group 'gnus-article)
60
61 (defgroup gnus-article-hiding nil
62   "Hiding article parts."
63   :link '(custom-manual "(gnus)Article Hiding")
64   :group 'gnus-article)
65
66 (defgroup gnus-article-highlight nil
67   "Article highlighting."
68   :link '(custom-manual "(gnus)Article Highlighting")
69   :group 'gnus-article
70   :group 'gnus-visual)
71
72 (defgroup gnus-article-signature nil
73   "Article signatures."
74   :link '(custom-manual "(gnus)Article Signature")
75   :group 'gnus-article)
76
77 (defgroup gnus-article-headers nil
78   "Article headers."
79   :link '(custom-manual "(gnus)Hiding Headers")
80   :group 'gnus-article)
81
82 (defgroup gnus-article-washing nil
83   "Special commands on articles."
84   :link '(custom-manual "(gnus)Article Washing")
85   :group 'gnus-article)
86
87 (defgroup gnus-article-emphasis nil
88   "Fontisizing articles."
89   :link '(custom-manual "(gnus)Article Fontisizing")
90   :group 'gnus-article)
91
92 (defgroup gnus-article-saving nil
93   "Saving articles."
94   :link '(custom-manual "(gnus)Saving Articles")
95   :group 'gnus-article)
96
97 (defgroup gnus-article-mime nil
98   "Worshiping the MIME wonder."
99   :link '(custom-manual "(gnus)Using MIME")
100   :group 'gnus-article)
101
102 (defgroup gnus-article-buttons nil
103   "Pushable buttons in the article buffer."
104   :link '(custom-manual "(gnus)Article Buttons")
105   :group 'gnus-article)
106
107 (defgroup gnus-article-various nil
108   "Other article options."
109   :link '(custom-manual "(gnus)Misc Article")
110   :group 'gnus-article)
111
112 (defcustom gnus-ignored-headers
113   '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
114     "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
115     "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
116     "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
117     "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
118     "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
119     "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
120     "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
121     "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
122     "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
123     "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
124     "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
125     "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
126     "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
127     "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
128     "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
129     "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
130     "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
131     "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
132     "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
133     "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
134     "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
135     "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
136     "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
137     "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
138     "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
139     "^X-Received:" "^Content-length:" "X-precedence:")
140   "*All headers that start with this regexp will be hidden.
141 This variable can also be a list of regexps of headers to be ignored.
142 If `gnus-visible-headers' is non-nil, this variable will be ignored."
143   :type '(choice :custom-show nil
144                  regexp
145                  (repeat regexp))
146   :group 'gnus-article-hiding)
147
148 (defcustom gnus-visible-headers
149   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
150   "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153   :type '(repeat :value-to-internal (lambda (widget value)
154                                       (custom-split-regexp-maybe value))
155                  :match (lambda (widget value)
156                           (or (stringp value)
157                               (widget-editable-list-match widget value)))
158                  regexp)
159   :group 'gnus-article-hiding)
160
161 (defcustom gnus-sorted-header-list
162   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164   "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
167 this list."
168   :type '(repeat regexp)
169   :group 'gnus-article-hiding)
170
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172   "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175   :type '(set (const :tag "Headers with no content." empty)
176               (const :tag "Newsgroups with only one group." newsgroups)
177               (const :tag "Followup-to identical to newsgroups." followup-to)
178               (const :tag "Reply-to identical to from." reply-to)
179               (const :tag "Date less than four days old." date)
180               (const :tag "Very long To and/or Cc header." long-to)
181               (const :tag "Multiple To and/or Cc headers." many-to))
182   :group 'gnus-article-hiding)
183
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185   "Regexp matching signature separator.
186 This can also be a list of regexps.  In that case, it will be checked
187 from head to tail looking for a separator.  Searches will be done from
188 the end of the buffer."
189   :type '(repeat string)
190   :group 'gnus-article-signature)
191
192 (defcustom gnus-signature-limit nil
193   "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number.  If it is a floating point number, no signature may be
196 longer (in lines) than that number.  If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer.  If it is a string, it will be used as a
199 regexp.  If it matches, the text in question is not a signature."
200   :type '(choice (integer :value 200)
201                  (number :value 4.0)
202                  (function :value fun)
203                  (regexp :value ".*"))
204   :group 'gnus-article-signature)
205
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207   "Property list to use for hiding text."
208   :type 'sexp
209   :group 'gnus-article-hiding)
210
211 (defcustom gnus-article-x-face-command
212   (cond
213    ;; Fixme: This isn't the right thing for mixed graphical and and
214    ;; non-graphical frames in a session.
215    ;; gnus-xmas.el overrides this for XEmacs.
216    ((and (fboundp 'image-type-available-p)
217          (image-type-available-p 'xbm))
218     'gnus-article-display-xface)
219    ((and (not gnus-xemacs)
220          window-system
221          (module-installed-p 'x-face-mule))
222     'x-face-mule-gnus-article-display-x-face)
223    (t
224     "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
225   "*String or function to be executed to display an X-Face header.
226 If it is a string, the command will be executed in a sub-shell
227 asynchronously.  The compressed face will be piped to this command."
228   :type '(choice string
229                  (function-item gnus-article-display-xface)
230                  (function-item x-face-mule-gnus-article-display-x-face)
231                  function)
232   :group 'gnus-article-washing)
233
234 (defcustom gnus-article-x-face-too-ugly nil
235   "Regexp matching posters whose face shouldn't be shown automatically."
236   :type '(choice regexp (const nil))
237   :group 'gnus-article-washing)
238
239 (defcustom gnus-article-banner-alist nil
240   "Banner alist for stripping.
241 For example, 
242      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
243   :type '(repeat (cons symbol regexp))
244   :group 'gnus-article-washing)
245
246 (defcustom gnus-emphasis-alist
247   (let ((format
248          "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
249         (types
250          '(("_" "_" underline)
251            ("/" "/" italic)
252            ("\\*" "\\*" bold)
253            ("_/" "/_" underline-italic)
254            ("_\\*" "\\*_" underline-bold)
255            ("\\*/" "/\\*" bold-italic)
256            ("_\\*/" "/\\*_" underline-bold-italic))))
257     `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
258        2 3 gnus-emphasis-underline)
259       ,@(mapcar
260          (lambda (spec)
261            (list
262             (format format (car spec) (car (cdr spec)))
263             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
264          types)))
265   "*Alist that says how to fontify certain phrases.
266 Each item looks like this:
267
268   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
269
270 The first element is a regular expression to be matched.  The second
271 is a number that says what regular expression grouping used to find
272 the entire emphasized word.  The third is a number that says what
273 regexp grouping should be displayed and highlighted.  The fourth
274 is the face used for highlighting."
275   :type '(repeat (list :value ("" 0 0 default)
276                        regexp
277                        (integer :tag "Match group")
278                        (integer :tag "Emphasize group")
279                        face))
280   :group 'gnus-article-emphasis)
281
282 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
283   "A regexp to describe whitespace which should not be emphasized.
284 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
285 The former avoids underlining of leading and trailing whitespace,
286 and the latter avoids underlining any whitespace at all."
287   :group 'gnus-article-emphasis
288   :type 'regexp)
289
290 (defface gnus-emphasis-bold '((t (:bold t)))
291   "Face used for displaying strong emphasized text (*word*)."
292   :group 'gnus-article-emphasis)
293
294 (defface gnus-emphasis-italic '((t (:italic t)))
295   "Face used for displaying italic emphasized text (/word/)."
296   :group 'gnus-article-emphasis)
297
298 (defface gnus-emphasis-underline '((t (:underline t)))
299   "Face used for displaying underlined emphasized text (_word_)."
300   :group 'gnus-article-emphasis)
301
302 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
303   "Face used for displaying underlined bold emphasized text (_*word*_)."
304   :group 'gnus-article-emphasis)
305
306 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
307   "Face used for displaying underlined italic emphasized text (_/word/_)."
308   :group 'gnus-article-emphasis)
309
310 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
311   "Face used for displaying bold italic emphasized text (/*word*/)."
312   :group 'gnus-article-emphasis)
313
314 (defface gnus-emphasis-underline-bold-italic
315   '((t (:bold t :italic t :underline t)))
316   "Face used for displaying underlined bold italic emphasized text.
317 Esample: (_/*word*/_)."
318   :group 'gnus-article-emphasis)
319
320 (defface gnus-emphasis-highlight-words
321   '((t (:background "black" :foreground "yellow")))
322   "Face used for displaying highlighted words."
323   :group 'gnus-article-emphasis)
324
325 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
326   "Format for display of Date headers in article bodies.
327 See `format-time-string' for the possible values.
328
329 The variable can also be function, which should return a complete Date
330 header.  The function is called with one argument, the time, which can
331 be fed to `format-time-string'."
332   :type '(choice string symbol)
333   :link '(custom-manual "(gnus)Article Date")
334   :group 'gnus-article-washing)
335
336 (eval-and-compile
337   (autoload 'mail-extract-address-components "mail-extr"))
338
339 (defcustom gnus-save-all-headers t
340   "*If non-nil, don't remove any headers before saving."
341   :group 'gnus-article-saving
342   :type 'boolean)
343
344 (defcustom gnus-prompt-before-saving 'always
345   "*This variable says how much prompting is to be done when saving articles.
346 If it is nil, no prompting will be done, and the articles will be
347 saved to the default files.  If this variable is `always', each and
348 every article that is saved will be preceded by a prompt, even when
349 saving large batches of articles.  If this variable is neither nil not
350 `always', there the user will be prompted once for a file name for
351 each invocation of the saving commands."
352   :group 'gnus-article-saving
353   :type '(choice (item always)
354                  (item :tag "never" nil)
355                  (sexp :tag "once" :format "%t\n" :value t)))
356
357 (defcustom gnus-saved-headers gnus-visible-headers
358   "Headers to keep if `gnus-save-all-headers' is nil.
359 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
360 If that variable is nil, however, all headers that match this regexp
361 will be kept while the rest will be deleted before saving."
362   :group 'gnus-article-saving
363   :type 'regexp)
364
365 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
366   "A function to save articles in your favourite format.
367 The function must be interactively callable (in other words, it must
368 be an Emacs command).
369
370 Gnus provides the following functions:
371
372 * gnus-summary-save-in-rmail (Rmail format)
373 * gnus-summary-save-in-mail (Unix mail format)
374 * gnus-summary-save-in-folder (MH folder)
375 * gnus-summary-save-in-file (article format)
376 * gnus-summary-save-in-vm (use VM's folder format)
377 * gnus-summary-write-to-file (article format -- overwrite)."
378   :group 'gnus-article-saving
379   :type '(radio (function-item gnus-summary-save-in-rmail)
380                 (function-item gnus-summary-save-in-mail)
381                 (function-item gnus-summary-save-in-folder)
382                 (function-item gnus-summary-save-in-file)
383                 (function-item gnus-summary-save-in-vm)
384                 (function-item gnus-summary-write-to-file)))
385
386 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
387   "A function generating a file name to save articles in Rmail format.
388 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
389   :group 'gnus-article-saving
390   :type 'function)
391
392 (defcustom gnus-mail-save-name 'gnus-plain-save-name
393   "A function generating a file name to save articles in Unix mail format.
394 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
395   :group 'gnus-article-saving
396   :type 'function)
397
398 (defcustom gnus-folder-save-name 'gnus-folder-save-name
399   "A function generating a file name to save articles in MH folder.
400 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
401   :group 'gnus-article-saving
402   :type 'function)
403
404 (defcustom gnus-file-save-name 'gnus-numeric-save-name
405   "A function generating a file name to save articles in article format.
406 The function is called with NEWSGROUP, HEADERS, and optional
407 LAST-FILE."
408   :group 'gnus-article-saving
409   :type 'function)
410
411 (defcustom gnus-split-methods
412   '((gnus-article-archive-name)
413     (gnus-article-nndoc-name))
414   "*Variable used to suggest where articles are to be saved.
415 For instance, if you would like to save articles related to Gnus in
416 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
417 you could set this variable to something like:
418
419  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
420    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
421
422 This variable is an alist where the where the key is the match and the
423 value is a list of possible files to save in if the match is non-nil.
424
425 If the match is a string, it is used as a regexp match on the
426 article.  If the match is a symbol, that symbol will be funcalled
427 from the buffer of the article to be saved with the newsgroup as the
428 parameter.  If it is a list, it will be evaled in the same buffer.
429
430 If this form or function returns a string, this string will be used as
431 a possible file name; and if it returns a non-nil list, that list will
432 be used as possible file names."
433   :group 'gnus-article-saving
434   :type '(repeat (choice (list :value (fun) function)
435                          (cons :value ("" "") regexp (repeat string))
436                          (sexp :value nil))))
437
438 (defcustom gnus-article-display-method-for-mime
439   'gnus-article-display-mime-message
440   "Function to display a MIME message.
441 The function is called from the article buffer."
442   :group 'gnus-article-mime
443   :type 'function)
444
445 (defcustom gnus-article-display-method-for-traditional
446   'gnus-article-display-traditional-message
447   "*Function to display a traditional message.
448 The function is called from the article buffer."
449   :group 'gnus-article-mime
450   :type 'function)
451
452 (defcustom gnus-page-delimiter "^\^L"
453   "*Regexp describing what to use as article page delimiters.
454 The default value is \"^\^L\", which is a form linefeed at the
455 beginning of a line."
456   :type 'regexp
457   :group 'gnus-article-various)
458
459 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
460   "*The format specification for the article mode line.
461 See `gnus-summary-mode-line-format' for a closer description.
462
463 The following additional specs are available:
464
465 %w  The article washing status.
466 %m  The number of MIME parts in the article."
467   :type 'string
468   :group 'gnus-article-various)
469
470 (defcustom gnus-article-mode-hook nil
471   "*A hook for Gnus article mode."
472   :type 'hook
473   :group 'gnus-article-various)
474
475 (defcustom gnus-article-menu-hook nil
476   "*Hook run after the creation of the article mode menu."
477   :type 'hook
478   :group 'gnus-article-various)
479
480 (defcustom gnus-article-prepare-hook nil
481   "*A hook called after an article has been prepared in the article buffer."
482   :type 'hook
483   :group 'gnus-article-various)
484
485 (defcustom gnus-article-hide-pgp-hook nil
486   "*A hook called after successfully hiding a PGP signature."
487   :type 'hook
488   :group 'gnus-article-various)
489
490 (defcustom gnus-article-button-face 'bold
491   "Face used for highlighting buttons in the article buffer.
492
493 An article button is a piece of text that you can activate by pressing
494 `RET' or `mouse-2' above it."
495   :type 'face
496   :group 'gnus-article-buttons)
497
498 (defcustom gnus-article-mouse-face 'highlight
499   "Face used for mouse highlighting in the article buffer.
500
501 Article buttons will be displayed in this face when the cursor is
502 above them."
503   :type 'face
504   :group 'gnus-article-buttons)
505
506 (defcustom gnus-signature-face 'gnus-signature-face
507   "Face used for highlighting a signature in the article buffer.
508 Obsolete; use the face `gnus-signature-face' for customizations instead."
509   :type 'face
510   :group 'gnus-article-highlight
511   :group 'gnus-article-signature)
512
513 (defface gnus-signature-face
514   '((t (:italic t)))
515   "Face used for highlighting a signature in the article buffer."
516   :group 'gnus-article-highlight
517   :group 'gnus-article-signature)
518
519 (defface gnus-header-from-face
520   '((((class color)
521       (background dark))
522      (:foreground "spring green"))
523     (((class color)
524       (background light))
525      (:foreground "red3"))
526     (t
527      (:italic t)))
528   "Face used for displaying from headers."
529   :group 'gnus-article-headers
530   :group 'gnus-article-highlight)
531
532 (defface gnus-header-subject-face
533   '((((class color)
534       (background dark))
535      (:foreground "SeaGreen3"))
536     (((class color)
537       (background light))
538      (:foreground "red4"))
539     (t
540      (:bold t :italic t)))
541   "Face used for displaying subject headers."
542   :group 'gnus-article-headers
543   :group 'gnus-article-highlight)
544
545 (defface gnus-header-newsgroups-face
546   '((((class color)
547       (background dark))
548      (:foreground "yellow" :italic t))
549     (((class color)
550       (background light))
551      (:foreground "MidnightBlue" :italic t))
552     (t
553      (:italic t)))
554   "Face used for displaying newsgroups headers."
555   :group 'gnus-article-headers
556   :group 'gnus-article-highlight)
557
558 (defface gnus-header-name-face
559   '((((class color)
560       (background dark))
561      (:foreground "SeaGreen"))
562     (((class color)
563       (background light))
564      (:foreground "maroon"))
565     (t
566      (:bold t)))
567   "Face used for displaying header names."
568   :group 'gnus-article-headers
569   :group 'gnus-article-highlight)
570
571 (defface gnus-header-content-face
572   '((((class color)
573       (background dark))
574      (:foreground "forest green" :italic t))
575     (((class color)
576       (background light))
577      (:foreground "indianred4" :italic t))
578     (t
579      (:italic t)))  "Face used for displaying header content."
580   :group 'gnus-article-headers
581   :group 'gnus-article-highlight)
582
583 (defcustom gnus-header-face-alist
584   '(("From" nil gnus-header-from-face)
585     ("Subject" nil gnus-header-subject-face)
586     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
587     ("" gnus-header-name-face gnus-header-content-face))
588   "*Controls highlighting of article header.
589
590 An alist of the form (HEADER NAME CONTENT).
591
592 HEADER is a regular expression which should match the name of an
593 header header and NAME and CONTENT are either face names or nil.
594
595 The name of each header field will be displayed using the face
596 specified by the first element in the list where HEADER match the
597 header name and NAME is non-nil.  Similarly, the content will be
598 displayed by the first non-nil matching CONTENT face."
599   :group 'gnus-article-headers
600   :group 'gnus-article-highlight
601   :type '(repeat (list (regexp :tag "Header")
602                        (choice :tag "Name"
603                                (item :tag "skip" nil)
604                                (face :value default))
605                        (choice :tag "Content"
606                                (item :tag "skip" nil)
607                                (face :value default)))))
608
609 (defcustom gnus-article-decode-hook nil
610   "*Hook run to decode charsets in articles."
611   :group 'gnus-article-headers
612   :type 'hook)
613
614 (defcustom gnus-display-mime-function 'gnus-display-mime
615   "Function to display MIME articles."
616   :group 'gnus-article-mime
617   :type 'function)
618
619 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
620   "Function used to decode headers.")
621
622 (defvar gnus-article-dumbquotes-map
623   '(("\202" ",")
624     ("\203" "f")
625     ("\204" ",,")
626     ("\205" "...")
627     ("\213" "<")
628     ("\214" "OE")
629     ("\221" "`")
630     ("\222" "'")
631     ("\223" "``")
632     ("\224" "\"")
633     ("\225" "*")
634     ("\226" "---")
635     ("\227" "-")
636     ("\231" "(TM)")
637     ("\233" ">")
638     ("\234" "oe")
639     ("\264" "'"))
640   "Table for MS-to-Latin1 translation.")
641
642 (defcustom gnus-ignored-mime-types nil
643   "List of MIME types that should be ignored by Gnus."
644   :group 'gnus-article-mime
645   :type '(repeat regexp))
646
647 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
648   "List of MIME types that should not be given buttons when rendered inline."
649   :group 'gnus-article-mime
650   :type '(repeat regexp))
651
652 (defcustom gnus-article-mime-part-function nil
653   "Function called with a MIME handle as the argument.
654 This is meant for people who want to do something automatic based
655 on parts -- for instance, adding Vcard info to a database."
656   :group 'gnus-article-mime
657   :type 'function)
658
659 (defcustom gnus-mime-multipart-functions nil
660   "An alist of MIME types to functions to display them.")
661
662 (defcustom gnus-article-date-lapsed-new-header nil
663   "Whether the X-Sent and Date headers can coexist.
664 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
665 either replace the old \"Date:\" header (if this variable is nil), or
666 be added below it (otherwise)."
667   :group 'gnus-article-headers
668   :type 'boolean)
669
670 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
671   "Function called with a MIME handle as the argument.
672 This is meant for people who want to view first matched part.
673 For `undisplayed-alternative' (default), the first undisplayed 
674 part or alternative part is used.  For `undisplayed', the first 
675 undisplayed part is used.  For a function, the first part which 
676 the function return `t' is used.  For `nil', the first part is
677 used."
678   :group 'gnus-article-mime
679   :type '(choice 
680           (item :tag "first" :value nil)
681           (item :tag "undisplayed" :value undisplayed)
682           (item :tag "undisplayed or alternative" 
683                 :value undisplayed-alternative)
684           (function)))
685
686 ;;;
687 ;;; The treatment variables
688 ;;;
689
690 (defvar gnus-part-display-hook nil
691   "Hook called on parts that are to receive treatment.")
692
693 (defvar gnus-article-treat-custom
694   '(choice (const :tag "Off" nil)
695            (const :tag "On" t)
696            (const :tag "Header" head)
697            (const :tag "Last" last)
698            (const :tag "Mime" mime)
699            (integer :tag "Less")
700            (repeat :tag "Groups" regexp)
701            (sexp :tag "Predicate")))
702
703 (defvar gnus-article-treat-head-custom
704   '(choice (const :tag "Off" nil)
705            (const :tag "Header" head)))
706
707 (defvar gnus-article-treat-types '("text/plain")
708   "Parts to treat.")
709
710 (defvar gnus-inhibit-treatment nil
711   "Whether to inhibit treatment.")
712
713 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
714   "Highlight the signature.
715 Valid values are nil, t, `head', `last', an integer or a predicate.
716 See the manual for details."
717   :group 'gnus-article-treat
718   :type gnus-article-treat-custom)
719 (put 'gnus-treat-highlight-signature 'highlight t)
720
721 (defcustom gnus-treat-buttonize 100000
722   "Add buttons.
723 Valid values are nil, t, `head', `last', an integer or a predicate.
724 See the manual for details."
725   :group 'gnus-article-treat
726   :type gnus-article-treat-custom)
727 (put 'gnus-treat-buttonize 'highlight t)
728
729 (defcustom gnus-treat-buttonize-head 'head
730   "Add buttons to the head.
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733   :group 'gnus-article-treat
734   :type gnus-article-treat-head-custom)
735 (put 'gnus-treat-buttonize-head 'highlight t)
736
737 (defcustom gnus-treat-emphasize nil
738   "Emphasize text.
739 Valid values are nil, t, `head', `last', an integer or a predicate.
740 See the manual for details."
741   :group 'gnus-article-treat
742   :type gnus-article-treat-custom)
743 (put 'gnus-treat-emphasize 'highlight t)
744
745 (defcustom gnus-treat-strip-cr nil
746   "Remove carriage returns.
747 Valid values are nil, t, `head', `last', an integer or a predicate.
748 See the manual for details."
749   :group 'gnus-article-treat
750   :type gnus-article-treat-custom)
751
752 (defcustom gnus-treat-hide-headers 'head
753   "Hide headers.
754 Valid values are nil, t, `head', `last', an integer or a predicate.
755 See the manual for details."
756   :group 'gnus-article-treat
757   :type gnus-article-treat-head-custom)
758
759 (defcustom gnus-treat-hide-boring-headers nil
760   "Hide boring headers.
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763   :group 'gnus-article-treat
764   :type gnus-article-treat-head-custom)
765
766 (defcustom gnus-treat-hide-signature nil
767   "Hide the signature.
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770   :group 'gnus-article-treat
771   :type gnus-article-treat-custom)
772
773 (defcustom gnus-treat-fill-article nil
774   "Fill the article.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777   :group 'gnus-article-treat
778   :type gnus-article-treat-custom)
779
780 (defcustom gnus-treat-hide-citation nil
781   "Hide cited text.
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784   :group 'gnus-article-treat
785   :type gnus-article-treat-custom)
786
787 (defcustom gnus-treat-strip-list-identifiers 'head
788   "Strip list identifiers from `gnus-list-identifiers`.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791   :group 'gnus-article-treat
792   :type gnus-article-treat-custom)
793
794 (defcustom gnus-treat-strip-pgp t
795   "Strip PGP signatures.
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798   :group 'gnus-article-treat
799   :type gnus-article-treat-custom)
800
801 (defcustom gnus-treat-strip-pem nil
802   "Strip PEM signatures.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805   :group 'gnus-article-treat
806   :type gnus-article-treat-custom)
807
808 (defcustom gnus-treat-strip-banner t
809   "Strip banners from articles.
810 The banner to be stripped is specified in the `banner' group parameter.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813   :group 'gnus-article-treat
814   :type gnus-article-treat-custom)
815
816 (defcustom gnus-treat-highlight-headers 'head
817   "Highlight the headers.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820   :group 'gnus-article-treat
821   :type gnus-article-treat-head-custom)
822 (put 'gnus-treat-highlight-headers 'highlight t)
823
824 (defcustom gnus-treat-highlight-citation t
825   "Highlight cited text.
826 Valid values are nil, t, `head', `last', an integer or a predicate.
827 See the manual for details."
828   :group 'gnus-article-treat
829   :type gnus-article-treat-custom)
830 (put 'gnus-treat-highlight-citation 'highlight t)
831
832 (defcustom gnus-treat-date-ut nil
833   "Display the Date in UT (GMT).
834 Valid values are nil, t, `head', `last', an integer or a predicate.
835 See the manual for details."
836   :group 'gnus-article-treat
837   :type gnus-article-treat-head-custom)
838
839 (defcustom gnus-treat-date-local nil
840   "Display the Date in the local timezone.
841 Valid values are nil, t, `head', `last', an integer or a predicate.
842 See the manual for details."
843   :group 'gnus-article-treat
844   :type gnus-article-treat-head-custom)
845
846 (defcustom gnus-treat-date-lapsed nil
847   "Display the Date header in a way that says how much time has elapsed.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See the manual for details."
850   :group 'gnus-article-treat
851   :type gnus-article-treat-head-custom)
852
853 (defcustom gnus-treat-date-original nil
854   "Display the date in the original timezone.
855 Valid values are nil, t, `head', `last', an integer or a predicate.
856 See the manual for details."
857   :group 'gnus-article-treat
858   :type gnus-article-treat-head-custom)
859
860 (defcustom gnus-treat-date-iso8601 nil
861   "Display the date in the ISO8601 format.
862 Valid values are nil, t, `head', `last', an integer or a predicate.
863 See the manual for details."
864   :group 'gnus-article-treat
865   :type gnus-article-treat-head-custom)
866
867 (defcustom gnus-treat-date-user-defined nil
868   "Display the date in a user-defined format.
869 The format is defined by the `gnus-article-time-format' variable.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See the manual for details."
872   :group 'gnus-article-treat
873   :type gnus-article-treat-head-custom)
874
875 (defcustom gnus-treat-strip-headers-in-body t
876   "Strip the X-No-Archive header line from the beginning of the body.
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See the manual for details."
879   :group 'gnus-article-treat
880   :type gnus-article-treat-custom)
881
882 (defcustom gnus-treat-strip-trailing-blank-lines nil
883   "Strip trailing blank lines.
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886   :group 'gnus-article-treat
887   :type gnus-article-treat-custom)
888
889 (defcustom gnus-treat-strip-leading-blank-lines nil
890   "Strip leading blank lines.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893   :group 'gnus-article-treat
894   :type gnus-article-treat-custom)
895
896 (defcustom gnus-treat-strip-multiple-blank-lines nil
897   "Strip multiple blank lines.
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900   :group 'gnus-article-treat
901   :type gnus-article-treat-custom)
902
903 (defcustom gnus-treat-overstrike t
904   "Treat overstrike highlighting.
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See the manual for details."
907   :group 'gnus-article-treat
908   :type gnus-article-treat-custom)
909 (put 'gnus-treat-overstrike 'highlight t)
910
911 (defcustom gnus-treat-display-xface
912   (and (or (and (fboundp 'image-type-available-p)
913                 (image-type-available-p 'xbm))
914            (and gnus-xemacs (featurep 'xface))
915            (eq 'x-face-mule-gnus-article-display-x-face
916                gnus-article-x-face-command))
917        'head)
918   "Display X-Face headers.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921   :group 'gnus-article-treat
922   :type gnus-article-treat-head-custom)
923 (put 'gnus-treat-display-xface 'highlight t)
924
925 (defcustom gnus-treat-display-smileys
926   (if (or (and gnus-xemacs (featurep 'xpm))
927           (and (not gnus-xemacs)
928                window-system
929                (module-installed-p 'gnus-bitmap)))
930       t
931     nil)
932   "Display smileys.
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
935   :group 'gnus-article-treat
936   :type gnus-article-treat-custom)
937 (put 'gnus-treat-display-smileys 'highlight t)
938
939 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
940   "Display picons.
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943   :group 'gnus-article-treat
944   :type gnus-article-treat-head-custom)
945 (put 'gnus-treat-display-picons 'highlight t)
946
947 (defcustom gnus-treat-capitalize-sentences nil
948   "Capitalize sentence-starting words.
949 Valid values are nil, t, `head', `last', an integer or a predicate.
950 See the manual for details."
951   :group 'gnus-article-treat
952   :type gnus-article-treat-custom)
953
954 (defcustom gnus-treat-fill-long-lines nil
955   "Fill long lines.
956 Valid values are nil, t, `head', `last', an integer or a predicate.
957 See the manual for details."
958   :group 'gnus-article-treat
959   :type gnus-article-treat-custom)
960
961 (defcustom gnus-treat-play-sounds nil
962   "Play sounds.
963 Valid values are nil, t, `head', `last', an integer or a predicate.
964 See the manual for details."
965   :group 'gnus-article-treat
966   :type gnus-article-treat-custom)
967
968 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
969   "Decode an article as `default-mime-charset'.  For instance, if you want to
970 attempt to decode an article even if the value of `gnus-show-mime' is nil,
971 you could set this variable to something like: nil for don't decode, t for
972 decode the body, '(or header t) for the whole article, etc."
973   :group 'gnus-article-treat
974   :type '(radio (const :tag "Off" nil)
975                 (const :tag "Decode body" t)
976                 (const :tag "Decode all" (or head t))))
977
978 (defcustom gnus-treat-translate nil
979   "Translate articles from one language to another.
980 Valid values are nil, t, `head', `last', an integer or a predicate.
981 See the manual for details."
982   :group 'gnus-article-treat
983   :type gnus-article-treat-custom)
984
985 ;;; Internal variables
986
987 (defvar article-goto-body-goes-to-point-min-p nil)
988 (defvar gnus-article-wash-types nil)
989 (defvar gnus-article-emphasis-alist nil)
990
991 (defvar gnus-article-mime-handle-alist-1 nil)
992 (defvar gnus-treatment-function-alist
993   '((gnus-treat-decode-article-as-default-mime-charset
994      gnus-article-decode-article-as-default-mime-charset)
995     (gnus-treat-strip-banner gnus-article-strip-banner)
996     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
997     (gnus-treat-buttonize gnus-article-add-buttons)
998     (gnus-treat-fill-article gnus-article-fill-cited-article)
999     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1000     (gnus-treat-strip-cr gnus-article-remove-cr)
1001     (gnus-treat-display-xface gnus-article-display-x-face)
1002     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1003     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1004     (gnus-treat-hide-signature gnus-article-hide-signature)
1005     (gnus-treat-hide-citation gnus-article-hide-citation)
1006     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1007     (gnus-treat-strip-pgp gnus-article-hide-pgp)
1008     (gnus-treat-strip-pem gnus-article-hide-pem)
1009     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1010     (gnus-treat-emphasize gnus-article-emphasize)
1011     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1012     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1013     (gnus-treat-date-ut gnus-article-date-ut)
1014     (gnus-treat-date-local gnus-article-date-local)
1015     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1016     (gnus-treat-date-original gnus-article-date-original)
1017     (gnus-treat-date-user-defined gnus-article-date-user)
1018     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1019     (gnus-treat-strip-trailing-blank-lines
1020      gnus-article-remove-trailing-blank-lines)
1021     (gnus-treat-strip-leading-blank-lines
1022      gnus-article-strip-leading-blank-lines)
1023     (gnus-treat-strip-multiple-blank-lines
1024      gnus-article-strip-multiple-blank-lines)
1025     (gnus-treat-overstrike gnus-article-treat-overstrike)
1026     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1027     (gnus-treat-display-smileys gnus-article-smiley-display)
1028     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1029     (gnus-treat-display-picons gnus-article-display-picons)
1030     (gnus-treat-play-sounds gnus-earcon-display)))
1031
1032 (defvar gnus-article-mime-handle-alist nil)
1033 (defvar article-lapsed-timer nil)
1034 (defvar gnus-article-current-summary nil)
1035
1036 (defvar gnus-article-mode-syntax-table
1037   (let ((table (copy-syntax-table text-mode-syntax-table)))
1038     (modify-syntax-entry ?- "w" table)
1039     (modify-syntax-entry ?> ")" table)
1040     (modify-syntax-entry ?< "(" table)
1041     table)
1042   "Syntax table used in article mode buffers.
1043 Initialized from `text-mode-syntax-table.")
1044
1045 (defvar gnus-save-article-buffer nil)
1046
1047 (defvar gnus-article-mode-line-format-alist
1048   (nconc '((?w (gnus-article-wash-status) ?s)
1049            (?m (gnus-article-mime-part-status) ?s))
1050          gnus-summary-mode-line-format-alist))
1051
1052 (defvar gnus-number-of-articles-to-be-saved nil)
1053
1054 (defvar gnus-inhibit-hiding nil)
1055
1056 (defsubst gnus-article-hide-text (b e props)
1057   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1058   (add-text-properties b e props)
1059   (when (memq 'intangible props)
1060     (put-text-property
1061      (max (1- b) (point-min))
1062      b 'intangible (cddr (memq 'intangible props)))))
1063 (defsubst gnus-article-unhide-text (b e)
1064   "Remove hidden text properties from region between B and E."
1065   (remove-text-properties b e gnus-hidden-properties)
1066   (when (memq 'intangible gnus-hidden-properties)
1067     (put-text-property (max (1- b) (point-min))
1068                        b 'intangible nil)))
1069
1070 (defun gnus-article-hide-text-type (b e type)
1071   "Hide text of TYPE between B and E."
1072   (push type gnus-article-wash-types)
1073   (gnus-article-hide-text
1074    b e (cons 'article-type (cons type gnus-hidden-properties))))
1075
1076 (defun gnus-article-unhide-text-type (b e type)
1077   "Unhide text of TYPE between B and E."
1078   (setq gnus-article-wash-types
1079         (delq type gnus-article-wash-types))
1080   (remove-text-properties
1081    b e (cons 'article-type (cons type gnus-hidden-properties)))
1082   (when (memq 'intangible gnus-hidden-properties)
1083     (put-text-property (max (1- b) (point-min))
1084                        b 'intangible nil)))
1085
1086 (defun gnus-article-hide-text-of-type (type)
1087   "Hide text of TYPE in the current buffer."
1088   (save-excursion
1089     (let ((b (point-min))
1090           (e (point-max)))
1091       (while (setq b (text-property-any b e 'article-type type))
1092         (add-text-properties b (incf b) gnus-hidden-properties)))))
1093
1094 (defun gnus-article-delete-text-of-type (type)
1095   "Delete text of TYPE in the current buffer."
1096   (save-excursion
1097     (let ((b (point-min)))
1098       (while (setq b (text-property-any b (point-max) 'article-type type))
1099         (delete-region
1100          b (or (text-property-not-all b (point-max) 'article-type type)
1101                (point-max)))))))
1102
1103 (defun gnus-article-delete-invisible-text ()
1104   "Delete all invisible text in the current buffer."
1105   (save-excursion
1106     (let ((b (point-min)))
1107       (while (setq b (text-property-any b (point-max) 'invisible t))
1108         (delete-region
1109          b (or (text-property-not-all b (point-max) 'invisible t)
1110                (point-max)))))))
1111
1112 (defun gnus-article-text-type-exists-p (type)
1113   "Say whether any text of type TYPE exists in the buffer."
1114   (text-property-any (point-min) (point-max) 'article-type type))
1115
1116 (defsubst gnus-article-header-rank ()
1117   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1118   (let ((list gnus-sorted-header-list)
1119         (i 0))
1120     (while list
1121       (when (looking-at (car list))
1122         (setq list nil))
1123       (setq list (cdr list))
1124       (incf i))
1125     i))
1126
1127 (defun article-hide-headers (&optional arg delete)
1128   "Hide unwanted headers and possibly sort them as well."
1129   (interactive (gnus-article-hidden-arg))
1130   ;; Lars said that this function might be inhibited.
1131   (if (gnus-article-check-hidden-text 'headers arg)
1132       (progn
1133         ;; Show boring headers as well.
1134         (gnus-article-show-hidden-text 'boring-headers)
1135         (when (eq 1 (point-min))
1136           (set-window-start (get-buffer-window (current-buffer)) 1)))
1137   (unless gnus-inhibit-hiding
1138     (save-excursion
1139       (save-restriction
1140         (let ((buffer-read-only nil)
1141               (inhibit-read-only t)
1142               (case-fold-search t)
1143               (max (1+ (length gnus-sorted-header-list)))
1144               (ignored (when (not gnus-visible-headers)
1145                          (cond ((stringp gnus-ignored-headers)
1146                                 gnus-ignored-headers)
1147                                ((listp gnus-ignored-headers)
1148                                 (mapconcat 'identity gnus-ignored-headers
1149                                            "\\|")))))
1150               (visible
1151                (cond ((stringp gnus-visible-headers)
1152                       gnus-visible-headers)
1153                      ((and gnus-visible-headers
1154                            (listp gnus-visible-headers))
1155                       (mapconcat 'identity gnus-visible-headers "\\|"))))
1156               (inhibit-point-motion-hooks t)
1157               beg)
1158           ;; First we narrow to just the headers.
1159           (article-narrow-to-head)
1160           ;; Hide any "From " lines at the beginning of (mail) articles.
1161           (while (looking-at "From ")
1162             (forward-line 1))
1163           (unless (bobp)
1164             (if delete
1165                 (delete-region (point-min) (point))
1166               (gnus-article-hide-text (point-min) (point)
1167                                       (nconc (list 'article-type 'headers)
1168                                              gnus-hidden-properties))))
1169           ;; Then treat the rest of the header lines.
1170           ;; Then we use the two regular expressions
1171           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1172           ;; select which header lines is to remain visible in the
1173           ;; article buffer.
1174           (while (re-search-forward "^[^ \t]*:" nil t)
1175             (beginning-of-line)
1176             ;; Mark the rank of the header.
1177             (put-text-property
1178              (point) (1+ (point)) 'message-rank
1179              (if (or (and visible (looking-at visible))
1180                      (and ignored
1181                           (not (looking-at ignored))))
1182                  (gnus-article-header-rank)
1183                (+ 2 max)))
1184             (forward-line 1))
1185           (message-sort-headers-1)
1186           (when (setq beg (text-property-any
1187                            (point-min) (point-max) 'message-rank (+ 2 max)))
1188             ;; We delete or make invisible the unwanted headers.
1189             (push 'headers gnus-article-wash-types)
1190             (if delete
1191                 (progn
1192                   (add-text-properties
1193                    (point-min) (+ 5 (point-min))
1194                    '(article-type headers dummy-invisible t))
1195                   (delete-region beg (point-max)))
1196               (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1197   )
1198
1199 (defun article-hide-boring-headers (&optional arg)
1200   "Toggle hiding of headers that aren't very interesting.
1201 If given a negative prefix, always show; if given a positive prefix,
1202 always hide."
1203   (interactive (gnus-article-hidden-arg))
1204   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1205              (not gnus-show-all-headers))
1206     (save-excursion
1207       (save-restriction
1208         (let ((buffer-read-only nil)
1209               (list gnus-boring-article-headers)
1210               (inhibit-point-motion-hooks t)
1211               elem)
1212           (article-narrow-to-head)
1213           (while list
1214             (setq elem (pop list))
1215             (goto-char (point-min))
1216             (cond
1217              ;; Hide empty headers.
1218              ((eq elem 'empty)
1219               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1220                 (forward-line -1)
1221                 (gnus-article-hide-text-type
1222                  (progn (beginning-of-line) (point))
1223                  (progn
1224                    (end-of-line)
1225                    (if (re-search-forward "^[^ \t]" nil t)
1226                        (match-beginning 0)
1227                      (point-max)))
1228                  'boring-headers)))
1229              ;; Hide boring Newsgroups header.
1230              ((eq elem 'newsgroups)
1231               (when (equal (gnus-fetch-field "newsgroups")
1232                            (gnus-group-real-name
1233                             (if (boundp 'gnus-newsgroup-name)
1234                                 gnus-newsgroup-name
1235                               "")))
1236                 (gnus-article-hide-header "newsgroups")))
1237              ((eq elem 'followup-to)
1238               (when (equal (message-fetch-field "followup-to")
1239                            (message-fetch-field "newsgroups"))
1240                 (gnus-article-hide-header "followup-to")))
1241              ((eq elem 'reply-to)
1242               (let ((from (message-fetch-field "from"))
1243                     (reply-to (message-fetch-field "reply-to")))
1244                 (when (and
1245                        from reply-to
1246                        (ignore-errors
1247                          (equal
1248                           (nth 1 (funcall gnus-extract-address-components from))
1249                           (nth 1 (funcall gnus-extract-address-components reply-to)))))
1250                   (gnus-article-hide-header "reply-to"))))
1251              ((eq elem 'date)
1252               (let ((date (message-fetch-field "date")))
1253                 (when (and date
1254                            (< (days-between (current-time-string) date)
1255                               4))
1256                   (gnus-article-hide-header "date"))))
1257              ((eq elem 'long-to)
1258               (let ((to (message-fetch-field "to"))
1259                     (cc (message-fetch-field "cc")))
1260                 (when (> (length to) 1024)
1261                   (gnus-article-hide-header "to"))
1262                 (when (> (length cc) 1024)
1263                   (gnus-article-hide-header "cc"))))
1264              ((eq elem 'many-to)
1265               (let ((to-count 0)
1266                     (cc-count 0))
1267                 (goto-char (point-min))
1268                 (while (re-search-forward "^to:" nil t)
1269                   (setq to-count (1+ to-count)))
1270                 (when (> to-count 1)
1271                   (while (> to-count 0)
1272                     (goto-char (point-min))
1273                     (save-restriction
1274                       (re-search-forward "^to:" nil nil to-count)
1275                       (forward-line -1)
1276                       (narrow-to-region (point) (point-max))
1277                       (gnus-article-hide-header "to"))
1278                     (setq to-count (1- to-count))))
1279                 (goto-char (point-min))
1280                 (while (re-search-forward "^cc:" nil t)
1281                   (setq cc-count (1+ cc-count)))
1282                 (when (> cc-count 1)
1283                   (while (> cc-count 0)
1284                     (goto-char (point-min))
1285                     (save-restriction
1286                       (re-search-forward "^cc:" nil nil cc-count)
1287                       (forward-line -1)
1288                       (narrow-to-region (point) (point-max))
1289                       (gnus-article-hide-header "cc"))
1290                     (setq cc-count (1- cc-count)))))))))))))
1291
1292 (defun gnus-article-hide-header (header)
1293   (save-excursion
1294     (goto-char (point-min))
1295     (when (re-search-forward (concat "^" header ":") nil t)
1296       (gnus-article-hide-text-type
1297        (progn (beginning-of-line) (point))
1298        (progn
1299          (end-of-line)
1300          (if (re-search-forward "^[^ \t]" nil t)
1301              (match-beginning 0)
1302            (point-max)))
1303        'boring-headers))))
1304
1305 (defun article-toggle-headers (&optional arg)
1306   "Toggle hiding of headers.  If given a negative prefix, always show;
1307 if given a positive prefix, always hide."
1308   (interactive (gnus-article-hidden-arg))
1309   (let ((force (when (numberp arg)
1310                  (cond ((> arg 0) 'always-hide)
1311                        ((< arg 0) 'always-show))))
1312         (window (get-buffer-window gnus-article-buffer))
1313         (header-end (point-min))
1314         header-start field-end field-start
1315         (inhibit-point-motion-hooks t)
1316         (inhibit-read-only t)
1317         buffer-read-only)
1318     (save-restriction
1319       (widen)
1320       (while (and (setq header-start
1321                         (text-property-any header-end (point-max)
1322                                            'article-treated-header t))
1323                   (setq header-end
1324                         (text-property-not-all header-start (point-max)
1325                                                'article-treated-header t)))
1326         (setq field-end header-start)
1327         (cond
1328          (;; Hide exposed invisible fields.
1329           (and (not (eq 'always-show force))
1330                (setq field-start
1331                      (text-property-any field-end header-end
1332                                         'exposed-invisible-field t)))
1333           (while (and field-start
1334                       (setq field-end (text-property-not-all
1335                                        field-start header-end
1336                                        'exposed-invisible-field t)))
1337             (add-text-properties field-start field-end gnus-hidden-properties)
1338             (setq field-start (text-property-any field-end header-end
1339                                                  'exposed-invisible-field t)))
1340           (put-text-property header-start header-end
1341                              'exposed-invisible-field nil))
1342          (;; Expose invisible fields.
1343           (and (not (eq 'always-hide force))
1344                (setq field-start
1345                      (text-property-any field-end header-end 'invisible t)))
1346           (while (and field-start
1347                       (setq field-end (text-property-not-all
1348                                        field-start header-end
1349                                        'invisible t)))
1350             ;; If the invisible text is not terminated with newline, we
1351             ;; won't expose it.  Because it may be created by x-face-mule.
1352             ;; BTW, XEmacs sometimes fail in putting a invisible text
1353             ;; property with `gnus-article-hide-text' (really?).  In that
1354             ;; case, the invisible text might be started from the middle of
1355             ;; a line so we will expose the sort of thing.
1356             (when (or (not (or (eq header-start field-start)
1357                                (eq ?\n (char-before field-start))))
1358                       (eq ?\n (char-before field-end)))
1359               (remove-text-properties field-start field-end
1360                                       gnus-hidden-properties)
1361               (put-text-property field-start field-end
1362                                  'exposed-invisible-field t))
1363             (setq field-start (text-property-any field-end header-end
1364                                                  'invisible t))))
1365          (;; Hide fields.
1366           (not (eq 'always-show force))
1367           (narrow-to-region header-start header-end)
1368           (article-hide-headers)
1369           ;; Re-display X-Face image under XEmacs.
1370           (when (and gnus-xemacs
1371                      (gnus-functionp gnus-article-x-face-command))
1372             (let ((func (cadr (assq 'gnus-treat-display-xface
1373                                     gnus-treatment-function-alist)))
1374                   (condition 'head))
1375               (when (and (not gnus-inhibit-treatment)
1376                          func
1377                          (gnus-treat-predicate gnus-treat-display-xface))
1378                 (funcall func)
1379                 (put-text-property header-start header-end 'read-only nil))))
1380           (widen))
1381          ))
1382       (goto-char (point-min))
1383       (when window
1384         (set-window-start window (point-min))))))
1385
1386 (defvar gnus-article-normalized-header-length 40
1387   "Length of normalized headers.")
1388
1389 (defun article-normalize-headers ()
1390   "Make all header lines 40 characters long."
1391   (interactive)
1392   (let ((buffer-read-only nil)
1393         column)
1394     (save-excursion
1395       (save-restriction
1396         (article-narrow-to-head)
1397         (while (not (eobp))
1398           (cond
1399            ((< (setq column (- (gnus-point-at-eol) (point)))
1400                gnus-article-normalized-header-length)
1401             (end-of-line)
1402             (insert (make-string
1403                      (- gnus-article-normalized-header-length column)
1404                      ? )))
1405            ((> column gnus-article-normalized-header-length)
1406             (gnus-put-text-property
1407              (progn
1408                (forward-char gnus-article-normalized-header-length)
1409                (point))
1410              (gnus-point-at-eol)
1411              'invisible t))
1412            (t
1413             ;; Do nothing.
1414             ))
1415           (forward-line 1))))))
1416
1417 (defun article-treat-dumbquotes ()
1418   "Translate M******** sm*rtq**t*s into proper text.
1419 Note that this function guesses whether a character is a sm*rtq**t* or
1420 not, so it should only be used interactively."
1421   (interactive)
1422   (article-translate-strings gnus-article-dumbquotes-map))
1423
1424 (defun article-translate-characters (from to)
1425   "Translate all characters in the body of the article according to FROM and TO.
1426 FROM is a string of characters to translate from; to is a string of
1427 characters to translate to."
1428   (save-excursion
1429     (when (article-goto-body)
1430       (let ((buffer-read-only nil)
1431             (x (make-string 225 ?x))
1432             (i -1))
1433         (while (< (incf i) (length x))
1434           (aset x i i))
1435         (setq i 0)
1436         (while (< i (length from))
1437           (aset x (aref from i) (aref to i))
1438           (incf i))
1439         (translate-region (point) (point-max) x)))))
1440
1441 (defun article-translate-strings (map)
1442   "Translate all string in the body of the article according to MAP.
1443 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1444   (save-excursion
1445     (when (article-goto-body)
1446       (let ((buffer-read-only nil)
1447             elem)
1448         (while (setq elem (pop map))
1449           (save-excursion
1450             (while (search-forward (car elem) nil t)
1451               (replace-match (cadr elem)))))))))
1452
1453 (defun article-treat-overstrike ()
1454   "Translate overstrikes into bold text."
1455   (interactive)
1456   (save-excursion
1457     (when (article-goto-body)
1458       (let ((buffer-read-only nil))
1459         (while (search-forward "\b" nil t)
1460           (let ((next (char-after))
1461                 start end previous)
1462             (backward-char 2)
1463             (setq start (point)
1464                   previous (char-after))
1465             (forward-char 3)
1466             (setq end (point))
1467             (backward-char)
1468             ;; We do the boldification/underlining by hiding the
1469             ;; overstrikes and putting the proper text property
1470             ;; on the letters.
1471             (cond
1472              ((eq next previous)
1473               (gnus-article-hide-text-type start (point) 'overstrike)
1474               (put-text-property (point) end 'face 'bold))
1475              ((eq next ?_)
1476               (gnus-article-hide-text-type
1477                (1- (point)) (1+ (point)) 'overstrike)
1478               (put-text-property
1479                start (1- (point)) 'face 'underline))
1480              ((eq previous ?_)
1481               (gnus-article-hide-text-type start (point) 'overstrike)
1482               (put-text-property
1483                (point) end 'face 'underline)))))))))
1484
1485 (defun article-fill-long-lines ()
1486   "Fill lines that are wider than the window width."
1487   (interactive)
1488   (save-excursion
1489     (let ((buffer-read-only nil)
1490           (width (window-width (get-buffer-window (current-buffer)))))
1491       (save-restriction
1492         (article-goto-body)
1493         (let ((adaptive-fill-mode nil))
1494           (while (not (eobp))
1495             (end-of-line)
1496             (when (>= (current-column) (min fill-column width))
1497               (narrow-to-region (point) (gnus-point-at-bol))
1498               (fill-paragraph nil)
1499               (goto-char (point-max))
1500               (widen))
1501             (forward-line 1)))))))
1502
1503 (defun article-capitalize-sentences ()
1504   "Capitalize the first word in each sentence."
1505   (interactive)
1506   (save-excursion
1507     (let ((buffer-read-only nil)
1508           (paragraph-start "^[\n\^L]"))
1509       (article-goto-body)
1510       (while (not (eobp))
1511         (capitalize-word 1)
1512         (forward-sentence)))))
1513
1514 (defun article-remove-cr ()
1515   "Remove trailing CRs and then translate remaining CRs into LFs."
1516   (interactive)
1517   (save-excursion
1518     (let ((buffer-read-only nil))
1519       (goto-char (point-min))
1520       (while (re-search-forward "\r+$" nil t)
1521         (replace-match "" t t))
1522       (goto-char (point-min))
1523       (while (search-forward "\r" nil t)
1524         (replace-match "\n" t t)))))
1525
1526 (defun article-remove-trailing-blank-lines ()
1527   "Remove all trailing blank lines from the article."
1528   (interactive)
1529   (save-excursion
1530     (let ((buffer-read-only nil))
1531       (goto-char (point-max))
1532       (delete-region
1533        (point)
1534        (progn
1535          (while (and (not (bobp))
1536                      (looking-at "^[ \t]*$")
1537                      (not (gnus-annotation-in-region-p
1538                            (point) (gnus-point-at-eol))))
1539            (forward-line -1))
1540          (forward-line 1)
1541          (point))))))
1542
1543 (defun article-display-x-face (&optional force)
1544   "Look for an X-Face header and display it if present."
1545   (interactive (list 'force))
1546   (save-excursion
1547     ;; Delete the old process, if any.
1548     (when (process-status "article-x-face")
1549       (delete-process "article-x-face"))
1550     (let ((inhibit-point-motion-hooks t)
1551           (case-fold-search t)
1552           from last)
1553       (save-restriction
1554         (article-narrow-to-head)
1555         (goto-char (point-min))
1556         (setq from (message-fetch-field "from"))
1557         (goto-char (point-min))
1558         (while (and gnus-article-x-face-command
1559                     (not last)
1560                     (or force
1561                         ;; Check whether this face is censored.
1562                         (not gnus-article-x-face-too-ugly)
1563                         (and gnus-article-x-face-too-ugly from
1564                              (not (string-match gnus-article-x-face-too-ugly
1565                                                 from))))
1566                     ;; Has to be present.
1567                     (re-search-forward "^X-Face:[ \t]*" nil t))
1568           ;; This used to try to do multiple faces (`while' instead of
1569           ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1570           ;; work (b) it can crash some versions of Emacs (c) are
1571           ;; multiple faces really something to encourage?
1572           (when (stringp gnus-article-x-face-command)
1573             (setq last t))
1574           ;; We now have the area of the buffer where the X-Face is stored.
1575           (save-excursion
1576             (let ((beg (point))
1577                   (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1578               ;; We display the face.
1579               (if (symbolp gnus-article-x-face-command)
1580                   ;; The command is a lisp function, so we call it.
1581                   (if (gnus-functionp gnus-article-x-face-command)
1582                       (funcall gnus-article-x-face-command beg end)
1583                     (error "%s is not a function" gnus-article-x-face-command))
1584                 ;; The command is a string, so we interpret the command
1585                 ;; as a, well, command, and fork it off.
1586                 (let ((process-connection-type nil))
1587                   (process-kill-without-query
1588                    (start-process
1589                     "article-x-face" nil shell-file-name shell-command-switch
1590                     gnus-article-x-face-command))
1591                   (process-send-region "article-x-face" beg end)
1592                   (process-send-eof "article-x-face"))))))))))
1593
1594 (defun article-decode-mime-words ()
1595   "Decode all MIME-encoded words in the article."
1596   (interactive)
1597   (save-excursion
1598     (set-buffer gnus-article-buffer)
1599     (let ((inhibit-point-motion-hooks t)
1600           buffer-read-only
1601           (mail-parse-charset gnus-newsgroup-charset)
1602           (mail-parse-ignored-charsets 
1603            (save-excursion (set-buffer gnus-summary-buffer)
1604                            gnus-newsgroup-ignored-charsets)))
1605       (mail-decode-encoded-word-region (point-min) (point-max)))))
1606
1607 (defun article-decode-charset (&optional prompt)
1608   "Decode charset-encoded text in the article.
1609 If PROMPT (the prefix), prompt for a coding system to use."
1610   (interactive "P")
1611   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1612         buffer-read-only
1613         (mail-parse-charset gnus-newsgroup-charset)
1614         (mail-parse-ignored-charsets 
1615          (save-excursion (condition-case nil
1616                              (set-buffer gnus-summary-buffer)
1617                            (error))
1618                          gnus-newsgroup-ignored-charsets))
1619         ct cte ctl charset format)
1620   (save-excursion
1621     (save-restriction
1622       (article-narrow-to-head)
1623       (setq ct (message-fetch-field "Content-Type" t)
1624             cte (message-fetch-field "Content-Transfer-Encoding" t)
1625             ctl (and ct (ignore-errors
1626                           (mail-header-parse-content-type ct)))
1627             charset (cond
1628                      (prompt
1629                       (mm-read-coding-system "Charset to decode: "))
1630                      (ctl
1631                       (mail-content-type-get ctl 'charset)))
1632             format (and ctl (mail-content-type-get ctl 'format)))
1633       (when cte
1634         (setq cte (mail-header-strip cte)))
1635       (if (and ctl (not (string-match "/" (car ctl)))) 
1636           (setq ctl nil))
1637       (goto-char (point-max)))
1638     (forward-line 1)
1639     (save-restriction
1640       (narrow-to-region (point) (point-max))
1641       (when (and (eq mail-parse-charset 'gnus-decoded)
1642                  (eq (mm-body-7-or-8) '8bit))
1643         ;; The text code could have been decoded.
1644         (setq charset mail-parse-charset))
1645       (when (and (or (not ctl)
1646                      (equal (car ctl) "text/plain"))
1647                  (not format)) ;; article with format will decode later.
1648         (mm-decode-body
1649          charset (and cte (intern (downcase
1650                                    (gnus-strip-whitespace cte))))
1651          (car ctl)))))))
1652
1653 (defun article-decode-encoded-words ()
1654   "Remove encoded-word encoding from headers."
1655   (let (buffer-read-only)
1656     (let ((charset (save-excursion
1657                      (set-buffer gnus-summary-buffer)
1658                      default-mime-charset)))
1659       (mime-decode-header-in-buffer charset)
1660       )))
1661
1662 (defun article-de-quoted-unreadable (&optional force)
1663   "Translate a quoted-printable-encoded article.
1664 If FORCE, decode the article whether it is marked as quoted-printable
1665 or not."
1666   (interactive (list 'force))
1667   (save-excursion
1668     (let ((buffer-read-only nil) type charset)
1669       (if (gnus-buffer-live-p gnus-original-article-buffer)
1670           (with-current-buffer gnus-original-article-buffer
1671             (setq type
1672                   (gnus-fetch-field "content-transfer-encoding"))
1673             (let* ((ct (gnus-fetch-field "content-type"))
1674                    (ctl (and ct 
1675                              (ignore-errors
1676                                (mail-header-parse-content-type ct)))))
1677               (setq charset (and ctl
1678                                  (mail-content-type-get ctl 'charset)))
1679               (if (stringp charset)
1680                   (setq charset (intern (downcase charset)))))))
1681       (unless charset 
1682         (setq charset gnus-newsgroup-charset))
1683       (when (or force
1684                 (and type (string-match "quoted-printable" (downcase type))))
1685         (article-goto-body)
1686         (quoted-printable-decode-region (point) (point-max) charset)))))
1687
1688 (defun article-de-base64-unreadable (&optional force)
1689   "Translate a base64 article.
1690 If FORCE, decode the article whether it is marked as base64 not."
1691   (interactive (list 'force))
1692   (save-excursion
1693     (let ((buffer-read-only nil) type charset)
1694       (if (gnus-buffer-live-p gnus-original-article-buffer)
1695           (with-current-buffer gnus-original-article-buffer
1696             (setq type
1697                   (gnus-fetch-field "content-transfer-encoding"))
1698             (let* ((ct (gnus-fetch-field "content-type"))
1699                    (ctl (and ct 
1700                              (ignore-errors
1701                                (mail-header-parse-content-type ct)))))
1702               (setq charset (and ctl
1703                                  (mail-content-type-get ctl 'charset)))
1704               (if (stringp charset)
1705                   (setq charset (intern (downcase charset)))))))
1706       (unless charset 
1707         (setq charset gnus-newsgroup-charset))
1708       (when (or force
1709                 (and type (string-match "base64" (downcase type))))
1710         (article-goto-body)
1711         (save-restriction
1712           (narrow-to-region (point) (point-max))
1713           (base64-decode-region (point-min) (point-max))
1714           (if (mm-coding-system-p charset)
1715               (mm-decode-coding-region (point-min) (point-max) charset)))))))
1716
1717 (eval-when-compile
1718   (require 'rfc1843))
1719
1720 (defun article-decode-HZ ()
1721   "Translate a HZ-encoded article."
1722   (interactive)
1723   (require 'rfc1843)
1724   (save-excursion
1725     (let ((buffer-read-only nil))
1726       (rfc1843-decode-region (point-min) (point-max)))))
1727
1728 (defun article-wash-html ()
1729   "Format an html article."
1730   (interactive)
1731   (save-excursion
1732     (let ((buffer-read-only nil)
1733           charset)
1734       (if (gnus-buffer-live-p gnus-original-article-buffer)
1735           (with-current-buffer gnus-original-article-buffer
1736             (let* ((ct (gnus-fetch-field "content-type"))
1737                    (ctl (and ct 
1738                              (ignore-errors
1739                                (mail-header-parse-content-type ct)))))
1740               (setq charset (and ctl
1741                                  (mail-content-type-get ctl 'charset)))
1742               (if (stringp charset)
1743                   (setq charset (intern (downcase charset)))))))
1744       (unless charset 
1745         (setq charset gnus-newsgroup-charset))
1746       (article-goto-body)
1747       (save-window-excursion
1748         (save-restriction
1749           (narrow-to-region (point) (point-max))
1750           (mm-setup-w3)
1751           (let ((w3-strict-width (window-width))
1752                 (url-standalone-mode t))
1753             (condition-case var
1754                 (w3-region (point-min) (point-max))
1755               (error))))))))
1756
1757 (defun article-hide-list-identifiers ()
1758   "Remove list identifies from the Subject header.
1759 The `gnus-list-identifiers' variable specifies what to do."
1760   (interactive)
1761   (save-excursion
1762     (save-restriction
1763       (let ((inhibit-point-motion-hooks t)
1764             buffer-read-only)
1765         (article-narrow-to-head)
1766         (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1767                         (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1768           (when regexp
1769             (goto-char (point-min))
1770             (when (re-search-forward
1771                    (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp 
1772                            " *\\)\\)+\\(Re: +\\)?\\)")
1773                    nil t)
1774               (let ((s (or (match-string 3) (match-string 5))))
1775                 (delete-region (match-beginning 1) (match-end 1))
1776                 (when s
1777                   (goto-char (match-beginning 1))
1778                   (insert s))))))))))
1779
1780 (defun article-hide-pgp ()
1781   "Remove any PGP headers and signatures in the current article."
1782   (interactive)
1783   (save-excursion
1784     (save-restriction
1785       (let ((inhibit-point-motion-hooks t)
1786             buffer-read-only beg end)
1787         (article-goto-body)
1788         ;; Hide the "header".
1789         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1790           (push 'pgp gnus-article-wash-types)
1791           (delete-region (match-beginning 0) (match-end 0))
1792           ;; Remove armor headers (rfc2440 6.2)
1793           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1794                                      (point)))
1795           (setq beg (point))
1796           ;; Hide the actual signature.
1797           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1798                (setq end (1+ (match-beginning 0)))
1799                (delete-region
1800                 end
1801                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1802                     (match-end 0)
1803                   ;; Perhaps we shouldn't hide to the end of the buffer
1804                   ;; if there is no end to the signature?
1805                   (point-max))))
1806           ;; Hide "- " PGP quotation markers.
1807           (when (and beg end)
1808             (narrow-to-region beg end)
1809             (goto-char (point-min))
1810             (while (re-search-forward "^- " nil t)
1811               (delete-region
1812                (match-beginning 0) (match-end 0)))
1813             (widen))
1814           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1815
1816 (defun article-hide-pem (&optional arg)
1817   "Toggle hiding of any PEM headers and signatures in the current article.
1818 If given a negative prefix, always show; if given a positive prefix,
1819 always hide."
1820   (interactive (gnus-article-hidden-arg))
1821   (unless (gnus-article-check-hidden-text 'pem arg)
1822     (save-excursion
1823       (let (buffer-read-only end)
1824         (goto-char (point-min))
1825         ;; Hide the horrendously ugly "header".
1826         (when (and (search-forward
1827                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1828                     nil t)
1829                    (setq end (1+ (match-beginning 0))))
1830           (push 'pem gnus-article-wash-types)
1831           (gnus-article-hide-text-type
1832            end
1833            (if (search-forward "\n\n" nil t)
1834                (match-end 0)
1835              (point-max))
1836            'pem)
1837           ;; Hide the trailer as well
1838           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1839                                 nil t)
1840             (gnus-article-hide-text-type
1841              (match-beginning 0) (match-end 0) 'pem)))))))
1842
1843 (defun article-strip-banner ()
1844   "Strip the banner specified by the `banner' group parameter."
1845   (interactive)
1846   (save-excursion
1847     (save-restriction
1848       (let ((inhibit-point-motion-hooks t)
1849             (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1850             (gnus-signature-limit nil)
1851             buffer-read-only beg end)
1852         (when banner
1853           (article-goto-body)
1854           (cond
1855            ((eq banner 'signature)
1856             (when (gnus-article-narrow-to-signature)
1857               (widen)
1858               (forward-line -1)
1859               (delete-region (point) (point-max))))
1860            ((symbolp banner)
1861             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1862                 (while (re-search-forward banner nil t)
1863                   (delete-region (match-beginning 0) (match-end 0)))))
1864            ((stringp banner)
1865             (while (re-search-forward banner nil t)
1866               (delete-region (match-beginning 0) (match-end 0))))))))))
1867
1868 (defun article-babel ()
1869   "Translate article using an online translation service."
1870   (interactive)
1871   (require 'babel)
1872   (save-excursion
1873     (set-buffer gnus-article-buffer)
1874     (when (article-goto-body)
1875       (let* ((buffer-read-only nil)
1876              (start (point))
1877              (end (point-max))
1878              (orig (buffer-substring start end))
1879              (trans (babel-as-string orig)))
1880         (save-restriction
1881           (narrow-to-region start end)
1882           (delete-region start end)
1883           (insert trans))))))
1884
1885 (defun article-hide-signature (&optional arg)
1886   "Hide the signature in the current article.
1887 If given a negative prefix, always show; if given a positive prefix,
1888 always hide."
1889   (interactive (gnus-article-hidden-arg))
1890   (save-excursion
1891     (save-restriction
1892       (if (interactive-p)
1893           (progn
1894             (widen)
1895             (article-goto-body))
1896         (goto-char (point-min)))
1897       (unless (gnus-article-check-hidden-text 'signature arg)
1898         (let ((buffer-read-only nil)
1899               (button (point)))
1900           (while (setq button (text-property-any button (point-max)
1901                                                  'gnus-callback
1902                                                  'gnus-signature-toggle))
1903             (setq button (text-property-not-all button (point-max)
1904                                                 'gnus-callback
1905                                                 'gnus-signature-toggle))
1906             (when (and button (not (eobp)))
1907               (gnus-article-hide-text-type
1908                (1+ button)
1909                (next-single-property-change (1+ button) 'mime-view-entity
1910                                             nil (point-max))
1911                'signature))))))))
1912
1913 (defun article-strip-headers-in-body ()
1914   "Strip offensive headers from bodies."
1915   (interactive)
1916   (save-excursion
1917     (article-goto-body)
1918     (let ((case-fold-search t))
1919       (when (looking-at "x-no-archive:")
1920         (gnus-delete-line)))))
1921
1922 (defun article-strip-leading-blank-lines ()
1923   "Remove all blank lines from the beginning of the article."
1924   (interactive)
1925   (save-excursion
1926     (let ((inhibit-point-motion-hooks t)
1927           buffer-read-only)
1928       (when (article-goto-body)
1929         (while (and (not (eobp))
1930                     (looking-at "[ \t]*$"))
1931           (gnus-delete-line))))))
1932
1933 (defun article-narrow-to-head ()
1934   "Narrow the buffer to the head of the message.
1935 Point is left at the beginning of the narrowed-to region."
1936   (narrow-to-region
1937    (goto-char (point-min))
1938    (if (search-forward "\n\n" nil 1)
1939        (1- (point))
1940      (point-max)))
1941   (goto-char (point-min)))
1942
1943 (defun article-goto-body ()
1944   "Place point at the start of the body."
1945   (goto-char (point-min))
1946   (cond
1947    ;; This variable is only bound when dealing with separate
1948    ;; MIME body parts.
1949    (article-goto-body-goes-to-point-min-p
1950     t)
1951    ((search-forward "\n\n" nil t)
1952     t)
1953    (t
1954     (goto-char (point-max))
1955     nil)))
1956
1957 (defun article-strip-multiple-blank-lines ()
1958   "Replace consecutive blank lines with one empty line."
1959   (interactive)
1960   (save-excursion
1961     (let ((inhibit-point-motion-hooks t)
1962           buffer-read-only)
1963       ;; First make all blank lines empty.
1964       (article-goto-body)
1965       (while (re-search-forward "^[ \t]+$" nil t)
1966         (unless (gnus-annotation-in-region-p
1967                  (match-beginning 0) (match-end 0))
1968           (replace-match "" nil t)))
1969       ;; Then replace multiple empty lines with a single empty line.
1970       (article-goto-body)
1971       (while (re-search-forward "\n\n\n+" nil t)
1972         (unless (gnus-annotation-in-region-p
1973                  (match-beginning 0) (match-end 0))
1974           (replace-match "\n\n" t t))))))
1975
1976 (defun article-strip-leading-space ()
1977   "Remove all white space from the beginning of the lines in the article."
1978   (interactive)
1979   (save-excursion
1980     (let ((inhibit-point-motion-hooks t)
1981           buffer-read-only)
1982       (article-goto-body)
1983       (while (re-search-forward "^[ \t]+" nil t)
1984         (replace-match "" t t)))))
1985
1986 (defun article-strip-trailing-space ()
1987   "Remove all white space from the end of the lines in the article."
1988   (interactive)
1989   (save-excursion
1990     (let ((inhibit-point-motion-hooks t)
1991           buffer-read-only)
1992       (article-goto-body)
1993       (while (re-search-forward "[ \t]+$" nil t)
1994         (replace-match "" t t)))))
1995
1996 (defun article-strip-blank-lines ()
1997   "Strip leading, trailing and multiple blank lines."
1998   (interactive)
1999   (article-strip-leading-blank-lines)
2000   (article-remove-trailing-blank-lines)
2001   (article-strip-multiple-blank-lines))
2002
2003 (defun article-strip-all-blank-lines ()
2004   "Strip all blank lines."
2005   (interactive)
2006   (save-excursion
2007     (let ((inhibit-point-motion-hooks t)
2008           buffer-read-only)
2009       (article-goto-body)
2010       (while (re-search-forward "^[ \t]*\n" nil t)
2011         (replace-match "" t t)))))
2012
2013 (defun gnus-article-narrow-to-signature ()
2014   "Narrow to the signature; return t if a signature is found, else nil."
2015   (let ((inhibit-point-motion-hooks t))
2016     (when (gnus-article-search-signature)
2017       (forward-line 1)
2018       ;; Check whether we have some limits to what we consider
2019       ;; to be a signature.
2020       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2021                       (list gnus-signature-limit)))
2022             limit limited)
2023         (while (setq limit (pop limits))
2024           (if (or (and (integerp limit)
2025                        (< (- (point-max) (point)) limit))
2026                   (and (floatp limit)
2027                        (< (count-lines (point) (point-max)) limit))
2028                   (and (gnus-functionp limit)
2029                        (funcall limit))
2030                   (and (stringp limit)
2031                        (not (re-search-forward limit nil t))))
2032               ()                        ; This limit did not succeed.
2033             (setq limited t
2034                   limits nil)))
2035         (unless limited
2036           (narrow-to-region (point) (point-max))
2037           t)))))
2038
2039 (defun gnus-article-search-signature ()
2040   "Search the current buffer for the signature separator.
2041 Put point at the beginning of the signature separator."
2042   (let ((cur (point)))
2043     (goto-char (point-max))
2044     (if (if (stringp gnus-signature-separator)
2045             (re-search-backward gnus-signature-separator nil t)
2046           (let ((seps gnus-signature-separator))
2047             (while (and seps
2048                         (not (re-search-backward (car seps) nil t)))
2049               (pop seps))
2050             seps))
2051         t
2052       (goto-char cur)
2053       nil)))
2054
2055 (defun gnus-article-hidden-arg ()
2056   "Return the current prefix arg as a number, or 0 if no prefix."
2057   (list (if current-prefix-arg
2058             (prefix-numeric-value current-prefix-arg)
2059           0)))
2060
2061 (defun gnus-article-check-hidden-text (type arg)
2062   "Return nil if hiding is necessary.
2063 Arg can be nil or a number.  Nil and positive means hide, negative
2064 means show, 0 means toggle."
2065   (save-excursion
2066     (save-restriction
2067       (let ((hide (gnus-article-hidden-text-p type)))
2068         (cond
2069          ((or (null arg)
2070               (> arg 0))
2071           nil)
2072          ((< arg 0)
2073           (gnus-article-show-hidden-text type))
2074          (t
2075           (if (eq hide 'hidden)
2076               (gnus-article-show-hidden-text type)
2077             nil)))))))
2078
2079 (defun gnus-article-hidden-text-p (type)
2080   "Say whether the current buffer contains hidden text of type TYPE."
2081   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2082     (while (and pos
2083                 (not (get-text-property pos 'invisible))
2084                 (not (get-text-property pos 'dummy-invisible)))
2085       (setq pos
2086             (text-property-any (1+ pos) (point-max) 'article-type type)))
2087     (if pos
2088         'hidden
2089       nil)))
2090
2091 (defun gnus-article-show-hidden-text (type &optional hide)
2092   "Show all hidden text of type TYPE.
2093 If HIDE, hide the text instead."
2094   (save-excursion
2095     (let ((buffer-read-only nil)
2096           (inhibit-point-motion-hooks t)
2097           (end (point-min))
2098           beg)
2099       (while (setq beg (text-property-any end (point-max) 'article-type type))
2100         (goto-char beg)
2101         (setq end (or
2102                    (text-property-not-all beg (point-max) 'article-type type)
2103                    (point-max)))
2104         (if hide
2105             (gnus-article-hide-text beg end gnus-hidden-properties)
2106           (gnus-article-unhide-text beg end))
2107         (goto-char end))
2108       t)))
2109
2110 (defconst article-time-units
2111   `((year . ,(* 365.25 24 60 60))
2112     (week . ,(* 7 24 60 60))
2113     (day . ,(* 24 60 60))
2114     (hour . ,(* 60 60))
2115     (minute . 60)
2116     (second . 1))
2117   "Mapping from time units to seconds.")
2118
2119 (defun article-date-ut (&optional type highlight header)
2120   "Convert DATE date to universal time in the current article.
2121 If TYPE is `local', convert to local time; if it is `lapsed', output
2122 how much time has lapsed since DATE.  For `lapsed', the value of
2123 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2124 should replace the \"Date:\" one, or should be added below it."
2125   (interactive (list 'ut t))
2126   (let* ((header (or header
2127                      (and (eq 1 (point-min))
2128                           (mail-header-date (save-excursion
2129                                               (set-buffer gnus-summary-buffer)
2130                                               gnus-current-headers)))
2131                      (message-fetch-field "date")
2132                      ""))
2133          (date (if (vectorp header) (mail-header-date header)
2134                  header))
2135          (inhibit-point-motion-hooks t)
2136          bface eface date-pos)
2137     (when (and date (not (string= date "")))
2138       (save-excursion
2139         (save-restriction
2140           (article-narrow-to-head)
2141           (when (or (and (eq type 'lapsed)
2142                          gnus-article-date-lapsed-new-header
2143                          ;; Attempt to get the face of X-Sent first.
2144                          (re-search-forward "^X-Sent:[ \t]" nil t))
2145                     (re-search-forward "^Date:[ \t]" nil t)
2146                     ;; If Date is missing, try again for X-Sent.
2147                     (re-search-forward "^X-Sent:[ \t]" nil t))
2148             (setq bface (get-text-property (gnus-point-at-bol) 'face)
2149                   date (or (get-text-property (gnus-point-at-bol)
2150                                                 'original-date)
2151                              date)
2152                   eface (get-text-property (1- (gnus-point-at-eol))
2153                                            'face)))
2154           (let ((buffer-read-only nil))
2155             ;; Delete any old X-Sent headers.
2156             (when (setq date-pos
2157                         (text-property-any (point-min) (point-max)
2158                                            'article-date-lapsed t))
2159               (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2160               (delete-region (match-beginning 0)
2161                              (progn (forward-line 1) (point))))
2162             (goto-char (point-min))
2163             ;; Delete any old Date headers.
2164             (while (re-search-forward "^Date:[ \t]" nil t)
2165               (unless date-pos
2166                 (setq date-pos (match-beginning 0)))
2167               (unless (and (eq type 'lapsed)
2168                            gnus-article-date-lapsed-new-header)
2169                 (delete-region (match-beginning 0)
2170                                (progn (message-next-header) (point)))))
2171             (if date-pos
2172                 (progn
2173                   (goto-char date-pos)
2174                   (unless (bolp)
2175                     ;; Possibly, Date has been deleted.
2176                     (insert "\n"))
2177                   (when (and (eq type 'lapsed)
2178                              gnus-article-date-lapsed-new-header
2179                              (looking-at "Date:"))
2180                     (forward-line 1)))
2181               (goto-char (point-min)))
2182             (insert (article-make-date-line date type))
2183             (when (eq type 'lapsed)
2184               (put-text-property (gnus-point-at-bol) (point)
2185                                  'article-date-lapsed t))
2186             (insert "\n")
2187             (forward-line -1)
2188             ;; Do highlighting.
2189             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2190               (put-text-property (match-beginning 1) (1+ (match-end 1))
2191                                  'original-date date)
2192               (put-text-property (match-beginning 1) (1+ (match-end 1))
2193                                  'face bface)
2194               (put-text-property (match-beginning 2) (match-end 2)
2195                                  'face eface))))))))
2196
2197 (defun article-make-date-line (date type)
2198   "Return a DATE line of TYPE."
2199   (let ((time (condition-case ()
2200                   (date-to-time date)
2201                 (error '(0 0)))))
2202     (cond
2203      ;; Convert to the local timezone.  We have to slap a
2204      ;; `condition-case' round the calls to the timezone
2205      ;; functions since they aren't particularly resistant to
2206      ;; buggy dates.
2207      ((eq type 'local)
2208       (let ((tz (car (current-time-zone time))))
2209         (format "Date: %s %s%02d%02d" (current-time-string time)
2210                 (if (> tz 0) "+" "-") (/ (abs tz) 3600) 
2211                 (/ (% (abs tz) 3600) 60))))
2212      ;; Convert to Universal Time.
2213      ((eq type 'ut)
2214       (concat "Date: "
2215               (current-time-string
2216                (let* ((e (parse-time-string date))
2217                       (tm (apply 'encode-time e))
2218                       (ms (car tm))
2219                       (ls (- (cadr tm) (car (current-time-zone time)))))
2220                  (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2221                        ((> ls 65535) (list (1+ ms) (- ls 65536)))
2222                        (t (list ms ls)))))
2223               " UT"))
2224      ;; Get the original date from the article.
2225      ((eq type 'original)
2226       (concat "Date: " (if (string-match "\n+$" date)
2227                            (substring date 0 (match-beginning 0))
2228                          date)))
2229      ;; Let the user define the format.
2230      ((eq type 'user)
2231       (if (gnus-functionp gnus-article-time-format)
2232           (funcall gnus-article-time-format time)
2233         (concat
2234          "Date: "
2235          (format-time-string gnus-article-time-format time))))
2236      ;; ISO 8601.
2237      ((eq type 'iso8601)
2238       (let ((tz (car (current-time-zone time))))
2239         (concat
2240          "Date: "
2241          (format-time-string "%Y%m%dT%H%M%S" time)
2242          (format "%s%02d%02d"
2243                  (if (> tz 0) "+" "-") (/ (abs tz) 3600) 
2244                  (/ (% (abs tz) 3600) 60)))))
2245      ;; Do an X-Sent lapsed format.
2246      ((eq type 'lapsed)
2247       ;; If the date is seriously mangled, the timezone functions are
2248       ;; liable to bug out, so we ignore all errors.
2249       (let* ((now (current-time))
2250              (real-time (subtract-time now time))
2251              (real-sec (and real-time
2252                             (+ (* (float (car real-time)) 65536)
2253                                (cadr real-time))))
2254              (sec (and real-time (abs real-sec)))
2255              num prev)
2256         (cond
2257          ((null real-time)
2258           "X-Sent: Unknown")
2259          ((zerop sec)
2260           "X-Sent: Now")
2261          (t
2262           (concat
2263            "X-Sent: "
2264            ;; This is a bit convoluted, but basically we go
2265            ;; through the time units for years, weeks, etc,
2266            ;; and divide things to see whether that results
2267            ;; in positive answers.
2268            (mapconcat
2269             (lambda (unit)
2270               (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2271                   ;; The (remaining) seconds are too few to
2272                   ;; be divided into this time unit.
2273                   ""
2274                 ;; It's big enough, so we output it.
2275                 (setq sec (- sec (* num (cdr unit))))
2276                 (prog1
2277                     (concat (if prev ", " "") (int-to-string
2278                                                (floor num))
2279                             " " (symbol-name (car unit))
2280                             (if (> num 1) "s" ""))
2281                   (setq prev t))))
2282             article-time-units "")
2283            ;; If dates are odd, then it might appear like the
2284            ;; article was sent in the future.
2285            (if (> real-sec 0)
2286                " ago"
2287              " in the future"))))))
2288      (t
2289       (error "Unknown conversion type: %s" type)))))
2290
2291 (defun article-date-local (&optional highlight)
2292   "Convert the current article date to the local timezone."
2293   (interactive (list t))
2294   (article-date-ut 'local highlight))
2295
2296 (defun article-date-original (&optional highlight)
2297   "Convert the current article date to what it was originally.
2298 This is only useful if you have used some other date conversion
2299 function and want to see what the date was before converting."
2300   (interactive (list t))
2301   (article-date-ut 'original highlight))
2302
2303 (defun article-date-lapsed (&optional highlight)
2304   "Convert the current article date to time lapsed since it was sent."
2305   (interactive (list t))
2306   (article-date-ut 'lapsed highlight))
2307
2308 (defun article-update-date-lapsed ()
2309   "Function to be run from a timer to update the lapsed time line."
2310   (let (deactivate-mark)
2311     (save-excursion
2312       (ignore-errors
2313         (walk-windows
2314          (lambda (w)
2315            (set-buffer (window-buffer w))
2316            (when (eq major-mode 'gnus-article-mode)
2317              (goto-char (point-min))
2318              (when (re-search-forward "^X-Sent:" nil t)
2319                (article-date-lapsed t))))
2320          nil 'visible)))))
2321
2322 (defun gnus-start-date-timer (&optional n)
2323   "Start a timer to update the X-Sent header in the article buffers.
2324 The numerical prefix says how frequently (in seconds) the function
2325 is to run."
2326   (interactive "p")
2327   (unless n
2328     (setq n 1))
2329   (gnus-stop-date-timer)
2330   (setq article-lapsed-timer
2331         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2332
2333 (defun gnus-stop-date-timer ()
2334   "Stop the X-Sent timer."
2335   (interactive)
2336   (when article-lapsed-timer
2337     (nnheader-cancel-timer article-lapsed-timer)
2338     (setq article-lapsed-timer nil)))
2339
2340 (defun article-date-user (&optional highlight)
2341   "Convert the current article date to the user-defined format.
2342 This format is defined by the `gnus-article-time-format' variable."
2343   (interactive (list t))
2344   (article-date-ut 'user highlight))
2345
2346 (defun article-date-iso8601 (&optional highlight)
2347   "Convert the current article date to ISO8601."
2348   (interactive (list t))
2349   (article-date-ut 'iso8601 highlight))
2350
2351 (defun article-show-all ()
2352   "Show all hidden text in the article buffer."
2353   (interactive)
2354   (save-excursion
2355     (widen)
2356     (let ((buffer-read-only nil))
2357       (gnus-article-unhide-text (point-min) (point-max))
2358       (gnus-remove-text-with-property 'gnus-prev)
2359       (gnus-remove-text-with-property 'gnus-next))))
2360
2361 (defun article-show-all-headers ()
2362   "Show all hidden headers in the article buffer."
2363   (interactive)
2364   (save-excursion
2365     (save-restriction
2366       (widen)
2367       (article-narrow-to-head)
2368       (let ((buffer-read-only nil))
2369         (gnus-article-unhide-text (point-min) (point-max))))))
2370
2371 (defun article-emphasize (&optional arg)
2372   "Emphasize text according to `gnus-emphasis-alist'."
2373   (interactive (gnus-article-hidden-arg))
2374   (unless (gnus-article-check-hidden-text 'emphasis arg)
2375     (save-excursion
2376       (let ((alist (or 
2377                     (condition-case nil
2378                         (with-current-buffer gnus-summary-buffer 
2379                           gnus-article-emphasis-alist) 
2380                       (error))
2381                     gnus-emphasis-alist))
2382             (buffer-read-only nil)
2383             (props (append '(article-type emphasis)
2384                            gnus-hidden-properties))
2385             regexp elem beg invisible visible face)
2386         (article-goto-body)
2387         (setq beg (point))
2388         (while (setq elem (pop alist))
2389           (goto-char beg)
2390           (setq regexp (car elem)
2391                 invisible (nth 1 elem)
2392                 visible (nth 2 elem)
2393                 face (nth 3 elem))
2394           (while (re-search-forward regexp nil t)
2395             (when (and (match-beginning visible) (match-beginning invisible))
2396               (push 'emphasis gnus-article-wash-types)
2397               (gnus-article-hide-text
2398                (match-beginning invisible) (match-end invisible) props)
2399               (gnus-article-unhide-text-type
2400                (match-beginning visible) (match-end visible) 'emphasis)
2401               (gnus-put-text-property-excluding-newlines
2402                (match-beginning visible) (match-end visible) 'face face)
2403               (goto-char (match-end invisible)))))))))
2404
2405 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2406   "Setup newsgroup emphasis alist."
2407   (unless gnus-article-emphasis-alist
2408     (let ((name (and gnus-newsgroup-name
2409                      (gnus-group-real-name gnus-newsgroup-name))))
2410       (make-local-variable 'gnus-article-emphasis-alist)
2411       (setq gnus-article-emphasis-alist
2412             (nconc
2413              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2414                (while (setq elem (pop alist))
2415                  (when (and name (string-match (car elem) name))
2416                    (setq alist nil
2417                          highlight (copy-sequence (cdr elem)))))
2418                highlight)
2419              (copy-sequence highlight-words)
2420              (if gnus-newsgroup-name
2421                  (copy-sequence (gnus-group-find-parameter
2422                                  gnus-newsgroup-name 'highlight-words t)))
2423              gnus-emphasis-alist)))))
2424
2425 (defvar gnus-summary-article-menu)
2426 (defvar gnus-summary-post-menu)
2427
2428 ;;; Saving functions.
2429
2430 (defun gnus-article-save (save-buffer file &optional num)
2431   "Save the currently selected article."
2432   (unless gnus-save-all-headers
2433     ;; Remove headers according to `gnus-saved-headers'.
2434     (let ((gnus-visible-headers
2435            (or gnus-saved-headers gnus-visible-headers))
2436           (gnus-article-buffer save-buffer))
2437       (save-excursion
2438         (set-buffer save-buffer)
2439         (article-hide-headers 1 t))))
2440   (save-window-excursion
2441     (if (not gnus-default-article-saver)
2442         (error "No default saver is defined")
2443       ;; !!! Magic!  The saving functions all save
2444       ;; `gnus-save-article-buffer' (or so they think), but we
2445       ;; bind that variable to our save-buffer.
2446       (set-buffer gnus-article-buffer)
2447       (let* ((gnus-save-article-buffer save-buffer)
2448              (filename
2449               (cond
2450                ((not gnus-prompt-before-saving) 'default)
2451                ((eq gnus-prompt-before-saving 'always) nil)
2452                (t file)))
2453              (gnus-number-of-articles-to-be-saved
2454               (when (eq gnus-prompt-before-saving t)
2455                 num)))                  ; Magic
2456         (set-buffer gnus-article-current-summary)
2457         (funcall gnus-default-article-saver filename)))))
2458
2459 (defun gnus-read-save-file-name (prompt &optional filename
2460                                         function group headers variable)
2461   (let ((default-name
2462           (funcall function group headers (symbol-value variable)))
2463         result)
2464     (setq result
2465         (expand-file-name
2466      (cond
2467       ((eq filename 'default)
2468        default-name)
2469       ((eq filename t)
2470        default-name)
2471       (filename filename)
2472       (t
2473        (let* ((split-name (gnus-get-split-value gnus-split-methods))
2474               (prompt
2475                (format prompt
2476                        (if (and gnus-number-of-articles-to-be-saved
2477                                 (> gnus-number-of-articles-to-be-saved 1))
2478                            (format "these %d articles"
2479                                    gnus-number-of-articles-to-be-saved)
2480                          "this article")))
2481               (file
2482                ;; Let the split methods have their say.
2483                (cond
2484                 ;; No split name was found.
2485                 ((null split-name)
2486                  (read-file-name
2487                   (concat prompt " (default "
2488                           (file-name-nondirectory default-name) ") ")
2489                   (file-name-directory default-name)
2490                   default-name))
2491                 ;; A single group name is returned.
2492                 ((stringp split-name)
2493                  (setq default-name
2494                        (funcall function split-name headers
2495                                 (symbol-value variable)))
2496                  (read-file-name
2497                   (concat prompt " (default "
2498                           (file-name-nondirectory default-name) ") ")
2499                   (file-name-directory default-name)
2500                   default-name))
2501                 ;; A single split name was found
2502                 ((= 1 (length split-name))
2503                  (let* ((name (expand-file-name
2504                                (car split-name) gnus-article-save-directory))
2505                         (dir (cond ((file-directory-p name)
2506                                     (file-name-as-directory name))
2507                                    ((file-exists-p name) name)
2508                                    (t gnus-article-save-directory))))
2509                    (read-file-name
2510                     (concat prompt " (default " name ") ")
2511                     dir name)))
2512                 ;; A list of splits was found.
2513                 (t
2514                  (setq split-name (nreverse split-name))
2515                  (let (result)
2516                    (let ((file-name-history
2517                           (nconc split-name file-name-history)))
2518                      (setq result
2519                            (expand-file-name
2520                             (read-file-name
2521                              (concat prompt " (`M-p' for defaults) ")
2522                              gnus-article-save-directory
2523                              (car split-name))
2524                             gnus-article-save-directory)))
2525                    (car (push result file-name-history)))))))
2526          ;; Create the directory.
2527          (gnus-make-directory (file-name-directory file))
2528          ;; If we have read a directory, we append the default file name.
2529          (when (file-directory-p file)
2530            (setq file (expand-file-name (file-name-nondirectory default-name)
2531                                         (file-name-as-directory file))))
2532          ;; Possibly translate some characters.
2533          (nnheader-translate-file-chars file))))))
2534     (gnus-make-directory (file-name-directory result))
2535     (set variable result)))
2536
2537 (defun gnus-article-archive-name (group)
2538   "Return the first instance of an \"Archive-name\" in the current buffer."
2539   (let ((case-fold-search t))
2540     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2541       (nnheader-concat gnus-article-save-directory
2542                        (match-string 1)))))
2543
2544 (defun gnus-article-nndoc-name (group)
2545   "If GROUP is an nndoc group, return the name of the parent group."
2546   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2547     (gnus-group-get-parameter group 'save-article-group)))
2548
2549 (defun gnus-summary-save-in-rmail (&optional filename)
2550   "Append this article to Rmail file.
2551 Optional argument FILENAME specifies file name.
2552 Directory to save to is default to `gnus-article-save-directory'."
2553   (setq filename (gnus-read-save-file-name
2554                   "Save %s in rmail file:" filename
2555                   gnus-rmail-save-name gnus-newsgroup-name
2556                   gnus-current-headers 'gnus-newsgroup-last-rmail))
2557   (gnus-eval-in-buffer-window gnus-save-article-buffer
2558     (save-excursion
2559       (save-restriction
2560         (widen)
2561         (gnus-output-to-rmail filename))))
2562   filename)
2563
2564 (defun gnus-summary-save-in-mail (&optional filename)
2565   "Append this article to Unix mail file.
2566 Optional argument FILENAME specifies file name.
2567 Directory to save to is default to `gnus-article-save-directory'."
2568   (setq filename (gnus-read-save-file-name
2569                   "Save %s in Unix mail file:" filename
2570                   gnus-mail-save-name gnus-newsgroup-name
2571                   gnus-current-headers 'gnus-newsgroup-last-mail))
2572   (gnus-eval-in-buffer-window gnus-save-article-buffer
2573     (save-excursion
2574       (save-restriction
2575         (widen)
2576         (if (and (file-readable-p filename)
2577                  (mail-file-babyl-p filename))
2578             (rmail-output-to-rmail-file filename t)
2579           (gnus-output-to-mail filename)))))
2580   filename)
2581
2582 (defun gnus-summary-save-in-file (&optional filename overwrite)
2583   "Append this article to file.
2584 Optional argument FILENAME specifies file name.
2585 Directory to save to is default to `gnus-article-save-directory'."
2586   (setq filename (gnus-read-save-file-name
2587                   "Save %s in file:" filename
2588                   gnus-file-save-name gnus-newsgroup-name
2589                   gnus-current-headers 'gnus-newsgroup-last-file))
2590   (gnus-eval-in-buffer-window gnus-save-article-buffer
2591     (save-excursion
2592       (save-restriction
2593         (widen)
2594         (when (and overwrite
2595                    (file-exists-p filename))
2596           (delete-file filename))
2597         (gnus-output-to-file filename))))
2598   filename)
2599
2600 (defun gnus-summary-write-to-file (&optional filename)
2601   "Write this article to a file.
2602 Optional argument FILENAME specifies file name.
2603 The directory to save in defaults to `gnus-article-save-directory'."
2604   (gnus-summary-save-in-file nil t))
2605
2606 (defun gnus-summary-save-body-in-file (&optional filename)
2607   "Append this article body to a file.
2608 Optional argument FILENAME specifies file name.
2609 The directory to save in defaults to `gnus-article-save-directory'."
2610   (setq filename (gnus-read-save-file-name
2611                   "Save %s body in file:" filename
2612                   gnus-file-save-name gnus-newsgroup-name
2613                   gnus-current-headers 'gnus-newsgroup-last-file))
2614   (gnus-eval-in-buffer-window gnus-save-article-buffer
2615     (save-excursion
2616       (save-restriction
2617         (widen)
2618         (when (article-goto-body)
2619           (narrow-to-region (point) (point-max)))
2620         (gnus-output-to-file filename))))
2621   filename)
2622
2623 (defun gnus-summary-save-in-pipe (&optional command)
2624   "Pipe this article to subprocess."
2625   (setq command
2626         (cond ((and (eq command 'default)
2627                     gnus-last-shell-command)
2628                gnus-last-shell-command)
2629               (command command)
2630               (t (read-string
2631                   (format
2632                    "Shell command on %s: "
2633                    (if (and gnus-number-of-articles-to-be-saved
2634                             (> gnus-number-of-articles-to-be-saved 1))
2635                        (format "these %d articles"
2636                                gnus-number-of-articles-to-be-saved)
2637                      "this article"))
2638                   gnus-last-shell-command))))
2639   (when (string-equal command "")
2640     (setq command gnus-last-shell-command))
2641   (gnus-eval-in-buffer-window gnus-article-buffer
2642     (save-restriction
2643       (widen)
2644       (shell-command-on-region (point-min) (point-max) command nil)))
2645   (setq gnus-last-shell-command command))
2646
2647 ;;; Article file names when saving.
2648
2649 (defun gnus-capitalize-newsgroup (newsgroup)
2650   "Capitalize NEWSGROUP name."
2651   (when (not (zerop (length newsgroup)))
2652     (concat (char-to-string (upcase (aref newsgroup 0)))
2653             (substring newsgroup 1))))
2654
2655 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2656   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2657 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2658 Otherwise, it is like ~/News/news/group/num."
2659   (let ((default
2660           (expand-file-name
2661            (concat (if (gnus-use-long-file-name 'not-save)
2662                        (gnus-capitalize-newsgroup newsgroup)
2663                      (gnus-newsgroup-directory-form newsgroup))
2664                    "/" (int-to-string (mail-header-number headers)))
2665            gnus-article-save-directory)))
2666     (if (and last-file
2667              (string-equal (file-name-directory default)
2668                            (file-name-directory last-file))
2669              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2670         default
2671       (or last-file default))))
2672
2673 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2674   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2675 If variable `gnus-use-long-file-name' is non-nil, it is
2676 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
2677   (let ((default
2678           (expand-file-name
2679            (concat (if (gnus-use-long-file-name 'not-save)
2680                        newsgroup
2681                      (gnus-newsgroup-directory-form newsgroup))
2682                    "/" (int-to-string (mail-header-number headers)))
2683            gnus-article-save-directory)))
2684     (if (and last-file
2685              (string-equal (file-name-directory default)
2686                            (file-name-directory last-file))
2687              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2688         default
2689       (or last-file default))))
2690
2691 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2692   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2693 If variable `gnus-use-long-file-name' is non-nil, it is
2694 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
2695   (or last-file
2696       (expand-file-name
2697        (if (gnus-use-long-file-name 'not-save)
2698            newsgroup
2699          (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2700        gnus-article-save-directory)))
2701
2702 (eval-and-compile
2703   (mapcar
2704    (lambda (func)
2705      (let (afunc gfunc)
2706        (if (consp func)
2707            (setq afunc (car func)
2708                  gfunc (cdr func))
2709          (setq afunc func
2710                gfunc (intern (format "gnus-%s" func))))
2711        (defalias gfunc
2712          (if (fboundp afunc)
2713            `(lambda (&optional interactive &rest args)
2714               ,(documentation afunc t)
2715               (interactive (list t))
2716               (save-excursion
2717                 (set-buffer gnus-article-buffer)
2718                 (if interactive
2719                     (call-interactively ',afunc)
2720                   (apply ',afunc args))))))))
2721    '(article-hide-headers
2722      article-hide-boring-headers
2723      article-toggle-headers
2724      article-treat-overstrike
2725      article-fill-long-lines
2726      article-capitalize-sentences
2727      article-remove-cr
2728      article-display-x-face
2729      article-de-quoted-unreadable
2730      article-de-base64-unreadable
2731      article-decode-HZ
2732      article-wash-html
2733      article-hide-list-identifiers
2734      article-hide-pgp
2735      article-strip-banner
2736      article-babel
2737      article-hide-pem
2738      article-hide-signature
2739      article-strip-headers-in-body
2740      article-remove-trailing-blank-lines
2741      article-strip-leading-blank-lines
2742      article-strip-multiple-blank-lines
2743      article-strip-leading-space
2744      article-strip-trailing-space
2745      article-strip-blank-lines
2746      article-strip-all-blank-lines
2747      article-date-local
2748      article-date-iso8601
2749      article-date-original
2750      article-date-ut
2751      article-decode-mime-words
2752      article-decode-charset
2753      article-decode-encoded-words
2754      article-date-user
2755      article-date-lapsed
2756      article-emphasize
2757      article-treat-dumbquotes
2758      article-normalize-headers
2759      (article-show-all-headers . gnus-article-show-all-headers)
2760      (article-show-all . gnus-article-show-all))))
2761 \f
2762 ;;;
2763 ;;; Gnus article mode
2764 ;;;
2765
2766 (put 'gnus-article-mode 'mode-class 'special)
2767
2768 (gnus-define-keys gnus-article-mode-map
2769   " " gnus-article-goto-next-page
2770   "\177" gnus-article-goto-prev-page
2771   [delete] gnus-article-goto-prev-page
2772   [backspace] gnus-article-goto-prev-page
2773   "\C-c^" gnus-article-refer-article
2774   "h" gnus-article-show-summary
2775   "s" gnus-article-show-summary
2776   "\C-c\C-m" gnus-article-mail
2777   "?" gnus-article-describe-briefly
2778   "e" gnus-summary-edit-article
2779   "<" beginning-of-buffer
2780   ">" end-of-buffer
2781   "\C-c\C-i" gnus-info-find-node
2782   "\C-c\C-b" gnus-bug
2783
2784   "\C-d" gnus-article-read-summary-keys
2785   "\M-*" gnus-article-read-summary-keys
2786   "\M-#" gnus-article-read-summary-keys
2787   "\M-^" gnus-article-read-summary-keys
2788   "\M-g" gnus-article-read-summary-keys)
2789
2790 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2791 (mapcar
2792  (lambda (key)
2793    (unless (lookup-key gnus-article-mode-map key)
2794      (define-key gnus-article-mode-map key
2795        'gnus-article-read-summary-keys)))
2796  (delq nil
2797        (append
2798         (mapcar
2799          (lambda (elt)
2800            (let ((key (car elt)))
2801              (and (> (length key) 0)
2802                   (not (eq 'menu-bar (aref key 0)))
2803                   (symbolp (lookup-key gnus-summary-mode-map key))
2804                   key)))
2805          (accessible-keymaps gnus-summary-mode-map))
2806         (let ((c 127)
2807               keys)
2808           (while (>= c 32)
2809             (push (char-to-string c) keys)
2810             (decf c))
2811           keys))))
2812
2813 (defun gnus-article-make-menu-bar ()
2814   (gnus-turn-off-edit-menu 'article)
2815   (unless (boundp 'gnus-article-article-menu)
2816     (easy-menu-define
2817      gnus-article-article-menu gnus-article-mode-map ""
2818      '("Article"
2819        ["Scroll forwards" gnus-article-goto-next-page t]
2820        ["Scroll backwards" gnus-article-goto-prev-page t]
2821        ["Show summary" gnus-article-show-summary t]
2822        ["Fetch Message-ID at point" gnus-article-refer-article t]
2823        ["Mail to address at point" gnus-article-mail t]
2824        ["Send a bug report" gnus-bug t]))
2825
2826     (easy-menu-define
2827      gnus-article-treatment-menu gnus-article-mode-map ""
2828      '("Treatment"
2829        ["Hide headers" gnus-article-toggle-headers t]
2830        ["Hide signature" gnus-article-hide-signature t]
2831        ["Hide citation" gnus-article-hide-citation t]
2832        ["Treat overstrike" gnus-article-treat-overstrike t]
2833        ["Remove carriage return" gnus-article-remove-cr t]
2834        ["Decode HZ" gnus-article-decode-HZ t]))
2835
2836     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2837
2838     (when (boundp 'gnus-summary-post-menu)
2839       (define-key gnus-article-mode-map [menu-bar post]
2840         (cons "Post" gnus-summary-post-menu)))
2841
2842     (gnus-run-hooks 'gnus-article-menu-hook)))
2843
2844 (defun gnus-article-mode ()
2845   "Major mode for displaying an article.
2846
2847 All normal editing commands are switched off.
2848
2849 The following commands are available in addition to all summary mode
2850 commands:
2851 \\<gnus-article-mode-map>
2852 \\[gnus-article-next-page]\t Scroll the article one page forwards
2853 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2854 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2855 \\[gnus-article-show-summary]\t Display the summary buffer
2856 \\[gnus-article-mail]\t Send a reply to the address near point
2857 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2858 \\[gnus-info-find-node]\t Go to the Gnus info node"
2859   (interactive)
2860   (when (gnus-visual-p 'article-menu 'menu)
2861     (gnus-article-make-menu-bar))
2862   (gnus-simplify-mode-line)
2863   (setq mode-name "Article")
2864   (setq major-mode 'gnus-article-mode)
2865   (make-local-variable 'minor-mode-alist)
2866   (unless (assq 'gnus-show-mime minor-mode-alist)
2867     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2868   (use-local-map gnus-article-mode-map)
2869   (gnus-update-format-specifications nil 'article-mode)
2870   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2871   (make-local-variable 'gnus-page-broken)
2872   (make-local-variable 'gnus-button-marker-list)
2873   (make-local-variable 'gnus-article-current-summary)
2874   (make-local-variable 'gnus-article-mime-handles)
2875   (make-local-variable 'gnus-article-decoded-p)
2876   (make-local-variable 'gnus-article-mime-handle-alist)
2877   (make-local-variable 'gnus-article-wash-types)
2878   (gnus-set-default-directory)
2879   (buffer-disable-undo)
2880   (setq buffer-read-only t)
2881   (set-syntax-table gnus-article-mode-syntax-table)
2882   (gnus-run-hooks 'gnus-article-mode-hook))
2883
2884 (defun gnus-article-setup-buffer ()
2885   "Initialize the article buffer."
2886   (let* ((name (if gnus-single-article-buffer "*Article*"
2887                  (concat "*Article " gnus-newsgroup-name "*")))
2888          (original
2889           (progn (string-match "\\*Article" name)
2890                  (concat " *Original Article"
2891                          (substring name (match-end 0))))))
2892     (setq gnus-article-buffer name)
2893     (setq gnus-original-article-buffer original)
2894     (setq gnus-article-mime-handle-alist nil)
2895     ;; This might be a variable local to the summary buffer.
2896     (unless gnus-single-article-buffer
2897       (save-excursion
2898         (set-buffer gnus-summary-buffer)
2899         (setq gnus-article-buffer name)
2900         (setq gnus-original-article-buffer original)
2901         (gnus-set-global-variables)))
2902     (gnus-article-setup-highlight-words)
2903     ;; Init original article buffer.
2904     (save-excursion
2905       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2906       (set-buffer-multibyte nil)
2907       (setq major-mode 'gnus-original-article-mode)
2908       (make-local-variable 'gnus-original-article))
2909     (if (get-buffer name)
2910         (save-excursion
2911           (set-buffer name)
2912           (buffer-disable-undo)
2913           (setq buffer-read-only t)
2914           (unless (eq major-mode 'gnus-article-mode)
2915             (gnus-article-mode))
2916           (current-buffer))
2917       (save-excursion
2918         (set-buffer (gnus-get-buffer-create name))
2919         (gnus-article-mode)
2920         (make-local-variable 'gnus-summary-buffer)
2921         (gnus-summary-set-local-parameters gnus-newsgroup-name)
2922         (current-buffer)))))
2923
2924 ;; Set article window start at LINE, where LINE is the number of lines
2925 ;; from the head of the article.
2926 (defun gnus-article-set-window-start (&optional line)
2927   (set-window-start
2928    (get-buffer-window gnus-article-buffer t)
2929    (save-excursion
2930      (set-buffer gnus-article-buffer)
2931      (goto-char (point-min))
2932      (if (not line)
2933          (point-min)
2934        (gnus-message 6 "Moved to bookmark")
2935        (search-forward "\n\n" nil t)
2936        (forward-line line)
2937        (point)))))
2938
2939 ;;; @@ article filters
2940 ;;;
2941
2942 (defun gnus-article-display-mime-message ()
2943   "Article display method for MIME message."
2944   ;; called from `gnus-original-article-buffer'.
2945   (let (charset all-headers)
2946     (with-current-buffer gnus-summary-buffer
2947       (setq charset default-mime-charset
2948             all-headers gnus-have-all-headers))
2949     (make-local-variable 'default-mime-charset)
2950     (setq default-mime-charset charset)
2951     (with-current-buffer (get-buffer-create gnus-article-buffer)
2952       (make-local-variable 'default-mime-charset)
2953       (setq default-mime-charset charset))
2954     (mime-display-message mime-message-structure
2955                           gnus-article-buffer nil gnus-article-mode-map)
2956     (when all-headers
2957       (gnus-article-hide-headers nil -1)))
2958   (run-hooks 'gnus-mime-article-prepare-hook))
2959
2960 (defun gnus-article-display-traditional-message ()
2961   "Article display method for traditional message."
2962   (set-buffer gnus-article-buffer)
2963   (let (buffer-read-only)
2964     (erase-buffer)
2965     (insert-buffer-substring gnus-original-article-buffer)))
2966
2967 (defun gnus-article-make-full-mail-header (&optional number charset)
2968   "Create a new mail header structure in a raw article buffer."
2969   (unless (and number charset)
2970     (save-current-buffer
2971       (set-buffer gnus-summary-buffer)
2972       (unless number
2973         (setq number (or (cdr gnus-article-current) 0)))
2974       (unless charset
2975         (setq charset (or default-mime-charset 'x-ctext)))))
2976   (goto-char (point-min))
2977   (let ((header-end (if (search-forward "\n\n" nil t)
2978                         (1- (point))
2979                       (goto-char (point-max))))
2980         (chars (- (point-max) (point)))
2981         (lines (count-lines (point) (point-max)))
2982         (default-mime-charset charset)
2983         xref)
2984     (narrow-to-region (point-min) header-end)
2985     (setq xref (std11-fetch-field "xref"))
2986     (prog1
2987         (make-full-mail-header
2988          number
2989          (std11-fetch-field "subject")
2990          (std11-fetch-field "from")
2991          (std11-fetch-field "date")
2992          (std11-fetch-field "message-id")
2993          (std11-fetch-field "references")
2994          chars
2995          lines
2996          (when xref (concat "Xref: " xref)))
2997       (widen))))
2998
2999 (defun gnus-article-prepare (article &optional all-headers header)
3000   "Prepare ARTICLE in article mode buffer.
3001 ARTICLE should either be an article number or a Message-ID.
3002 If ARTICLE is an id, HEADER should be the article headers.
3003 If ALL-HEADERS is non-nil, no headers are hidden."
3004   (save-excursion
3005     ;; Make sure we start in a summary buffer.
3006     (unless (eq major-mode 'gnus-summary-mode)
3007       (set-buffer gnus-summary-buffer))
3008     (setq gnus-summary-buffer (current-buffer))
3009     (let* ((gnus-article (if header (mail-header-number header) article))
3010            (summary-buffer (current-buffer))
3011            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3012            (group gnus-newsgroup-name)
3013            result)
3014       (save-excursion
3015         (gnus-article-setup-buffer)
3016         (set-buffer gnus-original-article-buffer)
3017         ;; Deactivate active regions.
3018         (when (and (boundp 'transient-mark-mode)
3019                    transient-mark-mode)
3020           (setq mark-active nil))
3021         (if (not (setq result (let ((buffer-read-only nil))
3022                                 (gnus-request-article-this-buffer
3023                                  article group))))
3024             ;; There is no such article.
3025             (save-excursion
3026               (when (and (numberp article)
3027                          (not (memq article gnus-newsgroup-sparse)))
3028                 (setq gnus-article-current
3029                       (cons gnus-newsgroup-name article))
3030                 (set-buffer gnus-summary-buffer)
3031                 (setq gnus-current-article article)
3032                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3033                     (progn
3034                       (gnus-summary-set-agent-mark article)
3035                       (message "Message marked for downloading"))
3036                   (gnus-summary-mark-article article gnus-canceled-mark)
3037                   (unless (memq article gnus-newsgroup-sparse)
3038                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3039           (if (or (eq result 'pseudo)
3040                   (eq result 'nneething))
3041               (progn
3042                 (save-excursion
3043                   (set-buffer summary-buffer)
3044                   (push article gnus-newsgroup-history)
3045                   (setq gnus-last-article gnus-current-article
3046                         gnus-current-article 0
3047                         gnus-current-headers nil
3048                         gnus-article-current nil)
3049                   (if (eq result 'nneething)
3050                       (gnus-configure-windows 'summary)
3051                     (gnus-configure-windows 'article))
3052                   (gnus-set-global-variables))
3053                 (let ((gnus-article-mime-handle-alist-1
3054                        gnus-article-mime-handle-alist))
3055                   (gnus-set-mode-line 'article)))
3056             ;; The result from the `request' was an actual article -
3057             ;; or at least some text that is now displayed in the
3058             ;; article buffer.
3059             (when (and (numberp article)
3060                        (not (eq article gnus-current-article)))
3061               ;; Seems like a new article has been selected.
3062               ;; `gnus-current-article' must be an article number.
3063               (save-excursion
3064                 (set-buffer summary-buffer)
3065                 (push article gnus-newsgroup-history)
3066                 (setq gnus-last-article gnus-current-article
3067                       gnus-current-article article
3068                       gnus-current-headers
3069                       (gnus-summary-article-header gnus-current-article)
3070                       gnus-article-current
3071                       (cons gnus-newsgroup-name gnus-current-article))
3072                 (unless (vectorp gnus-current-headers)
3073                   (setq gnus-current-headers nil))
3074                 (gnus-summary-goto-subject gnus-current-article)
3075                 (when (gnus-summary-show-thread)
3076                   ;; If the summary buffer really was folded, the
3077                   ;; previous goto may not actually have gone to
3078                   ;; the right article, but the thread root instead.
3079                   ;; So we go again.
3080                   (gnus-summary-goto-subject gnus-current-article))
3081                 (gnus-run-hooks 'gnus-mark-article-hook)
3082                 (gnus-set-mode-line 'summary)
3083                 (when (gnus-visual-p 'article-highlight 'highlight)
3084                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3085                 ;; Set the global newsgroup variables here.
3086                 (gnus-set-global-variables)
3087                 (setq gnus-have-all-headers
3088                       (or all-headers gnus-show-all-headers))))
3089             (when (or (numberp article)
3090                       (stringp article))
3091               (gnus-article-prepare-display)
3092               ;; Do page break.
3093               (goto-char (point-min))
3094               (setq gnus-page-broken
3095                     (when gnus-break-pages
3096                       (gnus-narrow-to-page)
3097                       t)))
3098             (let ((gnus-article-mime-handle-alist-1
3099                    gnus-article-mime-handle-alist))
3100               (gnus-set-mode-line 'article))
3101             (article-goto-body)
3102             (set-window-point (get-buffer-window (current-buffer)) (point))
3103             (gnus-configure-windows 'article)
3104             t))))))
3105
3106 (defun gnus-article-prepare-mime-display (&optional number)
3107   (goto-char (point-min))
3108   (when (re-search-forward "^[^\t ]+:" nil t)
3109     (goto-char (match-beginning 0)))
3110   (let ((entity (if (eq 1 (point-min))
3111                     (get-text-property 1 'mime-view-entity)
3112                   (get-text-property (point) 'mime-view-entity)))
3113         last-entity child-entity next type)
3114     (setq child-entity (mime-entity-children entity))
3115     (if child-entity
3116         (setq last-entity (nth (1- (length child-entity))
3117                                child-entity))
3118       (setq last-entity entity))
3119     (save-restriction
3120       (narrow-to-region (point)
3121                         (if (search-forward "\n\n" nil t)
3122                             (point)
3123                           (point-max)))
3124       (gnus-treat-article 'head)
3125       (put-text-property (point-min) (point-max) 'article-treated-header t)
3126       (goto-char (point-max)))
3127     (while (and (not (eobp)) entity)
3128       (setq next (set-marker
3129                   (make-marker)
3130                   (next-single-property-change (point) 'mime-view-entity
3131                                                nil (point-max))))
3132       (let ((types (mime-entity-content-type entity)))
3133         (while (eq 'multipart (mime-content-type-primary-type types))
3134           (setq entity (car (mime-entity-children entity))
3135                 types (mime-entity-content-type entity)))
3136         (when types
3137           (setq type (format "%s/%s"
3138                              (mime-content-type-primary-type types)
3139                              (mime-content-type-subtype types)))))
3140       (if (string-equal type "message/rfc822")
3141           (progn
3142             (setq next (point))
3143             (let ((children (mime-entity-children entity))
3144                   last-children)
3145               (when children
3146                 (setq last-children (nth (1- (length children)) children))
3147                 (while
3148                     (and
3149                      (not (eq last-children
3150                               (get-text-property next 'mime-view-entity)))
3151                      (setq next
3152                            (next-single-property-change next
3153                                                         'mime-view-entity
3154                                                         nil (point-max)))))))
3155             (setq next (next-single-property-change next 'mime-view-entity
3156                                                     nil (point-max)))
3157             (save-restriction
3158               (narrow-to-region (point) next)
3159               (gnus-article-prepare-mime-display)
3160               (goto-char (point-max)))
3161             (setq entity (get-text-property (point) 'mime-view-entity)))
3162         (save-restriction
3163           (narrow-to-region (point) next)
3164           ;; Kludge. We have to count true number, but for now,
3165           ;; part number is here only to achieve `last'.
3166           (gnus-treat-article nil 1
3167                               (if (eq entity last-entity)
3168                                   1 2)
3169                               type)
3170           (goto-char (point-max)))
3171         (setq entity (get-text-property next 'mime-view-entity))))))
3172
3173 ;;;###autoload
3174 (defun gnus-article-prepare-display ()
3175   "Make the current buffer look like a nice article."
3176   (setq gnus-article-wash-types nil)
3177   (gnus-run-hooks 'gnus-tmp-internal-hook)
3178   (gnus-run-hooks 'gnus-article-prepare-hook)
3179   ;; Display message.
3180   (let (mime-display-header-hook mime-display-text/plain-hook)
3181     (funcall (if gnus-show-mime
3182                  (progn
3183                    (setq mime-message-structure gnus-current-headers)
3184                    (mime-buffer-entity-set-buffer-internal
3185                     mime-message-structure
3186                     gnus-original-article-buffer)
3187                    (mime-entity-set-representation-type-internal
3188                     mime-message-structure 'mime-buffer-entity)
3189                    (luna-send mime-message-structure
3190                               'initialize-instance
3191                               mime-message-structure)
3192                    gnus-article-display-method-for-mime)
3193                gnus-article-display-method-for-traditional)))
3194   ;; Associate this article with the current summary buffer.
3195   (setq gnus-article-current-summary gnus-summary-buffer)
3196   ;; Call the treatment functions.
3197   (let ((inhibit-read-only t)
3198         buffer-read-only)
3199     (save-restriction
3200       (widen)
3201       (if gnus-show-mime
3202           (gnus-article-prepare-mime-display)
3203         (narrow-to-region (goto-char (point-min))
3204                           (if (search-forward "\n\n" nil t)
3205                               (point)
3206                             (point-max)))
3207         (gnus-treat-article 'head)
3208         (put-text-property (point-min) (point-max) 'article-treated-header t)
3209         (goto-char (point-max))
3210         (widen)
3211         (narrow-to-region (point) (point-max))
3212         (gnus-treat-article nil))
3213       (put-text-property (point-min) (point-max) 'read-only nil)))
3214   ;; Perform the article display hooks.  Incidentally, this hook is
3215   ;; an obsolete variable by now.
3216   (gnus-run-hooks 'gnus-article-display-hook))
3217
3218 (defun gnus-article-decode-article-as-default-mime-charset ()
3219   "Decode an article as `default-mime-charset'.  It won't work if the
3220 value of the variable `gnus-show-mime' is non-nil."
3221   (unless gnus-show-mime
3222     (decode-mime-charset-region (point-min) (point-max)
3223                                 (with-current-buffer gnus-summary-buffer
3224                                   default-mime-charset))))
3225
3226 ;;;
3227 ;;; Gnus MIME viewing functions
3228 ;;;
3229
3230 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3231   "The following specs can be used:
3232 %t  The MIME type
3233 %T  MIME type, along with additional info
3234 %n  The `name' parameter
3235 %d  The description, if any
3236 %l  The length of the encoded part
3237 %p  The part identifier number
3238 %e  Dots if the part isn't displayed")
3239
3240 (defvar gnus-mime-button-line-format-alist
3241   '((?t gnus-tmp-type ?s)
3242     (?T gnus-tmp-type-long ?s)
3243     (?n gnus-tmp-name ?s)
3244     (?d gnus-tmp-description ?s)
3245     (?p gnus-tmp-id ?s)
3246     (?l gnus-tmp-length ?d)
3247     (?e gnus-tmp-dots ?s)))
3248
3249 (defvar gnus-mime-button-commands
3250   '((gnus-article-press-button "\r" "Toggle Display")
3251     (gnus-mime-view-part "v" "View Interactively...")
3252     (gnus-mime-view-part-as-type "t" "View As Type...")
3253     (gnus-mime-save-part "o" "Save...")
3254     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3255     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3256     (gnus-mime-internalize-part "E" "View Internally")
3257     (gnus-mime-externalize-part "e" "View Externally")
3258     (gnus-mime-pipe-part "|" "Pipe To Command...")))
3259
3260 (defun gnus-article-mime-part-status ()
3261   (with-current-buffer gnus-article-buffer
3262     (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3263       (if (and entity (mime-entity-children entity))
3264           (format " (%d parts)" (length (mime-entity-children entity)))
3265         ""))))
3266
3267 (defvar gnus-mime-button-map
3268   (let ((map (make-sparse-keymap)))
3269     (set-keymap-parent map gnus-article-mode-map)
3270     (define-key map gnus-mouse-2 'gnus-article-push-button)
3271     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3272     (dolist (c gnus-mime-button-commands)
3273       (define-key map (cadr c) (car c)))
3274     map))
3275
3276 (defun gnus-mime-button-menu (event)
3277   "Construct a context-sensitive menu of MIME commands."
3278   (interactive "e")
3279   (save-excursion
3280     (let ((pos (event-start event)))
3281       (set-buffer (window-buffer (posn-window pos)))
3282       (goto-char (posn-point pos))
3283       (gnus-article-check-buffer)
3284       (let ((response (x-popup-menu
3285                        t `("MIME Part"
3286                            ("" ,@(mapcar (lambda (c)
3287                                            (cons (caddr c) (car c)))
3288                                          gnus-mime-button-commands))))))
3289         (if response
3290             (call-interactively response))))))
3291
3292 (defun gnus-mime-view-all-parts (&optional handles)
3293   "View all the MIME parts."
3294   (interactive)
3295   (save-current-buffer
3296     (set-buffer gnus-article-buffer)
3297     (let ((handles (or handles gnus-article-mime-handles))
3298           (mail-parse-charset gnus-newsgroup-charset)
3299           (mail-parse-ignored-charsets 
3300            (save-excursion (set-buffer gnus-summary-buffer)
3301                            gnus-newsgroup-ignored-charsets)))
3302       (if (stringp (car handles))
3303           (gnus-mime-view-all-parts (cdr handles))
3304         (mapcar 'mm-display-part handles)))))
3305
3306 (defun gnus-mime-save-part ()
3307   "Save the MIME part under point."
3308   (interactive)
3309   (gnus-article-check-buffer)
3310   (let ((data (get-text-property (point) 'gnus-data)))
3311     (mm-save-part data)))
3312
3313 (defun gnus-mime-pipe-part ()
3314   "Pipe the MIME part under point to a process."
3315   (interactive)
3316   (gnus-article-check-buffer)
3317   (let ((data (get-text-property (point) 'gnus-data)))
3318     (mm-pipe-part data)))
3319
3320 (defun gnus-mime-view-part ()
3321   "Interactively choose a viewing method for the MIME part under point."
3322   (interactive)
3323   (gnus-article-check-buffer)
3324   (let ((data (get-text-property (point) 'gnus-data)))
3325     (mm-interactively-view-part data)))
3326
3327 (defun gnus-mime-view-part-as-type-internal ()
3328   (gnus-article-check-buffer)
3329   (let* ((name (mail-content-type-get
3330                 (mm-handle-type (get-text-property (point) 'gnus-data))
3331                 'name))
3332          (def-type (and name (mm-default-file-encoding name))))
3333     (and def-type (cons def-type 0))))
3334
3335 (defun gnus-mime-view-part-as-type (mime-type)
3336   "Choose a MIME media type, and view the part as such."
3337   (interactive
3338    (list (completing-read
3339           "View as MIME type: "
3340           (mapcar #'list (mailcap-mime-types))
3341           nil nil
3342           (gnus-mime-view-part-as-type-internal))))
3343   (gnus-article-check-buffer)
3344   (let ((handle (get-text-property (point) 'gnus-data)))
3345     (gnus-mm-display-part
3346      (mm-make-handle (mm-handle-buffer handle)
3347                      (cons mime-type (cdr (mm-handle-type handle)))
3348                      (mm-handle-encoding handle)
3349                      (mm-handle-undisplayer handle)
3350                      (mm-handle-disposition handle)
3351                      (mm-handle-description handle)
3352                      (mm-handle-cache handle)
3353                      (mm-handle-id handle)))))
3354
3355 (defun gnus-mime-copy-part (&optional handle)
3356   "Put the the MIME part under point into a new buffer."
3357   (interactive)
3358   (gnus-article-check-buffer)
3359   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3360          (contents (mm-get-part handle))|
3361          (base (file-name-nondirectory
3362                 (or
3363                  (mail-content-type-get (mm-handle-type handle) 'name)
3364                  (mail-content-type-get (mm-handle-type handle)
3365                                         'filename)
3366                  "*decoded*")))
3367          (buffer (generate-new-buffer base)))
3368     (switch-to-buffer buffer)
3369     (insert contents)
3370     ;; We do it this way to make `normal-mode' set the appropriate mode.
3371     (unwind-protect
3372         (progn
3373           (setq buffer-file-name (expand-file-name base))
3374           (normal-mode))
3375       (setq buffer-file-name nil))
3376     (goto-char (point-min))))
3377
3378 (defun gnus-mime-inline-part (&optional handle)
3379   "Insert the MIME part under point into the current buffer."
3380   (interactive)
3381   (gnus-article-check-buffer)
3382   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3383          contents
3384          (b (point))
3385          buffer-read-only)
3386     (if (mm-handle-undisplayer handle)
3387         (mm-remove-part handle)
3388       (setq contents (mm-get-part handle))
3389       (forward-line 2)
3390       (mm-insert-inline handle contents)
3391       (goto-char b))))
3392
3393 (defun gnus-mime-externalize-part (&optional handle)
3394   "View the MIME part under point with an external viewer."
3395   (interactive)
3396   (gnus-article-check-buffer)
3397   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3398          (mm-user-display-methods nil)
3399          (mm-inlined-types nil)
3400          (mail-parse-charset gnus-newsgroup-charset)
3401          (mail-parse-ignored-charsets 
3402           (save-excursion (set-buffer gnus-summary-buffer)
3403                           gnus-newsgroup-ignored-charsets)))
3404     (if (mm-handle-undisplayer handle)
3405         (mm-remove-part handle)
3406       (mm-display-part handle))))
3407
3408 (defun gnus-mime-internalize-part (&optional handle)
3409   "View the MIME part under point with an internal viewer.
3410 In no internal viewer is available, use an external viewer."
3411   (interactive)
3412   (gnus-article-check-buffer)
3413   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3414          (mm-inlined-types '(".*"))
3415          (mm-inline-large-images t)
3416          (mail-parse-charset gnus-newsgroup-charset)
3417          (mail-parse-ignored-charsets 
3418           (save-excursion (set-buffer gnus-summary-buffer)
3419                           gnus-newsgroup-ignored-charsets)))
3420     (if (mm-handle-undisplayer handle)
3421         (mm-remove-part handle)
3422       (mm-display-part handle))))
3423
3424 (defun gnus-article-part-wrapper (n function)
3425   (save-current-buffer
3426     (set-buffer gnus-article-buffer)
3427     (when (> n (length gnus-article-mime-handle-alist))
3428       (error "No such part"))
3429     (gnus-article-goto-part n)
3430     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3431       (funcall function handle))))
3432
3433 (defun gnus-article-pipe-part (n)
3434   "Pipe MIME part N, which is the numerical prefix."
3435   (interactive "p")
3436   (gnus-article-part-wrapper n 'mm-pipe-part))
3437
3438 (defun gnus-article-save-part (n)
3439   "Save MIME part N, which is the numerical prefix."
3440   (interactive "p")
3441   (gnus-article-part-wrapper n 'mm-save-part))
3442
3443 (defun gnus-article-interactively-view-part (n)
3444   "View MIME part N interactively, which is the numerical prefix."
3445   (interactive "p")
3446   (gnus-article-part-wrapper n 'mm-interactively-view-part))
3447
3448 (defun gnus-article-copy-part (n)
3449   "Copy MIME part N, which is the numerical prefix."
3450   (interactive "p")
3451   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3452
3453 (defun gnus-article-externalize-part (n)
3454   "View MIME part N externally, which is the numerical prefix."
3455   (interactive "p")
3456   (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3457
3458 (defun gnus-article-inline-part (n)
3459   "Inline MIME part N, which is the numerical prefix."
3460   (interactive "p")
3461   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3462
3463 (defun gnus-article-mime-match-handle-first (condition)
3464   (if condition
3465       (let ((alist gnus-article-mime-handle-alist) ihandle n)
3466         (while (setq ihandle (pop alist))
3467           (if (and (cond 
3468                     ((functionp condition)
3469                      (funcall condition (cdr ihandle)))
3470                     ((eq condition 'undisplayed) 
3471                      (not (or (mm-handle-undisplayer (cdr ihandle))
3472                               (equal (mm-handle-media-type (cdr ihandle))
3473                                      "multipart/alternative"))))
3474                     ((eq condition 'undisplayed-alternative)
3475                      (not (mm-handle-undisplayer (cdr ihandle))))
3476                     (t t))
3477                    (gnus-article-goto-part (car ihandle))
3478                    (or (not n) (< (car ihandle) n)))
3479               (setq n (car ihandle))))
3480         (or n 1))
3481     1))
3482
3483 (defun gnus-article-view-part (&optional n)
3484   "View MIME part N, which is the numerical prefix."
3485   (interactive "P")
3486   (save-current-buffer
3487     (set-buffer gnus-article-buffer)
3488     (or (numberp n) (setq n (gnus-article-mime-match-handle-first 
3489                              gnus-article-mime-match-handle-function)))
3490     (when (> n (length gnus-article-mime-handle-alist))
3491       (error "No such part"))
3492     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3493       (when (gnus-article-goto-part n)
3494         (if (equal (car handle) "multipart/alternative")
3495             (gnus-article-press-button)
3496           (when (eq (gnus-mm-display-part handle) 'internal)
3497             (gnus-set-window-start)))))))
3498
3499 (defun gnus-mm-display-part (handle)
3500   "Display HANDLE and fix MIME button."
3501   (let ((id (get-text-property (point) 'gnus-part))
3502         (point (point))
3503         buffer-read-only)
3504     (forward-line 1)
3505     (prog1
3506         (let ((window (selected-window))
3507               (mail-parse-charset gnus-newsgroup-charset)
3508               (mail-parse-ignored-charsets 
3509                (save-excursion (set-buffer gnus-summary-buffer)
3510                                gnus-newsgroup-ignored-charsets)))
3511           (save-excursion
3512             (unwind-protect
3513                 (let ((win (get-buffer-window (current-buffer) t))
3514                       (beg (point)))
3515                   (when win
3516                     (select-window win))
3517                   (goto-char point)
3518                   (forward-line)
3519                   (if (mm-handle-displayed-p handle)
3520                       ;; This will remove the part.
3521                       (mm-display-part handle)
3522                     (save-restriction
3523                       (narrow-to-region (point) (1+ (point)))
3524                       (mm-display-part handle)
3525                       ;; We narrow to the part itself and
3526                       ;; then call the treatment functions.
3527                       (goto-char (point-min))
3528                       (forward-line 1)
3529                       (narrow-to-region (point) (point-max))
3530                       (gnus-treat-article
3531                        nil id
3532                        (1- (length gnus-article-mime-handles))
3533                        (mm-handle-media-type handle)))))
3534               (select-window window))))
3535       (goto-char point)
3536       (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3537       (gnus-insert-mime-button
3538        handle id (list (mm-handle-displayed-p handle)))
3539       (goto-char point))))
3540
3541 (defun gnus-article-goto-part (n)
3542   "Go to MIME part N."
3543   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3544     (when point
3545       (goto-char point))))
3546
3547 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3548   (let ((gnus-tmp-name
3549          (or (mail-content-type-get (mm-handle-type handle)
3550                                     'name)
3551              (mail-content-type-get (mm-handle-disposition handle)
3552                                     'filename)
3553              ""))
3554         (gnus-tmp-type (mm-handle-media-type handle))
3555         (gnus-tmp-description
3556          (mail-decode-encoded-word-string (or (mm-handle-description handle)
3557                                               "")))
3558         (gnus-tmp-dots
3559          (if (if displayed (car displayed)
3560                (mm-handle-displayed-p handle))
3561              "" "..."))
3562         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3563                            (buffer-size)))
3564         gnus-tmp-type-long b e)
3565     (when (string-match ".*/" gnus-tmp-name)
3566       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3567     (setq gnus-tmp-type-long (concat gnus-tmp-type
3568                                      (and (not (equal gnus-tmp-name ""))
3569                                           (concat "; " gnus-tmp-name))))
3570     (or (equal gnus-tmp-description "")
3571         (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3572     (unless (bolp)
3573       (insert "\n"))
3574     (setq b (point))
3575     (gnus-eval-format
3576      gnus-mime-button-line-format gnus-mime-button-line-format-alist
3577      `(local-map ,gnus-mime-button-map
3578                  keymap ,gnus-mime-button-map
3579                  gnus-callback gnus-mm-display-part
3580                  gnus-part ,gnus-tmp-id
3581                  article-type annotation
3582                  gnus-data ,handle))
3583     (setq e (point))
3584     (widget-convert-button
3585      'link b e
3586      :mime-handle handle
3587      :action 'gnus-widget-press-button
3588      :button-keymap gnus-mime-button-map
3589      :help-echo
3590      (lambda (widget/window &optional overlay pos)
3591        ;; Needed to properly clear the message due to a bug in
3592        ;; wid-edit (XEmacs only).
3593        (if (boundp 'help-echo-owns-message)
3594            (setq help-echo-owns-message t))
3595        (format
3596         "%S: %s the MIME part; %S: more options"
3597         (aref gnus-mouse-2 0)
3598         ;; XEmacs will get a single widget arg; Emacs 21 will get
3599         ;; window, overlay, position.
3600         (if (mm-handle-displayed-p
3601              (if overlay
3602                  (with-current-buffer (overlay-buffer overlay)
3603                    (widget-get (widget-at (overlay-start overlay))
3604                                :mime-handle))
3605                (widget-get widget/window :mime-handle)))
3606             "hide" "show")
3607         (aref gnus-down-mouse-3 0))))))
3608
3609 (defun gnus-widget-press-button (elems el)
3610   (goto-char (widget-get elems :from))
3611   (gnus-article-press-button))
3612
3613 (defvar gnus-displaying-mime nil)
3614
3615 (defun gnus-display-mime (&optional ihandles)
3616   "Display the MIME parts."
3617   (save-excursion
3618     (save-selected-window
3619       (let ((window (get-buffer-window gnus-article-buffer))
3620             (point (point)))
3621         (when window
3622           (select-window window)
3623           ;; We have to do this since selecting the window
3624           ;; may change the point.  So we set the window point.
3625           (set-window-point window point)))
3626       (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3627              buffer-read-only handle name type b e display)
3628         (when (and (not ihandles)
3629                    (not gnus-displaying-mime))
3630           ;; Top-level call; we clean up.
3631           (when gnus-article-mime-handles
3632             (mm-destroy-parts gnus-article-mime-handles)
3633             (setq gnus-article-mime-handle-alist nil));; A trick.
3634           (setq gnus-article-mime-handles handles)
3635           ;; We allow users to glean info from the handles.
3636           (when gnus-article-mime-part-function
3637             (gnus-mime-part-function handles)))
3638         (if (and handles
3639                  (or (not (stringp (car handles)))
3640                      (cdr handles)))
3641             (progn
3642               (when (and (not ihandles)
3643                          (not gnus-displaying-mime))
3644                 ;; Clean up for mime parts.
3645                 (article-goto-body)
3646                 (delete-region (point) (point-max)))
3647               (let ((gnus-displaying-mime t))
3648                 (gnus-mime-display-part handles)))
3649           (save-restriction
3650             (article-goto-body)
3651             (narrow-to-region (point) (point-max))
3652             (gnus-treat-article nil 1 1)
3653             (widen)))
3654         (unless ihandles
3655           ;; Highlight the headers.
3656           (save-excursion
3657             (save-restriction
3658               (article-goto-body)
3659               (narrow-to-region (point-min) (point))
3660               (gnus-treat-article 'head))))))))
3661
3662 (defvar gnus-mime-display-multipart-as-mixed nil)
3663
3664 (defun gnus-mime-display-part (handle)
3665   (cond
3666    ;; Single part.
3667    ((not (stringp (car handle)))
3668     (gnus-mime-display-single handle))
3669    ;; User-defined multipart
3670    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3671     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3672              handle))
3673    ;; multipart/alternative
3674    ((and (equal (car handle) "multipart/alternative")
3675          (not gnus-mime-display-multipart-as-mixed))
3676     (let ((id (1+ (length gnus-article-mime-handle-alist))))
3677       (push (cons id handle) gnus-article-mime-handle-alist)
3678       (gnus-mime-display-alternative (cdr handle) nil nil id)))
3679    ;; multipart/related
3680    ((and (equal (car handle) "multipart/related")
3681          (not gnus-mime-display-multipart-as-mixed))
3682     ;;;!!!We should find the start part, but we just default
3683     ;;;!!!to the first part.
3684     (gnus-mime-display-part (cadr handle)))
3685    ;; Other multiparts are handled like multipart/mixed.
3686    (t
3687     (gnus-mime-display-mixed (cdr handle)))))
3688
3689 (defun gnus-mime-part-function (handles)
3690   (if (stringp (car handles))
3691       (mapcar 'gnus-mime-part-function (cdr handles))
3692     (funcall gnus-article-mime-part-function handles)))
3693
3694 (defun gnus-mime-display-mixed (handles)
3695   (mapcar 'gnus-mime-display-part handles))
3696
3697 (defun gnus-mime-display-single (handle)
3698   (let ((type (mm-handle-media-type handle))
3699         (ignored gnus-ignored-mime-types)
3700         (not-attachment t)
3701         (move nil)
3702         display text)
3703     (catch 'ignored
3704       (progn
3705         (while ignored
3706           (when (string-match (pop ignored) type)
3707             (throw 'ignored nil)))
3708         (if (and (setq not-attachment
3709                        (and (not (mm-inline-override-p handle))
3710                             (or (not (mm-handle-disposition handle))
3711                                 (equal (car (mm-handle-disposition handle))
3712                                        "inline")
3713                                 (mm-attachment-override-p handle))))
3714                  (mm-automatic-display-p handle)
3715                  (or (mm-inlined-p handle)
3716                      (mm-automatic-external-display-p type)))
3717             (setq display t)
3718           (when (equal (mm-handle-media-supertype handle) "text")
3719             (setq text t)))
3720         (let ((id (1+ (length gnus-article-mime-handle-alist))))
3721           (push (cons id handle) gnus-article-mime-handle-alist)
3722           (when (or (not display)
3723                     (not (gnus-unbuttonized-mime-type-p type)))
3724             ;(gnus-article-insert-newline)
3725             (gnus-insert-mime-button
3726              handle id (list (or display (and not-attachment text))))
3727             (gnus-article-insert-newline)
3728             ;(gnus-article-insert-newline)
3729             (setq move t)))
3730         (let ((beg (point)))
3731           (cond
3732            (display
3733             (when move
3734               (forward-line -2)
3735               (setq beg (point)))
3736             (let ((mail-parse-charset gnus-newsgroup-charset)
3737                   (mail-parse-ignored-charsets 
3738                    (save-excursion (condition-case ()
3739                                        (set-buffer gnus-summary-buffer)
3740                                      (error))
3741                                    gnus-newsgroup-ignored-charsets)))
3742               (mm-display-part handle t))
3743             (goto-char (point-max)))
3744            ((and text not-attachment)
3745             (when move
3746               (forward-line -2)
3747               (setq beg (point)))
3748             (gnus-article-insert-newline)
3749             (mm-insert-inline handle (mm-get-part handle))
3750             (goto-char (point-max))))
3751           ;; Do highlighting.
3752           (save-excursion
3753             (save-restriction
3754               (narrow-to-region beg (point))
3755               (gnus-treat-article
3756                nil (length gnus-article-mime-handle-alist)
3757                (1- (length gnus-article-mime-handles))
3758                (mm-handle-media-type handle)))))))))
3759
3760 (defun gnus-unbuttonized-mime-type-p (type)
3761   "Say whether TYPE is to be unbuttonized."
3762   (unless gnus-inhibit-mime-unbuttonizing
3763     (catch 'found
3764       (let ((types gnus-unbuttonized-mime-types))
3765         (while types
3766           (when (string-match (pop types) type)
3767             (throw 'found t)))))))
3768
3769 (defun gnus-article-insert-newline ()
3770   "Insert a newline, but mark it as undeletable."
3771   (gnus-put-text-property
3772    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3773
3774 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3775   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3776          (ihandles handles)
3777          (point (point))
3778          handle buffer-read-only from props begend not-pref)
3779     (save-window-excursion
3780       (save-restriction
3781         (when ibegend
3782           (narrow-to-region (car ibegend)
3783                             (or (cdr ibegend)
3784                                 (progn
3785                                   (goto-char (car ibegend))
3786                                   (forward-line 2)
3787                                   (point))))
3788           (delete-region (point-min) (point-max))
3789           (mm-remove-parts handles))
3790         (setq begend (list (point-marker)))
3791         ;; Do the toggle.
3792         (unless (setq not-pref (cadr (member preferred ihandles)))
3793           (setq not-pref (car ihandles)))
3794         (when (or ibegend
3795                   (not (gnus-unbuttonized-mime-type-p
3796                         "multipart/alternative")))
3797           (gnus-add-text-properties
3798            (setq from (point))
3799            (progn
3800              (insert (format "%d.  " id))
3801              (point))
3802            `(gnus-callback
3803              (lambda (handles)
3804                (unless ,(not ibegend)
3805                  (setq gnus-article-mime-handle-alist
3806                        ',gnus-article-mime-handle-alist))
3807                (gnus-mime-display-alternative
3808                 ',ihandles ',not-pref ',begend ,id))
3809              local-map ,gnus-mime-button-map
3810              ,gnus-mouse-face-prop ,gnus-article-mouse-face
3811              face ,gnus-article-button-face
3812              keymap ,gnus-mime-button-map
3813              gnus-part ,id
3814              gnus-data ,handle))
3815           (widget-convert-button 'link from (point)
3816                                  :action 'gnus-widget-press-button
3817                                  :button-keymap gnus-widget-button-keymap)
3818           ;; Do the handles
3819           (while (setq handle (pop handles))
3820             (gnus-add-text-properties
3821              (setq from (point))
3822              (progn
3823                (insert (format "(%c) %-18s"
3824                                (if (equal handle preferred) ?* ? )
3825                                (mm-handle-media-type handle)))
3826                (point))
3827              `(gnus-callback
3828                (lambda (handles)
3829                  (unless ,(not ibegend)
3830                    (setq gnus-article-mime-handle-alist
3831                          ',gnus-article-mime-handle-alist))
3832                  (gnus-mime-display-alternative
3833                   ',ihandles ',handle ',begend ,id))
3834                local-map ,gnus-mime-button-map
3835                ,gnus-mouse-face-prop ,gnus-article-mouse-face
3836                face ,gnus-article-button-face
3837                keymap ,gnus-mime-button-map
3838                gnus-part ,id
3839                gnus-data ,handle))
3840             (widget-convert-button 'link from (point)
3841                                    :action 'gnus-widget-press-button
3842                                    :button-keymap gnus-widget-button-keymap)
3843             (insert "  "))
3844           (insert "\n\n"))
3845         (when preferred
3846           (if (stringp (car preferred))
3847               (gnus-display-mime preferred)
3848             (let ((mail-parse-charset gnus-newsgroup-charset)
3849                   (mail-parse-ignored-charsets 
3850                    (save-excursion (set-buffer gnus-summary-buffer)
3851                                    gnus-newsgroup-ignored-charsets)))
3852               (mm-display-part preferred)
3853               ;; Do highlighting.
3854               (save-excursion
3855                 (save-restriction
3856                   (narrow-to-region (car begend) (point-max))
3857                   (gnus-treat-article
3858                    nil (length gnus-article-mime-handle-alist)
3859                    (1- (length gnus-article-mime-handles))
3860                    (mm-handle-media-type handle))))))
3861           (goto-char (point-max))
3862           (setcdr begend (point-marker)))))
3863     (when ibegend
3864       (goto-char point))))
3865
3866 (defun gnus-article-wash-status ()
3867   "Return a string which display status of article washing."
3868   (save-excursion
3869     (set-buffer gnus-article-buffer)
3870     (let ((cite (memq 'cite gnus-article-wash-types))
3871           (headers (memq 'headers gnus-article-wash-types))
3872           (boring (memq 'boring-headers gnus-article-wash-types))
3873           (pgp (memq 'pgp gnus-article-wash-types))
3874           (pem (memq 'pem gnus-article-wash-types))
3875           (signature (memq 'signature gnus-article-wash-types))
3876           (overstrike (memq 'overstrike gnus-article-wash-types))
3877           (emphasis (memq 'emphasis gnus-article-wash-types)))
3878       (format "%c%c%c%c%c%c%c"
3879               (if cite ?c ? )
3880               (if (or headers boring) ?h ? )
3881               (if (or pgp pem) ?p ? )
3882               (if signature ?s ? )
3883               (if overstrike ?o ? )
3884               (if gnus-show-mime ?m ? )
3885               (if emphasis ?e ? )))))
3886
3887 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3888
3889 (defun gnus-article-maybe-hide-headers ()
3890   "Hide unwanted headers if `gnus-have-all-headers' is nil.
3891 Provided for backwards compatibility."
3892   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3893                  (not (save-excursion (set-buffer gnus-summary-buffer)
3894                                       gnus-have-all-headers)))
3895              (not gnus-inhibit-hiding))
3896     (gnus-article-hide-headers)))
3897
3898 ;;; Article savers.
3899
3900 (defun gnus-output-to-file (file-name)
3901   "Append the current article to a file named FILE-NAME."
3902   (let ((artbuf (current-buffer)))
3903     (with-temp-buffer
3904       (insert-buffer-substring artbuf)
3905       ;; Append newline at end of the buffer as separator, and then
3906       ;; save it to file.
3907       (goto-char (point-max))
3908       (insert "\n")
3909       (write-region-as-binary (point-min) (point-max) file-name 'append)
3910       t)))
3911
3912 (defun gnus-narrow-to-page (&optional arg)
3913   "Narrow the article buffer to a page.
3914 If given a numerical ARG, move forward ARG pages."
3915   (interactive "P")
3916   (setq arg (if arg (prefix-numeric-value arg) 0))
3917   (save-excursion
3918     (set-buffer gnus-article-buffer)
3919     (goto-char (point-min))
3920     (widen)
3921     ;; Remove any old next/prev buttons.
3922     (when (gnus-visual-p 'page-marker)
3923       (let ((buffer-read-only nil))
3924         (gnus-remove-text-with-property 'gnus-prev)
3925         (gnus-remove-text-with-property 'gnus-next)))
3926     (when
3927         (cond ((< arg 0)
3928                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3929               ((> arg 0)
3930                (re-search-forward page-delimiter nil 'move arg)))
3931       (goto-char (match-end 0)))
3932     (narrow-to-region
3933      (point)
3934      (if (re-search-forward page-delimiter nil 'move)
3935          (match-beginning 0)
3936        (point)))
3937     (when (and (gnus-visual-p 'page-marker)
3938                (not (= (point-min) 1)))
3939       (save-excursion
3940         (goto-char (point-min))
3941         (gnus-insert-prev-page-button)))
3942     (when (and (gnus-visual-p 'page-marker)
3943                (< (+ (point-max) 2) (buffer-size)))
3944       (save-excursion
3945         (goto-char (point-max))
3946         (gnus-insert-next-page-button)))))
3947
3948 ;; Article mode commands
3949
3950 (defun gnus-article-goto-next-page ()
3951   "Show the next page of the article."
3952   (interactive)
3953   (when (gnus-article-next-page)
3954     (goto-char (point-min))
3955     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3956
3957 (defun gnus-article-goto-prev-page ()
3958   "Show the next page of the article."
3959   (interactive)
3960   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3961     (gnus-article-prev-page nil)))
3962
3963 (defun gnus-article-next-page (&optional lines)
3964   "Show the next page of the current article.
3965 If end of article, return non-nil.  Otherwise return nil.
3966 Argument LINES specifies lines to be scrolled up."
3967   (interactive "p")
3968   (let ((start (window-start))
3969         end-of-buffer end-of-page)
3970     (save-excursion
3971       (move-to-window-line -1)
3972       (if (<= (point) start)
3973           (progn
3974             (forward-line 2)
3975             (setq start (point)))
3976         (forward-line 1)
3977         (setq start nil))
3978       (unless (or (cond ((eq (1+ (buffer-size)) (point))
3979                          (and (pos-visible-in-window-p)
3980                               (setq end-of-buffer t)))
3981                         ((eobp)
3982                          (setq end-of-page t)))
3983                   (not lines))
3984         (move-to-window-line lines)
3985         (unless (search-backward "\n\n" nil t)
3986           (setq start (point)))))
3987     (cond (end-of-buffer t)
3988           (end-of-page
3989            (gnus-narrow-to-page 1)
3990            nil)
3991           (t
3992            (if start
3993                (set-window-start (selected-window) start)
3994              (let (window-pixel-scroll-increment)
3995                (scroll-up lines)))
3996            nil))))
3997
3998 (defun gnus-article-prev-page (&optional lines)
3999   "Show previous page of current article.
4000 Argument LINES specifies lines to be scrolled down."
4001   (interactive "p")
4002   (let (beginning-of-buffer beginning-of-page)
4003     (save-excursion
4004       (move-to-window-line 0)
4005       (cond ((eq 1 (point))
4006              (setq beginning-of-buffer t))
4007             ((bobp)
4008              (setq beginning-of-page t))))
4009     (cond (beginning-of-buffer)
4010           (beginning-of-page
4011            (gnus-narrow-to-page -1))
4012           (t
4013            (condition-case nil
4014                (let (window-pixel-scroll-increment)
4015                  (scroll-down lines))
4016              (beginning-of-buffer
4017               (goto-char (point-min))))))))
4018
4019 (defun gnus-article-refer-article ()
4020   "Read article specified by message-id around point."
4021   (interactive)
4022   (let ((point (point)))
4023     (search-forward ">" nil t)          ;Move point to end of "<....>".
4024     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4025         (let ((message-id (match-string 1)))
4026           (goto-char point)
4027           (set-buffer gnus-summary-buffer)
4028           (gnus-summary-refer-article message-id))
4029       (goto-char (point))
4030       (error "No references around point"))))
4031
4032 (defun gnus-article-show-summary ()
4033   "Reconfigure windows to show summary buffer."
4034   (interactive)
4035   (if (not (gnus-buffer-live-p gnus-summary-buffer))
4036       (error "There is no summary buffer for this article buffer")
4037     (gnus-article-set-globals)
4038     (gnus-configure-windows 'article)
4039     (gnus-summary-goto-subject gnus-current-article)
4040     (gnus-summary-position-point)))
4041
4042 (defun gnus-article-describe-briefly ()
4043   "Describe article mode commands briefly."
4044   (interactive)
4045   (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")))
4046
4047 (defun gnus-article-summary-command ()
4048   "Execute the last keystroke in the summary buffer."
4049   (interactive)
4050   (let ((obuf (current-buffer))
4051         (owin (current-window-configuration))
4052         func)
4053     (switch-to-buffer gnus-article-current-summary 'norecord)
4054     (setq func (lookup-key (current-local-map) (this-command-keys)))
4055     (call-interactively func)
4056     (set-buffer obuf)
4057     (set-window-configuration owin)
4058     (set-window-point (get-buffer-window (current-buffer)) (point))))
4059
4060 (defun gnus-article-summary-command-nosave ()
4061   "Execute the last keystroke in the summary buffer."
4062   (interactive)
4063   (let (func)
4064     (pop-to-buffer gnus-article-current-summary 'norecord)
4065     (setq func (lookup-key (current-local-map) (this-command-keys)))
4066     (call-interactively func)))
4067
4068 (defun gnus-article-check-buffer ()
4069   "Beep if not in an article buffer."
4070   (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4071     (error "Command invoked outside of a Gnus article buffer")))
4072
4073 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4074   "Read a summary buffer key sequence and execute it from the article buffer."
4075   (interactive "P")
4076   (gnus-article-check-buffer)
4077   (let ((nosaves
4078          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
4079            "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4080            "=" "^" "\M-^" "|"))
4081         (nosave-but-article
4082          '("A\r"))
4083         (nosave-in-article
4084          '("\C-d"))
4085         (up-to-top
4086          '("n" "Gn" "p" "Gp"))
4087         keys new-sum-point)
4088     (save-excursion
4089       (set-buffer gnus-article-current-summary)
4090       (let (gnus-pick-mode)
4091         (push (or key last-command-event) unread-command-events)
4092         (setq keys (static-if (featurep 'xemacs)
4093                        (events-to-keys (read-key-sequence nil))
4094                      (read-key-sequence nil)))))
4095     (message "")
4096
4097     (if (or (member keys nosaves)
4098             (member keys nosave-but-article)
4099             (member keys nosave-in-article))
4100         (let (func)
4101           (save-window-excursion
4102             (pop-to-buffer gnus-article-current-summary 'norecord)
4103             ;; We disable the pick minor mode commands.
4104             (let (gnus-pick-mode)
4105               (setq func (lookup-key (current-local-map) keys))))
4106           (if (or (not func)
4107                   (numberp func))
4108               (ding)
4109             (unless (member keys nosave-in-article)
4110               (set-buffer gnus-article-current-summary))
4111             (call-interactively func)
4112             (setq new-sum-point (point)))
4113           (when (member keys nosave-but-article)
4114             (pop-to-buffer gnus-article-buffer 'norecord)))
4115       ;; These commands should restore window configuration.
4116       (let ((obuf (current-buffer))
4117             (owin (current-window-configuration))
4118             (opoint (point))
4119             (summary gnus-article-current-summary)
4120             func in-buffer selected)
4121         (if not-restore-window
4122             (pop-to-buffer summary 'norecord)
4123           (switch-to-buffer summary 'norecord))
4124         (setq in-buffer (current-buffer))
4125         ;; We disable the pick minor mode commands.
4126         (if (setq func (let (gnus-pick-mode)
4127                          (lookup-key (current-local-map) keys)))
4128             (progn
4129               (call-interactively func)
4130               (setq new-sum-point (point)))
4131           (ding))
4132         (when (eq in-buffer (current-buffer))
4133           (setq selected (gnus-summary-select-article))
4134           (set-buffer obuf)
4135           (unless not-restore-window
4136             (set-window-configuration owin))
4137           (when (eq selected 'old)
4138             (article-goto-body)
4139             (set-window-start (get-buffer-window (current-buffer))
4140                               1)
4141             (set-window-point (get-buffer-window (current-buffer))
4142                               (point)))
4143           (let ((win (get-buffer-window gnus-article-current-summary)))
4144             (when win
4145               (set-window-point win new-sum-point))))))))
4146
4147 (defun gnus-article-hide (&optional arg force)
4148   "Hide all the gruft in the current article.
4149 This means that PGP stuff, signatures, cited text and (some)
4150 headers will be hidden.
4151 If given a prefix, show the hidden text instead."
4152   (interactive (append (gnus-article-hidden-arg) (list 'force)))
4153   (gnus-article-hide-headers arg)
4154   (gnus-article-hide-list-identifiers arg)
4155   (gnus-article-hide-pgp arg)
4156   (gnus-article-hide-citation-maybe arg force)
4157   (gnus-article-hide-signature arg))
4158
4159 (defun gnus-article-maybe-highlight ()
4160   "Do some article highlighting if article highlighting is requested."
4161   (when (gnus-visual-p 'article-highlight 'highlight)
4162     (gnus-article-highlight-some)))
4163
4164 (defun gnus-check-group-server ()
4165   ;; Make sure the connection to the server is alive.
4166   (unless (gnus-server-opened
4167            (gnus-find-method-for-group gnus-newsgroup-name))
4168     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4169     (gnus-request-group gnus-newsgroup-name t)))
4170
4171 (defun gnus-request-article-this-buffer (article group)
4172   "Get an article and insert it into this buffer."
4173   (let (do-update-line sparse-header)
4174     (prog1
4175         (save-excursion
4176           (erase-buffer)
4177           (gnus-kill-all-overlays)
4178           (setq group (or group gnus-newsgroup-name))
4179
4180           ;; Using `gnus-request-article' directly will insert the article into
4181           ;; `nntp-server-buffer' - so we'll save some time by not having to
4182           ;; copy it from the server buffer into the article buffer.
4183
4184           ;; We only request an article by message-id when we do not have the
4185           ;; headers for it, so we'll have to get those.
4186           (when (stringp article)
4187             (gnus-read-header article))
4188
4189           ;; If the article number is negative, that means that this article
4190           ;; doesn't belong in this newsgroup (possibly), so we find its
4191           ;; message-id and request it by id instead of number.
4192           (when (and (numberp article)
4193                      gnus-summary-buffer
4194                      (get-buffer gnus-summary-buffer)
4195                      (gnus-buffer-exists-p gnus-summary-buffer))
4196             (save-excursion
4197               (set-buffer gnus-summary-buffer)
4198               (let ((header (gnus-summary-article-header article)))
4199                 (when (< article 0)
4200                   (cond
4201                    ((memq article gnus-newsgroup-sparse)
4202                     ;; This is a sparse gap article.
4203                     (setq do-update-line article)
4204                     (setq article (mail-header-id header))
4205                     (setq sparse-header (gnus-read-header article))
4206                     (setq gnus-newsgroup-sparse
4207                           (delq article gnus-newsgroup-sparse)))
4208                    ((vectorp header)
4209                     ;; It's a real article.
4210                     (setq article (mail-header-id header)))
4211                    (t
4212                     ;; It is an extracted pseudo-article.
4213                     (setq article 'pseudo)
4214                     (gnus-request-pseudo-article header))))
4215
4216                 (let ((method (gnus-find-method-for-group
4217                                gnus-newsgroup-name)))
4218                   (when (and (eq (car method) 'nneething)
4219                              (vectorp header))
4220                     (let ((dir (expand-file-name
4221                                 (mail-header-subject header)
4222                                 (file-name-as-directory
4223                                  (or (cadr (assq 'nneething-address method))
4224                                      (nth 1 method))))))
4225                       (when (file-directory-p dir)
4226                         (setq article 'nneething)
4227                         (gnus-group-enter-directory dir))))))))
4228
4229           (cond
4230            ;; Refuse to select canceled articles.
4231            ((and (numberp article)
4232                  gnus-summary-buffer
4233                  (get-buffer gnus-summary-buffer)
4234                  (gnus-buffer-exists-p gnus-summary-buffer)
4235                  (eq (cdr (save-excursion
4236                             (set-buffer gnus-summary-buffer)
4237                             (assq article gnus-newsgroup-reads)))
4238                      gnus-canceled-mark))
4239             nil)
4240            ;; Check the backlog.
4241            ((and gnus-keep-backlog
4242                  (gnus-backlog-request-article group article (current-buffer)))
4243             'article)
4244            ;; Check asynchronous pre-fetch.
4245            ((gnus-async-request-fetched-article group article (current-buffer))
4246             (gnus-async-prefetch-next group article gnus-summary-buffer)
4247             (when (and (numberp article) gnus-keep-backlog)
4248               (gnus-backlog-enter-article group article (current-buffer)))
4249             'article)
4250            ;; Check the cache.
4251            ((and gnus-use-cache
4252                  (numberp article)
4253                  (gnus-cache-request-article article group))
4254             'article)
4255            ;; Get the article and put into the article buffer.
4256            ((or (stringp article)
4257                 (numberp article))
4258             (let ((gnus-override-method gnus-override-method)
4259                   (methods (and (stringp article) 
4260                                 gnus-refer-article-method))
4261                   result
4262                   (buffer-read-only nil))
4263               (setq methods
4264                     (if (listp methods)
4265                         methods
4266                       (list methods)))
4267               (when (and (null gnus-override-method)
4268                          methods)
4269                 (setq gnus-override-method (pop methods)))
4270               (while (not result)
4271                 (when (eq gnus-override-method 'current)
4272                   (setq gnus-override-method gnus-current-select-method))
4273                 (erase-buffer)
4274                 (gnus-kill-all-overlays)
4275                 (let ((gnus-newsgroup-name group))
4276                   (gnus-check-group-server))
4277                 (when (gnus-request-article article group (current-buffer))
4278                   (when (numberp article)
4279                     (gnus-async-prefetch-next group article 
4280                                               gnus-summary-buffer)
4281                     (when gnus-keep-backlog
4282                       (gnus-backlog-enter-article
4283                        group article (current-buffer))))
4284                   (setq result 'article))
4285                 (if (not result)
4286                     (if methods
4287                         (setq gnus-override-method (pop methods))
4288                       (setq result 'done))))
4289               (and (eq result 'article) 'article)))
4290            ;; It was a pseudo.
4291            (t article)))
4292
4293       ;; Associate this article with the current summary buffer.
4294       (setq gnus-article-current-summary gnus-summary-buffer)
4295
4296       ;; Take the article from the original article buffer
4297       ;; and place it in the buffer it's supposed to be in.
4298       (when (and (get-buffer gnus-article-buffer)
4299                  (equal (buffer-name (current-buffer))
4300                         (buffer-name (get-buffer gnus-article-buffer))))
4301         (save-excursion
4302           (if (get-buffer gnus-original-article-buffer)
4303               (set-buffer gnus-original-article-buffer)
4304             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4305             (set-buffer-multibyte nil)
4306             (buffer-disable-undo)
4307             (setq major-mode 'gnus-original-article-mode)
4308             (setq buffer-read-only t))
4309           (let (buffer-read-only)
4310             (erase-buffer)
4311             (insert-buffer-substring gnus-article-buffer))
4312           (setq gnus-original-article (cons group article)))
4313
4314         ;; Decode charsets.
4315         (run-hooks 'gnus-article-decode-hook)
4316         ;; Mark article as decoded or not.
4317         (setq gnus-article-decoded-p gnus-article-decode-hook))
4318
4319       ;; Update sparse articles.
4320       (when (and do-update-line
4321                  (or (numberp article)
4322                      (stringp article)))
4323         (let ((buf (current-buffer)))
4324           (set-buffer gnus-summary-buffer)
4325           (gnus-summary-update-article do-update-line sparse-header)
4326           (gnus-summary-goto-subject do-update-line nil t)
4327           (set-window-point (get-buffer-window (current-buffer) t)
4328                             (point))
4329           (set-buffer buf))))))
4330
4331 ;;;
4332 ;;; Article editing
4333 ;;;
4334
4335 (defcustom gnus-article-edit-mode-hook nil
4336   "Hook run in article edit mode buffers."
4337   :group 'gnus-article-various
4338   :type 'hook)
4339
4340 (defcustom gnus-article-edit-article-setup-function
4341   'gnus-article-mime-edit-article-setup
4342   "Function called to setup an editing article buffer."
4343   :group 'gnus-article-various
4344   :type 'function)
4345
4346 (defvar gnus-article-edit-done-function nil)
4347
4348 (defvar gnus-article-edit-mode-map nil)
4349
4350 ;; Should we be using derived.el for this?
4351 (unless gnus-article-edit-mode-map
4352   (setq gnus-article-edit-mode-map (make-sparse-keymap))
4353   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4354
4355   (gnus-define-keys gnus-article-edit-mode-map
4356     "\C-c\C-c" gnus-article-edit-done
4357     "\C-c\C-k" gnus-article-edit-exit)
4358
4359   (gnus-define-keys (gnus-article-edit-wash-map
4360                      "\C-c\C-w" gnus-article-edit-mode-map)
4361     "f" gnus-article-edit-full-stops))
4362
4363 (defun gnus-article-edit-mode ()
4364   "Major mode for editing articles.
4365 This is an extended text-mode.
4366
4367 \\{gnus-article-edit-mode-map}"
4368   (interactive)
4369   (setq major-mode 'gnus-article-edit-mode)
4370   (setq mode-name "Article Edit")
4371   (use-local-map gnus-article-edit-mode-map)
4372   (make-local-variable 'gnus-article-edit-done-function)
4373   (make-local-variable 'gnus-prev-winconf)
4374   (setq buffer-read-only nil)
4375   (buffer-enable-undo)
4376   (widen)
4377   (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4378
4379 (defun gnus-article-edit (&optional force)
4380   "Edit the current article.
4381 This will have permanent effect only in mail groups.
4382 If FORCE is non-nil, allow editing of articles even in read-only
4383 groups."
4384   (interactive "P")
4385   (when (and (not force)
4386              (gnus-group-read-only-p))
4387     (error "The current newsgroup does not support article editing"))
4388   (gnus-article-date-original)
4389   (gnus-article-edit-article
4390    'ignore
4391    `(lambda (no-highlight)
4392       'ignore
4393       (gnus-summary-edit-article-done
4394        ,(or (mail-header-references gnus-current-headers) "")
4395        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4396
4397 (defun gnus-article-edit-article (start-func exit-func)
4398   "Start editing the contents of the current article buffer."
4399   (let ((winconf (current-window-configuration)))
4400     (set-buffer gnus-article-buffer)
4401     (gnus-article-edit-mode)
4402     (funcall start-func)
4403     (gnus-configure-windows 'edit-article)
4404     (setq gnus-article-edit-done-function exit-func)
4405     (setq gnus-prev-winconf winconf)
4406     (when gnus-article-edit-article-setup-function
4407       (funcall gnus-article-edit-article-setup-function))
4408     (gnus-message 6 "C-c C-c to end edits")))
4409
4410 (defun gnus-article-edit-done (&optional arg)
4411   "Update the article edits and exit."
4412   (interactive "P")
4413   (save-excursion
4414     (save-restriction
4415       (widen)
4416       (when (article-goto-body)
4417         (let ((lines (count-lines (point) (point-max)))
4418               (length (- (point-max) (point)))
4419               (case-fold-search t)
4420               (body (copy-marker (point))))
4421           (goto-char (point-min))
4422           (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4423             (delete-region (match-beginning 1) (match-end 1))
4424             (insert (number-to-string length)))
4425           (goto-char (point-min))
4426           (when (re-search-forward
4427                  "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4428             (delete-region (match-beginning 1) (match-end 1))
4429             (insert (number-to-string length)))
4430           (goto-char (point-min))
4431           (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4432             (delete-region (match-beginning 1) (match-end 1))
4433             (insert (number-to-string lines)))))))
4434   (let ((func gnus-article-edit-done-function)
4435         (buf (current-buffer))
4436         (start (window-start)))
4437     (remove-hook 'gnus-article-mode-hook
4438                  'gnus-article-mime-edit-article-unwind)
4439     (gnus-article-edit-exit)
4440     (save-excursion
4441       (set-buffer buf)
4442       (let ((buffer-read-only nil))
4443         (funcall func arg))
4444       ;; The cache and backlog have to be flushed somewhat.
4445       (when gnus-keep-backlog
4446         (gnus-backlog-remove-article
4447          (car gnus-article-current) (cdr gnus-article-current)))
4448       ;; Flush original article as well.
4449       (save-excursion
4450         (when (get-buffer gnus-original-article-buffer)
4451           (set-buffer gnus-original-article-buffer)
4452           (setq gnus-original-article nil)))
4453       (when gnus-use-cache
4454         (gnus-cache-update-article
4455          (car gnus-article-current) (cdr gnus-article-current))))
4456     (set-buffer buf)
4457     (set-window-start (get-buffer-window buf) start)
4458     (set-window-point (get-buffer-window buf) (point))))
4459
4460 (defun gnus-article-edit-exit ()
4461   "Exit the article editing without updating."
4462   (interactive)
4463   ;; We remove all text props from the article buffer.
4464   (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4465         (curbuf (current-buffer))
4466         (p (point))
4467         (window-start (window-start)))
4468     (erase-buffer)
4469     (insert buf)
4470     (let ((winconf gnus-prev-winconf))
4471       (gnus-article-mode)
4472       (set-window-configuration winconf)
4473       ;; Tippy-toe some to make sure that point remains where it was.
4474       (save-current-buffer
4475         (set-buffer curbuf)
4476         (set-window-start (get-buffer-window (current-buffer)) window-start)
4477         (goto-char p)))))
4478
4479 (defun gnus-article-edit-full-stops ()
4480   "Interactively repair spacing at end of sentences."
4481   (interactive)
4482   (save-excursion
4483     (goto-char (point-min))
4484     (search-forward-regexp "^$" nil t)
4485     (let ((case-fold-search nil))
4486       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4487
4488 ;;;
4489 ;;; Article editing with MIME-Edit
4490 ;;;
4491
4492 (defcustom gnus-article-mime-edit-article-setup-hook nil
4493   "Hook run after setting up a MIME editing article buffer."
4494   :group 'gnus-article-various
4495   :type 'hook)
4496
4497 (defun gnus-article-mime-edit-article-unwind ()
4498   "Unwind `gnus-article-buffer' if article editing was given up."
4499   (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4500   (when mime-edit-mode-flag
4501     (mime-edit-exit 'nomime 'no-error)
4502     (message ""))
4503   (when (featurep 'font-lock)
4504     (setq font-lock-defaults nil)
4505     (font-lock-mode 0)))
4506
4507 (defun gnus-article-mime-edit-article-setup ()
4508   "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4509 after replacing with the original article."
4510   (setq gnus-show-mime t)
4511   (setq gnus-article-edit-done-function
4512         `(lambda (&rest args)
4513            (when mime-edit-mode-flag
4514              (mime-edit-exit)
4515              (message ""))
4516            (goto-char (point-min))
4517            (let (case-fold-search)
4518              (when (re-search-forward
4519                     (format "^%s$" (regexp-quote mail-header-separator))
4520                     nil t)
4521                (replace-match "")))
4522            (when (featurep 'font-lock)
4523              (setq font-lock-defaults nil)
4524              (font-lock-mode 0))
4525            (apply ,gnus-article-edit-done-function args)
4526            (set-buffer gnus-original-article-buffer)
4527            (erase-buffer)
4528            (insert-buffer gnus-article-buffer)
4529            (setq gnus-current-headers (gnus-article-make-full-mail-header))
4530            (gnus-article-prepare-display)))
4531   (substitute-key-definition
4532    'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4533    gnus-article-edit-mode-map)
4534   (erase-buffer)
4535   (insert-buffer gnus-original-article-buffer)
4536   (mime-edit-again)
4537   (when (featurep 'font-lock)
4538     (set (make-local-variable 'font-lock-defaults)
4539          '(message-font-lock-keywords t))
4540     (font-lock-set-defaults)
4541     (turn-on-font-lock))
4542   (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4543   (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4544
4545 (defun gnus-article-mime-edit-exit ()
4546   "Exit the article MIME editing without updating."
4547   (interactive)
4548   (let ((winconf gnus-prev-winconf)
4549         buf)
4550     (when mime-edit-mode-flag
4551       (mime-edit-exit)
4552       (message ""))
4553     (goto-char (point-min))
4554     (let (case-fold-search)
4555       (when (re-search-forward
4556              (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4557         (replace-match "")))
4558     (when (featurep 'font-lock)
4559       (setq font-lock-defaults nil)
4560       (font-lock-mode 0))
4561     ;; We remove all text props from the article buffer.
4562     (setq buf (format "%s" (buffer-string)))
4563     (set-buffer (get-buffer-create gnus-original-article-buffer))
4564     (erase-buffer)
4565     (insert buf)
4566     (setq gnus-current-headers (gnus-article-make-full-mail-header))
4567     (gnus-article-prepare-display)
4568     (set-window-configuration winconf)))
4569
4570 ;;;
4571 ;;; Article highlights
4572 ;;;
4573
4574 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4575
4576 ;;; Internal Variables:
4577
4578 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)"
4579   "Regular expression that matches URLs."
4580   :group 'gnus-article-buttons
4581   :type 'regexp)
4582
4583 (defcustom gnus-button-alist
4584   `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4585      0 t gnus-button-message-id 2)
4586     ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4587     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4588      1 t
4589      gnus-button-fetch-group 4)
4590     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4591     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4592      t gnus-button-message-id 3)
4593     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4594     ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4595     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4596     ;; This is how URLs _should_ be embedded in text...
4597     ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4598     ;; Raw URLs.
4599     (,gnus-button-url-regexp 0 t browse-url 0))
4600   "*Alist of regexps matching buttons in article bodies.
4601
4602 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4603 REGEXP: is the string matching text around the button,
4604 BUTTON: is the number of the regexp grouping actually matching the button,
4605 FORM: is a lisp expression which must eval to true for the button to
4606 be added,
4607 CALLBACK: is the function to call when the user push this button, and each
4608 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4609
4610 CALLBACK can also be a variable, in that case the value of that
4611 variable it the real callback function."
4612   :group 'gnus-article-buttons
4613   :type '(repeat (list regexp
4614                        (integer :tag "Button")
4615                        (sexp :tag "Form")
4616                        (function :tag "Callback")
4617                        (repeat :tag "Par"
4618                                :inline t
4619                                (integer :tag "Regexp group")))))
4620
4621 (defcustom gnus-header-button-alist
4622   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4623      0 t gnus-button-message-id 0)
4624     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4625     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4626      0 t gnus-button-mailto 0)
4627     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4628     ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4629     ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4630     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4631      gnus-button-message-id 3))
4632   "*Alist of headers and regexps to match buttons in article heads.
4633
4634 This alist is very similar to `gnus-button-alist', except that each
4635 alist has an additional HEADER element first in each entry:
4636
4637 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4638
4639 HEADER is a regexp to match a header.  For a fuller explanation, see
4640 `gnus-button-alist'."
4641   :group 'gnus-article-buttons
4642   :group 'gnus-article-headers
4643   :type '(repeat (list (regexp :tag "Header")
4644                        regexp
4645                        (integer :tag "Button")
4646                        (sexp :tag "Form")
4647                        (function :tag "Callback")
4648                        (repeat :tag "Par"
4649                                :inline t
4650                                (integer :tag "Regexp group")))))
4651
4652 (defvar gnus-button-regexp nil)
4653 (defvar gnus-button-marker-list nil)
4654 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4655
4656 (defvar gnus-button-last nil)
4657 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4658
4659 ;;; Commands:
4660
4661 (defun gnus-article-push-button (event)
4662   "Check text under the mouse pointer for a callback function.
4663 If the text under the mouse pointer has a `gnus-callback' property,
4664 call it with the value of the `gnus-data' text property."
4665   (interactive "e")
4666   (set-buffer (window-buffer (posn-window (event-start event))))
4667   (let* ((pos (posn-point (event-start event)))
4668          (data (get-text-property pos 'gnus-data))
4669          (fun (get-text-property pos 'gnus-callback)))
4670     (goto-char pos)
4671     (when fun
4672       (funcall fun data))))
4673
4674 (defun gnus-article-press-button ()
4675   "Check text at point for a callback function.
4676 If the text at point has a `gnus-callback' property,
4677 call it with the value of the `gnus-data' text property."
4678   (interactive)
4679   (let* ((data (get-text-property (point) 'gnus-data))
4680          (fun (get-text-property (point) 'gnus-callback)))
4681     (when fun
4682       (funcall fun data))))
4683
4684 (defun gnus-article-prev-button (n)
4685   "Move point to N buttons backward.
4686 If N is negative, move forward instead."
4687   (interactive "p")
4688   (gnus-article-next-button (- n)))
4689
4690 (defun gnus-article-next-button (n)
4691   "Move point to N buttons forward.
4692 If N is negative, move backward instead."
4693   (interactive "p")
4694   (let ((function (if (< n 0) 'previous-single-property-change
4695                     'next-single-property-change))
4696         (inhibit-point-motion-hooks t)
4697         (backward (< n 0))
4698         (limit (if (< n 0) (point-min) (point-max))))
4699     (setq n (abs n))
4700     (while (and (not (= limit (point)))
4701                 (> n 0))
4702       ;; Skip past the current button.
4703       (when (get-text-property (point) 'gnus-callback)
4704         (goto-char (funcall function (point) 'gnus-callback nil limit)))
4705       ;; Go to the next (or previous) button.
4706       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4707       ;; Put point at the start of the button.
4708       (when (and backward (not (get-text-property (point) 'gnus-callback)))
4709         (goto-char (funcall function (point) 'gnus-callback nil limit)))
4710       ;; Skip past intangible buttons.
4711       (when (get-text-property (point) 'intangible)
4712         (incf n))
4713       (decf n))
4714     (unless (zerop n)
4715       (gnus-message 5 "No more buttons"))
4716     n))
4717
4718 (defun gnus-article-highlight (&optional force)
4719   "Highlight current article.
4720 This function calls `gnus-article-highlight-headers',
4721 `gnus-article-highlight-citation',
4722 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4723 do the highlighting.  See the documentation for those functions."
4724   (interactive (list 'force))
4725   (gnus-article-highlight-headers)
4726   (gnus-article-highlight-citation force)
4727   (gnus-article-highlight-signature)
4728   (gnus-article-add-buttons force)
4729   (gnus-article-add-buttons-to-head))
4730
4731 (defun gnus-article-highlight-some (&optional force)
4732   "Highlight current article.
4733 This function calls `gnus-article-highlight-headers',
4734 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4735 do the highlighting.  See the documentation for those functions."
4736   (interactive (list 'force))
4737   (gnus-article-highlight-headers)
4738   (gnus-article-highlight-signature)
4739   (gnus-article-add-buttons))
4740
4741 (defun gnus-article-highlight-headers ()
4742   "Highlight article headers as specified by `gnus-header-face-alist'."
4743   (interactive)
4744   (save-excursion
4745     (set-buffer gnus-article-buffer)
4746     (save-restriction
4747       (let ((alist gnus-header-face-alist)
4748             (buffer-read-only nil)
4749             (case-fold-search t)
4750             (inhibit-point-motion-hooks t)
4751             entry regexp header-face field-face from hpoints fpoints)
4752         (article-narrow-to-head)
4753         (while (setq entry (pop alist))
4754           (goto-char (point-min))
4755           (setq regexp (concat "^\\("
4756                                (if (string-equal "" (nth 0 entry))
4757                                    "[^\t ]"
4758                                  (nth 0 entry))
4759                                "\\)")
4760                 header-face (nth 1 entry)
4761                 field-face (nth 2 entry))
4762           (while (and (re-search-forward regexp nil t)
4763                       (not (eobp)))
4764             (beginning-of-line)
4765             (setq from (point))
4766             (unless (search-forward ":" nil t)
4767               (forward-char 1))
4768             (when (and header-face
4769                        (not (memq (point) hpoints)))
4770               (push (point) hpoints)
4771               (gnus-put-text-property from (point) 'face header-face))
4772             (when (and field-face
4773                        (not (memq (setq from (point)) fpoints)))
4774               (push from fpoints)
4775               (if (re-search-forward "^[^ \t]" nil t)
4776                   (forward-char -2)
4777                 (goto-char (point-max)))
4778               (gnus-put-text-property from (point) 'face field-face))))))))
4779
4780 (defun gnus-article-highlight-signature ()
4781   "Highlight the signature in an article.
4782 It does this by highlighting everything after
4783 `gnus-signature-separator' using `gnus-signature-face'."
4784   (interactive)
4785   (when gnus-signature-face
4786     (save-excursion
4787       (set-buffer gnus-article-buffer)
4788       (let ((buffer-read-only nil)
4789             (inhibit-point-motion-hooks t))
4790         (save-restriction
4791           (when (gnus-article-narrow-to-signature)
4792             (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4793                               'face gnus-signature-face)))))))
4794
4795 (defun gnus-article-buttonize-signature ()
4796   "Add button to the signature."
4797   (interactive)
4798   (save-excursion
4799     (set-buffer gnus-article-buffer)
4800     (let ((buffer-read-only nil)
4801           (inhibit-point-motion-hooks t))
4802       (when (gnus-article-search-signature)
4803         (gnus-article-add-button (match-beginning 0) (match-end 0)
4804                                  'gnus-signature-toggle
4805                                  (set-marker (make-marker)
4806                                              (1+ (match-end 0))))))))
4807
4808 (defun gnus-button-in-region-p (b e prop)
4809   "Say whether PROP exists in the region."
4810   (text-property-not-all b e prop nil))
4811
4812 (defun gnus-article-add-buttons (&optional force)
4813   "Find external references in the article and make buttons of them.
4814 \"External references\" are things like Message-IDs and URLs, as
4815 specified by `gnus-button-alist'."
4816   (interactive (list 'force))
4817   (save-excursion
4818     (set-buffer gnus-article-buffer)
4819     (let ((buffer-read-only nil)
4820           (inhibit-point-motion-hooks t)
4821           (case-fold-search t)
4822           (alist gnus-button-alist)
4823           beg entry regexp)
4824       ;; Remove all old markers.
4825       (let (marker entry new-list)
4826         (while (setq marker (pop gnus-button-marker-list))
4827           (if (or (< marker (point-min)) (>= marker (point-max)))
4828               (push marker new-list)
4829             (goto-char marker)
4830             (when (setq entry (gnus-button-entry))
4831               (put-text-property (match-beginning (nth 1 entry))
4832                                  (match-end (nth 1 entry))
4833                                  'gnus-callback nil))
4834             (set-marker marker nil)))
4835         (setq gnus-button-marker-list new-list))
4836       ;; We skip the headers.
4837       (article-goto-body)
4838       (setq beg (point))
4839       (while (setq entry (pop alist))
4840         (setq regexp (car entry))
4841         (goto-char beg)
4842         (while (re-search-forward regexp nil t)
4843           (let* ((start (and entry (match-beginning (nth 1 entry))))
4844                  (end (and entry (match-end (nth 1 entry))))
4845                  (from (match-beginning 0)))
4846             (when (and (or (eq t (nth 2 entry))
4847                            (eval (nth 2 entry)))
4848                        (not (gnus-button-in-region-p
4849                              start end 'gnus-callback)))
4850               ;; That optional form returned non-nil, so we add the
4851               ;; button.
4852               (gnus-article-add-button
4853                start end 'gnus-button-push
4854                (car (push (set-marker (make-marker) from)
4855                           gnus-button-marker-list))))))))))
4856
4857 ;; Add buttons to the head of an article.
4858 (defun gnus-article-add-buttons-to-head ()
4859   "Add buttons to the head of the article."
4860   (interactive)
4861   (save-excursion
4862     (set-buffer gnus-article-buffer)
4863     (save-restriction
4864       (let ((buffer-read-only nil)
4865             (inhibit-point-motion-hooks t)
4866             (case-fold-search t)
4867             (alist gnus-header-button-alist)
4868             entry beg end)
4869         (article-narrow-to-head)
4870         (while alist
4871           ;; Each alist entry.
4872           (setq entry (car alist)
4873                 alist (cdr alist))
4874           (goto-char (point-min))
4875           (while (re-search-forward (car entry) nil t)
4876             ;; Each header matching the entry.
4877             (setq beg (match-beginning 0))
4878             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4879                                (match-beginning 0))
4880                           (point-max)))
4881             (goto-char beg)
4882             (while (re-search-forward (nth 1 entry) end t)
4883               ;; Each match within a header.
4884               (let* ((entry (cdr entry))
4885                      (start (match-beginning (nth 1 entry)))
4886                      (end (match-end (nth 1 entry)))
4887                      (form (nth 2 entry)))
4888                 (goto-char (match-end 0))
4889                 (when (eval form)
4890                   (gnus-article-add-button
4891                    start end (nth 3 entry)
4892                    (buffer-substring (match-beginning (nth 4 entry))
4893                                      (match-end (nth 4 entry)))))))
4894             (goto-char end)))))))
4895
4896 ;;; External functions:
4897
4898 (defun gnus-article-add-button (from to fun &optional data)
4899   "Create a button between FROM and TO with callback FUN and data DATA."
4900   (when gnus-article-button-face
4901     (gnus-overlay-put (gnus-make-overlay from to)
4902                       'face gnus-article-button-face))
4903   (gnus-add-text-properties
4904    from to
4905    (nconc (and gnus-article-mouse-face
4906                (list gnus-mouse-face-prop gnus-article-mouse-face))
4907           (list 'gnus-callback fun)
4908           (and data (list 'gnus-data data))))
4909   (widget-convert-button 'link from to :action 'gnus-widget-press-button
4910                          ;; Quote `:button-keymap' for Mule 2.3
4911                          ;; but it won't work.
4912                          ':button-keymap gnus-widget-button-keymap))
4913
4914 ;;; Internal functions:
4915
4916 (defun gnus-article-set-globals ()
4917   (save-excursion
4918     (set-buffer gnus-summary-buffer)
4919     (gnus-set-global-variables)))
4920
4921 (defun gnus-signature-toggle (end)
4922   (save-excursion
4923     (set-buffer gnus-article-buffer)
4924     (let ((buffer-read-only nil)
4925           (inhibit-point-motion-hooks t)
4926           (limit (next-single-property-change end 'mime-view-entity
4927                                               nil (point-max))))
4928       (if (get-text-property end 'invisible)
4929           (gnus-article-unhide-text end limit)
4930         (gnus-article-hide-text end limit gnus-hidden-properties)))))
4931
4932 (defun gnus-button-entry ()
4933   ;; Return the first entry in `gnus-button-alist' matching this place.
4934   (let ((alist gnus-button-alist)
4935         (entry nil))
4936     (while alist
4937       (setq entry (pop alist))
4938       (if (looking-at (car entry))
4939           (setq alist nil)
4940         (setq entry nil)))
4941     entry))
4942
4943 (defun gnus-button-push (marker)
4944   ;; Push button starting at MARKER.
4945   (save-excursion
4946     (goto-char marker)
4947     (let* ((entry (gnus-button-entry))
4948            (inhibit-point-motion-hooks t)
4949            (fun (nth 3 entry))
4950            (args (mapcar (lambda (group)
4951                            (let ((string (match-string group)))
4952                              (gnus-set-text-properties
4953                               0 (length string) nil string)
4954                              string))
4955                          (nthcdr 4 entry))))
4956       (cond
4957        ((fboundp fun)
4958         (apply fun args))
4959        ((and (boundp fun)
4960              (fboundp (symbol-value fun)))
4961         (apply (symbol-value fun) args))
4962        (t
4963         (gnus-message 1 "You must define `%S' to use this button"
4964                       (cons fun args)))))))
4965
4966 (defun gnus-button-message-id (message-id)
4967   "Fetch MESSAGE-ID."
4968   (save-excursion
4969     (set-buffer gnus-summary-buffer)
4970     (gnus-summary-refer-article message-id)))
4971
4972 (defun gnus-button-fetch-group (address)
4973   "Fetch GROUP specified by ADDRESS."
4974   (if (not (string-match "[:/]" address))
4975       ;; This is just a simple group url.
4976       (gnus-group-read-ephemeral-group address gnus-select-method)
4977     (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4978                            address))
4979         (error "Can't parse %s" address)
4980       (gnus-group-read-ephemeral-group
4981        (match-string 4 address)
4982        `(nntp ,(match-string 1 address)
4983               (nntp-address ,(match-string 1 address))
4984               (nntp-port-number ,(if (match-end 3)
4985                                      (match-string 3 address)
4986                                    "nntp")))))))
4987
4988 (defun gnus-url-parse-query-string (query &optional downcase)
4989   (let (retval pairs cur key val)
4990     (setq pairs (split-string query "&"))
4991     (while pairs
4992       (setq cur (car pairs)
4993             pairs (cdr pairs))
4994       (if (not (string-match "=" cur))
4995           nil                           ; Grace
4996         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4997               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4998         (if downcase
4999             (setq key (downcase key)))
5000         (setq cur (assoc key retval))
5001         (if cur
5002             (setcdr cur (cons val (cdr cur)))
5003           (setq retval (cons (list key val) retval)))))
5004     retval))
5005
5006 (defun gnus-url-unhex (x)
5007   (if (> x ?9)
5008       (if (>= x ?a)
5009           (+ 10 (- x ?a))
5010         (+ 10 (- x ?A)))
5011     (- x ?0)))
5012
5013 (defun gnus-url-unhex-string (str &optional allow-newlines)
5014   "Remove %XXX embedded spaces, etc in a url.
5015 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5016 decoding of carriage returns and line feeds in the string, which is normally
5017 forbidden in URL encoding."
5018   (setq str (or str ""))
5019   (let ((tmp "")
5020         (case-fold-search t))
5021     (while (string-match "%[0-9a-f][0-9a-f]" str)
5022       (let* ((start (match-beginning 0))
5023              (ch1 (gnus-url-unhex (elt str (+ start 1))))
5024              (code (+ (* 16 ch1)
5025                       (gnus-url-unhex (elt str (+ start 2))))))
5026         (setq tmp (concat
5027                    tmp (substring str 0 start)
5028                    (cond
5029                     (allow-newlines
5030                      (char-to-string code))
5031                     ((or (= code ?\n) (= code ?\r))
5032                      " ")
5033                     (t (char-to-string code))))
5034               str (substring str (match-end 0)))))
5035     (setq tmp (concat tmp str))
5036     tmp))
5037
5038 (defun gnus-url-mailto (url)
5039   ;; Send mail to someone
5040   (when (string-match "mailto:/*\\(.*\\)" url)
5041     (setq url (substring url (match-beginning 1) nil)))
5042   (let (to args subject func)
5043     (if (string-match (regexp-quote "?") url)
5044         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5045               args (gnus-url-parse-query-string
5046                     (substring url (match-end 0) nil) t))
5047       (setq to (gnus-url-unhex-string url)))
5048     (setq args (cons (list "to" to) args)
5049           subject (cdr-safe (assoc "subject" args)))
5050     (gnus-setup-message 'reply
5051       (message-mail)
5052       (while args
5053         (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5054         (if (fboundp func)
5055             (funcall func)
5056           (message-position-on-field (caar args)))
5057         (insert (mapconcat 'identity (cdar args) ", "))
5058         (setq args (cdr args)))
5059       (if subject
5060           (message-goto-body)
5061         (message-goto-subject)))))
5062
5063 (defun gnus-button-mailto (address)
5064   ;; Mail to ADDRESS.
5065   (set-buffer (gnus-copy-article-buffer))
5066   (gnus-setup-message 'reply
5067     (message-reply address)))
5068
5069 (defun gnus-button-reply (address)
5070   ;; Reply to ADDRESS.
5071   (gnus-setup-message 'reply
5072     (message-reply address)))
5073
5074 (defun gnus-button-embedded-url (address)
5075   "Browse ADDRESS."
5076   (browse-url (gnus-strip-whitespace address)))
5077
5078 (defun gnus-article-smiley-display ()
5079   "Display \"smileys\" as small graphical icons."
5080   (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5081
5082 ;;; Next/prev buttons in the article buffer.
5083
5084 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5085 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5086
5087 (defvar gnus-prev-page-map nil)
5088 (unless gnus-prev-page-map
5089   (setq gnus-prev-page-map (make-sparse-keymap))
5090   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5091   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5092
5093 (static-if (featurep 'xemacs)
5094     (defun gnus-insert-prev-page-button ()
5095       (let ((buffer-read-only nil))
5096         (gnus-eval-format
5097          gnus-prev-page-line-format nil
5098          `(gnus-prev t local-map ,gnus-prev-page-map
5099                      gnus-callback gnus-article-button-prev-page
5100                      article-type annotation))))
5101   (defun gnus-insert-prev-page-button ()
5102     (let ((buffer-read-only nil)
5103           (situation (get-text-property (point-min) 'mime-view-situation)))
5104       (set-keymap-parent gnus-prev-page-map (current-local-map))
5105       (gnus-eval-format
5106        gnus-prev-page-line-format nil
5107        `(gnus-prev t local-map ,gnus-prev-page-map
5108                    gnus-callback gnus-article-button-prev-page
5109                    article-type annotation
5110                    mime-view-situation ,situation))))
5111   )
5112
5113 (defvar gnus-next-page-map nil)
5114 (unless gnus-next-page-map
5115   (setq gnus-next-page-map (make-sparse-keymap))
5116   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5117   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5118
5119 (defun gnus-button-next-page ()
5120   "Go to the next page."
5121   (interactive)
5122   (let ((win (selected-window)))
5123     (select-window (get-buffer-window gnus-article-buffer t))
5124     (gnus-article-next-page)
5125     (select-window win)))
5126
5127 (defun gnus-button-prev-page ()
5128   "Go to the prev page."
5129   (interactive)
5130   (let ((win (selected-window)))
5131     (select-window (get-buffer-window gnus-article-buffer t))
5132     (gnus-article-prev-page)
5133     (select-window win)))
5134
5135 (static-if (featurep 'xemacs)
5136     (defun gnus-insert-next-page-button ()
5137       (let ((buffer-read-only nil))
5138         (gnus-eval-format gnus-next-page-line-format nil
5139                           `(gnus-next
5140                             t local-map ,gnus-next-page-map
5141                             gnus-callback gnus-article-button-next-page
5142                             article-type annotation))))
5143   (defun gnus-insert-next-page-button ()
5144     (let ((buffer-read-only nil)
5145           (situation (get-text-property (point-min) 'mime-view-situation)))
5146       (set-keymap-parent gnus-next-page-map (current-local-map))
5147       (gnus-eval-format gnus-next-page-line-format nil
5148                         `(gnus-next
5149                           t local-map ,gnus-next-page-map
5150                           gnus-callback gnus-article-button-next-page
5151                           article-type annotation
5152                           mime-view-situation ,situation))))
5153   )
5154
5155 (defun gnus-article-button-next-page (arg)
5156   "Go to the next page."
5157   (interactive "P")
5158   (let ((win (selected-window)))
5159     (select-window (get-buffer-window gnus-article-buffer t))
5160     (gnus-article-next-page)
5161     (select-window win)))
5162
5163 (defun gnus-article-button-prev-page (arg)
5164   "Go to the prev page."
5165   (interactive "P")
5166   (let ((win (selected-window)))
5167     (select-window (get-buffer-window gnus-article-buffer t))
5168     (gnus-article-prev-page)
5169     (select-window win)))
5170
5171 (defvar gnus-decode-header-methods
5172   '(mail-decode-encoded-word-region)
5173   "List of methods used to decode headers.
5174
5175 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
5176 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
5177 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5178 whose names match REGEXP.
5179
5180 For example:
5181 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5182  mail-decode-encoded-word-region
5183  (\"chinese\" . rfc1843-decode-region))
5184 ")
5185
5186 (defvar gnus-decode-header-methods-cache nil)
5187
5188 (defun gnus-multi-decode-header (start end)
5189   "Apply the functions from `gnus-encoded-word-methods' that match."
5190   (unless (and gnus-decode-header-methods-cache
5191                (eq gnus-newsgroup-name
5192                    (car gnus-decode-header-methods-cache)))
5193     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5194     (mapcar (lambda (x)
5195               (if (symbolp x)
5196                   (nconc gnus-decode-header-methods-cache (list x))
5197                 (if (and gnus-newsgroup-name
5198                          (string-match (car x) gnus-newsgroup-name))
5199                     (nconc gnus-decode-header-methods-cache
5200                            (list (cdr x))))))
5201           gnus-decode-header-methods))
5202   (let ((xlist gnus-decode-header-methods-cache))
5203     (pop xlist)
5204     (save-restriction
5205       (narrow-to-region start end)
5206       (while xlist
5207         (funcall (pop xlist) (point-min) (point-max))))))
5208
5209 ;;;
5210 ;;; Treatment top-level handling.
5211 ;;;
5212
5213 (defun gnus-treat-article (condition &optional part-number total-parts type)
5214   (let ((length (- (point-max) (point-min)))
5215         (alist gnus-treatment-function-alist)
5216         (article-goto-body-goes-to-point-min-p t)
5217         (treated-type
5218          (or (not type)
5219              (catch 'found
5220                (let ((list gnus-article-treat-types))
5221                  (while list
5222                    (when (string-match (pop list) type)
5223                      (throw 'found t)))))))
5224         (highlightp (gnus-visual-p 'article-highlight 'highlight))
5225         (entity (static-unless (featurep 'xemacs)
5226                   (when (eq 'head condition)
5227                     (get-text-property (point-min) 'mime-view-entity))))
5228         val elem buttonized)
5229     (gnus-run-hooks 'gnus-part-display-hook)
5230     (unless gnus-inhibit-treatment
5231       (while (setq elem (pop alist))
5232         (setq val
5233               (save-excursion
5234                 (if (gnus-buffer-live-p gnus-summary-buffer)
5235                     (set-buffer gnus-summary-buffer))
5236                 (symbol-value (car elem))))
5237         (when (and (or (consp val)
5238                        treated-type)
5239                    (gnus-treat-predicate val)
5240                    (or (not (get (car elem) 'highlight))
5241                        highlightp))
5242           (when (and (not buttonized)
5243                      (memq (car elem)
5244                            '(gnus-treat-hide-signature
5245                              gnus-treat-highlight-signature)))
5246             (gnus-article-buttonize-signature)
5247             (setq buttonized t))
5248           (save-restriction
5249             (funcall (cadr elem)))))
5250       ;; FSF Emacsen does not inherit the existing text properties
5251       ;; in the new text, so we should do it for `mime-view-entity'.
5252       (static-unless (featurep 'xemacs)
5253         (when entity
5254           (put-text-property (point-min) (point-max)
5255                              'mime-view-entity entity))))))
5256
5257 ;; Dynamic variables.
5258 (defvar part-number)
5259 (defvar total-parts)
5260 (defvar type)
5261 (defvar condition)
5262 (defvar length)
5263 (defun gnus-treat-predicate (val)
5264   (cond
5265    ((null val)
5266     nil)
5267    ((and (listp val)
5268          (stringp (car val)))
5269     (apply 'gnus-or (mapcar `(lambda (s)
5270                                (string-match s ,(or gnus-newsgroup-name "")))
5271                             val)))
5272    ((listp val)
5273     (let ((pred (pop val)))
5274       (cond
5275        ((eq pred 'or)
5276         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5277        ((eq pred 'and)
5278         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5279        ((eq pred 'not)
5280         (not (gnus-treat-predicate (car val))))
5281        ((eq pred 'typep)
5282         (equal (car val) type))
5283        (t
5284         (error "%S is not a valid predicate" pred)))))
5285    ((eq val 'mime)
5286     gnus-show-mime)
5287    (condition
5288     (eq condition val))
5289    ((eq val t)
5290     t)
5291    ((eq val 'head)
5292     nil)
5293    ((eq val 'last)
5294     (eq part-number total-parts))
5295    ((numberp val)
5296     (< length val))
5297    (t
5298     (error "%S is not a valid value" val))))
5299
5300
5301 ;;; @ for mime-view
5302 ;;;
5303
5304 (defun gnus-article-header-presentation-method (entity situation)
5305   (mime-insert-header entity)
5306   )
5307
5308 (set-alist 'mime-header-presentation-method-alist
5309            'gnus-original-article-mode
5310            #'gnus-article-header-presentation-method)
5311
5312 (defun gnus-mime-preview-quitting-method ()
5313   (mime-preview-kill-buffer)
5314   (delete-other-windows)
5315   (gnus-article-show-summary)
5316   (gnus-summary-select-article gnus-show-all-headers t))
5317
5318 (set-alist 'mime-preview-quitting-method-alist
5319            'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5320
5321 (set-alist 'mime-preview-following-method-alist
5322            'gnus-original-article-mode #'gnus-following-method)
5323
5324 (set-alist 'mime-preview-over-to-previous-method-alist
5325            'gnus-original-article-mode
5326            (lambda ()
5327              (if (> (point-min) 1)
5328                  (gnus-article-prev-page)
5329                (gnus-article-read-summary-keys
5330                 nil (gnus-character-to-event ?P)))))
5331
5332 (set-alist 'mime-preview-over-to-next-method-alist
5333            'gnus-original-article-mode'
5334            (lambda ()
5335              (if (< (point-max) (buffer-size))
5336                  (gnus-article-next-page)
5337                (gnus-article-read-summary-keys
5338                 nil (gnus-character-to-event ?N)))))
5339
5340
5341 ;;; @ end
5342 ;;;
5343
5344 (gnus-ems-redefine)
5345
5346 (provide 'gnus-art)
5347
5348 (run-hooks 'gnus-art-load-hook)
5349
5350 ;;; gnus-art.el ends here