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