1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
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)
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.
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.
39 (defcustom gnus-ignored-headers
40 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
41 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
42 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
43 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
44 "All headers that match this regexp will be hidden.
45 This variable can also be a list of regexps of headers to be ignored.
46 If `gnus-visible-headers' is non-nil, this variable will be ignored."
47 :type '(choice :custom-show nil
52 (defcustom gnus-visible-headers
53 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-"
54 "All headers that do not match this regexp will be hidden.
55 This variable can also be a list of regexp of headers to remain visible.
56 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
57 :type '(repeat :value-to-internal (lambda (widget value)
58 (custom-split-regexp-maybe value))
59 :match (lambda (widget value)
61 (widget-editable-list-match widget value)))
65 (defcustom gnus-sorted-header-list
66 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:"
67 "^Cc:" "^Date:" "^Organization:")
68 "This variable is a list of regular expressions.
69 If it is non-nil, headers that match the regular expressions will
70 be placed first in the article buffer in the sequence specified by
72 :type '(repeat regexp)
75 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
76 "Headers that are only to be displayed if they have interesting data.
77 Possible values in this list are `empty', `newsgroups', `followup-to',
78 `reply-to', and `date'."
79 :type '(set (const :tag "Headers with no content." empty)
80 (const :tag "Newsgroups with only one group." newsgroups)
81 (const :tag "Followup-to identical to newsgroups." followup-to)
82 (const :tag "Reply-to identical to from." reply-to)
83 (const :tag "Date less than four days old." date))
86 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
87 "Regexp matching signature separator.
88 This can also be a list of regexps. In that case, it will be checked
89 from head to tail looking for a separator. Searches will be done from
90 the end of the buffer."
91 :type '(repeat string)
94 (defcustom gnus-signature-limit nil
95 "Provide a limit to what is considered a signature.
96 If it is a number, no signature may not be longer (in characters) than
97 that number. If it is a floating point number, no signature may be
98 longer (in lines) than that number. If it is a function, the function
99 will be called without any parameters, and if it returns nil, there is
100 no signature in the buffer. If it is a string, it will be used as a
101 regexp. If it matches, the text in question is not a signature."
102 :type '(choice integer number function regexp)
105 (defcustom gnus-hidden-properties '(invisible t intangible t)
106 "Property list to use for hiding text."
110 (defcustom gnus-article-x-face-command
111 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
112 "String or function to be executed to display an X-Face header.
113 If it is a string, the command will be executed in a sub-shell
114 asynchronously. The compressed face will be piped to this command."
115 :type 'string ;Leave function case to Lisp.
118 (defcustom gnus-article-x-face-too-ugly nil
119 "Regexp matching posters whose face shouldn't be shown automatically."
123 (defcustom gnus-emphasis-alist
125 "\\(\\s-\\|^\\|[-\"\(]\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*\\)%s\\)\\(\\s-\\|[-?!.,;:\"\)]\\)")
127 '(("_" "_" underline)
130 ("_/" "/_" underline-italic)
131 ("_\\*" "\\*_" underline-bold)
132 ("\\*/" "/\\*" bold-italic)
133 ("_\\*/" "/\\*_" underline-bold-italic))))
134 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
135 2 3 gnus-emphasis-underline)
139 (format format (car spec) (cadr spec))
140 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
142 "Alist that says how to fontify certain phrases.
143 Each item looks like this:
145 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
147 The first element is a regular expression to be matched. The second
148 is a number that says what regular expression grouping used to find
149 the entire emphasized word. The third is a number that says what
150 regexp grouping should be displayed and highlighted. The fourth
151 is the face used for highlighting."
152 :type '(repeat (list :value ("" 0 0 default)
154 (integer :tag "Match group")
155 (integer :tag "Emphasize group")
159 (defface gnus-emphasis-bold '((t (:bold t)))
160 "Face used for displaying strong emphasized text (*word*)."
163 (defface gnus-emphasis-italic '((t (:italic t)))
164 "Face used for displaying italic emphasized text (/word/)."
167 (defface gnus-emphasis-underline '((t (:underline t)))
168 "Face used for displaying underlined emphasized text (_word_)."
171 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
172 "Face used for displaying underlined bold emphasized text (_*word*_)."
175 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
176 "Face used for displaying underlined italic emphasized text (_*word*_)."
179 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
180 "Face used for displaying bold italic emphasized text (/*word*/)."
183 (defface gnus-emphasis-underline-bold-italic
184 '((t (:bold t :italic t :underline t)))
185 "Face used for displaying underlined bold italic emphasized text (_/*word*/_)."
189 (autoload 'hexl-hex-string-to-integer "hexl")
190 (autoload 'timezone-make-date-arpa-standard "timezone")
191 (autoload 'mail-extract-address-components "mail-extr"))
193 (defcustom gnus-article-save-directory gnus-directory
194 "*Name of the directory articles will be saved in (default \"~/News\")."
198 (defcustom gnus-save-all-headers t
199 "*If non-nil, don't remove any headers before saving."
203 (defcustom gnus-prompt-before-saving 'always
204 "*This variable says how much prompting is to be done when saving articles.
205 If it is nil, no prompting will be done, and the articles will be
206 saved to the default files. If this variable is `always', each and
207 every article that is saved will be preceded by a prompt, even when
208 saving large batches of articles. If this variable is neither nil not
209 `always', there the user will be prompted once for a file name for
210 each invocation of the saving commands."
212 :type '(choice (item always)
213 (item :tag "never" nil)
214 (sexp :tag "once" :format "%t")))
216 (defcustom gnus-saved-headers gnus-visible-headers
217 "Headers to keep if `gnus-save-all-headers' is nil.
218 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
219 If that variable is nil, however, all headers that match this regexp
220 will be kept while the rest will be deleted before saving."
222 :type '(repeat string))
224 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
225 "A function to save articles in your favourite format.
226 The function must be interactively callable (in other words, it must
227 be an Emacs command).
229 Gnus provides the following functions:
231 * gnus-summary-save-in-rmail (Rmail format)
232 * gnus-summary-save-in-mail (Unix mail format)
233 * gnus-summary-save-in-folder (MH folder)
234 * gnus-summary-save-in-file (article format)
235 * gnus-summary-save-in-vm (use VM's folder format)
236 * gnus-summary-write-to-file (article format -- overwrite)."
238 :type '(radio (function-item gnus-summary-save-in-rmail)
239 (function-item gnus-summary-save-in-mail)
240 (function-item gnus-summary-save-in-folder)
241 (function-item gnus-summary-save-in-file)
242 (function-item gnus-summary-save-in-vm)
243 (function-item gnus-summary-write-to-file)))
245 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
246 "A function generating a file name to save articles in Rmail format.
247 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
251 (defcustom gnus-mail-save-name 'gnus-plain-save-name
252 "A function generating a file name to save articles in Unix mail format.
253 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
257 (defcustom gnus-folder-save-name 'gnus-folder-save-name
258 "A function generating a file name to save articles in MH folder.
259 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
263 (defcustom gnus-file-save-name 'gnus-numeric-save-name
264 "A function generating a file name to save articles in article format.
265 The function is called with NEWSGROUP, HEADERS, and optional
270 (defcustom gnus-split-methods
271 '((gnus-article-archive-name))
272 "Variable used to suggest where articles are to be saved.
273 For instance, if you would like to save articles related to Gnus in
274 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
275 you could set this variable to something like:
277 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
278 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
280 This variable is an alist where the where the key is the match and the
281 value is a list of possible files to save in if the match is non-nil.
283 If the match is a string, it is used as a regexp match on the
284 article. If the match is a symbol, that symbol will be funcalled
285 from the buffer of the article to be saved with the newsgroup as the
286 parameter. If it is a list, it will be evaled in the same buffer.
288 If this form or function returns a string, this string will be used as
289 a possible file name; and if it returns a non-nil list, that list will
290 be used as possible file names."
292 :type '(repeat (choice (list function)
293 (cons regexp (repeat string))
296 (defcustom gnus-strict-mime t
297 "*If nil, MIME-decode even if there is no Mime-Version header."
301 (defcustom gnus-show-mime-method 'metamail-buffer
302 "Function to process a MIME message.
303 The function is called from the article buffer."
307 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
308 "*Function to decode MIME encoded words.
309 The function is called from the article buffer."
313 (defcustom gnus-page-delimiter "^\^L"
314 "*Regexp describing what to use as article page delimiters.
315 The default value is \"^\^L\", which is a form linefeed at the
316 beginning of a line."
320 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
321 "*The format specification for the article mode line.
322 See `gnus-summary-mode-line-format' for a closer description."
326 (defcustom gnus-article-mode-hook nil
327 "*A hook for Gnus article mode."
331 (defcustom gnus-article-menu-hook nil
332 "*Hook run after the creation of the article mode menu."
336 (defcustom gnus-article-prepare-hook nil
337 "*A hook called after an article has been prepared in the article buffer.
338 If you want to run a special decoding program like nkf, use this hook."
342 (defcustom gnus-article-button-face 'bold
343 "Face used for highlighting buttons in the article buffer.
345 An article button is a piece of text that you can activate by pressing
346 `RET' or `mouse-2' above it."
350 (defcustom gnus-article-mouse-face 'highlight
351 "Face used for mouse highlighting in the article buffer.
353 Article buttons will be displayed in this face when the cursor is
358 (defcustom gnus-signature-face 'italic
359 "Face used for highlighting a signature in the article buffer."
363 (defface gnus-header-from-face
366 (:foreground "light blue" :bold t :italic t))
369 (:foreground "MidnightBlue" :bold t :italic t))
371 (:bold t :italic t)))
372 "Face used for displaying from headers."
375 (defface gnus-header-subject-face
378 (:foreground "pink" :bold t :italic t))
381 (:foreground "firebrick" :bold t :italic t))
383 (:bold t :italic t)))
384 "Face used for displaying subject headers."
387 (defface gnus-header-newsgroups-face
390 (:foreground "yellow" :bold t :italic t))
393 (:foreground "indianred" :bold t :italic t))
395 (:bold t :italic t)))
396 "Face used for displaying newsgroups headers."
399 (defface gnus-header-name-face
402 (:foreground "cyan" :bold t))
405 (:foreground "DarkGreen" :bold t))
408 "Face used for displaying header names."
411 (defface gnus-header-content-face
414 (:foreground "forest green" :italic t))
417 (:foreground "DarkGreen" :italic t))
419 (:italic t))) "Face used for displaying header content."
422 (defcustom gnus-header-face-alist
423 '(("From" nil gnus-header-from-face)
424 ("Subject" nil gnus-header-subject-face)
425 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
426 ("" gnus-header-name-face gnus-header-content-face))
427 "Controls highlighting of article header.
429 An alist of the form (HEADER NAME CONTENT).
431 HEADER is a regular expression which should match the name of an
432 header header and NAME and CONTENT are either face names or nil.
434 The name of each header field will be displayed using the face
435 specified by the first element in the list where HEADER match the
436 header name and NAME is non-nil. Similarly, the content will be
437 displayed by the first non-nil matching CONTENT face."
439 :type '(repeat (list (regexp :tag "Header")
441 (item :tag "skip" nil)
442 (face :value default))
443 (choice :tag "Content"
444 (item :tag "skip" nil)
445 (face :value default)))))
447 ;;; Internal variables
449 (defvar gnus-article-mode-syntax-table
450 (let ((table (copy-syntax-table text-mode-syntax-table)))
451 ;;(modify-syntax-entry ?_ "w" table)
453 "Syntax table used in article mode buffers.
454 Initialized from `text-mode-syntax-table.")
456 (defvar gnus-save-article-buffer nil)
458 (defvar gnus-article-mode-line-format-alist
459 (nconc '((?w (gnus-article-wash-status) ?s))
460 gnus-summary-mode-line-format-alist))
462 (defvar gnus-number-of-articles-to-be-saved nil)
464 (defvar gnus-inhibit-hiding nil)
465 (defvar gnus-newsgroup-name)
467 (defsubst gnus-article-hide-text (b e props)
468 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
469 (add-text-properties b e props)
470 (when (memq 'intangible props)
472 (max (1- b) (point-min))
473 b 'intangible (cddr (memq 'intangible props)))))
475 (defsubst gnus-article-unhide-text (b e)
476 "Remove hidden text properties from region between B and E."
477 (remove-text-properties b e gnus-hidden-properties)
478 (when (memq 'intangible gnus-hidden-properties)
479 (put-text-property (max (1- b) (point-min))
482 (defun gnus-article-hide-text-type (b e type)
483 "Hide text of TYPE between B and E."
484 (gnus-article-hide-text
485 b e (cons 'article-type (cons type gnus-hidden-properties))))
487 (defun gnus-article-unhide-text-type (b e type)
488 "Hide text of TYPE between B and E."
489 (remove-text-properties
490 b e (cons 'article-type (cons type gnus-hidden-properties)))
491 (when (memq 'intangible gnus-hidden-properties)
492 (put-text-property (max (1- b) (point-min))
495 (defun gnus-article-hide-text-of-type (type)
496 "Hide text of TYPE in the current buffer."
498 (let ((b (point-min))
500 (while (setq b (text-property-any b e 'article-type type))
501 (add-text-properties b (incf b) gnus-hidden-properties)))))
503 (defun gnus-article-delete-text-of-type (type)
504 "Delete text of TYPE in the current buffer."
506 (let ((b (point-min)))
507 (while (setq b (text-property-any b (point-max) 'article-type type))
508 (delete-region b (incf b))))))
510 (defun gnus-article-delete-invisible-text ()
511 "Delete all invisible text in the current buffer."
513 (let ((b (point-min)))
514 (while (setq b (text-property-any b (point-max) 'invisible t))
515 (delete-region b (incf b))))))
517 (defun gnus-article-text-type-exists-p (type)
518 "Say whether any text of type TYPE exists in the buffer."
519 (text-property-any (point-min) (point-max) 'article-type type))
521 (defsubst gnus-article-header-rank ()
522 "Give the rank of the string HEADER as given by `article-sorted-header-list'."
523 (let ((list gnus-sorted-header-list)
526 (when (looking-at (car list))
528 (setq list (cdr list))
532 (defun gnus-article-hide-headers (&optional arg delete)
533 "Toggle whether to hide unwanted headers and possibly sort them as well.
534 If given a negative prefix, always show; if given a positive prefix,
536 (interactive (gnus-article-hidden-arg))
537 (if (gnus-article-check-hidden-text 'headers arg)
538 ;; Show boring headers as well.
539 (gnus-article-show-hidden-text 'boring-headers)
540 ;; This function might be inhibited.
541 (unless gnus-inhibit-hiding
544 (let ((buffer-read-only nil)
545 (props (nconc (list 'article-type 'headers)
546 gnus-hidden-properties))
547 (max (1+ (length gnus-sorted-header-list)))
548 (ignored (when (not gnus-visible-headers)
549 (cond ((stringp gnus-ignored-headers)
550 gnus-ignored-headers)
551 ((listp gnus-ignored-headers)
552 (mapconcat 'identity gnus-ignored-headers
555 (cond ((stringp gnus-visible-headers)
556 gnus-visible-headers)
557 ((and gnus-visible-headers
558 (listp gnus-visible-headers))
559 (mapconcat 'identity gnus-visible-headers "\\|"))))
560 (inhibit-point-motion-hooks t)
562 ;; First we narrow to just the headers.
564 (goto-char (point-min))
565 ;; Hide any "From " lines at the beginning of (mail) articles.
566 (while (looking-at "From ")
570 (delete-region (point-min) (point))
571 (gnus-article-hide-text (point-min) (point) props)))
572 ;; Then treat the rest of the header lines.
575 (if (search-forward "\n\n" nil t) ; if there's a body
576 (progn (forward-line -1) (point))
578 ;; Then we use the two regular expressions
579 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
580 ;; select which header lines is to remain visible in the
582 (goto-char (point-min))
583 (while (re-search-forward "^[^ \t]*:" nil t)
585 ;; Mark the rank of the header.
587 (point) (1+ (point)) 'message-rank
588 (if (or (and visible (looking-at visible))
590 (not (looking-at ignored))))
591 (gnus-article-header-rank)
594 (message-sort-headers-1)
595 (when (setq beg (text-property-any
596 (point-min) (point-max) 'message-rank (+ 2 max)))
597 ;; We make the unwanted headers invisible.
599 (delete-region beg (point-max))
600 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
601 (gnus-article-hide-text-type beg (point-max) 'headers))
602 ;; Work around XEmacs lossage.
603 (put-text-property (point-min) beg 'invisible nil))))))))
605 (defun gnus-article-hide-boring-headers (&optional arg)
606 "Toggle hiding of headers that aren't very interesting.
607 If given a negative prefix, always show; if given a positive prefix,
609 (interactive (gnus-article-hidden-arg))
610 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
611 (not gnus-show-all-headers))
614 (let ((buffer-read-only nil)
615 (list gnus-boring-article-headers)
616 (inhibit-point-motion-hooks t)
618 (nnheader-narrow-to-headers)
620 (setq elem (pop list))
621 (goto-char (point-min))
623 ;; Hide empty headers.
625 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
627 (gnus-article-hide-text-type
628 (progn (beginning-of-line) (point))
631 (if (re-search-forward "^[^ \t]" nil t)
635 ;; Hide boring Newsgroups header.
636 ((eq elem 'newsgroups)
637 (when (equal (gnus-fetch-field "newsgroups")
638 (gnus-group-real-name
639 (if (boundp 'gnus-newsgroup-name)
642 (gnus-article-hide-header "newsgroups")))
643 ((eq elem 'followup-to)
644 (when (equal (message-fetch-field "followup-to")
645 (message-fetch-field "newsgroups"))
646 (gnus-article-hide-header "followup-to")))
648 (let ((from (message-fetch-field "from"))
649 (reply-to (message-fetch-field "reply-to")))
653 (nth 1 (mail-extract-address-components from))
654 (nth 1 (mail-extract-address-components reply-to))))
655 (gnus-article-hide-header "reply-to"))))
657 (let ((date (message-fetch-field "date")))
659 (< (gnus-days-between (current-time-string) date)
661 (gnus-article-hide-header "date")))))))))))
663 (defun gnus-article-hide-header (header)
665 (goto-char (point-min))
666 (when (re-search-forward (concat "^" header ":") nil t)
667 (gnus-article-hide-text-type
668 (progn (beginning-of-line) (point))
671 (if (re-search-forward "^[^ \t]" nil t)
676 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
677 (defun gnus-article-treat-overstrike ()
678 "Translate overstrikes into bold text."
681 (let ((buffer-read-only nil))
682 (while (search-forward "\b" nil t)
683 (let ((next (following-char))
684 (previous (char-after (- (point) 2))))
685 ;; We do the boldification/underlining by hiding the
686 ;; overstrikes and putting the proper text property
690 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
691 (put-text-property (point) (1+ (point)) 'face 'bold))
693 (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
695 (- (point) 2) (1- (point)) 'face 'underline))
697 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
699 (point) (1+ (point)) 'face 'underline))))))))
701 (defun gnus-article-fill ()
702 "Format too long lines."
705 (let ((buffer-read-only nil))
707 (goto-char (point-min))
708 (search-forward "\n\n" nil t)
710 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
711 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
712 (adaptive-fill-mode t))
714 (and (>= (current-column) (min fill-column (window-width)))
715 (/= (preceding-char) ?:)
716 (fill-paragraph nil))
719 (defun gnus-article-remove-cr ()
720 "Remove carriage returns from an article."
723 (let ((buffer-read-only nil))
724 (goto-char (point-min))
725 (while (search-forward "\r" nil t)
726 (replace-match "" t t)))))
728 (defun gnus-article-remove-trailing-blank-lines ()
729 "Remove all trailing blank lines from the article."
732 (let ((buffer-read-only nil))
733 (goto-char (point-max))
737 (while (and (not (bobp))
738 (looking-at "^[ \t]*$"))
743 (defun gnus-article-display-x-face (&optional force)
744 "Look for an X-Face header and display it if present."
745 (interactive (list 'force))
747 ;; Delete the old process, if any.
748 (when (process-status "article-x-face")
749 (delete-process "article-x-face"))
750 (let ((inhibit-point-motion-hooks t)
751 (case-fold-search nil)
754 (nnheader-narrow-to-headers)
755 (setq from (message-fetch-field "from"))
756 (goto-char (point-min))
757 (when (and gnus-article-x-face-command
759 ;; Check whether this face is censored.
760 (not gnus-article-x-face-too-ugly)
761 (and gnus-article-x-face-too-ugly from
762 (not (string-match gnus-article-x-face-too-ugly
764 ;; Has to be present.
765 (re-search-forward "^X-Face: " nil t))
766 ;; We now have the area of the buffer where the X-Face is stored.
768 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
769 ;; We display the face.
770 (if (symbolp gnus-article-x-face-command)
771 ;; The command is a lisp function, so we call it.
772 (if (gnus-functionp gnus-article-x-face-command)
773 (funcall gnus-article-x-face-command beg end)
774 (error "%s is not a function" gnus-article-x-face-command))
775 ;; The command is a string, so we interpret the command
776 ;; as a, well, command, and fork it off.
777 (let ((process-connection-type nil))
778 (process-kill-without-query
780 "article-x-face" nil shell-file-name shell-command-switch
781 gnus-article-x-face-command))
782 (process-send-region "article-x-face" beg end)
783 (process-send-eof "article-x-face")))))))))
785 (defalias 'gnus-decode-rfc1522 'gnus-article-decode-rfc1522)
786 (defun gnus-article-decode-rfc1522 ()
787 "Hack to remove QP encoding from headers."
788 (let ((case-fold-search t)
789 (inhibit-point-motion-hooks t)
790 (buffer-read-only nil)
794 (goto-char (point-min))
795 (or (search-forward "\n\n" nil t) (point-max)))
796 (goto-char (point-min))
797 (while (re-search-forward
798 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
799 (setq string (match-string 1))
801 (narrow-to-region (match-beginning 0) (match-end 0))
802 (delete-region (point-min) (point-max))
804 (gnus-article-mime-decode-quoted-printable
805 (goto-char (point-min)) (point-max))
806 (subst-char-in-region (point-min) (point-max) ?_ ? )
807 (goto-char (point-max)))
808 (goto-char (point-min))))))
810 (defun gnus-article-de-quoted-unreadable (&optional force)
811 "Do a naive translation of a quoted-printable-encoded article.
812 This is in no way, shape or form meant as a replacement for real MIME
813 processing, but is simply a stop-gap measure until MIME support is
815 If FORCE, decode the article whether it is marked as quoted-printable
817 (interactive (list 'force))
819 (let ((case-fold-search t)
820 (buffer-read-only nil)
821 (type (gnus-fetch-field "content-transfer-encoding")))
822 (gnus-article-decode-rfc1522)
824 (and type (string-match "quoted-printable" (downcase type))))
825 (goto-char (point-min))
826 (search-forward "\n\n" nil 'move)
827 (gnus-article-mime-decode-quoted-printable (point) (point-max))))))
829 (defun gnus-article-mime-decode-quoted-printable-buffer ()
830 "Decode Quoted-Printable in the current buffer."
831 (gnus-article-mime-decode-quoted-printable (point-min) (point-max)))
833 (defun gnus-article-mime-decode-quoted-printable (from to)
834 "Decode Quoted-Printable in the region between FROM and TO."
837 (while (search-forward "=" to t)
838 (cond ((eq (following-char) ?\n)
841 ((looking-at "[0-9A-F][0-9A-F]")
842 (subst-char-in-region
843 (1- (point)) (point) ?=
844 (hexl-hex-string-to-integer
845 (buffer-substring (point) (+ 2 (point)))))
849 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
851 (defun gnus-article-hide-pgp (&optional arg)
852 "Toggle hiding of any PGP headers and signatures in the current article.
853 If given a negative prefix, always show; if given a positive prefix,
855 (interactive (gnus-article-hidden-arg))
856 (unless (gnus-article-check-hidden-text 'pgp arg)
858 (let (buffer-read-only beg end)
860 (goto-char (point-min))
861 ;; Hide the "header".
862 (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
863 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
865 ;; Hide the actual signature.
866 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
867 (setq end (1+ (match-beginning 0)))
868 (gnus-article-hide-text-type
870 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
872 ;; Perhaps we shouldn't hide to the end of the buffer
873 ;; if there is no end to the signature?
876 ;; Hide "- " PGP quotation markers.
878 (narrow-to-region beg end)
879 (goto-char (point-min))
880 (while (re-search-forward "^- " nil t)
881 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
884 (defun gnus-article-hide-pem (&optional arg)
885 "Toggle hiding of any PEM headers and signatures in the current article.
886 If given a negative prefix, always show; if given a positive prefix,
888 (interactive (gnus-article-hidden-arg))
889 (unless (gnus-article-check-hidden-text 'pem arg)
891 (let (buffer-read-only end)
893 (goto-char (point-min))
894 ;; hide the horrendously ugly "header".
895 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
898 (setq end (1+ (match-beginning 0)))
899 (gnus-article-hide-text-type
901 (if (search-forward "\n\n" nil t)
905 ;; hide the trailer as well
906 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
909 (gnus-article-hide-text-type
910 (match-beginning 0) (match-end 0) 'pem))))))
912 (defun gnus-article-hide-signature (&optional arg)
913 "Hide the signature in the current article.
914 If given a negative prefix, always show; if given a positive prefix,
916 (interactive (gnus-article-hidden-arg))
917 (unless (gnus-article-check-hidden-text 'signature arg)
920 (let ((buffer-read-only nil))
921 (when (gnus-article-narrow-to-signature)
922 (gnus-article-hide-text-type (point-min) (point-max) 'signature)))))))
924 (defun gnus-article-strip-leading-blank-lines ()
925 "Remove all blank lines from the beginning of the article."
928 (let ((inhibit-point-motion-hooks t)
930 (goto-char (point-min))
931 (when (search-forward "\n\n" nil t)
932 (while (and (not (eobp))
933 (looking-at "[ \t]*$"))
934 (gnus-delete-line))))))
936 (defun gnus-article-strip-multiple-blank-lines ()
937 "Replace consecutive blank lines with one empty line."
940 (let (buffer-read-only)
941 ;; First make all blank lines empty.
942 (goto-char (point-min))
943 (while (re-search-forward "^[ \t]+$" nil t)
944 (replace-match "" nil t))
945 ;; Then replace multiple empty lines with a single empty line.
946 (goto-char (point-min))
947 (while (re-search-forward "\n\n\n+" nil t)
948 (replace-match "\n\n" t t)))))
950 (defun gnus-article-strip-blank-lines ()
951 "Strip leading, trailing and multiple blank lines."
953 (gnus-article-strip-leading-blank-lines)
954 (gnus-article-remove-trailing-blank-lines)
955 (gnus-article-strip-multiple-blank-lines))
957 (defvar mime::preview/content-list)
958 (defvar mime::preview-content-info/point-min)
959 (defun gnus-article-narrow-to-signature ()
960 "Narrow to the signature; return t if a signature is found, else nil."
962 (when (and (boundp 'mime::preview/content-list)
963 mime::preview/content-list)
964 ;; We have a MIMEish article, so we use the MIME data to narrow.
965 (let ((pcinfo (car (last mime::preview/content-list))))
968 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
971 (when (gnus-article-search-signature)
973 ;; Check whether we have some limits to what we consider
974 ;; to be a signature.
975 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
976 (list gnus-signature-limit)))
978 (while (setq limit (pop limits))
979 (if (or (and (integerp limit)
980 (< (- (point-max) (point)) limit))
982 (< (count-lines (point) (point-max)) limit))
983 (and (gnus-functionp limit)
986 (not (re-search-forward limit nil t))))
987 () ; This limit did not succeed.
991 (narrow-to-region (point) (point-max))
994 (defun gnus-article-search-signature ()
995 "Search the current buffer for the signature separator.
996 Put point at the beginning of the signature separator."
998 (goto-char (point-max))
999 (if (if (stringp gnus-signature-separator)
1000 (re-search-backward gnus-signature-separator nil t)
1001 (let ((seps gnus-signature-separator))
1003 (not (re-search-backward (car seps) nil t)))
1010 (defun gnus-article-hidden-arg ()
1011 "Return the current prefix arg as a number, or 0 if no prefix."
1012 (list (if current-prefix-arg
1013 (prefix-numeric-value current-prefix-arg)
1016 (defun gnus-article-check-hidden-text (type arg)
1017 "Return nil if hiding is necessary.
1018 Arg can be nil or a number. Nil and positive means hide, negative
1019 means show, 0 means toggle."
1021 (let ((hide (gnus-article-hidden-text-p type)))
1027 (gnus-article-show-hidden-text type))
1029 (if (eq hide 'hidden)
1030 (gnus-article-show-hidden-text type)
1033 (defun gnus-article-hidden-text-p (type)
1034 "Say whether the current buffer contains hidden text of type TYPE."
1035 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1037 (if (get-text-property pos 'invisible)
1041 (defun gnus-article-show-hidden-text (type &optional hide)
1042 "Show all hidden text of type TYPE.
1043 If HIDE, hide the text instead."
1045 (let ((buffer-read-only nil)
1046 (inhibit-point-motion-hooks t)
1048 (while (gnus-goto-char (text-property-any
1049 beg (point-max) 'article-type type))
1053 (gnus-article-hide-text beg (point) gnus-hidden-properties)
1054 (gnus-article-unhide-text beg (point)))
1058 (defconst article-time-units
1059 `((year . ,(* 365.25 24 60 60))
1060 (week . ,(* 7 24 60 60))
1061 (day . ,(* 24 60 60))
1065 "Mapping from time units to seconds.")
1067 (defun gnus-article-date-ut (&optional type highlight header)
1068 "Convert DATE date to universal time in the current article.
1069 If TYPE is `local', convert to local time; if it is `lapsed', output
1070 how much time has lapsed since DATE."
1071 (interactive (list 'ut t))
1072 (let* ((header (or header
1073 (mail-header-date gnus-current-headers)
1074 (message-fetch-field "date")
1076 (date (if (vectorp header) (mail-header-date header)
1078 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1079 (inhibit-point-motion-hooks t)
1081 (when (and date (not (string= date "")))
1084 (nnheader-narrow-to-headers)
1085 (let ((buffer-read-only nil))
1086 ;; Delete any old Date headers.
1087 (if (re-search-forward date-regexp nil t)
1089 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1090 eface (get-text-property (1- (gnus-point-at-eol))
1092 (message-remove-header date-regexp t)
1093 (beginning-of-line))
1094 (goto-char (point-max)))
1095 (insert (gnus-article-make-date-line date type))
1098 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1099 (put-text-property (match-beginning 1) (match-end 1)
1101 (put-text-property (match-beginning 2) (match-end 2)
1104 (defun gnus-article-make-date-line (date type)
1105 "Return a DATE line of TYPE."
1107 ;; Convert to the local timezone. We have to slap a
1108 ;; `condition-case' round the calls to the timezone
1109 ;; functions since they aren't particularly resistant to
1112 (concat "Date: " (condition-case ()
1113 (timezone-make-date-arpa-standard date)
1116 ;; Convert to Universal Time.
1120 (timezone-make-date-arpa-standard date nil "UT")
1123 ;; Get the original date from the article.
1124 ((eq type 'original)
1125 (concat "Date: " date "\n"))
1126 ;; Do an X-Sent lapsed format.
1128 ;; If the date is seriously mangled, the timezone functions are
1129 ;; liable to bug out, so we ignore all errors.
1130 (let* ((now (current-time))
1135 (timezone-make-date-arpa-standard
1136 (current-time-string now)
1137 (current-time-zone now) "UT"))
1139 (timezone-make-date-arpa-standard
1141 (real-sec (and real-time
1142 (+ (* (float (car real-time)) 65536)
1144 (sec (and real-time (abs real-sec)))
1148 "X-Sent: Unknown\n")
1154 ;; This is a bit convoluted, but basically we go
1155 ;; through the time units for years, weeks, etc,
1156 ;; and divide things to see whether that results
1157 ;; in positive answers.
1160 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1161 ;; The (remaining) seconds are too few to
1162 ;; be divided into this time unit.
1164 ;; It's big enough, so we output it.
1165 (setq sec (- sec (* num (cdr unit))))
1167 (concat (if prev ", " "") (int-to-string
1169 " " (symbol-name (car unit))
1170 (if (> num 1) "s" ""))
1172 article-time-units "")
1173 ;; If dates are odd, then it might appear like the
1174 ;; article was sent in the future.
1177 " in the future\n"))))))
1179 (error "Unknown conversion type: %s" type))))
1181 (defun gnus-article-date-local (&optional highlight)
1182 "Convert the current article date to the local timezone."
1183 (interactive (list t))
1184 (gnus-article-date-ut 'local highlight))
1186 (defun gnus-article-date-original (&optional highlight)
1187 "Convert the current article date to what it was originally.
1188 This is only useful if you have used some other date conversion
1189 function and want to see what the date was before converting."
1190 (interactive (list t))
1191 (gnus-article-date-ut 'original highlight))
1193 (defun gnus-article-date-lapsed (&optional highlight)
1194 "Convert the current article date to time lapsed since it was sent."
1195 (interactive (list t))
1196 (gnus-article-date-ut 'lapsed highlight))
1198 (defun gnus-article-show-all ()
1199 "Show all hidden text in the article buffer."
1202 (let ((buffer-read-only nil))
1203 (gnus-article-unhide-text (point-min) (point-max)))))
1205 (defun gnus-article-emphasize (&optional arg)
1206 "Emphasize text according to `gnus-emphasis-alist'."
1207 (interactive (gnus-article-hidden-arg))
1208 (unless (gnus-article-check-hidden-text 'emphasis arg)
1210 (let ((alist gnus-emphasis-alist)
1211 (buffer-read-only nil)
1212 (props (append '(gnus-article-type emphasis)
1213 gnus-hidden-properties))
1214 regexp elem beg invisible visible face)
1215 (goto-char (point-min))
1216 (search-forward "\n\n" nil t)
1218 (while (setq elem (pop alist))
1220 (setq regexp (car elem)
1221 invisible (nth 1 elem)
1222 visible (nth 2 elem)
1224 (while (re-search-forward regexp nil t)
1225 (when (and (match-beginning visible) (match-beginning invisible))
1226 (gnus-article-hide-text
1227 (match-beginning invisible) (match-end invisible) props)
1228 (gnus-article-unhide-text-type
1229 (match-beginning visible) (match-end visible) 'emphasis)
1230 (gnus-put-text-property-excluding-newlines
1231 (match-beginning visible) (match-end visible) 'face face)
1232 (goto-char (match-end invisible)))))))))
1234 (defvar gnus-summary-article-menu)
1235 (defvar gnus-summary-post-menu)
1237 ;;; Saving functions.
1239 (defun gnus-article-save (save-buffer file &optional num)
1240 "Save the currently selected article."
1241 (unless gnus-save-all-headers
1242 ;; Remove headers according to `gnus-saved-headers'.
1243 (let ((gnus-visible-headers
1244 (or gnus-saved-headers gnus-visible-headers))
1245 (gnus-article-buffer save-buffer))
1246 (gnus-article-hide-headers 1 t)))
1247 (save-window-excursion
1248 (if (not gnus-default-article-saver)
1249 (error "No default saver is defined.")
1250 ;; !!! Magic! The saving functions all save
1251 ;; `gnus-original-article-buffer' (or so they think), but we
1252 ;; bind that variable to our save-buffer.
1253 (set-buffer gnus-article-buffer)
1254 (let* ((gnus-save-article-buffer save-buffer)
1257 ((not gnus-prompt-before-saving) 'default)
1258 ((eq gnus-prompt-before-saving 'always) nil)
1260 (gnus-number-of-articles-to-be-saved
1261 (when (eq gnus-prompt-before-saving t)
1263 (set-buffer gnus-summary-buffer)
1264 (funcall gnus-default-article-saver filename)))))
1266 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1268 ((eq filename 'default)
1272 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1274 (format prompt (if (and gnus-number-of-articles-to-be-saved
1275 (> gnus-number-of-articles-to-be-saved 1))
1276 (format "these %d articles"
1277 gnus-number-of-articles-to-be-saved)
1280 ;; Let the split methods have their say.
1282 ;; No split name was found.
1285 (concat prompt " (default "
1286 (file-name-nondirectory default-name) ") ")
1287 (file-name-directory default-name)
1289 ;; A single split name was found
1290 ((= 1 (length split-name))
1291 (let* ((name (car split-name))
1292 (dir (cond ((file-directory-p name)
1293 (file-name-as-directory name))
1294 ((file-exists-p name) name)
1295 (t gnus-article-save-directory))))
1297 (concat prompt " (default " name ") ")
1299 ;; A list of splits was found.
1301 (setq split-name (nreverse split-name))
1303 (let ((file-name-history (nconc split-name file-name-history)))
1307 (concat prompt " (`M-p' for defaults) ")
1308 gnus-article-save-directory
1310 gnus-article-save-directory)))
1311 (car (push result file-name-history)))))))
1312 ;; Create the directory.
1313 (gnus-make-directory (file-name-directory file))
1314 ;; If we have read a directory, we append the default file name.
1315 (when (file-directory-p file)
1316 (setq file (concat (file-name-as-directory file)
1317 (file-name-nondirectory default-name))))
1318 ;; Possibly translate some characters.
1319 (nnheader-translate-file-chars file)))))
1321 (defun gnus-article-archive-name (group)
1322 "Return the first instance of an \"Archive-name\" in the current buffer."
1323 (let ((case-fold-search t))
1324 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1325 (nnheader-concat gnus-article-save-directory
1326 (match-string 1)))))
1328 (defun gnus-summary-save-in-rmail (&optional filename)
1329 "Append this article to Rmail file.
1330 Optional argument FILENAME specifies file name.
1331 Directory to save to is default to `gnus-article-save-directory'."
1333 (gnus-set-global-variables)
1335 (funcall gnus-rmail-save-name gnus-newsgroup-name
1336 gnus-current-headers gnus-newsgroup-last-rmail)))
1337 (setq filename (gnus-read-save-file-name
1338 "Save %s in rmail file:" default-name filename))
1339 (gnus-make-directory (file-name-directory filename))
1340 (gnus-eval-in-buffer-window gnus-save-article-buffer
1344 (gnus-output-to-rmail filename))))
1345 ;; Remember the directory name to save articles
1346 (setq gnus-newsgroup-last-rmail filename)))
1348 (defun gnus-summary-save-in-mail (&optional filename)
1349 "Append this article to Unix mail file.
1350 Optional argument FILENAME specifies file name.
1351 Directory to save to is default to `gnus-article-save-directory'."
1353 (gnus-set-global-variables)
1355 (funcall gnus-mail-save-name gnus-newsgroup-name
1356 gnus-current-headers gnus-newsgroup-last-mail)))
1357 (setq filename (gnus-read-save-file-name
1358 "Save %s in Unix mail file:" default-name filename))
1360 (expand-file-name filename
1362 (file-name-directory default-name))))
1363 (gnus-make-directory (file-name-directory filename))
1364 (gnus-eval-in-buffer-window gnus-save-article-buffer
1368 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
1369 (gnus-output-to-rmail filename)
1370 (let ((mail-use-rfc822 t))
1371 (rmail-output filename 1 t t))))))
1372 ;; Remember the directory name to save articles.
1373 (setq gnus-newsgroup-last-mail filename)))
1375 (defun gnus-summary-save-in-file (&optional filename overwrite)
1376 "Append this article to file.
1377 Optional argument FILENAME specifies file name.
1378 Directory to save to is default to `gnus-article-save-directory'."
1380 (gnus-set-global-variables)
1382 (funcall gnus-file-save-name gnus-newsgroup-name
1383 gnus-current-headers gnus-newsgroup-last-file)))
1384 (setq filename (gnus-read-save-file-name
1385 "Save %s in file:" default-name filename))
1386 (gnus-make-directory (file-name-directory filename))
1387 (gnus-eval-in-buffer-window gnus-save-article-buffer
1391 (when (and overwrite
1392 (file-exists-p filename))
1393 (delete-file filename))
1394 (gnus-output-to-file filename))))
1395 ;; Remember the directory name to save articles.
1396 (setq gnus-newsgroup-last-file filename)))
1398 (defun gnus-summary-write-to-file (&optional filename)
1399 "Write this article to a file.
1400 Optional argument FILENAME specifies file name.
1401 The directory to save in defaults to `gnus-article-save-directory'."
1403 (gnus-summary-save-in-file nil t))
1405 (defun gnus-summary-save-body-in-file (&optional filename)
1406 "Append this article body to a file.
1407 Optional argument FILENAME specifies file name.
1408 The directory to save in defaults to `gnus-article-save-directory'."
1410 (gnus-set-global-variables)
1412 (funcall gnus-file-save-name gnus-newsgroup-name
1413 gnus-current-headers gnus-newsgroup-last-file)))
1414 (setq filename (gnus-read-save-file-name
1415 "Save %s body in file:" default-name filename))
1416 (gnus-make-directory (file-name-directory filename))
1417 (gnus-eval-in-buffer-window gnus-save-article-buffer
1421 (goto-char (point-min))
1422 (when (search-forward "\n\n" nil t)
1423 (narrow-to-region (point) (point-max)))
1424 (gnus-output-to-file filename))))
1425 ;; Remember the directory name to save articles.
1426 (setq gnus-newsgroup-last-file filename)))
1428 (defun gnus-summary-save-in-pipe (&optional command)
1429 "Pipe this article to subprocess."
1431 (gnus-set-global-variables)
1433 (cond ((eq command 'default)
1434 gnus-last-shell-command)
1438 "Shell command on %s: "
1439 (if (and gnus-number-of-articles-to-be-saved
1440 (> gnus-number-of-articles-to-be-saved 1))
1441 (format "these %d articles"
1442 gnus-number-of-articles-to-be-saved)
1444 gnus-last-shell-command))))
1445 (when (string-equal command "")
1446 (setq command gnus-last-shell-command))
1447 (gnus-eval-in-buffer-window gnus-article-buffer
1450 (shell-command-on-region (point-min) (point-max) command nil)))
1451 (setq gnus-last-shell-command command))
1453 ;;; Article file names when saving.
1455 (defun gnus-capitalize-newsgroup (newsgroup)
1456 "Capitalize NEWSGROUP name."
1457 (when (not (zerop (length newsgroup)))
1458 (concat (char-to-string (upcase (aref newsgroup 0)))
1459 (substring newsgroup 1))))
1461 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1462 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1463 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
1464 Otherwise, it is like ~/News/news/group/num."
1467 (concat (if (gnus-use-long-file-name 'not-save)
1468 (gnus-capitalize-newsgroup newsgroup)
1469 (gnus-newsgroup-directory-form newsgroup))
1470 "/" (int-to-string (mail-header-number headers)))
1471 gnus-article-save-directory)))
1473 (string-equal (file-name-directory default)
1474 (file-name-directory last-file))
1475 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1477 (or last-file default))))
1479 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1480 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1481 If variable `gnus-use-long-file-name' is non-nil, it is
1482 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1485 (concat (if (gnus-use-long-file-name 'not-save)
1487 (gnus-newsgroup-directory-form newsgroup))
1488 "/" (int-to-string (mail-header-number headers)))
1489 gnus-article-save-directory)))
1491 (string-equal (file-name-directory default)
1492 (file-name-directory last-file))
1493 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1495 (or last-file default))))
1497 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1498 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1499 If variable `gnus-use-long-file-name' is non-nil, it is
1500 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1503 (if (gnus-use-long-file-name 'not-save)
1504 (gnus-capitalize-newsgroup newsgroup)
1505 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1506 gnus-article-save-directory)))
1508 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1509 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1510 If variable `gnus-use-long-file-name' is non-nil, it is
1511 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1514 (if (gnus-use-long-file-name 'not-save)
1516 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1517 gnus-article-save-directory)))
1521 ;;; Gnus article mode
1524 (put 'gnus-article-mode 'mode-class 'special)
1527 (gnus-define-keys gnus-article-mode-map
1528 " " gnus-article-goto-next-page
1529 "\177" gnus-article-goto-prev-page
1530 [delete] gnus-article-goto-prev-page
1531 "\C-c^" gnus-article-refer-article
1532 "h" gnus-article-show-summary
1533 "s" gnus-article-show-summary
1534 "\C-c\C-m" gnus-article-mail
1535 "?" gnus-article-describe-briefly
1536 gnus-mouse-2 gnus-article-push-button
1537 "\r" gnus-article-press-button
1538 "\t" gnus-article-next-button
1539 "\M-\t" gnus-article-prev-button
1540 "e" gnus-article-edit
1541 "<" beginning-of-buffer
1543 "\C-c\C-i" gnus-info-find-node
1546 "\C-d" gnus-article-read-summary-keys
1547 "\M-*" gnus-article-read-summary-keys
1548 "\M-g" gnus-article-read-summary-keys)
1550 (substitute-key-definition
1551 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1553 (defun gnus-article-make-menu-bar ()
1554 (gnus-turn-off-edit-menu 'article)
1555 (unless (boundp 'gnus-article-article-menu)
1557 gnus-article-article-menu gnus-article-mode-map ""
1559 ["Scroll forwards" gnus-article-goto-next-page t]
1560 ["Scroll backwards" gnus-article-goto-prev-page t]
1561 ["Show summary" gnus-article-show-summary t]
1562 ["Fetch Message-ID at point" gnus-article-refer-article t]
1563 ["Mail to address at point" gnus-article-mail t]))
1566 gnus-article-treatment-menu gnus-article-mode-map ""
1568 ["Hide headers" gnus-article-hide-headers t]
1569 ["Hide signature" gnus-article-hide-signature t]
1570 ["Hide citation" gnus-article-hide-citation t]
1571 ["Treat overstrike" gnus-article-treat-overstrike t]
1572 ["Remove carriage return" gnus-article-remove-cr t]
1573 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1575 (when (boundp 'gnus-summary-article-menu)
1576 (define-key gnus-article-mode-map [menu-bar commands]
1577 (cons "Commands" gnus-summary-article-menu)))
1579 (when (boundp 'gnus-summary-post-menu)
1580 (define-key gnus-article-mode-map [menu-bar post]
1581 (cons "Post" gnus-summary-post-menu)))
1583 (run-hooks 'gnus-article-menu-hook)))
1585 (defun gnus-article-mode ()
1586 "Major mode for displaying an article.
1588 All normal editing commands are switched off.
1590 The following commands are available in addition to all summary mode
1592 \\<gnus-article-mode-map>
1593 \\[gnus-article-next-page]\t Scroll the article one page forwards
1594 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1595 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1596 \\[gnus-article-show-summary]\t Display the summary buffer
1597 \\[gnus-article-mail]\t Send a reply to the address near point
1598 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1599 \\[gnus-info-find-node]\t Go to the Gnus info node"
1601 (when (gnus-visual-p 'article-menu 'menu)
1602 (gnus-article-make-menu-bar))
1603 (kill-all-local-variables)
1604 (gnus-simplify-mode-line)
1605 (setq mode-name "Article")
1606 (setq major-mode 'gnus-article-mode)
1607 (make-local-variable 'minor-mode-alist)
1608 (unless (assq 'gnus-show-mime minor-mode-alist)
1609 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1610 (use-local-map gnus-article-mode-map)
1611 (gnus-update-format-specifications nil 'article-mode)
1612 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1613 (gnus-set-default-directory)
1614 (buffer-disable-undo (current-buffer))
1615 (setq buffer-read-only t)
1616 (set-syntax-table gnus-article-mode-syntax-table)
1617 (run-hooks 'gnus-article-mode-hook))
1619 (defun gnus-article-setup-buffer ()
1620 "Initialize the article buffer."
1621 (let* ((name (if gnus-single-article-buffer "*Article*"
1622 (concat "*Article " gnus-newsgroup-name "*")))
1624 (progn (string-match "\\*Article" name)
1625 (concat " *Original Article"
1626 (substring name (match-end 0))))))
1627 (setq gnus-article-buffer name)
1628 (setq gnus-original-article-buffer original)
1629 ;; This might be a variable local to the summary buffer.
1630 (unless gnus-single-article-buffer
1632 (set-buffer gnus-summary-buffer)
1633 (setq gnus-article-buffer name)
1634 (setq gnus-original-article-buffer original)
1635 (gnus-set-global-variables)))
1636 ;; Init original article buffer.
1638 (set-buffer (get-buffer-create gnus-original-article-buffer))
1639 (buffer-disable-undo (current-buffer))
1640 (setq major-mode 'gnus-original-article-mode)
1641 (gnus-add-current-to-buffer-list)
1642 (make-local-variable 'gnus-original-article))
1643 (if (get-buffer name)
1646 (buffer-disable-undo (current-buffer))
1647 (setq buffer-read-only t)
1648 (gnus-add-current-to-buffer-list)
1649 (unless (eq major-mode 'gnus-article-mode)
1650 (gnus-article-mode))
1653 (set-buffer (get-buffer-create name))
1654 (gnus-add-current-to-buffer-list)
1656 (make-local-variable 'gnus-summary-buffer)
1657 (current-buffer)))))
1659 ;; Set article window start at LINE, where LINE is the number of lines
1660 ;; from the head of the article.
1661 (defun gnus-article-set-window-start (&optional line)
1663 (get-buffer-window gnus-article-buffer t)
1665 (set-buffer gnus-article-buffer)
1666 (goto-char (point-min))
1669 (gnus-message 6 "Moved to bookmark")
1670 (search-forward "\n\n" nil t)
1674 (defun gnus-article-prepare (article &optional all-headers header)
1675 "Prepare ARTICLE in article mode buffer.
1676 ARTICLE should either be an article number or a Message-ID.
1677 If ARTICLE is an id, HEADER should be the article headers.
1678 If ALL-HEADERS is non-nil, no headers are hidden."
1680 ;; Make sure we start in a summary buffer.
1681 (unless (eq major-mode 'gnus-summary-mode)
1682 (set-buffer gnus-summary-buffer))
1683 (setq gnus-summary-buffer (current-buffer))
1684 ;; Make sure the connection to the server is alive.
1685 (unless (gnus-server-opened
1686 (gnus-find-method-for-group gnus-newsgroup-name))
1687 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1688 (gnus-request-group gnus-newsgroup-name t))
1689 (let* ((gnus-article (if header (mail-header-number header) article))
1690 (summary-buffer (current-buffer))
1691 (internal-hook gnus-article-internal-prepare-hook)
1692 (group gnus-newsgroup-name)
1695 (gnus-article-setup-buffer)
1696 (set-buffer gnus-article-buffer)
1697 ;; Deactivate active regions.
1698 (when (and (boundp 'transient-mark-mode)
1699 transient-mark-mode)
1700 (setq mark-active nil))
1701 (if (not (setq result (let ((buffer-read-only nil))
1702 (gnus-request-article-this-buffer
1704 ;; There is no such article.
1706 (when (and (numberp article)
1707 (not (memq article gnus-newsgroup-sparse)))
1708 (setq gnus-article-current
1709 (cons gnus-newsgroup-name article))
1710 (set-buffer gnus-summary-buffer)
1711 (setq gnus-current-article article)
1712 (gnus-summary-mark-article article gnus-canceled-mark))
1713 (unless (memq article gnus-newsgroup-sparse)
1715 1 "No such article (may have expired or been canceled)")))
1716 (if (or (eq result 'pseudo) (eq result 'nneething))
1719 (set-buffer summary-buffer)
1720 (setq gnus-last-article gnus-current-article
1721 gnus-newsgroup-history (cons gnus-current-article
1722 gnus-newsgroup-history)
1723 gnus-current-article 0
1724 gnus-current-headers nil
1725 gnus-article-current nil)
1726 (if (eq result 'nneething)
1727 (gnus-configure-windows 'summary)
1728 (gnus-configure-windows 'article))
1729 (gnus-set-global-variables))
1730 (gnus-set-mode-line 'article))
1731 ;; The result from the `request' was an actual article -
1732 ;; or at least some text that is now displayed in the
1734 (when (and (numberp article)
1735 (not (eq article gnus-current-article)))
1736 ;; Seems like a new article has been selected.
1737 ;; `gnus-current-article' must be an article number.
1739 (set-buffer summary-buffer)
1740 (setq gnus-last-article gnus-current-article
1741 gnus-newsgroup-history (cons gnus-current-article
1742 gnus-newsgroup-history)
1743 gnus-current-article article
1744 gnus-current-headers
1745 (gnus-summary-article-header gnus-current-article)
1746 gnus-article-current
1747 (cons gnus-newsgroup-name gnus-current-article))
1748 (unless (vectorp gnus-current-headers)
1749 (setq gnus-current-headers nil))
1750 (gnus-summary-show-thread)
1751 (run-hooks 'gnus-mark-article-hook)
1752 (gnus-set-mode-line 'summary)
1753 (when (gnus-visual-p 'article-highlight 'highlight)
1754 (run-hooks 'gnus-visual-mark-article-hook))
1755 ;; Set the global newsgroup variables here.
1756 ;; Suggested by Jim Sisolak
1757 ;; <sisolak@trans4.neep.wisc.edu>.
1758 (gnus-set-global-variables)
1759 (setq gnus-have-all-headers
1760 (or all-headers gnus-show-all-headers))
1762 (vectorp (gnus-summary-article-header article))
1763 (gnus-cache-possibly-enter-article
1765 (gnus-summary-article-header article)
1766 (memq article gnus-newsgroup-marked)
1767 (memq article gnus-newsgroup-dormant)
1768 (memq article gnus-newsgroup-unreads)))))
1769 (when (or (numberp article)
1771 ;; Hooks for getting information from the article.
1772 ;; This hook must be called before being narrowed.
1773 (let (buffer-read-only)
1774 (run-hooks 'internal-hook)
1775 (run-hooks 'gnus-article-prepare-hook)
1776 ;; Decode MIME message.
1777 (when gnus-show-mime
1778 (if (or (not gnus-strict-mime)
1779 (gnus-fetch-field "Mime-Version"))
1780 (funcall gnus-show-mime-method)
1781 (funcall gnus-decode-encoded-word-method)))
1782 ;; Perform the article display hooks.
1783 (run-hooks 'gnus-article-display-hook))
1785 (goto-char (point-min))
1786 (when gnus-break-pages
1787 (gnus-narrow-to-page)))
1788 (gnus-set-mode-line 'article)
1789 (gnus-configure-windows 'article)
1790 (goto-char (point-min))
1793 (defun gnus-article-wash-status ()
1794 "Return a string which display status of article washing."
1796 (set-buffer gnus-article-buffer)
1797 (let ((cite (gnus-article-hidden-text-p 'cite))
1798 (headers (gnus-article-hidden-text-p 'headers))
1799 (boring (gnus-article-hidden-text-p 'boring-headers))
1800 (pgp (gnus-article-hidden-text-p 'pgp))
1801 (pem (gnus-article-hidden-text-p 'pem))
1802 (signature (gnus-article-hidden-text-p 'signature))
1803 (overstrike (gnus-article-hidden-text-p 'overstrike))
1804 (emphasis (gnus-article-hidden-text-p 'emphasis))
1805 (mime gnus-show-mime))
1806 (format "%c%c%c%c%c%c%c"
1808 (if (or headers boring) ?h ? )
1809 (if (or pgp pem) ?p ? )
1810 (if signature ?s ? )
1811 (if overstrike ?o ? )
1813 (if emphasis ?e ? )))))
1815 (defun gnus-article-hide-headers-if-wanted ()
1816 "Hide unwanted headers if `gnus-have-all-headers' is nil.
1817 Provided for backwards compatibility."
1818 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1820 (gnus-article-hide-headers)))
1824 (defun gnus-output-to-rmail (file-name)
1825 "Append the current article to an Rmail file named FILE-NAME."
1827 ;; Most of these codes are borrowed from rmailout.el.
1828 (setq file-name (expand-file-name file-name))
1829 (setq rmail-default-rmail-file file-name)
1830 (let ((artbuf (current-buffer))
1831 (tmpbuf (get-buffer-create " *Gnus-output*")))
1833 (or (get-file-buffer file-name)
1834 (file-exists-p file-name)
1835 (if (gnus-yes-or-no-p
1836 (concat "\"" file-name "\" does not exist, create it? "))
1837 (let ((file-buffer (create-file-buffer file-name)))
1839 (set-buffer file-buffer)
1840 (rmail-insert-rmail-file-header)
1841 (let ((require-final-newline nil))
1842 (gnus-write-buffer file-name)))
1843 (kill-buffer file-buffer))
1844 (error "Output file does not exist")))
1846 (buffer-disable-undo (current-buffer))
1848 (insert-buffer-substring artbuf)
1849 (gnus-convert-article-to-rmail)
1850 ;; Decide whether to append to a file or to an Emacs buffer.
1851 (let ((outbuf (get-file-buffer file-name)))
1853 (append-to-file (point-min) (point-max) file-name)
1854 ;; File has been visited, in buffer OUTBUF.
1856 (let ((buffer-read-only nil)
1857 (msg (and (boundp 'rmail-current-message)
1858 (symbol-value 'rmail-current-message))))
1859 ;; If MSG is non-nil, buffer is in RMAIL mode.
1862 (narrow-to-region (point-max) (point-max)))
1863 (insert-buffer-substring tmpbuf)
1865 (goto-char (point-min))
1867 (search-backward "\^_")
1868 (narrow-to-region (point) (point-max))
1869 (goto-char (1+ (point-min)))
1870 (rmail-count-new-messages t)
1871 (rmail-show-message msg))))))
1872 (kill-buffer tmpbuf)))
1874 (defun gnus-output-to-file (file-name)
1875 "Append the current article to a file named FILE-NAME."
1876 (let ((artbuf (current-buffer)))
1877 (nnheader-temp-write nil
1878 (insert-buffer-substring artbuf)
1879 ;; Append newline at end of the buffer as separator, and then
1881 (goto-char (point-max))
1883 (append-to-file (point-min) (point-max) file-name))))
1885 (defun gnus-convert-article-to-rmail ()
1886 "Convert article in current buffer to Rmail message format."
1887 (let ((buffer-read-only nil))
1888 ;; Convert article directly into Babyl format.
1889 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
1890 (goto-char (point-min))
1891 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1892 (while (search-forward "\n\^_" nil t) ;single char
1893 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
1894 (goto-char (point-max))
1897 (defun gnus-narrow-to-page (&optional arg)
1898 "Narrow the article buffer to a page.
1899 If given a numerical ARG, move forward ARG pages."
1901 (setq arg (if arg (prefix-numeric-value arg) 0))
1903 (set-buffer gnus-article-buffer)
1904 (goto-char (point-min))
1906 ;; Remove any old next/prev buttons.
1907 (when (gnus-visual-p 'page-marker)
1908 (let ((buffer-read-only nil))
1909 (gnus-remove-text-with-property 'gnus-prev)
1910 (gnus-remove-text-with-property 'gnus-next)))
1913 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1915 (re-search-forward page-delimiter nil 'move arg)))
1916 (goto-char (match-end 0)))
1919 (if (re-search-forward page-delimiter nil 'move)
1922 (when (and (gnus-visual-p 'page-marker)
1923 (not (= (point-min) 1)))
1925 (goto-char (point-min))
1926 (gnus-insert-prev-page-button)))
1927 (when (and (gnus-visual-p 'page-marker)
1928 (< (+ (point-max) 2) (buffer-size)))
1930 (goto-char (point-max))
1931 (gnus-insert-next-page-button)))))
1933 ;; Article mode commands
1935 (defun gnus-article-goto-next-page ()
1936 "Show the next page of the article."
1938 (when (gnus-article-next-page)
1939 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
1941 (defun gnus-article-goto-prev-page ()
1942 "Show the next page of the article."
1944 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
1945 (gnus-article-prev-page nil)))
1947 (defun gnus-article-next-page (&optional lines)
1948 "Show the next page of the current article.
1949 If end of article, return non-nil. Otherwise return nil.
1950 Argument LINES specifies lines to be scrolled up."
1952 (move-to-window-line -1)
1955 (and (pos-visible-in-window-p) ;Not continuation line.
1957 ;; Nothing in this page.
1958 (if (or (not gnus-break-pages)
1961 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
1963 (gnus-narrow-to-page 1) ;Go to next page.
1965 ;; More in this page.
1966 (let ((scroll-in-place nil))
1970 ;; Long lines may cause an end-of-buffer error.
1971 (goto-char (point-max)))))
1972 (move-to-window-line 0)
1975 (defun gnus-article-prev-page (&optional lines)
1976 "Show previous page of current article.
1977 Argument LINES specifies lines to be scrolled down."
1979 (move-to-window-line 0)
1980 (if (and gnus-break-pages
1982 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
1984 (gnus-narrow-to-page -1) ;Go to previous page.
1985 (goto-char (point-max))
1987 (let ((scroll-in-place nil))
1990 (scroll-down lines))
1991 (move-to-window-line 0)))))
1993 (defun gnus-article-refer-article ()
1994 "Read article specified by message-id around point."
1996 (let ((point (point)))
1997 (search-forward ">" nil t) ;Move point to end of "<....>".
1998 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
1999 (let ((message-id (match-string 1)))
2001 (set-buffer gnus-summary-buffer)
2002 (gnus-summary-refer-article message-id))
2004 (error "No references around point"))))
2006 (defun gnus-article-show-summary ()
2007 "Reconfigure windows to show summary buffer."
2009 (gnus-configure-windows 'article)
2010 (gnus-summary-goto-subject gnus-current-article))
2012 (defun gnus-article-describe-briefly ()
2013 "Describe article mode commands briefly."
2016 (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")))
2018 (defun gnus-article-summary-command ()
2019 "Execute the last keystroke in the summary buffer."
2021 (let ((obuf (current-buffer))
2022 (owin (current-window-configuration))
2024 (switch-to-buffer gnus-summary-buffer 'norecord)
2025 (setq func (lookup-key (current-local-map) (this-command-keys)))
2026 (call-interactively func)
2028 (set-window-configuration owin)
2029 (set-window-point (get-buffer-window (current-buffer)) (point))))
2031 (defun gnus-article-summary-command-nosave ()
2032 "Execute the last keystroke in the summary buffer."
2035 (pop-to-buffer gnus-summary-buffer 'norecord)
2036 (setq func (lookup-key (current-local-map) (this-command-keys)))
2037 (call-interactively func)))
2039 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2040 "Read a summary buffer key sequence and execute it from the article buffer."
2043 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2044 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2045 "=" "^" "\M-^" "|"))
2052 (set-buffer gnus-summary-buffer)
2053 (push (or key last-command-event) unread-command-events)
2054 (setq keys (read-key-sequence nil)))
2057 (if (or (member keys nosaves)
2058 (member keys nosave-but-article)
2059 (member keys nosave-in-article))
2061 (save-window-excursion
2062 (pop-to-buffer gnus-summary-buffer 'norecord)
2063 (setq func (lookup-key (current-local-map) keys)))
2066 (unless (member keys nosave-in-article)
2067 (set-buffer gnus-summary-buffer))
2068 (call-interactively func))
2069 (when (member keys nosave-but-article)
2070 (pop-to-buffer gnus-article-buffer 'norecord)))
2071 ;; These commands should restore window configuration.
2072 (let ((obuf (current-buffer))
2073 (owin (current-window-configuration))
2076 (if not-restore-window
2077 (pop-to-buffer gnus-summary-buffer 'norecord)
2078 (switch-to-buffer gnus-summary-buffer 'norecord))
2079 (setq in-buffer (current-buffer))
2080 (if (setq func (lookup-key (current-local-map) keys))
2081 (call-interactively func)
2083 (when (eq in-buffer (current-buffer))
2085 (unless not-restore-window
2086 (set-window-configuration owin))
2087 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2089 (defun gnus-article-hide (&optional arg force)
2090 "Hide all the gruft in the current article.
2091 This means that PGP stuff, signatures, cited text and (some)
2092 headers will be hidden.
2093 If given a prefix, show the hidden text instead."
2094 (interactive (list current-prefix-arg 'force))
2095 (gnus-article-hide-headers arg)
2096 (gnus-article-hide-pgp arg)
2097 (gnus-article-hide-citation-maybe arg force)
2098 (gnus-article-hide-signature arg))
2100 (defun gnus-article-maybe-highlight ()
2101 "Do some article highlighting if `article-visual' is non-nil."
2102 (when (gnus-visual-p 'article-highlight 'highlight)
2103 (gnus-article-highlight-some)))
2105 (defun gnus-request-article-this-buffer (article group)
2106 "Get an article and insert it into this buffer."
2107 (let (do-update-line)
2111 (gnus-kill-all-overlays)
2112 (setq group (or group gnus-newsgroup-name))
2114 ;; Open server if it has closed.
2115 (gnus-check-server (gnus-find-method-for-group group))
2117 ;; Using `gnus-request-article' directly will insert the article into
2118 ;; `nntp-server-buffer' - so we'll save some time by not having to
2119 ;; copy it from the server buffer into the article buffer.
2121 ;; We only request an article by message-id when we do not have the
2122 ;; headers for it, so we'll have to get those.
2123 (when (stringp article)
2124 (let ((gnus-override-method gnus-refer-article-method))
2125 (gnus-read-header article)))
2127 ;; If the article number is negative, that means that this article
2128 ;; doesn't belong in this newsgroup (possibly), so we find its
2129 ;; message-id and request it by id instead of number.
2130 (when (and (numberp article)
2132 (get-buffer gnus-summary-buffer)
2133 (buffer-name (get-buffer gnus-summary-buffer)))
2135 (set-buffer gnus-summary-buffer)
2136 (let ((header (gnus-summary-article-header article)))
2139 ((memq article gnus-newsgroup-sparse)
2140 ;; This is a sparse gap article.
2141 (setq do-update-line article)
2142 (setq article (mail-header-id header))
2143 (let ((gnus-override-method gnus-refer-article-method))
2144 (gnus-read-header article))
2145 (setq gnus-newsgroup-sparse
2146 (delq article gnus-newsgroup-sparse)))
2148 ;; It's a real article.
2149 (setq article (mail-header-id header)))
2151 ;; It is an extracted pseudo-article.
2152 (setq article 'pseudo)
2153 (gnus-request-pseudo-article header))))
2155 (let ((method (gnus-find-method-for-group
2156 gnus-newsgroup-name)))
2157 (if (not (eq (car method) 'nneething))
2159 (let ((dir (concat (file-name-as-directory (nth 1 method))
2160 (mail-header-subject header))))
2161 (when (file-directory-p dir)
2162 (setq article 'nneething)
2163 (gnus-group-enter-directory dir))))))))
2166 ;; Refuse to select canceled articles.
2167 ((and (numberp article)
2169 (get-buffer gnus-summary-buffer)
2170 (buffer-name (get-buffer gnus-summary-buffer))
2171 (eq (cdr (save-excursion
2172 (set-buffer gnus-summary-buffer)
2173 (assq article gnus-newsgroup-reads)))
2174 gnus-canceled-mark))
2176 ;; We first check `gnus-original-article-buffer'.
2177 ((and (get-buffer gnus-original-article-buffer)
2180 (set-buffer gnus-original-article-buffer)
2181 (and (equal (car gnus-original-article) group)
2182 (eq (cdr gnus-original-article) article))))
2183 (insert-buffer-substring gnus-original-article-buffer)
2185 ;; Check the backlog.
2186 ((and gnus-keep-backlog
2187 (gnus-backlog-request-article group article (current-buffer)))
2189 ;; Check asynchronous pre-fetch.
2190 ((gnus-async-request-fetched-article group article (current-buffer))
2191 (gnus-async-prefetch-next group article gnus-summary-buffer)
2194 ((and gnus-use-cache
2196 (gnus-cache-request-article article group))
2198 ;; Get the article and put into the article buffer.
2199 ((or (stringp article) (numberp article))
2200 (let ((gnus-override-method
2201 (and (stringp article) gnus-refer-article-method))
2202 (buffer-read-only nil))
2204 (gnus-kill-all-overlays)
2205 (when (gnus-request-article article group (current-buffer))
2206 (when (numberp article)
2207 (gnus-async-prefetch-next group article gnus-summary-buffer)
2208 (when gnus-keep-backlog
2209 (gnus-backlog-enter-article
2210 group article (current-buffer))))
2215 ;; Take the article from the original article buffer
2216 ;; and place it in the buffer it's supposed to be in.
2217 (when (and (get-buffer gnus-article-buffer)
2219 (equal (buffer-name (current-buffer))
2220 (buffer-name (get-buffer gnus-article-buffer))))
2222 (if (get-buffer gnus-original-article-buffer)
2223 (set-buffer (get-buffer gnus-original-article-buffer))
2224 (set-buffer (get-buffer-create gnus-original-article-buffer))
2225 (buffer-disable-undo (current-buffer))
2226 (setq major-mode 'gnus-original-article-mode)
2227 (setq buffer-read-only t)
2228 (gnus-add-current-to-buffer-list))
2229 (let (buffer-read-only)
2231 (insert-buffer-substring gnus-article-buffer))
2232 (setq gnus-original-article (cons group article))))
2234 ;; Update sparse articles.
2235 (when (and do-update-line
2236 (or (numberp article)
2238 (let ((buf (current-buffer)))
2239 (set-buffer gnus-summary-buffer)
2240 (gnus-summary-update-article do-update-line)
2241 (gnus-summary-goto-subject do-update-line nil t)
2242 (set-window-point (get-buffer-window (current-buffer) t)
2244 (set-buffer buf))))))
2250 (defcustom gnus-article-edit-mode-hook nil
2251 "Hook run in article edit mode buffers."
2255 (defvar gnus-article-edit-done-function nil)
2257 (defvar gnus-article-edit-mode-map nil)
2259 (unless gnus-article-edit-mode-map
2260 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2262 (gnus-define-keys gnus-article-edit-mode-map
2263 "\C-c\C-c" gnus-article-edit-done
2264 "\C-c\C-k" gnus-article-edit-exit)
2266 (gnus-define-keys (gnus-article-edit-wash-map
2267 "\C-c\C-w" gnus-article-edit-mode-map)
2268 "f" gnus-article-edit-full-stops))
2270 (defun gnus-article-edit-mode ()
2271 "Major mode for editing articles.
2272 This is an extended text-mode.
2274 \\{gnus-article-edit-mode-map}"
2276 (kill-all-local-variables)
2277 (setq major-mode 'gnus-article-edit-mode)
2278 (setq mode-name "Article Edit")
2279 (use-local-map gnus-article-edit-mode-map)
2280 (make-local-variable 'gnus-article-edit-done-function)
2281 (make-local-variable 'gnus-prev-winconf)
2282 (setq buffer-read-only nil)
2283 (buffer-enable-undo)
2285 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2287 (defun gnus-article-edit (&optional force)
2288 "Edit the current article.
2289 This will have permanent effect only in mail groups.
2290 If FORCE is non-nil, allow editing of articles even in read-only
2293 (when (and (not force)
2294 (gnus-group-read-only-p))
2295 (error "The current newsgroup does not support article editing."))
2296 (gnus-article-edit-article
2298 (gnus-summary-edit-article-done
2299 ,(or (mail-header-references gnus-current-headers) "")
2300 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2302 (defun gnus-article-edit-article (exit-func)
2303 "Start editing the contents of the current article buffer."
2304 (let ((winconf (current-window-configuration)))
2305 (set-buffer gnus-article-buffer)
2306 (gnus-article-edit-mode)
2307 (set-text-properties (point-min) (point-max) nil)
2308 (gnus-configure-windows 'edit-article)
2309 (setq gnus-article-edit-done-function exit-func)
2310 (setq gnus-prev-winconf winconf)
2311 (gnus-message 6 "C-c C-c to end edits")))
2313 (defun gnus-article-edit-done ()
2314 "Update the article edits and exit."
2316 (let ((func gnus-article-edit-done-function)
2317 (buf (current-buffer))
2318 (start (window-start)))
2319 (gnus-article-edit-exit)
2322 (let ((buffer-read-only nil))
2325 (set-window-start (get-buffer-window buf) start)
2326 (set-window-point (get-buffer-window buf) (point))))
2328 (defun gnus-article-edit-exit ()
2329 "Exit the article editing without updating."
2331 ;; We remove all text props from the article buffer.
2332 (let ((buf (format "%s" (buffer-string)))
2333 (curbuf (current-buffer))
2335 (window-start (window-start)))
2338 (let ((winconf gnus-prev-winconf))
2340 ;; The cache and backlog have to be flushed somewhat.
2341 (when gnus-use-cache
2342 (gnus-cache-update-article
2343 (car gnus-article-current) (cdr gnus-article-current)))
2344 (when gnus-keep-backlog
2345 (gnus-backlog-remove-article
2346 (car gnus-article-current) (cdr gnus-article-current)))
2347 ;; Flush original article as well.
2349 (when (get-buffer gnus-original-article-buffer)
2350 (set-buffer gnus-original-article-buffer)
2351 (setq gnus-original-article nil)))
2352 (set-window-configuration winconf)
2353 ;; Tippy-toe some to make sure that point remains where it was.
2354 (let ((buf (current-buffer)))
2356 (set-window-start (get-buffer-window (current-buffer)) window-start)
2358 (set-buffer buf)))))
2360 (defun gnus-article-edit-full-stops ()
2361 "Interactively repair spacing at end of sentences."
2364 (goto-char (point-min))
2365 (search-forward-regexp "^$" nil t)
2366 (let ((case-fold-search nil))
2367 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2370 ;;; Article highlights
2373 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2375 ;;; Internal Variables:
2377 (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\\)"
2378 "Regular expression that matches URLs."
2382 (defcustom gnus-button-alist
2383 `(("\\(<?\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>?\\)" 1 t
2384 gnus-button-fetch-group 4)
2385 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2386 t gnus-button-message-id 3)
2387 ("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
2388 gnus-button-message-id 3)
2389 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
2390 ;; This is how URLs _should_ be embedded in text...
2391 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2393 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2394 "Alist of regexps matching buttons in article bodies.
2396 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2397 REGEXP: is the string matching text around the button,
2398 BUTTON: is the number of the regexp grouping actually matching the button,
2399 FORM: is a lisp expression which must eval to true for the button to
2401 CALLBACK: is the function to call when the user push this button, and each
2402 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2404 CALLBACK can also be a variable, in that case the value of that
2405 variable it the real callback function."
2407 :type '(repeat (list regexp
2408 (integer :tag "Button")
2410 (function :tag "Callback")
2413 (integer :tag "Regexp group")))))
2415 (defcustom gnus-header-button-alist
2416 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2417 0 t gnus-button-message-id 0)
2418 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2419 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2420 0 t gnus-button-mailto 0)
2421 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2422 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2423 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2424 gnus-button-message-id 3))
2425 "Alist of headers and regexps to match buttons in article heads.
2427 This alist is very similar to `gnus-button-alist', except that each
2428 alist has an additional HEADER element first in each entry:
2430 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2432 HEADER is a regexp to match a header. For a fuller explanation, see
2433 `gnus-button-alist'."
2435 :type '(repeat (list (regexp :tag "Header")
2437 (integer :tag "Button")
2439 (function :tag "Callback")
2442 (integer :tag "Regexp group")))))
2444 (defvar gnus-button-regexp nil)
2445 (defvar gnus-button-marker-list nil)
2446 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2448 (defvar gnus-button-last nil)
2449 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2453 (defun gnus-article-push-button (event)
2454 "Check text under the mouse pointer for a callback function.
2455 If the text under the mouse pointer has a `gnus-callback' property,
2456 call it with the value of the `gnus-data' text property."
2458 (set-buffer (window-buffer (posn-window (event-start event))))
2459 (let* ((pos (posn-point (event-start event)))
2460 (data (get-text-property pos 'gnus-data))
2461 (fun (get-text-property pos 'gnus-callback)))
2463 (funcall fun data))))
2465 (defun gnus-article-press-button ()
2466 "Check text at point for a callback function.
2467 If the text at point has a `gnus-callback' property,
2468 call it with the value of the `gnus-data' text property."
2470 (let* ((data (get-text-property (point) 'gnus-data))
2471 (fun (get-text-property (point) 'gnus-callback)))
2473 (funcall fun data))))
2475 (defun gnus-article-prev-button (n)
2476 "Move point to N buttons backward.
2477 If N is negative, move forward instead."
2479 (gnus-article-next-button (- n)))
2481 (defun gnus-article-next-button (n)
2482 "Move point to N buttons forward.
2483 If N is negative, move backward instead."
2485 (let ((function (if (< n 0) 'previous-single-property-change
2486 'next-single-property-change))
2487 (inhibit-point-motion-hooks t)
2489 (limit (if (< n 0) (point-min) (point-max))))
2491 (while (and (not (= limit (point)))
2493 ;; Skip past the current button.
2494 (when (get-text-property (point) 'gnus-callback)
2495 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2496 ;; Go to the next (or previous) button.
2497 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2498 ;; Put point at the start of the button.
2499 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2500 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2501 ;; Skip past intangible buttons.
2502 (when (get-text-property (point) 'intangible)
2506 (gnus-message 5 "No more buttons"))
2509 (defun gnus-article-highlight (&optional force)
2510 "Highlight current article.
2511 This function calls `gnus-article-highlight-headers',
2512 `gnus-article-highlight-citation',
2513 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2514 do the highlighting. See the documentation for those functions."
2515 (interactive (list 'force))
2516 (gnus-article-highlight-headers)
2517 (gnus-article-highlight-citation force)
2518 (gnus-article-highlight-signature)
2519 (gnus-article-add-buttons force)
2520 (gnus-article-add-buttons-to-head))
2522 (defun gnus-article-highlight-some (&optional force)
2523 "Highlight current article.
2524 This function calls `gnus-article-highlight-headers',
2525 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2526 do the highlighting. See the documentation for those functions."
2527 (interactive (list 'force))
2528 (gnus-article-highlight-headers)
2529 (gnus-article-highlight-signature)
2530 (gnus-article-add-buttons))
2532 (defun gnus-article-highlight-headers ()
2533 "Highlight article headers as specified by `gnus-header-face-alist'."
2536 (set-buffer gnus-article-buffer)
2538 (let ((alist gnus-header-face-alist)
2539 (buffer-read-only nil)
2540 (case-fold-search t)
2541 (inhibit-point-motion-hooks t)
2542 entry regexp header-face field-face from hpoints fpoints)
2543 (goto-char (point-min))
2544 (when (search-forward "\n\n" nil t)
2545 (narrow-to-region (1- (point)) (point-min))
2546 (while (setq entry (pop alist))
2547 (goto-char (point-min))
2548 (setq regexp (concat "^\\("
2549 (if (string-equal "" (nth 0 entry))
2553 header-face (nth 1 entry)
2554 field-face (nth 2 entry))
2555 (while (and (re-search-forward regexp nil t)
2559 (unless (search-forward ":" nil t)
2561 (when (and header-face
2562 (not (memq (point) hpoints)))
2563 (push (point) hpoints)
2564 (gnus-put-text-property from (point) 'face header-face))
2565 (when (and field-face
2566 (not (memq (setq from (point)) fpoints)))
2568 (if (re-search-forward "^[^ \t]" nil t)
2570 (goto-char (point-max)))
2571 (gnus-put-text-property from (point) 'face field-face)))))))))
2573 (defun gnus-article-highlight-signature ()
2574 "Highlight the signature in an article.
2575 It does this by highlighting everything after
2576 `gnus-signature-separator' using `gnus-signature-face'."
2579 (set-buffer gnus-article-buffer)
2580 (let ((buffer-read-only nil)
2581 (inhibit-point-motion-hooks t))
2583 (when (and gnus-signature-face
2584 (gnus-article-narrow-to-signature))
2585 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2586 'face gnus-signature-face)
2588 (gnus-article-search-signature)
2589 (let ((start (match-beginning 0))
2590 (end (set-marker (make-marker) (1+ (match-end 0)))))
2591 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2594 (defun gnus-article-add-buttons (&optional force)
2595 "Find external references in the article and make buttons of them.
2596 \"External references\" are things like Message-IDs and URLs, as
2597 specified by `gnus-button-alist'."
2598 (interactive (list 'force))
2600 (set-buffer gnus-article-buffer)
2601 ;; Remove all old markers.
2602 (while gnus-button-marker-list
2603 (set-marker (pop gnus-button-marker-list) nil))
2604 (let ((buffer-read-only nil)
2605 (inhibit-point-motion-hooks t)
2606 (case-fold-search t)
2607 (alist gnus-button-alist)
2609 (goto-char (point-min))
2610 ;; We skip the headers.
2611 (unless (search-forward "\n\n" nil t)
2612 (goto-char (point-max)))
2614 (while (setq entry (pop alist))
2615 (setq regexp (car entry))
2617 (while (re-search-forward regexp nil t)
2618 (let* ((start (and entry (match-beginning (nth 1 entry))))
2619 (end (and entry (match-end (nth 1 entry))))
2620 (from (match-beginning 0)))
2621 (when (and (or (eq t (nth 1 entry))
2622 (eval (nth 1 entry)))
2623 (not (get-text-property (point) 'gnus-callback)))
2624 ;; That optional form returned non-nil, so we add the
2626 (gnus-article-add-button
2627 start end 'gnus-button-push
2628 (car (push (set-marker (make-marker) from)
2629 gnus-button-marker-list))))))))))
2631 ;; Add buttons to the head of an article.
2632 (defun gnus-article-add-buttons-to-head ()
2633 "Add buttons to the head of the article."
2636 (set-buffer gnus-article-buffer)
2637 (let ((buffer-read-only nil)
2638 (inhibit-point-motion-hooks t)
2639 (case-fold-search t)
2640 (alist gnus-header-button-alist)
2642 (nnheader-narrow-to-headers)
2644 ;; Each alist entry.
2645 (setq entry (car alist)
2647 (goto-char (point-min))
2648 (while (re-search-forward (car entry) nil t)
2649 ;; Each header matching the entry.
2650 (setq beg (match-beginning 0))
2651 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2652 (match-beginning 0))
2655 (while (re-search-forward (nth 1 entry) end t)
2656 ;; Each match within a header.
2657 (let* ((entry (cdr entry))
2658 (start (match-beginning (nth 1 entry)))
2659 (end (match-end (nth 1 entry)))
2660 (form (nth 2 entry)))
2661 (goto-char (match-end 0))
2663 (gnus-article-add-button
2664 start end (nth 3 entry)
2665 (buffer-substring (match-beginning (nth 4 entry))
2666 (match-end (nth 4 entry)))))))
2670 ;;; External functions:
2672 (defun gnus-article-add-button (from to fun &optional data)
2673 "Create a button between FROM and TO with callback FUN and data DATA."
2674 (when gnus-article-button-face
2675 (gnus-overlay-put (gnus-make-overlay from to)
2676 'face gnus-article-button-face))
2677 (gnus-add-text-properties
2679 (nconc (and gnus-article-mouse-face
2680 (list gnus-mouse-face-prop gnus-article-mouse-face))
2681 (list 'gnus-callback fun)
2682 (and data (list 'gnus-data data)))))
2684 ;;; Internal functions:
2686 (defun gnus-signature-toggle (end)
2688 (set-buffer gnus-article-buffer)
2689 (let ((buffer-read-only nil)
2690 (inhibit-point-motion-hooks t))
2691 (if (get-text-property end 'invisible)
2692 (gnus-article-unhide-text end (point-max))
2693 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2695 (defun gnus-button-entry ()
2696 ;; Return the first entry in `gnus-button-alist' matching this place.
2697 (let ((alist gnus-button-alist)
2700 (setq entry (pop alist))
2701 (if (looking-at (car entry))
2706 (defun gnus-button-push (marker)
2707 ;; Push button starting at MARKER.
2709 (set-buffer gnus-article-buffer)
2711 (let* ((entry (gnus-button-entry))
2712 (inhibit-point-motion-hooks t)
2714 (args (mapcar (lambda (group)
2715 (let ((string (match-string group)))
2716 (gnus-set-text-properties
2717 0 (length string) nil string)
2724 (fboundp (symbol-value fun)))
2725 (apply (symbol-value fun) args))
2727 (gnus-message 1 "You must define `%S' to use this button"
2728 (cons fun args)))))))
2730 (defun gnus-button-message-id (message-id)
2733 (set-buffer gnus-summary-buffer)
2734 (gnus-summary-refer-article message-id)))
2736 (defun gnus-button-fetch-group (address)
2737 "Fetch GROUP specified by ADDRESS."
2738 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
2739 (error "Can't parse %s" address)
2740 (gnus-group-read-ephemeral-group
2741 (match-string 4 address)
2742 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
2743 (nntp-port-number ,(if (match-end 3)
2744 (match-string 3 address)
2747 (defun gnus-split-string (string pattern)
2748 "Return a list of substrings of STRING which are separated by PATTERN."
2749 (let (parts (start 0))
2750 (while (string-match pattern string start)
2751 (setq parts (cons (substring string start (match-beginning 0)) parts)
2752 start (match-end 0)))
2753 (nreverse (cons (substring string start) parts))))
2755 (defun gnus-url-parse-query-string (query &optional downcase)
2756 (let (retval pairs cur key val)
2757 (setq pairs (gnus-split-string query "&"))
2759 (setq cur (car pairs)
2761 (if (not (string-match "=" cur))
2763 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2764 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2766 (setq key (downcase key)))
2767 (setq cur (assoc key retval))
2769 (setcdr cur (cons val (cdr cur)))
2770 (setq retval (cons (list key val) retval)))))
2773 (defun gnus-url-unhex (x)
2780 (defun gnus-url-unhex-string (str &optional allow-newlines)
2781 "Remove %XXX embedded spaces, etc in a url.
2782 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2783 decoding of carriage returns and line feeds in the string, which is normally
2784 forbidden in URL encoding."
2785 (setq str (or str ""))
2787 (case-fold-search t))
2788 (while (string-match "%[0-9a-f][0-9a-f]" str)
2789 (let* ((start (match-beginning 0))
2790 (ch1 (gnus-url-unhex (elt str (+ start 1))))
2792 (gnus-url-unhex (elt str (+ start 2))))))
2794 tmp (substring str 0 start)
2797 (char-to-string code))
2798 ((or (= code ?\n) (= code ?\r))
2800 (t (char-to-string code))))
2801 str (substring str (match-end 0)))))
2802 (setq tmp (concat tmp str))
2805 (defun gnus-url-mailto (url)
2806 ;; Send mail to someone
2807 (if (not (string-match "mailto:/*\\(.*\\)" url))
2808 (error "Malformed mailto link: %s" url))
2809 (setq url (substring url (match-beginning 1) nil))
2810 (let (to args source-url subject func)
2811 (if (string-match (regexp-quote "?") url)
2812 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2813 args (gnus-url-parse-query-string
2814 (substring url (match-end 0) nil) t))
2815 (setq to (gnus-url-unhex-string url)))
2816 (setq args (cons (list "to" to) args)
2817 subject (cdr-safe (assoc "subject" args)))
2820 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2823 (message-position-on-field (caar args)))
2824 (insert (mapconcat 'identity (cdar args) ", "))
2825 (setq args (cdr args)))
2828 (message-goto-subject))))
2830 (defun gnus-button-mailto (address)
2832 (set-buffer (gnus-copy-article-buffer))
2833 (message-reply address))
2835 (defun gnus-button-reply (address)
2836 ;; Reply to ADDRESS.
2837 (message-reply address))
2839 (defun gnus-button-url (address)
2841 (funcall browse-url-browser-function address))
2843 (defun gnus-button-embedded-url (address)
2845 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2847 ;;; Next/prev buttons in the article buffer.
2849 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
2850 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
2852 (defvar gnus-prev-page-map nil)
2853 (unless gnus-prev-page-map
2854 (setq gnus-prev-page-map (make-sparse-keymap))
2855 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
2856 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
2858 (defun gnus-insert-prev-page-button ()
2859 (let ((buffer-read-only nil))
2861 gnus-prev-page-line-format nil
2862 `(gnus-prev t local-map ,gnus-prev-page-map
2863 gnus-callback gnus-article-button-prev-page))))
2865 (defvar gnus-next-page-map nil)
2866 (unless gnus-next-page-map
2867 (setq gnus-next-page-map (make-keymap))
2868 (suppress-keymap gnus-prev-page-map)
2869 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
2870 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
2872 (defun gnus-button-next-page ()
2873 "Go to the next page."
2875 (let ((win (selected-window)))
2876 (select-window (get-buffer-window gnus-article-buffer t))
2877 (gnus-article-next-page)
2878 (select-window win)))
2880 (defun gnus-button-prev-page ()
2881 "Go to the prev page."
2883 (let ((win (selected-window)))
2884 (select-window (get-buffer-window gnus-article-buffer t))
2885 (gnus-article-prev-page)
2886 (select-window win)))
2888 (defun gnus-insert-next-page-button ()
2889 (let ((buffer-read-only nil))
2890 (gnus-eval-format gnus-next-page-line-format nil
2891 `(gnus-next t local-map ,gnus-next-page-map
2893 gnus-article-button-next-page))))
2895 (defun gnus-article-button-next-page (arg)
2896 "Go to the next page."
2898 (let ((win (selected-window)))
2899 (select-window (get-buffer-window gnus-article-buffer t))
2900 (gnus-article-next-page)
2901 (select-window win)))
2903 (defun gnus-article-button-prev-page (arg)
2904 "Go to the prev page."
2906 (let ((win (selected-window)))
2907 (select-window (get-buffer-window gnus-article-buffer t))
2908 (gnus-article-prev-page)
2909 (select-window win)))
2913 (run-hooks 'gnus-art-load-hook)
2915 ;;; gnus-art.el ends here