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