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