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