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