1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
40 (defgroup gnus-article nil
42 :link '(custom-manual "(gnus)The Article Buffer")
45 (defgroup gnus-article-hiding nil
46 "Hiding article parts."
47 :link '(custom-manual "(gnus)Article Hiding")
50 (defgroup gnus-article-highlight nil
51 "Article highlighting."
52 :link '(custom-manual "(gnus)Article Highlighting")
56 (defgroup gnus-article-signature nil
58 :link '(custom-manual "(gnus)Article Signature")
61 (defgroup gnus-article-headers nil
63 :link '(custom-manual "(gnus)Hiding Headers")
66 (defgroup gnus-article-washing nil
67 "Special commands on articles."
68 :link '(custom-manual "(gnus)Article Washing")
71 (defgroup gnus-article-emphasis nil
72 "Fontisizing articles."
73 :link '(custom-manual "(gnus)Article Fontisizing")
76 (defgroup gnus-article-saving nil
78 :link '(custom-manual "(gnus)Saving Articles")
81 (defgroup gnus-article-mime nil
82 "Worshiping the MIME wonder."
83 :link '(custom-manual "(gnus)Using MIME")
86 (defgroup gnus-article-buttons nil
87 "Pushable buttons in the article buffer."
88 :link '(custom-manual "(gnus)Article Buttons")
91 (defgroup gnus-article-various nil
92 "Other article options."
93 :link '(custom-manual "(gnus)Misc Article")
96 (defcustom gnus-ignored-headers
97 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
98 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
99 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
100 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
101 "*All headers that start with this regexp will be hidden.
102 This variable can also be a list of regexps of headers to be ignored.
103 If `gnus-visible-headers' is non-nil, this variable will be ignored."
104 :type '(choice :custom-show nil
107 :group 'gnus-article-hiding)
109 (defcustom gnus-visible-headers
110 "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:"
111 "*All headers that do not match this regexp will be hidden.
112 This variable can also be a list of regexp of headers to remain visible.
113 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
114 :type '(repeat :value-to-internal (lambda (widget value)
115 (custom-split-regexp-maybe value))
116 :match (lambda (widget value)
118 (widget-editable-list-match widget value)))
120 :group 'gnus-article-hiding)
122 (defcustom gnus-sorted-header-list
123 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
124 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
125 "*This variable is a list of regular expressions.
126 If it is non-nil, headers that match the regular expressions will
127 be placed first in the article buffer in the sequence specified by
129 :type '(repeat regexp)
130 :group 'gnus-article-hiding)
132 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
133 "Headers that are only to be displayed if they have interesting data.
134 Possible values in this list are `empty', `newsgroups', `followup-to',
135 `reply-to', `date', `long-to', and `many-to'."
136 :type '(set (const :tag "Headers with no content." empty)
137 (const :tag "Newsgroups with only one group." newsgroups)
138 (const :tag "Followup-to identical to newsgroups." followup-to)
139 (const :tag "Reply-to identical to from." reply-to)
140 (const :tag "Date less than four days old." date)
141 (const :tag "Very long To header." long-to)
142 (const :tag "Multiple To headers." many-to))
143 :group 'gnus-article-hiding)
145 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
146 "Regexp matching signature separator.
147 This can also be a list of regexps. In that case, it will be checked
148 from head to tail looking for a separator. Searches will be done from
149 the end of the buffer."
150 :type '(repeat string)
151 :group 'gnus-article-signature)
153 (defcustom gnus-signature-limit nil
154 "Provide a limit to what is considered a signature.
155 If it is a number, no signature may not be longer (in characters) than
156 that number. If it is a floating point number, no signature may be
157 longer (in lines) than that number. If it is a function, the function
158 will be called without any parameters, and if it returns nil, there is
159 no signature in the buffer. If it is a string, it will be used as a
160 regexp. If it matches, the text in question is not a signature."
161 :type '(choice (integer :value 200)
163 (function :value fun)
164 (regexp :value ".*"))
165 :group 'gnus-article-signature)
167 (defcustom gnus-hidden-properties '(invisible t intangible t)
168 "Property list to use for hiding text."
170 :group 'gnus-article-hiding)
172 (defcustom gnus-article-x-face-command
173 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
174 "*String or function to be executed to display an X-Face header.
175 If it is a string, the command will be executed in a sub-shell
176 asynchronously. The compressed face will be piped to this command."
177 :type 'string ;Leave function case to Lisp.
178 :group 'gnus-article-washing)
180 (defcustom gnus-article-x-face-too-ugly nil
181 "Regexp matching posters whose face shouldn't be shown automatically."
182 :type '(choice regexp (const nil))
183 :group 'gnus-article-washing)
185 (defcustom gnus-emphasis-alist
187 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
189 '(("_" "_" underline)
192 ("_/" "/_" underline-italic)
193 ("_\\*" "\\*_" underline-bold)
194 ("\\*/" "/\\*" bold-italic)
195 ("_\\*/" "/\\*_" underline-bold-italic))))
196 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
197 2 3 gnus-emphasis-underline)
201 (format format (car spec) (cadr spec))
202 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
204 "*Alist that says how to fontify certain phrases.
205 Each item looks like this:
207 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
209 The first element is a regular expression to be matched. The second
210 is a number that says what regular expression grouping used to find
211 the entire emphasized word. The third is a number that says what
212 regexp grouping should be displayed and highlighted. The fourth
213 is the face used for highlighting."
214 :type '(repeat (list :value ("" 0 0 default)
216 (integer :tag "Match group")
217 (integer :tag "Emphasize group")
219 :group 'gnus-article-emphasis)
221 (defface gnus-emphasis-bold '((t (:bold t)))
222 "Face used for displaying strong emphasized text (*word*)."
223 :group 'gnus-article-emphasis)
225 (defface gnus-emphasis-italic '((t (:italic t)))
226 "Face used for displaying italic emphasized text (/word/)."
227 :group 'gnus-article-emphasis)
229 (defface gnus-emphasis-underline '((t (:underline t)))
230 "Face used for displaying underlined emphasized text (_word_)."
231 :group 'gnus-article-emphasis)
233 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
234 "Face used for displaying underlined bold emphasized text (_*word*_)."
235 :group 'gnus-article-emphasis)
237 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
238 "Face used for displaying underlined italic emphasized text (_*word*_)."
239 :group 'gnus-article-emphasis)
241 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
242 "Face used for displaying bold italic emphasized text (/*word*/)."
243 :group 'gnus-article-emphasis)
245 (defface gnus-emphasis-underline-bold-italic
246 '((t (:bold t :italic t :underline t)))
247 "Face used for displaying underlined bold italic emphasized text.
248 Esample: (_/*word*/_)."
249 :group 'gnus-article-emphasis)
251 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
252 "Format for display of Date headers in article bodies.
253 See `format-time-string' for the possible values.
255 The variable can also be function, which should return a complete Date
256 header. The function is called with one argument, the time, which can
257 be fed to `format-time-string'."
258 :type '(choice string symbol)
259 :link '(custom-manual "(gnus)Article Date")
260 :group 'gnus-article-washing)
263 (autoload 'hexl-hex-string-to-integer "hexl")
264 (autoload 'timezone-make-date-arpa-standard "timezone")
265 (autoload 'mail-extract-address-components "mail-extr"))
267 (defcustom gnus-save-all-headers t
268 "*If non-nil, don't remove any headers before saving."
269 :group 'gnus-article-saving
272 (defcustom gnus-prompt-before-saving 'always
273 "*This variable says how much prompting is to be done when saving articles.
274 If it is nil, no prompting will be done, and the articles will be
275 saved to the default files. If this variable is `always', each and
276 every article that is saved will be preceded by a prompt, even when
277 saving large batches of articles. If this variable is neither nil not
278 `always', there the user will be prompted once for a file name for
279 each invocation of the saving commands."
280 :group 'gnus-article-saving
281 :type '(choice (item always)
282 (item :tag "never" nil)
283 (sexp :tag "once" :format "%t\n" :value t)))
285 (defcustom gnus-saved-headers gnus-visible-headers
286 "Headers to keep if `gnus-save-all-headers' is nil.
287 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
288 If that variable is nil, however, all headers that match this regexp
289 will be kept while the rest will be deleted before saving."
290 :group 'gnus-article-saving
293 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
294 "A function to save articles in your favourite format.
295 The function must be interactively callable (in other words, it must
296 be an Emacs command).
298 Gnus provides the following functions:
300 * gnus-summary-save-in-rmail (Rmail format)
301 * gnus-summary-save-in-mail (Unix mail format)
302 * gnus-summary-save-in-folder (MH folder)
303 * gnus-summary-save-in-file (article format)
304 * gnus-summary-save-in-vm (use VM's folder format)
305 * gnus-summary-write-to-file (article format -- overwrite)."
306 :group 'gnus-article-saving
307 :type '(radio (function-item gnus-summary-save-in-rmail)
308 (function-item gnus-summary-save-in-mail)
309 (function-item gnus-summary-save-in-folder)
310 (function-item gnus-summary-save-in-file)
311 (function-item gnus-summary-save-in-vm)
312 (function-item gnus-summary-write-to-file)))
314 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
315 "A function generating a file name to save articles in Rmail format.
316 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
317 :group 'gnus-article-saving
320 (defcustom gnus-mail-save-name 'gnus-plain-save-name
321 "A function generating a file name to save articles in Unix mail format.
322 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
323 :group 'gnus-article-saving
326 (defcustom gnus-folder-save-name 'gnus-folder-save-name
327 "A function generating a file name to save articles in MH folder.
328 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
329 :group 'gnus-article-saving
332 (defcustom gnus-file-save-name 'gnus-numeric-save-name
333 "A function generating a file name to save articles in article format.
334 The function is called with NEWSGROUP, HEADERS, and optional
336 :group 'gnus-article-saving
339 (defcustom gnus-split-methods
340 '((gnus-article-archive-name)
341 (gnus-article-nndoc-name))
342 "*Variable used to suggest where articles are to be saved.
343 For instance, if you would like to save articles related to Gnus in
344 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
345 you could set this variable to something like:
347 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
348 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
350 This variable is an alist where the where the key is the match and the
351 value is a list of possible files to save in if the match is non-nil.
353 If the match is a string, it is used as a regexp match on the
354 article. If the match is a symbol, that symbol will be funcalled
355 from the buffer of the article to be saved with the newsgroup as the
356 parameter. If it is a list, it will be evaled in the same buffer.
358 If this form or function returns a string, this string will be used as
359 a possible file name; and if it returns a non-nil list, that list will
360 be used as possible file names."
361 :group 'gnus-article-saving
362 :type '(repeat (choice (list :value (fun) function)
363 (cons :value ("" "") regexp (repeat string))
366 (defcustom gnus-strict-mime t
367 "*If nil, MIME-decode even if there is no Mime-Version header."
368 :group 'gnus-article-mime
371 (defcustom gnus-show-mime-method 'gnus-article-preview-mime-message
372 "Function to process a MIME message.
373 The function is called from the article buffer."
374 :group 'gnus-article-mime
377 (defcustom gnus-decode-encoded-word-method 'gnus-article-decode-encoded-word
378 "*Function to decode MIME encoded words.
379 The function is called from the article buffer."
380 :group 'gnus-article-mime
383 (defcustom gnus-page-delimiter "^\^L"
384 "*Regexp describing what to use as article page delimiters.
385 The default value is \"^\^L\", which is a form linefeed at the
386 beginning of a line."
388 :group 'gnus-article-various)
390 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
391 "*The format specification for the article mode line.
392 See `gnus-summary-mode-line-format' for a closer description."
394 :group 'gnus-article-various)
396 (defcustom gnus-article-mode-hook nil
397 "*A hook for Gnus article mode."
399 :group 'gnus-article-various)
401 (defcustom gnus-article-menu-hook nil
402 "*Hook run after the creation of the article mode menu."
404 :group 'gnus-article-various)
406 (defcustom gnus-article-prepare-hook nil
407 "*A hook called after an article has been prepared in the article buffer.
408 If you want to run a special decoding program like nkf, use this hook."
410 :group 'gnus-article-various)
412 (defcustom gnus-article-hide-pgp-hook nil
413 "*A hook called after successfully hiding a PGP signature."
415 :group 'gnus-article-various)
417 (defcustom gnus-article-button-face 'bold
418 "Face used for highlighting buttons in the article buffer.
420 An article button is a piece of text that you can activate by pressing
421 `RET' or `mouse-2' above it."
423 :group 'gnus-article-buttons)
425 (defcustom gnus-article-mouse-face 'highlight
426 "Face used for mouse highlighting in the article buffer.
428 Article buttons will be displayed in this face when the cursor is
431 :group 'gnus-article-buttons)
433 (defcustom gnus-signature-face 'gnus-signature-face
434 "Face used for highlighting a signature in the article buffer.
435 Obsolete; use the face `gnus-signature-face' for customizations instead."
437 :group 'gnus-article-highlight
438 :group 'gnus-article-signature)
440 (defface gnus-signature-face
443 "Face used for highlighting a signature in the article buffer."
444 :group 'gnus-article-highlight
445 :group 'gnus-article-signature)
447 (defface gnus-header-from-face
450 (:foreground "spring green" :bold t))
453 (:foreground "red3" :bold t))
455 (:bold t :italic t)))
456 "Face used for displaying from headers."
457 :group 'gnus-article-headers
458 :group 'gnus-article-highlight)
460 (defface gnus-header-subject-face
463 (:foreground "SeaGreen3" :bold t))
466 (:foreground "red4" :bold t))
468 (:bold t :italic t)))
469 "Face used for displaying subject headers."
470 :group 'gnus-article-headers
471 :group 'gnus-article-highlight)
473 (defface gnus-header-newsgroups-face
476 (:foreground "yellow" :bold t :italic t))
479 (:foreground "MidnightBlue" :bold t :italic t))
481 (:bold t :italic t)))
482 "Face used for displaying newsgroups headers."
483 :group 'gnus-article-headers
484 :group 'gnus-article-highlight)
486 (defface gnus-header-name-face
489 (:foreground "SeaGreen"))
492 (:foreground "maroon"))
495 "Face used for displaying header names."
496 :group 'gnus-article-headers
497 :group 'gnus-article-highlight)
499 (defface gnus-header-content-face
502 (:foreground "forest green" :italic t))
505 (:foreground "indianred4" :italic t))
507 (:italic t))) "Face used for displaying header content."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defcustom gnus-header-face-alist
512 '(("From" nil gnus-header-from-face)
513 ("Subject" nil gnus-header-subject-face)
514 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
515 ("" gnus-header-name-face gnus-header-content-face))
516 "*Controls highlighting of article header.
518 An alist of the form (HEADER NAME CONTENT).
520 HEADER is a regular expression which should match the name of an
521 header header and NAME and CONTENT are either face names or nil.
523 The name of each header field will be displayed using the face
524 specified by the first element in the list where HEADER match the
525 header name and NAME is non-nil. Similarly, the content will be
526 displayed by the first non-nil matching CONTENT face."
527 :group 'gnus-article-headers
528 :group 'gnus-article-highlight
529 :type '(repeat (list (regexp :tag "Header")
531 (item :tag "skip" nil)
532 (face :value default))
533 (choice :tag "Content"
534 (item :tag "skip" nil)
535 (face :value default)))))
537 ;;; Internal variables
539 (defvar article-lapsed-timer nil)
540 (defvar gnus-article-current-summary nil)
542 (defvar gnus-article-mode-syntax-table
543 (let ((table (copy-syntax-table text-mode-syntax-table)))
544 (modify-syntax-entry ?- "w" table)
545 (modify-syntax-entry ?> ")" table)
546 (modify-syntax-entry ?< "(" table)
548 "Syntax table used in article mode buffers.
549 Initialized from `text-mode-syntax-table.")
551 (defvar gnus-save-article-buffer nil)
553 (defvar gnus-article-mode-line-format-alist
554 (nconc '((?w (gnus-article-wash-status) ?s))
555 gnus-summary-mode-line-format-alist))
557 (defvar gnus-number-of-articles-to-be-saved nil)
559 (defvar gnus-inhibit-hiding nil)
561 (defsubst gnus-article-hide-text (b e props)
562 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
563 (add-text-properties b e props)
564 (when (memq 'intangible props)
566 (max (1- b) (point-min))
567 b 'intangible (cddr (memq 'intangible props)))))
569 (defsubst gnus-article-unhide-text (b e)
570 "Remove hidden text properties from region between B and E."
571 (remove-text-properties b e gnus-hidden-properties)
572 (when (memq 'intangible gnus-hidden-properties)
573 (put-text-property (max (1- b) (point-min))
576 (defun gnus-article-hide-text-type (b e type)
577 "Hide text of TYPE between B and E."
578 (gnus-article-hide-text
579 b e (cons 'article-type (cons type gnus-hidden-properties))))
581 (defun gnus-article-unhide-text-type (b e type)
582 "Hide text of TYPE between B and E."
583 (remove-text-properties
584 b e (cons 'article-type (cons type gnus-hidden-properties)))
585 (when (memq 'intangible gnus-hidden-properties)
586 (put-text-property (max (1- b) (point-min))
589 (defun gnus-article-hide-text-of-type (type)
590 "Hide text of TYPE in the current buffer."
592 (let ((b (point-min))
594 (while (setq b (text-property-any b e 'article-type type))
595 (add-text-properties b (incf b) gnus-hidden-properties)))))
597 (defun gnus-article-delete-text-of-type (type)
598 "Delete text of TYPE in the current buffer."
600 (let ((b (point-min)))
601 (while (setq b (text-property-any b (point-max) 'article-type type))
603 b (or (text-property-not-all b (point-max) 'article-type type)
606 (defun gnus-article-delete-invisible-text ()
607 "Delete all invisible text in the current buffer."
609 (let ((b (point-min)))
610 (while (setq b (text-property-any b (point-max) 'invisible t))
612 b (or (text-property-not-all b (point-max) 'invisible t)
615 (defun gnus-article-text-type-exists-p (type)
616 "Say whether any text of type TYPE exists in the buffer."
617 (text-property-any (point-min) (point-max) 'article-type type))
619 (defsubst gnus-article-header-rank ()
620 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
621 (let ((list gnus-sorted-header-list)
624 (when (looking-at (car list))
626 (setq list (cdr list))
630 (defun article-hide-headers (&optional arg delete)
631 "Toggle whether to hide unwanted headers and possibly sort them as well.
632 If given a negative prefix, always show; if given a positive prefix,
634 (interactive (gnus-article-hidden-arg))
636 (if (gnus-article-check-hidden-text 'headers arg)
637 ;; Show boring headers as well.
638 (gnus-article-show-hidden-text 'boring-headers)
639 ;; This function might be inhibited.
640 (unless gnus-inhibit-hiding
643 (let ((buffer-read-only nil)
645 (props (nconc (list 'article-type 'headers)
646 gnus-hidden-properties))
647 (max (1+ (length gnus-sorted-header-list)))
648 (ignored (when (not gnus-visible-headers)
649 (cond ((stringp gnus-ignored-headers)
650 gnus-ignored-headers)
651 ((listp gnus-ignored-headers)
652 (mapconcat 'identity gnus-ignored-headers
655 (cond ((stringp gnus-visible-headers)
656 gnus-visible-headers)
657 ((and gnus-visible-headers
658 (listp gnus-visible-headers))
659 (mapconcat 'identity gnus-visible-headers "\\|"))))
660 (inhibit-point-motion-hooks t)
662 ;; First we narrow to just the headers.
664 (goto-char (point-min))
665 ;; Hide any "From " lines at the beginning of (mail) articles.
666 (while (looking-at "From ")
670 (delete-region (point-min) (point))
671 (gnus-article-hide-text (point-min) (point) props)))
672 ;; Then treat the rest of the header lines.
675 (if (search-forward "\n\n" nil t) ; if there's a body
676 (progn (forward-line -1) (point))
678 ;; Then we use the two regular expressions
679 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
680 ;; select which header lines is to remain visible in the
682 (goto-char (point-min))
683 (while (re-search-forward "^[^ \t]*:" nil t)
685 ;; Mark the rank of the header.
687 (point) (1+ (point)) 'message-rank
688 (if (or (and visible (looking-at visible))
690 (not (looking-at ignored))))
691 (gnus-article-header-rank)
694 (message-sort-headers-1)
695 (when (setq beg (text-property-any
696 (point-min) (point-max) 'message-rank (+ 2 max)))
697 ;; We make the unwanted headers invisible.
699 (delete-region beg (point-max))
700 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
701 (gnus-article-hide-text-type beg (point-max) 'headers))
702 ;; Work around XEmacs lossage.
703 (put-text-property (point-min) beg 'invisible nil))))))))
705 (defun article-hide-boring-headers (&optional arg)
706 "Toggle hiding of headers that aren't very interesting.
707 If given a negative prefix, always show; if given a positive prefix,
709 (interactive (gnus-article-hidden-arg))
710 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
711 (not gnus-show-all-headers))
714 (let ((buffer-read-only nil)
715 (list gnus-boring-article-headers)
716 (inhibit-point-motion-hooks t)
718 (nnheader-narrow-to-headers)
720 (setq elem (pop list))
721 (goto-char (point-min))
723 ;; Hide empty headers.
725 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
727 (gnus-article-hide-text-type
728 (progn (beginning-of-line) (point))
731 (if (re-search-forward "^[^ \t]" nil t)
735 ;; Hide boring Newsgroups header.
736 ((eq elem 'newsgroups)
737 (when (equal (gnus-fetch-field "newsgroups")
738 (gnus-group-real-name
739 (if (boundp 'gnus-newsgroup-name)
742 (gnus-article-hide-header "newsgroups")))
743 ((eq elem 'followup-to)
744 (when (equal (message-fetch-field "followup-to")
745 (message-fetch-field "newsgroups"))
746 (gnus-article-hide-header "followup-to")))
748 (let ((from (message-fetch-field "from"))
749 (reply-to (message-fetch-field "reply-to")))
754 (nth 1 (mail-extract-address-components from))
755 (nth 1 (mail-extract-address-components reply-to)))))
756 (gnus-article-hide-header "reply-to"))))
758 (let ((date (message-fetch-field "date")))
760 (< (gnus-days-between (current-time-string) date)
762 (gnus-article-hide-header "date"))))
764 (let ((to (message-fetch-field "to")))
765 (when (> (length to) 1024)
766 (gnus-article-hide-header "to"))))
769 (goto-char (point-min))
770 (while (re-search-forward "^to:" nil t)
771 (setq to-count (1+ to-count)))
773 (while (> to-count 0)
774 (goto-char (point-min))
776 (re-search-forward "^to:" nil nil to-count)
778 (narrow-to-region (point) (point-max))
779 (gnus-article-hide-header "to"))
780 (setq to-count (1- to-count)))))))))))))
782 (defun gnus-article-hide-header (header)
784 (goto-char (point-min))
785 (when (re-search-forward (concat "^" header ":") nil t)
786 (gnus-article-hide-text-type
787 (progn (beginning-of-line) (point))
790 (if (re-search-forward "^[^ \t]" nil t)
795 (defun article-treat-dumbquotes ()
796 "Translate M******** sm*rtq**t*s into proper text."
798 (article-translate-characters "\221\222\223\223" "`'\"\""))
800 (defun article-translate-characters (from to)
801 "Translate all characters in the body of the article according to FROM and TO.
802 FROM is a string of characters to translate from; to is a string of
803 characters to translate to."
805 (goto-char (point-min))
806 (when (search-forward "\n\n" nil t)
807 (let ((buffer-read-only nil)
808 (x (make-string 225 ?x))
810 (while (< (incf i) (length x))
813 (while (< i (length from))
814 (aset x (aref from i) (aref to i))
816 (translate-region (point) (point-max) x)))))
818 (defun article-treat-overstrike ()
819 "Translate overstrikes into bold text."
822 (goto-char (point-min))
823 (when (search-forward "\n\n" nil t)
824 (let ((buffer-read-only nil))
825 (while (search-forward "\b" nil t)
826 (let ((next (following-char))
827 (previous (char-after (- (point) 2))))
828 ;; We do the boldification/underlining by hiding the
829 ;; overstrikes and putting the proper text property
833 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
834 (put-text-property (point) (1+ (point)) 'face 'bold))
836 (gnus-article-hide-text-type
837 (1- (point)) (1+ (point)) 'overstrike)
839 (- (point) 2) (1- (point)) 'face 'underline))
841 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
843 (point) (1+ (point)) 'face 'underline)))))))))
845 (defun article-fill ()
846 "Format too long lines."
849 (let ((buffer-read-only nil))
851 (goto-char (point-min))
852 (search-forward "\n\n" nil t)
854 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
855 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
856 (adaptive-fill-mode t))
858 (and (>= (current-column) (min fill-column (window-width)))
859 (/= (preceding-char) ?:)
860 (fill-paragraph nil))
863 (defun article-remove-cr ()
864 "Remove carriage returns from an article."
867 (let ((buffer-read-only nil))
868 (goto-char (point-min))
869 (while (search-forward "\r" nil t)
870 (replace-match "" t t)))))
872 (defun article-remove-trailing-blank-lines ()
873 "Remove all trailing blank lines from the article."
876 (let ((buffer-read-only nil))
877 (goto-char (point-max))
881 (while (and (not (bobp))
882 (looking-at "^[ \t]*$"))
887 (defun article-display-x-face (&optional force)
888 "Look for an X-Face header and display it if present."
889 (interactive (list 'force))
891 ;; Delete the old process, if any.
892 (when (process-status "article-x-face")
893 (delete-process "article-x-face"))
894 (let ((inhibit-point-motion-hooks t)
898 (nnheader-narrow-to-headers)
899 (setq from (message-fetch-field "from"))
900 (goto-char (point-min))
901 (while (and gnus-article-x-face-command
903 ;; Check whether this face is censored.
904 (not gnus-article-x-face-too-ugly)
905 (and gnus-article-x-face-too-ugly from
906 (not (string-match gnus-article-x-face-too-ugly
908 ;; Has to be present.
909 (re-search-forward "^X-Face: " nil t))
910 ;; We now have the area of the buffer where the X-Face is stored.
913 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
914 ;; We display the face.
915 (if (symbolp gnus-article-x-face-command)
916 ;; The command is a lisp function, so we call it.
917 (if (gnus-functionp gnus-article-x-face-command)
918 (funcall gnus-article-x-face-command beg end)
919 (error "%s is not a function" gnus-article-x-face-command))
920 ;; The command is a string, so we interpret the command
921 ;; as a, well, command, and fork it off.
922 (let ((process-connection-type nil))
923 (process-kill-without-query
925 "article-x-face" nil shell-file-name shell-command-switch
926 gnus-article-x-face-command))
927 (process-send-region "article-x-face" beg end)
928 (process-send-eof "article-x-face"))))))))))
930 (defun gnus-article-decode-rfc1522 ()
931 "Decode MIME encoded-words in header fields."
932 (let (buffer-read-only)
933 (let ((charset (save-excursion
934 (set-buffer gnus-summary-buffer)
935 default-mime-charset)))
936 (eword-decode-header charset)
939 (defun article-hide-pgp (&optional arg)
940 "Toggle hiding of any PGP headers and signatures in the current article.
941 If given a negative prefix, always show; if given a positive prefix,
943 (interactive (gnus-article-hidden-arg))
944 (unless (gnus-article-check-hidden-text 'pgp arg)
946 (let ((inhibit-point-motion-hooks t)
947 buffer-read-only beg end)
949 (goto-char (point-min))
950 ;; Hide the "header".
951 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
952 (gnus-article-hide-text-type (1+ (match-beginning 0))
955 ;; Hide the actual signature.
956 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
957 (setq end (1+ (match-beginning 0)))
958 (gnus-article-hide-text-type
960 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
962 ;; Perhaps we shouldn't hide to the end of the buffer
963 ;; if there is no end to the signature?
966 ;; Hide "- " PGP quotation markers.
968 (narrow-to-region beg end)
969 (goto-char (point-min))
970 (while (re-search-forward "^- " nil t)
971 (gnus-article-hide-text-type
972 (match-beginning 0) (match-end 0) 'pgp))
974 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
976 (defun article-hide-pem (&optional arg)
977 "Toggle hiding of any PEM headers and signatures in the current article.
978 If given a negative prefix, always show; if given a positive prefix,
980 (interactive (gnus-article-hidden-arg))
981 (unless (gnus-article-check-hidden-text 'pem arg)
983 (let (buffer-read-only end)
985 (goto-char (point-min))
986 ;; hide the horrendously ugly "header".
987 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
990 (setq end (1+ (match-beginning 0)))
991 (gnus-article-hide-text-type
993 (if (search-forward "\n\n" nil t)
997 ;; hide the trailer as well
998 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1001 (gnus-article-hide-text-type
1002 (match-beginning 0) (match-end 0) 'pem))))))
1004 (defun article-hide-signature (&optional arg)
1005 "Hide the signature in the current article.
1006 If given a negative prefix, always show; if given a positive prefix,
1008 (interactive (gnus-article-hidden-arg))
1009 (unless (gnus-article-check-hidden-text 'signature arg)
1012 (let ((buffer-read-only nil))
1013 (when (gnus-article-narrow-to-signature)
1014 (gnus-article-hide-text-type
1015 (point-min) (point-max) 'signature)))))))
1017 (defun article-strip-leading-blank-lines ()
1018 "Remove all blank lines from the beginning of the article."
1021 (let ((inhibit-point-motion-hooks t)
1023 (goto-char (point-min))
1024 (when (search-forward "\n\n" nil t)
1025 (while (and (not (eobp))
1026 (looking-at "[ \t]*$"))
1027 (gnus-delete-line))))))
1029 (defun article-strip-multiple-blank-lines ()
1030 "Replace consecutive blank lines with one empty line."
1033 (let ((inhibit-point-motion-hooks t)
1035 ;; First make all blank lines empty.
1036 (goto-char (point-min))
1037 (search-forward "\n\n" nil t)
1038 (while (re-search-forward "^[ \t]+$" nil t)
1039 (replace-match "" nil t))
1040 ;; Then replace multiple empty lines with a single empty line.
1041 (goto-char (point-min))
1042 (search-forward "\n\n" nil t)
1043 (while (re-search-forward "\n\n\n+" nil t)
1044 (replace-match "\n\n" t t)))))
1046 (defun article-strip-leading-space ()
1047 "Remove all white space from the beginning of the lines in the article."
1050 (let ((inhibit-point-motion-hooks t)
1052 (goto-char (point-min))
1053 (search-forward "\n\n" nil t)
1054 (while (re-search-forward "^[ \t]+" nil t)
1055 (replace-match "" t t)))))
1057 (defun article-strip-blank-lines ()
1058 "Strip leading, trailing and multiple blank lines."
1060 (article-strip-leading-blank-lines)
1061 (article-remove-trailing-blank-lines)
1062 (article-strip-multiple-blank-lines))
1064 (defun article-strip-all-blank-lines ()
1065 "Strip all blank lines."
1068 (let ((inhibit-point-motion-hooks t)
1070 (goto-char (point-min))
1071 (search-forward "\n\n" nil t)
1072 (while (re-search-forward "^[ \t]*\n" nil t)
1073 (replace-match "" t t)))))
1075 (defvar mime::preview/content-list)
1076 (defvar mime::preview-content-info/point-min)
1077 (defun gnus-article-narrow-to-signature ()
1078 "Narrow to the signature; return t if a signature is found, else nil."
1080 (when (and (boundp 'mime::preview/content-list)
1081 mime::preview/content-list)
1082 ;; We have a MIMEish article, so we use the MIME data to narrow.
1083 (let ((pcinfo (car (last mime::preview/content-list))))
1086 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1089 (when (gnus-article-search-signature)
1091 ;; Check whether we have some limits to what we consider
1092 ;; to be a signature.
1093 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1094 (list gnus-signature-limit)))
1096 (while (setq limit (pop limits))
1097 (if (or (and (integerp limit)
1098 (< (- (point-max) (point)) limit))
1100 (< (count-lines (point) (point-max)) limit))
1101 (and (gnus-functionp limit)
1103 (and (stringp limit)
1104 (not (re-search-forward limit nil t))))
1105 () ; This limit did not succeed.
1109 (narrow-to-region (point) (point-max))
1112 (defun gnus-article-search-signature ()
1113 "Search the current buffer for the signature separator.
1114 Put point at the beginning of the signature separator."
1115 (let ((cur (point)))
1116 (goto-char (point-max))
1117 (if (if (stringp gnus-signature-separator)
1118 (re-search-backward gnus-signature-separator nil t)
1119 (let ((seps gnus-signature-separator))
1121 (not (re-search-backward (car seps) nil t)))
1129 (autoload 'w3-display "w3-parse")
1130 (autoload 'w3-do-setup "w3" "" t)
1131 (autoload 'w3-region "w3-display" "" t))
1133 (defun gnus-article-treat-html ()
1136 (let ((cbuf (current-buffer)))
1137 (set-buffer gnus-article-buffer)
1138 (let (buf buffer-read-only b e)
1140 (goto-char (point-min))
1142 (if (search-forward "\n\n" nil t)
1145 (setq e (point-max)))
1146 (nnheader-temp-write nil
1147 (insert-buffer-substring gnus-article-buffer b e)
1149 (save-window-excursion
1150 (w3-region (point-min) (point-max))
1151 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1153 (delete-region (point-min) (point-max))
1156 (goto-char (point-min))
1157 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1158 (set-buffer cbuf))))
1160 (defun gnus-article-hidden-arg ()
1161 "Return the current prefix arg as a number, or 0 if no prefix."
1162 (list (if current-prefix-arg
1163 (prefix-numeric-value current-prefix-arg)
1166 (defun gnus-article-check-hidden-text (type arg)
1167 "Return nil if hiding is necessary.
1168 Arg can be nil or a number. Nil and positive means hide, negative
1169 means show, 0 means toggle."
1173 (let ((hide (gnus-article-hidden-text-p type)))
1179 (gnus-article-show-hidden-text type))
1181 (if (eq hide 'hidden)
1182 (gnus-article-show-hidden-text type)
1185 (defun gnus-article-hidden-text-p (type)
1186 "Say whether the current buffer contains hidden text of type TYPE."
1187 (let ((start (point-min))
1188 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1190 (not (get-text-property pos 'invisible)))
1192 (text-property-any (1+ pos) (point-max) 'article-type type)))
1197 (defun gnus-article-show-hidden-text (type &optional hide)
1198 "Show all hidden text of type TYPE.
1199 If HIDE, hide the text instead."
1201 (let ((buffer-read-only nil)
1202 (inhibit-point-motion-hooks t)
1205 (while (setq beg (text-property-any end (point-max) 'article-type type))
1208 (text-property-not-all beg (point-max) 'article-type type)
1211 (gnus-article-hide-text beg end gnus-hidden-properties)
1212 (gnus-article-unhide-text beg end))
1216 (defconst article-time-units
1217 `((year . ,(* 365.25 24 60 60))
1218 (week . ,(* 7 24 60 60))
1219 (day . ,(* 24 60 60))
1223 "Mapping from time units to seconds.")
1225 (defun article-date-ut (&optional type highlight header)
1226 "Convert DATE date to universal time in the current article.
1227 If TYPE is `local', convert to local time; if it is `lapsed', output
1228 how much time has lapsed since DATE."
1229 (interactive (list 'ut t))
1230 (let* ((header (or header
1231 (mail-header-date gnus-current-headers)
1232 (message-fetch-field "date")
1234 (date (if (vectorp header) (mail-header-date header)
1236 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1237 (inhibit-point-motion-hooks t)
1238 bface eface newline)
1239 (when (and date (not (string= date "")))
1242 (nnheader-narrow-to-headers)
1243 (let ((buffer-read-only nil))
1244 ;; Delete any old Date headers.
1245 (if (re-search-forward date-regexp nil t)
1247 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1248 eface (get-text-property (1- (gnus-point-at-eol))
1250 (delete-region (progn (beginning-of-line) (point))
1251 (progn (end-of-line) (point)))
1252 (beginning-of-line))
1253 (goto-char (point-max))
1255 (insert (article-make-date-line date type))
1258 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1259 (put-text-property (match-beginning 1) (1+ (match-end 1))
1261 (put-text-property (match-beginning 2) (match-end 2)
1265 (insert "\n"))))))))
1267 (defun article-make-date-line (date type)
1268 "Return a DATE line of TYPE."
1270 ;; Convert to the local timezone. We have to slap a
1271 ;; `condition-case' round the calls to the timezone
1272 ;; functions since they aren't particularly resistant to
1275 (concat "Date: " (condition-case ()
1276 (timezone-make-date-arpa-standard date)
1278 ;; Convert to Universal Time.
1282 (timezone-make-date-arpa-standard date nil "UT")
1284 ;; Get the original date from the article.
1285 ((eq type 'original)
1286 (concat "Date: " date))
1287 ;; Let the user define the format.
1289 (if (gnus-functionp gnus-article-time-format)
1291 gnus-article-time-format
1294 (timezone-make-date-arpa-standard
1298 (format-time-string gnus-article-time-format
1301 (timezone-make-date-arpa-standard
1302 date nil "UT")))))))
1307 (format-time-string "%Y%M%DT%h%m%s"
1310 (timezone-make-date-arpa-standard
1312 ;; Do an X-Sent lapsed format.
1314 ;; If the date is seriously mangled, the timezone functions are
1315 ;; liable to bug out, so we ignore all errors.
1316 (let* ((now (current-time))
1321 (timezone-make-date-arpa-standard
1322 (current-time-string now)
1323 (current-time-zone now) "UT"))
1325 (timezone-make-date-arpa-standard
1327 (real-sec (and real-time
1328 (+ (* (float (car real-time)) 65536)
1330 (sec (and real-time (abs real-sec)))
1340 ;; This is a bit convoluted, but basically we go
1341 ;; through the time units for years, weeks, etc,
1342 ;; and divide things to see whether that results
1343 ;; in positive answers.
1346 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1347 ;; The (remaining) seconds are too few to
1348 ;; be divided into this time unit.
1350 ;; It's big enough, so we output it.
1351 (setq sec (- sec (* num (cdr unit))))
1353 (concat (if prev ", " "") (int-to-string
1355 " " (symbol-name (car unit))
1356 (if (> num 1) "s" ""))
1358 article-time-units "")
1359 ;; If dates are odd, then it might appear like the
1360 ;; article was sent in the future.
1363 " in the future"))))))
1365 (error "Unknown conversion type: %s" type))))
1367 (defun article-date-local (&optional highlight)
1368 "Convert the current article date to the local timezone."
1369 (interactive (list t))
1370 (article-date-ut 'local highlight))
1372 (defun article-date-original (&optional highlight)
1373 "Convert the current article date to what it was originally.
1374 This is only useful if you have used some other date conversion
1375 function and want to see what the date was before converting."
1376 (interactive (list t))
1377 (article-date-ut 'original highlight))
1379 (defun article-date-lapsed (&optional highlight)
1380 "Convert the current article date to time lapsed since it was sent."
1381 (interactive (list t))
1382 (article-date-ut 'lapsed highlight))
1384 (defun article-update-date-lapsed ()
1385 "Function to be run from a timer to update the lapsed time line."
1388 (when (gnus-buffer-live-p gnus-article-buffer)
1389 (set-buffer gnus-article-buffer)
1390 (goto-char (point-min))
1391 (when (re-search-forward "^X-Sent:" nil t)
1392 (article-date-lapsed t))))))
1394 (defun gnus-start-date-timer (&optional n)
1395 "Start a timer to update the X-Sent header in the article buffers.
1396 The numerical prefix says how frequently (in seconds) the function
1401 (gnus-stop-date-timer)
1402 (setq article-lapsed-timer
1403 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1405 (defun gnus-stop-date-timer ()
1406 "Stop the X-Sent timer."
1408 (when article-lapsed-timer
1409 (nnheader-cancel-timer article-lapsed-timer)
1410 (setq article-lapsed-timer nil)))
1412 (defun article-date-user (&optional highlight)
1413 "Convert the current article date to the user-defined format.
1414 This format is defined by the `gnus-article-time-format' variable."
1415 (interactive (list t))
1416 (article-date-ut 'user highlight))
1418 (defun article-date-iso8601 (&optional highlight)
1419 "Convert the current article date to ISO8601."
1420 (interactive (list t))
1421 (article-date-ut 'iso8601 highlight))
1423 (defun article-show-all ()
1424 "Show all hidden text in the article buffer."
1427 (let ((buffer-read-only nil))
1428 (gnus-article-unhide-text (point-min) (point-max)))))
1430 (defun article-emphasize (&optional arg)
1431 "Emphasize text according to `gnus-emphasis-alist'."
1432 (interactive (gnus-article-hidden-arg))
1433 (unless (gnus-article-check-hidden-text 'emphasis arg)
1435 (let ((alist gnus-emphasis-alist)
1436 (buffer-read-only nil)
1437 (props (append '(article-type emphasis)
1438 gnus-hidden-properties))
1439 regexp elem beg invisible visible face)
1440 (goto-char (point-min))
1441 (search-forward "\n\n" nil t)
1443 (while (setq elem (pop alist))
1445 (setq regexp (car elem)
1446 invisible (nth 1 elem)
1447 visible (nth 2 elem)
1449 (while (re-search-forward regexp nil t)
1450 (when (and (match-beginning visible) (match-beginning invisible))
1451 (gnus-article-hide-text
1452 (match-beginning invisible) (match-end invisible) props)
1453 (gnus-article-unhide-text-type
1454 (match-beginning visible) (match-end visible) 'emphasis)
1455 (gnus-put-text-property-excluding-newlines
1456 (match-beginning visible) (match-end visible) 'face face)
1457 (goto-char (match-end invisible)))))))))
1459 (defvar gnus-summary-article-menu)
1460 (defvar gnus-summary-post-menu)
1462 ;;; Saving functions.
1464 (defun gnus-article-save (save-buffer file &optional num)
1465 "Save the currently selected article."
1466 (unless gnus-save-all-headers
1467 ;; Remove headers according to `gnus-saved-headers'.
1468 (let ((gnus-visible-headers
1469 (or gnus-saved-headers gnus-visible-headers))
1470 (gnus-article-buffer save-buffer))
1472 (set-buffer save-buffer)
1473 (article-hide-headers 1 t))))
1474 (save-window-excursion
1475 (if (not gnus-default-article-saver)
1476 (error "No default saver is defined")
1477 ;; !!! Magic! The saving functions all save
1478 ;; `gnus-original-article-buffer' (or so they think), but we
1479 ;; bind that variable to our save-buffer.
1480 (set-buffer gnus-article-buffer)
1481 (let* ((gnus-save-article-buffer save-buffer)
1484 ((not gnus-prompt-before-saving) 'default)
1485 ((eq gnus-prompt-before-saving 'always) nil)
1487 (gnus-number-of-articles-to-be-saved
1488 (when (eq gnus-prompt-before-saving t)
1490 (set-buffer gnus-article-current-summary)
1491 (funcall gnus-default-article-saver filename)))))
1493 (defun gnus-read-save-file-name (prompt &optional filename
1494 function group headers variable)
1496 (funcall function group headers (symbol-value variable)))
1501 ((eq filename 'default)
1507 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1510 (if (and gnus-number-of-articles-to-be-saved
1511 (> gnus-number-of-articles-to-be-saved 1))
1512 (format "these %d articles"
1513 gnus-number-of-articles-to-be-saved)
1516 ;; Let the split methods have their say.
1518 ;; No split name was found.
1521 (concat prompt " (default "
1522 (file-name-nondirectory default-name) ") ")
1523 (file-name-directory default-name)
1525 ;; A single group name is returned.
1526 ((stringp split-name)
1528 (funcall function split-name headers
1529 (symbol-value variable)))
1531 (concat prompt " (default "
1532 (file-name-nondirectory default-name) ") ")
1533 (file-name-directory default-name)
1535 ;; A single split name was found
1536 ((= 1 (length split-name))
1537 (let* ((name (expand-file-name
1538 (car split-name) gnus-article-save-directory))
1539 (dir (cond ((file-directory-p name)
1540 (file-name-as-directory name))
1541 ((file-exists-p name) name)
1542 (t gnus-article-save-directory))))
1544 (concat prompt " (default " name ") ")
1546 ;; A list of splits was found.
1548 (setq split-name (nreverse split-name))
1550 (let ((file-name-history
1551 (nconc split-name file-name-history)))
1555 (concat prompt " (`M-p' for defaults) ")
1556 gnus-article-save-directory
1558 gnus-article-save-directory)))
1559 (car (push result file-name-history)))))))
1560 ;; Create the directory.
1561 (gnus-make-directory (file-name-directory file))
1562 ;; If we have read a directory, we append the default file name.
1563 (when (file-directory-p file)
1564 (setq file (concat (file-name-as-directory file)
1565 (file-name-nondirectory default-name))))
1566 ;; Possibly translate some characters.
1567 (nnheader-translate-file-chars file)))))
1568 (gnus-make-directory (file-name-directory result))
1569 (set variable result)))
1571 (defun gnus-article-archive-name (group)
1572 "Return the first instance of an \"Archive-name\" in the current buffer."
1573 (let ((case-fold-search t))
1574 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1575 (nnheader-concat gnus-article-save-directory
1576 (match-string 1)))))
1578 (defun gnus-article-nndoc-name (group)
1579 "If GROUP is an nndoc group, return the name of the parent group."
1580 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1581 (gnus-group-get-parameter group 'save-article-group)))
1583 (defun gnus-summary-save-in-rmail (&optional filename)
1584 "Append this article to Rmail file.
1585 Optional argument FILENAME specifies file name.
1586 Directory to save to is default to `gnus-article-save-directory'."
1588 (setq filename (gnus-read-save-file-name
1589 "Save %s in rmail file:" filename
1590 gnus-rmail-save-name gnus-newsgroup-name
1591 gnus-current-headers 'gnus-newsgroup-last-rmail))
1592 (gnus-eval-in-buffer-window gnus-save-article-buffer
1596 (gnus-output-to-rmail filename))))
1599 (defun gnus-summary-save-in-mail (&optional filename)
1600 "Append this article to Unix mail file.
1601 Optional argument FILENAME specifies file name.
1602 Directory to save to is default to `gnus-article-save-directory'."
1604 (setq filename (gnus-read-save-file-name
1605 "Save %s in Unix mail file:" filename
1606 gnus-mail-save-name gnus-newsgroup-name
1607 gnus-current-headers 'gnus-newsgroup-last-mail))
1608 (gnus-eval-in-buffer-window gnus-save-article-buffer
1612 (if (and (file-readable-p filename)
1613 (mail-file-babyl-p filename))
1614 (gnus-output-to-rmail filename t)
1615 (gnus-output-to-mail filename)))))
1618 (defun gnus-summary-save-in-file (&optional filename overwrite)
1619 "Append this article to file.
1620 Optional argument FILENAME specifies file name.
1621 Directory to save to is default to `gnus-article-save-directory'."
1623 (setq filename (gnus-read-save-file-name
1624 "Save %s in file:" filename
1625 gnus-file-save-name gnus-newsgroup-name
1626 gnus-current-headers 'gnus-newsgroup-last-file))
1627 (gnus-eval-in-buffer-window gnus-save-article-buffer
1631 (when (and overwrite
1632 (file-exists-p filename))
1633 (delete-file filename))
1634 (gnus-output-to-file filename))))
1637 (defun gnus-summary-write-to-file (&optional filename)
1638 "Write this article to a file.
1639 Optional argument FILENAME specifies file name.
1640 The directory to save in defaults to `gnus-article-save-directory'."
1642 (gnus-summary-save-in-file nil t))
1644 (defun gnus-summary-save-body-in-file (&optional filename)
1645 "Append this article body to a file.
1646 Optional argument FILENAME specifies file name.
1647 The directory to save in defaults to `gnus-article-save-directory'."
1649 (setq filename (gnus-read-save-file-name
1650 "Save %s body in file:" filename
1651 gnus-file-save-name gnus-newsgroup-name
1652 gnus-current-headers 'gnus-newsgroup-last-file))
1653 (gnus-eval-in-buffer-window gnus-save-article-buffer
1657 (goto-char (point-min))
1658 (when (search-forward "\n\n" nil t)
1659 (narrow-to-region (point) (point-max)))
1660 (gnus-output-to-file filename))))
1663 (defun gnus-summary-save-in-pipe (&optional command)
1664 "Pipe this article to subprocess."
1667 (cond ((eq command 'default)
1668 gnus-last-shell-command)
1672 "Shell command on %s: "
1673 (if (and gnus-number-of-articles-to-be-saved
1674 (> gnus-number-of-articles-to-be-saved 1))
1675 (format "these %d articles"
1676 gnus-number-of-articles-to-be-saved)
1678 gnus-last-shell-command))))
1679 (when (string-equal command "")
1680 (setq command gnus-last-shell-command))
1681 (gnus-eval-in-buffer-window gnus-article-buffer
1684 (shell-command-on-region (point-min) (point-max) command nil)))
1685 (setq gnus-last-shell-command command))
1687 ;;; Article file names when saving.
1689 (defun gnus-capitalize-newsgroup (newsgroup)
1690 "Capitalize NEWSGROUP name."
1691 (when (not (zerop (length newsgroup)))
1692 (concat (char-to-string (upcase (aref newsgroup 0)))
1693 (substring newsgroup 1))))
1695 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1696 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1697 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1698 Otherwise, it is like ~/News/news/group/num."
1701 (concat (if (gnus-use-long-file-name 'not-save)
1702 (gnus-capitalize-newsgroup newsgroup)
1703 (gnus-newsgroup-directory-form newsgroup))
1704 "/" (int-to-string (mail-header-number headers)))
1705 gnus-article-save-directory)))
1707 (string-equal (file-name-directory default)
1708 (file-name-directory last-file))
1709 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1711 (or last-file default))))
1713 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1714 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1715 If variable `gnus-use-long-file-name' is non-nil, it is
1716 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1719 (concat (if (gnus-use-long-file-name 'not-save)
1721 (gnus-newsgroup-directory-form newsgroup))
1722 "/" (int-to-string (mail-header-number headers)))
1723 gnus-article-save-directory)))
1725 (string-equal (file-name-directory default)
1726 (file-name-directory last-file))
1727 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1729 (or last-file default))))
1731 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1732 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1733 If variable `gnus-use-long-file-name' is non-nil, it is
1734 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1737 (if (gnus-use-long-file-name 'not-save)
1738 (gnus-capitalize-newsgroup newsgroup)
1739 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1740 gnus-article-save-directory)))
1742 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1743 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1744 If variable `gnus-use-long-file-name' is non-nil, it is
1745 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1748 (if (gnus-use-long-file-name 'not-save)
1750 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1751 gnus-article-save-directory)))
1758 (setq afunc (car func)
1761 gfunc (intern (format "gnus-%s" func))))
1763 (if (not (fboundp afunc))
1765 `(lambda (&optional interactive &rest args)
1766 ,(documentation afunc t)
1767 (interactive (list t))
1769 (set-buffer gnus-article-buffer)
1771 (call-interactively ',afunc)
1772 (apply ',afunc args))))))))
1773 '(article-hide-headers
1774 article-hide-boring-headers
1775 article-treat-overstrike
1776 (article-fill . gnus-article-word-wrap)
1778 article-display-x-face
1779 article-de-quoted-unreadable
1780 article-mime-decode-quoted-printable
1783 article-hide-signature
1784 article-remove-trailing-blank-lines
1785 article-strip-leading-blank-lines
1786 article-strip-multiple-blank-lines
1787 article-strip-leading-space
1788 article-strip-blank-lines
1789 article-strip-all-blank-lines
1791 article-date-iso8601
1792 article-date-original
1797 article-treat-dumbquotes
1798 (article-show-all . gnus-article-show-all-headers))))
1801 ;;; Gnus article mode
1804 (put 'gnus-article-mode 'mode-class 'special)
1806 (gnus-define-keys gnus-article-mode-map
1807 " " gnus-article-goto-next-page
1808 "\177" gnus-article-goto-prev-page
1809 [delete] gnus-article-goto-prev-page
1810 "\C-c^" gnus-article-refer-article
1811 "h" gnus-article-show-summary
1812 "s" gnus-article-show-summary
1813 "\C-c\C-m" gnus-article-mail
1814 "?" gnus-article-describe-briefly
1815 gnus-mouse-2 gnus-article-push-button
1816 "\r" gnus-article-press-button
1817 "\t" gnus-article-next-button
1818 "\M-\t" gnus-article-prev-button
1819 "e" gnus-article-edit
1820 "<" beginning-of-buffer
1822 "\C-c\C-i" gnus-info-find-node
1825 "\C-d" gnus-article-read-summary-keys
1826 "\M-*" gnus-article-read-summary-keys
1827 "\M-#" gnus-article-read-summary-keys
1828 "\M-^" gnus-article-read-summary-keys
1829 "\M-g" gnus-article-read-summary-keys)
1831 (substitute-key-definition
1832 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1834 (defun gnus-article-make-menu-bar ()
1835 (gnus-turn-off-edit-menu 'article)
1836 (unless (boundp 'gnus-article-article-menu)
1838 gnus-article-article-menu gnus-article-mode-map ""
1840 ["Scroll forwards" gnus-article-goto-next-page t]
1841 ["Scroll backwards" gnus-article-goto-prev-page t]
1842 ["Show summary" gnus-article-show-summary t]
1843 ["Fetch Message-ID at point" gnus-article-refer-article t]
1844 ["Mail to address at point" gnus-article-mail t]))
1847 gnus-article-treatment-menu gnus-article-mode-map ""
1849 ["Hide headers" gnus-article-hide-headers t]
1850 ["Hide signature" gnus-article-hide-signature t]
1851 ["Hide citation" gnus-article-hide-citation t]
1852 ["Treat overstrike" gnus-article-treat-overstrike t]
1853 ["Remove carriage return" gnus-article-remove-cr t]
1857 (when (boundp 'gnus-summary-article-menu)
1858 (define-key gnus-article-mode-map [menu-bar commands]
1859 (cons "Commands" gnus-summary-article-menu))))
1861 (when (boundp 'gnus-summary-post-menu)
1862 (define-key gnus-article-mode-map [menu-bar post]
1863 (cons "Post" gnus-summary-post-menu)))
1865 (gnus-run-hooks 'gnus-article-menu-hook)))
1867 (defun gnus-article-mode ()
1868 "Major mode for displaying an article.
1870 All normal editing commands are switched off.
1872 The following commands are available in addition to all summary mode
1874 \\<gnus-article-mode-map>
1875 \\[gnus-article-next-page]\t Scroll the article one page forwards
1876 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1877 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1878 \\[gnus-article-show-summary]\t Display the summary buffer
1879 \\[gnus-article-mail]\t Send a reply to the address near point
1880 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1881 \\[gnus-info-find-node]\t Go to the Gnus info node"
1883 (when (gnus-visual-p 'article-menu 'menu)
1884 (gnus-article-make-menu-bar))
1885 (kill-all-local-variables)
1886 (gnus-simplify-mode-line)
1887 (setq mode-name "Article")
1888 (setq major-mode 'gnus-article-mode)
1889 (make-local-variable 'minor-mode-alist)
1890 (unless (assq 'gnus-show-mime minor-mode-alist)
1891 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1892 (use-local-map gnus-article-mode-map)
1893 (gnus-update-format-specifications nil 'article-mode)
1894 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1895 (set (make-local-variable 'gnus-page-broken) nil)
1896 (set (make-local-variable 'gnus-button-marker-list) nil)
1897 (set (make-local-variable 'gnus-article-current-summary) nil)
1898 (gnus-set-default-directory)
1899 (buffer-disable-undo (current-buffer))
1900 (setq buffer-read-only t)
1901 (set-syntax-table gnus-article-mode-syntax-table)
1902 (gnus-run-hooks 'gnus-article-mode-hook))
1904 (defun gnus-article-setup-buffer ()
1905 "Initialize the article buffer."
1906 (let* ((name (if gnus-single-article-buffer "*Article*"
1907 (concat "*Article " gnus-newsgroup-name "*")))
1909 (progn (string-match "\\*Article" name)
1910 (concat " *Original Article"
1911 (substring name (match-end 0))))))
1912 (setq gnus-article-buffer name)
1913 (setq gnus-original-article-buffer original)
1914 ;; This might be a variable local to the summary buffer.
1915 (unless gnus-single-article-buffer
1917 (set-buffer gnus-summary-buffer)
1918 (setq gnus-article-buffer name)
1919 (setq gnus-original-article-buffer original)
1920 (gnus-set-global-variables)))
1921 ;; Init original article buffer.
1923 (set-buffer (get-buffer-create gnus-original-article-buffer))
1924 (buffer-disable-undo (current-buffer))
1925 (setq major-mode 'gnus-original-article-mode)
1926 (gnus-add-current-to-buffer-list)
1927 (make-local-variable 'gnus-original-article))
1928 (if (get-buffer name)
1931 (buffer-disable-undo (current-buffer))
1932 (setq buffer-read-only t)
1933 (gnus-add-current-to-buffer-list)
1934 (unless (eq major-mode 'gnus-article-mode)
1935 (gnus-article-mode))
1938 (set-buffer (get-buffer-create name))
1939 (gnus-add-current-to-buffer-list)
1941 (make-local-variable 'gnus-summary-buffer)
1942 (current-buffer)))))
1944 ;; Set article window start at LINE, where LINE is the number of lines
1945 ;; from the head of the article.
1946 (defun gnus-article-set-window-start (&optional line)
1948 (get-buffer-window gnus-article-buffer t)
1950 (set-buffer gnus-article-buffer)
1951 (goto-char (point-min))
1954 (gnus-message 6 "Moved to bookmark")
1955 (search-forward "\n\n" nil t)
1959 ;;; @@ article filters
1962 (defun gnus-article-preview-mime-message ()
1963 (make-local-variable 'mime-button-mother-dispatcher)
1964 (setq mime-button-mother-dispatcher
1965 (function gnus-article-push-button))
1966 (let ((default-mime-charset
1968 (set-buffer gnus-summary-buffer)
1969 default-mime-charset))
1972 (mime-view-mode nil nil nil gnus-original-article-buffer
1974 gnus-article-mode-map)
1976 (run-hooks 'gnus-mime-article-prepare-hook)
1979 (defun gnus-article-decode-encoded-word ()
1980 "Header filter for gnus-article-mode.
1981 It is registered to variable `mime-view-content-header-filter-alist'."
1982 (let ((charset (save-excursion
1983 (set-buffer gnus-summary-buffer)
1984 default-mime-charset)))
1985 (eword-decode-header charset)
1986 (goto-char (point-min))
1987 (if (search-forward "\n\n" nil t)
1988 (decode-mime-charset-region (match-end 0) (point-max) charset))
1989 (mime-maybe-hide-echo-buffer)
1991 (gnus-run-hooks 'gnus-mime-article-prepare-hook)
1994 (defun gnus-article-prepare (article &optional all-headers header)
1995 "Prepare ARTICLE in article mode buffer.
1996 ARTICLE should either be an article number or a Message-ID.
1997 If ARTICLE is an id, HEADER should be the article headers.
1998 If ALL-HEADERS is non-nil, no headers are hidden."
2000 ;; Make sure we start in a summary buffer.
2001 (unless (eq major-mode 'gnus-summary-mode)
2002 (set-buffer gnus-summary-buffer))
2003 (setq gnus-summary-buffer (current-buffer))
2004 ;; Make sure the connection to the server is alive.
2005 (unless (gnus-server-opened
2006 (gnus-find-method-for-group gnus-newsgroup-name))
2007 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2008 (gnus-request-group gnus-newsgroup-name t))
2009 (let* ((gnus-article (if header (mail-header-number header) article))
2010 (summary-buffer (current-buffer))
2011 (internal-hook gnus-article-internal-prepare-hook)
2012 (group gnus-newsgroup-name)
2015 (gnus-article-setup-buffer)
2016 (set-buffer gnus-article-buffer)
2017 ;; Deactivate active regions.
2018 (when (and (boundp 'transient-mark-mode)
2019 transient-mark-mode)
2020 (setq mark-active nil))
2021 (if (not (setq result (let ((buffer-read-only nil))
2022 (gnus-request-article-this-buffer
2024 ;; There is no such article.
2026 (when (and (numberp article)
2027 (not (memq article gnus-newsgroup-sparse)))
2028 (setq gnus-article-current
2029 (cons gnus-newsgroup-name article))
2030 (set-buffer gnus-summary-buffer)
2031 (setq gnus-current-article article)
2032 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2034 (gnus-summary-set-agent-mark article)
2035 (message "Message marked for downloading"))
2036 (gnus-summary-mark-article article gnus-canceled-mark)
2037 (unless (memq article gnus-newsgroup-sparse)
2039 "No such article (may have expired or been canceled)")))))
2040 (if (or (eq result 'pseudo) (eq result 'nneething))
2043 (set-buffer summary-buffer)
2044 (push article gnus-newsgroup-history)
2045 (setq gnus-last-article gnus-current-article
2046 gnus-current-article 0
2047 gnus-current-headers nil
2048 gnus-article-current nil)
2049 (if (eq result 'nneething)
2050 (gnus-configure-windows 'summary)
2051 (gnus-configure-windows 'article))
2052 (gnus-set-global-variables))
2053 (gnus-set-mode-line 'article))
2054 ;; The result from the `request' was an actual article -
2055 ;; or at least some text that is now displayed in the
2057 (when (and (numberp article)
2058 (not (eq article gnus-current-article)))
2059 ;; Seems like a new article has been selected.
2060 ;; `gnus-current-article' must be an article number.
2062 (set-buffer summary-buffer)
2063 (push article gnus-newsgroup-history)
2064 (setq gnus-last-article gnus-current-article
2065 gnus-current-article article
2066 gnus-current-headers
2067 (gnus-summary-article-header gnus-current-article)
2068 gnus-article-current
2069 (cons gnus-newsgroup-name gnus-current-article))
2070 (unless (vectorp gnus-current-headers)
2071 (setq gnus-current-headers nil))
2072 (gnus-summary-goto-subject gnus-current-article)
2073 (gnus-summary-show-thread)
2074 (gnus-run-hooks 'gnus-mark-article-hook)
2075 (gnus-set-mode-line 'summary)
2076 (when (gnus-visual-p 'article-highlight 'highlight)
2077 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2078 ;; Set the global newsgroup variables here.
2079 ;; Suggested by Jim Sisolak
2080 ;; <sisolak@trans4.neep.wisc.edu>.
2081 (gnus-set-global-variables)
2082 (setq gnus-have-all-headers
2083 (or all-headers gnus-show-all-headers))))
2084 (when (or (numberp article)
2086 ;; Hooks for getting information from the article.
2087 ;; This hook must be called before being narrowed.
2088 (let (buffer-read-only)
2089 (gnus-run-hooks 'internal-hook)
2090 (gnus-run-hooks 'gnus-article-prepare-hook)
2091 ;; Decode MIME message.
2092 (when gnus-show-mime
2093 (if (or (not gnus-strict-mime)
2094 (gnus-fetch-field "Mime-Version"))
2095 (funcall gnus-show-mime-method)
2096 (funcall gnus-decode-encoded-word-method)))
2097 ;; Perform the article display hooks.
2098 (gnus-run-hooks 'gnus-article-display-hook))
2100 (goto-char (point-min))
2101 (setq gnus-page-broken
2102 (when gnus-break-pages
2103 (gnus-narrow-to-page)
2105 (gnus-set-mode-line 'article)
2106 (gnus-configure-windows 'article)
2107 (goto-char (point-min))
2110 (defun gnus-article-wash-status ()
2111 "Return a string which display status of article washing."
2113 (set-buffer gnus-article-buffer)
2114 (let ((cite (gnus-article-hidden-text-p 'cite))
2115 (headers (gnus-article-hidden-text-p 'headers))
2116 (boring (gnus-article-hidden-text-p 'boring-headers))
2117 (pgp (gnus-article-hidden-text-p 'pgp))
2118 (pem (gnus-article-hidden-text-p 'pem))
2119 (signature (gnus-article-hidden-text-p 'signature))
2120 (overstrike (gnus-article-hidden-text-p 'overstrike))
2121 (emphasis (gnus-article-hidden-text-p 'emphasis))
2122 (mime gnus-show-mime))
2123 (format "%c%c%c%c%c%c%c"
2125 (if (or headers boring) ?h ? )
2126 (if (or pgp pem) ?p ? )
2127 (if signature ?s ? )
2128 (if overstrike ?o ? )
2130 (if emphasis ?e ? )))))
2132 (defun gnus-article-hide-headers-if-wanted ()
2133 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2134 Provided for backwards compatibility."
2135 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2137 (gnus-article-hide-headers)))
2141 (defun gnus-output-to-file (file-name)
2142 "Append the current article to a file named FILE-NAME."
2143 (let ((artbuf (current-buffer)))
2144 (nnheader-temp-write nil
2145 (insert-buffer-substring artbuf)
2146 ;; Append newline at end of the buffer as separator, and then
2148 (goto-char (point-max))
2150 (append-to-file (point-min) (point-max) file-name)
2153 (defun gnus-narrow-to-page (&optional arg)
2154 "Narrow the article buffer to a page.
2155 If given a numerical ARG, move forward ARG pages."
2157 (setq arg (if arg (prefix-numeric-value arg) 0))
2159 (set-buffer gnus-article-buffer)
2160 (goto-char (point-min))
2162 ;; Remove any old next/prev buttons.
2163 (when (gnus-visual-p 'page-marker)
2164 (let ((buffer-read-only nil))
2165 (gnus-remove-text-with-property 'gnus-prev)
2166 (gnus-remove-text-with-property 'gnus-next)))
2169 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2171 (re-search-forward page-delimiter nil 'move arg)))
2172 (goto-char (match-end 0)))
2175 (if (re-search-forward page-delimiter nil 'move)
2178 (when (and (gnus-visual-p 'page-marker)
2179 (not (= (point-min) 1)))
2181 (goto-char (point-min))
2182 (gnus-insert-prev-page-button)))
2183 (when (and (gnus-visual-p 'page-marker)
2184 (< (+ (point-max) 2) (buffer-size)))
2186 (goto-char (point-max))
2187 (gnus-insert-next-page-button)))))
2189 ;; Article mode commands
2191 (defun gnus-article-goto-next-page ()
2192 "Show the next page of the article."
2194 (when (gnus-article-next-page)
2195 (goto-char (point-min))
2196 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2198 (defun gnus-article-goto-prev-page ()
2199 "Show the next page of the article."
2201 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2202 (gnus-article-prev-page nil)))
2204 (defun gnus-article-next-page (&optional lines)
2205 "Show the next page of the current article.
2206 If end of article, return non-nil. Otherwise return nil.
2207 Argument LINES specifies lines to be scrolled up."
2209 (move-to-window-line -1)
2212 (and (pos-visible-in-window-p) ;Not continuation line.
2214 ;; Nothing in this page.
2215 (if (or (not gnus-page-broken)
2218 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2220 (gnus-narrow-to-page 1) ;Go to next page.
2222 ;; More in this page.
2223 (let ((scroll-in-place nil))
2227 ;; Long lines may cause an end-of-buffer error.
2228 (goto-char (point-max)))))
2229 (move-to-window-line 0)
2232 (defun gnus-article-prev-page (&optional lines)
2233 "Show previous page of current article.
2234 Argument LINES specifies lines to be scrolled down."
2236 (move-to-window-line 0)
2237 (if (and gnus-page-broken
2239 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2241 (gnus-narrow-to-page -1) ;Go to previous page.
2242 (goto-char (point-max))
2244 (let ((scroll-in-place nil))
2248 (beginning-of-buffer
2249 (goto-char (point-min))))
2250 (move-to-window-line 0)))))
2252 (defun gnus-article-refer-article ()
2253 "Read article specified by message-id around point."
2255 (let ((point (point)))
2256 (search-forward ">" nil t) ;Move point to end of "<....>".
2257 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2258 (let ((message-id (match-string 1)))
2260 (set-buffer gnus-summary-buffer)
2261 (gnus-summary-refer-article message-id))
2263 (error "No references around point"))))
2265 (defun gnus-article-show-summary ()
2266 "Reconfigure windows to show summary buffer."
2268 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2269 (error "There is no summary buffer for this article buffer")
2270 (gnus-article-set-globals)
2271 (gnus-configure-windows 'article)
2272 (gnus-summary-goto-subject gnus-current-article)))
2274 (defun gnus-article-describe-briefly ()
2275 "Describe article mode commands briefly."
2278 (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")))
2280 (defun gnus-article-summary-command ()
2281 "Execute the last keystroke in the summary buffer."
2283 (let ((obuf (current-buffer))
2284 (owin (current-window-configuration))
2286 (switch-to-buffer gnus-article-current-summary 'norecord)
2287 (setq func (lookup-key (current-local-map) (this-command-keys)))
2288 (call-interactively func)
2290 (set-window-configuration owin)
2291 (set-window-point (get-buffer-window (current-buffer)) (point))))
2293 (defun gnus-article-summary-command-nosave ()
2294 "Execute the last keystroke in the summary buffer."
2297 (pop-to-buffer gnus-article-current-summary 'norecord)
2298 (setq func (lookup-key (current-local-map) (this-command-keys)))
2299 (call-interactively func)))
2301 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2302 "Read a summary buffer key sequence and execute it from the article buffer."
2305 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2306 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2307 "=" "^" "\M-^" "|"))
2313 '("n" "Gn" "p" "Gp"))
2316 (set-buffer gnus-article-current-summary)
2317 (let (gnus-pick-mode)
2318 (push (or key last-command-event) unread-command-events)
2319 (setq keys (read-key-sequence nil))))
2322 (if (or (member keys nosaves)
2323 (member keys nosave-but-article)
2324 (member keys nosave-in-article))
2326 (save-window-excursion
2327 (pop-to-buffer gnus-article-current-summary 'norecord)
2328 ;; We disable the pick minor mode commands.
2329 (let (gnus-pick-mode)
2330 (setq func (lookup-key (current-local-map) keys))))
2333 (unless (member keys nosave-in-article)
2334 (set-buffer gnus-article-current-summary))
2335 (call-interactively func)
2336 (setq new-sum-point (point)))
2337 (when (member keys nosave-but-article)
2338 (pop-to-buffer gnus-article-buffer 'norecord)))
2339 ;; These commands should restore window configuration.
2340 (let ((obuf (current-buffer))
2341 (owin (current-window-configuration))
2343 (summary gnus-article-current-summary)
2345 (if not-restore-window
2346 (pop-to-buffer summary 'norecord)
2347 (switch-to-buffer summary 'norecord))
2348 (setq in-buffer (current-buffer))
2349 ;; We disable the pick minor mode commands.
2350 (if (setq func (let (gnus-pick-mode)
2351 (lookup-key (current-local-map) keys)))
2353 (call-interactively func)
2354 (setq new-sum-point (point)))
2356 (when (eq in-buffer (current-buffer))
2358 (unless not-restore-window
2359 (set-window-configuration owin))
2360 (unless (member keys up-to-top)
2361 (set-window-point (get-buffer-window (current-buffer))
2363 (let ((win (get-buffer-window gnus-article-current-summary)))
2365 (set-window-point win new-sum-point))))))))
2367 (defun gnus-article-hide (&optional arg force)
2368 "Hide all the gruft in the current article.
2369 This means that PGP stuff, signatures, cited text and (some)
2370 headers will be hidden.
2371 If given a prefix, show the hidden text instead."
2372 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2373 (gnus-article-hide-headers arg)
2374 (gnus-article-hide-pgp arg)
2375 (gnus-article-hide-citation-maybe arg force)
2376 (gnus-article-hide-signature arg))
2378 (defun gnus-article-maybe-highlight ()
2379 "Do some article highlighting if `article-visual' is non-nil."
2380 (when (gnus-visual-p 'article-highlight 'highlight)
2381 (gnus-article-highlight-some)))
2383 (defun gnus-request-article-this-buffer (article group)
2384 "Get an article and insert it into this buffer."
2385 (let (do-update-line)
2389 (gnus-kill-all-overlays)
2390 (setq group (or group gnus-newsgroup-name))
2392 ;; Open server if it has closed.
2393 (gnus-check-server (gnus-find-method-for-group group))
2395 ;; Using `gnus-request-article' directly will insert the article into
2396 ;; `nntp-server-buffer' - so we'll save some time by not having to
2397 ;; copy it from the server buffer into the article buffer.
2399 ;; We only request an article by message-id when we do not have the
2400 ;; headers for it, so we'll have to get those.
2401 (when (stringp article)
2402 (let ((gnus-override-method gnus-refer-article-method))
2403 (gnus-read-header article)))
2405 ;; If the article number is negative, that means that this article
2406 ;; doesn't belong in this newsgroup (possibly), so we find its
2407 ;; message-id and request it by id instead of number.
2408 (when (and (numberp article)
2410 (get-buffer gnus-summary-buffer)
2411 (buffer-name (get-buffer gnus-summary-buffer)))
2413 (set-buffer gnus-summary-buffer)
2414 (let ((header (gnus-summary-article-header article)))
2417 ((memq article gnus-newsgroup-sparse)
2418 ;; This is a sparse gap article.
2419 (setq do-update-line article)
2420 (setq article (mail-header-id header))
2421 (let ((gnus-override-method gnus-refer-article-method))
2422 (gnus-read-header article))
2423 (setq gnus-newsgroup-sparse
2424 (delq article gnus-newsgroup-sparse)))
2426 ;; It's a real article.
2427 (setq article (mail-header-id header)))
2429 ;; It is an extracted pseudo-article.
2430 (setq article 'pseudo)
2431 (gnus-request-pseudo-article header))))
2433 (let ((method (gnus-find-method-for-group
2434 gnus-newsgroup-name)))
2435 (if (not (eq (car method) 'nneething))
2437 (let ((dir (concat (file-name-as-directory (nth 1 method))
2438 (mail-header-subject header))))
2439 (when (file-directory-p dir)
2440 (setq article 'nneething)
2441 (gnus-group-enter-directory dir))))))))
2444 ;; Refuse to select canceled articles.
2445 ((and (numberp article)
2447 (get-buffer gnus-summary-buffer)
2448 (buffer-name (get-buffer gnus-summary-buffer))
2449 (eq (cdr (save-excursion
2450 (set-buffer gnus-summary-buffer)
2451 (assq article gnus-newsgroup-reads)))
2452 gnus-canceled-mark))
2454 ;; We first check `gnus-original-article-buffer'.
2455 ((and (get-buffer gnus-original-article-buffer)
2458 (set-buffer gnus-original-article-buffer)
2459 (and (equal (car gnus-original-article) group)
2460 (eq (cdr gnus-original-article) article))))
2461 (insert-buffer-substring gnus-original-article-buffer)
2463 ;; Check the backlog.
2464 ((and gnus-keep-backlog
2465 (gnus-backlog-request-article group article (current-buffer)))
2467 ;; Check asynchronous pre-fetch.
2468 ((gnus-async-request-fetched-article group article (current-buffer))
2469 (gnus-async-prefetch-next group article gnus-summary-buffer)
2470 (when (and (numberp article) gnus-keep-backlog)
2471 (gnus-backlog-enter-article group article (current-buffer)))
2474 ((and gnus-use-cache
2476 (gnus-cache-request-article article group))
2478 ;; Get the article and put into the article buffer.
2479 ((or (stringp article) (numberp article))
2480 (let ((gnus-override-method
2481 (and (stringp article) gnus-refer-article-method))
2482 (buffer-read-only nil))
2484 (gnus-kill-all-overlays)
2485 (when (gnus-request-article article group (current-buffer))
2486 (when (numberp article)
2487 (gnus-async-prefetch-next group article gnus-summary-buffer)
2488 (when gnus-keep-backlog
2489 (gnus-backlog-enter-article
2490 group article (current-buffer))))
2495 ;; Associate this article with the current summary buffer.
2496 (setq gnus-article-current-summary gnus-summary-buffer)
2498 ;; Take the article from the original article buffer
2499 ;; and place it in the buffer it's supposed to be in.
2500 (when (and (get-buffer gnus-article-buffer)
2501 (equal (buffer-name (current-buffer))
2502 (buffer-name (get-buffer gnus-article-buffer))))
2504 (if (get-buffer gnus-original-article-buffer)
2505 (set-buffer (get-buffer gnus-original-article-buffer))
2506 (set-buffer (get-buffer-create gnus-original-article-buffer))
2507 (buffer-disable-undo (current-buffer))
2508 (setq major-mode 'gnus-original-article-mode)
2509 (setq buffer-read-only t)
2510 (gnus-add-current-to-buffer-list))
2511 (let (buffer-read-only)
2513 (insert-buffer-substring gnus-article-buffer))
2514 (setq gnus-original-article (cons group article))))
2516 ;; Update sparse articles.
2517 (when (and do-update-line
2518 (or (numberp article)
2520 (let ((buf (current-buffer)))
2521 (set-buffer gnus-summary-buffer)
2522 (gnus-summary-update-article do-update-line)
2523 (gnus-summary-goto-subject do-update-line nil t)
2524 (set-window-point (get-buffer-window (current-buffer) t)
2526 (set-buffer buf))))))
2532 (defcustom gnus-article-edit-mode-hook nil
2533 "Hook run in article edit mode buffers."
2534 :group 'gnus-article-various
2537 (defvar gnus-article-edit-done-function nil)
2539 (defvar gnus-article-edit-mode-map nil)
2541 (unless gnus-article-edit-mode-map
2542 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2544 (gnus-define-keys gnus-article-edit-mode-map
2545 "\C-c\C-c" gnus-article-edit-done
2546 "\C-c\C-k" gnus-article-edit-exit)
2548 (gnus-define-keys (gnus-article-edit-wash-map
2549 "\C-c\C-w" gnus-article-edit-mode-map)
2550 "f" gnus-article-edit-full-stops))
2552 (defun gnus-article-edit-mode ()
2553 "Major mode for editing articles.
2554 This is an extended text-mode.
2556 \\{gnus-article-edit-mode-map}"
2558 (kill-all-local-variables)
2559 (setq major-mode 'gnus-article-edit-mode)
2560 (setq mode-name "Article Edit")
2561 (use-local-map gnus-article-edit-mode-map)
2562 (make-local-variable 'gnus-article-edit-done-function)
2563 (make-local-variable 'gnus-prev-winconf)
2564 (setq buffer-read-only nil)
2565 (buffer-enable-undo)
2567 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2569 (defun gnus-article-edit (&optional force)
2570 "Edit the current article.
2571 This will have permanent effect only in mail groups.
2572 If FORCE is non-nil, allow editing of articles even in read-only
2575 (when (and (not force)
2576 (gnus-group-read-only-p))
2577 (error "The current newsgroup does not support article editing"))
2578 (gnus-article-date-original)
2579 (gnus-article-edit-article
2580 `(lambda (no-highlight)
2581 (gnus-summary-edit-article-done
2582 ,(or (mail-header-references gnus-current-headers) "")
2583 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2585 (defun gnus-article-edit-article (exit-func)
2586 "Start editing the contents of the current article buffer."
2587 (let ((winconf (current-window-configuration)))
2588 (set-buffer gnus-article-buffer)
2589 (gnus-article-edit-mode)
2590 (gnus-set-text-properties (point-min) (point-max) nil)
2591 (gnus-configure-windows 'edit-article)
2592 (setq gnus-article-edit-done-function exit-func)
2593 (setq gnus-prev-winconf winconf)
2594 (gnus-message 6 "C-c C-c to end edits")))
2596 (defun gnus-article-edit-done (&optional arg)
2597 "Update the article edits and exit."
2602 (goto-char (point-min))
2603 (when (search-forward "\n\n" nil 1)
2604 (let ((lines (count-lines (point) (point-max)))
2605 (length (- (point-max) (point)))
2606 (case-fold-search t)
2607 (body (copy-marker (point))))
2608 (goto-char (point-min))
2609 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2610 (delete-region (match-beginning 1) (match-end 1))
2611 (insert (number-to-string length)))
2612 (goto-char (point-min))
2613 (when (re-search-forward
2614 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2615 (delete-region (match-beginning 1) (match-end 1))
2616 (insert (number-to-string length)))
2617 (goto-char (point-min))
2618 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2619 (delete-region (match-beginning 1) (match-end 1))
2620 (insert (number-to-string lines)))))))
2621 (let ((func gnus-article-edit-done-function)
2622 (buf (current-buffer))
2623 (start (window-start)))
2624 (gnus-article-edit-exit)
2627 (let ((buffer-read-only nil))
2628 (funcall func arg)))
2630 (set-window-start (get-buffer-window buf) start)
2631 (set-window-point (get-buffer-window buf) (point))))
2633 (defun gnus-article-edit-exit ()
2634 "Exit the article editing without updating."
2636 ;; We remove all text props from the article buffer.
2637 (let ((buf (format "%s" (buffer-string)))
2638 (curbuf (current-buffer))
2640 (window-start (window-start)))
2643 (let ((winconf gnus-prev-winconf))
2645 ;; The cache and backlog have to be flushed somewhat.
2646 (when gnus-use-cache
2647 (gnus-cache-update-article
2648 (car gnus-article-current) (cdr gnus-article-current)))
2649 (when gnus-keep-backlog
2650 (gnus-backlog-remove-article
2651 (car gnus-article-current) (cdr gnus-article-current)))
2652 ;; Flush original article as well.
2654 (when (get-buffer gnus-original-article-buffer)
2655 (set-buffer gnus-original-article-buffer)
2656 (setq gnus-original-article nil)))
2657 (set-window-configuration winconf)
2658 ;; Tippy-toe some to make sure that point remains where it was.
2659 (let ((buf (current-buffer)))
2661 (set-window-start (get-buffer-window (current-buffer)) window-start)
2663 (set-buffer buf)))))
2665 (defun gnus-article-edit-full-stops ()
2666 "Interactively repair spacing at end of sentences."
2669 (goto-char (point-min))
2670 (search-forward-regexp "^$" nil t)
2671 (let ((case-fold-search nil))
2672 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2675 ;;; Article highlights
2678 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2680 ;;; Internal Variables:
2682 (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\\)"
2683 "Regular expression that matches URLs."
2684 :group 'gnus-article-buttons
2687 (defcustom gnus-button-alist
2688 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2689 gnus-button-message-id 2)
2690 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2691 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2692 gnus-button-fetch-group 4)
2693 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2694 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2695 t gnus-button-message-id 3)
2696 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2697 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2698 ;; This is how URLs _should_ be embedded in text...
2699 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2701 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2702 "*Alist of regexps matching buttons in article bodies.
2704 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2705 REGEXP: is the string matching text around the button,
2706 BUTTON: is the number of the regexp grouping actually matching the button,
2707 FORM: is a lisp expression which must eval to true for the button to
2709 CALLBACK: is the function to call when the user push this button, and each
2710 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2712 CALLBACK can also be a variable, in that case the value of that
2713 variable it the real callback function."
2714 :group 'gnus-article-buttons
2715 :type '(repeat (list regexp
2716 (integer :tag "Button")
2718 (function :tag "Callback")
2721 (integer :tag "Regexp group")))))
2723 (defcustom gnus-header-button-alist
2724 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2725 0 t gnus-button-message-id 0)
2726 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2727 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2728 0 t gnus-button-mailto 0)
2729 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2730 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2731 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2732 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2733 gnus-button-message-id 3))
2734 "*Alist of headers and regexps to match buttons in article heads.
2736 This alist is very similar to `gnus-button-alist', except that each
2737 alist has an additional HEADER element first in each entry:
2739 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2741 HEADER is a regexp to match a header. For a fuller explanation, see
2742 `gnus-button-alist'."
2743 :group 'gnus-article-buttons
2744 :group 'gnus-article-headers
2745 :type '(repeat (list (regexp :tag "Header")
2747 (integer :tag "Button")
2749 (function :tag "Callback")
2752 (integer :tag "Regexp group")))))
2754 (defvar gnus-button-regexp nil)
2755 (defvar gnus-button-marker-list nil)
2756 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2758 (defvar gnus-button-last nil)
2759 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2763 (defun gnus-article-push-button (event)
2764 "Check text under the mouse pointer for a callback function.
2765 If the text under the mouse pointer has a `gnus-callback' property,
2766 call it with the value of the `gnus-data' text property."
2768 (set-buffer (window-buffer (posn-window (event-start event))))
2769 (let* ((pos (posn-point (event-start event)))
2770 (data (get-text-property pos 'gnus-data))
2771 (fun (get-text-property pos 'gnus-callback)))
2773 (funcall fun data))))
2775 (defun gnus-article-press-button ()
2776 "Check text at point for a callback function.
2777 If the text at point has a `gnus-callback' property,
2778 call it with the value of the `gnus-data' text property."
2780 (let* ((data (get-text-property (point) 'gnus-data))
2781 (fun (get-text-property (point) 'gnus-callback)))
2783 (funcall fun data))))
2785 (defun gnus-article-prev-button (n)
2786 "Move point to N buttons backward.
2787 If N is negative, move forward instead."
2789 (gnus-article-next-button (- n)))
2791 (defun gnus-article-next-button (n)
2792 "Move point to N buttons forward.
2793 If N is negative, move backward instead."
2795 (let ((function (if (< n 0) 'previous-single-property-change
2796 'next-single-property-change))
2797 (inhibit-point-motion-hooks t)
2799 (limit (if (< n 0) (point-min) (point-max))))
2801 (while (and (not (= limit (point)))
2803 ;; Skip past the current button.
2804 (when (get-text-property (point) 'gnus-callback)
2805 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2806 ;; Go to the next (or previous) button.
2807 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2808 ;; Put point at the start of the button.
2809 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2810 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2811 ;; Skip past intangible buttons.
2812 (when (get-text-property (point) 'intangible)
2816 (gnus-message 5 "No more buttons"))
2819 (defun gnus-article-highlight (&optional force)
2820 "Highlight current article.
2821 This function calls `gnus-article-highlight-headers',
2822 `gnus-article-highlight-citation',
2823 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2824 do the highlighting. See the documentation for those functions."
2825 (interactive (list 'force))
2826 (gnus-article-highlight-headers)
2827 (gnus-article-highlight-citation force)
2828 (gnus-article-highlight-signature)
2829 (gnus-article-add-buttons force)
2830 (gnus-article-add-buttons-to-head))
2832 (defun gnus-article-highlight-some (&optional force)
2833 "Highlight current article.
2834 This function calls `gnus-article-highlight-headers',
2835 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2836 do the highlighting. See the documentation for those functions."
2837 (interactive (list 'force))
2838 (gnus-article-highlight-headers)
2839 (gnus-article-highlight-signature)
2840 (gnus-article-add-buttons))
2842 (defun gnus-article-highlight-headers ()
2843 "Highlight article headers as specified by `gnus-header-face-alist'."
2846 (set-buffer gnus-article-buffer)
2848 (let ((alist gnus-header-face-alist)
2849 (buffer-read-only nil)
2850 (case-fold-search t)
2851 (inhibit-point-motion-hooks t)
2852 entry regexp header-face field-face from hpoints fpoints)
2853 (message-narrow-to-head)
2854 (while (setq entry (pop alist))
2855 (goto-char (point-min))
2856 (setq regexp (concat "^\\("
2857 (if (string-equal "" (nth 0 entry))
2861 header-face (nth 1 entry)
2862 field-face (nth 2 entry))
2863 (while (and (re-search-forward regexp nil t)
2867 (unless (search-forward ":" nil t)
2869 (when (and header-face
2870 (not (memq (point) hpoints)))
2871 (push (point) hpoints)
2872 (gnus-put-text-property from (point) 'face header-face))
2873 (when (and field-face
2874 (not (memq (setq from (point)) fpoints)))
2876 (if (re-search-forward "^[^ \t]" nil t)
2878 (goto-char (point-max)))
2879 (gnus-put-text-property from (point) 'face field-face))))))))
2881 (defun gnus-article-highlight-signature ()
2882 "Highlight the signature in an article.
2883 It does this by highlighting everything after
2884 `gnus-signature-separator' using `gnus-signature-face'."
2887 (set-buffer gnus-article-buffer)
2888 (let ((buffer-read-only nil)
2889 (inhibit-point-motion-hooks t))
2891 (when (and gnus-signature-face
2892 (gnus-article-narrow-to-signature))
2893 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2894 'face gnus-signature-face)
2896 (gnus-article-search-signature)
2897 (let ((start (match-beginning 0))
2898 (end (set-marker (make-marker) (1+ (match-end 0)))))
2899 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2902 (defun gnus-button-in-region-p (b e prop)
2903 "Say whether PROP exists in the region."
2904 (text-property-not-all b e prop nil))
2906 (defun gnus-article-add-buttons (&optional force)
2907 "Find external references in the article and make buttons of them.
2908 \"External references\" are things like Message-IDs and URLs, as
2909 specified by `gnus-button-alist'."
2910 (interactive (list 'force))
2912 (set-buffer gnus-article-buffer)
2913 (let ((buffer-read-only nil)
2914 (inhibit-point-motion-hooks t)
2915 (case-fold-search t)
2916 (alist gnus-button-alist)
2918 ;; Remove all old markers.
2920 (while (setq marker (pop gnus-button-marker-list))
2922 (when (setq entry (gnus-button-entry))
2923 (put-text-property (match-beginning (nth 1 entry))
2924 (match-end (nth 1 entry))
2925 'gnus-callback nil))
2926 (set-marker marker nil)))
2927 ;; We skip the headers.
2928 (goto-char (point-min))
2929 (unless (search-forward "\n\n" nil t)
2930 (goto-char (point-max)))
2932 (while (setq entry (pop alist))
2933 (setq regexp (car entry))
2935 (while (re-search-forward regexp nil t)
2936 (let* ((start (and entry (match-beginning (nth 1 entry))))
2937 (end (and entry (match-end (nth 1 entry))))
2938 (from (match-beginning 0)))
2939 (when (and (or (eq t (nth 2 entry))
2940 (eval (nth 2 entry)))
2941 (not (gnus-button-in-region-p
2942 start end 'gnus-callback)))
2943 ;; That optional form returned non-nil, so we add the
2945 (gnus-article-add-button
2946 start end 'gnus-button-push
2947 (car (push (set-marker (make-marker) from)
2948 gnus-button-marker-list))))))))))
2950 ;; Add buttons to the head of an article.
2951 (defun gnus-article-add-buttons-to-head ()
2952 "Add buttons to the head of the article."
2955 (set-buffer gnus-article-buffer)
2956 (let ((buffer-read-only nil)
2957 (inhibit-point-motion-hooks t)
2958 (case-fold-search t)
2959 (alist gnus-header-button-alist)
2961 (nnheader-narrow-to-headers)
2963 ;; Each alist entry.
2964 (setq entry (car alist)
2966 (goto-char (point-min))
2967 (while (re-search-forward (car entry) nil t)
2968 ;; Each header matching the entry.
2969 (setq beg (match-beginning 0))
2970 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2971 (match-beginning 0))
2974 (while (re-search-forward (nth 1 entry) end t)
2975 ;; Each match within a header.
2976 (let* ((entry (cdr entry))
2977 (start (match-beginning (nth 1 entry)))
2978 (end (match-end (nth 1 entry)))
2979 (form (nth 2 entry)))
2980 (goto-char (match-end 0))
2982 (gnus-article-add-button
2983 start end (nth 3 entry)
2984 (buffer-substring (match-beginning (nth 4 entry))
2985 (match-end (nth 4 entry)))))))
2989 ;;; External functions:
2991 (defun gnus-article-add-button (from to fun &optional data)
2992 "Create a button between FROM and TO with callback FUN and data DATA."
2993 (when gnus-article-button-face
2994 (gnus-overlay-put (gnus-make-overlay from to)
2995 'face gnus-article-button-face))
2996 (gnus-add-text-properties
2998 (nconc (and gnus-article-mouse-face
2999 (list gnus-mouse-face-prop gnus-article-mouse-face))
3000 (list 'gnus-callback fun)
3001 (and data (list 'gnus-data data)))))
3003 ;;; Internal functions:
3005 (defun gnus-article-set-globals ()
3007 (set-buffer gnus-summary-buffer)
3008 (gnus-set-global-variables)))
3010 (defun gnus-signature-toggle (end)
3012 (set-buffer gnus-article-buffer)
3013 (let ((buffer-read-only nil)
3014 (inhibit-point-motion-hooks t))
3015 (if (get-text-property end 'invisible)
3016 (gnus-article-unhide-text end (point-max))
3017 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3019 (defun gnus-button-entry ()
3020 ;; Return the first entry in `gnus-button-alist' matching this place.
3021 (let ((alist gnus-button-alist)
3024 (setq entry (pop alist))
3025 (if (looking-at (car entry))
3030 (defun gnus-button-push (marker)
3031 ;; Push button starting at MARKER.
3033 (set-buffer gnus-article-buffer)
3035 (let* ((entry (gnus-button-entry))
3036 (inhibit-point-motion-hooks t)
3038 (args (mapcar (lambda (group)
3039 (let ((string (match-string group)))
3040 (gnus-set-text-properties
3041 0 (length string) nil string)
3048 (fboundp (symbol-value fun)))
3049 (apply (symbol-value fun) args))
3051 (gnus-message 1 "You must define `%S' to use this button"
3052 (cons fun args)))))))
3054 (defun gnus-button-message-id (message-id)
3057 (set-buffer gnus-summary-buffer)
3058 (gnus-summary-refer-article message-id)))
3060 (defun gnus-button-fetch-group (address)
3061 "Fetch GROUP specified by ADDRESS."
3062 (if (not (string-match "[:/]" address))
3063 ;; This is just a simple group url.
3064 (gnus-group-read-ephemeral-group address gnus-select-method)
3065 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3067 (error "Can't parse %s" address)
3068 (gnus-group-read-ephemeral-group
3069 (match-string 4 address)
3070 `(nntp ,(match-string 1 address)
3071 (nntp-address ,(match-string 1 address))
3072 (nntp-port-number ,(if (match-end 3)
3073 (match-string 3 address)
3076 (defun gnus-split-string (string pattern)
3077 "Return a list of substrings of STRING which are separated by PATTERN."
3078 (let (parts (start 0))
3079 (while (string-match pattern string start)
3080 (setq parts (cons (substring string start (match-beginning 0)) parts)
3081 start (match-end 0)))
3082 (nreverse (cons (substring string start) parts))))
3084 (defun gnus-url-parse-query-string (query &optional downcase)
3085 (let (retval pairs cur key val)
3086 (setq pairs (gnus-split-string query "&"))
3088 (setq cur (car pairs)
3090 (if (not (string-match "=" cur))
3092 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3093 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3095 (setq key (downcase key)))
3096 (setq cur (assoc key retval))
3098 (setcdr cur (cons val (cdr cur)))
3099 (setq retval (cons (list key val) retval)))))
3102 (defun gnus-url-unhex (x)
3109 (defun gnus-url-unhex-string (str &optional allow-newlines)
3110 "Remove %XXX embedded spaces, etc in a url.
3111 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3112 decoding of carriage returns and line feeds in the string, which is normally
3113 forbidden in URL encoding."
3114 (setq str (or str ""))
3116 (case-fold-search t))
3117 (while (string-match "%[0-9a-f][0-9a-f]" str)
3118 (let* ((start (match-beginning 0))
3119 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3121 (gnus-url-unhex (elt str (+ start 2))))))
3123 tmp (substring str 0 start)
3126 (char-to-string code))
3127 ((or (= code ?\n) (= code ?\r))
3129 (t (char-to-string code))))
3130 str (substring str (match-end 0)))))
3131 (setq tmp (concat tmp str))
3134 (defun gnus-url-mailto (url)
3135 ;; Send mail to someone
3136 (when (string-match "mailto:/*\\(.*\\)" url)
3137 (setq url (substring url (match-beginning 1) nil)))
3138 (let (to args source-url subject func)
3139 (if (string-match (regexp-quote "?") url)
3140 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3141 args (gnus-url-parse-query-string
3142 (substring url (match-end 0) nil) t))
3143 (setq to (gnus-url-unhex-string url)))
3144 (setq args (cons (list "to" to) args)
3145 subject (cdr-safe (assoc "subject" args)))
3148 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3151 (message-position-on-field (caar args)))
3152 (insert (mapconcat 'identity (cdar args) ", "))
3153 (setq args (cdr args)))
3156 (message-goto-subject))))
3158 (defun gnus-button-mailto (address)
3160 (set-buffer (gnus-copy-article-buffer))
3161 (message-reply address))
3163 (defun gnus-button-reply (address)
3164 ;; Reply to ADDRESS.
3165 (message-reply address))
3167 (defun gnus-button-url (address)
3169 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3170 (if (listp browse-url-browser-function)
3171 (browse-url address)
3172 (funcall browse-url-browser-function address)))
3174 (defun gnus-button-embedded-url (address)
3176 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3177 (if (listp browse-url-browser-function)
3178 (browse-url (gnus-strip-whitespace address))
3179 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3181 ;;; Next/prev buttons in the article buffer.
3183 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3184 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3186 (defvar gnus-prev-page-map nil)
3187 (unless gnus-prev-page-map
3188 (setq gnus-prev-page-map (make-sparse-keymap))
3189 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3190 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3192 (defun gnus-insert-prev-page-button ()
3193 (let ((buffer-read-only nil))
3195 gnus-prev-page-line-format nil
3196 `(gnus-prev t local-map ,gnus-prev-page-map
3197 gnus-callback gnus-article-button-prev-page))))
3199 (defvar gnus-next-page-map nil)
3200 (unless gnus-next-page-map
3201 (setq gnus-next-page-map (make-keymap))
3202 (suppress-keymap gnus-prev-page-map)
3203 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3204 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3206 (defun gnus-button-next-page ()
3207 "Go to the next page."
3209 (let ((win (selected-window)))
3210 (select-window (get-buffer-window gnus-article-buffer t))
3211 (gnus-article-next-page)
3212 (select-window win)))
3214 (defun gnus-button-prev-page ()
3215 "Go to the prev page."
3217 (let ((win (selected-window)))
3218 (select-window (get-buffer-window gnus-article-buffer t))
3219 (gnus-article-prev-page)
3220 (select-window win)))
3222 (defun gnus-insert-next-page-button ()
3223 (let ((buffer-read-only nil))
3224 (gnus-eval-format gnus-next-page-line-format nil
3225 `(gnus-next t local-map ,gnus-next-page-map
3227 gnus-article-button-next-page))))
3229 (defun gnus-article-button-next-page (arg)
3230 "Go to the next page."
3232 (let ((win (selected-window)))
3233 (select-window (get-buffer-window gnus-article-buffer t))
3234 (gnus-article-next-page)
3235 (select-window win)))
3237 (defun gnus-article-button-prev-page (arg)
3238 "Go to the prev page."
3240 (let ((win (selected-window)))
3241 (select-window (get-buffer-window gnus-article-buffer t))
3242 (gnus-article-prev-page)
3243 (select-window win)))
3249 (defun gnus-content-header-filter ()
3250 "Header filter for mime-view.
3251 It is registered to variable `mime-view-content-header-filter-alist'."
3252 (eword-decode-header default-mime-charset))
3254 (defun mime-view-quitting-method-for-gnus ()
3255 (if (not gnus-show-mime)
3256 (mime-view-kill-buffer))
3257 (delete-other-windows)
3258 (gnus-article-show-summary)
3259 (if (or (not gnus-show-mime)
3260 (null gnus-have-all-headers))
3261 (gnus-summary-select-article nil t)
3264 (set-alist 'mime-view-content-header-filter-alist
3265 'gnus-original-article-mode
3266 (function gnus-content-header-filter))
3268 (set-alist 'mime-text-decoder-alist
3269 'gnus-original-article-mode
3270 (function mime-text-decode-buffer))
3272 (set-alist 'mime-view-quitting-method-alist
3273 'gnus-original-article-mode
3274 (function mime-view-quitting-method-for-gnus))
3276 (set-alist 'mime-view-show-summary-method
3277 'gnus-original-article-mode
3278 (function mime-view-quitting-method-for-gnus))
3288 (run-hooks 'gnus-art-load-hook)
3290 ;;; gnus-art.el ends here