Sync up with Pteroductyl Gnus 0.59
[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 (defun article-treat-dumbquotes ()
916   "Translate M******** sm*rtq**t*s into proper text."
917   (interactive)
918   (article-translate-strings gnus-article-dumbquotes-map))
919
920 (defun article-translate-characters (from to)
921   "Translate all characters in the body of the article according to FROM and TO.
922 FROM is a string of characters to translate from; to is a string of
923 characters to translate to."
924   (save-excursion
925     (when (article-goto-body)
926       (let ((buffer-read-only nil)
927             (x (make-string 225 ?x))
928             (i -1))
929         (while (< (incf i) (length x))
930           (aset x i i))
931         (setq i 0)
932         (while (< i (length from))
933           (aset x (aref from i) (aref to i))
934           (incf i))
935         (translate-region (point) (point-max) x)))))
936
937 (defun article-translate-strings (map)
938   "Translate all string in the body of the article according to MAP.
939 MAP is an alist where the elements are on the form (\"from\" \"to\")."
940   (save-excursion
941     (when (article-goto-body)
942       (let ((buffer-read-only nil)
943             elem)
944         (while (setq elem (pop map))
945           (save-excursion
946             (while (search-forward (car elem) nil t)
947               (replace-match (cadr elem)))))))))
948
949 (defun article-treat-overstrike ()
950   "Translate overstrikes into bold text."
951   (interactive)
952   (save-excursion
953     (when (article-goto-body)
954       (let ((buffer-read-only nil))
955         (while (search-forward "\b" nil t)
956           (let ((next (char-after))
957                 (previous (char-after (- (point) 2))))
958             ;; We do the boldification/underlining by hiding the
959             ;; overstrikes and putting the proper text property
960             ;; on the letters.
961             (cond
962              ((eq next previous)
963               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
964               (put-text-property (point) (1+ (point)) 'face 'bold))
965              ((eq next ?_)
966               (gnus-article-hide-text-type
967                (1- (point)) (1+ (point)) 'overstrike)
968               (put-text-property
969                (- (point) 2) (1- (point)) 'face 'underline))
970              ((eq previous ?_)
971               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
972               (put-text-property
973                (point) (1+ (point)) 'face 'underline)))))))))
974
975 (defun article-fill ()
976   "Format too long lines."
977   (interactive)
978   (save-excursion
979     (let ((buffer-read-only nil))
980       (widen)
981       (article-goto-body)
982       (end-of-line 1)
983       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
984             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
985             (adaptive-fill-mode t))
986         (while (not (eobp))
987           (and (>= (current-column) (min fill-column (window-width)))
988                (/= (preceding-char) ?:)
989                (fill-paragraph nil))
990           (end-of-line 2))))))
991
992 (defun article-remove-cr ()
993   "Translate CRLF pairs into LF, and then CR into LF.."
994   (interactive)
995   (save-excursion
996     (let ((buffer-read-only nil))
997       (goto-char (point-min))
998       (while (search-forward "\r$" nil t)
999         (replace-match "" t t))
1000       (goto-char (point-min))
1001       (while (search-forward "\r" nil t)
1002         (replace-match "\n" t t)))))
1003
1004 (defun article-remove-trailing-blank-lines ()
1005   "Remove all trailing blank lines from the article."
1006   (interactive)
1007   (save-excursion
1008     (let ((buffer-read-only nil))
1009       (goto-char (point-max))
1010       (delete-region
1011        (point)
1012        (progn
1013          (while (and (not (bobp))
1014                      (looking-at "^[ \t]*$")
1015                      (not (gnus-annotation-in-region-p
1016                            (point) (gnus-point-at-eol))))
1017            (forward-line -1))
1018          (forward-line 1)
1019          (point))))))
1020
1021 (defun article-display-x-face (&optional force)
1022   "Look for an X-Face header and display it if present."
1023   (interactive (list 'force))
1024   (save-excursion
1025     ;; Delete the old process, if any.
1026     (when (process-status "article-x-face")
1027       (delete-process "article-x-face"))
1028     (let ((inhibit-point-motion-hooks t)
1029           (case-fold-search t)
1030           from last)
1031       (save-restriction
1032         (nnheader-narrow-to-headers)
1033         (setq from (message-fetch-field "from"))
1034         (goto-char (point-min))
1035         (while (and gnus-article-x-face-command
1036                     (not last)
1037                     (or force
1038                         ;; Check whether this face is censored.
1039                         (not gnus-article-x-face-too-ugly)
1040                         (and gnus-article-x-face-too-ugly from
1041                              (not (string-match gnus-article-x-face-too-ugly
1042                                                 from))))
1043                     ;; Has to be present.
1044                     (re-search-forward "^X-Face: " nil t))
1045           ;; This used to try to do multiple faces (`while' instead of
1046           ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1047           ;; work (b) it can crash some versions of Emacs (c) are
1048           ;; multiple faces really something to encourage?
1049           (when (stringp gnus-article-x-face-command)
1050             (setq last t))
1051           ;; We now have the area of the buffer where the X-Face is stored.
1052           (save-excursion
1053             (let ((beg (point))
1054                   (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1055               ;; We display the face.
1056               (if (symbolp gnus-article-x-face-command)
1057                   ;; The command is a lisp function, so we call it.
1058                   (if (gnus-functionp gnus-article-x-face-command)
1059                       (funcall gnus-article-x-face-command beg end)
1060                     (error "%s is not a function" gnus-article-x-face-command))
1061                 ;; The command is a string, so we interpret the command
1062                 ;; as a, well, command, and fork it off.
1063                 (let ((process-connection-type nil))
1064                   (process-kill-without-query
1065                    (start-process
1066                     "article-x-face" nil shell-file-name shell-command-switch
1067                     gnus-article-x-face-command))
1068                   (process-send-region "article-x-face" beg end)
1069                   (process-send-eof "article-x-face"))))))))))
1070
1071 (defun article-decode-mime-words ()
1072   "Decode all MIME-encoded words in the article."
1073   (interactive)
1074   (save-excursion
1075     (set-buffer gnus-article-buffer)
1076     (let ((inhibit-point-motion-hooks t)
1077           buffer-read-only
1078           (rfc2047-default-charset gnus-newsgroup-default-charset)
1079           (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1080       (mail-decode-encoded-word-region (point-min) (point-max)))))
1081
1082 (defun article-decode-charset (&optional prompt)
1083   "Decode charset-encoded text in the article.
1084 If PROMPT (the prefix), prompt for a coding system to use."
1085   (interactive "P")
1086   (save-excursion
1087     (save-restriction
1088       (message-narrow-to-head)
1089       (let* ((inhibit-point-motion-hooks t)
1090              (case-fold-search t)
1091              (ct (message-fetch-field "Content-Type" t))
1092              (cte (message-fetch-field "Content-Transfer-Encoding" t))
1093              (ctl (and ct (condition-case ()
1094                               (mail-header-parse-content-type ct)
1095                             (error nil))))
1096              (charset (cond
1097                        (prompt
1098                         (mm-read-coding-system "Charset to decode: "))
1099                        (ctl
1100                         (mail-content-type-get ctl 'charset))))
1101              (rfc2047-default-charset gnus-newsgroup-default-charset)
1102              (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1103              buffer-read-only)
1104         (goto-char (point-max))
1105         (widen)
1106         (forward-line 1)
1107         (narrow-to-region (point) (point-max))
1108         (when (and (or (not ctl)
1109                        (equal (car ctl) "text/plain"))
1110                    (not (mm-uu-test)))
1111           (mm-decode-body
1112            charset (and cte (intern (downcase
1113                                      (gnus-strip-whitespace cte))))
1114            (car ctl)))))))
1115
1116 (defun article-decode-encoded-words ()
1117   "Remove encoded-word encoding from headers."
1118   (let (buffer-read-only)
1119     (let ((charset (save-excursion
1120                      (set-buffer gnus-summary-buffer)
1121                      default-mime-charset)))
1122       (mime-decode-header-in-buffer charset)
1123       )))
1124
1125 (defun article-de-quoted-unreadable (&optional force)
1126   "Translate a quoted-printable-encoded article.
1127 If FORCE, decode the article whether it is marked as quoted-printable
1128 or not."
1129   (interactive (list 'force))
1130   (save-excursion
1131     (let ((buffer-read-only nil)
1132           (type (gnus-fetch-field "content-transfer-encoding"))
1133           (charset
1134            (or gnus-newsgroup-default-charset mm-default-coding-system))
1135           (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1136       (when (or force
1137                 (and type (string-match "quoted-printable" (downcase type))))
1138         (article-goto-body)
1139         (save-restriction
1140           (narrow-to-region (point) (point-max))
1141           (quoted-printable-decode-region (point-min) (point-max))
1142           (when charset
1143             (mm-decode-body charset)))))))
1144
1145 (defun article-hide-pgp (&optional arg)
1146   "Toggle hiding of any PGP headers and signatures in the current article.
1147 If given a negative prefix, always show; if given a positive prefix,
1148 always hide."
1149   (interactive (gnus-article-hidden-arg))
1150   (unless (gnus-article-check-hidden-text 'pgp arg)
1151     (save-excursion
1152       (let ((inhibit-point-motion-hooks t)
1153             buffer-read-only beg end)
1154         (widen)
1155         (goto-char (point-min))
1156         ;; Hide the "header".
1157         (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1158           (delete-region (1+ (match-beginning 0)) (match-end 0))
1159           ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1160           (when (looking-at "Hash:.*$")
1161             (delete-region (point) (1+ (gnus-point-at-eol))))
1162           (setq beg (point))
1163           ;; Hide the actual signature.
1164           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1165                (setq end (1+ (match-beginning 0)))
1166                (delete-region
1167                 end
1168                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1169                     (match-end 0)
1170                   ;; Perhaps we shouldn't hide to the end of the buffer
1171                   ;; if there is no end to the signature?
1172                   (point-max))))
1173           ;; Hide "- " PGP quotation markers.
1174           (when (and beg end)
1175             (narrow-to-region beg end)
1176             (goto-char (point-min))
1177             (while (re-search-forward "^- " nil t)
1178               (delete-region
1179                (match-beginning 0) (match-end 0)))
1180             (widen))
1181           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1182
1183 (defun article-hide-pem (&optional arg)
1184   "Toggle hiding of any PEM headers and signatures in the current article.
1185 If given a negative prefix, always show; if given a positive prefix,
1186 always hide."
1187   (interactive (gnus-article-hidden-arg))
1188   (unless (gnus-article-check-hidden-text 'pem arg)
1189     (save-excursion
1190       (let (buffer-read-only end)
1191         (widen)
1192         (goto-char (point-min))
1193         ;; hide the horrendously ugly "header".
1194         (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1195                              nil
1196                              t)
1197              (setq end (1+ (match-beginning 0)))
1198              (gnus-article-hide-text-type
1199               end
1200               (if (search-forward "\n\n" nil t)
1201                   (match-end 0)
1202                 (point-max))
1203               'pem))
1204         ;; hide the trailer as well
1205         (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1206                              nil
1207                              t)
1208              (gnus-article-hide-text-type
1209               (match-beginning 0) (match-end 0) 'pem))))))
1210
1211 (defun article-hide-signature (&optional arg)
1212   "Hide the signature in the current article.
1213 If given a negative prefix, always show; if given a positive prefix,
1214 always hide."
1215   (interactive (gnus-article-hidden-arg))
1216   (unless (gnus-article-check-hidden-text 'signature arg)
1217     (save-excursion
1218       (save-restriction
1219         (let ((buffer-read-only nil))
1220           (when (gnus-article-narrow-to-signature)
1221             (gnus-article-hide-text-type
1222              (point-min) (point-max) 'signature)))))))
1223
1224 (defun article-strip-leading-blank-lines ()
1225   "Remove all blank lines from the beginning of the article."
1226   (interactive)
1227   (save-excursion
1228     (let ((inhibit-point-motion-hooks t)
1229           buffer-read-only)
1230       (when (article-goto-body)
1231         (while (and (not (eobp))
1232                     (looking-at "[ \t]*$"))
1233           (gnus-delete-line))))))
1234
1235 (defun article-goto-body ()
1236   "Place point at the start of the body."  
1237   (goto-char (point-min))
1238   (if (search-forward "\n\n" nil t)
1239       t
1240     (goto-char (point-max))
1241     nil))
1242
1243 (defun article-strip-multiple-blank-lines ()
1244   "Replace consecutive blank lines with one empty line."
1245   (interactive)
1246   (save-excursion
1247     (let ((inhibit-point-motion-hooks t)
1248           buffer-read-only)
1249       ;; First make all blank lines empty.
1250       (article-goto-body)
1251       (while (re-search-forward "^[ \t]+$" nil t)
1252         (unless (gnus-annotation-in-region-p
1253                  (match-beginning 0) (match-end 0))
1254           (replace-match "" nil t)))
1255       ;; Then replace multiple empty lines with a single empty line.
1256       (article-goto-body)
1257       (while (re-search-forward "\n\n\n+" nil t)
1258         (unless (gnus-annotation-in-region-p
1259                  (match-beginning 0) (match-end 0))
1260           (replace-match "\n\n" t t))))))
1261
1262 (defun article-strip-leading-space ()
1263   "Remove all white space from the beginning of the lines in the article."
1264   (interactive)
1265   (save-excursion
1266     (let ((inhibit-point-motion-hooks t)
1267           buffer-read-only)
1268       (article-goto-body)
1269       (while (re-search-forward "^[ \t]+" nil t)
1270         (replace-match "" t t)))))
1271
1272 (defun article-strip-trailing-space ()
1273   "Remove all white space from the end of the lines in the article."
1274   (interactive)
1275   (save-excursion
1276     (let ((inhibit-point-motion-hooks t)
1277           buffer-read-only)
1278       (article-goto-body)
1279       (while (re-search-forward "[ \t]+$" nil t)
1280         (replace-match "" t t)))))
1281
1282 (defun article-strip-blank-lines ()
1283   "Strip leading, trailing and multiple blank lines."
1284   (interactive)
1285   (article-strip-leading-blank-lines)
1286   (article-remove-trailing-blank-lines)
1287   (article-strip-multiple-blank-lines))
1288
1289 (defun article-strip-all-blank-lines ()
1290   "Strip all blank lines."
1291   (interactive)
1292   (save-excursion
1293     (let ((inhibit-point-motion-hooks t)
1294           buffer-read-only)
1295       (article-goto-body)
1296       (while (re-search-forward "^[ \t]*\n" nil t)
1297         (replace-match "" t t)))))
1298
1299 (defun gnus-article-narrow-to-signature ()
1300   "Narrow to the signature; return t if a signature is found, else nil."
1301   (widen)
1302   (let ((inhibit-point-motion-hooks t))
1303     (when (gnus-article-search-signature)
1304       (forward-line 1)
1305       ;; Check whether we have some limits to what we consider
1306       ;; to be a signature.
1307       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1308                       (list gnus-signature-limit)))
1309             limit limited)
1310         (while (setq limit (pop limits))
1311           (if (or (and (integerp limit)
1312                        (< (- (point-max) (point)) limit))
1313                   (and (floatp limit)
1314                        (< (count-lines (point) (point-max)) limit))
1315                   (and (gnus-functionp limit)
1316                        (funcall limit))
1317                   (and (stringp limit)
1318                        (not (re-search-forward limit nil t))))
1319               ()                        ; This limit did not succeed.
1320             (setq limited t
1321                   limits nil)))
1322         (unless limited
1323           (narrow-to-region (point) (point-max))
1324           t)))))
1325
1326 (defun gnus-article-search-signature ()
1327   "Search the current buffer for the signature separator.
1328 Put point at the beginning of the signature separator."
1329   (let ((cur (point)))
1330     (goto-char (point-max))
1331     (if (if (stringp gnus-signature-separator)
1332             (re-search-backward gnus-signature-separator nil t)
1333           (let ((seps gnus-signature-separator))
1334             (while (and seps
1335                         (not (re-search-backward (car seps) nil t)))
1336               (pop seps))
1337             seps))
1338         t
1339       (goto-char cur)
1340       nil)))
1341
1342 (eval-and-compile
1343   (autoload 'w3-display "w3-parse")
1344   (autoload 'w3-do-setup "w3" "" t)
1345   (autoload 'w3-region "w3-display" "" t))
1346
1347 (defun gnus-article-treat-html ()
1348   "Render HTML."
1349   (interactive)
1350   (let ((cbuf (current-buffer)))
1351     (set-buffer gnus-article-buffer)
1352     (let (buf buffer-read-only b e)
1353       (w3-do-setup)
1354       (goto-char (point-min))
1355       (narrow-to-region
1356        (if (search-forward "\n\n" nil t)
1357            (setq b (point))
1358          (point-max))
1359        (setq e (point-max)))
1360       (with-temp-buffer
1361         (insert-buffer-substring gnus-article-buffer b e)
1362         (require 'url)
1363         (save-window-excursion
1364           (w3-region (point-min) (point-max))
1365           (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1366       (when buf
1367         (delete-region (point-min) (point-max))
1368         (insert buf))
1369       (widen)
1370       (goto-char (point-min))
1371       (set-window-start (get-buffer-window (current-buffer)) (point-min))
1372       (set-buffer cbuf))))
1373
1374 (defun gnus-article-hidden-arg ()
1375   "Return the current prefix arg as a number, or 0 if no prefix."
1376   (list (if current-prefix-arg
1377             (prefix-numeric-value current-prefix-arg)
1378           0)))
1379
1380 (defun gnus-article-check-hidden-text (type arg)
1381   "Return nil if hiding is necessary.
1382 Arg can be nil or a number.  Nil and positive means hide, negative
1383 means show, 0 means toggle."
1384   (save-excursion
1385     (save-restriction
1386       (widen)
1387       (let ((hide (gnus-article-hidden-text-p type)))
1388         (cond
1389          ((or (null arg)
1390               (> arg 0))
1391           nil)
1392          ((< arg 0)
1393           (gnus-article-show-hidden-text type))
1394          (t
1395           (if (eq hide 'hidden)
1396               (gnus-article-show-hidden-text type)
1397             nil)))))))
1398
1399 (defun gnus-article-hidden-text-p (type)
1400   "Say whether the current buffer contains hidden text of type TYPE."
1401   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1402     (while (and pos
1403                 (not (get-text-property pos 'invisible)))
1404       (setq pos
1405             (text-property-any (1+ pos) (point-max) 'article-type type)))
1406     (if pos
1407         'hidden
1408       nil)))
1409
1410 (defun gnus-article-show-hidden-text (type &optional hide)
1411   "Show all hidden text of type TYPE.
1412 If HIDE, hide the text instead."
1413   (save-excursion
1414     (let ((buffer-read-only nil)
1415           (inhibit-point-motion-hooks t)
1416           (end (point-min))
1417           beg)
1418       (while (setq beg (text-property-any end (point-max) 'article-type type))
1419         (goto-char beg)
1420         (setq end (or
1421                    (text-property-not-all beg (point-max) 'article-type type)
1422                    (point-max)))
1423         (if hide
1424             (gnus-article-hide-text beg end gnus-hidden-properties)
1425           (gnus-article-unhide-text beg end))
1426         (goto-char end))
1427       t)))
1428
1429 (defconst article-time-units
1430   `((year . ,(* 365.25 24 60 60))
1431     (week . ,(* 7 24 60 60))
1432     (day . ,(* 24 60 60))
1433     (hour . ,(* 60 60))
1434     (minute . 60)
1435     (second . 1))
1436   "Mapping from time units to seconds.")
1437
1438 (defun article-date-ut (&optional type highlight header)
1439   "Convert DATE date to universal time in the current article.
1440 If TYPE is `local', convert to local time; if it is `lapsed', output
1441 how much time has lapsed since DATE."
1442   (interactive (list 'ut t))
1443   (let* ((header (or header
1444                      (mail-header-date gnus-current-headers)
1445                      (message-fetch-field "date")
1446                      ""))
1447          (date (if (vectorp header) (mail-header-date header)
1448                  header))
1449          (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1450          (inhibit-point-motion-hooks t)
1451          bface eface newline)
1452     (when (and date (not (string= date "")))
1453       (save-excursion
1454         (save-restriction
1455           (nnheader-narrow-to-headers)
1456           (let ((buffer-read-only nil))
1457             ;; Delete any old Date headers.
1458             (if (re-search-forward date-regexp nil t)
1459                 (progn
1460                   (setq bface (get-text-property (gnus-point-at-bol) 'face)
1461                         eface (get-text-property (1- (gnus-point-at-eol))
1462                                                  'face))
1463                   (delete-region (progn (beginning-of-line) (point))
1464                                  (progn (end-of-line) (point)))
1465                   (beginning-of-line))
1466               (goto-char (point-max))
1467               (setq newline t))
1468             (insert (article-make-date-line date type))
1469             ;; Do highlighting.
1470             (beginning-of-line)
1471             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1472               (put-text-property (match-beginning 1) (1+ (match-end 1))
1473                                  'face bface)
1474               (put-text-property (match-beginning 2) (match-end 2)
1475                                  'face eface))
1476             (when newline
1477               (end-of-line)
1478               (insert "\n"))))))))
1479
1480 (defun article-make-date-line (date type)
1481   "Return a DATE line of TYPE."
1482   (let ((time (condition-case ()
1483                   (date-to-time date)
1484                 (error '(0 0)))))
1485     (cond
1486      ;; Convert to the local timezone.  We have to slap a
1487      ;; `condition-case' round the calls to the timezone
1488      ;; functions since they aren't particularly resistant to
1489      ;; buggy dates.
1490      ((eq type 'local)
1491       (let ((tz (car (current-time-zone))))
1492         (format "Date: %s %s%04d" (current-time-string time)
1493                 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1494      ;; Convert to Universal Time.
1495      ((eq type 'ut)
1496       (concat "Date: "
1497               (current-time-string
1498                (let* ((e (parse-time-string date))
1499                      (tm (apply 'encode-time e))
1500                      (ms (car tm))
1501                      (ls (- (cadr tm) (car (current-time-zone)))))
1502                  (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1503                        ((> ls 65535) (list (1+ ms) (- ls 65536)))
1504                        (t (list ms ls)))))
1505               " UT"))
1506      ;; Get the original date from the article.
1507      ((eq type 'original)
1508       (concat "Date: " (if (string-match "\n+$" date)
1509                            (substring date 0 (match-beginning 0))
1510                          date)))
1511      ;; Let the user define the format.
1512      ((eq type 'user)
1513       (if (gnus-functionp gnus-article-time-format)
1514           (funcall gnus-article-time-format time)
1515         (concat
1516          "Date: "
1517          (format-time-string gnus-article-time-format time))))
1518      ;; ISO 8601.
1519      ((eq type 'iso8601)
1520       (concat
1521        "Date: "
1522        (format-time-string "%Y%M%DT%h%m%s" time)))
1523      ;; Do an X-Sent lapsed format.
1524      ((eq type 'lapsed)
1525       ;; If the date is seriously mangled, the timezone functions are
1526       ;; liable to bug out, so we ignore all errors.
1527       (let* ((now (current-time))
1528              (real-time (subtract-time now time))
1529              (real-sec (and real-time
1530                             (+ (* (float (car real-time)) 65536)
1531                                (cadr real-time))))
1532              (sec (and real-time (abs real-sec)))
1533              num prev)
1534         (cond
1535          ((null real-time)
1536           "X-Sent: Unknown")
1537          ((zerop sec)
1538           "X-Sent: Now")
1539          (t
1540           (concat
1541            "X-Sent: "
1542            ;; This is a bit convoluted, but basically we go
1543            ;; through the time units for years, weeks, etc,
1544            ;; and divide things to see whether that results
1545            ;; in positive answers.
1546            (mapconcat
1547             (lambda (unit)
1548               (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1549                   ;; The (remaining) seconds are too few to
1550                   ;; be divided into this time unit.
1551                   ""
1552                 ;; It's big enough, so we output it.
1553                 (setq sec (- sec (* num (cdr unit))))
1554                 (prog1
1555                     (concat (if prev ", " "") (int-to-string
1556                                                (floor num))
1557                             " " (symbol-name (car unit))
1558                             (if (> num 1) "s" ""))
1559                   (setq prev t))))
1560             article-time-units "")
1561            ;; If dates are odd, then it might appear like the
1562            ;; article was sent in the future.
1563            (if (> real-sec 0)
1564                " ago"
1565              " in the future"))))))
1566      (t
1567       (error "Unknown conversion type: %s" type)))))
1568
1569 (defun article-date-local (&optional highlight)
1570   "Convert the current article date to the local timezone."
1571   (interactive (list t))
1572   (article-date-ut 'local highlight))
1573
1574 (defun article-date-original (&optional highlight)
1575   "Convert the current article date to what it was originally.
1576 This is only useful if you have used some other date conversion
1577 function and want to see what the date was before converting."
1578   (interactive (list t))
1579   (article-date-ut 'original highlight))
1580
1581 (defun article-date-lapsed (&optional highlight)
1582   "Convert the current article date to time lapsed since it was sent."
1583   (interactive (list t))
1584   (article-date-ut 'lapsed highlight))
1585
1586 (defun article-update-date-lapsed ()
1587   "Function to be run from a timer to update the lapsed time line."
1588   (let (deactivate-mark)
1589     (save-excursion
1590       (ignore-errors
1591         (walk-windows
1592          (lambda (w)
1593            (set-buffer (window-buffer w))
1594            (when (eq major-mode 'gnus-article-mode)
1595              (goto-char (point-min))
1596              (when (re-search-forward "^X-Sent:" nil t)
1597                (article-date-lapsed t)))))))))
1598
1599 (defun gnus-start-date-timer (&optional n)
1600   "Start a timer to update the X-Sent header in the article buffers.
1601 The numerical prefix says how frequently (in seconds) the function
1602 is to run."
1603   (interactive "p")
1604   (unless n
1605     (setq n 1))
1606   (gnus-stop-date-timer)
1607   (setq article-lapsed-timer
1608         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1609
1610 (defun gnus-stop-date-timer ()
1611   "Stop the X-Sent timer."
1612   (interactive)
1613   (when article-lapsed-timer
1614     (nnheader-cancel-timer article-lapsed-timer)
1615     (setq article-lapsed-timer nil)))
1616
1617 (defun article-date-user (&optional highlight)
1618   "Convert the current article date to the user-defined format.
1619 This format is defined by the `gnus-article-time-format' variable."
1620   (interactive (list t))
1621   (article-date-ut 'user highlight))
1622
1623 (defun article-date-iso8601 (&optional highlight)
1624   "Convert the current article date to ISO8601."
1625   (interactive (list t))
1626   (article-date-ut 'iso8601 highlight))
1627
1628 (defun article-show-all ()
1629   "Show all hidden text in the article buffer."
1630   (interactive)
1631   (save-excursion
1632     (let ((buffer-read-only nil))
1633       (gnus-article-unhide-text (point-min) (point-max)))))
1634
1635 (defun article-emphasize (&optional arg)
1636   "Emphasize text according to `gnus-emphasis-alist'."
1637   (interactive (gnus-article-hidden-arg))
1638   (unless (gnus-article-check-hidden-text 'emphasis arg)
1639     (save-excursion
1640       (let ((alist gnus-emphasis-alist)
1641             (buffer-read-only nil)
1642             (props (append '(article-type emphasis)
1643                            gnus-hidden-properties))
1644             regexp elem beg invisible visible face)
1645         (article-goto-body)
1646         (setq beg (point))
1647         (while (setq elem (pop alist))
1648           (goto-char beg)
1649           (setq regexp (car elem)
1650                 invisible (nth 1 elem)
1651                 visible (nth 2 elem)
1652                 face (nth 3 elem))
1653           (while (re-search-forward regexp nil t)
1654             (when (and (match-beginning visible) (match-beginning invisible))
1655               (gnus-article-hide-text
1656                (match-beginning invisible) (match-end invisible) props)
1657               (gnus-article-unhide-text-type
1658                (match-beginning visible) (match-end visible) 'emphasis)
1659               (gnus-put-text-property-excluding-newlines
1660                (match-beginning visible) (match-end visible) 'face face)
1661               (goto-char (match-end invisible)))))))))
1662
1663 (defvar gnus-summary-article-menu)
1664 (defvar gnus-summary-post-menu)
1665
1666 ;;; Saving functions.
1667
1668 (defun gnus-article-save (save-buffer file &optional num)
1669   "Save the currently selected article."
1670   (unless gnus-save-all-headers
1671     ;; Remove headers according to `gnus-saved-headers'.
1672     (let ((gnus-visible-headers
1673            (or gnus-saved-headers gnus-visible-headers))
1674           (gnus-article-buffer save-buffer))
1675       (save-excursion
1676         (set-buffer save-buffer)
1677         (article-hide-headers 1 t))))
1678   (save-window-excursion
1679     (if (not gnus-default-article-saver)
1680         (error "No default saver is defined")
1681       ;; !!! Magic!  The saving functions all save
1682       ;; `gnus-save-article-buffer' (or so they think), but we
1683       ;; bind that variable to our save-buffer.
1684       (set-buffer gnus-article-buffer)
1685       (let* ((gnus-save-article-buffer save-buffer)
1686              (filename
1687               (cond
1688                ((not gnus-prompt-before-saving) 'default)
1689                ((eq gnus-prompt-before-saving 'always) nil)
1690                (t file)))
1691              (gnus-number-of-articles-to-be-saved
1692               (when (eq gnus-prompt-before-saving t)
1693                 num)))                  ; Magic
1694         (set-buffer gnus-article-current-summary)
1695         (funcall gnus-default-article-saver filename)))))
1696
1697 (defun gnus-read-save-file-name (prompt &optional filename
1698                                         function group headers variable)
1699   (let ((default-name
1700           (funcall function group headers (symbol-value variable)))
1701         result)
1702     (setq
1703      result
1704      (cond
1705       ((eq filename 'default)
1706        default-name)
1707       ((eq filename t)
1708        default-name)
1709       (filename filename)
1710       (t
1711        (let* ((split-name (gnus-get-split-value gnus-split-methods))
1712               (prompt
1713                (format prompt
1714                        (if (and gnus-number-of-articles-to-be-saved
1715                                 (> gnus-number-of-articles-to-be-saved 1))
1716                            (format "these %d articles"
1717                                    gnus-number-of-articles-to-be-saved)
1718                          "this article")))
1719               (file
1720                ;; Let the split methods have their say.
1721                (cond
1722                 ;; No split name was found.
1723                 ((null split-name)
1724                  (read-file-name
1725                   (concat prompt " (default "
1726                           (file-name-nondirectory default-name) ") ")
1727                   (file-name-directory default-name)
1728                   default-name))
1729                 ;; A single group name is returned.
1730                 ((stringp split-name)
1731                  (setq default-name
1732                        (funcall function split-name headers
1733                                 (symbol-value variable)))
1734                  (read-file-name
1735                   (concat prompt " (default "
1736                           (file-name-nondirectory default-name) ") ")
1737                   (file-name-directory default-name)
1738                   default-name))
1739                 ;; A single split name was found
1740                 ((= 1 (length split-name))
1741                  (let* ((name (expand-file-name
1742                                (car split-name) gnus-article-save-directory))
1743                         (dir (cond ((file-directory-p name)
1744                                     (file-name-as-directory name))
1745                                    ((file-exists-p name) name)
1746                                    (t gnus-article-save-directory))))
1747                    (read-file-name
1748                     (concat prompt " (default " name ") ")
1749                     dir name)))
1750                 ;; A list of splits was found.
1751                 (t
1752                  (setq split-name (nreverse split-name))
1753                  (let (result)
1754                    (let ((file-name-history
1755                           (nconc split-name file-name-history)))
1756                      (setq result
1757                            (expand-file-name
1758                             (read-file-name
1759                              (concat prompt " (`M-p' for defaults) ")
1760                              gnus-article-save-directory
1761                              (car split-name))
1762                             gnus-article-save-directory)))
1763                    (car (push result file-name-history)))))))
1764          ;; Create the directory.
1765          (gnus-make-directory (file-name-directory file))
1766          ;; If we have read a directory, we append the default file name.
1767          (when (file-directory-p file)
1768            (setq file (concat (file-name-as-directory file)
1769                               (file-name-nondirectory default-name))))
1770          ;; Possibly translate some characters.
1771          (nnheader-translate-file-chars file)))))
1772     (gnus-make-directory (file-name-directory result))
1773     (set variable result)))
1774
1775 (defun gnus-article-archive-name (group)
1776   "Return the first instance of an \"Archive-name\" in the current buffer."
1777   (let ((case-fold-search t))
1778     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1779       (nnheader-concat gnus-article-save-directory
1780                        (match-string 1)))))
1781
1782 (defun gnus-article-nndoc-name (group)
1783   "If GROUP is an nndoc group, return the name of the parent group."
1784   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1785     (gnus-group-get-parameter group 'save-article-group)))
1786
1787 (defun gnus-summary-save-in-rmail (&optional filename)
1788   "Append this article to Rmail file.
1789 Optional argument FILENAME specifies file name.
1790 Directory to save to is default to `gnus-article-save-directory'."
1791   (setq filename (gnus-read-save-file-name
1792                   "Save %s in rmail file:" filename
1793                   gnus-rmail-save-name gnus-newsgroup-name
1794                   gnus-current-headers 'gnus-newsgroup-last-rmail))
1795   (gnus-eval-in-buffer-window gnus-save-article-buffer
1796     (save-excursion
1797       (save-restriction
1798         (widen)
1799         (gnus-output-to-rmail filename))))
1800   filename)
1801
1802 (defun gnus-summary-save-in-mail (&optional filename)
1803   "Append this article to Unix mail file.
1804 Optional argument FILENAME specifies file name.
1805 Directory to save to is default to `gnus-article-save-directory'."
1806   (setq filename (gnus-read-save-file-name
1807                   "Save %s in Unix mail file:" filename
1808                   gnus-mail-save-name gnus-newsgroup-name
1809                   gnus-current-headers 'gnus-newsgroup-last-mail))
1810   (gnus-eval-in-buffer-window gnus-save-article-buffer
1811     (save-excursion
1812       (save-restriction
1813         (widen)
1814         (if (and (file-readable-p filename)
1815                  (mail-file-babyl-p filename))
1816             (rmail-output-to-rmail-file filename t)
1817           (gnus-output-to-mail filename)))))
1818   filename)
1819
1820 (defun gnus-summary-save-in-file (&optional filename overwrite)
1821   "Append this article to file.
1822 Optional argument FILENAME specifies file name.
1823 Directory to save to is default to `gnus-article-save-directory'."
1824   (setq filename (gnus-read-save-file-name
1825                   "Save %s in file:" filename
1826                   gnus-file-save-name gnus-newsgroup-name
1827                   gnus-current-headers 'gnus-newsgroup-last-file))
1828   (gnus-eval-in-buffer-window gnus-save-article-buffer
1829     (save-excursion
1830       (save-restriction
1831         (widen)
1832         (when (and overwrite
1833                    (file-exists-p filename))
1834           (delete-file filename))
1835         (gnus-output-to-file filename))))
1836   filename)
1837
1838 (defun gnus-summary-write-to-file (&optional filename)
1839   "Write this article to a file.
1840 Optional argument FILENAME specifies file name.
1841 The directory to save in defaults to `gnus-article-save-directory'."
1842   (gnus-summary-save-in-file nil t))
1843
1844 (defun gnus-summary-save-body-in-file (&optional filename)
1845   "Append this article body to a file.
1846 Optional argument FILENAME specifies file name.
1847 The directory to save in defaults to `gnus-article-save-directory'."
1848   (setq filename (gnus-read-save-file-name
1849                   "Save %s body in file:" filename
1850                   gnus-file-save-name gnus-newsgroup-name
1851                   gnus-current-headers 'gnus-newsgroup-last-file))
1852   (gnus-eval-in-buffer-window gnus-save-article-buffer
1853     (save-excursion
1854       (save-restriction
1855         (widen)
1856         (when (article-goto-body)
1857           (narrow-to-region (point) (point-max)))
1858         (gnus-output-to-file filename))))
1859   filename)
1860
1861 (defun gnus-summary-save-in-pipe (&optional command)
1862   "Pipe this article to subprocess."
1863   (setq command
1864         (cond ((and (eq command 'default)
1865                     gnus-last-shell-command)
1866                gnus-last-shell-command)
1867               (command command)
1868               (t (read-string
1869                   (format
1870                    "Shell command on %s: "
1871                    (if (and gnus-number-of-articles-to-be-saved
1872                             (> gnus-number-of-articles-to-be-saved 1))
1873                        (format "these %d articles"
1874                                gnus-number-of-articles-to-be-saved)
1875                      "this article"))
1876                   gnus-last-shell-command))))
1877   (when (string-equal command "")
1878     (setq command gnus-last-shell-command))
1879   (gnus-eval-in-buffer-window gnus-article-buffer
1880     (save-restriction
1881       (widen)
1882       (shell-command-on-region (point-min) (point-max) command nil)))
1883   (setq gnus-last-shell-command command))
1884
1885 ;;; Article file names when saving.
1886
1887 (defun gnus-capitalize-newsgroup (newsgroup)
1888   "Capitalize NEWSGROUP name."
1889   (when (not (zerop (length newsgroup)))
1890     (concat (char-to-string (upcase (aref newsgroup 0)))
1891             (substring newsgroup 1))))
1892
1893 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1894   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1895 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1896 Otherwise, it is like ~/News/news/group/num."
1897   (let ((default
1898           (expand-file-name
1899            (concat (if (gnus-use-long-file-name 'not-save)
1900                        (gnus-capitalize-newsgroup newsgroup)
1901                      (gnus-newsgroup-directory-form newsgroup))
1902                    "/" (int-to-string (mail-header-number headers)))
1903            gnus-article-save-directory)))
1904     (if (and last-file
1905              (string-equal (file-name-directory default)
1906                            (file-name-directory last-file))
1907              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1908         default
1909       (or last-file default))))
1910
1911 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1912   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1913 If variable `gnus-use-long-file-name' is non-nil, it is
1914 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1915   (let ((default
1916           (expand-file-name
1917            (concat (if (gnus-use-long-file-name 'not-save)
1918                        newsgroup
1919                      (gnus-newsgroup-directory-form newsgroup))
1920                    "/" (int-to-string (mail-header-number headers)))
1921            gnus-article-save-directory)))
1922     (if (and last-file
1923              (string-equal (file-name-directory default)
1924                            (file-name-directory last-file))
1925              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1926         default
1927       (or last-file default))))
1928
1929 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1930   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1931 If variable `gnus-use-long-file-name' is non-nil, it is
1932 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1933   (or last-file
1934       (expand-file-name
1935        (if (gnus-use-long-file-name 'not-save)
1936            (gnus-capitalize-newsgroup newsgroup)
1937          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1938        gnus-article-save-directory)))
1939
1940 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1941   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1942 If variable `gnus-use-long-file-name' is non-nil, it is
1943 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1944   (or last-file
1945       (expand-file-name
1946        (if (gnus-use-long-file-name 'not-save)
1947            newsgroup
1948          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1949        gnus-article-save-directory)))
1950
1951 (eval-and-compile
1952   (mapcar
1953    (lambda (func)
1954      (let (afunc gfunc)
1955        (if (consp func)
1956            (setq afunc (car func)
1957                  gfunc (cdr func))
1958          (setq afunc func
1959                gfunc (intern (format "gnus-%s" func))))
1960        (fset gfunc
1961              (if (not (fboundp afunc))
1962                  nil
1963                `(lambda (&optional interactive &rest args)
1964                   ,(documentation afunc t)
1965                   (interactive (list t))
1966                   (save-excursion
1967                     (set-buffer gnus-article-buffer)
1968                     (if interactive
1969                         (call-interactively ',afunc)
1970                       (apply ',afunc args))))))))
1971    '(article-hide-headers
1972      article-hide-boring-headers
1973      article-treat-overstrike
1974      (article-fill . gnus-article-word-wrap)
1975      article-remove-cr
1976      article-display-x-face
1977      article-de-quoted-unreadable
1978      article-mime-decode-quoted-printable
1979      article-hide-pgp
1980      article-hide-pem
1981      article-hide-signature
1982      article-remove-trailing-blank-lines
1983      article-strip-leading-blank-lines
1984      article-strip-multiple-blank-lines
1985      article-strip-leading-space
1986      article-strip-trailing-space
1987      article-strip-blank-lines
1988      article-strip-all-blank-lines
1989      article-date-local
1990      article-date-iso8601
1991      article-date-original
1992      article-date-ut
1993      article-decode-mime-words
1994      article-decode-charset
1995      article-decode-encoded-words
1996      article-date-user
1997      article-date-lapsed
1998      article-emphasize
1999      article-treat-dumbquotes
2000      (article-show-all . gnus-article-show-all-headers))))
2001 \f
2002 ;;;
2003 ;;; Gnus article mode
2004 ;;;
2005
2006 (put 'gnus-article-mode 'mode-class 'special)
2007
2008 (gnus-define-keys gnus-article-mode-map
2009   " " gnus-article-goto-next-page
2010   "\177" gnus-article-goto-prev-page
2011   [delete] gnus-article-goto-prev-page
2012   "\C-c^" gnus-article-refer-article
2013   "h" gnus-article-show-summary
2014   "s" gnus-article-show-summary
2015   "\C-c\C-m" gnus-article-mail
2016   "?" gnus-article-describe-briefly
2017   gnus-mouse-2 gnus-article-push-button
2018   "\r" gnus-article-press-button
2019   "\t" gnus-article-next-button
2020   "\M-\t" gnus-article-prev-button
2021   "e" gnus-article-edit
2022   "<" beginning-of-buffer
2023   ">" end-of-buffer
2024   "\C-c\C-i" gnus-info-find-node
2025   "\C-c\C-b" gnus-bug
2026
2027   "\C-d" gnus-article-read-summary-keys
2028   "\M-*" gnus-article-read-summary-keys
2029   "\M-#" gnus-article-read-summary-keys
2030   "\M-^" gnus-article-read-summary-keys
2031   "\M-g" gnus-article-read-summary-keys)
2032
2033 (substitute-key-definition
2034  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2035
2036 (defun gnus-article-make-menu-bar ()
2037   (gnus-turn-off-edit-menu 'article)
2038   (unless (boundp 'gnus-article-article-menu)
2039     (easy-menu-define
2040      gnus-article-article-menu gnus-article-mode-map ""
2041      '("Article"
2042        ["Scroll forwards" gnus-article-goto-next-page t]
2043        ["Scroll backwards" gnus-article-goto-prev-page t]
2044        ["Show summary" gnus-article-show-summary t]
2045        ["Fetch Message-ID at point" gnus-article-refer-article t]
2046        ["Mail to address at point" gnus-article-mail t]
2047        ["Send a bug report" gnus-bug t]))
2048
2049     (easy-menu-define
2050      gnus-article-treatment-menu gnus-article-mode-map ""
2051      '("Treatment"
2052        ["Hide headers" gnus-article-hide-headers t]
2053        ["Hide signature" gnus-article-hide-signature t]
2054        ["Hide citation" gnus-article-hide-citation t]
2055        ["Treat overstrike" gnus-article-treat-overstrike t]
2056        ["Remove carriage return" gnus-article-remove-cr t]))
2057
2058     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2059
2060     (when (boundp 'gnus-summary-post-menu)
2061       (define-key gnus-article-mode-map [menu-bar post]
2062         (cons "Post" gnus-summary-post-menu)))
2063
2064     (gnus-run-hooks 'gnus-article-menu-hook)))
2065
2066 (defun gnus-article-mode ()
2067   "Major mode for displaying an article.
2068
2069 All normal editing commands are switched off.
2070
2071 The following commands are available in addition to all summary mode
2072 commands:
2073 \\<gnus-article-mode-map>
2074 \\[gnus-article-next-page]\t Scroll the article one page forwards
2075 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2076 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2077 \\[gnus-article-show-summary]\t Display the summary buffer
2078 \\[gnus-article-mail]\t Send a reply to the address near point
2079 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2080 \\[gnus-info-find-node]\t Go to the Gnus info node"
2081   (interactive)
2082   (when (gnus-visual-p 'article-menu 'menu)
2083     (gnus-article-make-menu-bar))
2084   (gnus-simplify-mode-line)
2085   (setq mode-name "Article")
2086   (setq major-mode 'gnus-article-mode)
2087   (make-local-variable 'minor-mode-alist)
2088   (unless (assq 'gnus-show-mime minor-mode-alist)
2089     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2090   (use-local-map gnus-article-mode-map)
2091   (gnus-update-format-specifications nil 'article-mode)
2092   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2093   (make-local-variable 'gnus-page-broken)
2094   (make-local-variable 'gnus-button-marker-list)
2095   (make-local-variable 'gnus-article-current-summary)
2096   (make-local-variable 'gnus-article-mime-handles)
2097   (make-local-variable 'gnus-article-decoded-p)
2098   (make-local-variable 'gnus-article-mime-handle-alist)
2099   (gnus-set-default-directory)
2100   (buffer-disable-undo)
2101   (setq buffer-read-only t)
2102   (set-syntax-table gnus-article-mode-syntax-table)
2103   (gnus-run-hooks 'gnus-article-mode-hook))
2104
2105 (defun gnus-article-setup-buffer ()
2106   "Initialize the article buffer."
2107   (let* ((name (if gnus-single-article-buffer "*Article*"
2108                  (concat "*Article " gnus-newsgroup-name "*")))
2109          (original
2110           (progn (string-match "\\*Article" name)
2111                  (concat " *Original Article"
2112                          (substring name (match-end 0))))))
2113     (setq gnus-article-buffer name)
2114     (setq gnus-original-article-buffer original)
2115     (setq gnus-article-mime-handle-alist nil)
2116     ;; This might be a variable local to the summary buffer.
2117     (unless gnus-single-article-buffer
2118       (save-excursion
2119         (set-buffer gnus-summary-buffer)
2120         (setq gnus-article-buffer name)
2121         (setq gnus-original-article-buffer original)
2122         (gnus-set-global-variables)))
2123     ;; Init original article buffer.
2124     (save-excursion
2125       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2126       (setq major-mode 'gnus-original-article-mode)
2127       (make-local-variable 'gnus-original-article))
2128     (if (get-buffer name)
2129         (save-excursion
2130           (set-buffer name)
2131           (buffer-disable-undo)
2132           (setq buffer-read-only t)
2133           (unless (eq major-mode 'gnus-article-mode)
2134             (gnus-article-mode))
2135           (current-buffer))
2136       (save-excursion
2137         (set-buffer (gnus-get-buffer-create name))
2138         (gnus-article-mode)
2139         (make-local-variable 'gnus-summary-buffer)
2140         (gnus-summary-set-local-parameters gnus-newsgroup-name)
2141         (current-buffer)))))
2142
2143 ;; Set article window start at LINE, where LINE is the number of lines
2144 ;; from the head of the article.
2145 (defun gnus-article-set-window-start (&optional line)
2146   (set-window-start
2147    (get-buffer-window gnus-article-buffer t)
2148    (save-excursion
2149      (set-buffer gnus-article-buffer)
2150      (goto-char (point-min))
2151      (if (not line)
2152          (point-min)
2153        (gnus-message 6 "Moved to bookmark")
2154        (search-forward "\n\n" nil t)
2155        (forward-line line)
2156        (point)))))
2157
2158 ;;; @@ article filters
2159 ;;;
2160
2161 (defun gnus-article-display-mime-message ()
2162   "Article display method for MIME message."
2163   ;; called from `gnus-original-article-buffer'.
2164   (let ((charset (with-current-buffer gnus-summary-buffer
2165                    default-mime-charset)))
2166     (make-local-variable 'default-mime-charset)
2167     (setq default-mime-charset charset)
2168     (mime-display-message mime-message-structure
2169                           gnus-article-buffer nil gnus-article-mode-map)
2170     (make-local-variable 'default-mime-charset)
2171     (setq default-mime-charset charset)
2172     )
2173   ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2174   (make-local-variable 'mime-button-mother-dispatcher)
2175   (setq mime-button-mother-dispatcher
2176         (function gnus-article-push-button))
2177   (run-hooks 'gnus-mime-article-prepare-hook))
2178
2179 (defun gnus-article-display-traditional-message ()
2180   "Article display method for traditional message."
2181   (set-buffer gnus-article-buffer)
2182   (let (buffer-read-only)
2183     (erase-buffer)
2184     (insert-buffer-substring gnus-original-article-buffer)))
2185
2186 (defun gnus-article-make-full-mail-header (&optional number charset)
2187   "Create a new mail header structure in a raw article buffer."
2188   (unless (and number charset)
2189     (save-current-buffer
2190       (set-buffer gnus-summary-buffer)
2191       (unless number
2192         (setq number (or (cdr gnus-article-current) 0)))
2193       (unless charset
2194         (setq charset (or default-mime-charset 'x-ctext)))))
2195   (goto-char (point-min))
2196   (let ((header-end (if (search-forward "\n\n" nil t)
2197                         (1- (point))
2198                       (goto-char (point-max))))
2199         (chars (- (point-max) (point)))
2200         (lines (count-lines (point) (point-max)))
2201         (default-mime-charset charset)
2202         xref)
2203     (narrow-to-region (point-min) header-end)
2204     (setq xref (std11-fetch-field "xref"))
2205     (prog1
2206         (make-full-mail-header
2207          number
2208          (std11-fetch-field "subject")
2209          (std11-fetch-field "from")
2210          (std11-fetch-field "date")
2211          (std11-fetch-field "message-id")
2212          (std11-fetch-field "references")
2213          chars
2214          lines
2215          (when xref (concat "Xref: " xref)))
2216       (widen))))
2217
2218 (defun gnus-article-prepare (article &optional all-headers header)
2219   "Prepare ARTICLE in article mode buffer.
2220 ARTICLE should either be an article number or a Message-ID.
2221 If ARTICLE is an id, HEADER should be the article headers.
2222 If ALL-HEADERS is non-nil, no headers are hidden."
2223   (save-excursion
2224     ;; Make sure we start in a summary buffer.
2225     (unless (eq major-mode 'gnus-summary-mode)
2226       (set-buffer gnus-summary-buffer))
2227     (setq gnus-summary-buffer (current-buffer))
2228     (let* ((gnus-article (if header (mail-header-number header) article))
2229            (summary-buffer (current-buffer))
2230            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2231            (group gnus-newsgroup-name)
2232            result)
2233       (save-excursion
2234         (gnus-article-setup-buffer)
2235         (set-buffer gnus-original-article-buffer)
2236         ;; Deactivate active regions.
2237         (when (and (boundp 'transient-mark-mode)
2238                    transient-mark-mode)
2239           (setq mark-active nil))
2240         (if (not (setq result (let ((buffer-read-only nil))
2241                                 (gnus-request-article-this-buffer
2242                                  article group))))
2243             ;; There is no such article.
2244             (save-excursion
2245               (when (and (numberp article)
2246                          (not (memq article gnus-newsgroup-sparse)))
2247                 (setq gnus-article-current
2248                       (cons gnus-newsgroup-name article))
2249                 (set-buffer gnus-summary-buffer)
2250                 (setq gnus-current-article article)
2251                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2252                     (progn
2253                       (gnus-summary-set-agent-mark article)
2254                       (message "Message marked for downloading"))
2255                   (gnus-summary-mark-article article gnus-canceled-mark)
2256                   (unless (memq article gnus-newsgroup-sparse)
2257                     (gnus-error 1
2258                      "No such article (may have expired or been canceled)")))))
2259           (if (or (eq result 'pseudo)
2260                   (eq result 'nneething))
2261               (progn
2262                 (save-excursion
2263                   (set-buffer summary-buffer)
2264                   (push article gnus-newsgroup-history)
2265                   (setq gnus-last-article gnus-current-article
2266                         gnus-current-article 0
2267                         gnus-current-headers nil
2268                         gnus-article-current nil)
2269                   (if (eq result 'nneething)
2270                       (gnus-configure-windows 'summary)
2271                     (gnus-configure-windows 'article))
2272                   (gnus-set-global-variables))
2273                 (let ((gnus-article-mime-handle-alist-1
2274                        gnus-article-mime-handle-alist))
2275                   (gnus-set-mode-line 'article)))
2276             ;; The result from the `request' was an actual article -
2277             ;; or at least some text that is now displayed in the
2278             ;; article buffer.
2279             (when (and (numberp article)
2280                        (not (eq article gnus-current-article)))
2281               ;; Seems like a new article has been selected.
2282               ;; `gnus-current-article' must be an article number.
2283               (save-excursion
2284                 (set-buffer summary-buffer)
2285                 (push article gnus-newsgroup-history)
2286                 (setq gnus-last-article gnus-current-article
2287                       gnus-current-article article
2288                       gnus-current-headers
2289                       (gnus-summary-article-header gnus-current-article)
2290                       gnus-article-current
2291                       (cons gnus-newsgroup-name gnus-current-article))
2292                 (unless (vectorp gnus-current-headers)
2293                   (setq gnus-current-headers nil))
2294                 (gnus-summary-goto-subject gnus-current-article)
2295                 (when (gnus-summary-show-thread)
2296                   ;; If the summary buffer really was folded, the
2297                   ;; previous goto may not actually have gone to
2298                   ;; the right article, but the thread root instead.
2299                   ;; So we go again.
2300                   (gnus-summary-goto-subject gnus-current-article))
2301                 (gnus-run-hooks 'gnus-mark-article-hook)
2302                 (gnus-set-mode-line 'summary)
2303                 (when (gnus-visual-p 'article-highlight 'highlight)
2304                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
2305                 ;; Set the global newsgroup variables here.
2306                 ;; Suggested by Jim Sisolak
2307                 ;; <sisolak@trans4.neep.wisc.edu>.
2308                 (gnus-set-global-variables)
2309                 (setq gnus-have-all-headers
2310                       (or all-headers gnus-show-all-headers))))
2311             (when (or (numberp article)
2312                       (stringp article))
2313               (gnus-article-prepare-display)
2314               ;; Do page break.
2315               (goto-char (point-min))
2316               (setq gnus-page-broken
2317                     (when gnus-break-pages
2318                       (gnus-narrow-to-page)
2319                       t)))
2320             (let ((gnus-article-mime-handle-alist-1
2321                    gnus-article-mime-handle-alist))
2322               (gnus-set-mode-line 'article))
2323             (gnus-configure-windows 'article)
2324             (article-goto-body)
2325             (set-window-point (get-buffer-window (current-buffer)) (point))
2326             t))))))
2327
2328 (defun gnus-article-prepare-display ()
2329   "Make the current buffer look like a nice article."
2330   (let ((method
2331          (if gnus-show-mime
2332              (progn
2333                (setq mime-message-structure gnus-current-headers)
2334                gnus-article-display-method-for-mime)
2335            gnus-article-display-method-for-traditional)))
2336     (gnus-run-hooks 'gnus-tmp-internal-hook)
2337     (gnus-run-hooks 'gnus-article-prepare-hook)
2338     ;; Display message.
2339     (funcall method)
2340     ;; Associate this article with the current summary buffer.
2341     (setq gnus-article-current-summary (current-buffer))
2342     ;; Perform the article display hooks.
2343     (gnus-run-hooks 'gnus-article-display-hook)))
2344
2345 ;;;
2346 ;;; Gnus MIME viewing functions
2347 ;;;
2348
2349 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2350   "The following specs can be used:
2351 %t  The MIME type
2352 %n  The `name' parameter
2353 %d  The description, if any
2354 %l  The length of the encoded part
2355 %p  The part identifier
2356 %e  Dots if the part isn't displayed")
2357
2358 (defvar gnus-mime-button-line-format-alist
2359   '((?t gnus-tmp-type ?s)
2360     (?n gnus-tmp-name ?s)
2361     (?d gnus-tmp-description ?s)
2362     (?p gnus-tmp-id ?s)
2363     (?l gnus-tmp-length ?d)
2364     (?e gnus-tmp-dots ?s)))
2365
2366 (defvar gnus-mime-button-commands
2367   '((gnus-article-press-button  "\r"    "Toggle Display")
2368     (gnus-mime-view-part        "v"     "View Interactively...")
2369     (gnus-mime-save-part        "o"     "Save...")
2370     (gnus-mime-copy-part        "c"     "View As Text, In Other Buffer")
2371     (gnus-mime-inline-part      "i"     "View As Text, In This Buffer")
2372     (gnus-mime-internalize-part "E"     "View Internally")
2373     (gnus-mime-externalize-part "e"     "View Externally")
2374     (gnus-mime-pipe-part        "|"     "Pipe To Command...")))
2375
2376 (defun gnus-article-mime-part-status ()
2377   (if gnus-article-mime-handle-alist-1
2378       (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2379     ""))
2380
2381 (defvar gnus-mime-button-map nil)
2382 (unless gnus-mime-button-map
2383   (setq gnus-mime-button-map (make-sparse-keymap))
2384   (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2385   (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2386   (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2387   (mapcar (lambda (c)
2388             (define-key gnus-mime-button-map (cadr c) (car c)))
2389           gnus-mime-button-commands))
2390
2391 (defun gnus-mime-button-menu (event)
2392   "Construct a context-sensitive menu of MIME commands."
2393   (interactive "e")
2394   (gnus-article-check-buffer)
2395   (let ((response (x-popup-menu 
2396                   t `("MIME Part" 
2397                       ("" ,@(mapcar (lambda (c)
2398                                       (cons (caddr c) (car c)))
2399                                     gnus-mime-button-commands)))))
2400         (pos (event-start event)))
2401     (when response
2402       (set-buffer (window-buffer (posn-window pos)))
2403       (goto-char (posn-point pos))
2404       (funcall response))))
2405
2406 (defun gnus-mime-view-all-parts ()
2407   "View all the MIME parts."
2408   (interactive)
2409   (save-current-buffer
2410     (set-buffer gnus-article-buffer)
2411     (let ((handles gnus-article-mime-handles)
2412           (rfc2047-default-charset gnus-newsgroup-default-charset)
2413           (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2414       (while handles
2415         (mm-display-part (pop handles))))))
2416
2417 (defun gnus-mime-save-part ()
2418   "Save the MIME part under point."
2419   (interactive)
2420   (gnus-article-check-buffer)
2421   (let ((data (get-text-property (point) 'gnus-data)))
2422     (mm-save-part data)))
2423
2424 (defun gnus-mime-pipe-part ()
2425   "Pipe the MIME part under point to a process."
2426   (interactive)
2427   (gnus-article-check-buffer)
2428   (let ((data (get-text-property (point) 'gnus-data)))
2429     (mm-pipe-part data)))
2430
2431 (defun gnus-mime-view-part ()
2432   "Interactively choose a view method for the MIME part under point."
2433   (interactive)
2434   (gnus-article-check-buffer)
2435   (let ((data (get-text-property (point) 'gnus-data))
2436         (url-standalone-mode (not gnus-plugged)))
2437     (mm-interactively-view-part data)))
2438
2439 (defun gnus-mime-copy-part (&optional handle)
2440   "Put the the MIME part under point into a new buffer."
2441   (interactive)
2442   (gnus-article-check-buffer)
2443   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2444          (contents (mm-get-part handle))|
2445          (base (file-name-nondirectory
2446                 (or
2447                  (mail-content-type-get (mm-handle-type handle) 'name)
2448                  (mail-content-type-get (mm-handle-type handle)
2449                                         'filename)
2450                  "*decoded*")))
2451          (buffer (generate-new-buffer base)))
2452     (switch-to-buffer buffer)
2453     (insert contents)
2454     ;; We do it this way to make `normal-mode' set the appropriate mode.
2455     (unwind-protect
2456         (progn
2457           (setq buffer-file-name (expand-file-name base))
2458           (normal-mode))
2459       (setq buffer-file-name nil))
2460     (goto-char (point-min))))
2461
2462 (defun gnus-mime-inline-part (&optional charset)
2463   "Insert the MIME part under point into the current buffer."
2464   (interactive "P") ; For compatibility reasons we are not using "z".
2465   (gnus-article-check-buffer)
2466   (let* ((data (get-text-property (point) 'gnus-data))
2467          contents
2468          (url-standalone-mode (not gnus-plugged))
2469          (b (point))
2470          buffer-read-only)
2471     (if (mm-handle-undisplayer data)
2472         (mm-remove-part data)
2473       (setq contents (mm-get-part data))
2474       (forward-line 2)
2475       (when charset 
2476         (unless (symbolp charset)
2477           (setq charset (mm-read-coding-system "Charset: ")))
2478         (setq contents (mm-decode-coding-string contents charset)))
2479       (mm-insert-inline data contents)
2480       (goto-char b))))
2481
2482 (defun gnus-mime-externalize-part (&optional handle)
2483   "View the MIME part under point with an external viewer."
2484   (interactive)
2485   (gnus-article-check-buffer)
2486   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2487          (url-standalone-mode (not gnus-plugged))
2488          (mm-user-display-methods nil)
2489          (mm-all-images-fit t)
2490          (rfc2047-default-charset gnus-newsgroup-default-charset)
2491          (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2492     (if (mm-handle-undisplayer handle)
2493         (mm-remove-part handle)
2494       (mm-display-part handle))))
2495
2496 (defun gnus-mime-internalize-part (&optional handle)
2497   "View the MIME part under point with an internal viewer."
2498   (interactive)
2499   (gnus-article-check-buffer)
2500   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2501          (url-standalone-mode (not gnus-plugged))
2502          (mm-user-display-methods '(".*"))
2503          (rfc2047-default-charset gnus-newsgroup-default-charset)
2504          (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2505     (if (mm-handle-undisplayer handle)
2506         (mm-remove-part handle)
2507       (mm-display-part handle))))
2508
2509 (defun gnus-article-part-wrapper (n function)
2510   (save-current-buffer
2511     (set-buffer gnus-article-buffer)
2512     (when (> n (length gnus-article-mime-handle-alist))
2513       (error "No such part"))
2514     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2515       (funcall function handle))))
2516
2517 (defun gnus-article-pipe-part (n)
2518   "Pipe MIME part N, which is the numerical prefix."
2519   (interactive "p")
2520   (gnus-article-part-wrapper n 'mm-pipe-part))
2521   
2522 (defun gnus-article-save-part (n)
2523   "Save MIME part N, which is the numerical prefix."
2524   (interactive "p")
2525   (gnus-article-part-wrapper n 'mm-save-part))
2526   
2527 (defun gnus-article-interactively-view-part (n)
2528   "Pipe MIME part N, which is the numerical prefix."
2529   (interactive "p")
2530   (gnus-article-part-wrapper n 'mm-interactively-view-part))
2531   
2532 (defun gnus-article-copy-part (n)
2533   "Pipe MIME part N, which is the numerical prefix."
2534   (interactive "p")
2535   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2536
2537 (defun gnus-article-externalize-part (n)
2538   "Pipe MIME part N, which is the numerical prefix."
2539   (interactive "p")
2540   (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2541   
2542 (defun gnus-article-view-part (n)
2543   "View MIME part N, which is the numerical prefix."
2544   (interactive "p")
2545   (save-current-buffer
2546     (set-buffer gnus-article-buffer)
2547     (when (> n (length gnus-article-mime-handle-alist))
2548       (error "No such part"))
2549     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2550       (when (gnus-article-goto-part n)
2551         (if (equal (car handle) "multipart/alternative")
2552             (gnus-article-press-button)
2553           (when (eq (gnus-mm-display-part handle) 'internal)
2554             (gnus-set-window-start)))))))
2555
2556 (defun gnus-mm-display-part (handle)
2557   "Display HANDLE and fix MIME button."
2558   (let ((id (get-text-property (point) 'gnus-part))
2559         (point (point))
2560         buffer-read-only)
2561     (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2562     (gnus-insert-mime-button
2563      handle id (list (not (mm-handle-displayed-p handle))))
2564     (prog1
2565         (let ((window (selected-window))
2566               (rfc2047-default-charset gnus-newsgroup-default-charset)
2567               (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2568           (save-excursion
2569             (unwind-protect
2570                 (let ((win (get-buffer-window (current-buffer) t)))
2571                   (if win
2572                       (select-window win))
2573                   (goto-char point)
2574                   (forward-line)
2575                   (mm-display-part handle))
2576               (select-window window))))
2577       (goto-char point))))
2578
2579 (defun gnus-article-goto-part (n)
2580   "Go to MIME part N."
2581   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2582     (when point
2583       (goto-char point))))
2584
2585 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2586   (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2587         (filename (mail-content-type-get (mm-handle-disposition handle)
2588                                          'filename))
2589         (gnus-tmp-type (car (mm-handle-type handle)))
2590         (gnus-tmp-description (mm-handle-description handle))
2591         (gnus-tmp-dots
2592          (if (if displayed (car displayed)
2593                (mm-handle-displayed-p handle))
2594              "" "..."))
2595         (gnus-tmp-length (save-excursion
2596                            (set-buffer (mm-handle-buffer handle))
2597                            (buffer-size)))
2598         b e)
2599     (setq gnus-tmp-name (or gnus-tmp-name filename))
2600     (setq gnus-tmp-name
2601           (if gnus-tmp-name
2602               (concat " (" gnus-tmp-name ")")
2603             ""))
2604     (setq gnus-tmp-description
2605           (if gnus-tmp-description
2606               (concat " (" gnus-tmp-description ")")
2607             ""))
2608     (unless (bolp)
2609       (insert "\n"))
2610     (setq b (point))
2611     (gnus-eval-format
2612      gnus-mime-button-line-format gnus-mime-button-line-format-alist
2613      `(local-map ,gnus-mime-button-map
2614                  keymap ,gnus-mime-button-map
2615                  gnus-callback gnus-mm-display-part
2616                  gnus-part ,gnus-tmp-id
2617                  article-type annotation
2618                  gnus-data ,handle))
2619     (setq e (point))
2620     (widget-convert-button 'link b e :action 'gnus-widget-press-button
2621                            :button-keymap gnus-mime-button-map)))
2622
2623 (defun gnus-widget-press-button (elems el)
2624   (goto-char (widget-get elems :from))
2625   (let ((url-standalone-mode (not gnus-plugged)))
2626     (gnus-article-press-button)))
2627
2628 (defun gnus-display-mime (&optional ihandles)
2629   "Insert MIME buttons in the buffer."
2630   (save-excursion
2631     (save-selected-window
2632       (let ((window (get-buffer-window gnus-article-buffer)))
2633         (when window
2634           (select-window window)))
2635       (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2636              handle name type b e display)
2637         (unless ihandles
2638           ;; Top-level call; we clean up.
2639           (mm-destroy-parts gnus-article-mime-handles)
2640           (setq gnus-article-mime-handles handles
2641                 gnus-article-mime-handle-alist nil)
2642           ;; We allow users to glean info from the handles.
2643           (when gnus-article-mime-part-function
2644             (gnus-mime-part-function handles)))
2645         (when (and handles
2646                    (or (not (stringp (car handles)))
2647                        (cdr handles)))
2648           (unless ihandles
2649             ;; Clean up for mime parts.
2650             (article-goto-body)
2651             (delete-region (point) (point-max)))
2652           (gnus-mime-display-part handles))))))
2653
2654 (defun gnus-mime-display-part (handle)
2655   (cond
2656    ;; Single part.
2657    ((not (stringp (car handle)))
2658     (gnus-mime-display-single handle))
2659    ;; multipart/alternative
2660    ((equal (car handle) "multipart/alternative")
2661     (let ((id (1+ (length gnus-article-mime-handle-alist))))
2662       (push (cons id handle) gnus-article-mime-handle-alist)
2663       (gnus-mime-display-alternative (cdr handle) nil nil id)))
2664    ;; multipart/related
2665    ((equal (car handle) "multipart/related")
2666     ;;;!!!We should find the start part, but we just default
2667     ;;;!!!to the first part.
2668     (gnus-mime-display-part (cadr handle)))
2669    ;; Other multiparts are handled like multipart/mixed.
2670    (t
2671     (gnus-mime-display-mixed (cdr handle)))))
2672
2673 (defun gnus-mime-part-function (handles)
2674   (if (stringp (car handles))
2675       (mapcar 'gnus-mime-part-function (cdr handles))
2676     (funcall gnus-article-mime-part-function handles)))
2677
2678 (defun gnus-mime-display-mixed (handles)
2679   (mapcar 'gnus-mime-display-part handles))
2680
2681 (defun gnus-mime-display-single (handle)
2682   (let ((type (car (mm-handle-type handle)))
2683         (ignored gnus-ignored-mime-types)
2684         (not-attachment t)
2685         (move nil)
2686         display text)
2687     (catch 'ignored
2688       (progn
2689         (while ignored
2690           (when (string-match (pop ignored) type)
2691             (throw 'ignored nil)))
2692         (if (and (mm-automatic-display-p type)
2693                  (or (mm-inlinable-part-p type)
2694                      (mm-automatic-external-display-p type))
2695                  (setq not-attachment
2696                        (or (not (mm-handle-disposition handle))
2697                            (equal (car (mm-handle-disposition handle))
2698                                   "inline"))))
2699             (setq display t)
2700           (when (equal (car (split-string type "/"))
2701                        "text")
2702             (setq text t)))
2703         (let ((id (1+ (length gnus-article-mime-handle-alist))))
2704           (push (cons id handle) gnus-article-mime-handle-alist)
2705           (when (or (not display)
2706                     (not (gnus-unbuttonized-mime-type-p type)))
2707             (gnus-article-insert-newline)
2708             (gnus-insert-mime-button
2709              handle id (list (or display
2710                                  (and not-attachment text))))
2711             (gnus-article-insert-newline)
2712             (gnus-article-insert-newline)
2713             (setq move t)))
2714         (cond
2715          (display
2716           (when move
2717             (forward-line -2))
2718           (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2719                 (mm-charset-iso-8859-1-forced 
2720                  gnus-newsgroup-iso-8859-1-forced))
2721             (mm-display-part handle t))
2722           (goto-char (point-max)))
2723          ((and text not-attachment)
2724           (when move
2725             (forward-line -2))
2726           (gnus-article-insert-newline)
2727           (mm-insert-inline handle (mm-get-part handle))
2728           (goto-char (point-max))))))))
2729
2730 (defun gnus-unbuttonized-mime-type-p (type)
2731   "Say whether TYPE is to be unbuttonized."
2732   (unless gnus-inhibit-mime-unbuttonizing
2733     (catch 'found
2734       (let ((types gnus-unbuttonized-mime-types))
2735         (while types
2736           (when (string-match (pop types) type)
2737             (throw 'found t)))))))
2738
2739 (defun gnus-article-insert-newline ()
2740   "Insert a newline, but mark it as undeletable."
2741   (gnus-put-text-property
2742    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2743
2744 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2745   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2746          (ihandles handles)
2747          (point (point))
2748          handle buffer-read-only from props begend not-pref)
2749     (save-window-excursion
2750       (save-restriction
2751         (when ibegend
2752           (narrow-to-region (car ibegend)
2753                             (or (cdr ibegend)
2754                                 (progn
2755                                   (goto-char (car ibegend))
2756                                   (forward-line 2)
2757                                   (point))))
2758           (delete-region (point-min) (point-max))
2759           (mm-remove-parts handles))
2760         (setq begend (list (point-marker)))
2761         ;; Do the toggle.
2762         (unless (setq not-pref (cadr (member preferred ihandles)))
2763           (setq not-pref (car ihandles)))
2764         (when (or ibegend
2765                   (not (gnus-unbuttonized-mime-type-p
2766                         "multipart/alternative")))
2767           (gnus-add-text-properties
2768            (setq from (point))
2769            (progn
2770              (insert (format "%d.  " id))
2771              (point))
2772            `(gnus-callback
2773              (lambda (handles)
2774                (unless ,(not ibegend)
2775                  (setq gnus-article-mime-handle-alist
2776                        ',gnus-article-mime-handle-alist))
2777                (gnus-mime-display-alternative
2778                 ',ihandles ',not-pref ',begend ,id))
2779              local-map ,gnus-mime-button-map
2780              ,gnus-mouse-face-prop ,gnus-article-mouse-face
2781              face ,gnus-article-button-face
2782              keymap ,gnus-mime-button-map
2783              gnus-part ,id
2784              gnus-data ,handle))
2785           (widget-convert-button 'link from (point)
2786                                  :action 'gnus-widget-press-button
2787                                  :button-keymap gnus-widget-button-keymap)
2788           ;; Do the handles
2789           (while (setq handle (pop handles))
2790             (gnus-add-text-properties
2791              (setq from (point))
2792              (progn
2793                (insert (format "[%c] %-18s"
2794                                (if (equal handle preferred) ?* ? )
2795                                (if (stringp (car handle))
2796                                    (car handle)
2797                                  (car (mm-handle-type handle)))))
2798                (point))
2799              `(gnus-callback
2800                (lambda (handles)
2801                  (unless ,(not ibegend)
2802                    (setq gnus-article-mime-handle-alist
2803                          ',gnus-article-mime-handle-alist))
2804                  (gnus-mime-display-alternative
2805                   ',ihandles ',handle ',begend ,id))
2806                local-map ,gnus-mime-button-map
2807                ,gnus-mouse-face-prop ,gnus-article-mouse-face
2808                face ,gnus-article-button-face
2809                keymap ,gnus-mime-button-map
2810                gnus-part ,id
2811                gnus-data ,handle))
2812             (widget-convert-button 'link from (point)
2813                                    :action 'gnus-widget-press-button
2814                                    :button-keymap gnus-widget-button-keymap)
2815             (insert "  "))
2816           (insert "\n\n"))
2817         (when preferred
2818           (if (stringp (car preferred))
2819               (gnus-display-mime preferred)
2820             (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2821                   (mm-charset-iso-8859-1-forced 
2822                    gnus-newsgroup-iso-8859-1-forced))
2823               (mm-display-part preferred)))
2824           (goto-char (point-max))
2825           (setcdr begend (point-marker)))))
2826     (when ibegend
2827       (goto-char point))))
2828
2829 (defun gnus-article-wash-status ()
2830   "Return a string which display status of article washing."
2831   (save-excursion
2832     (set-buffer gnus-article-buffer)
2833     (let ((cite (gnus-article-hidden-text-p 'cite))
2834           (headers (gnus-article-hidden-text-p 'headers))
2835           (boring (gnus-article-hidden-text-p 'boring-headers))
2836           (pgp (gnus-article-hidden-text-p 'pgp))
2837           (pem (gnus-article-hidden-text-p 'pem))
2838           (signature (gnus-article-hidden-text-p 'signature))
2839           (overstrike (gnus-article-hidden-text-p 'overstrike))
2840           (emphasis (gnus-article-hidden-text-p 'emphasis))
2841           (mime gnus-show-mime))
2842       (format "%c%c%c%c%c%c%c"
2843               (if cite ?c ? )
2844               (if (or headers boring) ?h ? )
2845               (if (or pgp pem) ?p ? )
2846               (if signature ?s ? )
2847               (if overstrike ?o ? )
2848               (if mime ?m ? )
2849               (if emphasis ?e ? )))))
2850
2851 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2852
2853 (defun gnus-article-maybe-hide-headers ()
2854   "Hide unwanted headers if `gnus-have-all-headers' is nil.
2855 Provided for backwards compatibility."
2856   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2857       gnus-inhibit-hiding
2858       (gnus-article-hide-headers)))
2859
2860 ;;; Article savers.
2861
2862 (defun gnus-output-to-file (file-name)
2863   "Append the current article to a file named FILE-NAME."
2864   (let ((artbuf (current-buffer)))
2865     (with-temp-buffer
2866       (insert-buffer-substring artbuf)
2867       ;; Append newline at end of the buffer as separator, and then
2868       ;; save it to file.
2869       (goto-char (point-max))
2870       (insert "\n")
2871       (append-to-file (point-min) (point-max) file-name)
2872       t)))
2873
2874 (defun gnus-narrow-to-page (&optional arg)
2875   "Narrow the article buffer to a page.
2876 If given a numerical ARG, move forward ARG pages."
2877   (interactive "P")
2878   (setq arg (if arg (prefix-numeric-value arg) 0))
2879   (save-excursion
2880     (set-buffer gnus-article-buffer)
2881     (goto-char (point-min))
2882     (widen)
2883     ;; Remove any old next/prev buttons.
2884     (when (gnus-visual-p 'page-marker)
2885       (let ((buffer-read-only nil))
2886         (gnus-remove-text-with-property 'gnus-prev)
2887         (gnus-remove-text-with-property 'gnus-next)))
2888     (when
2889         (cond ((< arg 0)
2890                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2891               ((> arg 0)
2892                (re-search-forward page-delimiter nil 'move arg)))
2893       (goto-char (match-end 0)))
2894     (narrow-to-region
2895      (point)
2896      (if (re-search-forward page-delimiter nil 'move)
2897          (match-beginning 0)
2898        (point)))
2899     (when (and (gnus-visual-p 'page-marker)
2900                (not (= (point-min) 1)))
2901       (save-excursion
2902         (goto-char (point-min))
2903         (gnus-insert-prev-page-button)))
2904     (when (and (gnus-visual-p 'page-marker)
2905                (< (+ (point-max) 2) (buffer-size)))
2906       (save-excursion
2907         (goto-char (point-max))
2908         (gnus-insert-next-page-button)))))
2909
2910 ;; Article mode commands
2911
2912 (defun gnus-article-goto-next-page ()
2913   "Show the next page of the article."
2914   (interactive)
2915   (when (gnus-article-next-page)
2916     (goto-char (point-min))
2917     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2918
2919 (defun gnus-article-goto-prev-page ()
2920   "Show the next page of the article."
2921   (interactive)
2922   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2923     (gnus-article-prev-page nil)))
2924
2925 (defun gnus-article-next-page (&optional lines)
2926   "Show the next page of the current article.
2927 If end of article, return non-nil.  Otherwise return nil.
2928 Argument LINES specifies lines to be scrolled up."
2929   (interactive "p")
2930   (move-to-window-line -1)
2931   (if (save-excursion
2932         (end-of-line)
2933         (and (pos-visible-in-window-p)  ;Not continuation line.
2934              (eobp)))
2935       ;; Nothing in this page.
2936       (if (or (not gnus-page-broken)
2937               (save-excursion
2938                 (save-restriction
2939                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2940           t                             ;Nothing more.
2941         (gnus-narrow-to-page 1)         ;Go to next page.
2942         nil)
2943     ;; More in this page.
2944     (let ((scroll-in-place nil))
2945       (condition-case ()
2946           (scroll-up lines)
2947         (end-of-buffer
2948          ;; Long lines may cause an end-of-buffer error.
2949          (goto-char (point-max)))))
2950     (move-to-window-line 0)
2951     nil))
2952
2953 (defun gnus-article-prev-page (&optional lines)
2954   "Show previous page of current article.
2955 Argument LINES specifies lines to be scrolled down."
2956   (interactive "p")
2957   (move-to-window-line 0)
2958   (if (and gnus-page-broken
2959            (bobp)
2960            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2961       (progn
2962         (gnus-narrow-to-page -1)        ;Go to previous page.
2963         (goto-char (point-max))
2964         (recenter -1))
2965     (let ((scroll-in-place nil))
2966       (prog1
2967           (condition-case ()
2968               (scroll-down lines)
2969             (beginning-of-buffer
2970              (goto-char (point-min))))
2971         (move-to-window-line 0)))))
2972
2973 (defun gnus-article-refer-article ()
2974   "Read article specified by message-id around point."
2975   (interactive)
2976   (let ((point (point)))
2977     (search-forward ">" nil t)          ;Move point to end of "<....>".
2978     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2979         (let ((message-id (match-string 1)))
2980           (goto-char point)
2981           (set-buffer gnus-summary-buffer)
2982           (gnus-summary-refer-article message-id))
2983       (goto-char (point))
2984       (error "No references around point"))))
2985
2986 (defun gnus-article-show-summary ()
2987   "Reconfigure windows to show summary buffer."
2988   (interactive)
2989   (if (not (gnus-buffer-live-p gnus-summary-buffer))
2990       (error "There is no summary buffer for this article buffer")
2991     (gnus-article-set-globals)
2992     (gnus-configure-windows 'article)
2993     (gnus-summary-goto-subject gnus-current-article)
2994     (gnus-summary-position-point)))
2995
2996 (defun gnus-article-describe-briefly ()
2997   "Describe article mode commands briefly."
2998   (interactive)
2999   (gnus-message 6
3000                 (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")))
3001
3002 (defun gnus-article-summary-command ()
3003   "Execute the last keystroke in the summary buffer."
3004   (interactive)
3005   (let ((obuf (current-buffer))
3006         (owin (current-window-configuration))
3007         func)
3008     (switch-to-buffer gnus-article-current-summary 'norecord)
3009     (setq func (lookup-key (current-local-map) (this-command-keys)))
3010     (call-interactively func)
3011     (set-buffer obuf)
3012     (set-window-configuration owin)
3013     (set-window-point (get-buffer-window (current-buffer)) (point))))
3014
3015 (defun gnus-article-summary-command-nosave ()
3016   "Execute the last keystroke in the summary buffer."
3017   (interactive)
3018   (let (func)
3019     (pop-to-buffer gnus-article-current-summary 'norecord)
3020     (setq func (lookup-key (current-local-map) (this-command-keys)))
3021     (call-interactively func)))
3022
3023 (defun gnus-article-check-buffer ()
3024   "Beep if not in an article buffer."
3025   (unless (equal major-mode 'gnus-article-mode)
3026     (error "Command invoked outside of a Gnus article buffer")))
3027
3028 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3029   "Read a summary buffer key sequence and execute it from the article buffer."
3030   (interactive "P")
3031   (gnus-article-check-buffer)
3032   (let ((nosaves
3033          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
3034            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3035            "=" "^" "\M-^" "|"))
3036         (nosave-but-article
3037          '("A\r"))
3038         (nosave-in-article
3039          '("\C-d"))
3040         (up-to-top
3041          '("n" "Gn" "p" "Gp"))
3042         keys new-sum-point)
3043     (save-excursion
3044       (set-buffer gnus-article-current-summary)
3045       (let (gnus-pick-mode)
3046         (push (or key last-command-event) unread-command-events)
3047         (setq keys (read-key-sequence nil))))
3048     (message "")
3049
3050     (if (or (member keys nosaves)
3051             (member keys nosave-but-article)
3052             (member keys nosave-in-article))
3053         (let (func)
3054           (save-window-excursion
3055             (pop-to-buffer gnus-article-current-summary 'norecord)
3056             ;; We disable the pick minor mode commands.
3057             (let (gnus-pick-mode)
3058               (setq func (lookup-key (current-local-map) keys))))
3059           (if (not func)
3060               (ding)
3061             (unless (member keys nosave-in-article)
3062               (set-buffer gnus-article-current-summary))
3063             (call-interactively func)
3064             (setq new-sum-point (point)))
3065           (when (member keys nosave-but-article)
3066             (pop-to-buffer gnus-article-buffer 'norecord)))
3067       ;; These commands should restore window configuration.
3068       (let ((obuf (current-buffer))
3069             (owin (current-window-configuration))
3070             (opoint (point))
3071             (summary gnus-article-current-summary)
3072             func in-buffer selected)
3073         (if not-restore-window
3074             (pop-to-buffer summary 'norecord)
3075           (switch-to-buffer summary 'norecord))
3076         (setq in-buffer (current-buffer))
3077         ;; We disable the pick minor mode commands.
3078         (if (setq func (let (gnus-pick-mode)
3079                          (lookup-key (current-local-map) keys)))
3080             (progn
3081               (call-interactively func)
3082               (setq new-sum-point (point)))
3083           (ding))
3084         (when (eq in-buffer (current-buffer))
3085           (setq selected (gnus-summary-select-article))
3086           (set-buffer obuf)
3087           (unless not-restore-window
3088             (set-window-configuration owin))
3089           (unless (or (not (eq selected 'old)) (member keys up-to-top))
3090             (set-window-point (get-buffer-window (current-buffer))
3091                               opoint))
3092           (let ((win (get-buffer-window gnus-article-current-summary)))
3093             (when win
3094               (set-window-point win new-sum-point))))))))
3095
3096 (defun gnus-article-hide (&optional arg force)
3097   "Hide all the gruft in the current article.
3098 This means that PGP stuff, signatures, cited text and (some)
3099 headers will be hidden.
3100 If given a prefix, show the hidden text instead."
3101   (interactive (append (gnus-article-hidden-arg) (list 'force)))
3102   (gnus-article-hide-headers arg)
3103   (gnus-article-hide-pgp arg)
3104   (gnus-article-hide-citation-maybe arg force)
3105   (gnus-article-hide-signature arg))
3106
3107 (defun gnus-article-maybe-highlight ()
3108   "Do some article highlighting if article highlighting is requested."
3109   (when (gnus-visual-p 'article-highlight 'highlight)
3110     (gnus-article-highlight-some)))
3111
3112 (defun gnus-check-group-server ()
3113   ;; Make sure the connection to the server is alive.
3114   (unless (gnus-server-opened
3115            (gnus-find-method-for-group gnus-newsgroup-name))
3116     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3117     (gnus-request-group gnus-newsgroup-name t)))
3118
3119 (defun gnus-request-article-this-buffer (article group)
3120   "Get an article and insert it into this buffer."
3121   (let (do-update-line sparse-header)
3122     (prog1
3123         (save-excursion
3124           (erase-buffer)
3125           (gnus-kill-all-overlays)
3126           (setq group (or group gnus-newsgroup-name))
3127
3128           ;; Using `gnus-request-article' directly will insert the article into
3129           ;; `nntp-server-buffer' - so we'll save some time by not having to
3130           ;; copy it from the server buffer into the article buffer.
3131
3132           ;; We only request an article by message-id when we do not have the
3133           ;; headers for it, so we'll have to get those.
3134           (when (stringp article)
3135             (let ((gnus-override-method gnus-refer-article-method))
3136               (gnus-read-header article)))
3137
3138           ;; If the article number is negative, that means that this article
3139           ;; doesn't belong in this newsgroup (possibly), so we find its
3140           ;; message-id and request it by id instead of number.
3141           (when (and (numberp article)
3142                      gnus-summary-buffer
3143                      (get-buffer gnus-summary-buffer)
3144                      (gnus-buffer-exists-p gnus-summary-buffer))
3145             (save-excursion
3146               (set-buffer gnus-summary-buffer)
3147               (let ((header (gnus-summary-article-header article)))
3148                 (when (< article 0)
3149                   (cond
3150                    ((memq article gnus-newsgroup-sparse)
3151                     ;; This is a sparse gap article.
3152                     (setq do-update-line article)
3153                     (setq article (mail-header-id header))
3154                     (let ((gnus-override-method gnus-refer-article-method))
3155                       (setq sparse-header (gnus-read-header article)))
3156                     (setq gnus-newsgroup-sparse
3157                           (delq article gnus-newsgroup-sparse)))
3158                    ((vectorp header)
3159                     ;; It's a real article.
3160                     (setq article (mail-header-id header)))
3161                    (t
3162                     ;; It is an extracted pseudo-article.
3163                     (setq article 'pseudo)
3164                     (gnus-request-pseudo-article header))))
3165
3166                 (let ((method (gnus-find-method-for-group
3167                                gnus-newsgroup-name)))
3168                   (when (and (eq (car method) 'nneething)
3169                              (vectorp header))
3170                     (let ((dir (concat
3171                                 (file-name-as-directory
3172                                  (or (cadr (assq 'nneething-address method))
3173                                      (nth 1 method)))
3174                                 (mail-header-subject header))))
3175                       (when (file-directory-p dir)
3176                         (setq article 'nneething)
3177                         (gnus-group-enter-directory dir))))))))
3178
3179           (cond
3180            ;; Refuse to select canceled articles.
3181            ((and (numberp article)
3182                  gnus-summary-buffer
3183                  (get-buffer gnus-summary-buffer)
3184                  (gnus-buffer-exists-p gnus-summary-buffer)
3185                  (eq (cdr (save-excursion
3186                             (set-buffer gnus-summary-buffer)
3187                             (assq article gnus-newsgroup-reads)))
3188                      gnus-canceled-mark))
3189             nil)
3190            ;; Check the backlog.
3191            ((and gnus-keep-backlog
3192                  (gnus-backlog-request-article group article (current-buffer)))
3193             'article)
3194            ;; Check asynchronous pre-fetch.
3195            ((gnus-async-request-fetched-article group article (current-buffer))
3196             (gnus-async-prefetch-next group article gnus-summary-buffer)
3197             (when (and (numberp article) gnus-keep-backlog)
3198               (gnus-backlog-enter-article group article (current-buffer)))
3199             'article)
3200            ;; Check the cache.
3201            ((and gnus-use-cache
3202                  (numberp article)
3203                  (gnus-cache-request-article article group))
3204             'article)
3205            ;; Get the article and put into the article buffer.
3206            ((or (stringp article) (numberp article))
3207             (let ((gnus-override-method
3208                    (and (stringp article) gnus-refer-article-method))
3209                   (buffer-read-only nil))
3210               (erase-buffer)
3211               (gnus-kill-all-overlays)
3212               (gnus-check-group-server)
3213               (when (gnus-request-article article group (current-buffer))
3214                 (when (numberp article)
3215                   (gnus-async-prefetch-next group article gnus-summary-buffer)
3216                   (when gnus-keep-backlog
3217                     (gnus-backlog-enter-article
3218                      group article (current-buffer))))
3219                 'article)))
3220            ;; It was a pseudo.
3221            (t article)))
3222
3223       ;; Associate this article with the current summary buffer.
3224       (setq gnus-article-current-summary gnus-summary-buffer)
3225
3226       ;; Take the article from the original article buffer
3227       ;; and place it in the buffer it's supposed to be in.
3228       (when (and (get-buffer gnus-article-buffer)
3229                  (equal (buffer-name (current-buffer))
3230                         (buffer-name (get-buffer gnus-article-buffer))))
3231         (save-excursion
3232           (if (get-buffer gnus-original-article-buffer)
3233               (set-buffer gnus-original-article-buffer)
3234             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3235             (buffer-disable-undo)
3236             (setq major-mode 'gnus-original-article-mode)
3237             (setq buffer-read-only t))
3238           (let (buffer-read-only)
3239             (erase-buffer)
3240             (insert-buffer-substring gnus-article-buffer))
3241           (setq gnus-original-article (cons group article)))
3242
3243         ;; Decode charsets.
3244         (run-hooks 'gnus-article-decode-hook)
3245         ;; Mark article as decoded or not.
3246         (setq gnus-article-decoded-p gnus-article-decode-hook))
3247
3248       ;; Update sparse articles.
3249       (when (and do-update-line
3250                  (or (numberp article)
3251                      (stringp article)))
3252         (let ((buf (current-buffer)))
3253           (set-buffer gnus-summary-buffer)
3254           (gnus-summary-update-article do-update-line sparse-header)
3255           (gnus-summary-goto-subject do-update-line nil t)
3256           (set-window-point (get-buffer-window (current-buffer) t)
3257                             (point))
3258           (set-buffer buf))))))
3259
3260 ;;;
3261 ;;; Article editing
3262 ;;;
3263
3264 (defcustom gnus-article-edit-mode-hook nil
3265   "Hook run in article edit mode buffers."
3266   :group 'gnus-article-various
3267   :type 'hook)
3268
3269 (defcustom gnus-article-edit-article-setup-function
3270   'gnus-article-mime-edit-article-setup
3271   "Function called to setup an editing article buffer."
3272   :group 'gnus-article-various
3273   :type 'function)
3274
3275 (defvar gnus-article-edit-done-function nil)
3276
3277 (defvar gnus-article-edit-mode-map nil)
3278
3279 ;; Should we be using derived.el for this?
3280 (unless gnus-article-edit-mode-map
3281   (setq gnus-article-edit-mode-map (make-sparse-keymap))
3282   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3283
3284   (gnus-define-keys gnus-article-edit-mode-map
3285     "\C-c\C-c" gnus-article-edit-done
3286     "\C-c\C-k" gnus-article-edit-exit)
3287
3288   (gnus-define-keys (gnus-article-edit-wash-map
3289                      "\C-c\C-w" gnus-article-edit-mode-map)
3290     "f" gnus-article-edit-full-stops))
3291
3292 (defun gnus-article-edit-mode ()
3293   "Major mode for editing articles.
3294 This is an extended text-mode.
3295
3296 \\{gnus-article-edit-mode-map}"
3297   (interactive)
3298   (setq major-mode 'gnus-article-edit-mode)
3299   (setq mode-name "Article Edit")
3300   (use-local-map gnus-article-edit-mode-map)
3301   (make-local-variable 'gnus-article-edit-done-function)
3302   (make-local-variable 'gnus-prev-winconf)
3303   (setq buffer-read-only nil)
3304   (buffer-enable-undo)
3305   (widen)
3306   (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3307
3308 (defun gnus-article-edit (&optional force)
3309   "Edit the current article.
3310 This will have permanent effect only in mail groups.
3311 If FORCE is non-nil, allow editing of articles even in read-only
3312 groups."
3313   (interactive "P")
3314   (when (and (not force)
3315              (gnus-group-read-only-p))
3316     (error "The current newsgroup does not support article editing"))
3317   (gnus-article-date-original)
3318   (gnus-article-edit-article
3319    `(lambda (no-highlight)
3320       (gnus-summary-edit-article-done
3321        ,(or (mail-header-references gnus-current-headers) "")
3322        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3323
3324 (defun gnus-article-edit-article (exit-func)
3325   "Start editing the contents of the current article buffer."
3326   (let ((winconf (current-window-configuration)))
3327     (set-buffer gnus-article-buffer)
3328     (gnus-article-edit-mode)
3329     (gnus-article-delete-text-of-type 'annotation)
3330     (gnus-set-text-properties (point-min) (point-max) nil)
3331     (gnus-configure-windows 'edit-article)
3332     (setq gnus-article-edit-done-function exit-func)
3333     (setq gnus-prev-winconf winconf)
3334     (when gnus-article-edit-article-setup-function
3335       (funcall gnus-article-edit-article-setup-function))
3336     (gnus-message 6 "C-c C-c to end edits")))
3337
3338 (defun gnus-article-edit-done (&optional arg)
3339   "Update the article edits and exit."
3340   (interactive "P")
3341   (save-excursion
3342     (save-restriction
3343       (widen)
3344       (when (article-goto-body)
3345         (let ((lines (count-lines (point) (point-max)))
3346               (length (- (point-max) (point)))
3347               (case-fold-search t)
3348               (body (copy-marker (point))))
3349           (goto-char (point-min))
3350           (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3351             (delete-region (match-beginning 1) (match-end 1))
3352             (insert (number-to-string length)))
3353           (goto-char (point-min))
3354           (when (re-search-forward
3355                  "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3356             (delete-region (match-beginning 1) (match-end 1))
3357             (insert (number-to-string length)))
3358           (goto-char (point-min))
3359           (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3360             (delete-region (match-beginning 1) (match-end 1))
3361             (insert (number-to-string lines)))))))
3362   (let ((func gnus-article-edit-done-function)
3363         (buf (current-buffer))
3364         (start (window-start)))
3365     (remove-hook 'gnus-article-mode-hook
3366                  'gnus-article-mime-edit-article-unwind)
3367     (gnus-article-edit-exit)
3368     (save-excursion
3369       (set-buffer buf)
3370       (let ((buffer-read-only nil))
3371         (funcall func arg))
3372       ;; The cache and backlog have to be flushed somewhat.
3373       (when gnus-keep-backlog
3374         (gnus-backlog-remove-article
3375          (car gnus-article-current) (cdr gnus-article-current)))
3376       ;; Flush original article as well.
3377       (save-excursion
3378         (when (get-buffer gnus-original-article-buffer)
3379           (set-buffer gnus-original-article-buffer)
3380           (setq gnus-original-article nil)))
3381       (when gnus-use-cache
3382         (gnus-cache-update-article
3383          (car gnus-article-current) (cdr gnus-article-current))))
3384     (set-buffer buf)
3385     (set-window-start (get-buffer-window buf) start)
3386     (set-window-point (get-buffer-window buf) (point))))
3387
3388 (defun gnus-article-edit-exit ()
3389   "Exit the article editing without updating."
3390   (interactive)
3391   ;; We remove all text props from the article buffer.
3392   (let ((buf (format "%s" (buffer-string)))
3393         (curbuf (current-buffer))
3394         (p (point))
3395         (window-start (window-start)))
3396     (erase-buffer)
3397     (insert buf)
3398     (let ((winconf gnus-prev-winconf))
3399       (gnus-article-mode)
3400       (set-window-configuration winconf)
3401       ;; Tippy-toe some to make sure that point remains where it was.
3402       (save-current-buffer
3403         (set-buffer curbuf)
3404         (set-window-start (get-buffer-window (current-buffer)) window-start)
3405         (goto-char p)))))
3406
3407 (defun gnus-article-edit-full-stops ()
3408   "Interactively repair spacing at end of sentences."
3409   (interactive)
3410   (save-excursion
3411     (goto-char (point-min))
3412     (search-forward-regexp "^$" nil t)
3413     (let ((case-fold-search nil))
3414       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3415
3416 ;;;
3417 ;;; Article editing with MIME-Edit
3418 ;;;
3419
3420 (defcustom gnus-article-mime-edit-article-setup-hook nil
3421   "Hook run after setting up a MIME editing article buffer."
3422   :group 'gnus-article-various
3423   :type 'hook)
3424
3425 (defun gnus-article-mime-edit-article-unwind ()
3426   "Unwind `gnus-article-buffer' if article editing was given up."
3427   (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3428   (when mime-edit-mode-flag
3429     (mime-edit-exit 'nomime 'no-error)
3430     (message ""))
3431   (when (featurep 'font-lock)
3432     (setq font-lock-defaults nil)
3433     (font-lock-mode 0)))
3434
3435 (defun gnus-article-mime-edit-article-setup ()
3436   "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3437 after replacing with the original article."
3438   (setq gnus-show-mime t)
3439   (setq gnus-article-edit-done-function
3440         `(lambda (&rest args)
3441            (when mime-edit-mode-flag
3442              (mime-edit-exit)
3443              (message ""))
3444            (goto-char (point-min))
3445            (let (case-fold-search)
3446              (when (re-search-forward
3447                     (format "^%s$" (regexp-quote mail-header-separator))
3448                     nil t)
3449                (replace-match "")))
3450            (when (featurep 'font-lock)
3451              (setq font-lock-defaults nil)
3452              (font-lock-mode 0))
3453            (apply ,gnus-article-edit-done-function args)
3454            (set-buffer gnus-original-article-buffer)
3455            (erase-buffer)
3456            (insert-buffer gnus-article-buffer)
3457            (setq gnus-current-headers (gnus-article-make-full-mail-header))
3458            (gnus-article-prepare-display)))
3459   (substitute-key-definition
3460    'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3461    gnus-article-edit-mode-map)
3462   (erase-buffer)
3463   (insert-buffer gnus-original-article-buffer)
3464   (mime-edit-again)
3465   (when (featurep 'font-lock)
3466     (set (make-local-variable 'font-lock-defaults)
3467          '(message-font-lock-keywords t))
3468     (font-lock-set-defaults)
3469     (turn-on-font-lock))
3470   (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3471   (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3472
3473 (defun gnus-article-mime-edit-exit ()
3474   "Exit the article MIME editing without updating."
3475   (interactive)
3476   (let ((winconf gnus-prev-winconf)
3477         buf)
3478     (when mime-edit-mode-flag
3479       (mime-edit-exit)
3480       (message ""))
3481     (goto-char (point-min))
3482     (let (case-fold-search)
3483       (when (re-search-forward
3484              (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3485         (replace-match "")))
3486     (when (featurep 'font-lock)
3487       (setq font-lock-defaults nil)
3488       (font-lock-mode 0))
3489     ;; We remove all text props from the article buffer.
3490     (setq buf (format "%s" (buffer-string)))
3491     (set-buffer (get-buffer-create gnus-original-article-buffer))
3492     (erase-buffer)
3493     (insert buf)
3494     (setq gnus-current-headers (gnus-article-make-full-mail-header))
3495     (gnus-article-prepare-display)
3496     (set-window-configuration winconf)))
3497
3498 ;;;
3499 ;;; Article highlights
3500 ;;;
3501
3502 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3503
3504 ;;; Internal Variables:
3505
3506 (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\\)"
3507   "Regular expression that matches URLs."
3508   :group 'gnus-article-buttons
3509   :type 'regexp)
3510
3511 (defcustom gnus-button-alist
3512   `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3513      0 t gnus-button-message-id 2)
3514     ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3515     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3516      1 t
3517      gnus-button-fetch-group 4)
3518     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3519     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3520      t gnus-button-message-id 3)
3521     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3522     ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3523     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3524     ;; This is how URLs _should_ be embedded in text...
3525     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3526     ;; Raw URLs.
3527     (,gnus-button-url-regexp 0 t gnus-button-url 0))
3528   "*Alist of regexps matching buttons in article bodies.
3529
3530 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3531 REGEXP: is the string matching text around the button,
3532 BUTTON: is the number of the regexp grouping actually matching the button,
3533 FORM: is a lisp expression which must eval to true for the button to
3534 be added,
3535 CALLBACK: is the function to call when the user push this button, and each
3536 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3537
3538 CALLBACK can also be a variable, in that case the value of that
3539 variable it the real callback function."
3540   :group 'gnus-article-buttons
3541   :type '(repeat (list regexp
3542                        (integer :tag "Button")
3543                        (sexp :tag "Form")
3544                        (function :tag "Callback")
3545                        (repeat :tag "Par"
3546                                :inline t
3547                                (integer :tag "Regexp group")))))
3548
3549 (defcustom gnus-header-button-alist
3550   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3551      0 t gnus-button-message-id 0)
3552     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3553     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3554      0 t gnus-button-mailto 0)
3555     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3556     ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3557     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3558     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3559      gnus-button-message-id 3))
3560   "*Alist of headers and regexps to match buttons in article heads.
3561
3562 This alist is very similar to `gnus-button-alist', except that each
3563 alist has an additional HEADER element first in each entry:
3564
3565 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3566
3567 HEADER is a regexp to match a header.  For a fuller explanation, see
3568 `gnus-button-alist'."
3569   :group 'gnus-article-buttons
3570   :group 'gnus-article-headers
3571   :type '(repeat (list (regexp :tag "Header")
3572                        regexp
3573                        (integer :tag "Button")
3574                        (sexp :tag "Form")
3575                        (function :tag "Callback")
3576                        (repeat :tag "Par"
3577                                :inline t
3578                                (integer :tag "Regexp group")))))
3579
3580 (defvar gnus-button-regexp nil)
3581 (defvar gnus-button-marker-list nil)
3582 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3583
3584 (defvar gnus-button-last nil)
3585 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3586
3587 ;;; Commands:
3588
3589 (defun gnus-article-push-button (event)
3590   "Check text under the mouse pointer for a callback function.
3591 If the text under the mouse pointer has a `gnus-callback' property,
3592 call it with the value of the `gnus-data' text property."
3593   (interactive "e")
3594   (set-buffer (window-buffer (posn-window (event-start event))))
3595   (let* ((pos (posn-point (event-start event)))
3596          (data (get-text-property pos 'gnus-data))
3597          (fun (get-text-property pos 'gnus-callback)))
3598     (goto-char pos)
3599     (when fun
3600       (funcall fun data))))
3601
3602 (defun gnus-article-press-button ()
3603   "Check text at point for a callback function.
3604 If the text at point has a `gnus-callback' property,
3605 call it with the value of the `gnus-data' text property."
3606   (interactive)
3607   (let* ((data (get-text-property (point) 'gnus-data))
3608          (fun (get-text-property (point) 'gnus-callback)))
3609     (when fun
3610       (funcall fun data))))
3611
3612 (defun gnus-article-prev-button (n)
3613   "Move point to N buttons backward.
3614 If N is negative, move forward instead."
3615   (interactive "p")
3616   (gnus-article-next-button (- n)))
3617
3618 (defun gnus-article-next-button (n)
3619   "Move point to N buttons forward.
3620 If N is negative, move backward instead."
3621   (interactive "p")
3622   (let ((function (if (< n 0) 'previous-single-property-change
3623                     'next-single-property-change))
3624         (inhibit-point-motion-hooks t)
3625         (backward (< n 0))
3626         (limit (if (< n 0) (point-min) (point-max))))
3627     (setq n (abs n))
3628     (while (and (not (= limit (point)))
3629                 (> n 0))
3630       ;; Skip past the current button.
3631       (when (get-text-property (point) 'gnus-callback)
3632         (goto-char (funcall function (point) 'gnus-callback nil limit)))
3633       ;; Go to the next (or previous) button.
3634       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
3635       ;; Put point at the start of the button.
3636       (when (and backward (not (get-text-property (point) 'gnus-callback)))
3637         (goto-char (funcall function (point) 'gnus-callback nil limit)))
3638       ;; Skip past intangible buttons.
3639       (when (get-text-property (point) 'intangible)
3640         (incf n))
3641       (decf n))
3642     (unless (zerop n)
3643       (gnus-message 5 "No more buttons"))
3644     n))
3645
3646 (defun gnus-article-highlight (&optional force)
3647   "Highlight current article.
3648 This function calls `gnus-article-highlight-headers',
3649 `gnus-article-highlight-citation',
3650 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3651 do the highlighting.  See the documentation for those functions."
3652   (interactive (list 'force))
3653   (gnus-article-highlight-headers)
3654   (gnus-article-highlight-citation force)
3655   (gnus-article-highlight-signature)
3656   (gnus-article-add-buttons force)
3657   (gnus-article-add-buttons-to-head))
3658
3659 (defun gnus-article-highlight-some (&optional force)
3660   "Highlight current article.
3661 This function calls `gnus-article-highlight-headers',
3662 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3663 do the highlighting.  See the documentation for those functions."
3664   (interactive (list 'force))
3665   (gnus-article-highlight-headers)
3666   (gnus-article-highlight-signature)
3667   (gnus-article-add-buttons))
3668
3669 (defun gnus-article-highlight-headers ()
3670   "Highlight article headers as specified by `gnus-header-face-alist'."
3671   (interactive)
3672   (save-excursion
3673     (set-buffer gnus-article-buffer)
3674     (save-restriction
3675       (let ((alist gnus-header-face-alist)
3676             (buffer-read-only nil)
3677             (case-fold-search t)
3678             (inhibit-point-motion-hooks t)
3679             entry regexp header-face field-face from hpoints fpoints)
3680         (message-narrow-to-head)
3681         (while (setq entry (pop alist))
3682           (goto-char (point-min))
3683           (setq regexp (concat "^\\("
3684                                (if (string-equal "" (nth 0 entry))
3685                                    "[^\t ]"
3686                                  (nth 0 entry))
3687                                "\\)")
3688                 header-face (nth 1 entry)
3689                 field-face (nth 2 entry))
3690           (while (and (re-search-forward regexp nil t)
3691                       (not (eobp)))
3692             (beginning-of-line)
3693             (setq from (point))
3694             (unless (search-forward ":" nil t)
3695               (forward-char 1))
3696             (when (and header-face
3697                        (not (memq (point) hpoints)))
3698               (push (point) hpoints)
3699               (gnus-put-text-property from (point) 'face header-face))
3700             (when (and field-face
3701                        (not (memq (setq from (point)) fpoints)))
3702               (push from fpoints)
3703               (if (re-search-forward "^[^ \t]" nil t)
3704                   (forward-char -2)
3705                 (goto-char (point-max)))
3706               (gnus-put-text-property from (point) 'face field-face))))))))
3707
3708 (defun gnus-article-highlight-signature ()
3709   "Highlight the signature in an article.
3710 It does this by highlighting everything after
3711 `gnus-signature-separator' using `gnus-signature-face'."
3712   (interactive)
3713   (save-excursion
3714     (set-buffer gnus-article-buffer)
3715     (let ((buffer-read-only nil)
3716           (inhibit-point-motion-hooks t))
3717       (save-restriction
3718         (when (and gnus-signature-face
3719                    (gnus-article-narrow-to-signature))
3720           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3721                             'face gnus-signature-face)
3722           (widen)
3723           (gnus-article-search-signature)
3724           (let ((start (match-beginning 0))
3725                 (end (set-marker (make-marker) (1+ (match-end 0)))))
3726             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3727                                      end)))))))
3728
3729 (defun gnus-button-in-region-p (b e prop)
3730   "Say whether PROP exists in the region."
3731   (text-property-not-all b e prop nil))
3732
3733 (defun gnus-article-add-buttons (&optional force)
3734   "Find external references in the article and make buttons of them.
3735 \"External references\" are things like Message-IDs and URLs, as
3736 specified by `gnus-button-alist'."
3737   (interactive (list 'force))
3738   (save-excursion
3739     (set-buffer gnus-article-buffer)
3740     (let ((buffer-read-only nil)
3741           (inhibit-point-motion-hooks t)
3742           (case-fold-search t)
3743           (alist gnus-button-alist)
3744           beg entry regexp)
3745       ;; Remove all old markers.
3746       (let (marker entry)
3747         (while (setq marker (pop gnus-button-marker-list))
3748           (goto-char marker)
3749           (when (setq entry (gnus-button-entry))
3750             (put-text-property (match-beginning (nth 1 entry))
3751                                (match-end (nth 1 entry))
3752                                'gnus-callback nil))
3753           (set-marker marker nil)))
3754       ;; We skip the headers.
3755       (article-goto-body)
3756       (setq beg (point))
3757       (while (setq entry (pop alist))
3758         (setq regexp (car entry))
3759         (goto-char beg)
3760         (while (re-search-forward regexp nil t)
3761           (let* ((start (and entry (match-beginning (nth 1 entry))))
3762                  (end (and entry (match-end (nth 1 entry))))
3763                  (from (match-beginning 0)))
3764             (when (and (or (eq t (nth 2 entry))
3765                            (eval (nth 2 entry)))
3766                        (not (gnus-button-in-region-p
3767                              start end 'gnus-callback)))
3768               ;; That optional form returned non-nil, so we add the
3769               ;; button.
3770               (gnus-article-add-button
3771                start end 'gnus-button-push
3772                (car (push (set-marker (make-marker) from)
3773                           gnus-button-marker-list))))))))))
3774
3775 ;; Add buttons to the head of an article.
3776 (defun gnus-article-add-buttons-to-head ()
3777   "Add buttons to the head of the article."
3778   (interactive)
3779   (save-excursion
3780     (set-buffer gnus-article-buffer)
3781     (let ((buffer-read-only nil)
3782           (inhibit-point-motion-hooks t)
3783           (case-fold-search t)
3784           (alist gnus-header-button-alist)
3785           entry beg end)
3786       (nnheader-narrow-to-headers)
3787       (while alist
3788         ;; Each alist entry.
3789         (setq entry (car alist)
3790               alist (cdr alist))
3791         (goto-char (point-min))
3792         (while (re-search-forward (car entry) nil t)
3793           ;; Each header matching the entry.
3794           (setq beg (match-beginning 0))
3795           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3796                              (match-beginning 0))
3797                         (point-max)))
3798           (goto-char beg)
3799           (while (re-search-forward (nth 1 entry) end t)
3800             ;; Each match within a header.
3801             (let* ((entry (cdr entry))
3802                    (start (match-beginning (nth 1 entry)))
3803                    (end (match-end (nth 1 entry)))
3804                    (form (nth 2 entry)))
3805               (goto-char (match-end 0))
3806               (when (eval form)
3807                 (gnus-article-add-button
3808                  start end (nth 3 entry)
3809                  (buffer-substring (match-beginning (nth 4 entry))
3810                                    (match-end (nth 4 entry)))))))
3811           (goto-char end))))
3812     (widen)))
3813
3814 ;;; External functions:
3815
3816 (defun gnus-article-add-button (from to fun &optional data)
3817   "Create a button between FROM and TO with callback FUN and data DATA."
3818   (when gnus-article-button-face
3819     (gnus-overlay-put (gnus-make-overlay from to)
3820                       'face gnus-article-button-face))
3821   (gnus-add-text-properties
3822    from to
3823    (nconc (and gnus-article-mouse-face
3824                (list gnus-mouse-face-prop gnus-article-mouse-face))
3825           (list 'gnus-callback fun)
3826           (and data (list 'gnus-data data)))))
3827
3828 ;;; Internal functions:
3829
3830 (defun gnus-article-set-globals ()
3831   (save-excursion
3832     (set-buffer gnus-summary-buffer)
3833     (gnus-set-global-variables)))
3834
3835 (defun gnus-signature-toggle (end)
3836   (save-excursion
3837     (set-buffer gnus-article-buffer)
3838     (let ((buffer-read-only nil)
3839           (inhibit-point-motion-hooks t))
3840       (if (get-text-property end 'invisible)
3841           (gnus-article-unhide-text end (point-max))
3842         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3843
3844 (defun gnus-button-entry ()
3845   ;; Return the first entry in `gnus-button-alist' matching this place.
3846   (let ((alist gnus-button-alist)
3847         (entry nil))
3848     (while alist
3849       (setq entry (pop alist))
3850       (if (looking-at (car entry))
3851           (setq alist nil)
3852         (setq entry nil)))
3853     entry))
3854
3855 (defun gnus-button-push (marker)
3856   ;; Push button starting at MARKER.
3857   (save-excursion
3858     (goto-char marker)
3859     (let* ((entry (gnus-button-entry))
3860            (inhibit-point-motion-hooks t)
3861            (fun (nth 3 entry))
3862            (args (mapcar (lambda (group)
3863                            (let ((string (match-string group)))
3864                              (gnus-set-text-properties
3865                               0 (length string) nil string)
3866                              string))
3867                          (nthcdr 4 entry))))
3868       (cond
3869        ((fboundp fun)
3870         (apply fun args))
3871        ((and (boundp fun)
3872              (fboundp (symbol-value fun)))
3873         (apply (symbol-value fun) args))
3874        (t
3875         (gnus-message 1 "You must define `%S' to use this button"
3876                       (cons fun args)))))))
3877
3878 (defun gnus-button-message-id (message-id)
3879   "Fetch MESSAGE-ID."
3880   (save-excursion
3881     (set-buffer gnus-summary-buffer)
3882     (gnus-summary-refer-article message-id)))
3883
3884 (defun gnus-button-fetch-group (address)
3885   "Fetch GROUP specified by ADDRESS."
3886   (if (not (string-match "[:/]" address))
3887       ;; This is just a simple group url.
3888       (gnus-group-read-ephemeral-group address gnus-select-method)
3889     (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3890                            address))
3891         (error "Can't parse %s" address)
3892       (gnus-group-read-ephemeral-group
3893        (match-string 4 address)
3894        `(nntp ,(match-string 1 address)
3895               (nntp-address ,(match-string 1 address))
3896               (nntp-port-number ,(if (match-end 3)
3897                                      (match-string 3 address)
3898                                    "nntp")))))))
3899
3900 (defun gnus-url-parse-query-string (query &optional downcase)
3901   (let (retval pairs cur key val)
3902     (setq pairs (split-string query "&"))
3903     (while pairs
3904       (setq cur (car pairs)
3905             pairs (cdr pairs))
3906       (if (not (string-match "=" cur))
3907           nil                           ; Grace
3908         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3909               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3910         (if downcase
3911             (setq key (downcase key)))
3912         (setq cur (assoc key retval))
3913         (if cur
3914             (setcdr cur (cons val (cdr cur)))
3915           (setq retval (cons (list key val) retval)))))
3916     retval))
3917
3918 (defun gnus-url-unhex (x)
3919   (if (> x ?9)
3920       (if (>= x ?a)
3921           (+ 10 (- x ?a))
3922         (+ 10 (- x ?A)))
3923     (- x ?0)))
3924
3925 (defun gnus-url-unhex-string (str &optional allow-newlines)
3926   "Remove %XXX embedded spaces, etc in a url.
3927 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3928 decoding of carriage returns and line feeds in the string, which is normally
3929 forbidden in URL encoding."
3930   (setq str (or str ""))
3931   (let ((tmp "")
3932         (case-fold-search t))
3933     (while (string-match "%[0-9a-f][0-9a-f]" str)
3934       (let* ((start (match-beginning 0))
3935              (ch1 (gnus-url-unhex (elt str (+ start 1))))
3936              (code (+ (* 16 ch1)
3937                       (gnus-url-unhex (elt str (+ start 2))))))
3938         (setq tmp (concat
3939                    tmp (substring str 0 start)
3940                    (cond
3941                     (allow-newlines
3942                      (char-to-string code))
3943                     ((or (= code ?\n) (= code ?\r))
3944                      " ")
3945                     (t (char-to-string code))))
3946               str (substring str (match-end 0)))))
3947     (setq tmp (concat tmp str))
3948     tmp))
3949
3950 (defun gnus-url-mailto (url)
3951   ;; Send mail to someone
3952   (when (string-match "mailto:/*\\(.*\\)" url)
3953     (setq url (substring url (match-beginning 1) nil)))
3954   (let (to args subject func)
3955     (if (string-match (regexp-quote "?") url)
3956         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3957               args (gnus-url-parse-query-string
3958                     (substring url (match-end 0) nil) t))
3959       (setq to (gnus-url-unhex-string url)))
3960     (setq args (cons (list "to" to) args)
3961           subject (cdr-safe (assoc "subject" args)))
3962     (gnus-setup-message 'reply
3963       (message-mail)
3964       (while args
3965         (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3966         (if (fboundp func)
3967             (funcall func)
3968           (message-position-on-field (caar args)))
3969         (insert (mapconcat 'identity (cdar args) ", "))
3970         (setq args (cdr args)))
3971       (if subject
3972           (message-goto-body)
3973         (message-goto-subject)))))
3974
3975 (defun gnus-button-mailto (address)
3976   ;; Mail to ADDRESS.
3977   (set-buffer (gnus-copy-article-buffer))
3978   (gnus-setup-message 'reply
3979     (message-reply address)))
3980
3981 (defun gnus-button-reply (address)
3982   ;; Reply to ADDRESS.
3983   (gnus-setup-message 'reply
3984     (message-reply address)))
3985
3986 (defun gnus-button-url (address)
3987   "Browse ADDRESS."
3988   ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3989   (if (listp browse-url-browser-function)
3990       (browse-url address)
3991     (funcall browse-url-browser-function address)))
3992
3993 (defun gnus-button-embedded-url (address)
3994   "Browse ADDRESS."
3995   ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3996   (if (listp browse-url-browser-function)
3997       (browse-url (gnus-strip-whitespace address))
3998     (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3999
4000 ;;; Next/prev buttons in the article buffer.
4001
4002 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4003 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4004
4005 (defvar gnus-prev-page-map nil)
4006 (unless gnus-prev-page-map
4007   (setq gnus-prev-page-map (make-sparse-keymap))
4008   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4009   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4010
4011 (defun gnus-insert-prev-page-button ()
4012   (let ((buffer-read-only nil))
4013     (gnus-eval-format
4014      gnus-prev-page-line-format nil
4015      `(gnus-prev t local-map ,gnus-prev-page-map
4016                  gnus-callback gnus-article-button-prev-page
4017                  article-type annotation))))
4018
4019 (defvar gnus-next-page-map nil)
4020 (unless gnus-next-page-map
4021   (setq gnus-next-page-map (make-keymap))
4022   (suppress-keymap gnus-prev-page-map)
4023   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4024   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4025
4026 (defun gnus-button-next-page ()
4027   "Go to the next page."
4028   (interactive)
4029   (let ((win (selected-window)))
4030     (select-window (get-buffer-window gnus-article-buffer t))
4031     (gnus-article-next-page)
4032     (select-window win)))
4033
4034 (defun gnus-button-prev-page ()
4035   "Go to the prev page."
4036   (interactive)
4037   (let ((win (selected-window)))
4038     (select-window (get-buffer-window gnus-article-buffer t))
4039     (gnus-article-prev-page)
4040     (select-window win)))
4041
4042 (defun gnus-insert-next-page-button ()
4043   (let ((buffer-read-only nil))
4044     (gnus-eval-format gnus-next-page-line-format nil
4045                       `(gnus-next
4046                         t local-map ,gnus-next-page-map
4047                         gnus-callback gnus-article-button-next-page
4048                         article-type annotation))))
4049
4050 (defun gnus-article-button-next-page (arg)
4051   "Go to the next page."
4052   (interactive "P")
4053   (let ((win (selected-window)))
4054     (select-window (get-buffer-window gnus-article-buffer t))
4055     (gnus-article-next-page)
4056     (select-window win)))
4057
4058 (defun gnus-article-button-prev-page (arg)
4059   "Go to the prev page."
4060   (interactive "P")
4061   (let ((win (selected-window)))
4062     (select-window (get-buffer-window gnus-article-buffer t))
4063     (gnus-article-prev-page)
4064     (select-window win)))
4065
4066 (defvar gnus-decode-header-methods
4067   '(gnus-decode-with-mail-decode-encoded-word-region)
4068   "List of methods used to decode headers
4069
4070 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4071 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4072 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4073 whose names match REGEXP.
4074
4075 For example:
4076 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4077  mail-decode-encoded-word-region
4078  (\"chinese\" . rfc1843-decode-region))
4079 ")
4080
4081 (defvar gnus-decode-header-methods-cache nil)
4082
4083 (defun gnus-decode-with-mail-decode-encoded-word-region (start end)
4084   (let ((rfc2047-default-charset gnus-default-charset))
4085     (mail-decode-encoded-word-region start end)))
4086
4087 (defun gnus-multi-decode-header (start end)
4088   "Apply the functions from `gnus-encoded-word-methods' that match."
4089   (unless (and gnus-decode-header-methods-cache
4090                (eq gnus-newsgroup-name
4091                    (car gnus-decode-header-methods-cache)))
4092     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4093     (mapc '(lambda (x)
4094              (if (symbolp x)
4095                  (nconc gnus-decode-header-methods-cache (list x))
4096                (if (and gnus-newsgroup-name
4097                         (string-match (car x) gnus-newsgroup-name))
4098                    (nconc gnus-decode-header-methods-cache
4099                           (list (cdr x))))))
4100           gnus-decode-header-methods))
4101   (let ((xlist gnus-decode-header-methods-cache))
4102     (pop xlist)
4103     (save-restriction
4104       (narrow-to-region start end)
4105       (while xlist
4106         (funcall (pop xlist) (point-min) (point-max))))))
4107
4108
4109 ;;; @ for mime-view
4110 ;;;
4111
4112 (defun gnus-article-header-presentation-method (entity situation)
4113   (mime-insert-header entity)
4114   )
4115
4116 (set-alist 'mime-header-presentation-method-alist
4117            'gnus-original-article-mode
4118            #'gnus-article-header-presentation-method)
4119
4120 (defun gnus-mime-preview-quitting-method ()
4121   (if gnus-show-mime
4122       (gnus-article-show-summary)
4123     (mime-preview-kill-buffer)
4124     (delete-other-windows)
4125     (gnus-article-show-summary)
4126     (gnus-summary-select-article nil t)
4127     ))
4128
4129 (set-alist 'mime-preview-quitting-method-alist
4130            'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
4131
4132 (defun gnus-following-method (buf)
4133   (set-buffer buf)
4134   (message-followup)
4135   (message-yank-original)
4136   (kill-buffer buf)
4137   (goto-char (point-min))
4138   )
4139
4140 (set-alist 'mime-preview-following-method-alist
4141            'gnus-original-article-mode #'gnus-following-method)
4142
4143
4144 ;;; @ end
4145 ;;;
4146
4147 (gnus-ems-redefine)
4148
4149 (provide 'gnus-art)
4150
4151 (run-hooks 'gnus-art-load-hook)
4152
4153 ;;; gnus-art.el ends here