*** 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 (funcall function group headers
1402                                (symbol-value variable)))
1403         result)
1404     (setq
1405      result
1406      (cond
1407       ((eq filename 'default)
1408        default-name)
1409       (filename filename)
1410       (t
1411        (let* ((split-name (gnus-get-split-value gnus-split-methods))
1412               (prompt
1413                (format prompt
1414                        (if (and gnus-number-of-articles-to-be-saved
1415                                 (> gnus-number-of-articles-to-be-saved 1))
1416                            (format "these %d articles"
1417                                    gnus-number-of-articles-to-be-saved)
1418                          "this article")))
1419               (file
1420                ;; Let the split methods have their say.
1421                (cond
1422                 ;; No split name was found.
1423                 ((null split-name)
1424                  (read-file-name
1425                   (concat prompt " (default "
1426                           (file-name-nondirectory default-name) ") ")
1427                   (file-name-directory default-name)
1428                   default-name))
1429                 ;; A single group name is returned.
1430                 ((stringp split-name)
1431                  (setq default-name
1432                        (funcall function split-name headers
1433                                 (symbol-value variable)))
1434                  (read-file-name
1435                   (concat prompt " (default "
1436                           (file-name-nondirectory default-name) ") ")
1437                   (file-name-directory default-name)
1438                   default-name))
1439                 ;; A single split name was found
1440                 ((= 1 (length split-name))
1441                  (let* ((name (car split-name))
1442                         (dir (cond ((file-directory-p name)
1443                                     (file-name-as-directory name))
1444                                    ((file-exists-p name) name)
1445                                    (t gnus-article-save-directory))))
1446                    (read-file-name
1447                     (concat prompt " (default " name ") ")
1448                     dir name)))
1449                 ;; A list of splits was found.
1450                 (t
1451                  (setq split-name (nreverse split-name))
1452                  (let (result)
1453                    (let ((file-name-history
1454                           (nconc split-name file-name-history)))
1455                      (setq result
1456                            (expand-file-name
1457                             (read-file-name
1458                              (concat prompt " (`M-p' for defaults) ")
1459                              gnus-article-save-directory
1460                              (car split-name))
1461                             gnus-article-save-directory)))
1462                    (car (push result file-name-history)))))))
1463          ;; Create the directory.
1464          (gnus-make-directory (file-name-directory file))
1465          ;; If we have read a directory, we append the default file name.
1466          (when (file-directory-p file)
1467            (setq file (concat (file-name-as-directory file)
1468                               (file-name-nondirectory default-name))))
1469          ;; Possibly translate some characters.
1470          (nnheader-translate-file-chars file)))))
1471     (gnus-make-directory (file-name-directory result))
1472     (set variable result)))
1473
1474 (defun gnus-article-archive-name (group)
1475   "Return the first instance of an \"Archive-name\" in the current buffer."
1476   (let ((case-fold-search t))
1477     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1478       (nnheader-concat gnus-article-save-directory
1479                        (match-string 1)))))
1480
1481 (defun gnus-article-nndoc-name (group)
1482   "If GROUP is an nndoc group, return the name of the parent group."
1483   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1484     (gnus-group-get-parameter group 'save-article-group)))
1485
1486 (defun gnus-summary-save-in-rmail (&optional filename)
1487   "Append this article to Rmail file.
1488 Optional argument FILENAME specifies file name.
1489 Directory to save to is default to `gnus-article-save-directory'."
1490   (interactive)
1491   (gnus-set-global-variables)
1492   (setq filename (gnus-read-save-file-name
1493                   "Save %s in rmail file:" filename
1494                   gnus-rmail-save-name gnus-newsgroup-name
1495                   gnus-current-headers 'gnus-newsgroup-last-rmail))
1496   (gnus-eval-in-buffer-window gnus-save-article-buffer
1497     (save-excursion
1498       (save-restriction
1499         (widen)
1500         (gnus-output-to-rmail filename)))))
1501
1502 (defun gnus-summary-save-in-mail (&optional filename)
1503   "Append this article to Unix mail file.
1504 Optional argument FILENAME specifies file name.
1505 Directory to save to is default to `gnus-article-save-directory'."
1506   (interactive)
1507   (gnus-set-global-variables)
1508   (setq filename (gnus-read-save-file-name
1509                   "Save %s in Unix mail file:" filename
1510                   gnus-mail-save-name gnus-newsgroup-name
1511                   gnus-current-headers 'gnus-newsgroup-last-mail))
1512   (gnus-eval-in-buffer-window gnus-save-article-buffer
1513     (save-excursion
1514       (save-restriction
1515         (widen)
1516         (if (and (file-readable-p filename)
1517                  (mail-file-babyl-p filename))
1518             (gnus-output-to-rmail filename t)
1519           (gnus-output-to-mail filename))))))
1520
1521 (defun gnus-summary-save-in-file (&optional filename overwrite)
1522   "Append this article to file.
1523 Optional argument FILENAME specifies file name.
1524 Directory to save to is default to `gnus-article-save-directory'."
1525   (interactive)
1526   (gnus-set-global-variables)
1527   (setq filename (gnus-read-save-file-name
1528                   "Save %s in file:" filename
1529                   gnus-file-save-name gnus-newsgroup-name
1530                   gnus-current-headers 'gnus-newsgroup-last-file))
1531   (gnus-eval-in-buffer-window gnus-save-article-buffer
1532     (save-excursion
1533       (save-restriction
1534         (widen)
1535         (when (and overwrite
1536                    (file-exists-p filename))
1537           (delete-file filename))
1538         (gnus-output-to-file filename)))))
1539
1540 (defun gnus-summary-write-to-file (&optional filename)
1541   "Write this article to a file.
1542 Optional argument FILENAME specifies file name.
1543 The directory to save in defaults to `gnus-article-save-directory'."
1544   (interactive)
1545   (gnus-summary-save-in-file nil t))
1546
1547 (defun gnus-summary-save-body-in-file (&optional filename)
1548   "Append this article body to a file.
1549 Optional argument FILENAME specifies file name.
1550 The directory to save in defaults to `gnus-article-save-directory'."
1551   (interactive)
1552   (gnus-set-global-variables)
1553   (setq filename (gnus-read-save-file-name
1554                   "Save %s body in file:" filename
1555                   gnus-file-save-name gnus-newsgroup-name
1556                   gnus-current-headers 'gnus-newsgroup-last-file))
1557   (gnus-eval-in-buffer-window gnus-save-article-buffer
1558     (save-excursion
1559       (save-restriction
1560         (widen)
1561         (goto-char (point-min))
1562         (when (search-forward "\n\n" nil t)
1563           (narrow-to-region (point) (point-max)))
1564         (gnus-output-to-file filename)))))
1565
1566 (defun gnus-summary-save-in-pipe (&optional command)
1567   "Pipe this article to subprocess."
1568   (interactive)
1569   (gnus-set-global-variables)
1570   (setq command
1571         (cond ((eq command 'default)
1572                gnus-last-shell-command)
1573               (command command)
1574               (t (read-string
1575                   (format
1576                    "Shell command on %s: "
1577                    (if (and gnus-number-of-articles-to-be-saved
1578                             (> gnus-number-of-articles-to-be-saved 1))
1579                        (format "these %d articles"
1580                                gnus-number-of-articles-to-be-saved)
1581                      "this article"))
1582                   gnus-last-shell-command))))
1583   (when (string-equal command "")
1584     (setq command gnus-last-shell-command))
1585   (gnus-eval-in-buffer-window gnus-article-buffer
1586     (save-restriction
1587       (widen)
1588       (shell-command-on-region (point-min) (point-max) command nil)))
1589   (setq gnus-last-shell-command command))
1590
1591 ;;; Article file names when saving.
1592
1593 (defun gnus-capitalize-newsgroup (newsgroup)
1594   "Capitalize NEWSGROUP name."
1595   (when (not (zerop (length newsgroup)))
1596     (concat (char-to-string (upcase (aref newsgroup 0)))
1597             (substring newsgroup 1))))
1598
1599 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1600   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1601 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1602 Otherwise, it is like ~/News/news/group/num."
1603   (let ((default
1604           (expand-file-name
1605            (concat (if (gnus-use-long-file-name 'not-save)
1606                        (gnus-capitalize-newsgroup newsgroup)
1607                      (gnus-newsgroup-directory-form newsgroup))
1608                    "/" (int-to-string (mail-header-number headers)))
1609            gnus-article-save-directory)))
1610     (if (and last-file
1611              (string-equal (file-name-directory default)
1612                            (file-name-directory last-file))
1613              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1614         default
1615       (or last-file default))))
1616
1617 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1618   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1619 If variable `gnus-use-long-file-name' is non-nil, it is
1620 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1621   (let ((default
1622           (expand-file-name
1623            (concat (if (gnus-use-long-file-name 'not-save)
1624                        newsgroup
1625                      (gnus-newsgroup-directory-form newsgroup))
1626                    "/" (int-to-string (mail-header-number headers)))
1627            gnus-article-save-directory)))
1628     (if (and last-file
1629              (string-equal (file-name-directory default)
1630                            (file-name-directory last-file))
1631              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1632         default
1633       (or last-file default))))
1634
1635 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1636   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1637 If variable `gnus-use-long-file-name' is non-nil, it is
1638 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1639   (or last-file
1640       (expand-file-name
1641        (if (gnus-use-long-file-name 'not-save)
1642            (gnus-capitalize-newsgroup newsgroup)
1643          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1644        gnus-article-save-directory)))
1645
1646 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1647   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1648 If variable `gnus-use-long-file-name' is non-nil, it is
1649 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1650   (or last-file
1651       (expand-file-name
1652        (if (gnus-use-long-file-name 'not-save)
1653            newsgroup
1654          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1655        gnus-article-save-directory)))
1656
1657 (eval-and-compile
1658   (mapcar
1659    (lambda (func)
1660      (let (afunc gfunc)
1661        (if (consp func)
1662            (setq afunc (car func)
1663                  gfunc (cdr func))
1664          (setq afunc func
1665                gfunc (intern (format "gnus-%s" func))))
1666        (fset gfunc
1667              (if (not (fboundp afunc))
1668                  nil
1669                `(lambda (&optional interactive &rest args)
1670                   ,(documentation afunc t)
1671                   (interactive (list t))
1672                   (save-excursion
1673                     (set-buffer gnus-article-buffer)
1674                     (if interactive
1675                         (call-interactively ',afunc)
1676                       (apply ',afunc args))))))))
1677    '(article-hide-headers
1678      article-hide-boring-headers
1679      article-treat-overstrike
1680      (article-fill . gnus-article-word-wrap)
1681      article-remove-cr
1682      article-display-x-face
1683      article-de-quoted-unreadable
1684      article-mime-decode-quoted-printable
1685      article-hide-pgp
1686      article-hide-pem
1687      article-hide-signature
1688      article-remove-trailing-blank-lines
1689      article-strip-leading-blank-lines
1690      article-strip-multiple-blank-lines
1691      article-strip-leading-space
1692      article-strip-blank-lines
1693      article-date-local
1694      article-date-original
1695      article-date-ut
1696      article-date-user
1697      article-date-lapsed
1698      article-emphasize
1699      (article-show-all . gnus-article-show-all-headers))))
1700 \f
1701 ;;;
1702 ;;; Gnus article mode
1703 ;;;
1704
1705 (put 'gnus-article-mode 'mode-class 'special)
1706
1707 (when t
1708   (gnus-define-keys gnus-article-mode-map
1709     " " gnus-article-goto-next-page
1710     "\177" gnus-article-goto-prev-page
1711     [delete] gnus-article-goto-prev-page
1712     "\C-c^" gnus-article-refer-article
1713     "h" gnus-article-show-summary
1714     "s" gnus-article-show-summary
1715     "\C-c\C-m" gnus-article-mail
1716     "?" gnus-article-describe-briefly
1717     gnus-mouse-2 gnus-article-push-button
1718     "\r" gnus-article-press-button
1719     "\t" gnus-article-next-button
1720     "\M-\t" gnus-article-prev-button
1721     "e" gnus-article-edit
1722     "<" beginning-of-buffer
1723     ">" end-of-buffer
1724     "\C-c\C-i" gnus-info-find-node
1725     "\C-c\C-b" gnus-bug
1726
1727     "\C-d" gnus-article-read-summary-keys
1728     "\M-*" gnus-article-read-summary-keys
1729     "\M-#" gnus-article-read-summary-keys
1730     "\M-^" gnus-article-read-summary-keys
1731     "\M-g" gnus-article-read-summary-keys)
1732
1733   (substitute-key-definition
1734    'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1735
1736 (defun gnus-article-make-menu-bar ()
1737   (gnus-turn-off-edit-menu 'article)
1738   (unless (boundp 'gnus-article-article-menu)
1739     (easy-menu-define
1740      gnus-article-article-menu gnus-article-mode-map ""
1741      '("Article"
1742        ["Scroll forwards" gnus-article-goto-next-page t]
1743        ["Scroll backwards" gnus-article-goto-prev-page t]
1744        ["Show summary" gnus-article-show-summary t]
1745        ["Fetch Message-ID at point" gnus-article-refer-article t]
1746        ["Mail to address at point" gnus-article-mail t]))
1747
1748     (easy-menu-define
1749      gnus-article-treatment-menu gnus-article-mode-map ""
1750      '("Treatment"
1751        ["Hide headers" gnus-article-hide-headers t]
1752        ["Hide signature" gnus-article-hide-signature t]
1753        ["Hide citation" gnus-article-hide-citation t]
1754        ["Treat overstrike" gnus-article-treat-overstrike t]
1755        ["Remove carriage return" gnus-article-remove-cr t]
1756        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1757
1758     (when nil
1759       (when (boundp 'gnus-summary-article-menu)
1760         (define-key gnus-article-mode-map [menu-bar commands]
1761           (cons "Commands" gnus-summary-article-menu))))
1762
1763     (when (boundp 'gnus-summary-post-menu)
1764       (define-key gnus-article-mode-map [menu-bar post]
1765         (cons "Post" gnus-summary-post-menu)))
1766
1767     (run-hooks 'gnus-article-menu-hook)))
1768
1769 (defun gnus-article-mode ()
1770   "Major mode for displaying an article.
1771
1772 All normal editing commands are switched off.
1773
1774 The following commands are available in addition to all summary mode
1775 commands:
1776 \\<gnus-article-mode-map>
1777 \\[gnus-article-next-page]\t Scroll the article one page forwards
1778 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1779 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1780 \\[gnus-article-show-summary]\t Display the summary buffer
1781 \\[gnus-article-mail]\t Send a reply to the address near point
1782 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1783 \\[gnus-info-find-node]\t Go to the Gnus info node"
1784   (interactive)
1785   (when (gnus-visual-p 'article-menu 'menu)
1786     (gnus-article-make-menu-bar))
1787   (kill-all-local-variables)
1788   (gnus-simplify-mode-line)
1789   (setq mode-name "Article")
1790   (setq major-mode 'gnus-article-mode)
1791   (make-local-variable 'minor-mode-alist)
1792   (unless (assq 'gnus-show-mime minor-mode-alist)
1793     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1794   (use-local-map gnus-article-mode-map)
1795   (gnus-update-format-specifications nil 'article-mode)
1796   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1797   (set (make-local-variable 'gnus-button-marker-list) nil)
1798   (gnus-set-default-directory)
1799   (buffer-disable-undo (current-buffer))
1800   (setq buffer-read-only t)
1801   (set-syntax-table gnus-article-mode-syntax-table)
1802   (run-hooks 'gnus-article-mode-hook))
1803
1804 (defun gnus-article-setup-buffer ()
1805   "Initialize the article buffer."
1806   (let* ((name (if gnus-single-article-buffer "*Article*"
1807                  (concat "*Article " gnus-newsgroup-name "*")))
1808          (original
1809           (progn (string-match "\\*Article" name)
1810                  (concat " *Original Article"
1811                          (substring name (match-end 0))))))
1812     (setq gnus-article-buffer name)
1813     (setq gnus-original-article-buffer original)
1814     ;; This might be a variable local to the summary buffer.
1815     (unless gnus-single-article-buffer
1816       (save-excursion
1817         (set-buffer gnus-summary-buffer)
1818         (setq gnus-article-buffer name)
1819         (setq gnus-original-article-buffer original)
1820         (gnus-set-global-variables)))
1821     ;; Init original article buffer.
1822     (save-excursion
1823       (set-buffer (get-buffer-create gnus-original-article-buffer))
1824       (buffer-disable-undo (current-buffer))
1825       (setq major-mode 'gnus-original-article-mode)
1826       (gnus-add-current-to-buffer-list)
1827       (make-local-variable 'gnus-original-article))
1828     (if (get-buffer name)
1829         (save-excursion
1830           (set-buffer name)
1831           (buffer-disable-undo (current-buffer))
1832           (setq buffer-read-only t)
1833           (gnus-add-current-to-buffer-list)
1834           (unless (eq major-mode 'gnus-article-mode)
1835             (gnus-article-mode))
1836           (current-buffer))
1837       (save-excursion
1838         (set-buffer (get-buffer-create name))
1839         (gnus-add-current-to-buffer-list)
1840         (gnus-article-mode)
1841         (make-local-variable 'gnus-summary-buffer)
1842         (current-buffer)))))
1843
1844 ;; Set article window start at LINE, where LINE is the number of lines
1845 ;; from the head of the article.
1846 (defun gnus-article-set-window-start (&optional line)
1847   (set-window-start
1848    (get-buffer-window gnus-article-buffer t)
1849    (save-excursion
1850      (set-buffer gnus-article-buffer)
1851      (goto-char (point-min))
1852      (if (not line)
1853          (point-min)
1854        (gnus-message 6 "Moved to bookmark")
1855        (search-forward "\n\n" nil t)
1856        (forward-line line)
1857        (point)))))
1858
1859 (defun gnus-article-prepare (article &optional all-headers header)
1860   "Prepare ARTICLE in article mode buffer.
1861 ARTICLE should either be an article number or a Message-ID.
1862 If ARTICLE is an id, HEADER should be the article headers.
1863 If ALL-HEADERS is non-nil, no headers are hidden."
1864   (save-excursion
1865     ;; Make sure we start in a summary buffer.
1866     (unless (eq major-mode 'gnus-summary-mode)
1867       (set-buffer gnus-summary-buffer))
1868     (setq gnus-summary-buffer (current-buffer))
1869     ;; Make sure the connection to the server is alive.
1870     (unless (gnus-server-opened
1871              (gnus-find-method-for-group gnus-newsgroup-name))
1872       (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1873       (gnus-request-group gnus-newsgroup-name t))
1874     (let* ((gnus-article (if header (mail-header-number header) article))
1875            (summary-buffer (current-buffer))
1876            (internal-hook gnus-article-internal-prepare-hook)
1877            (group gnus-newsgroup-name)
1878            result)
1879       (save-excursion
1880         (gnus-article-setup-buffer)
1881         (set-buffer gnus-article-buffer)
1882         ;; Deactivate active regions.
1883         (when (and (boundp 'transient-mark-mode)
1884                    transient-mark-mode)
1885           (setq mark-active nil))
1886         (if (not (setq result (let ((buffer-read-only nil))
1887                                 (gnus-request-article-this-buffer
1888                                  article group))))
1889             ;; There is no such article.
1890             (save-excursion
1891               (when (and (numberp article)
1892                          (not (memq article gnus-newsgroup-sparse)))
1893                 (setq gnus-article-current
1894                       (cons gnus-newsgroup-name article))
1895                 (set-buffer gnus-summary-buffer)
1896                 (setq gnus-current-article article)
1897                 (gnus-summary-mark-article article gnus-canceled-mark))
1898               (unless (memq article gnus-newsgroup-sparse)
1899                 (gnus-error
1900                  1 "No such article (may have expired or been canceled)")))
1901           (if (or (eq result 'pseudo) (eq result 'nneething))
1902               (progn
1903                 (save-excursion
1904                   (set-buffer summary-buffer)
1905                   (setq gnus-last-article gnus-current-article
1906                         gnus-newsgroup-history (cons gnus-current-article
1907                                                      gnus-newsgroup-history)
1908                         gnus-current-article 0
1909                         gnus-current-headers nil
1910                         gnus-article-current nil)
1911                   (if (eq result 'nneething)
1912                       (gnus-configure-windows 'summary)
1913                     (gnus-configure-windows 'article))
1914                   (gnus-set-global-variables))
1915                 (gnus-set-mode-line 'article))
1916             ;; The result from the `request' was an actual article -
1917             ;; or at least some text that is now displayed in the
1918             ;; article buffer.
1919             (when (and (numberp article)
1920                        (not (eq article gnus-current-article)))
1921               ;; Seems like a new article has been selected.
1922               ;; `gnus-current-article' must be an article number.
1923               (save-excursion
1924                 (set-buffer summary-buffer)
1925                 (setq gnus-last-article gnus-current-article
1926                       gnus-newsgroup-history (cons gnus-current-article
1927                                                    gnus-newsgroup-history)
1928                       gnus-current-article article
1929                       gnus-current-headers
1930                       (gnus-summary-article-header gnus-current-article)
1931                       gnus-article-current
1932                       (cons gnus-newsgroup-name gnus-current-article))
1933                 (unless (vectorp gnus-current-headers)
1934                   (setq gnus-current-headers nil))
1935                 (gnus-summary-show-thread)
1936                 (run-hooks 'gnus-mark-article-hook)
1937                 (gnus-set-mode-line 'summary)
1938                 (when (gnus-visual-p 'article-highlight 'highlight)
1939                   (run-hooks 'gnus-visual-mark-article-hook))
1940                 ;; Set the global newsgroup variables here.
1941                 ;; Suggested by Jim Sisolak
1942                 ;; <sisolak@trans4.neep.wisc.edu>.
1943                 (gnus-set-global-variables)
1944                 (setq gnus-have-all-headers
1945                       (or all-headers gnus-show-all-headers))
1946                 (and gnus-use-cache
1947                      (vectorp (gnus-summary-article-header article))
1948                      (gnus-cache-possibly-enter-article
1949                       group article
1950                       (gnus-summary-article-header article)
1951                       (memq article gnus-newsgroup-marked)
1952                       (memq article gnus-newsgroup-dormant)
1953                       (memq article gnus-newsgroup-unreads)))))
1954             (when (or (numberp article)
1955                       (stringp article))
1956               ;; Hooks for getting information from the article.
1957               ;; This hook must be called before being narrowed.
1958               (let (buffer-read-only)
1959                 (run-hooks 'internal-hook)
1960                 (run-hooks 'gnus-article-prepare-hook)
1961                 ;; Decode MIME message.
1962                 (when gnus-show-mime
1963                   (if (or (not gnus-strict-mime)
1964                           (gnus-fetch-field "Mime-Version"))
1965                       (funcall gnus-show-mime-method)
1966                     (funcall gnus-decode-encoded-word-method)))
1967                 ;; Perform the article display hooks.
1968                 (run-hooks 'gnus-article-display-hook))
1969               ;; Do page break.
1970               (goto-char (point-min))
1971               (when gnus-break-pages
1972                 (gnus-narrow-to-page)))
1973             (gnus-set-mode-line 'article)
1974             (gnus-configure-windows 'article)
1975             (goto-char (point-min))
1976             t))))))
1977
1978 (defun gnus-article-wash-status ()
1979   "Return a string which display status of article washing."
1980   (save-excursion
1981     (set-buffer gnus-article-buffer)
1982     (let ((cite (gnus-article-hidden-text-p 'cite))
1983           (headers (gnus-article-hidden-text-p 'headers))
1984           (boring (gnus-article-hidden-text-p 'boring-headers))
1985           (pgp (gnus-article-hidden-text-p 'pgp))
1986           (pem (gnus-article-hidden-text-p 'pem))
1987           (signature (gnus-article-hidden-text-p 'signature))
1988           (overstrike (gnus-article-hidden-text-p 'overstrike))
1989           (emphasis (gnus-article-hidden-text-p 'emphasis))
1990           (mime gnus-show-mime))
1991       (format "%c%c%c%c%c%c%c"
1992               (if cite ?c ? )
1993               (if (or headers boring) ?h ? )
1994               (if (or pgp pem) ?p ? )
1995               (if signature ?s ? )
1996               (if overstrike ?o ? )
1997               (if mime ?m ? )
1998               (if emphasis ?e ? )))))
1999
2000 (defun gnus-article-hide-headers-if-wanted ()
2001   "Hide unwanted headers if `gnus-have-all-headers' is nil.
2002 Provided for backwards compatibility."
2003   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2004       gnus-inhibit-hiding
2005       (gnus-article-hide-headers)))
2006
2007 ;;; Article savers.
2008
2009 (defun gnus-output-to-file (file-name)
2010   "Append the current article to a file named FILE-NAME."
2011   (let ((artbuf (current-buffer)))
2012     (nnheader-temp-write nil
2013       (insert-buffer-substring artbuf)
2014       ;; Append newline at end of the buffer as separator, and then
2015       ;; save it to file.
2016       (goto-char (point-max))
2017       (insert "\n")
2018       (append-to-file (point-min) (point-max) file-name))))
2019
2020 (defun gnus-narrow-to-page (&optional arg)
2021   "Narrow the article buffer to a page.
2022 If given a numerical ARG, move forward ARG pages."
2023   (interactive "P")
2024   (setq arg (if arg (prefix-numeric-value arg) 0))
2025   (save-excursion
2026     (set-buffer gnus-article-buffer)
2027     (goto-char (point-min))
2028     (widen)
2029     ;; Remove any old next/prev buttons.
2030     (when (gnus-visual-p 'page-marker)
2031       (let ((buffer-read-only nil))
2032         (gnus-remove-text-with-property 'gnus-prev)
2033         (gnus-remove-text-with-property 'gnus-next)))
2034     (when
2035         (cond ((< arg 0)
2036                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2037               ((> arg 0)
2038                (re-search-forward page-delimiter nil 'move arg)))
2039       (goto-char (match-end 0)))
2040     (narrow-to-region
2041      (point)
2042      (if (re-search-forward page-delimiter nil 'move)
2043          (match-beginning 0)
2044        (point)))
2045     (when (and (gnus-visual-p 'page-marker)
2046                (not (= (point-min) 1)))
2047       (save-excursion
2048         (goto-char (point-min))
2049         (gnus-insert-prev-page-button)))
2050     (when (and (gnus-visual-p 'page-marker)
2051                (< (+ (point-max) 2) (buffer-size)))
2052       (save-excursion
2053         (goto-char (point-max))
2054         (gnus-insert-next-page-button)))))
2055
2056 ;; Article mode commands
2057
2058 (defun gnus-article-goto-next-page ()
2059   "Show the next page of the article."
2060   (interactive)
2061   (when (gnus-article-next-page)
2062     (goto-char (point-min))
2063     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2064
2065 (defun gnus-article-goto-prev-page ()
2066   "Show the next page of the article."
2067   (interactive)
2068   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2069     (gnus-article-prev-page nil)))
2070
2071 (defun gnus-article-next-page (&optional lines)
2072   "Show the next page of the current article.
2073 If end of article, return non-nil.  Otherwise return nil.
2074 Argument LINES specifies lines to be scrolled up."
2075   (interactive "p")
2076   (move-to-window-line -1)
2077   (if (save-excursion
2078         (end-of-line)
2079         (and (pos-visible-in-window-p)  ;Not continuation line.
2080              (eobp)))
2081       ;; Nothing in this page.
2082       (if (or (not gnus-break-pages)
2083               (save-excursion
2084                 (save-restriction
2085                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2086           t                             ;Nothing more.
2087         (gnus-narrow-to-page 1)         ;Go to next page.
2088         nil)
2089     ;; More in this page.
2090     (let ((scroll-in-place nil))
2091       (condition-case ()
2092           (scroll-up lines)
2093         (end-of-buffer
2094          ;; Long lines may cause an end-of-buffer error.
2095          (goto-char (point-max)))))
2096     (move-to-window-line 0)
2097     nil))
2098
2099 (defun gnus-article-prev-page (&optional lines)
2100   "Show previous page of current article.
2101 Argument LINES specifies lines to be scrolled down."
2102   (interactive "p")
2103   (move-to-window-line 0)
2104   (if (and gnus-break-pages
2105            (bobp)
2106            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2107       (progn
2108         (gnus-narrow-to-page -1)        ;Go to previous page.
2109         (goto-char (point-max))
2110         (recenter -1))
2111     (let ((scroll-in-place nil))
2112       (prog1
2113           (condition-case ()
2114               (scroll-down lines)
2115             (beginning-of-buffer
2116              (goto-char (point-min))))
2117         (move-to-window-line 0)))))
2118
2119 (defun gnus-article-refer-article ()
2120   "Read article specified by message-id around point."
2121   (interactive)
2122   (let ((point (point)))
2123     (search-forward ">" nil t)          ;Move point to end of "<....>".
2124     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2125         (let ((message-id (match-string 1)))
2126           (goto-char point)
2127           (set-buffer gnus-summary-buffer)
2128           (gnus-summary-refer-article message-id))
2129       (goto-char (point))
2130       (error "No references around point"))))
2131
2132 (defun gnus-article-show-summary ()
2133   "Reconfigure windows to show summary buffer."
2134   (interactive)
2135   (gnus-configure-windows 'article)
2136   (gnus-summary-goto-subject gnus-current-article))
2137
2138 (defun gnus-article-describe-briefly ()
2139   "Describe article mode commands briefly."
2140   (interactive)
2141   (gnus-message 6
2142                 (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")))
2143
2144 (defun gnus-article-summary-command ()
2145   "Execute the last keystroke in the summary buffer."
2146   (interactive)
2147   (let ((obuf (current-buffer))
2148         (owin (current-window-configuration))
2149         func)
2150     (switch-to-buffer gnus-summary-buffer 'norecord)
2151     (setq func (lookup-key (current-local-map) (this-command-keys)))
2152     (call-interactively func)
2153     (set-buffer obuf)
2154     (set-window-configuration owin)
2155     (set-window-point (get-buffer-window (current-buffer)) (point))))
2156
2157 (defun gnus-article-summary-command-nosave ()
2158   "Execute the last keystroke in the summary buffer."
2159   (interactive)
2160   (let (func)
2161     (pop-to-buffer gnus-summary-buffer 'norecord)
2162     (setq func (lookup-key (current-local-map) (this-command-keys)))
2163     (call-interactively func)))
2164
2165 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2166   "Read a summary buffer key sequence and execute it from the article buffer."
2167   (interactive "P")
2168   (let ((nosaves
2169          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
2170            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2171            "=" "^" "\M-^" "|"))
2172         (nosave-but-article
2173          '("A\r"))
2174         (nosave-in-article
2175          '("\C-d"))
2176         keys)
2177     (save-excursion
2178       (set-buffer gnus-summary-buffer)
2179       (let (gnus-pick-mode)
2180         (push (or key last-command-event) unread-command-events)
2181         (setq keys (read-key-sequence nil))))
2182     (message "")
2183
2184     (if (or (member keys nosaves)
2185             (member keys nosave-but-article)
2186             (member keys nosave-in-article))
2187         (let (func)
2188           (save-window-excursion
2189             (pop-to-buffer gnus-summary-buffer 'norecord)
2190             ;; We disable the pick minor mode commands.
2191             (let (gnus-pick-mode)
2192               (setq func (lookup-key (current-local-map) keys))))
2193           (if (not func)
2194               (ding)
2195             (unless (member keys nosave-in-article)
2196               (set-buffer gnus-summary-buffer))
2197             (call-interactively func))
2198           (when (member keys nosave-but-article)
2199             (pop-to-buffer gnus-article-buffer 'norecord)))
2200       ;; These commands should restore window configuration.
2201       (let ((obuf (current-buffer))
2202             (owin (current-window-configuration))
2203             (opoint (point))
2204             func in-buffer)
2205         (if not-restore-window
2206             (pop-to-buffer gnus-summary-buffer 'norecord)
2207           (switch-to-buffer gnus-summary-buffer 'norecord))
2208         (setq in-buffer (current-buffer))
2209         ;; We disable the pick minor mode commands.
2210         (if (setq func (let (gnus-pick-mode)
2211                          (lookup-key (current-local-map) keys)))
2212             (call-interactively func)
2213           (ding))
2214         (when (eq in-buffer (current-buffer))
2215           (set-buffer obuf)
2216           (unless not-restore-window
2217             (set-window-configuration owin))
2218           (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2219
2220 (defun gnus-article-hide (&optional arg force)
2221   "Hide all the gruft in the current article.
2222 This means that PGP stuff, signatures, cited text and (some)
2223 headers will be hidden.
2224 If given a prefix, show the hidden text instead."
2225   (interactive (list current-prefix-arg 'force))
2226   (gnus-article-hide-headers arg)
2227   (gnus-article-hide-pgp arg)
2228   (gnus-article-hide-citation-maybe arg force)
2229   (gnus-article-hide-signature arg))
2230
2231 (defun gnus-article-maybe-highlight ()
2232   "Do some article highlighting if `article-visual' is non-nil."
2233   (when (gnus-visual-p 'article-highlight 'highlight)
2234     (gnus-article-highlight-some)))
2235
2236 (defun gnus-request-article-this-buffer (article group)
2237   "Get an article and insert it into this buffer."
2238   (let (do-update-line)
2239     (prog1
2240         (save-excursion
2241           (erase-buffer)
2242           (gnus-kill-all-overlays)
2243           (setq group (or group gnus-newsgroup-name))
2244
2245           ;; Open server if it has closed.
2246           (gnus-check-server (gnus-find-method-for-group group))
2247
2248           ;; Using `gnus-request-article' directly will insert the article into
2249           ;; `nntp-server-buffer' - so we'll save some time by not having to
2250           ;; copy it from the server buffer into the article buffer.
2251
2252           ;; We only request an article by message-id when we do not have the
2253           ;; headers for it, so we'll have to get those.
2254           (when (stringp article)
2255             (let ((gnus-override-method gnus-refer-article-method))
2256               (gnus-read-header article)))
2257
2258           ;; If the article number is negative, that means that this article
2259           ;; doesn't belong in this newsgroup (possibly), so we find its
2260           ;; message-id and request it by id instead of number.
2261           (when (and (numberp article)
2262                      gnus-summary-buffer
2263                      (get-buffer gnus-summary-buffer)
2264                      (buffer-name (get-buffer gnus-summary-buffer)))
2265             (save-excursion
2266               (set-buffer gnus-summary-buffer)
2267               (let ((header (gnus-summary-article-header article)))
2268                 (when (< article 0)
2269                   (cond
2270                    ((memq article gnus-newsgroup-sparse)
2271                     ;; This is a sparse gap article.
2272                     (setq do-update-line article)
2273                     (setq article (mail-header-id header))
2274                     (let ((gnus-override-method gnus-refer-article-method))
2275                       (gnus-read-header article))
2276                     (setq gnus-newsgroup-sparse
2277                           (delq article gnus-newsgroup-sparse)))
2278                    ((vectorp header)
2279                     ;; It's a real article.
2280                     (setq article (mail-header-id header)))
2281                    (t
2282                     ;; It is an extracted pseudo-article.
2283                     (setq article 'pseudo)
2284                     (gnus-request-pseudo-article header))))
2285
2286                 (let ((method (gnus-find-method-for-group
2287                                gnus-newsgroup-name)))
2288                   (if (not (eq (car method) 'nneething))
2289                       ()
2290                     (let ((dir (concat (file-name-as-directory (nth 1 method))
2291                                        (mail-header-subject header))))
2292                       (when (file-directory-p dir)
2293                         (setq article 'nneething)
2294                         (gnus-group-enter-directory dir))))))))
2295
2296           (cond
2297            ;; Refuse to select canceled articles.
2298            ((and (numberp article)
2299                  gnus-summary-buffer
2300                  (get-buffer gnus-summary-buffer)
2301                  (buffer-name (get-buffer gnus-summary-buffer))
2302                  (eq (cdr (save-excursion
2303                             (set-buffer gnus-summary-buffer)
2304                             (assq article gnus-newsgroup-reads)))
2305                      gnus-canceled-mark))
2306             nil)
2307            ;; We first check `gnus-original-article-buffer'.
2308            ((and (get-buffer gnus-original-article-buffer)
2309                  (numberp article)
2310                  (save-excursion
2311                    (set-buffer gnus-original-article-buffer)
2312                    (and (equal (car gnus-original-article) group)
2313                         (eq (cdr gnus-original-article) article))))
2314             (insert-buffer-substring gnus-original-article-buffer)
2315             'article)
2316            ;; Check the backlog.
2317            ((and gnus-keep-backlog
2318                  (gnus-backlog-request-article group article (current-buffer)))
2319             'article)
2320            ;; Check asynchronous pre-fetch.
2321            ((gnus-async-request-fetched-article group article (current-buffer))
2322             (gnus-async-prefetch-next group article gnus-summary-buffer)
2323             'article)
2324            ;; Check the cache.
2325            ((and gnus-use-cache
2326                  (numberp article)
2327                  (gnus-cache-request-article article group))
2328             'article)
2329            ;; Get the article and put into the article buffer.
2330            ((or (stringp article) (numberp article))
2331             (let ((gnus-override-method
2332                    (and (stringp article) gnus-refer-article-method))
2333                   (buffer-read-only nil))
2334               (erase-buffer)
2335               (gnus-kill-all-overlays)
2336               (when (gnus-request-article article group (current-buffer))
2337                 (when (numberp article)
2338                   (gnus-async-prefetch-next group article gnus-summary-buffer)
2339                   (when gnus-keep-backlog
2340                     (gnus-backlog-enter-article
2341                      group article (current-buffer))))
2342                 'article)))
2343            ;; It was a pseudo.
2344            (t article)))
2345
2346       ;; Take the article from the original article buffer
2347       ;; and place it in the buffer it's supposed to be in.
2348       (when (and (get-buffer gnus-article-buffer)
2349                  ;;(numberp article)
2350                  (equal (buffer-name (current-buffer))
2351                         (buffer-name (get-buffer gnus-article-buffer))))
2352         (save-excursion
2353           (if (get-buffer gnus-original-article-buffer)
2354               (set-buffer (get-buffer gnus-original-article-buffer))
2355             (set-buffer (get-buffer-create gnus-original-article-buffer))
2356             (buffer-disable-undo (current-buffer))
2357             (setq major-mode 'gnus-original-article-mode)
2358             (setq buffer-read-only t)
2359             (gnus-add-current-to-buffer-list))
2360           (let (buffer-read-only)
2361             (erase-buffer)
2362             (insert-buffer-substring gnus-article-buffer))
2363           (setq gnus-original-article (cons group article))))
2364
2365       ;; Update sparse articles.
2366       (when (and do-update-line
2367                  (or (numberp article)
2368                      (stringp article)))
2369         (let ((buf (current-buffer)))
2370           (set-buffer gnus-summary-buffer)
2371           (gnus-summary-update-article do-update-line)
2372           (gnus-summary-goto-subject do-update-line nil t)
2373           (set-window-point (get-buffer-window (current-buffer) t)
2374                             (point))
2375           (set-buffer buf))))))
2376
2377 ;;;
2378 ;;; Article editing
2379 ;;;
2380
2381 (defcustom gnus-article-edit-mode-hook nil
2382   "Hook run in article edit mode buffers."
2383   :group 'gnus-article-various
2384   :type 'hook)
2385
2386 (defvar gnus-article-edit-done-function nil)
2387
2388 (defvar gnus-article-edit-mode-map nil)
2389
2390 (unless gnus-article-edit-mode-map
2391   (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2392
2393   (gnus-define-keys gnus-article-edit-mode-map
2394     "\C-c\C-c" gnus-article-edit-done
2395     "\C-c\C-k" gnus-article-edit-exit)
2396
2397   (gnus-define-keys (gnus-article-edit-wash-map
2398                      "\C-c\C-w" gnus-article-edit-mode-map)
2399     "f" gnus-article-edit-full-stops))
2400
2401 (defun gnus-article-edit-mode ()
2402   "Major mode for editing articles.
2403 This is an extended text-mode.
2404
2405 \\{gnus-article-edit-mode-map}"
2406   (interactive)
2407   (kill-all-local-variables)
2408   (setq major-mode 'gnus-article-edit-mode)
2409   (setq mode-name "Article Edit")
2410   (use-local-map gnus-article-edit-mode-map)
2411   (make-local-variable 'gnus-article-edit-done-function)
2412   (make-local-variable 'gnus-prev-winconf)
2413   (setq buffer-read-only nil)
2414   (buffer-enable-undo)
2415   (widen)
2416   (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2417
2418 (defun gnus-article-edit (&optional force)
2419   "Edit the current article.
2420 This will have permanent effect only in mail groups.
2421 If FORCE is non-nil, allow editing of articles even in read-only
2422 groups."
2423   (interactive "P")
2424   (when (and (not force)
2425              (gnus-group-read-only-p))
2426     (error "The current newsgroup does not support article editing."))
2427   (gnus-article-edit-article
2428    `(lambda ()
2429       (gnus-summary-edit-article-done
2430        ,(or (mail-header-references gnus-current-headers) "")
2431        ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2432
2433 (defun gnus-article-edit-article (exit-func)
2434   "Start editing the contents of the current article buffer."
2435   (let ((winconf (current-window-configuration)))
2436     (set-buffer gnus-article-buffer)
2437     (gnus-article-edit-mode)
2438     (set-text-properties (point-min) (point-max) nil)
2439     (gnus-configure-windows 'edit-article)
2440     (setq gnus-article-edit-done-function exit-func)
2441     (setq gnus-prev-winconf winconf)
2442     (gnus-message 6 "C-c C-c to end edits")))
2443
2444 (defun gnus-article-edit-done ()
2445   "Update the article edits and exit."
2446   (interactive)
2447   (let ((func gnus-article-edit-done-function)
2448         (buf (current-buffer))
2449         (start (window-start)))
2450     (gnus-article-edit-exit)
2451     (save-excursion
2452       (set-buffer buf)
2453       (let ((buffer-read-only nil))
2454         (funcall func)))
2455     (set-buffer buf)
2456     (set-window-start (get-buffer-window buf) start)
2457     (set-window-point (get-buffer-window buf) (point))))
2458
2459 (defun gnus-article-edit-exit ()
2460   "Exit the article editing without updating."
2461   (interactive)
2462   ;; We remove all text props from the article buffer.
2463   (let ((buf (format "%s" (buffer-string)))
2464         (curbuf (current-buffer))
2465         (p (point))
2466         (window-start (window-start)))
2467     (erase-buffer)
2468     (insert buf)
2469     (let ((winconf gnus-prev-winconf))
2470       (gnus-article-mode)
2471       ;; The cache and backlog have to be flushed somewhat.
2472       (when gnus-use-cache
2473         (gnus-cache-update-article
2474          (car gnus-article-current) (cdr gnus-article-current)))
2475       (when gnus-keep-backlog
2476         (gnus-backlog-remove-article
2477          (car gnus-article-current) (cdr gnus-article-current)))
2478       ;; Flush original article as well.
2479       (save-excursion
2480         (when (get-buffer gnus-original-article-buffer)
2481           (set-buffer gnus-original-article-buffer)
2482           (setq gnus-original-article nil)))
2483       (set-window-configuration winconf)
2484       ;; Tippy-toe some to make sure that point remains where it was.
2485       (let ((buf (current-buffer)))
2486         (set-buffer curbuf)
2487         (set-window-start (get-buffer-window (current-buffer)) window-start)
2488         (goto-char p)
2489         (set-buffer buf)))))
2490
2491 (defun gnus-article-edit-full-stops ()
2492   "Interactively repair spacing at end of sentences."
2493   (interactive)
2494   (save-excursion
2495     (goto-char (point-min))
2496     (search-forward-regexp "^$" nil t)
2497     (let ((case-fold-search nil))
2498       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2499
2500 ;;;
2501 ;;; Article highlights
2502 ;;;
2503
2504 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2505
2506 ;;; Internal Variables:
2507
2508 (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\\)"
2509   "Regular expression that matches URLs."
2510   :group 'gnus-article-buttons
2511   :type 'regexp)
2512
2513 (defcustom gnus-button-alist
2514   `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2515      gnus-button-message-id 2)
2516     ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*+\\)" 0 t gnus-button-message-id 1)
2517     ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2518      gnus-button-fetch-group 4)
2519     ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2520     ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2521      t gnus-button-message-id 3)
2522     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1)
2523     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2)
2524     ;; This is how URLs _should_ be embedded in text...
2525     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2526     ;; Raw URLs.
2527     (,gnus-button-url-regexp 0 t gnus-button-url 0))
2528   "Alist of regexps matching buttons in article bodies.
2529
2530 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2531 REGEXP: is the string matching text around the button,
2532 BUTTON: is the number of the regexp grouping actually matching the button,
2533 FORM: is a lisp expression which must eval to true for the button to
2534 be added,
2535 CALLBACK: is the function to call when the user push this button, and each
2536 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2537
2538 CALLBACK can also be a variable, in that case the value of that
2539 variable it the real callback function."
2540   :group 'gnus-article-buttons
2541   :type '(repeat (list regexp
2542                        (integer :tag "Button")
2543                        (sexp :tag "Form")
2544                        (function :tag "Callback")
2545                        (repeat :tag "Par"
2546                                :inline t
2547                                (integer :tag "Regexp group")))))
2548
2549 (defcustom gnus-header-button-alist
2550   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2551      0 t gnus-button-message-id 0)
2552     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2553     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2554      0 t gnus-button-mailto 0)
2555     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2556     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2557     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2558      gnus-button-message-id 3))
2559   "Alist of headers and regexps to match buttons in article heads.
2560
2561 This alist is very similar to `gnus-button-alist', except that each
2562 alist has an additional HEADER element first in each entry:
2563
2564 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2565
2566 HEADER is a regexp to match a header.  For a fuller explanation, see
2567 `gnus-button-alist'."
2568   :group 'gnus-article-buttons
2569   :group 'gnus-article-headers
2570   :type '(repeat (list (regexp :tag "Header")
2571                        regexp
2572                        (integer :tag "Button")
2573                        (sexp :tag "Form")
2574                        (function :tag "Callback")
2575                        (repeat :tag "Par"
2576                                :inline t
2577                                (integer :tag "Regexp group")))))
2578
2579 (defvar gnus-button-regexp nil)
2580 (defvar gnus-button-marker-list nil)
2581 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2582
2583 (defvar gnus-button-last nil)
2584 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2585
2586 ;;; Commands:
2587
2588 (defun gnus-article-push-button (event)
2589   "Check text under the mouse pointer for a callback function.
2590 If the text under the mouse pointer has a `gnus-callback' property,
2591 call it with the value of the `gnus-data' text property."
2592   (interactive "e")
2593   (set-buffer (window-buffer (posn-window (event-start event))))
2594   (let* ((pos (posn-point (event-start event)))
2595          (data (get-text-property pos 'gnus-data))
2596          (fun (get-text-property pos 'gnus-callback)))
2597     (when fun
2598       (funcall fun data))))
2599
2600 (defun gnus-article-press-button ()
2601   "Check text at point for a callback function.
2602 If the text at point has a `gnus-callback' property,
2603 call it with the value of the `gnus-data' text property."
2604   (interactive)
2605   (let* ((data (get-text-property (point) 'gnus-data))
2606          (fun (get-text-property (point) 'gnus-callback)))
2607     (when fun
2608       (funcall fun data))))
2609
2610 (defun gnus-article-prev-button (n)
2611   "Move point to N buttons backward.
2612 If N is negative, move forward instead."
2613   (interactive "p")
2614   (gnus-article-next-button (- n)))
2615
2616 (defun gnus-article-next-button (n)
2617   "Move point to N buttons forward.
2618 If N is negative, move backward instead."
2619   (interactive "p")
2620   (let ((function (if (< n 0) 'previous-single-property-change
2621                     'next-single-property-change))
2622         (inhibit-point-motion-hooks t)
2623         (backward (< n 0))
2624         (limit (if (< n 0) (point-min) (point-max))))
2625     (setq n (abs n))
2626     (while (and (not (= limit (point)))
2627                 (> n 0))
2628       ;; Skip past the current button.
2629       (when (get-text-property (point) 'gnus-callback)
2630         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2631       ;; Go to the next (or previous) button.
2632       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2633       ;; Put point at the start of the button.
2634       (when (and backward (not (get-text-property (point) 'gnus-callback)))
2635         (goto-char (funcall function (point) 'gnus-callback nil limit)))
2636       ;; Skip past intangible buttons.
2637       (when (get-text-property (point) 'intangible)
2638         (incf n))
2639       (decf n))
2640     (unless (zerop n)
2641       (gnus-message 5 "No more buttons"))
2642     n))
2643
2644 (defun gnus-article-highlight (&optional force)
2645   "Highlight current article.
2646 This function calls `gnus-article-highlight-headers',
2647 `gnus-article-highlight-citation',
2648 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2649 do the highlighting.  See the documentation for those functions."
2650   (interactive (list 'force))
2651   (gnus-article-highlight-headers)
2652   (gnus-article-highlight-citation force)
2653   (gnus-article-highlight-signature)
2654   (gnus-article-add-buttons force)
2655   (gnus-article-add-buttons-to-head))
2656
2657 (defun gnus-article-highlight-some (&optional force)
2658   "Highlight current article.
2659 This function calls `gnus-article-highlight-headers',
2660 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2661 do the highlighting.  See the documentation for those functions."
2662   (interactive (list 'force))
2663   (gnus-article-highlight-headers)
2664   (gnus-article-highlight-signature)
2665   (gnus-article-add-buttons))
2666
2667 (defun gnus-article-highlight-headers ()
2668   "Highlight article headers as specified by `gnus-header-face-alist'."
2669   (interactive)
2670   (save-excursion
2671     (set-buffer gnus-article-buffer)
2672     (save-restriction
2673       (let ((alist gnus-header-face-alist)
2674             (buffer-read-only nil)
2675             (case-fold-search t)
2676             (inhibit-point-motion-hooks t)
2677             entry regexp header-face field-face from hpoints fpoints)
2678         (message-narrow-to-head)
2679         (while (setq entry (pop alist))
2680           (goto-char (point-min))
2681           (setq regexp (concat "^\\("
2682                                (if (string-equal "" (nth 0 entry))
2683                                    "[^\t ]"
2684                                  (nth 0 entry))
2685                                "\\)")
2686                 header-face (nth 1 entry)
2687                 field-face (nth 2 entry))
2688           (while (and (re-search-forward regexp nil t)
2689                       (not (eobp)))
2690             (beginning-of-line)
2691             (setq from (point))
2692             (unless (search-forward ":" nil t)
2693               (forward-char 1))
2694             (when (and header-face
2695                        (not (memq (point) hpoints)))
2696               (push (point) hpoints)
2697               (gnus-put-text-property from (point) 'face header-face))
2698             (when (and field-face
2699                        (not (memq (setq from (point)) fpoints)))
2700               (push from fpoints)
2701               (if (re-search-forward "^[^ \t]" nil t)
2702                   (forward-char -2)
2703                 (goto-char (point-max)))
2704               (gnus-put-text-property from (point) 'face field-face))))))))
2705
2706 (defun gnus-article-highlight-signature ()
2707   "Highlight the signature in an article.
2708 It does this by highlighting everything after
2709 `gnus-signature-separator' using `gnus-signature-face'."
2710   (interactive)
2711   (save-excursion
2712     (set-buffer gnus-article-buffer)
2713     (let ((buffer-read-only nil)
2714           (inhibit-point-motion-hooks t))
2715       (save-restriction
2716         (when (and gnus-signature-face
2717                    (gnus-article-narrow-to-signature))
2718           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2719                             'face gnus-signature-face)
2720           (widen)
2721           (gnus-article-search-signature)
2722           (let ((start (match-beginning 0))
2723                 (end (set-marker (make-marker) (1+ (match-end 0)))))
2724             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2725                                      end)))))))
2726
2727 (defun gnus-button-in-region-p (b e prop)
2728   "Say whether PROP exists in the region."
2729   (text-property-not-all b e prop nil))
2730
2731 (defun gnus-article-add-buttons (&optional force)
2732   "Find external references in the article and make buttons of them.
2733 \"External references\" are things like Message-IDs and URLs, as
2734 specified by `gnus-button-alist'."
2735   (interactive (list 'force))
2736   (save-excursion
2737     (set-buffer gnus-article-buffer)
2738     (let ((buffer-read-only nil)
2739           (inhibit-point-motion-hooks t)
2740           (case-fold-search t)
2741           (alist gnus-button-alist)
2742           beg entry regexp)
2743       ;; Remove all old markers.
2744       (let (marker entry)
2745         (while (setq marker (pop gnus-button-marker-list))
2746           (goto-char marker)
2747           (when (setq entry (gnus-button-entry))
2748             (put-text-property (match-beginning (nth 1 entry))
2749                                (match-end (nth 1 entry))
2750                                'gnus-callback nil))
2751           (set-marker marker nil)))
2752       ;; We skip the headers.
2753       (goto-char (point-min))
2754       (unless (search-forward "\n\n" nil t)
2755         (goto-char (point-max)))
2756       (setq beg (point))
2757       (while (setq entry (pop alist))
2758         (setq regexp (car entry))
2759         (goto-char beg)
2760         (while (re-search-forward regexp nil t)
2761           (let* ((start (and entry (match-beginning (nth 1 entry))))
2762                  (end (and entry (match-end (nth 1 entry))))
2763                  (from (match-beginning 0)))
2764             (when (and (or (eq t (nth 2 entry))
2765                            (eval (nth 2 entry)))
2766                        (not (gnus-button-in-region-p
2767                              start end 'gnus-callback)))
2768               ;; That optional form returned non-nil, so we add the
2769               ;; button.
2770               (gnus-article-add-button
2771                start end 'gnus-button-push
2772                (car (push (set-marker (make-marker) from)
2773                           gnus-button-marker-list))))))))))
2774
2775 ;; Add buttons to the head of an article.
2776 (defun gnus-article-add-buttons-to-head ()
2777   "Add buttons to the head of the article."
2778   (interactive)
2779   (save-excursion
2780     (set-buffer gnus-article-buffer)
2781     (let ((buffer-read-only nil)
2782           (inhibit-point-motion-hooks t)
2783           (case-fold-search t)
2784           (alist gnus-header-button-alist)
2785           entry beg end)
2786       (nnheader-narrow-to-headers)
2787       (while alist
2788         ;; Each alist entry.
2789         (setq entry (car alist)
2790               alist (cdr alist))
2791         (goto-char (point-min))
2792         (while (re-search-forward (car entry) nil t)
2793           ;; Each header matching the entry.
2794           (setq beg (match-beginning 0))
2795           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2796                              (match-beginning 0))
2797                         (point-max)))
2798           (goto-char beg)
2799           (while (re-search-forward (nth 1 entry) end t)
2800             ;; Each match within a header.
2801             (let* ((entry (cdr entry))
2802                    (start (match-beginning (nth 1 entry)))
2803                    (end (match-end (nth 1 entry)))
2804                    (form (nth 2 entry)))
2805               (goto-char (match-end 0))
2806               (when (eval form)
2807                 (gnus-article-add-button
2808                  start end (nth 3 entry)
2809                  (buffer-substring (match-beginning (nth 4 entry))
2810                                    (match-end (nth 4 entry)))))))
2811           (goto-char end))))
2812     (widen)))
2813
2814 ;;; External functions:
2815
2816 (defun gnus-article-add-button (from to fun &optional data)
2817   "Create a button between FROM and TO with callback FUN and data DATA."
2818   (when gnus-article-button-face
2819     (gnus-overlay-put (gnus-make-overlay from to)
2820                       'face gnus-article-button-face))
2821   (gnus-add-text-properties
2822    from to
2823    (nconc (and gnus-article-mouse-face
2824                (list gnus-mouse-face-prop gnus-article-mouse-face))
2825           (list 'gnus-callback fun)
2826           (and data (list 'gnus-data data)))))
2827
2828 ;;; Internal functions:
2829
2830 (defun gnus-signature-toggle (end)
2831   (save-excursion
2832     (set-buffer gnus-article-buffer)
2833     (let ((buffer-read-only nil)
2834           (inhibit-point-motion-hooks t))
2835       (if (get-text-property end 'invisible)
2836           (gnus-article-unhide-text end (point-max))
2837         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2838
2839 (defun gnus-button-entry ()
2840   ;; Return the first entry in `gnus-button-alist' matching this place.
2841   (let ((alist gnus-button-alist)
2842         (entry nil))
2843     (while alist
2844       (setq entry (pop alist))
2845       (if (looking-at (car entry))
2846           (setq alist nil)
2847         (setq entry nil)))
2848     entry))
2849
2850 (defun gnus-button-push (marker)
2851   ;; Push button starting at MARKER.
2852   (save-excursion
2853     (set-buffer gnus-article-buffer)
2854     (goto-char marker)
2855     (let* ((entry (gnus-button-entry))
2856            (inhibit-point-motion-hooks t)
2857            (fun (nth 3 entry))
2858            (args (mapcar (lambda (group)
2859                            (let ((string (match-string group)))
2860                              (gnus-set-text-properties
2861                               0 (length string) nil string)
2862                              string))
2863                          (nthcdr 4 entry))))
2864       (cond
2865        ((fboundp fun)
2866         (apply fun args))
2867        ((and (boundp fun)
2868              (fboundp (symbol-value fun)))
2869         (apply (symbol-value fun) args))
2870        (t
2871         (gnus-message 1 "You must define `%S' to use this button"
2872                       (cons fun args)))))))
2873
2874 (defun gnus-button-message-id (message-id)
2875   "Fetch MESSAGE-ID."
2876   (save-excursion
2877     (set-buffer gnus-summary-buffer)
2878     (gnus-summary-refer-article message-id)))
2879
2880 (defun gnus-button-fetch-group (address)
2881   "Fetch GROUP specified by ADDRESS."
2882   (if (not (string-match "[:/]" address))
2883       ;; This is just a simple group url.
2884       (gnus-group-read-ephemeral-group address gnus-select-method)
2885     (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
2886                            address))
2887         (error "Can't parse %s" address)
2888       (gnus-group-read-ephemeral-group
2889        (match-string 4 address)
2890        `(nntp ,(match-string 1 address)
2891               (nntp-address ,(match-string 1 address))
2892               (nntp-port-number ,(if (match-end 3)
2893                                      (match-string 3 address)
2894                                    "nntp")))))))
2895
2896 (defun gnus-split-string (string pattern)
2897   "Return a list of substrings of STRING which are separated by PATTERN."
2898   (let (parts (start 0))
2899     (while (string-match pattern string start)
2900       (setq parts (cons (substring string start (match-beginning 0)) parts)
2901             start (match-end 0)))
2902     (nreverse (cons (substring string start) parts))))
2903
2904 (defun gnus-url-parse-query-string (query &optional downcase)
2905   (let (retval pairs cur key val)
2906     (setq pairs (gnus-split-string query "&"))
2907     (while pairs
2908       (setq cur (car pairs)
2909             pairs (cdr pairs))
2910       (if (not (string-match "=" cur))
2911           nil                           ; Grace
2912         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2913               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2914         (if downcase
2915             (setq key (downcase key)))
2916         (setq cur (assoc key retval))
2917         (if cur
2918             (setcdr cur (cons val (cdr cur)))
2919           (setq retval (cons (list key val) retval)))))
2920     retval))
2921
2922 (defun gnus-url-unhex (x)
2923   (if (> x ?9)
2924       (if (>= x ?a)
2925           (+ 10 (- x ?a))
2926         (+ 10 (- x ?A)))
2927     (- x ?0)))
2928
2929 (defun gnus-url-unhex-string (str &optional allow-newlines)
2930   "Remove %XXX embedded spaces, etc in a url.
2931 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2932 decoding of carriage returns and line feeds in the string, which is normally
2933 forbidden in URL encoding."
2934   (setq str (or str ""))
2935   (let ((tmp "")
2936         (case-fold-search t))
2937     (while (string-match "%[0-9a-f][0-9a-f]" str)
2938       (let* ((start (match-beginning 0))
2939              (ch1 (gnus-url-unhex (elt str (+ start 1))))
2940              (code (+ (* 16 ch1)
2941                       (gnus-url-unhex (elt str (+ start 2))))))
2942         (setq tmp (concat
2943                    tmp (substring str 0 start)
2944                    (cond
2945                     (allow-newlines
2946                      (char-to-string code))
2947                     ((or (= code ?\n) (= code ?\r))
2948                      " ")
2949                     (t (char-to-string code))))
2950               str (substring str (match-end 0)))))
2951     (setq tmp (concat tmp str))
2952     tmp))
2953
2954 (defun gnus-url-mailto (url)
2955   ;; Send mail to someone
2956   (when (string-match "mailto:/*\\(.*\\)" url)
2957     (setq url (substring url (match-beginning 1) nil)))
2958   (let (to args source-url subject func)
2959     (if (string-match (regexp-quote "?") url)
2960         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2961               args (gnus-url-parse-query-string
2962                     (substring url (match-end 0) nil) t))
2963       (setq to (gnus-url-unhex-string url)))
2964     (setq args (cons (list "to" to) args)
2965           subject (cdr-safe (assoc "subject" args)))
2966     (message-mail)
2967     (while args
2968       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2969       (if (fboundp func)
2970           (funcall func)
2971         (message-position-on-field (caar args)))
2972       (insert (mapconcat 'identity (cdar args) ", "))
2973       (setq args (cdr args)))
2974     (if subject
2975         (message-goto-body)
2976       (message-goto-subject))))
2977
2978 (defun gnus-button-mailto (address)
2979   ;; Mail to ADDRESS.
2980   (set-buffer (gnus-copy-article-buffer))
2981   (message-reply address))
2982
2983 (defun gnus-button-reply (address)
2984   ;; Reply to ADDRESS.
2985   (message-reply address))
2986
2987 (defun gnus-button-url (address)
2988   "Browse ADDRESS."
2989   (funcall browse-url-browser-function address))
2990
2991 (defun gnus-button-embedded-url (address)
2992   "Browse ADDRESS."
2993   (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2994
2995 ;;; Next/prev buttons in the article buffer.
2996
2997 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
2998 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
2999
3000 (defvar gnus-prev-page-map nil)
3001 (unless gnus-prev-page-map
3002   (setq gnus-prev-page-map (make-sparse-keymap))
3003   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3004   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3005
3006 (defun gnus-insert-prev-page-button ()
3007   (let ((buffer-read-only nil))
3008     (gnus-eval-format
3009      gnus-prev-page-line-format nil
3010      `(gnus-prev t local-map ,gnus-prev-page-map
3011                  gnus-callback gnus-article-button-prev-page))))
3012
3013 (defvar gnus-next-page-map nil)
3014 (unless gnus-next-page-map
3015   (setq gnus-next-page-map (make-keymap))
3016   (suppress-keymap gnus-prev-page-map)
3017   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3018   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3019
3020 (defun gnus-button-next-page ()
3021   "Go to the next page."
3022   (interactive)
3023   (let ((win (selected-window)))
3024     (select-window (get-buffer-window gnus-article-buffer t))
3025     (gnus-article-next-page)
3026     (select-window win)))
3027
3028 (defun gnus-button-prev-page ()
3029   "Go to the prev page."
3030   (interactive)
3031   (let ((win (selected-window)))
3032     (select-window (get-buffer-window gnus-article-buffer t))
3033     (gnus-article-prev-page)
3034     (select-window win)))
3035
3036 (defun gnus-insert-next-page-button ()
3037   (let ((buffer-read-only nil))
3038     (gnus-eval-format gnus-next-page-line-format nil
3039                       `(gnus-next t local-map ,gnus-next-page-map
3040                                   gnus-callback
3041                                   gnus-article-button-next-page))))
3042
3043 (defun gnus-article-button-next-page (arg)
3044   "Go to the next page."
3045   (interactive "P")
3046   (let ((win (selected-window)))
3047     (select-window (get-buffer-window gnus-article-buffer t))
3048     (gnus-article-next-page)
3049     (select-window win)))
3050
3051 (defun gnus-article-button-prev-page (arg)
3052   "Go to the prev page."
3053   (interactive "P")
3054   (let ((win (selected-window)))
3055     (select-window (get-buffer-window gnus-article-buffer t))
3056     (gnus-article-prev-page)
3057     (select-window win)))
3058
3059 (gnus-ems-redefine)
3060
3061 (provide 'gnus-art)
3062
3063 (run-hooks 'gnus-art-load-hook)
3064
3065 ;;; gnus-art.el ends here