1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
37 (defgroup gnus-article nil
39 :link '(custom-manual "(gnus)The Article Buffer")
42 (defgroup gnus-article-hiding nil
43 "Hiding article parts."
44 :link '(custom-manual "(gnus)Article Hiding")
47 (defgroup gnus-article-highlight nil
48 "Article highlighting."
49 :link '(custom-manual "(gnus)Article Highlighting")
53 (defgroup gnus-article-signature nil
55 :link '(custom-manual "(gnus)Article Signature")
58 (defgroup gnus-article-headers nil
60 :link '(custom-manual "(gnus)Hiding Headers")
63 (defgroup gnus-article-washing nil
64 "Special commands on articles."
65 :link '(custom-manual "(gnus)Article Washing")
68 (defgroup gnus-article-emphasis nil
69 "Fontisizing articles."
70 :link '(custom-manual "(gnus)Article Fontisizing")
73 (defgroup gnus-article-saving nil
75 :link '(custom-manual "(gnus)Saving Articles")
78 (defgroup gnus-article-mime nil
79 "Worshiping the MIME wonder."
80 :link '(custom-manual "(gnus)Using MIME")
83 (defgroup gnus-article-buttons nil
84 "Pushable buttons in the article buffer."
85 :link '(custom-manual "(gnus)Article Buttons")
88 (defgroup gnus-article-various nil
89 "Other article options."
90 :link '(custom-manual "(gnus)Misc Article")
93 (defcustom gnus-ignored-headers
94 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
95 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
96 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
97 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
98 "*All headers that start with this regexp will be hidden.
99 This variable can also be a list of regexps of headers to be ignored.
100 If `gnus-visible-headers' is non-nil, this variable will be ignored."
101 :type '(choice :custom-show nil
104 :group 'gnus-article-hiding)
106 (defcustom gnus-visible-headers
107 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
108 "*All headers that do not match this regexp will be hidden.
109 This variable can also be a list of regexp of headers to remain visible.
110 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
111 :type '(repeat :value-to-internal (lambda (widget value)
112 (custom-split-regexp-maybe value))
113 :match (lambda (widget value)
115 (widget-editable-list-match widget value)))
117 :group 'gnus-article-hiding)
119 (defcustom gnus-sorted-header-list
120 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
121 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
122 "*This variable is a list of regular expressions.
123 If it is non-nil, headers that match the regular expressions will
124 be placed first in the article buffer in the sequence specified by
126 :type '(repeat regexp)
127 :group 'gnus-article-hiding)
129 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
130 "Headers that are only to be displayed if they have interesting data.
131 Possible values in this list are `empty', `newsgroups', `followup-to',
132 `reply-to', `date', `long-to', and `many-to'."
133 :type '(set (const :tag "Headers with no content." empty)
134 (const :tag "Newsgroups with only one group." newsgroups)
135 (const :tag "Followup-to identical to newsgroups." followup-to)
136 (const :tag "Reply-to identical to from." reply-to)
137 (const :tag "Date less than four days old." date)
138 (const :tag "Very long To header." long-to)
139 (const :tag "Multiple To headers." many-to))
140 :group 'gnus-article-hiding)
142 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
143 "Regexp matching signature separator.
144 This can also be a list of regexps. In that case, it will be checked
145 from head to tail looking for a separator. Searches will be done from
146 the end of the buffer."
147 :type '(repeat string)
148 :group 'gnus-article-signature)
150 (defcustom gnus-signature-limit nil
151 "Provide a limit to what is considered a signature.
152 If it is a number, no signature may not be longer (in characters) than
153 that number. If it is a floating point number, no signature may be
154 longer (in lines) than that number. If it is a function, the function
155 will be called without any parameters, and if it returns nil, there is
156 no signature in the buffer. If it is a string, it will be used as a
157 regexp. If it matches, the text in question is not a signature."
158 :type '(choice (integer :value 200)
160 (function :value fun)
161 (regexp :value ".*"))
162 :group 'gnus-article-signature)
164 (defcustom gnus-hidden-properties '(invisible t intangible t)
165 "Property list to use for hiding text."
167 :group 'gnus-article-hiding)
169 (defcustom gnus-article-x-face-command
170 " echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
171 "*String or function to be executed to display an X-Face header.
172 If it is a string, the command will be executed in a sub-shell
173 asynchronously. The compressed face will be piped to this command."
174 :type 'string ;Leave function case to Lisp.
175 :group 'gnus-article-washing)
177 (defcustom gnus-article-x-face-too-ugly nil
178 "Regexp matching posters whose face shouldn't be shown automatically."
179 :type '(choice regexp (const nil))
180 :group 'gnus-article-washing)
182 (defcustom gnus-emphasis-alist
184 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
186 '(("_" "_" underline)
189 ("_/" "/_" underline-italic)
190 ("_\\*" "\\*_" underline-bold)
191 ("\\*/" "/\\*" bold-italic)
192 ("_\\*/" "/\\*_" underline-bold-italic))))
193 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
194 2 3 gnus-emphasis-underline)
198 (format format (car spec) (cadr spec))
199 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
201 "*Alist that says how to fontify certain phrases.
202 Each item looks like this:
204 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
206 The first element is a regular expression to be matched. The second
207 is a number that says what regular expression grouping used to find
208 the entire emphasized word. The third is a number that says what
209 regexp grouping should be displayed and highlighted. The fourth
210 is the face used for highlighting."
211 :type '(repeat (list :value ("" 0 0 default)
213 (integer :tag "Match group")
214 (integer :tag "Emphasize group")
216 :group 'gnus-article-emphasis)
218 (defface gnus-emphasis-bold '((t (:bold t)))
219 "Face used for displaying strong emphasized text (*word*)."
220 :group 'gnus-article-emphasis)
222 (defface gnus-emphasis-italic '((t (:italic t)))
223 "Face used for displaying italic emphasized text (/word/)."
224 :group 'gnus-article-emphasis)
226 (defface gnus-emphasis-underline '((t (:underline t)))
227 "Face used for displaying underlined emphasized text (_word_)."
228 :group 'gnus-article-emphasis)
230 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
231 "Face used for displaying underlined bold emphasized text (_*word*_)."
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
235 "Face used for displaying underlined italic emphasized text (_*word*_)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
239 "Face used for displaying bold italic emphasized text (/*word*/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline-bold-italic
243 '((t (:bold t :italic t :underline t)))
244 "Face used for displaying underlined bold italic emphasized text.
245 Esample: (_/*word*/_)."
246 :group 'gnus-article-emphasis)
248 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
249 "Format for display of Date headers in article bodies.
250 See `format-time-string' for the possible values.
252 The variable can also be function, which should return a complete Date
253 header. The function is called with one argument, the time, which can
254 be fed to `format-time-string'."
255 :type '(choice string symbol)
256 :link '(custom-manual "(gnus)Article Date")
257 :group 'gnus-article-washing)
260 (autoload 'hexl-hex-string-to-integer "hexl")
261 (autoload 'timezone-make-date-arpa-standard "timezone")
262 (autoload 'mail-extract-address-components "mail-extr"))
264 (defcustom gnus-save-all-headers t
265 "*If non-nil, don't remove any headers before saving."
266 :group 'gnus-article-saving
269 (defcustom gnus-prompt-before-saving 'always
270 "*This variable says how much prompting is to be done when saving articles.
271 If it is nil, no prompting will be done, and the articles will be
272 saved to the default files. If this variable is `always', each and
273 every article that is saved will be preceded by a prompt, even when
274 saving large batches of articles. If this variable is neither nil not
275 `always', there the user will be prompted once for a file name for
276 each invocation of the saving commands."
277 :group 'gnus-article-saving
278 :type '(choice (item always)
279 (item :tag "never" nil)
280 (sexp :tag "once" :format "%t\n" :value t)))
282 (defcustom gnus-saved-headers gnus-visible-headers
283 "Headers to keep if `gnus-save-all-headers' is nil.
284 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
285 If that variable is nil, however, all headers that match this regexp
286 will be kept while the rest will be deleted before saving."
287 :group 'gnus-article-saving
290 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
291 "A function to save articles in your favourite format.
292 The function must be interactively callable (in other words, it must
293 be an Emacs command).
295 Gnus provides the following functions:
297 * gnus-summary-save-in-rmail (Rmail format)
298 * gnus-summary-save-in-mail (Unix mail format)
299 * gnus-summary-save-in-folder (MH folder)
300 * gnus-summary-save-in-file (article format)
301 * gnus-summary-save-in-vm (use VM's folder format)
302 * gnus-summary-write-to-file (article format -- overwrite)."
303 :group 'gnus-article-saving
304 :type '(radio (function-item gnus-summary-save-in-rmail)
305 (function-item gnus-summary-save-in-mail)
306 (function-item gnus-summary-save-in-folder)
307 (function-item gnus-summary-save-in-file)
308 (function-item gnus-summary-save-in-vm)
309 (function-item gnus-summary-write-to-file)))
311 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
312 "A function generating a file name to save articles in Rmail format.
313 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
314 :group 'gnus-article-saving
317 (defcustom gnus-mail-save-name 'gnus-plain-save-name
318 "A function generating a file name to save articles in Unix mail format.
319 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
320 :group 'gnus-article-saving
323 (defcustom gnus-folder-save-name 'gnus-folder-save-name
324 "A function generating a file name to save articles in MH folder.
325 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
326 :group 'gnus-article-saving
329 (defcustom gnus-file-save-name 'gnus-numeric-save-name
330 "A function generating a file name to save articles in article format.
331 The function is called with NEWSGROUP, HEADERS, and optional
333 :group 'gnus-article-saving
336 (defcustom gnus-split-methods
337 '((gnus-article-archive-name)
338 (gnus-article-nndoc-name))
339 "*Variable used to suggest where articles are to be saved.
340 For instance, if you would like to save articles related to Gnus in
341 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
342 you could set this variable to something like:
344 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
345 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
347 This variable is an alist where the where the key is the match and the
348 value is a list of possible files to save in if the match is non-nil.
350 If the match is a string, it is used as a regexp match on the
351 article. If the match is a symbol, that symbol will be funcalled
352 from the buffer of the article to be saved with the newsgroup as the
353 parameter. If it is a list, it will be evaled in the same buffer.
355 If this form or function returns a string, this string will be used as
356 a possible file name; and if it returns a non-nil list, that list will
357 be used as possible file names."
358 :group 'gnus-article-saving
359 :type '(repeat (choice (list :value (fun) function)
360 (cons :value ("" "") regexp (repeat string))
363 (defcustom gnus-strict-mime t
364 "*If nil, MIME-decode even if there is no Mime-Version header."
365 :group 'gnus-article-mime
368 (defcustom gnus-show-mime-method 'metamail-buffer
369 "Function to process a MIME message.
370 The function is called from the article buffer."
371 :group 'gnus-article-mime
374 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
375 "*Function to decode MIME encoded words.
376 The function is called from the article buffer."
377 :group 'gnus-article-mime
380 (defcustom gnus-page-delimiter "^\^L"
381 "*Regexp describing what to use as article page delimiters.
382 The default value is \"^\^L\", which is a form linefeed at the
383 beginning of a line."
385 :group 'gnus-article-various)
387 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
388 "*The format specification for the article mode line.
389 See `gnus-summary-mode-line-format' for a closer description."
391 :group 'gnus-article-various)
393 (defcustom gnus-article-mode-hook nil
394 "*A hook for Gnus article mode."
396 :group 'gnus-article-various)
398 (defcustom gnus-article-menu-hook nil
399 "*Hook run after the creation of the article mode menu."
401 :group 'gnus-article-various)
403 (defcustom gnus-article-prepare-hook nil
404 "*A hook called after an article has been prepared in the article buffer.
405 If you want to run a special decoding program like nkf, use this hook."
407 :group 'gnus-article-various)
409 (defcustom gnus-article-hide-pgp-hook nil
410 "*A hook called after successfully hiding a PGP signature."
412 :group 'gnus-article-various)
414 (defcustom gnus-article-button-face 'bold
415 "Face used for highlighting buttons in the article buffer.
417 An article button is a piece of text that you can activate by pressing
418 `RET' or `mouse-2' above it."
420 :group 'gnus-article-buttons)
422 (defcustom gnus-article-mouse-face 'highlight
423 "Face used for mouse highlighting in the article buffer.
425 Article buttons will be displayed in this face when the cursor is
428 :group 'gnus-article-buttons)
430 (defcustom gnus-signature-face 'gnus-signature-face
431 "Face used for highlighting a signature in the article buffer.
432 Obsolete; use the face `gnus-signature-face' for customizations instead."
434 :group 'gnus-article-highlight
435 :group 'gnus-article-signature)
437 (defface gnus-signature-face
440 "Face used for highlighting a signature in the article buffer."
441 :group 'gnus-article-highlight
442 :group 'gnus-article-signature)
444 (defface gnus-header-from-face
447 (:foreground "spring green" :bold t))
450 (:foreground "red3" :bold t))
452 (:bold t :italic t)))
453 "Face used for displaying from headers."
454 :group 'gnus-article-headers
455 :group 'gnus-article-highlight)
457 (defface gnus-header-subject-face
460 (:foreground "SeaGreen3" :bold t))
463 (:foreground "red4" :bold t))
465 (:bold t :italic t)))
466 "Face used for displaying subject headers."
467 :group 'gnus-article-headers
468 :group 'gnus-article-highlight)
470 (defface gnus-header-newsgroups-face
473 (:foreground "yellow" :bold t :italic t))
476 (:foreground "MidnightBlue" :bold t :italic t))
478 (:bold t :italic t)))
479 "Face used for displaying newsgroups headers."
480 :group 'gnus-article-headers
481 :group 'gnus-article-highlight)
483 (defface gnus-header-name-face
486 (:foreground "SeaGreen"))
489 (:foreground "maroon"))
492 "Face used for displaying header names."
493 :group 'gnus-article-headers
494 :group 'gnus-article-highlight)
496 (defface gnus-header-content-face
499 (:foreground "forest green" :italic t))
502 (:foreground "indianred4" :italic t))
504 (:italic t))) "Face used for displaying header content."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight)
508 (defcustom gnus-header-face-alist
509 '(("From" nil gnus-header-from-face)
510 ("Subject" nil gnus-header-subject-face)
511 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
512 ("" gnus-header-name-face gnus-header-content-face))
513 "*Controls highlighting of article header.
515 An alist of the form (HEADER NAME CONTENT).
517 HEADER is a regular expression which should match the name of an
518 header header and NAME and CONTENT are either face names or nil.
520 The name of each header field will be displayed using the face
521 specified by the first element in the list where HEADER match the
522 header name and NAME is non-nil. Similarly, the content will be
523 displayed by the first non-nil matching CONTENT face."
524 :group 'gnus-article-headers
525 :group 'gnus-article-highlight
526 :type '(repeat (list (regexp :tag "Header")
528 (item :tag "skip" nil)
529 (face :value default))
530 (choice :tag "Content"
531 (item :tag "skip" nil)
532 (face :value default)))))
534 ;;; Internal variables
536 (defvar article-lapsed-timer nil)
537 (defvar gnus-article-current-summary nil)
539 (defvar gnus-article-mode-syntax-table
540 (let ((table (copy-syntax-table text-mode-syntax-table)))
541 (modify-syntax-entry ?- "w" table)
542 (modify-syntax-entry ?> ")" table)
543 (modify-syntax-entry ?< "(" table)
545 "Syntax table used in article mode buffers.
546 Initialized from `text-mode-syntax-table.")
548 (defvar gnus-save-article-buffer nil)
550 (defvar gnus-article-mode-line-format-alist
551 (nconc '((?w (gnus-article-wash-status) ?s))
552 gnus-summary-mode-line-format-alist))
554 (defvar gnus-number-of-articles-to-be-saved nil)
556 (defvar gnus-inhibit-hiding nil)
558 (defsubst gnus-article-hide-text (b e props)
559 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
560 (add-text-properties b e props)
561 (when (memq 'intangible props)
563 (max (1- b) (point-min))
564 b 'intangible (cddr (memq 'intangible props)))))
566 (defsubst gnus-article-unhide-text (b e)
567 "Remove hidden text properties from region between B and E."
568 (remove-text-properties b e gnus-hidden-properties)
569 (when (memq 'intangible gnus-hidden-properties)
570 (put-text-property (max (1- b) (point-min))
573 (defun gnus-article-hide-text-type (b e type)
574 "Hide text of TYPE between B and E."
575 (gnus-article-hide-text
576 b e (cons 'article-type (cons type gnus-hidden-properties))))
578 (defun gnus-article-unhide-text-type (b e type)
579 "Hide text of TYPE between B and E."
580 (remove-text-properties
581 b e (cons 'article-type (cons type gnus-hidden-properties)))
582 (when (memq 'intangible gnus-hidden-properties)
583 (put-text-property (max (1- b) (point-min))
586 (defun gnus-article-hide-text-of-type (type)
587 "Hide text of TYPE in the current buffer."
589 (let ((b (point-min))
591 (while (setq b (text-property-any b e 'article-type type))
592 (add-text-properties b (incf b) gnus-hidden-properties)))))
594 (defun gnus-article-delete-text-of-type (type)
595 "Delete text of TYPE in the current buffer."
597 (let ((b (point-min)))
598 (while (setq b (text-property-any b (point-max) 'article-type type))
600 b (or (text-property-not-all b (point-max) 'article-type type)
603 (defun gnus-article-delete-invisible-text ()
604 "Delete all invisible text in the current buffer."
606 (let ((b (point-min)))
607 (while (setq b (text-property-any b (point-max) 'invisible t))
609 b (or (text-property-not-all b (point-max) 'invisible t)
612 (defun gnus-article-text-type-exists-p (type)
613 "Say whether any text of type TYPE exists in the buffer."
614 (text-property-any (point-min) (point-max) 'article-type type))
616 (defsubst gnus-article-header-rank ()
617 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
618 (let ((list gnus-sorted-header-list)
621 (when (looking-at (car list))
623 (setq list (cdr list))
627 (defun article-hide-headers (&optional arg delete)
628 "Toggle whether to hide unwanted headers and possibly sort them as well.
629 If given a negative prefix, always show; if given a positive prefix,
631 (interactive (gnus-article-hidden-arg))
633 (if (gnus-article-check-hidden-text 'headers arg)
634 ;; Show boring headers as well.
635 (gnus-article-show-hidden-text 'boring-headers)
636 ;; This function might be inhibited.
637 (unless gnus-inhibit-hiding
640 (let ((buffer-read-only nil)
641 (props (nconc (list 'article-type 'headers)
642 gnus-hidden-properties))
643 (max (1+ (length gnus-sorted-header-list)))
644 (ignored (when (not gnus-visible-headers)
645 (cond ((stringp gnus-ignored-headers)
646 gnus-ignored-headers)
647 ((listp gnus-ignored-headers)
648 (mapconcat 'identity gnus-ignored-headers
651 (cond ((stringp gnus-visible-headers)
652 gnus-visible-headers)
653 ((and gnus-visible-headers
654 (listp gnus-visible-headers))
655 (mapconcat 'identity gnus-visible-headers "\\|"))))
656 (inhibit-point-motion-hooks t)
658 ;; First we narrow to just the headers.
660 (goto-char (point-min))
661 ;; Hide any "From " lines at the beginning of (mail) articles.
662 (while (looking-at "From ")
666 (delete-region (point-min) (point))
667 (gnus-article-hide-text (point-min) (point) props)))
668 ;; Then treat the rest of the header lines.
671 (if (search-forward "\n\n" nil t) ; if there's a body
672 (progn (forward-line -1) (point))
674 ;; Then we use the two regular expressions
675 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
676 ;; select which header lines is to remain visible in the
678 (goto-char (point-min))
679 (while (re-search-forward "^[^ \t]*:" nil t)
681 ;; Mark the rank of the header.
683 (point) (1+ (point)) 'message-rank
684 (if (or (and visible (looking-at visible))
686 (not (looking-at ignored))))
687 (gnus-article-header-rank)
690 (message-sort-headers-1)
691 (when (setq beg (text-property-any
692 (point-min) (point-max) 'message-rank (+ 2 max)))
693 ;; We make the unwanted headers invisible.
695 (delete-region beg (point-max))
696 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
697 (gnus-article-hide-text-type beg (point-max) 'headers))
698 ;; Work around XEmacs lossage.
699 (put-text-property (point-min) beg 'invisible nil))))))))
701 (defun article-hide-boring-headers (&optional arg)
702 "Toggle hiding of headers that aren't very interesting.
703 If given a negative prefix, always show; if given a positive prefix,
705 (interactive (gnus-article-hidden-arg))
706 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
707 (not gnus-show-all-headers))
710 (let ((buffer-read-only nil)
711 (list gnus-boring-article-headers)
712 (inhibit-point-motion-hooks t)
714 (nnheader-narrow-to-headers)
716 (setq elem (pop list))
717 (goto-char (point-min))
719 ;; Hide empty headers.
721 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
723 (gnus-article-hide-text-type
724 (progn (beginning-of-line) (point))
727 (if (re-search-forward "^[^ \t]" nil t)
731 ;; Hide boring Newsgroups header.
732 ((eq elem 'newsgroups)
733 (when (equal (gnus-fetch-field "newsgroups")
734 (gnus-group-real-name
735 (if (boundp 'gnus-newsgroup-name)
738 (gnus-article-hide-header "newsgroups")))
739 ((eq elem 'followup-to)
740 (when (equal (message-fetch-field "followup-to")
741 (message-fetch-field "newsgroups"))
742 (gnus-article-hide-header "followup-to")))
744 (let ((from (message-fetch-field "from"))
745 (reply-to (message-fetch-field "reply-to")))
750 (nth 1 (mail-extract-address-components from))
751 (nth 1 (mail-extract-address-components reply-to)))))
752 (gnus-article-hide-header "reply-to"))))
754 (let ((date (message-fetch-field "date")))
756 (< (gnus-days-between (current-time-string) date)
758 (gnus-article-hide-header "date"))))
760 (let ((to (message-fetch-field "to")))
761 (when (> (length to) 1024)
762 (gnus-article-hide-header "to"))))
765 (goto-char (point-min))
766 (while (re-search-forward "^to:" nil t)
767 (setq to-count (1+ to-count)))
769 (while (> to-count 0)
770 (goto-char (point-min))
772 (re-search-forward "^to:" nil nil to-count)
774 (narrow-to-region (point) (point-max))
775 (gnus-article-hide-header "to"))
776 (setq to-count (1- to-count)))))))))))))
778 (defun gnus-article-hide-header (header)
780 (goto-char (point-min))
781 (when (re-search-forward (concat "^" header ":") nil t)
782 (gnus-article-hide-text-type
783 (progn (beginning-of-line) (point))
786 (if (re-search-forward "^[^ \t]" nil t)
791 (defun article-treat-dumbquotes ()
792 "Translate M******** sm*rtq**t*s into proper text."
794 (article-translate-characters "\221\222\223\223" "`'\"\""))
796 (defun article-translate-characters (from to)
797 "Translate all characters in the body of the article according to FROM and TO.
798 FROM is a string of characters to translate from; to is a string of
799 characters to translate to."
801 (goto-char (point-min))
802 (when (search-forward "\n\n" nil t)
803 (let ((buffer-read-only nil)
804 (x (make-string 225 ?x))
806 (while (< (incf i) (length x))
809 (while (< i (length from))
810 (aset x (aref from i) (aref to i))
812 (translate-region (point) (point-max) x)))))
814 (defun article-treat-overstrike ()
815 "Translate overstrikes into bold text."
818 (goto-char (point-min))
819 (when (search-forward "\n\n" nil t)
820 (let ((buffer-read-only nil))
821 (while (search-forward "\b" nil t)
822 (let ((next (following-char))
823 (previous (char-after (- (point) 2))))
824 ;; We do the boldification/underlining by hiding the
825 ;; overstrikes and putting the proper text property
829 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
830 (put-text-property (point) (1+ (point)) 'face 'bold))
832 (gnus-article-hide-text-type
833 (1- (point)) (1+ (point)) 'overstrike)
835 (- (point) 2) (1- (point)) 'face 'underline))
837 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
839 (point) (1+ (point)) 'face 'underline)))))))))
841 (defun article-fill ()
842 "Format too long lines."
845 (let ((buffer-read-only nil))
847 (goto-char (point-min))
848 (search-forward "\n\n" nil t)
850 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
851 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
852 (adaptive-fill-mode t))
854 (and (>= (current-column) (min fill-column (window-width)))
855 (/= (preceding-char) ?:)
856 (fill-paragraph nil))
859 (defun article-remove-cr ()
860 "Remove carriage returns from an article."
863 (let ((buffer-read-only nil))
864 (goto-char (point-min))
865 (while (search-forward "\r" nil t)
866 (replace-match "" t t)))))
868 (defun article-remove-trailing-blank-lines ()
869 "Remove all trailing blank lines from the article."
872 (let ((buffer-read-only nil))
873 (goto-char (point-max))
877 (while (and (not (bobp))
878 (looking-at "^[ \t]*$"))
883 (defun article-display-x-face (&optional force)
884 "Look for an X-Face header and display it if present."
885 (interactive (list 'force))
887 ;; Delete the old process, if any.
888 (when (process-status "article-x-face")
889 (delete-process "article-x-face"))
890 (let ((inhibit-point-motion-hooks t)
894 (nnheader-narrow-to-headers)
895 (setq from (message-fetch-field "from"))
896 (goto-char (point-min))
897 (while (and gnus-article-x-face-command
899 ;; Check whether this face is censored.
900 (not gnus-article-x-face-too-ugly)
901 (and gnus-article-x-face-too-ugly from
902 (not (string-match gnus-article-x-face-too-ugly
904 ;; Has to be present.
905 (re-search-forward "^X-Face: " nil t))
906 ;; We now have the area of the buffer where the X-Face is stored.
909 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
910 ;; We display the face.
911 (if (symbolp gnus-article-x-face-command)
912 ;; The command is a lisp function, so we call it.
913 (if (gnus-functionp gnus-article-x-face-command)
914 (funcall gnus-article-x-face-command beg end)
915 (error "%s is not a function" gnus-article-x-face-command))
916 ;; The command is a string, so we interpret the command
917 ;; as a, well, command, and fork it off.
918 (let ((process-connection-type nil))
919 (process-kill-without-query
921 "article-x-face" nil shell-file-name shell-command-switch
922 gnus-article-x-face-command))
923 (process-send-region "article-x-face" beg end)
924 (process-send-eof "article-x-face"))))))))))
926 (defun gnus-hack-decode-rfc1522 ()
927 "Emergency hack function for avoiding problems when decoding."
928 (let ((buffer-read-only nil))
929 (goto-char (point-min))
930 ;; Remove encoded TABs.
931 (while (search-forward "=09" nil t)
932 (replace-match " " t t))
933 ;; Remove encoded newlines.
934 (goto-char (point-min))
935 (while (search-forward "=10" nil t)
936 (replace-match " " t t))))
938 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
939 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
940 (defun article-decode-rfc1522 ()
941 "Hack to remove QP encoding from headers."
942 (let ((case-fold-search t)
943 (inhibit-point-motion-hooks t)
944 (buffer-read-only nil)
948 (goto-char (point-min))
949 (or (search-forward "\n\n" nil t) (point-max)))
950 (goto-char (point-min))
951 (while (re-search-forward
952 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
953 (setq string (match-string 1))
955 (narrow-to-region (match-beginning 0) (match-end 0))
956 (delete-region (point-min) (point-max))
958 (article-mime-decode-quoted-printable
959 (goto-char (point-min)) (point-max))
960 (subst-char-in-region (point-min) (point-max) ?_ ? )
961 (goto-char (point-max)))
962 (goto-char (point-min))))))
964 (defun article-de-quoted-unreadable (&optional force)
965 "Do a naive translation of a quoted-printable-encoded article.
966 This is in no way, shape or form meant as a replacement for real MIME
967 processing, but is simply a stop-gap measure until MIME support is
969 If FORCE, decode the article whether it is marked as quoted-printable
971 (interactive (list 'force))
973 (let ((case-fold-search t)
974 (buffer-read-only nil)
975 (type (gnus-fetch-field "content-transfer-encoding")))
976 (gnus-article-decode-rfc1522)
978 (and type (string-match "quoted-printable" (downcase type))))
979 (goto-char (point-min))
980 (search-forward "\n\n" nil 'move)
981 (article-mime-decode-quoted-printable (point) (point-max))))))
983 (defun article-mime-decode-quoted-printable-buffer ()
984 "Decode Quoted-Printable in the current buffer."
985 (article-mime-decode-quoted-printable (point-min) (point-max)))
987 (defun article-mime-decode-quoted-printable (from to)
988 "Decode Quoted-Printable in the region between FROM and TO."
991 (while (search-forward "=" to t)
992 (cond ((eq (following-char) ?\n)
995 ((looking-at "[0-9A-F][0-9A-F]")
996 (subst-char-in-region
997 (1- (point)) (point) ?=
998 (hexl-hex-string-to-integer
999 (buffer-substring (point) (+ 2 (point)))))
1003 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
1005 (defun article-hide-pgp (&optional arg)
1006 "Toggle hiding of any PGP headers and signatures in the current article.
1007 If given a negative prefix, always show; if given a positive prefix,
1009 (interactive (gnus-article-hidden-arg))
1010 (unless (gnus-article-check-hidden-text 'pgp arg)
1012 (let ((inhibit-point-motion-hooks t)
1013 buffer-read-only beg end)
1015 (goto-char (point-min))
1016 ;; Hide the "header".
1017 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1018 (gnus-article-hide-text-type (1+ (match-beginning 0))
1021 ;; Hide the actual signature.
1022 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1023 (setq end (1+ (match-beginning 0)))
1024 (gnus-article-hide-text-type
1026 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1028 ;; Perhaps we shouldn't hide to the end of the buffer
1029 ;; if there is no end to the signature?
1032 ;; Hide "- " PGP quotation markers.
1034 (narrow-to-region beg end)
1035 (goto-char (point-min))
1036 (while (re-search-forward "^- " nil t)
1037 (gnus-article-hide-text-type
1038 (match-beginning 0) (match-end 0) 'pgp))
1040 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1042 (defun article-hide-pem (&optional arg)
1043 "Toggle hiding of any PEM headers and signatures in the current article.
1044 If given a negative prefix, always show; if given a positive prefix,
1046 (interactive (gnus-article-hidden-arg))
1047 (unless (gnus-article-check-hidden-text 'pem arg)
1049 (let (buffer-read-only end)
1051 (goto-char (point-min))
1052 ;; hide the horrendously ugly "header".
1053 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1056 (setq end (1+ (match-beginning 0)))
1057 (gnus-article-hide-text-type
1059 (if (search-forward "\n\n" nil t)
1063 ;; hide the trailer as well
1064 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1067 (gnus-article-hide-text-type
1068 (match-beginning 0) (match-end 0) 'pem))))))
1070 (defun article-hide-signature (&optional arg)
1071 "Hide the signature in the current article.
1072 If given a negative prefix, always show; if given a positive prefix,
1074 (interactive (gnus-article-hidden-arg))
1075 (unless (gnus-article-check-hidden-text 'signature arg)
1078 (let ((buffer-read-only nil))
1079 (when (gnus-article-narrow-to-signature)
1080 (gnus-article-hide-text-type
1081 (point-min) (point-max) 'signature)))))))
1083 (defun article-strip-leading-blank-lines ()
1084 "Remove all blank lines from the beginning of the article."
1087 (let ((inhibit-point-motion-hooks t)
1089 (goto-char (point-min))
1090 (when (search-forward "\n\n" nil t)
1091 (while (and (not (eobp))
1092 (looking-at "[ \t]*$"))
1093 (gnus-delete-line))))))
1095 (defun article-strip-multiple-blank-lines ()
1096 "Replace consecutive blank lines with one empty line."
1099 (let ((inhibit-point-motion-hooks t)
1101 ;; First make all blank lines empty.
1102 (goto-char (point-min))
1103 (search-forward "\n\n" nil t)
1104 (while (re-search-forward "^[ \t]+$" nil t)
1105 (replace-match "" nil t))
1106 ;; Then replace multiple empty lines with a single empty line.
1107 (goto-char (point-min))
1108 (search-forward "\n\n" nil t)
1109 (while (re-search-forward "\n\n\n+" nil t)
1110 (replace-match "\n\n" t t)))))
1112 (defun article-strip-leading-space ()
1113 "Remove all white space from the beginning of the lines in the article."
1116 (let ((inhibit-point-motion-hooks t)
1118 (goto-char (point-min))
1119 (search-forward "\n\n" nil t)
1120 (while (re-search-forward "^[ \t]+" nil t)
1121 (replace-match "" t t)))))
1123 (defun article-strip-blank-lines ()
1124 "Strip leading, trailing and multiple blank lines."
1126 (article-strip-leading-blank-lines)
1127 (article-remove-trailing-blank-lines)
1128 (article-strip-multiple-blank-lines))
1130 (defun article-strip-all-blank-lines ()
1131 "Strip all blank lines."
1134 (let ((inhibit-point-motion-hooks t)
1136 (goto-char (point-min))
1137 (search-forward "\n\n" nil t)
1138 (while (re-search-forward "^[ \t]*\n" nil t)
1139 (replace-match "" t t)))))
1141 (defvar mime::preview/content-list)
1142 (defvar mime::preview-content-info/point-min)
1143 (defun gnus-article-narrow-to-signature ()
1144 "Narrow to the signature; return t if a signature is found, else nil."
1146 (when (and (boundp 'mime::preview/content-list)
1147 mime::preview/content-list)
1148 ;; We have a MIMEish article, so we use the MIME data to narrow.
1149 (let ((pcinfo (car (last mime::preview/content-list))))
1152 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1155 (when (gnus-article-search-signature)
1157 ;; Check whether we have some limits to what we consider
1158 ;; to be a signature.
1159 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1160 (list gnus-signature-limit)))
1162 (while (setq limit (pop limits))
1163 (if (or (and (integerp limit)
1164 (< (- (point-max) (point)) limit))
1166 (< (count-lines (point) (point-max)) limit))
1167 (and (gnus-functionp limit)
1169 (and (stringp limit)
1170 (not (re-search-forward limit nil t))))
1171 () ; This limit did not succeed.
1175 (narrow-to-region (point) (point-max))
1178 (defun gnus-article-search-signature ()
1179 "Search the current buffer for the signature separator.
1180 Put point at the beginning of the signature separator."
1181 (let ((cur (point)))
1182 (goto-char (point-max))
1183 (if (if (stringp gnus-signature-separator)
1184 (re-search-backward gnus-signature-separator nil t)
1185 (let ((seps gnus-signature-separator))
1187 (not (re-search-backward (car seps) nil t)))
1195 (autoload 'w3-display "w3-parse")
1196 (autoload 'w3-do-setup "w3" "" t)
1197 (autoload 'w3-region "w3-display" "" t))
1199 (defun gnus-article-treat-html ()
1202 (let ((cbuf (current-buffer)))
1203 (set-buffer gnus-article-buffer)
1204 (let (buf buffer-read-only b e)
1206 (goto-char (point-min))
1208 (if (search-forward "\n\n" nil t)
1211 (setq e (point-max)))
1212 (nnheader-temp-write nil
1213 (insert-buffer-substring gnus-article-buffer b e)
1215 (save-window-excursion
1216 (w3-region (point-min) (point-max))
1217 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1219 (delete-region (point-min) (point-max))
1222 (goto-char (point-min))
1223 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1224 (set-buffer cbuf))))
1226 (defun gnus-article-hidden-arg ()
1227 "Return the current prefix arg as a number, or 0 if no prefix."
1228 (list (if current-prefix-arg
1229 (prefix-numeric-value current-prefix-arg)
1232 (defun gnus-article-check-hidden-text (type arg)
1233 "Return nil if hiding is necessary.
1234 Arg can be nil or a number. Nil and positive means hide, negative
1235 means show, 0 means toggle."
1239 (let ((hide (gnus-article-hidden-text-p type)))
1245 (gnus-article-show-hidden-text type))
1247 (if (eq hide 'hidden)
1248 (gnus-article-show-hidden-text type)
1251 (defun gnus-article-hidden-text-p (type)
1252 "Say whether the current buffer contains hidden text of type TYPE."
1253 (let ((start (point-min))
1254 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1256 (not (get-text-property pos 'invisible)))
1258 (text-property-any (1+ pos) (point-max) 'article-type type)))
1263 (defun gnus-article-show-hidden-text (type &optional hide)
1264 "Show all hidden text of type TYPE.
1265 If HIDE, hide the text instead."
1267 (let ((buffer-read-only nil)
1268 (inhibit-point-motion-hooks t)
1271 (while (setq beg (text-property-any end (point-max) 'article-type type))
1274 (text-property-not-all beg (point-max) 'article-type type)
1277 (gnus-article-hide-text beg end gnus-hidden-properties)
1278 (gnus-article-unhide-text beg end))
1282 (defconst article-time-units
1283 `((year . ,(* 365.25 24 60 60))
1284 (week . ,(* 7 24 60 60))
1285 (day . ,(* 24 60 60))
1289 "Mapping from time units to seconds.")
1291 (defun article-date-ut (&optional type highlight header)
1292 "Convert DATE date to universal time in the current article.
1293 If TYPE is `local', convert to local time; if it is `lapsed', output
1294 how much time has lapsed since DATE."
1295 (interactive (list 'ut t))
1296 (let* ((header (or header
1297 (mail-header-date gnus-current-headers)
1298 (message-fetch-field "date")
1300 (date (if (vectorp header) (mail-header-date header)
1302 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1303 (inhibit-point-motion-hooks t)
1304 bface eface newline)
1305 (when (and date (not (string= date "")))
1308 (nnheader-narrow-to-headers)
1309 (let ((buffer-read-only nil))
1310 ;; Delete any old Date headers.
1311 (if (re-search-forward date-regexp nil t)
1313 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1314 eface (get-text-property (1- (gnus-point-at-eol))
1316 (delete-region (progn (beginning-of-line) (point))
1317 (progn (end-of-line) (point)))
1318 (beginning-of-line))
1319 (goto-char (point-max))
1321 (insert (article-make-date-line date type))
1324 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1325 (put-text-property (match-beginning 1) (1+ (match-end 1))
1327 (put-text-property (match-beginning 2) (match-end 2)
1331 (insert "\n"))))))))
1333 (defun article-make-date-line (date type)
1334 "Return a DATE line of TYPE."
1336 ;; Convert to the local timezone. We have to slap a
1337 ;; `condition-case' round the calls to the timezone
1338 ;; functions since they aren't particularly resistant to
1341 (concat "Date: " (condition-case ()
1342 (timezone-make-date-arpa-standard date)
1344 ;; Convert to Universal Time.
1348 (timezone-make-date-arpa-standard date nil "UT")
1350 ;; Get the original date from the article.
1351 ((eq type 'original)
1352 (concat "Date: " date))
1353 ;; Let the user define the format.
1355 (if (gnus-functionp gnus-article-time-format)
1357 gnus-article-time-format
1360 (timezone-make-date-arpa-standard
1364 (format-time-string gnus-article-time-format
1367 (timezone-make-date-arpa-standard
1368 date nil "UT")))))))
1373 (format-time-string "%Y%M%DT%h%m%s"
1376 (timezone-make-date-arpa-standard
1378 ;; Do an X-Sent lapsed format.
1380 ;; If the date is seriously mangled, the timezone functions are
1381 ;; liable to bug out, so we ignore all errors.
1382 (let* ((now (current-time))
1387 (timezone-make-date-arpa-standard
1388 (current-time-string now)
1389 (current-time-zone now) "UT"))
1391 (timezone-make-date-arpa-standard
1393 (real-sec (and real-time
1394 (+ (* (float (car real-time)) 65536)
1396 (sec (and real-time (abs real-sec)))
1406 ;; This is a bit convoluted, but basically we go
1407 ;; through the time units for years, weeks, etc,
1408 ;; and divide things to see whether that results
1409 ;; in positive answers.
1412 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1413 ;; The (remaining) seconds are too few to
1414 ;; be divided into this time unit.
1416 ;; It's big enough, so we output it.
1417 (setq sec (- sec (* num (cdr unit))))
1419 (concat (if prev ", " "") (int-to-string
1421 " " (symbol-name (car unit))
1422 (if (> num 1) "s" ""))
1424 article-time-units "")
1425 ;; If dates are odd, then it might appear like the
1426 ;; article was sent in the future.
1429 " in the future"))))))
1431 (error "Unknown conversion type: %s" type))))
1433 (defun article-date-local (&optional highlight)
1434 "Convert the current article date to the local timezone."
1435 (interactive (list t))
1436 (article-date-ut 'local highlight))
1438 (defun article-date-original (&optional highlight)
1439 "Convert the current article date to what it was originally.
1440 This is only useful if you have used some other date conversion
1441 function and want to see what the date was before converting."
1442 (interactive (list t))
1443 (article-date-ut 'original highlight))
1445 (defun article-date-lapsed (&optional highlight)
1446 "Convert the current article date to time lapsed since it was sent."
1447 (interactive (list t))
1448 (article-date-ut 'lapsed highlight))
1450 (defun article-update-date-lapsed ()
1451 "Function to be run from a timer to update the lapsed time line."
1454 (when (gnus-buffer-live-p gnus-article-buffer)
1455 (set-buffer gnus-article-buffer)
1456 (goto-char (point-min))
1457 (when (re-search-forward "^X-Sent:" nil t)
1458 (article-date-lapsed t))))))
1460 (defun gnus-start-date-timer (&optional n)
1461 "Start a timer to update the X-Sent header in the article buffers.
1462 The numerical prefix says how frequently (in seconds) the function
1467 (gnus-stop-date-timer)
1468 (setq article-lapsed-timer
1469 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1471 (defun gnus-stop-date-timer ()
1472 "Stop the X-Sent timer."
1474 (when article-lapsed-timer
1475 (nnheader-cancel-timer article-lapsed-timer)
1476 (setq article-lapsed-timer nil)))
1478 (defun article-date-user (&optional highlight)
1479 "Convert the current article date to the user-defined format.
1480 This format is defined by the `gnus-article-time-format' variable."
1481 (interactive (list t))
1482 (article-date-ut 'user highlight))
1484 (defun article-date-iso8601 (&optional highlight)
1485 "Convert the current article date to ISO8601."
1486 (interactive (list t))
1487 (article-date-ut 'iso8601 highlight))
1489 (defun article-show-all ()
1490 "Show all hidden text in the article buffer."
1493 (let ((buffer-read-only nil))
1494 (gnus-article-unhide-text (point-min) (point-max)))))
1496 (defun article-emphasize (&optional arg)
1497 "Emphasize text according to `gnus-emphasis-alist'."
1498 (interactive (gnus-article-hidden-arg))
1499 (unless (gnus-article-check-hidden-text 'emphasis arg)
1501 (let ((alist gnus-emphasis-alist)
1502 (buffer-read-only nil)
1503 (props (append '(article-type emphasis)
1504 gnus-hidden-properties))
1505 regexp elem beg invisible visible face)
1506 (goto-char (point-min))
1507 (search-forward "\n\n" nil t)
1509 (while (setq elem (pop alist))
1511 (setq regexp (car elem)
1512 invisible (nth 1 elem)
1513 visible (nth 2 elem)
1515 (while (re-search-forward regexp nil t)
1516 (when (and (match-beginning visible) (match-beginning invisible))
1517 (gnus-article-hide-text
1518 (match-beginning invisible) (match-end invisible) props)
1519 (gnus-article-unhide-text-type
1520 (match-beginning visible) (match-end visible) 'emphasis)
1521 (gnus-put-text-property-excluding-newlines
1522 (match-beginning visible) (match-end visible) 'face face)
1523 (goto-char (match-end invisible)))))))))
1525 (defvar gnus-summary-article-menu)
1526 (defvar gnus-summary-post-menu)
1528 ;;; Saving functions.
1530 (defun gnus-article-save (save-buffer file &optional num)
1531 "Save the currently selected article."
1532 (unless gnus-save-all-headers
1533 ;; Remove headers according to `gnus-saved-headers'.
1534 (let ((gnus-visible-headers
1535 (or gnus-saved-headers gnus-visible-headers))
1536 (gnus-article-buffer save-buffer))
1538 (set-buffer save-buffer)
1539 (article-hide-headers 1 t))))
1540 (save-window-excursion
1541 (if (not gnus-default-article-saver)
1542 (error "No default saver is defined")
1543 ;; !!! Magic! The saving functions all save
1544 ;; `gnus-original-article-buffer' (or so they think), but we
1545 ;; bind that variable to our save-buffer.
1546 (set-buffer gnus-article-buffer)
1547 (let* ((gnus-save-article-buffer save-buffer)
1550 ((not gnus-prompt-before-saving) 'default)
1551 ((eq gnus-prompt-before-saving 'always) nil)
1553 (gnus-number-of-articles-to-be-saved
1554 (when (eq gnus-prompt-before-saving t)
1556 (set-buffer gnus-article-current-summary)
1557 (funcall gnus-default-article-saver filename)))))
1559 (defun gnus-read-save-file-name (prompt &optional filename
1560 function group headers variable)
1562 (funcall function group headers (symbol-value variable)))
1567 ((eq filename 'default)
1573 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1576 (if (and gnus-number-of-articles-to-be-saved
1577 (> gnus-number-of-articles-to-be-saved 1))
1578 (format "these %d articles"
1579 gnus-number-of-articles-to-be-saved)
1582 ;; Let the split methods have their say.
1584 ;; No split name was found.
1587 (concat prompt " (default "
1588 (file-name-nondirectory default-name) ") ")
1589 (file-name-directory default-name)
1591 ;; A single group name is returned.
1592 ((stringp split-name)
1594 (funcall function split-name headers
1595 (symbol-value variable)))
1597 (concat prompt " (default "
1598 (file-name-nondirectory default-name) ") ")
1599 (file-name-directory default-name)
1601 ;; A single split name was found
1602 ((= 1 (length split-name))
1603 (let* ((name (expand-file-name
1604 (car split-name) gnus-article-save-directory))
1605 (dir (cond ((file-directory-p name)
1606 (file-name-as-directory name))
1607 ((file-exists-p name) name)
1608 (t gnus-article-save-directory))))
1610 (concat prompt " (default " name ") ")
1612 ;; A list of splits was found.
1614 (setq split-name (nreverse split-name))
1616 (let ((file-name-history
1617 (nconc split-name file-name-history)))
1621 (concat prompt " (`M-p' for defaults) ")
1622 gnus-article-save-directory
1624 gnus-article-save-directory)))
1625 (car (push result file-name-history)))))))
1626 ;; Create the directory.
1627 (gnus-make-directory (file-name-directory file))
1628 ;; If we have read a directory, we append the default file name.
1629 (when (file-directory-p file)
1630 (setq file (concat (file-name-as-directory file)
1631 (file-name-nondirectory default-name))))
1632 ;; Possibly translate some characters.
1633 (nnheader-translate-file-chars file)))))
1634 (gnus-make-directory (file-name-directory result))
1635 (set variable result)))
1637 (defun gnus-article-archive-name (group)
1638 "Return the first instance of an \"Archive-name\" in the current buffer."
1639 (let ((case-fold-search t))
1640 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1641 (nnheader-concat gnus-article-save-directory
1642 (match-string 1)))))
1644 (defun gnus-article-nndoc-name (group)
1645 "If GROUP is an nndoc group, return the name of the parent group."
1646 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1647 (gnus-group-get-parameter group 'save-article-group)))
1649 (defun gnus-summary-save-in-rmail (&optional filename)
1650 "Append this article to Rmail file.
1651 Optional argument FILENAME specifies file name.
1652 Directory to save to is default to `gnus-article-save-directory'."
1654 (setq filename (gnus-read-save-file-name
1655 "Save %s in rmail file:" filename
1656 gnus-rmail-save-name gnus-newsgroup-name
1657 gnus-current-headers 'gnus-newsgroup-last-rmail))
1658 (gnus-eval-in-buffer-window gnus-save-article-buffer
1662 (gnus-output-to-rmail filename))))
1665 (defun gnus-summary-save-in-mail (&optional filename)
1666 "Append this article to Unix mail file.
1667 Optional argument FILENAME specifies file name.
1668 Directory to save to is default to `gnus-article-save-directory'."
1670 (setq filename (gnus-read-save-file-name
1671 "Save %s in Unix mail file:" filename
1672 gnus-mail-save-name gnus-newsgroup-name
1673 gnus-current-headers 'gnus-newsgroup-last-mail))
1674 (gnus-eval-in-buffer-window gnus-save-article-buffer
1678 (if (and (file-readable-p filename)
1679 (mail-file-babyl-p filename))
1680 (gnus-output-to-rmail filename t)
1681 (gnus-output-to-mail filename)))))
1684 (defun gnus-summary-save-in-file (&optional filename overwrite)
1685 "Append this article to file.
1686 Optional argument FILENAME specifies file name.
1687 Directory to save to is default to `gnus-article-save-directory'."
1689 (setq filename (gnus-read-save-file-name
1690 "Save %s in file:" filename
1691 gnus-file-save-name gnus-newsgroup-name
1692 gnus-current-headers 'gnus-newsgroup-last-file))
1693 (gnus-eval-in-buffer-window gnus-save-article-buffer
1697 (when (and overwrite
1698 (file-exists-p filename))
1699 (delete-file filename))
1700 (gnus-output-to-file filename))))
1703 (defun gnus-summary-write-to-file (&optional filename)
1704 "Write this article to a file.
1705 Optional argument FILENAME specifies file name.
1706 The directory to save in defaults to `gnus-article-save-directory'."
1708 (gnus-summary-save-in-file nil t))
1710 (defun gnus-summary-save-body-in-file (&optional filename)
1711 "Append this article body to a file.
1712 Optional argument FILENAME specifies file name.
1713 The directory to save in defaults to `gnus-article-save-directory'."
1715 (setq filename (gnus-read-save-file-name
1716 "Save %s body in file:" filename
1717 gnus-file-save-name gnus-newsgroup-name
1718 gnus-current-headers 'gnus-newsgroup-last-file))
1719 (gnus-eval-in-buffer-window gnus-save-article-buffer
1723 (goto-char (point-min))
1724 (when (search-forward "\n\n" nil t)
1725 (narrow-to-region (point) (point-max)))
1726 (gnus-output-to-file filename))))
1729 (defun gnus-summary-save-in-pipe (&optional command)
1730 "Pipe this article to subprocess."
1733 (cond ((eq command 'default)
1734 gnus-last-shell-command)
1738 "Shell command on %s: "
1739 (if (and gnus-number-of-articles-to-be-saved
1740 (> gnus-number-of-articles-to-be-saved 1))
1741 (format "these %d articles"
1742 gnus-number-of-articles-to-be-saved)
1744 gnus-last-shell-command))))
1745 (when (string-equal command "")
1746 (setq command gnus-last-shell-command))
1747 (gnus-eval-in-buffer-window gnus-article-buffer
1750 (shell-command-on-region (point-min) (point-max) command nil)))
1751 (setq gnus-last-shell-command command))
1753 ;;; Article file names when saving.
1755 (defun gnus-capitalize-newsgroup (newsgroup)
1756 "Capitalize NEWSGROUP name."
1757 (when (not (zerop (length newsgroup)))
1758 (concat (char-to-string (upcase (aref newsgroup 0)))
1759 (substring newsgroup 1))))
1761 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1762 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1763 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1764 Otherwise, it is like ~/News/news/group/num."
1767 (concat (if (gnus-use-long-file-name 'not-save)
1768 (gnus-capitalize-newsgroup newsgroup)
1769 (gnus-newsgroup-directory-form newsgroup))
1770 "/" (int-to-string (mail-header-number headers)))
1771 gnus-article-save-directory)))
1773 (string-equal (file-name-directory default)
1774 (file-name-directory last-file))
1775 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1777 (or last-file default))))
1779 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1780 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1781 If variable `gnus-use-long-file-name' is non-nil, it is
1782 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1785 (concat (if (gnus-use-long-file-name 'not-save)
1787 (gnus-newsgroup-directory-form newsgroup))
1788 "/" (int-to-string (mail-header-number headers)))
1789 gnus-article-save-directory)))
1791 (string-equal (file-name-directory default)
1792 (file-name-directory last-file))
1793 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1795 (or last-file default))))
1797 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1798 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1799 If variable `gnus-use-long-file-name' is non-nil, it is
1800 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1803 (if (gnus-use-long-file-name 'not-save)
1804 (gnus-capitalize-newsgroup newsgroup)
1805 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1806 gnus-article-save-directory)))
1808 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1809 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1810 If variable `gnus-use-long-file-name' is non-nil, it is
1811 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1814 (if (gnus-use-long-file-name 'not-save)
1816 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1817 gnus-article-save-directory)))
1824 (setq afunc (car func)
1827 gfunc (intern (format "gnus-%s" func))))
1829 (if (not (fboundp afunc))
1831 `(lambda (&optional interactive &rest args)
1832 ,(documentation afunc t)
1833 (interactive (list t))
1835 (set-buffer gnus-article-buffer)
1837 (call-interactively ',afunc)
1838 (apply ',afunc args))))))))
1839 '(article-hide-headers
1840 article-hide-boring-headers
1841 article-treat-overstrike
1842 (article-fill . gnus-article-word-wrap)
1844 article-display-x-face
1845 article-de-quoted-unreadable
1846 article-mime-decode-quoted-printable
1849 article-hide-signature
1850 article-remove-trailing-blank-lines
1851 article-strip-leading-blank-lines
1852 article-strip-multiple-blank-lines
1853 article-strip-leading-space
1854 article-strip-blank-lines
1855 article-strip-all-blank-lines
1857 article-date-iso8601
1858 article-date-original
1863 article-treat-dumbquotes
1864 (article-show-all . gnus-article-show-all-headers))))
1867 ;;; Gnus article mode
1870 (put 'gnus-article-mode 'mode-class 'special)
1872 (gnus-define-keys gnus-article-mode-map
1873 " " gnus-article-goto-next-page
1874 "\177" gnus-article-goto-prev-page
1875 [delete] gnus-article-goto-prev-page
1876 "\C-c^" gnus-article-refer-article
1877 "h" gnus-article-show-summary
1878 "s" gnus-article-show-summary
1879 "\C-c\C-m" gnus-article-mail
1880 "?" gnus-article-describe-briefly
1881 gnus-mouse-2 gnus-article-push-button
1882 "\r" gnus-article-press-button
1883 "\t" gnus-article-next-button
1884 "\M-\t" gnus-article-prev-button
1885 "e" gnus-article-edit
1886 "<" beginning-of-buffer
1888 "\C-c\C-i" gnus-info-find-node
1891 "\C-d" gnus-article-read-summary-keys
1892 "\M-*" gnus-article-read-summary-keys
1893 "\M-#" gnus-article-read-summary-keys
1894 "\M-^" gnus-article-read-summary-keys
1895 "\M-g" gnus-article-read-summary-keys)
1897 (substitute-key-definition
1898 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1900 (defun gnus-article-make-menu-bar ()
1901 (gnus-turn-off-edit-menu 'article)
1902 (unless (boundp 'gnus-article-article-menu)
1904 gnus-article-article-menu gnus-article-mode-map ""
1906 ["Scroll forwards" gnus-article-goto-next-page t]
1907 ["Scroll backwards" gnus-article-goto-prev-page t]
1908 ["Show summary" gnus-article-show-summary t]
1909 ["Fetch Message-ID at point" gnus-article-refer-article t]
1910 ["Mail to address at point" gnus-article-mail t]))
1913 gnus-article-treatment-menu gnus-article-mode-map ""
1915 ["Hide headers" gnus-article-hide-headers t]
1916 ["Hide signature" gnus-article-hide-signature t]
1917 ["Hide citation" gnus-article-hide-citation t]
1918 ["Treat overstrike" gnus-article-treat-overstrike t]
1919 ["Remove carriage return" gnus-article-remove-cr t]
1920 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1923 (when (boundp 'gnus-summary-article-menu)
1924 (define-key gnus-article-mode-map [menu-bar commands]
1925 (cons "Commands" gnus-summary-article-menu))))
1927 (when (boundp 'gnus-summary-post-menu)
1928 (define-key gnus-article-mode-map [menu-bar post]
1929 (cons "Post" gnus-summary-post-menu)))
1931 (gnus-run-hooks 'gnus-article-menu-hook)))
1933 (defun gnus-article-mode ()
1934 "Major mode for displaying an article.
1936 All normal editing commands are switched off.
1938 The following commands are available in addition to all summary mode
1940 \\<gnus-article-mode-map>
1941 \\[gnus-article-next-page]\t Scroll the article one page forwards
1942 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1943 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1944 \\[gnus-article-show-summary]\t Display the summary buffer
1945 \\[gnus-article-mail]\t Send a reply to the address near point
1946 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1947 \\[gnus-info-find-node]\t Go to the Gnus info node"
1949 (when (gnus-visual-p 'article-menu 'menu)
1950 (gnus-article-make-menu-bar))
1951 (kill-all-local-variables)
1952 (gnus-simplify-mode-line)
1953 (setq mode-name "Article")
1954 (setq major-mode 'gnus-article-mode)
1955 (make-local-variable 'minor-mode-alist)
1956 (unless (assq 'gnus-show-mime minor-mode-alist)
1957 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1958 (use-local-map gnus-article-mode-map)
1959 (gnus-update-format-specifications nil 'article-mode)
1960 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1961 (set (make-local-variable 'gnus-page-broken) nil)
1962 (set (make-local-variable 'gnus-button-marker-list) nil)
1963 (set (make-local-variable 'gnus-article-current-summary) nil)
1964 (gnus-set-default-directory)
1965 (buffer-disable-undo (current-buffer))
1966 (setq buffer-read-only t)
1967 (set-syntax-table gnus-article-mode-syntax-table)
1968 (gnus-run-hooks 'gnus-article-mode-hook))
1970 (defun gnus-article-setup-buffer ()
1971 "Initialize the article buffer."
1972 (let* ((name (if gnus-single-article-buffer "*Article*"
1973 (concat "*Article " gnus-newsgroup-name "*")))
1975 (progn (string-match "\\*Article" name)
1976 (concat " *Original Article"
1977 (substring name (match-end 0))))))
1978 (setq gnus-article-buffer name)
1979 (setq gnus-original-article-buffer original)
1980 ;; This might be a variable local to the summary buffer.
1981 (unless gnus-single-article-buffer
1983 (set-buffer gnus-summary-buffer)
1984 (setq gnus-article-buffer name)
1985 (setq gnus-original-article-buffer original)
1986 (gnus-set-global-variables)))
1987 ;; Init original article buffer.
1989 (set-buffer (get-buffer-create gnus-original-article-buffer))
1990 (buffer-disable-undo (current-buffer))
1991 (setq major-mode 'gnus-original-article-mode)
1992 (gnus-add-current-to-buffer-list)
1993 (make-local-variable 'gnus-original-article))
1994 (if (get-buffer name)
1997 (buffer-disable-undo (current-buffer))
1998 (setq buffer-read-only t)
1999 (gnus-add-current-to-buffer-list)
2000 (unless (eq major-mode 'gnus-article-mode)
2001 (gnus-article-mode))
2004 (set-buffer (get-buffer-create name))
2005 (gnus-add-current-to-buffer-list)
2007 (make-local-variable 'gnus-summary-buffer)
2008 (current-buffer)))))
2010 ;; Set article window start at LINE, where LINE is the number of lines
2011 ;; from the head of the article.
2012 (defun gnus-article-set-window-start (&optional line)
2014 (get-buffer-window gnus-article-buffer t)
2016 (set-buffer gnus-article-buffer)
2017 (goto-char (point-min))
2020 (gnus-message 6 "Moved to bookmark")
2021 (search-forward "\n\n" nil t)
2025 (defun gnus-article-prepare (article &optional all-headers header)
2026 "Prepare ARTICLE in article mode buffer.
2027 ARTICLE should either be an article number or a Message-ID.
2028 If ARTICLE is an id, HEADER should be the article headers.
2029 If ALL-HEADERS is non-nil, no headers are hidden."
2031 ;; Make sure we start in a summary buffer.
2032 (unless (eq major-mode 'gnus-summary-mode)
2033 (set-buffer gnus-summary-buffer))
2034 (setq gnus-summary-buffer (current-buffer))
2035 ;; Make sure the connection to the server is alive.
2036 (unless (gnus-server-opened
2037 (gnus-find-method-for-group gnus-newsgroup-name))
2038 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2039 (gnus-request-group gnus-newsgroup-name t))
2040 (let* ((gnus-article (if header (mail-header-number header) article))
2041 (summary-buffer (current-buffer))
2042 (internal-hook gnus-article-internal-prepare-hook)
2043 (group gnus-newsgroup-name)
2046 (gnus-article-setup-buffer)
2047 (set-buffer gnus-article-buffer)
2048 ;; Deactivate active regions.
2049 (when (and (boundp 'transient-mark-mode)
2050 transient-mark-mode)
2051 (setq mark-active nil))
2052 (if (not (setq result (let ((buffer-read-only nil))
2053 (gnus-request-article-this-buffer
2055 ;; There is no such article.
2057 (when (and (numberp article)
2058 (not (memq article gnus-newsgroup-sparse)))
2059 (setq gnus-article-current
2060 (cons gnus-newsgroup-name article))
2061 (set-buffer gnus-summary-buffer)
2062 (setq gnus-current-article article)
2063 (gnus-summary-mark-article article gnus-canceled-mark))
2064 (unless (memq article gnus-newsgroup-sparse)
2066 1 "No such article (may have expired or been canceled)")))
2067 (if (or (eq result 'pseudo) (eq result 'nneething))
2070 (set-buffer summary-buffer)
2071 (push article gnus-newsgroup-history)
2072 (setq gnus-last-article gnus-current-article
2073 gnus-current-article 0
2074 gnus-current-headers nil
2075 gnus-article-current nil)
2076 (if (eq result 'nneething)
2077 (gnus-configure-windows 'summary)
2078 (gnus-configure-windows 'article))
2079 (gnus-set-global-variables))
2080 (gnus-set-mode-line 'article))
2081 ;; The result from the `request' was an actual article -
2082 ;; or at least some text that is now displayed in the
2084 (when (and (numberp article)
2085 (not (eq article gnus-current-article)))
2086 ;; Seems like a new article has been selected.
2087 ;; `gnus-current-article' must be an article number.
2089 (set-buffer summary-buffer)
2090 (push article gnus-newsgroup-history)
2091 (setq gnus-last-article gnus-current-article
2092 gnus-current-article article
2093 gnus-current-headers
2094 (gnus-summary-article-header gnus-current-article)
2095 gnus-article-current
2096 (cons gnus-newsgroup-name gnus-current-article))
2097 (unless (vectorp gnus-current-headers)
2098 (setq gnus-current-headers nil))
2099 (gnus-summary-goto-subject gnus-current-article)
2100 (gnus-summary-show-thread)
2101 (gnus-run-hooks 'gnus-mark-article-hook)
2102 (gnus-set-mode-line 'summary)
2103 (when (gnus-visual-p 'article-highlight 'highlight)
2104 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2105 ;; Set the global newsgroup variables here.
2106 ;; Suggested by Jim Sisolak
2107 ;; <sisolak@trans4.neep.wisc.edu>.
2108 (gnus-set-global-variables)
2109 (setq gnus-have-all-headers
2110 (or all-headers gnus-show-all-headers))))
2111 (when (or (numberp article)
2113 ;; Hooks for getting information from the article.
2114 ;; This hook must be called before being narrowed.
2115 (let (buffer-read-only)
2116 (gnus-run-hooks 'internal-hook)
2117 (gnus-run-hooks 'gnus-article-prepare-hook)
2118 ;; Decode MIME message.
2119 (when gnus-show-mime
2120 (if (or (not gnus-strict-mime)
2121 (gnus-fetch-field "Mime-Version"))
2122 (let ((coding-system-for-write 'binary)
2123 (coding-system-for-read 'binary))
2124 (funcall gnus-show-mime-method))
2125 (funcall gnus-decode-encoded-word-method)))
2126 ;; Perform the article display hooks.
2127 (gnus-run-hooks 'gnus-article-display-hook))
2129 (goto-char (point-min))
2130 (setq gnus-page-broken
2131 (when gnus-break-pages
2132 (gnus-narrow-to-page)
2134 (gnus-set-mode-line 'article)
2135 (gnus-configure-windows 'article)
2136 (goto-char (point-min))
2139 (defun gnus-article-wash-status ()
2140 "Return a string which display status of article washing."
2142 (set-buffer gnus-article-buffer)
2143 (let ((cite (gnus-article-hidden-text-p 'cite))
2144 (headers (gnus-article-hidden-text-p 'headers))
2145 (boring (gnus-article-hidden-text-p 'boring-headers))
2146 (pgp (gnus-article-hidden-text-p 'pgp))
2147 (pem (gnus-article-hidden-text-p 'pem))
2148 (signature (gnus-article-hidden-text-p 'signature))
2149 (overstrike (gnus-article-hidden-text-p 'overstrike))
2150 (emphasis (gnus-article-hidden-text-p 'emphasis))
2151 (mime gnus-show-mime))
2152 (format "%c%c%c%c%c%c%c"
2154 (if (or headers boring) ?h ? )
2155 (if (or pgp pem) ?p ? )
2156 (if signature ?s ? )
2157 (if overstrike ?o ? )
2159 (if emphasis ?e ? )))))
2161 (defun gnus-article-hide-headers-if-wanted ()
2162 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2163 Provided for backwards compatibility."
2164 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2166 (gnus-article-hide-headers)))
2170 (defun gnus-output-to-file (file-name)
2171 "Append the current article to a file named FILE-NAME."
2172 (let ((artbuf (current-buffer)))
2173 (nnheader-temp-write nil
2174 (insert-buffer-substring artbuf)
2175 ;; Append newline at end of the buffer as separator, and then
2177 (goto-char (point-max))
2179 (append-to-file (point-min) (point-max) file-name)
2182 (defun gnus-narrow-to-page (&optional arg)
2183 "Narrow the article buffer to a page.
2184 If given a numerical ARG, move forward ARG pages."
2186 (setq arg (if arg (prefix-numeric-value arg) 0))
2188 (set-buffer gnus-article-buffer)
2189 (goto-char (point-min))
2191 ;; Remove any old next/prev buttons.
2192 (when (gnus-visual-p 'page-marker)
2193 (let ((buffer-read-only nil))
2194 (gnus-remove-text-with-property 'gnus-prev)
2195 (gnus-remove-text-with-property 'gnus-next)))
2198 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2200 (re-search-forward page-delimiter nil 'move arg)))
2201 (goto-char (match-end 0)))
2204 (if (re-search-forward page-delimiter nil 'move)
2207 (when (and (gnus-visual-p 'page-marker)
2208 (not (= (point-min) 1)))
2210 (goto-char (point-min))
2211 (gnus-insert-prev-page-button)))
2212 (when (and (gnus-visual-p 'page-marker)
2213 (< (+ (point-max) 2) (buffer-size)))
2215 (goto-char (point-max))
2216 (gnus-insert-next-page-button)))))
2218 ;; Article mode commands
2220 (defun gnus-article-goto-next-page ()
2221 "Show the next page of the article."
2223 (when (gnus-article-next-page)
2224 (goto-char (point-min))
2225 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2227 (defun gnus-article-goto-prev-page ()
2228 "Show the next page of the article."
2230 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2231 (gnus-article-prev-page nil)))
2233 (defun gnus-article-next-page (&optional lines)
2234 "Show the next page of the current article.
2235 If end of article, return non-nil. Otherwise return nil.
2236 Argument LINES specifies lines to be scrolled up."
2238 (move-to-window-line -1)
2241 (and (pos-visible-in-window-p) ;Not continuation line.
2243 ;; Nothing in this page.
2244 (if (or (not gnus-page-broken)
2247 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2249 (gnus-narrow-to-page 1) ;Go to next page.
2251 ;; More in this page.
2252 (let ((scroll-in-place nil))
2256 ;; Long lines may cause an end-of-buffer error.
2257 (goto-char (point-max)))))
2258 (move-to-window-line 0)
2261 (defun gnus-article-prev-page (&optional lines)
2262 "Show previous page of current article.
2263 Argument LINES specifies lines to be scrolled down."
2265 (move-to-window-line 0)
2266 (if (and gnus-page-broken
2268 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2270 (gnus-narrow-to-page -1) ;Go to previous page.
2271 (goto-char (point-max))
2273 (let ((scroll-in-place nil))
2277 (beginning-of-buffer
2278 (goto-char (point-min))))
2279 (move-to-window-line 0)))))
2281 (defun gnus-article-refer-article ()
2282 "Read article specified by message-id around point."
2284 (let ((point (point)))
2285 (search-forward ">" nil t) ;Move point to end of "<....>".
2286 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2287 (let ((message-id (match-string 1)))
2289 (set-buffer gnus-summary-buffer)
2290 (gnus-summary-refer-article message-id))
2292 (error "No references around point"))))
2294 (defun gnus-article-show-summary ()
2295 "Reconfigure windows to show summary buffer."
2297 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2298 (error "There is no summary buffer for this article buffer")
2299 (gnus-article-set-globals)
2300 (gnus-configure-windows 'article)
2301 (gnus-summary-goto-subject gnus-current-article)))
2303 (defun gnus-article-describe-briefly ()
2304 "Describe article mode commands briefly."
2307 (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")))
2309 (defun gnus-article-summary-command ()
2310 "Execute the last keystroke in the summary buffer."
2312 (let ((obuf (current-buffer))
2313 (owin (current-window-configuration))
2315 (switch-to-buffer gnus-article-current-summary 'norecord)
2316 (setq func (lookup-key (current-local-map) (this-command-keys)))
2317 (call-interactively func)
2319 (set-window-configuration owin)
2320 (set-window-point (get-buffer-window (current-buffer)) (point))))
2322 (defun gnus-article-summary-command-nosave ()
2323 "Execute the last keystroke in the summary buffer."
2326 (pop-to-buffer gnus-article-current-summary 'norecord)
2327 (setq func (lookup-key (current-local-map) (this-command-keys)))
2328 (call-interactively func)))
2330 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2331 "Read a summary buffer key sequence and execute it from the article buffer."
2334 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2335 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2336 "=" "^" "\M-^" "|"))
2342 '("n" "Gn" "p" "Gp"))
2345 (set-buffer gnus-article-current-summary)
2346 (let (gnus-pick-mode)
2347 (push (or key last-command-event) unread-command-events)
2348 (setq keys (read-key-sequence nil))))
2351 (if (or (member keys nosaves)
2352 (member keys nosave-but-article)
2353 (member keys nosave-in-article))
2355 (save-window-excursion
2356 (pop-to-buffer gnus-article-current-summary 'norecord)
2357 ;; We disable the pick minor mode commands.
2358 (let (gnus-pick-mode)
2359 (setq func (lookup-key (current-local-map) keys))))
2362 (unless (member keys nosave-in-article)
2363 (set-buffer gnus-article-current-summary))
2364 (call-interactively func))
2365 (when (member keys nosave-but-article)
2366 (pop-to-buffer gnus-article-buffer 'norecord)))
2367 ;; These commands should restore window configuration.
2368 (let ((obuf (current-buffer))
2369 (owin (current-window-configuration))
2372 (if not-restore-window
2373 (pop-to-buffer gnus-article-current-summary 'norecord)
2374 (switch-to-buffer gnus-article-current-summary 'norecord))
2375 (setq in-buffer (current-buffer))
2376 ;; We disable the pick minor mode commands.
2377 (if (setq func (let (gnus-pick-mode)
2378 (lookup-key (current-local-map) keys)))
2379 (call-interactively func)
2381 (when (eq in-buffer (current-buffer))
2383 (unless not-restore-window
2384 (set-window-configuration owin))
2385 (unless (member keys up-to-top)
2386 (set-window-point (get-buffer-window (current-buffer))
2389 (defun gnus-article-hide (&optional arg force)
2390 "Hide all the gruft in the current article.
2391 This means that PGP stuff, signatures, cited text and (some)
2392 headers will be hidden.
2393 If given a prefix, show the hidden text instead."
2394 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2395 (gnus-article-hide-headers arg)
2396 (gnus-article-hide-pgp arg)
2397 (gnus-article-hide-citation-maybe arg force)
2398 (gnus-article-hide-signature arg))
2400 (defun gnus-article-maybe-highlight ()
2401 "Do some article highlighting if `article-visual' is non-nil."
2402 (when (gnus-visual-p 'article-highlight 'highlight)
2403 (gnus-article-highlight-some)))
2405 (defun gnus-request-article-this-buffer (article group)
2406 "Get an article and insert it into this buffer."
2407 (let (do-update-line)
2411 (gnus-kill-all-overlays)
2412 (setq group (or group gnus-newsgroup-name))
2414 ;; Open server if it has closed.
2415 (gnus-check-server (gnus-find-method-for-group group))
2417 ;; Using `gnus-request-article' directly will insert the article into
2418 ;; `nntp-server-buffer' - so we'll save some time by not having to
2419 ;; copy it from the server buffer into the article buffer.
2421 ;; We only request an article by message-id when we do not have the
2422 ;; headers for it, so we'll have to get those.
2423 (when (stringp article)
2424 (let ((gnus-override-method gnus-refer-article-method))
2425 (gnus-read-header article)))
2427 ;; If the article number is negative, that means that this article
2428 ;; doesn't belong in this newsgroup (possibly), so we find its
2429 ;; message-id and request it by id instead of number.
2430 (when (and (numberp article)
2432 (get-buffer gnus-summary-buffer)
2433 (buffer-name (get-buffer gnus-summary-buffer)))
2435 (set-buffer gnus-summary-buffer)
2436 (let ((header (gnus-summary-article-header article)))
2439 ((memq article gnus-newsgroup-sparse)
2440 ;; This is a sparse gap article.
2441 (setq do-update-line article)
2442 (setq article (mail-header-id header))
2443 (let ((gnus-override-method gnus-refer-article-method))
2444 (gnus-read-header article))
2445 (setq gnus-newsgroup-sparse
2446 (delq article gnus-newsgroup-sparse)))
2448 ;; It's a real article.
2449 (setq article (mail-header-id header)))
2451 ;; It is an extracted pseudo-article.
2452 (setq article 'pseudo)
2453 (gnus-request-pseudo-article header))))
2455 (let ((method (gnus-find-method-for-group
2456 gnus-newsgroup-name)))
2457 (if (not (eq (car method) 'nneething))
2459 (let ((dir (concat (file-name-as-directory (nth 1 method))
2460 (mail-header-subject header))))
2461 (when (file-directory-p dir)
2462 (setq article 'nneething)
2463 (gnus-group-enter-directory dir))))))))
2466 ;; Refuse to select canceled articles.
2467 ((and (numberp article)
2469 (get-buffer gnus-summary-buffer)
2470 (buffer-name (get-buffer gnus-summary-buffer))
2471 (eq (cdr (save-excursion
2472 (set-buffer gnus-summary-buffer)
2473 (assq article gnus-newsgroup-reads)))
2474 gnus-canceled-mark))
2476 ;; We first check `gnus-original-article-buffer'.
2477 ((and (get-buffer gnus-original-article-buffer)
2480 (set-buffer gnus-original-article-buffer)
2481 (and (equal (car gnus-original-article) group)
2482 (eq (cdr gnus-original-article) article))))
2483 (insert-buffer-substring gnus-original-article-buffer)
2485 ;; Check the backlog.
2486 ((and gnus-keep-backlog
2487 (gnus-backlog-request-article group article (current-buffer)))
2489 ;; Check asynchronous pre-fetch.
2490 ((gnus-async-request-fetched-article group article (current-buffer))
2491 (gnus-async-prefetch-next group article gnus-summary-buffer)
2492 (when (and (numberp article) gnus-keep-backlog)
2493 (gnus-backlog-enter-article group article (current-buffer)))
2496 ((and gnus-use-cache
2498 (gnus-cache-request-article article group))
2500 ;; Get the article and put into the article buffer.
2501 ((or (stringp article) (numberp article))
2502 (let ((gnus-override-method
2503 (and (stringp article) gnus-refer-article-method))
2504 (buffer-read-only nil))
2506 (gnus-kill-all-overlays)
2507 (when (gnus-request-article article group (current-buffer))
2508 (when (numberp article)
2509 (gnus-async-prefetch-next group article gnus-summary-buffer)
2510 (when gnus-keep-backlog
2511 (gnus-backlog-enter-article
2512 group article (current-buffer))))
2517 ;; Associate this article with the current summary buffer.
2518 (setq gnus-article-current-summary gnus-summary-buffer)
2520 ;; Take the article from the original article buffer
2521 ;; and place it in the buffer it's supposed to be in.
2522 (when (and (get-buffer gnus-article-buffer)
2523 (equal (buffer-name (current-buffer))
2524 (buffer-name (get-buffer gnus-article-buffer))))
2526 (if (get-buffer gnus-original-article-buffer)
2527 (set-buffer (get-buffer gnus-original-article-buffer))
2528 (set-buffer (get-buffer-create gnus-original-article-buffer))
2529 (buffer-disable-undo (current-buffer))
2530 (setq major-mode 'gnus-original-article-mode)
2531 (setq buffer-read-only t)
2532 (gnus-add-current-to-buffer-list))
2533 (let (buffer-read-only)
2535 (insert-buffer-substring gnus-article-buffer))
2536 (setq gnus-original-article (cons group article))))
2538 ;; Update sparse articles.
2539 (when (and do-update-line
2540 (or (numberp article)
2542 (let ((buf (current-buffer)))
2543 (set-buffer gnus-summary-buffer)
2544 (gnus-summary-update-article do-update-line)
2545 (gnus-summary-goto-subject do-update-line nil t)
2546 (set-window-point (get-buffer-window (current-buffer) t)
2548 (set-buffer buf))))))
2554 (defcustom gnus-article-edit-mode-hook nil
2555 "Hook run in article edit mode buffers."
2556 :group 'gnus-article-various
2559 (defvar gnus-article-edit-done-function nil)
2561 (defvar gnus-article-edit-mode-map nil)
2563 (unless gnus-article-edit-mode-map
2564 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2566 (gnus-define-keys gnus-article-edit-mode-map
2567 "\C-c\C-c" gnus-article-edit-done
2568 "\C-c\C-k" gnus-article-edit-exit)
2570 (gnus-define-keys (gnus-article-edit-wash-map
2571 "\C-c\C-w" gnus-article-edit-mode-map)
2572 "f" gnus-article-edit-full-stops))
2574 (defun gnus-article-edit-mode ()
2575 "Major mode for editing articles.
2576 This is an extended text-mode.
2578 \\{gnus-article-edit-mode-map}"
2580 (kill-all-local-variables)
2581 (setq major-mode 'gnus-article-edit-mode)
2582 (setq mode-name "Article Edit")
2583 (use-local-map gnus-article-edit-mode-map)
2584 (make-local-variable 'gnus-article-edit-done-function)
2585 (make-local-variable 'gnus-prev-winconf)
2586 (setq buffer-read-only nil)
2587 (buffer-enable-undo)
2589 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2591 (defun gnus-article-edit (&optional force)
2592 "Edit the current article.
2593 This will have permanent effect only in mail groups.
2594 If FORCE is non-nil, allow editing of articles even in read-only
2597 (when (and (not force)
2598 (gnus-group-read-only-p))
2599 (error "The current newsgroup does not support article editing"))
2600 (gnus-article-date-original)
2601 (gnus-article-edit-article
2602 `(lambda (no-highlight)
2603 (gnus-summary-edit-article-done
2604 ,(or (mail-header-references gnus-current-headers) "")
2605 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2607 (defun gnus-article-edit-article (exit-func)
2608 "Start editing the contents of the current article buffer."
2609 (let ((winconf (current-window-configuration)))
2610 (set-buffer gnus-article-buffer)
2611 (gnus-article-edit-mode)
2612 (gnus-set-text-properties (point-min) (point-max) nil)
2613 (gnus-configure-windows 'edit-article)
2614 (setq gnus-article-edit-done-function exit-func)
2615 (setq gnus-prev-winconf winconf)
2616 (gnus-message 6 "C-c C-c to end edits")))
2618 (defun gnus-article-edit-done (&optional arg)
2619 "Update the article edits and exit."
2624 (goto-char (point-min))
2625 (when (search-forward "\n\n" nil 1)
2626 (let ((lines (count-lines (point) (point-max)))
2627 (length (- (point-max) (point)))
2628 (case-fold-search t)
2629 (body (copy-marker (point))))
2630 (goto-char (point-min))
2631 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2632 (delete-region (match-beginning 1) (match-end 1))
2633 (insert (number-to-string length)))
2634 (goto-char (point-min))
2635 (when (re-search-forward
2636 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2637 (delete-region (match-beginning 1) (match-end 1))
2638 (insert (number-to-string length)))
2639 (goto-char (point-min))
2640 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2641 (delete-region (match-beginning 1) (match-end 1))
2642 (insert (number-to-string lines)))))))
2643 (let ((func gnus-article-edit-done-function)
2644 (buf (current-buffer))
2645 (start (window-start)))
2646 (gnus-article-edit-exit)
2649 (let ((buffer-read-only nil))
2650 (funcall func arg)))
2652 (set-window-start (get-buffer-window buf) start)
2653 (set-window-point (get-buffer-window buf) (point))))
2655 (defun gnus-article-edit-exit ()
2656 "Exit the article editing without updating."
2658 ;; We remove all text props from the article buffer.
2659 (let ((buf (format "%s" (buffer-string)))
2660 (curbuf (current-buffer))
2662 (window-start (window-start)))
2665 (let ((winconf gnus-prev-winconf))
2667 ;; The cache and backlog have to be flushed somewhat.
2668 (when gnus-use-cache
2669 (gnus-cache-update-article
2670 (car gnus-article-current) (cdr gnus-article-current)))
2671 (when gnus-keep-backlog
2672 (gnus-backlog-remove-article
2673 (car gnus-article-current) (cdr gnus-article-current)))
2674 ;; Flush original article as well.
2676 (when (get-buffer gnus-original-article-buffer)
2677 (set-buffer gnus-original-article-buffer)
2678 (setq gnus-original-article nil)))
2679 (set-window-configuration winconf)
2680 ;; Tippy-toe some to make sure that point remains where it was.
2681 (let ((buf (current-buffer)))
2683 (set-window-start (get-buffer-window (current-buffer)) window-start)
2685 (set-buffer buf)))))
2687 (defun gnus-article-edit-full-stops ()
2688 "Interactively repair spacing at end of sentences."
2691 (goto-char (point-min))
2692 (search-forward-regexp "^$" nil t)
2693 (let ((case-fold-search nil))
2694 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2697 ;;; Article highlights
2700 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2702 ;;; Internal Variables:
2704 (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\\)"
2705 "Regular expression that matches URLs."
2706 :group 'gnus-article-buttons
2709 (defcustom gnus-button-alist
2710 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2711 gnus-button-message-id 2)
2712 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2713 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2714 gnus-button-fetch-group 4)
2715 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2716 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2717 t gnus-button-message-id 3)
2718 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2719 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2720 ;; This is how URLs _should_ be embedded in text...
2721 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2723 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2724 "*Alist of regexps matching buttons in article bodies.
2726 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2727 REGEXP: is the string matching text around the button,
2728 BUTTON: is the number of the regexp grouping actually matching the button,
2729 FORM: is a lisp expression which must eval to true for the button to
2731 CALLBACK: is the function to call when the user push this button, and each
2732 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2734 CALLBACK can also be a variable, in that case the value of that
2735 variable it the real callback function."
2736 :group 'gnus-article-buttons
2737 :type '(repeat (list regexp
2738 (integer :tag "Button")
2740 (function :tag "Callback")
2743 (integer :tag "Regexp group")))))
2745 (defcustom gnus-header-button-alist
2746 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2747 0 t gnus-button-message-id 0)
2748 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2749 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2750 0 t gnus-button-mailto 0)
2751 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2752 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2753 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2754 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2755 gnus-button-message-id 3))
2756 "*Alist of headers and regexps to match buttons in article heads.
2758 This alist is very similar to `gnus-button-alist', except that each
2759 alist has an additional HEADER element first in each entry:
2761 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2763 HEADER is a regexp to match a header. For a fuller explanation, see
2764 `gnus-button-alist'."
2765 :group 'gnus-article-buttons
2766 :group 'gnus-article-headers
2767 :type '(repeat (list (regexp :tag "Header")
2769 (integer :tag "Button")
2771 (function :tag "Callback")
2774 (integer :tag "Regexp group")))))
2776 (defvar gnus-button-regexp nil)
2777 (defvar gnus-button-marker-list nil)
2778 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2780 (defvar gnus-button-last nil)
2781 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2785 (defun gnus-article-push-button (event)
2786 "Check text under the mouse pointer for a callback function.
2787 If the text under the mouse pointer has a `gnus-callback' property,
2788 call it with the value of the `gnus-data' text property."
2790 (set-buffer (window-buffer (posn-window (event-start event))))
2791 (let* ((pos (posn-point (event-start event)))
2792 (data (get-text-property pos 'gnus-data))
2793 (fun (get-text-property pos 'gnus-callback)))
2795 (funcall fun data))))
2797 (defun gnus-article-press-button ()
2798 "Check text at point for a callback function.
2799 If the text at point has a `gnus-callback' property,
2800 call it with the value of the `gnus-data' text property."
2802 (let* ((data (get-text-property (point) 'gnus-data))
2803 (fun (get-text-property (point) 'gnus-callback)))
2805 (funcall fun data))))
2807 (defun gnus-article-prev-button (n)
2808 "Move point to N buttons backward.
2809 If N is negative, move forward instead."
2811 (gnus-article-next-button (- n)))
2813 (defun gnus-article-next-button (n)
2814 "Move point to N buttons forward.
2815 If N is negative, move backward instead."
2817 (let ((function (if (< n 0) 'previous-single-property-change
2818 'next-single-property-change))
2819 (inhibit-point-motion-hooks t)
2821 (limit (if (< n 0) (point-min) (point-max))))
2823 (while (and (not (= limit (point)))
2825 ;; Skip past the current button.
2826 (when (get-text-property (point) 'gnus-callback)
2827 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2828 ;; Go to the next (or previous) button.
2829 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2830 ;; Put point at the start of the button.
2831 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2832 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2833 ;; Skip past intangible buttons.
2834 (when (get-text-property (point) 'intangible)
2838 (gnus-message 5 "No more buttons"))
2841 (defun gnus-article-highlight (&optional force)
2842 "Highlight current article.
2843 This function calls `gnus-article-highlight-headers',
2844 `gnus-article-highlight-citation',
2845 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2846 do the highlighting. See the documentation for those functions."
2847 (interactive (list 'force))
2848 (gnus-article-highlight-headers)
2849 (gnus-article-highlight-citation force)
2850 (gnus-article-highlight-signature)
2851 (gnus-article-add-buttons force)
2852 (gnus-article-add-buttons-to-head))
2854 (defun gnus-article-highlight-some (&optional force)
2855 "Highlight current article.
2856 This function calls `gnus-article-highlight-headers',
2857 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2858 do the highlighting. See the documentation for those functions."
2859 (interactive (list 'force))
2860 (gnus-article-highlight-headers)
2861 (gnus-article-highlight-signature)
2862 (gnus-article-add-buttons))
2864 (defun gnus-article-highlight-headers ()
2865 "Highlight article headers as specified by `gnus-header-face-alist'."
2868 (set-buffer gnus-article-buffer)
2870 (let ((alist gnus-header-face-alist)
2871 (buffer-read-only nil)
2872 (case-fold-search t)
2873 (inhibit-point-motion-hooks t)
2874 entry regexp header-face field-face from hpoints fpoints)
2875 (message-narrow-to-head)
2876 (while (setq entry (pop alist))
2877 (goto-char (point-min))
2878 (setq regexp (concat "^\\("
2879 (if (string-equal "" (nth 0 entry))
2883 header-face (nth 1 entry)
2884 field-face (nth 2 entry))
2885 (while (and (re-search-forward regexp nil t)
2889 (unless (search-forward ":" nil t)
2891 (when (and header-face
2892 (not (memq (point) hpoints)))
2893 (push (point) hpoints)
2894 (gnus-put-text-property from (point) 'face header-face))
2895 (when (and field-face
2896 (not (memq (setq from (point)) fpoints)))
2898 (if (re-search-forward "^[^ \t]" nil t)
2900 (goto-char (point-max)))
2901 (gnus-put-text-property from (point) 'face field-face))))))))
2903 (defun gnus-article-highlight-signature ()
2904 "Highlight the signature in an article.
2905 It does this by highlighting everything after
2906 `gnus-signature-separator' using `gnus-signature-face'."
2909 (set-buffer gnus-article-buffer)
2910 (let ((buffer-read-only nil)
2911 (inhibit-point-motion-hooks t))
2913 (when (and gnus-signature-face
2914 (gnus-article-narrow-to-signature))
2915 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2916 'face gnus-signature-face)
2918 (gnus-article-search-signature)
2919 (let ((start (match-beginning 0))
2920 (end (set-marker (make-marker) (1+ (match-end 0)))))
2921 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2924 (defun gnus-button-in-region-p (b e prop)
2925 "Say whether PROP exists in the region."
2926 (text-property-not-all b e prop nil))
2928 (defun gnus-article-add-buttons (&optional force)
2929 "Find external references in the article and make buttons of them.
2930 \"External references\" are things like Message-IDs and URLs, as
2931 specified by `gnus-button-alist'."
2932 (interactive (list 'force))
2934 (set-buffer gnus-article-buffer)
2935 (let ((buffer-read-only nil)
2936 (inhibit-point-motion-hooks t)
2937 (case-fold-search t)
2938 (alist gnus-button-alist)
2940 ;; Remove all old markers.
2942 (while (setq marker (pop gnus-button-marker-list))
2944 (when (setq entry (gnus-button-entry))
2945 (put-text-property (match-beginning (nth 1 entry))
2946 (match-end (nth 1 entry))
2947 'gnus-callback nil))
2948 (set-marker marker nil)))
2949 ;; We skip the headers.
2950 (goto-char (point-min))
2951 (unless (search-forward "\n\n" nil t)
2952 (goto-char (point-max)))
2954 (while (setq entry (pop alist))
2955 (setq regexp (car entry))
2957 (while (re-search-forward regexp nil t)
2958 (let* ((start (and entry (match-beginning (nth 1 entry))))
2959 (end (and entry (match-end (nth 1 entry))))
2960 (from (match-beginning 0)))
2961 (when (and (or (eq t (nth 2 entry))
2962 (eval (nth 2 entry)))
2963 (not (gnus-button-in-region-p
2964 start end 'gnus-callback)))
2965 ;; That optional form returned non-nil, so we add the
2967 (gnus-article-add-button
2968 start end 'gnus-button-push
2969 (car (push (set-marker (make-marker) from)
2970 gnus-button-marker-list))))))))))
2972 ;; Add buttons to the head of an article.
2973 (defun gnus-article-add-buttons-to-head ()
2974 "Add buttons to the head of the article."
2977 (set-buffer gnus-article-buffer)
2978 (let ((buffer-read-only nil)
2979 (inhibit-point-motion-hooks t)
2980 (case-fold-search t)
2981 (alist gnus-header-button-alist)
2983 (nnheader-narrow-to-headers)
2985 ;; Each alist entry.
2986 (setq entry (car alist)
2988 (goto-char (point-min))
2989 (while (re-search-forward (car entry) nil t)
2990 ;; Each header matching the entry.
2991 (setq beg (match-beginning 0))
2992 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2993 (match-beginning 0))
2996 (while (re-search-forward (nth 1 entry) end t)
2997 ;; Each match within a header.
2998 (let* ((entry (cdr entry))
2999 (start (match-beginning (nth 1 entry)))
3000 (end (match-end (nth 1 entry)))
3001 (form (nth 2 entry)))
3002 (goto-char (match-end 0))
3004 (gnus-article-add-button
3005 start end (nth 3 entry)
3006 (buffer-substring (match-beginning (nth 4 entry))
3007 (match-end (nth 4 entry)))))))
3011 ;;; External functions:
3013 (defun gnus-article-add-button (from to fun &optional data)
3014 "Create a button between FROM and TO with callback FUN and data DATA."
3015 (when gnus-article-button-face
3016 (gnus-overlay-put (gnus-make-overlay from to)
3017 'face gnus-article-button-face))
3018 (gnus-add-text-properties
3020 (nconc (and gnus-article-mouse-face
3021 (list gnus-mouse-face-prop gnus-article-mouse-face))
3022 (list 'gnus-callback fun)
3023 (and data (list 'gnus-data data)))))
3025 ;;; Internal functions:
3027 (defun gnus-article-set-globals ()
3029 (set-buffer gnus-summary-buffer)
3030 (gnus-set-global-variables)))
3032 (defun gnus-signature-toggle (end)
3034 (set-buffer gnus-article-buffer)
3035 (let ((buffer-read-only nil)
3036 (inhibit-point-motion-hooks t))
3037 (if (get-text-property end 'invisible)
3038 (gnus-article-unhide-text end (point-max))
3039 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3041 (defun gnus-button-entry ()
3042 ;; Return the first entry in `gnus-button-alist' matching this place.
3043 (let ((alist gnus-button-alist)
3046 (setq entry (pop alist))
3047 (if (looking-at (car entry))
3052 (defun gnus-button-push (marker)
3053 ;; Push button starting at MARKER.
3055 (set-buffer gnus-article-buffer)
3057 (let* ((entry (gnus-button-entry))
3058 (inhibit-point-motion-hooks t)
3060 (args (mapcar (lambda (group)
3061 (let ((string (match-string group)))
3062 (gnus-set-text-properties
3063 0 (length string) nil string)
3070 (fboundp (symbol-value fun)))
3071 (apply (symbol-value fun) args))
3073 (gnus-message 1 "You must define `%S' to use this button"
3074 (cons fun args)))))))
3076 (defun gnus-button-message-id (message-id)
3079 (set-buffer gnus-summary-buffer)
3080 (gnus-summary-refer-article message-id)))
3082 (defun gnus-button-fetch-group (address)
3083 "Fetch GROUP specified by ADDRESS."
3084 (if (not (string-match "[:/]" address))
3085 ;; This is just a simple group url.
3086 (gnus-group-read-ephemeral-group address gnus-select-method)
3087 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3089 (error "Can't parse %s" address)
3090 (gnus-group-read-ephemeral-group
3091 (match-string 4 address)
3092 `(nntp ,(match-string 1 address)
3093 (nntp-address ,(match-string 1 address))
3094 (nntp-port-number ,(if (match-end 3)
3095 (match-string 3 address)
3098 (defun gnus-split-string (string pattern)
3099 "Return a list of substrings of STRING which are separated by PATTERN."
3100 (let (parts (start 0))
3101 (while (string-match pattern string start)
3102 (setq parts (cons (substring string start (match-beginning 0)) parts)
3103 start (match-end 0)))
3104 (nreverse (cons (substring string start) parts))))
3106 (defun gnus-url-parse-query-string (query &optional downcase)
3107 (let (retval pairs cur key val)
3108 (setq pairs (gnus-split-string query "&"))
3110 (setq cur (car pairs)
3112 (if (not (string-match "=" cur))
3114 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3115 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3117 (setq key (downcase key)))
3118 (setq cur (assoc key retval))
3120 (setcdr cur (cons val (cdr cur)))
3121 (setq retval (cons (list key val) retval)))))
3124 (defun gnus-url-unhex (x)
3131 (defun gnus-url-unhex-string (str &optional allow-newlines)
3132 "Remove %XXX embedded spaces, etc in a url.
3133 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3134 decoding of carriage returns and line feeds in the string, which is normally
3135 forbidden in URL encoding."
3136 (setq str (or str ""))
3138 (case-fold-search t))
3139 (while (string-match "%[0-9a-f][0-9a-f]" str)
3140 (let* ((start (match-beginning 0))
3141 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3143 (gnus-url-unhex (elt str (+ start 2))))))
3145 tmp (substring str 0 start)
3148 (char-to-string code))
3149 ((or (= code ?\n) (= code ?\r))
3151 (t (char-to-string code))))
3152 str (substring str (match-end 0)))))
3153 (setq tmp (concat tmp str))
3156 (defun gnus-url-mailto (url)
3157 ;; Send mail to someone
3158 (when (string-match "mailto:/*\\(.*\\)" url)
3159 (setq url (substring url (match-beginning 1) nil)))
3160 (let (to args source-url subject func)
3161 (if (string-match (regexp-quote "?") url)
3162 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3163 args (gnus-url-parse-query-string
3164 (substring url (match-end 0) nil) t))
3165 (setq to (gnus-url-unhex-string url)))
3166 (setq args (cons (list "to" to) args)
3167 subject (cdr-safe (assoc "subject" args)))
3170 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3173 (message-position-on-field (caar args)))
3174 (insert (mapconcat 'identity (cdar args) ", "))
3175 (setq args (cdr args)))
3178 (message-goto-subject))))
3180 (defun gnus-button-mailto (address)
3182 (set-buffer (gnus-copy-article-buffer))
3183 (message-reply address))
3185 (defun gnus-button-reply (address)
3186 ;; Reply to ADDRESS.
3187 (message-reply address))
3189 (defun gnus-button-url (address)
3191 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3192 (if (listp browse-url-browser-function)
3193 (browse-url address)
3194 (funcall browse-url-browser-function address)))
3196 (defun gnus-button-embedded-url (address)
3198 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3199 (if (listp browse-url-browser-function)
3200 (browse-url (gnus-strip-whitespace address))
3201 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3203 ;;; Next/prev buttons in the article buffer.
3205 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3206 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3208 (defvar gnus-prev-page-map nil)
3209 (unless gnus-prev-page-map
3210 (setq gnus-prev-page-map (make-sparse-keymap))
3211 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3212 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3214 (defun gnus-insert-prev-page-button ()
3215 (let ((buffer-read-only nil))
3217 gnus-prev-page-line-format nil
3218 `(gnus-prev t local-map ,gnus-prev-page-map
3219 gnus-callback gnus-article-button-prev-page))))
3221 (defvar gnus-next-page-map nil)
3222 (unless gnus-next-page-map
3223 (setq gnus-next-page-map (make-keymap))
3224 (suppress-keymap gnus-prev-page-map)
3225 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3226 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3228 (defun gnus-button-next-page ()
3229 "Go to the next page."
3231 (let ((win (selected-window)))
3232 (select-window (get-buffer-window gnus-article-buffer t))
3233 (gnus-article-next-page)
3234 (select-window win)))
3236 (defun gnus-button-prev-page ()
3237 "Go to the prev page."
3239 (let ((win (selected-window)))
3240 (select-window (get-buffer-window gnus-article-buffer t))
3241 (gnus-article-prev-page)
3242 (select-window win)))
3244 (defun gnus-insert-next-page-button ()
3245 (let ((buffer-read-only nil))
3246 (gnus-eval-format gnus-next-page-line-format nil
3247 `(gnus-next t local-map ,gnus-next-page-map
3249 gnus-article-button-next-page))))
3251 (defun gnus-article-button-next-page (arg)
3252 "Go to the next page."
3254 (let ((win (selected-window)))
3255 (select-window (get-buffer-window gnus-article-buffer t))
3256 (gnus-article-next-page)
3257 (select-window win)))
3259 (defun gnus-article-button-prev-page (arg)
3260 "Go to the prev page."
3262 (let ((win (selected-window)))
3263 (select-window (get-buffer-window gnus-article-buffer t))
3264 (gnus-article-prev-page)
3265 (select-window win)))
3271 (run-hooks 'gnus-art-load-hook)
3273 ;;; gnus-art.el ends here