1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
37 (defgroup gnus-article nil
39 :link '(custom-manual "(gnus)The Article Buffer")
42 (defgroup gnus-article-hiding nil
43 "Hiding article parts."
44 :link '(custom-manual "(gnus)Article Hiding")
47 (defgroup gnus-article-highlight nil
48 "Article highlighting."
49 :link '(custom-manual "(gnus)Article Highlighting")
53 (defgroup gnus-article-signature nil
55 :link '(custom-manual "(gnus)Article Signature")
58 (defgroup gnus-article-headers nil
60 :link '(custom-manual "(gnus)Hiding Headers")
63 (defgroup gnus-article-washing nil
64 "Special commands on articles."
65 :link '(custom-manual "(gnus)Article Washing")
68 (defgroup gnus-article-emphasis nil
69 "Fontisizing articles."
70 :link '(custom-manual "(gnus)Article Fontisizing")
73 (defgroup gnus-article-saving nil
75 :link '(custom-manual "(gnus)Saving Articles")
78 (defgroup gnus-article-mime nil
79 "Worshiping the MIME wonder."
80 :link '(custom-manual "(gnus)Using MIME")
83 (defgroup gnus-article-buttons nil
84 "Pushable buttons in the article buffer."
85 :link '(custom-manual "(gnus)Article Buttons")
88 (defgroup gnus-article-various nil
89 "Other article options."
90 :link '(custom-manual "(gnus)Misc Article")
93 (defcustom gnus-ignored-headers
94 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:"
95 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:"
96 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:"
97 "^Approved:" "^Sender:" "^Received:" "^Mail-from:")
98 "*All headers that start with this regexp will be hidden.
99 This variable can also be a list of regexps of headers to be ignored.
100 If `gnus-visible-headers' is non-nil, this variable will be ignored."
101 :type '(choice :custom-show nil
104 :group 'gnus-article-hiding)
106 (defcustom gnus-visible-headers
107 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
108 "*All headers that do not match this regexp will be hidden.
109 This variable can also be a list of regexp of headers to remain visible.
110 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
111 :type '(repeat :value-to-internal (lambda (widget value)
112 (custom-split-regexp-maybe value))
113 :match (lambda (widget value)
115 (widget-editable-list-match widget value)))
117 :group 'gnus-article-hiding)
119 (defcustom gnus-sorted-header-list
120 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
121 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
122 "*This variable is a list of regular expressions.
123 If it is non-nil, headers that match the regular expressions will
124 be placed first in the article buffer in the sequence specified by
126 :type '(repeat regexp)
127 :group 'gnus-article-hiding)
129 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
130 "Headers that are only to be displayed if they have interesting data.
131 Possible values in this list are `empty', `newsgroups', `followup-to',
132 `reply-to', `date', `long-to', and `many-to'."
133 :type '(set (const :tag "Headers with no content." empty)
134 (const :tag "Newsgroups with only one group." newsgroups)
135 (const :tag "Followup-to identical to newsgroups." followup-to)
136 (const :tag "Reply-to identical to from." reply-to)
137 (const :tag "Date less than four days old." date)
138 (const :tag "Very long To header." long-to)
139 (const :tag "Multiple To headers." many-to))
140 :group 'gnus-article-hiding)
142 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
143 "Regexp matching signature separator.
144 This can also be a list of regexps. In that case, it will be checked
145 from head to tail looking for a separator. Searches will be done from
146 the end of the buffer."
147 :type '(repeat string)
148 :group 'gnus-article-signature)
150 (defcustom gnus-signature-limit nil
151 "Provide a limit to what is considered a signature.
152 If it is a number, no signature may not be longer (in characters) than
153 that number. If it is a floating point number, no signature may be
154 longer (in lines) than that number. If it is a function, the function
155 will be called without any parameters, and if it returns nil, there is
156 no signature in the buffer. If it is a string, it will be used as a
157 regexp. If it matches, the text in question is not a signature."
158 :type '(choice (integer :value 200)
160 (function :value fun)
161 (regexp :value ".*"))
162 :group 'gnus-article-signature)
164 (defcustom gnus-hidden-properties '(invisible t intangible t)
165 "Property list to use for hiding text."
167 :group 'gnus-article-hiding)
169 (defcustom gnus-article-x-face-command
170 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
171 "*String or function to be executed to display an X-Face header.
172 If it is a string, the command will be executed in a sub-shell
173 asynchronously. The compressed face will be piped to this command."
174 :type 'string ;Leave function case to Lisp.
175 :group 'gnus-article-washing)
177 (defcustom gnus-article-x-face-too-ugly nil
178 "Regexp matching posters whose face shouldn't be shown automatically."
179 :type '(choice regexp (const nil))
180 :group 'gnus-article-washing)
182 (defcustom gnus-emphasis-alist
184 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
186 '(("_" "_" underline)
189 ("_/" "/_" underline-italic)
190 ("_\\*" "\\*_" underline-bold)
191 ("\\*/" "/\\*" bold-italic)
192 ("_\\*/" "/\\*_" underline-bold-italic))))
193 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
194 2 3 gnus-emphasis-underline)
198 (format format (car spec) (cadr spec))
199 2 3 (intern (format "gnus-emphasis-%s" (caddr spec)))))
201 "*Alist that says how to fontify certain phrases.
202 Each item looks like this:
204 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
206 The first element is a regular expression to be matched. The second
207 is a number that says what regular expression grouping used to find
208 the entire emphasized word. The third is a number that says what
209 regexp grouping should be displayed and highlighted. The fourth
210 is the face used for highlighting."
211 :type '(repeat (list :value ("" 0 0 default)
213 (integer :tag "Match group")
214 (integer :tag "Emphasize group")
216 :group 'gnus-article-emphasis)
218 (defface gnus-emphasis-bold '((t (:bold t)))
219 "Face used for displaying strong emphasized text (*word*)."
220 :group 'gnus-article-emphasis)
222 (defface gnus-emphasis-italic '((t (:italic t)))
223 "Face used for displaying italic emphasized text (/word/)."
224 :group 'gnus-article-emphasis)
226 (defface gnus-emphasis-underline '((t (:underline t)))
227 "Face used for displaying underlined emphasized text (_word_)."
228 :group 'gnus-article-emphasis)
230 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
231 "Face used for displaying underlined bold emphasized text (_*word*_)."
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
235 "Face used for displaying underlined italic emphasized text (_*word*_)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
239 "Face used for displaying bold italic emphasized text (/*word*/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline-bold-italic
243 '((t (:bold t :italic t :underline t)))
244 "Face used for displaying underlined bold italic emphasized text.
245 Esample: (_/*word*/_)."
246 :group 'gnus-article-emphasis)
248 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
249 "Format for display of Date headers in article bodies.
250 See `format-time-string' for the possible values.
252 The variable can also be function, which should return a complete Date
253 header. The function is called with one argument, the time, which can
254 be fed to `format-time-string'."
255 :type '(choice string symbol)
256 :link '(custom-manual "(gnus)Article Date")
257 :group 'gnus-article-washing)
260 (autoload 'hexl-hex-string-to-integer "hexl")
261 (autoload 'timezone-make-date-arpa-standard "timezone")
262 (autoload 'mail-extract-address-components "mail-extr"))
264 (defcustom gnus-save-all-headers t
265 "*If non-nil, don't remove any headers before saving."
266 :group 'gnus-article-saving
269 (defcustom gnus-prompt-before-saving 'always
270 "*This variable says how much prompting is to be done when saving articles.
271 If it is nil, no prompting will be done, and the articles will be
272 saved to the default files. If this variable is `always', each and
273 every article that is saved will be preceded by a prompt, even when
274 saving large batches of articles. If this variable is neither nil not
275 `always', there the user will be prompted once for a file name for
276 each invocation of the saving commands."
277 :group 'gnus-article-saving
278 :type '(choice (item always)
279 (item :tag "never" nil)
280 (sexp :tag "once" :format "%t\n" :value t)))
282 (defcustom gnus-saved-headers gnus-visible-headers
283 "Headers to keep if `gnus-save-all-headers' is nil.
284 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
285 If that variable is nil, however, all headers that match this regexp
286 will be kept while the rest will be deleted before saving."
287 :group 'gnus-article-saving
290 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
291 "A function to save articles in your favourite format.
292 The function must be interactively callable (in other words, it must
293 be an Emacs command).
295 Gnus provides the following functions:
297 * gnus-summary-save-in-rmail (Rmail format)
298 * gnus-summary-save-in-mail (Unix mail format)
299 * gnus-summary-save-in-folder (MH folder)
300 * gnus-summary-save-in-file (article format)
301 * gnus-summary-save-in-vm (use VM's folder format)
302 * gnus-summary-write-to-file (article format -- overwrite)."
303 :group 'gnus-article-saving
304 :type '(radio (function-item gnus-summary-save-in-rmail)
305 (function-item gnus-summary-save-in-mail)
306 (function-item gnus-summary-save-in-folder)
307 (function-item gnus-summary-save-in-file)
308 (function-item gnus-summary-save-in-vm)
309 (function-item gnus-summary-write-to-file)))
311 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
312 "A function generating a file name to save articles in Rmail format.
313 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
314 :group 'gnus-article-saving
317 (defcustom gnus-mail-save-name 'gnus-plain-save-name
318 "A function generating a file name to save articles in Unix mail format.
319 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
320 :group 'gnus-article-saving
323 (defcustom gnus-folder-save-name 'gnus-folder-save-name
324 "A function generating a file name to save articles in MH folder.
325 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
326 :group 'gnus-article-saving
329 (defcustom gnus-file-save-name 'gnus-numeric-save-name
330 "A function generating a file name to save articles in article format.
331 The function is called with NEWSGROUP, HEADERS, and optional
333 :group 'gnus-article-saving
336 (defcustom gnus-split-methods
337 '((gnus-article-archive-name)
338 (gnus-article-nndoc-name))
339 "*Variable used to suggest where articles are to be saved.
340 For instance, if you would like to save articles related to Gnus in
341 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
342 you could set this variable to something like:
344 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
345 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
347 This variable is an alist where the where the key is the match and the
348 value is a list of possible files to save in if the match is non-nil.
350 If the match is a string, it is used as a regexp match on the
351 article. If the match is a symbol, that symbol will be funcalled
352 from the buffer of the article to be saved with the newsgroup as the
353 parameter. If it is a list, it will be evaled in the same buffer.
355 If this form or function returns a string, this string will be used as
356 a possible file name; and if it returns a non-nil list, that list will
357 be used as possible file names."
358 :group 'gnus-article-saving
359 :type '(repeat (choice (list :value (fun) function)
360 (cons :value ("" "") regexp (repeat string))
363 (defcustom gnus-strict-mime t
364 "*If nil, MIME-decode even if there is no Mime-Version header."
365 :group 'gnus-article-mime
368 (defcustom gnus-show-mime-method 'metamail-buffer
369 "Function to process a MIME message.
370 The function is called from the article buffer."
371 :group 'gnus-article-mime
374 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
375 "*Function to decode MIME encoded words.
376 The function is called from the article buffer."
377 :group 'gnus-article-mime
380 (defcustom gnus-page-delimiter "^\^L"
381 "*Regexp describing what to use as article page delimiters.
382 The default value is \"^\^L\", which is a form linefeed at the
383 beginning of a line."
385 :group 'gnus-article-various)
387 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
388 "*The format specification for the article mode line.
389 See `gnus-summary-mode-line-format' for a closer description."
391 :group 'gnus-article-various)
393 (defcustom gnus-article-mode-hook nil
394 "*A hook for Gnus article mode."
396 :group 'gnus-article-various)
398 (defcustom gnus-article-menu-hook nil
399 "*Hook run after the creation of the article mode menu."
401 :group 'gnus-article-various)
403 (defcustom gnus-article-prepare-hook nil
404 "*A hook called after an article has been prepared in the article buffer.
405 If you want to run a special decoding program like nkf, use this hook."
407 :group 'gnus-article-various)
409 (defcustom gnus-article-hide-pgp-hook nil
410 "*A hook called after successfully hiding a PGP signature."
412 :group 'gnus-article-various)
414 (defcustom gnus-article-button-face 'bold
415 "Face used for highlighting buttons in the article buffer.
417 An article button is a piece of text that you can activate by pressing
418 `RET' or `mouse-2' above it."
420 :group 'gnus-article-buttons)
422 (defcustom gnus-article-mouse-face 'highlight
423 "Face used for mouse highlighting in the article buffer.
425 Article buttons will be displayed in this face when the cursor is
428 :group 'gnus-article-buttons)
430 (defcustom gnus-signature-face 'gnus-signature-face
431 "Face used for highlighting a signature in the article buffer.
432 Obsolete; use the face `gnus-signature-face' for customizations instead."
434 :group 'gnus-article-highlight
435 :group 'gnus-article-signature)
437 (defface gnus-signature-face
440 "Face used for highlighting a signature in the article buffer."
441 :group 'gnus-article-highlight
442 :group 'gnus-article-signature)
444 (defface gnus-header-from-face
447 (:foreground "spring green" :bold t))
450 (:foreground "red3" :bold t))
452 (:bold t :italic t)))
453 "Face used for displaying from headers."
454 :group 'gnus-article-headers
455 :group 'gnus-article-highlight)
457 (defface gnus-header-subject-face
460 (:foreground "SeaGreen3" :bold t))
463 (:foreground "red4" :bold t))
465 (:bold t :italic t)))
466 "Face used for displaying subject headers."
467 :group 'gnus-article-headers
468 :group 'gnus-article-highlight)
470 (defface gnus-header-newsgroups-face
473 (:foreground "yellow" :bold t :italic t))
476 (:foreground "MidnightBlue" :bold t :italic t))
478 (:bold t :italic t)))
479 "Face used for displaying newsgroups headers."
480 :group 'gnus-article-headers
481 :group 'gnus-article-highlight)
483 (defface gnus-header-name-face
486 (:foreground "SeaGreen"))
489 (:foreground "maroon"))
492 "Face used for displaying header names."
493 :group 'gnus-article-headers
494 :group 'gnus-article-highlight)
496 (defface gnus-header-content-face
499 (:foreground "forest green" :italic t))
502 (:foreground "indianred4" :italic t))
504 (:italic t))) "Face used for displaying header content."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight)
508 (defcustom gnus-header-face-alist
509 '(("From" nil gnus-header-from-face)
510 ("Subject" nil gnus-header-subject-face)
511 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
512 ("" gnus-header-name-face gnus-header-content-face))
513 "*Controls highlighting of article header.
515 An alist of the form (HEADER NAME CONTENT).
517 HEADER is a regular expression which should match the name of an
518 header header and NAME and CONTENT are either face names or nil.
520 The name of each header field will be displayed using the face
521 specified by the first element in the list where HEADER match the
522 header name and NAME is non-nil. Similarly, the content will be
523 displayed by the first non-nil matching CONTENT face."
524 :group 'gnus-article-headers
525 :group 'gnus-article-highlight
526 :type '(repeat (list (regexp :tag "Header")
528 (item :tag "skip" nil)
529 (face :value default))
530 (choice :tag "Content"
531 (item :tag "skip" nil)
532 (face :value default)))))
534 ;;; Internal variables
536 (defvar article-lapsed-timer nil)
537 (defvar gnus-article-current-summary nil)
539 (defvar gnus-article-mode-syntax-table
540 (let ((table (copy-syntax-table text-mode-syntax-table)))
541 (modify-syntax-entry ?- "w" table)
542 (modify-syntax-entry ?> ")" table)
543 (modify-syntax-entry ?< "(" table)
545 "Syntax table used in article mode buffers.
546 Initialized from `text-mode-syntax-table.")
548 (defvar gnus-save-article-buffer nil)
550 (defvar gnus-article-mode-line-format-alist
551 (nconc '((?w (gnus-article-wash-status) ?s))
552 gnus-summary-mode-line-format-alist))
554 (defvar gnus-number-of-articles-to-be-saved nil)
556 (defvar gnus-inhibit-hiding nil)
558 (defsubst gnus-article-hide-text (b e props)
559 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
560 (add-text-properties b e props)
561 (when (memq 'intangible props)
563 (max (1- b) (point-min))
564 b 'intangible (cddr (memq 'intangible props)))))
566 (defsubst gnus-article-unhide-text (b e)
567 "Remove hidden text properties from region between B and E."
568 (remove-text-properties b e gnus-hidden-properties)
569 (when (memq 'intangible gnus-hidden-properties)
570 (put-text-property (max (1- b) (point-min))
573 (defun gnus-article-hide-text-type (b e type)
574 "Hide text of TYPE between B and E."
575 (gnus-article-hide-text
576 b e (cons 'article-type (cons type gnus-hidden-properties))))
578 (defun gnus-article-unhide-text-type (b e type)
579 "Hide text of TYPE between B and E."
580 (remove-text-properties
581 b e (cons 'article-type (cons type gnus-hidden-properties)))
582 (when (memq 'intangible gnus-hidden-properties)
583 (put-text-property (max (1- b) (point-min))
586 (defun gnus-article-hide-text-of-type (type)
587 "Hide text of TYPE in the current buffer."
589 (let ((b (point-min))
591 (while (setq b (text-property-any b e 'article-type type))
592 (add-text-properties b (incf b) gnus-hidden-properties)))))
594 (defun gnus-article-delete-text-of-type (type)
595 "Delete text of TYPE in the current buffer."
597 (let ((b (point-min)))
598 (while (setq b (text-property-any b (point-max) 'article-type type))
600 b (or (text-property-not-all b (point-max) 'article-type type)
603 (defun gnus-article-delete-invisible-text ()
604 "Delete all invisible text in the current buffer."
606 (let ((b (point-min)))
607 (while (setq b (text-property-any b (point-max) 'invisible t))
609 b (or (text-property-not-all b (point-max) 'invisible t)
612 (defun gnus-article-text-type-exists-p (type)
613 "Say whether any text of type TYPE exists in the buffer."
614 (text-property-any (point-min) (point-max) 'article-type type))
616 (defsubst gnus-article-header-rank ()
617 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
618 (let ((list gnus-sorted-header-list)
621 (when (looking-at (car list))
623 (setq list (cdr list))
627 (defun article-hide-headers (&optional arg delete)
628 "Toggle whether to hide unwanted headers and possibly sort them as well.
629 If given a negative prefix, always show; if given a positive prefix,
631 (interactive (gnus-article-hidden-arg))
633 (if (gnus-article-check-hidden-text 'headers arg)
634 ;; Show boring headers as well.
635 (gnus-article-show-hidden-text 'boring-headers)
636 ;; This function might be inhibited.
637 (unless gnus-inhibit-hiding
640 (let ((buffer-read-only nil)
641 (props (nconc (list 'article-type 'headers)
642 gnus-hidden-properties))
643 (max (1+ (length gnus-sorted-header-list)))
644 (ignored (when (not gnus-visible-headers)
645 (cond ((stringp gnus-ignored-headers)
646 gnus-ignored-headers)
647 ((listp gnus-ignored-headers)
648 (mapconcat 'identity gnus-ignored-headers
651 (cond ((stringp gnus-visible-headers)
652 gnus-visible-headers)
653 ((and gnus-visible-headers
654 (listp gnus-visible-headers))
655 (mapconcat 'identity gnus-visible-headers "\\|"))))
656 (inhibit-point-motion-hooks t)
658 ;; First we narrow to just the headers.
660 (goto-char (point-min))
661 ;; Hide any "From " lines at the beginning of (mail) articles.
662 (while (looking-at "From ")
666 (delete-region (point-min) (point))
667 (gnus-article-hide-text (point-min) (point) props)))
668 ;; Then treat the rest of the header lines.
671 (if (search-forward "\n\n" nil t) ; if there's a body
672 (progn (forward-line -1) (point))
674 ;; Then we use the two regular expressions
675 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
676 ;; select which header lines is to remain visible in the
678 (goto-char (point-min))
679 (while (re-search-forward "^[^ \t]*:" nil t)
681 ;; Mark the rank of the header.
683 (point) (1+ (point)) 'message-rank
684 (if (or (and visible (looking-at visible))
686 (not (looking-at ignored))))
687 (gnus-article-header-rank)
690 (message-sort-headers-1)
691 (when (setq beg (text-property-any
692 (point-min) (point-max) 'message-rank (+ 2 max)))
693 ;; We make the unwanted headers invisible.
695 (delete-region beg (point-max))
696 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
697 (gnus-article-hide-text-type beg (point-max) 'headers))
698 ;; Work around XEmacs lossage.
699 (put-text-property (point-min) beg 'invisible nil))))))))
701 (defun article-hide-boring-headers (&optional arg)
702 "Toggle hiding of headers that aren't very interesting.
703 If given a negative prefix, always show; if given a positive prefix,
705 (interactive (gnus-article-hidden-arg))
706 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
707 (not gnus-show-all-headers))
710 (let ((buffer-read-only nil)
711 (list gnus-boring-article-headers)
712 (inhibit-point-motion-hooks t)
714 (nnheader-narrow-to-headers)
716 (setq elem (pop list))
717 (goto-char (point-min))
719 ;; Hide empty headers.
721 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
723 (gnus-article-hide-text-type
724 (progn (beginning-of-line) (point))
727 (if (re-search-forward "^[^ \t]" nil t)
731 ;; Hide boring Newsgroups header.
732 ((eq elem 'newsgroups)
733 (when (equal (gnus-fetch-field "newsgroups")
734 (gnus-group-real-name
735 (if (boundp 'gnus-newsgroup-name)
738 (gnus-article-hide-header "newsgroups")))
739 ((eq elem 'followup-to)
740 (when (equal (message-fetch-field "followup-to")
741 (message-fetch-field "newsgroups"))
742 (gnus-article-hide-header "followup-to")))
744 (let ((from (message-fetch-field "from"))
745 (reply-to (message-fetch-field "reply-to")))
750 (nth 1 (mail-extract-address-components from))
751 (nth 1 (mail-extract-address-components reply-to)))))
752 (gnus-article-hide-header "reply-to"))))
754 (let ((date (message-fetch-field "date")))
756 (< (gnus-days-between (current-time-string) date)
758 (gnus-article-hide-header "date"))))
760 (let ((to (message-fetch-field "to")))
761 (when (> (length to) 1024)
762 (gnus-article-hide-header "to"))))
765 (goto-char (point-min))
766 (while (re-search-forward "^to:" nil t)
767 (setq to-count (1+ to-count)))
769 (while (> to-count 0)
770 (goto-char (point-min))
772 (re-search-forward "^to:" nil nil to-count)
774 (narrow-to-region (point) (point-max))
775 (gnus-article-hide-header "to"))
776 (setq to-count (1- to-count)))))))))))))
778 (defun gnus-article-hide-header (header)
780 (goto-char (point-min))
781 (when (re-search-forward (concat "^" header ":") nil t)
782 (gnus-article-hide-text-type
783 (progn (beginning-of-line) (point))
786 (if (re-search-forward "^[^ \t]" nil t)
791 (defun article-treat-dumbquotes ()
792 "Translate M******** sm*rtq**t*s into proper text."
794 (article-translate-characters "\221\222\223\223" "`'\"\""))
796 (defun article-translate-characters (from to)
797 "Translate all characters in the body of the article according to FROM and TO.
798 FROM is a string of characters to translate from; to is a string of
799 characters to translate to."
801 (goto-char (point-min))
802 (when (search-forward "\n\n" nil t)
803 (let ((buffer-read-only nil)
804 (x (make-string 225 ?x))
806 (while (< (incf i) (length x))
809 (while (< i (length from))
810 (aset x (aref from i) (aref to i))
812 (translate-region (point) (point-max) x)))))
814 (defun article-treat-overstrike ()
815 "Translate overstrikes into bold text."
818 (goto-char (point-min))
819 (when (search-forward "\n\n" nil t)
820 (let ((buffer-read-only nil))
821 (while (search-forward "\b" nil t)
822 (let ((next (following-char))
823 (previous (char-after (- (point) 2))))
824 ;; We do the boldification/underlining by hiding the
825 ;; overstrikes and putting the proper text property
829 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
830 (put-text-property (point) (1+ (point)) 'face 'bold))
832 (gnus-article-hide-text-type
833 (1- (point)) (1+ (point)) 'overstrike)
835 (- (point) 2) (1- (point)) 'face 'underline))
837 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
839 (point) (1+ (point)) 'face 'underline)))))))))
841 (defun article-fill ()
842 "Format too long lines."
845 (let ((buffer-read-only nil))
847 (goto-char (point-min))
848 (search-forward "\n\n" nil t)
850 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
851 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
852 (adaptive-fill-mode t))
854 (and (>= (current-column) (min fill-column (window-width)))
855 (/= (preceding-char) ?:)
856 (fill-paragraph nil))
859 (defun article-remove-cr ()
860 "Remove carriage returns from an article."
863 (let ((buffer-read-only nil))
864 (goto-char (point-min))
865 (while (search-forward "\r" nil t)
866 (replace-match "" t t)))))
868 (defun article-remove-trailing-blank-lines ()
869 "Remove all trailing blank lines from the article."
872 (let ((buffer-read-only nil))
873 (goto-char (point-max))
877 (while (and (not (bobp))
878 (looking-at "^[ \t]*$"))
883 (defun article-display-x-face (&optional force)
884 "Look for an X-Face header and display it if present."
885 (interactive (list 'force))
887 ;; Delete the old process, if any.
888 (when (process-status "article-x-face")
889 (delete-process "article-x-face"))
890 (let ((inhibit-point-motion-hooks t)
894 (nnheader-narrow-to-headers)
895 (setq from (message-fetch-field "from"))
896 (goto-char (point-min))
897 (while (and gnus-article-x-face-command
899 ;; Check whether this face is censored.
900 (not gnus-article-x-face-too-ugly)
901 (and gnus-article-x-face-too-ugly from
902 (not (string-match gnus-article-x-face-too-ugly
904 ;; Has to be present.
905 (re-search-forward "^X-Face: " nil t))
906 ;; We now have the area of the buffer where the X-Face is stored.
909 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
910 ;; We display the face.
911 (if (symbolp gnus-article-x-face-command)
912 ;; The command is a lisp function, so we call it.
913 (if (gnus-functionp gnus-article-x-face-command)
914 (funcall gnus-article-x-face-command beg end)
915 (error "%s is not a function" gnus-article-x-face-command))
916 ;; The command is a string, so we interpret the command
917 ;; as a, well, command, and fork it off.
918 (let ((process-connection-type nil))
919 (process-kill-without-query
921 "article-x-face" nil shell-file-name shell-command-switch
922 gnus-article-x-face-command))
923 (process-send-region "article-x-face" beg end)
924 (process-send-eof "article-x-face"))))))))))
926 (defun gnus-hack-decode-rfc1522 ()
927 "Emergency hack function for avoiding problems when decoding."
928 (let ((buffer-read-only nil))
929 (goto-char (point-min))
930 ;; Remove encoded TABs.
931 (while (search-forward "=09" nil t)
932 (replace-match " " t t))
933 ;; Remove encoded newlines.
934 (goto-char (point-min))
935 (while (search-forward "=10" nil t)
936 (replace-match " " t t))))
938 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
939 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
940 (defun article-decode-rfc1522 ()
941 "Hack to remove QP encoding from headers."
942 (let ((case-fold-search t)
943 (inhibit-point-motion-hooks t)
944 (buffer-read-only nil)
948 (goto-char (point-min))
949 (or (search-forward "\n\n" nil t) (point-max)))
950 (goto-char (point-min))
951 (while (re-search-forward
952 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
953 (setq string (match-string 1))
955 (narrow-to-region (match-beginning 0) (match-end 0))
956 (delete-region (point-min) (point-max))
958 (article-mime-decode-quoted-printable
959 (goto-char (point-min)) (point-max))
960 (subst-char-in-region (point-min) (point-max) ?_ ? )
961 (goto-char (point-max)))
962 (goto-char (point-min))))))
964 (defun article-de-quoted-unreadable (&optional force)
965 "Do a naive translation of a quoted-printable-encoded article.
966 This is in no way, shape or form meant as a replacement for real MIME
967 processing, but is simply a stop-gap measure until MIME support is
969 If FORCE, decode the article whether it is marked as quoted-printable
971 (interactive (list 'force))
973 (let ((case-fold-search t)
974 (buffer-read-only nil)
975 (type (gnus-fetch-field "content-transfer-encoding")))
976 (gnus-article-decode-rfc1522)
978 (and type (string-match "quoted-printable" (downcase type))))
979 (goto-char (point-min))
980 (search-forward "\n\n" nil 'move)
981 (article-mime-decode-quoted-printable (point) (point-max))))))
983 (defun article-mime-decode-quoted-printable-buffer ()
984 "Decode Quoted-Printable in the current buffer."
985 (article-mime-decode-quoted-printable (point-min) (point-max)))
987 (defun article-mime-decode-quoted-printable (from to)
988 "Decode Quoted-Printable in the region between FROM and TO."
991 (while (search-forward "=" to t)
992 (cond ((eq (following-char) ?\n)
995 ((looking-at "[0-9A-F][0-9A-F]")
996 (subst-char-in-region
997 (1- (point)) (point) ?=
998 (hexl-hex-string-to-integer
999 (buffer-substring (point) (+ 2 (point)))))
1003 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
1005 (defun article-hide-pgp (&optional arg)
1006 "Toggle hiding of any PGP headers and signatures in the current article.
1007 If given a negative prefix, always show; if given a positive prefix,
1009 (interactive (gnus-article-hidden-arg))
1010 (unless (gnus-article-check-hidden-text 'pgp arg)
1012 (let ((inhibit-point-motion-hooks t)
1013 buffer-read-only beg end)
1015 (goto-char (point-min))
1016 ;; Hide the "header".
1017 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1018 (gnus-article-hide-text-type (1+ (match-beginning 0))
1021 ;; Hide the actual signature.
1022 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1023 (setq end (1+ (match-beginning 0)))
1024 (gnus-article-hide-text-type
1026 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1028 ;; Perhaps we shouldn't hide to the end of the buffer
1029 ;; if there is no end to the signature?
1032 ;; Hide "- " PGP quotation markers.
1034 (narrow-to-region beg end)
1035 (goto-char (point-min))
1036 (while (re-search-forward "^- " nil t)
1037 (gnus-article-hide-text-type
1038 (match-beginning 0) (match-end 0) 'pgp))
1040 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1042 (defun article-hide-pem (&optional arg)
1043 "Toggle hiding of any PEM headers and signatures in the current article.
1044 If given a negative prefix, always show; if given a positive prefix,
1046 (interactive (gnus-article-hidden-arg))
1047 (unless (gnus-article-check-hidden-text 'pem arg)
1049 (let (buffer-read-only end)
1051 (goto-char (point-min))
1052 ;; hide the horrendously ugly "header".
1053 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1056 (setq end (1+ (match-beginning 0)))
1057 (gnus-article-hide-text-type
1059 (if (search-forward "\n\n" nil t)
1063 ;; hide the trailer as well
1064 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1067 (gnus-article-hide-text-type
1068 (match-beginning 0) (match-end 0) 'pem))))))
1070 (defun article-hide-signature (&optional arg)
1071 "Hide the signature in the current article.
1072 If given a negative prefix, always show; if given a positive prefix,
1074 (interactive (gnus-article-hidden-arg))
1075 (unless (gnus-article-check-hidden-text 'signature arg)
1078 (let ((buffer-read-only nil))
1079 (when (gnus-article-narrow-to-signature)
1080 (gnus-article-hide-text-type
1081 (point-min) (point-max) 'signature)))))))
1083 (defun article-strip-leading-blank-lines ()
1084 "Remove all blank lines from the beginning of the article."
1087 (let ((inhibit-point-motion-hooks t)
1089 (goto-char (point-min))
1090 (when (search-forward "\n\n" nil t)
1091 (while (and (not (eobp))
1092 (looking-at "[ \t]*$"))
1093 (gnus-delete-line))))))
1095 (defun article-strip-multiple-blank-lines ()
1096 "Replace consecutive blank lines with one empty line."
1099 (let ((inhibit-point-motion-hooks t)
1101 ;; First make all blank lines empty.
1102 (goto-char (point-min))
1103 (search-forward "\n\n" nil t)
1104 (while (re-search-forward "^[ \t]+$" nil t)
1105 (replace-match "" nil t))
1106 ;; Then replace multiple empty lines with a single empty line.
1107 (goto-char (point-min))
1108 (search-forward "\n\n" nil t)
1109 (while (re-search-forward "\n\n\n+" nil t)
1110 (replace-match "\n\n" t t)))))
1112 (defun article-strip-leading-space ()
1113 "Remove all white space from the beginning of the lines in the article."
1116 (let ((inhibit-point-motion-hooks t)
1118 (goto-char (point-min))
1119 (search-forward "\n\n" nil t)
1120 (while (re-search-forward "^[ \t]+" nil t)
1121 (replace-match "" t t)))))
1123 (defun article-strip-blank-lines ()
1124 "Strip leading, trailing and multiple blank lines."
1126 (article-strip-leading-blank-lines)
1127 (article-remove-trailing-blank-lines)
1128 (article-strip-multiple-blank-lines))
1130 (defun article-strip-all-blank-lines ()
1131 "Strip all blank lines."
1134 (let ((inhibit-point-motion-hooks t)
1136 (goto-char (point-min))
1137 (search-forward "\n\n" nil t)
1138 (while (re-search-forward "^[ \t]*\n" nil t)
1139 (replace-match "" t t)))))
1141 (defvar mime::preview/content-list)
1142 (defvar mime::preview-content-info/point-min)
1143 (defun gnus-article-narrow-to-signature ()
1144 "Narrow to the signature; return t if a signature is found, else nil."
1146 (when (and (boundp 'mime::preview/content-list)
1147 mime::preview/content-list)
1148 ;; We have a MIMEish article, so we use the MIME data to narrow.
1149 (let ((pcinfo (car (last mime::preview/content-list))))
1152 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1155 (when (gnus-article-search-signature)
1157 ;; Check whether we have some limits to what we consider
1158 ;; to be a signature.
1159 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1160 (list gnus-signature-limit)))
1162 (while (setq limit (pop limits))
1163 (if (or (and (integerp limit)
1164 (< (- (point-max) (point)) limit))
1166 (< (count-lines (point) (point-max)) limit))
1167 (and (gnus-functionp limit)
1169 (and (stringp limit)
1170 (not (re-search-forward limit nil t))))
1171 () ; This limit did not succeed.
1175 (narrow-to-region (point) (point-max))
1178 (defun gnus-article-search-signature ()
1179 "Search the current buffer for the signature separator.
1180 Put point at the beginning of the signature separator."
1181 (let ((cur (point)))
1182 (goto-char (point-max))
1183 (if (if (stringp gnus-signature-separator)
1184 (re-search-backward gnus-signature-separator nil t)
1185 (let ((seps gnus-signature-separator))
1187 (not (re-search-backward (car seps) nil t)))
1195 (autoload 'w3-display "w3-parse")
1196 (autoload 'w3-do-setup "w3" "" t)
1197 (autoload 'w3-region "w3-display" "" t))
1199 (defun gnus-article-treat-html ()
1202 (let ((cbuf (current-buffer)))
1203 (set-buffer gnus-article-buffer)
1204 (let (buf buffer-read-only b e)
1206 (goto-char (point-min))
1208 (if (search-forward "\n\n" nil t)
1211 (setq e (point-max)))
1212 (nnheader-temp-write nil
1213 (insert-buffer-substring gnus-article-buffer b e)
1215 (save-window-excursion
1216 (w3-region (point-min) (point-max))
1217 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1219 (delete-region (point-min) (point-max))
1222 (goto-char (point-min))
1223 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1224 (set-buffer cbuf))))
1226 (defun gnus-article-hidden-arg ()
1227 "Return the current prefix arg as a number, or 0 if no prefix."
1228 (list (if current-prefix-arg
1229 (prefix-numeric-value current-prefix-arg)
1232 (defun gnus-article-check-hidden-text (type arg)
1233 "Return nil if hiding is necessary.
1234 Arg can be nil or a number. Nil and positive means hide, negative
1235 means show, 0 means toggle."
1239 (let ((hide (gnus-article-hidden-text-p type)))
1245 (gnus-article-show-hidden-text type))
1247 (if (eq hide 'hidden)
1248 (gnus-article-show-hidden-text type)
1251 (defun gnus-article-hidden-text-p (type)
1252 "Say whether the current buffer contains hidden text of type TYPE."
1253 (let ((start (point-min))
1254 (pos (text-property-any (point-min) (point-max) 'article-type type)))
1256 (not (get-text-property pos 'invisible)))
1258 (text-property-any (1+ pos) (point-max) 'article-type type)))
1263 (defun gnus-article-show-hidden-text (type &optional hide)
1264 "Show all hidden text of type TYPE.
1265 If HIDE, hide the text instead."
1267 (let ((buffer-read-only nil)
1268 (inhibit-point-motion-hooks t)
1271 (while (setq beg (text-property-any end (point-max) 'article-type type))
1274 (text-property-not-all beg (point-max) 'article-type type)
1277 (gnus-article-hide-text beg end gnus-hidden-properties)
1278 (gnus-article-unhide-text beg end))
1282 (defconst article-time-units
1283 `((year . ,(* 365.25 24 60 60))
1284 (week . ,(* 7 24 60 60))
1285 (day . ,(* 24 60 60))
1289 "Mapping from time units to seconds.")
1291 (defun article-date-ut (&optional type highlight header)
1292 "Convert DATE date to universal time in the current article.
1293 If TYPE is `local', convert to local time; if it is `lapsed', output
1294 how much time has lapsed since DATE."
1295 (interactive (list 'ut t))
1296 (let* ((header (or header
1297 (mail-header-date gnus-current-headers)
1298 (message-fetch-field "date")
1300 (date (if (vectorp header) (mail-header-date header)
1302 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1303 (inhibit-point-motion-hooks t)
1304 bface eface newline)
1305 (when (and date (not (string= date "")))
1308 (nnheader-narrow-to-headers)
1309 (let ((buffer-read-only nil))
1310 ;; Delete any old Date headers.
1311 (if (re-search-forward date-regexp nil t)
1313 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1314 eface (get-text-property (1- (gnus-point-at-eol))
1316 (delete-region (progn (beginning-of-line) (point))
1317 (progn (end-of-line) (point)))
1318 (beginning-of-line))
1319 (goto-char (point-max))
1321 (insert (article-make-date-line date type))
1324 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1325 (put-text-property (match-beginning 1) (1+ (match-end 1))
1327 (put-text-property (match-beginning 2) (match-end 2)
1331 (insert "\n"))))))))
1333 (defun article-make-date-line (date type)
1334 "Return a DATE line of TYPE."
1336 ;; Convert to the local timezone. We have to slap a
1337 ;; `condition-case' round the calls to the timezone
1338 ;; functions since they aren't particularly resistant to
1341 (concat "Date: " (condition-case ()
1342 (timezone-make-date-arpa-standard date)
1344 ;; Convert to Universal Time.
1348 (timezone-make-date-arpa-standard date nil "UT")
1350 ;; Get the original date from the article.
1351 ((eq type 'original)
1352 (concat "Date: " date))
1353 ;; Let the user define the format.
1355 (if (gnus-functionp gnus-article-time-format)
1357 gnus-article-time-format
1360 (timezone-make-date-arpa-standard
1364 (format-time-string gnus-article-time-format
1367 (timezone-make-date-arpa-standard
1368 date nil "UT")))))))
1373 (format-time-string "%Y%M%DT%h%m%s"
1376 (timezone-make-date-arpa-standard
1378 ;; Do an X-Sent lapsed format.
1380 ;; If the date is seriously mangled, the timezone functions are
1381 ;; liable to bug out, so we ignore all errors.
1382 (let* ((now (current-time))
1387 (timezone-make-date-arpa-standard
1388 (current-time-string now)
1389 (current-time-zone now) "UT"))
1391 (timezone-make-date-arpa-standard
1393 (real-sec (and real-time
1394 (+ (* (float (car real-time)) 65536)
1396 (sec (and real-time (abs real-sec)))
1406 ;; This is a bit convoluted, but basically we go
1407 ;; through the time units for years, weeks, etc,
1408 ;; and divide things to see whether that results
1409 ;; in positive answers.
1412 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1413 ;; The (remaining) seconds are too few to
1414 ;; be divided into this time unit.
1416 ;; It's big enough, so we output it.
1417 (setq sec (- sec (* num (cdr unit))))
1419 (concat (if prev ", " "") (int-to-string
1421 " " (symbol-name (car unit))
1422 (if (> num 1) "s" ""))
1424 article-time-units "")
1425 ;; If dates are odd, then it might appear like the
1426 ;; article was sent in the future.
1429 " in the future"))))))
1431 (error "Unknown conversion type: %s" type))))
1433 (defun article-date-local (&optional highlight)
1434 "Convert the current article date to the local timezone."
1435 (interactive (list t))
1436 (article-date-ut 'local highlight))
1438 (defun article-date-original (&optional highlight)
1439 "Convert the current article date to what it was originally.
1440 This is only useful if you have used some other date conversion
1441 function and want to see what the date was before converting."
1442 (interactive (list t))
1443 (article-date-ut 'original highlight))
1445 (defun article-date-lapsed (&optional highlight)
1446 "Convert the current article date to time lapsed since it was sent."
1447 (interactive (list t))
1448 (article-date-ut 'lapsed highlight))
1450 (defun article-update-date-lapsed ()
1451 "Function to be run from a timer to update the lapsed time line."
1454 (when (gnus-buffer-live-p gnus-article-buffer)
1455 (set-buffer gnus-article-buffer)
1456 (goto-char (point-min))
1457 (when (re-search-forward "^X-Sent:" nil t)
1458 (article-date-lapsed t))))))
1460 (defun gnus-start-date-timer (&optional n)
1461 "Start a timer to update the X-Sent header in the article buffers.
1462 The numerical prefix says how frequently (in seconds) the function
1467 (gnus-stop-date-timer)
1468 (setq article-lapsed-timer
1469 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1471 (defun gnus-stop-date-timer ()
1472 "Stop the X-Sent timer."
1474 (when article-lapsed-timer
1475 (nnheader-cancel-timer article-lapsed-timer)
1476 (setq article-lapsed-timer nil)))
1478 (defun article-date-user (&optional highlight)
1479 "Convert the current article date to the user-defined format.
1480 This format is defined by the `gnus-article-time-format' variable."
1481 (interactive (list t))
1482 (article-date-ut 'user highlight))
1484 (defun article-date-iso8601 (&optional highlight)
1485 "Convert the current article date to ISO8601."
1486 (interactive (list t))
1487 (article-date-ut 'iso8601 highlight))
1489 (defun article-show-all ()
1490 "Show all hidden text in the article buffer."
1493 (let ((buffer-read-only nil))
1494 (gnus-article-unhide-text (point-min) (point-max)))))
1496 (defun article-emphasize (&optional arg)
1497 "Emphasize text according to `gnus-emphasis-alist'."
1498 (interactive (gnus-article-hidden-arg))
1499 (unless (gnus-article-check-hidden-text 'emphasis arg)
1501 (let ((alist gnus-emphasis-alist)
1502 (buffer-read-only nil)
1503 (props (append '(article-type emphasis)
1504 gnus-hidden-properties))
1505 regexp elem beg invisible visible face)
1506 (goto-char (point-min))
1507 (search-forward "\n\n" nil t)
1509 (while (setq elem (pop alist))
1511 (setq regexp (car elem)
1512 invisible (nth 1 elem)
1513 visible (nth 2 elem)
1515 (while (re-search-forward regexp nil t)
1516 (when (and (match-beginning visible) (match-beginning invisible))
1517 (gnus-article-hide-text
1518 (match-beginning invisible) (match-end invisible) props)
1519 (gnus-article-unhide-text-type
1520 (match-beginning visible) (match-end visible) 'emphasis)
1521 (gnus-put-text-property-excluding-newlines
1522 (match-beginning visible) (match-end visible) 'face face)
1523 (goto-char (match-end invisible)))))))))
1525 (defvar gnus-summary-article-menu)
1526 (defvar gnus-summary-post-menu)
1528 ;;; Saving functions.
1530 (defun gnus-article-save (save-buffer file &optional num)
1531 "Save the currently selected article."
1532 (unless gnus-save-all-headers
1533 ;; Remove headers according to `gnus-saved-headers'.
1534 (let ((gnus-visible-headers
1535 (or gnus-saved-headers gnus-visible-headers))
1536 (gnus-article-buffer save-buffer))
1538 (set-buffer save-buffer)
1539 (article-hide-headers 1 t))))
1540 (save-window-excursion
1541 (if (not gnus-default-article-saver)
1542 (error "No default saver is defined")
1543 ;; !!! Magic! The saving functions all save
1544 ;; `gnus-original-article-buffer' (or so they think), but we
1545 ;; bind that variable to our save-buffer.
1546 (set-buffer gnus-article-buffer)
1547 (let* ((gnus-save-article-buffer save-buffer)
1550 ((not gnus-prompt-before-saving) 'default)
1551 ((eq gnus-prompt-before-saving 'always) nil)
1553 (gnus-number-of-articles-to-be-saved
1554 (when (eq gnus-prompt-before-saving t)
1556 (set-buffer gnus-article-current-summary)
1557 (funcall gnus-default-article-saver filename)))))
1559 (defun gnus-read-save-file-name (prompt &optional filename
1560 function group headers variable)
1562 (funcall function group headers (symbol-value variable)))
1567 ((eq filename 'default)
1573 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1576 (if (and gnus-number-of-articles-to-be-saved
1577 (> gnus-number-of-articles-to-be-saved 1))
1578 (format "these %d articles"
1579 gnus-number-of-articles-to-be-saved)
1582 ;; Let the split methods have their say.
1584 ;; No split name was found.
1587 (concat prompt " (default "
1588 (file-name-nondirectory default-name) ") ")
1589 (file-name-directory default-name)
1591 ;; A single group name is returned.
1592 ((stringp split-name)
1594 (funcall function split-name headers
1595 (symbol-value variable)))
1597 (concat prompt " (default "
1598 (file-name-nondirectory default-name) ") ")
1599 (file-name-directory default-name)
1601 ;; A single split name was found
1602 ((= 1 (length split-name))
1603 (let* ((name (expand-file-name
1604 (car split-name) gnus-article-save-directory))
1605 (dir (cond ((file-directory-p name)
1606 (file-name-as-directory name))
1607 ((file-exists-p name) name)
1608 (t gnus-article-save-directory))))
1610 (concat prompt " (default " name ") ")
1612 ;; A list of splits was found.
1614 (setq split-name (nreverse split-name))
1616 (let ((file-name-history
1617 (nconc split-name file-name-history)))
1621 (concat prompt " (`M-p' for defaults) ")
1622 gnus-article-save-directory
1624 gnus-article-save-directory)))
1625 (car (push result file-name-history)))))))
1626 ;; Create the directory.
1627 (gnus-make-directory (file-name-directory file))
1628 ;; If we have read a directory, we append the default file name.
1629 (when (file-directory-p file)
1630 (setq file (concat (file-name-as-directory file)
1631 (file-name-nondirectory default-name))))
1632 ;; Possibly translate some characters.
1633 (nnheader-translate-file-chars file)))))
1634 (gnus-make-directory (file-name-directory result))
1635 (set variable result)))
1637 (defun gnus-article-archive-name (group)
1638 "Return the first instance of an \"Archive-name\" in the current buffer."
1639 (let ((case-fold-search t))
1640 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1641 (nnheader-concat gnus-article-save-directory
1642 (match-string 1)))))
1644 (defun gnus-article-nndoc-name (group)
1645 "If GROUP is an nndoc group, return the name of the parent group."
1646 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1647 (gnus-group-get-parameter group 'save-article-group)))
1649 (defun gnus-summary-save-in-rmail (&optional filename)
1650 "Append this article to Rmail file.
1651 Optional argument FILENAME specifies file name.
1652 Directory to save to is default to `gnus-article-save-directory'."
1654 (setq filename (gnus-read-save-file-name
1655 "Save %s in rmail file:" filename
1656 gnus-rmail-save-name gnus-newsgroup-name
1657 gnus-current-headers 'gnus-newsgroup-last-rmail))
1658 (gnus-eval-in-buffer-window gnus-save-article-buffer
1662 (gnus-output-to-rmail filename))))
1665 (defun gnus-summary-save-in-mail (&optional filename)
1666 "Append this article to Unix mail file.
1667 Optional argument FILENAME specifies file name.
1668 Directory to save to is default to `gnus-article-save-directory'."
1670 (setq filename (gnus-read-save-file-name
1671 "Save %s in Unix mail file:" filename
1672 gnus-mail-save-name gnus-newsgroup-name
1673 gnus-current-headers 'gnus-newsgroup-last-mail))
1674 (gnus-eval-in-buffer-window gnus-save-article-buffer
1678 (if (and (file-readable-p filename)
1679 (mail-file-babyl-p filename))
1680 (gnus-output-to-rmail filename t)
1681 (gnus-output-to-mail filename)))))
1684 (defun gnus-summary-save-in-file (&optional filename overwrite)
1685 "Append this article to file.
1686 Optional argument FILENAME specifies file name.
1687 Directory to save to is default to `gnus-article-save-directory'."
1689 (setq filename (gnus-read-save-file-name