1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
40 (defgroup gnus-article nil
42 :link '(custom-manual "(gnus)The Article Buffer")
45 (defgroup gnus-article-hiding nil
46 "Hiding article parts."
47 :link '(custom-manual "(gnus)Article Hiding")
50 (defgroup gnus-article-highlight nil
51 "Article highlighting."
52 :link '(custom-manual "(gnus)Article Highlighting")
56 (defgroup gnus-article-signature nil
58 :link '(custom-manual "(gnus)Article Signature")
61 (defgroup gnus-article-headers nil
63 :link '(custom-manual "(gnus)Hiding Headers")
66 (defgroup gnus-article-washing nil
67 "Special commands on articles."
68 :link '(custom-manual "(gnus)Article Washing")
71 (defgroup gnus-article-emphasis nil
72 "Fontisizing articles."
73 :link '(custom-manual "(gnus)Article Fontisizing")
76 (defgroup gnus-article-saving nil
78 :link '(custom-manual "(gnus)Saving Articles")
81 (defgroup gnus-article-mime nil
82 "Worshiping the MIME wonder."
83 :link '(custom-manual "(gnus)Using MIME")
86 (defgroup gnus-article-buttons nil
87 "Pushable buttons in the article buffer."
88 :link '(custom-manual "(gnus)Article Buttons")
91 (defgroup gnus-article-various nil
92 "Other article options."
93 :link '(custom-manual "(gnus)Misc Article")
96 (defcustom gnus-ignored-headers
97 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
98 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
99 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
100 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
101 "All headers that start with this regexp will be hidden.
102 This variable can also be a list of regexps of headers to be ignored.
103 If `gnus-visible-headers' is non-nil, this variable will be ignored."
104 :type '(choice :custom-show nil
107 :group 'gnus-article-hiding)
109 (defcustom gnus-visible-headers
110 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
111 "All headers that do not match this regexp will be hidden.
112 This variable can also be a list of regexp of headers to remain visible.
113 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
114 :type '(repeat :value-to-internal (lambda (widget value)
115 (custom-split-regexp-maybe value))
116 :match (lambda (widget value)
118 (widget-editable-list-match widget value)))
120 :group 'gnus-article-hiding)
122 (defcustom gnus-sorted-header-list
123 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
124 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
125 "This variable is a list of regular expressions.
126 If it is non-nil, headers that match the regular expressions will
127 be placed first in the article buffer in the sequence specified by
129 :type '(repeat regexp)
130 :group 'gnus-article-hiding)
132 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
133 "Headers that are only to be displayed if they have interesting data.
134 Possible values in this list are `empty', `newsgroups', `followup-to',
135 `reply-to', `date', `long-to', and `many-to'."
136 :type '(set (const :tag "Headers with no content." empty)
137 (const :tag "Newsgroups with only one group." newsgroups)
138 (const :tag "Followup-to identical to newsgroups." followup-to)
139 (const :tag "Reply-to identical to from." reply-to)
140 (const :tag "Date less than four days old." date)
141 (const :tag "Very long To header." long-to)
142 (const :tag "Multiple To headers." many-to))
143 :group 'gnus-article-hiding)
145 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
146 "Regexp matching signature separator.
147 This can also be a list of regexps. In that case, it will be checked
148 from head to tail looking for a separator. Searches will be done from
149 the end of the buffer."
150 :type '(repeat string)
151 :group 'gnus-article-signature)
153 (defcustom gnus-signature-limit nil
154 "Provide a limit to what is considered a signature.
155 If it is a number, no signature may not be longer (in characters) than
156 that number. If it is a floating point number, no signature may be
157 longer (in lines) than that number. If it is a function, the function
158 will be called without any parameters, and if it returns nil, there is
159 no signature in the buffer. If it is a string, it will be used as a
160 regexp. If it matches, the text in question is not a signature."
161 :type '(choice (integer :value 200)
163 (function :value fun)
164 (regexp :value ".*"))
165 :group 'gnus-article-signature)
167 (defcustom gnus-hidden-properties '(invisible t intangible t)
168 "Property list to use for hiding text."
170 :group 'gnus-article-hiding)
172 (defcustom gnus-article-x-face-command
173 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
174 "String or function to be executed to display an X-Face header.
175 If it is a string, the command will be executed in a sub-shell
176 asynchronously. The compressed face will be piped to this command."
177 :type 'string ;Leave function case to Lisp.
178 :group 'gnus-article-washing)
180 (defcustom gnus-article-x-face-too-ugly nil
181 "Regexp matching posters whose face shouldn't be shown automatically."
182 :type '(choice regexp (const nil))
183 :group 'gnus-article-washing)
185 (defcustom gnus-emphasis-alist
187 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
189 '(("_" "_" underline)
192 ("_/" "/_" underline-italic)
193 ("_\\*" "\\*_" underline-bold)
194 ("\\*/" "/\\*" bold-italic)
195 ("_\\*/" "/\\*_" underline-bold-italic))))
196 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
197 2 3 gnus-emphasis-underline)
201 (format format (car spec) (cadr spec))
202 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
204 "Alist that says how to fontify certain phrases.
205 Each item looks like this:
207 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
209 The first element is a regular expression to be matched. The second
210 is a number that says what regular expression grouping used to find
211 the entire emphasized word. The third is a number that says what
212 regexp grouping should be displayed and highlighted. The fourth
213 is the face used for highlighting."
214 :type '(repeat (list :value ("" 0 0 default)
216 (integer :tag "Match group")
217 (integer :tag "Emphasize group")
219 :group 'gnus-article-emphasis)
221 (defface gnus-emphasis-bold '((t (:bold t)))
222 "Face used for displaying strong emphasized text (*word*)."
223 :group 'gnus-article-emphasis)
225 (defface gnus-emphasis-italic '((t (:italic t)))
226 "Face used for displaying italic emphasized text (/word/)."
227 :group 'gnus-article-emphasis)
229 (defface gnus-emphasis-underline '((t (:underline t)))
230 "Face used for displaying underlined emphasized text (_word_)."
231 :group 'gnus-article-emphasis)
233 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
234 "Face used for displaying underlined bold emphasized text (_*word*_)."
235 :group 'gnus-article-emphasis)
237 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
238 "Face used for displaying underlined italic emphasized text (_*word*_)."
239 :group 'gnus-article-emphasis)
241 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
242 "Face used for displaying bold italic emphasized text (/*word*/)."
243 :group 'gnus-article-emphasis)
245 (defface gnus-emphasis-underline-bold-italic
246 '((t (:bold t :italic t :underline t)))
247 "Face used for displaying underlined bold italic emphasized text.
248 Esample: (_/*word*/_)."
249 :group 'gnus-article-emphasis)
251 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
252 "Format for display of Date headers in article bodies.
253 See `format-time-string' for the possible values."
255 :link '(custom-manual "(gnus)Article Date")
256 :group 'gnus-article-washing)
259 (autoload 'hexl-hex-string-to-integer "hexl")
260 (autoload 'timezone-make-date-arpa-standard "timezone")
261 (autoload 'mail-extract-address-components "mail-extr"))
263 (defcustom gnus-save-all-headers t
264 "*If non-nil, don't remove any headers before saving."
265 :group 'gnus-article-saving
268 (defcustom gnus-prompt-before-saving 'always
269 "*This variable says how much prompting is to be done when saving articles.
270 If it is nil, no prompting will be done, and the articles will be
271 saved to the default files. If this variable is `always', each and
272 every article that is saved will be preceded by a prompt, even when
273 saving large batches of articles. If this variable is neither nil not
274 `always', there the user will be prompted once for a file name for
275 each invocation of the saving commands."
276 :group 'gnus-article-saving
277 :type '(choice (item always)
278 (item :tag "never" nil)
279 (sexp :tag "once" :format "%t\n" :value t)))
281 (defcustom gnus-saved-headers gnus-visible-headers
282 "Headers to keep if `gnus-save-all-headers' is nil.
283 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
284 If that variable is nil, however, all headers that match this regexp
285 will be kept while the rest will be deleted before saving."
286 :group 'gnus-article-saving
289 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
290 "A function to save articles in your favourite format.
291 The function must be interactively callable (in other words, it must
292 be an Emacs command).
294 Gnus provides the following functions:
296 * gnus-summary-save-in-rmail (Rmail format)
297 * gnus-summary-save-in-mail (Unix mail format)
298 * gnus-summary-save-in-folder (MH folder)
299 * gnus-summary-save-in-file (article format)
300 * gnus-summary-save-in-vm (use VM's folder format)
301 * gnus-summary-write-to-file (article format -- overwrite)."
302 :group 'gnus-article-saving
303 :type '(radio (function-item gnus-summary-save-in-rmail)
304 (function-item gnus-summary-save-in-mail)
305 (function-item gnus-summary-save-in-folder)
306 (function-item gnus-summary-save-in-file)
307 (function-item gnus-summary-save-in-vm)
308 (function-item gnus-summary-write-to-file)))
310 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
311 "A function generating a file name to save articles in Rmail format.
312 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
313 :group 'gnus-article-saving
316 (defcustom gnus-mail-save-name 'gnus-plain-save-name
317 "A function generating a file name to save articles in Unix mail format.
318 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
319 :group 'gnus-article-saving
322 (defcustom gnus-folder-save-name 'gnus-folder-save-name
323 "A function generating a file name to save articles in MH folder.
324 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
325 :group 'gnus-article-saving
328 (defcustom gnus-file-save-name 'gnus-numeric-save-name
329 "A function generating a file name to save articles in article format.
330 The function is called with NEWSGROUP, HEADERS, and optional
332 :group 'gnus-article-saving
335 (defcustom gnus-split-methods
336 '((gnus-article-archive-name)
337 (gnus-article-nndoc-name))
338 "Variable used to suggest where articles are to be saved.
339 For instance, if you would like to save articles related to Gnus in
340 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
341 you could set this variable to something like:
343 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
344 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
346 This variable is an alist where the where the key is the match and the
347 value is a list of possible files to save in if the match is non-nil.
349 If the match is a string, it is used as a regexp match on the
350 article. If the match is a symbol, that symbol will be funcalled
351 from the buffer of the article to be saved with the newsgroup as the
352 parameter. If it is a list, it will be evaled in the same buffer.
354 If this form or function returns a string, this string will be used as
355 a possible file name; and if it returns a non-nil list, that list will
356 be used as possible file names."
357 :group 'gnus-article-saving
358 :type '(repeat (choice (list :value (fun) function)
359 (cons :value ("" "") regexp (repeat string))
362 (defcustom gnus-strict-mime t
363 "*If nil, MIME-decode even if there is no Mime-Version header."
364 :group 'gnus-article-mime
367 (defcustom gnus-show-mime-method 'gnus-article-preview-mime-message
368 "Function to process a MIME message.
369 The function is called from the article buffer."
370 :group 'gnus-article-mime
373 (defcustom gnus-decode-encoded-word-method 'gnus-article-decode-encoded-word
374 "*Function to decode MIME encoded words.
375 The function is called from the article buffer."
376 :group 'gnus-article-mime
379 (defcustom gnus-page-delimiter "^\^L"
380 "*Regexp describing what to use as article page delimiters.
381 The default value is \"^\^L\", which is a form linefeed at the
382 beginning of a line."
384 :group 'gnus-article-various)
386 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
387 "*The format specification for the article mode line.
388 See `gnus-summary-mode-line-format' for a closer description."
390 :group 'gnus-article-various)
392 (defcustom gnus-article-mode-hook nil
393 "*A hook for Gnus article mode."
395 :group 'gnus-article-various)
397 (defcustom gnus-article-menu-hook nil
398 "*Hook run after the creation of the article mode menu."
400 :group 'gnus-article-various)
402 (defcustom gnus-article-prepare-hook nil
403 "*A hook called after an article has been prepared in the article buffer.
404 If you want to run a special decoding program like nkf, use this hook."
406 :group 'gnus-article-various)
408 (defcustom gnus-article-hide-pgp-hook nil
409 "*A hook called after successfully hiding a PGP signature."
411 :group 'gnus-article-various)
413 (defcustom gnus-article-button-face 'bold
414 "Face used for highlighting buttons in the article buffer.
416 An article button is a piece of text that you can activate by pressing
417 `RET' or `mouse-2' above it."
419 :group 'gnus-article-buttons)
421 (defcustom gnus-article-mouse-face 'highlight
422 "Face used for mouse highlighting in the article buffer.
424 Article buttons will be displayed in this face when the cursor is
427 :group 'gnus-article-buttons)
429 (defcustom gnus-signature-face 'gnus-signature-face
430 "Face used for highlighting a signature in the article buffer.
431 Obsolete; use the face `gnus-signature-face' for customizations instead."
433 :group 'gnus-article-highlight
434 :group 'gnus-article-signature)
436 (defface gnus-signature-face
439 "Face used for highlighting a signature in the article buffer."
440 :group 'gnus-article-highlight
441 :group 'gnus-article-signature)
443 (defface gnus-header-from-face
446 (:foreground "spring green" :bold t))
449 (:foreground "red3" :bold t))
451 (:bold t :italic t)))
452 "Face used for displaying from headers."
453 :group 'gnus-article-headers
454 :group 'gnus-article-highlight)
456 (defface gnus-header-subject-face
459 (:foreground "SeaGreen3" :bold t))
462 (:foreground "red4" :bold t))
464 (:bold t :italic t)))
465 "Face used for displaying subject headers."
466 :group 'gnus-article-headers
467 :group 'gnus-article-highlight)
469 (defface gnus-header-newsgroups-face
472 (:foreground "yellow" :bold t :italic t))
475 (:foreground "MidnightBlue" :bold t :italic t))
477 (:bold t :italic t)))
478 "Face used for displaying newsgroups headers."
479 :group 'gnus-article-headers
480 :group 'gnus-article-highlight)
482 (defface gnus-header-name-face
485 (:foreground "SeaGreen"))
488 (:foreground "maroon"))
491 "Face used for displaying header names."
492 :group 'gnus-article-headers
493 :group 'gnus-article-highlight)
495 (defface gnus-header-content-face
498 (:foreground "forest green" :italic t))
501 (:foreground "indianred4" :italic t))
503 (:italic t))) "Face used for displaying header content."
504 :group 'gnus-article-headers
505 :group 'gnus-article-highlight)
507 (defcustom gnus-header-face-alist
508 '(("From" nil gnus-header-from-face)
509 ("Subject" nil gnus-header-subject-face)
510 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
511 ("" gnus-header-name-face gnus-header-content-face))
512 "Controls highlighting of article header.
514 An alist of the form (HEADER NAME CONTENT).
516 HEADER is a regular expression which should match the name of an
517 header header and NAME and CONTENT are either face names or nil.
519 The name of each header field will be displayed using the face
520 specified by the first element in the list where HEADER match the
521 header name and NAME is non-nil. Similarly, the content will be
522 displayed by the first non-nil matching CONTENT face."
523 :group 'gnus-article-headers
524 :group 'gnus-article-highlight
525 :type '(repeat (list (regexp :tag "Header")
527 (item :tag "skip" nil)
528 (face :value default))
529 (choice :tag "Content"
530 (item :tag "skip" nil)
531 (face :value default)))))
533 ;;; Internal variables
535 (defvar article-lapsed-timer nil)
537 (defvar gnus-article-mode-syntax-table
538 (let ((table (copy-syntax-table text-mode-syntax-table)))
539 (modify-syntax-entry ?- "w" table)
540 (modify-syntax-entry ?> ")" table)
541 (modify-syntax-entry ?< "(" table)
543 "Syntax table used in article mode buffers.
544 Initialized from `text-mode-syntax-table.")
546 (defvar gnus-save-article-buffer nil)
548 (defvar gnus-article-mode-line-format-alist
549 (nconc '((?w (gnus-article-wash-status) ?s))
550 gnus-summary-mode-line-format-alist))
552 (defvar gnus-number-of-articles-to-be-saved nil)
554 (defvar gnus-inhibit-hiding nil)
556 (defsubst gnus-article-hide-text (b e props)
557 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
558 (add-text-properties b e props)
559 (when (memq 'intangible props)
561 (max (1- b) (point-min))
562 b 'intangible (cddr (memq 'intangible props)))))
564 (defsubst gnus-article-unhide-text (b e)
565 "Remove hidden text properties from region between B and E."
566 (remove-text-properties b e gnus-hidden-properties)
567 (when (memq 'intangible gnus-hidden-properties)
568 (put-text-property (max (1- b) (point-min))
571 (defun gnus-article-hide-text-type (b e type)
572 "Hide text of TYPE between B and E."
573 (gnus-article-hide-text
574 b e (cons 'article-type (cons type gnus-hidden-properties))))
576 (defun gnus-article-unhide-text-type (b e type)
577 "Hide text of TYPE between B and E."
578 (remove-text-properties
579 b e (cons 'article-type (cons type gnus-hidden-properties)))
580 (when (memq 'intangible gnus-hidden-properties)
581 (put-text-property (max (1- b) (point-min))
584 (defun gnus-article-hide-text-of-type (type)
585 "Hide text of TYPE in the current buffer."
587 (let ((b (point-min))
589 (while (setq b (text-property-any b e 'article-type type))
590 (add-text-properties b (incf b) gnus-hidden-properties)))))
592 (defun gnus-article-delete-text-of-type (type)
593 "Delete text of TYPE in the current buffer."
595 (let ((b (point-min)))
596 (while (setq b (text-property-any b (point-max) 'article-type type))
598 b (or (text-property-not-all b (point-max) 'article-type type)
601 (defun gnus-article-delete-invisible-text ()
602 "Delete all invisible text in the current buffer."
604 (let ((b (point-min)))
605 (while (setq b (text-property-any b (point-max) 'invisible t))
607 b (or (text-property-not-all b (point-max) 'invisible t)
610 (defun gnus-article-text-type-exists-p (type)
611 "Say whether any text of type TYPE exists in the buffer."
612 (text-property-any (point-min) (point-max) 'article-type type))
614 (defsubst gnus-article-header-rank ()
615 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
616 (let ((list gnus-sorted-header-list)
619 (when (looking-at (car list))
621 (setq list (cdr list))
625 (defun article-hide-headers (&optional arg delete)
626 "Toggle whether to hide unwanted headers and possibly sort them as well.
627 If given a negative prefix, always show; if given a positive prefix,
629 (interactive (gnus-article-hidden-arg))
631 (if (gnus-article-check-hidden-text 'headers arg)
632 ;; Show boring headers as well.
633 (gnus-article-show-hidden-text 'boring-headers)
634 ;; This function might be inhibited.
635 (unless gnus-inhibit-hiding
638 (let ((buffer-read-only nil)
639 (props (nconc (list 'article-type 'headers)
640 gnus-hidden-properties))
641 (max (1+ (length gnus-sorted-header-list)))
642 (ignored (when (not gnus-visible-headers)
643 (cond ((stringp gnus-ignored-headers)
644 gnus-ignored-headers)
645 ((listp gnus-ignored-headers)
646 (mapconcat 'identity gnus-ignored-headers
649 (cond ((stringp gnus-visible-headers)
650 gnus-visible-headers)
651 ((and gnus-visible-headers
652 (listp gnus-visible-headers))
653 (mapconcat 'identity gnus-visible-headers "\\|"))))
654 (inhibit-point-motion-hooks t)
656 ;; First we narrow to just the headers.
658 (goto-char (point-min))
659 ;; Hide any "From " lines at the beginning of (mail) articles.
660 (while (looking-at "From ")
664 (delete-region (point-min) (point))
665 (gnus-article-hide-text (point-min) (point) props)))
666 ;; Then treat the rest of the header lines.
669 (if (search-forward "\n\n" nil t) ; if there's a body
670 (progn (forward-line -1) (point))
672 ;; Then we use the two regular expressions
673 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
674 ;; select which header lines is to remain visible in the
676 (goto-char (point-min))
677 (while (re-search-forward "^[^ \t]*:" nil t)
679 ;; Mark the rank of the header.
681 (point) (1+ (point)) 'message-rank
682 (if (or (and visible (looking-at visible))
684 (not (looking-at ignored))))
685 (gnus-article-header-rank)
688 (message-sort-headers-1)
689 (when (setq beg (text-property-any
690 (point-min) (point-max) 'message-rank (+ 2 max)))
691 ;; We make the unwanted headers invisible.
693 (delete-region beg (point-max))
694 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
695 (gnus-article-hide-text-type beg (point-max) 'headers))
696 ;; Work around XEmacs lossage.
697 (put-text-property (point-min) beg 'invisible nil))))))))
699 (defun article-hide-boring-headers (&optional arg)
700 "Toggle hiding of headers that aren't very interesting.
701 If given a negative prefix, always show; if given a positive prefix,
703 (interactive (gnus-article-hidden-arg))
704 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
705 (not gnus-show-all-headers))
708 (let ((buffer-read-only nil)
709 (list gnus-boring-article-headers)
710 (inhibit-point-motion-hooks t)
712 (nnheader-narrow-to-headers)
714 (setq elem (pop list))
715 (goto-char (point-min))
717 ;; Hide empty headers.
719 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
721 (gnus-article-hide-text-type
722 (progn (beginning-of-line) (point))
725 (if (re-search-forward "^[^ \t]" nil t)
729 ;; Hide boring Newsgroups header.
730 ((eq elem 'newsgroups)
731 (when (equal (gnus-fetch-field "newsgroups")
732 (gnus-group-real-name
733 (if (boundp 'gnus-newsgroup-name)
736 (gnus-article-hide-header "newsgroups")))
737 ((eq elem 'followup-to)
738 (when (equal (message-fetch-field "followup-to")
739 (message-fetch-field "newsgroups"))
740 (gnus-article-hide-header "followup-to")))
742 (let ((from (message-fetch-field "from"))
743 (reply-to (message-fetch-field "reply-to")))
748 (nth 1 (mail-extract-address-components from))
749 (nth 1 (mail-extract-address-components reply-to)))))
750 (gnus-article-hide-header "reply-to"))))
752 (let ((date (message-fetch-field "date")))
754 (< (gnus-days-between (current-time-string) date)
756 (gnus-article-hide-header "date"))))
758 (let ((to (message-fetch-field "to")))
759 (when (> (length to) 1024)
760 (gnus-article-hide-header "to"))))
763 (goto-char (point-min))
764 (while (re-search-forward "^to:" nil t)
765 (setq to-count (1+ to-count)))
767 (while (> to-count 0)
768 (goto-char (point-min))
770 (re-search-forward "^to:" nil nil to-count)
772 (narrow-to-region (point) (point-max))
773 (gnus-article-hide-header "to"))
774 (setq to-count (1- to-count)))))))))))))
776 (defun gnus-article-hide-header (header)
778 (goto-char (point-min))
779 (when (re-search-forward (concat "^" header ":") nil t)
780 (gnus-article-hide-text-type
781 (progn (beginning-of-line) (point))
784 (if (re-search-forward "^[^ \t]" nil t)
789 (defun article-treat-dumbquotes ()
790 "Translate M******** sm*rtq**t*s into proper text."
792 (article-translate-characters "\221\222\223\223" "`'\"\""))
794 (defun article-translate-characters (from to)
795 "Translate all characters in the body of the article according to FROM and TO.
796 FROM is a string of characters to translate from; to is a string of
797 characters to translate to."
799 (goto-char (point-min))
800 (when (search-forward "\n\n" nil t)
801 (let ((buffer-read-only nil)
802 (x (make-string 225 ?x))
804 (while (< (incf i) (length x))
807 (while (< i (length from))
808 (aset x (aref from i) (aref to i))
810 (translate-region (point) (point-max) x)))))
812 (defun article-treat-overstrike ()
813 "Translate overstrikes into bold text."
816 (goto-char (point-min))
817 (when (search-forward "\n\n" nil t)
818 (let ((buffer-read-only nil))
819 (while (search-forward "\b" nil t)
820 (let ((next (following-char))
821 (previous (char-after (- (point) 2))))
822 ;; We do the boldification/underlining by hiding the
823 ;; overstrikes and putting the proper text property
827 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
828 (put-text-property (point) (1+ (point)) 'face 'bold))
830 (gnus-article-hide-text-type
831 (1- (point)) (1+ (point)) 'overstrike)
833 (- (point) 2) (1- (point)) 'face 'underline))
835 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
837 (point) (1+ (point)) 'face 'underline)))))))))
839 (defun article-fill ()
840 "Format too long lines."
843 (let ((buffer-read-only nil))
845 (goto-char (point-min))
846 (search-forward "\n\n" nil t)
848 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
849 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
850 (adaptive-fill-mode t))
852 (and (>= (current-column) (min fill-column (window-width)))
853 (/= (preceding-char) ?:)
854 (fill-paragraph nil))
857 (defun article-remove-cr ()
858 "Remove carriage returns from an article."
861 (let ((buffer-read-only nil))
862 (goto-char (point-min))
863 (while (search-forward "\r" nil t)
864 (replace-match "" t t)))))
866 (defun article-remove-trailing-blank-lines ()
867 "Remove all trailing blank lines from the article."
870 (let ((buffer-read-only nil))
871 (goto-char (point-max))
875 (while (and (not (bobp))
876 (looking-at "^[ \t]*$"))
881 (defun article-display-x-face (&optional force)
882 "Look for an X-Face header and display it if present."
883 (interactive (list 'force))
885 ;; Delete the old process, if any.
886 (when (process-status "article-x-face")
887 (delete-process "article-x-face"))
888 (let ((inhibit-point-motion-hooks t)
892 (nnheader-narrow-to-headers)
893 (setq from (message-fetch-field "from"))
894 (goto-char (point-min))
895 (while (and gnus-article-x-face-command
897 ;; Check whether this face is censored.
898 (not gnus-article-x-face-too-ugly)
899 (and gnus-article-x-face-too-ugly from
900 (not (string-match gnus-article-x-face-too-ugly
902 ;; Has to be present.
903 (re-search-forward "^X-Face: " nil t))
904 ;; We now have the area of the buffer where the X-Face is stored.
907 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
908 ;; We display the face.
909 (if (symbolp gnus-article-x-face-command)
910 ;; The command is a lisp function, so we call it.
911 (if (gnus-functionp gnus-article-x-face-command)
912 (funcall gnus-article-x-face-command beg end)
913 (error "%s is not a function" gnus-article-x-face-command))
914 ;; The command is a string, so we interpret the command
915 ;; as a, well, command, and fork it off.
916 (let ((process-connection-type nil))
917 (process-kill-without-query
919 "article-x-face" nil shell-file-name shell-command-switch
920 gnus-article-x-face-command))
921 (process-send-region "article-x-face" beg end)
922 (process-send-eof "article-x-face"))))))))))
924 (defun gnus-article-decode-rfc1522 ()
925 "Decode MIME encoded-words in header fields."
926 (let (buffer-read-only)
927 (eword-decode-header)
930 (defun article-hide-pgp (&optional arg)
931 "Toggle hiding of any PGP headers and signatures in the current article.
932 If given a negative prefix, always show; if given a positive prefix,
934 (interactive (gnus-article-hidden-arg))
935 (unless (gnus-article-check-hidden-text 'pgp arg)
937 (let ((inhibit-point-motion-hooks t)
938 buffer-read-only beg end)
940 (goto-char (point-min))
941 ;; Hide the "header".
942 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
943 (gnus-article-hide-text-type (1+ (match-beginning 0))
946 ;; Hide the actual signature.
947 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
948 (setq end (1+ (match-beginning 0)))
949 (gnus-article-hide-text-type
951 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
953 ;; Perhaps we shouldn't hide to the end of the buffer
954 ;; if there is no end to the signature?
957 ;; Hide "- " PGP quotation markers.
959 (narrow-to-region beg end)
960 (goto-char (point-min))
961 (while (re-search-forward "^- " nil t)
962 (gnus-article-hide-text-type
963 (match-beginning 0) (match-end 0) 'pgp))
965 (run-hooks 'gnus-article-hide-pgp-hook))))))
967 (defun article-hide-pem (&optional arg)
968 "Toggle hiding of any PEM headers and signatures in the current article.
969 If given a negative prefix, always show; if given a positive prefix,
971 (interactive (gnus-article-hidden-arg))
972 (unless (gnus-article-check-hidden-text 'pem arg)
974 (let (buffer-read-only end)
976 (goto-char (point-min))
977 ;; hide the horrendously ugly "header".
978 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
981 (setq end (1+ (match-beginning 0)))
982 (gnus-article-hide-text-type
984 (if (search-forward "\n\n" nil t)
988 ;; hide the trailer as well
989 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
992 (gnus-article-hide-text-type
993 (match-beginning 0) (match-end 0) 'pem))))))
995 (defun article-hide-signature (&optional arg)
996 "Hide the signature in the current article.
997 If given a negative prefix, always show; if given a positive prefix,
999 (interactive (gnus-article-hidden-arg))
1000 (unless (gnus-article-check-hidden-text 'signature arg)
1003 (let ((buffer-read-only nil))
1004 (when (gnus-article-narrow-to-signature)
1005 (gnus-article-hide-text-type
1006 (point-min) (point-max) 'signature)))))))
1008 (defun article-strip-leading-blank-lines ()
1009 "Remove all blank lines from the beginning of the article."
1012 (let ((inhibit-point-motion-hooks t)
1014 (goto-char (point-min))
1015 (when (search-forward "\n\n" nil t)
1016 (while (and (not (eobp))
1017 (looking-at "[ \t]*$"))
1018 (gnus-delete-line))))))
1020 (defun article-strip-multiple-blank-lines ()
1021 "Replace consecutive blank lines with one empty line."
1024 (let ((inhibit-point-motion-hooks t)
1026 ;; First make all blank lines empty.
1027 (goto-char (point-min))
1028 (search-forward "\n\n" nil t)
1029 (while (re-search-forward "^[ \t]+$" nil t)
1030 (replace-match "" nil t))
1031 ;; Then replace multiple empty lines with a single empty line.
1032 (goto-char (point-min))
1033 (search-forward "\n\n" nil t)
1034 (while (re-search-forward "\n\n\n+" nil t)
1035 (replace-match "\n\n" t t)))))
1037 (defun article-strip-leading-space ()
1038 "Remove all white space from the beginning of the lines in the article."
1041 (let ((inhibit-point-motion-hooks t)
1043 (goto-char (point-min))
1044 (search-forward "\n\n" nil t)
1045 (while (re-search-forward "^[ \t]+" nil t)
1046 (replace-match "" t t)))))
1048 (defun article-strip-blank-lines ()
1049 "Strip leading, trailing and multiple blank lines."
1051 (article-strip-leading-blank-lines)
1052 (article-remove-trailing-blank-lines)
1053 (article-strip-multiple-blank-lines))
1055 (defun article-strip-all-blank-lines ()
1056 "Strip all blank lines."
1059 (let ((inhibit-point-motion-hooks t)
1061 (goto-char (point-min))
1062 (search-forward "\n\n" nil t)
1063 (while (re-search-forward "^[ \t]*\n" nil t)
1064 (replace-match "" t t)))))
1066 (defvar mime::preview/content-list)
1067 (defvar mime::preview-content-info/point-min)
1068 (defun gnus-article-narrow-to-signature ()
1069 "Narrow to the signature; return t if a signature is found, else nil."
1071 (when (and (boundp 'mime::preview/content-list)
1072 mime::preview/content-list)
1073 ;; We have a MIMEish article, so we use the MIME data to narrow.
1074 (let ((pcinfo (car (last mime::preview/content-list))))
1077 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1080 (when (gnus-article-search-signature)
1082 ;; Check whether we have some limits to what we consider
1083 ;; to be a signature.
1084 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1085 (list gnus-signature-limit)))
1087 (while (setq limit (pop limits))
1088 (if (or (and (integerp limit)
1089 (< (- (point-max) (point)) limit))
1091 (< (count-lines (point) (point-max)) limit))
1092 (and (gnus-functionp limit)
1094 (and (stringp limit)
1095 (not (re-search-forward limit nil t))))
1096 () ; This limit did not succeed.
1100 (narrow-to-region (point) (point-max))
1103 (defun gnus-article-search-signature ()
1104 "Search the current buffer for the signature separator.
1105 Put point at the beginning of the signature separator."
1106 (let ((cur (point)))
1107 (goto-char (point-max))
1108 (if (if (stringp gnus-signature-separator)
1109 (re-search-backward gnus-signature-separator nil t)
1110 (let ((seps gnus-signature-separator))
1112 (not (re-search-backward (car seps) nil t)))
1120 (autoload 'w3-display "w3-parse")
1121 (autoload 'w3-do-setup "w3" "" t)
1122 (autoload 'w3-region "w3-display" "" t))
1124 (defun gnus-article-treat-html ()
1127 (let ((cbuf (current-buffer)))
1128 (set-buffer gnus-article-buffer)
1129 (let (buf buffer-read-only b e)
1131 (goto-char (point-min))
1133 (if (search-forward "\n\n" nil t)
1136 (setq e (point-max)))
1137 (nnheader-temp-write nil
1138 (insert-buffer-substring gnus-article-buffer b e)
1140 (save-window-excursion
1141 (w3-region (point-min) (point-max))
1142 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1144 (delete-region (point-min) (point-max))
1147 (goto-char (point-min))
1148 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1149 (set-buffer cbuf))))
1151 (defun gnus-article-hidden-arg ()
1152 "Return the current prefix arg as a number, or 0 if no prefix."
1153 (list (if current-prefix-arg
1154 (prefix-numeric-value current-prefix-arg)
1157 (defun gnus-article-check-hidden-text (type arg)
1158 "Return nil if hiding is necessary.
1159 Arg can be nil or a number. Nil and positive means hide, negative
1160 means show, 0 means toggle."
1164 (let ((hide (gnus-article-hidden-text-p type)))
1170 (gnus-article-show-hidden-text type))
1172 (if (eq hide 'hidden)
1173 (gnus-article-show-hidden-text type)
1176 (defun gnus-article-hidden-text-p (type)
1177 "Say whether the current buffer contains hidden text of type TYPE."
1178 (let ((start (point-min))
1179 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1181 (not (get-text-property pos 'invisible)))
1183 (text-property-any (1+ pos) (point-max) 'article-type type)))
1188 (defun gnus-article-show-hidden-text (type &optional hide)
1189 "Show all hidden text of type TYPE.
1190 If HIDE, hide the text instead."
1192 (let ((buffer-read-only nil)
1193 (inhibit-point-motion-hooks t)
1196 (while (setq beg (text-property-any end (point-max) 'article-type type))
1199 (text-property-not-all beg (point-max) 'article-type type)
1202 (gnus-article-hide-text beg end gnus-hidden-properties)
1203 (gnus-article-unhide-text beg end))
1207 (defconst article-time-units
1208 `((year . ,(* 365.25 24 60 60))
1209 (week . ,(* 7 24 60 60))
1210 (day . ,(* 24 60 60))
1214 "Mapping from time units to seconds.")
1216 (defun article-date-ut (&optional type highlight header)
1217 "Convert DATE date to universal time in the current article.
1218 If TYPE is `local', convert to local time; if it is `lapsed', output
1219 how much time has lapsed since DATE."
1220 (interactive (list 'ut t))
1221 (let* ((header (or header
1222 (mail-header-date gnus-current-headers)
1223 (message-fetch-field "date")
1225 (date (if (vectorp header) (mail-header-date header)
1227 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1228 (inhibit-point-motion-hooks t)
1229 bface eface newline)
1230 (when (and date (not (string= date "")))
1233 (nnheader-narrow-to-headers)
1234 (let ((buffer-read-only nil))
1235 ;; Delete any old Date headers.
1236 (if (re-search-forward date-regexp nil t)
1238 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1239 eface (get-text-property (1- (gnus-point-at-eol))
1241 (delete-region (progn (beginning-of-line) (point))
1242 (progn (end-of-line) (point)))
1243 (beginning-of-line))
1244 (goto-char (point-max))
1246 (insert (article-make-date-line date type))
1249 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1250 (put-text-property (match-beginning 1) (1+ (match-end 1))
1252 (put-text-property (match-beginning 2) (match-end 2)
1256 (insert "\n"))))))))
1258 (defun article-make-date-line (date type)
1259 "Return a DATE line of TYPE."
1261 ;; Convert to the local timezone. We have to slap a
1262 ;; `condition-case' round the calls to the timezone
1263 ;; functions since they aren't particularly resistant to
1266 (concat "Date: " (condition-case ()
1267 (timezone-make-date-arpa-standard date)
1269 ;; Convert to Universal Time.
1273 (timezone-make-date-arpa-standard date nil "UT")
1275 ;; Get the original date from the article.
1276 ((eq type 'original)
1277 (concat "Date: " date))
1278 ;; Let the user define the format.
1282 (format-time-string gnus-article-time-format
1285 (timezone-make-date-arpa-standard
1287 ;; Do an X-Sent lapsed format.
1289 ;; If the date is seriously mangled, the timezone functions are
1290 ;; liable to bug out, so we ignore all errors.
1291 (let* ((now (current-time))
1296 (timezone-make-date-arpa-standard
1297 (current-time-string now)
1298 (current-time-zone now) "UT"))
1300 (timezone-make-date-arpa-standard
1302 (real-sec (and real-time
1303 (+ (* (float (car real-time)) 65536)
1305 (sec (and real-time (abs real-sec)))
1315 ;; This is a bit convoluted, but basically we go
1316 ;; through the time units for years, weeks, etc,
1317 ;; and divide things to see whether that results
1318 ;; in positive answers.
1321 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1322 ;; The (remaining) seconds are too few to
1323 ;; be divided into this time unit.
1325 ;; It's big enough, so we output it.
1326 (setq sec (- sec (* num (cdr unit))))
1328 (concat (if prev ", " "") (int-to-string
1330 " " (symbol-name (car unit))
1331 (if (> num 1) "s" ""))
1333 article-time-units "")
1334 ;; If dates are odd, then it might appear like the
1335 ;; article was sent in the future.
1338 " in the future"))))))
1340 (error "Unknown conversion type: %s" type))))
1342 (defun article-date-local (&optional highlight)
1343 "Convert the current article date to the local timezone."
1344 (interactive (list t))
1345 (article-date-ut 'local highlight))
1347 (defun article-date-original (&optional highlight)
1348 "Convert the current article date to what it was originally.
1349 This is only useful if you have used some other date conversion
1350 function and want to see what the date was before converting."
1351 (interactive (list t))
1352 (article-date-ut 'original highlight))
1354 (defun article-date-lapsed (&optional highlight)
1355 "Convert the current article date to time lapsed since it was sent."
1356 (interactive (list t))
1357 (article-date-ut 'lapsed highlight))
1359 (defun article-update-date-lapsed ()
1360 "Function to be run from a timer to update the lapsed time line."
1363 (when (gnus-buffer-live-p gnus-article-buffer)
1364 (set-buffer gnus-article-buffer)
1365 (goto-char (point-min))
1366 (when (re-search-forward "^X-Sent:" nil t)
1367 (article-date-lapsed t))))))
1369 (defun gnus-start-date-timer (&optional n)
1370 "Start a timer to update the X-Sent header in the article buffers.
1371 The numerical prefix says how frequently (in seconds) the function
1376 (gnus-stop-date-timer)
1377 (setq article-lapsed-timer
1378 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1380 (defun gnus-stop-date-timer ()
1381 "Stop the X-Sent timer."
1383 (when article-lapsed-timer
1384 (nnheader-cancel-timer article-lapsed-timer)
1385 (setq article-lapsed-timer nil)))
1387 (defun article-date-user (&optional highlight)
1388 "Convert the current article date to the user-defined format.
1389 This format is defined by the `gnus-article-time-format' variable."
1390 (interactive (list t))
1391 (article-date-ut 'user highlight))
1393 (defun article-show-all ()
1394 "Show all hidden text in the article buffer."
1397 (let ((buffer-read-only nil))
1398 (gnus-article-unhide-text (point-min) (point-max)))))
1400 (defun article-emphasize (&optional arg)
1401 "Emphasize text according to `gnus-emphasis-alist'."
1402 (interactive (gnus-article-hidden-arg))
1403 (unless (gnus-article-check-hidden-text 'emphasis arg)
1405 (let ((alist gnus-emphasis-alist)
1406 (buffer-read-only nil)
1407 (props (append '(article-type emphasis)
1408 gnus-hidden-properties))
1409 regexp elem beg invisible visible face)
1410 (goto-char (point-min))
1411 (search-forward "\n\n" nil t)
1413 (while (setq elem (pop alist))
1415 (setq regexp (car elem)
1416 invisible (nth 1 elem)
1417 visible (nth 2 elem)
1419 (while (re-search-forward regexp nil t)
1420 (when (and (match-beginning visible) (match-beginning invisible))
1421 (gnus-article-hide-text
1422 (match-beginning invisible) (match-end invisible) props)
1423 (gnus-article-unhide-text-type
1424 (match-beginning visible) (match-end visible) 'emphasis)
1425 (gnus-put-text-property-excluding-newlines
1426 (match-beginning visible) (match-end visible) 'face face)
1427 (goto-char (match-end invisible)))))))))
1429 (defvar gnus-summary-article-menu)
1430 (defvar gnus-summary-post-menu)
1432 ;;; Saving functions.
1434 (defun gnus-article-save (save-buffer file &optional num)
1435 "Save the currently selected article."
1436 (unless gnus-save-all-headers
1437 ;; Remove headers according to `gnus-saved-headers'.
1438 (let ((gnus-visible-headers
1439 (or gnus-saved-headers gnus-visible-headers))
1440 (gnus-article-buffer save-buffer))
1442 (set-buffer save-buffer)
1443 (article-hide-headers 1 t))))
1444 (save-window-excursion
1445 (if (not gnus-default-article-saver)
1446 (error "No default saver is defined")
1447 ;; !!! Magic! The saving functions all save
1448 ;; `gnus-original-article-buffer' (or so they think), but we
1449 ;; bind that variable to our save-buffer.
1450 (set-buffer gnus-article-buffer)
1451 (let* ((gnus-save-article-buffer save-buffer)
1454 ((not gnus-prompt-before-saving) 'default)
1455 ((eq gnus-prompt-before-saving 'always) nil)
1457 (gnus-number-of-articles-to-be-saved
1458 (when (eq gnus-prompt-before-saving t)
1460 (set-buffer gnus-summary-buffer)
1461 (funcall gnus-default-article-saver filename)))))
1463 (defun gnus-read-save-file-name (prompt &optional filename
1464 function group headers variable)
1466 (funcall function group headers (symbol-value variable)))
1471 ((eq filename 'default)
1477 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1480 (if (and gnus-number-of-articles-to-be-saved
1481 (> gnus-number-of-articles-to-be-saved 1))
1482 (format "these %d articles"
1483 gnus-number-of-articles-to-be-saved)
1486 ;; Let the split methods have their say.
1488 ;; No split name was found.
1491 (concat prompt " (default "
1492 (file-name-nondirectory default-name) ") ")
1493 (file-name-directory default-name)
1495 ;; A single group name is returned.
1496 ((stringp split-name)
1498 (funcall function split-name headers
1499 (symbol-value variable)))
1501 (concat prompt " (default "
1502 (file-name-nondirectory default-name) ") ")
1503 (file-name-directory default-name)
1505 ;; A single split name was found
1506 ((= 1 (length split-name))
1507 (let* ((name (expand-file-name
1508 (car split-name) gnus-article-save-directory))
1509 (dir (cond ((file-directory-p name)
1510 (file-name-as-directory name))
1511 ((file-exists-p name) name)
1512 (t gnus-article-save-directory))))
1514 (concat prompt " (default " name ") ")
1516 ;; A list of splits was found.
1518 (setq split-name (nreverse split-name))
1520 (let ((file-name-history
1521 (nconc split-name file-name-history)))
1525 (concat prompt " (`M-p' for defaults) ")
1526 gnus-article-save-directory
1528 gnus-article-save-directory)))
1529 (car (push result file-name-history)))))))
1530 ;; Create the directory.
1531 (gnus-make-directory (file-name-directory file))
1532 ;; If we have read a directory, we append the default file name.
1533 (when (file-directory-p file)
1534 (setq file (concat (file-name-as-directory file)
1535 (file-name-nondirectory default-name))))
1536 ;; Possibly translate some characters.
1537 (nnheader-translate-file-chars file)))))
1538 (gnus-make-directory (file-name-directory result))
1539 (set variable result)))
1541 (defun gnus-article-archive-name (group)
1542 "Return the first instance of an \"Archive-name\" in the current buffer."
1543 (let ((case-fold-search t))
1544 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1545 (nnheader-concat gnus-article-save-directory
1546 (match-string 1)))))
1548 (defun gnus-article-nndoc-name (group)
1549 "If GROUP is an nndoc group, return the name of the parent group."
1550 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1551 (gnus-group-get-parameter group 'save-article-group)))
1553 (defun gnus-summary-save-in-rmail (&optional filename)
1554 "Append this article to Rmail file.
1555 Optional argument FILENAME specifies file name.
1556 Directory to save to is default to `gnus-article-save-directory'."
1558 (setq filename (gnus-read-save-file-name
1559 "Save %s in rmail file:" filename
1560 gnus-rmail-save-name gnus-newsgroup-name
1561 gnus-current-headers 'gnus-newsgroup-last-rmail))
1562 (gnus-eval-in-buffer-window gnus-save-article-buffer
1566 (gnus-output-to-rmail filename))))
1569 (defun gnus-summary-save-in-mail (&optional filename)
1570 "Append this article to Unix mail file.
1571 Optional argument FILENAME specifies file name.
1572 Directory to save to is default to `gnus-article-save-directory'."
1574 (setq filename (gnus-read-save-file-name
1575 "Save %s in Unix mail file:" filename
1576 gnus-mail-save-name gnus-newsgroup-name
1577 gnus-current-headers 'gnus-newsgroup-last-mail))
1578 (gnus-eval-in-buffer-window gnus-save-article-buffer
1582 (if (and (file-readable-p filename)
1583 (mail-file-babyl-p filename))
1584 (gnus-output-to-rmail filename t)
1585 (gnus-output-to-mail filename)))))
1588 (defun gnus-summary-save-in-file (&optional filename overwrite)
1589 "Append this article to file.
1590 Optional argument FILENAME specifies file name.
1591 Directory to save to is default to `gnus-article-save-directory'."
1593 (setq filename (gnus-read-save-file-name
1594 "Save %s in file:" filename
1595 gnus-file-save-name gnus-newsgroup-name
1596 gnus-current-headers 'gnus-newsgroup-last-file))
1597 (gnus-eval-in-buffer-window gnus-save-article-buffer
1601 (when (and overwrite
1602 (file-exists-p filename))
1603 (delete-file filename))
1604 (gnus-output-to-file filename))))
1607 (defun gnus-summary-write-to-file (&optional filename)
1608 "Write this article to a file.
1609 Optional argument FILENAME specifies file name.
1610 The directory to save in defaults to `gnus-article-save-directory'."
1612 (gnus-summary-save-in-file nil t))
1614 (defun gnus-summary-save-body-in-file (&optional filename)
1615 "Append this article body to a file.
1616 Optional argument FILENAME specifies file name.
1617 The directory to save in defaults to `gnus-article-save-directory'."
1619 (setq filename (gnus-read-save-file-name
1620 "Save %s body in file:" filename
1621 gnus-file-save-name gnus-newsgroup-name
1622 gnus-current-headers 'gnus-newsgroup-last-file))
1623 (gnus-eval-in-buffer-window gnus-save-article-buffer
1627 (goto-char (point-min))
1628 (when (search-forward "\n\n" nil t)
1629 (narrow-to-region (point) (point-max)))
1630 (gnus-output-to-file filename))))
1633 (defun gnus-summary-save-in-pipe (&optional command)
1634 "Pipe this article to subprocess."
1637 (cond ((eq command 'default)
1638 gnus-last-shell-command)
1642 "Shell command on %s: "
1643 (if (and gnus-number-of-articles-to-be-saved
1644 (> gnus-number-of-articles-to-be-saved 1))
1645 (format "these %d articles"
1646 gnus-number-of-articles-to-be-saved)
1648 gnus-last-shell-command))))
1649 (when (string-equal command "")
1650 (setq command gnus-last-shell-command))
1651 (gnus-eval-in-buffer-window gnus-article-buffer
1654 (shell-command-on-region (point-min) (point-max) command nil)))
1655 (setq gnus-last-shell-command command))
1657 ;;; Article file names when saving.
1659 (defun gnus-capitalize-newsgroup (newsgroup)
1660 "Capitalize NEWSGROUP name."
1661 (when (not (zerop (length newsgroup)))
1662 (concat (char-to-string (upcase (aref newsgroup 0)))
1663 (substring newsgroup 1))))
1665 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1666 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1667 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1668 Otherwise, it is like ~/News/news/group/num."
1671 (concat (if (gnus-use-long-file-name 'not-save)
1672 (gnus-capitalize-newsgroup newsgroup)
1673 (gnus-newsgroup-directory-form newsgroup))
1674 "/" (int-to-string (mail-header-number headers)))
1675 gnus-article-save-directory)))
1677 (string-equal (file-name-directory default)
1678 (file-name-directory last-file))
1679 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1681 (or last-file default))))
1683 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1684 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1685 If variable `gnus-use-long-file-name' is non-nil, it is
1686 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1689 (concat (if (gnus-use-long-file-name 'not-save)
1691 (gnus-newsgroup-directory-form newsgroup))
1692 "/" (int-to-string (mail-header-number headers)))
1693 gnus-article-save-directory)))
1695 (string-equal (file-name-directory default)
1696 (file-name-directory last-file))
1697 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1699 (or last-file default))))
1701 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1702 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1703 If variable `gnus-use-long-file-name' is non-nil, it is
1704 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1707 (if (gnus-use-long-file-name 'not-save)
1708 (gnus-capitalize-newsgroup newsgroup)
1709 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1710 gnus-article-save-directory)))
1712 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1713 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1714 If variable `gnus-use-long-file-name' is non-nil, it is
1715 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1718 (if (gnus-use-long-file-name 'not-save)
1720 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1721 gnus-article-save-directory)))
1728 (setq afunc (car func)
1731 gfunc (intern (format "gnus-%s" func))))
1733 (if (not (fboundp afunc))
1735 `(lambda (&optional interactive &rest args)
1736 ,(documentation afunc t)
1737 (interactive (list t))
1739 (set-buffer gnus-article-buffer)
1741 (call-interactively ',afunc)
1742 (apply ',afunc args))))))))
1743 '(article-hide-headers
1744 article-hide-boring-headers
1745 article-treat-overstrike
1746 (article-fill . gnus-article-word-wrap)
1748 article-display-x-face
1749 article-de-quoted-unreadable
1750 article-mime-decode-quoted-printable
1753 article-hide-signature
1754 article-remove-trailing-blank-lines
1755 article-strip-leading-blank-lines
1756 article-strip-multiple-blank-lines
1757 article-strip-leading-space
1758 article-strip-blank-lines
1759 article-strip-all-blank-lines
1761 article-date-original
1766 article-treat-dumbquotes
1767 (article-show-all . gnus-article-show-all-headers))))
1770 ;;; Gnus article mode
1773 (put 'gnus-article-mode 'mode-class 'special)
1775 (gnus-define-keys gnus-article-mode-map
1776 " " gnus-article-goto-next-page
1777 "\177" gnus-article-goto-prev-page
1778 [delete] gnus-article-goto-prev-page
1779 "\C-c^" gnus-article-refer-article
1780 "h" gnus-article-show-summary
1781 "s" gnus-article-show-summary
1782 "\C-c\C-m" gnus-article-mail
1783 "?" gnus-article-describe-briefly
1784 gnus-mouse-2 gnus-article-push-button
1785 "\r" gnus-article-press-button
1786 "\t" gnus-article-next-button
1787 "\M-\t" gnus-article-prev-button
1788 "e" gnus-article-edit
1789 "<" beginning-of-buffer
1791 "\C-c\C-i" gnus-info-find-node
1794 "\C-d" gnus-article-read-summary-keys
1795 "\M-*" gnus-article-read-summary-keys
1796 "\M-#" gnus-article-read-summary-keys
1797 "\M-^" gnus-article-read-summary-keys
1798 "\M-g" gnus-article-read-summary-keys)
1800 (substitute-key-definition
1801 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1803 (defun gnus-article-make-menu-bar ()
1804 (gnus-turn-off-edit-menu 'article)
1805 (unless (boundp 'gnus-article-article-menu)
1807 gnus-article-article-menu gnus-article-mode-map ""
1809 ["Scroll forwards" gnus-article-goto-next-page t]
1810 ["Scroll backwards" gnus-article-goto-prev-page t]
1811 ["Show summary" gnus-article-show-summary t]
1812 ["Fetch Message-ID at point" gnus-article-refer-article t]
1813 ["Mail to address at point" gnus-article-mail t]))
1816 gnus-article-treatment-menu gnus-article-mode-map ""
1818 ["Hide headers" gnus-article-hide-headers t]
1819 ["Hide signature" gnus-article-hide-signature t]
1820 ["Hide citation" gnus-article-hide-citation t]
1821 ["Treat overstrike" gnus-article-treat-overstrike t]
1822 ["Remove carriage return" gnus-article-remove-cr t]
1823 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1826 (when (boundp 'gnus-summary-article-menu)
1827 (define-key gnus-article-mode-map [menu-bar commands]
1828 (cons "Commands" gnus-summary-article-menu))))
1830 (when (boundp 'gnus-summary-post-menu)
1831 (define-key gnus-article-mode-map [menu-bar post]
1832 (cons "Post" gnus-summary-post-menu)))
1834 (run-hooks 'gnus-article-menu-hook)))
1836 (defun gnus-article-mode ()
1837 "Major mode for displaying an article.
1839 All normal editing commands are switched off.
1841 The following commands are available in addition to all summary mode
1843 \\<gnus-article-mode-map>
1844 \\[gnus-article-next-page]\t Scroll the article one page forwards
1845 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1846 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1847 \\[gnus-article-show-summary]\t Display the summary buffer
1848 \\[gnus-article-mail]\t Send a reply to the address near point
1849 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1850 \\[gnus-info-find-node]\t Go to the Gnus info node"
1852 (when (gnus-visual-p 'article-menu 'menu)
1853 (gnus-article-make-menu-bar))
1854 (kill-all-local-variables)
1855 (gnus-simplify-mode-line)
1856 (setq mode-name "Article")
1857 (setq major-mode 'gnus-article-mode)
1858 (make-local-variable 'minor-mode-alist)
1859 (unless (assq 'gnus-show-mime minor-mode-alist)
1860 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1861 (use-local-map gnus-article-mode-map)
1862 (gnus-update-format-specifications nil 'article-mode)
1863 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1864 (set (make-local-variable 'gnus-page-broken) nil)
1865 (set (make-local-variable 'gnus-button-marker-list) nil)
1866 (gnus-set-default-directory)
1867 (buffer-disable-undo (current-buffer))
1868 (setq buffer-read-only t)
1869 (set-syntax-table gnus-article-mode-syntax-table)
1870 (run-hooks 'gnus-article-mode-hook))
1872 (defun gnus-article-setup-buffer ()
1873 "Initialize the article buffer."
1874 (let* ((name (if gnus-single-article-buffer "*Article*"
1875 (concat "*Article " gnus-newsgroup-name "*")))
1877 (progn (string-match "\\*Article" name)
1878 (concat " *Original Article"
1879 (substring name (match-end 0))))))
1880 (setq gnus-article-buffer name)
1881 (setq gnus-original-article-buffer original)
1882 ;; This might be a variable local to the summary buffer.
1883 (unless gnus-single-article-buffer
1885 (set-buffer gnus-summary-buffer)
1886 (setq gnus-article-buffer name)
1887 (setq gnus-original-article-buffer original)
1888 (gnus-set-global-variables)))
1889 ;; Init original article buffer.
1891 (set-buffer (get-buffer-create gnus-original-article-buffer))
1892 (buffer-disable-undo (current-buffer))
1893 (setq major-mode 'gnus-original-article-mode)
1894 (gnus-add-current-to-buffer-list)
1895 (make-local-variable 'gnus-original-article))
1896 (if (get-buffer name)
1899 (buffer-disable-undo (current-buffer))
1900 (setq buffer-read-only t)
1901 (gnus-add-current-to-buffer-list)
1902 (unless (eq major-mode 'gnus-article-mode)
1903 (gnus-article-mode))
1906 (set-buffer (get-buffer-create name))
1907 (gnus-add-current-to-buffer-list)
1909 (make-local-variable 'gnus-summary-buffer)
1910 (current-buffer)))))
1912 ;; Set article window start at LINE, where LINE is the number of lines
1913 ;; from the head of the article.
1914 (defun gnus-article-set-window-start (&optional line)
1916 (get-buffer-window gnus-article-buffer t)
1918 (set-buffer gnus-article-buffer)
1919 (goto-char (point-min))
1922 (gnus-message 6 "Moved to bookmark")
1923 (search-forward "\n\n" nil t)
1927 ;;; @@ article filters
1929 (defun gnus-article-preview-mime-message ()
1930 (make-local-variable 'mime-button-mother-dispatcher)
1931 (setq mime-button-mother-dispatcher
1932 (function gnus-article-push-button))
1933 (let ((default-mime-charset
1935 (set-buffer gnus-summary-buffer)
1936 default-mime-charset))
1939 (mime-view-mode nil nil nil gnus-original-article-buffer
1941 gnus-article-mode-map)
1943 (run-hooks 'gnus-mime-article-prepare-hook)
1946 (defun gnus-article-decode-encoded-word ()
1947 "Header filter for gnus-article-mode.
1948 It is registered to variable `mime-view-content-header-filter-alist'."
1949 (goto-char (point-min))
1950 (let ((charset (save-excursion
1951 (set-buffer gnus-summary-buffer)
1952 default-mime-charset)))
1954 (std11-narrow-to-header)
1955 (goto-char (point-min))
1956 (while (re-search-forward "^[^ \t:]+:" nil t)
1957 (let ((start (match-beginning 0))
1958 (end (std11-field-end))
1961 (narrow-to-region start end)
1962 (decode-mime-charset-region start end charset)
1963 (goto-char (point-max))
1965 (eword-decode-header)
1967 (decode-mime-charset-region (point) (point-max) charset)
1968 (mime-maybe-hide-echo-buffer)
1970 (run-hooks 'gnus-mime-article-prepare-hook)
1973 (defun gnus-article-prepare (article &optional all-headers header)
1974 "Prepare ARTICLE in article mode buffer.
1975 ARTICLE should either be an article number or a Message-ID.
1976 If ARTICLE is an id, HEADER should be the article headers.
1977 If ALL-HEADERS is non-nil, no headers are hidden."
1979 ;; Make sure we start in a summary buffer.
1980 (unless (eq major-mode 'gnus-summary-mode)
1981 (set-buffer gnus-summary-buffer))
1982 (setq gnus-summary-buffer (current-buffer))
1983 ;; Make sure the connection to the server is alive.
1984 (unless (gnus-server-opened
1985 (gnus-find-method-for-group gnus-newsgroup-name))
1986 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1987 (gnus-request-group gnus-newsgroup-name t))
1988 (let* ((gnus-article (if header (mail-header-number header) article))
1989 (summary-buffer (current-buffer))
1990 (internal-hook gnus-article-internal-prepare-hook)
1991 (group gnus-newsgroup-name)
1994 (gnus-article-setup-buffer)
1995 (set-buffer gnus-article-buffer)
1996 ;; Deactivate active regions.
1997 (when (and (boundp 'transient-mark-mode)
1998 transient-mark-mode)
1999 (setq mark-active nil))
2000 (if (not (setq result (let ((buffer-read-only nil))
2001 (gnus-request-article-this-buffer
2003 ;; There is no such article.
2005 (when (and (numberp article)
2006 (not (memq article gnus-newsgroup-sparse)))
2007 (setq gnus-article-current
2008 (cons gnus-newsgroup-name article))
2009 (set-buffer gnus-summary-buffer)
2010 (setq gnus-current-article article)
2011 (gnus-summary-mark-article article gnus-canceled-mark))
2012 (unless (memq article gnus-newsgroup-sparse)
2014 1 "No such article (may have expired or been canceled)")))
2015 (if (or (eq result 'pseudo) (eq result 'nneething))
2018 (set-buffer summary-buffer)
2019 (push article gnus-newsgroup-history)
2020 (setq gnus-last-article gnus-current-article
2021 gnus-current-article 0
2022 gnus-current-headers nil
2023 gnus-article-current nil)
2024 (if (eq result 'nneething)
2025 (gnus-configure-windows 'summary)
2026 (gnus-configure-windows 'article))
2027 (gnus-set-global-variables))
2028 (gnus-set-mode-line 'article))
2029 ;; The result from the `request' was an actual article -
2030 ;; or at least some text that is now displayed in the
2032 (when (and (numberp article)
2033 (not (eq article gnus-current-article)))
2034 ;; Seems like a new article has been selected.
2035 ;; `gnus-current-article' must be an article number.
2037 (set-buffer summary-buffer)
2038 (push article gnus-newsgroup-history)
2039 (setq gnus-last-article gnus-current-article
2040 gnus-current-article article
2041 gnus-current-headers
2042 (gnus-summary-article-header gnus-current-article)
2043 gnus-article-current
2044 (cons gnus-newsgroup-name gnus-current-article))
2045 (unless (vectorp gnus-current-headers)
2046 (setq gnus-current-headers nil))
2047 (gnus-summary-goto-subject gnus-current-article)
2048 (gnus-summary-show-thread)
2049 (run-hooks 'gnus-mark-article-hook)
2050 (gnus-set-mode-line 'summary)
2051 (when (gnus-visual-p 'article-highlight 'highlight)
2052 (run-hooks 'gnus-visual-mark-article-hook))
2053 ;; Set the global newsgroup variables here.
2054 ;; Suggested by Jim Sisolak
2055 ;; <sisolak@trans4.neep.wisc.edu>.
2056 (gnus-set-global-variables)
2057 (setq gnus-have-all-headers
2058 (or all-headers gnus-show-all-headers))
2060 (vectorp (gnus-summary-article-header article))
2061 (gnus-cache-possibly-enter-article
2063 (gnus-summary-article-header article)
2064 (memq article gnus-newsgroup-marked)
2065 (memq article gnus-newsgroup-dormant)
2066 (memq article gnus-newsgroup-unreads)))))
2067 (when (or (numberp article)
2069 ;; Hooks for getting information from the article.
2070 ;; This hook must be called before being narrowed.
2071 (let (buffer-read-only)
2072 (run-hooks 'internal-hook)
2073 (run-hooks 'gnus-article-prepare-hook)
2074 ;; Decode MIME message.
2075 (when gnus-show-mime
2076 (if (or (not gnus-strict-mime)
2077 (gnus-fetch-field "Mime-Version"))
2078 (funcall gnus-show-mime-method)
2079 (funcall gnus-decode-encoded-word-method)))
2080 ;; Perform the article display hooks.
2081 (run-hooks 'gnus-article-display-hook))
2083 (goto-char (point-min))
2084 (setq gnus-page-broken
2085 (when gnus-break-pages
2086 (gnus-narrow-to-page)
2088 (gnus-set-mode-line 'article)
2089 (gnus-configure-windows 'article)
2090 (goto-char (point-min))
2093 (defun gnus-article-wash-status ()
2094 "Return a string which display status of article washing."
2096 (set-buffer gnus-article-buffer)
2097 (let ((cite (gnus-article-hidden-text-p 'cite))
2098 (headers (gnus-article-hidden-text-p 'headers))
2099 (boring (gnus-article-hidden-text-p 'boring-headers))
2100 (pgp (gnus-article-hidden-text-p 'pgp))
2101 (pem (gnus-article-hidden-text-p 'pem))
2102 (signature (gnus-article-hidden-text-p 'signature))
2103 (overstrike (gnus-article-hidden-text-p 'overstrike))
2104 (emphasis (gnus-article-hidden-text-p 'emphasis))
2105 (mime gnus-show-mime))
2106 (format "%c%c%c%c%c%c%c"
2108 (if (or headers boring) ?h ? )
2109 (if (or pgp pem) ?p ? )
2110 (if signature ?s ? )
2111 (if overstrike ?o ? )
2113 (if emphasis ?e ? )))))
2115 (defun gnus-article-hide-headers-if-wanted ()
2116 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2117 Provided for backwards compatibility."
2118 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2120 (gnus-article-hide-headers)))
2124 (defun gnus-output-to-file (file-name)
2125 "Append the current article to a file named FILE-NAME."
2126 (let ((artbuf (current-buffer)))
2127 (nnheader-temp-write nil
2128 (insert-buffer-substring artbuf)
2129 ;; Append newline at end of the buffer as separator, and then
2131 (goto-char (point-max))
2133 (append-to-file (point-min) (point-max) file-name)
2136 (defun gnus-narrow-to-page (&optional arg)
2137 "Narrow the article buffer to a page.
2138 If given a numerical ARG, move forward ARG pages."
2140 (setq arg (if arg (prefix-numeric-value arg) 0))
2142 (set-buffer gnus-article-buffer)
2143 (goto-char (point-min))
2145 ;; Remove any old next/prev buttons.
2146 (when (gnus-visual-p 'page-marker)
2147 (let ((buffer-read-only nil))
2148 (gnus-remove-text-with-property 'gnus-prev)
2149 (gnus-remove-text-with-property 'gnus-next)))
2152 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2154 (re-search-forward page-delimiter nil 'move arg)))
2155 (goto-char (match-end 0)))
2158 (if (re-search-forward page-delimiter nil 'move)
2161 (when (and (gnus-visual-p 'page-marker)
2162 (not (= (point-min) 1)))
2164 (goto-char (point-min))
2165 (gnus-insert-prev-page-button)))
2166 (when (and (gnus-visual-p 'page-marker)
2167 (< (+ (point-max) 2) (buffer-size)))
2169 (goto-char (point-max))
2170 (gnus-insert-next-page-button)))))
2172 ;; Article mode commands
2174 (defun gnus-article-goto-next-page ()
2175 "Show the next page of the article."
2177 (when (gnus-article-next-page)
2178 (goto-char (point-min))
2179 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2181 (defun gnus-article-goto-prev-page ()
2182 "Show the next page of the article."
2184 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2185 (gnus-article-prev-page nil)))
2187 (defun gnus-article-next-page (&optional lines)
2188 "Show the next page of the current article.
2189 If end of article, return non-nil. Otherwise return nil.
2190 Argument LINES specifies lines to be scrolled up."
2192 (move-to-window-line -1)
2195 (and (pos-visible-in-window-p) ;Not continuation line.
2197 ;; Nothing in this page.
2198 (if (or (not gnus-page-broken)
2201 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2203 (gnus-narrow-to-page 1) ;Go to next page.
2205 ;; More in this page.
2206 (let ((scroll-in-place nil))
2210 ;; Long lines may cause an end-of-buffer error.
2211 (goto-char (point-max)))))
2212 (move-to-window-line 0)
2215 (defun gnus-article-prev-page (&optional lines)
2216 "Show previous page of current article.
2217 Argument LINES specifies lines to be scrolled down."
2219 (move-to-window-line 0)
2220 (if (and gnus-page-broken
2222 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2224 (gnus-narrow-to-page -1) ;Go to previous page.
2225 (goto-char (point-max))
2227 (let ((scroll-in-place nil))
2231 (beginning-of-buffer
2232 (goto-char (point-min))))
2233 (move-to-window-line 0)))))
2235 (defun gnus-article-refer-article ()
2236 "Read article specified by message-id around point."
2238 (let ((point (point)))
2239 (search-forward ">" nil t) ;Move point to end of "<....>".
2240 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2241 (let ((message-id (match-string 1)))
2243 (set-buffer gnus-summary-buffer)
2244 (gnus-summary-refer-article message-id))
2246 (error "No references around point"))))
2248 (defun gnus-article-show-summary ()
2249 "Reconfigure windows to show summary buffer."
2251 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2252 (error "There is no summary buffer for this article buffer")
2253 (gnus-article-set-globals)
2254 (gnus-configure-windows 'article)
2255 (gnus-summary-goto-subject gnus-current-article)))
2257 (defun gnus-article-describe-briefly ()
2258 "Describe article mode commands briefly."
2261 (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")))
2263 (defun gnus-article-summary-command ()
2264 "Execute the last keystroke in the summary buffer."
2266 (let ((obuf (current-buffer))
2267 (owin (current-window-configuration))
2269 (switch-to-buffer gnus-summary-buffer 'norecord)
2270 (setq func (lookup-key (current-local-map) (this-command-keys)))
2271 (call-interactively func)
2273 (set-window-configuration owin)
2274 (set-window-point (get-buffer-window (current-buffer)) (point))))
2276 (defun gnus-article-summary-command-nosave ()
2277 "Execute the last keystroke in the summary buffer."
2280 (pop-to-buffer gnus-summary-buffer 'norecord)
2281 (setq func (lookup-key (current-local-map) (this-command-keys)))
2282 (call-interactively func)))
2284 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2285 "Read a summary buffer key sequence and execute it from the article buffer."
2288 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2289 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2290 "=" "^" "\M-^" "|"))
2297 (set-buffer gnus-summary-buffer)
2298 (let (gnus-pick-mode)
2299 (push (or key last-command-event) unread-command-events)
2300 (setq keys (read-key-sequence nil))))
2303 (if (or (member keys nosaves)
2304 (member keys nosave-but-article)
2305 (member keys nosave-in-article))
2307 (save-window-excursion
2308 (pop-to-buffer gnus-summary-buffer 'norecord)
2309 ;; We disable the pick minor mode commands.
2310 (let (gnus-pick-mode)
2311 (setq func (lookup-key (current-local-map) keys))))
2314 (unless (member keys nosave-in-article)
2315 (set-buffer gnus-summary-buffer))
2316 (call-interactively func))
2317 (when (member keys nosave-but-article)
2318 (pop-to-buffer gnus-article-buffer 'norecord)))
2319 ;; These commands should restore window configuration.
2320 (let ((obuf (current-buffer))
2321 (owin (current-window-configuration))
2324 (if not-restore-window
2325 (pop-to-buffer gnus-summary-buffer 'norecord)
2326 (switch-to-buffer gnus-summary-buffer 'norecord))
2327 (setq in-buffer (current-buffer))
2328 ;; We disable the pick minor mode commands.
2329 (if (setq func (let (gnus-pick-mode)
2330 (lookup-key (current-local-map) keys)))
2331 (call-interactively func)
2333 (when (eq in-buffer (current-buffer))
2335 (unless not-restore-window
2336 (set-window-configuration owin))
2337 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2339 (defun gnus-article-hide (&optional arg force)
2340 "Hide all the gruft in the current article.
2341 This means that PGP stuff, signatures, cited text and (some)
2342 headers will be hidden.
2343 If given a prefix, show the hidden text instead."
2344 (interactive (list current-prefix-arg 'force))
2345 (gnus-article-hide-headers arg)
2346 (gnus-article-hide-pgp arg)
2347 (gnus-article-hide-citation-maybe arg force)
2348 (gnus-article-hide-signature arg))
2350 (defun gnus-article-maybe-highlight ()
2351 "Do some article highlighting if `article-visual' is non-nil."
2352 (when (gnus-visual-p 'article-highlight 'highlight)
2353 (gnus-article-highlight-some)))
2355 (defun gnus-request-article-this-buffer (article group)
2356 "Get an article and insert it into this buffer."
2357 (let (do-update-line)
2361 (gnus-kill-all-overlays)
2362 (setq group (or group gnus-newsgroup-name))
2364 ;; Open server if it has closed.
2365 (gnus-check-server (gnus-find-method-for-group group))
2367 ;; Using `gnus-request-article' directly will insert the article into
2368 ;; `nntp-server-buffer' - so we'll save some time by not having to
2369 ;; copy it from the server buffer into the article buffer.
2371 ;; We only request an article by message-id when we do not have the
2372 ;; headers for it, so we'll have to get those.
2373 (when (stringp article)
2374 (let ((gnus-override-method gnus-refer-article-method))
2375 (gnus-read-header article)))
2377 ;; If the article number is negative, that means that this article
2378 ;; doesn't belong in this newsgroup (possibly), so we find its
2379 ;; message-id and request it by id instead of number.
2380 (when (and (numberp article)
2382 (get-buffer gnus-summary-buffer)
2383 (buffer-name (get-buffer gnus-summary-buffer)))
2385 (set-buffer gnus-summary-buffer)
2386 (let ((header (gnus-summary-article-header article)))
2389 ((memq article gnus-newsgroup-sparse)
2390 ;; This is a sparse gap article.
2391 (setq do-update-line article)
2392 (setq article (mail-header-id header))
2393 (let ((gnus-override-method gnus-refer-article-method))
2394 (gnus-read-header article))
2395 (setq gnus-newsgroup-sparse
2396 (delq article gnus-newsgroup-sparse)))
2398 ;; It's a real article.
2399 (setq article (mail-header-id header)))
2401 ;; It is an extracted pseudo-article.
2402 (setq article 'pseudo)
2403 (gnus-request-pseudo-article header))))
2405 (let ((method (gnus-find-method-for-group
2406 gnus-newsgroup-name)))
2407 (if (not (eq (car method) 'nneething))
2409 (let ((dir (concat (file-name-as-directory (nth 1 method))
2410 (mail-header-subject header))))
2411 (when (file-directory-p dir)
2412 (setq article 'nneething)
2413 (gnus-group-enter-directory dir))))))))
2416 ;; Refuse to select canceled articles.
2417 ((and (numberp article)
2419 (get-buffer gnus-summary-buffer)
2420 (buffer-name (get-buffer gnus-summary-buffer))
2421 (eq (cdr (save-excursion
2422 (set-buffer gnus-summary-buffer)
2423 (assq article gnus-newsgroup-reads)))
2424 gnus-canceled-mark))
2426 ;; We first check `gnus-original-article-buffer'.
2427 ((and (get-buffer gnus-original-article-buffer)
2430 (set-buffer gnus-original-article-buffer)
2431 (and (equal (car gnus-original-article) group)
2432 (eq (cdr gnus-original-article) article))))
2433 (insert-buffer-substring gnus-original-article-buffer)
2435 ;; Check the backlog.
2436 ((and gnus-keep-backlog
2437 (gnus-backlog-request-article group article (current-buffer)))
2439 ;; Check asynchronous pre-fetch.
2440 ((gnus-async-request-fetched-article group article (current-buffer))
2441 (gnus-async-prefetch-next group article gnus-summary-buffer)
2442 (when (and (numberp article) gnus-keep-backlog)
2443 (gnus-backlog-enter-article group article (current-buffer)))
2446 ((and gnus-use-cache
2448 (gnus-cache-request-article article group))
2450 ;; Get the article and put into the article buffer.
2451 ((or (stringp article) (numberp article))
2452 (let ((gnus-override-method
2453 (and (stringp article) gnus-refer-article-method))
2454 (buffer-read-only nil))
2456 (gnus-kill-all-overlays)
2457 (when (gnus-request-article article group (current-buffer))
2458 (when (numberp article)
2459 (gnus-async-prefetch-next group article gnus-summary-buffer)
2460 (when gnus-keep-backlog
2461 (gnus-backlog-enter-article
2462 group article (current-buffer))))
2467 ;; Take the article from the original article buffer
2468 ;; and place it in the buffer it's supposed to be in.
2469 (when (and (get-buffer gnus-article-buffer)
2471 (equal (buffer-name (current-buffer))
2472 (buffer-name (get-buffer gnus-article-buffer))))
2474 (if (get-buffer gnus-original-article-buffer)
2475 (set-buffer (get-buffer gnus-original-article-buffer))
2476 (set-buffer (get-buffer-create gnus-original-article-buffer))
2477 (buffer-disable-undo (current-buffer))
2478 (setq major-mode 'gnus-original-article-mode)
2479 (setq buffer-read-only t)
2480 (gnus-add-current-to-buffer-list))
2481 (let (buffer-read-only)
2483 (insert-buffer-substring gnus-article-buffer))
2484 (setq gnus-original-article (cons group article))))
2486 ;; Update sparse articles.
2487 (when (and do-update-line
2488 (or (numberp article)
2490 (let ((buf (current-buffer)))
2491 (set-buffer gnus-summary-buffer)
2492 (gnus-summary-update-article do-update-line)
2493 (gnus-summary-goto-subject do-update-line nil t)
2494 (set-window-point (get-buffer-window (current-buffer) t)
2496 (set-buffer buf))))))
2502 (defcustom gnus-article-edit-mode-hook nil
2503 "Hook run in article edit mode buffers."
2504 :group 'gnus-article-various
2507 (defvar gnus-article-edit-done-function nil)
2509 (defvar gnus-article-edit-mode-map nil)
2511 (unless gnus-article-edit-mode-map
2512 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2514 (gnus-define-keys gnus-article-edit-mode-map
2515 "\C-c\C-c" gnus-article-edit-done
2516 "\C-c\C-k" gnus-article-edit-exit)
2518 (gnus-define-keys (gnus-article-edit-wash-map
2519 "\C-c\C-w" gnus-article-edit-mode-map)
2520 "f" gnus-article-edit-full-stops))
2522 (defun gnus-article-edit-mode ()
2523 "Major mode for editing articles.
2524 This is an extended text-mode.
2526 \\{gnus-article-edit-mode-map}"
2528 (kill-all-local-variables)
2529 (setq major-mode 'gnus-article-edit-mode)
2530 (setq mode-name "Article Edit")
2531 (use-local-map gnus-article-edit-mode-map)
2532 (make-local-variable 'gnus-article-edit-done-function)
2533 (make-local-variable 'gnus-prev-winconf)
2534 (setq buffer-read-only nil)
2535 (buffer-enable-undo)
2537 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2539 (defun gnus-article-edit (&optional force)
2540 "Edit the current article.
2541 This will have permanent effect only in mail groups.
2542 If FORCE is non-nil, allow editing of articles even in read-only
2545 (when (and (not force)
2546 (gnus-group-read-only-p))
2547 (error "The current newsgroup does not support article editing"))
2548 (gnus-article-edit-article
2549 `(lambda (no-highlight)
2550 (gnus-summary-edit-article-done
2551 ,(or (mail-header-references gnus-current-headers) "")
2552 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2554 (defun gnus-article-edit-article (exit-func)
2555 "Start editing the contents of the current article buffer."
2556 (let ((winconf (current-window-configuration)))
2557 (set-buffer gnus-article-buffer)
2558 (gnus-article-edit-mode)
2559 (gnus-set-text-properties (point-min) (point-max) nil)
2560 (gnus-configure-windows 'edit-article)
2561 (setq gnus-article-edit-done-function exit-func)
2562 (setq gnus-prev-winconf winconf)
2563 (gnus-message 6 "C-c C-c to end edits")))
2565 (defun gnus-article-edit-done (&optional arg)
2566 "Update the article edits and exit."
2571 (goto-char (point-min))
2572 (when (search-forward "\n\n" nil 1)
2573 (let ((lines (count-lines (point) (point-max)))
2574 (length (- (point-max) (point)))
2575 (case-fold-search t)
2576 (body (copy-marker (point))))
2577 (goto-char (point-min))
2578 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2579 (delete-region (match-beginning 1) (match-end 1))
2580 (insert (number-to-string length)))
2581 (goto-char (point-min))
2582 (when (re-search-forward
2583 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2584 (delete-region (match-beginning 1) (match-end 1))
2585 (insert (number-to-string length)))
2586 (goto-char (point-min))
2587 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2588 (delete-region (match-beginning 1) (match-end 1))
2589 (insert (number-to-string lines)))))))
2590 (let ((func gnus-article-edit-done-function)
2591 (buf (current-buffer))
2592 (start (window-start)))
2593 (gnus-article-edit-exit)
2596 (let ((buffer-read-only nil))
2597 (funcall func arg)))
2599 (set-window-start (get-buffer-window buf) start)
2600 (set-window-point (get-buffer-window buf) (point))))
2602 (defun gnus-article-edit-exit ()
2603 "Exit the article editing without updating."
2605 ;; We remove all text props from the article buffer.
2606 (let ((buf (format "%s" (buffer-string)))
2607 (curbuf (current-buffer))
2609 (window-start (window-start)))
2612 (let ((winconf gnus-prev-winconf))
2614 ;; The cache and backlog have to be flushed somewhat.
2615 (when gnus-use-cache
2616 (gnus-cache-update-article
2617 (car gnus-article-current) (cdr gnus-article-current)))
2618 (when gnus-keep-backlog
2619 (gnus-backlog-remove-article
2620 (car gnus-article-current) (cdr gnus-article-current)))
2621 ;; Flush original article as well.
2623 (when (get-buffer gnus-original-article-buffer)
2624 (set-buffer gnus-original-article-buffer)
2625 (setq gnus-original-article nil)))
2626 (set-window-configuration winconf)
2627 ;; Tippy-toe some to make sure that point remains where it was.
2628 (let ((buf (current-buffer)))
2630 (set-window-start (get-buffer-window (current-buffer)) window-start)
2632 (set-buffer buf)))))
2634 (defun gnus-article-edit-full-stops ()
2635 "Interactively repair spacing at end of sentences."
2638 (goto-char (point-min))
2639 (search-forward-regexp "^$" nil t)
2640 (let ((case-fold-search nil))
2641 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2644 ;;; Article highlights
2647 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2649 ;;; Internal Variables:
2651 (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\\)"
2652 "Regular expression that matches URLs."
2653 :group 'gnus-article-buttons
2656 (defcustom gnus-button-alist
2657 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2658 gnus-button-message-id 2)
2659 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2660 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2661 gnus-button-fetch-group 4)
2662 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2663 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2664 t gnus-button-message-id 3)
2665 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2666 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2667 ;; This is how URLs _should_ be embedded in text...
2668 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2670 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2671 "Alist of regexps matching buttons in article bodies.
2673 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2674 REGEXP: is the string matching text around the button,
2675 BUTTON: is the number of the regexp grouping actually matching the button,
2676 FORM: is a lisp expression which must eval to true for the button to
2678 CALLBACK: is the function to call when the user push this button, and each
2679 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2681 CALLBACK can also be a variable, in that case the value of that
2682 variable it the real callback function."
2683 :group 'gnus-article-buttons
2684 :type '(repeat (list regexp
2685 (integer :tag "Button")
2687 (function :tag "Callback")
2690 (integer :tag "Regexp group")))))
2692 (defcustom gnus-header-button-alist
2693 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2694 0 t gnus-button-message-id 0)
2695 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2696 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2697 0 t gnus-button-mailto 0)
2698 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2699 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2700 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2701 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2702 gnus-button-message-id 3))
2703 "Alist of headers and regexps to match buttons in article heads.
2705 This alist is very similar to `gnus-button-alist', except that each
2706 alist has an additional HEADER element first in each entry:
2708 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2710 HEADER is a regexp to match a header. For a fuller explanation, see
2711 `gnus-button-alist'."
2712 :group 'gnus-article-buttons
2713 :group 'gnus-article-headers
2714 :type '(repeat (list (regexp :tag "Header")
2716 (integer :tag "Button")
2718 (function :tag "Callback")
2721 (integer :tag "Regexp group")))))
2723 (defvar gnus-button-regexp nil)
2724 (defvar gnus-button-marker-list nil)
2725 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2727 (defvar gnus-button-last nil)
2728 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2732 (defun gnus-article-push-button (event)
2733 "Check text under the mouse pointer for a callback function.
2734 If the text under the mouse pointer has a `gnus-callback' property,
2735 call it with the value of the `gnus-data' text property."
2737 (set-buffer (window-buffer (posn-window (event-start event))))
2738 (let* ((pos (posn-point (event-start event)))
2739 (data (get-text-property pos 'gnus-data))
2740 (fun (get-text-property pos 'gnus-callback)))
2742 (funcall fun data))))
2744 (defun gnus-article-press-button ()
2745 "Check text at point for a callback function.
2746 If the text at point has a `gnus-callback' property,
2747 call it with the value of the `gnus-data' text property."
2749 (let* ((data (get-text-property (point) 'gnus-data))
2750 (fun (get-text-property (point) 'gnus-callback)))
2752 (funcall fun data))))
2754 (defun gnus-article-prev-button (n)
2755 "Move point to N buttons backward.
2756 If N is negative, move forward instead."
2758 (gnus-article-next-button (- n)))
2760 (defun gnus-article-next-button (n)
2761 "Move point to N buttons forward.
2762 If N is negative, move backward instead."
2764 (let ((function (if (< n 0) 'previous-single-property-change
2765 'next-single-property-change))
2766 (inhibit-point-motion-hooks t)
2768 (limit (if (< n 0) (point-min) (point-max))))
2770 (while (and (not (= limit (point)))
2772 ;; Skip past the current button.
2773 (when (get-text-property (point) 'gnus-callback)
2774 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2775 ;; Go to the next (or previous) button.
2776 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2777 ;; Put point at the start of the button.
2778 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2779 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2780 ;; Skip past intangible buttons.
2781 (when (get-text-property (point) 'intangible)
2785 (gnus-message 5 "No more buttons"))
2788 (defun gnus-article-highlight (&optional force)
2789 "Highlight current article.
2790 This function calls `gnus-article-highlight-headers',
2791 `gnus-article-highlight-citation',
2792 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2793 do the highlighting. See the documentation for those functions."
2794 (interactive (list 'force))
2795 (gnus-article-highlight-headers)
2796 (gnus-article-highlight-citation force)
2797 (gnus-article-highlight-signature)
2798 (gnus-article-add-buttons force)
2799 (gnus-article-add-buttons-to-head))
2801 (defun gnus-article-highlight-some (&optional force)
2802 "Highlight current article.
2803 This function calls `gnus-article-highlight-headers',
2804 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2805 do the highlighting. See the documentation for those functions."
2806 (interactive (list 'force))
2807 (gnus-article-highlight-headers)
2808 (gnus-article-highlight-signature)
2809 (gnus-article-add-buttons))
2811 (defun gnus-article-highlight-headers ()
2812 "Highlight article headers as specified by `gnus-header-face-alist'."
2815 (set-buffer gnus-article-buffer)
2817 (let ((alist gnus-header-face-alist)
2818 (buffer-read-only nil)
2819 (case-fold-search t)
2820 (inhibit-point-motion-hooks t)
2821 entry regexp header-face field-face from hpoints fpoints)
2822 (message-narrow-to-head)
2823 (while (setq entry (pop alist))
2824 (goto-char (point-min))
2825 (setq regexp (concat "^\\("
2826 (if (string-equal "" (nth 0 entry))
2830 header-face (nth 1 entry)
2831 field-face (nth 2 entry))
2832 (while (and (re-search-forward regexp nil t)
2836 (unless (search-forward ":" nil t)
2838 (when (and header-face
2839 (not (memq (point) hpoints)))
2840 (push (point) hpoints)
2841 (gnus-put-text-property from (point) 'face header-face))
2842 (when (and field-face
2843 (not (memq (setq from (point)) fpoints)))
2845 (if (re-search-forward "^[^ \t]" nil t)
2847 (goto-char (point-max)))
2848 (gnus-put-text-property from (point) 'face field-face))))))))
2850 (defun gnus-article-highlight-signature ()
2851 "Highlight the signature in an article.
2852 It does this by highlighting everything after
2853 `gnus-signature-separator' using `gnus-signature-face'."
2856 (set-buffer gnus-article-buffer)
2857 (let ((buffer-read-only nil)
2858 (inhibit-point-motion-hooks t))
2860 (when (and gnus-signature-face
2861 (gnus-article-narrow-to-signature))
2862 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2863 'face gnus-signature-face)
2865 (gnus-article-search-signature)
2866 (let ((start (match-beginning 0))
2867 (end (set-marker (make-marker) (1+ (match-end 0)))))
2868 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2871 (defun gnus-button-in-region-p (b e prop)
2872 "Say whether PROP exists in the region."
2873 (text-property-not-all b e prop nil))
2875 (defun gnus-article-add-buttons (&optional force)
2876 "Find external references in the article and make buttons of them.
2877 \"External references\" are things like Message-IDs and URLs, as
2878 specified by `gnus-button-alist'."
2879 (interactive (list 'force))
2881 (set-buffer gnus-article-buffer)
2882 (let ((buffer-read-only nil)
2883 (inhibit-point-motion-hooks t)
2884 (case-fold-search t)
2885 (alist gnus-button-alist)
2887 ;; Remove all old markers.
2889 (while (setq marker (pop gnus-button-marker-list))
2891 (when (setq entry (gnus-button-entry))
2892 (put-text-property (match-beginning (nth 1 entry))
2893 (match-end (nth 1 entry))
2894 'gnus-callback nil))
2895 (set-marker marker nil)))
2896 ;; We skip the headers.
2897 (goto-char (point-min))
2898 (unless (search-forward "\n\n" nil t)
2899 (goto-char (point-max)))
2901 (while (setq entry (pop alist))
2902 (setq regexp (car entry))
2904 (while (re-search-forward regexp nil t)
2905 (let* ((start (and entry (match-beginning (nth 1 entry))))
2906 (end (and entry (match-end (nth 1 entry))))
2907 (from (match-beginning 0)))
2908 (when (and (or (eq t (nth 2 entry))
2909 (eval (nth 2 entry)))
2910 (not (gnus-button-in-region-p
2911 start end 'gnus-callback)))
2912 ;; That optional form returned non-nil, so we add the
2914 (gnus-article-add-button
2915 start end 'gnus-button-push
2916 (car (push (set-marker (make-marker) from)
2917 gnus-button-marker-list))))))))))
2919 ;; Add buttons to the head of an article.
2920 (defun gnus-article-add-buttons-to-head ()
2921 "Add buttons to the head of the article."
2924 (set-buffer gnus-article-buffer)
2925 (let ((buffer-read-only nil)
2926 (inhibit-point-motion-hooks t)
2927 (case-fold-search t)
2928 (alist gnus-header-button-alist)
2930 (nnheader-narrow-to-headers)
2932 ;; Each alist entry.
2933 (setq entry (car alist)
2935 (goto-char (point-min))
2936 (while (re-search-forward (car entry) nil t)
2937 ;; Each header matching the entry.
2938 (setq beg (match-beginning 0))
2939 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2940 (match-beginning 0))
2943 (while (re-search-forward (nth 1 entry) end t)
2944 ;; Each match within a header.
2945 (let* ((entry (cdr entry))
2946 (start (match-beginning (nth 1 entry)))
2947 (end (match-end (nth 1 entry)))
2948 (form (nth 2 entry)))
2949 (goto-char (match-end 0))
2951 (gnus-article-add-button
2952 start end (nth 3 entry)
2953 (buffer-substring (match-beginning (nth 4 entry))
2954 (match-end (nth 4 entry)))))))
2958 ;;; External functions:
2960 (defun gnus-article-add-button (from to fun &optional data)
2961 "Create a button between FROM and TO with callback FUN and data DATA."
2962 (when gnus-article-button-face
2963 (gnus-overlay-put (gnus-make-overlay from to)
2964 'face gnus-article-button-face))
2965 (gnus-add-text-properties
2967 (nconc (and gnus-article-mouse-face
2968 (list gnus-mouse-face-prop gnus-article-mouse-face))
2969 (list 'gnus-callback fun)
2970 (and data (list 'gnus-data data)))))
2972 ;;; Internal functions:
2974 (defun gnus-article-set-globals ()
2976 (set-buffer gnus-summary-buffer)
2977 (gnus-set-global-variables)))
2979 (defun gnus-signature-toggle (end)
2981 (set-buffer gnus-article-buffer)
2982 (let ((buffer-read-only nil)
2983 (inhibit-point-motion-hooks t))
2984 (if (get-text-property end 'invisible)
2985 (gnus-article-unhide-text end (point-max))
2986 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2988 (defun gnus-button-entry ()
2989 ;; Return the first entry in `gnus-button-alist' matching this place.
2990 (let ((alist gnus-button-alist)
2993 (setq entry (pop alist))
2994 (if (looking-at (car entry))
2999 (defun gnus-button-push (marker)
3000 ;; Push button starting at MARKER.
3002 (set-buffer gnus-article-buffer)
3004 (let* ((entry (gnus-button-entry))
3005 (inhibit-point-motion-hooks t)
3007 (args (mapcar (lambda (group)
3008 (let ((string (match-string group)))
3009 (gnus-set-text-properties
3010 0 (length string) nil string)
3017 (fboundp (symbol-value fun)))
3018 (apply (symbol-value fun) args))
3020 (gnus-message 1 "You must define `%S' to use this button"
3021 (cons fun args)))))))
3023 (defun gnus-button-message-id (message-id)
3026 (set-buffer gnus-summary-buffer)
3027 (gnus-summary-refer-article message-id)))
3029 (defun gnus-button-fetch-group (address)
3030 "Fetch GROUP specified by ADDRESS."
3031 (if (not (string-match "[:/]" address))
3032 ;; This is just a simple group url.
3033 (gnus-group-read-ephemeral-group address gnus-select-method)
3034 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3036 (error "Can't parse %s" address)
3037 (gnus-group-read-ephemeral-group
3038 (match-string 4 address)
3039 `(nntp ,(match-string 1 address)
3040 (nntp-address ,(match-string 1 address))
3041 (nntp-port-number ,(if (match-end 3)
3042 (match-string 3 address)
3045 (defun gnus-split-string (string pattern)
3046 "Return a list of substrings of STRING which are separated by PATTERN."
3047 (let (parts (start 0))
3048 (while (string-match pattern string start)
3049 (setq parts (cons (substring string start (match-beginning 0)) parts)
3050 start (match-end 0)))
3051 (nreverse (cons (substring string start) parts))))
3053 (defun gnus-url-parse-query-string (query &optional downcase)
3054 (let (retval pairs cur key val)
3055 (setq pairs (gnus-split-string query "&"))
3057 (setq cur (car pairs)
3059 (if (not (string-match "=" cur))
3061 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3062 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3064 (setq key (downcase key)))
3065 (setq cur (assoc key retval))
3067 (setcdr cur (cons val (cdr cur)))
3068 (setq retval (cons (list key val) retval)))))
3071 (defun gnus-url-unhex (x)
3078 (defun gnus-url-unhex-string (str &optional allow-newlines)
3079 "Remove %XXX embedded spaces, etc in a url.
3080 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3081 decoding of carriage returns and line feeds in the string, which is normally
3082 forbidden in URL encoding."
3083 (setq str (or str ""))
3085 (case-fold-search t))
3086 (while (string-match "%[0-9a-f][0-9a-f]" str)
3087 (let* ((start (match-beginning 0))
3088 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3090 (gnus-url-unhex (elt str (+ start 2))))))
3092 tmp (substring str 0 start)
3095 (char-to-string code))
3096 ((or (= code ?\n) (= code ?\r))
3098 (t (char-to-string code))))
3099 str (substring str (match-end 0)))))
3100 (setq tmp (concat tmp str))
3103 (defun gnus-url-mailto (url)
3104 ;; Send mail to someone
3105 (when (string-match "mailto:/*\\(.*\\)" url)
3106 (setq url (substring url (match-beginning 1) nil)))
3107 (let (to args source-url subject func)
3108 (if (string-match (regexp-quote "?") url)
3109 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3110 args (gnus-url-parse-query-string
3111 (substring url (match-end 0) nil) t))
3112 (setq to (gnus-url-unhex-string url)))
3113 (setq args (cons (list "to" to) args)
3114 subject (cdr-safe (assoc "subject" args)))
3117 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3120 (message-position-on-field (caar args)))
3121 (insert (mapconcat 'identity (cdar args) ", "))
3122 (setq args (cdr args)))
3125 (message-goto-subject))))
3127 (defun gnus-button-mailto (address)
3129 (set-buffer (gnus-copy-article-buffer))
3130 (message-reply address))
3132 (defun gnus-button-reply (address)
3133 ;; Reply to ADDRESS.
3134 (message-reply address))
3136 (defun gnus-button-url (address)
3138 (funcall browse-url-browser-function address))
3140 (defun gnus-button-embedded-url (address)
3142 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3144 ;;; Next/prev buttons in the article buffer.
3146 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3147 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3149 (defvar gnus-prev-page-map nil)
3150 (unless gnus-prev-page-map
3151 (setq gnus-prev-page-map (make-sparse-keymap))
3152 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3153 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3155 (defun gnus-insert-prev-page-button ()
3156 (let ((buffer-read-only nil))
3158 gnus-prev-page-line-format nil
3159 `(gnus-prev t local-map ,gnus-prev-page-map
3160 gnus-callback gnus-article-button-prev-page))))
3162 (defvar gnus-next-page-map nil)
3163 (unless gnus-next-page-map
3164 (setq gnus-next-page-map (make-keymap))
3165 (suppress-keymap gnus-prev-page-map)
3166 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3167 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3169 (defun gnus-button-next-page ()
3170 "Go to the next page."
3172 (let ((win (selected-window)))
3173 (select-window (get-buffer-window gnus-article-buffer t))
3174 (gnus-article-next-page)
3175 (select-window win)))
3177 (defun gnus-button-prev-page ()
3178 "Go to the prev page."
3180 (let ((win (selected-window)))
3181 (select-window (get-buffer-window gnus-article-buffer t))
3182 (gnus-article-prev-page)
3183 (select-window win)))
3185 (defun gnus-insert-next-page-button ()
3186 (let ((buffer-read-only nil))
3187 (gnus-eval-format gnus-next-page-line-format nil
3188 `(gnus-next t local-map ,gnus-next-page-map
3190 gnus-article-button-next-page))))
3192 (defun gnus-article-button-next-page (arg)
3193 "Go to the next page."
3195 (let ((win (selected-window)))
3196 (select-window (get-buffer-window gnus-article-buffer t))
3197 (gnus-article-next-page)
3198 (select-window win)))
3200 (defun gnus-article-button-prev-page (arg)
3201 "Go to the prev page."
3203 (let ((win (selected-window)))
3204 (select-window (get-buffer-window gnus-article-buffer t))
3205 (gnus-article-prev-page)
3206 (select-window win)))
3212 (defun gnus-content-header-filter ()
3213 "Header filter for mime-view.
3214 It is registered to variable `mime-view-content-header-filter-alist'."
3215 (goto-char (point-min))
3216 (while (re-search-forward "^[^ \t:]+:" nil t)
3217 (let ((start (match-beginning 0))
3218 (end (std11-field-end))
3221 (narrow-to-region start end)
3222 (decode-mime-charset-region start end default-mime-charset)
3223 (goto-char (point-max))
3225 (eword-decode-header)
3228 (defun mime-view-quitting-method-for-gnus ()
3229 (if (not gnus-show-mime)
3230 (mime-view-kill-buffer))
3231 (delete-other-windows)
3232 (gnus-article-show-summary)
3233 (if (or (not gnus-show-mime)
3234 (null gnus-have-all-headers))
3235 (gnus-summary-select-article nil t)
3238 (set-alist 'mime-view-content-header-filter-alist
3239 'gnus-original-article-mode
3240 (function gnus-content-header-filter))
3242 (set-alist 'mime-text-decoder-alist
3243 'gnus-original-article-mode
3244 (function mime-text-decode-buffer))
3246 (set-alist 'mime-view-quitting-method-alist
3247 'gnus-original-article-mode
3248 (function mime-view-quitting-method-for-gnus))
3250 (set-alist 'mime-view-show-summary-method
3251 'gnus-original-article-mode
3252 (function mime-view-quitting-method-for-gnus))
3262 (run-hooks 'gnus-art-load-hook)
3264 ;;; gnus-art.el ends here