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")))
659 (nth 1 (mail-extract-address-components from))
660 (nth 1 (mail-extract-address-components reply-to))))
661 (gnus-article-hide-header "reply-to"))))
663 (let ((date (message-fetch-field "date")))
665 (< (gnus-days-between (current-time-string) date)
667 (gnus-article-hide-header "date")))))))))))
669 (defun gnus-article-hide-header (header)
671 (goto-char (point-min))
672 (when (re-search-forward (concat "^" header ":") nil t)
673 (gnus-article-hide-text-type
674 (progn (beginning-of-line) (point))
677 (if (re-search-forward "^[^ \t]" nil t)
682 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
683 (defun article-treat-overstrike ()
684 "Translate overstrikes into bold text."
687 (let ((buffer-read-only nil))
688 (while (search-forward "\b" nil t)
689 (let ((next (following-char))
690 (previous (char-after (- (point) 2))))
691 ;; We do the boldification/underlining by hiding the
692 ;; overstrikes and putting the proper text property
696 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
697 (put-text-property (point) (1+ (point)) 'face 'bold))
699 (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
701 (- (point) 2) (1- (point)) 'face 'underline))
703 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
705 (point) (1+ (point)) 'face 'underline))))))))
707 (defun article-fill ()
708 "Format too long lines."
711 (let ((buffer-read-only nil))
713 (goto-char (point-min))
714 (search-forward "\n\n" nil t)
716 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
717 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
718 (adaptive-fill-mode t))
720 (and (>= (current-column) (min fill-column (window-width)))
721 (/= (preceding-char) ?:)
722 (fill-paragraph nil))
725 (defun article-remove-cr ()
726 "Remove carriage returns from an article."
729 (let ((buffer-read-only nil))
730 (goto-char (point-min))
731 (while (search-forward "\r" nil t)
732 (replace-match "" t t)))))
734 (defun article-remove-trailing-blank-lines ()
735 "Remove all trailing blank lines from the article."
738 (let ((buffer-read-only nil))
739 (goto-char (point-max))
743 (while (and (not (bobp))
744 (looking-at "^[ \t]*$"))
749 (defun article-display-x-face (&optional force)
750 "Look for an X-Face header and display it if present."
751 (interactive (list 'force))
753 ;; Delete the old process, if any.
754 (when (process-status "article-x-face")
755 (delete-process "article-x-face"))
756 (let ((inhibit-point-motion-hooks t)
757 (case-fold-search nil)
760 (nnheader-narrow-to-headers)
761 (setq from (message-fetch-field "from"))
762 (goto-char (point-min))
763 (when (and gnus-article-x-face-command
765 ;; Check whether this face is censored.
766 (not gnus-article-x-face-too-ugly)
767 (and gnus-article-x-face-too-ugly from
768 (not (string-match gnus-article-x-face-too-ugly
770 ;; Has to be present.
771 (re-search-forward "^X-Face: " nil t))
772 ;; We now have the area of the buffer where the X-Face is stored.
774 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
775 ;; We display the face.
776 (if (symbolp gnus-article-x-face-command)
777 ;; The command is a lisp function, so we call it.
778 (if (gnus-functionp gnus-article-x-face-command)
779 (funcall gnus-article-x-face-command beg end)
780 (error "%s is not a function" gnus-article-x-face-command))
781 ;; The command is a string, so we interpret the command
782 ;; as a, well, command, and fork it off.
783 (let ((process-connection-type nil))
784 (process-kill-without-query
786 "article-x-face" nil shell-file-name shell-command-switch
787 gnus-article-x-face-command))
788 (process-send-region "article-x-face" beg end)
789 (process-send-eof "article-x-face")))))))))
791 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
792 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
793 (defun article-decode-rfc1522 ()
794 "Hack to remove QP encoding from headers."
795 (let ((case-fold-search t)
796 (inhibit-point-motion-hooks t)
797 (buffer-read-only nil)
801 (goto-char (point-min))
802 (or (search-forward "\n\n" nil t) (point-max)))
803 (goto-char (point-min))
804 (while (re-search-forward
805 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
806 (setq string (match-string 1))
808 (narrow-to-region (match-beginning 0) (match-end 0))
809 (delete-region (point-min) (point-max))
811 (article-mime-decode-quoted-printable
812 (goto-char (point-min)) (point-max))
813 (subst-char-in-region (point-min) (point-max) ?_ ? )
814 (goto-char (point-max)))
815 (goto-char (point-min))))))
817 (defun article-de-quoted-unreadable (&optional force)
818 "Do a naive translation of a quoted-printable-encoded article.
819 This is in no way, shape or form meant as a replacement for real MIME
820 processing, but is simply a stop-gap measure until MIME support is
822 If FORCE, decode the article whether it is marked as quoted-printable
824 (interactive (list 'force))
826 (let ((case-fold-search t)
827 (buffer-read-only nil)
828 (type (gnus-fetch-field "content-transfer-encoding")))
829 (gnus-article-decode-rfc1522)
831 (and type (string-match "quoted-printable" (downcase type))))
832 (goto-char (point-min))
833 (search-forward "\n\n" nil 'move)
834 (article-mime-decode-quoted-printable (point) (point-max))))))
836 (defun article-mime-decode-quoted-printable-buffer ()
837 "Decode Quoted-Printable in the current buffer."
838 (article-mime-decode-quoted-printable (point-min) (point-max)))
840 (defun article-mime-decode-quoted-printable (from to)
841 "Decode Quoted-Printable in the region between FROM and TO."
844 (while (search-forward "=" to t)
845 (cond ((eq (following-char) ?\n)
848 ((looking-at "[0-9A-F][0-9A-F]")
849 (subst-char-in-region
850 (1- (point)) (point) ?=
851 (hexl-hex-string-to-integer
852 (buffer-substring (point) (+ 2 (point)))))
856 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
858 (defun article-hide-pgp (&optional arg)
859 "Toggle hiding of any PGP headers and signatures in the current article.
860 If given a negative prefix, always show; if given a positive prefix,
862 (interactive (gnus-article-hidden-arg))
863 (unless (gnus-article-check-hidden-text 'pgp arg)
865 (let (buffer-read-only beg end)
867 (goto-char (point-min))
868 ;; Hide the "header".
869 (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
870 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
872 ;; Hide the actual signature.
873 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
874 (setq end (1+ (match-beginning 0)))
875 (gnus-article-hide-text-type
877 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
879 ;; Perhaps we shouldn't hide to the end of the buffer
880 ;; if there is no end to the signature?
883 ;; Hide "- " PGP quotation markers.
885 (narrow-to-region beg end)
886 (goto-char (point-min))
887 (while (re-search-forward "^- " nil t)
888 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
891 (defun article-hide-pem (&optional arg)
892 "Toggle hiding of any PEM headers and signatures in the current article.
893 If given a negative prefix, always show; if given a positive prefix,
895 (interactive (gnus-article-hidden-arg))
896 (unless (gnus-article-check-hidden-text 'pem arg)
898 (let (buffer-read-only end)
900 (goto-char (point-min))
901 ;; hide the horrendously ugly "header".
902 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
905 (setq end (1+ (match-beginning 0)))
906 (gnus-article-hide-text-type
908 (if (search-forward "\n\n" nil t)
912 ;; hide the trailer as well
913 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
916 (gnus-article-hide-text-type
917 (match-beginning 0) (match-end 0) 'pem))))))
919 (defun article-hide-signature (&optional arg)
920 "Hide the signature in the current article.
921 If given a negative prefix, always show; if given a positive prefix,
923 (interactive (gnus-article-hidden-arg))
924 (unless (gnus-article-check-hidden-text 'signature arg)
927 (let ((buffer-read-only nil))
928 (when (gnus-article-narrow-to-signature)
929 (gnus-article-hide-text-type
930 (point-min) (point-max) 'signature)))))))
932 (defun article-strip-leading-blank-lines ()
933 "Remove all blank lines from the beginning of the article."
936 (let ((inhibit-point-motion-hooks t)
938 (goto-char (point-min))
939 (when (search-forward "\n\n" nil t)
940 (while (and (not (eobp))
941 (looking-at "[ \t]*$"))
942 (gnus-delete-line))))))
944 (defun article-strip-multiple-blank-lines ()
945 "Replace consecutive blank lines with one empty line."
948 (let (buffer-read-only)
949 ;; First make all blank lines empty.
950 (goto-char (point-min))
951 (while (re-search-forward "^[ \t]+$" nil t)
952 (replace-match "" nil t))
953 ;; Then replace multiple empty lines with a single empty line.
954 (goto-char (point-min))
955 (while (re-search-forward "\n\n\n+" nil t)
956 (replace-match "\n\n" t t)))))
958 (defun article-strip-blank-lines ()
959 "Strip leading, trailing and multiple blank lines."
961 (article-strip-leading-blank-lines)
962 (article-remove-trailing-blank-lines)
963 (article-strip-multiple-blank-lines))
965 (defvar mime::preview/content-list)
966 (defvar mime::preview-content-info/point-min)
967 (defun gnus-article-narrow-to-signature ()
968 "Narrow to the signature; return t if a signature is found, else nil."
970 (when (and (boundp 'mime::preview/content-list)
971 mime::preview/content-list)
972 ;; We have a MIMEish article, so we use the MIME data to narrow.
973 (let ((pcinfo (car (last mime::preview/content-list))))
976 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
979 (when (gnus-article-search-signature)
981 ;; Check whether we have some limits to what we consider
982 ;; to be a signature.
983 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
984 (list gnus-signature-limit)))
986 (while (setq limit (pop limits))
987 (if (or (and (integerp limit)
988 (< (- (point-max) (point)) limit))
990 (< (count-lines (point) (point-max)) limit))
991 (and (gnus-functionp limit)
994 (not (re-search-forward limit nil t))))
995 () ; This limit did not succeed.
999 (narrow-to-region (point) (point-max))
1002 (defun gnus-article-search-signature ()
1003 "Search the current buffer for the signature separator.
1004 Put point at the beginning of the signature separator."
1005 (let ((cur (point)))
1006 (goto-char (point-max))
1007 (if (if (stringp gnus-signature-separator)
1008 (re-search-backward gnus-signature-separator nil t)
1009 (let ((seps gnus-signature-separator))
1011 (not (re-search-backward (car seps) nil t)))
1018 (defun gnus-article-hidden-arg ()
1019 "Return the current prefix arg as a number, or 0 if no prefix."
1020 (list (if current-prefix-arg
1021 (prefix-numeric-value current-prefix-arg)
1024 (defun gnus-article-check-hidden-text (type arg)
1025 "Return nil if hiding is necessary.
1026 Arg can be nil or a number. Nil and positive means hide, negative
1027 means show, 0 means toggle."
1029 (let ((hide (gnus-article-hidden-text-p type)))
1035 (gnus-article-show-hidden-text type))
1037 (if (eq hide 'hidden)
1038 (gnus-article-show-hidden-text type)
1041 (defun gnus-article-hidden-text-p (type)
1042 "Say whether the current buffer contains hidden text of type TYPE."
1043 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1045 (if (get-text-property pos 'invisible)
1049 (defun gnus-article-show-hidden-text (type &optional hide)
1050 "Show all hidden text of type TYPE.
1051 If HIDE, hide the text instead."
1053 (let ((buffer-read-only nil)
1054 (inhibit-point-motion-hooks t)
1057 (while (setq beg (text-property-any end (point-max) 'article-type type))
1060 (text-property-not-all beg (point-max) 'article-type type)
1063 (gnus-article-hide-text beg end gnus-hidden-properties)
1064 (gnus-article-unhide-text beg end))
1068 (defconst article-time-units
1069 `((year . ,(* 365.25 24 60 60))
1070 (week . ,(* 7 24 60 60))
1071 (day . ,(* 24 60 60))
1075 "Mapping from time units to seconds.")
1077 (defun article-date-ut (&optional type highlight header)
1078 "Convert DATE date to universal time in the current article.
1079 If TYPE is `local', convert to local time; if it is `lapsed', output
1080 how much time has lapsed since DATE."
1081 (interactive (list 'ut t))
1082 (let* ((header (or header
1083 (mail-header-date gnus-current-headers)
1084 (message-fetch-field "date")
1086 (date (if (vectorp header) (mail-header-date header)
1088 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1089 (inhibit-point-motion-hooks t)
1091 (when (and date (not (string= date "")))
1094 (nnheader-narrow-to-headers)
1095 (let ((buffer-read-only nil))
1096 ;; Delete any old Date headers.
1097 (if (re-search-forward date-regexp nil t)
1099 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1100 eface (get-text-property (1- (gnus-point-at-eol))
1102 (message-remove-header date-regexp t)
1103 (beginning-of-line))
1104 (goto-char (point-max)))
1105 (insert (article-make-date-line date type))
1108 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1109 (put-text-property (match-beginning 1) (match-end 1)
1111 (put-text-property (match-beginning 2) (match-end 2)
1114 (defun article-make-date-line (date type)
1115 "Return a DATE line of TYPE."
1117 ;; Convert to the local timezone. We have to slap a
1118 ;; `condition-case' round the calls to the timezone
1119 ;; functions since they aren't particularly resistant to
1122 (concat "Date: " (condition-case ()
1123 (timezone-make-date-arpa-standard date)
1126 ;; Convert to Universal Time.
1130 (timezone-make-date-arpa-standard date nil "UT")
1133 ;; Get the original date from the article.
1134 ((eq type 'original)
1135 (concat "Date: " date "\n"))
1136 ;; Let the user define the format.
1138 (format-time-string gnus-article-time-format
1141 (timezone-make-date-arpa-standard
1143 ;; Do an X-Sent lapsed format.
1145 ;; If the date is seriously mangled, the timezone functions are
1146 ;; liable to bug out, so we ignore all errors.
1147 (let* ((now (current-time))
1152 (timezone-make-date-arpa-standard
1153 (current-time-string now)
1154 (current-time-zone now) "UT"))
1156 (timezone-make-date-arpa-standard
1158 (real-sec (and real-time
1159 (+ (* (float (car real-time)) 65536)
1161 (sec (and real-time (abs real-sec)))
1165 "X-Sent: Unknown\n")
1171 ;; This is a bit convoluted, but basically we go
1172 ;; through the time units for years, weeks, etc,
1173 ;; and divide things to see whether that results
1174 ;; in positive answers.
1177 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1178 ;; The (remaining) seconds are too few to
1179 ;; be divided into this time unit.
1181 ;; It's big enough, so we output it.
1182 (setq sec (- sec (* num (cdr unit))))
1184 (concat (if prev ", " "") (int-to-string
1186 " " (symbol-name (car unit))
1187 (if (> num 1) "s" ""))
1189 article-time-units "")
1190 ;; If dates are odd, then it might appear like the
1191 ;; article was sent in the future.
1194 " in the future\n"))))))
1196 (error "Unknown conversion type: %s" type))))
1198 (defun article-date-local (&optional highlight)
1199 "Convert the current article date to the local timezone."
1200 (interactive (list t))
1201 (article-date-ut 'local highlight))
1203 (defun article-date-original (&optional highlight)
1204 "Convert the current article date to what it was originally.
1205 This is only useful if you have used some other date conversion
1206 function and want to see what the date was before converting."
1207 (interactive (list t))
1208 (article-date-ut 'original highlight))
1210 (defun article-date-lapsed (&optional highlight)
1211 "Convert the current article date to time lapsed since it was sent."
1212 (interactive (list t))
1213 (article-date-ut 'lapsed highlight))
1215 (defun article-date-user (&optional highlight)
1216 "Convert the current article date to the user-defined format."
1217 (interactive (list t))
1218 (article-date-ut 'user highlight))
1220 (defun article-show-all ()
1221 "Show all hidden text in the article buffer."
1224 (let ((buffer-read-only nil))
1225 (gnus-article-unhide-text (point-min) (point-max)))))
1227 (defun article-emphasize (&optional arg)
1228 "Emphasize text according to `gnus-emphasis-alist'."
1229 (interactive (gnus-article-hidden-arg))
1230 (unless (gnus-article-check-hidden-text 'emphasis arg)
1232 (let ((alist gnus-emphasis-alist)
1233 (buffer-read-only nil)
1234 (props (append '(article-type emphasis)
1235 gnus-hidden-properties))
1236 regexp elem beg invisible visible face)
1237 (goto-char (point-min))
1238 (search-forward "\n\n" nil t)
1240 (while (setq elem (pop alist))
1242 (setq regexp (car elem)
1243 invisible (nth 1 elem)
1244 visible (nth 2 elem)
1246 (while (re-search-forward regexp nil t)
1247 (when (and (match-beginning visible) (match-beginning invisible))
1248 (gnus-article-hide-text
1249 (match-beginning invisible) (match-end invisible) props)
1250 (gnus-article-unhide-text-type
1251 (match-beginning visible) (match-end visible) 'emphasis)
1252 (gnus-put-text-property-excluding-newlines
1253 (match-beginning visible) (match-end visible) 'face face)
1254 (goto-char (match-end invisible)))))))))
1256 (defvar gnus-summary-article-menu)
1257 (defvar gnus-summary-post-menu)
1259 ;;; Saving functions.
1261 (defun gnus-article-save (save-buffer file &optional num)
1262 "Save the currently selected article."
1263 (unless gnus-save-all-headers
1264 ;; Remove headers according to `gnus-saved-headers'.
1265 (let ((gnus-visible-headers
1266 (or gnus-saved-headers gnus-visible-headers))
1267 (gnus-article-buffer save-buffer))
1268 (gnus-article-hide-headers 1 t)))
1269 (save-window-excursion
1270 (if (not gnus-default-article-saver)
1271 (error "No default saver is defined.")
1272 ;; !!! Magic! The saving functions all save
1273 ;; `gnus-original-article-buffer' (or so they think), but we
1274 ;; bind that variable to our save-buffer.
1275 (set-buffer gnus-article-buffer)
1276 (let* ((gnus-save-article-buffer save-buffer)
1279 ((not gnus-prompt-before-saving) 'default)
1280 ((eq gnus-prompt-before-saving 'always) nil)
1282 (gnus-number-of-articles-to-be-saved
1283 (when (eq gnus-prompt-before-saving t)
1285 (set-buffer gnus-summary-buffer)
1286 (funcall gnus-default-article-saver filename)))))
1288 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1290 ((eq filename 'default)
1294 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1296 (format prompt (if (and gnus-number-of-articles-to-be-saved
1297 (> gnus-number-of-articles-to-be-saved 1))
1298 (format "these %d articles"
1299 gnus-number-of-articles-to-be-saved)
1302 ;; Let the split methods have their say.
1304 ;; No split name was found.
1307 (concat prompt " (default "
1308 (file-name-nondirectory default-name) ") ")
1309 (file-name-directory default-name)
1311 ;; A single split name was found
1312 ((= 1 (length split-name))
1313 (let* ((name (car split-name))
1314 (dir (cond ((file-directory-p name)
1315 (file-name-as-directory name))
1316 ((file-exists-p name) name)
1317 (t gnus-article-save-directory))))
1319 (concat prompt " (default " name ") ")
1321 ;; A list of splits was found.
1323 (setq split-name (nreverse split-name))
1325 (let ((file-name-history (nconc split-name file-name-history)))
1329 (concat prompt " (`M-p' for defaults) ")
1330 gnus-article-save-directory
1332 gnus-article-save-directory)))
1333 (car (push result file-name-history)))))))
1334 ;; Create the directory.
1335 (gnus-make-directory (file-name-directory file))
1336 ;; If we have read a directory, we append the default file name.
1337 (when (file-directory-p file)
1338 (setq file (concat (file-name-as-directory file)
1339 (file-name-nondirectory default-name))))
1340 ;; Possibly translate some characters.
1341 (nnheader-translate-file-chars file)))))
1343 (defun gnus-article-archive-name (group)
1344 "Return the first instance of an \"Archive-name\" in the current buffer."
1345 (let ((case-fold-search t))
1346 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1347 (nnheader-concat gnus-article-save-directory
1348 (match-string 1)))))
1350 (defun gnus-summary-save-in-rmail (&optional filename)
1351 "Append this article to Rmail file.
1352 Optional argument FILENAME specifies file name.
1353 Directory to save to is default to `gnus-article-save-directory'."
1355 (gnus-set-global-variables)
1357 (funcall gnus-rmail-save-name gnus-newsgroup-name
1358 gnus-current-headers gnus-newsgroup-last-rmail)))
1359 (setq filename (gnus-read-save-file-name
1360 "Save %s in rmail file:" default-name filename))
1361 (gnus-make-directory (file-name-directory filename))
1362 (gnus-eval-in-buffer-window gnus-save-article-buffer
1366 (gnus-output-to-rmail filename))))
1367 ;; Remember the directory name to save articles
1368 (setq gnus-newsgroup-last-rmail filename)))
1370 (defun gnus-summary-save-in-mail (&optional filename)
1371 "Append this article to Unix mail file.
1372 Optional argument FILENAME specifies file name.
1373 Directory to save to is default to `gnus-article-save-directory'."
1375 (gnus-set-global-variables)
1377 (funcall gnus-mail-save-name gnus-newsgroup-name
1378 gnus-current-headers gnus-newsgroup-last-mail)))
1379 (setq filename (gnus-read-save-file-name
1380 "Save %s in Unix mail file:" default-name filename))
1382 (expand-file-name filename
1384 (file-name-directory default-name))))
1385 (gnus-make-directory (file-name-directory filename))
1386 (gnus-eval-in-buffer-window gnus-save-article-buffer
1390 (if (and (file-readable-p filename) (mail-file-babyl-p filename))
1391 (gnus-output-to-rmail filename)
1392 (let ((mail-use-rfc822 t))
1393 (rmail-output filename 1 t t))))))
1394 ;; Remember the directory name to save articles.
1395 (setq gnus-newsgroup-last-mail filename)))
1397 (defun gnus-summary-save-in-file (&optional filename overwrite)
1398 "Append this article to file.
1399 Optional argument FILENAME specifies file name.
1400 Directory to save to is default to `gnus-article-save-directory'."
1402 (gnus-set-global-variables)
1404 (funcall gnus-file-save-name gnus-newsgroup-name
1405 gnus-current-headers gnus-newsgroup-last-file)))
1406 (setq filename (gnus-read-save-file-name
1407 "Save %s in file:" default-name filename))
1408 (gnus-make-directory (file-name-directory filename))
1409 (gnus-eval-in-buffer-window gnus-save-article-buffer
1413 (when (and overwrite
1414 (file-exists-p filename))
1415 (delete-file filename))
1416 (gnus-output-to-file filename))))
1417 ;; Remember the directory name to save articles.
1418 (setq gnus-newsgroup-last-file filename)))
1420 (defun gnus-summary-write-to-file (&optional filename)
1421 "Write this article to a file.
1422 Optional argument FILENAME specifies file name.
1423 The directory to save in defaults to `gnus-article-save-directory'."
1425 (gnus-summary-save-in-file nil t))
1427 (defun gnus-summary-save-body-in-file (&optional filename)
1428 "Append this article body to a file.
1429 Optional argument FILENAME specifies file name.
1430 The directory to save in defaults to `gnus-article-save-directory'."
1432 (gnus-set-global-variables)
1434 (funcall gnus-file-save-name gnus-newsgroup-name
1435 gnus-current-headers gnus-newsgroup-last-file)))
1436 (setq filename (gnus-read-save-file-name
1437 "Save %s body in file:" default-name filename))
1438 (gnus-make-directory (file-name-directory filename))
1439 (gnus-eval-in-buffer-window gnus-save-article-buffer
1443 (goto-char (point-min))
1444 (when (search-forward "\n\n" nil t)
1445 (narrow-to-region (point) (point-max)))
1446 (gnus-output-to-file filename))))
1447 ;; Remember the directory name to save articles.
1448 (setq gnus-newsgroup-last-file filename)))
1450 (defun gnus-summary-save-in-pipe (&optional command)
1451 "Pipe this article to subprocess."
1453 (gnus-set-global-variables)
1455 (cond ((eq command 'default)
1456 gnus-last-shell-command)
1460 "Shell command on %s: "
1461 (if (and gnus-number-of-articles-to-be-saved
1462 (> gnus-number-of-articles-to-be-saved 1))
1463 (format "these %d articles"
1464 gnus-number-of-articles-to-be-saved)
1466 gnus-last-shell-command))))
1467 (when (string-equal command "")
1468 (setq command gnus-last-shell-command))
1469 (gnus-eval-in-buffer-window gnus-article-buffer
1472 (shell-command-on-region (point-min) (point-max) command nil)))
1473 (setq gnus-last-shell-command command))
1475 ;;; Article file names when saving.
1477 (defun gnus-capitalize-newsgroup (newsgroup)
1478 "Capitalize NEWSGROUP name."
1479 (when (not (zerop (length newsgroup)))
1480 (concat (char-to-string (upcase (aref newsgroup 0)))
1481 (substring newsgroup 1))))
1483 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1484 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1485 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1486 Otherwise, it is like ~/News/news/group/num."
1489 (concat (if (gnus-use-long-file-name 'not-save)
1490 (gnus-capitalize-newsgroup newsgroup)
1491 (gnus-newsgroup-directory-form newsgroup))
1492 "/" (int-to-string (mail-header-number headers)))
1493 gnus-article-save-directory)))
1495 (string-equal (file-name-directory default)
1496 (file-name-directory last-file))
1497 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1499 (or last-file default))))
1501 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1502 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1503 If variable `gnus-use-long-file-name' is non-nil, it is
1504 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1507 (concat (if (gnus-use-long-file-name 'not-save)
1509 (gnus-newsgroup-directory-form newsgroup))
1510 "/" (int-to-string (mail-header-number headers)))
1511 gnus-article-save-directory)))
1513 (string-equal (file-name-directory default)
1514 (file-name-directory last-file))
1515 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1517 (or last-file default))))
1519 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1520 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1521 If variable `gnus-use-long-file-name' is non-nil, it is
1522 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1525 (if (gnus-use-long-file-name 'not-save)
1526 (gnus-capitalize-newsgroup newsgroup)
1527 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1528 gnus-article-save-directory)))
1530 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1531 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1532 If variable `gnus-use-long-file-name' is non-nil, it is
1533 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1536 (if (gnus-use-long-file-name 'not-save)
1538 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1539 gnus-article-save-directory)))
1546 (setq afunc (car func)
1549 gfunc (intern (format "gnus-%s" func))))
1551 (if (not (fboundp afunc))
1553 `(lambda (&optional interactive &rest args)
1554 ,(documentation afunc t)
1555 (interactive (list t))
1557 (set-buffer gnus-article-buffer)
1559 (call-interactively ',afunc)
1560 (apply ',afunc args))))))))
1561 '(article-hide-headers
1562 article-hide-boring-headers
1563 article-treat-overstrike
1564 (article-fill . gnus-article-word-wrap)
1566 article-display-x-face
1567 article-de-quoted-unreadable
1568 article-mime-decode-quoted-printable
1571 article-hide-signature
1572 article-remove-trailing-blank-lines
1573 article-strip-leading-blank-lines
1574 article-strip-multiple-blank-lines
1575 article-strip-blank-lines
1577 article-date-original
1582 (article-show-all . gnus-article-show-all-headers))))
1585 ;;; Gnus article mode
1588 (put 'gnus-article-mode 'mode-class 'special)
1591 (gnus-define-keys gnus-article-mode-map
1592 " " gnus-article-goto-next-page
1593 "\177" gnus-article-goto-prev-page
1594 [delete] gnus-article-goto-prev-page
1595 "\C-c^" gnus-article-refer-article
1596 "h" gnus-article-show-summary
1597 "s" gnus-article-show-summary
1598 "\C-c\C-m" gnus-article-mail
1599 "?" gnus-article-describe-briefly
1600 gnus-mouse-2 gnus-article-push-button
1601 "\r" gnus-article-press-button
1602 "\t" gnus-article-next-button
1603 "\M-\t" gnus-article-prev-button
1604 "e" gnus-article-edit
1605 "<" beginning-of-buffer
1607 "\C-c\C-i" gnus-info-find-node
1610 "\C-d" gnus-article-read-summary-keys
1611 "\M-*" gnus-article-read-summary-keys
1612 "\M-g" gnus-article-read-summary-keys)
1614 (substitute-key-definition
1615 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1617 (defun gnus-article-make-menu-bar ()
1618 (gnus-turn-off-edit-menu 'article)
1619 (unless (boundp 'gnus-article-article-menu)
1621 gnus-article-article-menu gnus-article-mode-map ""
1623 ["Scroll forwards" gnus-article-goto-next-page t]
1624 ["Scroll backwards" gnus-article-goto-prev-page t]
1625 ["Show summary" gnus-article-show-summary t]
1626 ["Fetch Message-ID at point" gnus-article-refer-article t]
1627 ["Mail to address at point" gnus-article-mail t]))
1630 gnus-article-treatment-menu gnus-article-mode-map ""
1632 ["Hide headers" gnus-article-hide-headers t]
1633 ["Hide signature" gnus-article-hide-signature t]
1634 ["Hide citation" gnus-article-hide-citation t]
1635 ["Treat overstrike" gnus-article-treat-overstrike t]
1636 ["Remove carriage return" gnus-article-remove-cr t]
1637 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1639 (when (boundp 'gnus-summary-article-menu)
1640 (define-key gnus-article-mode-map [menu-bar commands]
1641 (cons "Commands" gnus-summary-article-menu)))
1643 (when (boundp 'gnus-summary-post-menu)
1644 (define-key gnus-article-mode-map [menu-bar post]
1645 (cons "Post" gnus-summary-post-menu)))
1647 (run-hooks 'gnus-article-menu-hook)))
1649 (defun gnus-article-mode ()
1650 "Major mode for displaying an article.
1652 All normal editing commands are switched off.
1654 The following commands are available in addition to all summary mode
1656 \\<gnus-article-mode-map>
1657 \\[gnus-article-next-page]\t Scroll the article one page forwards
1658 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1659 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1660 \\[gnus-article-show-summary]\t Display the summary buffer
1661 \\[gnus-article-mail]\t Send a reply to the address near point
1662 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1663 \\[gnus-info-find-node]\t Go to the Gnus info node"
1665 (when (gnus-visual-p 'article-menu 'menu)
1666 (gnus-article-make-menu-bar))
1667 (kill-all-local-variables)
1668 (gnus-simplify-mode-line)
1669 (setq mode-name "Article")
1670 (setq major-mode 'gnus-article-mode)
1671 (make-local-variable 'minor-mode-alist)
1672 (unless (assq 'gnus-show-mime minor-mode-alist)
1673 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1674 (use-local-map gnus-article-mode-map)
1675 (gnus-update-format-specifications nil 'article-mode)
1676 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1677 (gnus-set-default-directory)
1678 (buffer-disable-undo (current-buffer))
1679 (setq buffer-read-only t)
1680 (set-syntax-table gnus-article-mode-syntax-table)
1681 (run-hooks 'gnus-article-mode-hook))
1683 (defun gnus-article-setup-buffer ()
1684 "Initialize the article buffer."
1685 (let* ((name (if gnus-single-article-buffer "*Article*"
1686 (concat "*Article " gnus-newsgroup-name "*")))
1688 (progn (string-match "\\*Article" name)
1689 (concat " *Original Article"
1690 (substring name (match-end 0))))))
1691 (setq gnus-article-buffer name)
1692 (setq gnus-original-article-buffer original)
1693 ;; This might be a variable local to the summary buffer.
1694 (unless gnus-single-article-buffer
1696 (set-buffer gnus-summary-buffer)
1697 (setq gnus-article-buffer name)
1698 (setq gnus-original-article-buffer original)
1699 (gnus-set-global-variables)))
1700 ;; Init original article buffer.
1702 (set-buffer (get-buffer-create gnus-original-article-buffer))
1703 (buffer-disable-undo (current-buffer))
1704 (setq major-mode 'gnus-original-article-mode)
1705 (gnus-add-current-to-buffer-list)
1706 (make-local-variable 'gnus-original-article))
1707 (if (get-buffer name)
1710 (buffer-disable-undo (current-buffer))
1711 (setq buffer-read-only t)
1712 (gnus-add-current-to-buffer-list)
1713 (unless (eq major-mode 'gnus-article-mode)
1714 (gnus-article-mode))
1717 (set-buffer (get-buffer-create name))
1718 (gnus-add-current-to-buffer-list)
1720 (make-local-variable 'gnus-summary-buffer)
1721 (current-buffer)))))
1723 ;; Set article window start at LINE, where LINE is the number of lines
1724 ;; from the head of the article.
1725 (defun gnus-article-set-window-start (&optional line)
1727 (get-buffer-window gnus-article-buffer t)
1729 (set-buffer gnus-article-buffer)
1730 (goto-char (point-min))
1733 (gnus-message 6 "Moved to bookmark")
1734 (search-forward "\n\n" nil t)
1738 (defun gnus-article-prepare (article &optional all-headers header)
1739 "Prepare ARTICLE in article mode buffer.
1740 ARTICLE should either be an article number or a Message-ID.
1741 If ARTICLE is an id, HEADER should be the article headers.
1742 If ALL-HEADERS is non-nil, no headers are hidden."
1744 ;; Make sure we start in a summary buffer.
1745 (unless (eq major-mode 'gnus-summary-mode)
1746 (set-buffer gnus-summary-buffer))
1747 (setq gnus-summary-buffer (current-buffer))
1748 ;; Make sure the connection to the server is alive.
1749 (unless (gnus-server-opened
1750 (gnus-find-method-for-group gnus-newsgroup-name))
1751 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1752 (gnus-request-group gnus-newsgroup-name t))
1753 (let* ((gnus-article (if header (mail-header-number header) article))
1754 (summary-buffer (current-buffer))
1755 (internal-hook gnus-article-internal-prepare-hook)
1756 (group gnus-newsgroup-name)
1759 (gnus-article-setup-buffer)
1760 (set-buffer gnus-article-buffer)
1761 ;; Deactivate active regions.
1762 (when (and (boundp 'transient-mark-mode)
1763 transient-mark-mode)
1764 (setq mark-active nil))
1765 (if (not (setq result (let ((buffer-read-only nil))
1766 (gnus-request-article-this-buffer
1768 ;; There is no such article.
1770 (when (and (numberp article)
1771 (not (memq article gnus-newsgroup-sparse)))
1772 (setq gnus-article-current
1773 (cons gnus-newsgroup-name article))
1774 (set-buffer gnus-summary-buffer)
1775 (setq gnus-current-article article)
1776 (gnus-summary-mark-article article gnus-canceled-mark))
1777 (unless (memq article gnus-newsgroup-sparse)
1779 1 "No such article (may have expired or been canceled)")))
1780 (if (or (eq result 'pseudo) (eq result 'nneething))
1783 (set-buffer summary-buffer)
1784 (setq gnus-last-article gnus-current-article
1785 gnus-newsgroup-history (cons gnus-current-article
1786 gnus-newsgroup-history)
1787 gnus-current-article 0
1788 gnus-current-headers nil
1789 gnus-article-current nil)
1790 (if (eq result 'nneething)
1791 (gnus-configure-windows 'summary)
1792 (gnus-configure-windows 'article))
1793 (gnus-set-global-variables))
1794 (gnus-set-mode-line 'article))
1795 ;; The result from the `request' was an actual article -
1796 ;; or at least some text that is now displayed in the
1798 (when (and (numberp article)
1799 (not (eq article gnus-current-article)))
1800 ;; Seems like a new article has been selected.
1801 ;; `gnus-current-article' must be an article number.
1803 (set-buffer summary-buffer)
1804 (setq gnus-last-article gnus-current-article
1805 gnus-newsgroup-history (cons gnus-current-article
1806 gnus-newsgroup-history)
1807 gnus-current-article article
1808 gnus-current-headers
1809 (gnus-summary-article-header gnus-current-article)
1810 gnus-article-current
1811 (cons gnus-newsgroup-name gnus-current-article))
1812 (unless (vectorp gnus-current-headers)
1813 (setq gnus-current-headers nil))
1814 (gnus-summary-show-thread)
1815 (run-hooks 'gnus-mark-article-hook)
1816 (gnus-set-mode-line 'summary)
1817 (when (gnus-visual-p 'article-highlight 'highlight)
1818 (run-hooks 'gnus-visual-mark-article-hook))
1819 ;; Set the global newsgroup variables here.
1820 ;; Suggested by Jim Sisolak
1821 ;; <sisolak@trans4.neep.wisc.edu>.
1822 (gnus-set-global-variables)
1823 (setq gnus-have-all-headers
1824 (or all-headers gnus-show-all-headers))
1826 (vectorp (gnus-summary-article-header article))
1827 (gnus-cache-possibly-enter-article
1829 (gnus-summary-article-header article)
1830 (memq article gnus-newsgroup-marked)
1831 (memq article gnus-newsgroup-dormant)
1832 (memq article gnus-newsgroup-unreads)))))
1833 (when (or (numberp article)
1835 ;; Hooks for getting information from the article.
1836 ;; This hook must be called before being narrowed.
1837 (let (buffer-read-only)
1838 (run-hooks 'internal-hook)
1839 (run-hooks 'gnus-article-prepare-hook)
1840 ;; Decode MIME message.
1841 (when gnus-show-mime
1842 (if (or (not gnus-strict-mime)
1843 (gnus-fetch-field "Mime-Version"))
1844 (funcall gnus-show-mime-method)
1845 (funcall gnus-decode-encoded-word-method)))
1846 ;; Perform the article display hooks.
1847 (run-hooks 'gnus-article-display-hook))
1849 (goto-char (point-min))
1850 (when gnus-break-pages
1851 (gnus-narrow-to-page)))
1852 (gnus-set-mode-line 'article)
1853 (gnus-configure-windows 'article)
1854 (goto-char (point-min))
1857 (defun gnus-article-wash-status ()
1858 "Return a string which display status of article washing."
1860 (set-buffer gnus-article-buffer)
1861 (let ((cite (gnus-article-hidden-text-p 'cite))
1862 (headers (gnus-article-hidden-text-p 'headers))
1863 (boring (gnus-article-hidden-text-p 'boring-headers))
1864 (pgp (gnus-article-hidden-text-p 'pgp))
1865 (pem (gnus-article-hidden-text-p 'pem))
1866 (signature (gnus-article-hidden-text-p 'signature))
1867 (overstrike (gnus-article-hidden-text-p 'overstrike))
1868 (emphasis (gnus-article-hidden-text-p 'emphasis))
1869 (mime gnus-show-mime))
1870 (format "%c%c%c%c%c%c%c"
1872 (if (or headers boring) ?h ? )
1873 (if (or pgp pem) ?p ? )
1874 (if signature ?s ? )
1875 (if overstrike ?o ? )
1877 (if emphasis ?e ? )))))
1879 (defun gnus-article-hide-headers-if-wanted ()
1880 "Hide unwanted headers if `gnus-have-all-headers' is nil.
1881 Provided for backwards compatibility."
1882 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1884 (gnus-article-hide-headers)))
1888 (defun gnus-output-to-rmail (file-name)
1889 "Append the current article to an Rmail file named FILE-NAME."
1891 ;; Most of these codes are borrowed from rmailout.el.
1892 (setq file-name (expand-file-name file-name))
1893 (setq rmail-default-rmail-file file-name)
1894 (let ((artbuf (current-buffer))
1895 (tmpbuf (get-buffer-create " *Gnus-output*")))
1897 (or (get-file-buffer file-name)
1898 (file-exists-p file-name)
1899 (if (gnus-yes-or-no-p
1900 (concat "\"" file-name "\" does not exist, create it? "))
1901 (let ((file-buffer (create-file-buffer file-name)))
1903 (set-buffer file-buffer)
1904 (rmail-insert-rmail-file-header)
1905 (let ((require-final-newline nil))
1906 (gnus-write-buffer file-name)))
1907 (kill-buffer file-buffer))
1908 (error "Output file does not exist")))
1910 (buffer-disable-undo (current-buffer))
1912 (insert-buffer-substring artbuf)
1913 (gnus-convert-article-to-rmail)
1914 ;; Decide whether to append to a file or to an Emacs buffer.
1915 (let ((outbuf (get-file-buffer file-name)))
1917 (append-to-file (point-min) (point-max) file-name)
1918 ;; File has been visited, in buffer OUTBUF.
1920 (let ((buffer-read-only nil)
1921 (msg (and (boundp 'rmail-current-message)
1922 (symbol-value 'rmail-current-message))))
1923 ;; If MSG is non-nil, buffer is in RMAIL mode.
1926 (narrow-to-region (point-max) (point-max)))
1927 (insert-buffer-substring tmpbuf)
1929 (goto-char (point-min))
1931 (search-backward "\^_")
1932 (narrow-to-region (point) (point-max))
1933 (goto-char (1+ (point-min)))
1934 (rmail-count-new-messages t)
1935 (rmail-show-message msg))))))
1936 (kill-buffer tmpbuf)))
1938 (defun gnus-output-to-file (file-name)
1939 "Append the current article to a file named FILE-NAME."
1940 (let ((artbuf (current-buffer)))
1941 (nnheader-temp-write nil
1942 (insert-buffer-substring artbuf)
1943 ;; Append newline at end of the buffer as separator, and then
1945 (goto-char (point-max))
1947 (append-to-file (point-min) (point-max) file-name))))
1949 (defun gnus-convert-article-to-rmail ()
1950 "Convert article in current buffer to Rmail message format."
1951 (let ((buffer-read-only nil))
1952 ;; Convert article directly into Babyl format.
1953 ;; Suggested by Rob Austein <sra@lcs.mit.edu>
1954 (goto-char (point-min))
1955 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1956 (while (search-forward "\n\^_" nil t) ;single char
1957 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
1958 (goto-char (point-max))
1961 (defun gnus-narrow-to-page (&optional arg)
1962 "Narrow the article buffer to a page.
1963 If given a numerical ARG, move forward ARG pages."
1965 (setq arg (if arg (prefix-numeric-value arg) 0))
1967 (set-buffer gnus-article-buffer)
1968 (goto-char (point-min))
1970 ;; Remove any old next/prev buttons.
1971 (when (gnus-visual-p 'page-marker)
1972 (let ((buffer-read-only nil))
1973 (gnus-remove-text-with-property 'gnus-prev)
1974 (gnus-remove-text-with-property 'gnus-next)))
1977 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1979 (re-search-forward page-delimiter nil 'move arg)))
1980 (goto-char (match-end 0)))
1983 (if (re-search-forward page-delimiter nil 'move)
1986 (when (and (gnus-visual-p 'page-marker)
1987 (not (= (point-min) 1)))
1989 (goto-char (point-min))
1990 (gnus-insert-prev-page-button)))
1991 (when (and (gnus-visual-p 'page-marker)
1992 (< (+ (point-max) 2) (buffer-size)))
1994 (goto-char (point-max))
1995 (gnus-insert-next-page-button)))))
1997 ;; Article mode commands
1999 (defun gnus-article-goto-next-page ()
2000 "Show the next page of the article."
2002 (when (gnus-article-next-page)
2003 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2005 (defun gnus-article-goto-prev-page ()
2006 "Show the next page of the article."
2008 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))
2009 (gnus-article-prev-page nil)))
2011 (defun gnus-article-next-page (&optional lines)
2012 "Show the next page of the current article.
2013 If end of article, return non-nil. Otherwise return nil.
2014 Argument LINES specifies lines to be scrolled up."
2016 (move-to-window-line -1)
2019 (and (pos-visible-in-window-p) ;Not continuation line.
2021 ;; Nothing in this page.
2022 (if (or (not gnus-break-pages)
2025 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2027 (gnus-narrow-to-page 1) ;Go to next page.
2029 ;; More in this page.
2030 (let ((scroll-in-place nil))
2034 ;; Long lines may cause an end-of-buffer error.
2035 (goto-char (point-max)))))
2036 (move-to-window-line 0)
2039 (defun gnus-article-prev-page (&optional lines)
2040 "Show previous page of current article.
2041 Argument LINES specifies lines to be scrolled down."
2043 (move-to-window-line 0)
2044 (if (and gnus-break-pages
2046 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2048 (gnus-narrow-to-page -1) ;Go to previous page.
2049 (goto-char (point-max))
2051 (let ((scroll-in-place nil))
2054 (scroll-down lines))
2055 (move-to-window-line 0)))))
2057 (defun gnus-article-refer-article ()
2058 "Read article specified by message-id around point."
2060 (let ((point (point)))
2061 (search-forward ">" nil t) ;Move point to end of "<....>".
2062 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2063 (let ((message-id (match-string 1)))
2065 (set-buffer gnus-summary-buffer)
2066 (gnus-summary-refer-article message-id))
2068 (error "No references around point"))))
2070 (defun gnus-article-show-summary ()
2071 "Reconfigure windows to show summary buffer."
2073 (gnus-configure-windows 'article)
2074 (gnus-summary-goto-subject gnus-current-article))
2076 (defun gnus-article-describe-briefly ()
2077 "Describe article mode commands briefly."
2080 (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")))
2082 (defun gnus-article-summary-command ()
2083 "Execute the last keystroke in the summary buffer."
2085 (let ((obuf (current-buffer))
2086 (owin (current-window-configuration))
2088 (switch-to-buffer gnus-summary-buffer 'norecord)
2089 (setq func (lookup-key (current-local-map) (this-command-keys)))
2090 (call-interactively func)
2092 (set-window-configuration owin)
2093 (set-window-point (get-buffer-window (current-buffer)) (point))))
2095 (defun gnus-article-summary-command-nosave ()
2096 "Execute the last keystroke in the summary buffer."
2099 (pop-to-buffer gnus-summary-buffer 'norecord)
2100 (setq func (lookup-key (current-local-map) (this-command-keys)))
2101 (call-interactively func)))
2103 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2104 "Read a summary buffer key sequence and execute it from the article buffer."
2107 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2108 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2109 "=" "^" "\M-^" "|"))
2116 (set-buffer gnus-summary-buffer)
2117 (push (or key last-command-event) unread-command-events)
2118 (setq keys (read-key-sequence nil)))
2121 (if (or (member keys nosaves)
2122 (member keys nosave-but-article)
2123 (member keys nosave-in-article))
2125 (save-window-excursion
2126 (pop-to-buffer gnus-summary-buffer 'norecord)
2127 (setq func (lookup-key (current-local-map) keys)))
2130 (unless (member keys nosave-in-article)
2131 (set-buffer gnus-summary-buffer))
2132 (call-interactively func))
2133 (when (member keys nosave-but-article)
2134 (pop-to-buffer gnus-article-buffer 'norecord)))
2135 ;; These commands should restore window configuration.
2136 (let ((obuf (current-buffer))
2137 (owin (current-window-configuration))
2140 (if not-restore-window
2141 (pop-to-buffer gnus-summary-buffer 'norecord)
2142 (switch-to-buffer gnus-summary-buffer 'norecord))
2143 (setq in-buffer (current-buffer))
2144 (if (setq func (lookup-key (current-local-map) keys))
2145 (call-interactively func)
2147 (when (eq in-buffer (current-buffer))
2149 (unless not-restore-window
2150 (set-window-configuration owin))
2151 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2153 (defun gnus-article-hide (&optional arg force)
2154 "Hide all the gruft in the current article.
2155 This means that PGP stuff, signatures, cited text and (some)
2156 headers will be hidden.
2157 If given a prefix, show the hidden text instead."
2158 (interactive (list current-prefix-arg 'force))
2159 (gnus-article-hide-headers arg)
2160 (gnus-article-hide-pgp arg)
2161 (gnus-article-hide-citation-maybe arg force)
2162 (gnus-article-hide-signature arg))
2164 (defun gnus-article-maybe-highlight ()
2165 "Do some article highlighting if `article-visual' is non-nil."
2166 (when (gnus-visual-p 'article-highlight 'highlight)
2167 (gnus-article-highlight-some)))
2169 (defun gnus-request-article-this-buffer (article group)
2170 "Get an article and insert it into this buffer."
2171 (let (do-update-line)
2175 (gnus-kill-all-overlays)
2176 (setq group (or group gnus-newsgroup-name))
2178 ;; Open server if it has closed.
2179 (gnus-check-server (gnus-find-method-for-group group))
2181 ;; Using `gnus-request-article' directly will insert the article into
2182 ;; `nntp-server-buffer' - so we'll save some time by not having to
2183 ;; copy it from the server buffer into the article buffer.
2185 ;; We only request an article by message-id when we do not have the
2186 ;; headers for it, so we'll have to get those.
2187 (when (stringp article)
2188 (let ((gnus-override-method gnus-refer-article-method))
2189 (gnus-read-header article)))
2191 ;; If the article number is negative, that means that this article
2192 ;; doesn't belong in this newsgroup (possibly), so we find its
2193 ;; message-id and request it by id instead of number.
2194 (when (and (numberp article)
2196 (get-buffer gnus-summary-buffer)
2197 (buffer-name (get-buffer gnus-summary-buffer)))
2199 (set-buffer gnus-summary-buffer)
2200 (let ((header (gnus-summary-article-header article)))
2203 ((memq article gnus-newsgroup-sparse)
2204 ;; This is a sparse gap article.
2205 (setq do-update-line article)
2206 (setq article (mail-header-id header))
2207 (let ((gnus-override-method gnus-refer-article-method))
2208 (gnus-read-header article))
2209 (setq gnus-newsgroup-sparse
2210 (delq article gnus-newsgroup-sparse)))
2212 ;; It's a real article.
2213 (setq article (mail-header-id header)))
2215 ;; It is an extracted pseudo-article.
2216 (setq article 'pseudo)
2217 (gnus-request-pseudo-article header))))
2219 (let ((method (gnus-find-method-for-group
2220 gnus-newsgroup-name)))
2221 (if (not (eq (car method) 'nneething))
2223 (let ((dir (concat (file-name-as-directory (nth 1 method))
2224 (mail-header-subject header))))
2225 (when (file-directory-p dir)
2226 (setq article 'nneething)
2227 (gnus-group-enter-directory dir))))))))
2230 ;; Refuse to select canceled articles.
2231 ((and (numberp article)
2233 (get-buffer gnus-summary-buffer)
2234 (buffer-name (get-buffer gnus-summary-buffer))
2235 (eq (cdr (save-excursion
2236 (set-buffer gnus-summary-buffer)
2237 (assq article gnus-newsgroup-reads)))
2238 gnus-canceled-mark))
2240 ;; We first check `gnus-original-article-buffer'.
2241 ((and (get-buffer gnus-original-article-buffer)
2244 (set-buffer gnus-original-article-buffer)
2245 (and (equal (car gnus-original-article) group)
2246 (eq (cdr gnus-original-article) article))))
2247 (insert-buffer-substring gnus-original-article-buffer)
2249 ;; Check the backlog.
2250 ((and gnus-keep-backlog
2251 (gnus-backlog-request-article group article (current-buffer)))
2253 ;; Check asynchronous pre-fetch.
2254 ((gnus-async-request-fetched-article group article (current-buffer))
2255 (gnus-async-prefetch-next group article gnus-summary-buffer)
2258 ((and gnus-use-cache
2260 (gnus-cache-request-article article group))
2262 ;; Get the article and put into the article buffer.
2263 ((or (stringp article) (numberp article))
2264 (let ((gnus-override-method
2265 (and (stringp article) gnus-refer-article-method))
2266 (buffer-read-only nil))
2268 (gnus-kill-all-overlays)
2269 (when (gnus-request-article article group (current-buffer))
2270 (when (numberp article)
2271 (gnus-async-prefetch-next group article gnus-summary-buffer)
2272 (when gnus-keep-backlog
2273 (gnus-backlog-enter-article
2274 group article (current-buffer))))
2279 ;; Take the article from the original article buffer
2280 ;; and place it in the buffer it's supposed to be in.
2281 (when (and (get-buffer gnus-article-buffer)
2283 (equal (buffer-name (current-buffer))
2284 (buffer-name (get-buffer gnus-article-buffer))))
2286 (if (get-buffer gnus-original-article-buffer)
2287 (set-buffer (get-buffer gnus-original-article-buffer))
2288 (set-buffer (get-buffer-create gnus-original-article-buffer))
2289 (buffer-disable-undo (current-buffer))
2290 (setq major-mode 'gnus-original-article-mode)
2291 (setq buffer-read-only t)
2292 (gnus-add-current-to-buffer-list))
2293 (let (buffer-read-only)
2295 (insert-buffer-substring gnus-article-buffer))
2296 (setq gnus-original-article (cons group article))))
2298 ;; Update sparse articles.
2299 (when (and do-update-line
2300 (or (numberp article)
2302 (let ((buf (current-buffer)))
2303 (set-buffer gnus-summary-buffer)
2304 (gnus-summary-update-article do-update-line)
2305 (gnus-summary-goto-subject do-update-line nil t)
2306 (set-window-point (get-buffer-window (current-buffer) t)
2308 (set-buffer buf))))))
2314 (defcustom gnus-article-edit-mode-hook nil
2315 "Hook run in article edit mode buffers."
2319 (defvar gnus-article-edit-done-function nil)
2321 (defvar gnus-article-edit-mode-map nil)
2323 (unless gnus-article-edit-mode-map
2324 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2326 (gnus-define-keys gnus-article-edit-mode-map
2327 "\C-c\C-c" gnus-article-edit-done
2328 "\C-c\C-k" gnus-article-edit-exit)
2330 (gnus-define-keys (gnus-article-edit-wash-map
2331 "\C-c\C-w" gnus-article-edit-mode-map)
2332 "f" gnus-article-edit-full-stops))
2334 (defun gnus-article-edit-mode ()
2335 "Major mode for editing articles.
2336 This is an extended text-mode.
2338 \\{gnus-article-edit-mode-map}"
2340 (kill-all-local-variables)
2341 (setq major-mode 'gnus-article-edit-mode)
2342 (setq mode-name "Article Edit")
2343 (use-local-map gnus-article-edit-mode-map)
2344 (make-local-variable 'gnus-article-edit-done-function)
2345 (make-local-variable 'gnus-prev-winconf)
2346 (setq buffer-read-only nil)
2347 (buffer-enable-undo)
2349 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2351 (defun gnus-article-edit (&optional force)
2352 "Edit the current article.
2353 This will have permanent effect only in mail groups.
2354 If FORCE is non-nil, allow editing of articles even in read-only
2357 (when (and (not force)
2358 (gnus-group-read-only-p))
2359 (error "The current newsgroup does not support article editing."))
2360 (gnus-article-edit-article
2362 (gnus-summary-edit-article-done
2363 ,(or (mail-header-references gnus-current-headers) "")
2364 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2366 (defun gnus-article-edit-article (exit-func)
2367 "Start editing the contents of the current article buffer."
2368 (let ((winconf (current-window-configuration)))
2369 (set-buffer gnus-article-buffer)
2370 (gnus-article-edit-mode)
2371 (set-text-properties (point-min) (point-max) nil)
2372 (gnus-configure-windows 'edit-article)
2373 (setq gnus-article-edit-done-function exit-func)
2374 (setq gnus-prev-winconf winconf)
2375 (gnus-message 6 "C-c C-c to end edits")))
2377 (defun gnus-article-edit-done ()
2378 "Update the article edits and exit."
2380 (let ((func gnus-article-edit-done-function)
2381 (buf (current-buffer))
2382 (start (window-start)))
2383 (gnus-article-edit-exit)
2386 (let ((buffer-read-only nil))
2389 (set-window-start (get-buffer-window buf) start)
2390 (set-window-point (get-buffer-window buf) (point))))
2392 (defun gnus-article-edit-exit ()
2393 "Exit the article editing without updating."
2395 ;; We remove all text props from the article buffer.
2396 (let ((buf (format "%s" (buffer-string)))
2397 (curbuf (current-buffer))
2399 (window-start (window-start)))
2402 (let ((winconf gnus-prev-winconf))
2404 ;; The cache and backlog have to be flushed somewhat.
2405 (when gnus-use-cache
2406 (gnus-cache-update-article
2407 (car gnus-article-current) (cdr gnus-article-current)))
2408 (when gnus-keep-backlog
2409 (gnus-backlog-remove-article
2410 (car gnus-article-current) (cdr gnus-article-current)))
2411 ;; Flush original article as well.
2413 (when (get-buffer gnus-original-article-buffer)
2414 (set-buffer gnus-original-article-buffer)
2415 (setq gnus-original-article nil)))
2416 (set-window-configuration winconf)
2417 ;; Tippy-toe some to make sure that point remains where it was.
2418 (let ((buf (current-buffer)))
2420 (set-window-start (get-buffer-window (current-buffer)) window-start)
2422 (set-buffer buf)))))
2424 (defun gnus-article-edit-full-stops ()
2425 "Interactively repair spacing at end of sentences."
2428 (goto-char (point-min))
2429 (search-forward-regexp "^$" nil t)
2430 (let ((case-fold-search nil))
2431 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2434 ;;; Article highlights
2437 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2439 ;;; Internal Variables:
2441 (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\\)"
2442 "Regular expression that matches URLs."
2446 (defcustom gnus-button-alist
2447 `(("\\(<?\\(url: ?\\)?news:\\([^>\n\t ]*\\)>?\\)" 1 t
2448 gnus-button-message-id 3)
2449 ("\\(<?\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>?\\)" 1 t
2450 gnus-button-fetch-group 4)
2451 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2452 t gnus-button-message-id 3)
2453 ("\\(<URL: *\\)?mailto: *\\([^> \n\t]+\\)>?" 0 t gnus-url-mailto 2)
2454 ;; This is how URLs _should_ be embedded in text...
2455 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2457 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2458 "Alist of regexps matching buttons in article bodies.
2460 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2461 REGEXP: is the string matching text around the button,
2462 BUTTON: is the number of the regexp grouping actually matching the button,
2463 FORM: is a lisp expression which must eval to true for the button to
2465 CALLBACK: is the function to call when the user push this button, and each
2466 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2468 CALLBACK can also be a variable, in that case the value of that
2469 variable it the real callback function."
2471 :type '(repeat (list regexp
2472 (integer :tag "Button")
2474 (function :tag "Callback")
2477 (integer :tag "Regexp group")))))
2479 (defcustom gnus-header-button-alist
2480 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2481 0 t gnus-button-message-id 0)
2482 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2483 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2484 0 t gnus-button-mailto 0)
2485 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2486 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2487 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2488 gnus-button-message-id 3))
2489 "Alist of headers and regexps to match buttons in article heads.
2491 This alist is very similar to `gnus-button-alist', except that each
2492 alist has an additional HEADER element first in each entry:
2494 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2496 HEADER is a regexp to match a header. For a fuller explanation, see
2497 `gnus-button-alist'."
2499 :type '(repeat (list (regexp :tag "Header")
2501 (integer :tag "Button")
2503 (function :tag "Callback")
2506 (integer :tag "Regexp group")))))
2508 (defvar gnus-button-regexp nil)
2509 (defvar gnus-button-marker-list nil)
2510 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2512 (defvar gnus-button-last nil)
2513 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2517 (defun gnus-article-push-button (event)
2518 "Check text under the mouse pointer for a callback function.
2519 If the text under the mouse pointer has a `gnus-callback' property,
2520 call it with the value of the `gnus-data' text property."
2522 (set-buffer (window-buffer (posn-window (event-start event))))
2523 (let* ((pos (posn-point (event-start event)))
2524 (data (get-text-property pos 'gnus-data))
2525 (fun (get-text-property pos 'gnus-callback)))
2527 (funcall fun data))))
2529 (defun gnus-article-press-button ()
2530 "Check text at point for a callback function.
2531 If the text at point has a `gnus-callback' property,
2532 call it with the value of the `gnus-data' text property."
2534 (let* ((data (get-text-property (point) 'gnus-data))
2535 (fun (get-text-property (point) 'gnus-callback)))
2537 (funcall fun data))))
2539 (defun gnus-article-prev-button (n)
2540 "Move point to N buttons backward.
2541 If N is negative, move forward instead."
2543 (gnus-article-next-button (- n)))
2545 (defun gnus-article-next-button (n)
2546 "Move point to N buttons forward.
2547 If N is negative, move backward instead."
2549 (let ((function (if (< n 0) 'previous-single-property-change
2550 'next-single-property-change))
2551 (inhibit-point-motion-hooks t)
2553 (limit (if (< n 0) (point-min) (point-max))))
2555 (while (and (not (= limit (point)))
2557 ;; Skip past the current button.
2558 (when (get-text-property (point) 'gnus-callback)
2559 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2560 ;; Go to the next (or previous) button.
2561 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2562 ;; Put point at the start of the button.
2563 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2564 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2565 ;; Skip past intangible buttons.
2566 (when (get-text-property (point) 'intangible)
2570 (gnus-message 5 "No more buttons"))
2573 (defun gnus-article-highlight (&optional force)
2574 "Highlight current article.
2575 This function calls `gnus-article-highlight-headers',
2576 `gnus-article-highlight-citation',
2577 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2578 do the highlighting. See the documentation for those functions."
2579 (interactive (list 'force))
2580 (gnus-article-highlight-headers)
2581 (gnus-article-highlight-citation force)
2582 (gnus-article-highlight-signature)
2583 (gnus-article-add-buttons force)
2584 (gnus-article-add-buttons-to-head))
2586 (defun gnus-article-highlight-some (&optional force)
2587 "Highlight current article.
2588 This function calls `gnus-article-highlight-headers',
2589 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2590 do the highlighting. See the documentation for those functions."
2591 (interactive (list 'force))
2592 (gnus-article-highlight-headers)
2593 (gnus-article-highlight-signature)
2594 (gnus-article-add-buttons))
2596 (defun gnus-article-highlight-headers ()
2597 "Highlight article headers as specified by `gnus-header-face-alist'."
2600 (set-buffer gnus-article-buffer)
2602 (let ((alist gnus-header-face-alist)
2603 (buffer-read-only nil)
2604 (case-fold-search t)
2605 (inhibit-point-motion-hooks t)
2606 entry regexp header-face field-face from hpoints fpoints)
2607 (goto-char (point-min))
2608 (when (search-forward "\n\n" nil t)
2609 (narrow-to-region (1- (point)) (point-min))
2610 (while (setq entry (pop alist))
2611 (goto-char (point-min))
2612 (setq regexp (concat "^\\("
2613 (if (string-equal "" (nth 0 entry))
2617 header-face (nth 1 entry)
2618 field-face (nth 2 entry))
2619 (while (and (re-search-forward regexp nil t)
2623 (unless (search-forward ":" nil t)
2625 (when (and header-face
2626 (not (memq (point) hpoints)))
2627 (push (point) hpoints)
2628 (gnus-put-text-property from (point) 'face header-face))
2629 (when (and field-face
2630 (not (memq (setq from (point)) fpoints)))
2632 (if (re-search-forward "^[^ \t]" nil t)
2634 (goto-char (point-max)))
2635 (gnus-put-text-property from (point) 'face field-face)))))))))
2637 (defun gnus-article-highlight-signature ()
2638 "Highlight the signature in an article.
2639 It does this by highlighting everything after
2640 `gnus-signature-separator' using `gnus-signature-face'."
2643 (set-buffer gnus-article-buffer)
2644 (let ((buffer-read-only nil)
2645 (inhibit-point-motion-hooks t))
2647 (when (and gnus-signature-face
2648 (gnus-article-narrow-to-signature))
2649 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2650 'face gnus-signature-face)
2652 (gnus-article-search-signature)
2653 (let ((start (match-beginning 0))
2654 (end (set-marker (make-marker) (1+ (match-end 0)))))
2655 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2658 (defun gnus-article-add-buttons (&optional force)
2659 "Find external references in the article and make buttons of them.
2660 \"External references\" are things like Message-IDs and URLs, as
2661 specified by `gnus-button-alist'."
2662 (interactive (list 'force))
2664 (set-buffer gnus-article-buffer)
2665 ;; Remove all old markers.
2666 (while gnus-button-marker-list
2667 (set-marker (pop gnus-button-marker-list) nil))
2668 (let ((buffer-read-only nil)
2669 (inhibit-point-motion-hooks t)
2670 (case-fold-search t)
2671 (alist gnus-button-alist)
2673 (goto-char (point-min))
2674 ;; We skip the headers.
2675 (unless (search-forward "\n\n" nil t)
2676 (goto-char (point-max)))
2678 (while (setq entry (pop alist))
2679 (setq regexp (car entry))
2681 (while (re-search-forward regexp nil t)
2682 (let* ((start (and entry (match-beginning (nth 1 entry))))
2683 (end (and entry (match-end (nth 1 entry))))
2684 (from (match-beginning 0)))
2685 (when (and (or (eq t (nth 1 entry))
2686 (eval (nth 1 entry)))
2687 (not (get-text-property (point) 'gnus-callback)))
2688 ;; That optional form returned non-nil, so we add the
2690 (gnus-article-add-button
2691 start end 'gnus-button-push
2692 (car (push (set-marker (make-marker) from)
2693 gnus-button-marker-list))))))))))
2695 ;; Add buttons to the head of an article.
2696 (defun gnus-article-add-buttons-to-head ()
2697 "Add buttons to the head of the article."
2700 (set-buffer gnus-article-buffer)
2701 (let ((buffer-read-only nil)
2702 (inhibit-point-motion-hooks t)
2703 (case-fold-search t)
2704 (alist gnus-header-button-alist)
2706 (nnheader-narrow-to-headers)
2708 ;; Each alist entry.
2709 (setq entry (car alist)
2711 (goto-char (point-min))
2712 (while (re-search-forward (car entry) nil t)
2713 ;; Each header matching the entry.
2714 (setq beg (match-beginning 0))
2715 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2716 (match-beginning 0))
2719 (while (re-search-forward (nth 1 entry) end t)
2720 ;; Each match within a header.
2721 (let* ((entry (cdr entry))
2722 (start (match-beginning (nth 1 entry)))
2723 (end (match-end (nth 1 entry)))
2724 (form (nth 2 entry)))
2725 (goto-char (match-end 0))
2727 (gnus-article-add-button
2728 start end (nth 3 entry)
2729 (buffer-substring (match-beginning (nth 4 entry))
2730 (match-end (nth 4 entry)))))))
2734 ;;; External functions:
2736 (defun gnus-article-add-button (from to fun &optional data)
2737 "Create a button between FROM and TO with callback FUN and data DATA."
2738 (when gnus-article-button-face
2739 (gnus-overlay-put (gnus-make-overlay from to)
2740 'face gnus-article-button-face))
2741 (gnus-add-text-properties
2743 (nconc (and gnus-article-mouse-face
2744 (list gnus-mouse-face-prop gnus-article-mouse-face))
2745 (list 'gnus-callback fun)
2746 (and data (list 'gnus-data data)))))
2748 ;;; Internal functions:
2750 (defun gnus-signature-toggle (end)
2752 (set-buffer gnus-article-buffer)
2753 (let ((buffer-read-only nil)
2754 (inhibit-point-motion-hooks t))
2755 (if (get-text-property end 'invisible)
2756 (gnus-article-unhide-text end (point-max))
2757 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2759 (defun gnus-button-entry ()
2760 ;; Return the first entry in `gnus-button-alist' matching this place.
2761 (let ((alist gnus-button-alist)
2764 (setq entry (pop alist))
2765 (if (looking-at (car entry))
2770 (defun gnus-button-push (marker)
2771 ;; Push button starting at MARKER.
2773 (set-buffer gnus-article-buffer)
2775 (let* ((entry (gnus-button-entry))
2776 (inhibit-point-motion-hooks t)
2778 (args (mapcar (lambda (group)
2779 (let ((string (match-string group)))
2780 (gnus-set-text-properties
2781 0 (length string) nil string)
2788 (fboundp (symbol-value fun)))
2789 (apply (symbol-value fun) args))
2791 (gnus-message 1 "You must define `%S' to use this button"
2792 (cons fun args)))))))
2794 (defun gnus-button-message-id (message-id)
2797 (set-buffer gnus-summary-buffer)
2798 (gnus-summary-refer-article message-id)))
2800 (defun gnus-button-fetch-group (address)
2801 "Fetch GROUP specified by ADDRESS."
2802 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
2803 (error "Can't parse %s" address)
2804 (gnus-group-read-ephemeral-group
2805 (match-string 4 address)
2806 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
2807 (nntp-port-number ,(if (match-end 3)
2808 (match-string 3 address)
2811 (defun gnus-split-string (string pattern)
2812 "Return a list of substrings of STRING which are separated by PATTERN."
2813 (let (parts (start 0))
2814 (while (string-match pattern string start)
2815 (setq parts (cons (substring string start (match-beginning 0)) parts)
2816 start (match-end 0)))
2817 (nreverse (cons (substring string start) parts))))
2819 (defun gnus-url-parse-query-string (query &optional downcase)
2820 (let (retval pairs cur key val)
2821 (setq pairs (gnus-split-string query "&"))
2823 (setq cur (car pairs)
2825 (if (not (string-match "=" cur))
2827 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2828 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2830 (setq key (downcase key)))
2831 (setq cur (assoc key retval))
2833 (setcdr cur (cons val (cdr cur)))
2834 (setq retval (cons (list key val) retval)))))
2837 (defun gnus-url-unhex (x)
2844 (defun gnus-url-unhex-string (str &optional allow-newlines)
2845 "Remove %XXX embedded spaces, etc in a url.
2846 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2847 decoding of carriage returns and line feeds in the string, which is normally
2848 forbidden in URL encoding."
2849 (setq str (or str ""))
2851 (case-fold-search t))
2852 (while (string-match "%[0-9a-f][0-9a-f]" str)
2853 (let* ((start (match-beginning 0))
2854 (ch1 (gnus-url-unhex (elt str (+ start 1))))
2856 (gnus-url-unhex (elt str (+ start 2))))))
2858 tmp (substring str 0 start)
2861 (char-to-string code))
2862 ((or (= code ?\n) (= code ?\r))
2864 (t (char-to-string code))))
2865 str (substring str (match-end 0)))))
2866 (setq tmp (concat tmp str))
2869 (defun gnus-url-mailto (url)
2870 ;; Send mail to someone
2871 (if (not (string-match "mailto:/*\\(.*\\)" url))
2872 (error "Malformed mailto link: %s" 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