1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
37 (defgroup gnus-article nil
39 :link '(custom-manual "(gnus)The Article Buffer")
42 (defgroup gnus-article-hiding nil
43 "Hiding article parts."
44 :link '(custom-manual "(gnus)Article Hiding")
47 (defgroup gnus-article-highlight nil
48 "Article highlighting."
49 :link '(custom-manual "(gnus)Article Highlighting")
53 (defgroup gnus-article-signature nil
55 :link '(custom-manual "(gnus)Article Signature")
58 (defgroup gnus-article-headers nil
60 :link '(custom-manual "(gnus)Hiding Headers")
63 (defgroup gnus-article-washing nil
64 "Special commands on articles."
65 :link '(custom-manual "(gnus)Article Washing")
68 (defgroup gnus-article-emphasis nil
69 "Fontisizing articles."
70 :link '(custom-manual "(gnus)Article Fontisizing")
73 (defgroup gnus-article-saving nil
75 :link '(custom-manual "(gnus)Saving Articles")
78 (defgroup gnus-article-mime nil
79 "Worshiping the MIME wonder."
80 :link '(custom-manual "(gnus)Using MIME")
83 (defgroup gnus-article-buttons nil
84 "Pushable buttons in the article buffer."
85 :link '(custom-manual "(gnus)Article Buttons")
88 (defgroup gnus-article-various nil
89 "Other article options."
90 :link '(custom-manual "(gnus)Misc Article")
93 (defcustom gnus-ignored-headers
94 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
95 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
96 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
97 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
98 "*All headers that start with this regexp will be hidden.
99 This variable can also be a list of regexps of headers to be ignored.
100 If `gnus-visible-headers' is non-nil, this variable will be ignored."
101 :type '(choice :custom-show nil
104 :group 'gnus-article-hiding)
106 (defcustom gnus-visible-headers
107 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
108 "*All headers that do not match this regexp will be hidden.
109 This variable can also be a list of regexp of headers to remain visible.
110 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
111 :type '(repeat :value-to-internal (lambda (widget value)
112 (custom-split-regexp-maybe value))
113 :match (lambda (widget value)
115 (widget-editable-list-match widget value)))
117 :group 'gnus-article-hiding)
119 (defcustom gnus-sorted-header-list
120 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
121 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
122 "*This variable is a list of regular expressions.
123 If it is non-nil, headers that match the regular expressions will
124 be placed first in the article buffer in the sequence specified by
126 :type '(repeat regexp)
127 :group 'gnus-article-hiding)
129 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
130 "Headers that are only to be displayed if they have interesting data.
131 Possible values in this list are `empty', `newsgroups', `followup-to',
132 `reply-to', `date', `long-to', and `many-to'."
133 :type '(set (const :tag "Headers with no content." empty)
134 (const :tag "Newsgroups with only one group." newsgroups)
135 (const :tag "Followup-to identical to newsgroups." followup-to)
136 (const :tag "Reply-to identical to from." reply-to)
137 (const :tag "Date less than four days old." date)
138 (const :tag "Very long To header." long-to)
139 (const :tag "Multiple To headers." many-to))
140 :group 'gnus-article-hiding)
142 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
143 "Regexp matching signature separator.
144 This can also be a list of regexps. In that case, it will be checked
145 from head to tail looking for a separator. Searches will be done from
146 the end of the buffer."
147 :type '(repeat string)
148 :group 'gnus-article-signature)
150 (defcustom gnus-signature-limit nil
151 "Provide a limit to what is considered a signature.
152 If it is a number, no signature may not be longer (in characters) than
153 that number. If it is a floating point number, no signature may be
154 longer (in lines) than that number. If it is a function, the function
155 will be called without any parameters, and if it returns nil, there is
156 no signature in the buffer. If it is a string, it will be used as a
157 regexp. If it matches, the text in question is not a signature."
158 :type '(choice (integer :value 200)
160 (function :value fun)
161 (regexp :value ".*"))
162 :group 'gnus-article-signature)
164 (defcustom gnus-hidden-properties '(invisible t intangible t)
165 "Property list to use for hiding text."
167 :group 'gnus-article-hiding)
169 (defcustom gnus-article-x-face-command
170 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
171 "*String or function to be executed to display an X-Face header.
172 If it is a string, the command will be executed in a sub-shell
173 asynchronously. The compressed face will be piped to this command."
174 :type 'string ;Leave function case to Lisp.
175 :group 'gnus-article-washing)
177 (defcustom gnus-article-x-face-too-ugly nil
178 "Regexp matching posters whose face shouldn't be shown automatically."
179 :type '(choice regexp (const nil))
180 :group 'gnus-article-washing)
182 (defcustom gnus-emphasis-alist
184 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
186 '(("_" "_" underline)
189 ("_/" "/_" underline-italic)
190 ("_\\*" "\\*_" underline-bold)
191 ("\\*/" "/\\*" bold-italic)
192 ("_\\*/" "/\\*_" underline-bold-italic))))
193 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
194 2 3 gnus-emphasis-underline)
198 (format format (car spec) (cadr spec))
199 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
201 "*Alist that says how to fontify certain phrases.
202 Each item looks like this:
204 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
206 The first element is a regular expression to be matched. The second
207 is a number that says what regular expression grouping used to find
208 the entire emphasized word. The third is a number that says what
209 regexp grouping should be displayed and highlighted. The fourth
210 is the face used for highlighting."
211 :type '(repeat (list :value ("" 0 0 default)
213 (integer :tag "Match group")
214 (integer :tag "Emphasize group")
216 :group 'gnus-article-emphasis)
218 (defface gnus-emphasis-bold '((t (:bold t)))
219 "Face used for displaying strong emphasized text (*word*)."
220 :group 'gnus-article-emphasis)
222 (defface gnus-emphasis-italic '((t (:italic t)))
223 "Face used for displaying italic emphasized text (/word/)."
224 :group 'gnus-article-emphasis)
226 (defface gnus-emphasis-underline '((t (:underline t)))
227 "Face used for displaying underlined emphasized text (_word_)."
228 :group 'gnus-article-emphasis)
230 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
231 "Face used for displaying underlined bold emphasized text (_*word*_)."
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
235 "Face used for displaying underlined italic emphasized text (_*word*_)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
239 "Face used for displaying bold italic emphasized text (/*word*/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline-bold-italic
243 '((t (:bold t :italic t :underline t)))
244 "Face used for displaying underlined bold italic emphasized text.
245 Esample: (_/*word*/_)."
246 :group 'gnus-article-emphasis)
248 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
249 "Format for display of Date headers in article bodies.
250 See `format-time-string' for the possible values.
252 The variable can also be function, which should return a complete Date
253 header. The function is called with one argument, the time, which can
254 be fed to `format-time-string'."
255 :type '(choice string symbol)
256 :link '(custom-manual "(gnus)Article Date")
257 :group 'gnus-article-washing)
260 (autoload 'hexl-hex-string-to-integer "hexl")
261 (autoload 'timezone-make-date-arpa-standard "timezone")
262 (autoload 'mail-extract-address-components "mail-extr"))
264 (defcustom gnus-save-all-headers t
265 "*If non-nil, don't remove any headers before saving."
266 :group 'gnus-article-saving
269 (defcustom gnus-prompt-before-saving 'always
270 "*This variable says how much prompting is to be done when saving articles.
271 If it is nil, no prompting will be done, and the articles will be
272 saved to the default files. If this variable is `always', each and
273 every article that is saved will be preceded by a prompt, even when
274 saving large batches of articles. If this variable is neither nil not
275 `always', there the user will be prompted once for a file name for
276 each invocation of the saving commands."
277 :group 'gnus-article-saving
278 :type '(choice (item always)
279 (item :tag "never" nil)
280 (sexp :tag "once" :format "%t\n" :value t)))
282 (defcustom gnus-saved-headers gnus-visible-headers
283 "Headers to keep if `gnus-save-all-headers' is nil.
284 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
285 If that variable is nil, however, all headers that match this regexp
286 will be kept while the rest will be deleted before saving."
287 :group 'gnus-article-saving
290 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
291 "A function to save articles in your favourite format.
292 The function must be interactively callable (in other words, it must
293 be an Emacs command).
295 Gnus provides the following functions:
297 * gnus-summary-save-in-rmail (Rmail format)
298 * gnus-summary-save-in-mail (Unix mail format)
299 * gnus-summary-save-in-folder (MH folder)
300 * gnus-summary-save-in-file (article format)
301 * gnus-summary-save-in-vm (use VM's folder format)
302 * gnus-summary-write-to-file (article format -- overwrite)."
303 :group 'gnus-article-saving
304 :type '(radio (function-item gnus-summary-save-in-rmail)
305 (function-item gnus-summary-save-in-mail)
306 (function-item gnus-summary-save-in-folder)
307 (function-item gnus-summary-save-in-file)
308 (function-item gnus-summary-save-in-vm)
309 (function-item gnus-summary-write-to-file)))
311 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
312 "A function generating a file name to save articles in Rmail format.
313 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
314 :group 'gnus-article-saving
317 (defcustom gnus-mail-save-name 'gnus-plain-save-name
318 "A function generating a file name to save articles in Unix mail format.
319 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
320 :group 'gnus-article-saving
323 (defcustom gnus-folder-save-name 'gnus-folder-save-name
324 "A function generating a file name to save articles in MH folder.
325 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
326 :group 'gnus-article-saving
329 (defcustom gnus-file-save-name 'gnus-numeric-save-name
330 "A function generating a file name to save articles in article format.
331 The function is called with NEWSGROUP, HEADERS, and optional
333 :group 'gnus-article-saving
336 (defcustom gnus-split-methods
337 '((gnus-article-archive-name)
338 (gnus-article-nndoc-name))
339 "*Variable used to suggest where articles are to be saved.
340 For instance, if you would like to save articles related to Gnus in
341 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
342 you could set this variable to something like:
344 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
345 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
347 This variable is an alist where the where the key is the match and the
348 value is a list of possible files to save in if the match is non-nil.
350 If the match is a string, it is used as a regexp match on the
351 article. If the match is a symbol, that symbol will be funcalled
352 from the buffer of the article to be saved with the newsgroup as the
353 parameter. If it is a list, it will be evaled in the same buffer.
355 If this form or function returns a string, this string will be used as
356 a possible file name; and if it returns a non-nil list, that list will
357 be used as possible file names."
358 :group 'gnus-article-saving
359 :type '(repeat (choice (list :value (fun) function)
360 (cons :value ("" "") regexp (repeat string))
363 (defcustom gnus-strict-mime t
364 "*If nil, MIME-decode even if there is no Mime-Version header."
365 :group 'gnus-article-mime
368 (defcustom gnus-show-mime-method 'metamail-buffer
369 "Function to process a MIME message.
370 The function is called from the article buffer."
371 :group 'gnus-article-mime
374 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
375 "*Function to decode MIME encoded words.
376 The function is called from the article buffer."
377 :group 'gnus-article-mime
380 (defcustom gnus-page-delimiter "^\^L"
381 "*Regexp describing what to use as article page delimiters.
382 The default value is \"^\^L\", which is a form linefeed at the
383 beginning of a line."
385 :group 'gnus-article-various)
387 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
388 "*The format specification for the article mode line.
389 See `gnus-summary-mode-line-format' for a closer description."
391 :group 'gnus-article-various)
393 (defcustom gnus-article-mode-hook nil
394 "*A hook for Gnus article mode."
396 :group 'gnus-article-various)
398 (defcustom gnus-article-menu-hook nil
399 "*Hook run after the creation of the article mode menu."
401 :group 'gnus-article-various)
403 (defcustom gnus-article-prepare-hook nil
404 "*A hook called after an article has been prepared in the article buffer.
405 If you want to run a special decoding program like nkf, use this hook."
407 :group 'gnus-article-various)
409 (defcustom gnus-article-hide-pgp-hook nil
410 "*A hook called after successfully hiding a PGP signature."
412 :group 'gnus-article-various)
414 (defcustom gnus-article-button-face 'bold
415 "Face used for highlighting buttons in the article buffer.
417 An article button is a piece of text that you can activate by pressing
418 `RET' or `mouse-2' above it."
420 :group 'gnus-article-buttons)
422 (defcustom gnus-article-mouse-face 'highlight
423 "Face used for mouse highlighting in the article buffer.
425 Article buttons will be displayed in this face when the cursor is
428 :group 'gnus-article-buttons)
430 (defcustom gnus-signature-face 'gnus-signature-face
431 "Face used for highlighting a signature in the article buffer.
432 Obsolete; use the face `gnus-signature-face' for customizations instead."
434 :group 'gnus-article-highlight
435 :group 'gnus-article-signature)
437 (defface gnus-signature-face
440 "Face used for highlighting a signature in the article buffer."
441 :group 'gnus-article-highlight
442 :group 'gnus-article-signature)
444 (defface gnus-header-from-face
447 (:foreground "spring green" :bold t))
450 (:foreground "red3" :bold t))
452 (:bold t :italic t)))
453 "Face used for displaying from headers."
454 :group 'gnus-article-headers
455 :group 'gnus-article-highlight)
457 (defface gnus-header-subject-face
460 (:foreground "SeaGreen3" :bold t))
463 (:foreground "red4" :bold t))
465 (:bold t :italic t)))
466 "Face used for displaying subject headers."
467 :group 'gnus-article-headers
468 :group 'gnus-article-highlight)
470 (defface gnus-header-newsgroups-face
473 (:foreground "yellow" :bold t :italic t))
476 (:foreground "MidnightBlue" :bold t :italic t))
478 (:bold t :italic t)))
479 "Face used for displaying newsgroups headers."
480 :group 'gnus-article-headers
481 :group 'gnus-article-highlight)
483 (defface gnus-header-name-face
486 (:foreground "SeaGreen"))
489 (:foreground "maroon"))
492 "Face used for displaying header names."
493 :group 'gnus-article-headers
494 :group 'gnus-article-highlight)
496 (defface gnus-header-content-face
499 (:foreground "forest green" :italic t))
502 (:foreground "indianred4" :italic t))
504 (:italic t))) "Face used for displaying header content."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight)
508 (defcustom gnus-header-face-alist
509 '(("From" nil gnus-header-from-face)
510 ("Subject" nil gnus-header-subject-face)
511 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
512 ("" gnus-header-name-face gnus-header-content-face))
513 "*Controls highlighting of article header.
515 An alist of the form (HEADER NAME CONTENT).
517 HEADER is a regular expression which should match the name of an
518 header header and NAME and CONTENT are either face names or nil.
520 The name of each header field will be displayed using the face
521 specified by the first element in the list where HEADER match the
522 header name and NAME is non-nil. Similarly, the content will be
523 displayed by the first non-nil matching CONTENT face."
524 :group 'gnus-article-headers
525 :group 'gnus-article-highlight
526 :type '(repeat (list (regexp :tag "Header")
528 (item :tag "skip" nil)
529 (face :value default))
530 (choice :tag "Content"
531 (item :tag "skip" nil)
532 (face :value default)))))
534 ;;; Internal variables
536 (defvar article-lapsed-timer nil)
537 (defvar gnus-article-current-summary nil)
539 (defvar gnus-article-mode-syntax-table
540 (let ((table (copy-syntax-table text-mode-syntax-table)))
541 (modify-syntax-entry ?- "w" table)
542 (modify-syntax-entry ?> ")" table)
543 (modify-syntax-entry ?< "(" table)
545 "Syntax table used in article mode buffers.
546 Initialized from `text-mode-syntax-table.")
548 (defvar gnus-save-article-buffer nil)
550 (defvar gnus-article-mode-line-format-alist
551 (nconc '((?w (gnus-article-wash-status) ?s))
552 gnus-summary-mode-line-format-alist))
554 (defvar gnus-number-of-articles-to-be-saved nil)
556 (defvar gnus-inhibit-hiding nil)
558 (defsubst gnus-article-hide-text (b e props)
559 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
560 (add-text-properties b e props)
561 (when (memq 'intangible props)
563 (max (1- b) (point-min))
564 b 'intangible (cddr (memq 'intangible props)))))
566 (defsubst gnus-article-unhide-text (b e)
567 "Remove hidden text properties from region between B and E."
568 (remove-text-properties b e gnus-hidden-properties)
569 (when (memq 'intangible gnus-hidden-properties)
570 (put-text-property (max (1- b) (point-min))
573 (defun gnus-article-hide-text-type (b e type)
574 "Hide text of TYPE between B and E."
575 (gnus-article-hide-text
576 b e (cons 'article-type (cons type gnus-hidden-properties))))
578 (defun gnus-article-unhide-text-type (b e type)
579 "Hide text of TYPE between B and E."
580 (remove-text-properties
581 b e (cons 'article-type (cons type gnus-hidden-properties)))
582 (when (memq 'intangible gnus-hidden-properties)
583 (put-text-property (max (1- b) (point-min))
586 (defun gnus-article-hide-text-of-type (type)
587 "Hide text of TYPE in the current buffer."
589 (let ((b (point-min))
591 (while (setq b (text-property-any b e 'article-type type))
592 (add-text-properties b (incf b) gnus-hidden-properties)))))
594 (defun gnus-article-delete-text-of-type (type)
595 "Delete text of TYPE in the current buffer."
597 (let ((b (point-min)))
598 (while (setq b (text-property-any b (point-max) 'article-type type))
600 b (or (text-property-not-all b (point-max) 'article-type type)
603 (defun gnus-article-delete-invisible-text ()
604 "Delete all invisible text in the current buffer."
606 (let ((b (point-min)))
607 (while (setq b (text-property-any b (point-max) 'invisible t))
609 b (or (text-property-not-all b (point-max) 'invisible t)
612 (defun gnus-article-text-type-exists-p (type)
613 "Say whether any text of type TYPE exists in the buffer."
614 (text-property-any (point-min) (point-max) 'article-type type))
616 (defsubst gnus-article-header-rank ()
617 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
618 (let ((list gnus-sorted-header-list)
621 (when (looking-at (car list))
623 (setq list (cdr list))
627 (defun article-hide-headers (&optional arg delete)
628 "Toggle whether to hide unwanted headers and possibly sort them as well.
629 If given a negative prefix, always show; if given a positive prefix,
631 (interactive (gnus-article-hidden-arg))
633 (if (gnus-article-check-hidden-text 'headers arg)
634 ;; Show boring headers as well.
635 (gnus-article-show-hidden-text 'boring-headers)
636 ;; This function might be inhibited.
637 (unless gnus-inhibit-hiding
640 (let ((buffer-read-only nil)
642 (props (nconc (list 'article-type 'headers)
643 gnus-hidden-properties))
644 (max (1+ (length gnus-sorted-header-list)))
645 (ignored (when (not gnus-visible-headers)
646 (cond ((stringp gnus-ignored-headers)
647 gnus-ignored-headers)
648 ((listp gnus-ignored-headers)
649 (mapconcat 'identity gnus-ignored-headers
652 (cond ((stringp gnus-visible-headers)
653 gnus-visible-headers)
654 ((and gnus-visible-headers
655 (listp gnus-visible-headers))
656 (mapconcat 'identity gnus-visible-headers "\\|"))))
657 (inhibit-point-motion-hooks t)
659 ;; First we narrow to just the headers.
661 (goto-char (point-min))
662 ;; Hide any "From " lines at the beginning of (mail) articles.
663 (while (looking-at "From ")
667 (delete-region (point-min) (point))
668 (gnus-article-hide-text (point-min) (point) props)))
669 ;; Then treat the rest of the header lines.
672 (if (search-forward "\n\n" nil t) ; if there's a body
673 (progn (forward-line -1) (point))
675 ;; Then we use the two regular expressions
676 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
677 ;; select which header lines is to remain visible in the
679 (goto-char (point-min))
680 (while (re-search-forward "^[^ \t]*:" nil t)
682 ;; Mark the rank of the header.
684 (point) (1+ (point)) 'message-rank
685 (if (or (and visible (looking-at visible))
687 (not (looking-at ignored))))
688 (gnus-article-header-rank)
691 (message-sort-headers-1)
692 (when (setq beg (text-property-any
693 (point-min) (point-max) 'message-rank (+ 2 max)))
694 ;; We make the unwanted headers invisible.
696 (delete-region beg (point-max))
697 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
698 (gnus-article-hide-text-type beg (point-max) 'headers))
699 ;; Work around XEmacs lossage.
700 (put-text-property (point-min) beg 'invisible nil))))))))
702 (defun article-hide-boring-headers (&optional arg)
703 "Toggle hiding of headers that aren't very interesting.
704 If given a negative prefix, always show; if given a positive prefix,
706 (interactive (gnus-article-hidden-arg))
707 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
708 (not gnus-show-all-headers))
711 (let ((buffer-read-only nil)
712 (list gnus-boring-article-headers)
713 (inhibit-point-motion-hooks t)
715 (nnheader-narrow-to-headers)
717 (setq elem (pop list))
718 (goto-char (point-min))
720 ;; Hide empty headers.
722 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
724 (gnus-article-hide-text-type
725 (progn (beginning-of-line) (point))
728 (if (re-search-forward "^[^ \t]" nil t)
732 ;; Hide boring Newsgroups header.
733 ((eq elem 'newsgroups)
734 (when (equal (gnus-fetch-field "newsgroups")
735 (gnus-group-real-name
736 (if (boundp 'gnus-newsgroup-name)
739 (gnus-article-hide-header "newsgroups")))
740 ((eq elem 'followup-to)
741 (when (equal (message-fetch-field "followup-to")
742 (message-fetch-field "newsgroups"))
743 (gnus-article-hide-header "followup-to")))
745 (let ((from (message-fetch-field "from"))
746 (reply-to (message-fetch-field "reply-to")))
751 (nth 1 (mail-extract-address-components from))
752 (nth 1 (mail-extract-address-components reply-to)))))
753 (gnus-article-hide-header "reply-to"))))
755 (let ((date (message-fetch-field "date")))
757 (< (gnus-days-between (current-time-string) date)
759 (gnus-article-hide-header "date"))))
761 (let ((to (message-fetch-field "to")))
762 (when (> (length to) 1024)
763 (gnus-article-hide-header "to"))))
766 (goto-char (point-min))
767 (while (re-search-forward "^to:" nil t)
768 (setq to-count (1+ to-count)))
770 (while (> to-count 0)
771 (goto-char (point-min))
773 (re-search-forward "^to:" nil nil to-count)
775 (narrow-to-region (point) (point-max))
776 (gnus-article-hide-header "to"))
777 (setq to-count (1- to-count)))))))))))))
779 (defun gnus-article-hide-header (header)
781 (goto-char (point-min))
782 (when (re-search-forward (concat "^" header ":") nil t)
783 (gnus-article-hide-text-type
784 (progn (beginning-of-line) (point))
787 (if (re-search-forward "^[^ \t]" nil t)
792 (defun article-treat-dumbquotes ()
793 "Translate M******** sm*rtq**t*s into proper text."
795 (article-translate-characters "\221\222\223\223" "`'\"\""))
797 (defun article-translate-characters (from to)
798 "Translate all characters in the body of the article according to FROM and TO.
799 FROM is a string of characters to translate from; to is a string of
800 characters to translate to."
802 (goto-char (point-min))
803 (when (search-forward "\n\n" nil t)
804 (let ((buffer-read-only nil)
805 (x (make-string 225 ?x))
807 (while (< (incf i) (length x))
810 (while (< i (length from))
811 (aset x (aref from i) (aref to i))
813 (translate-region (point) (point-max) x)))))
815 (defun article-treat-overstrike ()
816 "Translate overstrikes into bold text."
819 (goto-char (point-min))
820 (when (search-forward "\n\n" nil t)
821 (let ((buffer-read-only nil))
822 (while (search-forward "\b" nil t)
823 (let ((next (following-char))
824 (previous (char-after (- (point) 2))))
825 ;; We do the boldification/underlining by hiding the
826 ;; overstrikes and putting the proper text property
830 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
831 (put-text-property (point) (1+ (point)) 'face 'bold))
833 (gnus-article-hide-text-type
834 (1- (point)) (1+ (point)) 'overstrike)
836 (- (point) 2) (1- (point)) 'face 'underline))
838 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
840 (point) (1+ (point)) 'face 'underline)))))))))
842 (defun article-fill ()
843 "Format too long lines."
846 (let ((buffer-read-only nil))
848 (goto-char (point-min))
849 (search-forward "\n\n" nil t)
851 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
852 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
853 (adaptive-fill-mode t))
855 (and (>= (current-column) (min fill-column (window-width)))
856 (/= (preceding-char) ?:)
857 (fill-paragraph nil))
860 (defun article-remove-cr ()
861 "Remove carriage returns from an article."
864 (let ((buffer-read-only nil))
865 (goto-char (point-min))
866 (while (search-forward "\r" nil t)
867 (replace-match "" t t)))))
869 (defun article-remove-trailing-blank-lines ()
870 "Remove all trailing blank lines from the article."
873 (let ((buffer-read-only nil))
874 (goto-char (point-max))
878 (while (and (not (bobp))
879 (looking-at "^[ \t]*$"))
884 (defun article-display-x-face (&optional force)
885 "Look for an X-Face header and display it if present."
886 (interactive (list 'force))
888 ;; Delete the old process, if any.
889 (when (process-status "article-x-face")
890 (delete-process "article-x-face"))
891 (let ((inhibit-point-motion-hooks t)
895 (nnheader-narrow-to-headers)
896 (setq from (message-fetch-field "from"))
897 (goto-char (point-min))
898 (while (and gnus-article-x-face-command
900 ;; Check whether this face is censored.
901 (not gnus-article-x-face-too-ugly)
902 (and gnus-article-x-face-too-ugly from
903 (not (string-match gnus-article-x-face-too-ugly
905 ;; Has to be present.
906 (re-search-forward "^X-Face: " nil t))
907 ;; We now have the area of the buffer where the X-Face is stored.
910 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
911 ;; We display the face.
912 (if (symbolp gnus-article-x-face-command)
913 ;; The command is a lisp function, so we call it.
914 (if (gnus-functionp gnus-article-x-face-command)
915 (funcall gnus-article-x-face-command beg end)
916 (error "%s is not a function" gnus-article-x-face-command))
917 ;; The command is a string, so we interpret the command
918 ;; as a, well, command, and fork it off.
919 (let ((process-connection-type nil))
920 (process-kill-without-query
922 "article-x-face" nil shell-file-name shell-command-switch
923 gnus-article-x-face-command))
924 (process-send-region "article-x-face" beg end)
925 (process-send-eof "article-x-face"))))))))))
927 (defun gnus-hack-decode-rfc1522 ()
928 "Emergency hack function for avoiding problems when decoding."
929 (let ((buffer-read-only nil))
930 (goto-char (point-min))
931 ;; Remove encoded TABs.
932 (while (search-forward "=09" nil t)
933 (replace-match " " t t))
934 ;; Remove encoded newlines.
935 (goto-char (point-min))
936 (while (search-forward "=10" nil t)
937 (replace-match " " t t))))
939 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
940 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
941 (defun article-decode-rfc1522 ()
942 "Hack to remove QP encoding from headers."
943 (let ((case-fold-search t)
944 (inhibit-point-motion-hooks t)
945 (buffer-read-only nil)
949 (goto-char (point-min))
950 (or (search-forward "\n\n" nil t) (point-max)))
951 (goto-char (point-min))
952 (while (re-search-forward
953 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
954 (setq string (match-string 1))
956 (narrow-to-region (match-beginning 0) (match-end 0))
957 (delete-region (point-min) (point-max))
959 (article-mime-decode-quoted-printable
960 (goto-char (point-min)) (point-max))
961 (subst-char-in-region (point-min) (point-max) ?_ ? )
962 (goto-char (point-max)))
963 (goto-char (point-min))))))
965 (defun article-de-quoted-unreadable (&optional force)
966 "Do a naive translation of a quoted-printable-encoded article.
967 This is in no way, shape or form meant as a replacement for real MIME
968 processing, but is simply a stop-gap measure until MIME support is
970 If FORCE, decode the article whether it is marked as quoted-printable
972 (interactive (list 'force))
974 (let ((case-fold-search t)
975 (buffer-read-only nil)
976 (type (gnus-fetch-field "content-transfer-encoding")))
977 (gnus-article-decode-rfc1522)
979 (and type (string-match "quoted-printable" (downcase type))))
980 (goto-char (point-min))
981 (search-forward "\n\n" nil 'move)
982 (article-mime-decode-quoted-printable (point) (point-max))))))
984 (defun article-mime-decode-quoted-printable-buffer ()
985 "Decode Quoted-Printable in the current buffer."
986 (article-mime-decode-quoted-printable (point-min) (point-max)))
988 (defun article-mime-decode-quoted-printable (from to)
989 "Decode Quoted-Printable in the region between FROM and TO."
992 (while (search-forward "=" to t)
993 (cond ((eq (following-char) ?\n)
996 ((looking-at "[0-9A-F][0-9A-F]")
997 (subst-char-in-region
998 (1- (point)) (point) ?=
999 (hexl-hex-string-to-integer
1000 (buffer-substring (point) (+ 2 (point)))))
1004 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
1006 (defun article-hide-pgp (&optional arg)
1007 "Toggle hiding of any PGP headers and signatures in the current article.
1008 If given a negative prefix, always show; if given a positive prefix,
1010 (interactive (gnus-article-hidden-arg))
1011 (unless (gnus-article-check-hidden-text 'pgp arg)
1013 (let ((inhibit-point-motion-hooks t)
1014 buffer-read-only beg end)
1016 (goto-char (point-min))
1017 ;; Hide the "header".
1018 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1019 (gnus-article-hide-text-type (1+ (match-beginning 0))
1022 ;; Hide the actual signature.
1023 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1024 (setq end (1+ (match-beginning 0)))
1025 (gnus-article-hide-text-type
1027 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1029 ;; Perhaps we shouldn't hide to the end of the buffer
1030 ;; if there is no end to the signature?
1033 ;; Hide "- " PGP quotation markers.
1035 (narrow-to-region beg end)
1036 (goto-char (point-min))
1037 (while (re-search-forward "^- " nil t)
1038 (gnus-article-hide-text-type
1039 (match-beginning 0) (match-end 0) 'pgp))
1041 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1043 (defun article-hide-pem (&optional arg)
1044 "Toggle hiding of any PEM headers and signatures in the current article.
1045 If given a negative prefix, always show; if given a positive prefix,
1047 (interactive (gnus-article-hidden-arg))
1048 (unless (gnus-article-check-hidden-text 'pem arg)
1050 (let (buffer-read-only end)
1052 (goto-char (point-min))
1053 ;; hide the horrendously ugly "header".
1054 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1057 (setq end (1+ (match-beginning 0)))
1058 (gnus-article-hide-text-type
1060 (if (search-forward "\n\n" nil t)
1064 ;; hide the trailer as well
1065 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1068 (gnus-article-hide-text-type
1069 (match-beginning 0) (match-end 0) 'pem))))))
1071 (defun article-hide-signature (&optional arg)
1072 "Hide the signature in the current article.
1073 If given a negative prefix, always show; if given a positive prefix,
1075 (interactive (gnus-article-hidden-arg))
1076 (unless (gnus-article-check-hidden-text 'signature arg)
1079 (let ((buffer-read-only nil))
1080 (when (gnus-article-narrow-to-signature)
1081 (gnus-article-hide-text-type
1082 (point-min) (point-max) 'signature)))))))
1084 (defun article-strip-leading-blank-lines ()
1085 "Remove all blank lines from the beginning of the article."
1088 (let ((inhibit-point-motion-hooks t)
1090 (goto-char (point-min))
1091 (when (search-forward "\n\n" nil t)
1092 (while (and (not (eobp))
1093 (looking-at "[ \t]*$"))
1094 (gnus-delete-line))))))
1096 (defun article-strip-multiple-blank-lines ()
1097 "Replace consecutive blank lines with one empty line."
1100 (let ((inhibit-point-motion-hooks t)
1102 ;; First make all blank lines empty.
1103 (goto-char (point-min))
1104 (search-forward "\n\n" nil t)
1105 (while (re-search-forward "^[ \t]+$" nil t)
1106 (replace-match "" nil t))
1107 ;; Then replace multiple empty lines with a single empty line.
1108 (goto-char (point-min))
1109 (search-forward "\n\n" nil t)
1110 (while (re-search-forward "\n\n\n+" nil t)
1111 (replace-match "\n\n" t t)))))
1113 (defun article-strip-leading-space ()
1114 "Remove all white space from the beginning of the lines in the article."
1117 (let ((inhibit-point-motion-hooks t)
1119 (goto-char (point-min))
1120 (search-forward "\n\n" nil t)
1121 (while (re-search-forward "^[ \t]+" nil t)
1122 (replace-match "" t t)))))
1124 (defun article-strip-blank-lines ()
1125 "Strip leading, trailing and multiple blank lines."
1127 (article-strip-leading-blank-lines)
1128 (article-remove-trailing-blank-lines)
1129 (article-strip-multiple-blank-lines))
1131 (defun article-strip-all-blank-lines ()
1132 "Strip all blank lines."
1135 (let ((inhibit-point-motion-hooks t)
1137 (goto-char (point-min))
1138 (search-forward "\n\n" nil t)
1139 (while (re-search-forward "^[ \t]*\n" nil t)
1140 (replace-match "" t t)))))
1142 (defvar mime::preview/content-list)
1143 (defvar mime::preview-content-info/point-min)
1144 (defun gnus-article-narrow-to-signature ()
1145 "Narrow to the signature; return t if a signature is found, else nil."
1147 (when (and (boundp 'mime::preview/content-list)
1148 mime::preview/content-list)
1149 ;; We have a MIMEish article, so we use the MIME data to narrow.
1150 (let ((pcinfo (car (last mime::preview/content-list))))
1153 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1156 (when (gnus-article-search-signature)
1158 ;; Check whether we have some limits to what we consider
1159 ;; to be a signature.
1160 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1161 (list gnus-signature-limit)))
1163 (while (setq limit (pop limits))
1164 (if (or (and (integerp limit)
1165 (< (- (point-max) (point)) limit))
1167 (< (count-lines (point) (point-max)) limit))
1168 (and (gnus-functionp limit)
1170 (and (stringp limit)
1171 (not (re-search-forward limit nil t))))
1172 () ; This limit did not succeed.
1176 (narrow-to-region (point) (point-max))
1179 (defun gnus-article-search-signature ()
1180 "Search the current buffer for the signature separator.
1181 Put point at the beginning of the signature separator."
1182 (let ((cur (point)))
1183 (goto-char (point-max))
1184 (if (if (stringp gnus-signature-separator)
1185 (re-search-backward gnus-signature-separator nil t)
1186 (let ((seps gnus-signature-separator))
1188 (not (re-search-backward (car seps) nil t)))
1196 (autoload 'w3-display "w3-parse")
1197 (autoload 'w3-do-setup "w3" "" t)
1198 (autoload 'w3-region "w3-display" "" t))
1200 (defun gnus-article-treat-html ()
1203 (let ((cbuf (current-buffer)))
1204 (set-buffer gnus-article-buffer)
1205 (let (buf buffer-read-only b e)
1207 (goto-char (point-min))
1209 (if (search-forward "\n\n" nil t)
1212 (setq e (point-max)))
1213 (nnheader-temp-write nil
1214 (insert-buffer-substring gnus-article-buffer b e)
1216 (save-window-excursion
1217 (w3-region (point-min) (point-max))
1218 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1220 (delete-region (point-min) (point-max))
1223 (goto-char (point-min))
1224 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1225 (set-buffer cbuf))))
1227 (defun gnus-article-hidden-arg ()
1228 "Return the current prefix arg as a number, or 0 if no prefix."
1229 (list (if current-prefix-arg
1230 (prefix-numeric-value current-prefix-arg)
1233 (defun gnus-article-check-hidden-text (type arg)
1234 "Return nil if hiding is necessary.
1235 Arg can be nil or a number. Nil and positive means hide, negative
1236 means show, 0 means toggle."
1240 (let ((hide (gnus-article-hidden-text-p type)))
1246 (gnus-article-show-hidden-text type))
1248 (if (eq hide 'hidden)
1249 (gnus-article-show-hidden-text type)
1252 (defun gnus-article-hidden-text-p (type)
1253 "Say whether the current buffer contains hidden text of type TYPE."
1254 (let ((start (point-min))
1255 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1257 (not (get-text-property pos 'invisible)))
1259 (text-property-any (1+ pos) (point-max) 'article-type type)))
1264 (defun gnus-article-show-hidden-text (type &optional hide)
1265 "Show all hidden text of type TYPE.
1266 If HIDE, hide the text instead."
1268 (let ((buffer-read-only nil)
1269 (inhibit-point-motion-hooks t)
1272 (while (setq beg (text-property-any end (point-max) 'article-type type))
1275 (text-property-not-all beg (point-max) 'article-type type)
1278 (gnus-article-hide-text beg end gnus-hidden-properties)
1279 (gnus-article-unhide-text beg end))
1283 (defconst article-time-units
1284 `((year . ,(* 365.25 24 60 60))
1285 (week . ,(* 7 24 60 60))
1286 (day . ,(* 24 60 60))
1290 "Mapping from time units to seconds.")
1292 (defun article-date-ut (&optional type highlight header)
1293 "Convert DATE date to universal time in the current article.
1294 If TYPE is `local', convert to local time; if it is `lapsed', output
1295 how much time has lapsed since DATE."
1296 (interactive (list 'ut t))
1297 (let* ((header (or header
1298 (mail-header-date gnus-current-headers)
1299 (message-fetch-field "date")
1301 (date (if (vectorp header) (mail-header-date header)
1303 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1304 (inhibit-point-motion-hooks t)
1305 bface eface newline)
1306 (when (and date (not (string= date "")))
1309 (nnheader-narrow-to-headers)
1310 (let ((buffer-read-only nil))
1311 ;; Delete any old Date headers.
1312 (if (re-search-forward date-regexp nil t)
1314 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1315 eface (get-text-property (1- (gnus-point-at-eol))
1317 (delete-region (progn (beginning-of-line) (point))
1318 (progn (end-of-line) (point)))
1319 (beginning-of-line))
1320 (goto-char (point-max))
1322 (insert (article-make-date-line date type))
1325 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1326 (put-text-property (match-beginning 1) (1+ (match-end 1))
1328 (put-text-property (match-beginning 2) (match-end 2)
1332 (insert "\n"))))))))
1334 (defun article-make-date-line (date type)
1335 "Return a DATE line of TYPE."
1337 ;; Convert to the local timezone. We have to slap a
1338 ;; `condition-case' round the calls to the timezone
1339 ;; functions since they aren't particularly resistant to
1342 (concat "Date: " (condition-case ()
1343 (timezone-make-date-arpa-standard date)
1345 ;; Convert to Universal Time.
1349 (timezone-make-date-arpa-standard date nil "UT")
1351 ;; Get the original date from the article.
1352 ((eq type 'original)
1353 (concat "Date: " date))
1354 ;; Let the user define the format.
1356 (if (gnus-functionp gnus-article-time-format)
1358 gnus-article-time-format
1361 (timezone-make-date-arpa-standard
1365 (format-time-string gnus-article-time-format
1368 (timezone-make-date-arpa-standard
1369 date nil "UT")))))))
1374 (format-time-string "%Y%M%DT%h%m%s"
1377 (timezone-make-date-arpa-standard
1379 ;; Do an X-Sent lapsed format.
1381 ;; If the date is seriously mangled, the timezone functions are
1382 ;; liable to bug out, so we ignore all errors.
1383 (let* ((now (current-time))
1388 (timezone-make-date-arpa-standard
1389 (current-time-string now)
1390 (current-time-zone now) "UT"))
1392 (timezone-make-date-arpa-standard
1394 (real-sec (and real-time
1395 (+ (* (float (car real-time)) 65536)
1397 (sec (and real-time (abs real-sec)))
1407 ;; This is a bit convoluted, but basically we go
1408 ;; through the time units for years, weeks, etc,
1409 ;; and divide things to see whether that results
1410 ;; in positive answers.
1413 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1414 ;; The (remaining) seconds are too few to
1415 ;; be divided into this time unit.
1417 ;; It's big enough, so we output it.
1418 (setq sec (- sec (* num (cdr unit))))
1420 (concat (if prev ", " "") (int-to-string
1422 " " (symbol-name (car unit))
1423 (if (> num 1) "s" ""))
1425 article-time-units "")
1426 ;; If dates are odd, then it might appear like the
1427 ;; article was sent in the future.
1430 " in the future"))))))
1432 (error "Unknown conversion type: %s" type))))
1434 (defun article-date-local (&optional highlight)
1435 "Convert the current article date to the local timezone."
1436 (interactive (list t))
1437 (article-date-ut 'local highlight))
1439 (defun article-date-original (&optional highlight)
1440 "Convert the current article date to what it was originally.
1441 This is only useful if you have used some other date conversion
1442 function and want to see what the date was before converting."
1443 (interactive (list t))
1444 (article-date-ut 'original highlight))
1446 (defun article-date-lapsed (&optional highlight)
1447 "Convert the current article date to time lapsed since it was sent."
1448 (interactive (list t))
1449 (article-date-ut 'lapsed highlight))
1451 (defun article-update-date-lapsed ()
1452 "Function to be run from a timer to update the lapsed time line."
1453 (let (deactivate-mark)
1456 (when (gnus-buffer-live-p gnus-article-buffer)
1457 (set-buffer gnus-article-buffer)
1458 (goto-char (point-min))
1459 (when (re-search-forward "^X-Sent:" nil t)
1460 (article-date-lapsed t)))))))
1462 (defun gnus-start-date-timer (&optional n)
1463 "Start a timer to update the X-Sent header in the article buffers.
1464 The numerical prefix says how frequently (in seconds) the function
1469 (gnus-stop-date-timer)
1470 (setq article-lapsed-timer
1471 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1473 (defun gnus-stop-date-timer ()
1474 "Stop the X-Sent timer."
1476 (when article-lapsed-timer
1477 (nnheader-cancel-timer article-lapsed-timer)
1478 (setq article-lapsed-timer nil)))
1480 (defun article-date-user (&optional highlight)
1481 "Convert the current article date to the user-defined format.
1482 This format is defined by the `gnus-article-time-format' variable."
1483 (interactive (list t))
1484 (article-date-ut 'user highlight))
1486 (defun article-date-iso8601 (&optional highlight)
1487 "Convert the current article date to ISO8601."
1488 (interactive (list t))
1489 (article-date-ut 'iso8601 highlight))
1491 (defun article-show-all ()
1492 "Show all hidden text in the article buffer."
1495 (let ((buffer-read-only nil))
1496 (gnus-article-unhide-text (point-min) (point-max)))))
1498 (defun article-emphasize (&optional arg)
1499 "Emphasize text according to `gnus-emphasis-alist'."
1500 (interactive (gnus-article-hidden-arg))
1501 (unless (gnus-article-check-hidden-text 'emphasis arg)
1503 (let ((alist gnus-emphasis-alist)
1504 (buffer-read-only nil)
1505 (props (append '(article-type emphasis)
1506 gnus-hidden-properties))
1507 regexp elem beg invisible visible face)
1508 (goto-char (point-min))
1509 (search-forward "\n\n" nil t)
1511 (while (setq elem (pop alist))
1513 (setq regexp (car elem)
1514 invisible (nth 1 elem)
1515 visible (nth 2 elem)
1517 (while (re-search-forward regexp nil t)
1518 (when (and (match-beginning visible) (match-beginning invisible))
1519 (gnus-article-hide-text
1520 (match-beginning invisible) (match-end invisible) props)
1521 (gnus-article-unhide-text-type
1522 (match-beginning visible) (match-end visible) 'emphasis)
1523 (gnus-put-text-property-excluding-newlines
1524 (match-beginning visible) (match-end visible) 'face face)
1525 (goto-char (match-end invisible)))))))))
1527 (defvar gnus-summary-article-menu)
1528 (defvar gnus-summary-post-menu)
1530 ;;; Saving functions.
1532 (defun gnus-article-save (save-buffer file &optional num)
1533 "Save the currently selected article."
1534 (unless gnus-save-all-headers
1535 ;; Remove headers according to `gnus-saved-headers'.
1536 (let ((gnus-visible-headers
1537 (or gnus-saved-headers gnus-visible-headers))
1538 (gnus-article-buffer save-buffer))
1540 (set-buffer save-buffer)
1541 (article-hide-headers 1 t))))
1542 (save-window-excursion
1543 (if (not gnus-default-article-saver)
1544 (error "No default saver is defined")
1545 ;; !!! Magic! The saving functions all save
1546 ;; `gnus-original-article-buffer' (or so they think), but we
1547 ;; bind that variable to our save-buffer.
1548 (set-buffer gnus-article-buffer)
1549 (let* ((gnus-save-article-buffer save-buffer)
1552 ((not gnus-prompt-before-saving) 'default)
1553 ((eq gnus-prompt-before-saving 'always) nil)
1555 (gnus-number-of-articles-to-be-saved
1556 (when (eq gnus-prompt-before-saving t)
1558 (set-buffer gnus-article-current-summary)
1559 (funcall gnus-default-article-saver filename)))))
1561 (defun gnus-read-save-file-name (prompt &optional filename
1562 function group headers variable)
1564 (funcall function group headers (symbol-value variable)))
1569 ((eq filename 'default)
1575 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1578 (if (and gnus-number-of-articles-to-be-saved
1579 (> gnus-number-of-articles-to-be-saved 1))
1580 (format "these %d articles"
1581 gnus-number-of-articles-to-be-saved)
1584 ;; Let the split methods have their say.
1586 ;; No split name was found.
1589 (concat prompt " (default "
1590 (file-name-nondirectory default-name) ") ")
1591 (file-name-directory default-name)
1593 ;; A single group name is returned.
1594 ((stringp split-name)
1596 (funcall function split-name headers
1597 (symbol-value variable)))
1599 (concat prompt " (default "
1600 (file-name-nondirectory default-name) ") ")
1601 (file-name-directory default-name)
1603 ;; A single split name was found
1604 ((= 1 (length split-name))
1605 (let* ((name (expand-file-name
1606 (car split-name) gnus-article-save-directory))
1607 (dir (cond ((file-directory-p name)
1608 (file-name-as-directory name))
1609 ((file-exists-p name) name)
1610 (t gnus-article-save-directory))))
1612 (concat prompt " (default " name ") ")
1614 ;; A list of splits was found.
1616 (setq split-name (nreverse split-name))
1618 (let ((file-name-history
1619 (nconc split-name file-name-history)))
1623 (concat prompt " (`M-p' for defaults) ")
1624 gnus-article-save-directory
1626 gnus-article-save-directory)))
1627 (car (push result file-name-history)))))))
1628 ;; Create the directory.
1629 (gnus-make-directory (file-name-directory file))
1630 ;; If we have read a directory, we append the default file name.
1631 (when (file-directory-p file)
1632 (setq file (concat (file-name-as-directory file)
1633 (file-name-nondirectory default-name))))
1634 ;; Possibly translate some characters.
1635 (nnheader-translate-file-chars file)))))
1636 (gnus-make-directory (file-name-directory result))
1637 (set variable result)))
1639 (defun gnus-article-archive-name (group)
1640 "Return the first instance of an \"Archive-name\" in the current buffer."
1641 (let ((case-fold-search t))
1642 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1643 (nnheader-concat gnus-article-save-directory
1644 (match-string 1)))))
1646 (defun gnus-article-nndoc-name (group)
1647 "If GROUP is an nndoc group, return the name of the parent group."
1648 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1649 (gnus-group-get-parameter group 'save-article-group)))
1651 (defun gnus-summary-save-in-rmail (&optional filename)
1652 "Append this article to Rmail file.
1653 Optional argument FILENAME specifies file name.
1654 Directory to save to is default to `gnus-article-save-directory'."
1655 (setq filename (gnus-read-save-file-name
1656 "Save %s in rmail file:" filename
1657 gnus-rmail-save-name gnus-newsgroup-name
1658 gnus-current-headers 'gnus-newsgroup-last-rmail))
1659 (gnus-eval-in-buffer-window gnus-save-article-buffer
1663 (gnus-output-to-rmail filename))))
1666 (defun gnus-summary-save-in-mail (&optional filename)
1667 "Append this article to Unix mail file.
1668 Optional argument FILENAME specifies file name.
1669 Directory to save to is default to `gnus-article-save-directory'."
1670 (setq filename (gnus-read-save-file-name
1671 "Save %s in Unix mail file:" filename
1672 gnus-mail-save-name gnus-newsgroup-name
1673 gnus-current-headers 'gnus-newsgroup-last-mail))
1674 (gnus-eval-in-buffer-window gnus-save-article-buffer
1678 (if (and (file-readable-p filename)
1679 (mail-file-babyl-p filename))
1680 (gnus-output-to-rmail filename t)
1681 (gnus-output-to-mail filename)))))
1684 (defun gnus-summary-save-in-file (&optional filename overwrite)
1685 "Append this article to file.
1686 Optional argument FILENAME specifies file name.
1687 Directory to save to is default to `gnus-article-save-directory'."
1688 (setq filename (gnus-read-save-file-name
1689 "Save %s in file:" filename
1690 gnus-file-save-name gnus-newsgroup-name
1691 gnus-current-headers 'gnus-newsgroup-last-file))
1692 (gnus-eval-in-buffer-window gnus-save-article-buffer
1696 (when (and overwrite
1697 (file-exists-p filename))
1698 (delete-file filename))
1699 (gnus-output-to-file filename))))
1702 (defun gnus-summary-write-to-file (&optional filename)
1703 "Write this article to a file.
1704 Optional argument FILENAME specifies file name.
1705 The directory to save in defaults to `gnus-article-save-directory'."
1706 (gnus-summary-save-in-file nil t))
1708 (defun gnus-summary-save-body-in-file (&optional filename)
1709 "Append this article body to a file.
1710 Optional argument FILENAME specifies file name.
1711 The directory to save in defaults to `gnus-article-save-directory'."
1712 (setq filename (gnus-read-save-file-name
1713 "Save %s body in file:" filename
1714 gnus-file-save-name gnus-newsgroup-name
1715 gnus-current-headers 'gnus-newsgroup-last-file))
1716 (gnus-eval-in-buffer-window gnus-save-article-buffer
1720 (goto-char (point-min))
1721 (when (search-forward "\n\n" nil t)
1722 (narrow-to-region (point) (point-max)))
1723 (gnus-output-to-file filename))))
1726 (defun gnus-summary-save-in-pipe (&optional command)
1727 "Pipe this article to subprocess."
1729 (cond ((eq command 'default)
1730 gnus-last-shell-command)
1734 "Shell command on %s: "
1735 (if (and gnus-number-of-articles-to-be-saved
1736 (> gnus-number-of-articles-to-be-saved 1))
1737 (format "these %d articles"
1738 gnus-number-of-articles-to-be-saved)
1740 gnus-last-shell-command))))
1741 (when (string-equal command "")
1742 (setq command gnus-last-shell-command))
1743 (gnus-eval-in-buffer-window gnus-article-buffer
1746 (shell-command-on-region (point-min) (point-max) command nil)))
1747 (setq gnus-last-shell-command command))
1749 ;;; Article file names when saving.
1751 (defun gnus-capitalize-newsgroup (newsgroup)
1752 "Capitalize NEWSGROUP name."
1753 (when (not (zerop (length newsgroup)))
1754 (concat (char-to-string (upcase (aref newsgroup 0)))
1755 (substring newsgroup 1))))
1757 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1758 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1759 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1760 Otherwise, it is like ~/News/news/group/num."
1763 (concat (if (gnus-use-long-file-name 'not-save)
1764 (gnus-capitalize-newsgroup newsgroup)
1765 (gnus-newsgroup-directory-form newsgroup))
1766 "/" (int-to-string (mail-header-number headers)))
1767 gnus-article-save-directory)))
1769 (string-equal (file-name-directory default)
1770 (file-name-directory last-file))
1771 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1773 (or last-file default))))
1775 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1776 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1777 If variable `gnus-use-long-file-name' is non-nil, it is
1778 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1781 (concat (if (gnus-use-long-file-name 'not-save)
1783 (gnus-newsgroup-directory-form newsgroup))
1784 "/" (int-to-string (mail-header-number headers)))
1785 gnus-article-save-directory)))
1787 (string-equal (file-name-directory default)
1788 (file-name-directory last-file))
1789 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1791 (or last-file default))))
1793 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1794 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1795 If variable `gnus-use-long-file-name' is non-nil, it is
1796 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1799 (if (gnus-use-long-file-name 'not-save)
1800 (gnus-capitalize-newsgroup newsgroup)
1801 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1802 gnus-article-save-directory)))
1804 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1805 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1806 If variable `gnus-use-long-file-name' is non-nil, it is
1807 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1810 (if (gnus-use-long-file-name 'not-save)
1812 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1813 gnus-article-save-directory)))
1820 (setq afunc (car func)
1823 gfunc (intern (format "gnus-%s" func))))
1825 (if (not (fboundp afunc))
1827 `(lambda (&optional interactive &rest args)
1828 ,(documentation afunc t)
1829 (interactive (list t))
1831 (set-buffer gnus-article-buffer)
1833 (call-interactively ',afunc)
1834 (apply ',afunc args))))))))
1835 '(article-hide-headers
1836 article-hide-boring-headers
1837 article-treat-overstrike
1838 (article-fill . gnus-article-word-wrap)
1840 article-display-x-face
1841 article-de-quoted-unreadable
1842 article-mime-decode-quoted-printable
1845 article-hide-signature
1846 article-remove-trailing-blank-lines
1847 article-strip-leading-blank-lines
1848 article-strip-multiple-blank-lines
1849 article-strip-leading-space
1850 article-strip-blank-lines
1851 article-strip-all-blank-lines
1853 article-date-iso8601
1854 article-date-original
1859 article-treat-dumbquotes
1860 (article-show-all . gnus-article-show-all-headers))))
1863 ;;; Gnus article mode
1866 (put 'gnus-article-mode 'mode-class 'special)
1868 (gnus-define-keys gnus-article-mode-map
1869 " " gnus-article-goto-next-page
1870 "\177" gnus-article-goto-prev-page
1871 [delete] gnus-article-goto-prev-page
1872 "\C-c^" gnus-article-refer-article
1873 "h" gnus-article-show-summary
1874 "s" gnus-article-show-summary
1875 "\C-c\C-m" gnus-article-mail
1876 "?" gnus-article-describe-briefly
1877 gnus-mouse-2 gnus-article-push-button
1878 "\r" gnus-article-press-button
1879 "\t" gnus-article-next-button
1880 "\M-\t" gnus-article-prev-button
1881 "e" gnus-article-edit
1882 "<" beginning-of-buffer
1884 "\C-c\C-i" gnus-info-find-node
1887 "\C-d" gnus-article-read-summary-keys
1888 "\M-*" gnus-article-read-summary-keys
1889 "\M-#" gnus-article-read-summary-keys
1890 "\M-^" gnus-article-read-summary-keys
1891 "\M-g" gnus-article-read-summary-keys)
1893 (substitute-key-definition
1894 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1896 (defun gnus-article-make-menu-bar ()
1897 (gnus-turn-off-edit-menu 'article)
1898 (unless (boundp 'gnus-article-article-menu)
1900 gnus-article-article-menu gnus-article-mode-map ""
1902 ["Scroll forwards" gnus-article-goto-next-page t]
1903 ["Scroll backwards" gnus-article-goto-prev-page t]
1904 ["Show summary" gnus-article-show-summary t]
1905 ["Fetch Message-ID at point" gnus-article-refer-article t]
1906 ["Mail to address at point" gnus-article-mail t]
1907 ["Send a bug report" gnus-bug t]))
1910 gnus-article-treatment-menu gnus-article-mode-map ""
1912 ["Hide headers" gnus-article-hide-headers t]
1913 ["Hide signature" gnus-article-hide-signature t]
1914 ["Hide citation" gnus-article-hide-citation t]
1915 ["Treat overstrike" gnus-article-treat-overstrike t]
1916 ["Remove carriage return" gnus-article-remove-cr t]
1917 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1919 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1921 (when (boundp 'gnus-summary-post-menu)
1922 (define-key gnus-article-mode-map [menu-bar post]
1923 (cons "Post" gnus-summary-post-menu)))
1925 (gnus-run-hooks 'gnus-article-menu-hook)))
1927 (defun gnus-article-mode ()
1928 "Major mode for displaying an article.
1930 All normal editing commands are switched off.
1932 The following commands are available in addition to all summary mode
1934 \\<gnus-article-mode-map>
1935 \\[gnus-article-next-page]\t Scroll the article one page forwards
1936 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1937 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1938 \\[gnus-article-show-summary]\t Display the summary buffer
1939 \\[gnus-article-mail]\t Send a reply to the address near point
1940 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1941 \\[gnus-info-find-node]\t Go to the Gnus info node"
1943 (when (gnus-visual-p 'article-menu 'menu)
1944 (gnus-article-make-menu-bar))
1945 (gnus-simplify-mode-line)
1946 (setq mode-name "Article")
1947 (setq major-mode 'gnus-article-mode)
1948 (make-local-variable 'minor-mode-alist)
1949 (unless (assq 'gnus-show-mime minor-mode-alist)
1950 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1951 (use-local-map gnus-article-mode-map)
1952 (gnus-update-format-specifications nil 'article-mode)
1953 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1954 (make-local-variable 'gnus-page-broken)
1955 (make-local-variable 'gnus-button-marker-list)
1956 (make-local-variable 'gnus-article-current-summary)
1957 (gnus-set-default-directory)
1958 (buffer-disable-undo (current-buffer))
1959 (setq buffer-read-only t)
1960 (set-syntax-table gnus-article-mode-syntax-table)
1961 (gnus-run-hooks 'gnus-article-mode-hook))
1963 (defun gnus-article-setup-buffer ()
1964 "Initialize the article buffer."
1965 (let* ((name (if gnus-single-article-buffer "*Article*"
1966 (concat "*Article " gnus-newsgroup-name "*")))
1968 (progn (string-match "\\*Article" name)
1969 (concat " *Original Article"
1970 (substring name (match-end 0))))))
1971 (setq gnus-article-buffer name)
1972 (setq gnus-original-article-buffer original)
1973 ;; This might be a variable local to the summary buffer.
1974 (unless gnus-single-article-buffer
1976 (set-buffer gnus-summary-buffer)
1977 (setq gnus-article-buffer name)
1978 (setq gnus-original-article-buffer original)
1979 (gnus-set-global-variables)))
1980 ;; Init original article buffer.
1982 (set-buffer (get-buffer-create gnus-original-article-buffer))
1983 (buffer-disable-undo (current-buffer))
1984 (setq major-mode 'gnus-original-article-mode)
1985 (gnus-add-current-to-buffer-list)
1986 (make-local-variable 'gnus-original-article))
1987 (if (get-buffer name)
1990 (buffer-disable-undo (current-buffer))
1991 (setq buffer-read-only t)
1992 (gnus-add-current-to-buffer-list)
1993 (unless (eq major-mode 'gnus-article-mode)
1994 (gnus-article-mode))
1997 (set-buffer (get-buffer-create name))
1998 (gnus-add-current-to-buffer-list)
2000 (make-local-variable 'gnus-summary-buffer)
2001 (current-buffer)))))
2003 ;; Set article window start at LINE, where LINE is the number of lines
2004 ;; from the head of the article.
2005 (defun gnus-article-set-window-start (&optional line)
2007 (get-buffer-window gnus-article-buffer t)
2009 (set-buffer gnus-article-buffer)
2010 (goto-char (point-min))
2013 (gnus-message 6 "Moved to bookmark")
2014 (search-forward "\n\n" nil t)
2018 (defun gnus-article-prepare (article &optional all-headers header)
2019 "Prepare ARTICLE in article mode buffer.
2020 ARTICLE should either be an article number or a Message-ID.
2021 If ARTICLE is an id, HEADER should be the article headers.
2022 If ALL-HEADERS is non-nil, no headers are hidden."
2024 ;; Make sure we start in a summary buffer.
2025 (unless (eq major-mode 'gnus-summary-mode)
2026 (set-buffer gnus-summary-buffer))
2027 (setq gnus-summary-buffer (current-buffer))
2028 (let* ((gnus-article (if header (mail-header-number header) article))
2029 (summary-buffer (current-buffer))
2030 (internal-hook gnus-article-internal-prepare-hook)
2031 (group gnus-newsgroup-name)
2034 (gnus-article-setup-buffer)
2035 (set-buffer gnus-article-buffer)
2036 ;; Deactivate active regions.
2037 (when (and (boundp 'transient-mark-mode)
2038 transient-mark-mode)
2039 (setq mark-active nil))
2040 (if (not (setq result (let ((buffer-read-only nil))
2041 (gnus-request-article-this-buffer
2043 ;; There is no such article.
2045 (when (and (numberp article)
2046 (not (memq article gnus-newsgroup-sparse)))
2047 (setq gnus-article-current
2048 (cons gnus-newsgroup-name article))
2049 (set-buffer gnus-summary-buffer)
2050 (setq gnus-current-article article)
2051 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2053 (gnus-summary-set-agent-mark article)
2054 (message "Message marked for downloading"))
2055 (gnus-summary-mark-article article gnus-canceled-mark)
2056 (unless (memq article gnus-newsgroup-sparse)
2058 "No such article (may have expired or been canceled)")))))
2059 (if (or (eq result 'pseudo) (eq result 'nneething))
2062 (set-buffer summary-buffer)
2063 (push article gnus-newsgroup-history)
2064 (setq gnus-last-article gnus-current-article
2065 gnus-current-article 0
2066 gnus-current-headers nil
2067 gnus-article-current nil)
2068 (if (eq result 'nneething)
2069 (gnus-configure-windows 'summary)
2070 (gnus-configure-windows 'article))
2071 (gnus-set-global-variables))
2072 (gnus-set-mode-line 'article))
2073 ;; The result from the `request' was an actual article -
2074 ;; or at least some text that is now displayed in the
2076 (when (and (numberp article)
2077 (not (eq article gnus-current-article)))
2078 ;; Seems like a new article has been selected.
2079 ;; `gnus-current-article' must be an article number.
2081 (set-buffer summary-buffer)
2082 (push article gnus-newsgroup-history)
2083 (setq gnus-last-article gnus-current-article
2084 gnus-current-article article
2085 gnus-current-headers
2086 (gnus-summary-article-header gnus-current-article)
2087 gnus-article-current
2088 (cons gnus-newsgroup-name gnus-current-article))
2089 (unless (vectorp gnus-current-headers)
2090 (setq gnus-current-headers nil))
2091 (gnus-summary-goto-subject gnus-current-article)
2092 (when (gnus-summary-show-thread)
2093 ;; If the summary buffer really was folded, the
2094 ;; previous goto may not actually have gone to
2095 ;; the right article, but the thread root instead.
2097 (gnus-summary-goto-subject gnus-current-article))
2098 (gnus-run-hooks 'gnus-mark-article-hook)
2099 (gnus-set-mode-line 'summary)
2100 (when (gnus-visual-p 'article-highlight 'highlight)
2101 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2102 ;; Set the global newsgroup variables here.
2103 ;; Suggested by Jim Sisolak
2104 ;; <sisolak@trans4.neep.wisc.edu>.
2105 (gnus-set-global-variables)
2106 (setq gnus-have-all-headers
2107 (or all-headers gnus-show-all-headers))))
2108 (when (or (numberp article)
2110 ;; Hooks for getting information from the article.
2111 ;; This hook must be called before being narrowed.
2112 (let (buffer-read-only)
2113 (gnus-run-hooks 'internal-hook)
2114 (gnus-run-hooks 'gnus-article-prepare-hook)
2115 ;; Decode MIME message.
2116 (when gnus-show-mime
2117 (if (or (not gnus-strict-mime)
2118 (gnus-fetch-field "Mime-Version"))
2119 (let ((coding-system-for-write 'binary)
2120 (coding-system-for-read 'binary))
2121 (funcall gnus-show-mime-method))
2122 (funcall gnus-decode-encoded-word-method)))
2123 ;; Perform the article display hooks.
2124 (gnus-run-hooks 'gnus-article-display-hook))
2126 (goto-char (point-min))
2127 (setq gnus-page-broken
2128 (when gnus-break-pages
2129 (gnus-narrow-to-page)
2131 (gnus-set-mode-line 'article)
2132 (gnus-configure-windows 'article)
2133 (goto-char (point-min))
2136 (defun gnus-article-wash-status ()
2137 "Return a string which display status of article washing."
2139 (set-buffer gnus-article-buffer)
2140 (let ((cite (gnus-article-hidden-text-p 'cite))
2141 (headers (gnus-article-hidden-text-p 'headers))
2142 (boring (gnus-article-hidden-text-p 'boring-headers))
2143 (pgp (gnus-article-hidden-text-p 'pgp))
2144 (pem (gnus-article-hidden-text-p 'pem))
2145 (signature (gnus-article-hidden-text-p 'signature))
2146 (overstrike (gnus-article-hidden-text-p 'overstrike))
2147 (emphasis (gnus-article-hidden-text-p 'emphasis))
2148 (mime gnus-show-mime))
2149 (format "%c%c%c%c%c%c%c"
2151 (if (or headers boring) ?h ? )
2152 (if (or pgp pem) ?p ? )
2153 (if signature ?s ? )
2154 (if overstrike ?o ? )
2156 (if emphasis ?e ? )))))
2158 (defun gnus-article-hide-headers-if-wanted ()
2159 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2160 Provided for backwards compatibility."
2161 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2163 (gnus-article-hide-headers)))
2167 (defun gnus-output-to-file (file-name)
2168 "Append the current article to a file named FILE-NAME."
2169 (let ((artbuf (current-buffer)))
2170 (nnheader-temp-write nil
2171 (insert-buffer-substring artbuf)
2172 ;; Append newline at end of the buffer as separator, and then
2174 (goto-char (point-max))
2176 (append-to-file (point-min) (point-max) file-name)
2179 (defun gnus-narrow-to-page (&optional arg)
2180 "Narrow the article buffer to a page.
2181 If given a numerical ARG, move forward ARG pages."
2183 (setq arg (if arg (prefix-numeric-value arg) 0))
2185 (set-buffer gnus-article-buffer)
2186 (goto-char (point-min))
2188 ;; Remove any old next/prev buttons.
2189 (when (gnus-visual-p 'page-marker)
2190 (let ((buffer-read-only nil))
2191 (gnus-remove-text-with-property 'gnus-prev)
2192 (gnus-remove-text-with-property 'gnus-next)))
2195 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2197 (re-search-forward page-delimiter nil 'move arg)))
2198 (goto-char (match-end 0)))
2201 (if (re-search-forward page-delimiter nil 'move)
2204 (when (and (gnus-visual-p 'page-marker)
2205 (not (= (point-min) 1)))
2207 (goto-char (point-min))
2208 (gnus-insert-prev-page-button)))
2209 (when (and (gnus-visual-p 'page-marker)
2210 (< (+ (point-max) 2) (buffer-size)))
2212 (goto-char (point-max))
2213 (gnus-insert-next-page-button)))))
2215 ;; Article mode commands
2217 (defun gnus-article-goto-next-page ()
2218 "Show the next page of the article."
2220 (when (gnus-article-next-page)
2221 (goto-char (point-min))
2222 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2224 (defun gnus-article-goto-prev-page ()
2225 "Show the next page of the article."
2227 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2228 (gnus-article-prev-page nil)))
2230 (defun gnus-article-next-page (&optional lines)
2231 "Show the next page of the current article.
2232 If end of article, return non-nil. Otherwise return nil.
2233 Argument LINES specifies lines to be scrolled up."
2235 (move-to-window-line -1)
2238 (and (pos-visible-in-window-p) ;Not continuation line.
2240 ;; Nothing in this page.
2241 (if (or (not gnus-page-broken)
2244 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2246 (gnus-narrow-to-page 1) ;Go to next page.
2248 ;; More in this page.
2249 (let ((scroll-in-place nil))
2253 ;; Long lines may cause an end-of-buffer error.
2254 (goto-char (point-max)))))
2255 (move-to-window-line 0)
2258 (defun gnus-article-prev-page (&optional lines)
2259 "Show previous page of current article.
2260 Argument LINES specifies lines to be scrolled down."
2262 (move-to-window-line 0)
2263 (if (and gnus-page-broken
2265 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2267 (gnus-narrow-to-page -1) ;Go to previous page.
2268 (goto-char (point-max))
2270 (let ((scroll-in-place nil))
2274 (beginning-of-buffer
2275 (goto-char (point-min))))
2276 (move-to-window-line 0)))))
2278 (defun gnus-article-refer-article ()
2279 "Read article specified by message-id around point."
2281 (let ((point (point)))
2282 (search-forward ">" nil t) ;Move point to end of "<....>".
2283 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2284 (let ((message-id (match-string 1)))
2286 (set-buffer gnus-summary-buffer)
2287 (gnus-summary-refer-article message-id))
2289 (error "No references around point"))))
2291 (defun gnus-article-show-summary ()
2292 "Reconfigure windows to show summary buffer."
2294 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2295 (error "There is no summary buffer for this article buffer")
2296 (gnus-article-set-globals)
2297 (gnus-configure-windows 'article)
2298 (gnus-summary-goto-subject gnus-current-article)
2299 (gnus-summary-position-point)))
2301 (defun gnus-article-describe-briefly ()
2302 "Describe article mode commands briefly."
2305 (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")))
2307 (defun gnus-article-summary-command ()
2308 "Execute the last keystroke in the summary buffer."
2310 (let ((obuf (current-buffer))
2311 (owin (current-window-configuration))
2313 (switch-to-buffer gnus-article-current-summary 'norecord)
2314 (setq func (lookup-key (current-local-map) (this-command-keys)))
2315 (call-interactively func)
2317 (set-window-configuration owin)
2318 (set-window-point (get-buffer-window (current-buffer)) (point))))
2320 (defun gnus-article-summary-command-nosave ()
2321 "Execute the last keystroke in the summary buffer."
2324 (pop-to-buffer gnus-article-current-summary 'norecord)
2325 (setq func (lookup-key (current-local-map) (this-command-keys)))
2326 (call-interactively func)))
2328 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2329 "Read a summary buffer key sequence and execute it from the article buffer."
2332 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2333 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2334 "=" "^" "\M-^" "|"))
2340 '("n" "Gn" "p" "Gp"))
2343 (set-buffer gnus-article-current-summary)
2344 (let (gnus-pick-mode)
2345 (push (or key last-command-event) unread-command-events)
2346 (setq keys (read-key-sequence nil))))
2349 (if (or (member keys nosaves)
2350 (member keys nosave-but-article)
2351 (member keys nosave-in-article))
2353 (save-window-excursion
2354 (pop-to-buffer gnus-article-current-summary 'norecord)
2355 ;; We disable the pick minor mode commands.
2356 (let (gnus-pick-mode)
2357 (setq func (lookup-key (current-local-map) keys))))
2360 (unless (member keys nosave-in-article)
2361 (set-buffer gnus-article-current-summary))
2362 (call-interactively func)
2363 (setq new-sum-point (point)))
2364 (when (member keys nosave-but-article)
2365 (pop-to-buffer gnus-article-buffer 'norecord)))
2366 ;; These commands should restore window configuration.
2367 (let ((obuf (current-buffer))
2368 (owin (current-window-configuration))
2370 (summary gnus-article-current-summary)
2371 func in-buffer selected)
2372 (if not-restore-window
2373 (pop-to-buffer summary 'norecord)
2374 (switch-to-buffer summary 'norecord))
2375 (setq in-buffer (current-buffer))
2376 ;; We disable the pick minor mode commands.
2377 (if (setq func (let (gnus-pick-mode)
2378 (lookup-key (current-local-map) keys)))
2380 (call-interactively func)
2381 (setq new-sum-point (point)))
2383 (when (eq in-buffer (current-buffer))
2384 (setq selected (gnus-summary-select-article))
2386 (unless not-restore-window
2387 (set-window-configuration owin))
2388 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2389 (set-window-point (get-buffer-window (current-buffer))
2391 (let ((win (get-buffer-window gnus-article-current-summary)))
2393 (set-window-point win new-sum-point))))))))
2395 (defun gnus-article-hide (&optional arg force)
2396 "Hide all the gruft in the current article.
2397 This means that PGP stuff, signatures, cited text and (some)
2398 headers will be hidden.
2399 If given a prefix, show the hidden text instead."
2400 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2401 (gnus-article-hide-headers arg)
2402 (gnus-article-hide-pgp arg)
2403 (gnus-article-hide-citation-maybe arg force)
2404 (gnus-article-hide-signature arg))
2406 (defun gnus-article-maybe-highlight ()
2407 "Do some article highlighting if article highlighting is requested."
2408 (when (gnus-visual-p 'article-highlight 'highlight)
2409 (gnus-article-highlight-some)))
2411 (defun gnus-check-group-server ()
2412 ;; Make sure the connection to the server is alive.
2413 (unless (gnus-server-opened
2414 (gnus-find-method-for-group gnus-newsgroup-name))
2415 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2416 (gnus-request-group gnus-newsgroup-name t)))
2418 (defun gnus-request-article-this-buffer (article group)
2419 "Get an article and insert it into this buffer."
2420 (let (do-update-line sparse-header)
2424 (gnus-kill-all-overlays)
2425 (setq group (or group gnus-newsgroup-name))
2427 ;; Using `gnus-request-article' directly will insert the article into
2428 ;; `nntp-server-buffer' - so we'll save some time by not having to
2429 ;; copy it from the server buffer into the article buffer.
2431 ;; We only request an article by message-id when we do not have the
2432 ;; headers for it, so we'll have to get those.
2433 (when (stringp article)
2434 (let ((gnus-override-method gnus-refer-article-method))
2435 (gnus-read-header article)))
2437 ;; If the article number is negative, that means that this article
2438 ;; doesn't belong in this newsgroup (possibly), so we find its
2439 ;; message-id and request it by id instead of number.
2440 (when (and (numberp article)
2442 (get-buffer gnus-summary-buffer)
2443 (gnus-buffer-exists-p gnus-summary-buffer))
2445 (set-buffer gnus-summary-buffer)
2446 (let ((header (gnus-summary-article-header article)))
2449 ((memq article gnus-newsgroup-sparse)
2450 ;; This is a sparse gap article.
2451 (setq do-update-line article)
2452 (setq article (mail-header-id header))
2453 (let ((gnus-override-method gnus-refer-article-method))
2454 (setq sparse-header (gnus-read-header article)))
2455 (setq gnus-newsgroup-sparse
2456 (delq article gnus-newsgroup-sparse)))
2458 ;; It's a real article.
2459 (setq article (mail-header-id header)))
2461 ;; It is an extracted pseudo-article.
2462 (setq article 'pseudo)
2463 (gnus-request-pseudo-article header))))
2465 (let ((method (gnus-find-method-for-group
2466 gnus-newsgroup-name)))
2467 (when (and (eq (car method) 'nneething)
2469 (let ((dir (concat (file-name-as-directory (nth 1 method))
2470 (mail-header-subject header))))
2471 (when (file-directory-p dir)
2472 (setq article 'nneething)
2473 (gnus-group-enter-directory dir))))))))
2476 ;; Refuse to select canceled articles.
2477 ((and (numberp article)
2479 (get-buffer gnus-summary-buffer)
2480 (gnus-buffer-exists-p gnus-summary-buffer)
2481 (eq (cdr (save-excursion
2482 (set-buffer gnus-summary-buffer)
2483 (assq article gnus-newsgroup-reads)))
2484 gnus-canceled-mark))
2486 ;; We first check `gnus-original-article-buffer'.
2487 ((and (get-buffer gnus-original-article-buffer)
2490 (set-buffer gnus-original-article-buffer)
2491 (and (equal (car gnus-original-article) group)
2492 (eq (cdr gnus-original-article) article))))
2493 (insert-buffer-substring gnus-original-article-buffer)
2495 ;; Check the backlog.
2496 ((and gnus-keep-backlog
2497 (gnus-backlog-request-article group article (current-buffer)))
2499 ;; Check asynchronous pre-fetch.
2500 ((gnus-async-request-fetched-article group article (current-buffer))
2501 (gnus-async-prefetch-next group article gnus-summary-buffer)
2502 (when (and (numberp article) gnus-keep-backlog)
2503 (gnus-backlog-enter-article group article (current-buffer)))
2506 ((and gnus-use-cache
2508 (gnus-cache-request-article article group))
2510 ;; Get the article and put into the article buffer.
2511 ((or (stringp article) (numberp article))
2512 (let ((gnus-override-method
2513 (and (stringp article) gnus-refer-article-method))
2514 (buffer-read-only nil))
2516 (gnus-kill-all-overlays)
2517 (gnus-check-group-server)
2518 (when (gnus-request-article article group (current-buffer))
2519 (when (numberp article)
2520 (gnus-async-prefetch-next group article gnus-summary-buffer)
2521 (when gnus-keep-backlog
2522 (gnus-backlog-enter-article
2523 group article (current-buffer))))
2528 ;; Associate this article with the current summary buffer.
2529 (setq gnus-article-current-summary gnus-summary-buffer)
2531 ;; Take the article from the original article buffer
2532 ;; and place it in the buffer it's supposed to be in.
2533 (when (and (get-buffer gnus-article-buffer)
2534 (equal (buffer-name (current-buffer))
2535 (buffer-name (get-buffer gnus-article-buffer))))
2537 (if (get-buffer gnus-original-article-buffer)
2538 (set-buffer gnus-original-article-buffer)
2539 (set-buffer (get-buffer-create gnus-original-article-buffer))
2540 (buffer-disable-undo (current-buffer))
2541 (setq major-mode 'gnus-original-article-mode)
2542 (setq buffer-read-only t)
2543 (gnus-add-current-to-buffer-list))
2544 (let (buffer-read-only)
2546 (insert-buffer-substring gnus-article-buffer))
2547 (setq gnus-original-article (cons group article))))
2549 ;; Update sparse articles.
2550 (when (and do-update-line
2551 (or (numberp article)
2553 (let ((buf (current-buffer)))
2554 (set-buffer gnus-summary-buffer)
2555 (gnus-summary-update-article do-update-line sparse-header)
2556 (gnus-summary-goto-subject do-update-line nil t)
2557 (set-window-point (get-buffer-window (current-buffer) t)
2559 (set-buffer buf))))))
2565 (defcustom gnus-article-edit-mode-hook nil
2566 "Hook run in article edit mode buffers."
2567 :group 'gnus-article-various
2570 (defvar gnus-article-edit-done-function nil)
2572 (defvar gnus-article-edit-mode-map nil)
2574 (unless gnus-article-edit-mode-map
2575 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2577 (gnus-define-keys gnus-article-edit-mode-map
2578 "\C-c\C-c" gnus-article-edit-done
2579 "\C-c\C-k" gnus-article-edit-exit)
2581 (gnus-define-keys (gnus-article-edit-wash-map
2582 "\C-c\C-w" gnus-article-edit-mode-map)
2583 "f" gnus-article-edit-full-stops))
2585 (defun gnus-article-edit-mode ()
2586 "Major mode for editing articles.
2587 This is an extended text-mode.
2589 \\{gnus-article-edit-mode-map}"
2591 (setq major-mode 'gnus-article-edit-mode)
2592 (setq mode-name "Article Edit")
2593 (use-local-map gnus-article-edit-mode-map)
2594 (make-local-variable 'gnus-article-edit-done-function)
2595 (make-local-variable 'gnus-prev-winconf)
2596 (setq buffer-read-only nil)
2597 (buffer-enable-undo)
2599 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2601 (defun gnus-article-edit (&optional force)
2602 "Edit the current article.
2603 This will have permanent effect only in mail groups.
2604 If FORCE is non-nil, allow editing of articles even in read-only
2607 (when (and (not force)
2608 (gnus-group-read-only-p))
2609 (error "The current newsgroup does not support article editing"))
2610 (gnus-article-date-original)
2611 (gnus-article-edit-article
2612 `(lambda (no-highlight)
2613 (gnus-summary-edit-article-done
2614 ,(or (mail-header-references gnus-current-headers) "")
2615 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2617 (defun gnus-article-edit-article (exit-func)
2618 "Start editing the contents of the current article buffer."
2619 (let ((winconf (current-window-configuration)))
2620 (set-buffer gnus-article-buffer)
2621 (gnus-article-edit-mode)
2622 (gnus-set-text-properties (point-min) (point-max) nil)
2623 (gnus-configure-windows 'edit-article)
2624 (setq gnus-article-edit-done-function exit-func)
2625 (setq gnus-prev-winconf winconf)
2626 (gnus-message 6 "C-c C-c to end edits")))
2628 (defun gnus-article-edit-done (&optional arg)
2629 "Update the article edits and exit."
2634 (goto-char (point-min))
2635 (when (search-forward "\n\n" nil 1)
2636 (let ((lines (count-lines (point) (point-max)))
2637 (length (- (point-max) (point)))
2638 (case-fold-search t)
2639 (body (copy-marker (point))))
2640 (goto-char (point-min))
2641 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2642 (delete-region (match-beginning 1) (match-end 1))
2643 (insert (number-to-string length)))
2644 (goto-char (point-min))
2645 (when (re-search-forward
2646 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2647 (delete-region (match-beginning 1) (match-end 1))
2648 (insert (number-to-string length)))
2649 (goto-char (point-min))
2650 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2651 (delete-region (match-beginning 1) (match-end 1))
2652 (insert (number-to-string lines)))))))
2653 (let ((func gnus-article-edit-done-function)
2654 (buf (current-buffer))
2655 (start (window-start)))
2656 (gnus-article-edit-exit)
2659 (let ((buffer-read-only nil))
2660 (funcall func arg)))
2662 (set-window-start (get-buffer-window buf) start)
2663 (set-window-point (get-buffer-window buf) (point))))
2665 (defun gnus-article-edit-exit ()
2666 "Exit the article editing without updating."
2668 ;; We remove all text props from the article buffer.
2669 (let ((buf (format "%s" (buffer-string)))
2670 (curbuf (current-buffer))
2672 (window-start (window-start)))
2675 (let ((winconf gnus-prev-winconf))
2677 ;; The cache and backlog have to be flushed somewhat.
2678 (when gnus-use-cache
2679 (gnus-cache-update-article
2680 (car gnus-article-current) (cdr gnus-article-current)))
2681 (when gnus-keep-backlog
2682 (gnus-backlog-remove-article
2683 (car gnus-article-current) (cdr gnus-article-current)))
2684 ;; Flush original article as well.
2686 (when (get-buffer gnus-original-article-buffer)
2687 (set-buffer gnus-original-article-buffer)
2688 (setq gnus-original-article nil)))
2689 (set-window-configuration winconf)
2690 ;; Tippy-toe some to make sure that point remains where it was.
2691 (let ((buf (current-buffer)))
2693 (set-window-start (get-buffer-window (current-buffer)) window-start)
2695 (set-buffer buf)))))
2697 (defun gnus-article-edit-full-stops ()
2698 "Interactively repair spacing at end of sentences."
2701 (goto-char (point-min))
2702 (search-forward-regexp "^$" nil t)
2703 (let ((case-fold-search nil))
2704 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2707 ;;; Article highlights
2710 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2712 ;;; Internal Variables:
2714 (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\\)"
2715 "Regular expression that matches URLs."
2716 :group 'gnus-article-buttons
2719 (defcustom gnus-button-alist
2720 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2721 gnus-button-message-id 2)
2722 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2723 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2725 gnus-button-fetch-group 4)
2726 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2727 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2728 t gnus-button-message-id 3)
2729 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2730 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2731 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2732 ;; This is how URLs _should_ be embedded in text...
2733 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2735 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2736 "*Alist of regexps matching buttons in article bodies.
2738 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2739 REGEXP: is the string matching text around the button,
2740 BUTTON: is the number of the regexp grouping actually matching the button,
2741 FORM: is a lisp expression which must eval to true for the button to
2743 CALLBACK: is the function to call when the user push this button, and each
2744 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2746 CALLBACK can also be a variable, in that case the value of that
2747 variable it the real callback function."
2748 :group 'gnus-article-buttons
2749 :type '(repeat (list regexp
2750 (integer :tag "Button")
2752 (function :tag "Callback")
2755 (integer :tag "Regexp group")))))
2757 (defcustom gnus-header-button-alist
2758 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2759 0 t gnus-button-message-id 0)
2760 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2761 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2762 0 t gnus-button-mailto 0)
2763 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2764 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2765 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2766 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2767 gnus-button-message-id 3))
2768 "*Alist of headers and regexps to match buttons in article heads.
2770 This alist is very similar to `gnus-button-alist', except that each
2771 alist has an additional HEADER element first in each entry:
2773 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2775 HEADER is a regexp to match a header. For a fuller explanation, see
2776 `gnus-button-alist'."
2777 :group 'gnus-article-buttons
2778 :group 'gnus-article-headers
2779 :type '(repeat (list (regexp :tag "Header")
2781 (integer :tag "Button")
2783 (function :tag "Callback")
2786 (integer :tag "Regexp group")))))
2788 (defvar gnus-button-regexp nil)
2789 (defvar gnus-button-marker-list nil)
2790 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2792 (defvar gnus-button-last nil)
2793 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2797 (defun gnus-article-push-button (event)
2798 "Check text under the mouse pointer for a callback function.
2799 If the text under the mouse pointer has a `gnus-callback' property,
2800 call it with the value of the `gnus-data' text property."
2802 (set-buffer (window-buffer (posn-window (event-start event))))
2803 (let* ((pos (posn-point (event-start event)))
2804 (data (get-text-property pos 'gnus-data))
2805 (fun (get-text-property pos 'gnus-callback)))
2807 (funcall fun data))))
2809 (defun gnus-article-press-button ()
2810 "Check text at point for a callback function.
2811 If the text at point has a `gnus-callback' property,
2812 call it with the value of the `gnus-data' text property."
2814 (let* ((data (get-text-property (point) 'gnus-data))
2815 (fun (get-text-property (point) 'gnus-callback)))
2817 (funcall fun data))))
2819 (defun gnus-article-prev-button (n)
2820 "Move point to N buttons backward.
2821 If N is negative, move forward instead."
2823 (gnus-article-next-button (- n)))
2825 (defun gnus-article-next-button (n)
2826 "Move point to N buttons forward.
2827 If N is negative, move backward instead."
2829 (let ((function (if (< n 0) 'previous-single-property-change
2830 'next-single-property-change))
2831 (inhibit-point-motion-hooks t)
2833 (limit (if (< n 0) (point-min) (point-max))))
2835 (while (and (not (= limit (point)))
2837 ;; Skip past the current button.
2838 (when (get-text-property (point) 'gnus-callback)
2839 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2840 ;; Go to the next (or previous) button.
2841 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2842 ;; Put point at the start of the button.
2843 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2844 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2845 ;; Skip past intangible buttons.
2846 (when (get-text-property (point) 'intangible)
2850 (gnus-message 5 "No more buttons"))
2853 (defun gnus-article-highlight (&optional force)
2854 "Highlight current article.
2855 This function calls `gnus-article-highlight-headers',
2856 `gnus-article-highlight-citation',
2857 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2858 do the highlighting. See the documentation for those functions."
2859 (interactive (list 'force))
2860 (gnus-article-highlight-headers)
2861 (gnus-article-highlight-citation force)
2862 (gnus-article-highlight-signature)
2863 (gnus-article-add-buttons force)
2864 (gnus-article-add-buttons-to-head))
2866 (defun gnus-article-highlight-some (&optional force)
2867 "Highlight current article.
2868 This function calls `gnus-article-highlight-headers',
2869 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2870 do the highlighting. See the documentation for those functions."
2871 (interactive (list 'force))
2872 (gnus-article-highlight-headers)
2873 (gnus-article-highlight-signature)
2874 (gnus-article-add-buttons))
2876 (defun gnus-article-highlight-headers ()
2877 "Highlight article headers as specified by `gnus-header-face-alist'."
2880 (set-buffer gnus-article-buffer)
2882 (let ((alist gnus-header-face-alist)
2883 (buffer-read-only nil)
2884 (case-fold-search t)
2885 (inhibit-point-motion-hooks t)
2886 entry regexp header-face field-face from hpoints fpoints)
2887 (message-narrow-to-head)
2888 (while (setq entry (pop alist))
2889 (goto-char (point-min))
2890 (setq regexp (concat "^\\("
2891 (if (string-equal "" (nth 0 entry))
2895 header-face (nth 1 entry)
2896 field-face (nth 2 entry))
2897 (while (and (re-search-forward regexp nil t)
2901 (unless (search-forward ":" nil t)
2903 (when (and header-face
2904 (not (memq (point) hpoints)))
2905 (push (point) hpoints)
2906 (gnus-put-text-property from (point) 'face header-face))
2907 (when (and field-face
2908 (not (memq (setq from (point)) fpoints)))
2910 (if (re-search-forward "^[^ \t]" nil t)
2912 (goto-char (point-max)))
2913 (gnus-put-text-property from (point) 'face field-face))))))))
2915 (defun gnus-article-highlight-signature ()
2916 "Highlight the signature in an article.
2917 It does this by highlighting everything after
2918 `gnus-signature-separator' using `gnus-signature-face'."
2921 (set-buffer gnus-article-buffer)
2922 (let ((buffer-read-only nil)
2923 (inhibit-point-motion-hooks t))
2925 (when (and gnus-signature-face
2926 (gnus-article-narrow-to-signature))
2927 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2928 'face gnus-signature-face)
2930 (gnus-article-search-signature)
2931 (let ((start (match-beginning 0))
2932 (end (set-marker (make-marker) (1+ (match-end 0)))))
2933 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2936 (defun gnus-button-in-region-p (b e prop)
2937 "Say whether PROP exists in the region."
2938 (text-property-not-all b e prop nil))
2940 (defun gnus-article-add-buttons (&optional force)
2941 "Find external references in the article and make buttons of them.
2942 \"External references\" are things like Message-IDs and URLs, as
2943 specified by `gnus-button-alist'."
2944 (interactive (list 'force))
2946 (set-buffer gnus-article-buffer)
2947 (let ((buffer-read-only nil)
2948 (inhibit-point-motion-hooks t)
2949 (case-fold-search t)
2950 (alist gnus-button-alist)
2952 ;; Remove all old markers.
2954 (while (setq marker (pop gnus-button-marker-list))
2956 (when (setq entry (gnus-button-entry))
2957 (put-text-property (match-beginning (nth 1 entry))
2958 (match-end (nth 1 entry))
2959 'gnus-callback nil))
2960 (set-marker marker nil)))
2961 ;; We skip the headers.
2962 (goto-char (point-min))
2963 (unless (search-forward "\n\n" nil t)
2964 (goto-char (point-max)))
2966 (while (setq entry (pop alist))
2967 (setq regexp (car entry))
2969 (while (re-search-forward regexp nil t)
2970 (let* ((start (and entry (match-beginning (nth 1 entry))))
2971 (end (and entry (match-end (nth 1 entry))))
2972 (from (match-beginning 0)))
2973 (when (and (or (eq t (nth 2 entry))
2974 (eval (nth 2 entry)))
2975 (not (gnus-button-in-region-p
2976 start end 'gnus-callback)))
2977 ;; That optional form returned non-nil, so we add the
2979 (gnus-article-add-button
2980 start end 'gnus-button-push
2981 (car (push (set-marker (make-marker) from)
2982 gnus-button-marker-list))))))))))
2984 ;; Add buttons to the head of an article.
2985 (defun gnus-article-add-buttons-to-head ()
2986 "Add buttons to the head of the article."
2989 (set-buffer gnus-article-buffer)
2990 (let ((buffer-read-only nil)
2991 (inhibit-point-motion-hooks t)
2992 (case-fold-search t)
2993 (alist gnus-header-button-alist)
2995 (nnheader-narrow-to-headers)
2997 ;; Each alist entry.
2998 (setq entry (car alist)
3000 (goto-char (point-min))
3001 (while (re-search-forward (car entry) nil t)
3002 ;; Each header matching the entry.
3003 (setq beg (match-beginning 0))
3004 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3005 (match-beginning 0))
3008 (while (re-search-forward (nth 1 entry) end t)
3009 ;; Each match within a header.
3010 (let* ((entry (cdr entry))
3011 (start (match-beginning (nth 1 entry)))
3012 (end (match-end (nth 1 entry)))
3013 (form (nth 2 entry)))
3014 (goto-char (match-end 0))
3016 (gnus-article-add-button
3017 start end (nth 3 entry)
3018 (buffer-substring (match-beginning (nth 4 entry))
3019 (match-end (nth 4 entry)))))))
3023 ;;; External functions:
3025 (defun gnus-article-add-button (from to fun &optional data)
3026 "Create a button between FROM and TO with callback FUN and data DATA."
3027 (when gnus-article-button-face
3028 (gnus-overlay-put (gnus-make-overlay from to)
3029 'face gnus-article-button-face))
3030 (gnus-add-text-properties
3032 (nconc (and gnus-article-mouse-face
3033 (list gnus-mouse-face-prop gnus-article-mouse-face))
3034 (list 'gnus-callback fun)
3035 (and data (list 'gnus-data data)))))
3037 ;;; Internal functions:
3039 (defun gnus-article-set-globals ()
3041 (set-buffer gnus-summary-buffer)
3042 (gnus-set-global-variables)))
3044 (defun gnus-signature-toggle (end)
3046 (set-buffer gnus-article-buffer)
3047 (let ((buffer-read-only nil)
3048 (inhibit-point-motion-hooks t))
3049 (if (get-text-property end 'invisible)
3050 (gnus-article-unhide-text end (point-max))
3051 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3053 (defun gnus-button-entry ()
3054 ;; Return the first entry in `gnus-button-alist' matching this place.
3055 (let ((alist gnus-button-alist)
3058 (setq entry (pop alist))
3059 (if (looking-at (car entry))
3064 (defun gnus-button-push (marker)
3065 ;; Push button starting at MARKER.
3067 (set-buffer gnus-article-buffer)
3069 (let* ((entry (gnus-button-entry))
3070 (inhibit-point-motion-hooks t)
3072 (args (mapcar (lambda (group)
3073 (let ((string (match-string group)))
3074 (gnus-set-text-properties
3075 0 (length string) nil string)
3082 (fboundp (symbol-value fun)))
3083 (apply (symbol-value fun) args))
3085 (gnus-message 1 "You must define `%S' to use this button"
3086 (cons fun args)))))))
3088 (defun gnus-button-message-id (message-id)
3091 (set-buffer gnus-summary-buffer)
3092 (gnus-summary-refer-article message-id)))
3094 (defun gnus-button-fetch-group (address)
3095 "Fetch GROUP specified by ADDRESS."
3096 (if (not (string-match "[:/]" address))
3097 ;; This is just a simple group url.
3098 (gnus-group-read-ephemeral-group address gnus-select-method)
3099 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3101 (error "Can't parse %s" address)
3102 (gnus-group-read-ephemeral-group
3103 (match-string 4 address)
3104 `(nntp ,(match-string 1 address)
3105 (nntp-address ,(match-string 1 address))
3106 (nntp-port-number ,(if (match-end 3)
3107 (match-string 3 address)
3110 (defun gnus-url-parse-query-string (query &optional downcase)
3111 (let (retval pairs cur key val)
3112 (setq pairs (gnus-split-string query "&"))
3114 (setq cur (car pairs)
3116 (if (not (string-match "=" cur))
3118 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3119 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3121 (setq key (downcase key)))
3122 (setq cur (assoc key retval))
3124 (setcdr cur (cons val (cdr cur)))
3125 (setq retval (cons (list key val) retval)))))
3128 (defun gnus-url-unhex (x)
3135 (defun gnus-url-unhex-string (str &optional allow-newlines)
3136 "Remove %XXX embedded spaces, etc in a url.
3137 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3138 decoding of carriage returns and line feeds in the string, which is normally
3139 forbidden in URL encoding."
3140 (setq str (or str ""))
3142 (case-fold-search t))
3143 (while (string-match "%[0-9a-f][0-9a-f]" str)
3144 (let* ((start (match-beginning 0))
3145 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3147 (gnus-url-unhex (elt str (+ start 2))))))
3149 tmp (substring str 0 start)
3152 (char-to-string code))
3153 ((or (= code ?\n) (= code ?\r))
3155 (t (char-to-string code))))
3156 str (substring str (match-end 0)))))
3157 (setq tmp (concat tmp str))
3160 (defun gnus-url-mailto (url)
3161 ;; Send mail to someone
3162 (when (string-match "mailto:/*\\(.*\\)" url)
3163 (setq url (substring url (match-beginning 1) nil)))
3164 (let (to args source-url subject func)
3165 (if (string-match (regexp-quote "?") url)
3166 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3167 args (gnus-url-parse-query-string
3168 (substring url (match-end 0) nil) t))
3169 (setq to (gnus-url-unhex-string url)))
3170 (setq args (cons (list "to" to) args)
3171 subject (cdr-safe (assoc "subject" args)))
3174 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3177 (message-position-on-field (caar args)))
3178 (insert (mapconcat 'identity (cdar args) ", "))
3179 (setq args (cdr args)))
3182 (message-goto-subject))))
3184 (defun gnus-button-mailto (address)
3186 (set-buffer (gnus-copy-article-buffer))
3187 (message-reply address))
3189 (defun gnus-button-reply (address)
3190 ;; Reply to ADDRESS.
3191 (message-reply address))
3193 (defun gnus-button-url (address)
3195 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3196 (if (listp browse-url-browser-function)
3197 (browse-url address)
3198 (funcall browse-url-browser-function address)))
3200 (defun gnus-button-embedded-url (address)
3202 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3203 (if (listp browse-url-browser-function)
3204 (browse-url (gnus-strip-whitespace address))
3205 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3207 ;;; Next/prev buttons in the article buffer.
3209 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3210 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3212 (defvar gnus-prev-page-map nil)
3213 (unless gnus-prev-page-map
3214 (setq gnus-prev-page-map (make-sparse-keymap))
3215 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3216 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3218 (defun gnus-insert-prev-page-button ()
3219 (let ((buffer-read-only nil))
3221 gnus-prev-page-line-format nil
3222 `(gnus-prev t local-map ,gnus-prev-page-map
3223 gnus-callback gnus-article-button-prev-page))))
3225 (defvar gnus-next-page-map nil)
3226 (unless gnus-next-page-map
3227 (setq gnus-next-page-map (make-keymap))
3228 (suppress-keymap gnus-prev-page-map)
3229 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3230 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3232 (defun gnus-button-next-page ()
3233 "Go to the next page."
3235 (let ((win (selected-window)))
3236 (select-window (get-buffer-window gnus-article-buffer t))
3237 (gnus-article-next-page)
3238 (select-window win)))
3240 (defun gnus-button-prev-page ()
3241 "Go to the prev page."
3243 (let ((win (selected-window)))
3244 (select-window (get-buffer-window gnus-article-buffer t))
3245 (gnus-article-prev-page)
3246 (select-window win)))
3248 (defun gnus-insert-next-page-button ()
3249 (let ((buffer-read-only nil))
3250 (gnus-eval-format gnus-next-page-line-format nil
3251 `(gnus-next t local-map ,gnus-next-page-map
3253 gnus-article-button-next-page))))
3255 (defun gnus-article-button-next-page (arg)
3256 "Go to the next page."
3258 (let ((win (selected-window)))
3259 (select-window (get-buffer-window gnus-article-buffer t))
3260 (gnus-article-next-page)
3261 (select-window win)))
3263 (defun gnus-article-button-prev-page (arg)
3264 "Go to the prev page."
3266 (let ((win (selected-window)))
3267 (select-window (get-buffer-window gnus-article-buffer t))
3268 (gnus-article-prev-page)
3269 (select-window win)))
3275 (run-hooks 'gnus-art-load-hook)
3277 ;;; gnus-art.el ends here