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