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@gnus.org>
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))
38 (defgroup gnus-article nil
40 :link '(custom-manual "(gnus)The Article Buffer")
43 (defgroup gnus-article-hiding nil
44 "Hiding article parts."
45 :link '(custom-manual "(gnus)Article Hiding")
48 (defgroup gnus-article-highlight nil
49 "Article highlighting."
50 :link '(custom-manual "(gnus)Article Highlighting")
54 (defgroup gnus-article-signature nil
56 :link '(custom-manual "(gnus)Article Signature")
59 (defgroup gnus-article-headers nil
61 :link '(custom-manual "(gnus)Hiding Headers")
64 (defgroup gnus-article-washing nil
65 "Special commands on articles."
66 :link '(custom-manual "(gnus)Article Washing")
69 (defgroup gnus-article-emphasis nil
70 "Fontisizing articles."
71 :link '(custom-manual "(gnus)Article Fontisizing")
74 (defgroup gnus-article-saving nil
76 :link '(custom-manual "(gnus)Saving Articles")
79 (defgroup gnus-article-mime nil
80 "Worshiping the MIME wonder."
81 :link '(custom-manual "(gnus)Using MIME")
84 (defgroup gnus-article-buttons nil
85 "Pushable buttons in the article buffer."
86 :link '(custom-manual "(gnus)Article Buttons")
89 (defgroup gnus-article-various nil
90 "Other article options."
91 :link '(custom-manual "(gnus)Misc Article")
94 (defcustom gnus-ignored-headers
95 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
96 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
97 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
98 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
99 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
100 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
101 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
102 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
103 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
104 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
105 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
106 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
107 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
108 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
109 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
110 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
111 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
112 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
114 "*All headers that start with this regexp will be hidden.
115 This variable can also be a list of regexps of headers to be ignored.
116 If `gnus-visible-headers' is non-nil, this variable will be ignored."
117 :type '(choice :custom-show nil
120 :group 'gnus-article-hiding)
122 (defcustom gnus-visible-headers
123 "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:"
124 "*All headers that do not match this regexp will be hidden.
125 This variable can also be a list of regexp of headers to remain visible.
126 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
127 :type '(repeat :value-to-internal (lambda (widget value)
128 (custom-split-regexp-maybe value))
129 :match (lambda (widget value)
131 (widget-editable-list-match widget value)))
133 :group 'gnus-article-hiding)
135 (defcustom gnus-sorted-header-list
136 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
137 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
138 "*This variable is a list of regular expressions.
139 If it is non-nil, headers that match the regular expressions will
140 be placed first in the article buffer in the sequence specified by
142 :type '(repeat regexp)
143 :group 'gnus-article-hiding)
145 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
146 "Headers that are only to be displayed if they have interesting data.
147 Possible values in this list are `empty', `newsgroups', `followup-to',
148 `reply-to', `date', `long-to', and `many-to'."
149 :type '(set (const :tag "Headers with no content." empty)
150 (const :tag "Newsgroups with only one group." newsgroups)
151 (const :tag "Followup-to identical to newsgroups." followup-to)
152 (const :tag "Reply-to identical to from." reply-to)
153 (const :tag "Date less than four days old." date)
154 (const :tag "Very long To header." long-to)
155 (const :tag "Multiple To headers." many-to))
156 :group 'gnus-article-hiding)
158 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
159 "Regexp matching signature separator.
160 This can also be a list of regexps. In that case, it will be checked
161 from head to tail looking for a separator. Searches will be done from
162 the end of the buffer."
163 :type '(repeat string)
164 :group 'gnus-article-signature)
166 (defcustom gnus-signature-limit nil
167 "Provide a limit to what is considered a signature.
168 If it is a number, no signature may not be longer (in characters) than
169 that number. If it is a floating point number, no signature may be
170 longer (in lines) than that number. If it is a function, the function
171 will be called without any parameters, and if it returns nil, there is
172 no signature in the buffer. If it is a string, it will be used as a
173 regexp. If it matches, the text in question is not a signature."
174 :type '(choice (integer :value 200)
176 (function :value fun)
177 (regexp :value ".*"))
178 :group 'gnus-article-signature)
180 (defcustom gnus-hidden-properties '(invisible t intangible t)
181 "Property list to use for hiding text."
183 :group 'gnus-article-hiding)
185 (defcustom gnus-article-x-face-command
186 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
187 "*String or function to be executed to display an X-Face header.
188 If it is a string, the command will be executed in a sub-shell
189 asynchronously. The compressed face will be piped to this command."
190 :type 'string ;Leave function case to Lisp.
191 :group 'gnus-article-washing)
193 (defcustom gnus-article-x-face-too-ugly nil
194 "Regexp matching posters whose face shouldn't be shown automatically."
195 :type '(choice regexp (const nil))
196 :group 'gnus-article-washing)
198 (defcustom gnus-emphasis-alist
200 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
202 '(("_" "_" underline)
205 ("_/" "/_" underline-italic)
206 ("_\\*" "\\*_" underline-bold)
207 ("\\*/" "/\\*" bold-italic)
208 ("_\\*/" "/\\*_" underline-bold-italic))))
209 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
210 2 3 gnus-emphasis-underline)
214 (format format (car spec) (cadr spec))
215 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
217 "*Alist that says how to fontify certain phrases.
218 Each item looks like this:
220 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
222 The first element is a regular expression to be matched. The second
223 is a number that says what regular expression grouping used to find
224 the entire emphasized word. The third is a number that says what
225 regexp grouping should be displayed and highlighted. The fourth
226 is the face used for highlighting."
227 :type '(repeat (list :value ("" 0 0 default)
229 (integer :tag "Match group")
230 (integer :tag "Emphasize group")
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-bold '((t (:bold t)))
235 "Face used for displaying strong emphasized text (*word*)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-italic '((t (:italic t)))
239 "Face used for displaying italic emphasized text (/word/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline '((t (:underline t)))
243 "Face used for displaying underlined emphasized text (_word_)."
244 :group 'gnus-article-emphasis)
246 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
247 "Face used for displaying underlined bold emphasized text (_*word*_)."
248 :group 'gnus-article-emphasis)
250 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
251 "Face used for displaying underlined italic emphasized text (_*word*_)."
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
255 "Face used for displaying bold italic emphasized text (/*word*/)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-underline-bold-italic
259 '((t (:bold t :italic t :underline t)))
260 "Face used for displaying underlined bold italic emphasized text.
261 Esample: (_/*word*/_)."
262 :group 'gnus-article-emphasis)
264 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
265 "Format for display of Date headers in article bodies.
266 See `format-time-string' for the possible values.
268 The variable can also be function, which should return a complete Date
269 header. The function is called with one argument, the time, which can
270 be fed to `format-time-string'."
271 :type '(choice string symbol)
272 :link '(custom-manual "(gnus)Article Date")
273 :group 'gnus-article-washing)
276 (autoload 'mail-extract-address-components "mail-extr"))
278 (defcustom gnus-save-all-headers t
279 "*If non-nil, don't remove any headers before saving."
280 :group 'gnus-article-saving
283 (defcustom gnus-prompt-before-saving 'always
284 "*This variable says how much prompting is to be done when saving articles.
285 If it is nil, no prompting will be done, and the articles will be
286 saved to the default files. If this variable is `always', each and
287 every article that is saved will be preceded by a prompt, even when
288 saving large batches of articles. If this variable is neither nil not
289 `always', there the user will be prompted once for a file name for
290 each invocation of the saving commands."
291 :group 'gnus-article-saving
292 :type '(choice (item always)
293 (item :tag "never" nil)
294 (sexp :tag "once" :format "%t\n" :value t)))
296 (defcustom gnus-saved-headers gnus-visible-headers
297 "Headers to keep if `gnus-save-all-headers' is nil.
298 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
299 If that variable is nil, however, all headers that match this regexp
300 will be kept while the rest will be deleted before saving."
301 :group 'gnus-article-saving
304 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
305 "A function to save articles in your favourite format.
306 The function must be interactively callable (in other words, it must
307 be an Emacs command).
309 Gnus provides the following functions:
311 * gnus-summary-save-in-rmail (Rmail format)
312 * gnus-summary-save-in-mail (Unix mail format)
313 * gnus-summary-save-in-folder (MH folder)
314 * gnus-summary-save-in-file (article format)
315 * gnus-summary-save-in-vm (use VM's folder format)
316 * gnus-summary-write-to-file (article format -- overwrite)."
317 :group 'gnus-article-saving
318 :type '(radio (function-item gnus-summary-save-in-rmail)
319 (function-item gnus-summary-save-in-mail)
320 (function-item gnus-summary-save-in-folder)
321 (function-item gnus-summary-save-in-file)
322 (function-item gnus-summary-save-in-vm)
323 (function-item gnus-summary-write-to-file)))
325 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
326 "A function generating a file name to save articles in Rmail format.
327 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
328 :group 'gnus-article-saving
331 (defcustom gnus-mail-save-name 'gnus-plain-save-name
332 "A function generating a file name to save articles in Unix mail format.
333 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
334 :group 'gnus-article-saving
337 (defcustom gnus-folder-save-name 'gnus-folder-save-name
338 "A function generating a file name to save articles in MH folder.
339 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
340 :group 'gnus-article-saving
343 (defcustom gnus-file-save-name 'gnus-numeric-save-name
344 "A function generating a file name to save articles in article format.
345 The function is called with NEWSGROUP, HEADERS, and optional
347 :group 'gnus-article-saving
350 (defcustom gnus-split-methods
351 '((gnus-article-archive-name)
352 (gnus-article-nndoc-name))
353 "*Variable used to suggest where articles are to be saved.
354 For instance, if you would like to save articles related to Gnus in
355 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
356 you could set this variable to something like:
358 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
359 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
361 This variable is an alist where the where the key is the match and the
362 value is a list of possible files to save in if the match is non-nil.
364 If the match is a string, it is used as a regexp match on the
365 article. If the match is a symbol, that symbol will be funcalled
366 from the buffer of the article to be saved with the newsgroup as the
367 parameter. If it is a list, it will be evaled in the same buffer.
369 If this form or function returns a string, this string will be used as
370 a possible file name; and if it returns a non-nil list, that list will
371 be used as possible file names."
372 :group 'gnus-article-saving
373 :type '(repeat (choice (list :value (fun) function)
374 (cons :value ("" "") regexp (repeat string))
377 (defcustom gnus-strict-mime t
378 "*If nil, MIME-decode even if there is no Mime-Version header."
379 :group 'gnus-article-mime
382 (defcustom gnus-show-mime-method 'metamail-buffer
383 "Function to process a MIME message.
384 The function is called from the article buffer."
385 :group 'gnus-article-mime
388 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
389 "*Function to decode MIME encoded words.
390 The function is called from the article buffer."
391 :group 'gnus-article-mime
394 (defcustom gnus-page-delimiter "^\^L"
395 "*Regexp describing what to use as article page delimiters.
396 The default value is \"^\^L\", which is a form linefeed at the
397 beginning of a line."
399 :group 'gnus-article-various)
401 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
402 "*The format specification for the article mode line.
403 See `gnus-summary-mode-line-format' for a closer description."
405 :group 'gnus-article-various)
407 (defcustom gnus-article-mode-hook nil
408 "*A hook for Gnus article mode."
410 :group 'gnus-article-various)
412 (defcustom gnus-article-menu-hook nil
413 "*Hook run after the creation of the article mode menu."
415 :group 'gnus-article-various)
417 (defcustom gnus-article-prepare-hook nil
418 "*A hook called after an article has been prepared in the article buffer.
419 If you want to run a special decoding program like nkf, use this hook."
421 :group 'gnus-article-various)
423 (defcustom gnus-article-hide-pgp-hook nil
424 "*A hook called after successfully hiding a PGP signature."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-button-face 'bold
429 "Face used for highlighting buttons in the article buffer.
431 An article button is a piece of text that you can activate by pressing
432 `RET' or `mouse-2' above it."
434 :group 'gnus-article-buttons)
436 (defcustom gnus-article-mouse-face 'highlight
437 "Face used for mouse highlighting in the article buffer.
439 Article buttons will be displayed in this face when the cursor is
442 :group 'gnus-article-buttons)
444 (defcustom gnus-signature-face 'gnus-signature-face
445 "Face used for highlighting a signature in the article buffer.
446 Obsolete; use the face `gnus-signature-face' for customizations instead."
448 :group 'gnus-article-highlight
449 :group 'gnus-article-signature)
451 (defface gnus-signature-face
454 "Face used for highlighting a signature in the article buffer."
455 :group 'gnus-article-highlight
456 :group 'gnus-article-signature)
458 (defface gnus-header-from-face
461 (:foreground "spring green"))
464 (:foreground "red3"))
467 "Face used for displaying from headers."
468 :group 'gnus-article-headers
469 :group 'gnus-article-highlight)
471 (defface gnus-header-subject-face
474 (:foreground "SeaGreen3"))
477 (:foreground "red4"))
479 (:bold t :italic t)))
480 "Face used for displaying subject headers."
481 :group 'gnus-article-headers
482 :group 'gnus-article-highlight)
484 (defface gnus-header-newsgroups-face
487 (:foreground "yellow" :italic t))
490 (:foreground "MidnightBlue" :italic t))
493 "Face used for displaying newsgroups headers."
494 :group 'gnus-article-headers
495 :group 'gnus-article-highlight)
497 (defface gnus-header-name-face
500 (:foreground "SeaGreen"))
503 (:foreground "maroon"))
506 "Face used for displaying header names."
507 :group 'gnus-article-headers
508 :group 'gnus-article-highlight)
510 (defface gnus-header-content-face
513 (:foreground "forest green" :italic t))
516 (:foreground "indianred4" :italic t))
518 (:italic t))) "Face used for displaying header content."
519 :group 'gnus-article-headers
520 :group 'gnus-article-highlight)
522 (defcustom gnus-header-face-alist
523 '(("From" nil gnus-header-from-face)
524 ("Subject" nil gnus-header-subject-face)
525 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
526 ("" gnus-header-name-face gnus-header-content-face))
527 "*Controls highlighting of article header.
529 An alist of the form (HEADER NAME CONTENT).
531 HEADER is a regular expression which should match the name of an
532 header header and NAME and CONTENT are either face names or nil.
534 The name of each header field will be displayed using the face
535 specified by the first element in the list where HEADER match the
536 header name and NAME is non-nil. Similarly, the content will be
537 displayed by the first non-nil matching CONTENT face."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight
540 :type '(repeat (list (regexp :tag "Header")
542 (item :tag "skip" nil)
543 (face :value default))
544 (choice :tag "Content"
545 (item :tag "skip" nil)
546 (face :value default)))))
548 (defcustom gnus-article-decode-hook
549 '(article-decode-charset article-decode-rfc1522)
550 "*Hook run to decode charsets in articles.")
552 ;;; Internal variables
554 (defvar article-lapsed-timer nil)
555 (defvar gnus-article-current-summary nil)
557 (defvar gnus-article-mode-syntax-table
558 (let ((table (copy-syntax-table text-mode-syntax-table)))
559 (modify-syntax-entry ?- "w" table)
560 (modify-syntax-entry ?> ")" table)
561 (modify-syntax-entry ?< "(" table)
563 "Syntax table used in article mode buffers.
564 Initialized from `text-mode-syntax-table.")
566 (defvar gnus-save-article-buffer nil)
568 (defvar gnus-article-mode-line-format-alist
569 (nconc '((?w (gnus-article-wash-status) ?s))
570 gnus-summary-mode-line-format-alist))
572 (defvar gnus-number-of-articles-to-be-saved nil)
574 (defvar gnus-inhibit-hiding nil)
576 (defsubst gnus-article-hide-text (b e props)
577 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
578 (add-text-properties b e props)
579 (when (memq 'intangible props)
581 (max (1- b) (point-min))
582 b 'intangible (cddr (memq 'intangible props)))))
584 (defsubst gnus-article-unhide-text (b e)
585 "Remove hidden text properties from region between B and E."
586 (remove-text-properties b e gnus-hidden-properties)
587 (when (memq 'intangible gnus-hidden-properties)
588 (put-text-property (max (1- b) (point-min))
591 (defun gnus-article-hide-text-type (b e type)
592 "Hide text of TYPE between B and E."
593 (gnus-article-hide-text
594 b e (cons 'article-type (cons type gnus-hidden-properties))))
596 (defun gnus-article-unhide-text-type (b e type)
597 "Unhide text of TYPE between B and E."
598 (remove-text-properties
599 b e (cons 'article-type (cons type gnus-hidden-properties)))
600 (when (memq 'intangible gnus-hidden-properties)
601 (put-text-property (max (1- b) (point-min))
604 (defun gnus-article-hide-text-of-type (type)
605 "Hide text of TYPE in the current buffer."
607 (let ((b (point-min))
609 (while (setq b (text-property-any b e 'article-type type))
610 (add-text-properties b (incf b) gnus-hidden-properties)))))
612 (defun gnus-article-delete-text-of-type (type)
613 "Delete text of TYPE in the current buffer."
615 (let ((b (point-min)))
616 (while (setq b (text-property-any b (point-max) 'article-type type))
618 b (or (text-property-not-all b (point-max) 'article-type type)
621 (defun gnus-article-delete-invisible-text ()
622 "Delete all invisible text in the current buffer."
624 (let ((b (point-min)))
625 (while (setq b (text-property-any b (point-max) 'invisible t))
627 b (or (text-property-not-all b (point-max) 'invisible t)
630 (defun gnus-article-text-type-exists-p (type)
631 "Say whether any text of type TYPE exists in the buffer."
632 (text-property-any (point-min) (point-max) 'article-type type))
634 (defsubst gnus-article-header-rank ()
635 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
636 (let ((list gnus-sorted-header-list)
639 (when (looking-at (car list))
641 (setq list (cdr list))
645 (defun article-hide-headers (&optional arg delete)
646 "Toggle whether to hide unwanted headers and possibly sort them as well.
647 If given a negative prefix, always show; if given a positive prefix,
649 (interactive (gnus-article-hidden-arg))
651 (if (gnus-article-check-hidden-text 'headers arg)
652 ;; Show boring headers as well.
653 (gnus-article-show-hidden-text 'boring-headers)
654 ;; This function might be inhibited.
655 (unless gnus-inhibit-hiding
658 (let ((buffer-read-only nil)
660 (props (nconc (list 'article-type 'headers)
661 gnus-hidden-properties))
662 (max (1+ (length gnus-sorted-header-list)))
663 (ignored (when (not gnus-visible-headers)
664 (cond ((stringp gnus-ignored-headers)
665 gnus-ignored-headers)
666 ((listp gnus-ignored-headers)
667 (mapconcat 'identity gnus-ignored-headers
670 (cond ((stringp gnus-visible-headers)
671 gnus-visible-headers)
672 ((and gnus-visible-headers
673 (listp gnus-visible-headers))
674 (mapconcat 'identity gnus-visible-headers "\\|"))))
675 (inhibit-point-motion-hooks t)
677 ;; First we narrow to just the headers.
679 (goto-char (point-min))
680 ;; Hide any "From " lines at the beginning of (mail) articles.
681 (while (looking-at "From ")
685 (delete-region (point-min) (point))
686 (gnus-article-hide-text (point-min) (point) props)))
687 ;; Then treat the rest of the header lines.
690 (if (search-forward "\n\n" nil t) ; if there's a body
691 (progn (forward-line -1) (point))
693 ;; Then we use the two regular expressions
694 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
695 ;; select which header lines is to remain visible in the
697 (goto-char (point-min))
698 (while (re-search-forward "^[^ \t]*:" nil t)
700 ;; Mark the rank of the header.
702 (point) (1+ (point)) 'message-rank
703 (if (or (and visible (looking-at visible))
705 (not (looking-at ignored))))
706 (gnus-article-header-rank)
709 (message-sort-headers-1)
710 (when (setq beg (text-property-any
711 (point-min) (point-max) 'message-rank (+ 2 max)))
712 ;; We make the unwanted headers invisible.
714 (delete-region beg (point-max))
715 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
716 (gnus-article-hide-text-type beg (point-max) 'headers))
717 ;; Work around XEmacs lossage.
718 (put-text-property (point-min) beg 'invisible nil))))))))
720 (defun article-hide-boring-headers (&optional arg)
721 "Toggle hiding of headers that aren't very interesting.
722 If given a negative prefix, always show; if given a positive prefix,
724 (interactive (gnus-article-hidden-arg))
725 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
726 (not gnus-show-all-headers))
729 (let ((buffer-read-only nil)
730 (list gnus-boring-article-headers)
731 (inhibit-point-motion-hooks t)
733 (nnheader-narrow-to-headers)
735 (setq elem (pop list))
736 (goto-char (point-min))
738 ;; Hide empty headers.
740 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
742 (gnus-article-hide-text-type
743 (progn (beginning-of-line) (point))
746 (if (re-search-forward "^[^ \t]" nil t)
750 ;; Hide boring Newsgroups header.
751 ((eq elem 'newsgroups)
752 (when (equal (gnus-fetch-field "newsgroups")
753 (gnus-group-real-name
754 (if (boundp 'gnus-newsgroup-name)
757 (gnus-article-hide-header "newsgroups")))
758 ((eq elem 'followup-to)
759 (when (equal (message-fetch-field "followup-to")
760 (message-fetch-field "newsgroups"))
761 (gnus-article-hide-header "followup-to")))
763 (let ((from (message-fetch-field "from"))
764 (reply-to (message-fetch-field "reply-to")))
769 (nth 1 (mail-extract-address-components from))
770 (nth 1 (mail-extract-address-components reply-to)))))
771 (gnus-article-hide-header "reply-to"))))
773 (let ((date (message-fetch-field "date")))
775 (< (days-between (current-time-string) date)
777 (gnus-article-hide-header "date"))))
779 (let ((to (message-fetch-field "to")))
780 (when (> (length to) 1024)
781 (gnus-article-hide-header "to"))))
784 (goto-char (point-min))
785 (while (re-search-forward "^to:" nil t)
786 (setq to-count (1+ to-count)))
788 (while (> to-count 0)
789 (goto-char (point-min))
791 (re-search-forward "^to:" nil nil to-count)
793 (narrow-to-region (point) (point-max))
794 (gnus-article-hide-header "to"))
795 (setq to-count (1- to-count)))))))))))))
797 (defun gnus-article-hide-header (header)
799 (goto-char (point-min))
800 (when (re-search-forward (concat "^" header ":") nil t)
801 (gnus-article-hide-text-type
802 (progn (beginning-of-line) (point))
805 (if (re-search-forward "^[^ \t]" nil t)
810 (defun article-treat-dumbquotes ()
811 "Translate M******** sm*rtq**t*s into proper text."
813 (article-translate-characters "\221\222\223\224" "`'\"\""))
815 (defun article-translate-characters (from to)
816 "Translate all characters in the body of the article according to FROM and TO.
817 FROM is a string of characters to translate from; to is a string of
818 characters to translate to."
820 (goto-char (point-min))
821 (when (search-forward "\n\n" nil t)
822 (let ((buffer-read-only nil)
823 (x (make-string 225 ?x))
825 (while (< (incf i) (length x))
828 (while (< i (length from))
829 (aset x (aref from i) (aref to i))
831 (translate-region (point) (point-max) x)))))
833 (defun article-treat-overstrike ()
834 "Translate overstrikes into bold text."
837 (goto-char (point-min))
838 (when (search-forward "\n\n" nil t)
839 (let ((buffer-read-only nil))
840 (while (search-forward "\b" nil t)
841 (let ((next (following-char))
842 (previous (char-after (- (point) 2))))
843 ;; We do the boldification/underlining by hiding the
844 ;; overstrikes and putting the proper text property
848 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
849 (put-text-property (point) (1+ (point)) 'face 'bold))
851 (gnus-article-hide-text-type
852 (1- (point)) (1+ (point)) 'overstrike)
854 (- (point) 2) (1- (point)) 'face 'underline))
856 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
858 (point) (1+ (point)) 'face 'underline)))))))))
860 (defun article-fill ()
861 "Format too long lines."
864 (let ((buffer-read-only nil))
866 (goto-char (point-min))
867 (search-forward "\n\n" nil t)
869 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
870 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
871 (adaptive-fill-mode t))
873 (and (>= (current-column) (min fill-column (window-width)))
874 (/= (preceding-char) ?:)
875 (fill-paragraph nil))
878 (defun article-remove-cr ()
879 "Remove carriage returns from an article."
882 (let ((buffer-read-only nil))
883 (goto-char (point-min))
884 (while (search-forward "\r" nil t)
885 (replace-match "" t t)))))
887 (defun article-remove-trailing-blank-lines ()
888 "Remove all trailing blank lines from the article."
891 (let ((buffer-read-only nil))
892 (goto-char (point-max))
896 (while (and (not (bobp))
897 (looking-at "^[ \t]*$"))
902 (defun article-display-x-face (&optional force)
903 "Look for an X-Face header and display it if present."
904 (interactive (list 'force))
906 ;; Delete the old process, if any.
907 (when (process-status "article-x-face")
908 (delete-process "article-x-face"))
909 (let ((inhibit-point-motion-hooks t)
913 (nnheader-narrow-to-headers)
914 (setq from (message-fetch-field "from"))
915 (goto-char (point-min))
916 (while (and gnus-article-x-face-command
919 ;; Check whether this face is censored.
920 (not gnus-article-x-face-too-ugly)
921 (and gnus-article-x-face-too-ugly from
922 (not (string-match gnus-article-x-face-too-ugly
924 ;; Has to be present.
925 (re-search-forward "^X-Face: " nil t))
926 ;; This used to try to do multiple faces (`while' instead of
927 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
928 ;; work (b) it can crash some versions of Emacs (c) are
929 ;; multiple faces really something to encourage?
930 (when (stringp gnus-article-x-face-command)
932 ;; We now have the area of the buffer where the X-Face is stored.
935 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
936 ;; We display the face.
937 (if (symbolp gnus-article-x-face-command)
938 ;; The command is a lisp function, so we call it.
939 (if (gnus-functionp gnus-article-x-face-command)
940 (funcall gnus-article-x-face-command beg end)
941 (error "%s is not a function" gnus-article-x-face-command))
942 ;; The command is a string, so we interpret the command
943 ;; as a, well, command, and fork it off.
944 (let ((process-connection-type nil))
945 (process-kill-without-query
947 "article-x-face" nil shell-file-name shell-command-switch
948 gnus-article-x-face-command))
949 (process-send-region "article-x-face" beg end)
950 (process-send-eof "article-x-face"))))))))))
952 (defun article-decode-mime-words ()
953 "Decode all MIME-encoded words in the article."
956 (set-buffer gnus-article-buffer)
957 (let ((inhibit-point-motion-hooks t)
959 (rfc2047-decode-region (point-min) (point-max)))))
961 (defun article-decode-charset (&optional prompt)
962 "Decode charset-encoded text in the article.
963 If PROMPT (the prefix), prompt for a coding system to use."
967 (message-narrow-to-head)
968 (let* ((inhibit-point-motion-hooks t)
969 (ct (message-fetch-field "Content-Type" t))
970 (cte (message-fetch-field "Content-Transfer-Encoding" t))
973 (mm-read-coding-system "Charset to decode: "))
975 (mm-content-type-charset ct))
977 (gnus-group-find-parameter
978 gnus-newsgroup-name 'charset))))
980 (goto-char (point-max))
982 (narrow-to-region (point) (point-max))
984 (string-match "text/plain" ct))
986 charset (and cte (intern (downcase
987 (gnus-strip-whitespace cte))))))))))
989 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
990 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
991 (defun article-decode-rfc1522 ()
992 "Remove QP encoding from headers."
993 (let ((inhibit-point-motion-hooks t)
994 (buffer-read-only nil))
996 (message-narrow-to-head)
997 (rfc2047-decode-region (point-min) (point-max)))))
999 (defun article-de-quoted-unreadable (&optional force)
1000 "Translate a quoted-printable-encoded article.
1001 If FORCE, decode the article whether it is marked as quoted-printable
1003 (interactive (list 'force))
1005 (let ((buffer-read-only nil)
1006 (type (gnus-fetch-field "content-transfer-encoding")))
1007 ;;(gnus-article-decode-rfc1522)
1009 (and type (string-match "quoted-printable" (downcase type))))
1010 (goto-char (point-min))
1011 (search-forward "\n\n" nil 'move)
1012 (quoted-printable-decode-region (point) (point-max))))))
1014 (defun article-mime-decode-quoted-printable-buffer ()
1015 "Decode Quoted-Printable in the current buffer."
1016 (quoted-printable-decode-region (point-min) (point-max)))
1018 (defun article-hide-pgp (&optional arg)
1019 "Toggle hiding of any PGP headers and signatures in the current article.
1020 If given a negative prefix, always show; if given a positive prefix,
1022 (interactive (gnus-article-hidden-arg))
1023 (unless (gnus-article-check-hidden-text 'pgp arg)
1025 (let ((inhibit-point-motion-hooks t)
1026 buffer-read-only beg end)
1028 (goto-char (point-min))
1029 ;; Hide the "header".
1030 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1031 (delete-region (1+ (match-beginning 0)) (match-end 0))
1033 ;; Hide the actual signature.
1034 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1035 (setq end (1+ (match-beginning 0)))
1038 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1040 ;; Perhaps we shouldn't hide to the end of the buffer
1041 ;; if there is no end to the signature?
1043 ;; Hide "- " PGP quotation markers.
1045 (narrow-to-region beg end)
1046 (goto-char (point-min))
1047 (while (re-search-forward "^- " nil t)
1049 (match-beginning 0) (match-end 0)))
1051 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1053 (defun article-hide-pem (&optional arg)
1054 "Toggle hiding of any PEM headers and signatures in the current article.
1055 If given a negative prefix, always show; if given a positive prefix,
1057 (interactive (gnus-article-hidden-arg))
1058 (unless (gnus-article-check-hidden-text 'pem arg)
1060 (let (buffer-read-only end)
1062 (goto-char (point-min))
1063 ;; hide the horrendously ugly "header".
1064 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1067 (setq end (1+ (match-beginning 0)))
1068 (gnus-article-hide-text-type
1070 (if (search-forward "\n\n" nil t)
1074 ;; hide the trailer as well
1075 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1078 (gnus-article-hide-text-type
1079 (match-beginning 0) (match-end 0) 'pem))))))
1081 (defun article-hide-signature (&optional arg)
1082 "Hide the signature in the current article.
1083 If given a negative prefix, always show; if given a positive prefix,
1085 (interactive (gnus-article-hidden-arg))
1086 (unless (gnus-article-check-hidden-text 'signature arg)
1089 (let ((buffer-read-only nil))
1090 (when (gnus-article-narrow-to-signature)
1091 (gnus-article-hide-text-type
1092 (point-min) (point-max) 'signature)))))))
1094 (defun article-strip-leading-blank-lines ()
1095 "Remove all blank lines from the beginning of the article."
1098 (let ((inhibit-point-motion-hooks t)
1100 (goto-char (point-min))
1101 (when (search-forward "\n\n" nil t)
1102 (while (and (not (eobp))
1103 (looking-at "[ \t]*$"))
1104 (gnus-delete-line))))))
1106 (defun article-strip-multiple-blank-lines ()
1107 "Replace consecutive blank lines with one empty line."
1110 (let ((inhibit-point-motion-hooks t)
1112 ;; First make all blank lines empty.
1113 (goto-char (point-min))
1114 (search-forward "\n\n" nil t)
1115 (while (re-search-forward "^[ \t]+$" nil t)
1116 (replace-match "" nil t))
1117 ;; Then replace multiple empty lines with a single empty line.
1118 (goto-char (point-min))
1119 (search-forward "\n\n" nil t)
1120 (while (re-search-forward "\n\n\n+" nil t)
1121 (replace-match "\n\n" t t)))))
1123 (defun article-strip-leading-space ()
1124 "Remove all white space from the beginning of the lines in the article."
1127 (let ((inhibit-point-motion-hooks t)
1129 (goto-char (point-min))
1130 (search-forward "\n\n" nil t)
1131 (while (re-search-forward "^[ \t]+" nil t)
1132 (replace-match "" t t)))))
1134 (defun article-strip-blank-lines ()
1135 "Strip leading, trailing and multiple blank lines."
1137 (article-strip-leading-blank-lines)
1138 (article-remove-trailing-blank-lines)
1139 (article-strip-multiple-blank-lines))
1141 (defun article-strip-all-blank-lines ()
1142 "Strip all blank lines."
1145 (let ((inhibit-point-motion-hooks t)
1147 (goto-char (point-min))
1148 (search-forward "\n\n" nil t)
1149 (while (re-search-forward "^[ \t]*\n" nil t)
1150 (replace-match "" t t)))))
1152 (defvar mime::preview/content-list)
1153 (defvar mime::preview-content-info/point-min)
1154 (defun gnus-article-narrow-to-signature ()
1155 "Narrow to the signature; return t if a signature is found, else nil."
1157 (let ((inhibit-point-motion-hooks t))
1158 (when (and (boundp 'mime::preview/content-list)
1159 mime::preview/content-list)
1160 ;; We have a MIMEish article, so we use the MIME data to narrow.
1161 (let ((pcinfo (car (last mime::preview/content-list))))
1164 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1167 (when (gnus-article-search-signature)
1169 ;; Check whether we have some limits to what we consider
1170 ;; to be a signature.
1171 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1172 (list gnus-signature-limit)))
1174 (while (setq limit (pop limits))
1175 (if (or (and (integerp limit)
1176 (< (- (point-max) (point)) limit))
1178 (< (count-lines (point) (point-max)) limit))
1179 (and (gnus-functionp limit)
1181 (and (stringp limit)
1182 (not (re-search-forward limit nil t))))
1183 () ; This limit did not succeed.
1187 (narrow-to-region (point) (point-max))
1190 (defun gnus-article-search-signature ()
1191 "Search the current buffer for the signature separator.
1192 Put point at the beginning of the signature separator."
1193 (let ((cur (point)))
1194 (goto-char (point-max))
1195 (if (if (stringp gnus-signature-separator)
1196 (re-search-backward gnus-signature-separator nil t)
1197 (let ((seps gnus-signature-separator))
1199 (not (re-search-backward (car seps) nil t)))
1207 (autoload 'w3-display "w3-parse")
1208 (autoload 'w3-do-setup "w3" "" t)
1209 (autoload 'w3-region "w3-display" "" t))
1211 (defun gnus-article-treat-html ()
1214 (let ((cbuf (current-buffer)))
1215 (set-buffer gnus-article-buffer)
1216 (let (buf buffer-read-only b e)
1218 (goto-char (point-min))
1220 (if (search-forward "\n\n" nil t)
1223 (setq e (point-max)))
1225 (insert-buffer-substring gnus-article-buffer b e)
1227 (save-window-excursion
1228 (w3-region (point-min) (point-max))
1229 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1231 (delete-region (point-min) (point-max))
1234 (goto-char (point-min))
1235 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1236 (set-buffer cbuf))))
1238 (defun gnus-article-hidden-arg ()
1239 "Return the current prefix arg as a number, or 0 if no prefix."
1240 (list (if current-prefix-arg
1241 (prefix-numeric-value current-prefix-arg)
1244 (defun gnus-article-check-hidden-text (type arg)
1245 "Return nil if hiding is necessary.
1246 Arg can be nil or a number. Nil and positive means hide, negative
1247 means show, 0 means toggle."
1251 (let ((hide (gnus-article-hidden-text-p type)))
1257 (gnus-article-show-hidden-text type))
1259 (if (eq hide 'hidden)
1260 (gnus-article-show-hidden-text type)
1263 (defun gnus-article-hidden-text-p (type)
1264 "Say whether the current buffer contains hidden text of type TYPE."
1265 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1267 (not (get-text-property pos 'invisible)))
1269 (text-property-any (1+ pos) (point-max) 'article-type type)))
1274 (defun gnus-article-show-hidden-text (type &optional hide)
1275 "Show all hidden text of type TYPE.
1276 If HIDE, hide the text instead."
1278 (let ((buffer-read-only nil)
1279 (inhibit-point-motion-hooks t)
1282 (while (setq beg (text-property-any end (point-max) 'article-type type))
1285 (text-property-not-all beg (point-max) 'article-type type)
1288 (gnus-article-hide-text beg end gnus-hidden-properties)
1289 (gnus-article-unhide-text beg end))
1293 (defconst article-time-units
1294 `((year . ,(* 365.25 24 60 60))
1295 (week . ,(* 7 24 60 60))
1296 (day . ,(* 24 60 60))
1300 "Mapping from time units to seconds.")
1302 (defun article-date-ut (&optional type highlight header)
1303 "Convert DATE date to universal time in the current article.
1304 If TYPE is `local', convert to local time; if it is `lapsed', output
1305 how much time has lapsed since DATE."
1306 (interactive (list 'ut t))
1307 (let* ((header (or header
1308 (mail-header-date gnus-current-headers)
1309 (message-fetch-field "date")
1311 (date (if (vectorp header) (mail-header-date header)
1313 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1314 (inhibit-point-motion-hooks t)
1315 bface eface newline)
1316 (when (and date (not (string= date "")))
1319 (nnheader-narrow-to-headers)
1320 (let ((buffer-read-only nil))
1321 ;; Delete any old Date headers.
1322 (if (re-search-forward date-regexp nil t)
1324 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1325 eface (get-text-property (1- (gnus-point-at-eol))
1327 (delete-region (progn (beginning-of-line) (point))
1328 (progn (end-of-line) (point)))
1329 (beginning-of-line))
1330 (goto-char (point-max))
1332 (insert (article-make-date-line date type))
1335 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1336 (put-text-property (match-beginning 1) (1+ (match-end 1))
1338 (put-text-property (match-beginning 2) (match-end 2)
1342 (insert "\n"))))))))
1344 (defun article-make-date-line (date type)
1345 "Return a DATE line of TYPE."
1346 (let ((time (condition-case ()
1350 ;; Convert to the local timezone. We have to slap a
1351 ;; `condition-case' round the calls to the timezone
1352 ;; functions since they aren't particularly resistant to
1355 (concat "Date: " (current-time-string time)))
1356 ;; Convert to Universal Time.
1359 (current-time-string
1360 (let ((e (parse-time-string date)))
1362 (apply 'encode-time e)))))
1363 ;; Get the original date from the article.
1364 ((eq type 'original)
1365 (concat "Date: " date))
1366 ;; Let the user define the format.
1368 (if (gnus-functionp gnus-article-time-format)
1369 (funcall gnus-article-time-format time)
1372 (format-time-string gnus-article-time-format time))))
1377 (format-time-string "%Y%M%DT%h%m%s" time)))
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))
1383 (real-time (subtract-time now time))
1384 (real-sec (and real-time
1385 (+ (* (float (car real-time)) 65536)
1387 (sec (and real-time (abs real-sec)))
1397 ;; This is a bit convoluted, but basically we go
1398 ;; through the time units for years, weeks, etc,
1399 ;; and divide things to see whether that results
1400 ;; in positive answers.
1403 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1404 ;; The (remaining) seconds are too few to
1405 ;; be divided into this time unit.
1407 ;; It's big enough, so we output it.
1408 (setq sec (- sec (* num (cdr unit))))
1410 (concat (if prev ", " "") (int-to-string
1412 " " (symbol-name (car unit))
1413 (if (> num 1) "s" ""))
1415 article-time-units "")
1416 ;; If dates are odd, then it might appear like the
1417 ;; article was sent in the future.
1420 " in the future"))))))
1422 (error "Unknown conversion type: %s" type)))))
1424 (defun article-date-local (&optional highlight)
1425 "Convert the current article date to the local timezone."
1426 (interactive (list t))
1427 (article-date-ut 'local highlight))
1429 (defun article-date-original (&optional highlight)
1430 "Convert the current article date to what it was originally.
1431 This is only useful if you have used some other date conversion
1432 function and want to see what the date was before converting."
1433 (interactive (list t))
1434 (article-date-ut 'original highlight))
1436 (defun article-date-lapsed (&optional highlight)
1437 "Convert the current article date to time lapsed since it was sent."
1438 (interactive (list t))
1439 (article-date-ut 'lapsed highlight))
1441 (defun article-update-date-lapsed ()
1442 "Function to be run from a timer to update the lapsed time line."
1443 (let (deactivate-mark)
1446 (when (gnus-buffer-live-p gnus-article-buffer)
1447 (set-buffer gnus-article-buffer)
1448 (goto-char (point-min))
1449 (when (re-search-forward "^X-Sent:" nil t)
1450 (article-date-lapsed t)))))))
1452 (defun gnus-start-date-timer (&optional n)
1453 "Start a timer to update the X-Sent header in the article buffers.
1454 The numerical prefix says how frequently (in seconds) the function
1459 (gnus-stop-date-timer)
1460 (setq article-lapsed-timer
1461 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1463 (defun gnus-stop-date-timer ()
1464 "Stop the X-Sent timer."
1466 (when article-lapsed-timer
1467 (nnheader-cancel-timer article-lapsed-timer)
1468 (setq article-lapsed-timer nil)))
1470 (defun article-date-user (&optional highlight)
1471 "Convert the current article date to the user-defined format.
1472 This format is defined by the `gnus-article-time-format' variable."
1473 (interactive (list t))
1474 (article-date-ut 'user highlight))
1476 (defun article-date-iso8601 (&optional highlight)
1477 "Convert the current article date to ISO8601."
1478 (interactive (list t))
1479 (article-date-ut 'iso8601 highlight))
1481 (defun article-show-all ()
1482 "Show all hidden text in the article buffer."
1485 (let ((buffer-read-only nil))
1486 (gnus-article-unhide-text (point-min) (point-max)))))
1488 (defun article-emphasize (&optional arg)
1489 "Emphasize text according to `gnus-emphasis-alist'."
1490 (interactive (gnus-article-hidden-arg))
1491 (unless (gnus-article-check-hidden-text 'emphasis arg)
1493 (let ((alist gnus-emphasis-alist)
1494 (buffer-read-only nil)
1495 (props (append '(article-type emphasis)
1496 gnus-hidden-properties))
1497 regexp elem beg invisible visible face)
1498 (goto-char (point-min))
1499 (search-forward "\n\n" nil t)
1501 (while (setq elem (pop alist))
1503 (setq regexp (car elem)
1504 invisible (nth 1 elem)
1505 visible (nth 2 elem)
1507 (while (re-search-forward regexp nil t)
1508 (when (and (match-beginning visible) (match-beginning invisible))
1509 (gnus-article-hide-text
1510 (match-beginning invisible) (match-end invisible) props)
1511 (gnus-article-unhide-text-type
1512 (match-beginning visible) (match-end visible) 'emphasis)
1513 (gnus-put-text-property-excluding-newlines
1514 (match-beginning visible) (match-end visible) 'face face)
1515 (goto-char (match-end invisible)))))))))
1517 (defvar gnus-summary-article-menu)
1518 (defvar gnus-summary-post-menu)
1520 ;;; Saving functions.
1522 (defun gnus-article-save (save-buffer file &optional num)
1523 "Save the currently selected article."
1524 (unless gnus-save-all-headers
1525 ;; Remove headers according to `gnus-saved-headers'.
1526 (let ((gnus-visible-headers
1527 (or gnus-saved-headers gnus-visible-headers))
1528 (gnus-article-buffer save-buffer))
1530 (set-buffer save-buffer)
1531 (article-hide-headers 1 t))))
1532 (save-window-excursion
1533 (if (not gnus-default-article-saver)
1534 (error "No default saver is defined")
1535 ;; !!! Magic! The saving functions all save
1536 ;; `gnus-original-article-buffer' (or so they think), but we
1537 ;; bind that variable to our save-buffer.
1538 (set-buffer gnus-article-buffer)
1539 (let* ((gnus-save-article-buffer save-buffer)
1542 ((not gnus-prompt-before-saving) 'default)
1543 ((eq gnus-prompt-before-saving 'always) nil)
1545 (gnus-number-of-articles-to-be-saved
1546 (when (eq gnus-prompt-before-saving t)
1548 (set-buffer gnus-article-current-summary)
1549 (funcall gnus-default-article-saver filename)))))
1551 (defun gnus-read-save-file-name (prompt &optional filename
1552 function group headers variable)
1554 (funcall function group headers (symbol-value variable)))
1559 ((eq filename 'default)
1565 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1568 (if (and gnus-number-of-articles-to-be-saved
1569 (> gnus-number-of-articles-to-be-saved 1))
1570 (format "these %d articles"
1571 gnus-number-of-articles-to-be-saved)
1574 ;; Let the split methods have their say.
1576 ;; No split name was found.
1579 (concat prompt " (default "
1580 (file-name-nondirectory default-name) ") ")
1581 (file-name-directory default-name)
1583 ;; A single group name is returned.
1584 ((stringp split-name)
1586 (funcall function split-name headers
1587 (symbol-value variable)))
1589 (concat prompt " (default "
1590 (file-name-nondirectory default-name) ") ")
1591 (file-name-directory default-name)
1593 ;; A single split name was found
1594 ((= 1 (length split-name))
1595 (let* ((name (expand-file-name
1596 (car split-name) gnus-article-save-directory))
1597 (dir (cond ((file-directory-p name)
1598 (file-name-as-directory name))
1599 ((file-exists-p name) name)
1600 (t gnus-article-save-directory))))
1602 (concat prompt " (default " name ") ")
1604 ;; A list of splits was found.
1606 (setq split-name (nreverse split-name))
1608 (let ((file-name-history
1609 (nconc split-name file-name-history)))
1613 (concat prompt " (`M-p' for defaults) ")
1614 gnus-article-save-directory
1616 gnus-article-save-directory)))
1617 (car (push result file-name-history)))))))
1618 ;; Create the directory.
1619 (gnus-make-directory (file-name-directory file))
1620 ;; If we have read a directory, we append the default file name.
1621 (when (file-directory-p file)
1622 (setq file (concat (file-name-as-directory file)
1623 (file-name-nondirectory default-name))))
1624 ;; Possibly translate some characters.
1625 (nnheader-translate-file-chars file)))))
1626 (gnus-make-directory (file-name-directory result))
1627 (set variable result)))
1629 (defun gnus-article-archive-name (group)
1630 "Return the first instance of an \"Archive-name\" in the current buffer."
1631 (let ((case-fold-search t))
1632 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1633 (nnheader-concat gnus-article-save-directory
1634 (match-string 1)))))
1636 (defun gnus-article-nndoc-name (group)
1637 "If GROUP is an nndoc group, return the name of the parent group."
1638 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1639 (gnus-group-get-parameter group 'save-article-group)))
1641 (defun gnus-summary-save-in-rmail (&optional filename)
1642 "Append this article to Rmail file.
1643 Optional argument FILENAME specifies file name.
1644 Directory to save to is default to `gnus-article-save-directory'."
1645 (setq filename (gnus-read-save-file-name
1646 "Save %s in rmail file:" filename
1647 gnus-rmail-save-name gnus-newsgroup-name
1648 gnus-current-headers 'gnus-newsgroup-last-rmail))
1649 (gnus-eval-in-buffer-window gnus-save-article-buffer
1653 (rmail-output-to-rmail-file filename))))
1656 (defun gnus-summary-save-in-mail (&optional filename)
1657 "Append this article to Unix mail file.
1658 Optional argument FILENAME specifies file name.
1659 Directory to save to is default to `gnus-article-save-directory'."
1660 (setq filename (gnus-read-save-file-name
1661 "Save %s in Unix mail file:" filename
1662 gnus-mail-save-name gnus-newsgroup-name
1663 gnus-current-headers 'gnus-newsgroup-last-mail))
1664 (gnus-eval-in-buffer-window gnus-save-article-buffer
1668 (if (and (file-readable-p filename)
1669 (mail-file-babyl-p filename))
1670 (rmail-output-to-rmail-file filename t)
1671 (gnus-output-to-mail filename)))))
1674 (defun gnus-summary-save-in-file (&optional filename overwrite)
1675 "Append this article to file.
1676 Optional argument FILENAME specifies file name.
1677 Directory to save to is default to `gnus-article-save-directory'."
1678 (setq filename (gnus-read-save-file-name
1679 "Save %s in file:" filename
1680 gnus-file-save-name gnus-newsgroup-name
1681 gnus-current-headers 'gnus-newsgroup-last-file))
1682 (gnus-eval-in-buffer-window gnus-save-article-buffer
1686 (when (and overwrite
1687 (file-exists-p filename))
1688 (delete-file filename))
1689 (gnus-output-to-file filename))))
1692 (defun gnus-summary-write-to-file (&optional filename)
1693 "Write this article to a file.
1694 Optional argument FILENAME specifies file name.
1695 The directory to save in defaults to `gnus-article-save-directory'."
1696 (gnus-summary-save-in-file nil t))
1698 (defun gnus-summary-save-body-in-file (&optional filename)
1699 "Append this article body to a file.
1700 Optional argument FILENAME specifies file name.
1701 The directory to save in defaults to `gnus-article-save-directory'."
1702 (setq filename (gnus-read-save-file-name
1703 "Save %s body in file:" filename
1704 gnus-file-save-name gnus-newsgroup-name
1705 gnus-current-headers 'gnus-newsgroup-last-file))
1706 (gnus-eval-in-buffer-window gnus-save-article-buffer
1710 (goto-char (point-min))
1711 (when (search-forward "\n\n" nil t)
1712 (narrow-to-region (point) (point-max)))
1713 (gnus-output-to-file filename))))
1716 (defun gnus-summary-save-in-pipe (&optional command)
1717 "Pipe this article to subprocess."
1719 (cond ((eq command 'default)
1720 gnus-last-shell-command)
1724 "Shell command on %s: "
1725 (if (and gnus-number-of-articles-to-be-saved
1726 (> gnus-number-of-articles-to-be-saved 1))
1727 (format "these %d articles"
1728 gnus-number-of-articles-to-be-saved)
1730 gnus-last-shell-command))))
1731 (when (string-equal command "")
1732 (setq command gnus-last-shell-command))
1733 (gnus-eval-in-buffer-window gnus-article-buffer
1736 (shell-command-on-region (point-min) (point-max) command nil)))
1737 (setq gnus-last-shell-command command))
1739 ;;; Article file names when saving.
1741 (defun gnus-capitalize-newsgroup (newsgroup)
1742 "Capitalize NEWSGROUP name."
1743 (when (not (zerop (length newsgroup)))
1744 (concat (char-to-string (upcase (aref newsgroup 0)))
1745 (substring newsgroup 1))))
1747 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1748 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1749 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1750 Otherwise, it is like ~/News/news/group/num."
1753 (concat (if (gnus-use-long-file-name 'not-save)
1754 (gnus-capitalize-newsgroup newsgroup)
1755 (gnus-newsgroup-directory-form newsgroup))
1756 "/" (int-to-string (mail-header-number headers)))
1757 gnus-article-save-directory)))
1759 (string-equal (file-name-directory default)
1760 (file-name-directory last-file))
1761 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1763 (or last-file default))))
1765 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1766 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1767 If variable `gnus-use-long-file-name' is non-nil, it is
1768 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1771 (concat (if (gnus-use-long-file-name 'not-save)
1773 (gnus-newsgroup-directory-form newsgroup))
1774 "/" (int-to-string (mail-header-number headers)))
1775 gnus-article-save-directory)))
1777 (string-equal (file-name-directory default)
1778 (file-name-directory last-file))
1779 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1781 (or last-file default))))
1783 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1784 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1785 If variable `gnus-use-long-file-name' is non-nil, it is
1786 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1789 (if (gnus-use-long-file-name 'not-save)
1790 (gnus-capitalize-newsgroup newsgroup)
1791 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1792 gnus-article-save-directory)))
1794 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1795 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1796 If variable `gnus-use-long-file-name' is non-nil, it is
1797 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1800 (if (gnus-use-long-file-name 'not-save)
1802 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1803 gnus-article-save-directory)))
1810 (setq afunc (car func)
1813 gfunc (intern (format "gnus-%s" func))))
1815 (if (not (fboundp afunc))
1817 `(lambda (&optional interactive &rest args)
1818 ,(documentation afunc t)
1819 (interactive (list t))
1821 (set-buffer gnus-article-buffer)
1823 (call-interactively ',afunc)
1824 (apply ',afunc args))))))))
1825 '(article-hide-headers
1826 article-hide-boring-headers
1827 article-treat-overstrike
1828 (article-fill . gnus-article-word-wrap)
1830 article-display-x-face
1831 article-de-quoted-unreadable
1832 article-mime-decode-quoted-printable
1835 article-hide-signature
1836 article-remove-trailing-blank-lines
1837 article-strip-leading-blank-lines
1838 article-strip-multiple-blank-lines
1839 article-strip-leading-space
1840 article-strip-blank-lines
1841 article-strip-all-blank-lines
1843 article-date-iso8601
1844 article-date-original
1846 article-decode-mime-words
1850 article-treat-dumbquotes
1851 (article-show-all . gnus-article-show-all-headers))))
1854 ;;; Gnus article mode
1857 (put 'gnus-article-mode 'mode-class 'special)
1859 (gnus-define-keys gnus-article-mode-map
1860 " " gnus-article-goto-next-page
1861 "\177" gnus-article-goto-prev-page
1862 [delete] gnus-article-goto-prev-page
1863 "\C-c^" gnus-article-refer-article
1864 "h" gnus-article-show-summary
1865 "s" gnus-article-show-summary
1866 "\C-c\C-m" gnus-article-mail
1867 "?" gnus-article-describe-briefly
1868 gnus-mouse-2 gnus-article-push-button
1869 "\r" gnus-article-press-button
1870 "\t" gnus-article-next-button
1871 "\M-\t" gnus-article-prev-button
1872 "e" gnus-article-edit
1873 "<" beginning-of-buffer
1875 "\C-c\C-i" gnus-info-find-node
1878 "\C-d" gnus-article-read-summary-keys
1879 "\M-*" gnus-article-read-summary-keys
1880 "\M-#" gnus-article-read-summary-keys
1881 "\M-^" gnus-article-read-summary-keys
1882 "\M-g" gnus-article-read-summary-keys)
1884 (substitute-key-definition
1885 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1887 (defun gnus-article-make-menu-bar ()
1888 (gnus-turn-off-edit-menu 'article)
1889 (unless (boundp 'gnus-article-article-menu)
1891 gnus-article-article-menu gnus-article-mode-map ""
1893 ["Scroll forwards" gnus-article-goto-next-page t]
1894 ["Scroll backwards" gnus-article-goto-prev-page t]
1895 ["Show summary" gnus-article-show-summary t]
1896 ["Fetch Message-ID at point" gnus-article-refer-article t]
1897 ["Mail to address at point" gnus-article-mail t]
1898 ["Send a bug report" gnus-bug t]))
1901 gnus-article-treatment-menu gnus-article-mode-map ""
1903 ["Hide headers" gnus-article-hide-headers t]
1904 ["Hide signature" gnus-article-hide-signature t]
1905 ["Hide citation" gnus-article-hide-citation t]
1906 ["Treat overstrike" gnus-article-treat-overstrike t]
1907 ["Remove carriage return" gnus-article-remove-cr t]
1908 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1910 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1912 (when (boundp 'gnus-summary-post-menu)
1913 (define-key gnus-article-mode-map [menu-bar post]
1914 (cons "Post" gnus-summary-post-menu)))
1916 (gnus-run-hooks 'gnus-article-menu-hook)))
1918 (defun gnus-article-mode ()
1919 "Major mode for displaying an article.
1921 All normal editing commands are switched off.
1923 The following commands are available in addition to all summary mode
1925 \\<gnus-article-mode-map>
1926 \\[gnus-article-next-page]\t Scroll the article one page forwards
1927 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1928 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1929 \\[gnus-article-show-summary]\t Display the summary buffer
1930 \\[gnus-article-mail]\t Send a reply to the address near point
1931 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1932 \\[gnus-info-find-node]\t Go to the Gnus info node"
1934 (when (gnus-visual-p 'article-menu 'menu)
1935 (gnus-article-make-menu-bar))
1936 (gnus-simplify-mode-line)
1937 (setq mode-name "Article")
1938 (setq major-mode 'gnus-article-mode)
1939 (make-local-variable 'minor-mode-alist)
1940 (unless (assq 'gnus-show-mime minor-mode-alist)
1941 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1942 (use-local-map gnus-article-mode-map)
1943 (gnus-update-format-specifications nil 'article-mode)
1944 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1945 (make-local-variable 'gnus-page-broken)
1946 (make-local-variable 'gnus-button-marker-list)
1947 (make-local-variable 'gnus-article-current-summary)
1948 (gnus-set-default-directory)
1949 (buffer-disable-undo (current-buffer))
1950 (setq buffer-read-only t)
1951 (set-syntax-table gnus-article-mode-syntax-table)
1952 (mm-enable-multibyte)
1953 (gnus-run-hooks 'gnus-article-mode-hook))
1955 (defun gnus-article-setup-buffer ()
1956 "Initialize the article buffer."
1957 (let* ((name (if gnus-single-article-buffer "*Article*"
1958 (concat "*Article " gnus-newsgroup-name "*")))
1960 (progn (string-match "\\*Article" name)
1961 (concat " *Original Article"
1962 (substring name (match-end 0))))))
1963 (setq gnus-article-buffer name)
1964 (setq gnus-original-article-buffer original)
1965 ;; This might be a variable local to the summary buffer.
1966 (unless gnus-single-article-buffer
1968 (set-buffer gnus-summary-buffer)
1969 (setq gnus-article-buffer name)
1970 (setq gnus-original-article-buffer original)
1971 (gnus-set-global-variables)))
1972 ;; Init original article buffer.
1974 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1975 (mm-enable-multibyte)
1976 (setq major-mode 'gnus-original-article-mode)
1977 (make-local-variable 'gnus-original-article))
1978 (if (get-buffer name)
1981 (buffer-disable-undo (current-buffer))
1982 (setq buffer-read-only t)
1983 (unless (eq major-mode 'gnus-article-mode)
1984 (gnus-article-mode))
1987 (set-buffer (gnus-get-buffer-create name))
1989 (make-local-variable 'gnus-summary-buffer)
1990 (current-buffer)))))
1992 ;; Set article window start at LINE, where LINE is the number of lines
1993 ;; from the head of the article.
1994 (defun gnus-article-set-window-start (&optional line)
1996 (get-buffer-window gnus-article-buffer t)
1998 (set-buffer gnus-article-buffer)
1999 (goto-char (point-min))
2002 (gnus-message 6 "Moved to bookmark")
2003 (search-forward "\n\n" nil t)
2007 (defun gnus-article-prepare (article &optional all-headers header)
2008 "Prepare ARTICLE in article mode buffer.
2009 ARTICLE should either be an article number or a Message-ID.
2010 If ARTICLE is an id, HEADER should be the article headers.
2011 If ALL-HEADERS is non-nil, no headers are hidden."
2013 ;; Make sure we start in a summary buffer.
2014 (unless (eq major-mode 'gnus-summary-mode)
2015 (set-buffer gnus-summary-buffer))
2016 (setq gnus-summary-buffer (current-buffer))
2017 (let* ((gnus-article (if header (mail-header-number header) article))
2018 (summary-buffer (current-buffer))
2019 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2020 (group gnus-newsgroup-name)
2023 (gnus-article-setup-buffer)
2024 (set-buffer gnus-article-buffer)
2025 ;; Deactivate active regions.
2026 (when (and (boundp 'transient-mark-mode)
2027 transient-mark-mode)
2028 (setq mark-active nil))
2029 (if (not (setq result (let ((buffer-read-only nil))
2030 (gnus-request-article-this-buffer
2032 ;; There is no such article.
2034 (when (and (numberp article)
2035 (not (memq article gnus-newsgroup-sparse)))
2036 (setq gnus-article-current
2037 (cons gnus-newsgroup-name article))
2038 (set-buffer gnus-summary-buffer)
2039 (setq gnus-current-article article)
2040 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2042 (gnus-summary-set-agent-mark article)
2043 (message "Message marked for downloading"))
2044 (gnus-summary-mark-article article gnus-canceled-mark)
2045 (unless (memq article gnus-newsgroup-sparse)
2047 "No such article (may have expired or been canceled)")))))
2048 (if (or (eq result 'pseudo)
2049 (eq result 'nneething))
2052 (set-buffer summary-buffer)
2053 (push article gnus-newsgroup-history)
2054 (setq gnus-last-article gnus-current-article
2055 gnus-current-article 0
2056 gnus-current-headers nil
2057 gnus-article-current nil)
2058 (if (eq result 'nneething)
2059 (gnus-configure-windows 'summary)
2060 (gnus-configure-windows 'article))
2061 (gnus-set-global-variables))
2062 (gnus-set-mode-line 'article))
2063 ;; The result from the `request' was an actual article -
2064 ;; or at least some text that is now displayed in the
2066 (when (and (numberp article)
2067 (not (eq article gnus-current-article)))
2068 ;; Seems like a new article has been selected.
2069 ;; `gnus-current-article' must be an article number.
2071 (set-buffer summary-buffer)
2072 (push article gnus-newsgroup-history)
2073 (setq gnus-last-article gnus-current-article
2074 gnus-current-article article
2075 gnus-current-headers
2076 (gnus-summary-article-header gnus-current-article)
2077 gnus-article-current
2078 (cons gnus-newsgroup-name gnus-current-article))
2079 (unless (vectorp gnus-current-headers)
2080 (setq gnus-current-headers nil))
2081 (gnus-summary-goto-subject gnus-current-article)
2082 (when (gnus-summary-show-thread)
2083 ;; If the summary buffer really was folded, the
2084 ;; previous goto may not actually have gone to
2085 ;; the right article, but the thread root instead.
2087 (gnus-summary-goto-subject gnus-current-article))
2088 (gnus-run-hooks 'gnus-mark-article-hook)
2089 (gnus-set-mode-line 'summary)
2090 (when (gnus-visual-p 'article-highlight 'highlight)
2091 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2092 ;; Set the global newsgroup variables here.
2093 ;; Suggested by Jim Sisolak
2094 ;; <sisolak@trans4.neep.wisc.edu>.
2095 (gnus-set-global-variables)
2096 (setq gnus-have-all-headers
2097 (or all-headers gnus-show-all-headers))))
2098 (when (or (numberp article)
2100 ;; Hooks for getting information from the article.
2101 ;; This hook must be called before being narrowed.
2102 (let (buffer-read-only)
2103 (gnus-run-hooks 'gnus-tmp-internal-hook)
2104 (gnus-run-hooks 'gnus-article-prepare-hook)
2105 ;; Decode MIME message.
2106 (when gnus-show-mime
2107 (if (or (not gnus-strict-mime)
2108 (gnus-fetch-field "Mime-Version"))
2109 (let ((coding-system-for-write 'binary)
2110 (coding-system-for-read 'binary))
2111 (funcall gnus-show-mime-method))
2112 (funcall gnus-decode-encoded-word-method)))
2113 ;; Perform the article display hooks.
2114 (gnus-run-hooks 'gnus-article-display-hook))
2116 (goto-char (point-min))
2117 (setq gnus-page-broken
2118 (when gnus-break-pages
2119 (gnus-narrow-to-page)
2121 (gnus-set-mode-line 'article)
2122 (gnus-configure-windows 'article)
2123 (goto-char (point-min))
2124 (search-forward "\n\n" nil t)
2125 (set-window-point (get-buffer-window (current-buffer)) (point))
2128 (defun gnus-article-wash-status ()
2129 "Return a string which display status of article washing."
2131 (set-buffer gnus-article-buffer)
2132 (let ((cite (gnus-article-hidden-text-p 'cite))
2133 (headers (gnus-article-hidden-text-p 'headers))
2134 (boring (gnus-article-hidden-text-p 'boring-headers))
2135 (pgp (gnus-article-hidden-text-p 'pgp))
2136 (pem (gnus-article-hidden-text-p 'pem))
2137 (signature (gnus-article-hidden-text-p 'signature))
2138 (overstrike (gnus-article-hidden-text-p 'overstrike))
2139 (emphasis (gnus-article-hidden-text-p 'emphasis))
2140 (mime gnus-show-mime))
2141 (format "%c%c%c%c%c%c%c"
2143 (if (or headers boring) ?h ? )
2144 (if (or pgp pem) ?p ? )
2145 (if signature ?s ? )
2146 (if overstrike ?o ? )
2148 (if emphasis ?e ? )))))
2150 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2152 (defun gnus-article-maybe-hide-headers ()
2153 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2154 Provided for backwards compatibility."
2155 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2157 (gnus-article-hide-headers)))
2161 (defun gnus-output-to-file (file-name)
2162 "Append the current article to a file named FILE-NAME."
2163 (let ((artbuf (current-buffer)))
2165 (insert-buffer-substring artbuf)
2166 ;; Append newline at end of the buffer as separator, and then
2168 (goto-char (point-max))
2170 (append-to-file (point-min) (point-max) file-name)
2173 (defun gnus-narrow-to-page (&optional arg)
2174 "Narrow the article buffer to a page.
2175 If given a numerical ARG, move forward ARG pages."
2177 (setq arg (if arg (prefix-numeric-value arg) 0))
2179 (set-buffer gnus-article-buffer)
2180 (goto-char (point-min))
2182 ;; Remove any old next/prev buttons.
2183 (when (gnus-visual-p 'page-marker)
2184 (let ((buffer-read-only nil))
2185 (gnus-remove-text-with-property 'gnus-prev)
2186 (gnus-remove-text-with-property 'gnus-next)))
2189 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2191 (re-search-forward page-delimiter nil 'move arg)))
2192 (goto-char (match-end 0)))
2195 (if (re-search-forward page-delimiter nil 'move)
2198 (when (and (gnus-visual-p 'page-marker)
2199 (not (= (point-min) 1)))
2201 (goto-char (point-min))
2202 (gnus-insert-prev-page-button)))
2203 (when (and (gnus-visual-p 'page-marker)
2204 (< (+ (point-max) 2) (buffer-size)))
2206 (goto-char (point-max))
2207 (gnus-insert-next-page-button)))))
2209 ;; Article mode commands
2211 (defun gnus-article-goto-next-page ()
2212 "Show the next page of the article."
2214 (when (gnus-article-next-page)
2215 (goto-char (point-min))
2216 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2218 (defun gnus-article-goto-prev-page ()
2219 "Show the next page of the article."
2221 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2222 (gnus-article-prev-page nil)))
2224 (defun gnus-article-next-page (&optional lines)
2225 "Show the next page of the current article.
2226 If end of article, return non-nil. Otherwise return nil.
2227 Argument LINES specifies lines to be scrolled up."
2229 (move-to-window-line -1)
2232 (and (pos-visible-in-window-p) ;Not continuation line.
2234 ;; Nothing in this page.
2235 (if (or (not gnus-page-broken)
2238 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2240 (gnus-narrow-to-page 1) ;Go to next page.
2242 ;; More in this page.
2243 (let ((scroll-in-place nil))
2247 ;; Long lines may cause an end-of-buffer error.
2248 (goto-char (point-max)))))
2249 (move-to-window-line 0)
2252 (defun gnus-article-prev-page (&optional lines)
2253 "Show previous page of current article.
2254 Argument LINES specifies lines to be scrolled down."
2256 (move-to-window-line 0)
2257 (if (and gnus-page-broken
2259 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2261 (gnus-narrow-to-page -1) ;Go to previous page.
2262 (goto-char (point-max))
2264 (let ((scroll-in-place nil))
2268 (beginning-of-buffer
2269 (goto-char (point-min))))
2270 (move-to-window-line 0)))))
2272 (defun gnus-article-refer-article ()
2273 "Read article specified by message-id around point."
2275 (let ((point (point)))
2276 (search-forward ">" nil t) ;Move point to end of "<....>".
2277 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2278 (let ((message-id (match-string 1)))
2280 (set-buffer gnus-summary-buffer)
2281 (gnus-summary-refer-article message-id))
2283 (error "No references around point"))))
2285 (defun gnus-article-show-summary ()
2286 "Reconfigure windows to show summary buffer."
2288 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2289 (error "There is no summary buffer for this article buffer")
2290 (gnus-article-set-globals)
2291 (gnus-configure-windows 'article)
2292 (gnus-summary-goto-subject gnus-current-article)
2293 (gnus-summary-position-point)))
2295 (defun gnus-article-describe-briefly ()
2296 "Describe article mode commands briefly."
2299 (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")))
2301 (defun gnus-article-summary-command ()
2302 "Execute the last keystroke in the summary buffer."
2304 (let ((obuf (current-buffer))
2305 (owin (current-window-configuration))
2307 (switch-to-buffer gnus-article-current-summary 'norecord)
2308 (setq func (lookup-key (current-local-map) (this-command-keys)))
2309 (call-interactively func)
2311 (set-window-configuration owin)
2312 (set-window-point (get-buffer-window (current-buffer)) (point))))
2314 (defun gnus-article-summary-command-nosave ()
2315 "Execute the last keystroke in the summary buffer."
2318 (pop-to-buffer gnus-article-current-summary 'norecord)
2319 (setq func (lookup-key (current-local-map) (this-command-keys)))
2320 (call-interactively func)))
2322 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2323 "Read a summary buffer key sequence and execute it from the article buffer."
2326 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2327 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2328 "=" "^" "\M-^" "|"))
2334 '("n" "Gn" "p" "Gp"))
2337 (set-buffer gnus-article-current-summary)
2338 (let (gnus-pick-mode)
2339 (push (or key last-command-event) unread-command-events)
2340 (setq keys (read-key-sequence nil))))
2343 (if (or (member keys nosaves)
2344 (member keys nosave-but-article)
2345 (member keys nosave-in-article))
2347 (save-window-excursion
2348 (pop-to-buffer gnus-article-current-summary 'norecord)
2349 ;; We disable the pick minor mode commands.
2350 (let (gnus-pick-mode)
2351 (setq func (lookup-key (current-local-map) keys))))
2354 (unless (member keys nosave-in-article)
2355 (set-buffer gnus-article-current-summary))
2356 (call-interactively func)
2357 (setq new-sum-point (point)))
2358 (when (member keys nosave-but-article)
2359 (pop-to-buffer gnus-article-buffer 'norecord)))
2360 ;; These commands should restore window configuration.
2361 (let ((obuf (current-buffer))
2362 (owin (current-window-configuration))
2364 (summary gnus-article-current-summary)
2365 func in-buffer selected)
2366 (if not-restore-window
2367 (pop-to-buffer summary 'norecord)
2368 (switch-to-buffer summary 'norecord))
2369 (setq in-buffer (current-buffer))
2370 ;; We disable the pick minor mode commands.
2371 (if (setq func (let (gnus-pick-mode)
2372 (lookup-key (current-local-map) keys)))
2374 (call-interactively func)
2375 (setq new-sum-point (point)))
2377 (when (eq in-buffer (current-buffer))
2378 (setq selected (gnus-summary-select-article))
2380 (unless not-restore-window
2381 (set-window-configuration owin))
2382 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2383 (set-window-point (get-buffer-window (current-buffer))
2385 (let ((win (get-buffer-window gnus-article-current-summary)))
2387 (set-window-point win new-sum-point))))))))
2389 (defun gnus-article-hide (&optional arg force)
2390 "Hide all the gruft in the current article.
2391 This means that PGP stuff, signatures, cited text and (some)
2392 headers will be hidden.
2393 If given a prefix, show the hidden text instead."
2394 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2395 (gnus-article-hide-headers arg)
2396 (gnus-article-hide-pgp arg)
2397 (gnus-article-hide-citation-maybe arg force)
2398 (gnus-article-hide-signature arg))
2400 (defun gnus-article-maybe-highlight ()
2401 "Do some article highlighting if article highlighting is requested."
2402 (when (gnus-visual-p 'article-highlight 'highlight)
2403 (gnus-article-highlight-some)))
2405 (defun gnus-check-group-server ()
2406 ;; Make sure the connection to the server is alive.
2407 (unless (gnus-server-opened
2408 (gnus-find-method-for-group gnus-newsgroup-name))
2409 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2410 (gnus-request-group gnus-newsgroup-name t)))
2412 (defun gnus-request-article-this-buffer (article group)
2413 "Get an article and insert it into this buffer."
2414 (let (do-update-line sparse-header)
2418 (gnus-kill-all-overlays)
2419 (setq group (or group gnus-newsgroup-name))
2421 ;; Using `gnus-request-article' directly will insert the article into
2422 ;; `nntp-server-buffer' - so we'll save some time by not having to
2423 ;; copy it from the server buffer into the article buffer.
2425 ;; We only request an article by message-id when we do not have the
2426 ;; headers for it, so we'll have to get those.
2427 (when (stringp article)
2428 (let ((gnus-override-method gnus-refer-article-method))
2429 (gnus-read-header article)))
2431 ;; If the article number is negative, that means that this article
2432 ;; doesn't belong in this newsgroup (possibly), so we find its
2433 ;; message-id and request it by id instead of number.
2434 (when (and (numberp article)
2436 (get-buffer gnus-summary-buffer)
2437 (gnus-buffer-exists-p gnus-summary-buffer))
2439 (set-buffer gnus-summary-buffer)
2440 (let ((header (gnus-summary-article-header article)))
2443 ((memq article gnus-newsgroup-sparse)
2444 ;; This is a sparse gap article.
2445 (setq do-update-line article)
2446 (setq article (mail-header-id header))
2447 (let ((gnus-override-method gnus-refer-article-method))
2448 (setq sparse-header (gnus-read-header article)))
2449 (setq gnus-newsgroup-sparse
2450 (delq article gnus-newsgroup-sparse)))
2452 ;; It's a real article.
2453 (setq article (mail-header-id header)))
2455 ;; It is an extracted pseudo-article.
2456 (setq article 'pseudo)
2457 (gnus-request-pseudo-article header))))
2459 (let ((method (gnus-find-method-for-group
2460 gnus-newsgroup-name)))
2461 (when (and (eq (car method) 'nneething)
2464 (file-name-as-directory
2465 (or (cadr (assq 'nneething-address method))
2467 (mail-header-subject header))))
2468 (when (file-directory-p dir)
2469 (setq article 'nneething)
2470 (gnus-group-enter-directory dir))))))))
2473 ;; Refuse to select canceled articles.
2474 ((and (numberp article)
2476 (get-buffer gnus-summary-buffer)
2477 (gnus-buffer-exists-p gnus-summary-buffer)
2478 (eq (cdr (save-excursion
2479 (set-buffer gnus-summary-buffer)
2480 (assq article gnus-newsgroup-reads)))
2481 gnus-canceled-mark))
2483 ;; We first check `gnus-original-article-buffer'.
2484 ((and (get-buffer gnus-original-article-buffer)
2487 (set-buffer gnus-original-article-buffer)
2488 (and (equal (car gnus-original-article) group)
2489 (eq (cdr gnus-original-article) article))))
2490 (insert-buffer-substring gnus-original-article-buffer)
2492 ;; Check the backlog.
2493 ((and gnus-keep-backlog
2494 (gnus-backlog-request-article group article (current-buffer)))
2496 ;; Check asynchronous pre-fetch.
2497 ((gnus-async-request-fetched-article group article (current-buffer))
2498 (gnus-async-prefetch-next group article gnus-summary-buffer)
2499 (when (and (numberp article) gnus-keep-backlog)
2500 (gnus-backlog-enter-article group article (current-buffer)))
2503 ((and gnus-use-cache
2505 (gnus-cache-request-article article group))
2507 ;; Get the article and put into the article buffer.
2508 ((or (stringp article) (numberp article))
2509 (let ((gnus-override-method
2510 (and (stringp article) gnus-refer-article-method))
2511 (buffer-read-only nil))
2513 (gnus-kill-all-overlays)
2514 (gnus-check-group-server)
2515 (when (gnus-request-article article group (current-buffer))
2516 (when (numberp article)
2517 (gnus-async-prefetch-next group article gnus-summary-buffer)
2518 (when gnus-keep-backlog
2519 (gnus-backlog-enter-article
2520 group article (current-buffer))))
2525 ;; Associate this article with the current summary buffer.
2526 (setq gnus-article-current-summary gnus-summary-buffer)
2528 ;; Take the article from the original article buffer
2529 ;; and place it in the buffer it's supposed to be in.
2530 (when (and (get-buffer gnus-article-buffer)
2531 (equal (buffer-name (current-buffer))
2532 (buffer-name (get-buffer gnus-article-buffer))))
2534 (if (get-buffer gnus-original-article-buffer)
2535 (set-buffer gnus-original-article-buffer)
2536 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2537 (buffer-disable-undo (current-buffer))
2538 (setq major-mode 'gnus-original-article-mode)
2539 (setq buffer-read-only t))
2540 (let (buffer-read-only)
2542 (insert-buffer-substring gnus-article-buffer))
2543 (setq gnus-original-article (cons group article))))
2546 (run-hooks 'gnus-article-decode-hook)
2548 ;; Update sparse articles.
2549 (when (and do-update-line
2550 (or (numberp article)
2552 (let ((buf (current-buffer)))
2553 (set-buffer gnus-summary-buffer)
2554 (gnus-summary-update-article do-update-line sparse-header)
2555 (gnus-summary-goto-subject do-update-line nil t)
2556 (set-window-point (get-buffer-window (current-buffer) t)
2558 (set-buffer buf))))))
2564 (defcustom gnus-article-edit-mode-hook nil
2565 "Hook run in article edit mode buffers."
2566 :group 'gnus-article-various
2569 (defvar gnus-article-edit-done-function nil)
2571 (defvar gnus-article-edit-mode-map nil)
2573 (unless gnus-article-edit-mode-map
2574 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2576 (gnus-define-keys gnus-article-edit-mode-map
2577 "\C-c\C-c" gnus-article-edit-done
2578 "\C-c\C-k" gnus-article-edit-exit)
2580 (gnus-define-keys (gnus-article-edit-wash-map
2581 "\C-c\C-w" gnus-article-edit-mode-map)
2582 "f" gnus-article-edit-full-stops))
2584 (defun gnus-article-edit-mode ()
2585 "Major mode for editing articles.
2586 This is an extended text-mode.
2588 \\{gnus-article-edit-mode-map}"
2590 (setq major-mode 'gnus-article-edit-mode)
2591 (setq mode-name "Article Edit")
2592 (use-local-map gnus-article-edit-mode-map)
2593 (make-local-variable 'gnus-article-edit-done-function)
2594 (make-local-variable 'gnus-prev-winconf)
2595 (setq buffer-read-only nil)
2596 (buffer-enable-undo)
2598 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2600 (defun gnus-article-edit (&optional force)
2601 "Edit the current article.
2602 This will have permanent effect only in mail groups.
2603 If FORCE is non-nil, allow editing of articles even in read-only
2606 (when (and (not force)
2607 (gnus-group-read-only-p))
2608 (error "The current newsgroup does not support article editing"))
2609 (gnus-article-date-original)
2610 (gnus-article-edit-article
2611 `(lambda (no-highlight)
2612 (gnus-summary-edit-article-done
2613 ,(or (mail-header-references gnus-current-headers) "")
2614 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2616 (defun gnus-article-edit-article (exit-func)
2617 "Start editing the contents of the current article buffer."
2618 (let ((winconf (current-window-configuration)))
2619 (set-buffer gnus-article-buffer)
2620 (gnus-article-edit-mode)
2621 (gnus-article-delete-text-of-type 'annotation)
2622 (gnus-set-text-properties (point-min) (point-max) nil)
2623 (gnus-configure-windows 'edit-article)
2624 (setq gnus-article-edit-done-function exit-func)
2625 (setq gnus-prev-winconf winconf)
2626 (gnus-message 6 "C-c C-c to end edits")))
2628 (defun gnus-article-edit-done (&optional arg)
2629 "Update the article edits and exit."
2634 (goto-char (point-min))
2635 (when (search-forward "\n\n" nil 1)
2636 (let ((lines (count-lines (point) (point-max)))
2637 (length (- (point-max) (point)))
2638 (case-fold-search t)
2639 (body (copy-marker (point))))
2640 (goto-char (point-min))
2641 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2642 (delete-region (match-beginning 1) (match-end 1))
2643 (insert (number-to-string length)))
2644 (goto-char (point-min))
2645 (when (re-search-forward
2646 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2647 (delete-region (match-beginning 1) (match-end 1))
2648 (insert (number-to-string length)))
2649 (goto-char (point-min))
2650 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2651 (delete-region (match-beginning 1) (match-end 1))
2652 (insert (number-to-string lines)))))))
2653 (let ((func gnus-article-edit-done-function)
2654 (buf (current-buffer))
2655 (start (window-start)))
2656 (gnus-article-edit-exit)
2659 (let ((buffer-read-only nil))
2660 (funcall func arg)))
2662 (set-window-start (get-buffer-window buf) start)
2663 (set-window-point (get-buffer-window buf) (point))))
2665 (defun gnus-article-edit-exit ()
2666 "Exit the article editing without updating."
2668 ;; We remove all text props from the article buffer.
2669 (let ((buf (format "%s" (buffer-string)))
2670 (curbuf (current-buffer))
2672 (window-start (window-start)))
2675 (let ((winconf gnus-prev-winconf))
2677 ;; The cache and backlog have to be flushed somewhat.
2678 (when gnus-use-cache
2679 (gnus-cache-update-article
2680 (car gnus-article-current) (cdr gnus-article-current)))
2681 (when gnus-keep-backlog
2682 (gnus-backlog-remove-article
2683 (car gnus-article-current) (cdr gnus-article-current)))
2684 ;; Flush original article as well.
2686 (when (get-buffer gnus-original-article-buffer)
2687 (set-buffer gnus-original-article-buffer)
2688 (setq gnus-original-article nil)))
2689 (set-window-configuration winconf)
2690 ;; Tippy-toe some to make sure that point remains where it was.
2691 (let ((buf (current-buffer)))
2693 (set-window-start (get-buffer-window (current-buffer)) window-start)
2695 (set-buffer buf)))))
2697 (defun gnus-article-edit-full-stops ()
2698 "Interactively repair spacing at end of sentences."
2701 (goto-char (point-min))
2702 (search-forward-regexp "^$" nil t)
2703 (let ((case-fold-search nil))
2704 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2707 ;;; Article highlights
2710 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2712 ;;; Internal Variables:
2714 (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\\)"
2715 "Regular expression that matches URLs."
2716 :group 'gnus-article-buttons
2719 (defcustom gnus-button-alist
2720 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2721 gnus-button-message-id 2)
2722 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2723 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2725 gnus-button-fetch-group 4)
2726 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2727 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2728 t gnus-button-message-id 3)
2729 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2730 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2731 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2732 ;; This is how URLs _should_ be embedded in text...
2733 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2735 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2736 "*Alist of regexps matching buttons in article bodies.
2738 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2739 REGEXP: is the string matching text around the button,
2740 BUTTON: is the number of the regexp grouping actually matching the button,
2741 FORM: is a lisp expression which must eval to true for the button to
2743 CALLBACK: is the function to call when the user push this button, and each
2744 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2746 CALLBACK can also be a variable, in that case the value of that
2747 variable it the real callback function."
2748 :group 'gnus-article-buttons
2749 :type '(repeat (list regexp
2750 (integer :tag "Button")
2752 (function :tag "Callback")
2755 (integer :tag "Regexp group")))))
2757 (defcustom gnus-header-button-alist
2758 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2759 0 t gnus-button-message-id 0)
2760 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2761 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2762 0 t gnus-button-mailto 0)
2763 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2764 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2765 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2766 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2767 gnus-button-message-id 3))
2768 "*Alist of headers and regexps to match buttons in article heads.
2770 This alist is very similar to `gnus-button-alist', except that each
2771 alist has an additional HEADER element first in each entry:
2773 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2775 HEADER is a regexp to match a header. For a fuller explanation, see
2776 `gnus-button-alist'."
2777 :group 'gnus-article-buttons
2778 :group 'gnus-article-headers
2779 :type '(repeat (list (regexp :tag "Header")
2781 (integer :tag "Button")
2783 (function :tag "Callback")
2786 (integer :tag "Regexp group")))))
2788 (defvar gnus-button-regexp nil)
2789 (defvar gnus-button-marker-list nil)
2790 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2792 (defvar gnus-button-last nil)
2793 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2797 (defun gnus-article-push-button (event)
2798 "Check text under the mouse pointer for a callback function.
2799 If the text under the mouse pointer has a `gnus-callback' property,
2800 call it with the value of the `gnus-data' text property."
2802 (set-buffer (window-buffer (posn-window (event-start event))))
2803 (let* ((pos (posn-point (event-start event)))
2804 (data (get-text-property pos 'gnus-data))
2805 (fun (get-text-property pos 'gnus-callback)))
2808 (funcall fun data))))
2810 (defun gnus-article-press-button ()
2811 "Check text at point for a callback function.
2812 If the text at point has a `gnus-callback' property,
2813 call it with the value of the `gnus-data' text property."
2815 (let* ((data (get-text-property (point) 'gnus-data))
2816 (fun (get-text-property (point) 'gnus-callback)))
2818 (funcall fun data))))
2820 (defun gnus-article-prev-button (n)
2821 "Move point to N buttons backward.
2822 If N is negative, move forward instead."
2824 (gnus-article-next-button (- n)))
2826 (defun gnus-article-next-button (n)
2827 "Move point to N buttons forward.
2828 If N is negative, move backward instead."
2830 (let ((function (if (< n 0) 'previous-single-property-change
2831 'next-single-property-change))
2832 (inhibit-point-motion-hooks t)
2834 (limit (if (< n 0) (point-min) (point-max))))
2836 (while (and (not (= limit (point)))
2838 ;; Skip past the current button.
2839 (when (get-text-property (point) 'gnus-callback)
2840 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2841 ;; Go to the next (or previous) button.
2842 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2843 ;; Put point at the start of the button.
2844 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2845 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2846 ;; Skip past intangible buttons.
2847 (when (get-text-property (point) 'intangible)
2851 (gnus-message 5 "No more buttons"))
2854 (defun gnus-article-highlight (&optional force)
2855 "Highlight current article.
2856 This function calls `gnus-article-highlight-headers',
2857 `gnus-article-highlight-citation',
2858 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2859 do the highlighting. See the documentation for those functions."
2860 (interactive (list 'force))
2861 (gnus-article-highlight-headers)
2862 (gnus-article-highlight-citation force)
2863 (gnus-article-highlight-signature)
2864 (gnus-article-add-buttons force)
2865 (gnus-article-add-buttons-to-head))
2867 (defun gnus-article-highlight-some (&optional force)
2868 "Highlight current article.
2869 This function calls `gnus-article-highlight-headers',
2870 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2871 do the highlighting. See the documentation for those functions."
2872 (interactive (list 'force))
2873 (gnus-article-highlight-headers)
2874 (gnus-article-highlight-signature)
2875 (gnus-article-add-buttons))
2877 (defun gnus-article-highlight-headers ()
2878 "Highlight article headers as specified by `gnus-header-face-alist'."
2881 (set-buffer gnus-article-buffer)
2883 (let ((alist gnus-header-face-alist)
2884 (buffer-read-only nil)
2885 (case-fold-search t)
2886 (inhibit-point-motion-hooks t)
2887 entry regexp header-face field-face from hpoints fpoints)
2888 (message-narrow-to-head)
2889 (while (setq entry (pop alist))
2890 (goto-char (point-min))
2891 (setq regexp (concat "^\\("
2892 (if (string-equal "" (nth 0 entry))
2896 header-face (nth 1 entry)
2897 field-face (nth 2 entry))
2898 (while (and (re-search-forward regexp nil t)
2902 (unless (search-forward ":" nil t)
2904 (when (and header-face
2905 (not (memq (point) hpoints)))
2906 (push (point) hpoints)
2907 (gnus-put-text-property from (point) 'face header-face))
2908 (when (and field-face
2909 (not (memq (setq from (point)) fpoints)))
2911 (if (re-search-forward "^[^ \t]" nil t)
2913 (goto-char (point-max)))
2914 (gnus-put-text-property from (point) 'face field-face))))))))
2916 (defun gnus-article-highlight-signature ()
2917 "Highlight the signature in an article.
2918 It does this by highlighting everything after
2919 `gnus-signature-separator' using `gnus-signature-face'."
2922 (set-buffer gnus-article-buffer)
2923 (let ((buffer-read-only nil)
2924 (inhibit-point-motion-hooks t))
2926 (when (and gnus-signature-face
2927 (gnus-article-narrow-to-signature))
2928 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2929 'face gnus-signature-face)
2931 (gnus-article-search-signature)
2932 (let ((start (match-beginning 0))
2933 (end (set-marker (make-marker) (1+ (match-end 0)))))
2934 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2937 (defun gnus-button-in-region-p (b e prop)
2938 "Say whether PROP exists in the region."
2939 (text-property-not-all b e prop nil))
2941 (defun gnus-article-add-buttons (&optional force)
2942 "Find external references in the article and make buttons of them.
2943 \"External references\" are things like Message-IDs and URLs, as
2944 specified by `gnus-button-alist'."
2945 (interactive (list 'force))
2947 (set-buffer gnus-article-buffer)
2948 (let ((buffer-read-only nil)
2949 (inhibit-point-motion-hooks t)
2950 (case-fold-search t)
2951 (alist gnus-button-alist)
2953 ;; Remove all old markers.
2955 (while (setq marker (pop gnus-button-marker-list))
2957 (when (setq entry (gnus-button-entry))
2958 (put-text-property (match-beginning (nth 1 entry))
2959 (match-end (nth 1 entry))
2960 'gnus-callback nil))
2961 (set-marker marker nil)))
2962 ;; We skip the headers.
2963 (goto-char (point-min))
2964 (unless (search-forward "\n\n" nil t)
2965 (goto-char (point-max)))
2967 (while (setq entry (pop alist))
2968 (setq regexp (car entry))
2970 (while (re-search-forward regexp nil t)
2971 (let* ((start (and entry (match-beginning (nth 1 entry))))
2972 (end (and entry (match-end (nth 1 entry))))
2973 (from (match-beginning 0)))
2974 (when (and (or (eq t (nth 2 entry))
2975 (eval (nth 2 entry)))
2976 (not (gnus-button-in-region-p
2977 start end 'gnus-callback)))
2978 ;; That optional form returned non-nil, so we add the
2980 (gnus-article-add-button
2981 start end 'gnus-button-push
2982 (car (push (set-marker (make-marker) from)
2983 gnus-button-marker-list))))))))))
2985 ;; Add buttons to the head of an article.
2986 (defun gnus-article-add-buttons-to-head ()
2987 "Add buttons to the head of the article."
2990 (set-buffer gnus-article-buffer)
2991 (let ((buffer-read-only nil)
2992 (inhibit-point-motion-hooks t)
2993 (case-fold-search t)
2994 (alist gnus-header-button-alist)
2996 (nnheader-narrow-to-headers)
2998 ;; Each alist entry.
2999 (setq entry (car alist)
3001 (goto-char (point-min))
3002 (while (re-search-forward (car entry) nil t)
3003 ;; Each header matching the entry.
3004 (setq beg (match-beginning 0))
3005 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3006 (match-beginning 0))
3009 (while (re-search-forward (nth 1 entry) end t)
3010 ;; Each match within a header.
3011 (let* ((entry (cdr entry))
3012 (start (match-beginning (nth 1 entry)))
3013 (end (match-end (nth 1 entry)))
3014 (form (nth 2 entry)))
3015 (goto-char (match-end 0))
3017 (gnus-article-add-button
3018 start end (nth 3 entry)
3019 (buffer-substring (match-beginning (nth 4 entry))
3020 (match-end (nth 4 entry)))))))
3024 ;;; External functions:
3026 (defun gnus-article-add-button (from to fun &optional data)
3027 "Create a button between FROM and TO with callback FUN and data DATA."
3028 (when gnus-article-button-face
3029 (gnus-overlay-put (gnus-make-overlay from to)
3030 'face gnus-article-button-face))
3031 (gnus-add-text-properties
3033 (nconc (and gnus-article-mouse-face
3034 (list gnus-mouse-face-prop gnus-article-mouse-face))
3035 (list 'gnus-callback fun)
3036 (and data (list 'gnus-data data)))))
3038 ;;; Internal functions:
3040 (defun gnus-article-set-globals ()
3042 (set-buffer gnus-summary-buffer)
3043 (gnus-set-global-variables)))
3045 (defun gnus-signature-toggle (end)
3047 (set-buffer gnus-article-buffer)
3048 (let ((buffer-read-only nil)
3049 (inhibit-point-motion-hooks t))
3050 (if (get-text-property end 'invisible)
3051 (gnus-article-unhide-text end (point-max))
3052 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3054 (defun gnus-button-entry ()
3055 ;; Return the first entry in `gnus-button-alist' matching this place.
3056 (let ((alist gnus-button-alist)
3059 (setq entry (pop alist))
3060 (if (looking-at (car entry))
3065 (defun gnus-button-push (marker)
3066 ;; Push button starting at MARKER.
3068 (set-buffer gnus-article-buffer)
3070 (let* ((entry (gnus-button-entry))
3071 (inhibit-point-motion-hooks t)
3073 (args (mapcar (lambda (group)
3074 (let ((string (match-string group)))
3075 (gnus-set-text-properties
3076 0 (length string) nil string)
3083 (fboundp (symbol-value fun)))
3084 (apply (symbol-value fun) args))
3086 (gnus-message 1 "You must define `%S' to use this button"
3087 (cons fun args)))))))
3089 (defun gnus-button-message-id (message-id)
3092 (set-buffer gnus-summary-buffer)
3093 (gnus-summary-refer-article message-id)))
3095 (defun gnus-button-fetch-group (address)
3096 "Fetch GROUP specified by ADDRESS."
3097 (if (not (string-match "[:/]" address))
3098 ;; This is just a simple group url.
3099 (gnus-group-read-ephemeral-group address gnus-select-method)
3100 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3102 (error "Can't parse %s" address)
3103 (gnus-group-read-ephemeral-group
3104 (match-string 4 address)
3105 `(nntp ,(match-string 1 address)
3106 (nntp-address ,(match-string 1 address))
3107 (nntp-port-number ,(if (match-end 3)
3108 (match-string 3 address)
3111 (defun gnus-url-parse-query-string (query &optional downcase)
3112 (let (retval pairs cur key val)
3113 (setq pairs (split-string query "&"))
3115 (setq cur (car pairs)
3117 (if (not (string-match "=" cur))
3119 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3120 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3122 (setq key (downcase key)))
3123 (setq cur (assoc key retval))
3125 (setcdr cur (cons val (cdr cur)))
3126 (setq retval (cons (list key val) retval)))))
3129 (defun gnus-url-unhex (x)
3136 (defun gnus-url-unhex-string (str &optional allow-newlines)
3137 "Remove %XXX embedded spaces, etc in a url.
3138 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3139 decoding of carriage returns and line feeds in the string, which is normally
3140 forbidden in URL encoding."
3141 (setq str (or str ""))
3143 (case-fold-search t))
3144 (while (string-match "%[0-9a-f][0-9a-f]" str)
3145 (let* ((start (match-beginning 0))
3146 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3148 (gnus-url-unhex (elt str (+ start 2))))))
3150 tmp (substring str 0 start)
3153 (char-to-string code))
3154 ((or (= code ?\n) (= code ?\r))
3156 (t (char-to-string code))))
3157 str (substring str (match-end 0)))))
3158 (setq tmp (concat tmp str))
3161 (defun gnus-url-mailto (url)
3162 ;; Send mail to someone
3163 (when (string-match "mailto:/*\\(.*\\)" url)
3164 (setq url (substring url (match-beginning 1) nil)))
3165 (let (to args subject func)
3166 (if (string-match (regexp-quote "?") url)
3167 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3168 args (gnus-url-parse-query-string
3169 (substring url (match-end 0) nil) t))
3170 (setq to (gnus-url-unhex-string url)))
3171 (setq args (cons (list "to" to) args)
3172 subject (cdr-safe (assoc "subject" args)))
3175 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3178 (message-position-on-field (caar args)))
3179 (insert (mapconcat 'identity (cdar args) ", "))
3180 (setq args (cdr args)))
3183 (message-goto-subject))))
3185 (defun gnus-button-mailto (address)
3187 (set-buffer (gnus-copy-article-buffer))
3188 (message-reply address))
3190 (defun gnus-button-reply (address)
3191 ;; Reply to ADDRESS.
3192 (message-reply address))
3194 (defun gnus-button-url (address)
3196 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3197 (if (listp browse-url-browser-function)
3198 (browse-url address)
3199 (funcall browse-url-browser-function address)))
3201 (defun gnus-button-embedded-url (address)
3203 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3204 (if (listp browse-url-browser-function)
3205 (browse-url (gnus-strip-whitespace address))
3206 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3208 ;;; Next/prev buttons in the article buffer.
3210 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3211 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3213 (defvar gnus-prev-page-map nil)
3214 (unless gnus-prev-page-map
3215 (setq gnus-prev-page-map (make-sparse-keymap))
3216 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3217 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3219 (defun gnus-insert-prev-page-button ()
3220 (let ((buffer-read-only nil))
3222 gnus-prev-page-line-format nil
3223 `(gnus-prev t local-map ,gnus-prev-page-map
3224 gnus-callback gnus-article-button-prev-page
3225 gnus-type annotation))))
3227 (defvar gnus-next-page-map nil)
3228 (unless gnus-next-page-map
3229 (setq gnus-next-page-map (make-keymap))
3230 (suppress-keymap gnus-prev-page-map)
3231 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3232 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3234 (defun gnus-button-next-page ()
3235 "Go to the next page."
3237 (let ((win (selected-window)))
3238 (select-window (get-buffer-window gnus-article-buffer t))
3239 (gnus-article-next-page)
3240 (select-window win)))
3242 (defun gnus-button-prev-page ()
3243 "Go to the prev page."
3245 (let ((win (selected-window)))
3246 (select-window (get-buffer-window gnus-article-buffer t))
3247 (gnus-article-prev-page)
3248 (select-window win)))
3250 (defun gnus-insert-next-page-button ()
3251 (let ((buffer-read-only nil))
3252 (gnus-eval-format gnus-next-page-line-format nil
3254 t local-map ,gnus-next-page-map
3255 gnus-callback gnus-article-button-next-page
3256 gnus-type annotation))))
3258 (defun gnus-article-button-next-page (arg)
3259 "Go to the next page."
3261 (let ((win (selected-window)))
3262 (select-window (get-buffer-window gnus-article-buffer t))
3263 (gnus-article-next-page)
3264 (select-window win)))
3266 (defun gnus-article-button-prev-page (arg)
3267 "Go to the prev page."
3269 (let ((win (selected-window)))
3270 (select-window (get-buffer-window gnus-article-buffer t))
3271 (gnus-article-prev-page)
3272 (select-window win)))
3278 (run-hooks 'gnus-art-load-hook)
3280 ;;; gnus-art.el ends here