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