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