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