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:" "^To:"
119 "^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\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"\)]\\)")
179 '(("_" "_" underline)
182 ;;("_/" "/_" underline-italic)
183 ;;("_\\*" "\\*_" underline-bold)
184 ("\\*/" "/\\*" bold-italic)
185 ;;("_\\*/" "/\\*_" underline-bold-italic)
187 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
188 2 3 gnus-emphasis-underline)
192 (format format (car spec) (cadr spec))
193 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
195 "Alist that says how to fontify certain phrases.
196 Each item looks like this:
198 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
200 The first element is a regular expression to be matched. The second
201 is a number that says what regular expression grouping used to find
202 the entire emphasized word. The third is a number that says what
203 regexp grouping should be displayed and highlighted. The fourth
204 is the face used for highlighting."
205 :type '(repeat (list :value ("" 0 0 default)
207 (integer :tag "Match group")
208 (integer :tag "Emphasize group")
210 :group 'gnus-article-emphasis)
212 (defface gnus-emphasis-bold '((t (:bold t)))
213 "Face used for displaying strong emphasized text (*word*)."
214 :group 'gnus-article-emphasis)
216 (defface gnus-emphasis-italic '((t (:italic t)))
217 "Face used for displaying italic emphasized text (/word/)."
218 :group 'gnus-article-emphasis)
220 (defface gnus-emphasis-underline '((t (:underline t)))
221 "Face used for displaying underlined emphasized text (_word_)."
222 :group 'gnus-article-emphasis)
224 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
225 "Face used for displaying underlined bold emphasized text (_*word*_)."
226 :group 'gnus-article-emphasis)
228 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
229 "Face used for displaying underlined italic emphasized text (_*word*_)."
230 :group 'gnus-article-emphasis)
232 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
233 "Face used for displaying bold italic emphasized text (/*word*/)."
234 :group 'gnus-article-emphasis)
236 (defface gnus-emphasis-underline-bold-italic
237 '((t (:bold t :italic t :underline t)))
238 "Face used for displaying underlined bold italic emphasized text.
239 Esample: (_/*word*/_)."
240 :group 'gnus-article-emphasis)
242 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
243 "Format for display of Date headers in article bodies.
244 See `format-time-zone' for the possible values."
246 :link '(custom-manual "(gnus)Article Date")
247 :group 'gnus-article-washing)
250 (autoload 'hexl-hex-string-to-integer "hexl")
251 (autoload 'timezone-make-date-arpa-standard "timezone")
252 (autoload 'mail-extract-address-components "mail-extr"))
254 (defcustom gnus-article-save-directory gnus-directory
255 "*Name of the directory articles will be saved in (default \"~/News\")."
256 :group 'gnus-article-saving
259 (defcustom gnus-save-all-headers t
260 "*If non-nil, don't remove any headers before saving."
261 :group 'gnus-article-saving
264 (defcustom gnus-prompt-before-saving 'always
265 "*This variable says how much prompting is to be done when saving articles.
266 If it is nil, no prompting will be done, and the articles will be
267 saved to the default files. If this variable is `always', each and
268 every article that is saved will be preceded by a prompt, even when
269 saving large batches of articles. If this variable is neither nil not
270 `always', there the user will be prompted once for a file name for
271 each invocation of the saving commands."
272 :group 'gnus-article-saving
273 :type '(choice (item always)
274 (item :tag "never" nil)
275 (sexp :tag "once" :format "%t")))
277 (defcustom gnus-saved-headers gnus-visible-headers
278 "Headers to keep if `gnus-save-all-headers' is nil.
279 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
280 If that variable is nil, however, all headers that match this regexp
281 will be kept while the rest will be deleted before saving."
282 :group 'gnus-article-saving
283 :type '(repeat string))
285 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
286 "A function to save articles in your favourite format.
287 The function must be interactively callable (in other words, it must
288 be an Emacs command).
290 Gnus provides the following functions:
292 * gnus-summary-save-in-rmail (Rmail format)
293 * gnus-summary-save-in-mail (Unix mail format)
294 * gnus-summary-save-in-folder (MH folder)
295 * gnus-summary-save-in-file (article format)
296 * gnus-summary-save-in-vm (use VM's folder format)
297 * gnus-summary-write-to-file (article format -- overwrite)."
298 :group 'gnus-article-saving
299 :type '(radio (function-item gnus-summary-save-in-rmail)
300 (function-item gnus-summary-save-in-mail)
301 (function-item gnus-summary-save-in-folder)
302 (function-item gnus-summary-save-in-file)
303 (function-item gnus-summary-save-in-vm)
304 (function-item gnus-summary-write-to-file)))
306 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
307 "A function generating a file name to save articles in Rmail format.
308 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
309 :group 'gnus-article-saving
312 (defcustom gnus-mail-save-name 'gnus-plain-save-name
313 "A function generating a file name to save articles in Unix mail format.
314 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
315 :group 'gnus-article-saving
318 (defcustom gnus-folder-save-name 'gnus-folder-save-name
319 "A function generating a file name to save articles in MH folder.
320 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
321 :group 'gnus-article-saving
324 (defcustom gnus-file-save-name 'gnus-numeric-save-name
325 "A function generating a file name to save articles in article format.
326 The function is called with NEWSGROUP, HEADERS, and optional
328 :group 'gnus-article-saving
331 (defcustom gnus-split-methods
332 '((gnus-article-archive-name))
333 "Variable used to suggest where articles are to be saved.
334 For instance, if you would like to save articles related to Gnus in
335 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
336 you could set this variable to something like:
338 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
339 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
341 This variable is an alist where the where the key is the match and the
342 value is a list of possible files to save in if the match is non-nil.
344 If the match is a string, it is used as a regexp match on the
345 article. If the match is a symbol, that symbol will be funcalled
346 from the buffer of the article to be saved with the newsgroup as the
347 parameter. If it is a list, it will be evaled in the same buffer.
349 If this form or function returns a string, this string will be used as
350 a possible file name; and if it returns a non-nil list, that list will
351 be used as possible file names."
352 :group 'gnus-article-saving
353 :type '(repeat (choice (list function)
354 (cons regexp (repeat string))
357 (defcustom gnus-strict-mime t
358 "*If nil, MIME-decode even if there is no Mime-Version header."
359 :group 'gnus-article-mime
362 (defcustom gnus-show-mime-method 'metamail-buffer
363 "Function to process a MIME message.
364 The function is called from the article buffer."
365 :group 'gnus-article-mime
368 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
369 "*Function to decode MIME encoded words.
370 The function is called from the article buffer."
371 :group 'gnus-article-mime
374 (defcustom gnus-page-delimiter "^\^L"
375 "*Regexp describing what to use as article page delimiters.
376 The default value is \"^\^L\", which is a form linefeed at the
377 beginning of a line."
379 :group 'gnus-article-various)
381 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
382 "*The format specification for the article mode line.
383 See `gnus-summary-mode-line-format' for a closer description."
385 :group 'gnus-article-various)
387 (defcustom gnus-article-mode-hook nil
388 "*A hook for Gnus article mode."
390 :group 'gnus-article-various)
392 (defcustom gnus-article-menu-hook nil
393 "*Hook run after the creation of the article mode menu."
395 :group 'gnus-article-various)
397 (defcustom gnus-article-prepare-hook nil
398 "*A hook called after an article has been prepared in the article buffer.
399 If you want to run a special decoding program like nkf, use this hook."
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 'italic
420 "Face used for highlighting a signature in the article buffer."
422 :group 'gnus-article-highlight
423 :group 'gnus-article-signature)
425 (defface gnus-header-from-face
428 (:foreground "light blue" :bold t :italic t))
431 (:foreground "MidnightBlue" :bold t :italic t))
433 (:bold t :italic t)))
434 "Face used for displaying from headers."
435 :group 'gnus-article-headers
436 :group 'gnus-article-highlight)
438 (defface gnus-header-subject-face
441 (:foreground "pink" :bold t :italic t))
444 (:foreground "firebrick" :bold t :italic t))
446 (:bold t :italic t)))
447 "Face used for displaying subject headers."
448 :group 'gnus-article-headers
449 :group 'gnus-article-highlight)
451 (defface gnus-header-newsgroups-face
454 (:foreground "yellow" :bold t :italic t))
457 (:foreground "indianred" :bold t :italic t))
459 (:bold t :italic t)))
460 "Face used for displaying newsgroups headers."
461 :group 'gnus-article-headers
462 :group 'gnus-article-highlight)
464 (defface gnus-header-name-face
467 (:foreground "cyan" :bold t))
470 (:foreground "DarkGreen" :bold t))
473 "Face used for displaying header names."
474 :group 'gnus-article-headers
475 :group 'gnus-article-highlight)
477 (defface gnus-header-content-face
480 (:foreground "forest green" :italic t))
483 (:foreground "DarkGreen" :italic t))
485 (:italic t))) "Face used for displaying header content."
486 :group 'gnus-article-headers
487 :group 'gnus-article-highlight)
489 (defcustom gnus-header-face-alist
490 '(("From" nil gnus-header-from-face)
491 ("Subject" nil gnus-header-subject-face)
492 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
493 ("" gnus-header-name-face gnus-header-content-face))
494 "Controls highlighting of article header.
496 An alist of the form (HEADER NAME CONTENT).
498 HEADER is a regular expression which should match the name of an
499 header header and NAME and CONTENT are either face names or nil.
501 The name of each header field will be displayed using the face
502 specified by the first element in the list where HEADER match the
503 header name and NAME is non-nil. Similarly, the content will be
504 displayed by the first non-nil matching CONTENT face."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight
507 :type '(repeat (list (regexp :tag "Header")
509 (item :tag "skip" nil)
510 (face :value default))
511 (choice :tag "Content"
512 (item :tag "skip" nil)
513 (face :value default)))))
515 ;;; Internal variables
517 (defvar gnus-article-mode-syntax-table
518 (let ((table (copy-syntax-table text-mode-syntax-table)))
519 ;;(modify-syntax-entry ?_ "w" table)
521 "Syntax table used in article mode buffers.
522 Initialized from `text-mode-syntax-table.")
524 (defvar gnus-save-article-buffer nil)
526 (defvar gnus-article-mode-line-format-alist
527 (nconc '((?w (gnus-article-wash-status) ?s))
528 gnus-summary-mode-line-format-alist))
530 (defvar gnus-number-of-articles-to-be-saved nil)
532 (defvar gnus-inhibit-hiding nil)
533 (defvar gnus-newsgroup-name)
535 (defsubst gnus-article-hide-text (b e props)
536 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
537 (add-text-properties b e props)
538 (when (memq 'intangible props)
540 (max (1- b) (point-min))
541 b 'intangible (cddr (memq 'intangible props)))))
543 (defsubst gnus-article-unhide-text (b e)
544 "Remove hidden text properties from region between B and E."
545 (remove-text-properties b e gnus-hidden-properties)
546 (when (memq 'intangible gnus-hidden-properties)
547 (put-text-property (max (1- b) (point-min))
550 (defun gnus-article-hide-text-type (b e type)
551 "Hide text of TYPE between B and E."
552 (gnus-article-hide-text
553 b e (cons 'article-type (cons type gnus-hidden-properties))))
555 (defun gnus-article-unhide-text-type (b e type)
556 "Hide text of TYPE between B and E."
557 (remove-text-properties
558 b e (cons 'article-type (cons type gnus-hidden-properties)))
559 (when (memq 'intangible gnus-hidden-properties)
560 (put-text-property (max (1- b) (point-min))
563 (defun gnus-article-hide-text-of-type (type)
564 "Hide text of TYPE in the current buffer."
566 (let ((b (point-min))
568 (while (setq b (text-property-any b e 'article-type type))
569 (add-text-properties b (incf b) gnus-hidden-properties)))))
571 (defun gnus-article-delete-text-of-type (type)
572 "Delete text of TYPE in the current buffer."
574 (let ((b (point-min)))
575 (while (setq b (text-property-any b (point-max) 'article-type type))
576 (delete-region b (incf b))))))
578 (defun gnus-article-delete-invisible-text ()
579 "Delete all invisible text in the current buffer."
581 (let ((b (point-min)))
582 (while (setq b (text-property-any b (point-max) 'invisible t))
583 (delete-region b (incf b))))))
585 (defun gnus-article-text-type-exists-p (type)
586 "Say whether any text of type TYPE exists in the buffer."
587 (text-property-any (point-min) (point-max) 'article-type type))
589 (defsubst gnus-article-header-rank ()
590 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
591 (let ((list gnus-sorted-header-list)
594 (when (looking-at (car list))
596 (setq list (cdr list))
600 (defun article-hide-headers (&optional arg delete)
601 "Toggle whether to hide unwanted headers and possibly sort them as well.
602 If given a negative prefix, always show; if given a positive prefix,
604 (interactive (gnus-article-hidden-arg))
605 (if (gnus-article-check-hidden-text 'headers arg)
606 ;; Show boring headers as well.
607 (gnus-article-show-hidden-text 'boring-headers)
608 ;; This function might be inhibited.
609 (unless gnus-inhibit-hiding
612 (let ((buffer-read-only nil)
613 (props (nconc (list 'article-type 'headers)
614 gnus-hidden-properties))
615 (max (1+ (length gnus-sorted-header-list)))
616 (ignored (when (not gnus-visible-headers)
617 (cond ((stringp gnus-ignored-headers)
618 gnus-ignored-headers)
619 ((listp gnus-ignored-headers)
620 (mapconcat 'identity gnus-ignored-headers
623 (cond ((stringp gnus-visible-headers)
624 gnus-visible-headers)
625 ((and gnus-visible-headers
626 (listp gnus-visible-headers))
627 (mapconcat 'identity gnus-visible-headers "\\|"))))
628 (inhibit-point-motion-hooks t)
630 ;; First we narrow to just the headers.
632 (goto-char (point-min))
633 ;; Hide any "From " lines at the beginning of (mail) articles.
634 (while (looking-at "From ")
638 (delete-region (point-min) (point))
639 (gnus-article-hide-text (point-min) (point) props)))
640 ;; Then treat the rest of the header lines.
643 (if (search-forward "\n\n" nil t) ; if there's a body
644 (progn (forward-line -1) (point))
646 ;; Then we use the two regular expressions
647 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
648 ;; select which header lines is to remain visible in the
650 (goto-char (point-min))
651 (while (re-search-forward "^[^ \t]*:" nil t)
653 ;; Mark the rank of the header.
655 (point) (1+ (point)) 'message-rank
656 (if (or (and visible (looking-at visible))
658 (not (looking-at ignored))))
659 (gnus-article-header-rank)
662 (message-sort-headers-1)
663 (when (setq beg (text-property-any
664 (point-min) (point-max) 'message-rank (+ 2 max)))
665 ;; We make the unwanted headers invisible.
667 (delete-region beg (point-max))
668 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
669 (gnus-article-hide-text-type beg (point-max) 'headers))
670 ;; Work around XEmacs lossage.
671 (put-text-property (point-min) beg 'invisible nil))))))))
673 (defun article-hide-boring-headers (&optional arg)
674 "Toggle hiding of headers that aren't very interesting.
675 If given a negative prefix, always show; if given a positive prefix,
677 (interactive (gnus-article-hidden-arg))
678 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
679 (not gnus-show-all-headers))
682 (let ((buffer-read-only nil)
683 (list gnus-boring-article-headers)
684 (inhibit-point-motion-hooks t)
686 (nnheader-narrow-to-headers)
688 (setq elem (pop list))
689 (goto-char (point-min))
691 ;; Hide empty headers.
693 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
695 (gnus-article-hide-text-type
696 (progn (beginning-of-line) (point))
699 (if (re-search-forward "^[^ \t]" nil t)
703 ;; Hide boring Newsgroups header.
704 ((eq elem 'newsgroups)
705 (when (equal (gnus-fetch-field "newsgroups")
706 (gnus-group-real-name
707 (if (boundp 'gnus-newsgroup-name)
710 (gnus-article-hide-header "newsgroups")))
711 ((eq elem 'followup-to)
712 (when (equal (message-fetch-field "followup-to")
713 (message-fetch-field "newsgroups"))
714 (gnus-article-hide-header "followup-to")))
716 (let ((from (message-fetch-field "from"))
717 (reply-to (message-fetch-field "reply-to")))
722 (nth 1 (mail-extract-address-components from))
723 (nth 1 (mail-extract-address-components reply-to)))))
724 (gnus-article-hide-header "reply-to"))))
726 (let ((date (message-fetch-field "date")))
728 (< (gnus-days-between (current-time-string) date)
730 (gnus-article-hide-header "date")))))))))))
732 (defun gnus-article-hide-header (header)
734 (goto-char (point-min))
735 (when (re-search-forward (concat "^" header ":") nil t)
736 (gnus-article-hide-text-type
737 (progn (beginning-of-line) (point))
740 (if (re-search-forward "^[^ \t]" nil t)
745 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
746 (defun article-treat-overstrike ()
747 "Translate overstrikes into bold text."
750 (let ((buffer-read-only nil))
751 (while (search-forward "\b" nil t)
752 (let ((next (following-char))
753 (previous (char-after (- (point) 2))))
754 ;; We do the boldification/underlining by hiding the
755 ;; overstrikes and putting the proper text property
759 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
760 (put-text-property (point) (1+ (point)) 'face 'bold))
762 (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike)
764 (- (point) 2) (1- (point)) 'face 'underline))
766 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
768 (point) (1+ (point)) 'face 'underline))))))))
770 (defun article-fill ()
771 "Format too long lines."
774 (let ((buffer-read-only nil))
776 (goto-char (point-min))
777 (search-forward "\n\n" nil t)
779 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
780 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
781 (adaptive-fill-mode t))
783 (and (>= (current-column) (min fill-column (window-width)))
784 (/= (preceding-char) ?:)
785 (fill-paragraph nil))
788 (defun article-remove-cr ()
789 "Remove carriage returns from an article."
792 (let ((buffer-read-only nil))
793 (goto-char (point-min))
794 (while (search-forward "\r" nil t)
795 (replace-match "" t t)))))
797 (defun article-remove-trailing-blank-lines ()
798 "Remove all trailing blank lines from the article."
801 (let ((buffer-read-only nil))
802 (goto-char (point-max))
806 (while (and (not (bobp))
807 (looking-at "^[ \t]*$"))
812 (defun article-display-x-face (&optional force)
813 "Look for an X-Face header and display it if present."
814 (interactive (list 'force))
816 ;; Delete the old process, if any.
817 (when (process-status "article-x-face")
818 (delete-process "article-x-face"))
819 (let ((inhibit-point-motion-hooks t)
820 (case-fold-search nil)
823 (nnheader-narrow-to-headers)
824 (setq from (message-fetch-field "from"))
825 (goto-char (point-min))
826 (when (and gnus-article-x-face-command
828 ;; Check whether this face is censored.
829 (not gnus-article-x-face-too-ugly)
830 (and gnus-article-x-face-too-ugly from
831 (not (string-match gnus-article-x-face-too-ugly
833 ;; Has to be present.
834 (re-search-forward "^X-Face: " nil t))
835 ;; We now have the area of the buffer where the X-Face is stored.
837 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
838 ;; We display the face.
839 (if (symbolp gnus-article-x-face-command)
840 ;; The command is a lisp function, so we call it.
841 (if (gnus-functionp gnus-article-x-face-command)
842 (funcall gnus-article-x-face-command beg end)
843 (error "%s is not a function" gnus-article-x-face-command))
844 ;; The command is a string, so we interpret the command
845 ;; as a, well, command, and fork it off.
846 (let ((process-connection-type nil))
847 (process-kill-without-query
849 "article-x-face" nil shell-file-name shell-command-switch
850 gnus-article-x-face-command))
851 (process-send-region "article-x-face" beg end)
852 (process-send-eof "article-x-face")))))))))
854 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
855 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
856 (defun article-decode-rfc1522 ()
857 "Hack to remove QP encoding from headers."
858 (let ((case-fold-search t)
859 (inhibit-point-motion-hooks t)
860 (buffer-read-only nil)
864 (goto-char (point-min))
865 (or (search-forward "\n\n" nil t) (point-max)))
866 (goto-char (point-min))
867 (while (re-search-forward
868 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
869 (setq string (match-string 1))
871 (narrow-to-region (match-beginning 0) (match-end 0))
872 (delete-region (point-min) (point-max))
874 (article-mime-decode-quoted-printable
875 (goto-char (point-min)) (point-max))
876 (subst-char-in-region (point-min) (point-max) ?_ ? )
877 (goto-char (point-max)))
878 (goto-char (point-min))))))
880 (defun article-de-quoted-unreadable (&optional force)
881 "Do a naive translation of a quoted-printable-encoded article.
882 This is in no way, shape or form meant as a replacement for real MIME
883 processing, but is simply a stop-gap measure until MIME support is
885 If FORCE, decode the article whether it is marked as quoted-printable
887 (interactive (list 'force))
889 (let ((case-fold-search t)
890 (buffer-read-only nil)
891 (type (gnus-fetch-field "content-transfer-encoding")))
892 (gnus-article-decode-rfc1522)
894 (and type (string-match "quoted-printable" (downcase type))))
895 (goto-char (point-min))
896 (search-forward "\n\n" nil 'move)
897 (article-mime-decode-quoted-printable (point) (point-max))))))
899 (defun article-mime-decode-quoted-printable-buffer ()
900 "Decode Quoted-Printable in the current buffer."
901 (article-mime-decode-quoted-printable (point-min) (point-max)))
903 (defun article-mime-decode-quoted-printable (from to)
904 "Decode Quoted-Printable in the region between FROM and TO."
907 (while (search-forward "=" to t)
908 (cond ((eq (following-char) ?\n)
911 ((looking-at "[0-9A-F][0-9A-F]")
912 (subst-char-in-region
913 (1- (point)) (point) ?=
914 (hexl-hex-string-to-integer
915 (buffer-substring (point) (+ 2 (point)))))
919 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
921 (defun article-hide-pgp (&optional arg)
922 "Toggle hiding of any PGP headers and signatures in the current article.
923 If given a negative prefix, always show; if given a positive prefix,
925 (interactive (gnus-article-hidden-arg))
926 (unless (gnus-article-check-hidden-text 'pgp arg)
928 (let ((inhibit-point-motion-hooks t)
929 buffer-read-only beg end)
931 (goto-char (point-min))
932 ;; Hide the "header".
933 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
934 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp))
936 ;; Hide the actual signature.
937 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
938 (setq end (1+ (match-beginning 0)))
939 (gnus-article-hide-text-type
941 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
943 ;; Perhaps we shouldn't hide to the end of the buffer
944 ;; if there is no end to the signature?
947 ;; Hide "- " PGP quotation markers.
949 (narrow-to-region beg end)
950 (goto-char (point-min))
951 (while (re-search-forward "^- " nil t)
952 (gnus-article-hide-text-type
953 (match-beginning 0) (match-end 0) 'pgp))
956 (defun article-hide-pem (&optional arg)
957 "Toggle hiding of any PEM headers and signatures in the current article.
958 If given a negative prefix, always show; if given a positive prefix,
960 (interactive (gnus-article-hidden-arg))
961 (unless (gnus-article-check-hidden-text 'pem arg)
963 (let (buffer-read-only end)
965 (goto-char (point-min))
966 ;; hide the horrendously ugly "header".
967 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
970 (setq end (1+ (match-beginning 0)))
971 (gnus-article-hide-text-type
973 (if (search-forward "\n\n" nil t)
977 ;; hide the trailer as well
978 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
981 (gnus-article-hide-text-type
982 (match-beginning 0) (match-end 0) 'pem))))))
984 (defun article-hide-signature (&optional arg)
985 "Hide the signature in the current article.
986 If given a negative prefix, always show; if given a positive prefix,
988 (interactive (gnus-article-hidden-arg))
989 (unless (gnus-article-check-hidden-text 'signature arg)
992 (let ((buffer-read-only nil))
993 (when (gnus-article-narrow-to-signature)
994 (gnus-article-hide-text-type
995 (point-min) (point-max) 'signature)))))))
997 (defun article-strip-leading-blank-lines ()
998 "Remove all blank lines from the beginning of the article."
1001 (let ((inhibit-point-motion-hooks t)
1003 (goto-char (point-min))
1004 (when (search-forward "\n\n" nil t)
1005 (while (and (not (eobp))
1006 (looking-at "[ \t]*$"))
1007 (gnus-delete-line))))))
1009 (defun article-strip-multiple-blank-lines ()
1010 "Replace consecutive blank lines with one empty line."
1013 (let (buffer-read-only)
1014 ;; First make all blank lines empty.
1015 (goto-char (point-min))
1016 (while (re-search-forward "^[ \t]+$" nil t)
1017 (replace-match "" nil t))
1018 ;; Then replace multiple empty lines with a single empty line.
1019 (goto-char (point-min))
1020 (while (re-search-forward "\n\n\n+" nil t)
1021 (replace-match "\n\n" t t)))))
1023 (defun article-strip-blank-lines ()
1024 "Strip leading, trailing and multiple blank lines."
1026 (article-strip-leading-blank-lines)
1027 (article-remove-trailing-blank-lines)
1028 (article-strip-multiple-blank-lines))
1030 (defvar mime::preview/content-list)
1031 (defvar mime::preview-content-info/point-min)
1032 (defun gnus-article-narrow-to-signature ()
1033 "Narrow to the signature; return t if a signature is found, else nil."
1035 (when (and (boundp 'mime::preview/content-list)
1036 mime::preview/content-list)
1037 ;; We have a MIMEish article, so we use the MIME data to narrow.
1038 (let ((pcinfo (car (last mime::preview/content-list))))
1041 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1044 (when (gnus-article-search-signature)
1046 ;; Check whether we have some limits to what we consider
1047 ;; to be a signature.
1048 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1049 (list gnus-signature-limit)))
1051 (while (setq limit (pop limits))
1052 (if (or (and (integerp limit)
1053 (< (- (point-max) (point)) limit))
1055 (< (count-lines (point) (point-max)) limit))
1056 (and (gnus-functionp limit)
1058 (and (stringp limit)
1059 (not (re-search-forward limit nil t))))
1060 () ; This limit did not succeed.
1064 (narrow-to-region (point) (point-max))
1067 (defun gnus-article-search-signature ()
1068 "Search the current buffer for the signature separator.
1069 Put point at the beginning of the signature separator."
1070 (let ((cur (point)))
1071 (goto-char (point-max))
1072 (if (if (stringp gnus-signature-separator)
1073 (re-search-backward gnus-signature-separator nil t)
1074 (let ((seps gnus-signature-separator))
1076 (not (re-search-backward (car seps) nil t)))
1083 (defun gnus-article-hidden-arg ()
1084 "Return the current prefix arg as a number, or 0 if no prefix."
1085 (list (if current-prefix-arg
1086 (prefix-numeric-value current-prefix-arg)
1089 (defun gnus-article-check-hidden-text (type arg)
1090 "Return nil if hiding is necessary.
1091 Arg can be nil or a number. Nil and positive means hide, negative
1092 means show, 0 means toggle."
1096 (let ((hide (gnus-article-hidden-text-p type)))
1102 (gnus-article-show-hidden-text type))
1104 (if (eq hide 'hidden)
1105 (gnus-article-show-hidden-text type)
1108 (defun gnus-article-hidden-text-p (type)
1109 "Say whether the current buffer contains hidden text of type TYPE."
1110 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1112 (if (get-text-property pos 'invisible)
1116 (defun gnus-article-show-hidden-text (type &optional hide)
1117 "Show all hidden text of type TYPE.
1118 If HIDE, hide the text instead."
1120 (let ((buffer-read-only nil)
1121 (inhibit-point-motion-hooks t)
1124 (while (setq beg (text-property-any end (point-max) 'article-type type))
1127 (text-property-not-all beg (point-max) 'article-type type)
1130 (gnus-article-hide-text beg end gnus-hidden-properties)
1131 (gnus-article-unhide-text beg end))
1135 (defconst article-time-units
1136 `((year . ,(* 365.25 24 60 60))
1137 (week . ,(* 7 24 60 60))
1138 (day . ,(* 24 60 60))
1142 "Mapping from time units to seconds.")
1144 (defun article-date-ut (&optional type highlight header)
1145 "Convert DATE date to universal time in the current article.
1146 If TYPE is `local', convert to local time; if it is `lapsed', output
1147 how much time has lapsed since DATE."
1148 (interactive (list 'ut t))
1149 (let* ((header (or header
1150 (mail-header-date gnus-current-headers)
1151 (message-fetch-field "date")
1153 (date (if (vectorp header) (mail-header-date header)
1155 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1156 (inhibit-point-motion-hooks t)
1158 (when (and date (not (string= date "")))
1161 (nnheader-narrow-to-headers)
1162 (let ((buffer-read-only nil))
1163 ;; Delete any old Date headers.
1164 (if (re-search-forward date-regexp nil t)
1166 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1167 eface (get-text-property (1- (gnus-point-at-eol))
1169 (message-remove-header date-regexp t)
1170 (beginning-of-line))
1171 (goto-char (point-max)))
1172 (insert (article-make-date-line date type))
1175 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1176 (put-text-property (match-beginning 1) (match-end 1)
1178 (put-text-property (match-beginning 2) (match-end 2)
1181 (defun article-make-date-line (date type)
1182 "Return a DATE line of TYPE."
1184 ;; Convert to the local timezone. We have to slap a
1185 ;; `condition-case' round the calls to the timezone
1186 ;; functions since they aren't particularly resistant to
1189 (concat "Date: " (condition-case ()
1190 (timezone-make-date-arpa-standard date)
1193 ;; Convert to Universal Time.
1197 (timezone-make-date-arpa-standard date nil "UT")
1200 ;; Get the original date from the article.
1201 ((eq type 'original)
1202 (concat "Date: " date "\n"))
1203 ;; Let the user define the format.
1206 (format-time-string gnus-article-time-format
1209 (timezone-make-date-arpa-standard
1212 ;; Do an X-Sent lapsed format.
1214 ;; If the date is seriously mangled, the timezone functions are
1215 ;; liable to bug out, so we ignore all errors.
1216 (let* ((now (current-time))
1221 (timezone-make-date-arpa-standard
1222 (current-time-string now)
1223 (current-time-zone now) "UT"))
1225 (timezone-make-date-arpa-standard
1227 (real-sec (and real-time
1228 (+ (* (float (car real-time)) 65536)
1230 (sec (and real-time (abs real-sec)))
1234 "X-Sent: Unknown\n")
1240 ;; This is a bit convoluted, but basically we go
1241 ;; through the time units for years, weeks, etc,
1242 ;; and divide things to see whether that results
1243 ;; in positive answers.
1246 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1247 ;; The (remaining) seconds are too few to
1248 ;; be divided into this time unit.
1250 ;; It's big enough, so we output it.
1251 (setq sec (- sec (* num (cdr unit))))
1253 (concat (if prev ", " "") (int-to-string
1255 " " (symbol-name (car unit))
1256 (if (> num 1) "s" ""))
1258 article-time-units "")
1259 ;; If dates are odd, then it might appear like the
1260 ;; article was sent in the future.
1263 " in the future\n"))))))
1265 (error "Unknown conversion type: %s" type))))
1267 (defun article-date-local (&optional highlight)
1268 "Convert the current article date to the local timezone."
1269 (interactive (list t))
1270 (article-date-ut 'local highlight))
1272 (defun article-date-original (&optional highlight)
1273 "Convert the current article date to what it was originally.
1274 This is only useful if you have used some other date conversion
1275 function and want to see what the date was before converting."
1276 (interactive (list t))
1277 (article-date-ut 'original highlight))
1279 (defun article-date-lapsed (&optional highlight)
1280 "Convert the current article date to time lapsed since it was sent."
1281 (interactive (list t))
1282 (article-date-ut 'lapsed highlight))
1284 (defun article-date-user (&optional highlight)
1285 "Convert the current article date to the user-defined format."
1286 (interactive (list t))
1287 (article-date-ut 'user highlight))
1289 (defun article-show-all ()
1290 "Show all hidden text in the article buffer."
1293 (let ((buffer-read-only nil))
1294 (gnus-article-unhide-text (point-min) (point-max)))))
1296 (defun article-emphasize (&optional arg)
1297 "Emphasize text according to `gnus-emphasis-alist'."
1298 (interactive (gnus-article-hidden-arg))
1299 (unless (gnus-article-check-hidden-text 'emphasis arg)
1301 (let ((alist gnus-emphasis-alist)
1302 (buffer-read-only nil)
1303 (props (append '(article-type emphasis)
1304 gnus-hidden-properties))
1305 regexp elem beg invisible visible face)
1306 (goto-char (point-min))
1307 (search-forward "\n\n" nil t)
1309 (while (setq elem (pop alist))
1311 (setq regexp (car elem)
1312 invisible (nth 1 elem)
1313 visible (nth 2 elem)
1315 (while (re-search-forward regexp nil t)
1316 (when (and (match-beginning visible) (match-beginning invisible))
1317 (gnus-article-hide-text
1318 (match-beginning invisible) (match-end invisible) props)
1319 (gnus-article-unhide-text-type
1320 (match-beginning visible) (match-end visible) 'emphasis)
1321 (gnus-put-text-property-excluding-newlines
1322 (match-beginning visible) (match-end visible) 'face face)
1323 (goto-char (match-end invisible)))))))))
1325 (defvar gnus-summary-article-menu)
1326 (defvar gnus-summary-post-menu)
1328 ;;; Saving functions.
1330 (defun gnus-article-save (save-buffer file &optional num)
1331 "Save the currently selected article."
1332 (unless gnus-save-all-headers
1333 ;; Remove headers according to `gnus-saved-headers'.
1334 (let ((gnus-visible-headers
1335 (or gnus-saved-headers gnus-visible-headers))
1336 (gnus-article-buffer save-buffer))
1337 (gnus-article-hide-headers 1 t)))
1338 (save-window-excursion
1339 (if (not gnus-default-article-saver)
1340 (error "No default saver is defined.")
1341 ;; !!! Magic! The saving functions all save
1342 ;; `gnus-original-article-buffer' (or so they think), but we
1343 ;; bind that variable to our save-buffer.
1344 (set-buffer gnus-article-buffer)
1345 (let* ((gnus-save-article-buffer save-buffer)
1348 ((not gnus-prompt-before-saving) 'default)
1349 ((eq gnus-prompt-before-saving 'always) nil)
1351 (gnus-number-of-articles-to-be-saved
1352 (when (eq gnus-prompt-before-saving t)
1354 (set-buffer gnus-summary-buffer)
1355 (funcall gnus-default-article-saver filename)))))
1357 (defun gnus-read-save-file-name (prompt default-name &optional filename)
1359 ((eq filename 'default)
1363 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1365 (format prompt (if (and gnus-number-of-articles-to-be-saved
1366 (> gnus-number-of-articles-to-be-saved 1))
1367 (format "these %d articles"
1368 gnus-number-of-articles-to-be-saved)
1371 ;; Let the split methods have their say.
1373 ;; No split name was found.
1376 (concat prompt " (default "
1377 (file-name-nondirectory default-name) ") ")
1378 (file-name-directory default-name)
1380 ;; A single split name was found
1381 ((= 1 (length split-name))
1382 (let* ((name (car split-name))
1383 (dir (cond ((file-directory-p name)
1384 (file-name-as-directory name))
1385 ((file-exists-p name) name)
1386 (t gnus-article-save-directory))))
1388 (concat prompt " (default " name ") ")
1390 ;; A list of splits was found.
1392 (setq split-name (nreverse split-name))
1394 (let ((file-name-history (nconc split-name file-name-history)))
1398 (concat prompt " (`M-p' for defaults) ")
1399 gnus-article-save-directory
1401 gnus-article-save-directory)))
1402 (car (push result file-name-history)))))))
1403 ;; Create the directory.
1404 (gnus-make-directory (file-name-directory file))
1405 ;; If we have read a directory, we append the default file name.
1406 (when (file-directory-p file)
1407 (setq file (concat (file-name-as-directory file)
1408 (file-name-nondirectory default-name))))
1409 ;; Possibly translate some characters.
1410 (nnheader-translate-file-chars file)))))
1412 (defun gnus-article-archive-name (group)
1413 "Return the first instance of an \"Archive-name\" in the current buffer."
1414 (let ((case-fold-search t))
1415 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1416 (nnheader-concat gnus-article-save-directory
1417 (match-string 1)))))
1419 (defun gnus-summary-save-in-rmail (&optional filename)
1420 "Append this article to Rmail file.
1421 Optional argument FILENAME specifies file name.
1422 Directory to save to is default to `gnus-article-save-directory'."
1424 (gnus-set-global-variables)
1426 (funcall gnus-rmail-save-name gnus-newsgroup-name
1427 gnus-current-headers gnus-newsgroup-last-rmail)))
1428 (setq filename (gnus-read-save-file-name
1429 "Save %s in rmail file:" default-name filename))
1430 (gnus-make-directory (file-name-directory filename))
1431 (gnus-eval-in-buffer-window gnus-save-article-buffer
1435 (gnus-output-to-rmail filename))))
1436 ;; Remember the directory name to save articles
1437 (setq gnus-newsgroup-last-rmail filename)))
1439 (defun gnus-summary-save-in-mail (&optional filename)
1440 "Append this article to Unix mail file.
1441 Optional argument FILENAME specifies file name.
1442 Directory to save to is default to `gnus-article-save-directory'."
1444 (gnus-set-global-variables)
1446 (funcall gnus-mail-save-name gnus-newsgroup-name
1447 gnus-current-headers gnus-newsgroup-last-mail)))
1448 (setq filename (gnus-read-save-file-name
1449 "Save %s in Unix mail file:" default-name filename))
1451 (expand-file-name filename
1453 (file-name-directory default-name))))
1454 (gnus-make-directory (file-name-directory filename))
1455 (gnus-eval-in-buffer-window gnus-save-article-buffer
1459 (if (and (file-readable-p filename)
1460 (mail-file-babyl-p filename))
1461 (gnus-output-to-rmail filename t)
1462 (gnus-output-to-mail filename)))))
1463 ;; Remember the directory name to save articles.
1464 (setq gnus-newsgroup-last-mail filename)))
1466 (defun gnus-summary-save-in-file (&optional filename overwrite)
1467 "Append this article to file.
1468 Optional argument FILENAME specifies file name.
1469 Directory to save to is default to `gnus-article-save-directory'."
1471 (gnus-set-global-variables)
1473 (funcall gnus-file-save-name gnus-newsgroup-name
1474 gnus-current-headers gnus-newsgroup-last-file)))
1475 (setq filename (gnus-read-save-file-name
1476 "Save %s in file:" default-name filename))
1477 (gnus-make-directory (file-name-directory filename))
1478 (gnus-eval-in-buffer-window gnus-save-article-buffer
1482 (when (and overwrite
1483 (file-exists-p filename))
1484 (delete-file filename))
1485 (gnus-output-to-file filename))))
1486 ;; Remember the directory name to save articles.
1487 (setq gnus-newsgroup-last-file filename)))
1489 (defun gnus-summary-write-to-file (&optional filename)
1490 "Write this article to a file.
1491 Optional argument FILENAME specifies file name.
1492 The directory to save in defaults to `gnus-article-save-directory'."
1494 (gnus-summary-save-in-file nil t))
1496 (defun gnus-summary-save-body-in-file (&optional filename)
1497 "Append this article body to a file.
1498 Optional argument FILENAME specifies file name.
1499 The directory to save in defaults to `gnus-article-save-directory'."
1501 (gnus-set-global-variables)
1503 (funcall gnus-file-save-name gnus-newsgroup-name
1504 gnus-current-headers gnus-newsgroup-last-file)))
1505 (setq filename (gnus-read-save-file-name
1506 "Save %s body in file:" default-name filename))
1507 (gnus-make-directory (file-name-directory filename))
1508 (gnus-eval-in-buffer-window gnus-save-article-buffer
1512 (goto-char (point-min))
1513 (when (search-forward "\n\n" nil t)
1514 (narrow-to-region (point) (point-max)))
1515 (gnus-output-to-file filename))))
1516 ;; Remember the directory name to save articles.
1517 (setq gnus-newsgroup-last-file filename)))
1519 (defun gnus-summary-save-in-pipe (&optional command)
1520 "Pipe this article to subprocess."
1522 (gnus-set-global-variables)
1524 (cond ((eq command 'default)
1525 gnus-last-shell-command)
1529 "Shell command on %s: "
1530 (if (and gnus-number-of-articles-to-be-saved
1531 (> gnus-number-of-articles-to-be-saved 1))
1532 (format "these %d articles"
1533 gnus-number-of-articles-to-be-saved)
1535 gnus-last-shell-command))))
1536 (when (string-equal command "")
1537 (setq command gnus-last-shell-command))
1538 (gnus-eval-in-buffer-window gnus-article-buffer
1541 (shell-command-on-region (point-min) (point-max) command nil)))
1542 (setq gnus-last-shell-command command))
1544 ;;; Article file names when saving.
1546 (defun gnus-capitalize-newsgroup (newsgroup)
1547 "Capitalize NEWSGROUP name."
1548 (when (not (zerop (length newsgroup)))
1549 (concat (char-to-string (upcase (aref newsgroup 0)))
1550 (substring newsgroup 1))))
1552 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1553 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1554 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1555 Otherwise, it is like ~/News/news/group/num."
1558 (concat (if (gnus-use-long-file-name 'not-save)
1559 (gnus-capitalize-newsgroup newsgroup)
1560 (gnus-newsgroup-directory-form newsgroup))
1561 "/" (int-to-string (mail-header-number headers)))
1562 gnus-article-save-directory)))
1564 (string-equal (file-name-directory default)
1565 (file-name-directory last-file))
1566 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1568 (or last-file default))))
1570 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1571 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1572 If variable `gnus-use-long-file-name' is non-nil, it is
1573 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1576 (concat (if (gnus-use-long-file-name 'not-save)
1578 (gnus-newsgroup-directory-form newsgroup))
1579 "/" (int-to-string (mail-header-number headers)))
1580 gnus-article-save-directory)))
1582 (string-equal (file-name-directory default)
1583 (file-name-directory last-file))
1584 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1586 (or last-file default))))
1588 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1589 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1590 If variable `gnus-use-long-file-name' is non-nil, it is
1591 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1594 (if (gnus-use-long-file-name 'not-save)
1595 (gnus-capitalize-newsgroup newsgroup)
1596 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1597 gnus-article-save-directory)))
1599 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1600 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1601 If variable `gnus-use-long-file-name' is non-nil, it is
1602 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1605 (if (gnus-use-long-file-name 'not-save)
1607 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1608 gnus-article-save-directory)))
1615 (setq afunc (car func)
1618 gfunc (intern (format "gnus-%s" func))))
1620 (if (not (fboundp afunc))
1622 `(lambda (&optional interactive &rest args)
1623 ,(documentation afunc t)
1624 (interactive (list t))
1626 (set-buffer gnus-article-buffer)
1628 (call-interactively ',afunc)
1629 (apply ',afunc args))))))))
1630 '(article-hide-headers
1631 article-hide-boring-headers
1632 article-treat-overstrike
1633 (article-fill . gnus-article-word-wrap)
1635 article-display-x-face
1636 article-de-quoted-unreadable
1637 article-mime-decode-quoted-printable
1640 article-hide-signature
1641 article-remove-trailing-blank-lines
1642 article-strip-leading-blank-lines
1643 article-strip-multiple-blank-lines
1644 article-strip-blank-lines
1646 article-date-original
1651 (article-show-all . gnus-article-show-all-headers))))
1654 ;;; Gnus article mode
1657 (put 'gnus-article-mode 'mode-class 'special)
1660 (gnus-define-keys gnus-article-mode-map
1661 " " gnus-article-goto-next-page
1662 "\177" gnus-article-goto-prev-page
1663 [delete] gnus-article-goto-prev-page
1664 "\C-c^" gnus-article-refer-article
1665 "h" gnus-article-show-summary
1666 "s" gnus-article-show-summary
1667 "\C-c\C-m" gnus-article-mail
1668 "?" gnus-article-describe-briefly
1669 gnus-mouse-2 gnus-article-push-button
1670 "\r" gnus-article-press-button
1671 "\t" gnus-article-next-button
1672 "\M-\t" gnus-article-prev-button
1673 "e" gnus-article-edit
1674 "<" beginning-of-buffer
1676 "\C-c\C-i" gnus-info-find-node
1679 "\C-d" gnus-article-read-summary-keys
1680 "\M-*" gnus-article-read-summary-keys
1681 "\M-#" gnus-article-read-summary-keys
1682 "\M-^" gnus-article-read-summary-keys
1683 "\M-g" gnus-article-read-summary-keys)
1685 (substitute-key-definition
1686 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map))
1688 (defun gnus-article-make-menu-bar ()
1689 (gnus-turn-off-edit-menu 'article)
1690 (unless (boundp 'gnus-article-article-menu)
1692 gnus-article-article-menu gnus-article-mode-map ""
1694 ["Scroll forwards" gnus-article-goto-next-page t]
1695 ["Scroll backwards" gnus-article-goto-prev-page t]
1696 ["Show summary" gnus-article-show-summary t]
1697 ["Fetch Message-ID at point" gnus-article-refer-article t]
1698 ["Mail to address at point" gnus-article-mail t]))
1701 gnus-article-treatment-menu gnus-article-mode-map ""
1703 ["Hide headers" gnus-article-hide-headers t]
1704 ["Hide signature" gnus-article-hide-signature t]
1705 ["Hide citation" gnus-article-hide-citation t]
1706 ["Treat overstrike" gnus-article-treat-overstrike t]
1707 ["Remove carriage return" gnus-article-remove-cr t]
1708 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1711 (when (boundp 'gnus-summary-article-menu)
1712 (define-key gnus-article-mode-map [menu-bar commands]
1713 (cons "Commands" gnus-summary-article-menu))))
1715 (when (boundp 'gnus-summary-post-menu)
1716 (define-key gnus-article-mode-map [menu-bar post]
1717 (cons "Post" gnus-summary-post-menu)))
1719 (run-hooks 'gnus-article-menu-hook)))
1721 (defun gnus-article-mode ()
1722 "Major mode for displaying an article.
1724 All normal editing commands are switched off.
1726 The following commands are available in addition to all summary mode
1728 \\<gnus-article-mode-map>
1729 \\[gnus-article-next-page]\t Scroll the article one page forwards
1730 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1731 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1732 \\[gnus-article-show-summary]\t Display the summary buffer
1733 \\[gnus-article-mail]\t Send a reply to the address near point
1734 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1735 \\[gnus-info-find-node]\t Go to the Gnus info node"
1737 (when (gnus-visual-p 'article-menu 'menu)
1738 (gnus-article-make-menu-bar))
1739 (kill-all-local-variables)
1740 (gnus-simplify-mode-line)
1741 (setq mode-name "Article")
1742 (setq major-mode 'gnus-article-mode)
1743 (make-local-variable 'minor-mode-alist)
1744 (unless (assq 'gnus-show-mime minor-mode-alist)
1745 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1746 (use-local-map gnus-article-mode-map)
1747 (gnus-update-format-specifications nil 'article-mode)
1748 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1749 (gnus-set-default-directory)
1750 (buffer-disable-undo (current-buffer))
1751 (setq buffer-read-only t)
1752 (set-syntax-table gnus-article-mode-syntax-table)
1753 (run-hooks 'gnus-article-mode-hook))
1755 (defun gnus-article-setup-buffer ()
1756 "Initialize the article buffer."
1757 (let* ((name (if gnus-single-article-buffer "*Article*"
1758 (concat "*Article " gnus-newsgroup-name "*")))
1760 (progn (string-match "\\*Article" name)
1761 (concat " *Original Article"
1762 (substring name (match-end 0))))))
1763 (setq gnus-article-buffer name)
1764 (setq gnus-original-article-buffer original)
1765 ;; This might be a variable local to the summary buffer.
1766 (unless gnus-single-article-buffer
1768 (set-buffer gnus-summary-buffer)
1769 (setq gnus-article-buffer name)
1770 (setq gnus-original-article-buffer original)
1771 (gnus-set-global-variables)))
1772 ;; Init original article buffer.
1774 (set-buffer (get-buffer-create gnus-original-article-buffer))
1775 (buffer-disable-undo (current-buffer))
1776 (setq major-mode 'gnus-original-article-mode)
1777 (gnus-add-current-to-buffer-list)
1778 (make-local-variable 'gnus-original-article))
1779 (if (get-buffer name)
1782 (buffer-disable-undo (current-buffer))
1783 (setq buffer-read-only t)
1784 (gnus-add-current-to-buffer-list)
1785 (unless (eq major-mode 'gnus-article-mode)
1786 (gnus-article-mode))
1789 (set-buffer (get-buffer-create name))
1790 (gnus-add-current-to-buffer-list)
1792 (make-local-variable 'gnus-summary-buffer)
1793 (current-buffer)))))
1795 ;; Set article window start at LINE, where LINE is the number of lines
1796 ;; from the head of the article.
1797 (defun gnus-article-set-window-start (&optional line)
1799 (get-buffer-window gnus-article-buffer t)
1801 (set-buffer gnus-article-buffer)
1802 (goto-char (point-min))
1805 (gnus-message 6 "Moved to bookmark")
1806 (search-forward "\n\n" nil t)
1810 (defun gnus-article-prepare (article &optional all-headers header)
1811 "Prepare ARTICLE in article mode buffer.
1812 ARTICLE should either be an article number or a Message-ID.
1813 If ARTICLE is an id, HEADER should be the article headers.
1814 If ALL-HEADERS is non-nil, no headers are hidden."
1816 ;; Make sure we start in a summary buffer.
1817 (unless (eq major-mode 'gnus-summary-mode)
1818 (set-buffer gnus-summary-buffer))
1819 (setq gnus-summary-buffer (current-buffer))
1820 ;; Make sure the connection to the server is alive.
1821 (unless (gnus-server-opened
1822 (gnus-find-method-for-group gnus-newsgroup-name))
1823 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1824 (gnus-request-group gnus-newsgroup-name t))
1825 (let* ((gnus-article (if header (mail-header-number header) article))
1826 (summary-buffer (current-buffer))
1827 (internal-hook gnus-article-internal-prepare-hook)
1828 (group gnus-newsgroup-name)
1831 (gnus-article-setup-buffer)
1832 (set-buffer gnus-article-buffer)
1833 ;; Deactivate active regions.
1834 (when (and (boundp 'transient-mark-mode)
1835 transient-mark-mode)
1836 (setq mark-active nil))
1837 (if (not (setq result (let ((buffer-read-only nil))
1838 (gnus-request-article-this-buffer
1840 ;; There is no such article.
1842 (when (and (numberp article)
1843 (not (memq article gnus-newsgroup-sparse)))
1844 (setq gnus-article-current
1845 (cons gnus-newsgroup-name article))
1846 (set-buffer gnus-summary-buffer)
1847 (setq gnus-current-article article)
1848 (gnus-summary-mark-article article gnus-canceled-mark))
1849 (unless (memq article gnus-newsgroup-sparse)
1851 1 "No such article (may have expired or been canceled)")))
1852 (if (or (eq result 'pseudo) (eq result 'nneething))
1855 (set-buffer summary-buffer)
1856 (setq gnus-last-article gnus-current-article
1857 gnus-newsgroup-history (cons gnus-current-article
1858 gnus-newsgroup-history)
1859 gnus-current-article 0
1860 gnus-current-headers nil
1861 gnus-article-current nil)
1862 (if (eq result 'nneething)
1863 (gnus-configure-windows 'summary)
1864 (gnus-configure-windows 'article))
1865 (gnus-set-global-variables))
1866 (gnus-set-mode-line 'article))
1867 ;; The result from the `request' was an actual article -
1868 ;; or at least some text that is now displayed in the
1870 (when (and (numberp article)
1871 (not (eq article gnus-current-article)))
1872 ;; Seems like a new article has been selected.
1873 ;; `gnus-current-article' must be an article number.
1875 (set-buffer summary-buffer)
1876 (setq gnus-last-article gnus-current-article
1877 gnus-newsgroup-history (cons gnus-current-article
1878 gnus-newsgroup-history)
1879 gnus-current-article article
1880 gnus-current-headers
1881 (gnus-summary-article-header gnus-current-article)
1882 gnus-article-current
1883 (cons gnus-newsgroup-name gnus-current-article))
1884 (unless (vectorp gnus-current-headers)
1885 (setq gnus-current-headers nil))
1886 (gnus-summary-show-thread)
1887 (run-hooks 'gnus-mark-article-hook)
1888 (gnus-set-mode-line 'summary)
1889 (when (gnus-visual-p 'article-highlight 'highlight)
1890 (run-hooks 'gnus-visual-mark-article-hook))
1891 ;; Set the global newsgroup variables here.
1892 ;; Suggested by Jim Sisolak
1893 ;; <sisolak@trans4.neep.wisc.edu>.
1894 (gnus-set-global-variables)
1895 (setq gnus-have-all-headers
1896 (or all-headers gnus-show-all-headers))
1898 (vectorp (gnus-summary-article-header article))
1899 (gnus-cache-possibly-enter-article
1901 (gnus-summary-article-header article)
1902 (memq article gnus-newsgroup-marked)
1903 (memq article gnus-newsgroup-dormant)
1904 (memq article gnus-newsgroup-unreads)))))
1905 (when (or (numberp article)
1907 ;; Hooks for getting information from the article.
1908 ;; This hook must be called before being narrowed.
1909 (let (buffer-read-only)
1910 (run-hooks 'internal-hook)
1911 (run-hooks 'gnus-article-prepare-hook)
1912 ;; Decode MIME message.
1913 (when gnus-show-mime
1914 (if (or (not gnus-strict-mime)
1915 (gnus-fetch-field "Mime-Version"))
1916 (funcall gnus-show-mime-method)
1917 (funcall gnus-decode-encoded-word-method)))
1918 ;; Perform the article display hooks.
1919 (run-hooks 'gnus-article-display-hook))
1921 (goto-char (point-min))
1922 (when gnus-break-pages
1923 (gnus-narrow-to-page)))
1924 (gnus-set-mode-line 'article)
1925 (gnus-configure-windows 'article)
1926 (goto-char (point-min))
1929 (defun gnus-article-wash-status ()
1930 "Return a string which display status of article washing."
1932 (set-buffer gnus-article-buffer)
1933 (let ((cite (gnus-article-hidden-text-p 'cite))
1934 (headers (gnus-article-hidden-text-p 'headers))
1935 (boring (gnus-article-hidden-text-p 'boring-headers))
1936 (pgp (gnus-article-hidden-text-p 'pgp))
1937 (pem (gnus-article-hidden-text-p 'pem))
1938 (signature (gnus-article-hidden-text-p 'signature))
1939 (overstrike (gnus-article-hidden-text-p 'overstrike))
1940 (emphasis (gnus-article-hidden-text-p 'emphasis))
1941 (mime gnus-show-mime))
1942 (format "%c%c%c%c%c%c%c"
1944 (if (or headers boring) ?h ? )
1945 (if (or pgp pem) ?p ? )
1946 (if signature ?s ? )
1947 (if overstrike ?o ? )
1949 (if emphasis ?e ? )))))
1951 (defun gnus-article-hide-headers-if-wanted ()
1952 "Hide unwanted headers if `gnus-have-all-headers' is nil.
1953 Provided for backwards compatibility."
1954 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
1956 (gnus-article-hide-headers)))
1960 (defun gnus-output-to-file (file-name)
1961 "Append the current article to a file named FILE-NAME."
1962 (let ((artbuf (current-buffer)))
1963 (nnheader-temp-write nil
1964 (insert-buffer-substring artbuf)
1965 ;; Append newline at end of the buffer as separator, and then
1967 (goto-char (point-max))
1969 (append-to-file (point-min) (point-max) file-name))))
1971 (defun gnus-narrow-to-page (&optional arg)
1972 "Narrow the article buffer to a page.
1973 If given a numerical ARG, move forward ARG pages."
1975 (setq arg (if arg (prefix-numeric-value arg) 0))
1977 (set-buffer gnus-article-buffer)
1978 (goto-char (point-min))
1980 ;; Remove any old next/prev buttons.
1981 (when (gnus-visual-p 'page-marker)
1982 (let ((buffer-read-only nil))
1983 (gnus-remove-text-with-property 'gnus-prev)
1984 (gnus-remove-text-with-property 'gnus-next)))
1987 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
1989 (re-search-forward page-delimiter nil 'move arg)))
1990 (goto-char (match-end 0)))
1993 (if (re-search-forward page-delimiter nil 'move)
1996 (when (and (gnus-visual-p 'page-marker)
1997 (not (= (point-min) 1)))
1999 (goto-char (point-min))
2000 (gnus-insert-prev-page-button)))
2001 (when (and (gnus-visual-p 'page-marker)
2002 (< (+ (point-max) 2) (buffer-size)))
2004 (goto-char (point-max))
2005 (gnus-insert-next-page-button)))))
2007 ;; Article mode commands
2009 (defun gnus-article-goto-next-page ()
2010 "Show the next page of the article."
2012 (when (gnus-article-next-page)
2013 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2015 (defun gnus-article-goto-prev-page ()
2016 "Show the next page of the article."
2018 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2019 (gnus-article-prev-page nil)))
2021 (defun gnus-article-next-page (&optional lines)
2022 "Show the next page of the current article.
2023 If end of article, return non-nil. Otherwise return nil.
2024 Argument LINES specifies lines to be scrolled up."
2026 (move-to-window-line -1)
2029 (and (pos-visible-in-window-p) ;Not continuation line.
2031 ;; Nothing in this page.
2032 (if (or (not gnus-break-pages)
2035 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2037 (gnus-narrow-to-page 1) ;Go to next page.
2039 ;; More in this page.
2040 (let ((scroll-in-place nil))
2044 ;; Long lines may cause an end-of-buffer error.
2045 (goto-char (point-max)))))
2046 (move-to-window-line 0)
2049 (defun gnus-article-prev-page (&optional lines)
2050 "Show previous page of current article.
2051 Argument LINES specifies lines to be scrolled down."
2053 (move-to-window-line 0)
2054 (if (and gnus-break-pages
2056 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2058 (gnus-narrow-to-page -1) ;Go to previous page.
2059 (goto-char (point-max))
2061 (let ((scroll-in-place nil))
2064 (scroll-down lines))
2065 (move-to-window-line 0)))))
2067 (defun gnus-article-refer-article ()
2068 "Read article specified by message-id around point."
2070 (let ((point (point)))
2071 (search-forward ">" nil t) ;Move point to end of "<....>".
2072 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2073 (let ((message-id (match-string 1)))
2075 (set-buffer gnus-summary-buffer)
2076 (gnus-summary-refer-article message-id))
2078 (error "No references around point"))))
2080 (defun gnus-article-show-summary ()
2081 "Reconfigure windows to show summary buffer."
2083 (gnus-configure-windows 'article)
2084 (gnus-summary-goto-subject gnus-current-article))
2086 (defun gnus-article-describe-briefly ()
2087 "Describe article mode commands briefly."
2090 (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")))
2092 (defun gnus-article-summary-command ()
2093 "Execute the last keystroke in the summary buffer."
2095 (let ((obuf (current-buffer))
2096 (owin (current-window-configuration))
2098 (switch-to-buffer gnus-summary-buffer 'norecord)
2099 (setq func (lookup-key (current-local-map) (this-command-keys)))
2100 (call-interactively func)
2102 (set-window-configuration owin)
2103 (set-window-point (get-buffer-window (current-buffer)) (point))))
2105 (defun gnus-article-summary-command-nosave ()
2106 "Execute the last keystroke in the summary buffer."
2109 (pop-to-buffer gnus-summary-buffer 'norecord)
2110 (setq func (lookup-key (current-local-map) (this-command-keys)))
2111 (call-interactively func)))
2113 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2114 "Read a summary buffer key sequence and execute it from the article buffer."
2117 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2118 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2119 "=" "^" "\M-^" "|"))
2126 (set-buffer gnus-summary-buffer)
2127 (let (gnus-pick-mode)
2128 (push (or key last-command-event) unread-command-events)
2129 (setq keys (read-key-sequence nil))))
2132 (if (or (member keys nosaves)
2133 (member keys nosave-but-article)
2134 (member keys nosave-in-article))
2136 (save-window-excursion
2137 (pop-to-buffer gnus-summary-buffer 'norecord)
2138 ;; We disable the pick minor mode commands.
2139 (let (gnus-pick-mode)
2140 (setq func (lookup-key (current-local-map) keys))))
2143 (unless (member keys nosave-in-article)
2144 (set-buffer gnus-summary-buffer))
2145 (call-interactively func))
2146 (when (member keys nosave-but-article)
2147 (pop-to-buffer gnus-article-buffer 'norecord)))
2148 ;; These commands should restore window configuration.
2149 (let ((obuf (current-buffer))
2150 (owin (current-window-configuration))
2153 (if not-restore-window
2154 (pop-to-buffer gnus-summary-buffer 'norecord)
2155 (switch-to-buffer gnus-summary-buffer 'norecord))
2156 (setq in-buffer (current-buffer))
2157 ;; We disable the pick minor mode commands.
2158 (if (setq func (let (gnus-pick-mode)
2159 (lookup-key (current-local-map) keys)))
2160 (call-interactively func)
2162 (when (eq in-buffer (current-buffer))
2164 (unless not-restore-window
2165 (set-window-configuration owin))
2166 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2168 (defun gnus-article-hide (&optional arg force)
2169 "Hide all the gruft in the current article.
2170 This means that PGP stuff, signatures, cited text and (some)
2171 headers will be hidden.
2172 If given a prefix, show the hidden text instead."
2173 (interactive (list current-prefix-arg 'force))
2174 (gnus-article-hide-headers arg)
2175 (gnus-article-hide-pgp arg)
2176 (gnus-article-hide-citation-maybe arg force)
2177 (gnus-article-hide-signature arg))
2179 (defun gnus-article-maybe-highlight ()
2180 "Do some article highlighting if `article-visual' is non-nil."
2181 (when (gnus-visual-p 'article-highlight 'highlight)
2182 (gnus-article-highlight-some)))
2184 (defun gnus-request-article-this-buffer (article group)
2185 "Get an article and insert it into this buffer."
2186 (let (do-update-line)
2190 (gnus-kill-all-overlays)
2191 (setq group (or group gnus-newsgroup-name))
2193 ;; Open server if it has closed.
2194 (gnus-check-server (gnus-find-method-for-group group))
2196 ;; Using `gnus-request-article' directly will insert the article into
2197 ;; `nntp-server-buffer' - so we'll save some time by not having to
2198 ;; copy it from the server buffer into the article buffer.
2200 ;; We only request an article by message-id when we do not have the
2201 ;; headers for it, so we'll have to get those.
2202 (when (stringp article)
2203 (let ((gnus-override-method gnus-refer-article-method))
2204 (gnus-read-header article)))
2206 ;; If the article number is negative, that means that this article
2207 ;; doesn't belong in this newsgroup (possibly), so we find its
2208 ;; message-id and request it by id instead of number.
2209 (when (and (numberp article)
2211 (get-buffer gnus-summary-buffer)
2212 (buffer-name (get-buffer gnus-summary-buffer)))
2214 (set-buffer gnus-summary-buffer)
2215 (let ((header (gnus-summary-article-header article)))
2218 ((memq article gnus-newsgroup-sparse)
2219 ;; This is a sparse gap article.
2220 (setq do-update-line article)
2221 (setq article (mail-header-id header))
2222 (let ((gnus-override-method gnus-refer-article-method))
2223 (gnus-read-header article))
2224 (setq gnus-newsgroup-sparse
2225 (delq article gnus-newsgroup-sparse)))
2227 ;; It's a real article.
2228 (setq article (mail-header-id header)))
2230 ;; It is an extracted pseudo-article.
2231 (setq article 'pseudo)
2232 (gnus-request-pseudo-article header))))
2234 (let ((method (gnus-find-method-for-group
2235 gnus-newsgroup-name)))
2236 (if (not (eq (car method) 'nneething))
2238 (let ((dir (concat (file-name-as-directory (nth 1 method))
2239 (mail-header-subject header))))
2240 (when (file-directory-p dir)
2241 (setq article 'nneething)
2242 (gnus-group-enter-directory dir))))))))
2245 ;; Refuse to select canceled articles.
2246 ((and (numberp article)
2248 (get-buffer gnus-summary-buffer)
2249 (buffer-name (get-buffer gnus-summary-buffer))
2250 (eq (cdr (save-excursion
2251 (set-buffer gnus-summary-buffer)
2252 (assq article gnus-newsgroup-reads)))
2253 gnus-canceled-mark))
2255 ;; We first check `gnus-original-article-buffer'.
2256 ((and (get-buffer gnus-original-article-buffer)
2259 (set-buffer gnus-original-article-buffer)
2260 (and (equal (car gnus-original-article) group)
2261 (eq (cdr gnus-original-article) article))))
2262 (insert-buffer-substring gnus-original-article-buffer)
2264 ;; Check the backlog.
2265 ((and gnus-keep-backlog
2266 (gnus-backlog-request-article group article (current-buffer)))
2268 ;; Check asynchronous pre-fetch.
2269 ((gnus-async-request-fetched-article group article (current-buffer))
2270 (gnus-async-prefetch-next group article gnus-summary-buffer)
2273 ((and gnus-use-cache
2275 (gnus-cache-request-article article group))
2277 ;; Get the article and put into the article buffer.
2278 ((or (stringp article) (numberp article))
2279 (let ((gnus-override-method
2280 (and (stringp article) gnus-refer-article-method))
2281 (buffer-read-only nil))
2283 (gnus-kill-all-overlays)
2284 (when (gnus-request-article article group (current-buffer))
2285 (when (numberp article)
2286 (gnus-async-prefetch-next group article gnus-summary-buffer)
2287 (when gnus-keep-backlog
2288 (gnus-backlog-enter-article
2289 group article (current-buffer))))
2294 ;; Take the article from the original article buffer
2295 ;; and place it in the buffer it's supposed to be in.
2296 (when (and (get-buffer gnus-article-buffer)
2298 (equal (buffer-name (current-buffer))
2299 (buffer-name (get-buffer gnus-article-buffer))))
2301 (if (get-buffer gnus-original-article-buffer)
2302 (set-buffer (get-buffer gnus-original-article-buffer))
2303 (set-buffer (get-buffer-create gnus-original-article-buffer))
2304 (buffer-disable-undo (current-buffer))
2305 (setq major-mode 'gnus-original-article-mode)
2306 (setq buffer-read-only t)
2307 (gnus-add-current-to-buffer-list))
2308 (let (buffer-read-only)
2310 (insert-buffer-substring gnus-article-buffer))
2311 (setq gnus-original-article (cons group article))))
2313 ;; Update sparse articles.
2314 (when (and do-update-line
2315 (or (numberp article)
2317 (let ((buf (current-buffer)))
2318 (set-buffer gnus-summary-buffer)
2319 (gnus-summary-update-article do-update-line)
2320 (gnus-summary-goto-subject do-update-line nil t)
2321 (set-window-point (get-buffer-window (current-buffer) t)
2323 (set-buffer buf))))))
2329 (defcustom gnus-article-edit-mode-hook nil
2330 "Hook run in article edit mode buffers."
2331 :group 'gnus-article-various
2334 (defvar gnus-article-edit-done-function nil)
2336 (defvar gnus-article-edit-mode-map nil)
2338 (unless gnus-article-edit-mode-map
2339 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2341 (gnus-define-keys gnus-article-edit-mode-map
2342 "\C-c\C-c" gnus-article-edit-done
2343 "\C-c\C-k" gnus-article-edit-exit)
2345 (gnus-define-keys (gnus-article-edit-wash-map
2346 "\C-c\C-w" gnus-article-edit-mode-map)
2347 "f" gnus-article-edit-full-stops))
2349 (defun gnus-article-edit-mode ()
2350 "Major mode for editing articles.
2351 This is an extended text-mode.
2353 \\{gnus-article-edit-mode-map}"
2355 (kill-all-local-variables)
2356 (setq major-mode 'gnus-article-edit-mode)
2357 (setq mode-name "Article Edit")
2358 (use-local-map gnus-article-edit-mode-map)
2359 (make-local-variable 'gnus-article-edit-done-function)
2360 (make-local-variable 'gnus-prev-winconf)
2361 (setq buffer-read-only nil)
2362 (buffer-enable-undo)
2364 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2366 (defun gnus-article-edit (&optional force)
2367 "Edit the current article.
2368 This will have permanent effect only in mail groups.
2369 If FORCE is non-nil, allow editing of articles even in read-only
2372 (when (and (not force)
2373 (gnus-group-read-only-p))
2374 (error "The current newsgroup does not support article editing."))
2375 (gnus-article-edit-article
2377 (gnus-summary-edit-article-done
2378 ,(or (mail-header-references gnus-current-headers) "")
2379 ,(gnus-group-read-only-p) ,gnus-summary-buffer))))
2381 (defun gnus-article-edit-article (exit-func)
2382 "Start editing the contents of the current article buffer."
2383 (let ((winconf (current-window-configuration)))
2384 (set-buffer gnus-article-buffer)
2385 (gnus-article-edit-mode)
2386 (set-text-properties (point-min) (point-max) nil)
2387 (gnus-configure-windows 'edit-article)
2388 (setq gnus-article-edit-done-function exit-func)
2389 (setq gnus-prev-winconf winconf)
2390 (gnus-message 6 "C-c C-c to end edits")))
2392 (defun gnus-article-edit-done ()
2393 "Update the article edits and exit."
2395 (let ((func gnus-article-edit-done-function)
2396 (buf (current-buffer))
2397 (start (window-start)))
2398 (gnus-article-edit-exit)
2401 (let ((buffer-read-only nil))
2404 (set-window-start (get-buffer-window buf) start)
2405 (set-window-point (get-buffer-window buf) (point))))
2407 (defun gnus-article-edit-exit ()
2408 "Exit the article editing without updating."
2410 ;; We remove all text props from the article buffer.
2411 (let ((buf (format "%s" (buffer-string)))
2412 (curbuf (current-buffer))
2414 (window-start (window-start)))
2417 (let ((winconf gnus-prev-winconf))
2419 ;; The cache and backlog have to be flushed somewhat.
2420 (when gnus-use-cache
2421 (gnus-cache-update-article
2422 (car gnus-article-current) (cdr gnus-article-current)))
2423 (when gnus-keep-backlog
2424 (gnus-backlog-remove-article
2425 (car gnus-article-current) (cdr gnus-article-current)))
2426 ;; Flush original article as well.
2428 (when (get-buffer gnus-original-article-buffer)
2429 (set-buffer gnus-original-article-buffer)
2430 (setq gnus-original-article nil)))
2431 (set-window-configuration winconf)
2432 ;; Tippy-toe some to make sure that point remains where it was.
2433 (let ((buf (current-buffer)))
2435 (set-window-start (get-buffer-window (current-buffer)) window-start)
2437 (set-buffer buf)))))
2439 (defun gnus-article-edit-full-stops ()
2440 "Interactively repair spacing at end of sentences."
2443 (goto-char (point-min))
2444 (search-forward-regexp "^$" nil t)
2445 (let ((case-fold-search nil))
2446 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2449 ;;; Article highlights
2452 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2454 ;;; Internal Variables:
2456 (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\\)"
2457 "Regular expression that matches URLs."
2458 :group 'gnus-article-buttons
2461 (defcustom gnus-button-alist
2462 `(("\\(\\b<\\(url: ?\\)?news:\\([^>\n\t ]*\\)>\\)" 1 t
2463 gnus-button-message-id 3)
2464 ("\\bnews:\\([^\n\t ]+\\)" 0 t gnus-button-message-id 1)
2465 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2466 gnus-button-fetch-group 4)
2467 ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2468 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2469 t gnus-button-message-id 3)
2470 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1)
2471 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2)
2472 ;; This is how URLs _should_ be embedded in text...
2473 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2475 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2476 "Alist of regexps matching buttons in article bodies.
2478 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2479 REGEXP: is the string matching text around the button,
2480 BUTTON: is the number of the regexp grouping actually matching the button,
2481 FORM: is a lisp expression which must eval to true for the button to
2483 CALLBACK: is the function to call when the user push this button, and each
2484 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2486 CALLBACK can also be a variable, in that case the value of that
2487 variable it the real callback function."
2488 :group 'gnus-article-buttons
2489 :type '(repeat (list regexp
2490 (integer :tag "Button")
2492 (function :tag "Callback")
2495 (integer :tag "Regexp group")))))
2497 (defcustom gnus-header-button-alist
2498 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2499 0 t gnus-button-message-id 0)
2500 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2501 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2502 0 t gnus-button-mailto 0)
2503 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2504 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2505 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2506 gnus-button-message-id 3))
2507 "Alist of headers and regexps to match buttons in article heads.
2509 This alist is very similar to `gnus-button-alist', except that each
2510 alist has an additional HEADER element first in each entry:
2512 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2514 HEADER is a regexp to match a header. For a fuller explanation, see
2515 `gnus-button-alist'."
2516 :group 'gnus-article-buttons
2517 :group 'gnus-article-headers
2518 :type '(repeat (list (regexp :tag "Header")
2520 (integer :tag "Button")
2522 (function :tag "Callback")
2525 (integer :tag "Regexp group")))))
2527 (defvar gnus-button-regexp nil)
2528 (defvar gnus-button-marker-list nil)
2529 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2531 (defvar gnus-button-last nil)
2532 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2536 (defun gnus-article-push-button (event)
2537 "Check text under the mouse pointer for a callback function.
2538 If the text under the mouse pointer has a `gnus-callback' property,
2539 call it with the value of the `gnus-data' text property."
2541 (set-buffer (window-buffer (posn-window (event-start event))))
2542 (let* ((pos (posn-point (event-start event)))
2543 (data (get-text-property pos 'gnus-data))
2544 (fun (get-text-property pos 'gnus-callback)))
2546 (funcall fun data))))
2548 (defun gnus-article-press-button ()
2549 "Check text at point for a callback function.
2550 If the text at point has a `gnus-callback' property,
2551 call it with the value of the `gnus-data' text property."
2553 (let* ((data (get-text-property (point) 'gnus-data))
2554 (fun (get-text-property (point) 'gnus-callback)))
2556 (funcall fun data))))
2558 (defun gnus-article-prev-button (n)
2559 "Move point to N buttons backward.
2560 If N is negative, move forward instead."
2562 (gnus-article-next-button (- n)))
2564 (defun gnus-article-next-button (n)
2565 "Move point to N buttons forward.
2566 If N is negative, move backward instead."
2568 (let ((function (if (< n 0) 'previous-single-property-change
2569 'next-single-property-change))
2570 (inhibit-point-motion-hooks t)
2572 (limit (if (< n 0) (point-min) (point-max))))
2574 (while (and (not (= limit (point)))
2576 ;; Skip past the current button.
2577 (when (get-text-property (point) 'gnus-callback)
2578 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2579 ;; Go to the next (or previous) button.
2580 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2581 ;; Put point at the start of the button.
2582 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2583 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2584 ;; Skip past intangible buttons.
2585 (when (get-text-property (point) 'intangible)
2589 (gnus-message 5 "No more buttons"))
2592 (defun gnus-article-highlight (&optional force)
2593 "Highlight current article.
2594 This function calls `gnus-article-highlight-headers',
2595 `gnus-article-highlight-citation',
2596 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2597 do the highlighting. See the documentation for those functions."
2598 (interactive (list 'force))
2599 (gnus-article-highlight-headers)
2600 (gnus-article-highlight-citation force)
2601 (gnus-article-highlight-signature)
2602 (gnus-article-add-buttons force)
2603 (gnus-article-add-buttons-to-head))
2605 (defun gnus-article-highlight-some (&optional force)
2606 "Highlight current article.
2607 This function calls `gnus-article-highlight-headers',
2608 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2609 do the highlighting. See the documentation for those functions."
2610 (interactive (list 'force))
2611 (gnus-article-highlight-headers)
2612 (gnus-article-highlight-signature)
2613 (gnus-article-add-buttons))
2615 (defun gnus-article-highlight-headers ()
2616 "Highlight article headers as specified by `gnus-header-face-alist'."
2619 (set-buffer gnus-article-buffer)
2621 (let ((alist gnus-header-face-alist)
2622 (buffer-read-only nil)
2623 (case-fold-search t)
2624 (inhibit-point-motion-hooks t)
2625 entry regexp header-face field-face from hpoints fpoints)
2626 (goto-char (point-min))
2627 (when (search-forward "\n\n" nil t)
2628 (narrow-to-region (1- (point)) (point-min))
2629 (while (setq entry (pop alist))
2630 (goto-char (point-min))
2631 (setq regexp (concat "^\\("
2632 (if (string-equal "" (nth 0 entry))
2636 header-face (nth 1 entry)
2637 field-face (nth 2 entry))
2638 (while (and (re-search-forward regexp nil t)
2642 (unless (search-forward ":" nil t)
2644 (when (and header-face
2645 (not (memq (point) hpoints)))
2646 (push (point) hpoints)
2647 (gnus-put-text-property from (point) 'face header-face))
2648 (when (and field-face
2649 (not (memq (setq from (point)) fpoints)))
2651 (if (re-search-forward "^[^ \t]" nil t)
2653 (goto-char (point-max)))
2654 (gnus-put-text-property from (point) 'face field-face)))))))))
2656 (defun gnus-article-highlight-signature ()
2657 "Highlight the signature in an article.
2658 It does this by highlighting everything after
2659 `gnus-signature-separator' using `gnus-signature-face'."
2662 (set-buffer gnus-article-buffer)
2663 (let ((buffer-read-only nil)
2664 (inhibit-point-motion-hooks t))
2666 (when (and gnus-signature-face
2667 (gnus-article-narrow-to-signature))
2668 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2669 'face gnus-signature-face)
2671 (gnus-article-search-signature)
2672 (let ((start (match-beginning 0))
2673 (end (set-marker (make-marker) (1+ (match-end 0)))))
2674 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2677 (defun gnus-article-add-buttons (&optional force)
2678 "Find external references in the article and make buttons of them.
2679 \"External references\" are things like Message-IDs and URLs, as
2680 specified by `gnus-button-alist'."
2681 (interactive (list 'force))
2683 (set-buffer gnus-article-buffer)
2684 ;; Remove all old markers.
2685 (while gnus-button-marker-list
2686 (set-marker (pop gnus-button-marker-list) nil))
2687 (let ((buffer-read-only nil)
2688 (inhibit-point-motion-hooks t)
2689 (case-fold-search t)
2690 (alist gnus-button-alist)
2692 (goto-char (point-min))
2693 ;; We skip the headers.
2694 (unless (search-forward "\n\n" nil t)
2695 (goto-char (point-max)))
2697 (while (setq entry (pop alist))
2698 (setq regexp (car entry))
2700 (while (re-search-forward regexp nil t)
2701 (let* ((start (and entry (match-beginning (nth 1 entry))))
2702 (end (and entry (match-end (nth 1 entry))))
2703 (from (match-beginning 0)))
2704 (when (and (or (eq t (nth 1 entry))
2705 (eval (nth 1 entry)))
2706 (not (get-text-property (point) 'gnus-callback)))
2707 ;; That optional form returned non-nil, so we add the
2709 (gnus-article-add-button
2710 start end 'gnus-button-push
2711 (car (push (set-marker (make-marker) from)
2712 gnus-button-marker-list))))))))))
2714 ;; Add buttons to the head of an article.
2715 (defun gnus-article-add-buttons-to-head ()
2716 "Add buttons to the head of the article."
2719 (set-buffer gnus-article-buffer)
2720 (let ((buffer-read-only nil)
2721 (inhibit-point-motion-hooks t)
2722 (case-fold-search t)
2723 (alist gnus-header-button-alist)
2725 (nnheader-narrow-to-headers)
2727 ;; Each alist entry.
2728 (setq entry (car alist)
2730 (goto-char (point-min))
2731 (while (re-search-forward (car entry) nil t)
2732 ;; Each header matching the entry.
2733 (setq beg (match-beginning 0))
2734 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2735 (match-beginning 0))
2738 (while (re-search-forward (nth 1 entry) end t)
2739 ;; Each match within a header.
2740 (let* ((entry (cdr entry))
2741 (start (match-beginning (nth 1 entry)))
2742 (end (match-end (nth 1 entry)))
2743 (form (nth 2 entry)))
2744 (goto-char (match-end 0))
2746 (gnus-article-add-button
2747 start end (nth 3 entry)
2748 (buffer-substring (match-beginning (nth 4 entry))
2749 (match-end (nth 4 entry)))))))
2753 ;;; External functions:
2755 (defun gnus-article-add-button (from to fun &optional data)
2756 "Create a button between FROM and TO with callback FUN and data DATA."
2757 (when gnus-article-button-face
2758 (gnus-overlay-put (gnus-make-overlay from to)
2759 'face gnus-article-button-face))
2760 (gnus-add-text-properties
2762 (nconc (and gnus-article-mouse-face
2763 (list gnus-mouse-face-prop gnus-article-mouse-face))
2764 (list 'gnus-callback fun)
2765 (and data (list 'gnus-data data)))))
2767 ;;; Internal functions:
2769 (defun gnus-signature-toggle (end)
2771 (set-buffer gnus-article-buffer)
2772 (let ((buffer-read-only nil)
2773 (inhibit-point-motion-hooks t))
2774 (if (get-text-property end 'invisible)
2775 (gnus-article-unhide-text end (point-max))
2776 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2778 (defun gnus-button-entry ()
2779 ;; Return the first entry in `gnus-button-alist' matching this place.
2780 (let ((alist gnus-button-alist)
2783 (setq entry (pop alist))
2784 (if (looking-at (car entry))
2789 (defun gnus-button-push (marker)
2790 ;; Push button starting at MARKER.
2792 (set-buffer gnus-article-buffer)
2794 (let* ((entry (gnus-button-entry))
2795 (inhibit-point-motion-hooks t)
2797 (args (mapcar (lambda (group)
2798 (let ((string (match-string group)))
2799 (gnus-set-text-properties
2800 0 (length string) nil string)
2807 (fboundp (symbol-value fun)))
2808 (apply (symbol-value fun) args))
2810 (gnus-message 1 "You must define `%S' to use this button"
2811 (cons fun args)))))))
2813 (defun gnus-button-message-id (message-id)
2816 (set-buffer gnus-summary-buffer)
2817 (gnus-summary-refer-article message-id)))
2819 (defun gnus-button-fetch-group (address)
2820 "Fetch GROUP specified by ADDRESS."
2821 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address))
2822 (error "Can't parse %s" address)
2823 (gnus-group-read-ephemeral-group
2824 (match-string 4 address)
2825 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address))
2826 (nntp-port-number ,(if (match-end 3)
2827 (match-string 3 address)
2830 (defun gnus-split-string (string pattern)
2831 "Return a list of substrings of STRING which are separated by PATTERN."
2832 (let (parts (start 0))
2833 (while (string-match pattern string start)
2834 (setq parts (cons (substring string start (match-beginning 0)) parts)
2835 start (match-end 0)))
2836 (nreverse (cons (substring string start) parts))))
2838 (defun gnus-url-parse-query-string (query &optional downcase)
2839 (let (retval pairs cur key val)
2840 (setq pairs (gnus-split-string query "&"))
2842 (setq cur (car pairs)
2844 (if (not (string-match "=" cur))
2846 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
2847 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
2849 (setq key (downcase key)))
2850 (setq cur (assoc key retval))
2852 (setcdr cur (cons val (cdr cur)))
2853 (setq retval (cons (list key val) retval)))))
2856 (defun gnus-url-unhex (x)
2863 (defun gnus-url-unhex-string (str &optional allow-newlines)
2864 "Remove %XXX embedded spaces, etc in a url.
2865 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
2866 decoding of carriage returns and line feeds in the string, which is normally
2867 forbidden in URL encoding."
2868 (setq str (or str ""))
2870 (case-fold-search t))
2871 (while (string-match "%[0-9a-f][0-9a-f]" str)
2872 (let* ((start (match-beginning 0))
2873 (ch1 (gnus-url-unhex (elt str (+ start 1))))
2875 (gnus-url-unhex (elt str (+ start 2))))))
2877 tmp (substring str 0 start)
2880 (char-to-string code))
2881 ((or (= code ?\n) (= code ?\r))
2883 (t (char-to-string code))))
2884 str (substring str (match-end 0)))))
2885 (setq tmp (concat tmp str))
2888 (defun gnus-url-mailto (url)
2889 ;; Send mail to someone
2890 (when (string-match "mailto:/*\\(.*\\)" url)
2891 (setq url (substring url (match-beginning 1) nil)))
2892 (let (to args source-url subject func)
2893 (if (string-match (regexp-quote "?") url)
2894 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
2895 args (gnus-url-parse-query-string
2896 (substring url (match-end 0) nil) t))
2897 (setq to (gnus-url-unhex-string url)))
2898 (setq args (cons (list "to" to) args)
2899 subject (cdr-safe (assoc "subject" args)))
2902 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
2905 (message-position-on-field (caar args)))
2906 (insert (mapconcat 'identity (cdar args) ", "))
2907 (setq args (cdr args)))
2910 (message-goto-subject))))
2912 (defun gnus-button-mailto (address)
2914 (set-buffer (gnus-copy-article-buffer))
2915 (message-reply address))
2917 (defun gnus-button-reply (address)
2918 ;; Reply to ADDRESS.
2919 (message-reply address))
2921 (defun gnus-button-url (address)
2923 (funcall browse-url-browser-function address))
2925 (defun gnus-button-embedded-url (address)
2927 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
2929 ;;; Next/prev buttons in the article buffer.
2931 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
2932 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
2934 (defvar gnus-prev-page-map nil)
2935 (unless gnus-prev-page-map
2936 (setq gnus-prev-page-map (make-sparse-keymap))
2937 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
2938 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
2940 (defun gnus-insert-prev-page-button ()
2941 (let ((buffer-read-only nil))
2943 gnus-prev-page-line-format nil
2944 `(gnus-prev t local-map ,gnus-prev-page-map
2945 gnus-callback gnus-article-button-prev-page))))
2947 (defvar gnus-next-page-map nil)
2948 (unless gnus-next-page-map
2949 (setq gnus-next-page-map (make-keymap))
2950 (suppress-keymap gnus-prev-page-map)
2951 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
2952 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
2954 (defun gnus-button-next-page ()
2955 "Go to the next page."
2957 (let ((win (selected-window)))
2958 (select-window (get-buffer-window gnus-article-buffer t))
2959 (gnus-article-next-page)
2960 (select-window win)))
2962 (defun gnus-button-prev-page ()
2963 "Go to the prev page."
2965 (let ((win (selected-window)))
2966 (select-window (get-buffer-window gnus-article-buffer t))
2967 (gnus-article-prev-page)
2968 (select-window win)))
2970 (defun gnus-insert-next-page-button ()
2971 (let ((buffer-read-only nil))
2972 (gnus-eval-format gnus-next-page-line-format nil
2973 `(gnus-next t local-map ,gnus-next-page-map
2975 gnus-article-button-next-page))))
2977 (defun gnus-article-button-next-page (arg)
2978 "Go to the next page."
2980 (let ((win (selected-window)))
2981 (select-window (get-buffer-window gnus-article-buffer t))
2982 (gnus-article-next-page)
2983 (select-window win)))
2985 (defun gnus-article-button-prev-page (arg)
2986 "Go to the prev page."
2988 (let ((win (selected-window)))
2989 (select-window (get-buffer-window gnus-article-buffer t))
2990 (gnus-article-prev-page)
2991 (select-window win)))
2997 (run-hooks 'gnus-art-load-hook)
2999 ;;; gnus-art.el ends here