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