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.
28 (eval-when-compile (require 'cl))
37 (defgroup gnus-article nil
39 :link '(custom-manual "(gnus)The Article Buffer")
42 (defgroup gnus-article-hiding nil
43 "Hiding article parts."
44 :link '(custom-manual "(gnus)Article Hiding")
47 (defgroup gnus-article-highlight nil
48 "Article highlighting."
49 :link '(custom-manual "(gnus)Article Highlighting")
53 (defgroup gnus-article-signature nil
55 :link '(custom-manual "(gnus)Article Signature")
58 (defgroup gnus-article-headers nil
60 :link '(custom-manual "(gnus)Hiding Headers")
63 (defgroup gnus-article-washing nil
64 "Special commands on articles."
65 :link '(custom-manual "(gnus)Article Washing")
68 (defgroup gnus-article-emphasis nil
69 "Fontisizing articles."
70 :link '(custom-manual "(gnus)Article Fontisizing")
73 (defgroup gnus-article-saving nil
75 :link '(custom-manual "(gnus)Saving Articles")
78 (defgroup gnus-article-mime nil
79 "Worshiping the MIME wonder."
80 :link '(custom-manual "(gnus)Using MIME")
83 (defgroup gnus-article-buttons nil
84 "Pushable buttons in the article buffer."
85 :link '(custom-manual "(gnus)Article Buttons")
88 (defgroup gnus-article-various nil
89 "Other article options."
90 :link '(custom-manual "(gnus)Misc Article")
93 (defcustom gnus-ignored-headers
94 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
95 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
96 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
97 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
98 "All headers that match this regexp will be hidden.
99 This variable can also be a list of regexps of headers to be ignored.
100 If `gnus-visible-headers' is non-nil, this variable will be ignored."
101 :type '(choice :custom-show nil
104 :group 'gnus-article-hiding)
106 (defcustom gnus-visible-headers
107 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From"
108 "All headers that do not match this regexp will be hidden.
109 This variable can also be a list of regexp of headers to remain visible.
110 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
111 :type '(repeat :value-to-internal (lambda (widget value)
112 (custom-split-regexp-maybe value))
113 :match (lambda (widget value)
115 (widget-editable-list-match widget value)))
117 :group 'gnus-article-hiding)
119 (defcustom gnus-sorted-header-list
120 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
121 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
122 "This variable is a list of regular expressions.
123 If it is non-nil, headers that match the regular expressions will
124 be placed first in the article buffer in the sequence specified by
126 :type '(repeat regexp)
127 :group 'gnus-article-hiding)
129 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
130 "Headers that are only to be displayed if they have interesting data.
131 Possible values in this list are `empty', `newsgroups', `followup-to',
132 `reply-to', and `date'."
133 :type '(set (const :tag "Headers with no content." empty)
134 (const :tag "Newsgroups with only one group." newsgroups)
135 (const :tag "Followup-to identical to newsgroups." followup-to)
136 (const :tag "Reply-to identical to from." reply-to)
137 (const :tag "Date less than four days old." date)
138 (const :tag "Very long To header." long-to))
139 :group 'gnus-article-hiding)
141 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
142 "Regexp matching signature separator.
143 This can also be a list of regexps. In that case, it will be checked
144 from head to tail looking for a separator. Searches will be done from
145 the end of the buffer."
146 :type '(repeat string)
147 :group 'gnus-article-signature)
149 (defcustom gnus-signature-limit nil
150 "Provide a limit to what is considered a signature.
151 If it is a number, no signature may not be longer (in characters) than
152 that number. If it is a floating point number, no signature may be
153 longer (in lines) than that number. If it is a function, the function
154 will be called without any parameters, and if it returns nil, there is
155 no signature in the buffer. If it is a string, it will be used as a
156 regexp. If it matches, the text in question is not a signature."
157 :type '(choice integer number function regexp)
158 :group 'gnus-article-signature)
160 (defcustom gnus-hidden-properties '(invisible t intangible t)
161 "Property list to use for hiding text."
163 :group 'gnus-article-hiding)
165 (defcustom gnus-article-x-face-command
166 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
167 "String or function to be executed to display an X-Face header.
168 If it is a string, the command will be executed in a sub-shell
169 asynchronously. The compressed face will be piped to this command."
170 :type 'string ;Leave function case to Lisp.
171 :group 'gnus-article-washing)
173 (defcustom gnus-article-x-face-too-ugly nil
174 "Regexp matching posters whose face shouldn't be shown automatically."
176 :group 'gnus-article-washing)
178 (defcustom gnus-emphasis-alist
180 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
182 '(("_" "_" underline)
185 ("_/" "/_" underline-italic)
186 ("_\\*" "\\*_" underline-bold)
187 ("\\*/" "/\\*" bold-italic)
188 ("_\\*/" "/\\*_" underline-bold-italic))))
189 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
190 2 3 gnus-emphasis-underline)
194 (format format (car spec) (cadr spec))
195 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
197 "Alist that says how to fontify certain phrases.
198 Each item looks like this:
200 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
202 The first element is a regular expression to be matched. The second
203 is a number that says what regular expression grouping used to find
204 the entire emphasized word. The third is a number that says what
205 regexp grouping should be displayed and highlighted. The fourth
206 is the face used for highlighting."
207 :type '(repeat (list :value ("" 0 0 default)
209 (integer :tag "Match group")
210 (integer :tag "Emphasize group")
212 :group 'gnus-article-emphasis)
214 (defface gnus-emphasis-bold '((t (:bold t)))
215 "Face used for displaying strong emphasized text (*word*)."
216 :group 'gnus-article-emphasis)
218 (defface gnus-emphasis-italic '((t (:italic t)))
219 "Face used for displaying italic emphasized text (/word/)."
220 :group 'gnus-article-emphasis)
222 (defface gnus-emphasis-underline '((t (:underline t)))
223 "Face used for displaying underlined emphasized text (_word_)."
224 :group 'gnus-article-emphasis)
226 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
227 "Face used for displaying underlined bold emphasized text (_*word*_)."
228 :group 'gnus-article-emphasis)
230 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
231 "Face used for displaying underlined italic emphasized text (_*word*_)."
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
235 "Face used for displaying bold italic emphasized text (/*word*/)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-underline-bold-italic
239 '((t (:bold t :italic t :underline t)))
240 "Face used for displaying underlined bold italic emphasized text.
241 Esample: (_/*word*/_)."
242 :group 'gnus-article-emphasis)
244 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
245 "Format for display of Date headers in article bodies.
246 See `format-time-zone' for the possible values."
248 :link '(custom-manual "(gnus)Article Date")
249 :group 'gnus-article-washing)
252 (autoload 'hexl-hex-string-to-integer "hexl")
253 (autoload 'timezone-make-date-arpa-standard "timezone")
254 (autoload 'mail-extract-address-components "mail-extr"))
256 (defcustom gnus-save-all-headers t
257 "*If non-nil, don't remove any headers before saving."
258 :group 'gnus-article-saving
261 (defcustom gnus-prompt-before-saving 'always
262 "*This variable says how much prompting is to be done when saving articles.
263 If it is nil, no prompting will be done, and the articles will be
264 saved to the default files. If this variable is `always', each and
265 every article that is saved will be preceded by a prompt, even when
266 saving large batches of articles. If this variable is neither nil not
267 `always', there the user will be prompted once for a file name for
268 each invocation of the saving commands."
269 :group 'gnus-article-saving
270 :type '(choice (item always)
271 (item :tag "never" nil)
272 (sexp :tag "once" :format "%t")))
274 (defcustom gnus-saved-headers gnus-visible-headers
275 "Headers to keep if `gnus-save-all-headers' is nil.
276 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
277 If that variable is nil, however, all headers that match this regexp
278 will be kept while the rest will be deleted before saving."
279 :group 'gnus-article-saving
280 :type '(repeat string))
282 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
283 "A function to save articles in your favourite format.
284 The function must be interactively callable (in other words, it must
285 be an Emacs command).
287 Gnus provides the following functions:
289 * gnus-summary-save-in-rmail (Rmail format)
290 * gnus-summary-save-in-mail (Unix mail format)
291 * gnus-summary-save-in-folder (MH folder)
292 * gnus-summary-save-in-file (article format)
293 * gnus-summary-save-in-vm (use VM's folder format)
294 * gnus-summary-write-to-file (article format -- overwrite)."
295 :group 'gnus-article-saving
296 :type '(radio (function-item gnus-summary-save-in-rmail)
297 (function-item gnus-summary-save-in-mail)
298 (function-item gnus-summary-save-in-folder)
299 (function-item gnus-summary-save-in-file)
300 (function-item gnus-summary-save-in-vm)
301 (function-item gnus-summary-write-to-file)))
303 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
304 "A function generating a file name to save articles in Rmail format.
305 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
306 :group 'gnus-article-saving
309 (defcustom gnus-mail-save-name 'gnus-plain-save-name
310 "A function generating a file name to save articles in Unix mail format.
311 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
312 :group 'gnus-article-saving
315 (defcustom gnus-folder-save-name 'gnus-folder-save-name
316 "A function generating a file name to save articles in MH folder.
317 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
318 :group 'gnus-article-saving
321 (defcustom gnus-file-save-name 'gnus-numeric-save-name
322 "A function generating a file name to save articles in article format.
323 The function is called with NEWSGROUP, HEADERS, and optional
325 :group 'gnus-article-saving
328 (defcustom gnus-split-methods
329 '((gnus-article-archive-name)
330 (gnus-article-nndoc-name))
331 "Variable used to suggest where articles are to be saved.
332 For instance, if you would like to save articles related to Gnus in
333 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
334 you could set this variable to something like:
336 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
337 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
339 This variable is an alist where the where the key is the match and the
340 value is a list of possible files to save in if the match is non-nil.
342 If the match is a string, it is used as a regexp match on the
343 article. If the match is a symbol, that symbol will be funcalled
344 from the buffer of the article to be saved with the newsgroup as the
345 parameter. If it is a list, it will be evaled in the same buffer.
347 If this form or function returns a string, this string will be used as
348 a possible file name; and if it returns a non-nil list, that list will
349 be used as possible file names."
350 :group 'gnus-article-saving
351 :type '(repeat (choice (list function)
352 (cons regexp (repeat string))
355 (defcustom gnus-strict-mime t
356 "*If nil, MIME-decode even if there is no Mime-Version header."
357 :group 'gnus-article-mime
360 (defcustom gnus-show-mime-method 'metamail-buffer
361 "Function to process a MIME message.
362 The function is called from the article buffer."
363 :group 'gnus-article-mime
366 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
367 "*Function to decode MIME encoded words.
368 The function is called from the article buffer."
369 :group 'gnus-article-mime
372 (defcustom gnus-page-delimiter "^\^L"
373 "*Regexp describing what to use as article page delimiters.
374 The default value is \"^\^L\", which is a form linefeed at the
375 beginning of a line."
377 :group 'gnus-article-various)
379 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
380 "*The format specification for the article mode line.
381 See `gnus-summary-mode-line-format' for a closer description."
383 :group 'gnus-article-various)
385 (defcustom gnus-article-mode-hook nil
386 "*A hook for Gnus article mode."
388 :group 'gnus-article-various)
390 (defcustom gnus-article-menu-hook nil
391 "*Hook run after the creation of the article mode menu."
393 :group 'gnus-article-various)
395 (defcustom gnus-article-prepare-hook nil
396 "*A hook called after an article has been prepared in the article buffer.
397 If you want to run a special decoding program like nkf, use this hook."
399 :group 'gnus-article-various)
401 (defcustom gnus-article-hide-pgp-hook nil
402 "*A hook called after successfully hiding a PGP signature."
404 :group 'gnus-article-various)
406 (defcustom gnus-article-button-face 'bold
407 "Face used for highlighting buttons in the article buffer.
409 An article button is a piece of text that you can activate by pressing
410 `RET' or `mouse-2' above it."
412 :group 'gnus-article-buttons)
414 (defcustom gnus-article-mouse-face 'highlight
415 "Face used for mouse highlighting in the article buffer.
417 Article buttons will be displayed in this face when the cursor is
420 :group 'gnus-article-buttons)
422 (defcustom gnus-signature-face 'gnus-signature-face
423 "Face used for highlighting a signature in the article buffer.
424 Obsolete; use the face `gnus-signature-face' for customizations instead."
426 :group 'gnus-article-highlight
427 :group 'gnus-article-signature)
429 (defface gnus-signature-face
432 "Face used for highlighting a signature in the article buffer."
433 :group 'gnus-article-highlight
434 :group 'gnus-article-signature)
436 (defface gnus-header-from-face
439 (:foreground "spring green" :bold t))
442 (:foreground "red3" :bold t))
444 (:bold t :italic t)))
445 "Face used for displaying from headers."
446 :group 'gnus-article-headers
447 :group 'gnus-article-highlight)
449 (defface gnus-header-subject-face
452 (:foreground "SeaGreen3" :bold t))
455 (:foreground "red4" :bold t))
457 (:bold t :italic t)))
458 "Face used for displaying subject headers."
459 :group 'gnus-article-headers
460 :group 'gnus-article-highlight)
462 (defface gnus-header-newsgroups-face
465 (:foreground "yellow" :bold t :italic t))
468 (:foreground "MidnightBlue" :bold t :italic t))
470 (:bold t :italic t)))
471 "Face used for displaying newsgroups headers."
472 :group 'gnus-article-headers
473 :group 'gnus-article-highlight)
475 (defface gnus-header-name-face
478 (:foreground "SeaGreen"))
481 (:foreground "maroon"))
484 "Face used for displaying header names."
485 :group 'gnus-article-headers
486 :group 'gnus-article-highlight)
488 (defface gnus-header-content-face
491 (:foreground "forest green" :italic t))
494 (:foreground "indianred4" :italic t))
496 (:italic t))) "Face used for displaying header content."
497 :group 'gnus-article-headers
498 :group 'gnus-article-highlight)
500 (defcustom gnus-header-face-alist
501 '(("From" nil gnus-header-from-face)
502 ("Subject" nil gnus-header-subject-face)
503 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
504 ("" gnus-header-name-face gnus-header-content-face))
505 "Controls highlighting of article header.
507 An alist of the form (HEADER NAME CONTENT).
509 HEADER is a regular expression which should match the name of an
510 header header and NAME and CONTENT are either face names or nil.
512 The name of each header field will be displayed using the face
513 specified by the first element in the list where HEADER match the
514 header name and NAME is non-nil. Similarly, the content will be
515 displayed by the first non-nil matching CONTENT face."
516 :group 'gnus-article-headers
517 :group 'gnus-article-highlight
518 :type '(repeat (list (regexp :tag "Header")
520 (item :tag "skip" nil)
521 (face :value default))
522 (choice :tag "Content"
523 (item :tag "skip" nil)
524 (face :value default)))))
526 ;;; Internal variables
528 (defvar gnus-article-mode-syntax-table
529 (let ((table (copy-syntax-table text-mode-syntax-table)))
530 (modify-syntax-entry ?- "w" table)
531 (modify-syntax-entry ?> ")" table)
532 (modify-syntax-entry ?< "(" table)
534 "Syntax table used in article mode buffers.
535 Initialized from `text-mode-syntax-table.")
537 (defvar gnus-save-article-buffer nil)
539 (defvar gnus-article-mode-line-format-alist
540 (nconc '((?w (gnus-article-wash-status) ?s))
541 gnus-summary-mode-line-format-alist))
543 (defvar gnus-number-of-articles-to-be-saved nil)
545 (defvar gnus-inhibit-hiding nil)
547 (defsubst gnus-article-hide-text (b e props)
548 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
549 (add-text-properties b e props)
550 (when (memq 'intangible props)
552 (max (1- b) (point-min))
553 b 'intangible (cddr (memq 'intangible props)))))
555 (defsubst gnus-article-unhide-text (b e)
556 "Remove hidden text properties from region between B and E."
557 (remove-text-properties b e gnus-hidden-properties)
558 (when (memq 'intangible gnus-hidden-properties)
559 (put-text-property (max (1- b) (point-min))
562 (defun gnus-article-hide-text-type (b e type)
563 "Hide text of TYPE between B and E."
564 (gnus-article-hide-text
565 b e (cons 'article-type (cons type gnus-hidden-properties))))
567 (defun gnus-article-unhide-text-type (b e type)
568 "Hide text of TYPE between B and E."
569 (remove-text-properties
570 b e (cons 'article-type (cons type gnus-hidden-properties)))
571 (when (memq 'intangible gnus-hidden-properties)
572 (put-text-property (max (1- b) (point-min))
575 (defun gnus-article-hide-text-of-type (type)
576 "Hide text of TYPE in the current buffer."
578 (let ((b (point-min))
580 (while (setq b (text-property-any b e 'article-type type))
581 (add-text-properties b (incf b) gnus-hidden-properties)))))
583 (defun gnus-article-delete-text-of-type (type)
584 "Delete text of TYPE in the current buffer."
586 (let ((b (point-min)))
587 (while (setq b (text-property-any b (point-max) 'article-type type))
589 b (or (text-property-not-all b (point-max) 'article-type type)
592 (defun gnus-article-delete-invisible-text ()
593 "Delete all invisible text in the current buffer."
595 (let ((b (point-min)))
596 (while (setq b (text-property-any b (point-max) 'invisible t))
598 b (or (text-property-not-all b (point-max) 'invisible t)
601 (defun gnus-article-text-type-exists-p (type)
602 "Say whether any text of type TYPE exists in the buffer."
603 (text-property-any (point-min) (point-max) 'article-type type))
605 (defsubst gnus-article-header-rank ()
606 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
607 (let ((list gnus-sorted-header-list)
610 (when (looking-at (car list))
612 (setq list (cdr list))
616 (defun article-hide-headers (&optional arg delete)
617 "Toggle whether to hide unwanted headers and possibly sort them as well.
618 If given a negative prefix, always show; if given a positive prefix,
620 (interactive (gnus-article-hidden-arg))
621 (if (gnus-article-check-hidden-text 'headers arg)
622 ;; Show boring headers as well.
623 (gnus-article-show-hidden-text 'boring-headers)
624 ;; This function might be inhibited.
625 (unless gnus-inhibit-hiding
628 (let ((buffer-read-only nil)
629 (props (nconc (list 'article-type 'headers)
630 gnus-hidden-properties))
631 (max (1+ (length gnus-sorted-header-list)))
632 (ignored (when (not gnus-visible-headers)
633 (cond ((stringp gnus-ignored-headers)
634 gnus-ignored-headers)
635 ((listp gnus-ignored-headers)
636 (mapconcat 'identity gnus-ignored-headers
639 (cond ((stringp gnus-visible-headers)
640 gnus-visible-headers)
641 ((and gnus-visible-headers
642 (listp gnus-visible-headers))
643 (mapconcat 'identity gnus-visible-headers "\\|"))))
644 (inhibit-point-motion-hooks t)
646 ;; First we narrow to just the headers.
648 (goto-char (point-min))
649 ;; Hide any "From " lines at the beginning of (mail) articles.
650 (while (looking-at "From ")
654 (delete-region (point-min) (point))
655 (gnus-article-hide-text (point-min) (point) props)))
656 ;; Then treat the rest of the header lines.
659 (if (search-forward "\n\n" nil t) ; if there's a body
660 (progn (forward-line -1) (point))
662 ;; Then we use the two regular expressions
663 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
664 ;; select which header lines is to remain visible in the
666 (goto-char (point-min))
667 (while (re-search-forward "^[^ \t]*:" nil t)
669 ;; Mark the rank of the header.
671 (point) (1+ (point)) 'message-rank
672 (if (or (and visible (looking-at visible))
674 (not (looking-at ignored))))
675 (gnus-article-header-rank)
678 (message-sort-headers-1)
679 (when (setq beg (text-property-any
680 (point-min) (point-max) 'message-rank (+ 2 max)))
681 ;; We make the unwanted headers invisible.
683 (delete-region beg (point-max))
684 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
685 (gnus-article-hide-text-type beg (point-max) 'headers))
686 ;; Work around XEmacs lossage.
687 (put-text-property (point-min) beg 'invisible nil))))))))
689 (defun article-hide-boring-headers (&optional arg)
690 "Toggle hiding of headers that aren't very interesting.
691 If given a negative prefix, always show; if given a positive prefix,
693 (interactive (gnus-article-hidden-arg))
694 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
695 (not gnus-show-all-headers))
698 (let ((buffer-read-only nil)
699 (list gnus-boring-article-headers)
700 (inhibit-point-motion-hooks t)
702 (nnheader-narrow-to-headers)
704 (setq elem (pop list))
705 (goto-char (point-min))
707 ;; Hide empty headers.
709 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
711 (gnus-article-hide-text-type
712 (progn (beginning-of-line) (point))
715 (if (re-search-forward "^[^ \t]" nil t)
719 ;; Hide boring Newsgroups header.
720 ((eq elem 'newsgroups)
721 (when (equal (gnus-fetch-field "newsgroups")
722 (gnus-group-real-name
723 (if (boundp 'gnus-newsgroup-name)
726 (gnus-article-hide-header "newsgroups")))
727 ((eq elem 'followup-to)
728 (when (equal (message-fetch-field "followup-to")
729 (message-fetch-field "newsgroups"))
730 (gnus-article-hide-header "followup-to")))
732 (let ((from (message-fetch-field "from"))
733 (reply-to (message-fetch-field "reply-to")))
738 (nth 1 (mail-extract-address-components from))
739 (nth 1 (mail-extract-address-components reply-to)))))
740 (gnus-article-hide-header "reply-to"))))
742 (let ((date (message-fetch-field "date")))
744 (< (gnus-days-between (current-time-string) date)
746 (gnus-article-hide-header "date"))))
748 (let ((to (message-fetch-field "to")))
749 (when (> (length to) 1024)
750 (gnus-article-hide-header "to")))))))))))
752 (defun gnus-article-hide-header (header)
754 (goto-char (point-min))
755 (when (re-search-forward (concat "^" header ":") nil t)
756 (gnus-article-hide-text-type
757 (progn (beginning-of-line) (point))
760 (if (re-search-forward "^[^ \t]" nil t)
765 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
766 (defun article-treat-overstrike ()
767 "Translate overstrikes into bold text."
770 (goto-char (point-min))
771 (when (search-forward "\n\n" nil t)
772 (let ((buffer-read-only nil))
773 (while (search-forward "\b" nil t)
774 (let ((next (following-char))
775 (previous (char-after (- (point) 2))))
776 ;; We do the boldification/underlining by hiding the
777 ;; overstrikes and putting the proper text property
781 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
782 (put-text-property (point) (1+ (point)) 'face 'bold))
784 (gnus-article-hide-text-type
785 (1- (point)) (1+ (point)) 'overstrike)
787 (- (point) 2) (1- (point)) 'face 'underline))
789 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
791 (point) (1+ (point)) 'face 'underline)))))))))
793 (defun article-fill ()
794 "Format too long lines."
797 (let ((buffer-read-only nil))
799 (goto-char (point-min))
800 (search-forward "\n\n" nil t)
802 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
803 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
804 (adaptive-fill-mode t))
806 (and (>= (current-column) (min fill-column (window-width)))
807 (/= (preceding-char) ?:)
808 (fill-paragraph nil))
811 (defun article-remove-cr ()
812 "Remove carriage returns from an article."
815 (let ((buffer-read-only nil))
816 (goto-char (point-min))
817 (while (search-forward "\r" nil t)
818 (replace-match "" t t)))))
820 (defun article-remove-trailing-blank-lines ()
821 "Remove all trailing blank lines from the article."
824 (let ((buffer-read-only nil))
825 (goto-char (point-max))
829 (while (and (not (bobp))
830 (looking-at "^[ \t]*$"))
835 (defun article-display-x-face (&optional force)
836 "Look for an X-Face header and display it if present."
837 (interactive (list 'force))
839 ;; Delete the old process, if any.
840 (when (process-status "article-x-face")
841 (delete-process "article-x-face"))
842 (let ((inhibit-point-motion-hooks t)
843 (case-fold-search nil)
846 (nnheader-narrow-to-headers)
847 (setq from (message-fetch-field "from"))
848 (goto-char (point-min))
849 (while (and gnus-article-x-face-command
851 ;; Check whether this face is censored.
852 (not gnus-article-x-face-too-ugly)
853 (and gnus-article-x-face-too-ugly from
854 (not (string-match gnus-article-x-face-too-ugly
856 ;; Has to be present.
857 (re-search-forward "^X-Face: " nil t))
858 ;; We now have the area of the buffer where the X-Face is stored.
861 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
862 ;; We display the face.
863 (if (symbolp gnus-article-x-face-command)
864 ;; The command is a lisp function, so we call it.
865 (if (gnus-functionp gnus-article-x-face-command)
866 (funcall gnus-article-x-face-command beg end)
867 (error "%s is not a function" gnus-article-x-face-command))
868 ;; The command is a string, so we interpret the command
869 ;; as a, well, command, and fork it off.
870 (let ((process-connection-type nil))
871 (process-kill-without-query
873 "article-x-face" nil shell-file-name shell-command-switch
874 gnus-article-x-face-command))
875 (process-send-region "article-x-face" beg end)
876 (process-send-eof "article-x-face"))))))))))
878 (defun gnus-hack-decode-rfc1522 ()
879 "Emergency hack function for avoiding problems when decoding."
880 (let ((buffer-read-only nil))
881 (goto-char (point-min))
882 ;; Remove encoded TABs.
883 (while (search-forward "=09" nil t)
884 (replace-match " " t t))
885 ;; Remove encoded newlines.
886 (goto-char (point-min))
887 (while (search-forward "=10" nil t)
888 (replace-match " " t t))))
890 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
891 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
892 (defun article-decode-rfc1522 ()
893 "Hack to remove QP encoding from headers."
894 (let ((case-fold-search t)
895 (inhibit-point-motion-hooks t)
896 (buffer-read-only nil)
900 (goto-char (point-min))
901 (or (search-forward "\n\n" nil t) (point-max)))
902 (goto-char (point-min))
903 (while (re-search-forward
904 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
905 (setq string (match-string 1))
907 (narrow-to-region (match-beginning 0) (match-end 0))
908 (delete-region (point-min) (point-max))
910 (article-mime-decode-quoted-printable
911 (goto-char (point-min)) (point-max))
912 (subst-char-in-region (point-min) (point-max) ?_ ? )
913 (goto-char (point-max)))
914 (goto-char (point-min))))))
916 (defun article-de-quoted-unreadable (&optional force)
917 "Do a naive translation of a quoted-printable-encoded article.
918 This is in no way, shape or form meant as a replacement for real MIME
919 processing, but is simply a stop-gap measure until MIME support is
921 If FORCE, decode the article whether it is marked as quoted-printable
923 (interactive (list 'force))
925 (let ((case-fold-search t)
926 (buffer-read-only nil)
927 (type (gnus-fetch-field "content-transfer-encoding")))
928 (gnus-article-decode-rfc1522)
930 (and type (string-match "quoted-printable" (downcase type))))
931 (goto-char (point-min))
932 (search-forward "\n\n" nil 'move)
933 (article-mime-decode-quoted-printable (point) (point-max))))))
935 (defun article-mime-decode-quoted-printable-buffer ()
936 "Decode Quoted-Printable in the current buffer."
937 (article-mime-decode-quoted-printable (point-min) (point-max)))
939 (defun article-mime-decode-quoted-printable (from to)
940 "Decode Quoted-Printable in the region between FROM and TO."
943 (while (search-forward "=" to t)
944 (cond ((eq (following-char) ?\n)
947 ((looking-at "[0-9A-F][0-9A-F]")
948 (subst-char-in-region
949 (1- (point)) (point) ?=
950 (hexl-hex-string-to-integer
951 (buffer-substring (point) (+ 2 (point)))))
955 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
957 (defun article-hide-pgp (&optional arg)
958 "Toggle hiding of any PGP headers and signatures in the current article.
959 If given a negative prefix, always show; if given a positive prefix,
961 (interactive (gnus-article-hidden-arg))
962 (unless (gnus-article-check-hidden-text 'pgp arg)
964 (let ((inhibit-point-motion-hooks t)
965 buffer-read-only beg end)
967 (goto-char (point-min))
968 ;; Hide the "header".
969 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
970 (gnus-article-hide-text-type (1+ (match-beginning 0))
973 ;; Hide the actual signature.
974 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
975 (setq end (1+ (match-beginning 0)))
976 (gnus-article-hide-text-type
978 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
980 ;; Perhaps we shouldn't hide to the end of the buffer
981 ;; if there is no end to the signature?
984 ;; Hide "- " PGP quotation markers.
986 (narrow-to-region beg end)
987 (goto-char (point-min))
988 (while (re-search-forward "^- " nil t)
989 (gnus-article-hide-text-type
990 (match-beginning 0) (match-end 0) 'pgp))
992 (run-hooks 'gnus-article-hide-pgp-hook))))))
994 (defun article-hide-pem (&optional arg)
995 "Toggle hiding of any PEM headers and signatures in the current article.
996 If given a negative prefix, always show; if given a positive prefix,
998 (interactive (gnus-article-hidden-arg))
999 (unless (gnus-article-check-hidden-text 'pem arg)
1001 (let (buffer-read-only end)
1003 (goto-char (point-min))
1004 ;; hide the horrendously ugly "header".
1005 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1008 (setq end (1+ (match-beginning 0)))
1009 (gnus-article-hide-text-type
1011 (if (search-forward "\n\n" nil t)
1015 ;; hide the trailer as well
1016 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1019 (gnus-article-hide-text-type
1020 (match-beginning 0) (match-end 0) 'pem))))))
1022 (defun article-hide-signature (&optional arg)
1023 "Hide the signature in the current article.
1024 If given a negative prefix, always show; if given a positive prefix,
1026 (interactive (gnus-article-hidden-arg))
1027 (unless (gnus-article-check-hidden-text 'signature arg)
1030 (let ((buffer-read-only nil))
1031 (when (gnus-article-narrow-to-signature)
1032 (gnus-article-hide-text-type
1033 (point-min) (point-max) 'signature)))))))
1035 (defun article-strip-leading-blank-lines ()
1036 "Remove all blank lines from the beginning of the article."
1039 (let ((inhibit-point-motion-hooks t)
1041 (goto-char (point-min))
1042 (when (search-forward "\n\n" nil t)
1043 (while (and (not (eobp))
1044 (looking-at "[ \t]*$"))
1045 (gnus-delete-line))))))
1047 (defun article-strip-multiple-blank-lines ()
1048 "Replace consecutive blank lines with one empty line."
1051 (let ((inhibit-point-motion-hooks t)
1053 ;; First make all blank lines empty.
1054 (goto-char (point-min))
1055 (search-forward "\n\n" nil t)
1056 (while (re-search-forward "^[ \t]+$" nil t)
1057 (replace-match "" nil t))
1058 ;; Then replace multiple empty lines with a single empty line.
1059 (goto-char (point-min))
1060 (search-forward "\n\n" nil t)
1061 (while (re-search-forward "\n\n\n+" nil t)
1062 (replace-match "\n\n" t t)))))
1064 (defun article-strip-leading-space ()
1065 "Remove all white space from the beginning of the lines in the article."
1068 (let ((inhibit-point-motion-hooks t)
1070 (goto-char (point-min))
1071 (search-forward "\n\n" nil t)
1072 (while (re-search-forward "^[ \t]+" nil t)
1073 (replace-match "" t t)))))
1075 (defun article-strip-blank-lines ()
1076 "Strip leading, trailing and multiple blank lines."
1078 (article-strip-leading-blank-lines)
1079 (article-remove-trailing-blank-lines)
1080 (article-strip-multiple-blank-lines))
1082 (defvar mime::preview/content-list)
1083 (defvar mime::preview-content-info/point-min)
1084 (defun gnus-article-narrow-to-signature ()
1085 "Narrow to the signature; return t if a signature is found, else nil."
1087 (when (and (boundp 'mime::preview/content-list)
1088 mime::preview/content-list)
1089 ;; We have a MIMEish article, so we use the MIME data to narrow.
1090 (let ((pcinfo (car (last mime::preview/content-list))))
1093 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1096 (when (gnus-article-search-signature)
1098 ;; Check whether we have some limits to what we consider
1099 ;; to be a signature.
1100 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1101 (list gnus-signature-limit)))
1103 (while (setq limit (pop limits))
1104 (if (or (and (integerp limit)
1105 (< (- (point-max) (point)) limit))
1107 (< (count-lines (point) (point-max)) limit))
1108 (and (gnus-functionp limit)
1110 (and (stringp limit)
1111 (not (re-search-forward limit nil t))))
1112 () ; This limit did not succeed.
1116 (narrow-to-region (point) (point-max))
1119 (defun gnus-article-search-signature ()
1120 "Search the current buffer for the signature separator.
1121 Put point at the beginning of the signature separator."
1122 (let ((cur (point)))
1123 (goto-char (point-max))
1124 (if (if (stringp gnus-signature-separator)
1125 (re-search-backward gnus-signature-separator nil t)
1126 (let ((seps gnus-signature-separator))
1128 (not (re-search-backward (car seps) nil t)))
1136 (autoload 'w3-display "w3-parse")
1137 (autoload 'w3-do-setup "w3" "" t)
1138 (autoload 'w3-region "w3-display" "" t))
1140 (defun gnus-article-treat-html ()
1143 (let ((cbuf (current-buffer)))
1144 (set-buffer gnus-article-buffer)
1145 (let (buf buffer-read-only b e)
1147 (goto-char (point-min))
1149 (if (search-forward "\n\n" nil t)
1152 (setq e (point-max)))
1153 (nnheader-temp-write nil
1154 (insert-buffer-substring gnus-article-buffer b e)
1156 (save-window-excursion
1157 (w3-region (point-min) (point-max))
1158 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1160 (delete-region (point-min) (point-max))
1163 (goto-char (point-min))
1164 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1165 (set-buffer cbuf))))
1167 (defun gnus-article-hidden-arg ()
1168 "Return the current prefix arg as a number, or 0 if no prefix."
1169 (list (if current-prefix-arg
1170 (prefix-numeric-value current-prefix-arg)
1173 (defun gnus-article-check-hidden-text (type arg)
1174 "Return nil if hiding is necessary.
1175 Arg can be nil or a number. Nil and positive means hide, negative
1176 means show, 0 means toggle."
1180 (let ((hide (gnus-article-hidden-text-p type)))
1186 (gnus-article-show-hidden-text type))
1188 (if (eq hide 'hidden)
1189 (gnus-article-show-hidden-text type)
1192 (defun gnus-article-hidden-text-p (type)
1193 "Say whether the current buffer contains hidden text of type TYPE."
1194 (let ((start (point-min))
1195 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1197 (not (get-text-property pos 'invisible)))
1199 (text-property-any (1+ pos) (point-max) 'article-type type)))
1204 (defun gnus-article-show-hidden-text (type &optional hide)
1205 "Show all hidden text of type TYPE.
1206 If HIDE, hide the text instead."
1208 (let ((buffer-read-only nil)
1209 (inhibit-point-motion-hooks t)
1212 (while (setq beg (text-property-any end (point-max) 'article-type type))
1215 (text-property-not-all beg (point-max) 'article-type type)
1218 (gnus-article-hide-text beg end gnus-hidden-properties)
1219 (gnus-article-unhide-text beg end))
1223 (defconst article-time-units
1224 `((year . ,(* 365.25 24 60 60))
1225 (week . ,(* 7 24 60 60))
1226 (day . ,(* 24 60 60))
1230 "Mapping from time units to seconds.")
1232 (defun article-date-ut (&optional type highlight header)
1233 "Convert DATE date to universal time in the current article.
1234 If TYPE is `local', convert to local time; if it is `lapsed', output
1235 how much time has lapsed since DATE."
1236 (interactive (list 'ut t))
1237 (let* ((header (or header
1238 (mail-header-date gnus-current-headers)
1239 (message-fetch-field "date")
1241 (date (if (vectorp header) (mail-header-date header)
1243 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1244 (inhibit-point-motion-hooks t)
1246 (when (and date (not (string= date "")))
1249 (nnheader-narrow-to-headers)
1250 (let ((buffer-read-only nil))
1251 ;; Delete any old Date headers.
1252 (if (re-search-forward date-regexp nil t)
1254 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1255 eface (get-text-property (1- (gnus-point-at-eol))
1257 (message-remove-header date-regexp t)
1258 (beginning-of-line))
1259 (goto-char (point-max)))
1260 (insert (article-make-date-line date type))
1263 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1264 (put-text-property (match-beginning 1) (match-end 1)
1266 (put-text-property (match-beginning 2) (match-end 2)
1269 (defun article-make-date-line (date type)
1270 "Return a DATE line of TYPE."
1272 ;; Convert to the local timezone. We have to slap a
1273 ;; `condition-case' round the calls to the timezone
1274 ;; functions since they aren't particularly resistant to
1277 (concat "Date: " (condition-case ()
1278 (timezone-make-date-arpa-standard date)
1281 ;; Convert to Universal Time.
1285 (timezone-make-date-arpa-standard date nil "UT")
1288 ;; Get the original date from the article.
1289 ((eq type 'original)
1290 (concat "Date: " date "\n"))
1291 ;; Let the user define the format.
1295 (format-time-string gnus-article-time-format
1298 (timezone-make-date-arpa-standard
1301 ;; Do an X-Sent lapsed format.
1303 ;; If the date is seriously mangled, the timezone functions are
1304 ;; liable to bug out, so we ignore all errors.
1305 (let* ((now (current-time))
1310 (timezone-make-date-arpa-standard
1311 (current-time-string now)
1312 (current-time-zone now) "UT"))
1314 (timezone-make-date-arpa-standard
1316 (real-sec (and real-time
1317 (+ (* (float (car real-time)) 65536)
1319 (sec (and real-time (abs real-sec)))
1323 "X-Sent: Unknown\n")
1329 ;; This is a bit convoluted, but basically we go
1330 ;; through the time units for years, weeks, etc,
1331 ;; and divide things to see whether that results
1332 ;; in positive answers.
1335 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1336 ;; The (remaining) seconds are too few to
1337 ;; be divided into this time unit.
1339 ;; It's big enough, so we output it.
1340 (setq sec (- sec (* num (cdr unit))))
1342 (concat (if prev ", " "") (int-to-string
1344 " " (symbol-name (car unit))
1345 (if (> num 1) "s" ""))
1347 article-time-units "")
1348 ;; If dates are odd, then it might appear like the
1349 ;; article was sent in the future.
1352 " in the future\n"))))))
1354 (error "Unknown conversion type: %s" type))))
1356 (defun article-date-local (&optional highlight)
1357 "Convert the current article date to the local timezone."
1358 (interactive (list t))
1359 (article-date-ut 'local highlight))
1361 (defun article-date-original (&optional highlight)
1362 "Convert the current article date to what it was originally.
1363 This is only useful if you have used some other date conversion
1364 function and want to see what the date was before converting."
1365 (interactive (list t))
1366 (article-date-ut 'original highlight))
1368 (defun article-date-lapsed (&optional highlight)
1369 "Convert the current article date to time lapsed since it was sent."
1370 (interactive (list t))
1371 (article-date-ut 'lapsed highlight))
1373 (defun article-date-user (&optional highlight)
1374 "Convert the current article date to the user-defined format.
1375 This format is defined by the `gnus-article-time-format' variable."
1376 (interactive (list t))
1377 (article-date-ut 'user highlight))
1379 (defun article-show-all ()
1380 "Show all hidden text in the article buffer."
1383 (let ((buffer-read-only nil))
1384 (gnus-article-unhide-text (point-min) (point-max)))))
1386 (defun article-emphasize (&optional arg)
1387 "Emphasize text according to `gnus-emphasis-alist'."
1388 (interactive (gnus-article-hidden-arg))
1389 (unless (gnus-article-check-hidden-text 'emphasis arg)
1391 (let ((alist gnus-emphasis-alist)
1392 (buffer-read-only nil)
1393 (props (append '(article-type emphasis)
1394 gnus-hidden-properties))
1395 regexp elem beg invisible visible face)
1396 (goto-char (point-min))
1397 (search-forward "\n\n" nil t)
1399 (while (setq elem (pop alist))
1401 (setq regexp (car elem)
1402 invisible (nth 1 elem)
1403 visible (nth 2 elem)
1405 (while (re-search-forward regexp nil t)
1406 (when (and (match-beginning visible) (match-beginning invisible))
1407 (gnus-article-hide-text
1408 (match-beginning invisible) (match-end invisible) props)
1409 (gnus-article-unhide-text-type
1410 (match-beginning visible) (match-end visible) 'emphasis)
1411 (gnus-put-text-property-excluding-newlines
1412 (match-beginning visible) (match-end visible) 'face face)
1413 (goto-char (match-end invisible)))))))))
1415 (defvar gnus-summary-article-menu)
1416 (defvar gnus-summary-post-menu)
1418 ;;; Saving functions.
1420 (defun gnus-article-save (save-buffer file &optional num)
1421 "Save the currently selected article."
1422 (unless gnus-save-all-headers
1423 ;; Remove headers according to `gnus-saved-headers'.
1424 (let ((gnus-visible-headers
1425 (or gnus-saved-headers gnus-visible-headers))
1426 (gnus-article-buffer save-buffer))
1427 (gnus-article-hide-headers 1 t)))
1428 (save-window-excursion
1429 (if (not gnus-default-article-saver)
1430 (error "No default saver is defined")
1431 ;; !!! Magic! The saving functions all save
1432 ;; `gnus-original-article-buffer' (or so they think), but we
1433 ;; bind that variable to our save-buffer.
1434 (set-buffer gnus-article-buffer)
1435 (let* ((gnus-save-article-buffer save-buffer)
1438 ((not gnus-prompt-before-saving) 'default)
1439 ((eq gnus-prompt-before-saving 'always) nil)
1441 (gnus-number-of-articles-to-be-saved
1442 (when (eq gnus-prompt-before-saving t)
1444 (set-buffer gnus-summary-buffer)
1445 (funcall gnus-default-article-saver filename)))))
1447 (defun gnus-read-save-file-name (prompt &optional filename
1448 function group headers variable)
1450 (funcall function group headers (symbol-value variable)))
1455 ((eq filename 'default)
1461 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1464 (if (and gnus-number-of-articles-to-be-saved
1465 (> gnus-number-of-articles-to-be-saved 1))
1466 (format "these %d articles"
1467 gnus-number-of-articles-to-be-saved)
1470 ;; Let the split methods have their say.
1472 ;; No split name was found.
1475 (concat prompt " (default "
1476 (file-name-nondirectory default-name) ") ")
1477 (file-name-directory default-name)
1479 ;; A single group name is returned.
1480 ((stringp split-name)
1482 (funcall function split-name headers
1483 (symbol-value variable)))
1485 (concat prompt " (default "
1486 (file-name-nondirectory default-name) ") ")
1487 (file-name-directory default-name)
1489 ;; A single split name was found
1490 ((= 1 (length split-name))
1491 (let* ((name (expand-file-name
1492 (car split-name) gnus-article-save-directory))
1493 (dir (cond ((file-directory-p name)
1494 (file-name-as-directory name))
1495 ((file-exists-p name) name)
1496 (t gnus-article-save-directory))))
1498 (concat prompt " (default " name ") ")
1500 ;; A list of splits was found.
1502 (setq split-name (nreverse split-name))
1504 (let ((file-name-history
1505 (nconc split-name file-name-history)))
1509 (concat prompt " (`M-p' for defaults) ")
1510 gnus-article-save-directory
1512 gnus-article-save-directory)))
1513 (car (push result file-name-history)))))))
1514 ;; Create the directory.
1515 (gnus-make-directory (file-name-directory file))
1516 ;; If we have read a directory, we append the default file name.
1517 (when (file-directory-p file)
1518 (setq file (concat (file-name-as-directory file)
1519 (file-name-nondirectory default-name))))
1520 ;; Possibly translate some characters.
1521 (nnheader-translate-file-chars file)))))
1522 (gnus-make-directory (file-name-directory result))
1523 (set variable result)))
1525 (defun gnus-article-archive-name (group)
1526 "Return the first instance of an \"Archive-name\" in the current buffer."
1527 (let ((case-fold-search t))
1528 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1529 (nnheader-concat gnus-article-save-directory
1530 (match-string 1)))))
1532 (defun gnus-article-nndoc-name (group)
1533 "If GROUP is an nndoc group, return the name of the parent group."
1534 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1535 (gnus-group-get-parameter group 'save-article-group)))
1537 (defun gnus-summary-save-in-rmail (&optional filename)
1538 "Append this article to Rmail file.
1539 Optional argument FILENAME specifies file name.
1540 Directory to save to is default to `gnus-article-save-directory'."
1542 (gnus-set-global-variables)
1543 (setq filename (gnus-read-save-file-name
1544 "Save %s in rmail file:" filename
1545 gnus-rmail-save-name gnus-newsgroup-name
1546 gnus-current-headers 'gnus-newsgroup-last-rmail))
1547 (gnus-eval-in-buffer-window gnus-save-article-buffer
1551 (gnus-output-to-rmail filename)))))
1553 (defun gnus-summary-save-in-mail (&optional filename)
1554 "Append this article to Unix mail file.
1555 Optional argument FILENAME specifies file name.
1556 Directory to save to is default to `gnus-article-save-directory'."
1558 (gnus-set-global-variables)
1559 (setq filename (gnus-read-save-file-name
1560 "Save %s in Unix mail file:" filename
1561 gnus-mail-save-name gnus-newsgroup-name
1562 gnus-current-headers 'gnus-newsgroup-last-mail))
1563 (gnus-eval-in-buffer-window gnus-save-article-buffer
1567 (if (and (file-readable-p filename)
1568 (mail-file-babyl-p filename))
1569 (gnus-output-to-rmail filename t)
1570 (gnus-output-to-mail filename))))))
1572 (defun gnus-summary-save-in-file (&optional filename overwrite)
1573 "Append this article to file.
1574 Optional argument FILENAME specifies file name.
1575 Directory to save to is default to `gnus-article-save-directory'."
1577 (gnus-set-global-variables)
1578 (setq filename (gnus-read-save-file-name
1579 "Save %s in file:" filename
1580 gnus-file-save-name gnus-newsgroup-name
1581 gnus-current-headers 'gnus-newsgroup-last-file))
1582 (gnus-eval-in-buffer-window gnus-save-article-buffer
1586 (when (and overwrite
1587 (file-exists-p filename))
1588 (delete-file filename))
1589 (gnus-output-to-file filename)))))
1591 (defun gnus-summary-write-to-file (&optional filename)
1592 "Write this article to a file.
1593 Optional argument FILENAME specifies file name.
1594 The directory to save in defaults to `gnus-article-save-directory'."
1596 (gnus-summary-save-in-file nil t))
1598 (defun gnus-summary-save-body-in-file (&optional filename)
1599 "Append this article body to a file.
1600 Optional argument FILENAME specifies file name.
1601 The directory to save in defaults to `gnus-article-save-directory'."
1603 (gnus-set-global-variables)
1604 (setq filename (gnus-read-save-file-name
1605 "Save %s body in file:" filename
1606 gnus-file-save-name gnus-newsgroup-name
1607 gnus-current-headers 'gnus-newsgroup-last-file))
1608 (gnus-eval-in-buffer-window gnus-save-article-buffer
1612 (goto-char (point-min))
1613 (when (search-forward "\n\n" nil t)
1614 (narrow-to-region (point) (point-max)))
1615 (gnus-output-to-file filename)))))
1617 (defun gnus-summary-save-in-pipe (&optional command)
1618 "Pipe this article to subprocess."
1620 (gnus-set-global-variables)
1622 (cond ((eq command 'default)
1623 gnus-last-shell-command)
1627 "Shell command on %s: "
1628 (if (and gnus-number-of-articles-to-be-saved
1629 (> gnus-number-of-articles-to-be-saved 1))
1630 (format "these %d articles"
1631 gnus-number-of-articles-to-be-saved)
1633 gnus-last-shell-command))))
1634 (when (string-equal command "")
1635 (setq command gnus-last-shell-command))
1636 (gnus-eval-in-buffer-window gnus-article-buffer
1639 (shell-command-on-region (point-min) (point-max) command nil)))
1640 (setq gnus-last-shell-command command))
1642 ;;; Article file names when saving.
1644 (defun gnus-capitalize-newsgroup (newsgroup)
1645 "Capitalize NEWSGROUP name."
1646 (when (not (zerop (length newsgroup)))
1647 (concat (char-to-string (upcase (aref newsgroup 0)))
1648 (substring newsgroup 1))))
1650 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1651 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1652 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1653 Otherwise, it is like ~/News/news/group/num."
1656 (concat (if (gnus-use-long-file-name 'not-save)
1657 (gnus-capitalize-newsgroup newsgroup)
1658 (gnus-newsgroup-directory-form newsgroup))
1659 "/" (int-to-string (mail-header-number headers)))
1660 gnus-article-save-directory)))
1662 (string-equal (file-name-directory default)
1663 (file-name-directory last-file))
1664 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1666 (or last-file default))))
1668 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1669 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1670 If variable `gnus-use-long-file-name' is non-nil, it is
1671 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1674 (concat (if (gnus-use-long-file-name 'not-save)
1676 (gnus-newsgroup-directory-form newsgroup))
1677 "/" (int-to-string (mail-header-number headers)))
1678 gnus-article-save-directory)))
1680 (string-equal (file-name-directory default)
1681 (file-name-directory last-file))
1682 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1684 (or last-file default))))
1686 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1687 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1688 If variable `gnus-use-long-file-name' is non-nil, it is
1689 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1692 (if (gnus-use-long-file-name 'not-save)
1693 (gnus-capitalize-newsgroup newsgroup)
1694 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1695 gnus-article-save-directory)))
1697 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1698 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1699 If variable `gnus-use-long-file-name' is non-nil, it is
1700 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1703 (if (gnus-use-long-file-name 'not-save)
1705 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1706 gnus-article-save-directory)))
1713 (setq afunc (car func)
1716 gfunc (intern (format "gnus-%s" func))))
1718 (if (not (fboundp afunc))
1720 `(lambda (&optional interactive &rest args)
1721 ,(documentation afunc t)
1722 (interactive (list t))
1724 (set-buffer gnus-article-buffer)
1726 (call-interactively ',afunc)
1727 (apply ',afunc args))))))))
1728 '(article-hide-headers
1729 article-hide-boring-headers
1730 article-treat-overstrike
1731 (article-fill . gnus-article-word-wrap)
1733 article-display-x-face
1734 article-de-quoted-unreadable
1735 article-mime-decode-quoted-printable
1738 article-hide-signature
1739 article-remove-trailing-blank-lines
1740 article-strip-leading-blank-lines
1741 article-strip-multiple-blank-lines
1742 article-strip-leading-space
1743 article-strip-blank-lines
1745 article-date-original
1750 (article-show-all . gnus-article-show-all-headers))))
1753 ;;; Gnus article mode
1756 (put 'gnus-article-mode 'mode-class 'special)
1758 (gnus-define-keys gnus-article-mode-map
1759 " " gnus-article-goto-next-page
1760 "\177" gnus-article-goto-prev-page
1761 [delete] gnus-article-goto-prev-page
1762 "\C-c^" gnus-article-refer-article
1763 "h" gnus-article-show-summary
1764 "s" gnus-article-show-summary
1765 "\C-c\C-m" gnus-article-mail
1766 "?" gnus-article-describe-briefly
1767 gnus-mouse-2 gnus-article-push-button
1768 "\r" gnus-article-press-button
1769 "\t" gnus-article-next-button
1770 "\M-\t" gnus-article-prev-button
1771 "e" gnus-article-edit
1772 "<" beginning-of-buffer
1774 "\C-c\C-i" gnus-info-find-node
1777 "\C-d" gnus-article-read-summary-keys
1778 "\M-*" gnus-article-read-summary-keys
1779 "\M-#" gnus-article-read-summary-keys
1780 "\M-^" gnus-article-read-summary-keys
1781 "\M-g" gnus-article-read-summary-keys)
1783 (substitute-key-definition
1784 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1786 (defun gnus-article-make-menu-bar ()
1787 (gnus-turn-off-edit-menu 'article)
1788 (unless (boundp 'gnus-article-article-menu)
1790 gnus-article-article-menu gnus-article-mode-map ""
1792 ["Scroll forwards" gnus-article-goto-next-page t]
1793 ["Scroll backwards" gnus-article-goto-prev-page t]
1794 ["Show summary" gnus-article-show-summary t]
1795 ["Fetch Message-ID at point" gnus-article-refer-article t]
1796 ["Mail to address at point" gnus-article-mail t]))
1799 gnus-article-treatment-menu gnus-article-mode-map ""
1801 ["Hide headers" gnus-article-hide-headers t]
1802 ["Hide signature" gnus-article-hide-signature t]
1803 ["Hide citation" gnus-article-hide-citation t]
1804 ["Treat overstrike" gnus-article-treat-overstrike t]
1805 ["Remove carriage return" gnus-article-remove-cr t]
1806 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1809 (when (boundp 'gnus-summary-article-menu)
1810 (define-key gnus-article-mode-map [menu-bar commands]
1811 (cons "Commands" gnus-summary-article-menu))))
1813 (when (boundp 'gnus-summary-post-menu)
1814 (define-key gnus-article-mode-map [menu-bar post]
1815 (cons "Post" gnus-summary-post-menu)))
1817 (run-hooks 'gnus-article-menu-hook)))
1819 (defun gnus-article-mode ()
1820 "Major mode for displaying an article.
1822 All normal editing commands are switched off.
1824 The following commands are available in addition to all summary mode
1826 \\<gnus-article-mode-map>
1827 \\[gnus-article-next-page]\t Scroll the article one page forwards
1828 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1829 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1830 \\[gnus-article-show-summary]\t Display the summary buffer
1831 \\[gnus-article-mail]\t Send a reply to the address near point
1832 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1833 \\[gnus-info-find-node]\t Go to the Gnus info node"
1835 (when (gnus-visual-p 'article-menu 'menu)
1836 (gnus-article-make-menu-bar))
1837 (kill-all-local-variables)
1838 (gnus-simplify-mode-line)
1839 (setq mode-name "Article")
1840 (setq major-mode 'gnus-article-mode)
1841 (make-local-variable 'minor-mode-alist)
1842 (unless (assq 'gnus-show-mime minor-mode-alist)
1843 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1844 (use-local-map gnus-article-mode-map)
1845 (gnus-update-format-specifications nil 'article-mode)
1846 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1847 (set (make-local-variable 'gnus-page-broken) nil)
1848 (set (make-local-variable 'gnus-button-marker-list) nil)
1849 (gnus-set-default-directory)
1850 (buffer-disable-undo (current-buffer))
1851 (setq buffer-read-only t)
1852 (set-syntax-table gnus-article-mode-syntax-table)
1853 (run-hooks 'gnus-article-mode-hook))
1855 (defun gnus-article-setup-buffer ()
1856 "Initialize the article buffer."
1857 (let* ((name (if gnus-single-article-buffer "*Article*"
1858 (concat "*Article " gnus-newsgroup-name "*")))
1860 (progn (string-match "\\*Article" name)
1861 (concat " *Original Article"
1862 (substring name (match-end 0))))))
1863 (setq gnus-article-buffer name)
1864 (setq gnus-original-article-buffer original)
1865 ;; This might be a variable local to the summary buffer.
1866 (unless gnus-single-article-buffer
1868 (set-buffer gnus-summary-buffer)
1869 (setq gnus-article-buffer name)
1870 (setq gnus-original-article-buffer original)
1871 (gnus-set-global-variables)))
1872 ;; Init original article buffer.
1874 (set-buffer (get-buffer-create gnus-original-article-buffer))
1875 (buffer-disable-undo (current-buffer))
1876 (setq major-mode 'gnus-original-article-mode)
1877 (gnus-add-current-to-buffer-list)
1878 (make-local-variable 'gnus-original-article))
1879 (if (get-buffer name)
1882 (buffer-disable-undo (current-buffer))
1883 (setq buffer-read-only t)
1884 (gnus-add-current-to-buffer-list)
1885 (unless (eq major-mode 'gnus-article-mode)
1886 (gnus-article-mode))
1889 (set-buffer (get-buffer-create name))
1890 (gnus-add-current-to-buffer-list)
1892 (make-local-variable 'gnus-summary-buffer)
1893 (current-buffer)))))
1895 ;; Set article window start at LINE, where LINE is the number of lines
1896 ;; from the head of the article.
1897 (defun gnus-article-set-window-start (&optional line)
1899 (get-buffer-window gnus-article-buffer t)
1901 (set-buffer gnus-article-buffer)
1902 (goto-char (point-min))
1905 (gnus-message 6 "Moved to bookmark")
1906 (search-forward "\n\n" nil t)
1910 (defun gnus-article-prepare (article &optional all-headers header)
1911 "Prepare ARTICLE in article mode buffer.
1912 ARTICLE should either be an article number or a Message-ID.
1913 If ARTICLE is an id, HEADER should be the article headers.
1914 If ALL-HEADERS is non-nil, no headers are hidden."
1916 ;; Make sure we start in a summary buffer.
1917 (unless (eq major-mode 'gnus-summary-mode)
1918 (set-buffer gnus-summary-buffer))
1919 (setq gnus-summary-buffer (current-buffer))
1920 ;; Make sure the connection to the server is alive.
1921 (unless (gnus-server-opened
1922 (gnus-find-method-for-group gnus-newsgroup-name))
1923 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1924 (gnus-request-group gnus-newsgroup-name t))
1925 (let* ((gnus-article (if header (mail-header-number header) article))
1926 (summary-buffer (current-buffer))
1927 (internal-hook gnus-article-internal-prepare-hook)
1928 (group gnus-newsgroup-name)
1931 (gnus-article-setup-buffer)
1932 (set-buffer gnus-article-buffer)
1933 ;; Deactivate active regions.
1934 (when (and (boundp 'transient-mark-mode)
1935 transient-mark-mode)
1936 (setq mark-active nil))
1937 (if (not (setq result (let ((buffer-read-only nil))
1938 (gnus-request-article-this-buffer
1940 ;; There is no such article.
1942 (when (and (numberp article)
1943 (not (memq article gnus-newsgroup-sparse)))
1944 (setq gnus-article-current
1945 (cons gnus-newsgroup-name article))
1946 (set-buffer gnus-summary-buffer)
1947 (setq gnus-current-article article)
1948 (gnus-summary-mark-article article gnus-canceled-mark))
1949 (unless (memq article gnus-newsgroup-sparse)
1951 1 "No such article (may have expired or been canceled)")))
1952 (if (or (eq result 'pseudo) (eq result 'nneething))
1955 (set-buffer summary-buffer)
1956 (setq gnus-last-article gnus-current-article
1957 gnus-newsgroup-history (cons gnus-current-article
1958 gnus-newsgroup-history)
1959 gnus-current-article 0
1960 gnus-current-headers nil
1961 gnus-article-current nil)
1962 (if (eq result 'nneething)
1963 (gnus-configure-windows 'summary)
1964 (gnus-configure-windows 'article))
1965 (gnus-set-global-variables))
1966 (gnus-set-mode-line 'article))
1967 ;; The result from the `request' was an actual article -
1968 ;; or at least some text that is now displayed in the
1970 (when (and (numberp article)
1971 (not (eq article gnus-current-article)))
1972 ;; Seems like a new article has been selected.
1973 ;; `gnus-current-article' must be an article number.
1975 (set-buffer summary-buffer)
1976 (setq gnus-last-article gnus-current-article
1977 gnus-newsgroup-history (cons gnus-current-article
1978 gnus-newsgroup-history)
1979 gnus-current-article article
1980 gnus-current-headers
1981 (gnus-summary-article-header gnus-current-article)
1982 gnus-article-current
1983 (cons gnus-newsgroup-name gnus-current-article))
1984 (unless (vectorp gnus-current-headers)
1985 (setq gnus-current-headers nil))
1986 (gnus-summary-goto-subject gnus-current-article)
1987 (gnus-summary-show-thread)
1988 (run-hooks 'gnus-mark-article-hook)
1989 (gnus-set-mode-line 'summary)
1990 (when (gnus-visual-p 'article-highlight 'highlight)
1991 (run-hooks 'gnus-visual-mark-article-hook))
1992 ;; Set the global newsgroup variables here.
1993 ;; Suggested by Jim Sisolak
1994 ;; <sisolak@trans4.neep.wisc.edu>.
1995 (gnus-set-global-variables)
1996 (setq gnus-have-all-headers
1997 (or all-headers gnus-show-all-headers))
1999 (vectorp (gnus-summary-article-header article))
2000 (gnus-cache-possibly-enter-article
2002 (gnus-summary-article-header article)
2003 (memq article gnus-newsgroup-marked)
2004 (memq article gnus-newsgroup-dormant)
2005 (memq article gnus-newsgroup-unreads)))))
2006 (when (or (numberp article)
2008 ;; Hooks for getting information from the article.
2009 ;; This hook must be called before being narrowed.
2010 (let (buffer-read-only)
2011 (run-hooks 'internal-hook)
2012 (run-hooks 'gnus-article-prepare-hook)
2013 ;; Decode MIME message.
2014 (when gnus-show-mime
2015 (if (or (not gnus-strict-mime)
2016 (gnus-fetch-field "Mime-Version"))
2017 (funcall gnus-show-mime-method)
2018 (funcall gnus-decode-encoded-word-method)))
2019 ;; Perform the article display hooks.
2020 (run-hooks 'gnus-article-display-hook))
2022 (goto-char (point-min))
2023 (setq gnus-page-broken
2024 (when gnus-break-pages
2025 (gnus-narrow-to-page)
2027 (gnus-set-mode-line 'article)
2028 (gnus-configure-windows 'article)
2029 (goto-char (point-min))
2032 (defun gnus-article-wash-status ()
2033 "Return a string which display status of article washing."
2035 (set-buffer gnus-article-buffer)
2036 (let ((cite (gnus-article-hidden-text-p 'cite))
2037 (headers (gnus-article-hidden-text-p 'headers))
2038 (boring (gnus-article-hidden-text-p 'boring-headers))
2039 (pgp (gnus-article-hidden-text-p 'pgp))
2040 (pem (gnus-article-hidden-text-p 'pem))
2041 (signature (gnus-article-hidden-text-p 'signature))
2042 (overstrike (gnus-article-hidden-text-p 'overstrike))
2043 (emphasis (gnus-article-hidden-text-p 'emphasis))
2044 (mime gnus-show-mime))
2045 (format "%c%c%c%c%c%c%c"
2047 (if (or headers boring) ?h ? )
2048 (if (or pgp pem) ?p ? )
2049 (if signature ?s ? )
2050 (if overstrike ?o ? )
2052 (if emphasis ?e ? )))))
2054 (defun gnus-article-hide-headers-if-wanted ()
2055 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2056 Provided for backwards compatibility."
2057 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2059 (gnus-article-hide-headers)))
2063 (defun gnus-output-to-file (file-name)
2064 "Append the current article to a file named FILE-NAME."
2065 (let ((artbuf (current-buffer)))
2066 (nnheader-temp-write nil
2067 (insert-buffer-substring artbuf)
2068 ;; Append newline at end of the buffer as separator, and then
2070 (goto-char (point-max))
2072 (append-to-file (point-min) (point-max) file-name)
2075 (defun gnus-narrow-to-page (&optional arg)
2076 "Narrow the article buffer to a page.
2077 If given a numerical ARG, move forward ARG pages."
2079 (setq arg (if arg (prefix-numeric-value arg) 0))
2081 (set-buffer gnus-article-buffer)
2082 (goto-char (point-min))
2084 ;; Remove any old next/prev buttons.
2085 (when (gnus-visual-p 'page-marker)
2086 (let ((buffer-read-only nil))
2087 (gnus-remove-text-with-property 'gnus-prev)
2088 (gnus-remove-text-with-property 'gnus-next)))
2091 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2093 (re-search-forward page-delimiter nil 'move arg)))
2094 (goto-char (match-end 0)))
2097 (if (re-search-forward page-delimiter nil 'move)
2100 (when (and (gnus-visual-p 'page-marker)
2101 (not (= (point-min) 1)))
2103 (goto-char (point-min))
2104 (gnus-insert-prev-page-button)))
2105 (when (and (gnus-visual-p 'page-marker)
2106 (< (+ (point-max) 2) (buffer-size)))
2108 (goto-char (point-max))
2109 (gnus-insert-next-page-button)))))
2111 ;; Article mode commands
2113 (defun gnus-article-goto-next-page ()
2114 "Show the next page of the article."
2116 (when (gnus-article-next-page)
2117 (goto-char (point-min))
2118 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2120 (defun gnus-article-goto-prev-page ()
2121 "Show the next page of the article."
2123 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2124 (gnus-article-prev-page nil)))
2126 (defun gnus-article-next-page (&optional lines)
2127 "Show the next page of the current article.
2128 If end of article, return non-nil. Otherwise return nil.
2129 Argument LINES specifies lines to be scrolled up."
2131 (move-to-window-line -1)
2134 (and (pos-visible-in-window-p) ;Not continuation line.
2136 ;; Nothing in this page.
2137 (if (or (not gnus-page-broken)
2140 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2142 (gnus-narrow-to-page 1) ;Go to next page.
2144 ;; More in this page.
2145 (let ((scroll-in-place nil))
2149 ;; Long lines may cause an end-of-buffer error.
2150 (goto-char (point-max)))))
2151 (move-to-window-line 0)
2154 (defun gnus-article-prev-page (&optional lines)
2155 "Show previous page of current article.
2156 Argument LINES specifies lines to be scrolled down."
2158 (move-to-window-line 0)
2159 (if (and gnus-page-broken
2161 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2163 (gnus-narrow-to-page -1) ;Go to previous page.
2164 (goto-char (point-max))
2166 (let ((scroll-in-place nil))
2170 (beginning-of-buffer
2171 (goto-char (point-min))))
2172 (move-to-window-line 0)))))
2174 (defun gnus-article-refer-article ()
2175 "Read article specified by message-id around point."
2177 (let ((point (point)))
2178 (search-forward ">" nil t) ;Move point to end of "<....>".
2179 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2180 (let ((message-id (match-string 1)))
2182 (set-buffer gnus-summary-buffer)
2183 (gnus-summary-refer-article message-id))
2185 (error "No references around point"))))
2187 (defun gnus-article-show-summary ()
2188 "Reconfigure windows to show summary buffer."
2190 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2191 (error "There is no summary buffer for this article buffer")
2192 (gnus-article-set-globals)
2193 (gnus-configure-windows 'article)
2194 (gnus-summary-goto-subject gnus-current-article)))
2196 (defun gnus-article-describe-briefly ()
2197 "Describe article mode commands briefly."
2200 (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")))
2202 (defun gnus-article-summary-command ()
2203 "Execute the last keystroke in the summary buffer."
2205 (let ((obuf (current-buffer))
2206 (owin (current-window-configuration))
2208 (switch-to-buffer gnus-summary-buffer 'norecord)
2209 (setq func (lookup-key (current-local-map) (this-command-keys)))
2210 (call-interactively func)
2212 (set-window-configuration owin)
2213 (set-window-point (get-buffer-window (current-buffer)) (point))))
2215 (defun gnus-article-summary-command-nosave ()
2216 "Execute the last keystroke in the summary buffer."
2219 (pop-to-buffer gnus-summary-buffer 'norecord)
2220 (setq func (lookup-key (current-local-map) (this-command-keys)))
2221 (call-interactively func)))
2223 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2224 "Read a summary buffer key sequence and execute it from the article buffer."
2227 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2228 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2229 "=" "^" "\M-^" "|"))
2236 (set-buffer gnus-summary-buffer)
2237 (let (gnus-pick-mode)
2238 (push (or key last-command-event) unread-command-events)
2239 (setq keys (read-key-sequence nil))))
2242 (if (or (member keys nosaves)
2243 (member keys nosave-but-article)
2244 (member keys nosave-in-article))
2246 (save-window-excursion
2247 (pop-to-buffer gnus-summary-buffer 'norecord)
2248 ;; We disable the pick minor mode commands.
2249 (let (gnus-pick-mode)
2250 (setq func (lookup-key (current-local-map) keys))))
2253 (unless (member keys nosave-in-article)
2254 (set-buffer gnus-summary-buffer))
2255 (call-interactively func))
2256 (when (member keys nosave-but-article)
2257 (pop-to-buffer gnus-article-buffer 'norecord)))
2258 ;; These commands should restore window configuration.
2259 (let ((obuf (current-buffer))
2260 (owin (current-window-configuration))
2263 (if not-restore-window
2264 (pop-to-buffer gnus-summary-buffer 'norecord)
2265 (switch-to-buffer gnus-summary-buffer 'norecord))
2266 (setq in-buffer (current-buffer))
2267 ;; We disable the pick minor mode commands.
2268 (if (setq func (let (gnus-pick-mode)
2269 (lookup-key (current-local-map) keys)))
2270 (call-interactively func)
2272 (when (eq in-buffer (current-buffer))
2274 (unless not-restore-window
2275 (set-window-configuration owin))
2276 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2278 (defun gnus-article-hide (&optional arg force)
2279 "Hide all the gruft in the current article.
2280 This means that PGP stuff, signatures, cited text and (some)
2281 headers will be hidden.
2282 If given a prefix, show the hidden text instead."
2283 (interactive (list current-prefix-arg 'force))
2284 (gnus-article-hide-headers arg)
2285 (gnus-article-hide-pgp arg)
2286 (gnus-article-hide-citation-maybe arg force)
2287 (gnus-article-hide-signature arg))
2289 (defun gnus-article-maybe-highlight ()
2290 "Do some article highlighting if `article-visual' is non-nil."
2291 (when (gnus-visual-p 'article-highlight 'highlight)
2292 (gnus-article-highlight-some)))
2294 (defun gnus-request-article-this-buffer (article group)
2295 "Get an article and insert it into this buffer."
2296 (let (do-update-line)
2300 (gnus-kill-all-overlays)
2301 (setq group (or group gnus-newsgroup-name))
2303 ;; Open server if it has closed.
2304 (gnus-check-server (gnus-find-method-for-group group))
2306 ;; Using `gnus-request-article' directly will insert the article into
2307 ;; `nntp-server-buffer' - so we'll save some time by not having to
2308 ;; copy it from the server buffer into the article buffer.
2310 ;; We only request an article by message-id when we do not have the
2311 ;; headers for it, so we'll have to get those.
2312 (when (stringp article)
2313 (let ((gnus-override-method gnus-refer-article-method))
2314 (gnus-read-header article)))
2316 ;; If the article number is negative, that means that this article
2317 ;; doesn't belong in this newsgroup (possibly), so we find its
2318 ;; message-id and request it by id instead of number.
2319 (when (and (numberp article)
2321 (get-buffer gnus-summary-buffer)
2322 (buffer-name (get-buffer gnus-summary-buffer)))
2324 (set-buffer gnus-summary-buffer)
2325 (let ((header (gnus-summary-article-header article)))
2328 ((memq article gnus-newsgroup-sparse)
2329 ;; This is a sparse gap article.
2330 (setq do-update-line article)
2331 (setq article (mail-header-id header))
2332 (let ((gnus-override-method gnus-refer-article-method))
2333 (gnus-read-header article))
2334 (setq gnus-newsgroup-sparse
2335 (delq article gnus-newsgroup-sparse)))
2337 ;; It's a real article.
2338 (setq article (mail-header-id header)))
2340 ;; It is an extracted pseudo-article.
2341 (setq article 'pseudo)
2342 (gnus-request-pseudo-article header))))
2344 (let ((method (gnus-find-method-for-group
2345 gnus-newsgroup-name)))
2346 (if (not (eq (car method) 'nneething))
2348 (let ((dir (concat (file-name-as-directory (nth 1 method))
2349 (mail-header-subject header))))
2350 (when (file-directory-p dir)
2351 (setq article 'nneething)
2352 (gnus-group-enter-directory dir))))))))
2355 ;; Refuse to select canceled articles.
2356 ((and (numberp article)
2358 (get-buffer gnus-summary-buffer)
2359 (buffer-name (get-buffer gnus-summary-buffer))
2360 (eq (cdr (save-excursion
2361 (set-buffer gnus-summary-buffer)
2362 (assq article gnus-newsgroup-reads)))
2363 gnus-canceled-mark))
2365 ;; We first check `gnus-original-article-buffer'.
2366 ((and (get-buffer gnus-original-article-buffer)
2369 (set-buffer gnus-original-article-buffer)
2370 (and (equal (car gnus-original-article) group)
2371 (eq (cdr gnus-original-article) article))))
2372 (insert-buffer-substring gnus-original-article-buffer)
2374 ;; Check the backlog.
2375 ((and gnus-keep-backlog
2376 (gnus-backlog-request-article group article (current-buffer)))
2378 ;; Check asynchronous pre-fetch.
2379 ((gnus-async-request-fetched-article group article (current-buffer))
2380 (gnus-async-prefetch-next group article gnus-summary-buffer)
2383 ((and gnus-use-cache
2385 (gnus-cache-request-article article group))
2387 ;; Get the article and put into the article buffer.
2388 ((or (stringp article) (numberp article))
2389 (let ((gnus-override-method
2390 (and (stringp article) gnus-refer-article-method))
2391 (buffer-read-only nil))
2393 (gnus-kill-all-overlays)
2394 (when (gnus-request-article article group (current-buffer))
2395 (when (numberp article)
2396 (gnus-async-prefetch-next group article gnus-summary-buffer)
2397 (when gnus-keep-backlog
2398 (gnus-backlog-enter-article
2399 group article (current-buffer))))
2404 ;; Take the article from the original article buffer
2405 ;; and place it in the buffer it's supposed to be in.
2406 (when (and (get-buffer gnus-article-buffer)
2408 (equal (buffer-name (current-buffer))
2409 (buffer-name (get-buffer gnus-article-buffer))))
2411 (if (get-buffer gnus-original-article-buffer)
2412 (set-buffer (get-buffer gnus-original-article-buffer))
2413 (set-buffer (get-buffer-create gnus-original-article-buffer))
2414 (buffer-disable-undo (current-buffer))
2415 (setq major-mode 'gnus-original-article-mode)
2416 (setq buffer-read-only t)
2417 (gnus-add-current-to-buffer-list))
2418 (let (buffer-read-only)
2420 (insert-buffer-substring gnus-article-buffer))
2421 (setq gnus-original-article (cons group article))))
2423 ;; Update sparse articles.
2424 (when (and do-update-line
2425 (or (numberp article)
2427 (let ((buf (current-buffer)))
2428 (set-buffer gnus-summary-buffer)
2429 (gnus-summary-update-article do-update-line)
2430 (gnus-summary-goto-subject do-update-line nil t)
2431 (set-window-point (get-buffer-window (current-buffer) t)
2433 (set-buffer buf))))))
2439 (defcustom gnus-article-edit-mode-hook nil
2440 "Hook run in article edit mode buffers."
2441 :group 'gnus-article-various
2444 (defvar gnus-article-edit-done-function nil)
2446 (defvar gnus-article-edit-mode-map nil)
2448 (unless gnus-article-edit-mode-map
2449 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2451 (gnus-define-keys gnus-article-edit-mode-map
2452 "\C-c\C-c" gnus-article-edit-done
2453 "\C-c\C-k" gnus-article-edit-exit)
2455 (gnus-define-keys (gnus-article-edit-wash-map
2456 "\C-c\C-w" gnus-article-edit-mode-map)
2457 "f" gnus-article-edit-full-stops))
2459 (defun gnus-article-edit-mode ()
2460 "Major mode for editing articles.
2461 This is an extended text-mode.
2463 \\{gnus-article-edit-mode-map}"
2465 (kill-all-local-variables)
2466 (setq major-mode 'gnus-article-edit-mode)
2467 (setq mode-name "Article Edit")
2468 (use-local-map gnus-article-edit-mode-map)
2469 (make-local-variable 'gnus-article-edit-done-function)
2470 (make-local-variable 'gnus-prev-winconf)
2471 (setq buffer-read-only nil)
2472 (buffer-enable-undo)
2474 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2476 (defun gnus-article-edit (&optional force)
2477 "Edit the current article.
2478 This will have permanent effect only in mail groups.
2479 If FORCE is non-nil, allow editing of articles even in read-only
2482 (when (and (not force)
2483 (gnus-group-read-only-p))
2484 (error "The current newsgroup does not support article editing"))
2485 (gnus-article-edit-article
2486 `(lambda (no-highlight)
2487 (gnus-summary-edit-article-done
2488 ,(or (mail-header-references gnus-current-headers) "")
2489 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2491 (defun gnus-article-edit-article (exit-func)
2492 "Start editing the contents of the current article buffer."
2493 (let ((winconf (current-window-configuration)))
2494 (set-buffer gnus-article-buffer)
2495 (gnus-article-edit-mode)
2496 (gnus-set-text-properties (point-min) (point-max) nil)
2497 (gnus-configure-windows 'edit-article)
2498 (setq gnus-article-edit-done-function exit-func)
2499 (setq gnus-prev-winconf winconf)
2500 (gnus-message 6 "C-c C-c to end edits")))
2502 (defun gnus-article-edit-done (&optional arg)
2503 "Update the article edits and exit."
2505 (let ((func gnus-article-edit-done-function)
2506 (buf (current-buffer))
2507 (start (window-start)))
2508 (gnus-article-edit-exit)
2511 (let ((buffer-read-only nil))
2512 (funcall func arg)))
2514 (set-window-start (get-buffer-window buf) start)
2515 (set-window-point (get-buffer-window buf) (point))))
2517 (defun gnus-article-edit-exit ()
2518 "Exit the article editing without updating."
2520 ;; We remove all text props from the article buffer.
2521 (let ((buf (format "%s" (buffer-string)))
2522 (curbuf (current-buffer))
2524 (window-start (window-start)))
2527 (let ((winconf gnus-prev-winconf))
2529 ;; The cache and backlog have to be flushed somewhat.
2530 (when gnus-use-cache
2531 (gnus-cache-update-article
2532 (car gnus-article-current) (cdr gnus-article-current)))
2533 (when gnus-keep-backlog
2534 (gnus-backlog-remove-article
2535 (car gnus-article-current) (cdr gnus-article-current)))
2536 ;; Flush original article as well.
2538 (when (get-buffer gnus-original-article-buffer)
2539 (set-buffer gnus-original-article-buffer)
2540 (setq gnus-original-article nil)))
2541 (set-window-configuration winconf)
2542 ;; Tippy-toe some to make sure that point remains where it was.
2543 (let ((buf (current-buffer)))
2545 (set-window-start (get-buffer-window (current-buffer)) window-start)
2547 (set-buffer buf)))))
2549 (defun gnus-article-edit-full-stops ()
2550 "Interactively repair spacing at end of sentences."
2553 (goto-char (point-min))
2554 (search-forward-regexp "^$" nil t)
2555 (let ((case-fold-search nil))
2556 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2559 ;;; Article highlights
2562 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2564 ;;; Internal Variables:
2566 (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\\)"
2567 "Regular expression that matches URLs."
2568 :group 'gnus-article-buttons
2571 (defcustom gnus-button-alist
2572 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2573 gnus-button-message-id 2)
2574 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2575 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2576 gnus-button-fetch-group 4)
2577 ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2578 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2579 t gnus-button-message-id 3)
2580 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2581 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2582 ;; This is how URLs _should_ be embedded in text...
2583 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2585 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2586 "Alist of regexps matching buttons in article bodies.
2588 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2589 REGEXP: is the string matching text around the button,
2590 BUTTON: is the number of the regexp grouping actually matching the button,
2591 FORM: is a lisp expression which must eval to true for the button to
2593 CALLBACK: is the function to call when the user push this button, and each
2594 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2596 CALLBACK can also be a variable, in that case the value of that
2597 variable it the real callback function."
2598 :group 'gnus-article-buttons
2599 :type '(repeat (list regexp
2600 (integer :tag "Button")
2602 (function :tag "Callback")
2605 (integer :tag "Regexp group")))))
2607 (defcustom gnus-header-button-alist
2608 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2609 0 t gnus-button-message-id 0)
2610 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2611 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2612 0 t gnus-button-mailto 0)
2613 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2614 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2615 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2616 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2617 gnus-button-message-id 3))
2618 "Alist of headers and regexps to match buttons in article heads.
2620 This alist is very similar to `gnus-button-alist', except that each
2621 alist has an additional HEADER element first in each entry:
2623 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2625 HEADER is a regexp to match a header. For a fuller explanation, see
2626 `gnus-button-alist'."
2627 :group 'gnus-article-buttons
2628 :group 'gnus-article-headers
2629 :type '(repeat (list (regexp :tag "Header")
2631 (integer :tag "Button")
2633 (function :tag "Callback")
2636 (integer :tag "Regexp group")))))
2638 (defvar gnus-button-regexp nil)
2639 (defvar gnus-button-marker-list nil)
2640 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2642 (defvar gnus-button-last nil)
2643 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2647 (defun gnus-article-push-button (event)
2648 "Check text under the mouse pointer for a callback function.
2649 If the text under the mouse pointer has a `gnus-callback' property,
2650 call it with the value of the `gnus-data' text property."
2652 (set-buffer (window-buffer (posn-window (event-start event))))
2653 (let* ((pos (posn-point (event-start event)))
2654 (data (get-text-property pos 'gnus-data))
2655 (fun (get-text-property pos 'gnus-callback)))
2657 (funcall fun data))))
2659 (defun gnus-article-press-button ()
2660 "Check text at point for a callback function.
2661 If the text at point has a `gnus-callback' property,
2662 call it with the value of the `gnus-data' text property."
2664 (let* ((data (get-text-property (point) 'gnus-data))
2665 (fun (get-text-property (point) 'gnus-callback)))
2667 (funcall fun data))))
2669 (defun gnus-article-prev-button (n)
2670 "Move point to N buttons backward.
2671 If N is negative, move forward instead."
2673 (gnus-article-next-button (- n)))
2675 (defun gnus-article-next-button (n)
2676 "Move point to N buttons forward.
2677 If N is negative, move backward instead."
2679 (let ((function (if (< n 0) 'previous-single-property-change
2680 'next-single-property-change))
2681 (inhibit-point-motion-hooks t)
2683 (limit (if (< n 0) (point-min) (point-max))))
2685 (while (and (not (= limit (point)))
2687 ;; Skip past the current button.
2688 (when (get-text-property (point) 'gnus-callback)
2689 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2690 ;; Go to the next (or previous) button.
2691 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2692 ;; Put point at the start of the button.
2693 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2694 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2695 ;; Skip past intangible buttons.
2696 (when (get-text-property (point) 'intangible)
2700 (gnus-message 5 "No more buttons"))
2703 (defun gnus-article-highlight (&optional force)
2704 "Highlight current article.
2705 This function calls `gnus-article-highlight-headers',
2706 `gnus-article-highlight-citation',
2707 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2708 do the highlighting. See the documentation for those functions."
2709 (interactive (list 'force))
2710 (gnus-article-highlight-headers)
2711 (gnus-article-highlight-citation force)
2712 (gnus-article-highlight-signature)
2713 (gnus-article-add-buttons force)
2714 (gnus-article-add-buttons-to-head))
2716 (defun gnus-article-highlight-some (&optional force)
2717 "Highlight current article.
2718 This function calls `gnus-article-highlight-headers',
2719 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2720 do the highlighting. See the documentation for those functions."
2721 (interactive (list 'force))
2722 (gnus-article-highlight-headers)
2723 (gnus-article-highlight-signature)
2724 (gnus-article-add-buttons))
2726 (defun gnus-article-highlight-headers ()
2727 "Highlight article headers as specified by `gnus-header-face-alist'."
2730 (set-buffer gnus-article-buffer)
2732 (let ((alist gnus-header-face-alist)
2733 (buffer-read-only nil)
2734 (case-fold-search t)
2735 (inhibit-point-motion-hooks t)
2736 entry regexp header-face field-face from hpoints fpoints)
2737 (message-narrow-to-head)
2738 (while (setq entry (pop alist))
2739 (goto-char (point-min))
2740 (setq regexp (concat "^\\("
2741 (if (string-equal "" (nth 0 entry))
2745 header-face (nth 1 entry)
2746 field-face (nth 2 entry))
2747 (while (and (re-search-forward regexp nil t)
2751 (unless (search-forward ":" nil t)
2753 (when (and header-face
2754 (not (memq (point) hpoints)))
2755 (push (point) hpoints)
2756 (gnus-put-text-property from (point) 'face header-face))
2757 (when (and field-face
2758 (not (memq (setq from (point)) fpoints)))
2760 (if (re-search-forward "^[^ \t]" nil t)
2762 (goto-char (point-max)))
2763 (gnus-put-text-property from (point) 'face field-face))))))))
2765 (defun gnus-article-highlight-signature ()
2766 "Highlight the signature in an article.
2767 It does this by highlighting everything after
2768 `gnus-signature-separator' using `gnus-signature-face'."
2771 (set-buffer gnus-article-buffer)
2772 (let ((buffer-read-only nil)
2773 (inhibit-point-motion-hooks t))
2775 (when (and gnus-signature-face
2776 (gnus-article-narrow-to-signature))
2777 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2778 'face gnus-signature-face)
2780 (gnus-article-search-signature)
2781 (let ((start (match-beginning 0))
2782 (end (set-marker (make-marker) (1+ (match-end 0)))))
2783 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2786 (defun gnus-button-in-region-p (b e prop)
2787 "Say whether PROP exists in the region."
2788 (text-property-not-all b e prop nil))
2790 (defun gnus-article-add-buttons (&optional force)
2791 "Find external references in the article and make buttons of them.
2792 \"External references\" are things like Message-IDs and URLs, as
2793 specified by `gnus-button-alist'."
2794 (interactive (list 'force))
2796 (set-buffer gnus-article-buffer)
2797 (let ((buffer-read-only nil)
2798 (inhibit-point-motion-hooks t)
2799 (case-fold-search t)
2800 (alist gnus-button-alist)
2802 ;; Remove all old markers.
2804 (while (setq marker (pop gnus-button-marker-list))
2806 (when (setq entry (gnus-button-entry))
2807 (put-text-property (match-beginning (nth 1 entry))
2808 (match-end (nth 1 entry))
2809 'gnus-callback nil))
2810 (set-marker marker nil)))
2811 ;; We skip the headers.
2812 (goto-char (point-min))
2813 (unless (search-forward "\n\n" nil t)
2814 (goto-char (point-max)))
2816 (while (setq entry (pop alist))
2817 (setq regexp (car entry))
2819 (while (re-search-forward regexp nil t)
2820 (let* ((start (and entry (match-beginning (nth 1 entry))))
2821 (end (and entry (match-end (nth 1 entry))))
2822 (from (match-beginning 0)))
2823 (when (and (or (eq t (nth 2 entry))
2824 (eval (nth 2 entry)))
2825 (not (gnus-button-in-region-p
2826 start end 'gnus-callback)))
2827 ;; That optional form returned non-nil, so we add the
2829 (gnus-article-add-button
2830 start end 'gnus-button-push
2831 (car (push (set-marker (make-marker) from)
2832 gnus-button-marker-list))))))))))
2834 ;; Add buttons to the head of an article.
2835 (defun gnus-article-add-buttons-to-head ()
2836 "Add buttons to the head of the article."
2839 (set-buffer gnus-article-buffer)
2840 (let ((buffer-read-only nil)
2841 (inhibit-point-motion-hooks t)
2842 (case-fold-search t)
2843 (alist gnus-header-button-alist)
2845 (nnheader-narrow-to-headers)
2847 ;; Each alist entry.
2848 (setq entry (car alist)
2850 (goto-char (point-min))
2851 (while (re-search-forward (car entry) nil t)
2852 ;; Each header matching the entry.
2853 (setq beg (match-beginning 0))
2854 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2855 (match-beginning 0))
2858 (while (re-search-forward (nth 1 entry) end t)
2859 ;; Each match within a header.
2860 (let* ((entry (cdr entry))
2861 (start (match-beginning (nth 1 entry)))
2862 (end (match-end (nth 1 entry)))
2863 (form (nth 2 entry)))
2864 (goto-char (match-end 0))
2866 (gnus-article-add-button
2867 start end (nth 3 entry)
2868 (buffer-substring (match-beginning (nth 4 entry))
2869 (match-end (nth 4 entry)))))))
2873 ;;; External functions:
2875 (defun gnus-article-add-button (from to fun &optional data)
2876 "Create a button between FROM and TO with callback FUN and data DATA."
2877 (when gnus-article-button-face
2878 (gnus-overlay-put (gnus-make-overlay from to)
2879 'face gnus-article-button-face))
2880 (gnus-add-text-properties
2882 (nconc (and gnus-article-mouse-face
2883 (list gnus-mouse-face-prop gnus-article-mouse-face))
2884 (list 'gnus-callback fun)
2885 (and data (list 'gnus-data data)))))
2887 ;;; Internal functions:
2889 (defun gnus-article-set-globals ()
2891 (set-buffer gnus-summary-buffer)
2892 (gnus-set-global-variables)))
2894 (defun gnus-signature-toggle (end)
2896 (set-buffer gnus-article-buffer)
2897 (let ((buffer-read-only nil)
2898 (inhibit-point-motion-hooks t))
2899 (if (get-text-property end 'invisible)
2900 (gnus-article-unhide-text end (point-max))
2901 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2903 (defun gnus-button-entry ()
2904 ;; Return the first entry in `gnus-button-alist' matching this place.
2905 (let ((alist gnus-button-alist)
2908 (setq entry (pop alist))
2909 (if (looking-at (car entry))
2914 (defun gnus-button-push (marker)
2915 ;; Push button starting at MARKER.
2917 (set-buffer gnus-article-buffer)
2919 (let* ((entry (gnus-button-entry))
2920 (inhibit-point-motion-hooks t)
2922 (args (mapcar (lambda (group)
2923 (let ((string (match-string group)))
2924 (gnus-set-text-properties
2925 0 (length string) nil string)
2932 (fboundp (symbol-value fun)))
2933 (apply (symbol-value fun) args))
2935 (gnus-message 1 "You must define `%S' to use this button"
2936 (cons fun args)))))))
2938 (defun gnus-button-message-id (message-id)
2941 (set-buffer gnus-summary-buffer)
2942 (gnus-summary-refer-article message-id)))
2944 (defun gnus-button-fetch-group (address)
2945 "Fetch GROUP specified by ADDRESS."
2946 (if (not (string-match "[:/]" address))
2947 ;; This is just a simple group url.
2948 (gnus-group-read-ephemeral-group address gnus-select-method)
2949 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
2951 (error "Can't parse %s" address)
2952 (gnus-group-read-ephemeral-group
2953 (match-string 4 address)
2954 `(nntp ,(match-string 1 address)
2955 (nntp-address ,(match-string 1 address))
2956 (nntp-port-number ,(if (match-end 3)
2957 (match-string 3 address)
2960 (defun gnus-split-string (string pattern)
2961 "Return a list of substrings of STRING which are separated by PATTERN."
2962 (let (parts (start 0))
2963 (while (string-match pattern string start)
2964 (setq parts (cons (substring string start (match-beginning 0)) parts)
2965 start (match-end 0)))
2966 (nreverse (cons (substring string start) parts))))
2968 (defun gnus-url-parse-query-string (query &optional downcase)
2969 (let (retval pairs cur key val)
2970 (setq pairs (gnus-split-string query "&"))
2972 (setq cur (car pairs)
2974 (if (not (string-match "=" cur))
2976 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2977 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2979 (setq key (downcase key)))
2980 (setq cur (assoc key retval))
2982 (setcdr cur (cons val (cdr cur)))
2983 (setq retval (cons (list key val) retval)))))
2986 (defun gnus-url-unhex (x)
2993 (defun gnus-url-unhex-string (str &optional allow-newlines)
2994 "Remove %XXX embedded spaces, etc in a url.
2995 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2996 decoding of carriage returns and line feeds in the string, which is normally
2997 forbidden in URL encoding."
2998 (setq str (or str ""))
3000 (case-fold-search t))
3001 (while (string-match "%[0-9a-f][0-9a-f]" str)
3002 (let* ((start (match-beginning 0))
3003 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3005 (gnus-url-unhex (elt str (+ start 2))))))
3007 tmp (substring str 0 start)
3010 (char-to-string code))
3011 ((or (= code ?\n) (= code ?\r))
3013 (t (char-to-string code))))
3014 str (substring str (match-end 0)))))
3015 (setq tmp (concat tmp str))
3018 (defun gnus-url-mailto (url)
3019 ;; Send mail to someone
3020 (when (string-match "mailto:/*\\(.*\\)" url)
3021 (setq url (substring url (match-beginning 1) nil)))
3022 (let (to args source-url subject func)
3023 (if (string-match (regexp-quote "?") url)
3024 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3025 args (gnus-url-parse-query-string
3026 (substring url (match-end 0) nil) t))
3027 (setq to (gnus-url-unhex-string url)))
3028 (setq args (cons (list "to" to) args)
3029 subject (cdr-safe (assoc "subject" args)))
3032 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3035 (message-position-on-field (caar args)))
3036 (insert (mapconcat 'identity (cdar args) ", "))
3037 (setq args (cdr args)))
3040 (message-goto-subject))))
3042 (defun gnus-button-mailto (address)
3044 (set-buffer (gnus-copy-article-buffer))
3045 (message-reply address))
3047 (defun gnus-button-reply (address)
3048 ;; Reply to ADDRESS.
3049 (message-reply address))
3051 (defun gnus-button-url (address)
3053 (funcall browse-url-browser-function address))
3055 (defun gnus-button-embedded-url (address)
3057 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3059 ;;; Next/prev buttons in the article buffer.
3061 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3062 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3064 (defvar gnus-prev-page-map nil)
3065 (unless gnus-prev-page-map
3066 (setq gnus-prev-page-map (make-sparse-keymap))
3067 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3068 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3070 (defun gnus-insert-prev-page-button ()
3071 (let ((buffer-read-only nil))
3073 gnus-prev-page-line-format nil
3074 `(gnus-prev t local-map ,gnus-prev-page-map
3075 gnus-callback gnus-article-button-prev-page))))
3077 (defvar gnus-next-page-map nil)
3078 (unless gnus-next-page-map
3079 (setq gnus-next-page-map (make-keymap))
3080 (suppress-keymap gnus-prev-page-map)
3081 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3082 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3084 (defun gnus-button-next-page ()
3085 "Go to the next page."
3087 (let ((win (selected-window)))
3088 (select-window (get-buffer-window gnus-article-buffer t))
3089 (gnus-article-next-page)
3090 (select-window win)))
3092 (defun gnus-button-prev-page ()
3093 "Go to the prev page."
3095 (let ((win (selected-window)))
3096 (select-window (get-buffer-window gnus-article-buffer t))
3097 (gnus-article-prev-page)
3098 (select-window win)))
3100 (defun gnus-insert-next-page-button ()
3101 (let ((buffer-read-only nil))
3102 (gnus-eval-format gnus-next-page-line-format nil
3103 `(gnus-next t local-map ,gnus-next-page-map
3105 gnus-article-button-next-page))))
3107 (defun gnus-article-button-next-page (arg)
3108 "Go to the next page."
3110 (let ((win (selected-window)))
3111 (select-window (get-buffer-window gnus-article-buffer t))
3112 (gnus-article-next-page)
3113 (select-window win)))
3115 (defun gnus-article-button-prev-page (arg)
3116 "Go to the prev page."
3118 (let ((win (selected-window)))
3119 (select-window (get-buffer-window gnus-article-buffer t))
3120 (gnus-article-prev-page)
3121 (select-window win)))
3127 (run-hooks 'gnus-art-load-hook)
3129 ;;; gnus-art.el ends here