1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
35 (defgroup gnus-article nil
37 :link '(custom-manual "(gnus)The Article Buffer")
40 (defgroup gnus-article-hiding nil
41 "Hiding article parts."
42 :link '(custom-manual "(gnus)Article Hiding")
45 (defgroup gnus-article-highlight nil
46 "Article highlighting."
47 :link '(custom-manual "(gnus)Article Highlighting")
51 (defgroup gnus-article-signature nil
53 :link '(custom-manual "(gnus)Article Signature")
56 (defgroup gnus-article-headers nil
58 :link '(custom-manual "(gnus)Hiding Headers")
61 (defgroup gnus-article-washing nil
62 "Special commands on articles."
63 :link '(custom-manual "(gnus)Article Washing")
66 (defgroup gnus-article-emphasis nil
67 "Fontisizing articles."
68 :link '(custom-manual "(gnus)Article Fontisizing")
71 (defgroup gnus-article-saving nil
73 :link '(custom-manual "(gnus)Saving Articles")
76 (defgroup gnus-article-mime nil
77 "Worshiping the MIME wonder."
78 :link '(custom-manual "(gnus)Using MIME")
81 (defgroup gnus-article-buttons nil
82 "Pushable buttons in the article buffer."
83 :link '(custom-manual "(gnus)Article Buttons")
86 (defgroup gnus-article-various nil
87 "Other article options."
88 :link '(custom-manual "(gnus)Misc Article")
91 (defcustom gnus-ignored-headers
92 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
93 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
94 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
95 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
96 "All headers that match this regexp will be hidden.
97 This variable can also be a list of regexps of headers to be ignored.
98 If `gnus-visible-headers' is non-nil, this variable will be ignored."
99 :type '(choice :custom-show nil
102 :group 'gnus-article-hiding)
104 (defcustom gnus-visible-headers
105 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From"
106 "All headers that do not match this regexp will be hidden.
107 This variable can also be a list of regexp of headers to remain visible.
108 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
109 :type '(repeat :value-to-internal (lambda (widget value)
110 (custom-split-regexp-maybe value))
111 :match (lambda (widget value)
113 (widget-editable-list-match widget value)))
115 :group 'gnus-article-hiding)
117 (defcustom gnus-sorted-header-list
118 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
119 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
120 "This variable is a list of regular expressions.
121 If it is non-nil, headers that match the regular expressions will
122 be placed first in the article buffer in the sequence specified by
124 :type '(repeat regexp)
125 :group 'gnus-article-hiding)
127 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
128 "Headers that are only to be displayed if they have interesting data.
129 Possible values in this list are `empty', `newsgroups', `followup-to',
130 `reply-to', and `date'."
131 :type '(set (const :tag "Headers with no content." empty)
132 (const :tag "Newsgroups with only one group." newsgroups)
133 (const :tag "Followup-to identical to newsgroups." followup-to)
134 (const :tag "Reply-to identical to from." reply-to)
135 (const :tag "Date less than four days old." date))
136 :group 'gnus-article-hiding)
138 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
139 "Regexp matching signature separator.
140 This can also be a list of regexps. In that case, it will be checked
141 from head to tail looking for a separator. Searches will be done from
142 the end of the buffer."
143 :type '(repeat string)
144 :group 'gnus-article-signature)
146 (defcustom gnus-signature-limit nil
147 "Provide a limit to what is considered a signature.
148 If it is a number, no signature may not be longer (in characters) than
149 that number. If it is a floating point number, no signature may be
150 longer (in lines) than that number. If it is a function, the function
151 will be called without any parameters, and if it returns nil, there is
152 no signature in the buffer. If it is a string, it will be used as a
153 regexp. If it matches, the text in question is not a signature."
154 :type '(choice integer number function regexp)
155 :group 'gnus-article-signature)
157 (defcustom gnus-hidden-properties '(invisible t intangible t)
158 "Property list to use for hiding text."
160 :group 'gnus-article-hiding)
162 (defcustom gnus-article-x-face-command
163 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
164 "String or function to be executed to display an X-Face header.
165 If it is a string, the command will be executed in a sub-shell
166 asynchronously. The compressed face will be piped to this command."
167 :type 'string ;Leave function case to Lisp.
168 :group 'gnus-article-washing)
170 (defcustom gnus-article-x-face-too-ugly nil
171 "Regexp matching posters whose face shouldn't be shown automatically."
173 :group 'gnus-article-washing)
175 (defcustom gnus-emphasis-alist
177 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
179 '(("_" "_" underline)
182 ("_/" "/_" underline-italic)
183 ("_\\*" "\\*_" underline-bold)
184 ("\\*/" "/\\*" bold-italic)
185 ("_\\*/" "/\\*_" underline-bold-italic))))
186 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
187 2 3 gnus-emphasis-underline)
191 (format format (car spec) (cadr spec))
192 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
194 "Alist that says how to fontify certain phrases.
195 Each item looks like this:
197 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
199 The first element is a regular expression to be matched. The second
200 is a number that says what regular expression grouping used to find
201 the entire emphasized word. The third is a number that says what
202 regexp grouping should be displayed and highlighted. The fourth
203 is the face used for highlighting."
204 :type '(repeat (list :value ("" 0 0 default)
206 (integer :tag "Match group")
207 (integer :tag "Emphasize group")
209 :group 'gnus-article-emphasis)
211 (defface gnus-emphasis-bold '((t (:bold t)))
212 "Face used for displaying strong emphasized text (*word*)."
213 :group 'gnus-article-emphasis)
215 (defface gnus-emphasis-italic '((t (:italic t)))
216 "Face used for displaying italic emphasized text (/word/)."
217 :group 'gnus-article-emphasis)
219 (defface gnus-emphasis-underline '((t (:underline t)))
220 "Face used for displaying underlined emphasized text (_word_)."
221 :group 'gnus-article-emphasis)
223 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
224 "Face used for displaying underlined bold emphasized text (_*word*_)."
225 :group 'gnus-article-emphasis)
227 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
228 "Face used for displaying underlined italic emphasized text (_*word*_)."
229 :group 'gnus-article-emphasis)
231 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
232 "Face used for displaying bold italic emphasized text (/*word*/)."
233 :group 'gnus-article-emphasis)
235 (defface gnus-emphasis-underline-bold-italic
236 '((t (:bold t :italic t :underline t)))
237 "Face used for displaying underlined bold italic emphasized text.
238 Esample: (_/*word*/_)."
239 :group 'gnus-article-emphasis)
241 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
242 "Format for display of Date headers in article bodies.
243 See `format-time-zone' for the possible values."
245 :link '(custom-manual "(gnus)Article Date")
246 :group 'gnus-article-washing)
249 (autoload 'hexl-hex-string-to-integer "hexl")
250 (autoload 'timezone-make-date-arpa-standard "timezone")
251 (autoload 'mail-extract-address-components "mail-extr"))
253 (defcustom gnus-save-all-headers t
254 "*If non-nil, don't remove any headers before saving."
255 :group 'gnus-article-saving
258 (defcustom gnus-prompt-before-saving 'always
259 "*This variable says how much prompting is to be done when saving articles.
260 If it is nil, no prompting will be done, and the articles will be
261 saved to the default files. If this variable is `always', each and
262 every article that is saved will be preceded by a prompt, even when
263 saving large batches of articles. If this variable is neither nil not
264 `always', there the user will be prompted once for a file name for
265 each invocation of the saving commands."
266 :group 'gnus-article-saving
267 :type '(choice (item always)
268 (item :tag "never" nil)
269 (sexp :tag "once" :format "%t")))
271 (defcustom gnus-saved-headers gnus-visible-headers
272 "Headers to keep if `gnus-save-all-headers' is nil.
273 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
274 If that variable is nil, however, all headers that match this regexp
275 will be kept while the rest will be deleted before saving."
276 :group 'gnus-article-saving
277 :type '(repeat string))
279 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
280 "A function to save articles in your favourite format.
281 The function must be interactively callable (in other words, it must
282 be an Emacs command).
284 Gnus provides the following functions:
286 * gnus-summary-save-in-rmail (Rmail format)
287 * gnus-summary-save-in-mail (Unix mail format)
288 * gnus-summary-save-in-folder (MH folder)
289 * gnus-summary-save-in-file (article format)
290 * gnus-summary-save-in-vm (use VM's folder format)
291 * gnus-summary-write-to-file (article format -- overwrite)."
292 :group 'gnus-article-saving
293 :type '(radio (function-item gnus-summary-save-in-rmail)
294 (function-item gnus-summary-save-in-mail)
295 (function-item gnus-summary-save-in-folder)
296 (function-item gnus-summary-save-in-file)
297 (function-item gnus-summary-save-in-vm)
298 (function-item gnus-summary-write-to-file)))
300 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
301 "A function generating a file name to save articles in Rmail format.
302 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
303 :group 'gnus-article-saving
306 (defcustom gnus-mail-save-name 'gnus-plain-save-name
307 "A function generating a file name to save articles in Unix mail format.
308 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
309 :group 'gnus-article-saving
312 (defcustom gnus-folder-save-name 'gnus-folder-save-name
313 "A function generating a file name to save articles in MH folder.
314 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
315 :group 'gnus-article-saving
318 (defcustom gnus-file-save-name 'gnus-numeric-save-name
319 "A function generating a file name to save articles in article format.
320 The function is called with NEWSGROUP, HEADERS, and optional
322 :group 'gnus-article-saving
325 (defcustom gnus-split-methods
326 '((gnus-article-archive-name)
327 (gnus-article-nndoc-name))
328 "Variable used to suggest where articles are to be saved.
329 For instance, if you would like to save articles related to Gnus in
330 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
331 you could set this variable to something like:
333 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
334 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
336 This variable is an alist where the where the key is the match and the
337 value is a list of possible files to save in if the match is non-nil.
339 If the match is a string, it is used as a regexp match on the
340 article. If the match is a symbol, that symbol will be funcalled
341 from the buffer of the article to be saved with the newsgroup as the
342 parameter. If it is a list, it will be evaled in the same buffer.
344 If this form or function returns a string, this string will be used as
345 a possible file name; and if it returns a non-nil list, that list will
346 be used as possible file names."
347 :group 'gnus-article-saving
348 :type '(repeat (choice (list function)
349 (cons regexp (repeat string))
352 (defcustom gnus-strict-mime t
353 "*If nil, MIME-decode even if there is no Mime-Version header."
354 :group 'gnus-article-mime
357 (defcustom gnus-show-mime-method 'metamail-buffer
358 "Function to process a MIME message.
359 The function is called from the article buffer."
360 :group 'gnus-article-mime
363 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
364 "*Function to decode MIME encoded words.
365 The function is called from the article buffer."
366 :group 'gnus-article-mime
369 (defcustom gnus-page-delimiter "^\^L"
370 "*Regexp describing what to use as article page delimiters.
371 The default value is \"^\^L\", which is a form linefeed at the
372 beginning of a line."
374 :group 'gnus-article-various)
376 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
377 "*The format specification for the article mode line.
378 See `gnus-summary-mode-line-format' for a closer description."
380 :group 'gnus-article-various)
382 (defcustom gnus-article-mode-hook nil
383 "*A hook for Gnus article mode."
385 :group 'gnus-article-various)
387 (defcustom gnus-article-menu-hook nil
388 "*Hook run after the creation of the article mode menu."
390 :group 'gnus-article-various)
392 (defcustom gnus-article-prepare-hook nil
393 "*A hook called after an article has been prepared in the article buffer.
394 If you want to run a special decoding program like nkf, use this hook."
396 :group 'gnus-article-various)
398 (defcustom gnus-article-hide-pgp-hook nil
399 "*A hook called after successfully hiding a PGP signature."
401 :group 'gnus-article-various)
403 (defcustom gnus-article-button-face 'bold
404 "Face used for highlighting buttons in the article buffer.
406 An article button is a piece of text that you can activate by pressing
407 `RET' or `mouse-2' above it."
409 :group 'gnus-article-buttons)
411 (defcustom gnus-article-mouse-face 'highlight
412 "Face used for mouse highlighting in the article buffer.
414 Article buttons will be displayed in this face when the cursor is
417 :group 'gnus-article-buttons)
419 (defcustom gnus-signature-face 'gnus-signature-face
420 "Face used for highlighting a signature in the article buffer.
421 Obsolete; use the face `gnus-signature-face' for customizations instead."
423 :group 'gnus-article-highlight
424 :group 'gnus-article-signature)
426 (defface gnus-signature-face
429 "Face used for highlighting a signature in the article buffer."
430 :group 'gnus-article-highlight
431 :group 'gnus-article-signature)
433 (defface gnus-header-from-face
436 (:foreground "spring green" :bold t))
439 (:foreground "red3" :bold t))
441 (:bold t :italic t)))
442 "Face used for displaying from headers."
443 :group 'gnus-article-headers
444 :group 'gnus-article-highlight)
446 (defface gnus-header-subject-face
449 (:foreground "SeaGreen3" :bold t))
452 (:foreground "red4" :bold t))
454 (:bold t :italic t)))
455 "Face used for displaying subject headers."
456 :group 'gnus-article-headers
457 :group 'gnus-article-highlight)
459 (defface gnus-header-newsgroups-face
462 (:foreground "yellow" :bold t :italic t))
465 (:foreground "MidnightBlue" :bold t :italic t))
467 (:bold t :italic t)))
468 "Face used for displaying newsgroups headers."
469 :group 'gnus-article-headers
470 :group 'gnus-article-highlight)
472 (defface gnus-header-name-face
475 (:foreground "SeaGreen"))
478 (:foreground "maroon"))
481 "Face used for displaying header names."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-content-face
488 (:foreground "forest green" :italic t))
491 (:foreground "indianred4" :italic t))
493 (:italic t))) "Face used for displaying header content."
494 :group 'gnus-article-headers
495 :group 'gnus-article-highlight)
497 (defcustom gnus-header-face-alist
498 '(("From" nil gnus-header-from-face)
499 ("Subject" nil gnus-header-subject-face)
500 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
501 ("" gnus-header-name-face gnus-header-content-face))
502 "Controls highlighting of article header.
504 An alist of the form (HEADER NAME CONTENT).
506 HEADER is a regular expression which should match the name of an
507 header header and NAME and CONTENT are either face names or nil.
509 The name of each header field will be displayed using the face
510 specified by the first element in the list where HEADER match the
511 header name and NAME is non-nil. Similarly, the content will be
512 displayed by the first non-nil matching CONTENT face."
513 :group 'gnus-article-headers
514 :group 'gnus-article-highlight
515 :type '(repeat (list (regexp :tag "Header")
517 (item :tag "skip" nil)
518 (face :value default))
519 (choice :tag "Content"
520 (item :tag "skip" nil)
521 (face :value default)))))
523 ;;; Internal variables
525 (defvar gnus-article-mode-syntax-table
526 (let ((table (copy-syntax-table text-mode-syntax-table)))
527 (modify-syntax-entry ?- "w" table)
528 (modify-syntax-entry ?> ")" table)
529 (modify-syntax-entry ?< "(" table)
531 "Syntax table used in article mode buffers.
532 Initialized from `text-mode-syntax-table.")
534 (defvar gnus-save-article-buffer nil)
536 (defvar gnus-article-mode-line-format-alist
537 (nconc '((?w (gnus-article-wash-status) ?s))
538 gnus-summary-mode-line-format-alist))
540 (defvar gnus-number-of-articles-to-be-saved nil)
542 (defvar gnus-inhibit-hiding nil)
544 (defsubst gnus-article-hide-text (b e props)
545 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
546 (add-text-properties b e props)
547 (when (memq 'intangible props)
549 (max (1- b) (point-min))
550 b 'intangible (cddr (memq 'intangible props)))))
552 (defsubst gnus-article-unhide-text (b e)
553 "Remove hidden text properties from region between B and E."
554 (remove-text-properties b e gnus-hidden-properties)
555 (when (memq 'intangible gnus-hidden-properties)
556 (put-text-property (max (1- b) (point-min))
559 (defun gnus-article-hide-text-type (b e type)
560 "Hide text of TYPE between B and E."
561 (gnus-article-hide-text
562 b e (cons 'article-type (cons type gnus-hidden-properties))))
564 (defun gnus-article-unhide-text-type (b e type)
565 "Hide text of TYPE between B and E."
566 (remove-text-properties
567 b e (cons 'article-type (cons type gnus-hidden-properties)))
568 (when (memq 'intangible gnus-hidden-properties)
569 (put-text-property (max (1- b) (point-min))
572 (defun gnus-article-hide-text-of-type (type)
573 "Hide text of TYPE in the current buffer."
575 (let ((b (point-min))
577 (while (setq b (text-property-any b e 'article-type type))
578 (add-text-properties b (incf b) gnus-hidden-properties)))))
580 (defun gnus-article-delete-text-of-type (type)
581 "Delete text of TYPE in the current buffer."
583 (let ((b (point-min)))
584 (while (setq b (text-property-any b (point-max) 'article-type type))
586 b (text-property-not-all b (point-max) 'article-type type))))))
588 (defun gnus-article-delete-invisible-text ()
589 "Delete all invisible text in the current buffer."
591 (let ((b (point-min)))
592 (while (setq b (text-property-any b (point-max) 'invisible t))
594 b (text-property-not-all b (point-max) 'invisible t))))))
596 (defun gnus-article-text-type-exists-p (type)
597 "Say whether any text of type TYPE exists in the buffer."
598 (text-property-any (point-min) (point-max) 'article-type type))
600 (defsubst gnus-article-header-rank ()
601 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
602 (let ((list gnus-sorted-header-list)
605 (when (looking-at (car list))
607 (setq list (cdr list))
611 (defun article-hide-headers (&optional arg delete)
612 "Toggle whether to hide unwanted headers and possibly sort them as well.
613 If given a negative prefix, always show; if given a positive prefix,
615 (interactive (gnus-article-hidden-arg))
616 (if (gnus-article-check-hidden-text 'headers arg)
617 ;; Show boring headers as well.
618 (gnus-article-show-hidden-text 'boring-headers)
619 ;; This function might be inhibited.
620 (unless gnus-inhibit-hiding
623 (let ((buffer-read-only nil)
624 (props (nconc (list 'article-type 'headers)
625 gnus-hidden-properties))
626 (max (1+ (length gnus-sorted-header-list)))
627 (ignored (when (not gnus-visible-headers)
628 (cond ((stringp gnus-ignored-headers)
629 gnus-ignored-headers)
630 ((listp gnus-ignored-headers)
631 (mapconcat 'identity gnus-ignored-headers
634 (cond ((stringp gnus-visible-headers)
635 gnus-visible-headers)
636 ((and gnus-visible-headers
637 (listp gnus-visible-headers))
638 (mapconcat 'identity gnus-visible-headers "\\|"))))
639 (inhibit-point-motion-hooks t)
641 ;; First we narrow to just the headers.
643 (goto-char (point-min))
644 ;; Hide any "From " lines at the beginning of (mail) articles.
645 (while (looking-at "From ")
649 (delete-region (point-min) (point))
650 (gnus-article-hide-text (point-min) (point) props)))
651 ;; Then treat the rest of the header lines.
654 (if (search-forward "\n\n" nil t) ; if there's a body
655 (progn (forward-line -1) (point))
657 ;; Then we use the two regular expressions
658 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
659 ;; select which header lines is to remain visible in the
661 (goto-char (point-min))
662 (while (re-search-forward "^[^ \t]*:" nil t)
664 ;; Mark the rank of the header.
666 (point) (1+ (point)) 'message-rank
667 (if (or (and visible (looking-at visible))
669 (not (looking-at ignored))))
670 (gnus-article-header-rank)
673 (message-sort-headers-1)
674 (when (setq beg (text-property-any
675 (point-min) (point-max) 'message-rank (+ 2 max)))
676 ;; We make the unwanted headers invisible.
678 (delete-region beg (point-max))
679 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
680 (gnus-article-hide-text-type beg (point-max) 'headers))
681 ;; Work around XEmacs lossage.
682 (put-text-property (point-min) beg 'invisible nil))))))))
684 (defun article-hide-boring-headers (&optional arg)
685 "Toggle hiding of headers that aren't very interesting.
686 If given a negative prefix, always show; if given a positive prefix,
688 (interactive (gnus-article-hidden-arg))
689 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
690 (not gnus-show-all-headers))
693 (let ((buffer-read-only nil)
694 (list gnus-boring-article-headers)
695 (inhibit-point-motion-hooks t)
697 (nnheader-narrow-to-headers)
699 (setq elem (pop list))
700 (goto-char (point-min))
702 ;; Hide empty headers.
704 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
706 (gnus-article-hide-text-type
707 (progn (beginning-of-line) (point))
710 (if (re-search-forward "^[^ \t]" nil t)
714 ;; Hide boring Newsgroups header.
715 ((eq elem 'newsgroups)
716 (when (equal (gnus-fetch-field "newsgroups")
717 (gnus-group-real-name
718 (if (boundp 'gnus-newsgroup-name)
721 (gnus-article-hide-header "newsgroups")))
722 ((eq elem 'followup-to)
723 (when (equal (message-fetch-field "followup-to")
724 (message-fetch-field "newsgroups"))
725 (gnus-article-hide-header "followup-to")))
727 (let ((from (message-fetch-field "from"))
728 (reply-to (message-fetch-field "reply-to")))
733 (nth 1 (mail-extract-address-components from))
734 (nth 1 (mail-extract-address-components reply-to)))))
735 (gnus-article-hide-header "reply-to"))))
737 (let ((date (message-fetch-field "date")))
739 (< (gnus-days-between (current-time-string) date)
741 (gnus-article-hide-header "date")))))))))))
743 (defun gnus-article-hide-header (header)
745 (goto-char (point-min))
746 (when (re-search-forward (concat "^" header ":") nil t)
747 (gnus-article-hide-text-type
748 (progn (beginning-of-line) (point))
751 (if (re-search-forward "^[^ \t]" nil t)
756 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
757 (defun article-treat-overstrike ()
758 "Translate overstrikes into bold text."
761 (goto-char (point-min))
762 (when (search-forward "\n\n" nil t)
763 (let ((buffer-read-only nil))
764 (while (search-forward "\b" nil t)
765 (let ((next (following-char))
766 (previous (char-after (- (point) 2))))
767 ;; We do the boldification/underlining by hiding the
768 ;; overstrikes and putting the proper text property
772 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
773 (put-text-property (point) (1+ (point)) 'face 'bold))
775 (gnus-article-hide-text-type
776 (1- (point)) (1+ (point)) 'overstrike)
778 (- (point) 2) (1- (point)) 'face 'underline))
780 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
782 (point) (1+ (point)) 'face 'underline)))))))))
784 (defun article-fill ()
785 "Format too long lines."
788 (let ((buffer-read-only nil))
790 (goto-char (point-min))
791 (search-forward "\n\n" nil t)
793 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
794 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
795 (adaptive-fill-mode t))
797 (and (>= (current-column) (min fill-column (window-width)))
798 (/= (preceding-char) ?:)
799 (fill-paragraph nil))
802 (defun article-remove-cr ()
803 "Remove carriage returns from an article."
806 (let ((buffer-read-only nil))
807 (goto-char (point-min))
808 (while (search-forward "\r" nil t)
809 (replace-match "" t t)))))
811 (defun article-remove-trailing-blank-lines ()
812 "Remove all trailing blank lines from the article."
815 (let ((buffer-read-only nil))
816 (goto-char (point-max))
820 (while (and (not (bobp))
821 (looking-at "^[ \t]*$"))
826 (defun article-display-x-face (&optional force)
827 "Look for an X-Face header and display it if present."
828 (interactive (list 'force))
830 ;; Delete the old process, if any.
831 (when (process-status "article-x-face")
832 (delete-process "article-x-face"))
833 (let ((inhibit-point-motion-hooks t)
834 (case-fold-search nil)
837 (nnheader-narrow-to-headers)
838 (setq from (message-fetch-field "from"))
839 (goto-char (point-min))
840 (while (and gnus-article-x-face-command
842 ;; Check whether this face is censored.
843 (not gnus-article-x-face-too-ugly)
844 (and gnus-article-x-face-too-ugly from
845 (not (string-match gnus-article-x-face-too-ugly
847 ;; Has to be present.
848 (re-search-forward "^X-Face: " nil t))
849 ;; We now have the area of the buffer where the X-Face is stored.
852 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
853 ;; We display the face.
854 (if (symbolp gnus-article-x-face-command)
855 ;; The command is a lisp function, so we call it.
856 (if (gnus-functionp gnus-article-x-face-command)
857 (funcall gnus-article-x-face-command beg end)
858 (error "%s is not a function" gnus-article-x-face-command))
859 ;; The command is a string, so we interpret the command
860 ;; as a, well, command, and fork it off.
861 (let ((process-connection-type nil))
862 (process-kill-without-query
864 "article-x-face" nil shell-file-name shell-command-switch
865 gnus-article-x-face-command))
866 (process-send-region "article-x-face" beg end)
867 (process-send-eof "article-x-face"))))))))))
869 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
870 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
871 (defun article-decode-rfc1522 ()
872 "Hack to remove QP encoding from headers."
873 (let ((case-fold-search t)
874 (inhibit-point-motion-hooks t)
875 (buffer-read-only nil)
879 (goto-char (point-min))
880 (or (search-forward "\n\n" nil t) (point-max)))
881 (goto-char (point-min))
882 (while (re-search-forward
883 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
884 (setq string (match-string 1))
886 (narrow-to-region (match-beginning 0) (match-end 0))
887 (delete-region (point-min) (point-max))
889 (article-mime-decode-quoted-printable
890 (goto-char (point-min)) (point-max))
891 (subst-char-in-region (point-min) (point-max) ?_ ? )
892 (goto-char (point-max)))
893 (goto-char (point-min))))))
895 (defun article-de-quoted-unreadable (&optional force)
896 "Do a naive translation of a quoted-printable-encoded article.
897 This is in no way, shape or form meant as a replacement for real MIME
898 processing, but is simply a stop-gap measure until MIME support is
900 If FORCE, decode the article whether it is marked as quoted-printable
902 (interactive (list 'force))
904 (let ((case-fold-search t)
905 (buffer-read-only nil)
906 (type (gnus-fetch-field "content-transfer-encoding")))
907 (gnus-article-decode-rfc1522)
909 (and type (string-match "quoted-printable" (downcase type))))
910 (goto-char (point-min))
911 (search-forward "\n\n" nil 'move)
912 (article-mime-decode-quoted-printable (point) (point-max))))))
914 (defun article-mime-decode-quoted-printable-buffer ()
915 "Decode Quoted-Printable in the current buffer."
916 (article-mime-decode-quoted-printable (point-min) (point-max)))
918 (defun article-mime-decode-quoted-printable (from to)
919 "Decode Quoted-Printable in the region between FROM and TO."
922 (while (search-forward "=" to t)
923 (cond ((eq (following-char) ?\n)
926 ((looking-at "[0-9A-F][0-9A-F]")
927 (subst-char-in-region
928 (1- (point)) (point) ?=
929 (hexl-hex-string-to-integer
930 (buffer-substring (point) (+ 2 (point)))))
934 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
936 (defun article-hide-pgp (&optional arg)
937 "Toggle hiding of any PGP headers and signatures in the current article.
938 If given a negative prefix, always show; if given a positive prefix,
940 (interactive (gnus-article-hidden-arg))
941 (unless (gnus-article-check-hidden-text 'pgp arg)
943 (let ((inhibit-point-motion-hooks t)
944 buffer-read-only beg end)
946 (goto-char (point-min))
947 ;; Hide the "header".
948 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
949 (gnus-article-hide-text-type (1+ (match-beginning 0))
952 ;; Hide the actual signature.
953 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
954 (setq end (1+ (match-beginning 0)))
955 (gnus-article-hide-text-type
957 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
959 ;; Perhaps we shouldn't hide to the end of the buffer
960 ;; if there is no end to the signature?
963 ;; Hide "- " PGP quotation markers.
965 (narrow-to-region beg end)
966 (goto-char (point-min))
967 (while (re-search-forward "^- " nil t)
968 (gnus-article-hide-text-type
969 (match-beginning 0) (match-end 0) 'pgp))
971 (run-hooks 'gnus-article-hide-pgp-hook))))
973 (defun article-hide-pem (&optional arg)
974 "Toggle hiding of any PEM headers and signatures in the current article.
975 If given a negative prefix, always show; if given a positive prefix,
977 (interactive (gnus-article-hidden-arg))
978 (unless (gnus-article-check-hidden-text 'pem arg)
980 (let (buffer-read-only end)
982 (goto-char (point-min))
983 ;; hide the horrendously ugly "header".
984 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
987 (setq end (1+ (match-beginning 0)))
988 (gnus-article-hide-text-type
990 (if (search-forward "\n\n" nil t)
994 ;; hide the trailer as well
995 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
998 (gnus-article-hide-text-type
999 (match-beginning 0) (match-end 0) 'pem))))))
1001 (defun article-hide-signature (&optional arg)
1002 "Hide the signature in the current article.
1003 If given a negative prefix, always show; if given a positive prefix,
1005 (interactive (gnus-article-hidden-arg))
1006 (unless (gnus-article-check-hidden-text 'signature arg)
1009 (let ((buffer-read-only nil))
1010 (when (gnus-article-narrow-to-signature)
1011 (gnus-article-hide-text-type
1012 (point-min) (point-max) 'signature)))))))
1014 (defun article-strip-leading-blank-lines ()
1015 "Remove all blank lines from the beginning of the article."
1018 (let ((inhibit-point-motion-hooks t)
1020 (goto-char (point-min))
1021 (when (search-forward "\n\n" nil t)
1022 (while (and (not (eobp))
1023 (looking-at "[ \t]*$"))
1024 (gnus-delete-line))))))
1026 (defun article-strip-multiple-blank-lines ()
1027 "Replace consecutive blank lines with one empty line."
1030 (let ((inhibit-point-motion-hooks t)
1032 ;; First make all blank lines empty.
1033 (goto-char (point-min))
1034 (search-forward "\n\n" nil t)
1035 (while (re-search-forward "^[ \t]+$" nil t)
1036 (replace-match "" nil t))
1037 ;; Then replace multiple empty lines with a single empty line.
1038 (goto-char (point-min))
1039 (search-forward "\n\n" nil t)
1040 (while (re-search-forward "\n\n\n+" nil t)
1041 (replace-match "\n\n" t t)))))
1043 (defun article-strip-leading-space ()
1044 "Remove all white space from the beginning of the lines in the article."
1047 (let ((inhibit-point-motion-hooks t)
1049 (goto-char (point-min))
1050 (search-forward "\n\n" nil t)
1051 (while (re-search-forward "^[ \t]+" nil t)
1052 (replace-match "" t t)))))
1054 (defun article-strip-blank-lines ()
1055 "Strip leading, trailing and multiple blank lines."
1057 (article-strip-leading-blank-lines)
1058 (article-remove-trailing-blank-lines)
1059 (article-strip-multiple-blank-lines))
1061 (defvar mime::preview/content-list)
1062 (defvar mime::preview-content-info/point-min)
1063 (defun gnus-article-narrow-to-signature ()
1064 "Narrow to the signature; return t if a signature is found, else nil."
1066 (when (and (boundp 'mime::preview/content-list)
1067 mime::preview/content-list)
1068 ;; We have a MIMEish article, so we use the MIME data to narrow.
1069 (let ((pcinfo (car (last mime::preview/content-list))))
1072 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1075 (when (gnus-article-search-signature)
1077 ;; Check whether we have some limits to what we consider
1078 ;; to be a signature.
1079 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1080 (list gnus-signature-limit)))
1082 (while (setq limit (pop limits))
1083 (if (or (and (integerp limit)
1084 (< (- (point-max) (point)) limit))
1086 (< (count-lines (point) (point-max)) limit))
1087 (and (gnus-functionp limit)
1089 (and (stringp limit)
1090 (not (re-search-forward limit nil t))))
1091 () ; This limit did not succeed.
1095 (narrow-to-region (point) (point-max))
1098 (defun gnus-article-search-signature ()
1099 "Search the current buffer for the signature separator.
1100 Put point at the beginning of the signature separator."
1101 (let ((cur (point)))
1102 (goto-char (point-max))
1103 (if (if (stringp gnus-signature-separator)
1104 (re-search-backward gnus-signature-separator nil t)
1105 (let ((seps gnus-signature-separator))
1107 (not (re-search-backward (car seps) nil t)))
1115 (autoload 'w3-parse-buffer "w3-parse"))
1117 (defun gnus-article-treat-html ()
1120 (let ((cbuf (current-buffer)))
1121 (set-buffer gnus-article-buffer)
1122 (let (buf buffer-read-only b e)
1123 (goto-char (point-min))
1125 (if (search-forward "\n\n" nil t)
1128 (setq e (point-max)))
1129 (nnheader-temp-write nil
1130 (insert-buffer-substring gnus-article-buffer b e)
1132 (save-window-excursion
1133 (w3-parse-buffer (current-buffer))
1134 (setq buf (buffer-string))))
1136 (delete-region (point-min) (point-max))
1139 (goto-char (point-min))
1140 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1141 (set-buffer cbuf))))
1143 (defun gnus-article-hidden-arg ()
1144 "Return the current prefix arg as a number, or 0 if no prefix."
1145 (list (if current-prefix-arg
1146 (prefix-numeric-value current-prefix-arg)
1149 (defun gnus-article-check-hidden-text (type arg)
1150 "Return nil if hiding is necessary.
1151 Arg can be nil or a number. Nil and positive means hide, negative
1152 means show, 0 means toggle."
1156 (let ((hide (gnus-article-hidden-text-p type)))
1162 (gnus-article-show-hidden-text type))
1164 (if (eq hide 'hidden)
1165 (gnus-article-show-hidden-text type)
1168 (defun gnus-article-hidden-text-p (type)
1169 "Say whether the current buffer contains hidden text of type TYPE."
1170 (let ((start (point-min))
1171 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1173 (not (get-text-property pos 'invisible)))
1175 (text-property-any (1+ pos) (point-max) 'article-type type)))
1180 (defun gnus-article-show-hidden-text (type &optional hide)
1181 "Show all hidden text of type TYPE.
1182 If HIDE, hide the text instead."
1184 (let ((buffer-read-only nil)
1185 (inhibit-point-motion-hooks t)
1188 (while (setq beg (text-property-any end (point-max) 'article-type type))
1191 (text-property-not-all beg (point-max) 'article-type type)
1194 (gnus-article-hide-text beg end gnus-hidden-properties)
1195 (gnus-article-unhide-text beg end))
1199 (defconst article-time-units
1200 `((year . ,(* 365.25 24 60 60))
1201 (week . ,(* 7 24 60 60))
1202 (day . ,(* 24 60 60))
1206 "Mapping from time units to seconds.")
1208 (defun article-date-ut (&optional type highlight header)
1209 "Convert DATE date to universal time in the current article.
1210 If TYPE is `local', convert to local time; if it is `lapsed', output
1211 how much time has lapsed since DATE."
1212 (interactive (list 'ut t))
1213 (let* ((header (or header
1214 (mail-header-date gnus-current-headers)
1215 (message-fetch-field "date")
1217 (date (if (vectorp header) (mail-header-date header)
1219 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1220 (inhibit-point-motion-hooks t)
1222 (when (and date (not (string= date "")))
1225 (nnheader-narrow-to-headers)
1226 (let ((buffer-read-only nil))
1227 ;; Delete any old Date headers.
1228 (if (re-search-forward date-regexp nil t)
1230 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1231 eface (get-text-property (1- (gnus-point-at-eol))
1233 (message-remove-header date-regexp t)
1234 (beginning-of-line))
1235 (goto-char (point-max)))
1236 (insert (article-make-date-line date type))
1239 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1240 (put-text-property (match-beginning 1) (match-end 1)
1242 (put-text-property (match-beginning 2) (match-end 2)
1245 (defun article-make-date-line (date type)
1246 "Return a DATE line of TYPE."
1248 ;; Convert to the local timezone. We have to slap a
1249 ;; `condition-case' round the calls to the timezone
1250 ;; functions since they aren't particularly resistant to
1253 (concat "Date: " (condition-case ()
1254 (timezone-make-date-arpa-standard date)
1257 ;; Convert to Universal Time.
1261 (timezone-make-date-arpa-standard date nil "UT")
1264 ;; Get the original date from the article.
1265 ((eq type 'original)
1266 (concat "Date: " date "\n"))
1267 ;; Let the user define the format.
1271 (format-time-string gnus-article-time-format
1274 (timezone-make-date-arpa-standard
1277 ;; Do an X-Sent lapsed format.
1279 ;; If the date is seriously mangled, the timezone functions are
1280 ;; liable to bug out, so we ignore all errors.
1281 (let* ((now (current-time))
1286 (timezone-make-date-arpa-standard
1287 (current-time-string now)
1288 (current-time-zone now) "UT"))
1290 (timezone-make-date-arpa-standard
1292 (real-sec (and real-time
1293 (+ (* (float (car real-time)) 65536)
1295 (sec (and real-time (abs real-sec)))
1299 "X-Sent: Unknown\n")
1305 ;; This is a bit convoluted, but basically we go
1306 ;; through the time units for years, weeks, etc,
1307 ;; and divide things to see whether that results
1308 ;; in positive answers.
1311 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1312 ;; The (remaining) seconds are too few to
1313 ;; be divided into this time unit.
1315 ;; It's big enough, so we output it.
1316 (setq sec (- sec (* num (cdr unit))))
1318 (concat (if prev ", " "") (int-to-string
1320 " " (symbol-name (car unit))
1321 (if (> num 1) "s" ""))
1323 article-time-units "")
1324 ;; If dates are odd, then it might appear like the
1325 ;; article was sent in the future.
1328 " in the future\n"))))))
1330 (error "Unknown conversion type: %s" type))))
1332 (defun article-date-local (&optional highlight)
1333 "Convert the current article date to the local timezone."
1334 (interactive (list t))
1335 (article-date-ut 'local highlight))
1337 (defun article-date-original (&optional highlight)
1338 "Convert the current article date to what it was originally.
1339 This is only useful if you have used some other date conversion
1340 function and want to see what the date was before converting."
1341 (interactive (list t))
1342 (article-date-ut 'original highlight))
1344 (defun article-date-lapsed (&optional highlight)
1345 "Convert the current article date to time lapsed since it was sent."
1346 (interactive (list t))
1347 (article-date-ut 'lapsed highlight))
1349 (defun article-date-user (&optional highlight)
1350 "Convert the current article date to the user-defined format.
1351 This format is defined by the `gnus-article-time-format' variable."
1352 (interactive (list t))
1353 (article-date-ut 'user highlight))
1355 (defun article-show-all ()
1356 "Show all hidden text in the article buffer."
1359 (let ((buffer-read-only nil))
1360 (gnus-article-unhide-text (point-min) (point-max)))))
1362 (defun article-emphasize (&optional arg)
1363 "Emphasize text according to `gnus-emphasis-alist'."
1364 (interactive (gnus-article-hidden-arg))
1365 (unless (gnus-article-check-hidden-text 'emphasis arg)
1367 (let ((alist gnus-emphasis-alist)
1368 (buffer-read-only nil)
1369 (props (append '(article-type emphasis)
1370 gnus-hidden-properties))
1371 regexp elem beg invisible visible face)
1372 (goto-char (point-min))
1373 (search-forward "\n\n" nil t)
1375 (while (setq elem (pop alist))
1377 (setq regexp (car elem)
1378 invisible (nth 1 elem)
1379 visible (nth 2 elem)
1381 (while (re-search-forward regexp nil t)
1382 (when (and (match-beginning visible) (match-beginning invisible))
1383 (gnus-article-hide-text
1384 (match-beginning invisible) (match-end invisible) props)
1385 (gnus-article-unhide-text-type
1386 (match-beginning visible) (match-end visible) 'emphasis)
1387 (gnus-put-text-property-excluding-newlines
1388 (match-beginning visible) (match-end visible) 'face face)
1389 (goto-char (match-end invisible)))))))))
1391 (defvar gnus-summary-article-menu)
1392 (defvar gnus-summary-post-menu)
1394 ;;; Saving functions.
1396 (defun gnus-article-save (save-buffer file &optional num)
1397 "Save the currently selected article."
1398 (unless gnus-save-all-headers
1399 ;; Remove headers according to `gnus-saved-headers'.
1400 (let ((gnus-visible-headers
1401 (or gnus-saved-headers gnus-visible-headers))
1402 (gnus-article-buffer save-buffer))
1403 (gnus-article-hide-headers 1 t)))
1404 (save-window-excursion
1405 (if (not gnus-default-article-saver)
1406 (error "No default saver is defined.")
1407 ;; !!! Magic! The saving functions all save
1408 ;; `gnus-original-article-buffer' (or so they think), but we
1409 ;; bind that variable to our save-buffer.
1410 (set-buffer gnus-article-buffer)
1411 (let* ((gnus-save-article-buffer save-buffer)
1414 ((not gnus-prompt-before-saving) 'default)
1415 ((eq gnus-prompt-before-saving 'always) nil)
1417 (gnus-number-of-articles-to-be-saved
1418 (when (eq gnus-prompt-before-saving t)
1420 (set-buffer gnus-summary-buffer)
1421 (funcall gnus-default-article-saver filename)))))
1423 (defun gnus-read-save-file-name (prompt &optional filename
1424 function group headers variable)
1426 (funcall function group headers (symbol-value variable)))
1431 ((eq filename 'default)
1437 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1440 (if (and gnus-number-of-articles-to-be-saved
1441 (> gnus-number-of-articles-to-be-saved 1))
1442 (format "these %d articles"
1443 gnus-number-of-articles-to-be-saved)
1446 ;; Let the split methods have their say.
1448 ;; No split name was found.
1451 (concat prompt " (default "
1452 (file-name-nondirectory default-name) ") ")
1453 (file-name-directory default-name)
1455 ;; A single group name is returned.
1456 ((stringp split-name)
1458 (funcall function split-name headers
1459 (symbol-value variable)))
1461 (concat prompt " (default "
1462 (file-name-nondirectory default-name) ") ")
1463 (file-name-directory default-name)
1465 ;; A single split name was found
1466 ((= 1 (length split-name))
1467 (let* ((name (expand-file-name
1468 (car split-name) gnus-article-save-directory))
1469 (dir (cond ((file-directory-p name)
1470 (file-name-as-directory name))
1471 ((file-exists-p name) name)
1472 (t gnus-article-save-directory))))
1474 (concat prompt " (default " name ") ")
1476 ;; A list of splits was found.
1478 (setq split-name (nreverse split-name))
1480 (let ((file-name-history
1481 (nconc split-name file-name-history)))
1485 (concat prompt " (`M-p' for defaults) ")
1486 gnus-article-save-directory
1488 gnus-article-save-directory)))
1489 (car (push result file-name-history)))))))
1490 ;; Create the directory.
1491 (gnus-make-directory (file-name-directory file))
1492 ;; If we have read a directory, we append the default file name.
1493 (when (file-directory-p file)
1494 (setq file (concat (file-name-as-directory file)
1495 (file-name-nondirectory default-name))))
1496 ;; Possibly translate some characters.
1497 (nnheader-translate-file-chars file)))))
1498 (gnus-make-directory (file-name-directory result))
1499 (set variable result)))
1501 (defun gnus-article-archive-name (group)
1502 "Return the first instance of an \"Archive-name\" in the current buffer."
1503 (let ((case-fold-search t))
1504 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1505 (nnheader-concat gnus-article-save-directory
1506 (match-string 1)))))
1508 (defun gnus-article-nndoc-name (group)
1509 "If GROUP is an nndoc group, return the name of the parent group."
1510 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1511 (gnus-group-get-parameter group 'save-article-group)))
1513 (defun gnus-summary-save-in-rmail (&optional filename)
1514 "Append this article to Rmail file.
1515 Optional argument FILENAME specifies file name.
1516 Directory to save to is default to `gnus-article-save-directory'."
1518 (gnus-set-global-variables)
1519 (setq filename (gnus-read-save-file-name
1520 "Save %s in rmail file:" filename
1521 gnus-rmail-save-name gnus-newsgroup-name
1522 gnus-current-headers 'gnus-newsgroup-last-rmail))
1523 (gnus-eval-in-buffer-window gnus-save-article-buffer
1527 (gnus-output-to-rmail filename)))))
1529 (defun gnus-summary-save-in-mail (&optional filename)
1530 "Append this article to Unix mail file.
1531 Optional argument FILENAME specifies file name.
1532 Directory to save to is default to `gnus-article-save-directory'."
1534 (gnus-set-global-variables)
1535 (setq filename (gnus-read-save-file-name
1536 "Save %s in Unix mail file:" filename
1537 gnus-mail-save-name gnus-newsgroup-name
1538 gnus-current-headers 'gnus-newsgroup-last-mail))
1539 (gnus-eval-in-buffer-window gnus-save-article-buffer
1543 (if (and (file-readable-p filename)
1544 (mail-file-babyl-p filename))
1545 (gnus-output-to-rmail filename t)
1546 (gnus-output-to-mail filename))))))
1548 (defun gnus-summary-save-in-file (&optional filename overwrite)
1549 "Append this article to file.
1550 Optional argument FILENAME specifies file name.
1551 Directory to save to is default to `gnus-article-save-directory'."
1553 (gnus-set-global-variables)
1554 (setq filename (gnus-read-save-file-name
1555 "Save %s in file:" filename
1556 gnus-file-save-name gnus-newsgroup-name
1557 gnus-current-headers 'gnus-newsgroup-last-file))
1558 (gnus-eval-in-buffer-window gnus-save-article-buffer
1562 (when (and overwrite
1563 (file-exists-p filename))
1564 (delete-file filename))
1565 (gnus-output-to-file filename)))))
1567 (defun gnus-summary-write-to-file (&optional filename)
1568 "Write this article to a file.
1569 Optional argument FILENAME specifies file name.
1570 The directory to save in defaults to `gnus-article-save-directory'."
1572 (gnus-summary-save-in-file nil t))
1574 (defun gnus-summary-save-body-in-file (&optional filename)
1575 "Append this article body to a file.
1576 Optional argument FILENAME specifies file name.
1577 The directory to save in defaults to `gnus-article-save-directory'."
1579 (gnus-set-global-variables)
1580 (setq filename (gnus-read-save-file-name
1581 "Save %s body in file:" filename
1582 gnus-file-save-name gnus-newsgroup-name
1583 gnus-current-headers 'gnus-newsgroup-last-file))
1584 (gnus-eval-in-buffer-window gnus-save-article-buffer
1588 (goto-char (point-min))
1589 (when (search-forward "\n\n" nil t)
1590 (narrow-to-region (point) (point-max)))
1591 (gnus-output-to-file filename)))))
1593 (defun gnus-summary-save-in-pipe (&optional command)
1594 "Pipe this article to subprocess."
1596 (gnus-set-global-variables)
1598 (cond ((eq command 'default)
1599 gnus-last-shell-command)
1603 "Shell command on %s: "
1604 (if (and gnus-number-of-articles-to-be-saved
1605 (> gnus-number-of-articles-to-be-saved 1))
1606 (format "these %d articles"
1607 gnus-number-of-articles-to-be-saved)
1609 gnus-last-shell-command))))
1610 (when (string-equal command "")
1611 (setq command gnus-last-shell-command))
1612 (gnus-eval-in-buffer-window gnus-article-buffer
1615 (shell-command-on-region (point-min) (point-max) command nil)))
1616 (setq gnus-last-shell-command command))
1618 ;;; Article file names when saving.
1620 (defun gnus-capitalize-newsgroup (newsgroup)
1621 "Capitalize NEWSGROUP name."
1622 (when (not (zerop (length newsgroup)))
1623 (concat (char-to-string (upcase (aref newsgroup 0)))
1624 (substring newsgroup 1))))
1626 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1627 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1628 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1629 Otherwise, it is like ~/News/news/group/num."
1632 (concat (if (gnus-use-long-file-name 'not-save)
1633 (gnus-capitalize-newsgroup newsgroup)
1634 (gnus-newsgroup-directory-form newsgroup))
1635 "/" (int-to-string (mail-header-number headers)))
1636 gnus-article-save-directory)))
1638 (string-equal (file-name-directory default)
1639 (file-name-directory last-file))
1640 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1642 (or last-file default))))
1644 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1645 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1646 If variable `gnus-use-long-file-name' is non-nil, it is
1647 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1650 (concat (if (gnus-use-long-file-name 'not-save)
1652 (gnus-newsgroup-directory-form newsgroup))
1653 "/" (int-to-string (mail-header-number headers)))
1654 gnus-article-save-directory)))
1656 (string-equal (file-name-directory default)
1657 (file-name-directory last-file))
1658 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1660 (or last-file default))))
1662 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1663 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1664 If variable `gnus-use-long-file-name' is non-nil, it is
1665 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1668 (if (gnus-use-long-file-name 'not-save)
1669 (gnus-capitalize-newsgroup newsgroup)
1670 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1671 gnus-article-save-directory)))
1673 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1674 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1675 If variable `gnus-use-long-file-name' is non-nil, it is
1676 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1679 (if (gnus-use-long-file-name 'not-save)
1681 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1682 gnus-article-save-directory)))
1689 (setq afunc (car func)
1692 gfunc (intern (format "gnus-%s" func))))
1694 (if (not (fboundp afunc))
1696 `(lambda (&optional interactive &rest args)
1697 ,(documentation afunc t)
1698 (interactive (list t))
1700 (set-buffer gnus-article-buffer)
1702 (call-interactively ',afunc)
1703 (apply ',afunc args))))))))
1704 '(article-hide-headers
1705 article-hide-boring-headers
1706 article-treat-overstrike
1707 (article-fill . gnus-article-word-wrap)
1709 article-display-x-face
1710 article-de-quoted-unreadable
1711 article-mime-decode-quoted-printable
1714 article-hide-signature
1715 article-remove-trailing-blank-lines
1716 article-strip-leading-blank-lines
1717 article-strip-multiple-blank-lines
1718 article-strip-leading-space
1719 article-strip-blank-lines
1721 article-date-original
1726 (article-show-all . gnus-article-show-all-headers))))
1729 ;;; Gnus article mode
1732 (put 'gnus-article-mode 'mode-class 'special)
1734 (gnus-define-keys gnus-article-mode-map
1735 " " gnus-article-goto-next-page
1736 "\177" gnus-article-goto-prev-page
1737 [delete] gnus-article-goto-prev-page
1738 "\C-c^" gnus-article-refer-article
1739 "h" gnus-article-show-summary
1740 "s" gnus-article-show-summary
1741 "\C-c\C-m" gnus-article-mail
1742 "?" gnus-article-describe-briefly
1743 gnus-mouse-2 gnus-article-push-button
1744 "\r" gnus-article-press-button
1745 "\t" gnus-article-next-button
1746 "\M-\t" gnus-article-prev-button
1747 "e" gnus-article-edit
1748 "<" beginning-of-buffer
1750 "\C-c\C-i" gnus-info-find-node
1753 "\C-d" gnus-article-read-summary-keys
1754 "\M-*" gnus-article-read-summary-keys
1755 "\M-#" gnus-article-read-summary-keys
1756 "\M-^" gnus-article-read-summary-keys
1757 "\M-g" gnus-article-read-summary-keys)
1759 (substitute-key-definition
1760 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1762 (defun gnus-article-make-menu-bar ()
1763 (gnus-turn-off-edit-menu 'article)
1764 (unless (boundp 'gnus-article-article-menu)
1766 gnus-article-article-menu gnus-article-mode-map ""
1768 ["Scroll forwards" gnus-article-goto-next-page t]
1769 ["Scroll backwards" gnus-article-goto-prev-page t]
1770 ["Show summary" gnus-article-show-summary t]
1771 ["Fetch Message-ID at point" gnus-article-refer-article t]
1772 ["Mail to address at point" gnus-article-mail t]))
1775 gnus-article-treatment-menu gnus-article-mode-map ""
1777 ["Hide headers" gnus-article-hide-headers t]
1778 ["Hide signature" gnus-article-hide-signature t]
1779 ["Hide citation" gnus-article-hide-citation t]
1780 ["Treat overstrike" gnus-article-treat-overstrike t]
1781 ["Remove carriage return" gnus-article-remove-cr t]
1782 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1785 (when (boundp 'gnus-summary-article-menu)
1786 (define-key gnus-article-mode-map [menu-bar commands]
1787 (cons "Commands" gnus-summary-article-menu))))
1789 (when (boundp 'gnus-summary-post-menu)
1790 (define-key gnus-article-mode-map [menu-bar post]
1791 (cons "Post" gnus-summary-post-menu)))
1793 (run-hooks 'gnus-article-menu-hook)))
1795 (defun gnus-article-mode ()
1796 "Major mode for displaying an article.
1798 All normal editing commands are switched off.
1800 The following commands are available in addition to all summary mode
1802 \\<gnus-article-mode-map>
1803 \\[gnus-article-next-page]\t Scroll the article one page forwards
1804 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1805 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1806 \\[gnus-article-show-summary]\t Display the summary buffer
1807 \\[gnus-article-mail]\t Send a reply to the address near point
1808 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1809 \\[gnus-info-find-node]\t Go to the Gnus info node"
1811 (when (gnus-visual-p 'article-menu 'menu)
1812 (gnus-article-make-menu-bar))
1813 (kill-all-local-variables)
1814 (gnus-simplify-mode-line)
1815 (setq mode-name "Article")
1816 (setq major-mode 'gnus-article-mode)
1817 (make-local-variable 'minor-mode-alist)
1818 (unless (assq 'gnus-show-mime minor-mode-alist)
1819 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1820 (use-local-map gnus-article-mode-map)
1821 (gnus-update-format-specifications nil 'article-mode)
1822 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1823 (set (make-local-variable 'gnus-page-broken) nil)
1824 (set (make-local-variable 'gnus-button-marker-list) nil)
1825 (gnus-set-default-directory)
1826 (buffer-disable-undo (current-buffer))
1827 (setq buffer-read-only t)
1828 (set-syntax-table gnus-article-mode-syntax-table)
1829 (run-hooks 'gnus-article-mode-hook))
1831 (defun gnus-article-setup-buffer ()
1832 "Initialize the article buffer."
1833 (let* ((name (if gnus-single-article-buffer "*Article*"
1834 (concat "*Article " gnus-newsgroup-name "*")))
1836 (progn (string-match "\\*Article" name)
1837 (concat " *Original Article"
1838 (substring name (match-end 0))))))
1839 (setq gnus-article-buffer name)
1840 (setq gnus-original-article-buffer original)
1841 ;; This might be a variable local to the summary buffer.
1842 (unless gnus-single-article-buffer
1844 (set-buffer gnus-summary-buffer)
1845 (setq gnus-article-buffer name)
1846 (setq gnus-original-article-buffer original)
1847 (gnus-set-global-variables)))
1848 ;; Init original article buffer.
1850 (set-buffer (get-buffer-create gnus-original-article-buffer))
1851 (buffer-disable-undo (current-buffer))
1852 (setq major-mode 'gnus-original-article-mode)
1853 (gnus-add-current-to-buffer-list)
1854 (make-local-variable 'gnus-original-article))
1855 (if (get-buffer name)
1858 (buffer-disable-undo (current-buffer))
1859 (setq buffer-read-only t)
1860 (gnus-add-current-to-buffer-list)
1861 (unless (eq major-mode 'gnus-article-mode)
1862 (gnus-article-mode))
1865 (set-buffer (get-buffer-create name))
1866 (gnus-add-current-to-buffer-list)
1868 (make-local-variable 'gnus-summary-buffer)
1869 (current-buffer)))))
1871 ;; Set article window start at LINE, where LINE is the number of lines
1872 ;; from the head of the article.
1873 (defun gnus-article-set-window-start (&optional line)
1875 (get-buffer-window gnus-article-buffer t)
1877 (set-buffer gnus-article-buffer)
1878 (goto-char (point-min))
1881 (gnus-message 6 "Moved to bookmark")
1882 (search-forward "\n\n" nil t)
1886 (defun gnus-article-prepare (article &optional all-headers header)
1887 "Prepare ARTICLE in article mode buffer.
1888 ARTICLE should either be an article number or a Message-ID.
1889 If ARTICLE is an id, HEADER should be the article headers.
1890 If ALL-HEADERS is non-nil, no headers are hidden."
1892 ;; Make sure we start in a summary buffer.
1893 (unless (eq major-mode 'gnus-summary-mode)
1894 (set-buffer gnus-summary-buffer))
1895 (setq gnus-summary-buffer (current-buffer))
1896 ;; Make sure the connection to the server is alive.
1897 (unless (gnus-server-opened
1898 (gnus-find-method-for-group gnus-newsgroup-name))
1899 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1900 (gnus-request-group gnus-newsgroup-name t))
1901 (let* ((gnus-article (if header (mail-header-number header) article))
1902 (summary-buffer (current-buffer))
1903 (internal-hook gnus-article-internal-prepare-hook)
1904 (group gnus-newsgroup-name)
1907 (gnus-article-setup-buffer)
1908 (set-buffer gnus-article-buffer)
1909 ;; Deactivate active regions.
1910 (when (and (boundp 'transient-mark-mode)
1911 transient-mark-mode)
1912 (setq mark-active nil))
1913 (if (not (setq result (let ((buffer-read-only nil))
1914 (gnus-request-article-this-buffer
1916 ;; There is no such article.
1918 (when (and (numberp article)
1919 (not (memq article gnus-newsgroup-sparse)))
1920 (setq gnus-article-current
1921 (cons gnus-newsgroup-name article))
1922 (set-buffer gnus-summary-buffer)
1923 (setq gnus-current-article article)
1924 (gnus-summary-mark-article article gnus-canceled-mark))
1925 (unless (memq article gnus-newsgroup-sparse)
1927 1 "No such article (may have expired or been canceled)")))
1928 (if (or (eq result 'pseudo) (eq result 'nneething))
1931 (set-buffer summary-buffer)
1932 (setq gnus-last-article gnus-current-article
1933 gnus-newsgroup-history (cons gnus-current-article
1934 gnus-newsgroup-history)
1935 gnus-current-article 0
1936 gnus-current-headers nil
1937 gnus-article-current nil)
1938 (if (eq result 'nneething)
1939 (gnus-configure-windows 'summary)
1940 (gnus-configure-windows 'article))
1941 (gnus-set-global-variables))
1942 (gnus-set-mode-line 'article))
1943 ;; The result from the `request' was an actual article -
1944 ;; or at least some text that is now displayed in the
1946 (when (and (numberp article)
1947 (not (eq article gnus-current-article)))
1948 ;; Seems like a new article has been selected.
1949 ;; `gnus-current-article' must be an article number.
1951 (set-buffer summary-buffer)
1952 (setq gnus-last-article gnus-current-article
1953 gnus-newsgroup-history (cons gnus-current-article
1954 gnus-newsgroup-history)
1955 gnus-current-article article
1956 gnus-current-headers
1957 (gnus-summary-article-header gnus-current-article)
1958 gnus-article-current
1959 (cons gnus-newsgroup-name gnus-current-article))
1960 (unless (vectorp gnus-current-headers)
1961 (setq gnus-current-headers nil))
1962 (gnus-summary-show-thread)
1963 (run-hooks 'gnus-mark-article-hook)
1964 (gnus-set-mode-line 'summary)
1965 (when (gnus-visual-p 'article-highlight 'highlight)
1966 (run-hooks 'gnus-visual-mark-article-hook))
1967 ;; Set the global newsgroup variables here.
1968 ;; Suggested by Jim Sisolak
1969 ;; <sisolak@trans4.neep.wisc.edu>.
1970 (gnus-set-global-variables)
1971 (setq gnus-have-all-headers
1972 (or all-headers gnus-show-all-headers))
1974 (vectorp (gnus-summary-article-header article))
1975 (gnus-cache-possibly-enter-article
1977 (gnus-summary-article-header article)
1978 (memq article gnus-newsgroup-marked)
1979 (memq article gnus-newsgroup-dormant)
1980 (memq article gnus-newsgroup-unreads)))))
1981 (when (or (numberp article)
1983 ;; Hooks for getting information from the article.
1984 ;; This hook must be called before being narrowed.
1985 (let (buffer-read-only)
1986 (run-hooks 'internal-hook)
1987 (run-hooks 'gnus-article-prepare-hook)
1988 ;; Decode MIME message.
1989 (when gnus-show-mime
1990 (if (or (not gnus-strict-mime)
1991 (gnus-fetch-field "Mime-Version"))
1992 (funcall gnus-show-mime-method)
1993 (funcall gnus-decode-encoded-word-method)))
1994 ;; Perform the article display hooks.
1995 (run-hooks 'gnus-article-display-hook))
1997 (goto-char (point-min))
1998 (setq gnus-page-broken
1999 (when gnus-break-pages
2000 (gnus-narrow-to-page)
2002 (gnus-set-mode-line 'article)
2003 (gnus-configure-windows 'article)
2004 (goto-char (point-min))
2007 (defun gnus-article-wash-status ()
2008 "Return a string which display status of article washing."
2010 (set-buffer gnus-article-buffer)
2011 (let ((cite (gnus-article-hidden-text-p 'cite))
2012 (headers (gnus-article-hidden-text-p 'headers))
2013 (boring (gnus-article-hidden-text-p 'boring-headers))
2014 (pgp (gnus-article-hidden-text-p 'pgp))
2015 (pem (gnus-article-hidden-text-p 'pem))
2016 (signature (gnus-article-hidden-text-p 'signature))
2017 (overstrike (gnus-article-hidden-text-p 'overstrike))
2018 (emphasis (gnus-article-hidden-text-p 'emphasis))
2019 (mime gnus-show-mime))
2020 (format "%c%c%c%c%c%c%c"
2022 (if (or headers boring) ?h ? )
2023 (if (or pgp pem) ?p ? )
2024 (if signature ?s ? )
2025 (if overstrike ?o ? )
2027 (if emphasis ?e ? )))))
2029 (defun gnus-article-hide-headers-if-wanted ()
2030 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2031 Provided for backwards compatibility."
2032 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2034 (gnus-article-hide-headers)))
2038 (defun gnus-output-to-file (file-name)
2039 "Append the current article to a file named FILE-NAME."
2040 (let ((artbuf (current-buffer)))
2041 (nnheader-temp-write nil
2042 (insert-buffer-substring artbuf)
2043 ;; Append newline at end of the buffer as separator, and then
2045 (goto-char (point-max))
2047 (append-to-file (point-min) (point-max) file-name))))
2049 (defun gnus-narrow-to-page (&optional arg)
2050 "Narrow the article buffer to a page.
2051 If given a numerical ARG, move forward ARG pages."
2053 (setq arg (if arg (prefix-numeric-value arg) 0))
2055 (set-buffer gnus-article-buffer)
2056 (goto-char (point-min))
2058 ;; Remove any old next/prev buttons.
2059 (when (gnus-visual-p 'page-marker)
2060 (let ((buffer-read-only nil))
2061 (gnus-remove-text-with-property 'gnus-prev)
2062 (gnus-remove-text-with-property 'gnus-next)))
2065 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2067 (re-search-forward page-delimiter nil 'move arg)))
2068 (goto-char (match-end 0)))
2071 (if (re-search-forward page-delimiter nil 'move)
2074 (when (and (gnus-visual-p 'page-marker)
2075 (not (= (point-min) 1)))
2077 (goto-char (point-min))
2078 (gnus-insert-prev-page-button)))
2079 (when (and (gnus-visual-p 'page-marker)
2080 (< (+ (point-max) 2) (buffer-size)))
2082 (goto-char (point-max))
2083 (gnus-insert-next-page-button)))))
2085 ;; Article mode commands
2087 (defun gnus-article-goto-next-page ()
2088 "Show the next page of the article."
2090 (when (gnus-article-next-page)
2091 (goto-char (point-min))
2092 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2094 (defun gnus-article-goto-prev-page ()
2095 "Show the next page of the article."
2097 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2098 (gnus-article-prev-page nil)))
2100 (defun gnus-article-next-page (&optional lines)
2101 "Show the next page of the current article.
2102 If end of article, return non-nil. Otherwise return nil.
2103 Argument LINES specifies lines to be scrolled up."
2105 (move-to-window-line -1)
2108 (and (pos-visible-in-window-p) ;Not continuation line.
2110 ;; Nothing in this page.
2111 (if (or (not gnus-page-broken)
2114 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2116 (gnus-narrow-to-page 1) ;Go to next page.
2118 ;; More in this page.
2119 (let ((scroll-in-place nil))
2123 ;; Long lines may cause an end-of-buffer error.
2124 (goto-char (point-max)))))
2125 (move-to-window-line 0)
2128 (defun gnus-article-prev-page (&optional lines)
2129 "Show previous page of current article.
2130 Argument LINES specifies lines to be scrolled down."
2132 (move-to-window-line 0)
2133 (if (and gnus-page-broken
2135 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2137 (gnus-narrow-to-page -1) ;Go to previous page.
2138 (goto-char (point-max))
2140 (let ((scroll-in-place nil))
2144 (beginning-of-buffer
2145 (goto-char (point-min))))
2146 (move-to-window-line 0)))))
2148 (defun gnus-article-refer-article ()
2149 "Read article specified by message-id around point."
2151 (let ((point (point)))
2152 (search-forward ">" nil t) ;Move point to end of "<....>".
2153 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2154 (let ((message-id (match-string 1)))
2156 (set-buffer gnus-summary-buffer)
2157 (gnus-summary-refer-article message-id))
2159 (error "No references around point"))))
2161 (defun gnus-article-show-summary ()
2162 "Reconfigure windows to show summary buffer."
2164 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2165 (error "There is no summary buffer for this article buffer")
2166 (gnus-configure-windows 'article)
2167 (gnus-summary-goto-subject gnus-current-article)))
2169 (defun gnus-article-describe-briefly ()
2170 "Describe article mode commands briefly."
2173 (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")))
2175 (defun gnus-article-summary-command ()
2176 "Execute the last keystroke in the summary buffer."
2178 (let ((obuf (current-buffer))
2179 (owin (current-window-configuration))
2181 (switch-to-buffer gnus-summary-buffer 'norecord)
2182 (setq func (lookup-key (current-local-map) (this-command-keys)))
2183 (call-interactively func)
2185 (set-window-configuration owin)
2186 (set-window-point (get-buffer-window (current-buffer)) (point))))
2188 (defun gnus-article-summary-command-nosave ()
2189 "Execute the last keystroke in the summary buffer."
2192 (pop-to-buffer gnus-summary-buffer 'norecord)
2193 (setq func (lookup-key (current-local-map) (this-command-keys)))
2194 (call-interactively func)))
2196 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2197 "Read a summary buffer key sequence and execute it from the article buffer."
2200 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2201 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2202 "=" "^" "\M-^" "|"))
2209 (set-buffer gnus-summary-buffer)
2210 (let (gnus-pick-mode)
2211 (push (or key last-command-event) unread-command-events)
2212 (setq keys (read-key-sequence nil))))
2215 (if (or (member keys nosaves)
2216 (member keys nosave-but-article)
2217 (member keys nosave-in-article))
2219 (save-window-excursion
2220 (pop-to-buffer gnus-summary-buffer 'norecord)
2221 ;; We disable the pick minor mode commands.
2222 (let (gnus-pick-mode)
2223 (setq func (lookup-key (current-local-map) keys))))
2226 (unless (member keys nosave-in-article)
2227 (set-buffer gnus-summary-buffer))
2228 (call-interactively func))
2229 (when (member keys nosave-but-article)
2230 (pop-to-buffer gnus-article-buffer 'norecord)))
2231 ;; These commands should restore window configuration.
2232 (let ((obuf (current-buffer))
2233 (owin (current-window-configuration))
2236 (if not-restore-window
2237 (pop-to-buffer gnus-summary-buffer 'norecord)
2238 (switch-to-buffer gnus-summary-buffer 'norecord))
2239 (setq in-buffer (current-buffer))
2240 ;; We disable the pick minor mode commands.
2241 (if (setq func (let (gnus-pick-mode)
2242 (lookup-key (current-local-map) keys)))
2243 (call-interactively func)
2245 (when (eq in-buffer (current-buffer))
2247 (unless not-restore-window
2248 (set-window-configuration owin))
2249 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2251 (defun gnus-article-hide (&optional arg force)
2252 "Hide all the gruft in the current article.
2253 This means that PGP stuff, signatures, cited text and (some)
2254 headers will be hidden.
2255 If given a prefix, show the hidden text instead."
2256 (interactive (list current-prefix-arg 'force))
2257 (gnus-article-hide-headers arg)
2258 (gnus-article-hide-pgp arg)
2259 (gnus-article-hide-citation-maybe arg force)
2260 (gnus-article-hide-signature arg))
2262 (defun gnus-article-maybe-highlight ()
2263 "Do some article highlighting if `article-visual' is non-nil."
2264 (when (gnus-visual-p 'article-highlight 'highlight)
2265 (gnus-article-highlight-some)))
2267 (defun gnus-request-article-this-buffer (article group)
2268 "Get an article and insert it into this buffer."
2269 (let (do-update-line)
2273 (gnus-kill-all-overlays)
2274 (setq group (or group gnus-newsgroup-name))
2276 ;; Open server if it has closed.
2277 (gnus-check-server (gnus-find-method-for-group group))
2279 ;; Using `gnus-request-article' directly will insert the article into
2280 ;; `nntp-server-buffer' - so we'll save some time by not having to
2281 ;; copy it from the server buffer into the article buffer.
2283 ;; We only request an article by message-id when we do not have the
2284 ;; headers for it, so we'll have to get those.
2285 (when (stringp article)
2286 (let ((gnus-override-method gnus-refer-article-method))
2287 (gnus-read-header article)))
2289 ;; If the article number is negative, that means that this article
2290 ;; doesn't belong in this newsgroup (possibly), so we find its
2291 ;; message-id and request it by id instead of number.
2292 (when (and (numberp article)
2294 (get-buffer gnus-summary-buffer)
2295 (buffer-name (get-buffer gnus-summary-buffer)))
2297 (set-buffer gnus-summary-buffer)
2298 (let ((header (gnus-summary-article-header article)))
2301 ((memq article gnus-newsgroup-sparse)
2302 ;; This is a sparse gap article.
2303 (setq do-update-line article)
2304 (setq article (mail-header-id header))
2305 (let ((gnus-override-method gnus-refer-article-method))
2306 (gnus-read-header article))
2307 (setq gnus-newsgroup-sparse
2308 (delq article gnus-newsgroup-sparse)))
2310 ;; It's a real article.
2311 (setq article (mail-header-id header)))
2313 ;; It is an extracted pseudo-article.
2314 (setq article 'pseudo)
2315 (gnus-request-pseudo-article header))))
2317 (let ((method (gnus-find-method-for-group
2318 gnus-newsgroup-name)))
2319 (if (not (eq (car method) 'nneething))
2321 (let ((dir (concat (file-name-as-directory (nth 1 method))
2322 (mail-header-subject header))))
2323 (when (file-directory-p dir)
2324 (setq article 'nneething)
2325 (gnus-group-enter-directory dir))))))))
2328 ;; Refuse to select canceled articles.
2329 ((and (numberp article)
2331 (get-buffer gnus-summary-buffer)
2332 (buffer-name (get-buffer gnus-summary-buffer))
2333 (eq (cdr (save-excursion
2334 (set-buffer gnus-summary-buffer)
2335 (assq article gnus-newsgroup-reads)))
2336 gnus-canceled-mark))
2338 ;; We first check `gnus-original-article-buffer'.
2339 ((and (get-buffer gnus-original-article-buffer)
2342 (set-buffer gnus-original-article-buffer)
2343 (and (equal (car gnus-original-article) group)
2344 (eq (cdr gnus-original-article) article))))
2345 (insert-buffer-substring gnus-original-article-buffer)
2347 ;; Check the backlog.
2348 ((and gnus-keep-backlog
2349 (gnus-backlog-request-article group article (current-buffer)))
2351 ;; Check asynchronous pre-fetch.
2352 ((gnus-async-request-fetched-article group article (current-buffer))
2353 (gnus-async-prefetch-next group article gnus-summary-buffer)
2356 ((and gnus-use-cache
2358 (gnus-cache-request-article article group))
2360 ;; Get the article and put into the article buffer.
2361 ((or (stringp article) (numberp article))
2362 (let ((gnus-override-method
2363 (and (stringp article) gnus-refer-article-method))
2364 (buffer-read-only nil))
2366 (gnus-kill-all-overlays)
2367 (when (gnus-request-article article group (current-buffer))
2368 (when (numberp article)
2369 (gnus-async-prefetch-next group article gnus-summary-buffer)
2370 (when gnus-keep-backlog
2371 (gnus-backlog-enter-article
2372 group article (current-buffer))))
2377 ;; Take the article from the original article buffer
2378 ;; and place it in the buffer it's supposed to be in.
2379 (when (and (get-buffer gnus-article-buffer)
2381 (equal (buffer-name (current-buffer))
2382 (buffer-name (get-buffer gnus-article-buffer))))
2384 (if (get-buffer gnus-original-article-buffer)
2385 (set-buffer (get-buffer gnus-original-article-buffer))
2386 (set-buffer (get-buffer-create gnus-original-article-buffer))
2387 (buffer-disable-undo (current-buffer))
2388 (setq major-mode 'gnus-original-article-mode)
2389 (setq buffer-read-only t)
2390 (gnus-add-current-to-buffer-list))
2391 (let (buffer-read-only)
2393 (insert-buffer-substring gnus-article-buffer))
2394 (setq gnus-original-article (cons group article))))
2396 ;; Update sparse articles.
2397 (when (and do-update-line
2398 (or (numberp article)
2400 (let ((buf (current-buffer)))
2401 (set-buffer gnus-summary-buffer)
2402 (gnus-summary-update-article do-update-line)
2403 (gnus-summary-goto-subject do-update-line nil t)
2404 (set-window-point (get-buffer-window (current-buffer) t)
2406 (set-buffer buf))))))
2412 (defcustom gnus-article-edit-mode-hook nil
2413 "Hook run in article edit mode buffers."
2414 :group 'gnus-article-various
2417 (defvar gnus-article-edit-done-function nil)
2419 (defvar gnus-article-edit-mode-map nil)
2421 (unless gnus-article-edit-mode-map
2422 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2424 (gnus-define-keys gnus-article-edit-mode-map
2425 "\C-c\C-c" gnus-article-edit-done
2426 "\C-c\C-k" gnus-article-edit-exit)
2428 (gnus-define-keys (gnus-article-edit-wash-map
2429 "\C-c\C-w" gnus-article-edit-mode-map)
2430 "f" gnus-article-edit-full-stops))
2432 (defun gnus-article-edit-mode ()
2433 "Major mode for editing articles.
2434 This is an extended text-mode.
2436 \\{gnus-article-edit-mode-map}"
2438 (kill-all-local-variables)
2439 (setq major-mode 'gnus-article-edit-mode)
2440 (setq mode-name "Article Edit")
2441 (use-local-map gnus-article-edit-mode-map)
2442 (make-local-variable 'gnus-article-edit-done-function)
2443 (make-local-variable 'gnus-prev-winconf)
2444 (setq buffer-read-only nil)
2445 (buffer-enable-undo)
2447 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2449 (defun gnus-article-edit (&optional force)
2450 "Edit the current article.
2451 This will have permanent effect only in mail groups.
2452 If FORCE is non-nil, allow editing of articles even in read-only
2455 (when (and (not force)
2456 (gnus-group-read-only-p))
2457 (error "The current newsgroup does not support article editing."))
2458 (gnus-article-edit-article
2460 (gnus-summary-edit-article-done
2461 ,(or (mail-header-references gnus-current-headers) "")
2462 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2464 (defun gnus-article-edit-article (exit-func)
2465 "Start editing the contents of the current article buffer."
2466 (let ((winconf (current-window-configuration)))
2467 (set-buffer gnus-article-buffer)
2468 (gnus-article-edit-mode)
2469 (gnus-set-text-properties (point-min) (point-max) nil)
2470 (gnus-configure-windows 'edit-article)
2471 (setq gnus-article-edit-done-function exit-func)
2472 (setq gnus-prev-winconf winconf)
2473 (gnus-message 6 "C-c C-c to end edits")))
2475 (defun gnus-article-edit-done ()
2476 "Update the article edits and exit."
2478 (let ((func gnus-article-edit-done-function)
2479 (buf (current-buffer))
2480 (start (window-start)))
2481 (gnus-article-edit-exit)
2484 (let ((buffer-read-only nil))
2487 (set-window-start (get-buffer-window buf) start)
2488 (set-window-point (get-buffer-window buf) (point))))
2490 (defun gnus-article-edit-exit ()
2491 "Exit the article editing without updating."
2493 ;; We remove all text props from the article buffer.
2494 (let ((buf (format "%s" (buffer-string)))
2495 (curbuf (current-buffer))
2497 (window-start (window-start)))
2500 (let ((winconf gnus-prev-winconf))
2502 ;; The cache and backlog have to be flushed somewhat.
2503 (when gnus-use-cache
2504 (gnus-cache-update-article
2505 (car gnus-article-current) (cdr gnus-article-current)))
2506 (when gnus-keep-backlog
2507 (gnus-backlog-remove-article
2508 (car gnus-article-current) (cdr gnus-article-current)))
2509 ;; Flush original article as well.
2511 (when (get-buffer gnus-original-article-buffer)
2512 (set-buffer gnus-original-article-buffer)
2513 (setq gnus-original-article nil)))
2514 (set-window-configuration winconf)
2515 ;; Tippy-toe some to make sure that point remains where it was.
2516 (let ((buf (current-buffer)))
2518 (set-window-start (get-buffer-window (current-buffer)) window-start)
2520 (set-buffer buf)))))
2522 (defun gnus-article-edit-full-stops ()
2523 "Interactively repair spacing at end of sentences."
2526 (goto-char (point-min))
2527 (search-forward-regexp "^$" nil t)
2528 (let ((case-fold-search nil))
2529 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2532 ;;; Article highlights
2535 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2537 ;;; Internal Variables:
2539 (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\\)"
2540 "Regular expression that matches URLs."
2541 :group 'gnus-article-buttons
2544 (defcustom gnus-button-alist
2545 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2546 gnus-button-message-id 2)
2547 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2548 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2549 gnus-button-fetch-group 4)
2550 ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2551 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2552 t gnus-button-message-id 3)
2553 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1)
2554 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2)
2555 ;; This is how URLs _should_ be embedded in text...
2556 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2558 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2559 "Alist of regexps matching buttons in article bodies.
2561 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2562 REGEXP: is the string matching text around the button,
2563 BUTTON: is the number of the regexp grouping actually matching the button,
2564 FORM: is a lisp expression which must eval to true for the button to
2566 CALLBACK: is the function to call when the user push this button, and each
2567 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2569 CALLBACK can also be a variable, in that case the value of that
2570 variable it the real callback function."
2571 :group 'gnus-article-buttons
2572 :type '(repeat (list regexp
2573 (integer :tag "Button")
2575 (function :tag "Callback")
2578 (integer :tag "Regexp group")))))
2580 (defcustom gnus-header-button-alist
2581 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2582 0 t gnus-button-message-id 0)
2583 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2584 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2585 0 t gnus-button-mailto 0)
2586 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2587 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2588 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2589 gnus-button-message-id 3))
2590 "Alist of headers and regexps to match buttons in article heads.
2592 This alist is very similar to `gnus-button-alist', except that each
2593 alist has an additional HEADER element first in each entry:
2595 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2597 HEADER is a regexp to match a header. For a fuller explanation, see
2598 `gnus-button-alist'."
2599 :group 'gnus-article-buttons
2600 :group 'gnus-article-headers
2601 :type '(repeat (list (regexp :tag "Header")
2603 (integer :tag "Button")
2605 (function :tag "Callback")
2608 (integer :tag "Regexp group")))))
2610 (defvar gnus-button-regexp nil)
2611 (defvar gnus-button-marker-list nil)
2612 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2614 (defvar gnus-button-last nil)
2615 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2619 (defun gnus-article-push-button (event)
2620 "Check text under the mouse pointer for a callback function.
2621 If the text under the mouse pointer has a `gnus-callback' property,
2622 call it with the value of the `gnus-data' text property."
2624 (set-buffer (window-buffer (posn-window (event-start event))))
2625 (let* ((pos (posn-point (event-start event)))
2626 (data (get-text-property pos 'gnus-data))
2627 (fun (get-text-property pos 'gnus-callback)))
2629 (funcall fun data))))
2631 (defun gnus-article-press-button ()
2632 "Check text at point for a callback function.
2633 If the text at point has a `gnus-callback' property,
2634 call it with the value of the `gnus-data' text property."
2636 (let* ((data (get-text-property (point) 'gnus-data))
2637 (fun (get-text-property (point) 'gnus-callback)))
2639 (funcall fun data))))
2641 (defun gnus-article-prev-button (n)
2642 "Move point to N buttons backward.
2643 If N is negative, move forward instead."
2645 (gnus-article-next-button (- n)))
2647 (defun gnus-article-next-button (n)
2648 "Move point to N buttons forward.
2649 If N is negative, move backward instead."
2651 (let ((function (if (< n 0) 'previous-single-property-change
2652 'next-single-property-change))
2653 (inhibit-point-motion-hooks t)
2655 (limit (if (< n 0) (point-min) (point-max))))
2657 (while (and (not (= limit (point)))
2659 ;; Skip past the current button.
2660 (when (get-text-property (point) 'gnus-callback)
2661 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2662 ;; Go to the next (or previous) button.
2663 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2664 ;; Put point at the start of the button.
2665 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2666 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2667 ;; Skip past intangible buttons.
2668 (when (get-text-property (point) 'intangible)
2672 (gnus-message 5 "No more buttons"))
2675 (defun gnus-article-highlight (&optional force)
2676 "Highlight current article.
2677 This function calls `gnus-article-highlight-headers',
2678 `gnus-article-highlight-citation',
2679 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2680 do the highlighting. See the documentation for those functions."
2681 (interactive (list 'force))
2682 (gnus-article-highlight-headers)
2683 (gnus-article-highlight-citation force)
2684 (gnus-article-highlight-signature)
2685 (gnus-article-add-buttons force)
2686 (gnus-article-add-buttons-to-head))
2688 (defun gnus-article-highlight-some (&optional force)
2689 "Highlight current article.
2690 This function calls `gnus-article-highlight-headers',
2691 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2692 do the highlighting. See the documentation for those functions."
2693 (interactive (list 'force))
2694 (gnus-article-highlight-headers)
2695 (gnus-article-highlight-signature)
2696 (gnus-article-add-buttons))
2698 (defun gnus-article-highlight-headers ()
2699 "Highlight article headers as specified by `gnus-header-face-alist'."
2702 (set-buffer gnus-article-buffer)
2704 (let ((alist gnus-header-face-alist)
2705 (buffer-read-only nil)
2706 (case-fold-search t)
2707 (inhibit-point-motion-hooks t)
2708 entry regexp header-face field-face from hpoints fpoints)
2709 (message-narrow-to-head)
2710 (while (setq entry (pop alist))
2711 (goto-char (point-min))
2712 (setq regexp (concat "^\\("
2713 (if (string-equal "" (nth 0 entry))
2717 header-face (nth 1 entry)
2718 field-face (nth 2 entry))
2719 (while (and (re-search-forward regexp nil t)
2723 (unless (search-forward ":" nil t)
2725 (when (and header-face
2726 (not (memq (point) hpoints)))
2727 (push (point) hpoints)
2728 (gnus-put-text-property from (point) 'face header-face))
2729 (when (and field-face
2730 (not (memq (setq from (point)) fpoints)))
2732 (if (re-search-forward "^[^ \t]" nil t)
2734 (goto-char (point-max)))
2735 (gnus-put-text-property from (point) 'face field-face))))))))
2737 (defun gnus-article-highlight-signature ()
2738 "Highlight the signature in an article.
2739 It does this by highlighting everything after
2740 `gnus-signature-separator' using `gnus-signature-face'."
2743 (set-buffer gnus-article-buffer)
2744 (let ((buffer-read-only nil)
2745 (inhibit-point-motion-hooks t))
2747 (when (and gnus-signature-face
2748 (gnus-article-narrow-to-signature))
2749 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2750 'face gnus-signature-face)
2752 (gnus-article-search-signature)
2753 (let ((start (match-beginning 0))
2754 (end (set-marker (make-marker) (1+ (match-end 0)))))
2755 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2758 (defun gnus-button-in-region-p (b e prop)
2759 "Say whether PROP exists in the region."
2760 (text-property-not-all b e prop nil))
2762 (defun gnus-article-add-buttons (&optional force)
2763 "Find external references in the article and make buttons of them.
2764 \"External references\" are things like Message-IDs and URLs, as
2765 specified by `gnus-button-alist'."
2766 (interactive (list 'force))
2768 (set-buffer gnus-article-buffer)
2769 (let ((buffer-read-only nil)
2770 (inhibit-point-motion-hooks t)
2771 (case-fold-search t)
2772 (alist gnus-button-alist)
2774 ;; Remove all old markers.
2776 (while (setq marker (pop gnus-button-marker-list))
2778 (when (setq entry (gnus-button-entry))
2779 (put-text-property (match-beginning (nth 1 entry))
2780 (match-end (nth 1 entry))
2781 'gnus-callback nil))
2782 (set-marker marker nil)))
2783 ;; We skip the headers.
2784 (goto-char (point-min))
2785 (unless (search-forward "\n\n" nil t)
2786 (goto-char (point-max)))
2788 (while (setq entry (pop alist))
2789 (setq regexp (car entry))
2791 (while (re-search-forward regexp nil t)
2792 (let* ((start (and entry (match-beginning (nth 1 entry))))
2793 (end (and entry (match-end (nth 1 entry))))
2794 (from (match-beginning 0)))
2795 (when (and (or (eq t (nth 2 entry))
2796 (eval (nth 2 entry)))
2797 (not (gnus-button-in-region-p
2798 start end 'gnus-callback)))
2799 ;; That optional form returned non-nil, so we add the
2801 (gnus-article-add-button
2802 start end 'gnus-button-push
2803 (car (push (set-marker (make-marker) from)
2804 gnus-button-marker-list))))))))))
2806 ;; Add buttons to the head of an article.
2807 (defun gnus-article-add-buttons-to-head ()
2808 "Add buttons to the head of the article."
2811 (set-buffer gnus-article-buffer)
2812 (let ((buffer-read-only nil)
2813 (inhibit-point-motion-hooks t)
2814 (case-fold-search t)
2815 (alist gnus-header-button-alist)
2817 (nnheader-narrow-to-headers)
2819 ;; Each alist entry.
2820 (setq entry (car alist)
2822 (goto-char (point-min))
2823 (while (re-search-forward (car entry) nil t)
2824 ;; Each header matching the entry.
2825 (setq beg (match-beginning 0))
2826 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2827 (match-beginning 0))
2830 (while (re-search-forward (nth 1 entry) end t)
2831 ;; Each match within a header.
2832 (let* ((entry (cdr entry))
2833 (start (match-beginning (nth 1 entry)))
2834 (end (match-end (nth 1 entry)))
2835 (form (nth 2 entry)))
2836 (goto-char (match-end 0))
2838 (gnus-article-add-button
2839 start end (nth 3 entry)
2840 (buffer-substring (match-beginning (nth 4 entry))
2841 (match-end (nth 4 entry)))))))
2845 ;;; External functions:
2847 (defun gnus-article-add-button (from to fun &optional data)
2848 "Create a button between FROM and TO with callback FUN and data DATA."
2849 (when gnus-article-button-face
2850 (gnus-overlay-put (gnus-make-overlay from to)
2851 'face gnus-article-button-face))
2852 (gnus-add-text-properties
2854 (nconc (and gnus-article-mouse-face
2855 (list gnus-mouse-face-prop gnus-article-mouse-face))
2856 (list 'gnus-callback fun)
2857 (and data (list 'gnus-data data)))))
2859 ;;; Internal functions:
2861 (defun gnus-signature-toggle (end)
2863 (set-buffer gnus-article-buffer)
2864 (let ((buffer-read-only nil)
2865 (inhibit-point-motion-hooks t))
2866 (if (get-text-property end 'invisible)
2867 (gnus-article-unhide-text end (point-max))
2868 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2870 (defun gnus-button-entry ()
2871 ;; Return the first entry in `gnus-button-alist' matching this place.
2872 (let ((alist gnus-button-alist)
2875 (setq entry (pop alist))
2876 (if (looking-at (car entry))
2881 (defun gnus-button-push (marker)
2882 ;; Push button starting at MARKER.
2884 (set-buffer gnus-article-buffer)
2886 (let* ((entry (gnus-button-entry))
2887 (inhibit-point-motion-hooks t)
2889 (args (mapcar (lambda (group)
2890 (let ((string (match-string group)))
2891 (gnus-set-text-properties
2892 0 (length string) nil string)
2899 (fboundp (symbol-value fun)))
2900 (apply (symbol-value fun) args))
2902 (gnus-message 1 "You must define `%S' to use this button"
2903 (cons fun args)))))))
2905 (defun gnus-button-message-id (message-id)
2908 (set-buffer gnus-summary-buffer)
2909 (gnus-summary-refer-article message-id)))
2911 (defun gnus-button-fetch-group (address)
2912 "Fetch GROUP specified by ADDRESS."
2913 (if (not (string-match "[:/]" address))
2914 ;; This is just a simple group url.
2915 (gnus-group-read-ephemeral-group address gnus-select-method)
2916 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
2918 (error "Can't parse %s" address)
2919 (gnus-group-read-ephemeral-group
2920 (match-string 4 address)
2921 `(nntp ,(match-string 1 address)
2922 (nntp-address ,(match-string 1 address))
2923 (nntp-port-number ,(if (match-end 3)
2924 (match-string 3 address)
2927 (defun gnus-split-string (string pattern)
2928 "Return a list of substrings of STRING which are separated by PATTERN."
2929 (let (parts (start 0))
2930 (while (string-match pattern string start)
2931 (setq parts (cons (substring string start (match-beginning 0)) parts)
2932 start (match-end 0)))
2933 (nreverse (cons (substring string start) parts))))
2935 (defun gnus-url-parse-query-string (query &optional downcase)
2936 (let (retval pairs cur key val)
2937 (setq pairs (gnus-split-string query "&"))
2939 (setq cur (car pairs)
2941 (if (not (string-match "=" cur))
2943 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2944 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2946 (setq key (downcase key)))
2947 (setq cur (assoc key retval))
2949 (setcdr cur (cons val (cdr cur)))
2950 (setq retval (cons (list key val) retval)))))
2953 (defun gnus-url-unhex (x)
2960 (defun gnus-url-unhex-string (str &optional allow-newlines)
2961 "Remove %XXX embedded spaces, etc in a url.
2962 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2963 decoding of carriage returns and line feeds in the string, which is normally
2964 forbidden in URL encoding."
2965 (setq str (or str ""))
2967 (case-fold-search t))
2968 (while (string-match "%[0-9a-f][0-9a-f]" str)
2969 (let* ((start (match-beginning 0))
2970 (ch1 (gnus-url-unhex (elt str (+ start 1))))
2972 (gnus-url-unhex (elt str (+ start 2))))))
2974 tmp (substring str 0 start)
2977 (char-to-string code))
2978 ((or (= code ?\n) (= code ?\r))
2980 (t (char-to-string code))))
2981 str (substring str (match-end 0)))))
2982 (setq tmp (concat tmp str))
2985 (defun gnus-url-mailto (url)
2986 ;; Send mail to someone
2987 (when (string-match "mailto:/*\\(.*\\)" url)
2988 (setq url (substring url (match-beginning 1) nil)))
2989 (let (to args source-url subject func)
2990 (if (string-match (regexp-quote "?") url)
2991 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2992 args (gnus-url-parse-query-string
2993 (substring url (match-end 0) nil) t))
2994 (setq to (gnus-url-unhex-string url)))
2995 (setq args (cons (list "to" to) args)
2996 subject (cdr-safe (assoc "subject" args)))
2999 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3002 (message-position-on-field (caar args)))
3003 (insert (mapconcat 'identity (cdar args) ", "))
3004 (setq args (cdr args)))
3007 (message-goto-subject))))
3009 (defun gnus-button-mailto (address)
3011 (set-buffer (gnus-copy-article-buffer))
3012 (message-reply address))
3014 (defun gnus-button-reply (address)
3015 ;; Reply to ADDRESS.
3016 (message-reply address))
3018 (defun gnus-button-url (address)
3020 (funcall browse-url-browser-function address))
3022 (defun gnus-button-embedded-url (address)
3024 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3026 ;;; Next/prev buttons in the article buffer.
3028 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3029 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3031 (defvar gnus-prev-page-map nil)
3032 (unless gnus-prev-page-map
3033 (setq gnus-prev-page-map (make-sparse-keymap))
3034 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3035 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3037 (defun gnus-insert-prev-page-button ()
3038 (let ((buffer-read-only nil))
3040 gnus-prev-page-line-format nil
3041 `(gnus-prev t local-map ,gnus-prev-page-map
3042 gnus-callback gnus-article-button-prev-page))))
3044 (defvar gnus-next-page-map nil)
3045 (unless gnus-next-page-map
3046 (setq gnus-next-page-map (make-keymap))
3047 (suppress-keymap gnus-prev-page-map)
3048 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3049 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3051 (defun gnus-button-next-page ()
3052 "Go to the next page."
3054 (let ((win (selected-window)))
3055 (select-window (get-buffer-window gnus-article-buffer t))
3056 (gnus-article-next-page)
3057 (select-window win)))
3059 (defun gnus-button-prev-page ()
3060 "Go to the prev page."
3062 (let ((win (selected-window)))
3063 (select-window (get-buffer-window gnus-article-buffer t))
3064 (gnus-article-prev-page)
3065 (select-window win)))
3067 (defun gnus-insert-next-page-button ()
3068 (let ((buffer-read-only nil))
3069 (gnus-eval-format gnus-next-page-line-format nil
3070 `(gnus-next t local-map ,gnus-next-page-map
3072 gnus-article-button-next-page))))
3074 (defun gnus-article-button-next-page (arg)
3075 "Go to the next page."
3077 (let ((win (selected-window)))
3078 (select-window (get-buffer-window gnus-article-buffer t))
3079 (gnus-article-next-page)
3080 (select-window win)))
3082 (defun gnus-article-button-prev-page (arg)
3083 "Go to the prev page."
3085 (let ((win (selected-window)))
3086 (select-window (get-buffer-window gnus-article-buffer t))
3087 (gnus-article-prev-page)
3088 (select-window win)))
3094 (run-hooks 'gnus-art-load-hook)
3096 ;;; gnus-art.el ends here