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)
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)))
1301 (insert (article-make-date-line date type))
1304 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1305 (put-text-property (match-beginning 1) (1+ (match-end 1))
1307 (put-text-property (match-beginning 2) (match-end 2)
1310 (defun article-make-date-line (date type)
1311 "Return a DATE line of TYPE."
1313 ;; Convert to the local timezone. We have to slap a
1314 ;; `condition-case' round the calls to the timezone
1315 ;; functions since they aren't particularly resistant to
1318 (concat "Date: " (condition-case ()
1319 (timezone-make-date-arpa-standard date)
1321 ;; Convert to Universal Time.
1325 (timezone-make-date-arpa-standard date nil "UT")
1327 ;; Get the original date from the article.
1328 ((eq type 'original)
1329 (concat "Date: " date))
1330 ;; Let the user define the format.
1334 (format-time-string gnus-article-time-format
1337 (timezone-make-date-arpa-standard
1339 ;; Do an X-Sent lapsed format.
1341 ;; If the date is seriously mangled, the timezone functions are
1342 ;; liable to bug out, so we ignore all errors.
1343 (let* ((now (current-time))
1348 (timezone-make-date-arpa-standard
1349 (current-time-string now)
1350 (current-time-zone now) "UT"))
1352 (timezone-make-date-arpa-standard
1354 (real-sec (and real-time
1355 (+ (* (float (car real-time)) 65536)
1357 (sec (and real-time (abs real-sec)))
1361 "X-Sent: Unknown\n")
1367 ;; This is a bit convoluted, but basically we go
1368 ;; through the time units for years, weeks, etc,
1369 ;; and divide things to see whether that results
1370 ;; in positive answers.
1373 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1374 ;; The (remaining) seconds are too few to
1375 ;; be divided into this time unit.
1377 ;; It's big enough, so we output it.
1378 (setq sec (- sec (* num (cdr unit))))
1380 (concat (if prev ", " "") (int-to-string
1382 " " (symbol-name (car unit))
1383 (if (> num 1) "s" ""))
1385 article-time-units "")
1386 ;; If dates are odd, then it might appear like the
1387 ;; article was sent in the future.
1390 " in the future"))))))
1392 (error "Unknown conversion type: %s" type))))
1394 (defun article-date-local (&optional highlight)
1395 "Convert the current article date to the local timezone."
1396 (interactive (list t))
1397 (article-date-ut 'local highlight))
1399 (defun article-date-original (&optional highlight)
1400 "Convert the current article date to what it was originally.
1401 This is only useful if you have used some other date conversion
1402 function and want to see what the date was before converting."
1403 (interactive (list t))
1404 (article-date-ut 'original highlight))
1406 (defun article-date-lapsed (&optional highlight)
1407 "Convert the current article date to time lapsed since it was sent."
1408 (interactive (list t))
1409 (article-date-ut 'lapsed highlight))
1411 (defun article-update-date-lapsed ()
1412 "Function to be run from a timer to update the lapsed time line."
1414 (when (gnus-buffer-live-p gnus-article-buffer)
1415 (set-buffer gnus-article-buffer)
1416 (goto-char (point-min))
1417 (when (re-search-forward "^X-Sent:" nil t)
1418 (article-date-lapsed t)))))
1420 (defun gnus-start-date-timer ()
1421 "Start a timer to update the X-Sent header in the article buffers."
1423 (gnus-stop-date-timer)
1424 (setq article-lapsed-timer
1425 (nnheader-run-at-time 1 1 'article-update-date-lapsed)))
1427 (defun gnus-stop-date-timer ()
1428 "Stop the X-Sent timer."
1430 (when article-lapsed-timer
1431 (nnheader-delete-timer article-lapsed-timer)
1432 (setq article-lapsed-timer nil)))
1434 (defun article-date-user (&optional highlight)
1435 "Convert the current article date to the user-defined format.
1436 This format is defined by the `gnus-article-time-format' variable."
1437 (interactive (list t))
1438 (article-date-ut 'user highlight))
1440 (defun article-show-all ()
1441 "Show all hidden text in the article buffer."
1444 (let ((buffer-read-only nil))
1445 (gnus-article-unhide-text (point-min) (point-max)))))
1447 (defun article-emphasize (&optional arg)
1448 "Emphasize text according to `gnus-emphasis-alist'."
1449 (interactive (gnus-article-hidden-arg))
1450 (unless (gnus-article-check-hidden-text 'emphasis arg)
1452 (let ((alist gnus-emphasis-alist)
1453 (buffer-read-only nil)
1454 (props (append '(article-type emphasis)
1455 gnus-hidden-properties))
1456 regexp elem beg invisible visible face)
1457 (goto-char (point-min))
1458 (search-forward "\n\n" nil t)
1460 (while (setq elem (pop alist))
1462 (setq regexp (car elem)
1463 invisible (nth 1 elem)
1464 visible (nth 2 elem)
1466 (while (re-search-forward regexp nil t)
1467 (when (and (match-beginning visible) (match-beginning invisible))
1468 (gnus-article-hide-text
1469 (match-beginning invisible) (match-end invisible) props)
1470 (gnus-article-unhide-text-type
1471 (match-beginning visible) (match-end visible) 'emphasis)
1472 (gnus-put-text-property-excluding-newlines
1473 (match-beginning visible) (match-end visible) 'face face)
1474 (goto-char (match-end invisible)))))))))
1476 (defvar gnus-summary-article-menu)
1477 (defvar gnus-summary-post-menu)
1479 ;;; Saving functions.
1481 (defun gnus-article-save (save-buffer file &optional num)
1482 "Save the currently selected article."
1483 (unless gnus-save-all-headers
1484 ;; Remove headers according to `gnus-saved-headers'.
1485 (let ((gnus-visible-headers
1486 (or gnus-saved-headers gnus-visible-headers))
1487 (gnus-article-buffer save-buffer))
1489 (set-buffer save-buffer)
1490 (article-hide-headers 1 t))))
1491 (save-window-excursion
1492 (if (not gnus-default-article-saver)
1493 (error "No default saver is defined")
1494 ;; !!! Magic! The saving functions all save
1495 ;; `gnus-original-article-buffer' (or so they think), but we
1496 ;; bind that variable to our save-buffer.
1497 (set-buffer gnus-article-buffer)
1498 (let* ((gnus-save-article-buffer save-buffer)
1501 ((not gnus-prompt-before-saving) 'default)
1502 ((eq gnus-prompt-before-saving 'always) nil)
1504 (gnus-number-of-articles-to-be-saved
1505 (when (eq gnus-prompt-before-saving t)
1507 (set-buffer gnus-summary-buffer)
1508 (funcall gnus-default-article-saver filename)))))
1510 (defun gnus-read-save-file-name (prompt &optional filename
1511 function group headers variable)
1513 (funcall function group headers (symbol-value variable)))
1518 ((eq filename 'default)
1524 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1527 (if (and gnus-number-of-articles-to-be-saved
1528 (> gnus-number-of-articles-to-be-saved 1))
1529 (format "these %d articles"
1530 gnus-number-of-articles-to-be-saved)
1533 ;; Let the split methods have their say.
1535 ;; No split name was found.
1538 (concat prompt " (default "
1539 (file-name-nondirectory default-name) ") ")
1540 (file-name-directory default-name)
1542 ;; A single group name is returned.
1543 ((stringp split-name)
1545 (funcall function split-name headers
1546 (symbol-value variable)))
1548 (concat prompt " (default "
1549 (file-name-nondirectory default-name) ") ")
1550 (file-name-directory default-name)
1552 ;; A single split name was found
1553 ((= 1 (length split-name))
1554 (let* ((name (expand-file-name
1555 (car split-name) gnus-article-save-directory))
1556 (dir (cond ((file-directory-p name)
1557 (file-name-as-directory name))
1558 ((file-exists-p name) name)
1559 (t gnus-article-save-directory))))
1561 (concat prompt " (default " name ") ")
1563 ;; A list of splits was found.
1565 (setq split-name (nreverse split-name))
1567 (let ((file-name-history
1568 (nconc split-name file-name-history)))
1572 (concat prompt " (`M-p' for defaults) ")
1573 gnus-article-save-directory
1575 gnus-article-save-directory)))
1576 (car (push result file-name-history)))))))
1577 ;; Create the directory.
1578 (gnus-make-directory (file-name-directory file))
1579 ;; If we have read a directory, we append the default file name.
1580 (when (file-directory-p file)
1581 (setq file (concat (file-name-as-directory file)
1582 (file-name-nondirectory default-name))))
1583 ;; Possibly translate some characters.
1584 (nnheader-translate-file-chars file)))))
1585 (gnus-make-directory (file-name-directory result))
1586 (set variable result)))
1588 (defun gnus-article-archive-name (group)
1589 "Return the first instance of an \"Archive-name\" in the current buffer."
1590 (let ((case-fold-search t))
1591 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1592 (nnheader-concat gnus-article-save-directory
1593 (match-string 1)))))
1595 (defun gnus-article-nndoc-name (group)
1596 "If GROUP is an nndoc group, return the name of the parent group."
1597 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1598 (gnus-group-get-parameter group 'save-article-group)))
1600 (defun gnus-summary-save-in-rmail (&optional filename)
1601 "Append this article to Rmail file.
1602 Optional argument FILENAME specifies file name.
1603 Directory to save to is default to `gnus-article-save-directory'."
1605 (setq filename (gnus-read-save-file-name
1606 "Save %s in rmail file:" filename
1607 gnus-rmail-save-name gnus-newsgroup-name
1608 gnus-current-headers 'gnus-newsgroup-last-rmail))
1609 (gnus-eval-in-buffer-window gnus-save-article-buffer
1613 (gnus-output-to-rmail filename)))))
1615 (defun gnus-summary-save-in-mail (&optional filename)
1616 "Append this article to Unix mail file.
1617 Optional argument FILENAME specifies file name.
1618 Directory to save to is default to `gnus-article-save-directory'."
1620 (setq filename (gnus-read-save-file-name
1621 "Save %s in Unix mail file:" filename
1622 gnus-mail-save-name gnus-newsgroup-name
1623 gnus-current-headers 'gnus-newsgroup-last-mail))
1624 (gnus-eval-in-buffer-window gnus-save-article-buffer
1628 (if (and (file-readable-p filename)
1629 (mail-file-babyl-p filename))
1630 (gnus-output-to-rmail filename t)
1631 (gnus-output-to-mail filename))))))
1633 (defun gnus-summary-save-in-file (&optional filename overwrite)
1634 "Append this article to file.
1635 Optional argument FILENAME specifies file name.
1636 Directory to save to is default to `gnus-article-save-directory'."
1638 (setq filename (gnus-read-save-file-name
1639 "Save %s in file:" filename
1640 gnus-file-save-name gnus-newsgroup-name
1641 gnus-current-headers 'gnus-newsgroup-last-file))
1642 (gnus-eval-in-buffer-window gnus-save-article-buffer
1646 (when (and overwrite
1647 (file-exists-p filename))
1648 (delete-file filename))
1649 (gnus-output-to-file filename)))))
1651 (defun gnus-summary-write-to-file (&optional filename)
1652 "Write this article to a file.
1653 Optional argument FILENAME specifies file name.
1654 The directory to save in defaults to `gnus-article-save-directory'."
1656 (gnus-summary-save-in-file nil t))
1658 (defun gnus-summary-save-body-in-file (&optional filename)
1659 "Append this article body to a file.
1660 Optional argument FILENAME specifies file name.
1661 The directory to save in defaults to `gnus-article-save-directory'."
1663 (setq filename (gnus-read-save-file-name
1664 "Save %s body in file:" filename
1665 gnus-file-save-name gnus-newsgroup-name
1666 gnus-current-headers 'gnus-newsgroup-last-file))
1667 (gnus-eval-in-buffer-window gnus-save-article-buffer
1671 (goto-char (point-min))
1672 (when (search-forward "\n\n" nil t)
1673 (narrow-to-region (point) (point-max)))
1674 (gnus-output-to-file filename)))))
1676 (defun gnus-summary-save-in-pipe (&optional command)
1677 "Pipe this article to subprocess."
1680 (cond ((eq command 'default)
1681 gnus-last-shell-command)
1685 "Shell command on %s: "
1686 (if (and gnus-number-of-articles-to-be-saved
1687 (> gnus-number-of-articles-to-be-saved 1))
1688 (format "these %d articles"
1689 gnus-number-of-articles-to-be-saved)
1691 gnus-last-shell-command))))
1692 (when (string-equal command "")
1693 (setq command gnus-last-shell-command))
1694 (gnus-eval-in-buffer-window gnus-article-buffer
1697 (shell-command-on-region (point-min) (point-max) command nil)))
1698 (setq gnus-last-shell-command command))
1700 ;;; Article file names when saving.
1702 (defun gnus-capitalize-newsgroup (newsgroup)
1703 "Capitalize NEWSGROUP name."
1704 (when (not (zerop (length newsgroup)))
1705 (concat (char-to-string (upcase (aref newsgroup 0)))
1706 (substring newsgroup 1))))
1708 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1709 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1710 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1711 Otherwise, it is like ~/News/news/group/num."
1714 (concat (if (gnus-use-long-file-name 'not-save)
1715 (gnus-capitalize-newsgroup newsgroup)
1716 (gnus-newsgroup-directory-form newsgroup))
1717 "/" (int-to-string (mail-header-number headers)))
1718 gnus-article-save-directory)))
1720 (string-equal (file-name-directory default)
1721 (file-name-directory last-file))
1722 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1724 (or last-file default))))
1726 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1727 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1728 If variable `gnus-use-long-file-name' is non-nil, it is
1729 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1732 (concat (if (gnus-use-long-file-name 'not-save)
1734 (gnus-newsgroup-directory-form newsgroup))
1735 "/" (int-to-string (mail-header-number headers)))
1736 gnus-article-save-directory)))
1738 (string-equal (file-name-directory default)
1739 (file-name-directory last-file))
1740 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1742 (or last-file default))))
1744 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1745 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1746 If variable `gnus-use-long-file-name' is non-nil, it is
1747 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1750 (if (gnus-use-long-file-name 'not-save)
1751 (gnus-capitalize-newsgroup newsgroup)
1752 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1753 gnus-article-save-directory)))
1755 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1756 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1757 If variable `gnus-use-long-file-name' is non-nil, it is
1758 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1761 (if (gnus-use-long-file-name 'not-save)
1763 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1764 gnus-article-save-directory)))
1771 (setq afunc (car func)
1774 gfunc (intern (format "gnus-%s" func))))
1776 (if (not (fboundp afunc))
1778 `(lambda (&optional interactive &rest args)
1779 ,(documentation afunc t)
1780 (interactive (list t))
1782 (set-buffer gnus-article-buffer)
1784 (call-interactively ',afunc)
1785 (apply ',afunc args))))))))
1786 '(article-hide-headers
1787 article-hide-boring-headers
1788 article-treat-overstrike
1789 (article-fill . gnus-article-word-wrap)
1791 article-display-x-face
1792 article-de-quoted-unreadable
1793 article-mime-decode-quoted-printable
1796 article-hide-signature
1797 article-remove-trailing-blank-lines
1798 article-strip-leading-blank-lines
1799 article-strip-multiple-blank-lines
1800 article-strip-leading-space
1801 article-strip-blank-lines
1803 article-date-original
1808 article-treat-dumbquotes
1809 (article-show-all . gnus-article-show-all-headers))))
1812 ;;; Gnus article mode
1815 (put 'gnus-article-mode 'mode-class 'special)
1817 (gnus-define-keys gnus-article-mode-map
1818 " " gnus-article-goto-next-page
1819 "\177" gnus-article-goto-prev-page
1820 [delete] gnus-article-goto-prev-page
1821 "\C-c^" gnus-article-refer-article
1822 "h" gnus-article-show-summary
1823 "s" gnus-article-show-summary
1824 "\C-c\C-m" gnus-article-mail
1825 "?" gnus-article-describe-briefly
1826 gnus-mouse-2 gnus-article-push-button
1827 "\r" gnus-article-press-button
1828 "\t" gnus-article-next-button
1829 "\M-\t" gnus-article-prev-button
1830 "e" gnus-article-edit
1831 "<" beginning-of-buffer
1833 "\C-c\C-i" gnus-info-find-node
1836 "\C-d" gnus-article-read-summary-keys
1837 "\M-*" gnus-article-read-summary-keys
1838 "\M-#" gnus-article-read-summary-keys
1839 "\M-^" gnus-article-read-summary-keys
1840 "\M-g" gnus-article-read-summary-keys)
1842 (substitute-key-definition
1843 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1845 (defun gnus-article-make-menu-bar ()
1846 (gnus-turn-off-edit-menu 'article)
1847 (unless (boundp 'gnus-article-article-menu)
1849 gnus-article-article-menu gnus-article-mode-map ""
1851 ["Scroll forwards" gnus-article-goto-next-page t]
1852 ["Scroll backwards" gnus-article-goto-prev-page t]
1853 ["Show summary" gnus-article-show-summary t]
1854 ["Fetch Message-ID at point" gnus-article-refer-article t]
1855 ["Mail to address at point" gnus-article-mail t]))
1858 gnus-article-treatment-menu gnus-article-mode-map ""
1860 ["Hide headers" gnus-article-hide-headers t]
1861 ["Hide signature" gnus-article-hide-signature t]
1862 ["Hide citation" gnus-article-hide-citation t]
1863 ["Treat overstrike" gnus-article-treat-overstrike t]
1864 ["Remove carriage return" gnus-article-remove-cr t]
1865 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1868 (when (boundp 'gnus-summary-article-menu)
1869 (define-key gnus-article-mode-map [menu-bar commands]
1870 (cons "Commands" gnus-summary-article-menu))))
1872 (when (boundp 'gnus-summary-post-menu)
1873 (define-key gnus-article-mode-map [menu-bar post]
1874 (cons "Post" gnus-summary-post-menu)))
1876 (run-hooks 'gnus-article-menu-hook)))
1878 (defun gnus-article-mode ()
1879 "Major mode for displaying an article.
1881 All normal editing commands are switched off.
1883 The following commands are available in addition to all summary mode
1885 \\<gnus-article-mode-map>
1886 \\[gnus-article-next-page]\t Scroll the article one page forwards
1887 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1888 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1889 \\[gnus-article-show-summary]\t Display the summary buffer
1890 \\[gnus-article-mail]\t Send a reply to the address near point
1891 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1892 \\[gnus-info-find-node]\t Go to the Gnus info node"
1894 (when (gnus-visual-p 'article-menu 'menu)
1895 (gnus-article-make-menu-bar))
1896 (kill-all-local-variables)
1897 (gnus-simplify-mode-line)
1898 (setq mode-name "Article")
1899 (setq major-mode 'gnus-article-mode)
1900 (make-local-variable 'minor-mode-alist)
1901 (unless (assq 'gnus-show-mime minor-mode-alist)
1902 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1903 (use-local-map gnus-article-mode-map)
1904 (gnus-update-format-specifications nil 'article-mode)
1905 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1906 (set (make-local-variable 'gnus-page-broken) nil)
1907 (set (make-local-variable 'gnus-button-marker-list) nil)
1908 (gnus-set-default-directory)
1909 (buffer-disable-undo (current-buffer))
1910 (setq buffer-read-only t)
1911 (set-syntax-table gnus-article-mode-syntax-table)
1912 (run-hooks 'gnus-article-mode-hook))
1914 (defun gnus-article-setup-buffer ()
1915 "Initialize the article buffer."
1916 (let* ((name (if gnus-single-article-buffer "*Article*"
1917 (concat "*Article " gnus-newsgroup-name "*")))
1919 (progn (string-match "\\*Article" name)
1920 (concat " *Original Article"
1921 (substring name (match-end 0))))))
1922 (setq gnus-article-buffer name)
1923 (setq gnus-original-article-buffer original)
1924 ;; This might be a variable local to the summary buffer.
1925 (unless gnus-single-article-buffer
1927 (set-buffer gnus-summary-buffer)
1928 (setq gnus-article-buffer name)
1929 (setq gnus-original-article-buffer original)
1930 (gnus-set-global-variables)))
1931 ;; Init original article buffer.
1933 (set-buffer (get-buffer-create gnus-original-article-buffer))
1934 (buffer-disable-undo (current-buffer))
1935 (setq major-mode 'gnus-original-article-mode)
1936 (gnus-add-current-to-buffer-list)
1937 (make-local-variable 'gnus-original-article))
1938 (if (get-buffer name)
1941 (buffer-disable-undo (current-buffer))
1942 (setq buffer-read-only t)
1943 (gnus-add-current-to-buffer-list)
1944 (unless (eq major-mode 'gnus-article-mode)
1945 (gnus-article-mode))
1948 (set-buffer (get-buffer-create name))
1949 (gnus-add-current-to-buffer-list)
1951 (make-local-variable 'gnus-summary-buffer)
1952 (current-buffer)))))
1954 ;; Set article window start at LINE, where LINE is the number of lines
1955 ;; from the head of the article.
1956 (defun gnus-article-set-window-start (&optional line)
1958 (get-buffer-window gnus-article-buffer t)
1960 (set-buffer gnus-article-buffer)
1961 (goto-char (point-min))
1964 (gnus-message 6 "Moved to bookmark")
1965 (search-forward "\n\n" nil t)
1969 (defun gnus-article-prepare (article &optional all-headers header)
1970 "Prepare ARTICLE in article mode buffer.
1971 ARTICLE should either be an article number or a Message-ID.
1972 If ARTICLE is an id, HEADER should be the article headers.
1973 If ALL-HEADERS is non-nil, no headers are hidden."
1975 ;; Make sure we start in a summary buffer.
1976 (unless (eq major-mode 'gnus-summary-mode)
1977 (set-buffer gnus-summary-buffer))
1978 (setq gnus-summary-buffer (current-buffer))
1979 ;; Make sure the connection to the server is alive.
1980 (unless (gnus-server-opened
1981 (gnus-find-method-for-group gnus-newsgroup-name))
1982 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1983 (gnus-request-group gnus-newsgroup-name t))
1984 (let* ((gnus-article (if header (mail-header-number header) article))
1985 (summary-buffer (current-buffer))
1986 (internal-hook gnus-article-internal-prepare-hook)
1987 (group gnus-newsgroup-name)
1990 (gnus-article-setup-buffer)
1991 (set-buffer gnus-article-buffer)
1992 ;; Deactivate active regions.
1993 (when (and (boundp 'transient-mark-mode)
1994 transient-mark-mode)
1995 (setq mark-active nil))
1996 (if (not (setq result (let ((buffer-read-only nil))
1997 (gnus-request-article-this-buffer
1999 ;; There is no such article.
2001 (when (and (numberp article)
2002 (not (memq article gnus-newsgroup-sparse)))
2003 (setq gnus-article-current
2004 (cons gnus-newsgroup-name article))
2005 (set-buffer gnus-summary-buffer)
2006 (setq gnus-current-article article)
2007 (gnus-summary-mark-article article gnus-canceled-mark))
2008 (unless (memq article gnus-newsgroup-sparse)
2010 1 "No such article (may have expired or been canceled)")))
2011 (if (or (eq result 'pseudo) (eq result 'nneething))
2014 (set-buffer summary-buffer)
2015 (push article gnus-newsgroup-history)
2016 (setq gnus-last-article gnus-current-article
2017 gnus-current-article 0
2018 gnus-current-headers nil
2019 gnus-article-current nil)
2020 (if (eq result 'nneething)
2021 (gnus-configure-windows 'summary)
2022 (gnus-configure-windows 'article))
2023 (gnus-set-global-variables))
2024 (gnus-set-mode-line 'article))
2025 ;; The result from the `request' was an actual article -
2026 ;; or at least some text that is now displayed in the
2028 (when (and (numberp article)
2029 (not (eq article gnus-current-article)))
2030 ;; Seems like a new article has been selected.
2031 ;; `gnus-current-article' must be an article number.
2033 (set-buffer summary-buffer)
2034 (push article gnus-newsgroup-history)
2035 (setq gnus-last-article gnus-current-article
2036 gnus-current-article article
2037 gnus-current-headers
2038 (gnus-summary-article-header gnus-current-article)
2039 gnus-article-current
2040 (cons gnus-newsgroup-name gnus-current-article))
2041 (unless (vectorp gnus-current-headers)
2042 (setq gnus-current-headers nil))
2043 (gnus-summary-goto-subject gnus-current-article)
2044 (gnus-summary-show-thread)
2045 (run-hooks 'gnus-mark-article-hook)
2046 (gnus-set-mode-line 'summary)
2047 (when (gnus-visual-p 'article-highlight 'highlight)
2048 (run-hooks 'gnus-visual-mark-article-hook))
2049 ;; Set the global newsgroup variables here.
2050 ;; Suggested by Jim Sisolak
2051 ;; <sisolak@trans4.neep.wisc.edu>.
2052 (gnus-set-global-variables)
2053 (setq gnus-have-all-headers
2054 (or all-headers gnus-show-all-headers))
2056 (vectorp (gnus-summary-article-header article))
2057 (gnus-cache-possibly-enter-article
2059 (gnus-summary-article-header article)
2060 (memq article gnus-newsgroup-marked)
2061 (memq article gnus-newsgroup-dormant)
2062 (memq article gnus-newsgroup-unreads)))))
2063 (when (or (numberp article)
2065 ;; Hooks for getting information from the article.
2066 ;; This hook must be called before being narrowed.
2067 (let (buffer-read-only)
2068 (run-hooks 'internal-hook)
2069 (run-hooks 'gnus-article-prepare-hook)
2070 ;; Decode MIME message.
2071 (when gnus-show-mime
2072 (if (or (not gnus-strict-mime)
2073 (gnus-fetch-field "Mime-Version"))
2074 (funcall gnus-show-mime-method)
2075 (funcall gnus-decode-encoded-word-method)))
2076 ;; Perform the article display hooks.
2077 (run-hooks 'gnus-article-display-hook))
2079 (goto-char (point-min))
2080 (setq gnus-page-broken
2081 (when gnus-break-pages
2082 (gnus-narrow-to-page)
2084 (gnus-set-mode-line 'article)
2085 (gnus-configure-windows 'article)
2086 (goto-char (point-min))
2089 (defun gnus-article-wash-status ()
2090 "Return a string which display status of article washing."
2092 (set-buffer gnus-article-buffer)
2093 (let ((cite (gnus-article-hidden-text-p 'cite))
2094 (headers (gnus-article-hidden-text-p 'headers))
2095 (boring (gnus-article-hidden-text-p 'boring-headers))
2096 (pgp (gnus-article-hidden-text-p 'pgp))
2097 (pem (gnus-article-hidden-text-p 'pem))
2098 (signature (gnus-article-hidden-text-p 'signature))
2099 (overstrike (gnus-article-hidden-text-p 'overstrike))
2100 (emphasis (gnus-article-hidden-text-p 'emphasis))
2101 (mime gnus-show-mime))
2102 (format "%c%c%c%c%c%c%c"
2104 (if (or headers boring) ?h ? )
2105 (if (or pgp pem) ?p ? )
2106 (if signature ?s ? )
2107 (if overstrike ?o ? )
2109 (if emphasis ?e ? )))))
2111 (defun gnus-article-hide-headers-if-wanted ()
2112 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2113 Provided for backwards compatibility."
2114 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2116 (gnus-article-hide-headers)))
2120 (defun gnus-output-to-file (file-name)
2121 "Append the current article to a file named FILE-NAME."
2122 (let ((artbuf (current-buffer)))
2123 (nnheader-temp-write nil
2124 (insert-buffer-substring artbuf)
2125 ;; Append newline at end of the buffer as separator, and then
2127 (goto-char (point-max))
2129 (append-to-file (point-min) (point-max) file-name)
2132 (defun gnus-narrow-to-page (&optional arg)
2133 "Narrow the article buffer to a page.
2134 If given a numerical ARG, move forward ARG pages."
2136 (setq arg (if arg (prefix-numeric-value arg) 0))
2138 (set-buffer gnus-article-buffer)
2139 (goto-char (point-min))
2141 ;; Remove any old next/prev buttons.
2142 (when (gnus-visual-p 'page-marker)
2143 (let ((buffer-read-only nil))
2144 (gnus-remove-text-with-property 'gnus-prev)
2145 (gnus-remove-text-with-property 'gnus-next)))
2148 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2150 (re-search-forward page-delimiter nil 'move arg)))
2151 (goto-char (match-end 0)))
2154 (if (re-search-forward page-delimiter nil 'move)
2157 (when (and (gnus-visual-p 'page-marker)
2158 (not (= (point-min) 1)))
2160 (goto-char (point-min))
2161 (gnus-insert-prev-page-button)))
2162 (when (and (gnus-visual-p 'page-marker)
2163 (< (+ (point-max) 2) (buffer-size)))
2165 (goto-char (point-max))
2166 (gnus-insert-next-page-button)))))
2168 ;; Article mode commands
2170 (defun gnus-article-goto-next-page ()
2171 "Show the next page of the article."
2173 (when (gnus-article-next-page)
2174 (goto-char (point-min))
2175 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2177 (defun gnus-article-goto-prev-page ()
2178 "Show the next page of the article."
2180 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2181 (gnus-article-prev-page nil)))
2183 (defun gnus-article-next-page (&optional lines)
2184 "Show the next page of the current article.
2185 If end of article, return non-nil. Otherwise return nil.
2186 Argument LINES specifies lines to be scrolled up."
2188 (move-to-window-line -1)
2191 (and (pos-visible-in-window-p) ;Not continuation line.
2193 ;; Nothing in this page.
2194 (if (or (not gnus-page-broken)
2197 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2199 (gnus-narrow-to-page 1) ;Go to next page.
2201 ;; More in this page.
2202 (let ((scroll-in-place nil))
2206 ;; Long lines may cause an end-of-buffer error.
2207 (goto-char (point-max)))))
2208 (move-to-window-line 0)
2211 (defun gnus-article-prev-page (&optional lines)
2212 "Show previous page of current article.
2213 Argument LINES specifies lines to be scrolled down."
2215 (move-to-window-line 0)
2216 (if (and gnus-page-broken
2218 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2220 (gnus-narrow-to-page -1) ;Go to previous page.
2221 (goto-char (point-max))
2223 (let ((scroll-in-place nil))
2227 (beginning-of-buffer
2228 (goto-char (point-min))))
2229 (move-to-window-line 0)))))
2231 (defun gnus-article-refer-article ()
2232 "Read article specified by message-id around point."
2234 (let ((point (point)))
2235 (search-forward ">" nil t) ;Move point to end of "<....>".
2236 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2237 (let ((message-id (match-string 1)))
2239 (set-buffer gnus-summary-buffer)
2240 (gnus-summary-refer-article message-id))
2242 (error "No references around point"))))
2244 (defun gnus-article-show-summary ()
2245 "Reconfigure windows to show summary buffer."
2247 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2248 (error "There is no summary buffer for this article buffer")
2249 (gnus-article-set-globals)
2250 (gnus-configure-windows 'article)
2251 (gnus-summary-goto-subject gnus-current-article)))
2253 (defun gnus-article-describe-briefly ()
2254 "Describe article mode commands briefly."
2257 (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")))
2259 (defun gnus-article-summary-command ()
2260 "Execute the last keystroke in the summary buffer."
2262 (let ((obuf (current-buffer))
2263 (owin (current-window-configuration))
2265 (switch-to-buffer gnus-summary-buffer 'norecord)
2266 (setq func (lookup-key (current-local-map) (this-command-keys)))
2267 (call-interactively func)
2269 (set-window-configuration owin)
2270 (set-window-point (get-buffer-window (current-buffer)) (point))))
2272 (defun gnus-article-summary-command-nosave ()
2273 "Execute the last keystroke in the summary buffer."
2276 (pop-to-buffer gnus-summary-buffer 'norecord)
2277 (setq func (lookup-key (current-local-map) (this-command-keys)))
2278 (call-interactively func)))
2280 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2281 "Read a summary buffer key sequence and execute it from the article buffer."
2284 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2285 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2286 "=" "^" "\M-^" "|"))
2293 (set-buffer gnus-summary-buffer)
2294 (let (gnus-pick-mode)
2295 (push (or key last-command-event) unread-command-events)
2296 (setq keys (read-key-sequence nil))))
2299 (if (or (member keys nosaves)
2300 (member keys nosave-but-article)
2301 (member keys nosave-in-article))
2303 (save-window-excursion
2304 (pop-to-buffer gnus-summary-buffer 'norecord)
2305 ;; We disable the pick minor mode commands.
2306 (let (gnus-pick-mode)
2307 (setq func (lookup-key (current-local-map) keys))))
2310 (unless (member keys nosave-in-article)
2311 (set-buffer gnus-summary-buffer))
2312 (call-interactively func))
2313 (when (member keys nosave-but-article)
2314 (pop-to-buffer gnus-article-buffer 'norecord)))
2315 ;; These commands should restore window configuration.
2316 (let ((obuf (current-buffer))
2317 (owin (current-window-configuration))
2320 (if not-restore-window
2321 (pop-to-buffer gnus-summary-buffer 'norecord)
2322 (switch-to-buffer gnus-summary-buffer 'norecord))
2323 (setq in-buffer (current-buffer))
2324 ;; We disable the pick minor mode commands.
2325 (if (setq func (let (gnus-pick-mode)
2326 (lookup-key (current-local-map) keys)))
2327 (call-interactively func)
2329 (when (eq in-buffer (current-buffer))
2331 (unless not-restore-window
2332 (set-window-configuration owin))
2333 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2335 (defun gnus-article-hide (&optional arg force)
2336 "Hide all the gruft in the current article.
2337 This means that PGP stuff, signatures, cited text and (some)
2338 headers will be hidden.
2339 If given a prefix, show the hidden text instead."
2340 (interactive (list current-prefix-arg 'force))
2341 (gnus-article-hide-headers arg)
2342 (gnus-article-hide-pgp arg)
2343 (gnus-article-hide-citation-maybe arg force)
2344 (gnus-article-hide-signature arg))
2346 (defun gnus-article-maybe-highlight ()
2347 "Do some article highlighting if `article-visual' is non-nil."
2348 (when (gnus-visual-p 'article-highlight 'highlight)
2349 (gnus-article-highlight-some)))
2351 (defun gnus-request-article-this-buffer (article group)
2352 "Get an article and insert it into this buffer."
2353 (let (do-update-line)
2357 (gnus-kill-all-overlays)
2358 (setq group (or group gnus-newsgroup-name))
2360 ;; Open server if it has closed.
2361 (gnus-check-server (gnus-find-method-for-group group))
2363 ;; Using `gnus-request-article' directly will insert the article into
2364 ;; `nntp-server-buffer' - so we'll save some time by not having to
2365 ;; copy it from the server buffer into the article buffer.
2367 ;; We only request an article by message-id when we do not have the
2368 ;; headers for it, so we'll have to get those.
2369 (when (stringp article)
2370 (let ((gnus-override-method gnus-refer-article-method))
2371 (gnus-read-header article)))
2373 ;; If the article number is negative, that means that this article
2374 ;; doesn't belong in this newsgroup (possibly), so we find its
2375 ;; message-id and request it by id instead of number.
2376 (when (and (numberp article)
2378 (get-buffer gnus-summary-buffer)
2379 (buffer-name (get-buffer gnus-summary-buffer)))
2381 (set-buffer gnus-summary-buffer)
2382 (let ((header (gnus-summary-article-header article)))
2385 ((memq article gnus-newsgroup-sparse)
2386 ;; This is a sparse gap article.
2387 (setq do-update-line article)
2388 (setq article (mail-header-id header))
2389 (let ((gnus-override-method gnus-refer-article-method))
2390 (gnus-read-header article))
2391 (setq gnus-newsgroup-sparse
2392 (delq article gnus-newsgroup-sparse)))
2394 ;; It's a real article.
2395 (setq article (mail-header-id header)))
2397 ;; It is an extracted pseudo-article.
2398 (setq article 'pseudo)
2399 (gnus-request-pseudo-article header))))
2401 (let ((method (gnus-find-method-for-group
2402 gnus-newsgroup-name)))
2403 (if (not (eq (car method) 'nneething))
2405 (let ((dir (concat (file-name-as-directory (nth 1 method))
2406 (mail-header-subject header))))
2407 (when (file-directory-p dir)
2408 (setq article 'nneething)
2409 (gnus-group-enter-directory dir))))))))
2412 ;; Refuse to select canceled articles.
2413 ((and (numberp article)
2415 (get-buffer gnus-summary-buffer)
2416 (buffer-name (get-buffer gnus-summary-buffer))
2417 (eq (cdr (save-excursion
2418 (set-buffer gnus-summary-buffer)
2419 (assq article gnus-newsgroup-reads)))
2420 gnus-canceled-mark))
2422 ;; We first check `gnus-original-article-buffer'.
2423 ((and (get-buffer gnus-original-article-buffer)
2426 (set-buffer gnus-original-article-buffer)
2427 (and (equal (car gnus-original-article) group)
2428 (eq (cdr gnus-original-article) article))))
2429 (insert-buffer-substring gnus-original-article-buffer)
2431 ;; Check the backlog.
2432 ((and gnus-keep-backlog
2433 (gnus-backlog-request-article group article (current-buffer)))
2435 ;; Check asynchronous pre-fetch.
2436 ((gnus-async-request-fetched-article group article (current-buffer))
2437 (gnus-async-prefetch-next group article gnus-summary-buffer)
2440 ((and gnus-use-cache
2442 (gnus-cache-request-article article group))
2444 ;; Get the article and put into the article buffer.
2445 ((or (stringp article) (numberp article))
2446 (let ((gnus-override-method
2447 (and (stringp article) gnus-refer-article-method))
2448 (buffer-read-only nil))
2450 (gnus-kill-all-overlays)
2451 (when (gnus-request-article article group (current-buffer))
2452 (when (numberp article)
2453 (gnus-async-prefetch-next group article gnus-summary-buffer)
2454 (when gnus-keep-backlog
2455 (gnus-backlog-enter-article
2456 group article (current-buffer))))
2461 ;; Take the article from the original article buffer
2462 ;; and place it in the buffer it's supposed to be in.
2463 (when (and (get-buffer gnus-article-buffer)
2465 (equal (buffer-name (current-buffer))
2466 (buffer-name (get-buffer gnus-article-buffer))))
2468 (if (get-buffer gnus-original-article-buffer)
2469 (set-buffer (get-buffer gnus-original-article-buffer))
2470 (set-buffer (get-buffer-create gnus-original-article-buffer))
2471 (buffer-disable-undo (current-buffer))
2472 (setq major-mode 'gnus-original-article-mode)
2473 (setq buffer-read-only t)
2474 (gnus-add-current-to-buffer-list))
2475 (let (buffer-read-only)
2477 (insert-buffer-substring gnus-article-buffer))
2478 (setq gnus-original-article (cons group article))))
2480 ;; Update sparse articles.
2481 (when (and do-update-line
2482 (or (numberp article)
2484 (let ((buf (current-buffer)))
2485 (set-buffer gnus-summary-buffer)
2486 (gnus-summary-update-article do-update-line)
2487 (gnus-summary-goto-subject do-update-line nil t)
2488 (set-window-point (get-buffer-window (current-buffer) t)
2490 (set-buffer buf))))))
2496 (defcustom gnus-article-edit-mode-hook nil
2497 "Hook run in article edit mode buffers."
2498 :group 'gnus-article-various
2501 (defvar gnus-article-edit-done-function nil)
2503 (defvar gnus-article-edit-mode-map nil)
2505 (unless gnus-article-edit-mode-map
2506 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2508 (gnus-define-keys gnus-article-edit-mode-map
2509 "\C-c\C-c" gnus-article-edit-done
2510 "\C-c\C-k" gnus-article-edit-exit)
2512 (gnus-define-keys (gnus-article-edit-wash-map
2513 "\C-c\C-w" gnus-article-edit-mode-map)
2514 "f" gnus-article-edit-full-stops))
2516 (defun gnus-article-edit-mode ()
2517 "Major mode for editing articles.
2518 This is an extended text-mode.
2520 \\{gnus-article-edit-mode-map}"
2522 (kill-all-local-variables)
2523 (setq major-mode 'gnus-article-edit-mode)
2524 (setq mode-name "Article Edit")
2525 (use-local-map gnus-article-edit-mode-map)
2526 (make-local-variable 'gnus-article-edit-done-function)
2527 (make-local-variable 'gnus-prev-winconf)
2528 (setq buffer-read-only nil)
2529 (buffer-enable-undo)
2531 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2533 (defun gnus-article-edit (&optional force)
2534 "Edit the current article.
2535 This will have permanent effect only in mail groups.
2536 If FORCE is non-nil, allow editing of articles even in read-only
2539 (when (and (not force)
2540 (gnus-group-read-only-p))
2541 (error "The current newsgroup does not support article editing"))
2542 (gnus-article-edit-article
2543 `(lambda (no-highlight)
2544 (gnus-summary-edit-article-done
2545 ,(or (mail-header-references gnus-current-headers) "")
2546 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2548 (defun gnus-article-edit-article (exit-func)
2549 "Start editing the contents of the current article buffer."
2550 (let ((winconf (current-window-configuration)))
2551 (set-buffer gnus-article-buffer)
2552 (gnus-article-edit-mode)
2553 (gnus-set-text-properties (point-min) (point-max) nil)
2554 (gnus-configure-windows 'edit-article)
2555 (setq gnus-article-edit-done-function exit-func)
2556 (setq gnus-prev-winconf winconf)
2557 (gnus-message 6 "C-c C-c to end edits")))
2559 (defun gnus-article-edit-done (&optional arg)
2560 "Update the article edits and exit."
2562 (let ((func gnus-article-edit-done-function)
2563 (buf (current-buffer))
2564 (start (window-start)))
2565 (gnus-article-edit-exit)
2568 (let ((buffer-read-only nil))
2569 (funcall func arg)))
2571 (set-window-start (get-buffer-window buf) start)
2572 (set-window-point (get-buffer-window buf) (point))))
2574 (defun gnus-article-edit-exit ()
2575 "Exit the article editing without updating."
2577 ;; We remove all text props from the article buffer.
2578 (let ((buf (format "%s" (buffer-string)))
2579 (curbuf (current-buffer))
2581 (window-start (window-start)))
2584 (let ((winconf gnus-prev-winconf))
2586 ;; The cache and backlog have to be flushed somewhat.
2587 (when gnus-use-cache
2588 (gnus-cache-update-article
2589 (car gnus-article-current) (cdr gnus-article-current)))
2590 (when gnus-keep-backlog
2591 (gnus-backlog-remove-article
2592 (car gnus-article-current) (cdr gnus-article-current)))
2593 ;; Flush original article as well.
2595 (when (get-buffer gnus-original-article-buffer)
2596 (set-buffer gnus-original-article-buffer)
2597 (setq gnus-original-article nil)))
2598 (set-window-configuration winconf)
2599 ;; Tippy-toe some to make sure that point remains where it was.
2600 (let ((buf (current-buffer)))
2602 (set-window-start (get-buffer-window (current-buffer)) window-start)
2604 (set-buffer buf)))))
2606 (defun gnus-article-edit-full-stops ()
2607 "Interactively repair spacing at end of sentences."
2610 (goto-char (point-min))
2611 (search-forward-regexp "^$" nil t)
2612 (let ((case-fold-search nil))
2613 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2616 ;;; Article highlights
2619 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2621 ;;; Internal Variables:
2623 (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\\)"
2624 "Regular expression that matches URLs."
2625 :group 'gnus-article-buttons
2628 (defcustom gnus-button-alist
2629 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2630 gnus-button-message-id 2)
2631 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2632 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2633 gnus-button-fetch-group 4)
2634 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2635 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2636 t gnus-button-message-id 3)
2637 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2638 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2639 ;; This is how URLs _should_ be embedded in text...
2640 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2642 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2643 "Alist of regexps matching buttons in article bodies.
2645 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2646 REGEXP: is the string matching text around the button,
2647 BUTTON: is the number of the regexp grouping actually matching the button,
2648 FORM: is a lisp expression which must eval to true for the button to
2650 CALLBACK: is the function to call when the user push this button, and each
2651 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2653 CALLBACK can also be a variable, in that case the value of that
2654 variable it the real callback function."
2655 :group 'gnus-article-buttons
2656 :type '(repeat (list regexp
2657 (integer :tag "Button")
2659 (function :tag "Callback")
2662 (integer :tag "Regexp group")))))
2664 (defcustom gnus-header-button-alist
2665 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2666 0 t gnus-button-message-id 0)
2667 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2668 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2669 0 t gnus-button-mailto 0)
2670 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2671 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2672 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2673 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2674 gnus-button-message-id 3))
2675 "Alist of headers and regexps to match buttons in article heads.
2677 This alist is very similar to `gnus-button-alist', except that each
2678 alist has an additional HEADER element first in each entry:
2680 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2682 HEADER is a regexp to match a header. For a fuller explanation, see
2683 `gnus-button-alist'."
2684 :group 'gnus-article-buttons
2685 :group 'gnus-article-headers
2686 :type '(repeat (list (regexp :tag "Header")
2688 (integer :tag "Button")
2690 (function :tag "Callback")
2693 (integer :tag "Regexp group")))))
2695 (defvar gnus-button-regexp nil)
2696 (defvar gnus-button-marker-list nil)
2697 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2699 (defvar gnus-button-last nil)
2700 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2704 (defun gnus-article-push-button (event)
2705 "Check text under the mouse pointer for a callback function.
2706 If the text under the mouse pointer has a `gnus-callback' property,
2707 call it with the value of the `gnus-data' text property."
2709 (set-buffer (window-buffer (posn-window (event-start event))))
2710 (let* ((pos (posn-point (event-start event)))
2711 (data (get-text-property pos 'gnus-data))
2712 (fun (get-text-property pos 'gnus-callback)))
2714 (funcall fun data))))
2716 (defun gnus-article-press-button ()
2717 "Check text at point for a callback function.
2718 If the text at point has a `gnus-callback' property,
2719 call it with the value of the `gnus-data' text property."
2721 (let* ((data (get-text-property (point) 'gnus-data))
2722 (fun (get-text-property (point) 'gnus-callback)))
2724 (funcall fun data))))
2726 (defun gnus-article-prev-button (n)
2727 "Move point to N buttons backward.
2728 If N is negative, move forward instead."
2730 (gnus-article-next-button (- n)))
2732 (defun gnus-article-next-button (n)
2733 "Move point to N buttons forward.
2734 If N is negative, move backward instead."
2736 (let ((function (if (< n 0) 'previous-single-property-change
2737 'next-single-property-change))
2738 (inhibit-point-motion-hooks t)
2740 (limit (if (< n 0) (point-min) (point-max))))
2742 (while (and (not (= limit (point)))
2744 ;; Skip past the current button.
2745 (when (get-text-property (point) 'gnus-callback)
2746 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2747 ;; Go to the next (or previous) button.
2748 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2749 ;; Put point at the start of the button.
2750 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2751 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2752 ;; Skip past intangible buttons.
2753 (when (get-text-property (point) 'intangible)
2757 (gnus-message 5 "No more buttons"))
2760 (defun gnus-article-highlight (&optional force)
2761 "Highlight current article.
2762 This function calls `gnus-article-highlight-headers',
2763 `gnus-article-highlight-citation',
2764 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2765 do the highlighting. See the documentation for those functions."
2766 (interactive (list 'force))
2767 (gnus-article-highlight-headers)
2768 (gnus-article-highlight-citation force)
2769 (gnus-article-highlight-signature)
2770 (gnus-article-add-buttons force)
2771 (gnus-article-add-buttons-to-head))
2773 (defun gnus-article-highlight-some (&optional force)
2774 "Highlight current article.
2775 This function calls `gnus-article-highlight-headers',
2776 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2777 do the highlighting. See the documentation for those functions."
2778 (interactive (list 'force))
2779 (gnus-article-highlight-headers)
2780 (gnus-article-highlight-signature)
2781 (gnus-article-add-buttons))
2783 (defun gnus-article-highlight-headers ()
2784 "Highlight article headers as specified by `gnus-header-face-alist'."
2787 (set-buffer gnus-article-buffer)
2789 (let ((alist gnus-header-face-alist)
2790 (buffer-read-only nil)
2791 (case-fold-search t)
2792 (inhibit-point-motion-hooks t)
2793 entry regexp header-face field-face from hpoints fpoints)
2794 (message-narrow-to-head)
2795 (while (setq entry (pop alist))
2796 (goto-char (point-min))
2797 (setq regexp (concat "^\\("
2798 (if (string-equal "" (nth 0 entry))
2802 header-face (nth 1 entry)
2803 field-face (nth 2 entry))
2804 (while (and (re-search-forward regexp nil t)
2808 (unless (search-forward ":" nil t)
2810 (when (and header-face
2811 (not (memq (point) hpoints)))
2812 (push (point) hpoints)
2813 (gnus-put-text-property from (point) 'face header-face))
2814 (when (and field-face
2815 (not (memq (setq from (point)) fpoints)))
2817 (if (re-search-forward "^[^ \t]" nil t)
2819 (goto-char (point-max)))
2820 (gnus-put-text-property from (point) 'face field-face))))))))
2822 (defun gnus-article-highlight-signature ()
2823 "Highlight the signature in an article.
2824 It does this by highlighting everything after
2825 `gnus-signature-separator' using `gnus-signature-face'."
2828 (set-buffer gnus-article-buffer)
2829 (let ((buffer-read-only nil)
2830 (inhibit-point-motion-hooks t))
2832 (when (and gnus-signature-face
2833 (gnus-article-narrow-to-signature))
2834 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2835 'face gnus-signature-face)
2837 (gnus-article-search-signature)
2838 (let ((start (match-beginning 0))
2839 (end (set-marker (make-marker) (1+ (match-end 0)))))
2840 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2843 (defun gnus-button-in-region-p (b e prop)
2844 "Say whether PROP exists in the region."
2845 (text-property-not-all b e prop nil))
2847 (defun gnus-article-add-buttons (&optional force)
2848 "Find external references in the article and make buttons of them.
2849 \"External references\" are things like Message-IDs and URLs, as
2850 specified by `gnus-button-alist'."
2851 (interactive (list 'force))
2853 (set-buffer gnus-article-buffer)
2854 (let ((buffer-read-only nil)
2855 (inhibit-point-motion-hooks t)
2856 (case-fold-search t)
2857 (alist gnus-button-alist)
2859 ;; Remove all old markers.
2861 (while (setq marker (pop gnus-button-marker-list))
2863 (when (setq entry (gnus-button-entry))
2864 (put-text-property (match-beginning (nth 1 entry))
2865 (match-end (nth 1 entry))
2866 'gnus-callback nil))
2867 (set-marker marker nil)))
2868 ;; We skip the headers.
2869 (goto-char (point-min))
2870 (unless (search-forward "\n\n" nil t)
2871 (goto-char (point-max)))
2873 (while (setq entry (pop alist))
2874 (setq regexp (car entry))
2876 (while (re-search-forward regexp nil t)
2877 (let* ((start (and entry (match-beginning (nth 1 entry))))
2878 (end (and entry (match-end (nth 1 entry))))
2879 (from (match-beginning 0)))
2880 (when (and (or (eq t (nth 2 entry))
2881 (eval (nth 2 entry)))
2882 (not (gnus-button-in-region-p
2883 start end 'gnus-callback)))
2884 ;; That optional form returned non-nil, so we add the
2886 (gnus-article-add-button
2887 start end 'gnus-button-push
2888 (car (push (set-marker (make-marker) from)
2889 gnus-button-marker-list))))))))))
2891 ;; Add buttons to the head of an article.
2892 (defun gnus-article-add-buttons-to-head ()
2893 "Add buttons to the head of the article."
2896 (set-buffer gnus-article-buffer)
2897 (let ((buffer-read-only nil)
2898 (inhibit-point-motion-hooks t)
2899 (case-fold-search t)
2900 (alist gnus-header-button-alist)
2902 (nnheader-narrow-to-headers)
2904 ;; Each alist entry.
2905 (setq entry (car alist)
2907 (goto-char (point-min))
2908 (while (re-search-forward (car entry) nil t)
2909 ;; Each header matching the entry.
2910 (setq beg (match-beginning 0))
2911 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2912 (match-beginning 0))
2915 (while (re-search-forward (nth 1 entry) end t)
2916 ;; Each match within a header.
2917 (let* ((entry (cdr entry))
2918 (start (match-beginning (nth 1 entry)))
2919 (end (match-end (nth 1 entry)))
2920 (form (nth 2 entry)))
2921 (goto-char (match-end 0))
2923 (gnus-article-add-button
2924 start end (nth 3 entry)
2925 (buffer-substring (match-beginning (nth 4 entry))
2926 (match-end (nth 4 entry)))))))
2930 ;;; External functions:
2932 (defun gnus-article-add-button (from to fun &optional data)
2933 "Create a button between FROM and TO with callback FUN and data DATA."
2934 (when gnus-article-button-face
2935 (gnus-overlay-put (gnus-make-overlay from to)
2936 'face gnus-article-button-face))
2937 (gnus-add-text-properties
2939 (nconc (and gnus-article-mouse-face
2940 (list gnus-mouse-face-prop gnus-article-mouse-face))
2941 (list 'gnus-callback fun)
2942 (and data (list 'gnus-data data)))))
2944 ;;; Internal functions:
2946 (defun gnus-article-set-globals ()
2948 (set-buffer gnus-summary-buffer)
2949 (gnus-set-global-variables)))
2951 (defun gnus-signature-toggle (end)
2953 (set-buffer gnus-article-buffer)
2954 (let ((buffer-read-only nil)
2955 (inhibit-point-motion-hooks t))
2956 (if (get-text-property end 'invisible)
2957 (gnus-article-unhide-text end (point-max))
2958 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2960 (defun gnus-button-entry ()
2961 ;; Return the first entry in `gnus-button-alist' matching this place.
2962 (let ((alist gnus-button-alist)
2965 (setq entry (pop alist))
2966 (if (looking-at (car entry))
2971 (defun gnus-button-push (marker)
2972 ;; Push button starting at MARKER.
2974 (set-buffer gnus-article-buffer)
2976 (let* ((entry (gnus-button-entry))
2977 (inhibit-point-motion-hooks t)
2979 (args (mapcar (lambda (group)
2980 (let ((string (match-string group)))
2981 (gnus-set-text-properties
2982 0 (length string) nil string)
2989 (fboundp (symbol-value fun)))
2990 (apply (symbol-value fun) args))
2992 (gnus-message 1 "You must define `%S' to use this button"
2993 (cons fun args)))))))
2995 (defun gnus-button-message-id (message-id)
2998 (set-buffer gnus-summary-buffer)
2999 (gnus-summary-refer-article message-id)))
3001 (defun gnus-button-fetch-group (address)
3002 "Fetch GROUP specified by ADDRESS."
3003 (if (not (string-match "[:/]" address))
3004 ;; This is just a simple group url.
3005 (gnus-group-read-ephemeral-group address gnus-select-method)
3006 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3008 (error "Can't parse %s" address)
3009 (gnus-group-read-ephemeral-group
3010 (match-string 4 address)
3011 `(nntp ,(match-string 1 address)
3012 (nntp-address ,(match-string 1 address))
3013 (nntp-port-number ,(if (match-end 3)
3014 (match-string 3 address)
3017 (defun gnus-split-string (string pattern)
3018 "Return a list of substrings of STRING which are separated by PATTERN."
3019 (let (parts (start 0))
3020 (while (string-match pattern string start)
3021 (setq parts (cons (substring string start (match-beginning 0)) parts)
3022 start (match-end 0)))
3023 (nreverse (cons (substring string start) parts))))
3025 (defun gnus-url-parse-query-string (query &optional downcase)
3026 (let (retval pairs cur key val)
3027 (setq pairs (gnus-split-string query "&"))
3029 (setq cur (car pairs)
3031 (if (not (string-match "=" cur))
3033 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3034 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3036 (setq key (downcase key)))
3037 (setq cur (assoc key retval))
3039 (setcdr cur (cons val (cdr cur)))
3040 (setq retval (cons (list key val) retval)))))
3043 (defun gnus-url-unhex (x)
3050 (defun gnus-url-unhex-string (str &optional allow-newlines)
3051 "Remove %XXX embedded spaces, etc in a url.
3052 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3053 decoding of carriage returns and line feeds in the string, which is normally
3054 forbidden in URL encoding."
3055 (setq str (or str ""))
3057 (case-fold-search t))
3058 (while (string-match "%[0-9a-f][0-9a-f]" str)
3059 (let* ((start (match-beginning 0))
3060 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3062 (gnus-url-unhex (elt str (+ start 2))))))
3064 tmp (substring str 0 start)
3067 (char-to-string code))
3068 ((or (= code ?\n) (= code ?\r))
3070 (t (char-to-string code))))
3071 str (substring str (match-end 0)))))
3072 (setq tmp (concat tmp str))
3075 (defun gnus-url-mailto (url)
3076 ;; Send mail to someone
3077 (when (string-match "mailto:/*\\(.*\\)" url)
3078 (setq url (substring url (match-beginning 1) nil)))
3079 (let (to args source-url subject func)
3080 (if (string-match (regexp-quote "?") url)
3081 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3082 args (gnus-url-parse-query-string
3083 (substring url (match-end 0) nil) t))
3084 (setq to (gnus-url-unhex-string url)))
3085 (setq args (cons (list "to" to) args)
3086 subject (cdr-safe (assoc "subject" args)))
3089 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3092 (message-position-on-field (caar args)))
3093 (insert (mapconcat 'identity (cdar args) ", "))
3094 (setq args (cdr args)))
3097 (message-goto-subject))))
3099 (defun gnus-button-mailto (address)
3101 (set-buffer (gnus-copy-article-buffer))
3102 (message-reply address))
3104 (defun gnus-button-reply (address)
3105 ;; Reply to ADDRESS.
3106 (message-reply address))
3108 (defun gnus-button-url (address)
3110 (funcall browse-url-browser-function address))
3112 (defun gnus-button-embedded-url (address)
3114 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3116 ;;; Next/prev buttons in the article buffer.
3118 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3119 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3121 (defvar gnus-prev-page-map nil)
3122 (unless gnus-prev-page-map
3123 (setq gnus-prev-page-map (make-sparse-keymap))
3124 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3125 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3127 (defun gnus-insert-prev-page-button ()
3128 (let ((buffer-read-only nil))
3130 gnus-prev-page-line-format nil
3131 `(gnus-prev t local-map ,gnus-prev-page-map
3132 gnus-callback gnus-article-button-prev-page))))
3134 (defvar gnus-next-page-map nil)
3135 (unless gnus-next-page-map
3136 (setq gnus-next-page-map (make-keymap))
3137 (suppress-keymap gnus-prev-page-map)
3138 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3139 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3141 (defun gnus-button-next-page ()
3142 "Go to the next page."
3144 (let ((win (selected-window)))
3145 (select-window (get-buffer-window gnus-article-buffer t))
3146 (gnus-article-next-page)
3147 (select-window win)))
3149 (defun gnus-button-prev-page ()
3150 "Go to the prev page."
3152 (let ((win (selected-window)))
3153 (select-window (get-buffer-window gnus-article-buffer t))
3154 (gnus-article-prev-page)
3155 (select-window win)))
3157 (defun gnus-insert-next-page-button ()
3158 (let ((buffer-read-only nil))
3159 (gnus-eval-format gnus-next-page-line-format nil
3160 `(gnus-next t local-map ,gnus-next-page-map
3162 gnus-article-button-next-page))))
3164 (defun gnus-article-button-next-page (arg)
3165 "Go to the next page."
3167 (let ((win (selected-window)))
3168 (select-window (get-buffer-window gnus-article-buffer t))
3169 (gnus-article-next-page)
3170 (select-window win)))
3172 (defun gnus-article-button-prev-page (arg)
3173 "Go to the prev page."
3175 (let ((win (selected-window)))
3176 (select-window (get-buffer-window gnus-article-buffer t))
3177 (gnus-article-prev-page)
3178 (select-window win)))
3184 (run-hooks 'gnus-art-load-hook)
3186 ;;; gnus-art.el ends here