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