1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97 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*/_)."
188 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
189 "Format for display of Date headers in article bodies.
190 See `format-time-zone' for the possible values."
195 (autoload 'hexl-hex-string-to-integer "hexl")
196 (autoload 'timezone-make-date-arpa-standard "timezone")
197 (autoload 'mail-extract-address-components "mail-extr"))
199 (defcustom gnus-article-save-directory gnus-directory
200 "*Name of the directory articles will be saved in (default \"~/News\")."
204 (defcustom gnus-save-all-headers t
205 "*If non-nil, don't remove any headers before saving."
209 (defcustom gnus-prompt-before-saving 'always
210 "*This variable says how much prompting is to be done when saving articles.
211 If it is nil, no prompting will be done, and the articles will be
212 saved to the default files. If this variable is `always', each and
213 every article that is saved will be preceded by a prompt, even when
214 saving large batches of articles. If this variable is neither nil not
215 `always', there the user will be prompted once for a file name for
216 each invocation of the saving commands."
218 :type '(choice (item always)
219 (item :tag "never" nil)
220 (sexp :tag "once" :format "%t")))
222 (defcustom gnus-saved-headers gnus-visible-headers
223 "Headers to keep if `gnus-save-all-headers' is nil.
224 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
225 If that variable is nil, however, all headers that match this regexp
226 will be kept while the rest will be deleted before saving."
228 :type '(repeat string))
230 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
231 "A function to save articles in your favourite format.
232 The function must be interactively callable (in other words, it must
233 be an Emacs command).
235 Gnus provides the following functions:
237 * gnus-summary-save-in-rmail (Rmail format)
238 * gnus-summary-save-in-mail (Unix mail format)
239 * gnus-summary-save-in-folder (MH folder)
240 * gnus-summary-save-in-file (article format)
241 * gnus-summary-save-in-vm (use VM's folder format)
242 * gnus-summary-write-to-file (article format -- overwrite)."
244 :type '(radio (function-item gnus-summary-save-in-rmail)
245 (function-item gnus-summary-save-in-mail)
246 (function-item gnus-summary-save-in-folder)
247 (function-item gnus-summary-save-in-file)
248 (function-item gnus-summary-save-in-vm)
249 (function-item gnus-summary-write-to-file)))
251 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
252 "A function generating a file name to save articles in Rmail format.
253 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
257 (defcustom gnus-mail-save-name 'gnus-plain-save-name
258 "A function generating a file name to save articles in Unix mail format.
259 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
263 (defcustom gnus-folder-save-name 'gnus-folder-save-name
264 "A function generating a file name to save articles in MH folder.
265 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
269 (defcustom gnus-file-save-name 'gnus-numeric-save-name
270 "A function generating a file name to save articles in article format.
271 The function is called with NEWSGROUP, HEADERS, and optional
276 (defcustom gnus-split-methods
277 '((gnus-article-archive-name))
278 "Variable used to suggest where articles are to be saved.
279 For instance, if you would like to save articles related to Gnus in
280 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
281 you could set this variable to something like:
283 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
284 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
286 This variable is an alist where the where the key is the match and the
287 value is a list of possible files to save in if the match is non-nil.
289 If the match is a string, it is used as a regexp match on the
290 article. If the match is a symbol, that symbol will be funcalled
291 from the buffer of the article to be saved with the newsgroup as the
292 parameter. If it is a list, it will be evaled in the same buffer.
294 If this form or function returns a string, this string will be used as
295 a possible file name; and if it returns a non-nil list, that list will
296 be used as possible file names."
298 :type '(repeat (choice (list function)
299 (cons regexp (repeat string))
302 (defcustom gnus-strict-mime t
303 "*If nil, MIME-decode even if there is no Mime-Version header."
307 (defcustom gnus-show-mime-method 'metamail-buffer
308 "Function to process a MIME message.
309 The function is called from the article buffer."
313 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
314 "*Function to decode MIME encoded words.
315 The function is called from the article buffer."
319 (defcustom gnus-page-delimiter "^\^L"
320 "*Regexp describing what to use as article page delimiters.
321 The default value is \"^\^L\", which is a form linefeed at the
322 beginning of a line."
326 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
327 "*The format specification for the article mode line.
328 See `gnus-summary-mode-line-format' for a closer description."
332 (defcustom gnus-article-mode-hook nil
333 "*A hook for Gnus article mode."
337 (defcustom gnus-article-menu-hook nil
338 "*Hook run after the creation of the article mode menu."
342 (defcustom gnus-article-prepare-hook nil
343 "*A hook called after an article has been prepared in the article buffer.
344 If you want to run a special decoding program like nkf, use this hook."
348 (defcustom gnus-article-button-face 'bold
349 "Face used for highlighting buttons in the article buffer.
351 An article button is a piece of text that you can activate by pressing
352 `RET' or `mouse-2' above it."
356 (defcustom gnus-article-mouse-face 'highlight
357 "Face used for mouse highlighting in the article buffer.
359 Article buttons will be displayed in this face when the cursor is
364 (defcustom gnus-signature-face 'italic
365 "Face used for highlighting a signature in the article buffer."
369 (defface gnus-header-from-face
372 (:foreground "light blue" :bold t :italic t))
375 (:foreground "MidnightBlue" :bold t :italic t))
377 (:bold t :italic t)))
378 "Face used for displaying from headers."
381 (defface gnus-header-subject-face
384 (:foreground "pink" :bold t :italic t))
387 (:foreground "firebrick" :bold t :italic t))
389 (:bold t :italic t)))
390 "Face used for displaying subject headers."
393 (defface gnus-header-newsgroups-face
396 (:foreground "yellow" :bold t :italic t))
399 (:foreground "indianred" :bold t :italic t))
401 (:bold t :italic t)))
402 "Face used for displaying newsgroups headers."
405 (defface gnus-header-name-face
408 (:foreground "cyan" :bold t))
411 (:foreground "DarkGreen" :bold t))
414 "Face used for displaying header names."
417 (defface gnus-header-content-face
420 (:foreground "forest green" :italic t))
423 (:foreground "DarkGreen" :italic t))
425 (:italic t))) "Face used for displaying header content."
428 (defcustom gnus-header-face-alist
429 '(("From" nil gnus-header-from-face)
430 ("Subject" nil gnus-header-subject-face)
431 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
432 ("" gnus-header-name-face gnus-header-content-face))
433 "Controls highlighting of article header.
435 An alist of the form (HEADER NAME CONTENT).
437 HEADER is a regular expression which should match the name of an
438 header header and NAME and CONTENT are either face names or nil.
440 The name of each header field will be displayed using the face
441 specified by the first element in the list where HEADER match the
442 header name and NAME is non-nil. Similarly, the content will be
443 displayed by the first non-nil matching CONTENT face."
445 :type '(repeat (list (regexp :tag "Header")
447 (item :tag "skip" nil)
448 (face :value default))
449 (choice :tag "Content"
450 (item :tag "skip" nil)
451 (face :value default)))))
453 ;;; Internal variables
455 (defvar gnus-article-mode-syntax-table
456 (let ((table (copy-syntax-table text-mode-syntax-table)))
457 ;;(modify-syntax-entry ?_ "w" table)
459 "Syntax table used in article mode buffers.
460 Initialized from `text-mode-syntax-table.")
462 (defvar gnus-save-article-buffer nil)
464 (defvar gnus-article-mode-line-format-alist
465 (nconc '((?w (gnus-article-wash-status) ?s))
466 gnus-summary-mode-line-format-alist))
468 (defvar gnus-number-of-articles-to-be-saved nil)
470 (defvar gnus-inhibit-hiding nil)
471 (defvar gnus-newsgroup-name)
473 (defsubst gnus-article-hide-text (b e props)
474 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
475 (add-text-properties b e props)
476 (when (memq 'intangible props)
478 (max (1- b) (point-min))
479 b 'intangible (cddr (memq 'intangible props)))))
481 (defsubst gnus-article-unhide-text (b e)
482 "Remove hidden text properties from region between B and E."
483 (remove-text-properties b e gnus-hidden-properties)
484 (when (memq 'intangible gnus-hidden-properties)
485 (put-text-property (max (1- b) (point-min))
488 (defun gnus-article-hide-text-type (b e type)
489 "Hide text of TYPE between B and E."
490 (gnus-article-hide-text
491 b e (cons 'article-type (cons type gnus-hidden-properties))))
493 (defun gnus-article-unhide-text-type (b e type)
494 "Hide text of TYPE between B and E."
495 (remove-text-properties
496 b e (cons 'article-type (cons type gnus-hidden-properties)))
497 (when (memq 'intangible gnus-hidden-properties)
498 (put-text-property (max (1- b) (point-min))
501 (defun gnus-article-hide-text-of-type (type)
502 "Hide text of TYPE in the current buffer."
504 (let ((b (point-min))
506 (while (setq b (text-property-any b e 'article-type type))
507 (add-text-properties b (incf b) gnus-hidden-properties)))))
509 (defun gnus-article-delete-text-of-type (type)
510 "Delete text of TYPE in the current buffer."
512 (let ((b (point-min)))
513 (while (setq b (text-property-any b (point-max) 'article-type type))
514 (delete-region b (incf b))))))
516 (defun gnus-article-delete-invisible-text ()
517 "Delete all invisible text in the current buffer."
519 (let ((b (point-min)))
520 (while (setq b (text-property-any b (point-max) 'invisible t))
521 (delete-region b (incf b))))))
523 (defun gnus-article-text-type-exists-p (type)
524 "Say whether any text of type TYPE exists in the buffer."
525 (text-property-any (point-min) (point-max) 'article-type type))
527 (defsubst gnus-article-header-rank ()
528 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
529 (let ((list gnus-sorted-header-list)
532 (when (looking-at (car list))
534 (setq list (cdr list))
538 (defun article-hide-headers (&optional arg delete)
539 "Toggle whether to hide unwanted headers and possibly sort them as well.
540 If given a negative prefix, always show; if given a positive prefix,
542 (interactive (gnus-article-hidden-arg))
543 (if (gnus-article-check-hidden-text 'headers arg)
544 ;; Show boring headers as well.
545 (gnus-article-show-hidden-text 'boring-headers)
546 ;; This function might be inhibited.
547 (unless gnus-inhibit-hiding
550 (let ((buffer-read-only nil)
551 (props (nconc (list 'article-type 'headers)
552 gnus-hidden-properties))
553 (max (1+ (length gnus-sorted-header-list)))
554 (ignored (when (not gnus-visible-headers)
555 (cond ((stringp gnus-ignored-headers)
556 gnus-ignored-headers)
557 ((listp gnus-ignored-headers)
558 (mapconcat 'identity gnus-ignored-headers
561 (cond ((stringp gnus-visible-headers)
562 gnus-visible-headers)
563 ((and gnus-visible-headers
564 (listp gnus-visible-headers))
565 (mapconcat 'identity gnus-visible-headers "\\|"))))
566 (inhibit-point-motion-hooks t)
568 ;; First we narrow to just the headers.
570 (goto-char (point-min))
571 ;; Hide any "From " lines at the beginning of (mail) articles.
572 (while (looking-at "From ")
576 (delete-region (point-min) (point))
577 (gnus-article-hide-text (point-min) (point) props)))
578 ;; Then treat the rest of the header lines.
581 (if (search-forward "\n\n" nil t) ; if there's a body
582 (progn (forward-line -1) (point))
584 ;; Then we use the two regular expressions
585 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
586 ;; select which header lines is to remain visible in the
588 (goto-char (point-min))
589 (while (re-search-forward "^[^ \t]*:" nil t)
591 ;; Mark the rank of the header.
593 (point) (1+ (point)) 'message-rank
594 (if (or (and visible (looking-at visible))
596 (not (looking-at ignored))))
597 (gnus-article-header-rank)
600 (message-sort-headers-1)
601 (when (setq beg (text-property-any
602 (point-min) (point-max) 'message-rank (+ 2 max)))
603 ;; We make the unwanted headers invisible.
605 (delete-region beg (point-max))
606 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
607 (gnus-article-hide-text-type beg (point-max) 'headers))
608 ;; Work around XEmacs lossage.
609 (put-text-property (point-min) beg 'invisible nil))))))))
611 (defun article-hide-boring-headers (&optional arg)
612 "Toggle hiding of headers that aren't very interesting.
613 If given a negative prefix, always show; if given a positive prefix,
615 (interactive (gnus-article-hidden-arg))
616 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
617 (not gnus-show-all-headers))
620 (let ((buffer-read-only nil)
621 (list gnus-boring-article-headers)
622 (inhibit-point-motion-hooks t)
624 (nnheader-narrow-to-headers)
626 (setq elem (pop list))
627 (goto-char (point-min))
629 ;; Hide empty headers.
631 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
633 (gnus-article-hide-text-type
634 (progn (beginning-of-line) (point))
637 (if (re-search-forward "^[^ \t]" nil t)
641 ;; Hide boring Newsgroups header.
642 ((eq elem 'newsgroups)
643 (when (equal (gnus-fetch-field "newsgroups")
644 (gnus-group-real-name
645 (if (boundp 'gnus-newsgroup-name)
648 (gnus-article-hide-header "newsgroups")))
649 ((eq elem 'followup-to)
650 (when (equal (message-fetch-field "followup-to")
651 (message-fetch-field "newsgroups"))
652 (gnus-article-hide-header "followup-to")))
654 (let ((from (message-fetch-field "from"))
655 (reply-to (message-fetch-field "reply-to")))
660 (nth 1 (mail-extract-address-components from))
661 (nth 1 (mail-extract-address-components reply-to)))))
662 (gnus-article-hide-header "reply-to"))))
664 (let ((date (message-fetch-field "date")))
666 (< (gnus-days-between (current-time-string) date)
668 (gnus-article-hide-header "date")))))))))))
670 (defun gnus-article-hide-header (header)
672 (goto-char (point-min))
673 (when (re-search-forward (concat "^" header ":") nil t)
674 (gnus-article-hide-text-type
675 (progn (beginning-of-line) (point))
678 (if (re-search-forward "^[^ \t]" nil t)
683 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
684 (defun article-treat-overstrike ()
685 "Translate overstrikes into bold text."
688 (let ((buffer-read-only nil))
689 (while (search-forward "\b" nil t)
690 (let ((next (following-char))
691 (previous (char-after (- (point) 2))))
692 ;; We do the boldification/underlining by hiding the
693 ;; overstrikes and putting the proper text property
697 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
698 (put-text-property (point) (1+ (point)) 'face 'bold))
700 (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
702 (- (point) 2) (1- (point)) 'face 'underline))
704 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
706 (point) (1+ (point)) 'face 'underline))))))))
708 (defun article-fill ()
709 "Format too long lines."
712 (let ((buffer-read-only nil))
714 (goto-char (point-min))
715 (search-forward "\n\n" nil t)
717 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
718 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
719 (adaptive-fill-mode t))
721 (and (>= (current-column) (min fill-column (window-width)))
722 (/= (preceding-char) ?:)
723 (fill-paragraph nil))
726 (defun article-remove-cr ()
727 "Remove carriage returns from an article."
730 (let ((buffer-read-only nil))
731 (goto-char (point-min))
732 (while (search-forward "\r" nil t)
733 (replace-match "" t t)))))
735 (defun article-remove-trailing-blank-lines ()
736 "Remove all trailing blank lines from the article."
739 (let ((buffer-read-only nil))
740 (goto-char (point-max))
744 (while (and (not (bobp))
745 (looking-at "^[ \t]*$"))
750 (defun article-display-x-face (&optional force)
751 "Look for an X-Face header and display it if present."
752 (interactive (list 'force))
754 ;; Delete the old process, if any.
755 (when (process-status "article-x-face")
756 (delete-process "article-x-face"))
757 (let ((inhibit-point-motion-hooks t)
758 (case-fold-search nil)
761 (nnheader-narrow-to-headers)
762 (setq from (message-fetch-field "from"))
763 (goto-char (point-min))
764 (when (and gnus-article-x-face-command
766 ;; Check whether this face is censored.
767 (not gnus-article-x-face-too-ugly)
768 (and gnus-article-x-face-too-ugly from
769 (not (string-match gnus-article-x-face-too-ugly
771 ;; Has to be present.
772 (re-search-forward "^X-Face: " nil t))
773 ;; We now have the area of the buffer where the X-Face is stored.
775 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
776 ;; We display the face.
777 (if (symbolp gnus-article-x-face-command)
778 ;; The command is a lisp function, so we call it.
779 (if (gnus-functionp gnus-article-x-face-command)
780 (funcall gnus-article-x-face-command beg end)
781 (error "%s is not a function" gnus-article-x-face-command))
782 ;; The command is a string, so we interpret the command
783 ;; as a, well, command, and fork it off.
784 (let ((process-connection-type nil))
785 (process-kill-without-query
787 "article-x-face" nil shell-file-name shell-command-switch
788 gnus-article-x-face-command))
789 (process-send-region "article-x-face" beg end)
790 (process-send-eof "article-x-face")))))))))
792 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
793 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
794 (defun article-decode-rfc1522 ()
795 "Hack to remove QP encoding from headers."
796 (let ((case-fold-search t)
797 (inhibit-point-motion-hooks t)
798 (buffer-read-only nil)
802 (goto-char (point-min))
803 (or (search-forward "\n\n" nil t) (point-max)))
804 (goto-char (point-min))
805 (while (re-search-forward
806 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
807 (setq string (match-string 1))
809 (narrow-to-region (match-beginning 0) (match-end 0))
810 (delete-region (point-min) (point-max))
812 (article-mime-decode-quoted-printable
813 (goto-char (point-min)) (point-max))
814 (subst-char-in-region (point-min) (point-max) ?_ ? )
815 (goto-char (point-max)))
816 (goto-char (point-min))))))
818 (defun article-de-quoted-unreadable (&optional force)
819 "Do a naive translation of a quoted-printable-encoded article.
820 This is in no way, shape or form meant as a replacement for real MIME
821 processing, but is simply a stop-gap measure until MIME support is
823 If FORCE, decode the article whether it is marked as quoted-printable
825 (interactive (list 'force))
827 (let ((case-fold-search t)
828 (buffer-read-only nil)
829 (type (gnus-fetch-field "content-transfer-encoding")))
830 (gnus-article-decode-rfc1522)
832 (and type (string-match "quoted-printable" (downcase type))))
833 (goto-char (point-min))
834 (search-forward "\n\n" nil 'move)
835 (article-mime-decode-quoted-printable (point) (point-max))))))
837 (defun article-mime-decode-quoted-printable-buffer ()
838 "Decode Quoted-Printable in the current buffer."
839 (article-mime-decode-quoted-printable (point-min) (point-max)))
841 (defun article-mime-decode-quoted-printable (from to)
842 "Decode Quoted-Printable in the region between FROM and TO."
845 (while (search-forward "=" to t)
846 (cond ((eq (following-char) ?\n)
849 ((looking-at "[0-9A-F][0-9A-F]")
850 (subst-char-in-region
851 (1- (point)) (point) ?=
852 (hexl-hex-string-to-integer
853 (buffer-substring (point) (+ 2 (point)))))
857 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
859 (defun article-hide-pgp (&optional arg)
860 "Toggle hiding of any PGP headers and signatures in the current article.
861 If given a negative prefix, always show; if given a positive prefix,
863 (interactive (gnus-article-hidden-arg))
864 (unless (gnus-article-check-hidden-text 'pgp arg)
866 (let (buffer-read-only beg end)
868 (goto-char (point-min))
869 ;; Hide the "header".
870 (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
871 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
873 ;; Hide the actual signature.
874 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
875 (setq end (1+ (match-beginning 0)))
876 (gnus-article-hide-text-type
878 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
880 ;; Perhaps we shouldn't hide to the end of the buffer
881 ;; if there is no end to the signature?
884 ;; Hide "- " PGP quotation markers.
886 (narrow-to-region beg end)
887 (goto-char (point-min))
888 (while (re-search-forward "^- " nil t)
889 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
892 (defun article-hide-pem (&optional arg)
893 "Toggle hiding of any PEM headers and signatures in the current article.
894 If given a negative prefix, always show; if given a positive prefix,
896 (interactive (gnus-article-hidden-arg))
897 (unless (gnus-article-check-hidden-text 'pem arg)
899 (let (buffer-read-only end)
901 (goto-char (point-min))
902 ;; hide the horrendously ugly "header".
903 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
906 (setq end (1+ (match-beginning 0)))
907 (gnus-article-hide-text-type
909 (if (search-forward "\n\n" nil t)
913 ;; hide the trailer as well
914 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
917 (gnus-article-hide-text-type
918 (match-beginning 0) (match-end 0) 'pem))))))
920 (defun article-hide-signature (&optional arg)
921 "Hide the signature in the current article.
922 If given a negative prefix, always show; if given a positive prefix,
924 (interactive (gnus-article-hidden-arg))
925 (unless (gnus-article-check-hidden-text 'signature arg)
928 (let ((buffer-read-only nil))
929 (when (gnus-article-narrow-to-signature)
930 (gnus-article-hide-text-type
931 (point-min) (point-max) 'signature)))))))
933 (defun article-strip-leading-blank-lines ()
934 "Remove all blank lines from the beginning of the article."
937 (let ((inhibit-point-motion-hooks t)
939 (goto-char (point-min))
940 (when (search-forward "\n\n" nil t)
941 (while (and (not (eobp))
942 (looking-at "[ \t]*$"))
943 (gnus-delete-line))))))
945 (defun article-strip-multiple-blank-lines ()
946 "Replace consecutive blank lines with one empty line."
949 (let (buffer-read-only)
950 ;; First make all blank lines empty.
951 (goto-char (point-min))
952 (while (re-search-forward "^[ \t]+$" nil t)
953 (replace-match "" nil t))
954 ;; Then replace multiple empty lines with a single empty line.
955 (goto-char (point-min))
956 (while (re-search-forward "\n\n\n+" nil t)
957 (replace-match "\n\n" t t)))))
959 (defun article-strip-blank-lines ()
960 "Strip leading, trailing and multiple blank lines."
962 (article-strip-leading-blank-lines)
963 (article-remove-trailing-blank-lines)
964 (article-strip-multiple-blank-lines))
966 (defvar mime::preview/content-list)
967 (defvar mime::preview-content-info/point-min)
968 (defun gnus-article-narrow-to-signature ()
969 "Narrow to the signature; return t if a signature is found, else nil."
971 (when (and (boundp 'mime::preview/content-list)
972 mime::preview/content-list)
973 ;; We have a MIMEish article, so we use the MIME data to narrow.
974 (let ((pcinfo (car (last mime::preview/content-list))))
977 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
980 (when (gnus-article-search-signature)
982 ;; Check whether we have some limits to what we consider
983 ;; to be a signature.
984 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
985 (list gnus-signature-limit)))
987 (while (setq limit (pop limits))
988 (if (or (and (integerp limit)
989 (< (- (point-max) (point)) limit))
991 (< (count-lines (point) (point-max)) limit))
992 (and (gnus-functionp limit)
995 (not (re-search-forward limit nil t))))
996 () ; This limit did not succeed.
1000 (narrow-to-region (point) (point-max))
1003 (defun gnus-article-search-signature ()
1004 "Search the current buffer for the signature separator.
1005 Put point at the beginning of the signature separator."
1006 (let ((cur (point)))
1007 (goto-char (point-max))
1008 (if (if (stringp gnus-signature-separator)
1009 (re-search-backward gnus-signature-separator nil t)
1010 (let ((seps gnus-signature-separator))
1012 (not (re-search-backward (car seps) nil t)))
1019 (defun gnus-article-hidden-arg ()
1020 "Return the current prefix arg as a number, or 0 if no prefix."
1021 (list (if current-prefix-arg
1022 (prefix-numeric-value current-prefix-arg)
1025 (defun gnus-article-check-hidden-text (type arg)
1026 "Return nil if hiding is necessary.
1027 Arg can be nil or a number. Nil and positive means hide, negative
1028 means show, 0 means toggle."
1030 (let ((hide (gnus-article-hidden-text-p type)))
1036 (gnus-article-show-hidden-text type))
1038 (if (eq hide 'hidden)
1039 (gnus-article-show-hidden-text type)
1042 (defun gnus-article-hidden-text-p (type)
1043 "Say whether the current buffer contains hidden text of type TYPE."
1044 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1046 (if (get-text-property pos 'invisible)
1050 (defun gnus-article-show-hidden-text (type &optional hide)
1051 "Show all hidden text of type TYPE.
1052 If HIDE, hide the text instead."
1054 (let ((buffer-read-only nil)
1055 (inhibit-point-motion-hooks t)
1058 (while (setq beg (text-property-any end (point-max) 'article-type type))
1061 (text-property-not-all beg (point-max) 'article-type type)
1064 (gnus-article-hide-text beg end gnus-hidden-properties)
1065 (gnus-article-unhide-text beg end))
1069 (defconst article-time-units
1070 `((year . ,(* 365.25 24 60 60))
1071 (week . ,(* 7 24 60 60))
1072 (day . ,(* 24 60 60))
1076 "Mapping from time units to seconds.")
1078 (defun article-date-ut (&optional type highlight header)
1079 "Convert DATE date to universal time in the current article.
1080 If TYPE is `local', convert to local time; if it is `lapsed', output
1081 how much time has lapsed since DATE."
1082 (interactive (list 'ut t))
1083 (let* ((header (or header
1084 (mail-header-date gnus-current-headers)
1085 (message-fetch-field "date")
1087 (date (if (vectorp header) (mail-header-date header)
1089 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1090 (inhibit-point-motion-hooks t)
1092 (when (and date (not (string= date "")))
1095 (nnheader-narrow-to-headers)
1096 (let ((buffer-read-only nil))
1097 ;; Delete any old Date headers.
1098 (if (re-search-forward date-regexp nil t)
1100 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1101 eface (get-text-property (1- (gnus-point-at-eol))
1103 (message-remove-header date-regexp t)
1104 (beginning-of-line))
1105 (goto-char (point-max)))
1106 (insert (article-make-date-line date type))
1109 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1110 (put-text-property (match-beginning 1) (match-end 1)
1112 (put-text-property (match-beginning 2) (match-end 2)
1115 (defun article-make-date-line (date type)
1116 "Return a DATE line of TYPE."
1118 ;; Convert to the local timezone. We have to slap a
1119 ;; `condition-case' round the calls to the timezone
1120 ;; functions since they aren't particularly resistant to
1123 (concat "Date: " (condition-case ()
1124 (timezone-make-date-arpa-standard date)
1127 ;; Convert to Universal Time.
1131 (timezone-make-date-arpa-standard date nil "UT")
1134 ;; Get the original date from the article.
1135 ((eq type 'original)
1136 (concat "Date: " date "\n"))
1137 ;; Let the user define the format.
1139 (format-time-string gnus-article-time-format
1142 (timezone-make-date-arpa-standard
1144 ;; Do an X-Sent lapsed format.
1146 ;; If the date is seriously mangled, the timezone functions are
1147 ;; liable to bug out, so we ignore all errors.
1148 (let* ((now (current-time))
1153 (timezone-make-date-arpa-standard
1154 (current-time-string now)
1155 (current-time-zone now) "UT"))
1157 (timezone-make-date-arpa-standard
1159 (real-sec (and real-time
1160 (+ (* (float (car real-time)) 65536)
1162 (sec (and real-time (abs real-sec)))
1166 "X-Sent: Unknown\n")
1172 ;; This is a bit convoluted, but basically we go
1173 ;; through the time units for years, weeks, etc,
1174 ;; and divide things to see whether that results
1175 ;; in positive answers.
1178 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1179 ;; The (remaining) seconds are too few to
1180 ;; be divided into this time unit.
1182 ;; It's big enough, so we output it.
1183 (setq sec (- sec (* num (cdr unit))))
1185 (concat (if prev ", " "") (int-to-string
1187 " " (symbol-name (car unit))
1188 (if (> num 1) "s" ""))
1190 article-time-units "")
1191 ;; If dates are odd, then it might appear like the
1192 ;; article was sent in the future.
1195 " in the future\n"))))))
1197 (error "Unknown conversion type: %s" type))))
1199 (defun article-date-local (&optional highlight)
1200 "Convert the current article date to the local timezone."
1201 (interactive (list t))
1202 (article-date-ut 'local highlight))
1204 (defun article-date-original (&optional highlight)
1205 "Convert the current article date to what it was originally.
1206 This is only useful if you have used some other date conversion
1207 function and want to see what the date was before converting."
1208 (interactive (list t))
1209 (article-date-ut 'original highlight))
1211 (defun article-date-lapsed (&optional highlight)
1212 "Convert the current article date to time lapsed since it was sent."
1213 (interactive (list t))
1214 (article-date-ut 'lapsed highlight))
1216 (defun article-date-user (&optional highlight)
1217 "Convert the current article date to the user-defined format."
1218 (interactive (list t))
1219 (article-date-ut 'user highlight))
1221 (defun article-show-all ()
1222 "Show all hidden text in the article buffer."
1225 (let ((buffer-read-only nil))
1226 (gnus-article-unhide-text (point-min) (point-max)))))
1228 (defun article-emphasize (&optional arg)
1229 "Emphasize text according to `gnus-emphasis-alist'."
1230 (interactive (gnus-article-hidden-arg))
1231 (unless (gnus-article-check-hidden-text 'emphasis arg)
1233 (let ((alist gnus-emphasis-alist)
1234 (buffer-read-only nil)
1235 (props (append '(article-type emphasis)
1236 gnus-hidden-properties))
1237 regexp elem beg invisible visible face)
1238 (goto-char (point-min))
1239 (search-forward "\n\n" nil t)
1241 (while (setq elem (pop alist))
1243 (setq regexp (car elem)
1244 invisible (nth 1 elem)
1245 visible (nth 2 elem)
1247 (while (re-search-forward regexp nil t)
1248 (when (and (match-beginning visible) (match-beginning invisible))
1249 (gnus-article-hide-text
1250 (match-beginning invisible) (match-end invisible) props)
1251 (gnus-article-unhide-text-type
1252 (match-beginning visible) (match-end visible) 'emphasis)
1253 (gnus-put-text-property-excluding-newlines
1254 (match-beginning visible) (match-end visible) 'face face)
1255 (goto-char (match-end invisible)))))))))
1257 (defvar gnus-summary-article-menu)
1258 (defvar gnus-summary-post-menu)
1260 ;;; Saving functions.
1262 (defun gnus-article-save (save-buffer file &optional num)
1263 "Save the currently selected article."
1264 (unless gnus-save-all-headers
1265 ;; Remove headers according to `gnus-saved-headers'.
1266 (let ((gnus-visible-headers
1267 (or gnus-saved-headers gnus-visible-headers))
1268 (gnus-article-buffer save-buffer))
1269 (gnus-article-hide-headers 1 t)))
1270 (save-window-excursion
1271 (if (not gnus-default-article-saver)
1272 (error "No default saver is defined.")
1273 ;; !!! Magic! The saving functions all save
1274 ;; `gnus-original-article-buffer' (or so they think), but we
1275 ;; bind that variable to our save-buffer.
1276 (set-buffer gnus-article-buffer)
1277 (let* ((gnus-save-article-buffer save-buffer)
1280 ((not gnus-prompt-before-saving) 'default)
1281 ((eq gnus-prompt-before-saving 'always) nil)
1283 (gnus-number-of-articles-to-be-saved
1284 (when (eq gnus-prompt-before-saving t)
1286 (set-buffer gnus-summary-buffer)
1287 (funcall gnus-default-article-saver filename)))))
1289 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1291 ((eq filename 'default)
1295 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1297 (format prompt (if (and gnus-number-of-articles-to-be-saved
1298 (> gnus-number-of-articles-to-be-saved 1))
1299 (format "these %d articles"
1300 gnus-number-of-articles-to-be-saved)
1303 ;; Let the split methods have their say.
1305 ;; No split name was found.
1308 (concat prompt " (default "
1309 (file-name-nondirectory default-name) ") ")
1310 (file-name-directory default-name)
1312 ;; A single split name was found
1313 ((= 1 (length split-name))
1314 (let* ((name (car split-name))
1315 (dir (cond ((file-directory-p name)
1316 (file-name-as-directory name))
1317 ((file-exists-p name) name)
1318 (t gnus-article-save-directory))))
1320 (concat prompt " (default " name ") ")
1322 ;; A list of splits was found.
1324 (setq split-name (nreverse split-name))
1326 (let ((file-name-history (nconc split-name file-name-history)))
1330 (concat prompt " (`M-p' for defaults) ")
1331 gnus-article-save-directory
1333 gnus-article-save-directory)))
1334 (car (push result file-name-history)))))))
1335 ;; Create the directory.
1336 (gnus-make-directory (file-name-directory file))
1337 ;; If we have read a directory, we append the default file name.
1338 (when (file-directory-p file)
1339 (setq file (concat (file-name-as-directory file)
1340 (file-name-nondirectory default-name))))
1341 ;; Possibly translate some characters.
1342 (nnheader-translate-file-chars file)))))
1344 (defun gnus-article-archive-name (group)
1345 "Return the first instance of an \"Archive-name\" in the current buffer."
1346 (let ((case-fold-search t))
1347 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1348 (nnheader-concat gnus-article-save-directory
1349 (match-string 1)))))
1351 (defun gnus-summary-save-in-rmail (&optional filename)
1352 "Append this article to Rmail file.
1353 Optional argument FILENAME specifies file name.
1354 Directory to save to is default to `gnus-article-save-directory'."
1356 (gnus-set-global-variables)
1358 (funcall gnus-rmail-save-name gnus-newsgroup-name
1359 gnus-current-headers gnus-newsgroup-last-rmail)))
1360 (setq filename (gnus-read-save-file-name
1361 "Save %s in rmail file:" default-name filename))
1362 (gnus-make-directory (file-name-directory filename))
1363 (gnus-eval-in-buffer-window gnus-save-article-buffer
1367 (gnus-output-to-rmail filename))))
1368 ;; Remember the directory name to save articles
1369 (setq gnus-newsgroup-last-rmail filename)))
1371 (defun gnus-summary-save-in-mail (&optional filename)
1372 "Append this article to Unix mail file.
1373 Optional argument FILENAME specifies file name.
1374 Directory to save to is default to `gnus-article-save-directory'."
1376 (gnus-set-global-variables)
1378 (funcall gnus-mail-save-name gnus-newsgroup-name
1379 gnus-current-headers gnus-newsgroup-last-mail)))
1380 (setq filename (gnus-read-save-file-name
1381 "Save %s in Unix mail file:" default-name filename))
1383 (expand-file-name filename
1385 (file-name-directory default-name))))
1386 (gnus-make-directory (file-name-directory filename))
1387 (gnus-eval-in-buffer-window gnus-save-article-buffer
1391 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
1392 (gnus-output-to-rmail filename)
1393 (let ((mail-use-rfc822 t))
1394 (rmail-output filename 1 t t))))))
1395 ;; Remember the directory name to save articles.
1396 (setq gnus-newsgroup-last-mail filename)))
1398 (defun gnus-summary-save-in-file (&optional filename overwrite)
1399 "Append this article to file.
1400 Optional argument FILENAME specifies file name.
1401 Directory to save to is default to `gnus-article-save-directory'."
1403 (gnus-set-global-variables)
1405 (funcall gnus-file-save-name gnus-newsgroup-name
1406 gnus-current-headers gnus-newsgroup-last-file)))
1407 (setq filename (gnus-read-save-file-name
1408 "Save %s in file:" default-name filename))
1409 (gnus-make-directory (file-name-directory filename))
1410 (gnus-eval-in-buffer-window gnus-save-article-buffer
1414 (when (and overwrite
1415 (file-exists-p filename))
1416 (delete-file filename))
1417 (gnus-output-to-file filename))))
1418 ;; Remember the directory name to save articles.
1419 (setq gnus-newsgroup-last-file filename)))
1421 (defun gnus-summary-write-to-file (&optional filename)
1422 "Write this article to a file.
1423 Optional argument FILENAME specifies file name.
1424 The directory to save in defaults to `gnus-article-save-directory'."
1426 (gnus-summary-save-in-file nil t))
1428 (defun gnus-summary-save-body-in-file (&optional filename)
1429 "Append this article body to a file.
1430 Optional argument FILENAME specifies file name.
1431 The directory to save in defaults to `gnus-article-save-directory'."
1433 (gnus-set-global-variables)
1435 (funcall gnus-file-save-name gnus-newsgroup-name
1436 gnus-current-headers gnus-newsgroup-last-file)))
1437 (setq filename (gnus-read-save-file-name
1438 "Save %s body in file:" default-name filename))
1439 (gnus-make-directory (file-name-directory filename))
1440 (gnus-eval-in-buffer-window gnus-save-article-buffer
1444 (goto-char (point-min))
1445 (when (search-forward "\n\n" nil t)
1446 (narrow-to-region (point) (point-max)))
1447 (gnus-output-to-file filename))))
1448 ;; Remember the directory name to save articles.
1449 (setq gnus-newsgroup-last-file filename)))
1451 (defun gnus-summary-save-in-pipe (&optional command)
1452 "Pipe this article to subprocess."
1454 (gnus-set-global-variables)
1456 (cond ((eq command 'default)
1457 gnus-last-shell-command)
1461 "Shell command on %s: "
1462 (if (and gnus-number-of-articles-to-be-saved
1463 (> gnus-number-of-articles-to-be-saved 1))
1464 (format "these %d articles"
1465 gnus-number-of-articles-to-be-saved)
1467 gnus-last-shell-command))))
1468 (when (string-equal command "")
1469 (setq command gnus-last-shell-command))
1470 (gnus-eval-in-buffer-window gnus-article-buffer
1473 (shell-command-on-region (point-min) (point-max) command nil)))
1474 (setq gnus-last-shell-command command))
1476 ;;; Article file names when saving.
1478 (defun gnus-capitalize-newsgroup (newsgroup)
1479 "Capitalize NEWSGROUP name."
1480 (when (not (zerop (length newsgroup)))
1481 (concat (char-to-string (upcase (aref newsgroup 0)))
1482 (substring newsgroup 1))))
1484 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1485 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1486 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1487 Otherwise, it is like ~/News/news/group/num."
1490 (concat (if (gnus-use-long-file-name 'not-save)
1491 (gnus-capitalize-newsgroup newsgroup)
1492 (gnus-newsgroup-directory-form newsgroup))
1493 "/" (int-to-string (mail-header-number headers)))
1494 gnus-article-save-directory)))
1496 (string-equal (file-name-directory default)
1497 (file-name-directory last-file))
1498 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1500 (or last-file default))))
1502 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1503 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1504 If variable `gnus-use-long-file-name' is non-nil, it is
1505 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1508 (concat (if (gnus-use-long-file-name 'not-save)
1510 (gnus-newsgroup-directory-form newsgroup))
1511 "/" (int-to-string (mail-header-number headers)))
1512 gnus-article-save-directory)))
1514 (string-equal (file-name-directory default)
1515 (file-name-directory last-file))
1516 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1518 (or last-file default))))
1520 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1521 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1522 If variable `gnus-use-long-file-name' is non-nil, it is
1523 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1526 (if (gnus-use-long-file-name 'not-save)
1527 (gnus-capitalize-newsgroup newsgroup)
1528 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1529 gnus-article-save-directory)))
1531 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1532 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1533 If variable `gnus-use-long-file-name' is non-nil, it is
1534 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1537 (if (gnus-use-long-file-name 'not-save)
1539 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1540 gnus-article-save-directory)))
1547 (setq afunc (car func)
1550 gfunc (intern (format "gnus-%s" func))))
1552 (if (not (fboundp afunc))
1554 `(lambda (&optional interactive &rest args)
1555 ,(documentation afunc t)
1556 (interactive (list t))
1558 (set-buffer gnus-article-buffer)
1560 (call-interactively ',afunc)
1561 (apply ',afunc args))))))))
1562 '(article-hide-headers
1563 article-hide-boring-headers
1564 article-treat-overstrike
1565 (article-fill . gnus-article-word-wrap)
1567 article-display-x-face
1568 article-de-quoted-unreadable
1569 article-mime-decode-quoted-printable
1572 article-hide-signature
1573 article-remove-trailing-blank-lines
1574 article-strip-leading-blank-lines
1575 article-strip-multiple-blank-lines
1576 article-strip-blank-lines
1578 article-date-original
1583 (article-show-all . gnus-article-show-all-headers))))
1586 ;;; Gnus article mode
1589 (put 'gnus-article-mode 'mode-class 'special)
1592 (gnus-define-keys gnus-article-mode-map
1593 " " gnus-article-goto-next-page
1594 "\177" gnus-article-goto-prev-page
1595 [delete] gnus-article-goto-prev-page
1596 "\C-c^" gnus-article-refer-article
1597 "h" gnus-article-show-summary
1598 "s" gnus-article-show-summary
1599 "\C-c\C-m" gnus-article-mail
1600 "?" gnus-article-describe-briefly
1601 gnus-mouse-2 gnus-article-push-button
1602 "\r" gnus-article-press-button
1603 "\t" gnus-article-next-button
1604 "\M-\t" gnus-article-prev-button
1605 "e" gnus-article-edit
1606 "<" beginning-of-buffer
1608 "\C-c\C-i" gnus-info-find-node
1611 "\C-d" gnus-article-read-summary-keys
1612 "\M-*" gnus-article-read-summary-keys
1613 "\M-g" gnus-article-read-summary-keys)
1615 (substitute-key-definition
1616 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1618 (defun gnus-article-make-menu-bar ()
1619 (gnus-turn-off-edit-menu 'article)
1620 (unless (boundp 'gnus-article-article-menu)
1622 gnus-article-article-menu gnus-article-mode-map ""
1624 ["Scroll forwards" gnus-article-goto-next-page t]
1625 ["Scroll backwards" gnus-article-goto-prev-page t]
1626 ["Show summary" gnus-article-show-summary t]
1627 ["Fetch Message-ID at point" gnus-article-refer-article t]
1628 ["Mail to address at point" gnus-article-mail t]))
1631 gnus-article-treatment-menu gnus-article-mode-map ""
1633 ["Hide headers" gnus-article-hide-headers t]
1634 ["Hide signature" gnus-article-hide-signature t]
1635 ["Hide citation" gnus-article-hide-citation t]
1636 ["Treat overstrike" gnus-article-treat-overstrike t]
1637 ["Remove carriage return" gnus-article-remove-cr t]
1638 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1640 (when (boundp 'gnus-summary-article-menu)
1641 (define-key gnus-article-mode-map [menu-bar commands]
1642 (cons "Commands" gnus-summary-article-menu)))
1644 (when (boundp 'gnus-summary-post-menu)
1645 (define-key gnus-article-mode-map [menu-bar post]
1646 (cons "Post" gnus-summary-post-menu)))
1648 (run-hooks 'gnus-article-menu-hook)))
1650 (defun gnus-article-mode ()
1651 "Major mode for displaying an article.
1653 All normal editing commands are switched off.
1655 The following commands are available in addition to all summary mode
1657 \\<gnus-article-mode-map>
1658 \\[gnus-article-next-page]\t Scroll the article one page forwards
1659 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1660 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1661 \\[gnus-article-show-summary]\t Display the summary buffer
1662 \\[gnus-article-mail]\t Send a reply to the address near point
1663 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1664 \\[gnus-info-find-node]\t Go to the Gnus info node"
1666 (when (gnus-visual-p 'article-menu 'menu)
1667 (gnus-article-make-menu-bar))
1668 (kill-all-local-variables)
1669 (gnus-simplify-mode-line)
1670 (setq mode-name "Article")
1671 (setq major-mode 'gnus-article-mode)
1672 (make-local-variable 'minor-mode-alist)
1673 (unless (assq 'gnus-show-mime minor-mode-alist)
1674 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1675 (use-local-map gnus-article-mode-map)
1676 (gnus-update-format-specifications nil 'article-mode)
1677 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1678 (gnus-set-default-directory)
1679 (buffer-disable-undo (current-buffer))
1680 (setq buffer-read-only t)
1681 (set-syntax-table gnus-article-mode-syntax-table)
1682 (run-hooks 'gnus-article-mode-hook))
1684 (defun gnus-article-setup-buffer ()
1685 "Initialize the article buffer."
1686 (let* ((name (if gnus-single-article-buffer "*Article*"
1687 (concat "*Article " gnus-newsgroup-name "*")))
1689 (progn (string-match "\\*Article" name)
1690 (concat " *Original Article"
1691 (substring name (match-end 0))))))
1692 (setq gnus-article-buffer name)
1693 (setq gnus-original-article-buffer original)
1694 ;; This might be a variable local to the summary buffer.
1695 (unless gnus-single-article-buffer
1697 (set-buffer gnus-summary-buffer)
1698 (setq gnus-article-buffer name)
1699 (setq gnus-original-article-buffer original)
1700 (gnus-set-global-variables)))
1701 ;; Init original article buffer.
1703 (set-buffer (get-buffer-create gnus-original-article-buffer))
1704 (buffer-disable-undo (current-buffer))
1705 (setq major-mode 'gnus-original-article-mode)
1706 (gnus-add-current-to-buffer-list)
1707 (make-local-variable 'gnus-original-article))
1708 (if (get-buffer name)
1711 (buffer-disable-undo (current-buffer))
1712 (setq buffer-read-only t)
1713 (gnus-add-current-to-buffer-list)
1714 (unless (eq major-mode 'gnus-article-mode)
1715 (gnus-article-mode))
1718 (set-buffer (get-buffer-create name))
1719 (gnus-add-current-to-buffer-list)
1721 (make-local-variable 'gnus-summary-buffer)
1722 (current-buffer)))))
1724 ;; Set article window start at LINE, where LINE is the number of lines
1725 ;; from the head of the article.
1726 (defun gnus-article-set-window-start (&optional line)
1728 (get-buffer-window gnus-article-buffer t)
1730 (set-buffer gnus-article-buffer)
1731 (goto-char (point-min))
1734 (gnus-message 6 "Moved to bookmark")
1735 (search-forward "\n\n" nil t)
1739 (defun gnus-article-prepare (article &optional all-headers header)
1740 "Prepare ARTICLE in article mode buffer.
1741 ARTICLE should either be an article number or a Message-ID.
1742 If ARTICLE is an id, HEADER should be the article headers.
1743 If ALL-HEADERS is non-nil, no headers are hidden."
1745 ;; Make sure we start in a summary buffer.
1746 (unless (eq major-mode 'gnus-summary-mode)
1747 (set-buffer gnus-summary-buffer))
1748 (setq gnus-summary-buffer (current-buffer))
1749 ;; Make sure the connection to the server is alive.
1750 (unless (gnus-server-opened
1751 (gnus-find-method-for-group gnus-newsgroup-name))
1752 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1753 (gnus-request-group gnus-newsgroup-name t))
1754 (let* ((gnus-article (if header (mail-header-number header) article))
1755 (summary-buffer (current-buffer))
1756 (internal-hook gnus-article-internal-prepare-hook)
1757 (group gnus-newsgroup-name)
1760 (gnus-article-setup-buffer)
1761 (set-buffer gnus-article-buffer)
1762 ;; Deactivate active regions.
1763 (when (and (boundp 'transient-mark-mode)
1764 transient-mark-mode)
1765 (setq mark-active nil))
1766 (if (not (setq result (let ((buffer-read-only nil))
1767 (gnus-request-article-this-buffer
1769 ;; There is no such article.
1771 (when (and (numberp article)
1772 (not (memq article gnus-newsgroup-sparse)))
1773 (setq gnus-article-current
1774 (cons gnus-newsgroup-name article))
1775 (set-buffer gnus-summary-buffer)
1776 (setq gnus-current-article article)
1777 (gnus-summary-mark-article article gnus-canceled-mark))
1778 (unless (memq article gnus-newsgroup-sparse)
1780 1 "No such article (may have expired or been canceled)")))
1781 (if (or (eq result 'pseudo) (eq result 'nneething))
1784 (set-buffer summary-buffer)
1785 (setq gnus-last-article gnus-current-article
1786 gnus-newsgroup-history (cons gnus-current-article
1787 gnus-newsgroup-history)
1788 gnus-current-article 0
1789 gnus-current-headers nil
1790 gnus-article-current nil)
1791 (if (eq result 'nneething)
1792 (gnus-configure-windows 'summary)
1793 (gnus-configure-windows 'article))
1794 (gnus-set-global-variables))
1795 (gnus-set-mode-line 'article))
1796 ;; The result from the `request' was an actual article -
1797 ;; or at least some text that is now displayed in the
1799 (when (and (numberp article)
1800 (not (eq article gnus-current-article)))
1801 ;; Seems like a new article has been selected.
1802 ;; `gnus-current-article' must be an article number.
1804 (set-buffer summary-buffer)
1805 (setq gnus-last-article gnus-current-article
1806 gnus-newsgroup-history (cons gnus-current-article
1807 gnus-newsgroup-history)
1808 gnus-current-article article
1809 gnus-current-headers
1810 (gnus-summary-article-header gnus-current-article)
1811 gnus-article-current
1812 (cons gnus-newsgroup-name gnus-current-article))
1813 (unless (vectorp gnus-current-headers)
1814 (setq gnus-current-headers nil))
1815 (gnus-summary-show-thread)
1816 (run-hooks 'gnus-mark-article-hook)
1817 (gnus-set-mode-line 'summary)
1818 (when (gnus-visual-p 'article-highlight 'highlight)
1819 (run-hooks 'gnus-visual-mark-article-hook))
1820 ;; Set the global newsgroup variables here.
1821 ;; Suggested by Jim Sisolak
1822 ;; <sisolak@trans4.neep.wisc.edu>.
1823 (gnus-set-global-variables)
1824 (setq gnus-have-all-headers
1825 (or all-headers gnus-show-all-headers))
1827 (vectorp (gnus-summary-article-header article))
1828 (gnus-cache-possibly-enter-article
1830 (gnus-summary-article-header article)
1831 (memq article gnus-newsgroup-marked)
1832 (memq article gnus-newsgroup-dormant)
1833 (memq article gnus-newsgroup-unreads)))))
1834 (when (or (numberp article)
1836 ;; Hooks for getting information from the article.
1837 ;; This hook must be called before being narrowed.
1838 (let (buffer-read-only)
1839 (run-hooks 'internal-hook)
1840 (run-hooks 'gnus-article-prepare-hook)
1841 ;; Decode MIME message.
1842 (when gnus-show-mime
1843 (if (or (not gnus-strict-mime)
1844 (gnus-fetch-field "Mime-Version"))
1845 (funcall gnus-show-mime-method)
1846 (funcall gnus-decode-encoded-word-method)))
1847 ;; Perform the article display hooks.
1848 (run-hooks 'gnus-article-display-hook))
1850 (goto-char (point-min))
1851 (when gnus-break-pages
1852 (gnus-narrow-to-page)))
1853 (gnus-set-mode-line 'article)
1854 (gnus-configure-windows 'article)
1855 (goto-char (point-min))
1858 (defun gnus-article-wash-status ()
1859 "Return a string which display status of article washing."
1861 (set-buffer gnus-article-buffer)
1862 (let ((cite (gnus-article-hidden-text-p 'cite))
1863 (headers (gnus-article-hidden-text-p 'headers))
1864 (boring (gnus-article-hidden-text-p 'boring-headers))
1865 (pgp (gnus-article-hidden-text-p 'pgp))
1866 (pem (gnus-article-hidden-text-p 'pem))
1867 (signature (gnus-article-hidden-text-p 'signature))
1868 (overstrike (gnus-article-hidden-text-p 'overstrike))
1869 (emphasis (gnus-article-hidden-text-p 'emphasis))
1870 (mime gnus-show-mime))
1871 (format "%c%c%c%c%c%c%c"
1873 (if (or headers boring) ?h ? )
1874 (if (or pgp pem) ?p ? )
1875 (if signature ?s ? )
1876 (if overstrike ?o ? )
1878 (if emphasis ?e ? )))))
1880 (defun gnus-article-hide-headers-if-wanted ()
1881 "Hide unwanted headers if `gnus-have-all-headers' is nil.
1882 Provided for backwards compatibility."
1883 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1885 (gnus-article-hide-headers)))
1889 (defun gnus-output-to-rmail (file-name)
1890 "Append the current article to an Rmail file named FILE-NAME."
1892 ;; Most of these codes are borrowed from rmailout.el.
1893 (setq file-name (expand-file-name file-name))
1894 (setq rmail-default-rmail-file file-name)
1895 (let ((artbuf (current-buffer))
1896 (tmpbuf (get-buffer-create " *Gnus-output*")))
1898 (or (get-file-buffer file-name)
1899 (file-exists-p file-name)
1900 (if (gnus-yes-or-no-p
1901 (concat "\"" file-name "\" does not exist, create it? "))
1902 (let ((file-buffer (create-file-buffer file-name)))
1904 (set-buffer file-buffer)
1905 (rmail-insert-rmail-file-header)
1906 (let ((require-final-newline nil))
1907 (gnus-write-buffer file-name)))
1908 (kill-buffer file-buffer))
1909 (error "Output file does not exist")))
1911 (buffer-disable-undo (current-buffer))
1913 (insert-buffer-substring artbuf)
1914 (gnus-convert-article-to-rmail)
1915 ;; Decide whether to append to a file or to an Emacs buffer.
1916 (let ((outbuf (get-file-buffer file-name)))
1918 (append-to-file (point-min) (point-max) file-name)
1919 ;; File has been visited, in buffer OUTBUF.
1921 (let ((buffer-read-only nil)
1922 (msg (and (boundp 'rmail-current-message)
1923 (symbol-value 'rmail-current-message))))
1924 ;; If MSG is non-nil, buffer is in RMAIL mode.
1927 (narrow-to-region (point-max) (point-max)))
1928 (insert-buffer-substring tmpbuf)
1930 (goto-char (point-min))
1932 (search-backward "\^_")
1933 (narrow-to-region (point) (point-max))
1934 (goto-char (1+ (point-min)))
1935 (rmail-count-new-messages t)
1936 (rmail-show-message msg))))))
1937 (kill-buffer tmpbuf)))
1939 (defun gnus-output-to-file (file-name)
1940 "Append the current article to a file named FILE-NAME."
1941 (let ((artbuf (current-buffer)))
1942 (nnheader-temp-write nil
1943 (insert-buffer-substring artbuf)
1944 ;; Append newline at end of the buffer as separator, and then
1946 (goto-char (point-max))
1948 (append-to-file (point-min) (point-max) file-name))))
1950 (defun gnus-convert-article-to-rmail ()
1951 "Convert article in current buffer to Rmail message format."
1952 (let ((buffer-read-only nil))
1953 ;; Convert article directly into Babyl format.
1954 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
1955 (goto-char (point-min))
1956 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1957 (while (search-forward "\n\^_" nil t) ;single char
1958 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
1959 (goto-char (point-max))
1962 (defun gnus-narrow-to-page (&optional arg)
1963 "Narrow the article buffer to a page.
1964 If given a numerical ARG, move forward ARG pages."
1966 (setq arg (if arg (prefix-numeric-value arg) 0))
1968 (set-buffer gnus-article-buffer)
1969 (goto-char (point-min))
1971 ;; Remove any old next/prev buttons.
1972 (when (gnus-visual-p 'page-marker)
1973 (let ((buffer-read-only nil))
1974 (gnus-remove-text-with-property 'gnus-prev)
1975 (gnus-remove-text-with-property 'gnus-next)))
1978 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1980 (re-search-forward page-delimiter nil 'move arg)))
1981 (goto-char (match-end 0)))
1984 (if (re-search-forward page-delimiter nil 'move)
1987 (when (and (gnus-visual-p 'page-marker)
1988 (not (= (point-min) 1)))
1990 (goto-char (point-min))
1991 (gnus-insert-prev-page-button)))
1992 (when (and (gnus-visual-p 'page-marker)
1993 (< (+ (point-max) 2) (buffer-size)))
1995 (goto-char (point-max))
1996 (gnus-insert-next-page-button)))))
1998 ;; Article mode commands
2000 (defun gnus-article-goto-next-page ()
2001 "Show the next page of the article."
2003 (when (gnus-article-next-page)
2004 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2006 (defun gnus-article-goto-prev-page ()
2007 "Show the next page of the article."
2009 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2010 (gnus-article-prev-page nil)))
2012 (defun gnus-article-next-page (&optional lines)
2013 "Show the next page of the current article.
2014 If end of article, return non-nil. Otherwise return nil.
2015 Argument LINES specifies lines to be scrolled up."
2017 (move-to-window-line -1)
2020 (and (pos-visible-in-window-p) ;Not continuation line.
2022 ;; Nothing in this page.
2023 (if (or (not gnus-break-pages)
2026 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2028 (gnus-narrow-to-page 1) ;Go to next page.
2030 ;; More in this page.
2031 (let ((scroll-in-place nil))
2035 ;; Long lines may cause an end-of-buffer error.
2036 (goto-char (point-max)))))
2037 (move-to-window-line 0)
2040 (defun gnus-article-prev-page (&optional lines)
2041 "Show previous page of current article.
2042 Argument LINES specifies lines to be scrolled down."
2044 (move-to-window-line 0)
2045 (if (and gnus-break-pages
2047 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2049 (gnus-narrow-to-page -1) ;Go to previous page.
2050 (goto-char (point-max))
2052 (let ((scroll-in-place nil))
2055 (scroll-down lines))
2056 (move-to-window-line 0)))))
2058 (defun gnus-article-refer-article ()
2059 "Read article specified by message-id around point."
2061 (let ((point (point)))
2062 (search-forward ">" nil t) ;Move point to end of "<....>".
2063 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2064 (let ((message-id (match-string 1)))
2066 (set-buffer gnus-summary-buffer)
2067 (gnus-summary-refer-article message-id))
2069 (error "No references around point"))))
2071 (defun gnus-article-show-summary ()
2072 "Reconfigure windows to show summary buffer."
2074 (gnus-configure-windows 'article)
2075 (gnus-summary-goto-subject gnus-current-article))
2077 (defun gnus-article-describe-briefly ()
2078 "Describe article mode commands briefly."
2081 (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")))
2083 (defun gnus-article-summary-command ()
2084 "Execute the last keystroke in the summary buffer."
2086 (let ((obuf (current-buffer))
2087 (owin (current-window-configuration))
2089 (switch-to-buffer gnus-summary-buffer 'norecord)
2090 (setq func (lookup-key (current-local-map) (this-command-keys)))
2091 (call-interactively func)
2093 (set-window-configuration owin)
2094 (set-window-point (get-buffer-window (current-buffer)) (point))))
2096 (defun gnus-article-summary-command-nosave ()
2097 "Execute the last keystroke in the summary buffer."
2100 (pop-to-buffer gnus-summary-buffer 'norecord)
2101 (setq func (lookup-key (current-local-map) (this-command-keys)))
2102 (call-interactively func)))
2104 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2105 "Read a summary buffer key sequence and execute it from the article buffer."
2108 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2109 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2110 "=" "^" "\M-^" "|"))
2117 (set-buffer gnus-summary-buffer)
2118 (push (or key last-command-event) unread-command-events)
2119 (setq keys (read-key-sequence nil)))
2122 (if (or (member keys nosaves)
2123 (member keys nosave-but-article)
2124 (member keys nosave-in-article))
2126 (save-window-excursion
2127 (pop-to-buffer gnus-summary-buffer 'norecord)
2128 (setq func (lookup-key (current-local-map) keys)))
2131 (unless (member keys nosave-in-article)
2132 (set-buffer gnus-summary-buffer))
2133 (call-interactively func))
2134 (when (member keys nosave-but-article)
2135 (pop-to-buffer gnus-article-buffer 'norecord)))
2136 ;; These commands should restore window configuration.
2137 (let ((obuf (current-buffer))
2138 (owin (current-window-configuration))
2141 (if not-restore-window
2142 (pop-to-buffer gnus-summary-buffer 'norecord)
2143 (switch-to-buffer gnus-summary-buffer 'norecord))
2144 (setq in-buffer (current-buffer))
2145 (if (setq func (lookup-key (current-local-map) keys))
2146 (call-interactively func)
2148 (when (eq in-buffer (current-buffer))
2150 (unless not-restore-window
2151 (set-window-configuration owin))
2152 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2154 (defun gnus-article-hide (&optional arg force)
2155 "Hide all the gruft in the current article.
2156 This means that PGP stuff, signatures, cited text and (some)
2157 headers will be hidden.
2158 If given a prefix, show the hidden text instead."
2159 (interactive (list current-prefix-arg 'force))
2160 (gnus-article-hide-headers arg)
2161 (gnus-article-hide-pgp arg)
2162 (gnus-article-hide-citation-maybe arg force)
2163 (gnus-article-hide-signature arg))
2165 (defun gnus-article-maybe-highlight ()
2166 "Do some article highlighting if `article-visual' is non-nil."
2167 (when (gnus-visual-p 'article-highlight 'highlight)
2168 (gnus-article-highlight-some)))
2170 (defun gnus-request-article-this-buffer (article group)
2171 "Get an article and insert it into this buffer."
2172 (let (do-update-line)
2176 (gnus-kill-all-overlays)
2177 (setq group (or group gnus-newsgroup-name))
2179 ;; Open server if it has closed.
2180 (gnus-check-server (gnus-find-method-for-group group))
2182 ;; Using `gnus-request-article' directly will insert the article into
2183 ;; `nntp-server-buffer' - so we'll save some time by not having to
2184 ;; copy it from the server buffer into the article buffer.
2186 ;; We only request an article by message-id when we do not have the
2187 ;; headers for it, so we'll have to get those.
2188 (when (stringp article)
2189 (let ((gnus-override-method gnus-refer-article-method))
2190 (gnus-read-header article)))
2192 ;; If the article number is negative, that means that this article
2193 ;; doesn't belong in this newsgroup (possibly), so we find its
2194 ;; message-id and request it by id instead of number.
2195 (when (and (numberp article)
2197 (get-buffer gnus-summary-buffer)
2198 (buffer-name (get-buffer gnus-summary-buffer)))
2200 (set-buffer gnus-summary-buffer)
2201 (let ((header (gnus-summary-article-header article)))
2204 ((memq article gnus-newsgroup-sparse)
2205 ;; This is a sparse gap article.
2206 (setq do-update-line article)
2207 (setq article (mail-header-id header))
2208 (let ((gnus-override-method gnus-refer-article-method))
2209 (gnus-read-header article))
2210 (setq gnus-newsgroup-sparse
2211 (delq article gnus-newsgroup-sparse)))
2213 ;; It's a real article.
2214 (setq article (mail-header-id header)))
2216 ;; It is an extracted pseudo-article.
2217 (setq article 'pseudo)
2218 (gnus-request-pseudo-article header))))
2220 (let ((method (gnus-find-method-for-group
2221 gnus-newsgroup-name)))
2222 (if (not (eq (car method) 'nneething))
2224 (let ((dir (concat (file-name-as-directory (nth 1 method))
2225 (mail-header-subject header))))
2226 (when (file-directory-p dir)
2227 (setq article 'nneething)
2228 (gnus-group-enter-directory dir))))))))
2231 ;; Refuse to select canceled articles.
2232 ((and (numberp article)
2234 (get-buffer gnus-summary-buffer)
2235 (buffer-name (get-buffer gnus-summary-buffer))
2236 (eq (cdr (save-excursion
2237 (set-buffer gnus-summary-buffer)
2238 (assq article gnus-newsgroup-reads)))
2239 gnus-canceled-mark))
2241 ;; We first check `gnus-original-article-buffer'.
2242 ((and (get-buffer gnus-original-article-buffer)
2245 (set-buffer gnus-original-article-buffer)
2246 (and (equal (car gnus-original-article) group)
2247 (eq (cdr gnus-original-article) article))))
2248 (insert-buffer-substring gnus-original-article-buffer)
2250 ;; Check the backlog.
2251 ((and gnus-keep-backlog
2252 (gnus-backlog-request-article group article (current-buffer)))
2254 ;; Check asynchronous pre-fetch.
2255 ((gnus-async-request-fetched-article group article (current-buffer))
2256 (gnus-async-prefetch-next group article gnus-summary-buffer)
2259 ((and gnus-use-cache
2261 (gnus-cache-request-article article group))
2263 ;; Get the article and put into the article buffer.
2264 ((or (stringp article) (numberp article))
2265 (let ((gnus-override-method
2266 (and (stringp article) gnus-refer-article-method))
2267 (buffer-read-only nil))
2269 (gnus-kill-all-overlays)
2270 (when (gnus-request-article article group (current-buffer))
2271 (when (numberp article)
2272 (gnus-async-prefetch-next group article gnus-summary-buffer)
2273 (when gnus-keep-backlog
2274 (gnus-backlog-enter-article
2275 group article (current-buffer))))
2280 ;; Take the article from the original article buffer
2281 ;; and place it in the buffer it's supposed to be in.
2282 (when (and (get-buffer gnus-article-buffer)
2284 (equal (buffer-name (current-buffer))
2285 (buffer-name (get-buffer gnus-article-buffer))))
2287 (if (get-buffer gnus-original-article-buffer)
2288 (set-buffer (get-buffer gnus-original-article-buffer))
2289 (set-buffer (get-buffer-create gnus-original-article-buffer))
2290 (buffer-disable-undo (current-buffer))
2291 (setq major-mode 'gnus-original-article-mode)
2292 (setq buffer-read-only t)
2293 (gnus-add-current-to-buffer-list))
2294 (let (buffer-read-only)
2296 (insert-buffer-substring gnus-article-buffer))
2297 (setq gnus-original-article (cons group article))))
2299 ;; Update sparse articles.
2300 (when (and do-update-line
2301 (or (numberp article)
2303 (let ((buf (current-buffer)))
2304 (set-buffer gnus-summary-buffer)
2305 (gnus-summary-update-article do-update-line)
2306 (gnus-summary-goto-subject do-update-line nil t)
2307 (set-window-point (get-buffer-window (current-buffer) t)
2309 (set-buffer buf))))))
2315 (defcustom gnus-article-edit-mode-hook nil
2316 "Hook run in article edit mode buffers."
2320 (defvar gnus-article-edit-done-function nil)
2322 (defvar gnus-article-edit-mode-map nil)
2324 (unless gnus-article-edit-mode-map
2325 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2327 (gnus-define-keys gnus-article-edit-mode-map
2328 "\C-c\C-c" gnus-article-edit-done
2329 "\C-c\C-k" gnus-article-edit-exit)
2331 (gnus-define-keys (gnus-article-edit-wash-map
2332 "\C-c\C-w" gnus-article-edit-mode-map)
2333 "f" gnus-article-edit-full-stops))
2335 (defun gnus-article-edit-mode ()
2336 "Major mode for editing articles.
2337 This is an extended text-mode.
2339 \\{gnus-article-edit-mode-map}"
2341 (kill-all-local-variables)
2342 (setq major-mode 'gnus-article-edit-mode)
2343 (setq mode-name "Article Edit")
2344 (use-local-map gnus-article-edit-mode-map)
2345 (make-local-variable 'gnus-article-edit-done-function)
2346 (make-local-variable 'gnus-prev-winconf)
2347 (setq buffer-read-only nil)
2348 (buffer-enable-undo)
2350 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2352 (defun gnus-article-edit (&optional force)
2353 "Edit the current article.
2354 This will have permanent effect only in mail groups.
2355 If FORCE is non-nil, allow editing of articles even in read-only
2358 (when (and (not force)
2359 (gnus-group-read-only-p))
2360 (error "The current newsgroup does not support article editing."))
2361 (gnus-article-edit-article
2363 (gnus-summary-edit-article-done
2364 ,(or (mail-header-references gnus-current-headers) "")
2365 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2367 (defun gnus-article-edit-article (exit-func)
2368 "Start editing the contents of the current article buffer."
2369 (let ((winconf (current-window-configuration)))
2370 (set-buffer gnus-article-buffer)
2371 (gnus-article-edit-mode)
2372 (set-text-properties (point-min) (point-max) nil)
2373 (gnus-configure-windows 'edit-article)
2374 (setq gnus-article-edit-done-function exit-func)
2375 (setq gnus-prev-winconf winconf)
2376 (gnus-message 6 "C-c C-c to end edits")))
2378 (defun gnus-article-edit-done ()
2379 "Update the article edits and exit."
2381 (let ((func gnus-article-edit-done-function)
2382 (buf (current-buffer))
2383 (start (window-start)))
2384 (gnus-article-edit-exit)
2387 (let ((buffer-read-only nil))
2390 (set-window-start (get-buffer-window buf) start)
2391 (set-window-point (get-buffer-window buf) (point))))
2393 (defun gnus-article-edit-exit ()
2394 "Exit the article editing without updating."
2396 ;; We remove all text props from the article buffer.
2397 (let ((buf (format "%s" (buffer-string)))
2398 (curbuf (current-buffer))
2400 (window-start (window-start)))
2403 (let ((winconf gnus-prev-winconf))
2405 ;; The cache and backlog have to be flushed somewhat.
2406 (when gnus-use-cache
2407 (gnus-cache-update-article
2408 (car gnus-article-current) (cdr gnus-article-current)))
2409 (when gnus-keep-backlog
2410 (gnus-backlog-remove-article
2411 (car gnus-article-current) (cdr gnus-article-current)))
2412 ;; Flush original article as well.
2414 (when (get-buffer gnus-original-article-buffer)
2415 (set-buffer gnus-original-article-buffer)
2416 (setq gnus-original-article nil)))
2417 (set-window-configuration winconf)
2418 ;; Tippy-toe some to make sure that point remains where it was.
2419 (let ((buf (current-buffer)))
2421 (set-window-start (get-buffer-window (current-buffer)) window-start)
2423 (set-buffer buf)))))
2425 (defun gnus-article-edit-full-stops ()
2426 "Interactively repair spacing at end of sentences."
2429 (goto-char (point-min))
2430 (search-forward-regexp "^$" nil t)
2431 (let ((case-fold-search nil))
2432 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2435 ;;; Article highlights
2438 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2440 ;;; Internal Variables:
2442 (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\\)"
2443 "Regular expression that matches URLs."
2447 (defcustom gnus-button-alist
2448 `(("\\(\\b<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
2449 gnus-button-message-id 3)
2450 ("\\(\\b<?\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>?\\)" 1 t
2451 gnus-button-fetch-group 4)
2452 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2453 t gnus-button-message-id 3)
2454 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
2455 ;; This is how URLs _should_ be embedded in text...
2456 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2458 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2459 "Alist of regexps matching buttons in article bodies.
2461 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2462 REGEXP: is the string matching text around the button,
2463 BUTTON: is the number of the regexp grouping actually matching the button,
2464 FORM: is a lisp expression which must eval to true for the button to
2466 CALLBACK: is the function to call when the user push this button, and each
2467 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2469 CALLBACK can also be a variable, in that case the value of that
2470 variable it the real callback function."
2472 :type '(repeat (list regexp
2473 (integer :tag "Button")
2475 (function :tag "Callback")
2478 (integer :tag "Regexp group")))))
2480 (defcustom gnus-header-button-alist
2481 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2482 0 t gnus-button-message-id 0)
2483 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2484 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2485 0 t gnus-button-mailto 0)
2486 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2487 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2488 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2489 gnus-button-message-id 3))
2490 "Alist of headers and regexps to match buttons in article heads.
2492 This alist is very similar to `gnus-button-alist', except that each
2493 alist has an additional HEADER element first in each entry:
2495 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2497 HEADER is a regexp to match a header. For a fuller explanation, see
2498 `gnus-button-alist'."
2500 :type '(repeat (list (regexp :tag "Header")
2502 (integer :tag "Button")
2504 (function :tag "Callback")
2507 (integer :tag "Regexp group")))))
2509 (defvar gnus-button-regexp nil)
2510 (defvar gnus-button-marker-list nil)
2511 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2513 (defvar gnus-button-last nil)
2514 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2518 (defun gnus-article-push-button (event)
2519 "Check text under the mouse pointer for a callback function.
2520 If the text under the mouse pointer has a `gnus-callback' property,
2521 call it with the value of the `gnus-data' text property."
2523 (set-buffer (window-buffer (posn-window (event-start event))))
2524 (let* ((pos (posn-point (event-start event)))
2525 (data (get-text-property pos 'gnus-data))
2526 (fun (get-text-property pos 'gnus-callback)))
2528 (funcall fun data))))
2530 (defun gnus-article-press-button ()
2531 "Check text at point for a callback function.
2532 If the text at point has a `gnus-callback' property,
2533 call it with the value of the `gnus-data' text property."
2535 (let* ((data (get-text-property (point) 'gnus-data))
2536 (fun (get-text-property (point) 'gnus-callback)))
2538 (funcall fun data))))
2540 (defun gnus-article-prev-button (n)
2541 "Move point to N buttons backward.
2542 If N is negative, move forward instead."
2544 (gnus-article-next-button (- n)))
2546 (defun gnus-article-next-button (n)
2547 "Move point to N buttons forward.
2548 If N is negative, move backward instead."
2550 (let ((function (if (< n 0) 'previous-single-property-change
2551 'next-single-property-change))
2552 (inhibit-point-motion-hooks t)
2554 (limit (if (< n 0) (point-min) (point-max))))
2556 (while (and (not (= limit (point)))
2558 ;; Skip past the current button.
2559 (when (get-text-property (point) 'gnus-callback)
2560 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2561 ;; Go to the next (or previous) button.
2562 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2563 ;; Put point at the start of the button.
2564 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2565 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2566 ;; Skip past intangible buttons.
2567 (when (get-text-property (point) 'intangible)
2571 (gnus-message 5 "No more buttons"))
2574 (defun gnus-article-highlight (&optional force)
2575 "Highlight current article.
2576 This function calls `gnus-article-highlight-headers',
2577 `gnus-article-highlight-citation',
2578 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2579 do the highlighting. See the documentation for those functions."
2580 (interactive (list 'force))
2581 (gnus-article-highlight-headers)
2582 (gnus-article-highlight-citation force)
2583 (gnus-article-highlight-signature)
2584 (gnus-article-add-buttons force)
2585 (gnus-article-add-buttons-to-head))
2587 (defun gnus-article-highlight-some (&optional force)
2588 "Highlight current article.
2589 This function calls `gnus-article-highlight-headers',
2590 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2591 do the highlighting. See the documentation for those functions."
2592 (interactive (list 'force))
2593 (gnus-article-highlight-headers)
2594 (gnus-article-highlight-signature)
2595 (gnus-article-add-buttons))
2597 (defun gnus-article-highlight-headers ()
2598 "Highlight article headers as specified by `gnus-header-face-alist'."
2601 (set-buffer gnus-article-buffer)
2603 (let ((alist gnus-header-face-alist)
2604 (buffer-read-only nil)
2605 (case-fold-search t)
2606 (inhibit-point-motion-hooks t)
2607 entry regexp header-face field-face from hpoints fpoints)
2608 (goto-char (point-min))
2609 (when (search-forward "\n\n" nil t)
2610 (narrow-to-region (1- (point)) (point-min))
2611 (while (setq entry (pop alist))
2612 (goto-char (point-min))
2613 (setq regexp (concat "^\\("
2614 (if (string-equal "" (nth 0 entry))
2618 header-face (nth 1 entry)
2619 field-face (nth 2 entry))
2620 (while (and (re-search-forward regexp nil t)
2624 (unless (search-forward ":" nil t)
2626 (when (and header-face
2627 (not (memq (point) hpoints)))
2628 (push (point) hpoints)
2629 (gnus-put-text-property from (point) 'face header-face))
2630 (when (and field-face
2631 (not (memq (setq from (point)) fpoints)))
2633 (if (re-search-forward "^[^ \t]" nil t)
2635 (goto-char (point-max)))
2636 (gnus-put-text-property from (point) 'face field-face)))))))))
2638 (defun gnus-article-highlight-signature ()
2639 "Highlight the signature in an article.
2640 It does this by highlighting everything after
2641 `gnus-signature-separator' using `gnus-signature-face'."
2644 (set-buffer gnus-article-buffer)
2645 (let ((buffer-read-only nil)
2646 (inhibit-point-motion-hooks t))
2648 (when (and gnus-signature-face
2649 (gnus-article-narrow-to-signature))
2650 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2651 'face gnus-signature-face)
2653 (gnus-article-search-signature)
2654 (let ((start (match-beginning 0))
2655 (end (set-marker (make-marker) (1+ (match-end 0)))))
2656 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2659 (defun gnus-article-add-buttons (&optional force)
2660 "Find external references in the article and make buttons of them.
2661 \"External references\" are things like Message-IDs and URLs, as
2662 specified by `gnus-button-alist'."
2663 (interactive (list 'force))
2665 (set-buffer gnus-article-buffer)
2666 ;; Remove all old markers.
2667 (while gnus-button-marker-list
2668 (set-marker (pop gnus-button-marker-list) nil))
2669 (let ((buffer-read-only nil)
2670 (inhibit-point-motion-hooks t)
2671 (case-fold-search t)
2672 (alist gnus-button-alist)
2674 (goto-char (point-min))
2675 ;; We skip the headers.
2676 (unless (search-forward "\n\n" nil t)
2677 (goto-char (point-max)))
2679 (while (setq entry (pop alist))
2680 (setq regexp (car entry))
2682 (while (re-search-forward regexp nil t)
2683 (let* ((start (and entry (match-beginning (nth 1 entry))))
2684 (end (and entry (match-end (nth 1 entry))))
2685 (from (match-beginning 0)))
2686 (when (and (or (eq t (nth 1 entry))
2687 (eval (nth 1 entry)))
2688 (not (get-text-property (point) 'gnus-callback)))
2689 ;; That optional form returned non-nil, so we add the
2691 (gnus-article-add-button
2692 start end 'gnus-button-push
2693 (car (push (set-marker (make-marker) from)
2694 gnus-button-marker-list))))))))))
2696 ;; Add buttons to the head of an article.
2697 (defun gnus-article-add-buttons-to-head ()
2698 "Add buttons to the head of the article."
2701 (set-buffer gnus-article-buffer)
2702 (let ((buffer-read-only nil)
2703 (inhibit-point-motion-hooks t)
2704 (case-fold-search t)
2705 (alist gnus-header-button-alist)
2707 (nnheader-narrow-to-headers)
2709 ;; Each alist entry.
2710 (setq entry (car alist)
2712 (goto-char (point-min))
2713 (while (re-search-forward (car entry) nil t)
2714 ;; Each header matching the entry.
2715 (setq beg (match-beginning 0))
2716 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2717 (match-beginning 0))
2720 (while (re-search-forward (nth 1 entry) end t)
2721 ;; Each match within a header.
2722 (let* ((entry (cdr entry))
2723 (start (match-beginning (nth 1 entry)))
2724 (end (match-end (nth 1 entry)))
2725 (form (nth 2 entry)))
2726 (goto-char (match-end 0))
2728 (gnus-article-add-button
2729 start end (nth 3 entry)
2730 (buffer-substring (match-beginning (nth 4 entry))
2731 (match-end (nth 4 entry)))))))
2735 ;;; External functions:
2737 (defun gnus-article-add-button (from to fun &optional data)
2738 "Create a button between FROM and TO with callback FUN and data DATA."
2739 (when gnus-article-button-face
2740 (gnus-overlay-put (gnus-make-overlay from to)
2741 'face gnus-article-button-face))
2742 (gnus-add-text-properties
2744 (nconc (and gnus-article-mouse-face
2745 (list gnus-mouse-face-prop gnus-article-mouse-face))
2746 (list 'gnus-callback fun)
2747 (and data (list 'gnus-data data)))))
2749 ;;; Internal functions:
2751 (defun gnus-signature-toggle (end)
2753 (set-buffer gnus-article-buffer)
2754 (let ((buffer-read-only nil)
2755 (inhibit-point-motion-hooks t))
2756 (if (get-text-property end 'invisible)
2757 (gnus-article-unhide-text end (point-max))
2758 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2760 (defun gnus-button-entry ()
2761 ;; Return the first entry in `gnus-button-alist' matching this place.
2762 (let ((alist gnus-button-alist)
2765 (setq entry (pop alist))
2766 (if (looking-at (car entry))
2771 (defun gnus-button-push (marker)
2772 ;; Push button starting at MARKER.
2774 (set-buffer gnus-article-buffer)
2776 (let* ((entry (gnus-button-entry))
2777 (inhibit-point-motion-hooks t)
2779 (args (mapcar (lambda (group)
2780 (let ((string (match-string group)))
2781 (gnus-set-text-properties
2782 0 (length string) nil string)
2789 (fboundp (symbol-value fun)))
2790 (apply (symbol-value fun) args))
2792 (gnus-message 1 "You must define `%S' to use this button"
2793 (cons fun args)))))))
2795 (defun gnus-button-message-id (message-id)
2798 (set-buffer gnus-summary-buffer)
2799 (gnus-summary-refer-article message-id)))
2801 (defun gnus-button-fetch-group (address)
2802 "Fetch GROUP specified by ADDRESS."
2803 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
2804 (error "Can't parse %s" address)
2805 (gnus-group-read-ephemeral-group
2806 (match-string 4 address)
2807 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
2808 (nntp-port-number ,(if (match-end 3)
2809 (match-string 3 address)
2812 (defun gnus-split-string (string pattern)
2813 "Return a list of substrings of STRING which are separated by PATTERN."
2814 (let (parts (start 0))
2815 (while (string-match pattern string start)
2816 (setq parts (cons (substring string start (match-beginning 0)) parts)
2817 start (match-end 0)))
2818 (nreverse (cons (substring string start) parts))))
2820 (defun gnus-url-parse-query-string (query &optional downcase)
2821 (let (retval pairs cur key val)
2822 (setq pairs (gnus-split-string query "&"))
2824 (setq cur (car pairs)
2826 (if (not (string-match "=" cur))
2828 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2829 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2831 (setq key (downcase key)))
2832 (setq cur (assoc key retval))
2834 (setcdr cur (cons val (cdr cur)))
2835 (setq retval (cons (list key val) retval)))))
2838 (defun gnus-url-unhex (x)
2845 (defun gnus-url-unhex-string (str &optional allow-newlines)
2846 "Remove %XXX embedded spaces, etc in a url.
2847 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2848 decoding of carriage returns and line feeds in the string, which is normally
2849 forbidden in URL encoding."
2850 (setq str (or str ""))
2852 (case-fold-search t))
2853 (while (string-match "%[0-9a-f][0-9a-f]" str)
2854 (let* ((start (match-beginning 0))
2855 (ch1 (gnus-url-unhex (elt str (+ start 1))))
2857 (gnus-url-unhex (elt str (+ start 2))))))
2859 tmp (substring str 0 start)
2862 (char-to-string code))
2863 ((or (= code ?\n) (= code ?\r))
2865 (t (char-to-string code))))
2866 str (substring str (match-end 0)))))
2867 (setq tmp (concat tmp str))
2870 (defun gnus-url-mailto (url)
2871 ;; Send mail to someone
2872 (when (string-match "mailto:/*\\(.*\\)" url)
2873 (setq url (substring url (match-beginning 1) nil)))
2874 (let (to args source-url subject func)
2875 (if (string-match (regexp-quote "?") url)
2876 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2877 args (gnus-url-parse-query-string
2878 (substring url (match-end 0) nil) t))
2879 (setq to (gnus-url-unhex-string url)))
2880 (setq args (cons (list "to" to) args)
2881 subject (cdr-safe (assoc "subject" args)))
2884 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2887 (message-position-on-field (caar args)))
2888 (insert (mapconcat 'identity (cdar args) ", "))
2889 (setq args (cdr args)))
2892 (message-goto-subject))))
2894 (defun gnus-button-mailto (address)
2896 (set-buffer (gnus-copy-article-buffer))
2897 (message-reply address))
2899 (defun gnus-button-reply (address)
2900 ;; Reply to ADDRESS.
2901 (message-reply address))
2903 (defun gnus-button-url (address)
2905 (funcall browse-url-browser-function address))
2907 (defun gnus-button-embedded-url (address)
2909 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2911 ;;; Next/prev buttons in the article buffer.
2913 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
2914 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
2916 (defvar gnus-prev-page-map nil)
2917 (unless gnus-prev-page-map
2918 (setq gnus-prev-page-map (make-sparse-keymap))
2919 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
2920 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
2922 (defun gnus-insert-prev-page-button ()
2923 (let ((buffer-read-only nil))
2925 gnus-prev-page-line-format nil
2926 `(gnus-prev t local-map ,gnus-prev-page-map
2927 gnus-callback gnus-article-button-prev-page))))
2929 (defvar gnus-next-page-map nil)
2930 (unless gnus-next-page-map
2931 (setq gnus-next-page-map (make-keymap))
2932 (suppress-keymap gnus-prev-page-map)
2933 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
2934 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
2936 (defun gnus-button-next-page ()
2937 "Go to the next page."
2939 (let ((win (selected-window)))
2940 (select-window (get-buffer-window gnus-article-buffer t))
2941 (gnus-article-next-page)
2942 (select-window win)))
2944 (defun gnus-button-prev-page ()
2945 "Go to the prev page."
2947 (let ((win (selected-window)))
2948 (select-window (get-buffer-window gnus-article-buffer t))
2949 (gnus-article-prev-page)
2950 (select-window win)))
2952 (defun gnus-insert-next-page-button ()
2953 (let ((buffer-read-only nil))
2954 (gnus-eval-format gnus-next-page-line-format nil
2955 `(gnus-next t local-map ,gnus-next-page-map
2957 gnus-article-button-next-page))))
2959 (defun gnus-article-button-next-page (arg)
2960 "Go to the next page."
2962 (let ((win (selected-window)))
2963 (select-window (get-buffer-window gnus-article-buffer t))
2964 (gnus-article-next-page)
2965 (select-window win)))
2967 (defun gnus-article-button-prev-page (arg)
2968 "Go to the prev page."
2970 (let ((win (selected-window)))
2971 (select-window (get-buffer-window gnus-article-buffer t))
2972 (gnus-article-prev-page)
2973 (select-window win)))
2979 (run-hooks 'gnus-art-load-hook)
2981 ;;; gnus-art.el ends here