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