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"
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 number function regexp)
159 :group 'gnus-article-signature)
161 (defcustom gnus-hidden-properties '(invisible t intangible t)
162 "Property list to use for hiding text."
164 :group 'gnus-article-hiding)
166 (defcustom gnus-article-x-face-command
167 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
168 "String or function to be executed to display an X-Face header.
169 If it is a string, the command will be executed in a sub-shell
170 asynchronously. The compressed face will be piped to this command."
171 :type 'string ;Leave function case to Lisp.
172 :group 'gnus-article-washing)
174 (defcustom gnus-article-x-face-too-ugly nil
175 "Regexp matching posters whose face shouldn't be shown automatically."
176 :type '(choice regexp (const nil))
177 :group 'gnus-article-washing)
179 (defcustom gnus-emphasis-alist
181 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
183 '(("_" "_" underline)
186 ("_/" "/_" underline-italic)
187 ("_\\*" "\\*_" underline-bold)
188 ("\\*/" "/\\*" bold-italic)
189 ("_\\*/" "/\\*_" underline-bold-italic))))
190 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
191 2 3 gnus-emphasis-underline)
195 (format format (car spec) (cadr spec))
196 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
198 "Alist that says how to fontify certain phrases.
199 Each item looks like this:
201 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
203 The first element is a regular expression to be matched. The second
204 is a number that says what regular expression grouping used to find
205 the entire emphasized word. The third is a number that says what
206 regexp grouping should be displayed and highlighted. The fourth
207 is the face used for highlighting."
208 :type '(repeat (list :value ("" 0 0 default)
210 (integer :tag "Match group")
211 (integer :tag "Emphasize group")
213 :group 'gnus-article-emphasis)
215 (defface gnus-emphasis-bold '((t (:bold t)))
216 "Face used for displaying strong emphasized text (*word*)."
217 :group 'gnus-article-emphasis)
219 (defface gnus-emphasis-italic '((t (:italic t)))
220 "Face used for displaying italic emphasized text (/word/)."
221 :group 'gnus-article-emphasis)
223 (defface gnus-emphasis-underline '((t (:underline t)))
224 "Face used for displaying underlined emphasized text (_word_)."
225 :group 'gnus-article-emphasis)
227 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
228 "Face used for displaying underlined bold emphasized text (_*word*_)."
229 :group 'gnus-article-emphasis)
231 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
232 "Face used for displaying underlined italic emphasized text (_*word*_)."
233 :group 'gnus-article-emphasis)
235 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
236 "Face used for displaying bold italic emphasized text (/*word*/)."
237 :group 'gnus-article-emphasis)
239 (defface gnus-emphasis-underline-bold-italic
240 '((t (:bold t :italic t :underline t)))
241 "Face used for displaying underlined bold italic emphasized text.
242 Esample: (_/*word*/_)."
243 :group 'gnus-article-emphasis)
245 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
246 "Format for display of Date headers in article bodies.
247 See `format-time-string' for the possible values."
249 :link '(custom-manual "(gnus)Article Date")
250 :group 'gnus-article-washing)
253 (autoload 'hexl-hex-string-to-integer "hexl")
254 (autoload 'timezone-make-date-arpa-standard "timezone")
255 (autoload 'mail-extract-address-components "mail-extr"))
257 (defcustom gnus-save-all-headers t
258 "*If non-nil, don't remove any headers before saving."
259 :group 'gnus-article-saving
262 (defcustom gnus-prompt-before-saving 'always
263 "*This variable says how much prompting is to be done when saving articles.
264 If it is nil, no prompting will be done, and the articles will be
265 saved to the default files. If this variable is `always', each and
266 every article that is saved will be preceded by a prompt, even when
267 saving large batches of articles. If this variable is neither nil not
268 `always', there the user will be prompted once for a file name for
269 each invocation of the saving commands."
270 :group 'gnus-article-saving
271 :type '(choice (item always)
272 (item :tag "never" nil)
273 (sexp :tag "once" :format "%t")))
275 (defcustom gnus-saved-headers gnus-visible-headers
276 "Headers to keep if `gnus-save-all-headers' is nil.
277 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
278 If that variable is nil, however, all headers that match this regexp
279 will be kept while the rest will be deleted before saving."
280 :group 'gnus-article-saving
283 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
284 "A function to save articles in your favourite format.
285 The function must be interactively callable (in other words, it must
286 be an Emacs command).
288 Gnus provides the following functions:
290 * gnus-summary-save-in-rmail (Rmail format)
291 * gnus-summary-save-in-mail (Unix mail format)
292 * gnus-summary-save-in-folder (MH folder)
293 * gnus-summary-save-in-file (article format)
294 * gnus-summary-save-in-vm (use VM's folder format)
295 * gnus-summary-write-to-file (article format -- overwrite)."
296 :group 'gnus-article-saving
297 :type '(radio (function-item gnus-summary-save-in-rmail)
298 (function-item gnus-summary-save-in-mail)
299 (function-item gnus-summary-save-in-folder)
300 (function-item gnus-summary-save-in-file)
301 (function-item gnus-summary-save-in-vm)
302 (function-item gnus-summary-write-to-file)))
304 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
305 "A function generating a file name to save articles in Rmail format.
306 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
307 :group 'gnus-article-saving
310 (defcustom gnus-mail-save-name 'gnus-plain-save-name
311 "A function generating a file name to save articles in Unix mail format.
312 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
313 :group 'gnus-article-saving
316 (defcustom gnus-folder-save-name 'gnus-folder-save-name
317 "A function generating a file name to save articles in MH folder.
318 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
319 :group 'gnus-article-saving
322 (defcustom gnus-file-save-name 'gnus-numeric-save-name
323 "A function generating a file name to save articles in article format.
324 The function is called with NEWSGROUP, HEADERS, and optional
326 :group 'gnus-article-saving
329 (defcustom gnus-split-methods
330 '((gnus-article-archive-name)
331 (gnus-article-nndoc-name))
332 "Variable used to suggest where articles are to be saved.
333 For instance, if you would like to save articles related to Gnus in
334 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
335 you could set this variable to something like:
337 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
338 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
340 This variable is an alist where the where the key is the match and the
341 value is a list of possible files to save in if the match is non-nil.
343 If the match is a string, it is used as a regexp match on the
344 article. If the match is a symbol, that symbol will be funcalled
345 from the buffer of the article to be saved with the newsgroup as the
346 parameter. If it is a list, it will be evaled in the same buffer.
348 If this form or function returns a string, this string will be used as
349 a possible file name; and if it returns a non-nil list, that list will
350 be used as possible file names."
351 :group 'gnus-article-saving
352 :type '(repeat (choice (list function)
353 (cons regexp (repeat string))
356 (defcustom gnus-strict-mime t
357 "*If nil, MIME-decode even if there is no Mime-Version header."
358 :group 'gnus-article-mime
361 (defcustom gnus-show-mime-method 'metamail-buffer
362 "Function to process a MIME message.
363 The function is called from the article buffer."
364 :group 'gnus-article-mime
367 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
368 "*Function to decode MIME encoded words.
369 The function is called from the article buffer."
370 :group 'gnus-article-mime
373 (defcustom gnus-page-delimiter "^\^L"
374 "*Regexp describing what to use as article page delimiters.
375 The default value is \"^\^L\", which is a form linefeed at the
376 beginning of a line."
378 :group 'gnus-article-various)
380 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
381 "*The format specification for the article mode line.
382 See `gnus-summary-mode-line-format' for a closer description."
384 :group 'gnus-article-various)
386 (defcustom gnus-article-mode-hook nil
387 "*A hook for Gnus article mode."
389 :group 'gnus-article-various)
391 (defcustom gnus-article-menu-hook nil
392 "*Hook run after the creation of the article mode menu."
394 :group 'gnus-article-various)
396 (defcustom gnus-article-prepare-hook nil
397 "*A hook called after an article has been prepared in the article buffer.
398 If you want to run a special decoding program like nkf, use this hook."
400 :group 'gnus-article-various)
402 (defcustom gnus-article-hide-pgp-hook nil
403 "*A hook called after successfully hiding a PGP signature."
405 :group 'gnus-article-various)
407 (defcustom gnus-article-button-face 'bold
408 "Face used for highlighting buttons in the article buffer.
410 An article button is a piece of text that you can activate by pressing
411 `RET' or `mouse-2' above it."
413 :group 'gnus-article-buttons)
415 (defcustom gnus-article-mouse-face 'highlight
416 "Face used for mouse highlighting in the article buffer.
418 Article buttons will be displayed in this face when the cursor is
421 :group 'gnus-article-buttons)
423 (defcustom gnus-signature-face 'gnus-signature-face
424 "Face used for highlighting a signature in the article buffer.
425 Obsolete; use the face `gnus-signature-face' for customizations instead."
427 :group 'gnus-article-highlight
428 :group 'gnus-article-signature)
430 (defface gnus-signature-face
433 "Face used for highlighting a signature in the article buffer."
434 :group 'gnus-article-highlight
435 :group 'gnus-article-signature)
437 (defface gnus-header-from-face
440 (:foreground "spring green" :bold t))
443 (:foreground "red3" :bold t))
445 (:bold t :italic t)))
446 "Face used for displaying from headers."
447 :group 'gnus-article-headers
448 :group 'gnus-article-highlight)
450 (defface gnus-header-subject-face
453 (:foreground "SeaGreen3" :bold t))
456 (:foreground "red4" :bold t))
458 (:bold t :italic t)))
459 "Face used for displaying subject headers."
460 :group 'gnus-article-headers
461 :group 'gnus-article-highlight)
463 (defface gnus-header-newsgroups-face
466 (:foreground "yellow" :bold t :italic t))
469 (:foreground "MidnightBlue" :bold t :italic t))
471 (:bold t :italic t)))
472 "Face used for displaying newsgroups headers."
473 :group 'gnus-article-headers
474 :group 'gnus-article-highlight)
476 (defface gnus-header-name-face
479 (:foreground "SeaGreen"))
482 (:foreground "maroon"))
485 "Face used for displaying header names."
486 :group 'gnus-article-headers
487 :group 'gnus-article-highlight)
489 (defface gnus-header-content-face
492 (:foreground "forest green" :italic t))
495 (:foreground "indianred4" :italic t))
497 (:italic t))) "Face used for displaying header content."
498 :group 'gnus-article-headers
499 :group 'gnus-article-highlight)
501 (defcustom gnus-header-face-alist
502 '(("From" nil gnus-header-from-face)
503 ("Subject" nil gnus-header-subject-face)
504 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
505 ("" gnus-header-name-face gnus-header-content-face))
506 "Controls highlighting of article header.
508 An alist of the form (HEADER NAME CONTENT).
510 HEADER is a regular expression which should match the name of an
511 header header and NAME and CONTENT are either face names or nil.
513 The name of each header field will be displayed using the face
514 specified by the first element in the list where HEADER match the
515 header name and NAME is non-nil. Similarly, the content will be
516 displayed by the first non-nil matching CONTENT face."
517 :group 'gnus-article-headers
518 :group 'gnus-article-highlight
519 :type '(repeat (list (regexp :tag "Header")
521 (item :tag "skip" nil)
522 (face :value default))
523 (choice :tag "Content"
524 (item :tag "skip" nil)
525 (face :value default)))))
527 ;;; Internal variables
529 (defvar article-lapsed-timer nil)
531 (defvar gnus-article-mode-syntax-table
532 (let ((table (copy-syntax-table text-mode-syntax-table)))
533 (modify-syntax-entry ?- "w" table)
534 (modify-syntax-entry ?> ")" table)
535 (modify-syntax-entry ?< "(" table)
537 "Syntax table used in article mode buffers.
538 Initialized from `text-mode-syntax-table.")
540 (defvar gnus-save-article-buffer nil)
542 (defvar gnus-article-mode-line-format-alist
543 (nconc '((?w (gnus-article-wash-status) ?s))
544 gnus-summary-mode-line-format-alist))
546 (defvar gnus-number-of-articles-to-be-saved nil)
548 (defvar gnus-inhibit-hiding nil)
550 (defsubst gnus-article-hide-text (b e props)
551 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
552 (add-text-properties b e props)
553 (when (memq 'intangible props)
555 (max (1- b) (point-min))
556 b 'intangible (cddr (memq 'intangible props)))))
558 (defsubst gnus-article-unhide-text (b e)
559 "Remove hidden text properties from region between B and E."
560 (remove-text-properties b e gnus-hidden-properties)
561 (when (memq 'intangible gnus-hidden-properties)
562 (put-text-property (max (1- b) (point-min))
565 (defun gnus-article-hide-text-type (b e type)
566 "Hide text of TYPE between B and E."
567 (gnus-article-hide-text
568 b e (cons 'article-type (cons type gnus-hidden-properties))))
570 (defun gnus-article-unhide-text-type (b e type)
571 "Hide text of TYPE between B and E."
572 (remove-text-properties
573 b e (cons 'article-type (cons type gnus-hidden-properties)))
574 (when (memq 'intangible gnus-hidden-properties)
575 (put-text-property (max (1- b) (point-min))
578 (defun gnus-article-hide-text-of-type (type)
579 "Hide text of TYPE in the current buffer."
581 (let ((b (point-min))
583 (while (setq b (text-property-any b e 'article-type type))
584 (add-text-properties b (incf b) gnus-hidden-properties)))))
586 (defun gnus-article-delete-text-of-type (type)
587 "Delete text of TYPE in the current buffer."
589 (let ((b (point-min)))
590 (while (setq b (text-property-any b (point-max) 'article-type type))
592 b (or (text-property-not-all b (point-max) 'article-type type)
595 (defun gnus-article-delete-invisible-text ()
596 "Delete all invisible text in the current buffer."
598 (let ((b (point-min)))
599 (while (setq b (text-property-any b (point-max) 'invisible t))
601 b (or (text-property-not-all b (point-max) 'invisible t)
604 (defun gnus-article-text-type-exists-p (type)
605 "Say whether any text of type TYPE exists in the buffer."
606 (text-property-any (point-min) (point-max) 'article-type type))
608 (defsubst gnus-article-header-rank ()
609 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
610 (let ((list gnus-sorted-header-list)
613 (when (looking-at (car list))
615 (setq list (cdr list))
619 (defun article-hide-headers (&optional arg delete)
620 "Toggle whether to hide unwanted headers and possibly sort them as well.
621 If given a negative prefix, always show; if given a positive prefix,
623 (interactive (gnus-article-hidden-arg))
625 (if (gnus-article-check-hidden-text 'headers arg)
626 ;; Show boring headers as well.
627 (gnus-article-show-hidden-text 'boring-headers)
628 ;; This function might be inhibited.
629 (unless gnus-inhibit-hiding
632 (let ((buffer-read-only nil)
633 (props (nconc (list 'article-type 'headers)
634 gnus-hidden-properties))
635 (max (1+ (length gnus-sorted-header-list)))
636 (ignored (when (not gnus-visible-headers)
637 (cond ((stringp gnus-ignored-headers)
638 gnus-ignored-headers)
639 ((listp gnus-ignored-headers)
640 (mapconcat 'identity gnus-ignored-headers
643 (cond ((stringp gnus-visible-headers)
644 gnus-visible-headers)
645 ((and gnus-visible-headers
646 (listp gnus-visible-headers))
647 (mapconcat 'identity gnus-visible-headers "\\|"))))
648 (inhibit-point-motion-hooks t)
650 ;; First we narrow to just the headers.
652 (goto-char (point-min))
653 ;; Hide any "From " lines at the beginning of (mail) articles.
654 (while (looking-at "From ")
658 (delete-region (point-min) (point))
659 (gnus-article-hide-text (point-min) (point) props)))
660 ;; Then treat the rest of the header lines.
663 (if (search-forward "\n\n" nil t) ; if there's a body
664 (progn (forward-line -1) (point))
666 ;; Then we use the two regular expressions
667 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
668 ;; select which header lines is to remain visible in the
670 (goto-char (point-min))
671 (while (re-search-forward "^[^ \t]*:" nil t)
673 ;; Mark the rank of the header.
675 (point) (1+ (point)) 'message-rank
676 (if (or (and visible (looking-at visible))
678 (not (looking-at ignored))))
679 (gnus-article-header-rank)
682 (message-sort-headers-1)
683 (when (setq beg (text-property-any
684 (point-min) (point-max) 'message-rank (+ 2 max)))
685 ;; We make the unwanted headers invisible.
687 (delete-region beg (point-max))
688 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
689 (gnus-article-hide-text-type beg (point-max) 'headers))
690 ;; Work around XEmacs lossage.
691 (put-text-property (point-min) beg 'invisible nil))))))))
693 (defun article-hide-boring-headers (&optional arg)
694 "Toggle hiding of headers that aren't very interesting.
695 If given a negative prefix, always show; if given a positive prefix,
697 (interactive (gnus-article-hidden-arg))
698 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
699 (not gnus-show-all-headers))
702 (let ((buffer-read-only nil)
703 (list gnus-boring-article-headers)
704 (inhibit-point-motion-hooks t)
706 (nnheader-narrow-to-headers)
708 (setq elem (pop list))
709 (goto-char (point-min))
711 ;; Hide empty headers.
713 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
715 (gnus-article-hide-text-type
716 (progn (beginning-of-line) (point))
719 (if (re-search-forward "^[^ \t]" nil t)
723 ;; Hide boring Newsgroups header.
724 ((eq elem 'newsgroups)
725 (when (equal (gnus-fetch-field "newsgroups")
726 (gnus-group-real-name
727 (if (boundp 'gnus-newsgroup-name)
730 (gnus-article-hide-header "newsgroups")))
731 ((eq elem 'followup-to)
732 (when (equal (message-fetch-field "followup-to")
733 (message-fetch-field "newsgroups"))
734 (gnus-article-hide-header "followup-to")))
736 (let ((from (message-fetch-field "from"))
737 (reply-to (message-fetch-field "reply-to")))
742 (nth 1 (mail-extract-address-components from))
743 (nth 1 (mail-extract-address-components reply-to)))))
744 (gnus-article-hide-header "reply-to"))))
746 (let ((date (message-fetch-field "date")))
748 (< (gnus-days-between (current-time-string) date)
750 (gnus-article-hide-header "date"))))
752 (let ((to (message-fetch-field "to")))
753 (when (> (length to) 1024)
754 (gnus-article-hide-header "to"))))
757 (goto-char (point-min))
758 (while (re-search-forward "^to:" nil t)
759 (setq to-count (1+ to-count)))
761 (while (> to-count 0)
762 (goto-char (point-min))
764 (re-search-forward "^to:" nil nil to-count)
766 (narrow-to-region (point) (point-max))
767 (gnus-article-hide-header "to"))
768 (setq to-count (1- to-count)))))))))))))
770 (defun gnus-article-hide-header (header)
772 (goto-char (point-min))
773 (when (re-search-forward (concat "^" header ":") nil t)
774 (gnus-article-hide-text-type
775 (progn (beginning-of-line) (point))
778 (if (re-search-forward "^[^ \t]" nil t)
783 (defun article-treat-dumbquotes ()
784 "Translate M******** sm*rtq**t*s into proper text."
786 (article-translate-characters "\221\222\223\223" "`'\"\""))
788 (defun article-translate-characters (from to)
789 "Translate all characters in the body of the article according to FROM and TO.
790 FROM is a string of characters to translate from; to is a string of
791 characters to translate to."
793 (goto-char (point-min))
794 (when (search-forward "\n\n" nil t)
795 (let ((buffer-read-only nil)
796 (x (make-string 225 ?x))
798 (while (< (incf i) (length x))
801 (while (< i (length from))
802 (aset x (aref from i) (aref to i))
804 (translate-region (point) (point-max) x)))))
806 (defun article-treat-overstrike ()
807 "Translate overstrikes into bold text."
810 (goto-char (point-min))
811 (when (search-forward "\n\n" nil t)
812 (let ((buffer-read-only nil))
813 (while (search-forward "\b" nil t)
814 (let ((next (following-char))
815 (previous (char-after (- (point) 2))))
816 ;; We do the boldification/underlining by hiding the
817 ;; overstrikes and putting the proper text property
821 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
822 (put-text-property (point) (1+ (point)) 'face 'bold))
824 (gnus-article-hide-text-type
825 (1- (point)) (1+ (point)) 'overstrike)
827 (- (point) 2) (1- (point)) 'face 'underline))
829 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
831 (point) (1+ (point)) 'face 'underline)))))))))
833 (defun article-fill ()
834 "Format too long lines."
837 (let ((buffer-read-only nil))
839 (goto-char (point-min))
840 (search-forward "\n\n" nil t)
842 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
843 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
844 (adaptive-fill-mode t))
846 (and (>= (current-column) (min fill-column (window-width)))
847 (/= (preceding-char) ?:)
848 (fill-paragraph nil))
851 (defun article-remove-cr ()
852 "Remove carriage returns from an article."
855 (let ((buffer-read-only nil))
856 (goto-char (point-min))
857 (while (search-forward "\r" nil t)
858 (replace-match "" t t)))))
860 (defun article-remove-trailing-blank-lines ()
861 "Remove all trailing blank lines from the article."
864 (let ((buffer-read-only nil))
865 (goto-char (point-max))
869 (while (and (not (bobp))
870 (looking-at "^[ \t]*$"))
875 (defun article-display-x-face (&optional force)
876 "Look for an X-Face header and display it if present."
877 (interactive (list 'force))
879 ;; Delete the old process, if any.
880 (when (process-status "article-x-face")
881 (delete-process "article-x-face"))
882 (let ((inhibit-point-motion-hooks t)
886 (nnheader-narrow-to-headers)
887 (setq from (message-fetch-field "from"))
888 (goto-char (point-min))
889 (while (and gnus-article-x-face-command
891 ;; Check whether this face is censored.
892 (not gnus-article-x-face-too-ugly)
893 (and gnus-article-x-face-too-ugly from
894 (not (string-match gnus-article-x-face-too-ugly
896 ;; Has to be present.
897 (re-search-forward "^X-Face: " nil t))
898 ;; We now have the area of the buffer where the X-Face is stored.
901 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
902 ;; We display the face.
903 (if (symbolp gnus-article-x-face-command)
904 ;; The command is a lisp function, so we call it.
905 (if (gnus-functionp gnus-article-x-face-command)
906 (funcall gnus-article-x-face-command beg end)
907 (error "%s is not a function" gnus-article-x-face-command))
908 ;; The command is a string, so we interpret the command
909 ;; as a, well, command, and fork it off.
910 (let ((process-connection-type nil))
911 (process-kill-without-query
913 "article-x-face" nil shell-file-name shell-command-switch
914 gnus-article-x-face-command))
915 (process-send-region "article-x-face" beg end)
916 (process-send-eof "article-x-face"))))))))))
918 (defun gnus-hack-decode-rfc1522 ()
919 "Emergency hack function for avoiding problems when decoding."
920 (let ((buffer-read-only nil))
921 (goto-char (point-min))
922 ;; Remove encoded TABs.
923 (while (search-forward "=09" nil t)
924 (replace-match " " t t))
925 ;; Remove encoded newlines.
926 (goto-char (point-min))
927 (while (search-forward "=10" nil t)
928 (replace-match " " t t))))
930 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
931 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
932 (defun article-decode-rfc1522 ()
933 "Hack to remove QP encoding from headers."
934 (let ((case-fold-search t)
935 (inhibit-point-motion-hooks t)
936 (buffer-read-only nil)
940 (goto-char (point-min))
941 (or (search-forward "\n\n" nil t) (point-max)))
942 (goto-char (point-min))
943 (while (re-search-forward
944 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
945 (setq string (match-string 1))
947 (narrow-to-region (match-beginning 0) (match-end 0))
948 (delete-region (point-min) (point-max))
950 (article-mime-decode-quoted-printable
951 (goto-char (point-min)) (point-max))
952 (subst-char-in-region (point-min) (point-max) ?_ ? )
953 (goto-char (point-max)))
954 (goto-char (point-min))))))
956 (defun article-de-quoted-unreadable (&optional force)
957 "Do a naive translation of a quoted-printable-encoded article.
958 This is in no way, shape or form meant as a replacement for real MIME
959 processing, but is simply a stop-gap measure until MIME support is
961 If FORCE, decode the article whether it is marked as quoted-printable
963 (interactive (list 'force))
965 (let ((case-fold-search t)
966 (buffer-read-only nil)
967 (type (gnus-fetch-field "content-transfer-encoding")))
968 (gnus-article-decode-rfc1522)
970 (and type (string-match "quoted-printable" (downcase type))))
971 (goto-char (point-min))
972 (search-forward "\n\n" nil 'move)
973 (article-mime-decode-quoted-printable (point) (point-max))))))
975 (defun article-mime-decode-quoted-printable-buffer ()
976 "Decode Quoted-Printable in the current buffer."
977 (article-mime-decode-quoted-printable (point-min) (point-max)))
979 (defun article-mime-decode-quoted-printable (from to)
980 "Decode Quoted-Printable in the region between FROM and TO."
983 (while (search-forward "=" to t)
984 (cond ((eq (following-char) ?\n)
987 ((looking-at "[0-9A-F][0-9A-F]")
988 (subst-char-in-region
989 (1- (point)) (point) ?=
990 (hexl-hex-string-to-integer
991 (buffer-substring (point) (+ 2 (point)))))
995 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
997 (defun article-hide-pgp (&optional arg)
998 "Toggle hiding of any PGP headers and signatures in the current article.
999 If given a negative prefix, always show; if given a positive prefix,
1001 (interactive (gnus-article-hidden-arg))
1002 (unless (gnus-article-check-hidden-text 'pgp arg)
1004 (let ((inhibit-point-motion-hooks t)
1005 buffer-read-only beg end)
1007 (goto-char (point-min))
1008 ;; Hide the "header".
1009 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1010 (gnus-article-hide-text-type (1+ (match-beginning 0))
1013 ;; Hide the actual signature.
1014 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1015 (setq end (1+ (match-beginning 0)))
1016 (gnus-article-hide-text-type
1018 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1020 ;; Perhaps we shouldn't hide to the end of the buffer
1021 ;; if there is no end to the signature?
1024 ;; Hide "- " PGP quotation markers.
1026 (narrow-to-region beg end)
1027 (goto-char (point-min))
1028 (while (re-search-forward "^- " nil t)
1029 (gnus-article-hide-text-type
1030 (match-beginning 0) (match-end 0) 'pgp))
1032 (run-hooks 'gnus-article-hide-pgp-hook))))))
1034 (defun article-hide-pem (&optional arg)
1035 "Toggle hiding of any PEM headers and signatures in the current article.
1036 If given a negative prefix, always show; if given a positive prefix,
1038 (interactive (gnus-article-hidden-arg))
1039 (unless (gnus-article-check-hidden-text 'pem arg)
1041 (let (buffer-read-only end)
1043 (goto-char (point-min))
1044 ;; hide the horrendously ugly "header".
1045 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1048 (setq end (1+ (match-beginning 0)))
1049 (gnus-article-hide-text-type
1051 (if (search-forward "\n\n" nil t)
1055 ;; hide the trailer as well
1056 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1059 (gnus-article-hide-text-type
1060 (match-beginning 0) (match-end 0) 'pem))))))
1062 (defun article-hide-signature (&optional arg)
1063 "Hide the signature in the current article.
1064 If given a negative prefix, always show; if given a positive prefix,
1066 (interactive (gnus-article-hidden-arg))
1067 (unless (gnus-article-check-hidden-text 'signature arg)
1070 (let ((buffer-read-only nil))
1071 (when (gnus-article-narrow-to-signature)
1072 (gnus-article-hide-text-type
1073 (point-min) (point-max) 'signature)))))))
1075 (defun article-strip-leading-blank-lines ()
1076 "Remove all blank lines from the beginning of the article."
1079 (let ((inhibit-point-motion-hooks t)
1081 (goto-char (point-min))
1082 (when (search-forward "\n\n" nil t)
1083 (while (and (not (eobp))
1084 (looking-at "[ \t]*$"))
1085 (gnus-delete-line))))))
1087 (defun article-strip-multiple-blank-lines ()
1088 "Replace consecutive blank lines with one empty line."
1091 (let ((inhibit-point-motion-hooks t)
1093 ;; First make all blank lines empty.
1094 (goto-char (point-min))
1095 (search-forward "\n\n" nil t)
1096 (while (re-search-forward "^[ \t]+$" nil t)
1097 (replace-match "" nil t))
1098 ;; Then replace multiple empty lines with a single empty line.
1099 (goto-char (point-min))
1100 (search-forward "\n\n" nil t)
1101 (while (re-search-forward "\n\n\n+" nil t)
1102 (replace-match "\n\n" t t)))))
1104 (defun article-strip-leading-space ()
1105 "Remove all white space from the beginning of the lines in the article."
1108 (let ((inhibit-point-motion-hooks t)
1110 (goto-char (point-min))
1111 (search-forward "\n\n" nil t)
1112 (while (re-search-forward "^[ \t]+" nil t)
1113 (replace-match "" t t)))))
1115 (defun article-strip-blank-lines ()
1116 "Strip leading, trailing and multiple blank lines."
1118 (article-strip-leading-blank-lines)
1119 (article-remove-trailing-blank-lines)
1120 (article-strip-multiple-blank-lines))
1122 (defvar mime::preview/content-list)
1123 (defvar mime::preview-content-info/point-min)
1124 (defun gnus-article-narrow-to-signature ()
1125 "Narrow to the signature; return t if a signature is found, else nil."
1127 (when (and (boundp 'mime::preview/content-list)
1128 mime::preview/content-list)
1129 ;; We have a MIMEish article, so we use the MIME data to narrow.
1130 (let ((pcinfo (car (last mime::preview/content-list))))
1133 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1136 (when (gnus-article-search-signature)
1138 ;; Check whether we have some limits to what we consider
1139 ;; to be a signature.
1140 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1141 (list gnus-signature-limit)))
1143 (while (setq limit (pop limits))
1144 (if (or (and (integerp limit)
1145 (< (- (point-max) (point)) limit))
1147 (< (count-lines (point) (point-max)) limit))
1148 (and (gnus-functionp limit)
1150 (and (stringp limit)
1151 (not (re-search-forward limit nil t))))
1152 () ; This limit did not succeed.
1156 (narrow-to-region (point) (point-max))
1159 (defun gnus-article-search-signature ()
1160 "Search the current buffer for the signature separator.
1161 Put point at the beginning of the signature separator."
1162 (let ((cur (point)))
1163 (goto-char (point-max))
1164 (if (if (stringp gnus-signature-separator)
1165 (re-search-backward gnus-signature-separator nil t)
1166 (let ((seps gnus-signature-separator))
1168 (not (re-search-backward (car seps) nil t)))
1176 (autoload 'w3-display "w3-parse")
1177 (autoload 'w3-do-setup "w3" "" t)
1178 (autoload 'w3-region "w3-display" "" t))
1180 (defun gnus-article-treat-html ()
1183 (let ((cbuf (current-buffer)))
1184 (set-buffer gnus-article-buffer)
1185 (let (buf buffer-read-only b e)
1187 (goto-char (point-min))
1189 (if (search-forward "\n\n" nil t)
1192 (setq e (point-max)))
1193 (nnheader-temp-write nil
1194 (insert-buffer-substring gnus-article-buffer b e)
1196 (save-window-excursion
1197 (w3-region (point-min) (point-max))
1198 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1200 (delete-region (point-min) (point-max))
1203 (goto-char (point-min))
1204 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1205 (set-buffer cbuf))))
1207 (defun gnus-article-hidden-arg ()
1208 "Return the current prefix arg as a number, or 0 if no prefix."
1209 (list (if current-prefix-arg
1210 (prefix-numeric-value current-prefix-arg)
1213 (defun gnus-article-check-hidden-text (type arg)
1214 "Return nil if hiding is necessary.
1215 Arg can be nil or a number. Nil and positive means hide, negative
1216 means show, 0 means toggle."
1220 (let ((hide (gnus-article-hidden-text-p type)))
1226 (gnus-article-show-hidden-text type))
1228 (if (eq hide 'hidden)
1229 (gnus-article-show-hidden-text type)
1232 (defun gnus-article-hidden-text-p (type)
1233 "Say whether the current buffer contains hidden text of type TYPE."
1234 (let ((start (point-min))
1235 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1237 (not (get-text-property pos 'invisible)))
1239 (text-property-any (1+ pos) (point-max) 'article-type type)))
1244 (defun gnus-article-show-hidden-text (type &optional hide)
1245 "Show all hidden text of type TYPE.
1246 If HIDE, hide the text instead."
1248 (let ((buffer-read-only nil)
1249 (inhibit-point-motion-hooks t)
1252 (while (setq beg (text-property-any end (point-max) 'article-type type))
1255 (text-property-not-all beg (point-max) 'article-type type)
1258 (gnus-article-hide-text beg end gnus-hidden-properties)
1259 (gnus-article-unhide-text beg end))
1263 (defconst article-time-units
1264 `((year . ,(* 365.25 24 60 60))
1265 (week . ,(* 7 24 60 60))
1266 (day . ,(* 24 60 60))
1270 "Mapping from time units to seconds.")
1272 (defun article-date-ut (&optional type highlight header)
1273 "Convert DATE date to universal time in the current article.
1274 If TYPE is `local', convert to local time; if it is `lapsed', output
1275 how much time has lapsed since DATE."
1276 (interactive (list 'ut t))
1277 (let* ((header (or header
1278 (mail-header-date gnus-current-headers)
1279 (message-fetch-field "date")
1281 (date (if (vectorp header) (mail-header-date header)
1283 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1284 (inhibit-point-motion-hooks t)
1285 bface eface newline)
1286 (when (and date (not (string= date "")))
1289 (nnheader-narrow-to-headers)
1290 (let ((buffer-read-only nil))
1291 ;; Delete any old Date headers.
1292 (if (re-search-forward date-regexp nil t)
1294 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1295 eface (get-text-property (1- (gnus-point-at-eol))
1297 (delete-region (progn (beginning-of-line) (point))
1298 (progn (end-of-line) (point)))
1299 (beginning-of-line))
1300 (goto-char (point-max))
1302 (insert (article-make-date-line date type))
1305 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1306 (put-text-property (match-beginning 1) (1+ (match-end 1))
1308 (put-text-property (match-beginning 2) (match-end 2)
1312 (insert "\n"))))))))
1314 (defun article-make-date-line (date type)
1315 "Return a DATE line of TYPE."
1317 ;; Convert to the local timezone. We have to slap a
1318 ;; `condition-case' round the calls to the timezone
1319 ;; functions since they aren't particularly resistant to
1322 (concat "Date: " (condition-case ()
1323 (timezone-make-date-arpa-standard date)
1325 ;; Convert to Universal Time.
1329 (timezone-make-date-arpa-standard date nil "UT")
1331 ;; Get the original date from the article.
1332 ((eq type 'original)
1333 (concat "Date: " date))
1334 ;; Let the user define the format.
1338 (format-time-string gnus-article-time-format
1341 (timezone-make-date-arpa-standard
1343 ;; Do an X-Sent lapsed format.
1345 ;; If the date is seriously mangled, the timezone functions are
1346 ;; liable to bug out, so we ignore all errors.
1347 (let* ((now (current-time))
1352 (timezone-make-date-arpa-standard
1353 (current-time-string now)
1354 (current-time-zone now) "UT"))
1356 (timezone-make-date-arpa-standard
1358 (real-sec (and real-time
1359 (+ (* (float (car real-time)) 65536)
1361 (sec (and real-time (abs real-sec)))
1365 "X-Sent: Unknown\n")
1371 ;; This is a bit convoluted, but basically we go
1372 ;; through the time units for years, weeks, etc,
1373 ;; and divide things to see whether that results
1374 ;; in positive answers.
1377 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1378 ;; The (remaining) seconds are too few to
1379 ;; be divided into this time unit.
1381 ;; It's big enough, so we output it.
1382 (setq sec (- sec (* num (cdr unit))))
1384 (concat (if prev ", " "") (int-to-string
1386 " " (symbol-name (car unit))
1387 (if (> num 1) "s" ""))
1389 article-time-units "")
1390 ;; If dates are odd, then it might appear like the
1391 ;; article was sent in the future.
1394 " in the future"))))))
1396 (error "Unknown conversion type: %s" type))))
1398 (defun article-date-local (&optional highlight)
1399 "Convert the current article date to the local timezone."
1400 (interactive (list t))
1401 (article-date-ut 'local highlight))
1403 (defun article-date-original (&optional highlight)
1404 "Convert the current article date to what it was originally.
1405 This is only useful if you have used some other date conversion
1406 function and want to see what the date was before converting."
1407 (interactive (list t))
1408 (article-date-ut 'original highlight))
1410 (defun article-date-lapsed (&optional highlight)
1411 "Convert the current article date to time lapsed since it was sent."
1412 (interactive (list t))
1413 (article-date-ut 'lapsed highlight))
1415 (defun article-update-date-lapsed ()
1416 "Function to be run from a timer to update the lapsed time line."
1419 (when (gnus-buffer-live-p gnus-article-buffer)
1420 (set-buffer gnus-article-buffer)
1421 (goto-char (point-min))
1422 (when (re-search-forward "^X-Sent:" nil t)
1423 (article-date-lapsed t))))))
1425 (defun gnus-start-date-timer (&optional n)
1426 "Start a timer to update the X-Sent header in the article buffers.
1427 The numerical prefix says how frequently (in seconds) the function
1432 (gnus-stop-date-timer)
1433 (setq article-lapsed-timer
1434 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1436 (defun gnus-stop-date-timer ()
1437 "Stop the X-Sent timer."
1439 (when article-lapsed-timer
1440 (nnheader-cancel-timer article-lapsed-timer)
1441 (setq article-lapsed-timer nil)))
1443 (defun article-date-user (&optional highlight)
1444 "Convert the current article date to the user-defined format.
1445 This format is defined by the `gnus-article-time-format' variable."
1446 (interactive (list t))
1447 (article-date-ut 'user highlight))
1449 (defun article-show-all ()
1450 "Show all hidden text in the article buffer."
1453 (let ((buffer-read-only nil))
1454 (gnus-article-unhide-text (point-min) (point-max)))))
1456 (defun article-emphasize (&optional arg)
1457 "Emphasize text according to `gnus-emphasis-alist'."
1458 (interactive (gnus-article-hidden-arg))
1459 (unless (gnus-article-check-hidden-text 'emphasis arg)
1461 (let ((alist gnus-emphasis-alist)
1462 (buffer-read-only nil)
1463 (props (append '(article-type emphasis)
1464 gnus-hidden-properties))
1465 regexp elem beg invisible visible face)
1466 (goto-char (point-min))
1467 (search-forward "\n\n" nil t)
1469 (while (setq elem (pop alist))
1471 (setq regexp (car elem)
1472 invisible (nth 1 elem)
1473 visible (nth 2 elem)
1475 (while (re-search-forward regexp nil t)
1476 (when (and (match-beginning visible) (match-beginning invisible))
1477 (gnus-article-hide-text
1478 (match-beginning invisible) (match-end invisible) props)
1479 (gnus-article-unhide-text-type
1480 (match-beginning visible) (match-end visible) 'emphasis)
1481 (gnus-put-text-property-excluding-newlines
1482 (match-beginning visible) (match-end visible) 'face face)
1483 (goto-char (match-end invisible)))))))))
1485 (defvar gnus-summary-article-menu)
1486 (defvar gnus-summary-post-menu)
1488 ;;; Saving functions.
1490 (defun gnus-article-save (save-buffer file &optional num)
1491 "Save the currently selected article."
1492 (unless gnus-save-all-headers
1493 ;; Remove headers according to `gnus-saved-headers'.
1494 (let ((gnus-visible-headers
1495 (or gnus-saved-headers gnus-visible-headers))
1496 (gnus-article-buffer save-buffer))
1498 (set-buffer save-buffer)
1499 (article-hide-headers 1 t))))
1500 (save-window-excursion
1501 (if (not gnus-default-article-saver)
1502 (error "No default saver is defined")
1503 ;; !!! Magic! The saving functions all save
1504 ;; `gnus-original-article-buffer' (or so they think), but we
1505 ;; bind that variable to our save-buffer.
1506 (set-buffer gnus-article-buffer)
1507 (let* ((gnus-save-article-buffer save-buffer)
1510 ((not gnus-prompt-before-saving) 'default)
1511 ((eq gnus-prompt-before-saving 'always) nil)
1513 (gnus-number-of-articles-to-be-saved
1514 (when (eq gnus-prompt-before-saving t)
1516 (set-buffer gnus-summary-buffer)
1517 (funcall gnus-default-article-saver filename)))))
1519 (defun gnus-read-save-file-name (prompt &optional filename
1520 function group headers variable)
1522 (funcall function group headers (symbol-value variable)))
1527 ((eq filename 'default)
1533 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1536 (if (and gnus-number-of-articles-to-be-saved
1537 (> gnus-number-of-articles-to-be-saved 1))
1538 (format "these %d articles"
1539 gnus-number-of-articles-to-be-saved)
1542 ;; Let the split methods have their say.
1544 ;; No split name was found.
1547 (concat prompt " (default "
1548 (file-name-nondirectory default-name) ") ")
1549 (file-name-directory default-name)
1551 ;; A single group name is returned.
1552 ((stringp split-name)
1554 (funcall function split-name headers
1555 (symbol-value variable)))
1557 (concat prompt " (default "
1558 (file-name-nondirectory default-name) ") ")
1559 (file-name-directory default-name)
1561 ;; A single split name was found
1562 ((= 1 (length split-name))
1563 (let* ((name (expand-file-name
1564 (car split-name) gnus-article-save-directory))
1565 (dir (cond ((file-directory-p name)
1566 (file-name-as-directory name))
1567 ((file-exists-p name) name)
1568 (t gnus-article-save-directory))))
1570 (concat prompt " (default " name ") ")
1572 ;; A list of splits was found.
1574 (setq split-name (nreverse split-name))
1576 (let ((file-name-history
1577 (nconc split-name file-name-history)))
1581 (concat prompt " (`M-p' for defaults) ")
1582 gnus-article-save-directory
1584 gnus-article-save-directory)))
1585 (car (push result file-name-history)))))))
1586 ;; Create the directory.
1587 (gnus-make-directory (file-name-directory file))
1588 ;; If we have read a directory, we append the default file name.
1589 (when (file-directory-p file)
1590 (setq file (concat (file-name-as-directory file)
1591 (file-name-nondirectory default-name))))
1592 ;; Possibly translate some characters.
1593 (nnheader-translate-file-chars file)))))
1594 (gnus-make-directory (file-name-directory result))
1595 (set variable result)))
1597 (defun gnus-article-archive-name (group)
1598 "Return the first instance of an \"Archive-name\" in the current buffer."
1599 (let ((case-fold-search t))
1600 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1601 (nnheader-concat gnus-article-save-directory
1602 (match-string 1)))))
1604 (defun gnus-article-nndoc-name (group)
1605 "If GROUP is an nndoc group, return the name of the parent group."
1606 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1607 (gnus-group-get-parameter group 'save-article-group)))
1609 (defun gnus-summary-save-in-rmail (&optional filename)
1610 "Append this article to Rmail file.
1611 Optional argument FILENAME specifies file name.
1612 Directory to save to is default to `gnus-article-save-directory'."
1614 (setq filename (gnus-read-save-file-name
1615 "Save %s in rmail file:" filename
1616 gnus-rmail-save-name gnus-newsgroup-name
1617 gnus-current-headers 'gnus-newsgroup-last-rmail))
1618 (gnus-eval-in-buffer-window gnus-save-article-buffer
1622 (gnus-output-to-rmail filename))))
1625 (defun gnus-summary-save-in-mail (&optional filename)
1626 "Append this article to Unix mail file.
1627 Optional argument FILENAME specifies file name.
1628 Directory to save to is default to `gnus-article-save-directory'."
1630 (setq filename (gnus-read-save-file-name
1631 "Save %s in Unix mail file:" filename
1632 gnus-mail-save-name gnus-newsgroup-name
1633 gnus-current-headers 'gnus-newsgroup-last-mail))
1634 (gnus-eval-in-buffer-window gnus-save-article-buffer
1638 (if (and (file-readable-p filename)
1639 (mail-file-babyl-p filename))
1640 (gnus-output-to-rmail filename t)
1641 (gnus-output-to-mail filename)))))
1644 (defun gnus-summary-save-in-file (&optional filename overwrite)
1645 "Append this article to file.
1646 Optional argument FILENAME specifies file name.
1647 Directory to save to is default to `gnus-article-save-directory'."
1649 (setq filename (gnus-read-save-file-name
1650 "Save %s in file:" filename
1651 gnus-file-save-name gnus-newsgroup-name
1652 gnus-current-headers 'gnus-newsgroup-last-file))
1653 (gnus-eval-in-buffer-window gnus-save-article-buffer
1657 (when (and overwrite
1658 (file-exists-p filename))
1659 (delete-file filename))
1660 (gnus-output-to-file filename))))
1663 (defun gnus-summary-write-to-file (&optional filename)
1664 "Write this article to a file.
1665 Optional argument FILENAME specifies file name.
1666 The directory to save in defaults to `gnus-article-save-directory'."
1668 (gnus-summary-save-in-file nil t))
1670 (defun gnus-summary-save-body-in-file (&optional filename)
1671 "Append this article body to a file.
1672 Optional argument FILENAME specifies file name.
1673 The directory to save in defaults to `gnus-article-save-directory'."
1675 (setq filename (gnus-read-save-file-name
1676 "Save %s body in file:" filename
1677 gnus-file-save-name gnus-newsgroup-name
1678 gnus-current-headers 'gnus-newsgroup-last-file))
1679 (gnus-eval-in-buffer-window gnus-save-article-buffer
1683 (goto-char (point-min))
1684 (when (search-forward "\n\n" nil t)
1685 (narrow-to-region (point) (point-max)))
1686 (gnus-output-to-file filename))))
1689 (defun gnus-summary-save-in-pipe (&optional command)
1690 "Pipe this article to subprocess."
1693 (cond ((eq command 'default)
1694 gnus-last-shell-command)
1698 "Shell command on %s: "
1699 (if (and gnus-number-of-articles-to-be-saved
1700 (> gnus-number-of-articles-to-be-saved 1))
1701 (format "these %d articles"
1702 gnus-number-of-articles-to-be-saved)
1704 gnus-last-shell-command))))
1705 (when (string-equal command "")
1706 (setq command gnus-last-shell-command))
1707 (gnus-eval-in-buffer-window gnus-article-buffer
1710 (shell-command-on-region (point-min) (point-max) command nil)))
1711 (setq gnus-last-shell-command command))
1713 ;;; Article file names when saving.
1715 (defun gnus-capitalize-newsgroup (newsgroup)
1716 "Capitalize NEWSGROUP name."
1717 (when (not (zerop (length newsgroup)))
1718 (concat (char-to-string (upcase (aref newsgroup 0)))
1719 (substring newsgroup 1))))
1721 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1722 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1723 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1724 Otherwise, it is like ~/News/news/group/num."
1727 (concat (if (gnus-use-long-file-name 'not-save)
1728 (gnus-capitalize-newsgroup newsgroup)
1729 (gnus-newsgroup-directory-form newsgroup))
1730 "/" (int-to-string (mail-header-number headers)))
1731 gnus-article-save-directory)))
1733 (string-equal (file-name-directory default)
1734 (file-name-directory last-file))
1735 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1737 (or last-file default))))
1739 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1740 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1741 If variable `gnus-use-long-file-name' is non-nil, it is
1742 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1745 (concat (if (gnus-use-long-file-name 'not-save)
1747 (gnus-newsgroup-directory-form newsgroup))
1748 "/" (int-to-string (mail-header-number headers)))
1749 gnus-article-save-directory)))
1751 (string-equal (file-name-directory default)
1752 (file-name-directory last-file))
1753 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1755 (or last-file default))))
1757 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1758 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1759 If variable `gnus-use-long-file-name' is non-nil, it is
1760 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1763 (if (gnus-use-long-file-name 'not-save)
1764 (gnus-capitalize-newsgroup newsgroup)
1765 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1766 gnus-article-save-directory)))
1768 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1769 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1770 If variable `gnus-use-long-file-name' is non-nil, it is
1771 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1774 (if (gnus-use-long-file-name 'not-save)
1776 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1777 gnus-article-save-directory)))
1784 (setq afunc (car func)
1787 gfunc (intern (format "gnus-%s" func))))
1789 (if (not (fboundp afunc))
1791 `(lambda (&optional interactive &rest args)
1792 ,(documentation afunc t)
1793 (interactive (list t))
1795 (set-buffer gnus-article-buffer)
1797 (call-interactively ',afunc)
1798 (apply ',afunc args))))))))
1799 '(article-hide-headers
1800 article-hide-boring-headers
1801 article-treat-overstrike
1802 (article-fill . gnus-article-word-wrap)
1804 article-display-x-face
1805 article-de-quoted-unreadable
1806 article-mime-decode-quoted-printable
1809 article-hide-signature
1810 article-remove-trailing-blank-lines
1811 article-strip-leading-blank-lines
1812 article-strip-multiple-blank-lines
1813 article-strip-leading-space
1814 article-strip-blank-lines
1816 article-date-original
1821 article-treat-dumbquotes
1822 (article-show-all . gnus-article-show-all-headers))))
1825 ;;; Gnus article mode
1828 (put 'gnus-article-mode 'mode-class 'special)
1830 (gnus-define-keys gnus-article-mode-map
1831 " " gnus-article-goto-next-page
1832 "\177" gnus-article-goto-prev-page
1833 [delete] gnus-article-goto-prev-page
1834 "\C-c^" gnus-article-refer-article
1835 "h" gnus-article-show-summary
1836 "s" gnus-article-show-summary
1837 "\C-c\C-m" gnus-article-mail
1838 "?" gnus-article-describe-briefly
1839 gnus-mouse-2 gnus-article-push-button
1840 "\r" gnus-article-press-button
1841 "\t" gnus-article-next-button
1842 "\M-\t" gnus-article-prev-button
1843 "e" gnus-article-edit
1844 "<" beginning-of-buffer
1846 "\C-c\C-i" gnus-info-find-node
1849 "\C-d" gnus-article-read-summary-keys
1850 "\M-*" gnus-article-read-summary-keys
1851 "\M-#" gnus-article-read-summary-keys
1852 "\M-^" gnus-article-read-summary-keys
1853 "\M-g" gnus-article-read-summary-keys)
1855 (substitute-key-definition
1856 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1858 (defun gnus-article-make-menu-bar ()
1859 (gnus-turn-off-edit-menu 'article)
1860 (unless (boundp 'gnus-article-article-menu)
1862 gnus-article-article-menu gnus-article-mode-map ""
1864 ["Scroll forwards" gnus-article-goto-next-page t]
1865 ["Scroll backwards" gnus-article-goto-prev-page t]
1866 ["Show summary" gnus-article-show-summary t]
1867 ["Fetch Message-ID at point" gnus-article-refer-article t]
1868 ["Mail to address at point" gnus-article-mail t]))
1871 gnus-article-treatment-menu gnus-article-mode-map ""
1873 ["Hide headers" gnus-article-hide-headers t]
1874 ["Hide signature" gnus-article-hide-signature t]
1875 ["Hide citation" gnus-article-hide-citation t]
1876 ["Treat overstrike" gnus-article-treat-overstrike t]
1877 ["Remove carriage return" gnus-article-remove-cr t]
1878 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1881 (when (boundp 'gnus-summary-article-menu)
1882 (define-key gnus-article-mode-map [menu-bar commands]
1883 (cons "Commands" gnus-summary-article-menu))))
1885 (when (boundp 'gnus-summary-post-menu)
1886 (define-key gnus-article-mode-map [menu-bar post]
1887 (cons "Post" gnus-summary-post-menu)))
1889 (run-hooks 'gnus-article-menu-hook)))
1891 (defun gnus-article-mode ()
1892 "Major mode for displaying an article.
1894 All normal editing commands are switched off.
1896 The following commands are available in addition to all summary mode
1898 \\<gnus-article-mode-map>
1899 \\[gnus-article-next-page]\t Scroll the article one page forwards
1900 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1901 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1902 \\[gnus-article-show-summary]\t Display the summary buffer
1903 \\[gnus-article-mail]\t Send a reply to the address near point
1904 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1905 \\[gnus-info-find-node]\t Go to the Gnus info node"
1907 (when (gnus-visual-p 'article-menu 'menu)
1908 (gnus-article-make-menu-bar))
1909 (kill-all-local-variables)
1910 (gnus-simplify-mode-line)
1911 (setq mode-name "Article")
1912 (setq major-mode 'gnus-article-mode)
1913 (make-local-variable 'minor-mode-alist)
1914 (unless (assq 'gnus-show-mime minor-mode-alist)
1915 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1916 (use-local-map gnus-article-mode-map)
1917 (gnus-update-format-specifications nil 'article-mode)
1918 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1919 (set (make-local-variable 'gnus-page-broken) nil)
1920 (set (make-local-variable 'gnus-button-marker-list) nil)
1921 (gnus-set-default-directory)
1922 (buffer-disable-undo (current-buffer))
1923 (setq buffer-read-only t)
1924 (set-syntax-table gnus-article-mode-syntax-table)
1925 (run-hooks 'gnus-article-mode-hook))
1927 (defun gnus-article-setup-buffer ()
1928 "Initialize the article buffer."
1929 (let* ((name (if gnus-single-article-buffer "*Article*"
1930 (concat "*Article " gnus-newsgroup-name "*")))
1932 (progn (string-match "\\*Article" name)
1933 (concat " *Original Article"
1934 (substring name (match-end 0))))))
1935 (setq gnus-article-buffer name)
1936 (setq gnus-original-article-buffer original)
1937 ;; This might be a variable local to the summary buffer.
1938 (unless gnus-single-article-buffer
1940 (set-buffer gnus-summary-buffer)
1941 (setq gnus-article-buffer name)
1942 (setq gnus-original-article-buffer original)
1943 (gnus-set-global-variables)))
1944 ;; Init original article buffer.
1946 (set-buffer (get-buffer-create gnus-original-article-buffer))
1947 (buffer-disable-undo (current-buffer))
1948 (setq major-mode 'gnus-original-article-mode)
1949 (gnus-add-current-to-buffer-list)
1950 (make-local-variable 'gnus-original-article))
1951 (if (get-buffer name)
1954 (buffer-disable-undo (current-buffer))
1955 (setq buffer-read-only t)
1956 (gnus-add-current-to-buffer-list)
1957 (unless (eq major-mode 'gnus-article-mode)
1958 (gnus-article-mode))
1961 (set-buffer (get-buffer-create name))
1962 (gnus-add-current-to-buffer-list)
1964 (make-local-variable 'gnus-summary-buffer)
1965 (current-buffer)))))
1967 ;; Set article window start at LINE, where LINE is the number of lines
1968 ;; from the head of the article.
1969 (defun gnus-article-set-window-start (&optional line)
1971 (get-buffer-window gnus-article-buffer t)
1973 (set-buffer gnus-article-buffer)
1974 (goto-char (point-min))
1977 (gnus-message 6 "Moved to bookmark")
1978 (search-forward "\n\n" nil t)
1982 (defun gnus-article-prepare (article &optional all-headers header)
1983 "Prepare ARTICLE in article mode buffer.
1984 ARTICLE should either be an article number or a Message-ID.
1985 If ARTICLE is an id, HEADER should be the article headers.
1986 If ALL-HEADERS is non-nil, no headers are hidden."
1988 ;; Make sure we start in a summary buffer.
1989 (unless (eq major-mode 'gnus-summary-mode)
1990 (set-buffer gnus-summary-buffer))
1991 (setq gnus-summary-buffer (current-buffer))
1992 ;; Make sure the connection to the server is alive.
1993 (unless (gnus-server-opened
1994 (gnus-find-method-for-group gnus-newsgroup-name))
1995 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1996 (gnus-request-group gnus-newsgroup-name t))
1997 (let* ((gnus-article (if header (mail-header-number header) article))
1998 (summary-buffer (current-buffer))
1999 (internal-hook gnus-article-internal-prepare-hook)
2000 (group gnus-newsgroup-name)
2003 (gnus-article-setup-buffer)
2004 (set-buffer gnus-article-buffer)
2005 ;; Deactivate active regions.
2006 (when (and (boundp 'transient-mark-mode)
2007 transient-mark-mode)
2008 (setq mark-active nil))
2009 (if (not (setq result (let ((buffer-read-only nil))
2010 (gnus-request-article-this-buffer
2012 ;; There is no such article.
2014 (when (and (numberp article)
2015 (not (memq article gnus-newsgroup-sparse)))
2016 (setq gnus-article-current
2017 (cons gnus-newsgroup-name article))
2018 (set-buffer gnus-summary-buffer)
2019 (setq gnus-current-article article)
2020 (gnus-summary-mark-article article gnus-canceled-mark))
2021 (unless (memq article gnus-newsgroup-sparse)
2023 1 "No such article (may have expired or been canceled)")))
2024 (if (or (eq result 'pseudo) (eq result 'nneething))
2027 (set-buffer summary-buffer)
2028 (push article gnus-newsgroup-history)
2029 (setq gnus-last-article gnus-current-article
2030 gnus-current-article 0
2031 gnus-current-headers nil
2032 gnus-article-current nil)
2033 (if (eq result 'nneething)
2034 (gnus-configure-windows 'summary)
2035 (gnus-configure-windows 'article))
2036 (gnus-set-global-variables))
2037 (gnus-set-mode-line 'article))
2038 ;; The result from the `request' was an actual article -
2039 ;; or at least some text that is now displayed in the
2041 (when (and (numberp article)
2042 (not (eq article gnus-current-article)))
2043 ;; Seems like a new article has been selected.
2044 ;; `gnus-current-article' must be an article number.
2046 (set-buffer summary-buffer)
2047 (push article gnus-newsgroup-history)
2048 (setq gnus-last-article gnus-current-article
2049 gnus-current-article article
2050 gnus-current-headers
2051 (gnus-summary-article-header gnus-current-article)
2052 gnus-article-current
2053 (cons gnus-newsgroup-name gnus-current-article))
2054 (unless (vectorp gnus-current-headers)
2055 (setq gnus-current-headers nil))
2056 (gnus-summary-goto-subject gnus-current-article)
2057 (gnus-summary-show-thread)
2058 (run-hooks 'gnus-mark-article-hook)
2059 (gnus-set-mode-line 'summary)
2060 (when (gnus-visual-p 'article-highlight 'highlight)
2061 (run-hooks 'gnus-visual-mark-article-hook))
2062 ;; Set the global newsgroup variables here.
2063 ;; Suggested by Jim Sisolak
2064 ;; <sisolak@trans4.neep.wisc.edu>.
2065 (gnus-set-global-variables)
2066 (setq gnus-have-all-headers
2067 (or all-headers gnus-show-all-headers))
2069 (vectorp (gnus-summary-article-header article))
2070 (gnus-cache-possibly-enter-article
2072 (gnus-summary-article-header article)
2073 (memq article gnus-newsgroup-marked)
2074 (memq article gnus-newsgroup-dormant)
2075 (memq article gnus-newsgroup-unreads)))))
2076 (when (or (numberp article)
2078 ;; Hooks for getting information from the article.
2079 ;; This hook must be called before being narrowed.
2080 (let (buffer-read-only)
2081 (run-hooks 'internal-hook)
2082 (run-hooks 'gnus-article-prepare-hook)
2083 ;; Decode MIME message.
2084 (when gnus-show-mime
2085 (if (or (not gnus-strict-mime)
2086 (gnus-fetch-field "Mime-Version"))
2087 (funcall gnus-show-mime-method)
2088 (funcall gnus-decode-encoded-word-method)))
2089 ;; Perform the article display hooks.
2090 (run-hooks 'gnus-article-display-hook))
2092 (goto-char (point-min))
2093 (setq gnus-page-broken
2094 (when gnus-break-pages
2095 (gnus-narrow-to-page)
2097 (gnus-set-mode-line 'article)
2098 (gnus-configure-windows 'article)
2099 (goto-char (point-min))
2102 (defun gnus-article-wash-status ()
2103 "Return a string which display status of article washing."
2105 (set-buffer gnus-article-buffer)
2106 (let ((cite (gnus-article-hidden-text-p 'cite))
2107 (headers (gnus-article-hidden-text-p 'headers))
2108 (boring (gnus-article-hidden-text-p 'boring-headers))
2109 (pgp (gnus-article-hidden-text-p 'pgp))
2110 (pem (gnus-article-hidden-text-p 'pem))
2111 (signature (gnus-article-hidden-text-p 'signature))
2112 (overstrike (gnus-article-hidden-text-p 'overstrike))
2113 (emphasis (gnus-article-hidden-text-p 'emphasis))
2114 (mime gnus-show-mime))
2115 (format "%c%c%c%c%c%c%c"
2117 (if (or headers boring) ?h ? )
2118 (if (or pgp pem) ?p ? )
2119 (if signature ?s ? )
2120 (if overstrike ?o ? )
2122 (if emphasis ?e ? )))))
2124 (defun gnus-article-hide-headers-if-wanted ()
2125 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2126 Provided for backwards compatibility."
2127 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2129 (gnus-article-hide-headers)))
2133 (defun gnus-output-to-file (file-name)
2134 "Append the current article to a file named FILE-NAME."
2135 (let ((artbuf (current-buffer)))
2136 (nnheader-temp-write nil
2137 (insert-buffer-substring artbuf)
2138 ;; Append newline at end of the buffer as separator, and then
2140 (goto-char (point-max))
2142 (append-to-file (point-min) (point-max) file-name)
2145 (defun gnus-narrow-to-page (&optional arg)
2146 "Narrow the article buffer to a page.
2147 If given a numerical ARG, move forward ARG pages."
2149 (setq arg (if arg (prefix-numeric-value arg) 0))
2151 (set-buffer gnus-article-buffer)
2152 (goto-char (point-min))
2154 ;; Remove any old next/prev buttons.
2155 (when (gnus-visual-p 'page-marker)
2156 (let ((buffer-read-only nil))
2157 (gnus-remove-text-with-property 'gnus-prev)
2158 (gnus-remove-text-with-property 'gnus-next)))
2161 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2163 (re-search-forward page-delimiter nil 'move arg)))
2164 (goto-char (match-end 0)))
2167 (if (re-search-forward page-delimiter nil 'move)
2170 (when (and (gnus-visual-p 'page-marker)
2171 (not (= (point-min) 1)))
2173 (goto-char (point-min))
2174 (gnus-insert-prev-page-button)))
2175 (when (and (gnus-visual-p 'page-marker)
2176 (< (+ (point-max) 2) (buffer-size)))
2178 (goto-char (point-max))
2179 (gnus-insert-next-page-button)))))
2181 ;; Article mode commands
2183 (defun gnus-article-goto-next-page ()
2184 "Show the next page of the article."
2186 (when (gnus-article-next-page)
2187 (goto-char (point-min))
2188 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2190 (defun gnus-article-goto-prev-page ()
2191 "Show the next page of the article."
2193 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2194 (gnus-article-prev-page nil)))
2196 (defun gnus-article-next-page (&optional lines)
2197 "Show the next page of the current article.
2198 If end of article, return non-nil. Otherwise return nil.
2199 Argument LINES specifies lines to be scrolled up."
2201 (move-to-window-line -1)
2204 (and (pos-visible-in-window-p) ;Not continuation line.
2206 ;; Nothing in this page.
2207 (if (or (not gnus-page-broken)
2210 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2212 (gnus-narrow-to-page 1) ;Go to next page.
2214 ;; More in this page.
2215 (let ((scroll-in-place nil))
2219 ;; Long lines may cause an end-of-buffer error.
2220 (goto-char (point-max)))))
2221 (move-to-window-line 0)
2224 (defun gnus-article-prev-page (&optional lines)
2225 "Show previous page of current article.
2226 Argument LINES specifies lines to be scrolled down."
2228 (move-to-window-line 0)
2229 (if (and gnus-page-broken
2231 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2233 (gnus-narrow-to-page -1) ;Go to previous page.
2234 (goto-char (point-max))
2236 (let ((scroll-in-place nil))
2240 (beginning-of-buffer
2241 (goto-char (point-min))))
2242 (move-to-window-line 0)))))
2244 (defun gnus-article-refer-article ()
2245 "Read article specified by message-id around point."
2247 (let ((point (point)))
2248 (search-forward ">" nil t) ;Move point to end of "<....>".
2249 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2250 (let ((message-id (match-string 1)))
2252 (set-buffer gnus-summary-buffer)
2253 (gnus-summary-refer-article message-id))
2255 (error "No references around point"))))
2257 (defun gnus-article-show-summary ()
2258 "Reconfigure windows to show summary buffer."
2260 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2261 (error "There is no summary buffer for this article buffer")
2262 (gnus-article-set-globals)
2263 (gnus-configure-windows 'article)
2264 (gnus-summary-goto-subject gnus-current-article)))
2266 (defun gnus-article-describe-briefly ()
2267 "Describe article mode commands briefly."
2270 (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")))
2272 (defun gnus-article-summary-command ()
2273 "Execute the last keystroke in the summary buffer."
2275 (let ((obuf (current-buffer))
2276 (owin (current-window-configuration))
2278 (switch-to-buffer gnus-summary-buffer 'norecord)
2279 (setq func (lookup-key (current-local-map) (this-command-keys)))
2280 (call-interactively func)
2282 (set-window-configuration owin)
2283 (set-window-point (get-buffer-window (current-buffer)) (point))))
2285 (defun gnus-article-summary-command-nosave ()
2286 "Execute the last keystroke in the summary buffer."
2289 (pop-to-buffer gnus-summary-buffer 'norecord)
2290 (setq func (lookup-key (current-local-map) (this-command-keys)))
2291 (call-interactively func)))
2293 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2294 "Read a summary buffer key sequence and execute it from the article buffer."
2297 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2298 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2299 "=" "^" "\M-^" "|"))
2306 (set-buffer gnus-summary-buffer)
2307 (let (gnus-pick-mode)
2308 (push (or key last-command-event) unread-command-events)
2309 (setq keys (read-key-sequence nil))))
2312 (if (or (member keys nosaves)
2313 (member keys nosave-but-article)
2314 (member keys nosave-in-article))
2316 (save-window-excursion
2317 (pop-to-buffer gnus-summary-buffer 'norecord)
2318 ;; We disable the pick minor mode commands.
2319 (let (gnus-pick-mode)
2320 (setq func (lookup-key (current-local-map) keys))))
2323 (unless (member keys nosave-in-article)
2324 (set-buffer gnus-summary-buffer))
2325 (call-interactively func))
2326 (when (member keys nosave-but-article)
2327 (pop-to-buffer gnus-article-buffer 'norecord)))
2328 ;; These commands should restore window configuration.
2329 (let ((obuf (current-buffer))
2330 (owin (current-window-configuration))
2333 (if not-restore-window
2334 (pop-to-buffer gnus-summary-buffer 'norecord)
2335 (switch-to-buffer gnus-summary-buffer 'norecord))
2336 (setq in-buffer (current-buffer))
2337 ;; We disable the pick minor mode commands.
2338 (if (setq func (let (gnus-pick-mode)
2339 (lookup-key (current-local-map) keys)))
2340 (call-interactively func)
2342 (when (eq in-buffer (current-buffer))
2344 (unless not-restore-window
2345 (set-window-configuration owin))
2346 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2348 (defun gnus-article-hide (&optional arg force)
2349 "Hide all the gruft in the current article.
2350 This means that PGP stuff, signatures, cited text and (some)
2351 headers will be hidden.
2352 If given a prefix, show the hidden text instead."
2353 (interactive (list current-prefix-arg 'force))
2354 (gnus-article-hide-headers arg)
2355 (gnus-article-hide-pgp arg)
2356 (gnus-article-hide-citation-maybe arg force)
2357 (gnus-article-hide-signature arg))
2359 (defun gnus-article-maybe-highlight ()
2360 "Do some article highlighting if `article-visual' is non-nil."
2361 (when (gnus-visual-p 'article-highlight 'highlight)
2362 (gnus-article-highlight-some)))
2364 (defun gnus-request-article-this-buffer (article group)
2365 "Get an article and insert it into this buffer."
2366 (let (do-update-line)
2370 (gnus-kill-all-overlays)
2371 (setq group (or group gnus-newsgroup-name))
2373 ;; Open server if it has closed.
2374 (gnus-check-server (gnus-find-method-for-group group))
2376 ;; Using `gnus-request-article' directly will insert the article into
2377 ;; `nntp-server-buffer' - so we'll save some time by not having to
2378 ;; copy it from the server buffer into the article buffer.
2380 ;; We only request an article by message-id when we do not have the
2381 ;; headers for it, so we'll have to get those.
2382 (when (stringp article)
2383 (let ((gnus-override-method gnus-refer-article-method))
2384 (gnus-read-header article)))
2386 ;; If the article number is negative, that means that this article
2387 ;; doesn't belong in this newsgroup (possibly), so we find its
2388 ;; message-id and request it by id instead of number.
2389 (when (and (numberp article)
2391 (get-buffer gnus-summary-buffer)
2392 (buffer-name (get-buffer gnus-summary-buffer)))
2394 (set-buffer gnus-summary-buffer)
2395 (let ((header (gnus-summary-article-header article)))
2398 ((memq article gnus-newsgroup-sparse)
2399 ;; This is a sparse gap article.
2400 (setq do-update-line article)
2401 (setq article (mail-header-id header))
2402 (let ((gnus-override-method gnus-refer-article-method))
2403 (gnus-read-header article))
2404 (setq gnus-newsgroup-sparse
2405 (delq article gnus-newsgroup-sparse)))
2407 ;; It's a real article.
2408 (setq article (mail-header-id header)))
2410 ;; It is an extracted pseudo-article.
2411 (setq article 'pseudo)
2412 (gnus-request-pseudo-article header))))
2414 (let ((method (gnus-find-method-for-group
2415 gnus-newsgroup-name)))
2416 (if (not (eq (car method) 'nneething))
2418 (let ((dir (concat (file-name-as-directory (nth 1 method))
2419 (mail-header-subject header))))
2420 (when (file-directory-p dir)
2421 (setq article 'nneething)
2422 (gnus-group-enter-directory dir))))))))
2425 ;; Refuse to select canceled articles.
2426 ((and (numberp article)
2428 (get-buffer gnus-summary-buffer)
2429 (buffer-name (get-buffer gnus-summary-buffer))
2430 (eq (cdr (save-excursion
2431 (set-buffer gnus-summary-buffer)
2432 (assq article gnus-newsgroup-reads)))
2433 gnus-canceled-mark))
2435 ;; We first check `gnus-original-article-buffer'.
2436 ((and (get-buffer gnus-original-article-buffer)
2439 (set-buffer gnus-original-article-buffer)
2440 (and (equal (car gnus-original-article) group)
2441 (eq (cdr gnus-original-article) article))))
2442 (insert-buffer-substring gnus-original-article-buffer)
2444 ;; Check the backlog.
2445 ((and gnus-keep-backlog
2446 (gnus-backlog-request-article group article (current-buffer)))
2448 ;; Check asynchronous pre-fetch.
2449 ((gnus-async-request-fetched-article group article (current-buffer))
2450 (gnus-async-prefetch-next group article gnus-summary-buffer)
2453 ((and gnus-use-cache
2455 (gnus-cache-request-article article group))
2457 ;; Get the article and put into the article buffer.
2458 ((or (stringp article) (numberp article))
2459 (let ((gnus-override-method
2460 (and (stringp article) gnus-refer-article-method))
2461 (buffer-read-only nil))
2463 (gnus-kill-all-overlays)
2464 (when (gnus-request-article article group (current-buffer))
2465 (when (numberp article)
2466 (gnus-async-prefetch-next group article gnus-summary-buffer)
2467 (when gnus-keep-backlog
2468 (gnus-backlog-enter-article
2469 group article (current-buffer))))
2474 ;; Take the article from the original article buffer
2475 ;; and place it in the buffer it's supposed to be in.
2476 (when (and (get-buffer gnus-article-buffer)
2478 (equal (buffer-name (current-buffer))
2479 (buffer-name (get-buffer gnus-article-buffer))))
2481 (if (get-buffer gnus-original-article-buffer)
2482 (set-buffer (get-buffer gnus-original-article-buffer))
2483 (set-buffer (get-buffer-create gnus-original-article-buffer))
2484 (buffer-disable-undo (current-buffer))
2485 (setq major-mode 'gnus-original-article-mode)
2486 (setq buffer-read-only t)
2487 (gnus-add-current-to-buffer-list))
2488 (let (buffer-read-only)
2490 (insert-buffer-substring gnus-article-buffer))
2491 (setq gnus-original-article (cons group article))))
2493 ;; Update sparse articles.
2494 (when (and do-update-line
2495 (or (numberp article)
2497 (let ((buf (current-buffer)))
2498 (set-buffer gnus-summary-buffer)
2499 (gnus-summary-update-article do-update-line)
2500 (gnus-summary-goto-subject do-update-line nil t)
2501 (set-window-point (get-buffer-window (current-buffer) t)
2503 (set-buffer buf))))))
2509 (defcustom gnus-article-edit-mode-hook nil
2510 "Hook run in article edit mode buffers."
2511 :group 'gnus-article-various
2514 (defvar gnus-article-edit-done-function nil)
2516 (defvar gnus-article-edit-mode-map nil)
2518 (unless gnus-article-edit-mode-map
2519 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2521 (gnus-define-keys gnus-article-edit-mode-map
2522 "\C-c\C-c" gnus-article-edit-done
2523 "\C-c\C-k" gnus-article-edit-exit)
2525 (gnus-define-keys (gnus-article-edit-wash-map
2526 "\C-c\C-w" gnus-article-edit-mode-map)
2527 "f" gnus-article-edit-full-stops))
2529 (defun gnus-article-edit-mode ()
2530 "Major mode for editing articles.
2531 This is an extended text-mode.
2533 \\{gnus-article-edit-mode-map}"
2535 (kill-all-local-variables)
2536 (setq major-mode 'gnus-article-edit-mode)
2537 (setq mode-name "Article Edit")
2538 (use-local-map gnus-article-edit-mode-map)
2539 (make-local-variable 'gnus-article-edit-done-function)
2540 (make-local-variable 'gnus-prev-winconf)
2541 (setq buffer-read-only nil)
2542 (buffer-enable-undo)
2544 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2546 (defun gnus-article-edit (&optional force)
2547 "Edit the current article.
2548 This will have permanent effect only in mail groups.
2549 If FORCE is non-nil, allow editing of articles even in read-only
2552 (when (and (not force)
2553 (gnus-group-read-only-p))
2554 (error "The current newsgroup does not support article editing"))
2555 (gnus-article-edit-article
2556 `(lambda (no-highlight)
2557 (gnus-summary-edit-article-done
2558 ,(or (mail-header-references gnus-current-headers) "")
2559 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2561 (defun gnus-article-edit-article (exit-func)
2562 "Start editing the contents of the current article buffer."
2563 (let ((winconf (current-window-configuration)))
2564 (set-buffer gnus-article-buffer)
2565 (gnus-article-edit-mode)
2566 (gnus-set-text-properties (point-min) (point-max) nil)
2567 (gnus-configure-windows 'edit-article)
2568 (setq gnus-article-edit-done-function exit-func)
2569 (setq gnus-prev-winconf winconf)
2570 (gnus-message 6 "C-c C-c to end edits")))
2572 (defun gnus-article-edit-done (&optional arg)
2573 "Update the article edits and exit."
2578 (goto-char (point-min))
2579 (when (search-forward "\n\n" nil 1)
2580 (let ((lines (count-lines (point) (point-max)))
2581 (length (- (point-max) (point)))
2582 (case-fold-search t)
2583 (body (copy-marker (point))))
2584 (goto-char (point-min))
2585 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2586 (delete-region (match-beginning 1) (match-end 1))
2587 (insert (number-to-string length)))
2588 (goto-char (point-min))
2589 (when (re-search-forward
2590 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2591 (delete-region (match-beginning 1) (match-end 1))
2592 (insert (number-to-string length)))
2593 (goto-char (point-min))
2594 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2595 (delete-region (match-beginning 1) (match-end 1))
2596 (insert (number-to-string lines)))))))
2597 (let ((func gnus-article-edit-done-function)
2598 (buf (current-buffer))
2599 (start (window-start)))
2600 (gnus-article-edit-exit)
2603 (let ((buffer-read-only nil))
2604 (funcall func arg)))
2606 (set-window-start (get-buffer-window buf) start)
2607 (set-window-point (get-buffer-window buf) (point))))
2609 (defun gnus-article-edit-exit ()
2610 "Exit the article editing without updating."
2612 ;; We remove all text props from the article buffer.
2613 (let ((buf (format "%s" (buffer-string)))
2614 (curbuf (current-buffer))
2616 (window-start (window-start)))
2619 (let ((winconf gnus-prev-winconf))
2621 ;; The cache and backlog have to be flushed somewhat.
2622 (when gnus-use-cache
2623 (gnus-cache-update-article
2624 (car gnus-article-current) (cdr gnus-article-current)))
2625 (when gnus-keep-backlog
2626 (gnus-backlog-remove-article
2627 (car gnus-article-current) (cdr gnus-article-current)))
2628 ;; Flush original article as well.
2630 (when (get-buffer gnus-original-article-buffer)
2631 (set-buffer gnus-original-article-buffer)
2632 (setq gnus-original-article nil)))
2633 (set-window-configuration winconf)
2634 ;; Tippy-toe some to make sure that point remains where it was.
2635 (let ((buf (current-buffer)))
2637 (set-window-start (get-buffer-window (current-buffer)) window-start)
2639 (set-buffer buf)))))
2641 (defun gnus-article-edit-full-stops ()
2642 "Interactively repair spacing at end of sentences."
2645 (goto-char (point-min))
2646 (search-forward-regexp "^$" nil t)
2647 (let ((case-fold-search nil))
2648 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2651 ;;; Article highlights
2654 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2656 ;;; Internal Variables:
2658 (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\\)"
2659 "Regular expression that matches URLs."
2660 :group 'gnus-article-buttons
2663 (defcustom gnus-button-alist
2664 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2665 gnus-button-message-id 2)
2666 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2667 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2668 gnus-button-fetch-group 4)
2669 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2670 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2671 t gnus-button-message-id 3)
2672 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2673 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2674 ;; This is how URLs _should_ be embedded in text...
2675 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2677 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2678 "Alist of regexps matching buttons in article bodies.
2680 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2681 REGEXP: is the string matching text around the button,
2682 BUTTON: is the number of the regexp grouping actually matching the button,
2683 FORM: is a lisp expression which must eval to true for the button to
2685 CALLBACK: is the function to call when the user push this button, and each
2686 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2688 CALLBACK can also be a variable, in that case the value of that
2689 variable it the real callback function."
2690 :group 'gnus-article-buttons
2691 :type '(repeat (list regexp
2692 (integer :tag "Button")
2694 (function :tag "Callback")
2697 (integer :tag "Regexp group")))))
2699 (defcustom gnus-header-button-alist
2700 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2701 0 t gnus-button-message-id 0)
2702 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2703 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2704 0 t gnus-button-mailto 0)
2705 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2706 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2707 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2708 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2709 gnus-button-message-id 3))
2710 "Alist of headers and regexps to match buttons in article heads.
2712 This alist is very similar to `gnus-button-alist', except that each
2713 alist has an additional HEADER element first in each entry:
2715 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2717 HEADER is a regexp to match a header. For a fuller explanation, see
2718 `gnus-button-alist'."
2719 :group 'gnus-article-buttons
2720 :group 'gnus-article-headers
2721 :type '(repeat (list (regexp :tag "Header")
2723 (integer :tag "Button")
2725 (function :tag "Callback")
2728 (integer :tag "Regexp group")))))
2730 (defvar gnus-button-regexp nil)
2731 (defvar gnus-button-marker-list nil)
2732 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2734 (defvar gnus-button-last nil)
2735 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2739 (defun gnus-article-push-button (event)
2740 "Check text under the mouse pointer for a callback function.
2741 If the text under the mouse pointer has a `gnus-callback' property,
2742 call it with the value of the `gnus-data' text property."
2744 (set-buffer (window-buffer (posn-window (event-start event))))
2745 (let* ((pos (posn-point (event-start event)))
2746 (data (get-text-property pos 'gnus-data))
2747 (fun (get-text-property pos 'gnus-callback)))
2749 (funcall fun data))))
2751 (defun gnus-article-press-button ()
2752 "Check text at point for a callback function.
2753 If the text at point has a `gnus-callback' property,
2754 call it with the value of the `gnus-data' text property."
2756 (let* ((data (get-text-property (point) 'gnus-data))
2757 (fun (get-text-property (point) 'gnus-callback)))
2759 (funcall fun data))))
2761 (defun gnus-article-prev-button (n)
2762 "Move point to N buttons backward.
2763 If N is negative, move forward instead."
2765 (gnus-article-next-button (- n)))
2767 (defun gnus-article-next-button (n)
2768 "Move point to N buttons forward.
2769 If N is negative, move backward instead."
2771 (let ((function (if (< n 0) 'previous-single-property-change
2772 'next-single-property-change))
2773 (inhibit-point-motion-hooks t)
2775 (limit (if (< n 0) (point-min) (point-max))))
2777 (while (and (not (= limit (point)))
2779 ;; Skip past the current button.
2780 (when (get-text-property (point) 'gnus-callback)
2781 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2782 ;; Go to the next (or previous) button.
2783 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2784 ;; Put point at the start of the button.
2785 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2786 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2787 ;; Skip past intangible buttons.
2788 (when (get-text-property (point) 'intangible)
2792 (gnus-message 5 "No more buttons"))
2795 (defun gnus-article-highlight (&optional force)
2796 "Highlight current article.
2797 This function calls `gnus-article-highlight-headers',
2798 `gnus-article-highlight-citation',
2799 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2800 do the highlighting. See the documentation for those functions."
2801 (interactive (list 'force))
2802 (gnus-article-highlight-headers)
2803 (gnus-article-highlight-citation force)
2804 (gnus-article-highlight-signature)
2805 (gnus-article-add-buttons force)
2806 (gnus-article-add-buttons-to-head))
2808 (defun gnus-article-highlight-some (&optional force)
2809 "Highlight current article.
2810 This function calls `gnus-article-highlight-headers',
2811 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2812 do the highlighting. See the documentation for those functions."
2813 (interactive (list 'force))
2814 (gnus-article-highlight-headers)
2815 (gnus-article-highlight-signature)
2816 (gnus-article-add-buttons))
2818 (defun gnus-article-highlight-headers ()
2819 "Highlight article headers as specified by `gnus-header-face-alist'."
2822 (set-buffer gnus-article-buffer)
2824 (let ((alist gnus-header-face-alist)
2825 (buffer-read-only nil)
2826 (case-fold-search t)
2827 (inhibit-point-motion-hooks t)
2828 entry regexp header-face field-face from hpoints fpoints)
2829 (message-narrow-to-head)
2830 (while (setq entry (pop alist))
2831 (goto-char (point-min))
2832 (setq regexp (concat "^\\("
2833 (if (string-equal "" (nth 0 entry))
2837 header-face (nth 1 entry)
2838 field-face (nth 2 entry))
2839 (while (and (re-search-forward regexp nil t)
2843 (unless (search-forward ":" nil t)
2845 (when (and header-face
2846 (not (memq (point) hpoints)))
2847 (push (point) hpoints)
2848 (gnus-put-text-property from (point) 'face header-face))
2849 (when (and field-face
2850 (not (memq (setq from (point)) fpoints)))
2852 (if (re-search-forward "^[^ \t]" nil t)
2854 (goto-char (point-max)))
2855 (gnus-put-text-property from (point) 'face field-face))))))))
2857 (defun gnus-article-highlight-signature ()
2858 "Highlight the signature in an article.
2859 It does this by highlighting everything after
2860 `gnus-signature-separator' using `gnus-signature-face'."
2863 (set-buffer gnus-article-buffer)
2864 (let ((buffer-read-only nil)
2865 (inhibit-point-motion-hooks t))
2867 (when (and gnus-signature-face
2868 (gnus-article-narrow-to-signature))
2869 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2870 'face gnus-signature-face)
2872 (gnus-article-search-signature)
2873 (let ((start (match-beginning 0))
2874 (end (set-marker (make-marker) (1+ (match-end 0)))))
2875 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2878 (defun gnus-button-in-region-p (b e prop)
2879 "Say whether PROP exists in the region."
2880 (text-property-not-all b e prop nil))
2882 (defun gnus-article-add-buttons (&optional force)
2883 "Find external references in the article and make buttons of them.
2884 \"External references\" are things like Message-IDs and URLs, as
2885 specified by `gnus-button-alist'."
2886 (interactive (list 'force))
2888 (set-buffer gnus-article-buffer)
2889 (let ((buffer-read-only nil)
2890 (inhibit-point-motion-hooks t)
2891 (case-fold-search t)
2892 (alist gnus-button-alist)
2894 ;; Remove all old markers.
2896 (while (setq marker (pop gnus-button-marker-list))
2898 (when (setq entry (gnus-button-entry))
2899 (put-text-property (match-beginning (nth 1 entry))
2900 (match-end (nth 1 entry))
2901 'gnus-callback nil))
2902 (set-marker marker nil)))
2903 ;; We skip the headers.
2904 (goto-char (point-min))
2905 (unless (search-forward "\n\n" nil t)
2906 (goto-char (point-max)))
2908 (while (setq entry (pop alist))
2909 (setq regexp (car entry))
2911 (while (re-search-forward regexp nil t)
2912 (let* ((start (and entry (match-beginning (nth 1 entry))))
2913 (end (and entry (match-end (nth 1 entry))))
2914 (from (match-beginning 0)))
2915 (when (and (or (eq t (nth 2 entry))
2916 (eval (nth 2 entry)))
2917 (not (gnus-button-in-region-p
2918 start end 'gnus-callback)))
2919 ;; That optional form returned non-nil, so we add the
2921 (gnus-article-add-button
2922 start end 'gnus-button-push
2923 (car (push (set-marker (make-marker) from)
2924 gnus-button-marker-list))))))))))
2926 ;; Add buttons to the head of an article.
2927 (defun gnus-article-add-buttons-to-head ()
2928 "Add buttons to the head of the article."
2931 (set-buffer gnus-article-buffer)
2932 (let ((buffer-read-only nil)
2933 (inhibit-point-motion-hooks t)
2934 (case-fold-search t)
2935 (alist gnus-header-button-alist)
2937 (nnheader-narrow-to-headers)
2939 ;; Each alist entry.
2940 (setq entry (car alist)
2942 (goto-char (point-min))
2943 (while (re-search-forward (car entry) nil t)
2944 ;; Each header matching the entry.
2945 (setq beg (match-beginning 0))
2946 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2947 (match-beginning 0))
2950 (while (re-search-forward (nth 1 entry) end t)
2951 ;; Each match within a header.
2952 (let* ((entry (cdr entry))
2953 (start (match-beginning (nth 1 entry)))
2954 (end (match-end (nth 1 entry)))
2955 (form (nth 2 entry)))
2956 (goto-char (match-end 0))
2958 (gnus-article-add-button
2959 start end (nth 3 entry)
2960 (buffer-substring (match-beginning (nth 4 entry))
2961 (match-end (nth 4 entry)))))))
2965 ;;; External functions:
2967 (defun gnus-article-add-button (from to fun &optional data)
2968 "Create a button between FROM and TO with callback FUN and data DATA."
2969 (when gnus-article-button-face
2970 (gnus-overlay-put (gnus-make-overlay from to)
2971 'face gnus-article-button-face))
2972 (gnus-add-text-properties
2974 (nconc (and gnus-article-mouse-face
2975 (list gnus-mouse-face-prop gnus-article-mouse-face))
2976 (list 'gnus-callback fun)
2977 (and data (list 'gnus-data data)))))
2979 ;;; Internal functions:
2981 (defun gnus-article-set-globals ()
2983 (set-buffer gnus-summary-buffer)
2984 (gnus-set-global-variables)))
2986 (defun gnus-signature-toggle (end)
2988 (set-buffer gnus-article-buffer)
2989 (let ((buffer-read-only nil)
2990 (inhibit-point-motion-hooks t))
2991 (if (get-text-property end 'invisible)
2992 (gnus-article-unhide-text end (point-max))
2993 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2995 (defun gnus-button-entry ()
2996 ;; Return the first entry in `gnus-button-alist' matching this place.
2997 (let ((alist gnus-button-alist)
3000 (setq entry (pop alist))
3001 (if (looking-at (car entry))
3006 (defun gnus-button-push (marker)
3007 ;; Push button starting at MARKER.
3009 (set-buffer gnus-article-buffer)
3011 (let* ((entry (gnus-button-entry))
3012 (inhibit-point-motion-hooks t)
3014 (args (mapcar (lambda (group)
3015 (let ((string (match-string group)))
3016 (gnus-set-text-properties
3017 0 (length string) nil string)
3024 (fboundp (symbol-value fun)))
3025 (apply (symbol-value fun) args))
3027 (gnus-message 1 "You must define `%S' to use this button"
3028 (cons fun args)))))))
3030 (defun gnus-button-message-id (message-id)
3033 (set-buffer gnus-summary-buffer)
3034 (gnus-summary-refer-article message-id)))
3036 (defun gnus-button-fetch-group (address)
3037 "Fetch GROUP specified by ADDRESS."
3038 (if (not (string-match "[:/]" address))
3039 ;; This is just a simple group url.
3040 (gnus-group-read-ephemeral-group address gnus-select-method)
3041 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3043 (error "Can't parse %s" address)
3044 (gnus-group-read-ephemeral-group
3045 (match-string 4 address)
3046 `(nntp ,(match-string 1 address)
3047 (nntp-address ,(match-string 1 address))
3048 (nntp-port-number ,(if (match-end 3)
3049 (match-string 3 address)
3052 (defun gnus-split-string (string pattern)
3053 "Return a list of substrings of STRING which are separated by PATTERN."
3054 (let (parts (start 0))
3055 (while (string-match pattern string start)
3056 (setq parts (cons (substring string start (match-beginning 0)) parts)
3057 start (match-end 0)))
3058 (nreverse (cons (substring string start) parts))))
3060 (defun gnus-url-parse-query-string (query &optional downcase)
3061 (let (retval pairs cur key val)
3062 (setq pairs (gnus-split-string query "&"))
3064 (setq cur (car pairs)
3066 (if (not (string-match "=" cur))
3068 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3069 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3071 (setq key (downcase key)))
3072 (setq cur (assoc key retval))
3074 (setcdr cur (cons val (cdr cur)))
3075 (setq retval (cons (list key val) retval)))))
3078 (defun gnus-url-unhex (x)
3085 (defun gnus-url-unhex-string (str &optional allow-newlines)
3086 "Remove %XXX embedded spaces, etc in a url.
3087 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3088 decoding of carriage returns and line feeds in the string, which is normally
3089 forbidden in URL encoding."
3090 (setq str (or str ""))
3092 (case-fold-search t))
3093 (while (string-match "%[0-9a-f][0-9a-f]" str)
3094 (let* ((start (match-beginning 0))
3095 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3097 (gnus-url-unhex (elt str (+ start 2))))))
3099 tmp (substring str 0 start)
3102 (char-to-string code))
3103 ((or (= code ?\n) (= code ?\r))
3105 (t (char-to-string code))))
3106 str (substring str (match-end 0)))))
3107 (setq tmp (concat tmp str))
3110 (defun gnus-url-mailto (url)
3111 ;; Send mail to someone
3112 (when (string-match "mailto:/*\\(.*\\)" url)
3113 (setq url (substring url (match-beginning 1) nil)))
3114 (let (to args source-url subject func)
3115 (if (string-match (regexp-quote "?") url)
3116 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3117 args (gnus-url-parse-query-string
3118 (substring url (match-end 0) nil) t))
3119 (setq to (gnus-url-unhex-string url)))
3120 (setq args (cons (list "to" to) args)
3121 subject (cdr-safe (assoc "subject" args)))
3124 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3127 (message-position-on-field (caar args)))
3128 (insert (mapconcat 'identity (cdar args) ", "))
3129 (setq args (cdr args)))
3132 (message-goto-subject))))
3134 (defun gnus-button-mailto (address)
3136 (set-buffer (gnus-copy-article-buffer))
3137 (message-reply address))
3139 (defun gnus-button-reply (address)
3140 ;; Reply to ADDRESS.
3141 (message-reply address))
3143 (defun gnus-button-url (address)
3145 (funcall browse-url-browser-function address))
3147 (defun gnus-button-embedded-url (address)
3149 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3151 ;;; Next/prev buttons in the article buffer.
3153 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3154 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3156 (defvar gnus-prev-page-map nil)
3157 (unless gnus-prev-page-map
3158 (setq gnus-prev-page-map (make-sparse-keymap))
3159 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3160 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3162 (defun gnus-insert-prev-page-button ()
3163 (let ((buffer-read-only nil))
3165 gnus-prev-page-line-format nil
3166 `(gnus-prev t local-map ,gnus-prev-page-map
3167 gnus-callback gnus-article-button-prev-page))))
3169 (defvar gnus-next-page-map nil)
3170 (unless gnus-next-page-map
3171 (setq gnus-next-page-map (make-keymap))
3172 (suppress-keymap gnus-prev-page-map)
3173 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3174 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3176 (defun gnus-button-next-page ()
3177 "Go to the next page."
3179 (let ((win (selected-window)))
3180 (select-window (get-buffer-window gnus-article-buffer t))
3181 (gnus-article-next-page)
3182 (select-window win)))
3184 (defun gnus-button-prev-page ()
3185 "Go to the prev page."
3187 (let ((win (selected-window)))
3188 (select-window (get-buffer-window gnus-article-buffer t))
3189 (gnus-article-prev-page)
3190 (select-window win)))
3192 (defun gnus-insert-next-page-button ()
3193 (let ((buffer-read-only nil))
3194 (gnus-eval-format gnus-next-page-line-format nil
3195 `(gnus-next t local-map ,gnus-next-page-map
3197 gnus-article-button-next-page))))
3199 (defun gnus-article-button-next-page (arg)
3200 "Go to the next page."
3202 (let ((win (selected-window)))
3203 (select-window (get-buffer-window gnus-article-buffer t))
3204 (gnus-article-next-page)
3205 (select-window win)))
3207 (defun gnus-article-button-prev-page (arg)
3208 "Go to the prev page."
3210 (let ((win (selected-window)))
3211 (select-window (get-buffer-window gnus-article-buffer t))
3212 (gnus-article-prev-page)
3213 (select-window win)))
3219 (run-hooks 'gnus-art-load-hook)
3221 ;;; gnus-art.el ends here