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 (defvar mime::preview/content-list)
1056 (defvar mime::preview-content-info/point-min)
1057 (defun gnus-article-narrow-to-signature ()
1058 "Narrow to the signature; return t if a signature is found, else nil."
1060 (when (and (boundp 'mime::preview/content-list)
1061 mime::preview/content-list)
1062 ;; We have a MIMEish article, so we use the MIME data to narrow.
1063 (let ((pcinfo (car (last mime::preview/content-list))))
1066 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1069 (when (gnus-article-search-signature)
1071 ;; Check whether we have some limits to what we consider
1072 ;; to be a signature.
1073 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1074 (list gnus-signature-limit)))
1076 (while (setq limit (pop limits))
1077 (if (or (and (integerp limit)
1078 (< (- (point-max) (point)) limit))
1080 (< (count-lines (point) (point-max)) limit))
1081 (and (gnus-functionp limit)
1083 (and (stringp limit)
1084 (not (re-search-forward limit nil t))))
1085 () ; This limit did not succeed.
1089 (narrow-to-region (point) (point-max))
1092 (defun gnus-article-search-signature ()
1093 "Search the current buffer for the signature separator.
1094 Put point at the beginning of the signature separator."
1095 (let ((cur (point)))
1096 (goto-char (point-max))
1097 (if (if (stringp gnus-signature-separator)
1098 (re-search-backward gnus-signature-separator nil t)
1099 (let ((seps gnus-signature-separator))
1101 (not (re-search-backward (car seps) nil t)))
1109 (autoload 'w3-display "w3-parse")
1110 (autoload 'w3-do-setup "w3" "" t)
1111 (autoload 'w3-region "w3-display" "" t))
1113 (defun gnus-article-treat-html ()
1116 (let ((cbuf (current-buffer)))
1117 (set-buffer gnus-article-buffer)
1118 (let (buf buffer-read-only b e)
1120 (goto-char (point-min))
1122 (if (search-forward "\n\n" nil t)
1125 (setq e (point-max)))
1126 (nnheader-temp-write nil
1127 (insert-buffer-substring gnus-article-buffer b e)
1129 (save-window-excursion
1130 (w3-region (point-min) (point-max))
1131 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1133 (delete-region (point-min) (point-max))
1136 (goto-char (point-min))
1137 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1138 (set-buffer cbuf))))
1140 (defun gnus-article-hidden-arg ()
1141 "Return the current prefix arg as a number, or 0 if no prefix."
1142 (list (if current-prefix-arg
1143 (prefix-numeric-value current-prefix-arg)
1146 (defun gnus-article-check-hidden-text (type arg)
1147 "Return nil if hiding is necessary.
1148 Arg can be nil or a number. Nil and positive means hide, negative
1149 means show, 0 means toggle."
1153 (let ((hide (gnus-article-hidden-text-p type)))
1159 (gnus-article-show-hidden-text type))
1161 (if (eq hide 'hidden)
1162 (gnus-article-show-hidden-text type)
1165 (defun gnus-article-hidden-text-p (type)
1166 "Say whether the current buffer contains hidden text of type TYPE."
1167 (let ((start (point-min))
1168 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1170 (not (get-text-property pos 'invisible)))
1172 (text-property-any (1+ pos) (point-max) 'article-type type)))
1177 (defun gnus-article-show-hidden-text (type &optional hide)
1178 "Show all hidden text of type TYPE.
1179 If HIDE, hide the text instead."
1181 (let ((buffer-read-only nil)
1182 (inhibit-point-motion-hooks t)
1185 (while (setq beg (text-property-any end (point-max) 'article-type type))
1188 (text-property-not-all beg (point-max) 'article-type type)
1191 (gnus-article-hide-text beg end gnus-hidden-properties)
1192 (gnus-article-unhide-text beg end))
1196 (defconst article-time-units
1197 `((year . ,(* 365.25 24 60 60))
1198 (week . ,(* 7 24 60 60))
1199 (day . ,(* 24 60 60))
1203 "Mapping from time units to seconds.")
1205 (defun article-date-ut (&optional type highlight header)
1206 "Convert DATE date to universal time in the current article.
1207 If TYPE is `local', convert to local time; if it is `lapsed', output
1208 how much time has lapsed since DATE."
1209 (interactive (list 'ut t))
1210 (let* ((header (or header
1211 (mail-header-date gnus-current-headers)
1212 (message-fetch-field "date")
1214 (date (if (vectorp header) (mail-header-date header)
1216 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1217 (inhibit-point-motion-hooks t)
1218 bface eface newline)
1219 (when (and date (not (string= date "")))
1222 (nnheader-narrow-to-headers)
1223 (let ((buffer-read-only nil))
1224 ;; Delete any old Date headers.
1225 (if (re-search-forward date-regexp nil t)
1227 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1228 eface (get-text-property (1- (gnus-point-at-eol))
1230 (delete-region (progn (beginning-of-line) (point))
1231 (progn (end-of-line) (point)))
1232 (beginning-of-line))
1233 (goto-char (point-max))
1235 (insert (article-make-date-line date type))
1238 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1239 (put-text-property (match-beginning 1) (1+ (match-end 1))
1241 (put-text-property (match-beginning 2) (match-end 2)
1245 (insert "\n"))))))))
1247 (defun article-make-date-line (date type)
1248 "Return a DATE line of TYPE."
1250 ;; Convert to the local timezone. We have to slap a
1251 ;; `condition-case' round the calls to the timezone
1252 ;; functions since they aren't particularly resistant to
1255 (concat "Date: " (condition-case ()
1256 (timezone-make-date-arpa-standard date)
1258 ;; Convert to Universal Time.
1262 (timezone-make-date-arpa-standard date nil "UT")
1264 ;; Get the original date from the article.
1265 ((eq type 'original)
1266 (concat "Date: " date))
1267 ;; Let the user define the format.
1271 (format-time-string gnus-article-time-format
1274 (timezone-make-date-arpa-standard
1276 ;; Do an X-Sent lapsed format.
1278 ;; If the date is seriously mangled, the timezone functions are
1279 ;; liable to bug out, so we ignore all errors.
1280 (let* ((now (current-time))
1285 (timezone-make-date-arpa-standard
1286 (current-time-string now)
1287 (current-time-zone now) "UT"))
1289 (timezone-make-date-arpa-standard
1291 (real-sec (and real-time
1292 (+ (* (float (car real-time)) 65536)
1294 (sec (and real-time (abs real-sec)))
1304 ;; This is a bit convoluted, but basically we go
1305 ;; through the time units for years, weeks, etc,
1306 ;; and divide things to see whether that results
1307 ;; in positive answers.
1310 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1311 ;; The (remaining) seconds are too few to
1312 ;; be divided into this time unit.
1314 ;; It's big enough, so we output it.
1315 (setq sec (- sec (* num (cdr unit))))
1317 (concat (if prev ", " "") (int-to-string
1319 " " (symbol-name (car unit))
1320 (if (> num 1) "s" ""))
1322 article-time-units "")
1323 ;; If dates are odd, then it might appear like the
1324 ;; article was sent in the future.
1327 " in the future"))))))
1329 (error "Unknown conversion type: %s" type))))
1331 (defun article-date-local (&optional highlight)
1332 "Convert the current article date to the local timezone."
1333 (interactive (list t))
1334 (article-date-ut 'local highlight))
1336 (defun article-date-original (&optional highlight)
1337 "Convert the current article date to what it was originally.
1338 This is only useful if you have used some other date conversion
1339 function and want to see what the date was before converting."
1340 (interactive (list t))
1341 (article-date-ut 'original highlight))
1343 (defun article-date-lapsed (&optional highlight)
1344 "Convert the current article date to time lapsed since it was sent."
1345 (interactive (list t))
1346 (article-date-ut 'lapsed highlight))
1348 (defun article-update-date-lapsed ()
1349 "Function to be run from a timer to update the lapsed time line."
1352 (when (gnus-buffer-live-p gnus-article-buffer)
1353 (set-buffer gnus-article-buffer)
1354 (goto-char (point-min))
1355 (when (re-search-forward "^X-Sent:" nil t)
1356 (article-date-lapsed t))))))
1358 (defun gnus-start-date-timer (&optional n)
1359 "Start a timer to update the X-Sent header in the article buffers.
1360 The numerical prefix says how frequently (in seconds) the function
1365 (gnus-stop-date-timer)
1366 (setq article-lapsed-timer
1367 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1369 (defun gnus-stop-date-timer ()
1370 "Stop the X-Sent timer."
1372 (when article-lapsed-timer
1373 (nnheader-cancel-timer article-lapsed-timer)
1374 (setq article-lapsed-timer nil)))
1376 (defun article-date-user (&optional highlight)
1377 "Convert the current article date to the user-defined format.
1378 This format is defined by the `gnus-article-time-format' variable."
1379 (interactive (list t))
1380 (article-date-ut 'user highlight))
1382 (defun article-show-all ()
1383 "Show all hidden text in the article buffer."
1386 (let ((buffer-read-only nil))
1387 (gnus-article-unhide-text (point-min) (point-max)))))
1389 (defun article-emphasize (&optional arg)
1390 "Emphasize text according to `gnus-emphasis-alist'."
1391 (interactive (gnus-article-hidden-arg))
1392 (unless (gnus-article-check-hidden-text 'emphasis arg)
1394 (let ((alist gnus-emphasis-alist)
1395 (buffer-read-only nil)
1396 (props (append '(article-type emphasis)
1397 gnus-hidden-properties))
1398 regexp elem beg invisible visible face)
1399 (goto-char (point-min))
1400 (search-forward "\n\n" nil t)
1402 (while (setq elem (pop alist))
1404 (setq regexp (car elem)
1405 invisible (nth 1 elem)
1406 visible (nth 2 elem)
1408 (while (re-search-forward regexp nil t)
1409 (when (and (match-beginning visible) (match-beginning invisible))
1410 (gnus-article-hide-text
1411 (match-beginning invisible) (match-end invisible) props)
1412 (gnus-article-unhide-text-type
1413 (match-beginning visible) (match-end visible) 'emphasis)
1414 (gnus-put-text-property-excluding-newlines
1415 (match-beginning visible) (match-end visible) 'face face)
1416 (goto-char (match-end invisible)))))))))
1418 (defvar gnus-summary-article-menu)
1419 (defvar gnus-summary-post-menu)
1421 ;;; Saving functions.
1423 (defun gnus-article-save (save-buffer file &optional num)
1424 "Save the currently selected article."
1425 (unless gnus-save-all-headers
1426 ;; Remove headers according to `gnus-saved-headers'.
1427 (let ((gnus-visible-headers
1428 (or gnus-saved-headers gnus-visible-headers))
1429 (gnus-article-buffer save-buffer))
1431 (set-buffer save-buffer)
1432 (article-hide-headers 1 t))))
1433 (save-window-excursion
1434 (if (not gnus-default-article-saver)
1435 (error "No default saver is defined")
1436 ;; !!! Magic! The saving functions all save
1437 ;; `gnus-original-article-buffer' (or so they think), but we
1438 ;; bind that variable to our save-buffer.
1439 (set-buffer gnus-article-buffer)
1440 (let* ((gnus-save-article-buffer save-buffer)
1443 ((not gnus-prompt-before-saving) 'default)
1444 ((eq gnus-prompt-before-saving 'always) nil)
1446 (gnus-number-of-articles-to-be-saved
1447 (when (eq gnus-prompt-before-saving t)
1449 (set-buffer gnus-summary-buffer)
1450 (funcall gnus-default-article-saver filename)))))
1452 (defun gnus-read-save-file-name (prompt &optional filename
1453 function group headers variable)
1455 (funcall function group headers (symbol-value variable)))
1460 ((eq filename 'default)
1466 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1469 (if (and gnus-number-of-articles-to-be-saved
1470 (> gnus-number-of-articles-to-be-saved 1))
1471 (format "these %d articles"
1472 gnus-number-of-articles-to-be-saved)
1475 ;; Let the split methods have their say.
1477 ;; No split name was found.
1480 (concat prompt " (default "
1481 (file-name-nondirectory default-name) ") ")
1482 (file-name-directory default-name)
1484 ;; A single group name is returned.
1485 ((stringp split-name)
1487 (funcall function split-name headers
1488 (symbol-value variable)))
1490 (concat prompt " (default "
1491 (file-name-nondirectory default-name) ") ")
1492 (file-name-directory default-name)
1494 ;; A single split name was found
1495 ((= 1 (length split-name))
1496 (let* ((name (expand-file-name
1497 (car split-name) gnus-article-save-directory))
1498 (dir (cond ((file-directory-p name)
1499 (file-name-as-directory name))
1500 ((file-exists-p name) name)
1501 (t gnus-article-save-directory))))
1503 (concat prompt " (default " name ") ")
1505 ;; A list of splits was found.
1507 (setq split-name (nreverse split-name))
1509 (let ((file-name-history
1510 (nconc split-name file-name-history)))
1514 (concat prompt " (`M-p' for defaults) ")
1515 gnus-article-save-directory
1517 gnus-article-save-directory)))
1518 (car (push result file-name-history)))))))
1519 ;; Create the directory.
1520 (gnus-make-directory (file-name-directory file))
1521 ;; If we have read a directory, we append the default file name.
1522 (when (file-directory-p file)
1523 (setq file (concat (file-name-as-directory file)
1524 (file-name-nondirectory default-name))))
1525 ;; Possibly translate some characters.
1526 (nnheader-translate-file-chars file)))))
1527 (gnus-make-directory (file-name-directory result))
1528 (set variable result)))
1530 (defun gnus-article-archive-name (group)
1531 "Return the first instance of an \"Archive-name\" in the current buffer."
1532 (let ((case-fold-search t))
1533 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1534 (nnheader-concat gnus-article-save-directory
1535 (match-string 1)))))
1537 (defun gnus-article-nndoc-name (group)
1538 "If GROUP is an nndoc group, return the name of the parent group."
1539 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1540 (gnus-group-get-parameter group 'save-article-group)))
1542 (defun gnus-summary-save-in-rmail (&optional filename)
1543 "Append this article to Rmail file.
1544 Optional argument FILENAME specifies file name.
1545 Directory to save to is default to `gnus-article-save-directory'."
1547 (setq filename (gnus-read-save-file-name
1548 "Save %s in rmail file:" filename
1549 gnus-rmail-save-name gnus-newsgroup-name
1550 gnus-current-headers 'gnus-newsgroup-last-rmail))
1551 (gnus-eval-in-buffer-window gnus-save-article-buffer
1555 (gnus-output-to-rmail filename))))
1558 (defun gnus-summary-save-in-mail (&optional filename)
1559 "Append this article to Unix mail file.
1560 Optional argument FILENAME specifies file name.
1561 Directory to save to is default to `gnus-article-save-directory'."
1563 (setq filename (gnus-read-save-file-name
1564 "Save %s in Unix mail file:" filename
1565 gnus-mail-save-name gnus-newsgroup-name
1566 gnus-current-headers 'gnus-newsgroup-last-mail))
1567 (gnus-eval-in-buffer-window gnus-save-article-buffer
1571 (if (and (file-readable-p filename)
1572 (mail-file-babyl-p filename))
1573 (gnus-output-to-rmail filename t)
1574 (gnus-output-to-mail filename)))))
1577 (defun gnus-summary-save-in-file (&optional filename overwrite)
1578 "Append this article to file.
1579 Optional argument FILENAME specifies file name.
1580 Directory to save to is default to `gnus-article-save-directory'."
1582 (setq filename (gnus-read-save-file-name
1583 "Save %s in file:" filename
1584 gnus-file-save-name gnus-newsgroup-name
1585 gnus-current-headers 'gnus-newsgroup-last-file))
1586 (gnus-eval-in-buffer-window gnus-save-article-buffer
1590 (when (and overwrite
1591 (file-exists-p filename))
1592 (delete-file filename))
1593 (gnus-output-to-file filename))))
1596 (defun gnus-summary-write-to-file (&optional filename)
1597 "Write this article to a file.
1598 Optional argument FILENAME specifies file name.
1599 The directory to save in defaults to `gnus-article-save-directory'."
1601 (gnus-summary-save-in-file nil t))
1603 (defun gnus-summary-save-body-in-file (&optional filename)
1604 "Append this article body to a file.
1605 Optional argument FILENAME specifies file name.
1606 The directory to save in defaults to `gnus-article-save-directory'."
1608 (setq filename (gnus-read-save-file-name
1609 "Save %s body in file:" filename
1610 gnus-file-save-name gnus-newsgroup-name
1611 gnus-current-headers 'gnus-newsgroup-last-file))
1612 (gnus-eval-in-buffer-window gnus-save-article-buffer
1616 (goto-char (point-min))
1617 (when (search-forward "\n\n" nil t)
1618 (narrow-to-region (point) (point-max)))
1619 (gnus-output-to-file filename))))
1622 (defun gnus-summary-save-in-pipe (&optional command)
1623 "Pipe this article to subprocess."
1626 (cond ((eq command 'default)
1627 gnus-last-shell-command)
1631 "Shell command on %s: "
1632 (if (and gnus-number-of-articles-to-be-saved
1633 (> gnus-number-of-articles-to-be-saved 1))
1634 (format "these %d articles"
1635 gnus-number-of-articles-to-be-saved)
1637 gnus-last-shell-command))))
1638 (when (string-equal command "")
1639 (setq command gnus-last-shell-command))
1640 (gnus-eval-in-buffer-window gnus-article-buffer
1643 (shell-command-on-region (point-min) (point-max) command nil)))
1644 (setq gnus-last-shell-command command))
1646 ;;; Article file names when saving.
1648 (defun gnus-capitalize-newsgroup (newsgroup)
1649 "Capitalize NEWSGROUP name."
1650 (when (not (zerop (length newsgroup)))
1651 (concat (char-to-string (upcase (aref newsgroup 0)))
1652 (substring newsgroup 1))))
1654 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1655 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1656 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1657 Otherwise, it is like ~/News/news/group/num."
1660 (concat (if (gnus-use-long-file-name 'not-save)
1661 (gnus-capitalize-newsgroup newsgroup)
1662 (gnus-newsgroup-directory-form newsgroup))
1663 "/" (int-to-string (mail-header-number headers)))
1664 gnus-article-save-directory)))
1666 (string-equal (file-name-directory default)
1667 (file-name-directory last-file))
1668 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1670 (or last-file default))))
1672 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1673 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1674 If variable `gnus-use-long-file-name' is non-nil, it is
1675 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1678 (concat (if (gnus-use-long-file-name 'not-save)
1680 (gnus-newsgroup-directory-form newsgroup))
1681 "/" (int-to-string (mail-header-number headers)))
1682 gnus-article-save-directory)))
1684 (string-equal (file-name-directory default)
1685 (file-name-directory last-file))
1686 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1688 (or last-file default))))
1690 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1691 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1692 If variable `gnus-use-long-file-name' is non-nil, it is
1693 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1696 (if (gnus-use-long-file-name 'not-save)
1697 (gnus-capitalize-newsgroup newsgroup)
1698 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1699 gnus-article-save-directory)))
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)
1709 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1710 gnus-article-save-directory)))
1717 (setq afunc (car func)
1720 gfunc (intern (format "gnus-%s" func))))
1722 (if (not (fboundp afunc))
1724 `(lambda (&optional interactive &rest args)
1725 ,(documentation afunc t)
1726 (interactive (list t))
1728 (set-buffer gnus-article-buffer)
1730 (call-interactively ',afunc)
1731 (apply ',afunc args))))))))
1732 '(article-hide-headers
1733 article-hide-boring-headers
1734 article-treat-overstrike
1735 (article-fill . gnus-article-word-wrap)
1737 article-display-x-face
1738 article-de-quoted-unreadable
1739 article-mime-decode-quoted-printable
1742 article-hide-signature
1743 article-remove-trailing-blank-lines
1744 article-strip-leading-blank-lines
1745 article-strip-multiple-blank-lines
1746 article-strip-leading-space
1747 article-strip-blank-lines
1749 article-date-original
1754 article-treat-dumbquotes
1755 (article-show-all . gnus-article-show-all-headers))))
1758 ;;; Gnus article mode
1761 (put 'gnus-article-mode 'mode-class 'special)
1763 (gnus-define-keys gnus-article-mode-map
1764 " " gnus-article-goto-next-page
1765 "\177" gnus-article-goto-prev-page
1766 [delete] gnus-article-goto-prev-page
1767 "\C-c^" gnus-article-refer-article
1768 "h" gnus-article-show-summary
1769 "s" gnus-article-show-summary
1770 "\C-c\C-m" gnus-article-mail
1771 "?" gnus-article-describe-briefly
1772 gnus-mouse-2 gnus-article-push-button
1773 "\r" gnus-article-press-button
1774 "\t" gnus-article-next-button
1775 "\M-\t" gnus-article-prev-button
1776 "e" gnus-article-edit
1777 "<" beginning-of-buffer
1779 "\C-c\C-i" gnus-info-find-node
1782 "\C-d" gnus-article-read-summary-keys
1783 "\M-*" gnus-article-read-summary-keys
1784 "\M-#" gnus-article-read-summary-keys
1785 "\M-^" gnus-article-read-summary-keys
1786 "\M-g" gnus-article-read-summary-keys)
1788 (substitute-key-definition
1789 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1791 (defun gnus-article-make-menu-bar ()
1792 (gnus-turn-off-edit-menu 'article)
1793 (unless (boundp 'gnus-article-article-menu)
1795 gnus-article-article-menu gnus-article-mode-map ""
1797 ["Scroll forwards" gnus-article-goto-next-page t]
1798 ["Scroll backwards" gnus-article-goto-prev-page t]
1799 ["Show summary" gnus-article-show-summary t]
1800 ["Fetch Message-ID at point" gnus-article-refer-article t]
1801 ["Mail to address at point" gnus-article-mail t]))
1804 gnus-article-treatment-menu gnus-article-mode-map ""
1806 ["Hide headers" gnus-article-hide-headers t]
1807 ["Hide signature" gnus-article-hide-signature t]
1808 ["Hide citation" gnus-article-hide-citation t]
1809 ["Treat overstrike" gnus-article-treat-overstrike t]
1810 ["Remove carriage return" gnus-article-remove-cr t]
1811 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1814 (when (boundp 'gnus-summary-article-menu)
1815 (define-key gnus-article-mode-map [menu-bar commands]
1816 (cons "Commands" gnus-summary-article-menu))))
1818 (when (boundp 'gnus-summary-post-menu)
1819 (define-key gnus-article-mode-map [menu-bar post]
1820 (cons "Post" gnus-summary-post-menu)))
1822 (run-hooks 'gnus-article-menu-hook)))
1824 (defun gnus-article-mode ()
1825 "Major mode for displaying an article.
1827 All normal editing commands are switched off.
1829 The following commands are available in addition to all summary mode
1831 \\<gnus-article-mode-map>
1832 \\[gnus-article-next-page]\t Scroll the article one page forwards
1833 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1834 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1835 \\[gnus-article-show-summary]\t Display the summary buffer
1836 \\[gnus-article-mail]\t Send a reply to the address near point
1837 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1838 \\[gnus-info-find-node]\t Go to the Gnus info node"
1840 (when (gnus-visual-p 'article-menu 'menu)
1841 (gnus-article-make-menu-bar))
1842 (kill-all-local-variables)
1843 (gnus-simplify-mode-line)
1844 (setq mode-name "Article")
1845 (setq major-mode 'gnus-article-mode)
1846 (make-local-variable 'minor-mode-alist)
1847 (unless (assq 'gnus-show-mime minor-mode-alist)
1848 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1849 (use-local-map gnus-article-mode-map)
1850 (gnus-update-format-specifications nil 'article-mode)
1851 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1852 (set (make-local-variable 'gnus-page-broken) nil)
1853 (set (make-local-variable 'gnus-button-marker-list) nil)
1854 (gnus-set-default-directory)
1855 (buffer-disable-undo (current-buffer))
1856 (setq buffer-read-only t)
1857 (set-syntax-table gnus-article-mode-syntax-table)
1858 (run-hooks 'gnus-article-mode-hook))
1860 (defun gnus-article-setup-buffer ()
1861 "Initialize the article buffer."
1862 (let* ((name (if gnus-single-article-buffer "*Article*"
1863 (concat "*Article " gnus-newsgroup-name "*")))
1865 (progn (string-match "\\*Article" name)
1866 (concat " *Original Article"
1867 (substring name (match-end 0))))))
1868 (setq gnus-article-buffer name)
1869 (setq gnus-original-article-buffer original)
1870 ;; This might be a variable local to the summary buffer.
1871 (unless gnus-single-article-buffer
1873 (set-buffer gnus-summary-buffer)
1874 (setq gnus-article-buffer name)
1875 (setq gnus-original-article-buffer original)
1876 (gnus-set-global-variables)))
1877 ;; Init original article buffer.
1879 (set-buffer (get-buffer-create gnus-original-article-buffer))
1880 (buffer-disable-undo (current-buffer))
1881 (setq major-mode 'gnus-original-article-mode)
1882 (gnus-add-current-to-buffer-list)
1883 (make-local-variable 'gnus-original-article))
1884 (if (get-buffer name)
1887 (buffer-disable-undo (current-buffer))
1888 (setq buffer-read-only t)
1889 (gnus-add-current-to-buffer-list)
1890 (unless (eq major-mode 'gnus-article-mode)
1891 (gnus-article-mode))
1894 (set-buffer (get-buffer-create name))
1895 (gnus-add-current-to-buffer-list)
1897 (make-local-variable 'gnus-summary-buffer)
1898 (current-buffer)))))
1900 ;; Set article window start at LINE, where LINE is the number of lines
1901 ;; from the head of the article.
1902 (defun gnus-article-set-window-start (&optional line)
1904 (get-buffer-window gnus-article-buffer t)
1906 (set-buffer gnus-article-buffer)
1907 (goto-char (point-min))
1910 (gnus-message 6 "Moved to bookmark")
1911 (search-forward "\n\n" nil t)
1915 ;;; @@ article filters
1917 (defun gnus-article-preview-mime-message ()
1918 (make-local-variable 'mime-button-mother-dispatcher)
1919 (setq mime-button-mother-dispatcher
1920 (function gnus-article-push-button))
1921 (let ((default-mime-charset
1923 (set-buffer gnus-summary-buffer)
1924 default-mime-charset))
1927 (mime-view-mode nil nil nil gnus-original-article-buffer
1929 gnus-article-mode-map)
1931 (run-hooks 'gnus-mime-article-prepare-hook)
1934 (defun gnus-article-decode-encoded-word ()
1935 "Header filter for gnus-article-mode.
1936 It is registered to variable `mime-view-content-header-filter-alist'."
1937 (goto-char (point-min))
1938 (let ((charset (save-excursion
1939 (set-buffer gnus-summary-buffer)
1940 default-mime-charset)))
1942 (std11-narrow-to-header)
1943 (goto-char (point-min))
1944 (while (re-search-forward "^[^ \t:]+:" nil t)
1945 (let ((start (match-beginning 0))
1946 (end (std11-field-end))
1949 (narrow-to-region start end)
1950 (decode-mime-charset-region start end charset)
1951 (goto-char (point-max))
1953 (eword-decode-header)
1955 (decode-mime-charset-region (point) (point-max) charset)
1956 (mime-maybe-hide-echo-buffer)
1958 (run-hooks 'gnus-mime-article-prepare-hook)
1961 (defun gnus-article-prepare (article &optional all-headers header)
1962 "Prepare ARTICLE in article mode buffer.
1963 ARTICLE should either be an article number or a Message-ID.
1964 If ARTICLE is an id, HEADER should be the article headers.
1965 If ALL-HEADERS is non-nil, no headers are hidden."
1967 ;; Make sure we start in a summary buffer.
1968 (unless (eq major-mode 'gnus-summary-mode)
1969 (set-buffer gnus-summary-buffer))
1970 (setq gnus-summary-buffer (current-buffer))
1971 ;; Make sure the connection to the server is alive.
1972 (unless (gnus-server-opened
1973 (gnus-find-method-for-group gnus-newsgroup-name))
1974 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
1975 (gnus-request-group gnus-newsgroup-name t))
1976 (let* ((gnus-article (if header (mail-header-number header) article))
1977 (summary-buffer (current-buffer))
1978 (internal-hook gnus-article-internal-prepare-hook)
1979 (group gnus-newsgroup-name)
1982 (gnus-article-setup-buffer)
1983 (set-buffer gnus-article-buffer)
1984 ;; Deactivate active regions.
1985 (when (and (boundp 'transient-mark-mode)
1986 transient-mark-mode)
1987 (setq mark-active nil))
1988 (if (not (setq result (let ((buffer-read-only nil))
1989 (gnus-request-article-this-buffer
1991 ;; There is no such article.
1993 (when (and (numberp article)
1994 (not (memq article gnus-newsgroup-sparse)))
1995 (setq gnus-article-current
1996 (cons gnus-newsgroup-name article))
1997 (set-buffer gnus-summary-buffer)
1998 (setq gnus-current-article article)
1999 (gnus-summary-mark-article article gnus-canceled-mark))
2000 (unless (memq article gnus-newsgroup-sparse)
2002 1 "No such article (may have expired or been canceled)")))
2003 (if (or (eq result 'pseudo) (eq result 'nneething))
2006 (set-buffer summary-buffer)
2007 (push article gnus-newsgroup-history)
2008 (setq gnus-last-article gnus-current-article
2009 gnus-current-article 0
2010 gnus-current-headers nil
2011 gnus-article-current nil)
2012 (if (eq result 'nneething)
2013 (gnus-configure-windows 'summary)
2014 (gnus-configure-windows 'article))
2015 (gnus-set-global-variables))
2016 (gnus-set-mode-line 'article))
2017 ;; The result from the `request' was an actual article -
2018 ;; or at least some text that is now displayed in the
2020 (when (and (numberp article)
2021 (not (eq article gnus-current-article)))
2022 ;; Seems like a new article has been selected.
2023 ;; `gnus-current-article' must be an article number.
2025 (set-buffer summary-buffer)
2026 (push article gnus-newsgroup-history)
2027 (setq gnus-last-article gnus-current-article
2028 gnus-current-article article
2029 gnus-current-headers
2030 (gnus-summary-article-header gnus-current-article)
2031 gnus-article-current
2032 (cons gnus-newsgroup-name gnus-current-article))
2033 (unless (vectorp gnus-current-headers)
2034 (setq gnus-current-headers nil))
2035 (gnus-summary-goto-subject gnus-current-article)
2036 (gnus-summary-show-thread)
2037 (run-hooks 'gnus-mark-article-hook)
2038 (gnus-set-mode-line 'summary)
2039 (when (gnus-visual-p 'article-highlight 'highlight)
2040 (run-hooks 'gnus-visual-mark-article-hook))
2041 ;; Set the global newsgroup variables here.
2042 ;; Suggested by Jim Sisolak
2043 ;; <sisolak@trans4.neep.wisc.edu>.
2044 (gnus-set-global-variables)
2045 (setq gnus-have-all-headers
2046 (or all-headers gnus-show-all-headers))
2048 (vectorp (gnus-summary-article-header article))
2049 (gnus-cache-possibly-enter-article
2051 (gnus-summary-article-header article)
2052 (memq article gnus-newsgroup-marked)
2053 (memq article gnus-newsgroup-dormant)
2054 (memq article gnus-newsgroup-unreads)))))
2055 (when (or (numberp article)
2057 ;; Hooks for getting information from the article.
2058 ;; This hook must be called before being narrowed.
2059 (let (buffer-read-only)
2060 (run-hooks 'internal-hook)
2061 (run-hooks 'gnus-article-prepare-hook)
2062 ;; Decode MIME message.
2063 (when gnus-show-mime
2064 (if (or (not gnus-strict-mime)
2065 (gnus-fetch-field "Mime-Version"))
2066 (funcall gnus-show-mime-method)
2067 (funcall gnus-decode-encoded-word-method)))
2068 ;; Perform the article display hooks.
2069 (run-hooks 'gnus-article-display-hook))
2071 (goto-char (point-min))
2072 (setq gnus-page-broken
2073 (when gnus-break-pages
2074 (gnus-narrow-to-page)
2076 (gnus-set-mode-line 'article)
2077 (gnus-configure-windows 'article)
2078 (goto-char (point-min))
2081 (defun gnus-article-wash-status ()
2082 "Return a string which display status of article washing."
2084 (set-buffer gnus-article-buffer)
2085 (let ((cite (gnus-article-hidden-text-p 'cite))
2086 (headers (gnus-article-hidden-text-p 'headers))
2087 (boring (gnus-article-hidden-text-p 'boring-headers))
2088 (pgp (gnus-article-hidden-text-p 'pgp))
2089 (pem (gnus-article-hidden-text-p 'pem))
2090 (signature (gnus-article-hidden-text-p 'signature))
2091 (overstrike (gnus-article-hidden-text-p 'overstrike))
2092 (emphasis (gnus-article-hidden-text-p 'emphasis))
2093 (mime gnus-show-mime))
2094 (format "%c%c%c%c%c%c%c"
2096 (if (or headers boring) ?h ? )
2097 (if (or pgp pem) ?p ? )
2098 (if signature ?s ? )
2099 (if overstrike ?o ? )
2101 (if emphasis ?e ? )))))
2103 (defun gnus-article-hide-headers-if-wanted ()
2104 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2105 Provided for backwards compatibility."
2106 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2108 (gnus-article-hide-headers)))
2112 (defun gnus-output-to-file (file-name)
2113 "Append the current article to a file named FILE-NAME."
2114 (let ((artbuf (current-buffer)))
2115 (nnheader-temp-write nil
2116 (insert-buffer-substring artbuf)
2117 ;; Append newline at end of the buffer as separator, and then
2119 (goto-char (point-max))
2121 (append-to-file (point-min) (point-max) file-name)
2124 (defun gnus-narrow-to-page (&optional arg)
2125 "Narrow the article buffer to a page.
2126 If given a numerical ARG, move forward ARG pages."
2128 (setq arg (if arg (prefix-numeric-value arg) 0))
2130 (set-buffer gnus-article-buffer)
2131 (goto-char (point-min))
2133 ;; Remove any old next/prev buttons.
2134 (when (gnus-visual-p 'page-marker)
2135 (let ((buffer-read-only nil))
2136 (gnus-remove-text-with-property 'gnus-prev)
2137 (gnus-remove-text-with-property 'gnus-next)))
2140 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2142 (re-search-forward page-delimiter nil 'move arg)))
2143 (goto-char (match-end 0)))
2146 (if (re-search-forward page-delimiter nil 'move)
2149 (when (and (gnus-visual-p 'page-marker)
2150 (not (= (point-min) 1)))
2152 (goto-char (point-min))
2153 (gnus-insert-prev-page-button)))
2154 (when (and (gnus-visual-p 'page-marker)
2155 (< (+ (point-max) 2) (buffer-size)))
2157 (goto-char (point-max))
2158 (gnus-insert-next-page-button)))))
2160 ;; Article mode commands
2162 (defun gnus-article-goto-next-page ()
2163 "Show the next page of the article."
2165 (when (gnus-article-next-page)
2166 (goto-char (point-min))
2167 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2169 (defun gnus-article-goto-prev-page ()
2170 "Show the next page of the article."
2172 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2173 (gnus-article-prev-page nil)))
2175 (defun gnus-article-next-page (&optional lines)
2176 "Show the next page of the current article.
2177 If end of article, return non-nil. Otherwise return nil.
2178 Argument LINES specifies lines to be scrolled up."
2180 (move-to-window-line -1)
2183 (and (pos-visible-in-window-p) ;Not continuation line.
2185 ;; Nothing in this page.
2186 (if (or (not gnus-page-broken)
2189 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2191 (gnus-narrow-to-page 1) ;Go to next page.
2193 ;; More in this page.
2194 (let ((scroll-in-place nil))
2198 ;; Long lines may cause an end-of-buffer error.
2199 (goto-char (point-max)))))
2200 (move-to-window-line 0)
2203 (defun gnus-article-prev-page (&optional lines)
2204 "Show previous page of current article.
2205 Argument LINES specifies lines to be scrolled down."
2207 (move-to-window-line 0)
2208 (if (and gnus-page-broken
2210 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2212 (gnus-narrow-to-page -1) ;Go to previous page.
2213 (goto-char (point-max))
2215 (let ((scroll-in-place nil))
2219 (beginning-of-buffer
2220 (goto-char (point-min))))
2221 (move-to-window-line 0)))))
2223 (defun gnus-article-refer-article ()
2224 "Read article specified by message-id around point."
2226 (let ((point (point)))
2227 (search-forward ">" nil t) ;Move point to end of "<....>".
2228 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2229 (let ((message-id (match-string 1)))
2231 (set-buffer gnus-summary-buffer)
2232 (gnus-summary-refer-article message-id))
2234 (error "No references around point"))))
2236 (defun gnus-article-show-summary ()
2237 "Reconfigure windows to show summary buffer."
2239 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2240 (error "There is no summary buffer for this article buffer")
2241 (gnus-article-set-globals)
2242 (gnus-configure-windows 'article)
2243 (gnus-summary-goto-subject gnus-current-article)))
2245 (defun gnus-article-describe-briefly ()
2246 "Describe article mode commands briefly."
2249 (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")))
2251 (defun gnus-article-summary-command ()
2252 "Execute the last keystroke in the summary buffer."
2254 (let ((obuf (current-buffer))
2255 (owin (current-window-configuration))
2257 (switch-to-buffer gnus-summary-buffer 'norecord)
2258 (setq func (lookup-key (current-local-map) (this-command-keys)))
2259 (call-interactively func)
2261 (set-window-configuration owin)
2262 (set-window-point (get-buffer-window (current-buffer)) (point))))
2264 (defun gnus-article-summary-command-nosave ()
2265 "Execute the last keystroke in the summary buffer."
2268 (pop-to-buffer gnus-summary-buffer 'norecord)
2269 (setq func (lookup-key (current-local-map) (this-command-keys)))
2270 (call-interactively func)))
2272 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2273 "Read a summary buffer key sequence and execute it from the article buffer."
2276 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2277 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2278 "=" "^" "\M-^" "|"))
2285 (set-buffer gnus-summary-buffer)
2286 (let (gnus-pick-mode)
2287 (push (or key last-command-event) unread-command-events)
2288 (setq keys (read-key-sequence nil))))
2291 (if (or (member keys nosaves)
2292 (member keys nosave-but-article)
2293 (member keys nosave-in-article))
2295 (save-window-excursion
2296 (pop-to-buffer gnus-summary-buffer 'norecord)
2297 ;; We disable the pick minor mode commands.
2298 (let (gnus-pick-mode)
2299 (setq func (lookup-key (current-local-map) keys))))
2302 (unless (member keys nosave-in-article)
2303 (set-buffer gnus-summary-buffer))
2304 (call-interactively func))
2305 (when (member keys nosave-but-article)
2306 (pop-to-buffer gnus-article-buffer 'norecord)))
2307 ;; These commands should restore window configuration.
2308 (let ((obuf (current-buffer))
2309 (owin (current-window-configuration))
2312 (if not-restore-window
2313 (pop-to-buffer gnus-summary-buffer 'norecord)
2314 (switch-to-buffer gnus-summary-buffer 'norecord))
2315 (setq in-buffer (current-buffer))
2316 ;; We disable the pick minor mode commands.
2317 (if (setq func (let (gnus-pick-mode)
2318 (lookup-key (current-local-map) keys)))
2319 (call-interactively func)
2321 (when (eq in-buffer (current-buffer))
2323 (unless not-restore-window
2324 (set-window-configuration owin))
2325 (set-window-point (get-buffer-window (current-buffer)) opoint))))))
2327 (defun gnus-article-hide (&optional arg force)
2328 "Hide all the gruft in the current article.
2329 This means that PGP stuff, signatures, cited text and (some)
2330 headers will be hidden.
2331 If given a prefix, show the hidden text instead."
2332 (interactive (list current-prefix-arg 'force))
2333 (gnus-article-hide-headers arg)
2334 (gnus-article-hide-pgp arg)
2335 (gnus-article-hide-citation-maybe arg force)
2336 (gnus-article-hide-signature arg))
2338 (defun gnus-article-maybe-highlight ()
2339 "Do some article highlighting if `article-visual' is non-nil."
2340 (when (gnus-visual-p 'article-highlight 'highlight)
2341 (gnus-article-highlight-some)))
2343 (defun gnus-request-article-this-buffer (article group)
2344 "Get an article and insert it into this buffer."
2345 (let (do-update-line)
2349 (gnus-kill-all-overlays)
2350 (setq group (or group gnus-newsgroup-name))
2352 ;; Open server if it has closed.
2353 (gnus-check-server (gnus-find-method-for-group group))
2355 ;; Using `gnus-request-article' directly will insert the article into
2356 ;; `nntp-server-buffer' - so we'll save some time by not having to
2357 ;; copy it from the server buffer into the article buffer.
2359 ;; We only request an article by message-id when we do not have the
2360 ;; headers for it, so we'll have to get those.
2361 (when (stringp article)
2362 (let ((gnus-override-method gnus-refer-article-method))
2363 (gnus-read-header article)))
2365 ;; If the article number is negative, that means that this article
2366 ;; doesn't belong in this newsgroup (possibly), so we find its
2367 ;; message-id and request it by id instead of number.
2368 (when (and (numberp article)
2370 (get-buffer gnus-summary-buffer)
2371 (buffer-name (get-buffer gnus-summary-buffer)))
2373 (set-buffer gnus-summary-buffer)
2374 (let ((header (gnus-summary-article-header article)))
2377 ((memq article gnus-newsgroup-sparse)
2378 ;; This is a sparse gap article.
2379 (setq do-update-line article)
2380 (setq article (mail-header-id header))
2381 (let ((gnus-override-method gnus-refer-article-method))
2382 (gnus-read-header article))
2383 (setq gnus-newsgroup-sparse
2384 (delq article gnus-newsgroup-sparse)))
2386 ;; It's a real article.
2387 (setq article (mail-header-id header)))
2389 ;; It is an extracted pseudo-article.
2390 (setq article 'pseudo)
2391 (gnus-request-pseudo-article header))))
2393 (let ((method (gnus-find-method-for-group
2394 gnus-newsgroup-name)))
2395 (if (not (eq (car method) 'nneething))
2397 (let ((dir (concat (file-name-as-directory (nth 1 method))
2398 (mail-header-subject header))))
2399 (when (file-directory-p dir)
2400 (setq article 'nneething)
2401 (gnus-group-enter-directory dir))))))))
2404 ;; Refuse to select canceled articles.
2405 ((and (numberp article)
2407 (get-buffer gnus-summary-buffer)
2408 (buffer-name (get-buffer gnus-summary-buffer))
2409 (eq (cdr (save-excursion
2410 (set-buffer gnus-summary-buffer)
2411 (assq article gnus-newsgroup-reads)))
2412 gnus-canceled-mark))
2414 ;; We first check `gnus-original-article-buffer'.
2415 ((and (get-buffer gnus-original-article-buffer)
2418 (set-buffer gnus-original-article-buffer)
2419 (and (equal (car gnus-original-article) group)
2420 (eq (cdr gnus-original-article) article))))
2421 (insert-buffer-substring gnus-original-article-buffer)
2423 ;; Check the backlog.
2424 ((and gnus-keep-backlog
2425 (gnus-backlog-request-article group article (current-buffer)))
2427 ;; Check asynchronous pre-fetch.
2428 ((gnus-async-request-fetched-article group article (current-buffer))
2429 (gnus-async-prefetch-next group article gnus-summary-buffer)
2432 ((and gnus-use-cache
2434 (gnus-cache-request-article article group))
2436 ;; Get the article and put into the article buffer.
2437 ((or (stringp article) (numberp article))
2438 (let ((gnus-override-method
2439 (and (stringp article) gnus-refer-article-method))
2440 (buffer-read-only nil))
2442 (gnus-kill-all-overlays)
2443 (when (gnus-request-article article group (current-buffer))
2444 (when (numberp article)
2445 (gnus-async-prefetch-next group article gnus-summary-buffer)
2446 (when gnus-keep-backlog
2447 (gnus-backlog-enter-article
2448 group article (current-buffer))))
2453 ;; Take the article from the original article buffer
2454 ;; and place it in the buffer it's supposed to be in.
2455 (when (and (get-buffer gnus-article-buffer)
2457 (equal (buffer-name (current-buffer))
2458 (buffer-name (get-buffer gnus-article-buffer))))
2460 (if (get-buffer gnus-original-article-buffer)
2461 (set-buffer (get-buffer gnus-original-article-buffer))
2462 (set-buffer (get-buffer-create gnus-original-article-buffer))
2463 (buffer-disable-undo (current-buffer))
2464 (setq major-mode 'gnus-original-article-mode)
2465 (setq buffer-read-only t)
2466 (gnus-add-current-to-buffer-list))
2467 (let (buffer-read-only)
2469 (insert-buffer-substring gnus-article-buffer))
2470 (setq gnus-original-article (cons group article))))
2472 ;; Update sparse articles.
2473 (when (and do-update-line
2474 (or (numberp article)
2476 (let ((buf (current-buffer)))
2477 (set-buffer gnus-summary-buffer)
2478 (gnus-summary-update-article do-update-line)
2479 (gnus-summary-goto-subject do-update-line nil t)
2480 (set-window-point (get-buffer-window (current-buffer) t)
2482 (set-buffer buf))))))
2488 (defcustom gnus-article-edit-mode-hook nil
2489 "Hook run in article edit mode buffers."
2490 :group 'gnus-article-various
2493 (defvar gnus-article-edit-done-function nil)
2495 (defvar gnus-article-edit-mode-map nil)
2497 (unless gnus-article-edit-mode-map
2498 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2500 (gnus-define-keys gnus-article-edit-mode-map
2501 "\C-c\C-c" gnus-article-edit-done
2502 "\C-c\C-k" gnus-article-edit-exit)
2504 (gnus-define-keys (gnus-article-edit-wash-map
2505 "\C-c\C-w" gnus-article-edit-mode-map)
2506 "f" gnus-article-edit-full-stops))
2508 (defun gnus-article-edit-mode ()
2509 "Major mode for editing articles.
2510 This is an extended text-mode.
2512 \\{gnus-article-edit-mode-map}"
2514 (kill-all-local-variables)
2515 (setq major-mode 'gnus-article-edit-mode)
2516 (setq mode-name "Article Edit")
2517 (use-local-map gnus-article-edit-mode-map)
2518 (make-local-variable 'gnus-article-edit-done-function)
2519 (make-local-variable 'gnus-prev-winconf)
2520 (setq buffer-read-only nil)
2521 (buffer-enable-undo)
2523 (run-hooks 'text-mode 'gnus-article-edit-mode-hook))
2525 (defun gnus-article-edit (&optional force)
2526 "Edit the current article.
2527 This will have permanent effect only in mail groups.
2528 If FORCE is non-nil, allow editing of articles even in read-only
2531 (when (and (not force)
2532 (gnus-group-read-only-p))
2533 (error "The current newsgroup does not support article editing"))
2534 (gnus-article-edit-article
2535 `(lambda (no-highlight)
2536 (gnus-summary-edit-article-done
2537 ,(or (mail-header-references gnus-current-headers) "")
2538 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2540 (defun gnus-article-edit-article (exit-func)
2541 "Start editing the contents of the current article buffer."
2542 (let ((winconf (current-window-configuration)))
2543 (set-buffer gnus-article-buffer)
2544 (gnus-article-edit-mode)
2545 (gnus-set-text-properties (point-min) (point-max) nil)
2546 (gnus-configure-windows 'edit-article)
2547 (setq gnus-article-edit-done-function exit-func)
2548 (setq gnus-prev-winconf winconf)
2549 (gnus-message 6 "C-c C-c to end edits")))
2551 (defun gnus-article-edit-done (&optional arg)
2552 "Update the article edits and exit."
2557 (goto-char (point-min))
2558 (when (search-forward "\n\n" nil 1)
2559 (let ((lines (count-lines (point) (point-max)))
2560 (length (- (point-max) (point)))
2561 (case-fold-search t)
2562 (body (copy-marker (point))))
2563 (goto-char (point-min))
2564 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2565 (delete-region (match-beginning 1) (match-end 1))
2566 (insert (number-to-string length)))
2567 (goto-char (point-min))
2568 (when (re-search-forward
2569 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2570 (delete-region (match-beginning 1) (match-end 1))
2571 (insert (number-to-string length)))
2572 (goto-char (point-min))
2573 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2574 (delete-region (match-beginning 1) (match-end 1))
2575 (insert (number-to-string lines)))))))
2576 (let ((func gnus-article-edit-done-function)
2577 (buf (current-buffer))
2578 (start (window-start)))
2579 (gnus-article-edit-exit)
2582 (let ((buffer-read-only nil))
2583 (funcall func arg)))
2585 (set-window-start (get-buffer-window buf) start)
2586 (set-window-point (get-buffer-window buf) (point))))
2588 (defun gnus-article-edit-exit ()
2589 "Exit the article editing without updating."
2591 ;; We remove all text props from the article buffer.
2592 (let ((buf (format "%s" (buffer-string)))
2593 (curbuf (current-buffer))
2595 (window-start (window-start)))
2598 (let ((winconf gnus-prev-winconf))
2600 ;; The cache and backlog have to be flushed somewhat.
2601 (when gnus-use-cache
2602 (gnus-cache-update-article
2603 (car gnus-article-current) (cdr gnus-article-current)))
2604 (when gnus-keep-backlog
2605 (gnus-backlog-remove-article
2606 (car gnus-article-current) (cdr gnus-article-current)))
2607 ;; Flush original article as well.
2609 (when (get-buffer gnus-original-article-buffer)
2610 (set-buffer gnus-original-article-buffer)
2611 (setq gnus-original-article nil)))
2612 (set-window-configuration winconf)
2613 ;; Tippy-toe some to make sure that point remains where it was.
2614 (let ((buf (current-buffer)))
2616 (set-window-start (get-buffer-window (current-buffer)) window-start)
2618 (set-buffer buf)))))
2620 (defun gnus-article-edit-full-stops ()
2621 "Interactively repair spacing at end of sentences."
2624 (goto-char (point-min))
2625 (search-forward-regexp "^$" nil t)
2626 (let ((case-fold-search nil))
2627 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2630 ;;; Article highlights
2633 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2635 ;;; Internal Variables:
2637 (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\\)"
2638 "Regular expression that matches URLs."
2639 :group 'gnus-article-buttons
2642 (defcustom gnus-button-alist
2643 `(("<\\(url: ?\\)?news:\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2644 gnus-button-message-id 2)
2645 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2646 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t
2647 gnus-button-fetch-group 4)
2648 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2649 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2650 t gnus-button-message-id 3)
2651 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2652 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2653 ;; This is how URLs _should_ be embedded in text...
2654 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2656 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2657 "Alist of regexps matching buttons in article bodies.
2659 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2660 REGEXP: is the string matching text around the button,
2661 BUTTON: is the number of the regexp grouping actually matching the button,
2662 FORM: is a lisp expression which must eval to true for the button to
2664 CALLBACK: is the function to call when the user push this button, and each
2665 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2667 CALLBACK can also be a variable, in that case the value of that
2668 variable it the real callback function."
2669 :group 'gnus-article-buttons
2670 :type '(repeat (list regexp
2671 (integer :tag "Button")
2673 (function :tag "Callback")
2676 (integer :tag "Regexp group")))))
2678 (defcustom gnus-header-button-alist
2679 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2680 0 t gnus-button-message-id 0)
2681 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2682 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2683 0 t gnus-button-mailto 0)
2684 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2685 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2686 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2687 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2688 gnus-button-message-id 3))
2689 "Alist of headers and regexps to match buttons in article heads.
2691 This alist is very similar to `gnus-button-alist', except that each
2692 alist has an additional HEADER element first in each entry:
2694 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2696 HEADER is a regexp to match a header. For a fuller explanation, see
2697 `gnus-button-alist'."
2698 :group 'gnus-article-buttons
2699 :group 'gnus-article-headers
2700 :type '(repeat (list (regexp :tag "Header")
2702 (integer :tag "Button")
2704 (function :tag "Callback")
2707 (integer :tag "Regexp group")))))
2709 (defvar gnus-button-regexp nil)
2710 (defvar gnus-button-marker-list nil)
2711 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2713 (defvar gnus-button-last nil)
2714 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2718 (defun gnus-article-push-button (event)
2719 "Check text under the mouse pointer for a callback function.
2720 If the text under the mouse pointer has a `gnus-callback' property,
2721 call it with the value of the `gnus-data' text property."
2723 (set-buffer (window-buffer (posn-window (event-start event))))
2724 (let* ((pos (posn-point (event-start event)))
2725 (data (get-text-property pos 'gnus-data))
2726 (fun (get-text-property pos 'gnus-callback)))
2728 (funcall fun data))))
2730 (defun gnus-article-press-button ()
2731 "Check text at point for a callback function.
2732 If the text at point has a `gnus-callback' property,
2733 call it with the value of the `gnus-data' text property."
2735 (let* ((data (get-text-property (point) 'gnus-data))
2736 (fun (get-text-property (point) 'gnus-callback)))
2738 (funcall fun data))))
2740 (defun gnus-article-prev-button (n)
2741 "Move point to N buttons backward.
2742 If N is negative, move forward instead."
2744 (gnus-article-next-button (- n)))
2746 (defun gnus-article-next-button (n)
2747 "Move point to N buttons forward.
2748 If N is negative, move backward instead."
2750 (let ((function (if (< n 0) 'previous-single-property-change
2751 'next-single-property-change))
2752 (inhibit-point-motion-hooks t)
2754 (limit (if (< n 0) (point-min) (point-max))))
2756 (while (and (not (= limit (point)))
2758 ;; Skip past the current button.
2759 (when (get-text-property (point) 'gnus-callback)
2760 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2761 ;; Go to the next (or previous) button.
2762 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2763 ;; Put point at the start of the button.
2764 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2765 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2766 ;; Skip past intangible buttons.
2767 (when (get-text-property (point) 'intangible)
2771 (gnus-message 5 "No more buttons"))
2774 (defun gnus-article-highlight (&optional force)
2775 "Highlight current article.
2776 This function calls `gnus-article-highlight-headers',
2777 `gnus-article-highlight-citation',
2778 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2779 do the highlighting. See the documentation for those functions."
2780 (interactive (list 'force))
2781 (gnus-article-highlight-headers)
2782 (gnus-article-highlight-citation force)
2783 (gnus-article-highlight-signature)
2784 (gnus-article-add-buttons force)
2785 (gnus-article-add-buttons-to-head))
2787 (defun gnus-article-highlight-some (&optional force)
2788 "Highlight current article.
2789 This function calls `gnus-article-highlight-headers',
2790 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2791 do the highlighting. See the documentation for those functions."
2792 (interactive (list 'force))
2793 (gnus-article-highlight-headers)
2794 (gnus-article-highlight-signature)
2795 (gnus-article-add-buttons))
2797 (defun gnus-article-highlight-headers ()
2798 "Highlight article headers as specified by `gnus-header-face-alist'."
2801 (set-buffer gnus-article-buffer)
2803 (let ((alist gnus-header-face-alist)
2804 (buffer-read-only nil)
2805 (case-fold-search t)
2806 (inhibit-point-motion-hooks t)
2807 entry regexp header-face field-face from hpoints fpoints)
2808 (message-narrow-to-head)
2809 (while (setq entry (pop alist))
2810 (goto-char (point-min))
2811 (setq regexp (concat "^\\("
2812 (if (string-equal "" (nth 0 entry))
2816 header-face (nth 1 entry)
2817 field-face (nth 2 entry))
2818 (while (and (re-search-forward regexp nil t)
2822 (unless (search-forward ":" nil t)
2824 (when (and header-face
2825 (not (memq (point) hpoints)))
2826 (push (point) hpoints)
2827 (gnus-put-text-property from (point) 'face header-face))
2828 (when (and field-face
2829 (not (memq (setq from (point)) fpoints)))
2831 (if (re-search-forward "^[^ \t]" nil t)
2833 (goto-char (point-max)))
2834 (gnus-put-text-property from (point) 'face field-face))))))))
2836 (defun gnus-article-highlight-signature ()
2837 "Highlight the signature in an article.
2838 It does this by highlighting everything after
2839 `gnus-signature-separator' using `gnus-signature-face'."
2842 (set-buffer gnus-article-buffer)
2843 (let ((buffer-read-only nil)
2844 (inhibit-point-motion-hooks t))
2846 (when (and gnus-signature-face
2847 (gnus-article-narrow-to-signature))
2848 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2849 'face gnus-signature-face)
2851 (gnus-article-search-signature)
2852 (let ((start (match-beginning 0))
2853 (end (set-marker (make-marker) (1+ (match-end 0)))))
2854 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2857 (defun gnus-button-in-region-p (b e prop)
2858 "Say whether PROP exists in the region."
2859 (text-property-not-all b e prop nil))
2861 (defun gnus-article-add-buttons (&optional force)
2862 "Find external references in the article and make buttons of them.
2863 \"External references\" are things like Message-IDs and URLs, as
2864 specified by `gnus-button-alist'."
2865 (interactive (list 'force))
2867 (set-buffer gnus-article-buffer)
2868 (let ((buffer-read-only nil)
2869 (inhibit-point-motion-hooks t)
2870 (case-fold-search t)
2871 (alist gnus-button-alist)
2873 ;; Remove all old markers.
2875 (while (setq marker (pop gnus-button-marker-list))
2877 (when (setq entry (gnus-button-entry))
2878 (put-text-property (match-beginning (nth 1 entry))
2879 (match-end (nth 1 entry))
2880 'gnus-callback nil))
2881 (set-marker marker nil)))
2882 ;; We skip the headers.
2883 (goto-char (point-min))
2884 (unless (search-forward "\n\n" nil t)
2885 (goto-char (point-max)))
2887 (while (setq entry (pop alist))
2888 (setq regexp (car entry))
2890 (while (re-search-forward regexp nil t)
2891 (let* ((start (and entry (match-beginning (nth 1 entry))))
2892 (end (and entry (match-end (nth 1 entry))))
2893 (from (match-beginning 0)))
2894 (when (and (or (eq t (nth 2 entry))
2895 (eval (nth 2 entry)))
2896 (not (gnus-button-in-region-p
2897 start end 'gnus-callback)))
2898 ;; That optional form returned non-nil, so we add the
2900 (gnus-article-add-button
2901 start end 'gnus-button-push
2902 (car (push (set-marker (make-marker) from)
2903 gnus-button-marker-list))))))))))
2905 ;; Add buttons to the head of an article.
2906 (defun gnus-article-add-buttons-to-head ()
2907 "Add buttons to the head of the article."
2910 (set-buffer gnus-article-buffer)
2911 (let ((buffer-read-only nil)
2912 (inhibit-point-motion-hooks t)
2913 (case-fold-search t)
2914 (alist gnus-header-button-alist)
2916 (nnheader-narrow-to-headers)
2918 ;; Each alist entry.
2919 (setq entry (car alist)
2921 (goto-char (point-min))
2922 (while (re-search-forward (car entry) nil t)
2923 ;; Each header matching the entry.
2924 (setq beg (match-beginning 0))
2925 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2926 (match-beginning 0))
2929 (while (re-search-forward (nth 1 entry) end t)
2930 ;; Each match within a header.
2931 (let* ((entry (cdr entry))
2932 (start (match-beginning (nth 1 entry)))
2933 (end (match-end (nth 1 entry)))
2934 (form (nth 2 entry)))
2935 (goto-char (match-end 0))
2937 (gnus-article-add-button
2938 start end (nth 3 entry)
2939 (buffer-substring (match-beginning (nth 4 entry))
2940 (match-end (nth 4 entry)))))))
2944 ;;; External functions:
2946 (defun gnus-article-add-button (from to fun &optional data)
2947 "Create a button between FROM and TO with callback FUN and data DATA."
2948 (when gnus-article-button-face
2949 (gnus-overlay-put (gnus-make-overlay from to)
2950 'face gnus-article-button-face))
2951 (gnus-add-text-properties
2953 (nconc (and gnus-article-mouse-face
2954 (list gnus-mouse-face-prop gnus-article-mouse-face))
2955 (list 'gnus-callback fun)
2956 (and data (list 'gnus-data data)))))
2958 ;;; Internal functions:
2960 (defun gnus-article-set-globals ()
2962 (set-buffer gnus-summary-buffer)
2963 (gnus-set-global-variables)))
2965 (defun gnus-signature-toggle (end)
2967 (set-buffer gnus-article-buffer)
2968 (let ((buffer-read-only nil)
2969 (inhibit-point-motion-hooks t))
2970 (if (get-text-property end 'invisible)
2971 (gnus-article-unhide-text end (point-max))
2972 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
2974 (defun gnus-button-entry ()
2975 ;; Return the first entry in `gnus-button-alist' matching this place.
2976 (let ((alist gnus-button-alist)
2979 (setq entry (pop alist))
2980 (if (looking-at (car entry))
2985 (defun gnus-button-push (marker)
2986 ;; Push button starting at MARKER.
2988 (set-buffer gnus-article-buffer)
2990 (let* ((entry (gnus-button-entry))
2991 (inhibit-point-motion-hooks t)
2993 (args (mapcar (lambda (group)
2994 (let ((string (match-string group)))
2995 (gnus-set-text-properties
2996 0 (length string) nil string)
3003 (fboundp (symbol-value fun)))
3004 (apply (symbol-value fun) args))
3006 (gnus-message 1 "You must define `%S' to use this button"
3007 (cons fun args)))))))
3009 (defun gnus-button-message-id (message-id)
3012 (set-buffer gnus-summary-buffer)
3013 (gnus-summary-refer-article message-id)))
3015 (defun gnus-button-fetch-group (address)
3016 "Fetch GROUP specified by ADDRESS."
3017 (if (not (string-match "[:/]" address))
3018 ;; This is just a simple group url.
3019 (gnus-group-read-ephemeral-group address gnus-select-method)
3020 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3022 (error "Can't parse %s" address)
3023 (gnus-group-read-ephemeral-group
3024 (match-string 4 address)
3025 `(nntp ,(match-string 1 address)
3026 (nntp-address ,(match-string 1 address))
3027 (nntp-port-number ,(if (match-end 3)
3028 (match-string 3 address)
3031 (defun gnus-split-string (string pattern)
3032 "Return a list of substrings of STRING which are separated by PATTERN."
3033 (let (parts (start 0))
3034 (while (string-match pattern string start)
3035 (setq parts (cons (substring string start (match-beginning 0)) parts)
3036 start (match-end 0)))
3037 (nreverse (cons (substring string start) parts))))
3039 (defun gnus-url-parse-query-string (query &optional downcase)
3040 (let (retval pairs cur key val)
3041 (setq pairs (gnus-split-string query "&"))
3043 (setq cur (car pairs)
3045 (if (not (string-match "=" cur))
3047 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3048 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3050 (setq key (downcase key)))
3051 (setq cur (assoc key retval))
3053 (setcdr cur (cons val (cdr cur)))
3054 (setq retval (cons (list key val) retval)))))
3057 (defun gnus-url-unhex (x)
3064 (defun gnus-url-unhex-string (str &optional allow-newlines)
3065 "Remove %XXX embedded spaces, etc in a url.
3066 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3067 decoding of carriage returns and line feeds in the string, which is normally
3068 forbidden in URL encoding."
3069 (setq str (or str ""))
3071 (case-fold-search t))
3072 (while (string-match "%[0-9a-f][0-9a-f]" str)
3073 (let* ((start (match-beginning 0))
3074 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3076 (gnus-url-unhex (elt str (+ start 2))))))
3078 tmp (substring str 0 start)
3081 (char-to-string code))
3082 ((or (= code ?\n) (= code ?\r))
3084 (t (char-to-string code))))
3085 str (substring str (match-end 0)))))
3086 (setq tmp (concat tmp str))
3089 (defun gnus-url-mailto (url)
3090 ;; Send mail to someone
3091 (when (string-match "mailto:/*\\(.*\\)" url)
3092 (setq url (substring url (match-beginning 1) nil)))
3093 (let (to args source-url subject func)
3094 (if (string-match (regexp-quote "?") url)
3095 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3096 args (gnus-url-parse-query-string
3097 (substring url (match-end 0) nil) t))
3098 (setq to (gnus-url-unhex-string url)))
3099 (setq args (cons (list "to" to) args)
3100 subject (cdr-safe (assoc "subject" args)))
3103 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3106 (message-position-on-field (caar args)))
3107 (insert (mapconcat 'identity (cdar args) ", "))
3108 (setq args (cdr args)))
3111 (message-goto-subject))))
3113 (defun gnus-button-mailto (address)
3115 (set-buffer (gnus-copy-article-buffer))
3116 (message-reply address))
3118 (defun gnus-button-reply (address)
3119 ;; Reply to ADDRESS.
3120 (message-reply address))
3122 (defun gnus-button-url (address)
3124 (funcall browse-url-browser-function address))
3126 (defun gnus-button-embedded-url (address)
3128 (funcall browse-url-browser-function (gnus-strip-whitespace address)))
3130 ;;; Next/prev buttons in the article buffer.
3132 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3133 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3135 (defvar gnus-prev-page-map nil)
3136 (unless gnus-prev-page-map
3137 (setq gnus-prev-page-map (make-sparse-keymap))
3138 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3139 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3141 (defun gnus-insert-prev-page-button ()
3142 (let ((buffer-read-only nil))
3144 gnus-prev-page-line-format nil
3145 `(gnus-prev t local-map ,gnus-prev-page-map
3146 gnus-callback gnus-article-button-prev-page))))
3148 (defvar gnus-next-page-map nil)
3149 (unless gnus-next-page-map
3150 (setq gnus-next-page-map (make-keymap))
3151 (suppress-keymap gnus-prev-page-map)
3152 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3153 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3155 (defun gnus-button-next-page ()
3156 "Go to the next page."
3158 (let ((win (selected-window)))
3159 (select-window (get-buffer-window gnus-article-buffer t))
3160 (gnus-article-next-page)
3161 (select-window win)))
3163 (defun gnus-button-prev-page ()
3164 "Go to the prev page."
3166 (let ((win (selected-window)))
3167 (select-window (get-buffer-window gnus-article-buffer t))
3168 (gnus-article-prev-page)
3169 (select-window win)))
3171 (defun gnus-insert-next-page-button ()
3172 (let ((buffer-read-only nil))
3173 (gnus-eval-format gnus-next-page-line-format nil
3174 `(gnus-next t local-map ,gnus-next-page-map
3176 gnus-article-button-next-page))))
3178 (defun gnus-article-button-next-page (arg)
3179 "Go to the next page."
3181 (let ((win (selected-window)))
3182 (select-window (get-buffer-window gnus-article-buffer t))
3183 (gnus-article-next-page)
3184 (select-window win)))
3186 (defun gnus-article-button-prev-page (arg)
3187 "Go to the prev page."
3189 (let ((win (selected-window)))
3190 (select-window (get-buffer-window gnus-article-buffer t))
3191 (gnus-article-prev-page)
3192 (select-window win)))
3198 (defun gnus-content-header-filter ()
3199 "Header filter for mime-view.
3200 It is registered to variable `mime-view-content-header-filter-alist'."
3201 (goto-char (point-min))
3202 (while (re-search-forward "^[^ \t:]+:" nil t)
3203 (let ((start (match-beginning 0))
3204 (end (std11-field-end))
3207 (narrow-to-region start end)
3208 (decode-mime-charset-region start end default-mime-charset)
3209 (goto-char (point-max))
3211 (eword-decode-header)
3214 (defun mime-view-quitting-method-for-gnus ()
3215 (if (not gnus-show-mime)
3216 (mime-view-kill-buffer))
3217 (delete-other-windows)
3218 (gnus-article-show-summary)
3219 (if (or (not gnus-show-mime)
3220 (null gnus-have-all-headers))
3221 (gnus-summary-select-article nil t)
3224 (set-alist 'mime-view-content-header-filter-alist
3225 'gnus-original-article-mode
3226 (function gnus-content-header-filter))
3228 (set-alist 'mime-text-decoder-alist
3229 'gnus-original-article-mode
3230 (function mime-text-decode-buffer))
3232 (set-alist 'mime-view-quitting-method-alist
3233 'gnus-original-article-mode
3234 (function mime-view-quitting-method-for-gnus))
3236 (set-alist 'mime-view-show-summary-method
3237 'gnus-original-article-mode
3238 (function mime-view-quitting-method-for-gnus))
3248 (run-hooks 'gnus-art-load-hook)
3250 ;;; gnus-art.el ends here