*** empty log message ***
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'custom)
29 (require 'gnus)
30 (require 'gnus-sum)
31 (require 'gnus-spec)
32 (require 'gnus-int)
33 (require 'browse-url)
34
35 (defgroup gnus-article nil
36   "Article display."
37   :link '(custom-manual "(gnus)The Article Buffer")
38   :group 'gnus)
39
40 (defgroup gnus-article-hiding nil
41   "Hiding article parts."
42   :link '(custom-manual "(gnus)Article Hiding")
43   :group 'gnus-article)
44
45 (defgroup gnus-article-highlight nil
46   "Article highlighting."
47   :link '(custom-manual "(gnus)Article Highlighting")
48   :group 'gnus-article
49   :group 'gnus-visual)
50
51 (defgroup gnus-article-signature nil
52   "Article signatures."
53   :link '(custom-manual "(gnus)Article Signature")
54   :group 'gnus-article)
55
56 (defgroup gnus-article-headers nil
57   "Article headers."
58   :link '(custom-manual "(gnus)Hiding Headers")
59   :group 'gnus-article)
60
61 (defgroup gnus-article-washing nil
62   "Special commands on articles."
63   :link '(custom-manual "(gnus)Article Washing")
64   :group 'gnus-article)
65
66 (defgroup gnus-article-emphasis nil
67   "Fontisizing articles."
68   :link '(custom-manual "(gnus)Article Fontisizing")
69   :group 'gnus-article)
70
71 (defgroup gnus-article-saving nil
72   "Saving articles."
73   :link '(custom-manual "(gnus)Saving Articles")
74   :group 'gnus-article)
75
76 (defgroup gnus-article-mime nil
77   "Worshiping the MIME wonder."
78   :link '(custom-manual "(gnus)Using MIME")
79   :group 'gnus-article)
80
81 (defgroup gnus-article-buttons nil
82   "Pushable buttons in the article buffer."
83   :link '(custom-manual "(gnus)Article Buttons")
84   :group 'gnus-article)
85
86 (defgroup gnus-article-various nil
87   "Other article options."
88   :link '(custom-manual "(gnus)Misc Article")
89   :group 'gnus-article)
90
91 (defcustom gnus-ignored-headers
92   '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
93     "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
94     "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
95     "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
96   "All headers that match this regexp will be hidden.
97 This variable can also be a list of regexps of headers to be ignored.
98 If `gnus-visible-headers' is non-nil, this variable will be ignored."
99   :type '(choice :custom-show nil
100                  regexp
101                  (repeat regexp))
102   :group 'gnus-article-hiding)
103
104 (defcustom gnus-visible-headers
105   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From"
106   "All headers that do not match this regexp will be hidden.
107 This variable can also be a list of regexp of headers to remain visible.
108 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
109   :type '(repeat :value-to-internal (lambda (widget value)
110                                       (custom-split-regexp-maybe value))
111                  :match (lambda (widget value)
112                           (or (stringp value)
113                               (widget-editable-list-match widget value)))
114                  regexp)
115   :group 'gnus-article-hiding)
116
117 (defcustom gnus-sorted-header-list
118   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
119     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
120   "This variable is a list of regular expressions.
121 If it is non-nil, headers that match the regular expressions will
122 be placed first in the article buffer in the sequence specified by
123 this list."
124   :type '(repeat regexp)
125   :group 'gnus-article-hiding)
126
127 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
128   "Headers that are only to be displayed if they have interesting data.
129 Possible values in this list are `empty', `newsgroups', `followup-to',
130 `reply-to', and `date'."
131   :type '(set (const :tag "Headers with no content." empty)
132               (const :tag "Newsgroups with only one group." newsgroups)
133               (const :tag "Followup-to identical to newsgroups." followup-to)
134               (const :tag "Reply-to identical to from." reply-to)
135               (const :tag "Date less than four days old." date))
136   :group 'gnus-article-hiding)
137
138 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
139   "Regexp matching signature separator.
140 This can also be a list of regexps.  In that case, it will be checked
141 from head to tail looking for a separator.  Searches will be done from
142 the end of the buffer."
143   :type '(repeat string)
144   :group 'gnus-article-signature)
145
146 (defcustom gnus-signature-limit nil
147    "Provide a limit to what is considered a signature.
148 If it is a number, no signature may not be longer (in characters) than
149 that number.  If it is a floating point number, no signature may be
150 longer (in lines) than that number.  If it is a function, the function
151 will be called without any parameters, and if it returns nil, there is
152 no signature in the buffer.  If it is a string, it will be used as a
153 regexp.  If it matches, the text in question is not a signature."
154   :type '(choice integer number function regexp)
155   :group 'gnus-article-signature)
156
157 (defcustom gnus-hidden-properties '(invisible t intangible t)
158   "Property list to use for hiding text."
159   :type 'sexp
160   :group 'gnus-article-hiding)
161
162 (defcustom gnus-article-x-face-command
163   "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
164   "String or function to be executed to display an X-Face header.
165 If it is a string, the command will be executed in a sub-shell
166 asynchronously.  The compressed face will be piped to this command."
167   :type 'string                         ;Leave function case to Lisp.
168   :group 'gnus-article-washing)
169
170 (defcustom gnus-article-x-face-too-ugly nil
171   "Regexp matching posters whose face shouldn't be shown automatically."
172   :type 'regexp
173   :group 'gnus-article-washing)
174
175 (defcustom gnus-emphasis-alist
176   (let ((format
177          "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
178         (types
179          '(("_" "_" underline)
180            ("/" "/" italic)
181            ("\\*" "\\*" bold)
182            ("_/" "/_" underline-italic)
183            ("_\\*" "\\*_" underline-bold)
184            ("\\*/" "/\\*" bold-italic)
185            ("_\\*/" "/\\*_" underline-bold-italic))))
186     `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
187        2 3 gnus-emphasis-underline)
188       ,@(mapcar
189          (lambda (spec)
190            (list
191             (format format (car spec) (cadr spec))
192             2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
193          types)))
194   "Alist that says how to fontify certain phrases.
195 Each item looks like this:
196
197   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
198
199 The first element is a regular expression to be matched.  The second
200 is a number that says what regular expression grouping used to find
201 the entire emphasized word.  The third is a number that says what
202 regexp grouping should be displayed and highlighted.  The fourth
203 is the face used for highlighting."
204   :type '(repeat (list :value ("" 0 0 default)
205                        regexp
206                        (integer :tag "Match group")
207                        (integer :tag "Emphasize group")
208                        face))
209   :group 'gnus-article-emphasis)
210
211 (defface gnus-emphasis-bold '((t (:bold t)))
212   "Face used for displaying strong emphasized text (*word*)."
213   :group 'gnus-article-emphasis)
214
215 (defface gnus-emphasis-italic '((t (:italic t)))
216   "Face used for displaying italic emphasized text (/word/)."
217   :group 'gnus-article-emphasis)
218
219 (defface gnus-emphasis-underline '((t (:underline t)))
220   "Face used for displaying underlined emphasized text (_word_)."
221   :group 'gnus-article-emphasis)
222
223 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
224   "Face used for displaying underlined bold emphasized text (_*word*_)."
225   :group 'gnus-article-emphasis)
226
227 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
228   "Face used for displaying underlined italic emphasized text (_*word*_)."
229   :group 'gnus-article-emphasis)
230
231 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
232   "Face used for displaying bold italic emphasized text (/*word*/)."
233   :group 'gnus-article-emphasis)
234
235 (defface gnus-emphasis-underline-bold-italic
236   '((t (:bold t :italic t :underline t)))
237   "Face used for displaying underlined bold italic emphasized text.
238 Esample: (_/*word*/_)."
239   :group 'gnus-article-emphasis)
240
241 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
242   "Format for display of Date headers in article bodies.
243 See `format-time-zone' for the possible values."
244   :type 'string
245   :link '(custom-manual "(gnus)Article Date")
246   :group 'gnus-article-washing)
247
248 (eval-and-compile
249   (autoload 'hexl-hex-string-to-integer "hexl")
250   (autoload 'timezone-make-date-arpa-standard "timezone")
251   (autoload 'mail-extract-address-components "mail-extr"))
252
253 (defcustom gnus-save-all-headers t
254   "*If non-nil, don't remove any headers before saving."
255   :group 'gnus-article-saving
256   :type 'boolean)
257
258 (defcustom gnus-prompt-before-saving 'always
259   "*This variable says how much prompting is to be done when saving articles.
260 If it is nil, no prompting will be done, and the articles will be
261 saved to the default files.  If this variable is `always', each and
262 every article that is saved will be preceded by a prompt, even when
263 saving large batches of articles.  If this variable is neither nil not
264 `always', there the user will be prompted once for a file name for
265 each invocation of the saving commands."
266   :group 'gnus-article-saving
267   :type '(choice (item always)
268                  (item :tag "never" nil)
269                  (sexp :tag "once" :format "%t")))
270
271 (defcustom gnus-saved-headers gnus-visible-headers
272   "Headers to keep if `gnus-save-all-headers' is nil.
273 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
274 If that variable is nil, however, all headers that match this regexp
275 will be kept while the rest will be deleted before saving."
276   :group 'gnus-article-saving
277   :type '(repeat string))
278
279 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
280   "A function to save articles in your favourite format.
281 The function must be interactively callable (in other words, it must
282 be an Emacs command).
283
284 Gnus provides the following functions:
285
286 * gnus-summary-save-in-rmail (Rmail format)
287 * gnus-summary-save-in-mail (Unix mail format)
288 * gnus-summary-save-in-folder (MH folder)
289 * gnus-summary-save-in-file (article format)
290 * gnus-summary-save-in-vm (use VM's folder format)
291 * gnus-summary-write-to-file (article format -- overwrite)."
292   :group 'gnus-article-saving
293   :type '(radio (function-item gnus-summary-save-in-rmail)
294                 (function-item gnus-summary-save-in-mail)
295                 (function-item gnus-summary-save-in-folder)
296                 (function-item gnus-summary-save-in-file)
297                 (function-item gnus-summary-save-in-vm)
298                 (function-item gnus-summary-write-to-file)))
299
300 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
301   "A function generating a file name to save articles in Rmail format.
302 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
303   :group 'gnus-article-saving
304   :type 'function)
305
306 (defcustom gnus-mail-save-name 'gnus-plain-save-name
307   "A function generating a file name to save articles in Unix mail format.
308 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
309   :group 'gnus-article-saving
310   :type 'function)
311
312 (defcustom gnus-folder-save-name 'gnus-folder-save-name
313   "A function generating a file name to save articles in MH folder.
314 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
315   :group 'gnus-article-saving
316   :type 'function)
317
318 (defcustom gnus-file-save-name 'gnus-numeric-save-name
319   "A function generating a file name to save articles in article format.
320 The function is called with NEWSGROUP, HEADERS, and optional
321 LAST-FILE."
322   :group 'gnus-article-saving
323   :type 'function)
324
325 (defcustom gnus-split-methods
326   '((gnus-article-archive-name)
327     (gnus-article-nndoc-name))
328   "Variable used to suggest where articles are to be saved.
329 For instance, if you would like to save articles related to Gnus in
330 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
331 you could set this variable to something like:
332
333  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
334    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
335
336 This variable is an alist where the where the key is the match and the
337 value is a list of possible files to save in if the match is non-nil.
338
339 If the match is a string, it is used as a regexp match on the
340 article.  If the match is a symbol, that symbol will be funcalled
341 from the buffer of the article to be saved with the newsgroup as the
342 parameter.  If it is a list, it will be evaled in the same buffer.
343
344 If this form or function returns a string, this string will be used as
345 a possible file name; and if it returns a non-nil list, that list will
346 be used as possible file names."
347   :group 'gnus-article-saving
348   :type '(repeat (choice (list function)
349                          (cons regexp (repeat string))
350                          sexp)))
351
352 (defcustom gnus-strict-mime t
353   "*If nil, MIME-decode even if there is no Mime-Version header."
354   :group 'gnus-article-mime
355   :type 'boolean)
356
357 (defcustom gnus-show-mime-method 'metamail-buffer
358   "Function to process a MIME message.
359 The function is called from the article buffer."
360   :group 'gnus-article-mime
361   :type 'function)
362
363 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
364   "*Function to decode MIME encoded words.
365 The function is called from the article buffer."
366   :group 'gnus-article-mime
367   :type 'function)
368
369 (defcustom gnus-page-delimiter "^\^L"
370   "*Regexp describing what to use as article page delimiters.
371 The default value is \"^\^L\", which is a form linefeed at the
372 beginning of a line."
373   :type 'regexp
374   :group 'gnus-article-various)
375
376 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
377   "*The format specification for the article mode line.
378 See `gnus-summary-mode-line-format' for a closer description."
379   :type 'string
380   :group 'gnus-article-various)
381
382 (defcustom gnus-article-mode-hook nil
383   "*A hook for Gnus article mode."
384   :type 'hook
385   :group 'gnus-article-various)
386
387 (defcustom gnus-article-menu-hook nil
388   "*Hook run after the creation of the article mode menu."
389   :type 'hook
390   :group 'gnus-article-various)
391
392 (defcustom gnus-article-prepare-hook nil
393   "*A hook called after an article has been prepared in the article buffer.
394 If you want to run a special decoding program like nkf, use this hook."
395   :type 'hook
396   :group 'gnus-article-various)
397
398 (defcustom gnus-article-button-face 'bold
399   "Face used for highlighting buttons in the article buffer.
400
401 An article button is a piece of text that you can activate by pressing
402 `RET' or `mouse-2' above it."
403   :type 'face
404   :group 'gnus-article-buttons)
405
406 (defcustom gnus-article-mouse-face 'highlight
407   "Face used for mouse highlighting in the article buffer.
408
409 Article buttons will be displayed in this face when the cursor is
410 above them."
411   :type 'face
412   :group 'gnus-article-buttons)
413
414 (defcustom gnus-signature-face 'italic
415   "Face used for highlighting a signature in the article buffer."
416   :type 'face
417   :group 'gnus-article-highlight
418   :group 'gnus-article-signature)
419
420 (defface gnus-header-from-face
421   '((((class color)
422       (background dark))
423      (:foreground "spring green" :bold t))
424     (((class color)
425       (background light))
426      (:foreground "red3" :bold t))
427     (t
428      (:bold t :italic t)))
429   "Face used for displaying from headers."
430   :group 'gnus-article-headers
431   :group 'gnus-article-highlight)
432
433 (defface gnus-header-subject-face
434   '((((class color)
435       (background dark))
436      (:foreground "SeaGreen3" :bold t))
437     (((class color)
438       (background light))
439      (:foreground "red4" :bold t))
440     (t
441      (:bold t :italic t)))
442   "Face used for displaying subject headers."
443   :group 'gnus-article-headers
444   :group 'gnus-article-highlight)
445
446 (defface gnus-header-newsgroups-face
447   '((((class color)
448       (background dark))
449      (:foreground "yellow" :bold t :italic t))
450     (((class color)
451       (background light))
452      (:foreground "MidnightBlue" :bold t :italic t))
453     (t
454      (:bold t :italic t)))
455   "Face used for displaying newsgroups headers."
456   :group 'gnus-article-headers
457   :group 'gnus-article-highlight)
458
459 (defface gnus-header-name-face
460   '((((class color)
461       (background dark))
462      (:foreground "SeaGreen"))
463     (((class color)
464       (background light))
465      (:foreground "maroon"))
466     (t
467      (:bold t)))
468   "Face used for displaying header names."
469   :group 'gnus-article-headers
470   :group 'gnus-article-highlight)
471
472 (defface gnus-header-content-face
473   '((((class color)
474       (background dark))
475      (:foreground "forest green" :italic t))
476     (((class color)
477       (background light))
478      (:foreground "indianred4" :italic t))
479     (t
480      (:italic t)))  "Face used for displaying header content."
481   :group 'gnus-article-headers
482   :group 'gnus-article-highlight)
483
484 (defcustom gnus-header-face-alist
485   '(("From" nil gnus-header-from-face)
486     ("Subject" nil gnus-header-subject-face)
487     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
488     ("" gnus-header-name-face gnus-header-content-face))
489   "Controls highlighting of article header.
490
491 An alist of the form (HEADER NAME CONTENT).
492
493 HEADER is a regular expression which should match the name of an
494 header header and NAME and CONTENT are either face names or nil.
495
496 The name of each header field will be displayed using the face
497 specified by the first element in the list where HEADER match the
498 header name and NAME is non-nil.  Similarly, the content will be
499 displayed by the first non-nil matching CONTENT face."
500   :group 'gnus-article-headers
501   :group 'gnus-article-highlight
502   :type '(repeat (list (regexp :tag "Header")
503                        (choice :tag "Name"
504                                (item :tag "skip" nil)
505                                (face :value default))
506                        (choice :tag "Content"
507                                (item :tag "skip" nil)
508                                (face :value default)))))
509
510 ;;; Internal variables
511
512 (defvar gnus-article-mode-syntax-table
513   (let ((table (copy-syntax-table text-mode-syntax-table)))
514     (modify-syntax-entry ?- "w" table)
515     (modify-syntax-entry ?> ")" table)
516     (modify-syntax-entry ?< "(" table)
517     table)
518   "Syntax table used in article mode buffers.
519 Initialized from `text-mode-syntax-table.")
520
521 (defvar gnus-save-article-buffer nil)
522
523 (defvar gnus-article-mode-line-format-alist
524     (nconc '((?w (gnus-article-wash-status) ?s))
525            gnus-summary-mode-line-format-alist))
526
527 (defvar gnus-number-of-articles-to-be-saved nil)
528
529 (defvar gnus-inhibit-hiding nil)
530 (defvar gnus-newsgroup-name)
531
532 (defsubst gnus-article-hide-text (b e props)
533   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
534   (add-text-properties b e props)
535   (when (memq 'intangible props)
536     (put-text-property
537      (max (1- b) (point-min))
538      b 'intangible (cddr (memq 'intangible props)))))
539
540 (defsubst gnus-article-unhide-text (b e)
541   "Remove hidden text properties from region between B and E."
542   (remove-text-properties b e gnus-hidden-properties)
543   (when (memq 'intangible gnus-hidden-properties)
544     (put-text-property (max (1- b) (point-min))
545                        b 'intangible nil)))
546
547 (defun gnus-article-hide-text-type (b e type)
548   "Hide text of TYPE between B and E."
549   (gnus-article-hide-text
550    b e (cons 'article-type (cons type gnus-hidden-properties))))
551
552 (defun gnus-article-unhide-text-type (b e type)
553   "Hide text of TYPE between B and E."
554   (remove-text-properties
555    b e (cons 'article-type (cons type gnus-hidden-properties)))
556   (when (memq 'intangible gnus-hidden-properties)
557     (put-text-property (max (1- b) (point-min))
558                        b 'intangible nil)))
559
560 (defun gnus-article-hide-text-of-type (type)
561   "Hide text of TYPE in the current buffer."
562   (save-excursion
563     (let ((b (point-min))
564           (e (point-max)))
565       (while (setq b (text-property-any b e 'article-type type))
566         (add-text-properties b (incf b) gnus-hidden-properties)))))
567
568 (defun gnus-article-delete-text-of-type (type)
569   "Delete text of TYPE in the current buffer."
570   (save-excursion
571     (let ((b (point-min)))
572       (while (setq b (text-property-any b (point-max) 'article-type type))
573         (delete-region b (incf b))))))
574
575 (defun gnus-article-delete-invisible-text ()
576   "Delete all invisible text in the current buffer."
577   (save-excursion
578     (let ((b (point-min)))
579       (while (setq b (text-property-any b (point-max) 'invisible t))
580         (delete-region b (incf b))))))
581
582 (defun gnus-article-text-type-exists-p (type)
583   "Say whether any text of type TYPE exists in the buffer."
584   (text-property-any (point-min) (point-max) 'article-type type))
585
586 (defsubst gnus-article-header-rank ()
587   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
588   (let ((list gnus-sorted-header-list)
589         (i 0))
590     (while list
591       (when (looking-at (car list))
592         (setq list nil))
593       (setq list (cdr list))
594       (incf i))
595     i))
596
597 (defun article-hide-headers (&optional arg delete)
598   "Toggle whether to hide unwanted headers and possibly sort them as well.
599 If given a negative prefix, always show; if given a positive prefix,
600 always hide."
601   (interactive (gnus-article-hidden-arg))
602   (if (gnus-article-check-hidden-text 'headers arg)
603       ;; Show boring headers as well.
604       (gnus-article-show-hidden-text 'boring-headers)
605     ;; This function might be inhibited.
606     (unless gnus-inhibit-hiding
607       (save-excursion
608         (save-restriction
609           (let ((buffer-read-only nil)
610                 (props (nconc (list 'article-type 'headers)
611                               gnus-hidden-properties))
612                 (max (1+ (length gnus-sorted-header-list)))
613                 (ignored (when (not gnus-visible-headers)
614                            (cond ((stringp gnus-ignored-headers)
615                                   gnus-ignored-headers)
616                                  ((listp gnus-ignored-headers)
617                                   (mapconcat 'identity gnus-ignored-headers
618                                              "\\|")))))
619                 (visible
620                  (cond ((stringp gnus-visible-headers)
621                         gnus-visible-headers)
622                        ((and gnus-visible-headers
623                              (listp gnus-visible-headers))
624                         (mapconcat 'identity gnus-visible-headers "\\|"))))
625                 (inhibit-point-motion-hooks t)
626                 want-list beg)
627             ;; First we narrow to just the headers.
628             (widen)
629             (goto-char (point-min))
630             ;; Hide any "From " lines at the beginning of (mail) articles.
631             (while (looking-at "From ")
632               (forward-line 1))
633             (unless (bobp)
634               (if delete
635                   (delete-region (point-min) (point))
636                 (gnus-article-hide-text (point-min) (point) props)))
637             ;; Then treat the rest of the header lines.
638             (narrow-to-region
639              (point)
640              (if (search-forward "\n\n" nil t) ; if there's a body
641                  (progn (forward-line -1) (point))
642                (point-max)))
643             ;; Then we use the two regular expressions
644             ;; `gnus-ignored-headers' and `gnus-visible-headers' to
645             ;; select which header lines is to remain visible in the
646             ;; article buffer.
647             (goto-char (point-min))
648             (while (re-search-forward "^[^ \t]*:" nil t)
649               (beginning-of-line)
650               ;; Mark the rank of the header.
651               (put-text-property
652                (point) (1+ (point)) 'message-rank
653                (if (or (and visible (looking-at visible))
654                        (and ignored
655                             (not (looking-at ignored))))
656                    (gnus-article-header-rank)
657                  (+ 2 max)))
658               (forward-line 1))
659             (message-sort-headers-1)
660             (when (setq beg (text-property-any
661                              (point-min) (point-max) 'message-rank (+ 2 max)))
662               ;; We make the unwanted headers invisible.
663               (if delete
664                   (delete-region beg (point-max))
665                 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
666                 (gnus-article-hide-text-type beg (point-max) 'headers))
667               ;; Work around XEmacs lossage.
668               (put-text-property (point-min) beg 'invisible nil))))))))
669
670 (defun article-hide-boring-headers (&optional arg)
671   "Toggle hiding of headers that aren't very interesting.
672 If given a negative prefix, always show; if given a positive prefix,
673 always hide."
674   (interactive (gnus-article-hidden-arg))
675   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
676              (not gnus-show-all-headers))
677     (save-excursion
678       (save-restriction
679         (let ((buffer-read-only nil)
680               (list gnus-boring-article-headers)
681               (inhibit-point-motion-hooks t)
682               elem)
683           (nnheader-narrow-to-headers)
684           (while list
685             (setq elem (pop list))
686             (goto-char (point-min))
687             (cond
688              ;; Hide empty headers.
689              ((eq elem 'empty)
690               (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
691                 (forward-line -1)
692                 (gnus-article-hide-text-type
693                  (progn (beginning-of-line) (point))
694                  (progn
695                    (end-of-line)
696                    (if (re-search-forward "^[^ \t]" nil t)
697                        (match-beginning 0)
698                      (point-max)))
699                  'boring-headers)))
700              ;; Hide boring Newsgroups header.
701              ((eq elem 'newsgroups)
702               (when (equal (gnus-fetch-field "newsgroups")
703                            (gnus-group-real-name
704                             (if (boundp 'gnus-newsgroup-name)
705                                 gnus-newsgroup-name
706                               "")))
707                 (gnus-article-hide-header "newsgroups")))
708              ((eq elem 'followup-to)
709               (when (equal (message-fetch-field "followup-to")
710                            (message-fetch-field "newsgroups"))
711                 (gnus-article-hide-header "followup-to")))
712              ((eq elem 'reply-to)
713               (let ((from (message-fetch-field "from"))
714                     (reply-to (message-fetch-field "reply-to")))
715                 (when (and
716                        from reply-to
717                        (ignore-errors
718                          (equal
719                           (nth 1 (mail-extract-address-components from))
720                           (nth 1 (mail-extract-address-components reply-to)))))
721                   (gnus-article-hide-header "reply-to"))))
722              ((eq elem 'date)
723               (let ((date (message-fetch-field "date")))
724                 (when (and date
725                            (< (gnus-days-between (current-time-string) date)
726                               4))
727                   (gnus-article-hide-header "date")))))))))))
728
729 (defun gnus-article-hide-header (header)
730   (save-excursion
731     (goto-char (point-min))
732     (when (re-search-forward (concat "^" header ":") nil t)
733       (gnus-article-hide-text-type
734        (progn (beginning-of-line) (point))
735        (progn
736          (end-of-line)
737          (if (re-search-forward "^[^ \t]" nil t)
738              (match-beginning 0)
739            (point-max)))
740        'boring-headers))))
741
742 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
743 (defun article-treat-overstrike ()
744   "Translate overstrikes into bold text."
745   (interactive)
746   (save-excursion
747     (let ((buffer-read-only nil))
748       (while (search-forward "\b" nil t)
749         (let ((next (following-char))
750               (previous (char-after (- (point) 2))))
751           ;; We do the boldification/underlining by hiding the
752           ;; overstrikes and putting the proper text property
753           ;; on the letters.
754           (cond
755            ((eq next previous)
756             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
757             (put-text-property (point) (1+ (point)) 'face 'bold))
758            ((eq next ?_)
759             (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
760             (put-text-property
761              (- (point) 2) (1- (point)) 'face 'underline))
762            ((eq previous ?_)
763             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
764             (put-text-property
765              (point) (1+ (point)) 'face 'underline))))))))
766
767 (defun article-fill ()
768   "Format too long lines."
769   (interactive)
770   (save-excursion
771     (let ((buffer-read-only nil))
772       (widen)
773       (goto-char (point-min))
774       (search-forward "\n\n" nil t)
775       (end-of-line 1)
776       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
777             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
778             (adaptive-fill-mode t))
779         (while (not (eobp))
780           (and (>= (current-column) (min fill-column (window-width)))
781                (/= (preceding-char) ?:)
782                (fill-paragraph nil))
783           (end-of-line 2))))))
784
785 (defun article-remove-cr ()
786   "Remove carriage returns from an article."
787   (interactive)
788   (save-excursion
789     (let ((buffer-read-only nil))
790       (goto-char (point-min))
791       (while (search-forward "\r" nil t)
792         (replace-match "" t t)))))
793
794 (defun article-remove-trailing-blank-lines ()
795   "Remove all trailing blank lines from the article."
796   (interactive)
797   (save-excursion
798     (let ((buffer-read-only nil))
799       (goto-char (point-max))
800       (delete-region
801        (point)
802        (progn
803          (while (and (not (bobp))
804                      (looking-at "^[ \t]*$"))
805            (forward-line -1))
806          (forward-line 1)
807          (point))))))
808
809 (defun article-display-x-face (&optional force)
810   "Look for an X-Face header and display it if present."
811   (interactive (list 'force))
812   (save-excursion
813     ;; Delete the old process, if any.
814     (when (process-status "article-x-face")
815       (delete-process "article-x-face"))
816     (let ((inhibit-point-motion-hooks t)
817           (case-fold-search nil)
818           from)
819       (save-restriction
820         (nnheader-narrow-to-headers)
821         (setq from (message-fetch-field "from"))
822         (goto-char (point-min))
823         (when (and gnus-article-x-face-command
824                    (or force
825                        ;; Check whether this face is censored.
826                        (not gnus-article-x-face-too-ugly)
827                        (and gnus-article-x-face-too-ugly from
828                             (not (string-match gnus-article-x-face-too-ugly
829                                                from))))
830                    ;; Has to be present.
831                    (re-search-forward "^X-Face: " nil t))
832           ;; We now have the area of the buffer where the X-Face is stored.
833           (let ((beg (point))
834                 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
835             ;; We display the face.
836             (if (symbolp gnus-article-x-face-command)
837                 ;; The command is a lisp function, so we call it.
838                 (if (gnus-functionp gnus-article-x-face-command)
839                     (funcall gnus-article-x-face-command beg end)
840                   (error "%s is not a function" gnus-article-x-face-command))
841               ;; The command is a string, so we interpret the command
842               ;; as a, well, command, and fork it off.
843               (let ((process-connection-type nil))
844                 (process-kill-without-query
845                  (start-process
846                   "article-x-face" nil shell-file-name shell-command-switch
847                   gnus-article-x-face-command))
848                 (process-send-region "article-x-face" beg end)
849                 (process-send-eof "article-x-face")))))))))
850
851 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
852 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
853 (defun article-decode-rfc1522 ()
854   "Hack to remove QP encoding from headers."
855   (let ((case-fold-search t)
856         (inhibit-point-motion-hooks t)
857         (buffer-read-only nil)
858         string)
859     (save-restriction
860       (narrow-to-region
861        (goto-char (point-min))
862        (or (search-forward "\n\n" nil t) (point-max)))
863       (goto-char (point-min))
864       (while (re-search-forward
865               "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
866         (setq string (match-string 1))
867         (save-restriction
868           (narrow-to-region (match-beginning 0) (match-end 0))
869           (delete-region (point-min) (point-max))
870           (insert string)
871           (article-mime-decode-quoted-printable
872            (goto-char (point-min)) (point-max))
873           (subst-char-in-region (point-min) (point-max) ?_ ? )
874           (goto-char (point-max)))
875         (goto-char (point-min))))))
876
877 (defun article-de-quoted-unreadable (&optional force)
878   "Do a naive translation of a quoted-printable-encoded article.
879 This is in no way, shape or form meant as a replacement for real MIME
880 processing, but is simply a stop-gap measure until MIME support is
881 written.
882 If FORCE, decode the article whether it is marked as quoted-printable
883 or not."
884   (interactive (list 'force))
885   (save-excursion
886     (let ((case-fold-search t)
887           (buffer-read-only nil)
888           (type (gnus-fetch-field "content-transfer-encoding")))
889       (gnus-article-decode-rfc1522)
890       (when (or force
891                 (and type (string-match "quoted-printable" (downcase type))))
892         (goto-char (point-min))
893         (search-forward "\n\n" nil 'move)
894         (article-mime-decode-quoted-printable (point) (point-max))))))
895
896 (defun article-mime-decode-quoted-printable-buffer ()
897   "Decode Quoted-Printable in the current buffer."
898   (article-mime-decode-quoted-printable (point-min) (point-max)))
899
900 (defun article-mime-decode-quoted-printable (from to)
901   "Decode Quoted-Printable in the region between FROM and TO."
902   (interactive "r")
903   (goto-char from)
904   (while (search-forward "=" to t)
905     (cond ((eq (following-char) ?\n)
906            (delete-char -1)
907            (delete-char 1))
908           ((looking-at "[0-9A-F][0-9A-F]")
909            (subst-char-in-region
910             (1- (point)) (point) ?=
911             (hexl-hex-string-to-integer
912              (buffer-substring (point) (+ 2 (point)))))
913            (delete-char 2))
914           ((looking-at "=")
915            (delete-char 1))
916           ((gnus-message 3 "Malformed MIME quoted-printable message")))))
917
918 (defun article-hide-pgp (&optional arg)
919   "Toggle hiding of any PGP headers and signatures in the current article.
920 If given a negative prefix, always show; if given a positive prefix,
921 always hide."
922   (interactive (gnus-article-hidden-arg))
923   (unless (gnus-article-check-hidden-text 'pgp arg)
924     (save-excursion
925       (let ((inhibit-point-motion-hooks t)
926             buffer-read-only beg end)
927         (widen)
928         (goto-char (point-min))
929         ;; Hide the "header".
930         (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
931           (gnus-article-hide-text-type (1+ (match-beginning 0))
932                                        (match-end 0) 'pgp))
933         (setq beg (point))
934         ;; Hide the actual signature.
935         (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
936              (setq end (1+ (match-beginning 0)))
937              (gnus-article-hide-text-type
938               end
939               (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
940                   (match-end 0)
941                 ;; Perhaps we shouldn't hide to the end of the buffer
942                 ;; if there is no end to the signature?
943                 (point-max))
944               'pgp))
945         ;; Hide "- " PGP quotation markers.
946         (when (and beg end)
947           (narrow-to-region beg end)
948           (goto-char (point-min))
949           (while (re-search-forward "^- " nil t)
950             (gnus-article-hide-text-type
951              (match-beginning 0) (match-end 0) 'pgp))
952           (widen))))))
953
954 (defun article-hide-pem (&optional arg)
955   "Toggle hiding of any PEM headers and signatures in the current article.
956 If given a negative prefix, always show; if given a positive prefix,
957 always hide."
958   (interactive (gnus-article-hidden-arg))
959   (unless (gnus-article-check-hidden-text 'pem arg)
960     (save-excursion
961       (let (buffer-read-only end)
962         (widen)
963         (goto-char (point-min))
964         ;; hide the horrendously ugly "header".
965         (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
966                              nil
967                              t)
968              (setq end (1+ (match-beginning 0)))
969              (gnus-article-hide-text-type
970               end
971               (if (search-forward "\n\n" nil t)
972                   (match-end 0)
973                 (point-max))
974               'pem))
975         ;; hide the trailer as well
976         (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
977                              nil
978                              t)
979              (gnus-article-hide-text-type
980               (match-beginning 0) (match-end 0) 'pem))))))
981
982 (defun article-hide-signature (&optional arg)
983   "Hide the signature in the current article.
984 If given a negative prefix, always show; if given a positive prefix,
985 always hide."
986   (interactive (gnus-article-hidden-arg))
987   (unless (gnus-article-check-hidden-text 'signature arg)
988     (save-excursion
989       (save-restriction
990         (let ((buffer-read-only nil))
991           (when (gnus-article-narrow-to-signature)
992             (gnus-article-hide-text-type
993              (point-min) (point-max) 'signature)))))))
994
995 (defun article-strip-leading-blank-lines ()
996   "Remove all blank lines from the beginning of the article."
997   (interactive)
998   (save-excursion
999     (let ((inhibit-point-motion-hooks t)
1000           buffer-read-only)
1001       (goto-char (point-min))
1002       (when (search-forward "\n\n" nil t)
1003         (while (and (not (eobp))
1004                     (looking-at "[ \t]*$"))
1005           (gnus-delete-line))))))
1006
1007 (defun article-strip-multiple-blank-lines ()
1008   "Replace consecutive blank lines with one empty line."
1009   (interactive)
1010   (save-excursion
1011     (let ((inhibit-point-motion-hooks t)
1012           buffer-read-only)
1013       ;; First make all blank lines empty.
1014       (goto-char (point-min))
1015       (search-forward "\n\n" nil t)
1016       (while (re-search-forward "^[ \t]+$" nil t)
1017         (replace-match "" nil t))
1018       ;; Then replace multiple empty lines with a single empty line.
1019       (goto-char (point-min))
1020       (search-forward "\n\n" nil t)
1021       (while (re-search-forward "\n\n\n+" nil t)
1022         (replace-match "\n\n" t t)))))
1023
1024 (defun article-strip-leading-space ()
1025   "Remove all white space from the beginning of the lines in the article."
1026   (interactive)
1027   (save-excursion
1028     (let ((inhibit-point-motion-hooks t)
1029           buffer-read-only)
1030       (goto-char (point-min))
1031       (search-forward "\n\n" nil t)
1032       (while (re-search-forward "^[ \t]+" nil t)
1033         (replace-match "" t t)))))
1034
1035 (defun article-strip-blank-lines ()
1036   "Strip leading, trailing and multiple blank lines."
1037   (interactive)
1038   (article-strip-leading-blank-lines)
1039   (article-remove-trailing-blank-lines)
1040   (article-strip-multiple-blank-lines))
1041
1042 (defvar mime::preview/content-list)
1043 (defvar mime::preview-content-info/point-min)
1044 (defun gnus-article-narrow-to-signature ()
1045   "Narrow to the signature; return t if a signature is found, else nil."
1046   (widen)
1047   (when (and (boundp 'mime::preview/content-list)
1048              mime::preview/content-list)
1049     ;; We have a MIMEish article, so we use the MIME data to narrow.
1050     (let ((pcinfo (car (last mime::preview/content-list))))
1051       (ignore-errors
1052         (narrow-to-region
1053          (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1054          (point-max)))))
1055
1056   (when (gnus-article-search-signature)
1057     (forward-line 1)
1058     ;; Check whether we have some limits to what we consider
1059     ;; to be a signature.
1060     (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1061                     (list gnus-signature-limit)))
1062           limit limited)
1063       (while (setq limit (pop limits))
1064         (if (or (and (integerp limit)
1065                      (< (- (point-max) (point)) limit))
1066                 (and (floatp limit)
1067                      (< (count-lines (point) (point-max)) limit))
1068                 (and (gnus-functionp limit)
1069                      (funcall limit))
1070                 (and (stringp limit)
1071                      (not (re-search-forward limit nil t))))
1072             ()                          ; This limit did not succeed.
1073           (setq limited t
1074                 limits nil)))
1075       (unless limited
1076         (narrow-to-region (point) (point-max))
1077         t))))
1078
1079 (defun gnus-article-search-signature ()
1080   "Search the current buffer for the signature separator.
1081 Put point at the beginning of the signature separator."
1082   (let ((cur (point)))
1083     (goto-char (point-max))
1084     (if (if (stringp gnus-signature-separator)
1085             (re-search-backward gnus-signature-separator nil t)
1086           (let ((seps gnus-signature-separator))
1087             (while (and seps
1088                         (not (re-search-backward (car seps) nil t)))
1089               (pop seps))
1090             seps))
1091         t
1092       (goto-char cur)
1093       nil)))
1094
1095 (eval-and-compile
1096   (autoload 'w3-parse-buffer "w3-parse"))
1097
1098 (defun gnus-article-treat-html ()
1099   "Render HTML."
1100   (interactive)
1101   (let ((cbuf (current-buffer)))
1102     (set-buffer gnus-article-buffer)
1103     (let (buf buffer-read-only b e)
1104       (goto-char (point-min))
1105       (narrow-to-region
1106        (if (search-forward "\n\n" nil t)
1107            (setq b (point))
1108          (point-max))
1109        (setq e (point-max)))
1110       (nnheader-temp-write nil
1111         (insert-buffer-substring gnus-article-buffer b e)
1112         (save-window-excursion
1113           (setq buf (car (w3-parse-buffer (current-buffer))))))
1114       (when buf
1115         (delete-region (point-min) (point-max))
1116         (insert-buffer-substring buf)
1117         (kill-buffer buf))
1118       (widen)
1119       (goto-char (point-min))
1120       (set-window-start (get-buffer-window (current-buffer)) (point-min))
1121       (set-buffer cbuf))))
1122
1123 (defun gnus-article-hidden-arg ()
1124   "Return the current prefix arg as a number, or 0 if no prefix."
1125   (list (if current-prefix-arg
1126             (prefix-numeric-value current-prefix-arg)
1127           0)))
1128
1129 (defun gnus-article-check-hidden-text (type arg)
1130   "Return nil if hiding is necessary.
1131 Arg can be nil or a number.  Nil and positive means hide, negative
1132 means show, 0 means toggle."
1133   (save-excursion
1134     (save-restriction
1135       (widen)
1136       (let ((hide (gnus-article-hidden-text-p type)))
1137         (cond
1138          ((or (null arg)
1139               (> arg 0))
1140           nil)
1141          ((< arg 0)
1142           (gnus-article-show-hidden-text type))
1143          (t
1144           (if (eq hide 'hidden)
1145               (gnus-article-show-hidden-text type)
1146             nil)))))))
1147
1148 (defun gnus-article-hidden-text-p (type)
1149   "Say whether the current buffer contains hidden text of type TYPE."
1150   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1151     (when pos
1152       (if (get-text-property pos 'invisible)
1153           'hidden
1154         'shown))))
1155
1156 (defun gnus-article-show-hidden-text (type &optional hide)
1157   "Show all hidden text of type TYPE.
1158 If HIDE, hide the text instead."
1159   (save-excursion
1160     (let ((buffer-read-only nil)
1161           (inhibit-point-motion-hooks t)
1162           (end (point-min))
1163           beg)
1164       (while (setq beg (text-property-any end (point-max) 'article-type type))
1165         (goto-char beg)
1166         (setq end (or
1167                    (text-property-not-all beg (point-max) 'article-type type)
1168                    (point-max)))
1169         (if hide
1170             (gnus-article-hide-text beg end gnus-hidden-properties)
1171           (gnus-article-unhide-text beg end))
1172         (goto-char end))
1173       t)))
1174
1175 (defconst article-time-units
1176   `((year . ,(* 365.25 24 60 60))
1177     (week . ,(* 7 24 60 60))
1178     (day . ,(* 24 60 60))
1179     (hour . ,(* 60 60))
1180     (minute . 60)
1181     (second . 1))
1182   "Mapping from time units to seconds.")
1183
1184 (defun article-date-ut (&optional type highlight header)
1185   "Convert DATE date to universal time in the current article.
1186 If TYPE is `local', convert to local time; if it is `lapsed', output
1187 how much time has lapsed since DATE."
1188   (interactive (list 'ut t))
1189   (let* ((header (or header
1190                      (mail-header-date gnus-current-headers)
1191                      (message-fetch-field "date")
1192                      ""))
1193          (date (if (vectorp header) (mail-header-date header)
1194                  header))
1195          (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1196          (inhibit-point-motion-hooks t)
1197          bface eface)
1198     (when (and date (not (string= date "")))
1199       (save-excursion
1200         (save-restriction
1201           (nnheader-narrow-to-headers)
1202           (let ((buffer-read-only nil))
1203             ;; Delete any old Date headers.
1204             (if (re-search-forward date-regexp nil t)
1205                 (progn
1206                   (setq bface (get-text-property (gnus-point-at-bol) 'face)
1207                         eface (get-text-property (1- (gnus-point-at-eol))
1208                                                  'face))
1209                   (message-remove-header date-regexp t)
1210                   (beginning-of-line))
1211               (goto-char (point-max)))
1212             (insert (article-make-date-line date type))
1213             ;; Do highlighting.
1214             (forward-line -1)
1215             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1216               (put-text-property (match-beginning 1) (match-end 1)
1217                                  'face bface)
1218               (put-text-property (match-beginning 2) (match-end 2)
1219                                  'face eface))))))))
1220
1221 (defun article-make-date-line (date type)
1222   "Return a DATE line of TYPE."
1223   (cond
1224    ;; Convert to the local timezone.  We have to slap a
1225    ;; `condition-case' round the calls to the timezone
1226    ;; functions since they aren't particularly resistant to
1227    ;; buggy dates.
1228    ((eq type 'local)
1229     (concat "Date: " (condition-case ()
1230                          (timezone-make-date-arpa-standard date)
1231                        (error date))
1232             "\n"))
1233    ;; Convert to Universal Time.
1234    ((eq type 'ut)
1235     (concat "Date: "
1236             (condition-case ()
1237                 (timezone-make-date-arpa-standard date nil "UT")
1238               (error date))
1239             "\n"))
1240    ;; Get the original date from the article.
1241    ((eq type 'original)
1242     (concat "Date: " date "\n"))
1243    ;; Let the user define the format.
1244    ((eq type 'user)
1245     (concat
1246      "Date: "
1247      (format-time-string gnus-article-time-format
1248                          (ignore-errors
1249                            (gnus-encode-date
1250                             (timezone-make-date-arpa-standard
1251                              date nil "UT"))))
1252      "\n"))
1253    ;; Do an X-Sent lapsed format.
1254    ((eq type 'lapsed)
1255     ;; If the date is seriously mangled, the timezone functions are
1256     ;; liable to bug out, so we ignore all errors.
1257     (let* ((now (current-time))
1258            (real-time
1259             (ignore-errors
1260               (gnus-time-minus
1261                (gnus-encode-date
1262                 (timezone-make-date-arpa-standard
1263                  (current-time-string now)
1264                  (current-time-zone now) "UT"))
1265                (gnus-encode-date
1266                 (timezone-make-date-arpa-standard
1267                  date nil "UT")))))
1268            (real-sec (and real-time
1269                           (+ (* (float (car real-time)) 65536)
1270                              (cadr real-time))))
1271            (sec (and real-time (abs real-sec)))
1272            num prev)
1273       (cond
1274        ((null real-time)
1275         "X-Sent: Unknown\n")
1276        ((zerop sec)
1277         "X-Sent: Now\n")
1278        (t
1279         (concat
1280          "X-Sent: "
1281          ;; This is a bit convoluted, but basically we go
1282          ;; through the time units for years, weeks, etc,
1283          ;; and divide things to see whether that results
1284          ;; in positive answers.
1285          (mapconcat
1286           (lambda (unit)
1287             (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1288                 ;; The (remaining) seconds are too few to
1289                 ;; be divided into this time unit.
1290                 ""
1291               ;; It's big enough, so we output it.
1292               (setq sec (- sec (* num (cdr unit))))
1293               (prog1
1294                   (concat (if prev ", " "") (int-to-string
1295                                              (floor num))
1296                           " " (symbol-name (car unit))
1297                           (if (> num 1) "s" ""))
1298                 (setq prev t))))
1299           article-time-units "")
1300          ;; If dates are odd, then it might appear like the
1301          ;; article was sent in the future.
1302          (if (> real-sec 0)
1303              " ago\n"
1304            " in the future\n"))))))
1305    (t
1306     (error "Unknown conversion type: %s" type))))
1307
1308 (defun article-date-local (&optional highlight)
1309   "Convert the current article date to the local timezone."
1310   (interactive (list t))
1311   (article-date-ut 'local highlight))
1312
1313 (defun article-date-original (&optional highlight)
1314   "Convert the current article date to what it was originally.
1315 This is only useful if you have used some other date conversion
1316 function and want to see what the date was before converting."
1317   (interactive (list t))
1318   (article-date-ut 'original highlight))
1319
1320 (defun article-date-lapsed (&optional highlight)
1321   "Convert the current article date to time lapsed since it was sent."
1322   (interactive (list t))
1323   (article-date-ut 'lapsed highlight))
1324
1325 (defun article-date-user (&optional highlight)
1326   "Convert the current article date to the user-defined format.
1327 This format is defined by the `gnus-article-time-format' variable."
1328   (interactive (list t))
1329   (article-date-ut 'user highlight))
1330
1331 (defun article-show-all ()
1332   "Show all hidden text in the article buffer."
1333   (interactive)
1334   (save-excursion
1335     (let ((buffer-read-only nil))
1336       (gnus-article-unhide-text (point-min) (point-max)))))
1337
1338 (defun article-emphasize (&optional arg)
1339   "Emphasize text according to `gnus-emphasis-alist'."
1340   (interactive (gnus-article-hidden-arg))
1341   (unless (gnus-article-check-hidden-text 'emphasis arg)
1342     (save-excursion
1343       (let ((alist gnus-emphasis-alist)
1344             (buffer-read-only nil)
1345             (props (append '(article-type emphasis)
1346                            gnus-hidden-properties))
1347             regexp elem beg invisible visible face)
1348         (goto-char (point-min))
1349         (search-forward "\n\n" nil t)
1350         (setq beg (point))
1351         (while (setq elem (pop alist))
1352           (goto-char beg)
1353           (setq regexp (car elem)
1354                 invisible (nth 1 elem)
1355                 visible (nth 2 elem)
1356                 face (nth 3 elem))
1357           (while (re-search-forward regexp nil t)
1358             (when (and (match-beginning visible) (match-beginning invisible))
1359               (gnus-article-hide-text
1360                (match-beginning invisible) (match-end invisible) props)
1361               (gnus-article-unhide-text-type
1362                (match-beginning visible) (match-end visible) 'emphasis)
1363               (gnus-put-text-property-excluding-newlines
1364                (match-beginning visible) (match-end visible) 'face face)
1365               (goto-char (match-end invisible)))))))))
1366
1367 (defvar gnus-summary-article-menu)
1368 (defvar gnus-summary-post-menu)
1369
1370 ;;; Saving functions.
1371
1372 (defun gnus-article-save (save-buffer file &optional num)
1373   "Save the currently selected article."
1374   (unless gnus-save-all-headers
1375     ;; Remove headers according to `gnus-saved-headers'.
1376     (let ((gnus-visible-headers
1377            (or gnus-saved-headers gnus-visible-headers))
1378           (gnus-article-buffer save-buffer))
1379       (gnus-article-hide-headers 1 t)))
1380   (save-window-excursion
1381     (if (not gnus-default-article-saver)
1382         (error "No default saver is defined.")
1383       ;; !!! Magic!  The saving functions all save
1384       ;; `gnus-original-article-buffer' (or so they think), but we
1385       ;; bind that variable to our save-buffer.
1386       (set-buffer gnus-article-buffer)
1387       (let* ((gnus-save-article-buffer save-buffer)
1388              (filename
1389               (cond
1390                ((not gnus-prompt-before-saving) 'default)
1391                ((eq gnus-prompt-before-saving 'always) nil)
1392                (t file)))
1393              (gnus-number-of-articles-to-be-saved
1394               (when (eq gnus-prompt-before-saving t)
1395                 num)))                  ; Magic
1396         (set-buffer gnus-summary-buffer)
1397         (funcall gnus-default-article-saver filename)))))
1398
1399 (defun gnus-read-save-file-name (prompt &optional filename
1400                                         function group headers variable)
1401   (let ((default-name
1402           (funcall function group headers (symbol-value variable)))
1403         result)
1404     (setq
1405      result
1406      (cond
1407       ((eq filename 'default)
1408        default-name)
1409       ((eq filename t)
1410        default-name)
1411       (filename filename)
1412       (t
1413        (let* ((split-name (gnus-get-split-value gnus-split-methods))
1414               (prompt
1415                (format prompt
1416                        (if (and gnus-number-of-articles-to-be-saved
1417                                 (> gnus-number-of-articles-to-be-saved 1))
1418                            (format "these %d articles"
1419                                    gnus-number-of-articles-to-be-saved)
1420                          "this article")))
1421               (file
1422                ;; Let the split methods have their say.
1423                (cond
1424                 ;; No split name was found.
1425                 ((null split-name)
1426                  (read-file-name
1427                   (concat prompt " (default "
1428                           (file-name-nondirectory default-name) ") ")
1429                   (file-name-directory default-name)
1430                   default-name))
1431                 ;; A single group name is returned.
1432                 ((stringp split-name)
1433                  (setq default-name
1434                        (funcall function split-name headers
1435                                 (symbol-value variable)))
1436                  (read-file-name
1437                   (concat prompt " (default "
1438                           (file-name-nondirectory default-name) ") ")
1439                   (file-name-directory default-name)
1440                   default-name))
1441                 ;; A single split name was found
1442                 ((= 1 (length split-name))
1443                  (let* ((name (car split-name))
1444                         (dir (cond ((file-directory-p name)
1445                                     (file-name-as-directory name))
1446                                    ((file-exists-p name) name)
1447                                    (t gnus-article-save-directory))))
1448                    (read-file-name
1449                     (concat prompt " (default " name ") ")
1450                     dir name)))
1451                 ;; A list of splits was found.
1452                 (t
1453                  (setq split-name (nreverse split-name))
1454                  (let (result)
1455                    (let ((file-name-history
1456                           (nconc split-name file-name-history)))
1457                      (setq result
1458                            (expand-file-name
1459                             (read-file-name
1460                              (concat prompt " (`M-p' for defaults) ")
1461                              gnus-article-save-directory
1462                              (car split-name))
1463                             gnus-article-save-directory)))
1464                    (car (push result file-name-history)))))))
1465          ;; Create the directory.
1466          (gnus-make-directory (file-name-directory file))
1467          ;; If we have read a directory, we append the default file name.
1468          (when (file-directory-p file)
1469            (setq file (concat (file-name-as-directory file)
1470                               (file-name-nondirectory default-name))))
1471          ;; Possibly translate some characters.
1472          (nnheader-translate-file-chars file)))))
1473     (gnus-make-directory (file-name-directory result))
1474     (set variable result)))
1475
1476 (defun gnus-article-archive-name (group)
1477   "Return the first instance of an \"Archive-name\" in the current buffer."
1478   (let ((case-fold-search t))
1479     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1480       (nnheader-concat gnus-article-save-directory
1481                        (match-string 1)))))
1482
1483 (defun gnus-article-nndoc-name (group)
1484   "If GROUP is an nndoc group, return the name of the parent group."
1485   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1486     (gnus-group-get-parameter group 'save-article-group)))
1487
1488 (defun gnus-summary-save-in-rmail (&optional filename)
1489   "Append this article to Rmail file.
1490 Optional argument FILENAME specifies file name.
1491 Directory to save to is default to `gnus-article-save-directory'."
1492   (interactive)
1493   (gnus-set-global-variables)
1494   (setq filename (gnus-read-save-file-name
1495                   "Save %s in rmail file:" filename
1496                   gnus-rmail-save-name gnus-newsgroup-name
1497                   gnus-current-headers 'gnus-newsgroup-last-rmail))
1498   (gnus-eval-in-buffer-window gnus-save-article-buffer
1499     (save-excursion
1500       (save-restriction
1501         (widen)
1502         (gnus-output-to-rmail filename)))))
1503
1504 (defun gnus-summary-save-in-mail (&optional filename)
1505   "Append this article to Unix mail file.
1506 Optional argument FILENAME specifies file name.
1507 Directory to save to is default to `gnus-article-save-directory'."
1508   (interactive)
1509   (gnus-set-global-variables)
1510   (setq filename (gnus-read-save-file-name
1511                   "Save %s in Unix mail file:" filename
1512                   gnus-mail-save-name gnus-newsgroup-name
1513                   gnus-current-headers 'gnus-newsgroup-last-mail))
1514   (gnus-eval-in-buffer-window gnus-save-article-buffer
1515     (save-excursion
1516       (save-restriction
1517         (widen)
1518         (if (and (file-readable-p filename)
1519                  (mail-file-babyl-p filename))
1520             (gnus-output-to-rmail filename t)
1521           (gnus-output-to-mail filename))))))
1522
1523 (defun gnus-summary-save-in-file (&optional filename overwrite)
1524   "Append this article to file.
1525 Optional argument FILENAME specifies file name.
1526 Directory to save to is default to `gnus-article-save-directory'."
1527   (interactive)
1528   (gnus-set-global-variables)
1529   (setq filename (gnus-read-save-file-name
1530                   "Save %s in file:" filename
1531                   gnus-file-save-name gnus-newsgroup-name
1532                   gnus-current-headers 'gnus-newsgroup-last-file))
1533   (gnus-eval-in-buffer-window gnus-save-article-buffer
1534     (save-excursion
1535       (save-restriction
1536         (widen)
1537         (when (and overwrite
1538                    (file-exists-p filename))
1539           (delete-file filename))
1540         (gnus-output-to-file filename)))))
1541
1542 (defun gnus-summary-write-to-file (&optional filename)
1543   "Write this article to a file.
1544 Optional argument FILENAME specifies file name.
1545 The directory to save in defaults to `gnus-article-save-directory'."
1546   (interactive)
1547   (gnus-summary-save-in-file nil t))
1548
1549 (defun gnus-summary-save-body-in-file (&optional filename)
1550   "Append this article body to a file.
1551 Optional argument FILENAME specifies file name.
1552 The directory to save in defaults to `gnus-article-save-directory'."
1553   (interactive)
1554   (gnus-set-global-variables)
1555   (setq filename (gnus-read-save-file-name
1556                   "Save %s body in file:" filename
1557                   gnus-file-save-name gnus-newsgroup-name
1558                   gnus-current-headers 'gnus-newsgroup-last-file))
1559   (gnus-eval-in-buffer-window gnus-save-article-buffer
1560     (save-excursion
1561       (save-restriction
1562         (widen)
1563         (goto-char (point-min))
1564         (when (search-forward "\n\n" nil t)
1565           (narrow-to-region (point) (point-max)))
1566         (gnus-output-to-file filename)))))
1567
1568 (defun gnus-summary-save-in-pipe (&optional command)
1569   "Pipe this article to subprocess."
1570   (interactive)
1571   (gnus-set-global-variables)
1572   (setq command
1573         (cond ((eq command 'default)
1574                gnus-last-shell-command)
1575               (command command)
1576               (t (read-string
1577                   (format
1578                    "Shell command on %s: "
1579                    (if (and gnus-number-of-articles-to-be-saved
1580                             (> gnus-number-of-articles-to-be-saved 1))
1581                        (format "these %d articles"
1582                                gnus-number-of-articles-to-be-saved)
1583                      "this article"))
1584                   gnus-last-shell-command))))
1585   (when (string-equal command "")
1586     (setq command gnus-last-shell-command))
1587   (gnus-eval-in-buffer-window gnus-article-buffer
1588     (save-restriction
1589       (widen)
1590       (shell-command-on-region (point-min) (point-max) command nil)))
1591   (setq gnus-last-shell-command command))
1592
1593 ;;; Article file names when saving.
1594
1595 (defun gnus-capitalize-newsgroup (newsgroup)
1596   "Capitalize NEWSGROUP name."
1597   (when (not (zerop (length newsgroup)))
1598     (concat (char-to-string (upcase (aref newsgroup 0)))
1599             (substring newsgroup 1))))
1600
1601 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1602   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1603 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1604 Otherwise, it is like ~/News/news/group/num."
1605   (let ((default
1606           (expand-file-name
1607            (concat (if (gnus-use-long-file-name 'not-save)
1608                        (gnus-capitalize-newsgroup newsgroup)
1609                      (gnus-newsgroup-directory-form newsgroup))
1610                    "/" (int-to-string (mail-header-number headers)))
1611            gnus-article-save-directory)))
1612     (if (and last-file
1613              (string-equal (file-name-directory default)
1614                            (file-name-directory last-file))
1615              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1616         default
1617       (or last-file default))))
1618
1619 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1620   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1621 If variable `gnus-use-long-file-name' is non-nil, it is
1622 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1623   (let ((default
1624           (expand-file-name
1625            (concat (if (gnus-use-long-file-name 'not-save)
1626                        newsgroup
1627                      (gnus-newsgroup-directory-form newsgroup))
1628                    "/" (int-to-string (mail-header-number headers)))
1629            gnus-article-save-directory)))
1630     (if (and last-file
1631              (string-equal (file-name-directory default)
1632                            (file-name-directory last-file))
1633              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1634         default
1635       (or last-file default))))
1636
1637 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1638   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1639 If variable `gnus-use-long-file-name' is non-nil, it is
1640 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1641   (or last-file
1642       (expand-file-name
1643        (if (gnus-use-long-file-name 'not-save)
1644            (gnus-capitalize-newsgroup newsgroup)
1645          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1646        gnus-article-save-directory)))
1647
1648 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1649   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1650 If variable `gnus-use-long-file-name' is non-nil, it is
1651 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1652   (or last-file
1653       (expand-file-name
1654        (if (gnus-use-long-file-name 'not-save)
1655            newsgroup
1656          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1657        gnus-article-save-directory)))
1658
1659 (eval-and-compile
1660   (mapcar
1661    (lambda (func)
1662      (let (afunc gfunc)
1663        (if (consp func)
1664            (setq afunc (car func)
1665                  gfunc (cdr func))
1666          (setq afunc func
1667                gfunc (intern (format "gnus-%s" func))))
1668        (fset gfunc
1669              (if (not (fboundp afunc))
1670                  nil
1671                `(lambda (&optional interactive &rest args)
1672                   ,(documentation afunc t)
1673                   (interactive (list t))
1674                   (save-excursion
1675                     (set-buffer gnus-article-buffer)
1676                     (if interactive
1677                         (call-interactively ',afunc)
1678                       (apply ',afunc args))))))))
1679    '(article-hide-headers
1680      article-hide-boring-headers
1681      article-treat-overstrike
1682      (article-fill . gnus-article-word-wrap)
1683      article-remove-cr
1684      article-display-x-face
1685      article-de-quoted-unreadable
1686      article-mime-decode-quoted-printable
1687      article-hide-pgp
1688      article-hide-pem
1689      article-hide-signature
1690      article-remove-trailing-blank-lines
1691      article-strip-leading-blank-lines
1692      article-strip-multiple-blank-lines
1693      article-strip-leading-space
1694      article-strip-blank-lines
1695      article-date-local
1696      article-date-original
1697      article-date-ut
1698      article-date-user
1699      article-date-lapsed
1700      article-emphasize
1701      (article-show-all . gnus-article-show-all-headers))))
1702 \f
1703 ;;;
1704 ;;; Gnus article mode
1705 ;;;
1706
1707 (put 'gnus-article-mode 'mode-class 'special)
1708
1709 (when t
1710   (gnus-define-keys gnus-article-mode-map
1711     " " gnus-article-goto-next-page
1712     "\177" gnus-article-goto-prev-page
1713     [delete] gnus-article-goto-prev-page
1714     "\C-c^" gnus-article-refer-article
1715     "h" gnus-article-show-summary
1716     "s" gnus-article-show-summary
1717     "\C-c\C-m" gnus-article-mail
1718     "?" gnus-article-describe-briefly
1719     gnus-mouse-2 gnus-article-push-button
1720     "\r" gnus-article-press-button
1721     "\t" gnus-article-next-button
1722     "\M-\t" gnus-article-prev-button
1723     "e" gnus-article-edit
1724     "<" beginning-of-buffer
1725     ">" end-of-buffer
1726     "\C-c\C-i" gnus-info-find-node
1727     "\C-c\C-b" gnus-bug
1728
1729     "\C-d" gnus-article-read-summary-keys
1730     "\M-*" gnus-article-read-summary-keys
1731     "\M-#" gnus-article-read-summary-keys
1732     "\M-^" gnus-article-read-summary-keys
1733     "\M-g" gnus-article-read-summary-keys)
1734
1735   (substitute-key-definition
1736    'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1737
1738 (defun gnus-article-make-menu-bar ()
1739   (gnus-turn-off-edit-menu 'article)
1740   (unless (boundp 'gnus-article-article-menu)
1741     (easy-menu-define
1742      gnus-article-article-menu gnus-article-mode-map ""
1743      '("Article"
1744        ["Scroll forwards" gnus-article-goto-next-page t]
1745        ["Scroll backwards" gnus-article-goto-prev-page t]
1746        ["Show summary" gnus-article-show-summary t]
1747        ["Fetch Message-ID at point" gnus-article-refer-article t]
1748        ["Mail to address at point" gnus-article-mail t]))
1749
1750     (easy-menu-define
1751      gnus-article-treatment-menu gnus-article-mode-map ""
1752      '("Treatment"
1753        ["Hide headers" gnus-article-hide-headers t]
1754        ["Hide signature" gnus-article-hide-signature t]
1755        ["Hide citation" gnus-article-hide-citation t]
1756        ["Treat overstrike" gnus-article-treat-overstrike t]
1757        ["Remove carriage return" gnus-article-remove-cr t]
1758        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1759
1760     (when nil
1761       (when (boundp 'gnus-summary-article-menu)
1762         (define-key gnus-article-mode-map [menu-bar commands]
1763           (cons "Commands" gnus-summary-article-menu))))
1764
1765     (when (boundp 'gnus-summary-post-menu)
1766       (define-key gnus-article-mode-map [menu-bar post]
1767         (cons "Post" gnus-summary-post-menu)))
1768
1769     (run-hooks 'gnus-article-menu-hook)))
1770
1771 (defun gnus-article-mode ()
1772   "Major mode for displaying an article.
1773
1774 All normal editing commands are switched off.
1775
1776 The following commands are available in addition to all summary mode
1777 commands:
1778 \\<gnus-article-mode-map>
1779 \\[gnus-article-next-page]\t Scroll the article one page forwards
1780 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1781 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1782 \\[gnus-article-show-summary]\t Display the summary buffer
1783 \\[gnus-article-mail]\t Send a reply to the address near point
1784 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1785 \\[gnus-info-find-node]\t Go to the Gnus info node"
1786   (interactive)
1787   (when (gnus-visual-p 'article-menu 'menu)
1788     (gnus-article-make-menu-bar))
1789   (kill-all-local-variables)
1790   (gnus-simplify-mode-line)
1791   (setq mode-name "Article")
1792   (setq major-mode 'gnus-article-mode)
1793   (make-local-variable 'minor-mode-alist)
1794   (unless (assq 'gnus-show-mime minor-mode-alist)
1795     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1796   (use-local-map gnus-article-mode-map)
1797   (gnus-update-format-specifications nil 'article-mode)
1798   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1799   (set (make-local-variable 'gnus-button-marker-list) nil)
1800   (gnus-set-default-directory)
1801   (buffer-disable-undo (current-buffer))
1802   (setq buffer-read-only t)
1803   (set-syntax-table gnus-article-mode-syntax-table)
1804   (run-hooks 'gnus-article-mode-hook))
1805
1806 (defun gnus-article-setup-buffer ()
1807   "Initialize the article buffer."
1808   (let* ((name (if gnus-single-article-buffer "*Article*"
1809                  (concat "*Article " gnus-newsgroup-name "*")))
1810          (original
1811           (progn (string-match "\\*Article" name)
1812                  (concat " *Original Article"
1813                          (substring name (match-end 0))))))
1814     (setq gnus-article-buffer name)
1815     (setq gnus-original-article-buffer original)
1816     ;; This might be a variable local to the summary buffer.
1817     (unless gnus-single-article-buffer
1818       (save-excursion
1819         (set-buffer gnus-summary-buffer)
1820         (setq gnus-article-buffer name)
1821         (setq gnus-original-article-buffer original)
1822         (gnus-set-global-variables)))
1823     ;; Init original article buffer.
1824     (save-excursion
1825       (set-buffer (get-buffer-create gnus-original-article-buffer))
1826       (buffer-disable-undo (current-buffer))
1827       (setq major-mode 'gnus-original-article-mode)
1828       (gnus-add-current-to-buffer-list)
1829       (make-local-variable 'gnus-original-article))
1830     (if (get-buffer name)
1831         (save-excursion
1832           (set-buffer name)
1833           (buffer-disable-undo (current-buffer))
1834           (setq buffer-read-only t)
1835           (gnus-add-current-to-buffer-list)
1836           (unless (eq major-mode 'gnus-article-mode)
1837             (gnus-article-mode))
1838           (current-buffer))
1839       (save-excursion
1840         (set-buffer (get-buffer-create name))
1841         (gnus-add-current-to-buffer-list)
1842         (gnus-article-mode)
1843         (make-local-variable 'gnus-summary-buffer)
1844         (current-buffer)))))
1845
1846 ;; Set article window start at LINE, where LINE is the number of lines
1847 ;; from the head of the article.
1848 (defun gnus-article-set-window-start (&optional line)
1849   (set-window-start
1850    (get-buffer-window gnus-article-buffer t)
1851    (save-excursion
1852      (set-buffer gnus-article-buffer)
1853      (goto-char (point-min))
1854      (if (not line)
1855          (point-min)
1856        (gnus-message 6 "Moved to bookmark")
1857        (search-forward "\n\n" nil t)
1858        (forward-line line)
1859        (point)))))
1860
1861 (defun gnus-article-prepare (article &optional all-headers header)
1862   "Prepare ARTICLE in article mode buffer.
1863 ARTICLE should either be an article number or a Message-ID.
1864 If ARTICLE is an id, HEADER should be the article headers.
1865 If ALL-HEADERS is non-nil, no headers are hidden."
1866   (save-excursion
1867     ;; Make sure we start in a summary buffer.
1868     (unless (eq major-mode 'gnus-summary-mode)
1869       (set-buffer gnus-summary-buffer))
1870     (setq gnus-summary-buffer (current-buffer))
1871     ;; Make sure the connection to the server is alive.
1872     (unless (gnus-server-opened
1873              (gnus-find-method-for-group gnus-newsgroup-name))
1874       (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1875       (gnus-request-group gnus-newsgroup-name t))
1876     (let* ((gnus-article (if header (mail-header-number header) article))
1877            (summary-buffer (current-buffer))
1878            (internal-hook gnus-article-internal-prepare-hook)
1879            (group gnus-newsgroup-name)
1880            result)
1881       (save-excursion
1882         (gnus-article-setup-buffer)
1883         (set-buffer gnus-article-buffer)
1884         ;; Deactivate active regions.
1885         (when (and (boundp 'transient-mark-mode)
1886                    transient-mark-mode)
1887           (setq mark-active nil))
1888         (if (not (setq result (let ((buffer-read-only nil))
1889                                 (gnus-request-article-this-buffer
1890                                  article group))))
1891             ;; There is no such article.
1892             (save-excursion
1893               (when (and (numberp article)
1894                          (not (memq article gnus-newsgroup-sparse)))
1895                 (setq gnus-article-current
1896                       (cons gnus-newsgroup-name article))
1897                 (set-buffer gnus-summary-buffer)
1898                 (setq gnus-current-article article)
1899                 (gnus-summary-mark-article article gnus-canceled-mark))
1900               (unless (memq article gnus-newsgroup-sparse)
1901                 (gnus-error
1902                  1 "No such article (may have expired or been canceled)")))
1903           (if (or (eq result 'pseudo) (eq result 'nneething))
1904               (progn
1905                 (save-excursion
1906                   (set-buffer summary-buffer)
1907                   (setq gnus-last-article gnus-current-article
1908                         gnus-newsgroup-history (cons gnus-current-article
1909                                                      gnus-newsgroup-history)
1910                         gnus-current-article 0
1911                         gnus-current-headers nil
1912                         gnus-article-current nil)
1913                   (if (eq result 'nneething)
1914                       (gnus-configure-windows 'summary)
1915                     (gnus-configure-windows 'article))
1916                   (gnus-set-global-variables))
1917                 (gnus-set-mode-line 'article))
1918             ;; The result from the `request' was an actual article -
1919             ;; or at least some text that is now displayed in the
1920             ;; article buffer.
1921             (when (and (numberp article)
1922                        (not (eq article gnus-current-article)))
1923               ;; Seems like a new article has been selected.
1924               ;; `gnus-current-article' must be an article number.
1925               (save-excursion
1926                 (set-buffer summary-buffer)
1927                 (setq gnus-last-article gnus-current-article
1928                       gnus-newsgroup-history (cons gnus-current-article
1929                                                    gnus-newsgroup-history)
1930                       gnus-current-article article
1931                       gnus-current-headers
1932                       (gnus-summary-article-header gnus-current-article)
1933                       gnus-article-current
1934                       (cons gnus-newsgroup-name gnus-current-article))
1935                 (unless (vectorp gnus-current-headers)
1936                   (setq gnus-current-headers nil))
1937                 (gnus-summary-show-thread)
1938                 (run-hooks 'gnus-mark-article-hook)
1939                 (gnus-set-mode-line 'summary)
1940                 (when (gnus-visual-p 'article-highlight 'highlight)
1941                   (run-hooks 'gnus-visual-mark-article-hook))
1942                 ;; Set the global newsgroup variables here.
1943                 ;; Suggested by Jim Sisolak
1944                 ;; <sisolak@trans4.neep.wisc.edu>.
1945                 (gnus-set-global-variables)
1946                 (setq gnus-have-all-headers
1947                       (or all-headers gnus-show-all-headers))
1948                 (and gnus-use-cache
1949                      (vectorp (gnus-summary-article-header article))
1950                      (gnus-cache-possibly-enter-article
1951                       group article
1952                       (gnus-summary-article-header article)
1953                       (memq article gnus-newsgroup-marked)
1954                       (memq article gnus-newsgroup-dormant)
1955                       (memq article gnus-newsgroup-unreads)))))
1956             (when (or (numberp article)
1957                       (stringp article))
1958               ;; Hooks for getting information from the article.
1959               ;; This hook must be called before being narrowed.
1960               (let (buffer-read-only)
1961                 (run-hooks 'internal-hook)
1962                 (run-hooks 'gnus-article-prepare-hook)
1963                 ;; Decode MIME message.
1964                 (when gnus-show-mime
1965                   (if (or (not gnus-strict-mime)
1966                           (gnus-fetch-field "Mime-Version"))
1967                       (funcall gnus-show-mime-method)
1968                     (funcall gnus-decode-encoded-word-method)))
1969                 ;; Perform the article display hooks.
1970                 (run-hooks 'gnus-article-display-hook))
1971               ;; Do page break.
1972               (goto-char (point-min))
1973               (when gnus-break-pages
1974                 (gnus-narrow-to-page)))
1975             (gnus-set-mode-line 'article)
1976             (gnus-configure-windows 'article)
1977             (goto-char (point-min))
1978             t))))))
1979
1980 (defun gnus-article-wash-status ()
1981   "Return a string which display status of article washing."
1982   (save-excursion
1983     (set-buffer gnus-article-buffer)
1984     (let ((cite (gnus-article-hidden-text-p 'cite))
1985           (headers (gnus-article-hidden-text-p 'headers))
1986           (boring (gnus-article-hidden-text-p 'boring-headers))
1987           (pgp (gnus-article-hidden-text-p 'pgp))
1988           (pem (gnus-article-hidden-text-p 'pem))
1989           (signature (gnus-article-hidden-text-p 'signature))
1990           (overstrike (gnus-article-hidden-text-p 'overstrike))
1991           (emphasis (gnus-article-hidden-text-p 'emphasis))
1992           (mime gnus-show-mime))
1993       (format "%c%c%c%c%c%c%c"
1994               (if cite ?c ? )
1995               (if (or headers boring) ?h ? )
1996               (if (or pgp pem) ?p ? )
1997               (if signature ?s ? )
1998               (if overstrike ?o ? )
1999               (if mime ?m ? )
2000               (if emphasis ?e ? )))))
2001
2002 (defun gnus-article-hide-headers-if-wanted ()
2003   "Hide unwanted headers if `gnus-have-all-headers' is nil.
2004 Provided for backwards compatibility."
2005   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2006       gnus-inhibit-hiding
2007       (gnus-article-hide-headers)))
2008
2009 ;;; Article savers.
2010
2011 (defun gnus-output-to-file (file-name)
2012   "Append the current article to a file named FILE-NAME."
2013   (let ((artbuf (current-buffer)))
2014     (nnheader-temp-write nil
2015       (insert-buffer-substring artbuf)
2016       ;; Append newline at end of the buffer as separator, and then
2017       ;; save it to file.
2018       (goto-char (point-max))
2019       (insert "\n")
2020       (append-to-file (point-min) (point-max) file-name))))
2021
2022 (defun gnus-narrow-to-page (&optional arg)
2023   "Narrow the article buffer to a page.
2024 If given a numerical ARG, move forward ARG pages."
2025   (interactive "P")
2026   (setq arg (if arg (prefix-numeric-value arg) 0))
2027   (save-excursion
2028     (set-buffer gnus-article-buffer)
2029     (goto-char (point-min))
2030     (widen)
2031     ;; Remove any old next/prev buttons.
2032     (when (gnus-visual-p 'page-marker)
2033       (let ((buffer-read-only nil))
2034         (gnus-remove-text-with-property 'gnus-prev)
2035         (gnus-remove-text-with-property 'gnus-next)))
2036     (when
2037         (cond ((< arg 0)
2038                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2039               ((> arg 0)
2040                (re-search-forward page-delimiter nil 'move arg)))
2041       (goto-char (match-end 0)))
2042     (narrow-to-region
2043      (point)
2044      (if (re-search-forward page-delimiter nil 'move)
2045          (match-beginning 0)
2046        (point)))
2047     (when (and (gnus-visual-p 'page-marker)
2048                (not (= (point-min) 1)))
2049       (save-excursion
2050         (goto-char (point-min))
2051         (gnus-insert-prev-page-button)))
2052     (when (and (gnus-visual-p 'page-marker)
2053                (< (+ (point-max) 2) (buffer-size)))
2054       (save-excursion
2055         (goto-char (point-max))
2056         (gnus-insert-next-page-button)))))
2057
2058 ;; Article mode commands
2059
2060 (defun gnus-article-goto-next-page ()
2061   "Show the next page of the article."
2062   (interactive)
2063   (when (gnus-article-next-page)
2064     (goto-char (point-min))
2065     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2066
2067 (defun gnus-article-goto-prev-page ()
2068   "Show the next page of the article."
2069   (interactive)
2070   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2071     (gnus-article-prev-page nil)))
2072
2073 (defun gnus-article-next-page (&optional lines)
2074   "Show the next page of the current article.
2075 If end of article, return non-nil.  Otherwise return nil.
2076 Argument LINES specifies lines to be scrolled up."
2077   (interactive "p")
2078   (move-to-window-line -1)
2079   (if (save-excursion
2080         (end-of-line)
2081         (and (pos-visible-in-window-p)  ;Not continuation line.
2082              (eobp)))
2083       ;; Nothing in this page.
2084       (if (or (not gnus-break-pages)
2085               (save-excursion
2086                 (save-restriction
2087                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2088           t                             ;Nothing more.
2089         (gnus-narrow-to-page 1)         ;Go to next page.
2090         nil)
2091     ;; More in this page.
2092     (let ((scroll-in-place nil))
2093       (condition-case ()
2094           (scroll-up lines)
2095         (end-of-buffer
2096          ;; Long lines may cause an end-of-buffer error.
2097          (goto-char (point-max)))))
2098     (move-to-window-line 0)
2099     nil))
2100
2101 (defun gnus-article-prev-page (&optional lines)
2102   "Show previous page of current article.
2103 Argument LINES specifies lines to be scrolled down."
2104   (interactive "p")
2105   (move-to-window-line 0)
2106   (if (and gnus-break-pages
2107            (bobp)
2108            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2109       (progn
2110         (gnus-narrow-to-page -1)        ;Go to previous page.
2111         (goto-char (point-max))
2112         (recenter -1))
2113     (let ((scroll-in-place nil))
2114       (prog1
2115           (condition-case ()
2116               (scroll-down lines)
2117             (beginning-of-buffer
2118              (goto-char (point-min))))
2119         (move-to-window-line 0)))))
2120
2121 (defun gnus-article-refer-article ()
2122   "Read article specified by message-id around point."
2123   (interactive)
2124   (let ((point (point)))
2125     (search-forward ">" nil t)          ;Move point to end of "<....>".
2126     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2127         (let ((message-id (match-string 1)))
2128           (goto-char point)
2129           (set-buffer gnus-summary-buffer)
2130           (gnus-summary-refer-article message-id))
2131       (goto-char (point))
2132       (error "No references around point"))))
2133
2134 (defun gnus-article-show-summary ()
2135   "Reconfigure windows to show summary buffer."
2136   (interactive)
2137   (gnus-configure-windows 'article)
2138   (gnus-summary-goto-subject gnus-current-article))
2139
2140 (defun gnus-article-describe-briefly ()
2141   "Describe article mode commands briefly."
2142   (interactive)
2143   (gnus-message 6
2144                 (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")))
2145
2146 (defun gnus-article-summary-command ()
2147   "Execute the last keystroke in the summary buffer."
2148   (interactive)
2149   (let ((obuf (current-buffer))
2150         (owin (current-window-configuration))
2151         func)
2152     (switch-to-buffer gnus-summary-buffer 'norecord)
2153     (setq func (lookup-key (current-local-map) (this-command-keys)))
2154     (call-interactively func)
2155     (set-buffer obuf)
2156     (set-window-configuration owin)
2157     (set-window-point (get-buffer-window (current-buffer)) (point))))
2158
2159 (defun gnus-article-summary-command-nosave ()
2160   "Execute the last keystroke in the summary buffer."
2161   (interactive)
2162   (let (func)
2163     (pop-to-buffer gnus-summary-buffer 'norecord)
2164     (setq func (lookup-key (current-local-map) (this-command-keys)))
2165     (call-interactively func)))
2166
2167 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2168   "Read a summary buffer key sequence and execute it from the article buffer."
2169   (interactive "P")
2170   (let ((nosaves
2171          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
2172            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2173            "=" "^" "\M-^" "|"))
2174         (nosave-but-article
2175          '("A\r"))
2176         (nosave-in-article
2177          '("\C-d"))
2178         keys)
2179     (save-excursion
2180       (set-buffer gnus-summary-buffer)
2181       (let (gnus-pick-mode)
2182         (push (or key last-command-event) unread-command-events)
2183         (setq keys (read-key-sequence nil))))
2184     (message "")
2185
2186     (if (or (member keys nosaves)
2187             (member keys nosave-but-article)
2188             (member keys nosave-in-article))
2189         (let (func)
2190           (save-window-excursion
2191             (pop-to-buffer gnus-summary-buffer 'norecord)
2192             ;; We disable the pick minor mode commands.
2193             (let (gnus-pick-mode)
2194               (setq func (lookup-key (current-local-map) keys))))
2195           (if (not func)
2196               (ding)
2197             (unless (member keys nosave-in-article)
2198               (set-buffer gnus-summary-buffer))
2199             (call-interactively func))
2200           (when (member keys nosave-but-article)
2201             (pop-to-buffer gnus-article-buffer 'norecord)))
2202       ;; These commands should restore window configuration.
2203       (let ((obuf (current-buffer))
2204             (owin (current-window-configuration))
2205             (opoint (point))
2206             func in-buffer)
2207         (if not-restore-window
2208             (pop-to-buffer gnus-summary-buffer 'norecord)
2209           (switch-to-buffer gnus-summary-buffer 'norecord))
2210         (setq in-buffer (current-buffer))
2211         ;; We disable the pick minor mode commands.
2212         (if (setq func (let (gnus-pick-mode)
2213                          (lookup-key (current-local-map) keys)))
2214             (call-interactively func)
2215           (ding))
2216         (when (eq in-buffer (current-buffer))
2217           (set-buffer obuf)
2218           (unless not-restore-window
2219             (set-window-configuration owin))
2220           (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2221
2222 (defun gnus-article-hide (&optional arg force)
2223   "Hide all the gruft in the current article.
2224 This means that PGP stuff, signatures, cited text and (some)
2225 headers will be hidden.
2226 If given a prefix, show the hidden text instead."
2227   (interactive (list current-prefix-arg 'force))
2228   (gnus-article-hide-headers arg)
2229   (gnus-article-hide-pgp arg)
2230   (gnus-article-hide-citation-maybe arg force)
2231   (gnus-article-hide-signature arg))
2232
2233 (defun gnus-article-maybe-highlight ()
2234   "Do some article highlighting if `article-visual' is non-nil."
2235   (when (gnus-visual-p 'article-highlight 'highlight)
2236     (gnus-article-highlight-some)))
2237
2238 (defun gnus-request-article-this-buffer (article group)
2239   "Get an article and insert it into this buffer."
2240   (let (do-update-line)
2241     (prog1
2242         (save-excursion
2243           (erase-buffer)
2244           (gnus-kill-all-overlays)
2245           (setq group (or group gnus-newsgroup-name))
2246
2247           ;; Open server if it has closed.
2248           (gnus-check-server (gnus-find-method-for-group group))
2249
2250           ;; Using `gnus-request-article' directly will insert the article into
2251           ;; `nntp-server-buffer' - so we'll save some time by not having to
2252           ;; copy it from the server buffer into the article buffer.
2253
2254           ;; We only request an article by message-id when we do not have the
2255           ;; headers for it, so we'll have to get those.
2256           (when (stringp article)
2257             (let ((gnus-override-method gnus-refer-article-method))
2258               (gnus-read-header article)))
2259
2260           ;; If the article number is negative, that means that this article
2261           ;; doesn't belong in this newsgroup (possibly), so we find its
2262           ;; message-id and request it by id instead of number.
2263           (when (and (numberp article)
2264                      gnus-summary-buffer
2265                      (get-buffer gnus-summary-buffer)
2266                      (buffer-name (get-buffer gnus-summary-buffer)))
2267             (save-excursion
2268               (set-buffer gnus-summary-buffer)
2269               (let ((header (gnus-summary-article-header article)))
2270                 (when (< article 0)
2271                   (cond
2272                    ((memq article gnus-newsgroup-sparse)
2273                     ;; This is a sparse gap article.
2274                     (setq do-update-line article)
2275                     (setq article (mail-header-id header))
2276                     (let ((gnus-override-method gnus-refer-article-method))
2277                       (gnus-read-header article))
2278                     (setq gnus-newsgroup-sparse
2279                           (delq article gnus-newsgroup-sparse)))
2280                    ((vectorp header)
2281                     ;; It's a real article.
2282                     (setq article (mail-header-id header)))
2283                    (t
2284                     ;; It is an extracted pseudo-article.
2285                     (setq article 'pseudo)
2286                     (gnus-request-pseudo-article header))))
2287
2288                 (let ((method (gnus-find-method-for-group
2289                                gnus-newsgroup-name)))
2290                   (if (not (eq (car method) 'nneething))
2291                       ()
2292                     (let ((dir (concat (file-name-as-directory (nth 1 method))
2293                                        (mail-header-subject header))))
2294                       (when (file-directory-p dir)
2295                         (setq article 'nneething)
2296                         (gnus-group-enter-directory dir))))))))
2297
2298           (cond
2299            ;; Refuse to select canceled articles.
2300            ((and (numberp article)
2301                  gnus-summary-buffer
2302                  (get-buffer gnus-summary-buffer)
2303                  (buffer-name (get-buffer gnus-summary-buffer))
2304                  (eq (cdr (save-excursion
2305                             (set-buffer gnus-summary-buffer)
2306                             (assq article gnus-newsgroup-reads)))
2307                      gnus-canceled-mark))
2308             nil)
2309            ;; We first check `gnus-original-article-buffer'.
2310            ((and (get-buffer gnus-original-article-buffer)
2311                  (numberp article)
2312                  (save-excursion
2313                    (set-buffer gnus-original-article-buffer)
2314                    (and (equal (car gnus-original-article) group)
2315                         (eq (cdr gnus-original-article) article))))
2316             (insert-buffer-substring gnus-original-article-buffer)
2317             'article)
2318            ;; Check the backlog.
2319            ((and gnus-keep-backlog
2320                  (gnus-backlog-request-article group article (current-buffer)))
2321             'article)
2322            ;; Check asynchronous pre-fetch.
2323            ((gnus-async-request-fetched-article group article (current-buffer))
2324             (gnus-async-prefetch-next group article gnus-summary-buffer)
2325             'article)
2326            ;; Check the cache.
2327            ((and gnus-use-cache
2328                  (numberp article)
2329                  (gnus-cache-request-article article group))
2330             'article)
2331            ;; Get the article and put into the article buffer.
2332            ((or (stringp article) (numberp article))
2333             (let ((gnus-override-method
2334                    (and (stringp article) gnus-refer-article-method))
2335                   (buffer-read-only nil))
2336               (erase-buffer)
2337               (gnus-kill-all-overlays)
2338               (when (gnus-request-article article group (current-buffer))
2339                 (when (numberp article)
2340                   (gnus-async-prefetch-next group article gnus-summary-buffer)
2341                   (when gnus-keep-backlog
2342                     (gnus-backlog-enter-article
2343                      group article (current-buffer))))
2344                 'article)))
2345            ;; It was a pseudo.
2346            (t article)))
2347
2348       ;; Take the article from the original article buffer
2349       ;; and place it in the buffer it's supposed to be in.
2350       (when (and (get-buffer gnus-article-buffer)
2351                  ;;(numberp article)
2352                  (equal (buffer-name (current-buffer))
2353                         (buffer-name (get-buffer gnus-article-buffer))))
2354         (save-excursion
2355           (if (get-buffer gnus-original-article-buffer)
2356               (set-buffer (get-buffer gnus-original-article-buffer))
2357             (set-buffer (get-buffer-create gnus-original-article-buffer))
2358             (buffer-disable-undo (current-buffer))
2359             (setq major-mode 'gnus-original-article-mode)
2360             (setq buffer-read-only t)
2361             (gnus-add-current-to-buffer-list))
2362           (let (buffer-read-only)
2363             (erase-buffer)
2364             (insert-buffer-substring gnus-article-buffer))
2365           (setq gnus-original-article (cons group article))))
2366
2367       ;; Update sparse articles.
2368       (when (and do-update-line
2369                  (or (numberp article)
2370                      (stringp article)))
2371         (let ((buf (current-buffer)))
2372           (set-buffer gnus-summary-buffer)
2373           (gnus-summary-update-article do-update-line)
2374           (gnus-summary-goto-subject do-update-line nil t)
2375           (set-window-point (get-buffer-window (current-buffer) t)
2376                             (point))
2377           (set-buffer buf))))))
2378
2379 ;;;
2380 ;;; Article editing
2381 ;;;
2382
2383 (defcustom gnus-article-edit-mode-hook nil
2384   "Hook run in article edit mode buffers."
2385   :group 'gnus-article-various
2386   :type 'hook)
2387
2388 (defvar gnus-article-edit-done-function nil)
2389
2390 (defvar gnus-article-edit-mode-map nil)
2391
2392 (unless gnus-article-edit-mode-map
2393   (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2394
2395   (gnus-define-keys gnus-article-edit-mode-map
2396     "\C-c\C-c" gnus-article-edit-done
2397     "\C-c\C-k" gnus-article-edit-exit)
2398
2399   (gnus-define-keys (gnus-article-edit-wash-map
2400                      "\C-c\C-w" gnus-article-edit-mode-map)
2401     "f" gnus-article-edit-full-stops))
2402
2403 (defun gnus-article-edit-mode ()
2404   "Major mode for editing articles.
2405 This is an extended text-mode.
2406
2407 \\{gnus-article-edit-mode-map}"
2408   (interactive)
2409   (kill-all-local-variables)
2410   (setq major-mode 'gnus-article-edit-mode)
2411   (setq mode-name "Article Edit")
2412   (use-local-map gnus-article-edit-mode-map)
2413   (make-local-variable 'gnus-article-edit-done-function)
2414   (make-local-variable 'gnus-prev-winconf)
2415   (setq buffer-read-only nil)
2416   (buffer-enable-undo)
2417   (widen)
2418   (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2419
2420 (defun gnus-article-edit (&optional force)
2421   "Edit the current article.
2422 This will have permanent effect only in mail groups.
2423 If FORCE is non-nil, allow editing of articles even in read-only
2424 groups."
2425   (interactive "P")
2426   (when (and (not force)
2427              (gnus-group-read-only-p))
2428     (error "The current newsgroup does not support article editing."))
2429   (gnus-article-edit-article
2430    `(lambda ()
2431       (gnus-summary-edit-article-done
2432        ,(or (mail-header-references gnus-current-headers) "")
2433        ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2434
2435 (defun gnus-article-edit-article (exit-func)
2436   "Start editing the contents of the current article buffer."
2437   (let ((winconf (current-window-configuration)))
2438     (set-buffer gnus-article-buffer)
2439     (gnus-article-edit-mode)
2440     (set-text-properties (point-min) (point-max) nil)
2441     (gnus-configure-windows 'edit-article)
2442     (setq gnus-article-edit-done-function exit-func)
2443     (setq gnus-prev-winconf winconf)
2444     (gnus-message 6 "C-c C-c to end edits")))
2445
2446 (defun gnus-article-edit-done ()
2447   "Update the article edits and exit."
2448   (interactive)
2449   (let ((func gnus-article-edit-done-function)
2450         (buf (current-buffer))
2451         (start (window-start)))
2452     (gnus-article-edit-exit)
2453     (save-excursion
2454       (set-buffer buf)
2455       (let ((buffer-read-only nil))
2456         (funcall func)))
2457     (set-buffer buf)
2458     (set-window-start (get-buffer-window buf) start)
2459     (set-window-point (get-buffer-window buf) (point))))
2460
2461 (defun gnus-article-edit-exit ()
2462   "Exit the article editing without updating."
2463   (interactive)
2464   ;; We remove all text props from the article buffer.
2465   (let ((buf (format "%s" (buffer-string)))
2466         (curbuf (current-buffer))
2467         (p (point))
2468         (window-start (window-start)))
2469     (erase-buffer)
2470     (insert buf)
2471     (let ((winconf gnus-prev-winconf))
2472       (gnus-article-mode)
2473       ;; The cache and backlog have to be flushed somewhat.
2474       (when gnus-use-cache
2475         (gnus-cache-update-article
2476          (car gnus-article-current) (cdr gnus-article-current)))
2477       (when gnus-keep-backlog
2478         (gnus-backlog-remove-article
2479          (car gnus-article-current) (cdr gnus-article-current)))
2480       ;; Flush original article as well.
2481       (save-excursion
2482         (when (get-buffer gnus-original-article-buffer)
2483           (set-buffer gnus-original-article-buffer)
2484           (setq gnus-original-article nil)))
2485       (set-window-configuration winconf)
2486       ;; Tippy-toe some to make sure that point remains where it was.
2487       (let ((buf (current-buffer)))
2488         (set-buffer curbuf)
2489         (set-window-start (get-buffer-window (current-buffer)) window-start)
2490         (goto-char p)
2491         (set-buffer buf)))))
2492
2493 (defun gnus-article-edit-full-stops ()
2494   "Interactively repair spacing at end of sentences."
2495   (interactive)
2496   (save-excursion
2497     (goto-char (point-min))
2498     (search-forward-regexp "^$" nil t)
2499     (let ((case-fold-search nil))
2500       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2501
2502 ;;;
2503 ;;; Article highlights
2504 ;;;
2505
2506 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2507
2508 ;;; Internal Variables:
2509
2510 (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\\)"
2511   "Regular expression that matches URLs."
2512   :group 'gnus-article-buttons
2513   :type 'regexp)
2514
2515 (defcustom gnus-button-alist
2516   `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2517      gnus-button-message-id 2)
2518     ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*+\\)" 0 t gnus-button-message-id 1)
2519     ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2520      gnus-button-fetch-group 4)
2521     ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2522     ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2523      t gnus-button-message-id 3)
2524     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1)
2525     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2)
2526     ;; This is how URLs _should_ be embedded in text...
2527     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2528     ;; Raw URLs.
2529     (,gnus-button-url-regexp 0 t gnus-button-url 0))
2530   "Alist of regexps matching buttons in article bodies.
2531
2532 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2533 REGEXP: is the string matching text around the button,
2534 BUTTON: is the number of the regexp grouping actually matching the button,
2535 FORM: is a lisp expression which must eval to true for the button to
2536 be added,
2537 CALLBACK: is the function to call when the user push this button, and each
2538 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2539
2540 CALLBACK can also be a variable, in that case the value of that
2541 variable it the real callback function."
2542   :group 'gnus-article-buttons
2543   :type '(repeat (list regexp
2544                        (integer :tag "Button")
2545                        (sexp :tag "Form")
2546                        (function :tag "Callback")
2547                        (repeat :tag "Par"
2548                                :inline t
2549                                (integer :tag "Regexp group")))))
2550
2551 (defcustom gnus-header-button-alist
2552   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2553      0 t gnus-button-message-id 0)
2554     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2555     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2556      0 t gnus-button-mailto 0)
2557     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2558     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2559     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2560      gnus-button-message-id 3))
2561   "Alist of headers and regexps to match buttons in article heads.
2562
2563 This alist is very similar to `gnus-button-alist', except that each
2564 alist has an additional HEADER element first in each entry:
2565
2566 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2567
2568 HEADER is a regexp to match a header.  For a fuller explanation, see
2569 `gnus-button-alist'."
2570   :group 'gnus-article-buttons
2571   :group 'gnus-article-headers
2572   :type '(repeat (list (regexp :tag "Header")
2573                        regexp
2574                        (integer :tag "Button")
2575                        (sexp :tag "Form")
2576                        (function :tag "Callback")
2577                        (repeat :tag "Par"
2578                                :inline t
2579                                (integer :tag "Regexp group")))))
2580
2581 (defvar gnus-button-regexp nil)
2582 (defvar gnus-button-marker-list nil)
2583 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2584
2585 (defvar gnus-button-last nil)
2586 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2587
2588 ;;; Commands:
2589
2590 (defun gnus-article-push-button (event)
2591   "Check text under the mouse pointer for a callback function.
2592 If the text under the mouse pointer has a `gnus-callback' property,
2593 call it with the value of the `gnus-data' text property."
2594   (interactive "e")
2595   (set-buffer (window-buffer (posn-window (event-start event))))
2596   (let* ((pos (posn-point (event-start event)))
2597          (data (get-text-property pos 'gnus-data))
2598          (fun (get-text-property pos 'gnus-callback)))
2599     (when fun
2600       (funcall fun data))))
2601
2602 (defun gnus-article-press-button ()
2603   "Check text at point for a callback function.
2604 If the text at point has a `gnus-callback' property,
2605 call it with the value of the `gnus-data' text property."
2606   (interactive)
2607   (let* ((data (get-text-property (point) 'gnus-data))
2608          (fun (get-text-property (point) 'gnus-callback)))
2609     (when fun
2610       (funcall fun data))))
2611
2612 (defun gnus-article-prev-button (n)
2613   "Move point to N buttons backward.
2614 If N is negative, move forward instead."
2615   (interactive "p")
2616   (gnus-article-next-button (- n)))
2617
2618 (defun gnus-article-next-button (n)
2619   "Move point to N buttons forward.
2620 If N is negative, move backward instead."
2621   (interactive "p")
2622   (let ((function (if (< n 0) 'previous-single-property-change
2623                     'next-single-property-change))
2624         (inhibit-point-motion-hooks t)
2625         (backward (< n 0))
2626         (limit (if (< n 0) (point-min) (point-max))))
2627     (setq n (abs n))
2628     (while (and (not (= limit (point)))
2629                 (> n 0))
2630       ;; Skip past the current button.
2631       (when (get-text-property (point) 'gnus-callback)
2632         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2633       ;; Go to the next (or previous) button.
2634       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2635       ;; Put point at the start of the button.
2636       (when (and backward (not (get-text-property (point) 'gnus-callback)))
2637         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2638       ;; Skip past intangible buttons.
2639       (when (get-text-property (point) 'intangible)
2640         (incf n))
2641       (decf n))
2642     (unless (zerop n)
2643       (gnus-message 5 "No more buttons"))
2644     n))
2645
2646 (defun gnus-article-highlight (&optional force)
2647   "Highlight current article.
2648 This function calls `gnus-article-highlight-headers',
2649 `gnus-article-highlight-citation',
2650 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2651 do the highlighting.  See the documentation for those functions."
2652   (interactive (list 'force))
2653   (gnus-article-highlight-headers)
2654   (gnus-article-highlight-citation force)
2655   (gnus-article-highlight-signature)
2656   (gnus-article-add-buttons force)
2657   (gnus-article-add-buttons-to-head))
2658
2659 (defun gnus-article-highlight-some (&optional force)
2660   "Highlight current article.
2661 This function calls `gnus-article-highlight-headers',
2662 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2663 do the highlighting.  See the documentation for those functions."
2664   (interactive (list 'force))
2665   (gnus-article-highlight-headers)
2666   (gnus-article-highlight-signature)
2667   (gnus-article-add-buttons))
2668
2669 (defun gnus-article-highlight-headers ()
2670   "Highlight article headers as specified by `gnus-header-face-alist'."
2671   (interactive)
2672   (save-excursion
2673     (set-buffer gnus-article-buffer)
2674     (save-restriction
2675       (let ((alist gnus-header-face-alist)
2676             (buffer-read-only nil)
2677             (case-fold-search t)
2678             (inhibit-point-motion-hooks t)
2679             entry regexp header-face field-face from hpoints fpoints)
2680         (message-narrow-to-head)
2681         (while (setq entry (pop alist))
2682           (goto-char (point-min))
2683           (setq regexp (concat "^\\("
2684                                (if (string-equal "" (nth 0 entry))
2685                                    "[^\t ]"
2686                                  (nth 0 entry))
2687                                "\\)")
2688                 header-face (nth 1 entry)
2689                 field-face (nth 2 entry))
2690           (while (and (re-search-forward regexp nil t)
2691                       (not (eobp)))
2692             (beginning-of-line)
2693             (setq from (point))
2694             (unless (search-forward ":" nil t)
2695               (forward-char 1))
2696             (when (and header-face
2697                        (not (memq (point) hpoints)))
2698               (push (point) hpoints)
2699               (gnus-put-text-property from (point) 'face header-face))
2700             (when (and field-face
2701                        (not (memq (setq from (point)) fpoints)))
2702               (push from fpoints)
2703               (if (re-search-forward "^[^ \t]" nil t)
2704                   (forward-char -2)
2705                 (goto-char (point-max)))
2706               (gnus-put-text-property from (point) 'face field-face))))))))
2707
2708 (defun gnus-article-highlight-signature ()
2709   "Highlight the signature in an article.
2710 It does this by highlighting everything after
2711 `gnus-signature-separator' using `gnus-signature-face'."
2712   (interactive)
2713   (save-excursion
2714     (set-buffer gnus-article-buffer)
2715     (let ((buffer-read-only nil)
2716           (inhibit-point-motion-hooks t))
2717       (save-restriction
2718         (when (and gnus-signature-face
2719                    (gnus-article-narrow-to-signature))
2720           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2721                             'face gnus-signature-face)
2722           (widen)
2723           (gnus-article-search-signature)
2724           (let ((start (match-beginning 0))
2725                 (end (set-marker (make-marker) (1+ (match-end 0)))))
2726             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2727                                      end)))))))
2728
2729 (defun gnus-button-in-region-p (b e prop)
2730   "Say whether PROP exists in the region."
2731   (text-property-not-all b e prop nil))
2732
2733 (defun gnus-article-add-buttons (&optional force)
2734   "Find external references in the article and make buttons of them.
2735 \"External references\" are things like Message-IDs and URLs, as
2736 specified by `gnus-button-alist'."
2737   (interactive (list 'force))
2738   (save-excursion
2739     (set-buffer gnus-article-buffer)
2740     (let ((buffer-read-only nil)
2741           (inhibit-point-motion-hooks t)
2742           (case-fold-search t)
2743           (alist gnus-button-alist)
2744           beg entry regexp)
2745       ;; Remove all old markers.
2746       (let (marker entry)
2747         (while (setq marker (pop gnus-button-marker-list))
2748           (goto-char marker)
2749           (when (setq entry (gnus-button-entry))
2750             (put-text-property (match-beginning (nth 1 entry))
2751                                (match-end (nth 1 entry))
2752                                'gnus-callback nil))
2753           (set-marker marker nil)))
2754       ;; We skip the headers.
2755       (goto-char (point-min))
2756       (unless (search-forward "\n\n" nil t)
2757         (goto-char (point-max)))
2758       (setq beg (point))
2759       (while (setq entry (pop alist))
2760         (setq regexp (car entry))
2761         (goto-char beg)
2762         (while (re-search-forward regexp nil t)
2763           (let* ((start (and entry (match-beginning (nth 1 entry))))
2764                  (end (and entry (match-end (nth 1 entry))))
2765                  (from (match-beginning 0)))
2766             (when (and (or (eq t (nth 2 entry))
2767                            (eval (nth 2 entry)))
2768                        (not (gnus-button-in-region-p
2769                              start end 'gnus-callback)))
2770               ;; That optional form returned non-nil, so we add the
2771               ;; button.
2772               (gnus-article-add-button
2773                start end 'gnus-button-push
2774                (car (push (set-marker (make-marker) from)
2775                           gnus-button-marker-list))))))))))
2776
2777 ;; Add buttons to the head of an article.
2778 (defun gnus-article-add-buttons-to-head ()
2779   "Add buttons to the head of the article."
2780   (interactive)
2781   (save-excursion
2782     (set-buffer gnus-article-buffer)
2783     (let ((buffer-read-only nil)
2784           (inhibit-point-motion-hooks t)
2785           (case-fold-search t)
2786           (alist gnus-header-button-alist)
2787           entry beg end)
2788       (nnheader-narrow-to-headers)
2789       (while alist
2790         ;; Each alist entry.
2791         (setq entry (car alist)
2792               alist (cdr alist))
2793         (goto-char (point-min))
2794         (while (re-search-forward (car entry) nil t)
2795           ;; Each header matching the entry.
2796           (setq beg (match-beginning 0))
2797           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2798                              (match-beginning 0))
2799                         (point-max)))
2800           (goto-char beg)
2801           (while (re-search-forward (nth 1 entry) end t)
2802             ;; Each match within a header.
2803             (let* ((entry (cdr entry))
2804                    (start (match-beginning (nth 1 entry)))
2805                    (end (match-end (nth 1 entry)))
2806                    (form (nth 2 entry)))
2807               (goto-char (match-end 0))
2808               (when (eval form)
2809                 (gnus-article-add-button
2810                  start end (nth 3 entry)
2811                  (buffer-substring (match-beginning (nth 4 entry))
2812                                    (match-end (nth 4 entry)))))))
2813           (goto-char end))))
2814     (widen)))
2815
2816 ;;; External functions:
2817
2818 (defun gnus-article-add-button (from to fun &optional data)
2819   "Create a button between FROM and TO with callback FUN and data DATA."
2820   (when gnus-article-button-face
2821     (gnus-overlay-put (gnus-make-overlay from to)
2822                       'face gnus-article-button-face))
2823   (gnus-add-text-properties
2824    from to
2825    (nconc (and gnus-article-mouse-face
2826                (list gnus-mouse-face-prop gnus-article-mouse-face))
2827           (list 'gnus-callback fun)
2828           (and data (list 'gnus-data data)))))
2829
2830 ;;; Internal functions:
2831
2832 (defun gnus-signature-toggle (end)
2833   (save-excursion
2834     (set-buffer gnus-article-buffer)
2835     (let ((buffer-read-only nil)
2836           (inhibit-point-motion-hooks t))
2837       (if (get-text-property end 'invisible)
2838           (gnus-article-unhide-text end (point-max))
2839         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2840
2841 (defun gnus-button-entry ()
2842   ;; Return the first entry in `gnus-button-alist' matching this place.
2843   (let ((alist gnus-button-alist)
2844         (entry nil))
2845     (while alist
2846       (setq entry (pop alist))
2847       (if (looking-at (car entry))
2848           (setq alist nil)
2849         (setq entry nil)))
2850     entry))
2851
2852 (defun gnus-button-push (marker)
2853   ;; Push button starting at MARKER.
2854   (save-excursion
2855     (set-buffer gnus-article-buffer)
2856     (goto-char marker)
2857     (let* ((entry (gnus-button-entry))
2858            (inhibit-point-motion-hooks t)
2859            (fun (nth 3 entry))
2860            (args (mapcar (lambda (group)
2861                            (let ((string (match-string group)))
2862                              (gnus-set-text-properties
2863                               0 (length string) nil string)
2864                              string))
2865                          (nthcdr 4 entry))))
2866       (cond
2867        ((fboundp fun)
2868         (apply fun args))
2869        ((and (boundp fun)
2870              (fboundp (symbol-value fun)))
2871         (apply (symbol-value fun) args))
2872        (t
2873         (gnus-message 1 "You must define `%S' to use this button"
2874                       (cons fun args)))))))
2875
2876 (defun gnus-button-message-id (message-id)
2877   "Fetch MESSAGE-ID."
2878   (save-excursion
2879     (set-buffer gnus-summary-buffer)
2880     (gnus-summary-refer-article message-id)))
2881
2882 (defun gnus-button-fetch-group (address)
2883   "Fetch GROUP specified by ADDRESS."
2884   (if (not (string-match "[:/]" address))
2885       ;; This is just a simple group url.
2886       (gnus-group-read-ephemeral-group address gnus-select-method)
2887     (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
2888                            address))
2889         (error "Can't parse %s" address)
2890       (gnus-group-read-ephemeral-group
2891        (match-string 4 address)
2892        `(nntp ,(match-string 1 address)
2893               (nntp-address ,(match-string 1 address))
2894               (nntp-port-number ,(if (match-end 3)
2895                                      (match-string 3 address)
2896                                    "nntp")))))))
2897
2898 (defun gnus-split-string (string pattern)
2899   "Return a list of substrings of STRING which are separated by PATTERN."
2900   (let (parts (start 0))
2901     (while (string-match pattern string start)
2902       (setq parts (cons (substring string start (match-beginning 0)) parts)
2903             start (match-end 0)))
2904     (nreverse (cons (substring string start) parts))))
2905
2906 (defun gnus-url-parse-query-string (query &optional downcase)
2907   (let (retval pairs cur key val)
2908     (setq pairs (gnus-split-string query "&"))
2909     (while pairs
2910       (setq cur (car pairs)
2911             pairs (cdr pairs))
2912       (if (not (string-match "=" cur))
2913           nil                           ; Grace
2914         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2915               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2916         (if downcase
2917             (setq key (downcase key)))
2918         (setq cur (assoc key retval))
2919         (if cur
2920             (setcdr cur (cons val (cdr cur)))
2921           (setq retval (cons (list key val) retval)))))
2922     retval))
2923
2924 (defun gnus-url-unhex (x)
2925   (if (> x ?9)
2926       (if (>= x ?a)
2927           (+ 10 (- x ?a))
2928         (+ 10 (- x ?A)))
2929     (- x ?0)))
2930
2931 (defun gnus-url-unhex-string (str &optional allow-newlines)
2932   "Remove %XXX embedded spaces, etc in a url.
2933 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2934 decoding of carriage returns and line feeds in the string, which is normally
2935 forbidden in URL encoding."
2936   (setq str (or str ""))
2937   (let ((tmp "")
2938         (case-fold-search t))
2939     (while (string-match "%[0-9a-f][0-9a-f]" str)
2940       (let* ((start (match-beginning 0))
2941              (ch1 (gnus-url-unhex (elt str (+ start 1))))
2942              (code (+ (* 16 ch1)
2943                       (gnus-url-unhex (elt str (+ start 2))))))
2944         (setq tmp (concat
2945                    tmp (substring str 0 start)
2946                    (cond
2947                     (allow-newlines
2948                      (char-to-string code))
2949                     ((or (= code ?\n) (= code ?\r))
2950                      " ")
2951                     (t (char-to-string code))))
2952               str (substring str (match-end 0)))))
2953     (setq tmp (concat tmp str))
2954     tmp))
2955
2956 (defun gnus-url-mailto (url)
2957   ;; Send mail to someone
2958   (when (string-match "mailto:/*\\(.*\\)" url)
2959     (setq url (substring url (match-beginning 1) nil)))
2960   (let (to args source-url subject func)
2961     (if (string-match (regexp-quote "?") url)
2962         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2963               args (gnus-url-parse-query-string
2964                     (substring url (match-end 0) nil) t))
2965       (setq to (gnus-url-unhex-string url)))
2966     (setq args (cons (list "to" to) args)
2967           subject (cdr-safe (assoc "subject" args)))
2968     (message-mail)
2969     (while args
2970       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2971       (if (fboundp func)
2972           (funcall func)
2973         (message-position-on-field (caar args)))
2974       (insert (mapconcat 'identity (cdar args) ", "))
2975       (setq args (cdr args)))
2976     (if subject
2977         (message-goto-body)
2978       (message-goto-subject))))
2979
2980 (defun gnus-button-mailto (address)
2981   ;; Mail to ADDRESS.
2982   (set-buffer (gnus-copy-article-buffer))
2983   (message-reply address))
2984
2985 (defun gnus-button-reply (address)
2986   ;; Reply to ADDRESS.
2987   (message-reply address))
2988
2989 (defun gnus-button-url (address)
2990   "Browse ADDRESS."
2991   (funcall browse-url-browser-function address))
2992
2993 (defun gnus-button-embedded-url (address)
2994   "Browse ADDRESS."
2995   (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2996
2997 ;;; Next/prev buttons in the article buffer.
2998
2999 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3000 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3001
3002 (defvar gnus-prev-page-map nil)
3003 (unless gnus-prev-page-map
3004   (setq gnus-prev-page-map (make-sparse-keymap))
3005   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3006   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3007
3008 (defun gnus-insert-prev-page-button ()
3009   (let ((buffer-read-only nil))
3010     (gnus-eval-format
3011      gnus-prev-page-line-format nil
3012      `(gnus-prev t local-map ,gnus-prev-page-map
3013                  gnus-callback gnus-article-button-prev-page))))
3014
3015 (defvar gnus-next-page-map nil)
3016 (unless gnus-next-page-map
3017   (setq gnus-next-page-map (make-keymap))
3018   (suppress-keymap gnus-prev-page-map)
3019   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3020   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3021
3022 (defun gnus-button-next-page ()
3023   "Go to the next page."
3024   (interactive)
3025   (let ((win (selected-window)))
3026     (select-window (get-buffer-window gnus-article-buffer t))
3027     (gnus-article-next-page)
3028     (select-window win)))
3029
3030 (defun gnus-button-prev-page ()
3031   "Go to the prev page."
3032   (interactive)
3033   (let ((win (selected-window)))
3034     (select-window (get-buffer-window gnus-article-buffer t))
3035     (gnus-article-prev-page)
3036     (select-window win)))
3037
3038 (defun gnus-insert-next-page-button ()
3039   (let ((buffer-read-only nil))
3040     (gnus-eval-format gnus-next-page-line-format nil
3041                       `(gnus-next t local-map ,gnus-next-page-map
3042                                   gnus-callback
3043                                   gnus-article-button-next-page))))
3044
3045 (defun gnus-article-button-next-page (arg)
3046   "Go to the next page."
3047   (interactive "P")
3048   (let ((win (selected-window)))
3049     (select-window (get-buffer-window gnus-article-buffer t))
3050     (gnus-article-next-page)
3051     (select-window win)))
3052
3053 (defun gnus-article-button-prev-page (arg)
3054   "Go to the prev page."
3055   (interactive "P")
3056   (let ((win (selected-window)))
3057     (select-window (get-buffer-window gnus-article-buffer t))
3058     (gnus-article-prev-page)
3059     (select-window win)))
3060
3061 (gnus-ems-redefine)
3062
3063 (provide 'gnus-art)
3064
3065 (run-hooks 'gnus-art-load-hook)
3066
3067 ;;; gnus-art.el ends here