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 start with 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:\\|X-Sent:"
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', `date', `long-to', and `many-to'."
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 (const :tag "Multiple To headers." many-to))
140 :group 'gnus-article-hiding)
142 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
143 "Regexp matching signature separator.
144 This can also be a list of regexps. In that case, it will be checked
145 from head to tail looking for a separator. Searches will be done from
146 the end of the buffer."
147 :type '(repeat string)
148 :group 'gnus-article-signature)
150 (defcustom gnus-signature-limit nil
151 "Provide a limit to what is considered a signature.
152 If it is a number, no signature may not be longer (in characters) than
153 that number. If it is a floating point number, no signature may be
154 longer (in lines) than that number. If it is a function, the function
155 will be called without any parameters, and if it returns nil, there is
156 no signature in the buffer. If it is a string, it will be used as a
157 regexp. If it matches, the text in question is not a signature."
158 :type '(choice (integer :value 200)
160 (function :value fun)
161 (regexp :value ".*"))
162 :group 'gnus-article-signature)
164 (defcustom gnus-hidden-properties '(invisible t intangible t)
165 "Property list to use for hiding text."
167 :group 'gnus-article-hiding)
169 (defcustom gnus-article-x-face-command
170 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
171 "String or function to be executed to display an X-Face header.
172 If it is a string, the command will be executed in a sub-shell
173 asynchronously. The compressed face will be piped to this command."
174 :type 'string ;Leave function case to Lisp.
175 :group 'gnus-article-washing)
177 (defcustom gnus-article-x-face-too-ugly nil
178 "Regexp matching posters whose face shouldn't be shown automatically."
179 :type '(choice regexp (const nil))
180 :group 'gnus-article-washing)
182 (defcustom gnus-emphasis-alist
184 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
186 '(("_" "_" underline)
189 ("_/" "/_" underline-italic)
190 ("_\\*" "\\*_" underline-bold)
191 ("\\*/" "/\\*" bold-italic)
192 ("_\\*/" "/\\*_" underline-bold-italic))))
193 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
194 2 3 gnus-emphasis-underline)
198 (format format (car spec) (cadr spec))
199 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
201 "Alist that says how to fontify certain phrases.
202 Each item looks like this:
204 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
206 The first element is a regular expression to be matched. The second
207 is a number that says what regular expression grouping used to find
208 the entire emphasized word. The third is a number that says what
209 regexp grouping should be displayed and highlighted. The fourth
210 is the face used for highlighting."
211 :type '(repeat (list :value ("" 0 0 default)
213 (integer :tag "Match group")
214 (integer :tag "Emphasize group")
216 :group 'gnus-article-emphasis)
218 (defface gnus-emphasis-bold '((t (:bold t)))
219 "Face used for displaying strong emphasized text (*word*)."
220 :group 'gnus-article-emphasis)
222 (defface gnus-emphasis-italic '((t (:italic t)))
223 "Face used for displaying italic emphasized text (/word/)."
224 :group 'gnus-article-emphasis)
226 (defface gnus-emphasis-underline '((t (:underline t)))
227 "Face used for displaying underlined emphasized text (_word_)."
228 :group 'gnus-article-emphasis)
230 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
231 "Face used for displaying underlined bold emphasized text (_*word*_)."
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
235 "Face used for displaying underlined italic emphasized text (_*word*_)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
239 "Face used for displaying bold italic emphasized text (/*word*/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline-bold-italic
243 '((t (:bold t :italic t :underline t)))
244 "Face used for displaying underlined bold italic emphasized text.
245 Esample: (_/*word*/_)."
246 :group 'gnus-article-emphasis)
248 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
249 "Format for display of Date headers in article bodies.
250 See `format-time-string' for the possible values."
252 :link '(custom-manual "(gnus)Article Date")
253 :group 'gnus-article-washing)
256 (autoload 'hexl-hex-string-to-integer "hexl")
257 (autoload 'timezone-make-date-arpa-standard "timezone")
258 (autoload 'mail-extract-address-components "mail-extr"))
260 (defcustom gnus-save-all-headers t
261 "*If non-nil, don't remove any headers before saving."
262 :group 'gnus-article-saving
265 (defcustom gnus-prompt-before-saving 'always
266 "*This variable says how much prompting is to be done when saving articles.
267 If it is nil, no prompting will be done, and the articles will be
268 saved to the default files. If this variable is `always', each and
269 every article that is saved will be preceded by a prompt, even when
270 saving large batches of articles. If this variable is neither nil not
271 `always', there the user will be prompted once for a file name for
272 each invocation of the saving commands."
273 :group 'gnus-article-saving
274 :type '(choice (item always)
275 (item :tag "never" nil)
276 (sexp :tag "once" :format "%t\n" :value t)))
278 (defcustom gnus-saved-headers gnus-visible-headers
279 "Headers to keep if `gnus-save-all-headers' is nil.
280 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
281 If that variable is nil, however, all headers that match this regexp
282 will be kept while the rest will be deleted before saving."
283 :group 'gnus-article-saving
286 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
287 "A function to save articles in your favourite format.
288 The function must be interactively callable (in other words, it must
289 be an Emacs command).
291 Gnus provides the following functions:
293 * gnus-summary-save-in-rmail (Rmail format)
294 * gnus-summary-save-in-mail (Unix mail format)
295 * gnus-summary-save-in-folder (MH folder)
296 * gnus-summary-save-in-file (article format)
297 * gnus-summary-save-in-vm (use VM's folder format)
298 * gnus-summary-write-to-file (article format -- overwrite)."
299 :group 'gnus-article-saving
300 :type '(radio (function-item gnus-summary-save-in-rmail)
301 (function-item gnus-summary-save-in-mail)
302 (function-item gnus-summary-save-in-folder)
303 (function-item gnus-summary-save-in-file)
304 (function-item gnus-summary-save-in-vm)
305 (function-item gnus-summary-write-to-file)))
307 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
308 "A function generating a file name to save articles in Rmail format.
309 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
310 :group 'gnus-article-saving
313 (defcustom gnus-mail-save-name 'gnus-plain-save-name
314 "A function generating a file name to save articles in Unix mail format.
315 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
316 :group 'gnus-article-saving
319 (defcustom gnus-folder-save-name 'gnus-folder-save-name
320 "A function generating a file name to save articles in MH folder.
321 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
322 :group 'gnus-article-saving
325 (defcustom gnus-file-save-name 'gnus-numeric-save-name
326 "A function generating a file name to save articles in article format.
327 The function is called with NEWSGROUP, HEADERS, and optional
329 :group 'gnus-article-saving
332 (defcustom gnus-split-methods
333 '((gnus-article-archive-name)
334 (gnus-article-nndoc-name))
335 "Variable used to suggest where articles are to be saved.
336 For instance, if you would like to save articles related to Gnus in
337 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
338 you could set this variable to something like:
340 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
341 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
343 This variable is an alist where the where the key is the match and the
344 value is a list of possible files to save in if the match is non-nil.
346 If the match is a string, it is used as a regexp match on the
347 article. If the match is a symbol, that symbol will be funcalled
348 from the buffer of the article to be saved with the newsgroup as the
349 parameter. If it is a list, it will be evaled in the same buffer.
351 If this form or function returns a string, this string will be used as
352 a possible file name; and if it returns a non-nil list, that list will
353 be used as possible file names."
354 :group 'gnus-article-saving
355 :type '(repeat (choice (list :value (fun) function)
356 (cons :value ("" "") regexp (repeat string))
359 (defcustom gnus-strict-mime t
360 "*If nil, MIME-decode even if there is no Mime-Version header."
361 :group 'gnus-article-mime
364 (defcustom gnus-show-mime-method 'metamail-buffer
365 "Function to process a MIME message.
366 The function is called from the article buffer."
367 :group 'gnus-article-mime
370 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
371 "*Function to decode MIME encoded words.
372 The function is called from the article buffer."
373 :group 'gnus-article-mime
376 (defcustom gnus-page-delimiter "^\^L"
377 "*Regexp describing what to use as article page delimiters.
378 The default value is \"^\^L\", which is a form linefeed at the
379 beginning of a line."
381 :group 'gnus-article-various)
383 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
384 "*The format specification for the article mode line.
385 See `gnus-summary-mode-line-format' for a closer description."
387 :group 'gnus-article-various)
389 (defcustom gnus-article-mode-hook nil
390 "*A hook for Gnus article mode."
392 :group 'gnus-article-various)
394 (defcustom gnus-article-menu-hook nil
395 "*Hook run after the creation of the article mode menu."
397 :group 'gnus-article-various)
399 (defcustom gnus-article-prepare-hook nil
400 "*A hook called after an article has been prepared in the article buffer.
401 If you want to run a special decoding program like nkf, use this hook."
403 :group 'gnus-article-various)
405 (defcustom gnus-article-hide-pgp-hook nil
406 "*A hook called after successfully hiding a PGP signature."
408 :group 'gnus-article-various)
410 (defcustom gnus-article-button-face 'bold
411 "Face used for highlighting buttons in the article buffer.
413 An article button is a piece of text that you can activate by pressing
414 `RET' or `mouse-2' above it."
416 :group 'gnus-article-buttons)
418 (defcustom gnus-article-mouse-face 'highlight
419 "Face used for mouse highlighting in the article buffer.
421 Article buttons will be displayed in this face when the cursor is
424 :group 'gnus-article-buttons)
426 (defcustom gnus-signature-face 'gnus-signature-face
427 "Face used for highlighting a signature in the article buffer.
428 Obsolete; use the face `gnus-signature-face' for customizations instead."
430 :group 'gnus-article-highlight
431 :group 'gnus-article-signature)
433 (defface gnus-signature-face
436 "Face used for highlighting a signature in the article buffer."
437 :group 'gnus-article-highlight
438 :group 'gnus-article-signature)
440 (defface gnus-header-from-face
443 (:foreground "spring green" :bold t))
446 (:foreground "red3" :bold t))
448 (:bold t :italic t)))
449 "Face used for displaying from headers."
450 :group 'gnus-article-headers
451 :group 'gnus-article-highlight)
453 (defface gnus-header-subject-face
456 (:foreground "SeaGreen3" :bold t))
459 (:foreground "red4" :bold t))
461 (:bold t :italic t)))
462 "Face used for displaying subject headers."
463 :group 'gnus-article-headers
464 :group 'gnus-article-highlight)
466 (defface gnus-header-newsgroups-face
469 (:foreground "yellow" :bold t :italic t))
472 (:foreground "MidnightBlue" :bold t :italic t))
474 (:bold t :italic t)))
475 "Face used for displaying newsgroups headers."
476 :group 'gnus-article-headers
477 :group 'gnus-article-highlight)
479 (defface gnus-header-name-face
482 (:foreground "SeaGreen"))
485 (:foreground "maroon"))
488 "Face used for displaying header names."
489 :group 'gnus-article-headers
490 :group 'gnus-article-highlight)
492 (defface gnus-header-content-face
495 (:foreground "forest green" :italic t))
498 (:foreground "indianred4" :italic t))
500 (:italic t))) "Face used for displaying header content."
501 :group 'gnus-article-headers
502 :group 'gnus-article-highlight)
504 (defcustom gnus-header-face-alist
505 '(("From" nil gnus-header-from-face)
506 ("Subject" nil gnus-header-subject-face)
507 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
508 ("" gnus-header-name-face gnus-header-content-face))
509 "Controls highlighting of article header.
511 An alist of the form (HEADER NAME CONTENT).
513 HEADER is a regular expression which should match the name of an
514 header header and NAME and CONTENT are either face names or nil.
516 The name of each header field will be displayed using the face
517 specified by the first element in the list where HEADER match the
518 header name and NAME is non-nil. Similarly, the content will be
519 displayed by the first non-nil matching CONTENT face."
520 :group 'gnus-article-headers
521 :group 'gnus-article-highlight
522 :type '(repeat (list (regexp :tag "Header")
524 (item :tag "skip" nil)
525 (face :value default))
526 (choice :tag "Content"
527 (item :tag "skip" nil)
528 (face :value default)))))
530 ;;; Internal variables
532 (defvar article-lapsed-timer nil)
534 (defvar gnus-article-mode-syntax-table
535 (let ((table (copy-syntax-table text-mode-syntax-table)))
536 (modify-syntax-entry ?- "w" table)
537 (modify-syntax-entry ?> ")" table)
538 (modify-syntax-entry ?< "(" table)
540 "Syntax table used in article mode buffers.
541 Initialized from `text-mode-syntax-table.")
543 (defvar gnus-save-article-buffer nil)
545 (defvar gnus-article-mode-line-format-alist
546 (nconc '((?w (gnus-article-wash-status) ?s))
547 gnus-summary-mode-line-format-alist))
549 (defvar gnus-number-of-articles-to-be-saved nil)
551 (defvar gnus-inhibit-hiding nil)
553 (defsubst gnus-article-hide-text (b e props)
554 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
555 (add-text-properties b e props)
556 (when (memq 'intangible props)
558 (max (1- b) (point-min))
559 b 'intangible (cddr (memq 'intangible props)))))
561 (defsubst gnus-article-unhide-text (b e)
562 "Remove hidden text properties from region between B and E."
563 (remove-text-properties b e gnus-hidden-properties)
564 (when (memq 'intangible gnus-hidden-properties)
565 (put-text-property (max (1- b) (point-min))
568 (defun gnus-article-hide-text-type (b e type)
569 "Hide text of TYPE between B and E."
570 (gnus-article-hide-text
571 b e (cons 'article-type (cons type gnus-hidden-properties))))
573 (defun gnus-article-unhide-text-type (b e type)
574 "Hide text of TYPE between B and E."
575 (remove-text-properties
576 b e (cons 'article-type (cons type gnus-hidden-properties)))
577 (when (memq 'intangible gnus-hidden-properties)
578 (put-text-property (max (1- b) (point-min))
581 (defun gnus-article-hide-text-of-type (type)
582 "Hide text of TYPE in the current buffer."
584 (let ((b (point-min))
586 (while (setq b (text-property-any b e 'article-type type))
587 (add-text-properties b (incf b) gnus-hidden-properties)))))
589 (defun gnus-article-delete-text-of-type (type)
590 "Delete text of TYPE in the current buffer."
592 (let ((b (point-min)))
593 (while (setq b (text-property-any b (point-max) 'article-type type))
595 b (or (text-property-not-all b (point-max) 'article-type type)
598 (defun gnus-article-delete-invisible-text ()
599 "Delete all invisible text in the current buffer."
601 (let ((b (point-min)))
602 (while (setq b (text-property-any b (point-max) 'invisible t))
604 b (or (text-property-not-all b (point-max) 'invisible t)
607 (defun gnus-article-text-type-exists-p (type)
608 "Say whether any text of type TYPE exists in the buffer."
609 (text-property-any (point-min) (point-max) 'article-type type))
611 (defsubst gnus-article-header-rank ()
612 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
613 (let ((list gnus-sorted-header-list)
616 (when (looking-at (car list))
618 (setq list (cdr list))
622 (defun article-hide-headers (&optional arg delete)
623 "Toggle whether to hide unwanted headers and possibly sort them as well.
624 If given a negative prefix, always show; if given a positive prefix,
626 (interactive (gnus-article-hidden-arg))
628 (if (gnus-article-check-hidden-text 'headers arg)
629 ;; Show boring headers as well.
630 (gnus-article-show-hidden-text 'boring-headers)
631 ;; This function might be inhibited.
632 (unless gnus-inhibit-hiding
635 (let ((buffer-read-only nil)
636 (props (nconc (list 'article-type 'headers)
637 gnus-hidden-properties))
638 (max (1+ (length gnus-sorted-header-list)))
639 (ignored (when (not gnus-visible-headers)
640 (cond ((stringp gnus-ignored-headers)
641 gnus-ignored-headers)
642 ((listp gnus-ignored-headers)
643 (mapconcat 'identity gnus-ignored-headers
646 (cond ((stringp gnus-visible-headers)
647 gnus-visible-headers)
648 ((and gnus-visible-headers
649 (listp gnus-visible-headers))
650 (mapconcat 'identity gnus-visible-headers "\\|"))))
651 (inhibit-point-motion-hooks t)
653 ;; First we narrow to just the headers.
655 (goto-char (point-min))
656 ;; Hide any "From " lines at the beginning of (mail) articles.
657 (while (looking-at "From ")
661 (delete-region (point-min) (point))
662 (gnus-article-hide-text (point-min) (point) props)))
663 ;; Then treat the rest of the header lines.
666 (if (search-forward "\n\n" nil t) ; if there's a body
667 (progn (forward-line -1) (point))
669 ;; Then we use the two regular expressions
670 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
671 ;; select which header lines is to remain visible in the
673 (goto-char (point-min))
674 (while (re-search-forward "^[^ \t]*:" nil t)
676 ;; Mark the rank of the header.
678 (point) (1+ (point)) 'message-rank
679 (if (or (and visible (looking-at visible))
681 (not (looking-at ignored))))
682 (gnus-article-header-rank)
685 (message-sort-headers-1)
686 (when (setq beg (text-property-any
687 (point-min) (point-max) 'message-rank (+ 2 max)))
688 ;; We make the unwanted headers invisible.
690 (delete-region beg (point-max))
691 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
692 (gnus-article-hide-text-type beg (point-max) 'headers))
693 ;; Work around XEmacs lossage.
694 (put-text-property (point-min) beg 'invisible nil))))))))
696 (defun article-hide-boring-headers (&optional arg)
697 "Toggle hiding of headers that aren't very interesting.
698 If given a negative prefix, always show; if given a positive prefix,
700 (interactive (gnus-article-hidden-arg))
701 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
702 (not gnus-show-all-headers))
705 (let ((buffer-read-only nil)
706 (list gnus-boring-article-headers)
707 (inhibit-point-motion-hooks t)
709 (nnheader-narrow-to-headers)
711 (setq elem (pop list))
712 (goto-char (point-min))
714 ;; Hide empty headers.
716 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
718 (gnus-article-hide-text-type
719 (progn (beginning-of-line) (point))
722 (if (re-search-forward "^[^ \t]" nil t)
726 ;; Hide boring Newsgroups header.
727 ((eq elem 'newsgroups)
728 (when (equal (gnus-fetch-field "newsgroups")
729 (gnus-group-real-name
730 (if (boundp 'gnus-newsgroup-name)
733 (gnus-article-hide-header "newsgroups")))
734 ((eq elem 'followup-to)
735 (when (equal (message-fetch-field "followup-to")
736 (message-fetch-field "newsgroups"))
737 (gnus-article-hide-header "followup-to")))
739 (let ((from (message-fetch-field "from"))
740 (reply-to (message-fetch-field "reply-to")))
745 (nth 1 (mail-extract-address-components from))
746 (nth 1 (mail-extract-address-components reply-to)))))
747 (gnus-article-hide-header "reply-to"))))
749 (let ((date (message-fetch-field "date")))
751 (< (gnus-days-between (current-time-string) date)
753 (gnus-article-hide-header "date"))))
755 (let ((to (message-fetch-field "to")))
756 (when (> (length to) 1024)
757 (gnus-article-hide-header "to"))))
760 (goto-char (point-min))
761 (while (re-search-forward "^to:" nil t)
762 (setq to-count (1+ to-count)))
764 (while (> to-count 0)
765 (goto-char (point-min))
767 (re-search-forward "^to:" nil nil to-count)
769 (narrow-to-region (point) (point-max))
770 (gnus-article-hide-header "to"))
771 (setq to-count (1- to-count)))))))))))))
773 (defun gnus-article-hide-header (header)
775 (goto-char (point-min))
776 (when (re-search-forward (concat "^" header ":") nil t)
777 (gnus-article-hide-text-type
778 (progn (beginning-of-line) (point))
781 (if (re-search-forward "^[^ \t]" nil t)
786 (defun article-treat-dumbquotes ()
787 "Translate M******** sm*rtq**t*s into proper text."
789 (article-translate-characters "\221\222\223\223" "`'\"\""))
791 (defun article-translate-characters (from to)
792 "Translate all characters in the body of the article according to FROM and TO.
793 FROM is a string of characters to translate from; to is a string of
794 characters to translate to."
796 (goto-char (point-min))
797 (when (search-forward "\n\n" nil t)
798 (let ((buffer-read-only nil)
799 (x (make-string 225 ?x))
801 (while (< (incf i) (length x))
804 (while (< i (length from))
805 (aset x (aref from i) (aref to i))
807 (translate-region (point) (point-max) x)))))
809 (defun article-treat-overstrike ()
810 "Translate overstrikes into bold text."
813 (goto-char (point-min))
814 (when (search-forward "\n\n" nil t)
815 (let ((buffer-read-only nil))
816 (while (search-forward "\b" nil t)
817 (let ((next (following-char))
818 (previous (char-after (- (point) 2))))
819 ;; We do the boldification/underlining by hiding the
820 ;; overstrikes and putting the proper text property
824 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
825 (put-text-property (point) (1+ (point)) 'face 'bold))
827 (gnus-article-hide-text-type
828 (1- (point)) (1+ (point)) 'overstrike)
830 (- (point) 2) (1- (point)) 'face 'underline))
832 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
834 (point) (1+ (point)) 'face 'underline)))))))))
836 (defun article-fill ()
837 "Format too long lines."
840 (let ((buffer-read-only nil))
842 (goto-char (point-min))
843 (search-forward "\n\n" nil t)
845 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
846 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
847 (adaptive-fill-mode t))
849 (and (>= (current-column) (min fill-column (window-width)))
850 (/= (preceding-char) ?:)
851 (fill-paragraph nil))
854 (defun article-remove-cr ()
855 "Remove carriage returns from an article."
858 (let ((buffer-read-only nil))
859 (goto-char (point-min))
860 (while (search-forward "\r" nil t)
861 (replace-match "" t t)))))
863 (defun article-remove-trailing-blank-lines ()
864 "Remove all trailing blank lines from the article."
867 (let ((buffer-read-only nil))
868 (goto-char (point-max))
872 (while (and (not (bobp))
873 (looking-at "^[ \t]*$"))
878 (defun article-display-x-face (&optional force)
879 "Look for an X-Face header and display it if present."
880 (interactive (list 'force))
882 ;; Delete the old process, if any.
883 (when (process-status "article-x-face")
884 (delete-process "article-x-face"))
885 (let ((inhibit-point-motion-hooks t)
889 (nnheader-narrow-to-headers)
890 (setq from (message-fetch-field "from"))
891 (goto-char (point-min))
892 (while (and gnus-article-x-face-command
894 ;; Check whether this face is censored.
895 (not gnus-article-x-face-too-ugly)
896 (and gnus-article-x-face-too-ugly from
897 (not (string-match gnus-article-x-face-too-ugly
899 ;; Has to be present.
900 (re-search-forward "^X-Face: " nil t))
901 ;; We now have the area of the buffer where the X-Face is stored.
904 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
905 ;; We display the face.
906 (if (symbolp gnus-article-x-face-command)
907 ;; The command is a lisp function, so we call it.
908 (if (gnus-functionp gnus-article-x-face-command)
909 (funcall gnus-article-x-face-command beg end)
910 (error "%s is not a function" gnus-article-x-face-command))
911 ;; The command is a string, so we interpret the command
912 ;; as a, well, command, and fork it off.
913 (let ((process-connection-type nil))
914 (process-kill-without-query
916 "article-x-face" nil shell-file-name shell-command-switch
917 gnus-article-x-face-command))
918 (process-send-region "article-x-face" beg end)
919 (process-send-eof "article-x-face"))))))))))
921 (defun gnus-hack-decode-rfc1522 ()
922 "Emergency hack function for avoiding problems when decoding."
923 (let ((buffer-read-only nil))
924 (goto-char (point-min))
925 ;; Remove encoded TABs.
926 (while (search-forward "=09" nil t)
927 (replace-match " " t t))
928 ;; Remove encoded newlines.
929 (goto-char (point-min))
930 (while (search-forward "=10" nil t)
931 (replace-match " " t t))))
933 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
934 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
935 (defun article-decode-rfc1522 ()
936 "Hack to remove QP encoding from headers."
937 (let ((case-fold-search t)
938 (inhibit-point-motion-hooks t)
939 (buffer-read-only nil)
943 (goto-char (point-min))
944 (or (search-forward "\n\n" nil t) (point-max)))
945 (goto-char (point-min))
946 (while (re-search-forward
947 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
948 (setq string (match-string 1))
950 (narrow-to-region (match-beginning 0) (match-end 0))
951 (delete-region (point-min) (point-max))
953 (article-mime-decode-quoted-printable
954 (goto-char (point-min)) (point-max))
955 (subst-char-in-region (point-min) (point-max) ?_ ? )
956 (goto-char (point-max)))
957 (goto-char (point-min))))))
959 (defun article-de-quoted-unreadable (&optional force)
960 "Do a naive translation of a quoted-printable-encoded article.
961 This is in no way, shape or form meant as a replacement for real MIME
962 processing, but is simply a stop-gap measure until MIME support is
964 If FORCE, decode the article whether it is marked as quoted-printable
966 (interactive (list 'force))
968 (let ((case-fold-search t)
969 (buffer-read-only nil)
970 (type (gnus-fetch-field "content-transfer-encoding")))
971 (gnus-article-decode-rfc1522)
973 (and type (string-match "quoted-printable" (downcase type))))
974 (goto-char (point-min))
975 (search-forward "\n\n" nil 'move)
976 (article-mime-decode-quoted-printable (point) (point-max))))))
978 (defun article-mime-decode-quoted-printable-buffer ()
979 "Decode Quoted-Printable in the current buffer."
980 (article-mime-decode-quoted-printable (point-min) (point-max)))
982 (defun article-mime-decode-quoted-printable (from to)
983 "Decode Quoted-Printable in the region between FROM and TO."
986 (while (search-forward "=" to t)
987 (cond ((eq (following-char) ?\n)
990 ((looking-at "[0-9A-F][0-9A-F]")
991 (subst-char-in-region
992 (1- (point)) (point) ?=
993 (hexl-hex-string-to-integer
994 (buffer-substring (point) (+ 2 (point)))))
998 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
1000 (defun article-hide-pgp (&optional arg)
1001 "Toggle hiding of any PGP headers and signatures in the current article.
1002 If given a negative prefix, always show; if given a positive prefix,
1004 (interactive (gnus-article-hidden-arg))
1005 (unless (gnus-article-check-hidden-text 'pgp arg)
1007 (let ((inhibit-point-motion-hooks t)
1008 buffer-read-only beg end)
1010 (goto-char (point-min))
1011 ;; Hide the "header".
1012 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1013 (gnus-article-hide-text-type (1+ (match-beginning 0))
1016 ;; Hide the actual signature.
1017 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1018 (setq end (1+ (match-beginning 0)))
1019 (gnus-article-hide-text-type
1021 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1023 ;; Perhaps we shouldn't hide to the end of the buffer
1024 ;; if there is no end to the signature?
1027 ;; Hide "- " PGP quotation markers.
1029 (narrow-to-region beg end)
1030 (goto-char (point-min))
1031 (while (re-search-forward "^- " nil t)
1032 (gnus-article-hide-text-type
1033 (match-beginning 0) (match-end 0) 'pgp))
1035 (run-hooks 'gnus-article-hide-pgp-hook))))))
1037 (defun article-hide-pem (&optional arg)
1038 "Toggle hiding of any PEM headers and signatures in the current article.
1039 If given a negative prefix, always show; if given a positive prefix,
1041 (interactive (gnus-article-hidden-arg))
1042 (unless (gnus-article-check-hidden-text 'pem arg)
1044 (let (buffer-read-only end)
1046 (goto-char (point-min))
1047 ;; hide the horrendously ugly "header".
1048 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1051 (setq end (1+ (match-beginning 0)))
1052 (gnus-article-hide-text-type
1054 (if (search-forward "\n\n" nil t)
1058 ;; hide the trailer as well
1059 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1062 (gnus-article-hide-text-type
1063 (match-beginning 0) (match-end 0) 'pem))))))
1065 (defun article-hide-signature (&optional arg)
1066 "Hide the signature in the current article.
1067 If given a negative prefix, always show; if given a positive prefix,
1069 (interactive (gnus-article-hidden-arg))
1070 (unless (gnus-article-check-hidden-text 'signature arg)
1073 (let ((buffer-read-only nil))
1074 (when (gnus-article-narrow-to-signature)
1075 (gnus-article-hide-text-type
1076 (point-min) (point-max) 'signature)))))))
1078 (defun article-strip-leading-blank-lines ()
1079 "Remove all blank lines from the beginning of the article."
1082 (let ((inhibit-point-motion-hooks t)
1084 (goto-char (point-min))
1085 (when (search-forward "\n\n" nil t)
1086 (while (and (not (eobp))
1087 (looking-at "[ \t]*$"))
1088 (gnus-delete-line))))))
1090 (defun article-strip-multiple-blank-lines ()
1091 "Replace consecutive blank lines with one empty line."
1094 (let ((inhibit-point-motion-hooks t)
1096 ;; First make all blank lines empty.
1097 (goto-char (point-min))
1098 (search-forward "\n\n" nil t)
1099 (while (re-search-forward "^[ \t]+$" nil t)
1100 (replace-match "" nil t))
1101 ;; Then replace multiple empty lines with a single empty line.
1102 (goto-char (point-min))
1103 (search-forward "\n\n" nil t)
1104 (while (re-search-forward "\n\n\n+" nil t)
1105 (replace-match "\n\n" t t)))))
1107 (defun article-strip-leading-space ()
1108 "Remove all white space from the beginning of the lines in the article."
1111 (let ((inhibit-point-motion-hooks t)
1113 (goto-char (point-min))
1114 (search-forward "\n\n" nil t)
1115 (while (re-search-forward "^[ \t]+" nil t)
1116 (replace-match "" t t)))))
1118 (defun article-strip-blank-lines ()
1119 "Strip leading, trailing and multiple blank lines."
1121 (article-strip-leading-blank-lines)
1122 (article-remove-trailing-blank-lines)
1123 (article-strip-multiple-blank-lines))
1125 (defun article-strip-all-blank-lines ()
1126 "Strip all blank lines."
1129 (let ((inhibit-point-motion-hooks t)
1131 (goto-char (point-min))
1132 (search-forward "\n\n" nil t)
1133 (while (re-search-forward "^[ \t]*\n" nil t)
1134 (replace-match "" t t)))))
1136 (defvar mime::preview/content-list)
1137 (defvar mime::preview-content-info/point-min)
1138 (defun gnus-article-narrow-to-signature ()
1139 "Narrow to the signature; return t if a signature is found, else nil."
1141 (when (and (boundp 'mime::preview/content-list)
1142 mime::preview/content-list)
1143 ;; We have a MIMEish article, so we use the MIME data to narrow.
1144 (let ((pcinfo (car (last mime::preview/content-list))))
1147 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1150 (when (gnus-article-search-signature)
1152 ;; Check whether we have some limits to what we consider
1153 ;; to be a signature.
1154 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1155 (list gnus-signature-limit)))
1157 (while (setq limit (pop limits))
1158 (if (or (and (integerp limit)
1159 (< (- (point-max) (point)) limit))
1161 (< (count-lines (point) (point-max)) limit))
1162 (and (gnus-functionp limit)
1164 (and (stringp limit)
1165 (not (re-search-forward limit nil t))))
1166 () ; This limit did not succeed.
1170 (narrow-to-region (point) (point-max))
1173 (defun gnus-article-search-signature ()
1174 "Search the current buffer for the signature separator.
1175 Put point at the beginning of the signature separator."
1176 (let ((cur (point)))
1177 (goto-char (point-max))
1178 (if (if (stringp gnus-signature-separator)
1179 (re-search-backward gnus-signature-separator nil t)
1180 (let ((seps gnus-signature-separator))
1182 (not (re-search-backward (car seps) nil t)))
1190 (autoload 'w3-display "w3-parse")
1191 (autoload 'w3-do-setup "w3" "" t)
1192 (autoload 'w3-region "w3-display" "" t))
1194 (defun gnus-article-treat-html ()
1197 (let ((cbuf (current-buffer)))
1198 (set-buffer gnus-article-buffer)
1199 (let (buf buffer-read-only b e)
1201 (goto-char (point-min))
1203 (if (search-forward "\n\n" nil t)
1206 (setq e (point-max)))
1207 (nnheader-temp-write nil
1208 (insert-buffer-substring gnus-article-buffer b e)
1210 (save-window-excursion
1211 (w3-region (point-min) (point-max))
1212 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1214 (delete-region (point-min) (point-max))
1217 (goto-char (point-min))
1218 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1219 (set-buffer cbuf))))
1221 (defun gnus-article-hidden-arg ()
1222 "Return the current prefix arg as a number, or 0 if no prefix."
1223 (list (if current-prefix-arg
1224 (prefix-numeric-value current-prefix-arg)
1227 (defun gnus-article-check-hidden-text (type arg)
1228 "Return nil if hiding is necessary.
1229 Arg can be nil or a number. Nil and positive means hide, negative
1230 means show, 0 means toggle."
1234 (let ((hide (gnus-article-hidden-text-p type)))
1240 (gnus-article-show-hidden-text type))
1242 (if (eq hide 'hidden)
1243 (gnus-article-show-hidden-text type)
1246 (defun gnus-article-hidden-text-p (type)
1247 "Say whether the current buffer contains hidden text of type TYPE."
1248 (let ((start (point-min))
1249 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1251 (not (get-text-property pos 'invisible)))
1253 (text-property-any (1+ pos) (point-max) 'article-type type)))
1258 (defun gnus-article-show-hidden-text (type &optional hide)
1259 "Show all hidden text of type TYPE.
1260 If HIDE, hide the text instead."
1262 (let ((buffer-read-only nil)
1263 (inhibit-point-motion-hooks t)
1266 (while (setq beg (text-property-any end (point-max) 'article-type type))
1269 (text-property-not-all beg (point-max) 'article-type type)
1272 (gnus-article-hide-text beg end gnus-hidden-properties)
1273 (gnus-article-unhide-text beg end))
1277 (defconst article-time-units
1278 `((year . ,(* 365.25 24 60 60))
1279 (week . ,(* 7 24 60 60))
1280 (day . ,(* 24 60 60))
1284 "Mapping from time units to seconds.")
1286 (defun article-date-ut (&optional type highlight header)
1287 "Convert DATE date to universal time in the current article.
1288 If TYPE is `local', convert to local time; if it is `lapsed', output
1289 how much time has lapsed since DATE."
1290 (interactive (list 'ut t))
1291 (let* ((header (or header
1292 (mail-header-date gnus-current-headers)
1293 (message-fetch-field "date")
1295 (date (if (vectorp header) (mail-header-date header)
1297 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1298 (inhibit-point-motion-hooks t)
1299 bface eface newline)
1300 (when (and date (not (string= date "")))
1303 (nnheader-narrow-to-headers)
1304 (let ((buffer-read-only nil))
1305 ;; Delete any old Date headers.
1306 (if (re-search-forward date-regexp nil t)
1308 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1309 eface (get-text-property (1- (gnus-point-at-eol))
1311 (delete-region (progn (beginning-of-line) (point))
1312 (progn (end-of-line) (point)))
1313 (beginning-of-line))
1314 (goto-char (point-max))
1316 (insert (article-make-date-line date type))
1319 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1320 (put-text-property (match-beginning 1) (1+ (match-end 1))
1322 (put-text-property (match-beginning 2) (match-end 2)
1326 (insert "\n"))))))))
1328 (defun article-make-date-line (date type)
1329 "Return a DATE line of TYPE."
1331 ;; Convert to the local timezone. We have to slap a
1332 ;; `condition-case' round the calls to the timezone
1333 ;; functions since they aren't particularly resistant to
1336 (concat "Date: " (condition-case ()
1337 (timezone-make-date-arpa-standard date)
1339 ;; Convert to Universal Time.
1343 (timezone-make-date-arpa-standard date nil "UT")
1345 ;; Get the original date from the article.
1346 ((eq type 'original)
1347 (concat "Date: " date))
1348 ;; Let the user define the format.
1352 (format-time-string gnus-article-time-format
1355 (timezone-make-date-arpa-standard
1357 ;; Do an X-Sent lapsed format.
1359 ;; If the date is seriously mangled, the timezone functions are
1360 ;; liable to bug out, so we ignore all errors.
1361 (let* ((now (current-time))
1366 (timezone-make-date-arpa-standard
1367 (current-time-string now)
1368 (current-time-zone now) "UT"))
1370 (timezone-make-date-arpa-standard
1372 (real-sec (and real-time
1373 (+ (* (float (car real-time)) 65536)
1375 (sec (and real-time (abs real-sec)))
1385 ;; This is a bit convoluted, but basically we go
1386 ;; through the time units for years, weeks, etc,
1387 ;; and divide things to see whether that results
1388 ;; in positive answers.
1391 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1392 ;; The (remaining) seconds are too few to
1393 ;; be divided into this time unit.
1395 ;; It's big enough, so we output it.
1396 (setq sec (- sec (* num (cdr unit))))
1398 (concat (if prev ", " "") (int-to-string
1400 " " (symbol-name (car unit))
1401 (if (> num 1) "s" ""))
1403 article-time-units "")
1404 ;; If dates are odd, then it might appear like the
1405 ;; article was sent in the future.
1408 " in the future"))))))
1410 (error "Unknown conversion type: %s" type))))
1412 (defun article-date-local (&optional highlight)
1413 "Convert the current article date to the local timezone."
1414 (interactive (list t))
1415 (article-date-ut 'local highlight))
1417 (defun article-date-original (&optional highlight)
1418 "Convert the current article date to what it was originally.
1419 This is only useful if you have used some other date conversion
1420 function and want to see what the date was before converting."
1421 (interactive (list t))
1422 (article-date-ut 'original highlight))
1424 (defun article-date-lapsed (&optional highlight)
1425 "Convert the current article date to time lapsed since it was sent."
1426 (interactive (list t))
1427 (article-date-ut 'lapsed highlight))
1429 (defun article-update-date-lapsed ()
1430 "Function to be run from a timer to update the lapsed time line."
1433 (when (gnus-buffer-live-p gnus-article-buffer)
1434 (set-buffer gnus-article-buffer)
1435 (goto-char (point-min))
1436 (when (re-search-forward "^X-Sent:" nil t)
1437 (article-date-lapsed t))))))
1439 (defun gnus-start-date-timer (&optional n)
1440 "Start a timer to update the X-Sent header in the article buffers.
1441 The numerical prefix says how frequently (in seconds) the function
1446 (gnus-stop-date-timer)
1447 (setq article-lapsed-timer
1448 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1450 (defun gnus-stop-date-timer ()
1451 "Stop the X-Sent timer."
1453 (when article-lapsed-timer
1454 (nnheader-cancel-timer article-lapsed-timer)
1455 (setq article-lapsed-timer nil)))
1457 (defun article-date-user (&optional highlight)
1458 "Convert the current article date to the user-defined format.
1459 This format is defined by the `gnus-article-time-format' variable."
1460 (interactive (list t))
1461 (article-date-ut 'user highlight))
1463 (defun article-show-all ()
1464 "Show all hidden text in the article buffer."
1467 (let ((buffer-read-only nil))
1468 (gnus-article-unhide-text (point-min) (point-max)))))
1470 (defun article-emphasize (&optional arg)
1471 "Emphasize text according to `gnus-emphasis-alist'."
1472 (interactive (gnus-article-hidden-arg))
1473 (unless (gnus-article-check-hidden-text 'emphasis arg)
1475 (let ((alist gnus-emphasis-alist)
1476 (buffer-read-only nil)
1477 (props (append '(article-type emphasis)
1478 gnus-hidden-properties))
1479 regexp elem beg invisible visible face)
1480 (goto-char (point-min))
1481 (search-forward "\n\n" nil t)
1483 (while (setq elem (pop alist))
1485 (setq regexp (car elem)
1486 invisible (nth 1 elem)
1487 visible (nth 2 elem)
1489 (while (re-search-forward regexp nil t)
1490 (when (and (match-beginning visible) (match-beginning invisible))
1491 (gnus-article-hide-text
1492 (match-beginning invisible) (match-end invisible) props)
1493 (gnus-article-unhide-text-type
1494 (match-beginning visible) (match-end visible) 'emphasis)
1495 (gnus-put-text-property-excluding-newlines
1496 (match-beginning visible) (match-end visible) 'face face)
1497 (goto-char (match-end invisible)))))))))
1499 (defvar gnus-summary-article-menu)
1500 (defvar gnus-summary-post-menu)
1502 ;;; Saving functions.
1504 (defun gnus-article-save (save-buffer file &optional num)
1505 "Save the currently selected article."
1506 (unless gnus-save-all-headers
1507 ;; Remove headers according to `gnus-saved-headers'.
1508 (let ((gnus-visible-headers
1509 (or gnus-saved-headers gnus-visible-headers))
1510 (gnus-article-buffer save-buffer))
1512 (set-buffer save-buffer)
1513 (article-hide-headers 1 t))))
1514 (save-window-excursion
1515 (if (not gnus-default-article-saver)
1516 (error "No default saver is defined")
1517 ;; !!! Magic! The saving functions all save
1518 ;; `gnus-original-article-buffer' (or so they think), but we
1519 ;; bind that variable to our save-buffer.
1520 (set-buffer gnus-article-buffer)
1521 (let* ((gnus-save-article-buffer save-buffer)
1524 ((not gnus-prompt-before-saving) 'default)
1525 ((eq gnus-prompt-before-saving 'always) nil)
1527 (gnus-number-of-articles-to-be-saved
1528 (when (eq gnus-prompt-before-saving t)
1530 (set-buffer gnus-summary-buffer)
1531 (funcall gnus-default-article-saver filename)))))
1533 (defun gnus-read-save-file-name (prompt &optional filename
1534 function group headers variable)
1536 (funcall function group headers (symbol-value variable)))
1541 ((eq filename 'default)
1547 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1550 (if (and gnus-number-of-articles-to-be-saved
1551 (> gnus-number-of-articles-to-be-saved 1))
1552 (format "these %d articles"
1553 gnus-number-of-articles-to-be-saved)
1556 ;; Let the split methods have their say.
1558 ;; No split name was found.
1561 (concat prompt " (default "
1562 (file-name-nondirectory default-name) ") ")
1563 (file-name-directory default-name)
1565 ;; A single group name is returned.
1566 ((stringp split-name)
1568 (funcall function split-name headers
1569 (symbol-value variable)))
1571 (concat prompt " (default "
1572 (file-name-nondirectory default-name) ") ")
1573 (file-name-directory default-name)
1575 ;; A single split name was found
1576 ((= 1 (length split-name))
1577 (let* ((name (expand-file-name
1578 (car split-name) gnus-article-save-directory))
1579 (dir (cond ((file-directory-p name)
1580 (file-name-as-directory name))
1581 ((file-exists-p name) name)
1582 (t gnus-article-save-directory))))
1584 (concat prompt " (default " name ") ")
1586 ;; A list of splits was found.
1588 (setq split-name (nreverse split-name))
1590 (let ((file-name-history
1591 (nconc split-name file-name-history)))
1595 (concat prompt " (`M-p' for defaults) ")
1596 gnus-article-save-directory
1598 gnus-article-save-directory)))
1599 (car (push result file-name-history)))))))
1600 ;; Create the directory.
1601 (gnus-make-directory (file-name-directory file))
1602 ;; If we have read a directory, we append the default file name.
1603 (when (file-directory-p file)
1604 (setq file (concat (file-name-as-directory file)
1605 (file-name-nondirectory default-name))))
1606 ;; Possibly translate some characters.
1607 (nnheader-translate-file-chars file)))))
1608 (gnus-make-directory (file-name-directory result))
1609 (set variable result)))
1611 (defun gnus-article-archive-name (group)
1612 "Return the first instance of an \"Archive-name\" in the current buffer."
1613 (let ((case-fold-search t))
1614 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1615 (nnheader-concat gnus-article-save-directory
1616 (match-string 1)))))
1618 (defun gnus-article-nndoc-name (group)
1619 "If GROUP is an nndoc group, return the name of the parent group."
1620 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1621 (gnus-group-get-parameter group 'save-article-group)))
1623 (defun gnus-summary-save-in-rmail (&optional filename)
1624 "Append this article to Rmail file.
1625 Optional argument FILENAME specifies file name.
1626 Directory to save to is default to `gnus-article-save-directory'."
1628 (setq filename (gnus-read-save-file-name
1629 "Save %s in rmail file:" filename
1630 gnus-rmail-save-name gnus-newsgroup-name
1631 gnus-current-headers 'gnus-newsgroup-last-rmail))
1632 (gnus-eval-in-buffer-window gnus-save-article-buffer
1636 (gnus-output-to-rmail filename))))
1639 (defun gnus-summary-save-in-mail (&optional filename)
1640 "Append this article to Unix mail file.
1641 Optional argument FILENAME specifies file name.
1642 Directory to save to is default to `gnus-article-save-directory'."
1644 (setq filename (gnus-read-save-file-name
1645 "Save %s in Unix mail file:" filename
1646 gnus-mail-save-name gnus-newsgroup-name
1647 gnus-current-headers 'gnus-newsgroup-last-mail))
1648 (gnus-eval-in-buffer-window gnus-save-article-buffer
1652 (if (and (file-readable-p filename)
1653 (mail-file-babyl-p filename))
1654 (gnus-output-to-rmail filename t)
1655 (gnus-output-to-mail filename)))))
1658 (defun gnus-summary-save-in-file (&optional filename overwrite)
1659 "Append this article to file.
1660 Optional argument FILENAME specifies file name.
1661 Directory to save to is default to `gnus-article-save-directory'."
1663 (setq filename (gnus-read-save-file-name
1664 "Save %s in file:" filename
1665 gnus-file-save-name gnus-newsgroup-name
1666 gnus-current-headers 'gnus-newsgroup-last-file))
1667 (gnus-eval-in-buffer-window gnus-save-article-buffer
1671 (when (and overwrite
1672 (file-exists-p filename))
1673 (delete-file filename))
1674 (gnus-output-to-file filename))))
1677 (defun gnus-summary-write-to-file (&optional filename)
1678 "Write this article to a file.
1679 Optional argument FILENAME specifies file name.
1680 The directory to save in defaults to `gnus-article-save-directory'."
1682 (gnus-summary-save-in-file nil t))
1684 (defun gnus-summary-save-body-in-file (&optional filename)
1685 "Append this article body to a file.
1686 Optional argument FILENAME specifies file name.
1687 The directory to save in defaults to `gnus-article-save-directory'."
1689 (setq filename (gnus-read-save-file-name
1690 "Save %s body in file:" filename
1691 gnus-file-save-name gnus-newsgroup-name
1692 gnus-current-headers 'gnus-newsgroup-last-file))
1693 (gnus-eval-in-buffer-window gnus-save-article-buffer
1697 (goto-char (point-min))
1698 (when (search-forward "\n\n" nil t)
1699 (narrow-to-region (point) (point-max)))
1700 (gnus-output-to-file filename))))
1703 (defun gnus-summary-save-in-pipe (&optional command)
1704 "Pipe this article to subprocess."
1707 (cond ((eq command 'default)
1708 gnus-last-shell-command)
1712 "Shell command on %s: "
1713 (if (and gnus-number-of-articles-to-be-saved
1714 (> gnus-number-of-articles-to-be-saved 1))
1715 (format "these %d articles"
1716 gnus-number-of-articles-to-be-saved)
1718 gnus-last-shell-command))))
1719 (when (string-equal command "")
1720 (setq command gnus-last-shell-command))
1721 (gnus-eval-in-buffer-window gnus-article-buffer
1724 (shell-command-on-region (point-min) (point-max) command nil)))
1725 (setq gnus-last-shell-command command))
1727 ;;; Article file names when saving.
1729 (defun gnus-capitalize-newsgroup (newsgroup)
1730 "Capitalize NEWSGROUP name."
1731 (when (not (zerop (length newsgroup)))
1732 (concat (char-to-string (upcase (aref newsgroup 0)))
1733 (substring newsgroup 1))))
1735 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1736 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1737 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1738 Otherwise, it is like ~/News/news/group/num."
1741 (concat (if (gnus-use-long-file-name 'not-save)
1742 (gnus-capitalize-newsgroup newsgroup)
1743 (gnus-newsgroup-directory-form newsgroup))
1744 "/" (int-to-string (mail-header-number headers)))
1745 gnus-article-save-directory)))
1747 (string-equal (file-name-directory default)
1748 (file-name-directory last-file))
1749 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1751 (or last-file default))))
1753 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1754 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1755 If variable `gnus-use-long-file-name' is non-nil, it is
1756 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1759 (concat (if (gnus-use-long-file-name 'not-save)
1761 (gnus-newsgroup-directory-form newsgroup))
1762 "/" (int-to-string (mail-header-number headers)))
1763 gnus-article-save-directory)))
1765 (string-equal (file-name-directory default)
1766 (file-name-directory last-file))
1767 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1769 (or last-file default))))
1771 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1772 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1773 If variable `gnus-use-long-file-name' is non-nil, it is
1774 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1777 (if (gnus-use-long-file-name 'not-save)
1778 (gnus-capitalize-newsgroup newsgroup)
1779 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1780 gnus-article-save-directory)))
1782 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1783 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1784 If variable `gnus-use-long-file-name' is non-nil, it is
1785 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1788 (if (gnus-use-long-file-name 'not-save)
1790 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1791 gnus-article-save-directory)))
1798 (setq afunc (car func)
1801 gfunc (intern (format "gnus-%s" func))))
1803 (if (not (fboundp afunc))
1805 `(lambda (&optional interactive &rest args)
1806 ,(documentation afunc t)
1807 (interactive (list t))
1809 (set-buffer gnus-article-buffer)
1811 (call-interactively ',afunc)
1812 (apply ',afunc args))))))))
1813 '(article-hide-headers
1814 article-hide-boring-headers
1815 article-treat-overstrike
1816 (article-fill . gnus-article-word-wrap)
1818 article-display-x-face
1819 article-de-quoted-unreadable
1820 article-mime-decode-quoted-printable
1823 article-hide-signature
1824 article-remove-trailing-blank-lines
1825 article-strip-leading-blank-lines
1826 article-strip-multiple-blank-lines
1827 article-strip-leading-space
1828 article-strip-blank-lines
1829 article-strip-all-blank-lines
1831 article-date-original
1836 article-treat-dumbquotes
1837 (article-show-all . gnus-article-show-all-headers))))
1840 ;;; Gnus article mode
1843 (put 'gnus-article-mode 'mode-class 'special)
1845 (gnus-define-keys gnus-article-mode-map
1846 " " gnus-article-goto-next-page
1847 "\177" gnus-article-goto-prev-page
1848 [delete] gnus-article-goto-prev-page
1849 "\C-c^" gnus-article-refer-article
1850 "h" gnus-article-show-summary
1851 "s" gnus-article-show-summary
1852 "\C-c\C-m" gnus-article-mail
1853 "?" gnus-article-describe-briefly
1854 gnus-mouse-2 gnus-article-push-button
1855 "\r" gnus-article-press-button
1856 "\t" gnus-article-next-button
1857 "\M-\t" gnus-article-prev-button
1858 "e" gnus-article-edit
1859 "<" beginning-of-buffer
1861 "\C-c\C-i" gnus-info-find-node
1864 "\C-d" gnus-article-read-summary-keys
1865 "\M-*" gnus-article-read-summary-keys
1866 "\M-#" gnus-article-read-summary-keys
1867 "\M-^" gnus-article-read-summary-keys
1868 "\M-g" gnus-article-read-summary-keys)
1870 (substitute-key-definition
1871 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1873 (defun gnus-article-make-menu-bar ()
1874 (gnus-turn-off-edit-menu 'article)
1875 (unless (boundp 'gnus-article-article-menu)
1877 gnus-article-article-menu gnus-article-mode-map ""
1879 ["Scroll forwards" gnus-article-goto-next-page t]
1880 ["Scroll backwards" gnus-article-goto-prev-page t]
1881 ["Show summary" gnus-article-show-summary t]
1882 ["Fetch Message-ID at point" gnus-article-refer-article t]
1883 ["Mail to address at point" gnus-article-mail t]))
1886 gnus-article-treatment-menu gnus-article-mode-map ""
1888 ["Hide headers" gnus-article-hide-headers t]
1889 ["Hide signature" gnus-article-hide-signature t]
1890 ["Hide citation" gnus-article-hide-citation t]
1891 ["Treat overstrike" gnus-article-treat-overstrike t]
1892 ["Remove carriage return" gnus-article-remove-cr t]
1893 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1896 (when (boundp 'gnus-summary-article-menu)
1897 (define-key gnus-article-mode-map [menu-bar commands]
1898 (cons "Commands" gnus-summary-article-menu))))
1900 (when (boundp 'gnus-summary-post-menu)
1901 (define-key gnus-article-mode-map [menu-bar post]
1902 (cons "Post" gnus-summary-post-menu)))
1904 (run-hooks 'gnus-article-menu-hook)))
1906 (defun gnus-article-mode ()
1907 "Major mode for displaying an article.
1909 All normal editing commands are switched off.
1911 The following commands are available in addition to all summary mode
1913 \\<gnus-article-mode-map>
1914 \\[gnus-article-next-page]\t Scroll the article one page forwards
1915 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1916 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1917 \\[gnus-article-show-summary]\t Display the summary buffer
1918 \\[gnus-article-mail]\t Send a reply to the address near point
1919 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1920 \\[gnus-info-find-node]\t Go to the Gnus info node"
1922 (when (gnus-visual-p 'article-menu 'menu)
1923 (gnus-article-make-menu-bar))
1924 (kill-all-local-variables)
1925 (gnus-simplify-mode-line)
1926 (setq mode-name "Article")
1927 (setq major-mode 'gnus-article-mode)
1928 (make-local-variable 'minor-mode-alist)
1929 (unless (assq 'gnus-show-mime minor-mode-alist)
1930 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1931 (use-local-map gnus-article-mode-map)
1932 (gnus-update-format-specifications nil 'article-mode)
1933 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1934 (set (make-local-variable 'gnus-page-broken) nil)
1935 (set (make-local-variable 'gnus-button-marker-list) nil)
1936 (gnus-set-default-directory)
1937 (buffer-disable-undo (current-buffer))
1938 (setq buffer-read-only t)
1939 (set-syntax-table gnus-article-mode-syntax-table)
1940 (run-hooks 'gnus-article-mode-hook))
1942 (defun gnus-article-setup-buffer ()
1943 "Initialize the article buffer."
1944 (let* ((name (if gnus-single-article-buffer "*Article*"
1945 (concat "*Article " gnus-newsgroup-name "*")))
1947 (progn (string-match "\\*Article" name)
1948 (concat " *Original Article"
1949 (substring name (match-end 0))))))
1950 (setq gnus-article-buffer name)
1951 (setq gnus-original-article-buffer original)
1952 ;; This might be a variable local to the summary buffer.
1953 (unless gnus-single-article-buffer
1955 (set-buffer gnus-summary-buffer)
1956 (setq gnus-article-buffer name)
1957 (setq gnus-original-article-buffer original)
1958 (gnus-set-global-variables)))
1959 ;; Init original article buffer.
1961 (set-buffer (get-buffer-create gnus-original-article-buffer))
1962 (buffer-disable-undo (current-buffer))
1963 (setq major-mode 'gnus-original-article-mode)
1964 (gnus-add-current-to-buffer-list)
1965 (make-local-variable 'gnus-original-article))
1966 (if (get-buffer name)
1969 (buffer-disable-undo (current-buffer))
1970 (setq buffer-read-only t)
1971 (gnus-add-current-to-buffer-list)
1972 (unless (eq major-mode 'gnus-article-mode)
1973 (gnus-article-mode))
1976 (set-buffer (get-buffer-create name))
1977 (gnus-add-current-to-buffer-list)
1979 (make-local-variable 'gnus-summary-buffer)
1980 (current-buffer)))))
1982 ;; Set article window start at LINE, where LINE is the number of lines
1983 ;; from the head of the article.
1984 (defun gnus-article-set-window-start (&optional line)
1986 (get-buffer-window gnus-article-buffer t)
1988 (set-buffer gnus-article-buffer)
1989 (goto-char (point-min))
1992 (gnus-message 6 "Moved to bookmark")
1993 (search-forward "\n\n" nil t)
1997 (defun gnus-article-prepare (article &optional all-headers header)
1998 "Prepare ARTICLE in article mode buffer.
1999 ARTICLE should either be an article number or a Message-ID.
2000 If ARTICLE is an id, HEADER should be the article headers.
2001 If ALL-HEADERS is non-nil, no headers are hidden."
2003 ;; Make sure we start in a summary buffer.
2004 (unless (eq major-mode 'gnus-summary-mode)
2005 (set-buffer gnus-summary-buffer))
2006 (setq gnus-summary-buffer (current-buffer))
2007 ;; Make sure the connection to the server is alive.
2008 (unless (gnus-server-opened
2009 (gnus-find-method-for-group gnus-newsgroup-name))
2010 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2011 (gnus-request-group gnus-newsgroup-name t))
2012 (let* ((gnus-article (if header (mail-header-number header) article))
2013 (summary-buffer (current-buffer))
2014 (internal-hook gnus-article-internal-prepare-hook)
2015 (group gnus-newsgroup-name)
2018 (gnus-article-setup-buffer)
2019 (set-buffer gnus-article-buffer)
2020 ;; Deactivate active regions.
2021 (when (and (boundp 'transient-mark-mode)
2022 transient-mark-mode)
2023 (setq mark-active nil))
2024 (if (not (setq result (let ((buffer-read-only nil))
2025 (gnus-request-article-this-buffer
2027 ;; There is no such article.
2029 (when (and (numberp article)
2030 (not (memq article gnus-newsgroup-sparse)))
2031 (setq gnus-article-current
2032 (cons gnus-newsgroup-name article))
2033 (set-buffer gnus-summary-buffer)
2034 (setq gnus-current-article article)
2035 (gnus-summary-mark-article article gnus-canceled-mark))
2036 (unless (memq article gnus-newsgroup-sparse)
2038 1 "No such article (may have expired or been canceled)")))
2039 (if (or (eq result 'pseudo) (eq result 'nneething))
2042 (set-buffer summary-buffer)
2043 (push article gnus-newsgroup-history)
2044 (setq gnus-last-article gnus-current-article
2045 gnus-current-article 0
2046 gnus-current-headers nil
2047 gnus-article-current nil)
2048 (if (eq result 'nneething)
2049 (gnus-configure-windows 'summary)
2050 (gnus-configure-windows 'article))
2051 (gnus-set-global-variables))
2052 (gnus-set-mode-line 'article))
2053 ;; The result from the `request' was an actual article -
2054 ;; or at least some text that is now displayed in the
2056 (when (and (numberp article)
2057 (not (eq article gnus-current-article)))
2058 ;; Seems like a new article has been selected.
2059 ;; `gnus-current-article' must be an article number.
2061 (set-buffer summary-buffer)
2062 (push article gnus-newsgroup-history)
2063 (setq gnus-last-article gnus-current-article
2064 gnus-current-article article
2065 gnus-current-headers
2066 (gnus-summary-article-header gnus-current-article)
2067 gnus-article-current
2068 (cons gnus-newsgroup-name gnus-current-article))
2069 (unless (vectorp gnus-current-headers)
2070 (setq gnus-current-headers nil))
2071 (gnus-summary-goto-subject gnus-current-article)
2072 (gnus-summary-show-thread)
2073 (run-hooks 'gnus-mark-article-hook)
2074 (gnus-set-mode-line 'summary)
2075 (when (gnus-visual-p 'article-highlight 'highlight)
2076 (run-hooks 'gnus-visual-mark-article-hook))
2077 ;; Set the global newsgroup variables here.
2078 ;; Suggested by Jim Sisolak
2079 ;; <sisolak@trans4.neep.wisc.edu>.
2080 (gnus-set-global-variables)
2081 (setq gnus-have-all-headers
2082 (or all-headers gnus-show-all-headers))
2084 (vectorp (gnus-summary-article-header article))
2085 (gnus-cache-possibly-enter-article
2087 (gnus-summary-article-header article)
2088 (memq article gnus-newsgroup-marked)
2089 (memq article gnus-newsgroup-dormant)
2090 (memq article gnus-newsgroup-unreads)))))
2091 (when (or (numberp article)
2093 ;; Hooks for getting information from the article.
2094 ;; This hook must be called before being narrowed.
2095 (let (buffer-read-only)
2096 (run-hooks 'internal-hook)
2097 (run-hooks 'gnus-article-prepare-hook)
2098 ;; Decode MIME message.
2099 (when gnus-show-mime
2100 (if (or (not gnus-strict-mime)
2101 (gnus-fetch-field "Mime-Version"))
2102 (let ((coding-system-for-write 'binary)
2103 (coding-system-for-read 'binary))
2104 (funcall gnus-show-mime-method))
2105 (funcall gnus-decode-encoded-word-method)))
2106 ;; Perform the article display hooks.
2107 (run-hooks 'gnus-article-display-hook))
2109 (goto-char (point-min))
2110 (setq gnus-page-broken
2111 (when gnus-break-pages
2112 (gnus-narrow-to-page)
2114 (gnus-set-mode-line 'article)
2115 (gnus-configure-windows 'article)
2116 (goto-char (point-min))
2119 (defun gnus-article-wash-status ()
2120 "Return a string which display status of article washing."
2122 (set-buffer gnus-article-buffer)
2123 (let ((cite (gnus-article-hidden-text-p 'cite))
2124 (headers (gnus-article-hidden-text-p 'headers))
2125 (boring (gnus-article-hidden-text-p 'boring-headers))
2126 (pgp (gnus-article-hidden-text-p 'pgp))
2127 (pem (gnus-article-hidden-text-p 'pem))
2128 (signature (gnus-article-hidden-text-p 'signature))
2129 (overstrike (gnus-article-hidden-text-p 'overstrike))
2130 (emphasis (gnus-article-hidden-text-p 'emphasis))
2131 (mime gnus-show-mime))
2132 (format "%c%c%c%c%c%c%c"
2134 (if (or headers boring) ?h ? )
2135 (if (or pgp pem) ?p ? )
2136 (if signature ?s ? )
2137 (if overstrike ?o ? )
2139 (if emphasis ?e ? )))))
2141 (defun gnus-article-hide-headers-if-wanted ()
2142 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2143 Provided for backwards compatibility."
2144 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2146 (gnus-article-hide-headers)))
2150 (defun gnus-output-to-file (file-name)
2151 "Append the current article to a file named FILE-NAME."
2152 (let ((artbuf (current-buffer)))
2153 (nnheader-temp-write nil
2154 (insert-buffer-substring artbuf)
2155 ;; Append newline at end of the buffer as separator, and then
2157 (goto-char (point-max))
2159 (append-to-file (point-min) (point-max) file-name)
2162 (defun gnus-narrow-to-page (&optional arg)
2163 "Narrow the article buffer to a page.
2164 If given a numerical ARG, move forward ARG pages."
2166 (setq arg (if arg (prefix-numeric-value arg) 0))
2168 (set-buffer gnus-article-buffer)
2169 (goto-char (point-min))
2171 ;; Remove any old next/prev buttons.
2172 (when (gnus-visual-p 'page-marker)
2173 (let ((buffer-read-only nil))
2174 (gnus-remove-text-with-property 'gnus-prev)
2175 (gnus-remove-text-with-property 'gnus-next)))
2178 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2180 (re-search-forward page-delimiter nil 'move arg)))
2181 (goto-char (match-end 0)))
2184 (if (re-search-forward page-delimiter nil 'move)
2187 (when (and (gnus-visual-p 'page-marker)
2188 (not (= (point-min) 1)))
2190 (goto-char (point-min))
2191 (gnus-insert-prev-page-button)))
2192 (when (and (gnus-visual-p 'page-marker)
2193 (< (+ (point-max) 2) (buffer-size)))
2195 (goto-char (point-max))
2196 (gnus-insert-next-page-button)))))
2198 ;; Article mode commands
2200 (defun gnus-article-goto-next-page ()
2201 "Show the next page of the article."
2203 (when (gnus-article-next-page)
2204 (goto-char (point-min))
2205 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2207 (defun gnus-article-goto-prev-page ()
2208 "Show the next page of the article."
2210 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2211 (gnus-article-prev-page nil)))
2213 (defun gnus-article-next-page (&optional lines)
2214 "Show the next page of the current article.
2215 If end of article, return non-nil. Otherwise return nil.
2216 Argument LINES specifies lines to be scrolled up."
2218 (move-to-window-line -1)
2221 (and (pos-visible-in-window-p) ;Not continuation line.
2223 ;; Nothing in this page.
2224 (if (or (not gnus-page-broken)
2227 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2229 (gnus-narrow-to-page 1) ;Go to next page.
2231 ;; More in this page.
2232 (let ((scroll-in-place nil))
2236 ;; Long lines may cause an end-of-buffer error.
2237 (goto-char (point-max)))))
2238 (move-to-window-line 0)
2241 (defun gnus-article-prev-page (&optional lines)
2242 "Show previous page of current article.
2243 Argument LINES specifies lines to be scrolled down."
2245 (move-to-window-line 0)
2246 (if (and gnus-page-broken
2248 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2250 (gnus-narrow-to-page -1) ;Go to previous page.
2251 (goto-char (point-max))
2253 (let ((scroll-in-place nil))
2257 (beginning-of-buffer
2258 (goto-char (point-min))))
2259 (move-to-window-line 0)))))
2261 (defun gnus-article-refer-article ()
2262 "Read article specified by message-id around point."
2264 (let ((point (point)))
2265 (search-forward ">" nil t) ;Move point to end of "<....>".
2266 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2267 (let ((message-id (match-string 1)))
2269 (set-buffer gnus-summary-buffer)
2270 (gnus-summary-refer-article message-id))
2272 (error "No references around point"))))
2274 (defun gnus-article-show-summary ()
2275 "Reconfigure windows to show summary buffer."
2277 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2278 (error "There is no summary buffer for this article buffer")
2279 (gnus-article-set-globals)
2280 (gnus-configure-windows 'article)
2281 (gnus-summary-goto-subject gnus-current-article)))
2283 (defun gnus-article-describe-briefly ()
2284 "Describe article mode commands briefly."
2287 (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")))
2289 (defun gnus-article-summary-command ()
2290 "Execute the last keystroke in the summary buffer."
2292 (let ((obuf (current-buffer))
2293 (owin (current-window-configuration))
2295 (switch-to-buffer gnus-summary-buffer 'norecord)
2296 (setq func (lookup-key (current-local-map) (this-command-keys)))
2297 (call-interactively func)
2299 (set-window-configuration owin)
2300 (set-window-point (get-buffer-window (current-buffer)) (point))))
2302 (defun gnus-article-summary-command-nosave ()
2303 "Execute the last keystroke in the summary buffer."
2306 (pop-to-buffer gnus-summary-buffer 'norecord)
2307 (setq func (lookup-key (current-local-map) (this-command-keys)))
2308 (call-interactively func)))
2310 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2311 "Read a summary buffer key sequence and execute it from the article buffer."
2314 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2315 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2316 "=" "^" "\M-^" "|"))
2323 (set-buffer gnus-summary-buffer)
2324 (let (gnus-pick-mode)
2325 (push (or key last-command-event) unread-command-events)
2326 (setq keys (read-key-sequence nil))))
2329 (if (or (member keys nosaves)
2330 (member keys nosave-but-article)
2331 (member keys nosave-in-article))
2333 (save-window-excursion
2334 (pop-to-buffer gnus-summary-buffer 'norecord)
2335 ;; We disable the pick minor mode commands.
2336 (let (gnus-pick-mode)
2337 (setq func (lookup-key (current-local-map) keys))))
2340 (unless (member keys nosave-in-article)
2341 (set-buffer gnus-summary-buffer))
2342 (call-interactively func))
2343 (when (member keys nosave-but-article)
2344 (pop-to-buffer gnus-article-buffer 'norecord)))
2345 ;; These commands should restore window configuration.
2346 (let ((obuf (current-buffer))
2347 (owin (current-window-configuration))
2350 (if not-restore-window
2351 (pop-to-buffer gnus-summary-buffer 'norecord)
2352 (switch-to-buffer gnus-summary-buffer 'norecord))
2353 (setq in-buffer (current-buffer))
2354 ;; We disable the pick minor mode commands.
2355 (if (setq func (let (gnus-pick-mode)
2356 (lookup-key (current-local-map) keys)))
2357 (call-interactively func)
2359 (when (eq in-buffer (current-buffer))
2361 (unless not-restore-window
2362 (set-window-configuration owin))
2363 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2365 (defun gnus-article-hide (&optional arg force)
2366 "Hide all the gruft in the current article.
2367 This means that PGP stuff, signatures, cited text and (some)
2368 headers will be hidden.
2369 If given a prefix, show the hidden text instead."
2370 (interactive (list current-prefix-arg 'force))
2371 (gnus-article-hide-headers arg)
2372 (gnus-article-hide-pgp arg)
2373 (gnus-article-hide-citation-maybe arg force)
2374 (gnus-article-hide-signature arg))
2376 (defun gnus-article-maybe-highlight ()
2377 "Do some article highlighting if `article-visual' is non-nil."
2378 (when (gnus-visual-p 'article-highlight 'highlight)
2379 (gnus-article-highlight-some)))
2381 (defun gnus-request-article-this-buffer (article group)
2382 "Get an article and insert it into this buffer."
2383 (let (do-update-line)
2387 (gnus-kill-all-overlays)
2388 (setq group (or group gnus-newsgroup-name))
2390 ;; Open server if it has closed.
2391 (gnus-check-server (gnus-find-method-for-group group))
2393 ;; Using `gnus-request-article' directly will insert the article into
2394 ;; `nntp-server-buffer' - so we'll save some time by not having to
2395 ;; copy it from the server buffer into the article buffer.
2397 ;; We only request an article by message-id when we do not have the
2398 ;; headers for it, so we'll have to get those.
2399 (when (stringp article)
2400 (let ((gnus-override-method gnus-refer-article-method))
2401 (gnus-read-header article)))
2403 ;; If the article number is negative, that means that this article
2404 ;; doesn't belong in this newsgroup (possibly), so we find its
2405 ;; message-id and request it by id instead of number.
2406 (when (and (numberp article)
2408 (get-buffer gnus-summary-buffer)
2409 (buffer-name (get-buffer gnus-summary-buffer)))
2411 (set-buffer gnus-summary-buffer)
2412 (let ((header (gnus-summary-article-header article)))
2415 ((memq article gnus-newsgroup-sparse)
2416 ;; This is a sparse gap article.
2417 (setq do-update-line article)
2418 (setq article (mail-header-id header))
2419 (let ((gnus-override-method gnus-refer-article-method))
2420 (gnus-read-header article))
2421 (setq gnus-newsgroup-sparse
2422 (delq article gnus-newsgroup-sparse)))
2424 ;; It's a real article.
2425 (setq article (mail-header-id header)))
2427 ;; It is an extracted pseudo-article.
2428 (setq article 'pseudo)
2429 (gnus-request-pseudo-article header))))
2431 (let ((method (gnus-find-method-for-group
2432 gnus-newsgroup-name)))
2433 (if (not (eq (car method) 'nneething))
2435 (let ((dir (concat (file-name-as-directory (nth 1 method))
2436 (mail-header-subject header))))
2437 (when (file-directory-p dir)
2438 (setq article 'nneething)
2439 (gnus-group-enter-directory dir))))))))
2442 ;; Refuse to select canceled articles.
2443 ((and (numberp article)
2445 (get-buffer gnus-summary-buffer)
2446 (buffer-name (get-buffer gnus-summary-buffer))
2447 (eq (cdr (save-excursion
2448 (set-buffer gnus-summary-buffer)
2449 (assq article gnus-newsgroup-reads)))
2450 gnus-canceled-mark))
2452 ;; We first check `gnus-original-article-buffer'.
2453 ((and (get-buffer gnus-original-article-buffer)
2456 (set-buffer gnus-original-article-buffer)
2457 (and (equal (car gnus-original-article) group)
2458 (eq (cdr gnus-original-article) article))))
2459 (insert-buffer-substring gnus-original-article-buffer)
2461 ;; Check the backlog.
2462 ((and gnus-keep-backlog
2463 (gnus-backlog-request-article group article (current-buffer)))
2465 ;; Check asynchronous pre-fetch.
2466 ((gnus-async-request-fetched-article group article (current-buffer))
2467 (gnus-async-prefetch-next group article gnus-summary-buffer)
2468 (when (and (numberp article) gnus-keep-backlog)
2469 (gnus-backlog-enter-article group article (current-buffer)))
2472 ((and gnus-use-cache
2474 (gnus-cache-request-article article group))
2476 ;; Get the article and put into the article buffer.
2477 ((or (stringp article) (numberp article))
2478 (let ((gnus-override-method
2479 (and (stringp article) gnus-refer-article-method))
2480 (buffer-read-only nil))
2482 (gnus-kill-all-overlays)
2483 (when (gnus-request-article article group (current-buffer))
2484 (when (numberp article)
2485 (gnus-async-prefetch-next group article gnus-summary-buffer)
2486 (when gnus-keep-backlog
2487 (gnus-backlog-enter-article
2488 group article (current-buffer))))
2493 ;; Take the article from the original article buffer
2494 ;; and place it in the buffer it's supposed to be in.
2495 (when (and (get-buffer gnus-article-buffer)
2497 (equal (buffer-name (current-buffer))
2498 (buffer-name (get-buffer gnus-article-buffer))))
2500 (if (get-buffer gnus-original-article-buffer)
2501 (set-buffer (get-buffer gnus-original-article-buffer))
2502 (set-buffer (get-buffer-create gnus-original-article-buffer))
2503 (buffer-disable-undo (current-buffer))
2504 (setq major-mode 'gnus-original-article-mode)
2505 (setq buffer-read-only t)
2506 (gnus-add-current-to-buffer-list))
2507 (let (buffer-read-only)
2509 (insert-buffer-substring gnus-article-buffer))
2510 (setq gnus-original-article (cons group article))))
2512 ;; Update sparse articles.
2513 (when (and do-update-line
2514 (or (numberp article)
2516 (let ((buf (current-buffer)))
2517 (set-buffer gnus-summary-buffer)
2518 (gnus-summary-update-article do-update-line)
2519 (gnus-summary-goto-subject do-update-line nil t)
2520 (set-window-point (get-buffer-window (current-buffer) t)
2522 (set-buffer buf))))))
2528 (defcustom gnus-article-edit-mode-hook nil
2529 "Hook run in article edit mode buffers."
2530 :group 'gnus-article-various
2533 (defvar gnus-article-edit-done-function nil)
2535 (defvar gnus-article-edit-mode-map nil)
2537 (unless gnus-article-edit-mode-map
2538 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2540 (gnus-define-keys gnus-article-edit-mode-map
2541 "\C-c\C-c" gnus-article-edit-done
2542 "\C-c\C-k" gnus-article-edit-exit)
2544 (gnus-define-keys (gnus-article-edit-wash-map
2545 "\C-c\C-w" gnus-article-edit-mode-map)
2546 "f" gnus-article-edit-full-stops))
2548 (defun gnus-article-edit-mode ()
2549 "Major mode for editing articles.
2550 This is an extended text-mode.
2552 \\{gnus-article-edit-mode-map}"
2554 (kill-all-local-variables)
2555 (setq major-mode 'gnus-article-edit-mode)
2556 (setq mode-name "Article Edit")
2557 (use-local-map gnus-article-edit-mode-map)
2558 (make-local-variable 'gnus-article-edit-done-function)
2559 (make-local-variable 'gnus-prev-winconf)
2560 (setq buffer-read-only nil)
2561 (buffer-enable-undo)
2563 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2565 (defun gnus-article-edit (&optional force)
2566 "Edit the current article.
2567 This will have permanent effect only in mail groups.
2568 If FORCE is non-nil, allow editing of articles even in read-only
2571 (when (and (not force)
2572 (gnus-group-read-only-p))
2573 (error "The current newsgroup does not support article editing"))
2574 (gnus-article-edit-article
2575 `(lambda (no-highlight)
2576 (gnus-summary-edit-article-done
2577 ,(or (mail-header-references gnus-current-headers) "")
2578 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2580 (defun gnus-article-edit-article (exit-func)
2581 "Start editing the contents of the current article buffer."
2582 (let ((winconf (current-window-configuration)))
2583 (set-buffer gnus-article-buffer)
2584 (gnus-article-edit-mode)
2585 (gnus-set-text-properties (point-min) (point-max) nil)
2586 (gnus-configure-windows 'edit-article)
2587 (setq gnus-article-edit-done-function exit-func)
2588 (setq gnus-prev-winconf winconf)
2589 (gnus-message 6 "C-c C-c to end edits")))
2591 (defun gnus-article-edit-done (&optional arg)
2592 "Update the article edits and exit."
2597 (goto-char (point-min))
2598 (when (search-forward "\n\n" nil 1)
2599 (let ((lines (count-lines (point) (point-max)))
2600 (length (- (point-max) (point)))
2601 (case-fold-search t)
2602 (body (copy-marker (point))))
2603 (goto-char (point-min))
2604 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2605 (delete-region (match-beginning 1) (match-end 1))
2606 (insert (number-to-string length)))
2607 (goto-char (point-min))
2608 (when (re-search-forward
2609 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2610 (delete-region (match-beginning 1) (match-end 1))
2611 (insert (number-to-string length)))
2612 (goto-char (point-min))
2613 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2614 (delete-region (match-beginning 1) (match-end 1))
2615 (insert (number-to-string lines)))))))
2616 (let ((func gnus-article-edit-done-function)
2617 (buf (current-buffer))
2618 (start (window-start)))
2619 (gnus-article-edit-exit)
2622 (let ((buffer-read-only nil))
2623 (funcall func arg)))
2625 (set-window-start (get-buffer-window buf) start)
2626 (set-window-point (get-buffer-window buf) (point))))
2628 (defun gnus-article-edit-exit ()
2629 "Exit the article editing without updating."
2631 ;; We remove all text props from the article buffer.
2632 (let ((buf (format "%s" (buffer-string)))
2633 (curbuf (current-buffer))
2635 (window-start (window-start)))
2638 (let ((winconf gnus-prev-winconf))
2640 ;; The cache and backlog have to be flushed somewhat.
2641 (when gnus-use-cache
2642 (gnus-cache-update-article
2643 (car gnus-article-current) (cdr gnus-article-current)))
2644 (when gnus-keep-backlog
2645 (gnus-backlog-remove-article
2646 (car gnus-article-current) (cdr gnus-article-current)))
2647 ;; Flush original article as well.
2649 (when (get-buffer gnus-original-article-buffer)
2650 (set-buffer gnus-original-article-buffer)
2651 (setq gnus-original-article nil)))
2652 (set-window-configuration winconf)
2653 ;; Tippy-toe some to make sure that point remains where it was.
2654 (let ((buf (current-buffer)))
2656 (set-window-start (get-buffer-window (current-buffer)) window-start)
2658 (set-buffer buf)))))
2660 (defun gnus-article-edit-full-stops ()
2661 "Interactively repair spacing at end of sentences."
2664 (goto-char (point-min))
2665 (search-forward-regexp "^$" nil t)
2666 (let ((case-fold-search nil))
2667 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2670 ;;; Article highlights
2673 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2675 ;;; Internal Variables:
2677 (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\\)"
2678 "Regular expression that matches URLs."
2679 :group 'gnus-article-buttons
2682 (defcustom gnus-button-alist
2683 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2684 gnus-button-message-id 2)
2685 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2686 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2687 gnus-button-fetch-group 4)
2688 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2689 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2690 t gnus-button-message-id 3)
2691 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2692 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2693 ;; This is how URLs _should_ be embedded in text...
2694 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2696 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2697 "Alist of regexps matching buttons in article bodies.
2699 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2700 REGEXP: is the string matching text around the button,
2701 BUTTON: is the number of the regexp grouping actually matching the button,
2702 FORM: is a lisp expression which must eval to true for the button to
2704 CALLBACK: is the function to call when the user push this button, and each
2705 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2707 CALLBACK can also be a variable, in that case the value of that
2708 variable it the real callback function."
2709 :group 'gnus-article-buttons
2710 :type '(repeat (list regexp
2711 (integer :tag "Button")
2713 (function :tag "Callback")
2716 (integer :tag "Regexp group")))))
2718 (defcustom gnus-header-button-alist
2719 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2720 0 t gnus-button-message-id 0)
2721 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2722 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2723 0 t gnus-button-mailto 0)
2724 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2725 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2726 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2727 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2728 gnus-button-message-id 3))
2729 "Alist of headers and regexps to match buttons in article heads.
2731 This alist is very similar to `gnus-button-alist', except that each
2732 alist has an additional HEADER element first in each entry:
2734 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2736 HEADER is a regexp to match a header. For a fuller explanation, see
2737 `gnus-button-alist'."
2738 :group 'gnus-article-buttons
2739 :group 'gnus-article-headers
2740 :type '(repeat (list (regexp :tag "Header")
2742 (integer :tag "Button")
2744 (function :tag "Callback")
2747 (integer :tag "Regexp group")))))
2749 (defvar gnus-button-regexp nil)
2750 (defvar gnus-button-marker-list nil)
2751 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2753 (defvar gnus-button-last nil)
2754 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2758 (defun gnus-article-push-button (event)
2759 "Check text under the mouse pointer for a callback function.
2760 If the text under the mouse pointer has a `gnus-callback' property,
2761 call it with the value of the `gnus-data' text property."
2763 (set-buffer (window-buffer (posn-window (event-start event))))
2764 (let* ((pos (posn-point (event-start event)))
2765 (data (get-text-property pos 'gnus-data))
2766 (fun (get-text-property pos 'gnus-callback)))
2768 (funcall fun data))))
2770 (defun gnus-article-press-button ()
2771 "Check text at point for a callback function.
2772 If the text at point has a `gnus-callback' property,
2773 call it with the value of the `gnus-data' text property."
2775 (let* ((data (get-text-property (point) 'gnus-data))
2776 (fun (get-text-property (point) 'gnus-callback)))
2778 (funcall fun data))))
2780 (defun gnus-article-prev-button (n)
2781 "Move point to N buttons backward.
2782 If N is negative, move forward instead."
2784 (gnus-article-next-button (- n)))
2786 (defun gnus-article-next-button (n)
2787 "Move point to N buttons forward.
2788 If N is negative, move backward instead."
2790 (let ((function (if (< n 0) 'previous-single-property-change
2791 'next-single-property-change))
2792 (inhibit-point-motion-hooks t)
2794 (limit (if (< n 0) (point-min) (point-max))))
2796 (while (and (not (= limit (point)))
2798 ;; Skip past the current button.
2799 (when (get-text-property (point) 'gnus-callback)
2800 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2801 ;; Go to the next (or previous) button.
2802 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2803 ;; Put point at the start of the button.
2804 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2805 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2806 ;; Skip past intangible buttons.
2807 (when (get-text-property (point) 'intangible)
2811 (gnus-message 5 "No more buttons"))
2814 (defun gnus-article-highlight (&optional force)
2815 "Highlight current article.
2816 This function calls `gnus-article-highlight-headers',
2817 `gnus-article-highlight-citation',
2818 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2819 do the highlighting. See the documentation for those functions."
2820 (interactive (list 'force))
2821 (gnus-article-highlight-headers)
2822 (gnus-article-highlight-citation force)
2823 (gnus-article-highlight-signature)
2824 (gnus-article-add-buttons force)
2825 (gnus-article-add-buttons-to-head))
2827 (defun gnus-article-highlight-some (&optional force)
2828 "Highlight current article.
2829 This function calls `gnus-article-highlight-headers',
2830 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2831 do the highlighting. See the documentation for those functions."
2832 (interactive (list 'force))
2833 (gnus-article-highlight-headers)
2834 (gnus-article-highlight-signature)
2835 (gnus-article-add-buttons))
2837 (defun gnus-article-highlight-headers ()
2838 "Highlight article headers as specified by `gnus-header-face-alist'."
2841 (set-buffer gnus-article-buffer)
2843 (let ((alist gnus-header-face-alist)
2844 (buffer-read-only nil)
2845 (case-fold-search t)
2846 (inhibit-point-motion-hooks t)
2847 entry regexp header-face field-face from hpoints fpoints)
2848 (message-narrow-to-head)
2849 (while (setq entry (pop alist))
2850 (goto-char (point-min))
2851 (setq regexp (concat "^\\("
2852 (if (string-equal "" (nth 0 entry))
2856 header-face (nth 1 entry)
2857 field-face (nth 2 entry))
2858 (while (and (re-search-forward regexp nil t)
2862 (unless (search-forward ":" nil t)
2864 (when (and header-face
2865 (not (memq (point) hpoints)))
2866 (push (point) hpoints)
2867 (gnus-put-text-property from (point) 'face header-face))
2868 (when (and field-face
2869 (not (memq (setq from (point)) fpoints)))
2871 (if (re-search-forward "^[^ \t]" nil t)
2873 (goto-char (point-max)))
2874 (gnus-put-text-property from (point) 'face field-face))))))))
2876 (defun gnus-article-highlight-signature ()
2877 "Highlight the signature in an article.
2878 It does this by highlighting everything after
2879 `gnus-signature-separator' using `gnus-signature-face'."
2882 (set-buffer gnus-article-buffer)
2883 (let ((buffer-read-only nil)
2884 (inhibit-point-motion-hooks t))
2886 (when (and gnus-signature-face
2887 (gnus-article-narrow-to-signature))
2888 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2889 'face gnus-signature-face)
2891 (gnus-article-search-signature)
2892 (let ((start (match-beginning 0))
2893 (end (set-marker (make-marker) (1+ (match-end 0)))))
2894 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2897 (defun gnus-button-in-region-p (b e prop)
2898 "Say whether PROP exists in the region."
2899 (text-property-not-all b e prop nil))
2901 (defun gnus-article-add-buttons (&optional force)
2902 "Find external references in the article and make buttons of them.
2903 \"External references\" are things like Message-IDs and URLs, as
2904 specified by `gnus-button-alist'."
2905 (interactive (list 'force))
2907 (set-buffer gnus-article-buffer)
2908 (let ((buffer-read-only nil)
2909 (inhibit-point-motion-hooks t)
2910 (case-fold-search t)
2911 (alist gnus-button-alist)
2913 ;; Remove all old markers.
2915 (while (setq marker (pop gnus-button-marker-list))
2917 (when (setq entry (gnus-button-entry))
2918 (put-text-property (match-beginning (nth 1 entry))
2919 (match-end (nth 1 entry))
2920 'gnus-callback nil))
2921 (set-marker marker nil)))
2922 ;; We skip the headers.
2923 (goto-char (point-min))
2924 (unless (search-forward "\n\n" nil t)
2925 (goto-char (point-max)))
2927 (while (setq entry (pop alist))
2928 (setq regexp (car entry))
2930 (while (re-search-forward regexp nil t)
2931 (let* ((start (and entry (match-beginning (nth 1 entry))))
2932 (end (and entry (match-end (nth 1 entry))))
2933 (from (match-beginning 0)))
2934 (when (and (or (eq t (nth 2 entry))
2935 (eval (nth 2 entry)))
2936 (not (gnus-button-in-region-p
2937 start end 'gnus-callback)))
2938 ;; That optional form returned non-nil, so we add the
2940 (gnus-article-add-button
2941 start end 'gnus-button-push
2942 (car (push (set-marker (make-marker) from)
2943 gnus-button-marker-list))))))))))
2945 ;; Add buttons to the head of an article.
2946 (defun gnus-article-add-buttons-to-head ()
2947 "Add buttons to the head of the article."
2950 (set-buffer gnus-article-buffer)
2951 (let ((buffer-read-only nil)
2952 (inhibit-point-motion-hooks t)
2953 (case-fold-search t)
2954 (alist gnus-header-button-alist)
2956 (nnheader-narrow-to-headers)
2958 ;; Each alist entry.
2959 (setq entry (car alist)
2961 (goto-char (point-min))
2962 (while (re-search-forward (car entry) nil t)
2963 ;; Each header matching the entry.
2964 (setq beg (match-beginning 0))
2965 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2966 (match-beginning 0))
2969 (while (re-search-forward (nth 1 entry) end t)
2970 ;; Each match within a header.
2971 (let* ((entry (cdr entry))
2972 (start (match-beginning (nth 1 entry)))
2973 (end (match-end (nth 1 entry)))
2974 (form (nth 2 entry)))
2975 (goto-char (match-end 0))
2977 (gnus-article-add-button
2978 start end (nth 3 entry)
2979 (buffer-substring (match-beginning (nth 4 entry))
2980 (match-end (nth 4 entry)))))))
2984 ;;; External functions:
2986 (defun gnus-article-add-button (from to fun &optional data)
2987 "Create a button between FROM and TO with callback FUN and data DATA."
2988 (when gnus-article-button-face
2989 (gnus-overlay-put (gnus-make-overlay from to)
2990 'face gnus-article-button-face))
2991 (gnus-add-text-properties
2993 (nconc (and gnus-article-mouse-face
2994 (list gnus-mouse-face-prop gnus-article-mouse-face))
2995 (list 'gnus-callback fun)
2996 (and data (list 'gnus-data data)))))
2998 ;;; Internal functions:
3000 (defun gnus-article-set-globals ()
3002 (set-buffer gnus-summary-buffer)
3003 (gnus-set-global-variables)))
3005 (defun gnus-signature-toggle (end)
3007 (set-buffer gnus-article-buffer)
3008 (let ((buffer-read-only nil)
3009 (inhibit-point-motion-hooks t))
3010 (if (get-text-property end 'invisible)
3011 (gnus-article-unhide-text end (point-max))
3012 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3014 (defun gnus-button-entry ()
3015 ;; Return the first entry in `gnus-button-alist' matching this place.
3016 (let ((alist gnus-button-alist)
3019 (setq entry (pop alist))
3020 (if (looking-at (car entry))
3025 (defun gnus-button-push (marker)
3026 ;; Push button starting at MARKER.
3028 (set-buffer gnus-article-buffer)
3030 (let* ((entry (gnus-button-entry))
3031 (inhibit-point-motion-hooks t)
3033 (args (mapcar (lambda (group)
3034 (let ((string (match-string group)))
3035 (gnus-set-text-properties
3036 0 (length string) nil string)
3043 (fboundp (symbol-value fun)))
3044 (apply (symbol-value fun) args))
3046 (gnus-message 1 "You must define `%S' to use this button"
3047 (cons fun args)))))))
3049 (defun gnus-button-message-id (message-id)
3052 (set-buffer gnus-summary-buffer)
3053 (gnus-summary-refer-article message-id)))
3055 (defun gnus-button-fetch-group (address)
3056 "Fetch GROUP specified by ADDRESS."
3057 (if (not (string-match "[:/]" address))
3058 ;; This is just a simple group url.
3059 (gnus-group-read-ephemeral-group address gnus-select-method)
3060 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3062 (error "Can't parse %s" address)
3063 (gnus-group-read-ephemeral-group
3064 (match-string 4 address)
3065 `(nntp ,(match-string 1 address)
3066 (nntp-address ,(match-string 1 address))
3067 (nntp-port-number ,(if (match-end 3)
3068 (match-string 3 address)
3071 (defun gnus-split-string (string pattern)
3072 "Return a list of substrings of STRING which are separated by PATTERN."
3073 (let (parts (start 0))
3074 (while (string-match pattern string start)
3075 (setq parts (cons (substring string start (match-beginning 0)) parts)
3076 start (match-end 0)))
3077 (nreverse (cons (substring string start) parts))))
3079 (defun gnus-url-parse-query-string (query &optional downcase)
3080 (let (retval pairs cur key val)
3081 (setq pairs (gnus-split-string query "&"))
3083 (setq cur (car pairs)
3085 (if (not (string-match "=" cur))
3087 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3088 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3090 (setq key (downcase key)))
3091 (setq cur (assoc key retval))
3093 (setcdr cur (cons val (cdr cur)))
3094 (setq retval (cons (list key val) retval)))))
3097 (defun gnus-url-unhex (x)
3104 (defun gnus-url-unhex-string (str &optional allow-newlines)
3105 "Remove %XXX embedded spaces, etc in a url.
3106 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3107 decoding of carriage returns and line feeds in the string, which is normally
3108 forbidden in URL encoding."
3109 (setq str (or str ""))
3111 (case-fold-search t))
3112 (while (string-match "%[0-9a-f][0-9a-f]" str)
3113 (let* ((start (match-beginning 0))
3114 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3116 (gnus-url-unhex (elt str (+ start 2))))))
3118 tmp (substring str 0 start)
3121 (char-to-string code))
3122 ((or (= code ?\n) (= code ?\r))
3124 (t (char-to-string code))))
3125 str (substring str (match-end 0)))))
3126 (setq tmp (concat tmp str))
3129 (defun gnus-url-mailto (url)
3130 ;; Send mail to someone
3131 (when (string-match "mailto:/*\\(.*\\)" url)
3132 (setq url (substring url (match-beginning 1) nil)))
3133 (let (to args source-url subject func)
3134 (if (string-match (regexp-quote "?") url)
3135 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3136 args (gnus-url-parse-query-string
3137 (substring url (match-end 0) nil) t))
3138 (setq to (gnus-url-unhex-string url)))
3139 (setq args (cons (list "to" to) args)
3140 subject (cdr-safe (assoc "subject" args)))
3143 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3146 (message-position-on-field (caar args)))
3147 (insert (mapconcat 'identity (cdar args) ", "))
3148 (setq args (cdr args)))
3151 (message-goto-subject))))
3153 (defun gnus-button-mailto (address)
3155 (set-buffer (gnus-copy-article-buffer))
3156 (message-reply address))
3158 (defun gnus-button-reply (address)
3159 ;; Reply to ADDRESS.
3160 (message-reply address))
3162 (defun gnus-button-url (address)
3164 (funcall browse-url-browser-function address))
3166 (defun gnus-button-embedded-url (address)
3168 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3170 ;;; Next/prev buttons in the article buffer.
3172 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3173 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3175 (defvar gnus-prev-page-map nil)
3176 (unless gnus-prev-page-map
3177 (setq gnus-prev-page-map (make-sparse-keymap))
3178 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3179 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3181 (defun gnus-insert-prev-page-button ()
3182 (let ((buffer-read-only nil))
3184 gnus-prev-page-line-format nil
3185 `(gnus-prev t local-map ,gnus-prev-page-map
3186 gnus-callback gnus-article-button-prev-page))))
3188 (defvar gnus-next-page-map nil)
3189 (unless gnus-next-page-map
3190 (setq gnus-next-page-map (make-keymap))
3191 (suppress-keymap gnus-prev-page-map)
3192 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3193 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3195 (defun gnus-button-next-page ()
3196 "Go to the next page."
3198 (let ((win (selected-window)))
3199 (select-window (get-buffer-window gnus-article-buffer t))
3200 (gnus-article-next-page)
3201 (select-window win)))
3203 (defun gnus-button-prev-page ()
3204 "Go to the prev page."
3206 (let ((win (selected-window)))
3207 (select-window (get-buffer-window gnus-article-buffer t))
3208 (gnus-article-prev-page)
3209 (select-window win)))
3211 (defun gnus-insert-next-page-button ()
3212 (let ((buffer-read-only nil))
3213 (gnus-eval-format gnus-next-page-line-format nil
3214 `(gnus-next t local-map ,gnus-next-page-map
3216 gnus-article-button-next-page))))
3218 (defun gnus-article-button-next-page (arg)
3219 "Go to the next page."
3221 (let ((win (selected-window)))
3222 (select-window (get-buffer-window gnus-article-buffer t))
3223 (gnus-article-next-page)
3224 (select-window win)))
3226 (defun gnus-article-button-prev-page (arg)
3227 "Go to the prev page."
3229 (let ((win (selected-window)))
3230 (select-window (get-buffer-window gnus-article-buffer t))
3231 (gnus-article-prev-page)
3232 (select-window win)))
3238 (run-hooks 'gnus-art-load-hook)
3240 ;;; gnus-art.el ends here