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 'timezone-make-date-arpa-standard "timezone")
277 (autoload 'mail-extract-address-components "mail-extr"))
279 (defcustom gnus-save-all-headers t
280 "*If non-nil, don't remove any headers before saving."
281 :group 'gnus-article-saving
284 (defcustom gnus-prompt-before-saving 'always
285 "*This variable says how much prompting is to be done when saving articles.
286 If it is nil, no prompting will be done, and the articles will be
287 saved to the default files. If this variable is `always', each and
288 every article that is saved will be preceded by a prompt, even when
289 saving large batches of articles. If this variable is neither nil not
290 `always', there the user will be prompted once for a file name for
291 each invocation of the saving commands."
292 :group 'gnus-article-saving
293 :type '(choice (item always)
294 (item :tag "never" nil)
295 (sexp :tag "once" :format "%t\n" :value t)))
297 (defcustom gnus-saved-headers gnus-visible-headers
298 "Headers to keep if `gnus-save-all-headers' is nil.
299 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
300 If that variable is nil, however, all headers that match this regexp
301 will be kept while the rest will be deleted before saving."
302 :group 'gnus-article-saving
305 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
306 "A function to save articles in your favourite format.
307 The function must be interactively callable (in other words, it must
308 be an Emacs command).
310 Gnus provides the following functions:
312 * gnus-summary-save-in-rmail (Rmail format)
313 * gnus-summary-save-in-mail (Unix mail format)
314 * gnus-summary-save-in-folder (MH folder)
315 * gnus-summary-save-in-file (article format)
316 * gnus-summary-save-in-vm (use VM's folder format)
317 * gnus-summary-write-to-file (article format -- overwrite)."
318 :group 'gnus-article-saving
319 :type '(radio (function-item gnus-summary-save-in-rmail)
320 (function-item gnus-summary-save-in-mail)
321 (function-item gnus-summary-save-in-folder)
322 (function-item gnus-summary-save-in-file)
323 (function-item gnus-summary-save-in-vm)
324 (function-item gnus-summary-write-to-file)))
326 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
327 "A function generating a file name to save articles in Rmail format.
328 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
329 :group 'gnus-article-saving
332 (defcustom gnus-mail-save-name 'gnus-plain-save-name
333 "A function generating a file name to save articles in Unix mail format.
334 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
335 :group 'gnus-article-saving
338 (defcustom gnus-folder-save-name 'gnus-folder-save-name
339 "A function generating a file name to save articles in MH folder.
340 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
341 :group 'gnus-article-saving
344 (defcustom gnus-file-save-name 'gnus-numeric-save-name
345 "A function generating a file name to save articles in article format.
346 The function is called with NEWSGROUP, HEADERS, and optional
348 :group 'gnus-article-saving
351 (defcustom gnus-split-methods
352 '((gnus-article-archive-name)
353 (gnus-article-nndoc-name))
354 "*Variable used to suggest where articles are to be saved.
355 For instance, if you would like to save articles related to Gnus in
356 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
357 you could set this variable to something like:
359 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
360 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
362 This variable is an alist where the where the key is the match and the
363 value is a list of possible files to save in if the match is non-nil.
365 If the match is a string, it is used as a regexp match on the
366 article. If the match is a symbol, that symbol will be funcalled
367 from the buffer of the article to be saved with the newsgroup as the
368 parameter. If it is a list, it will be evaled in the same buffer.
370 If this form or function returns a string, this string will be used as
371 a possible file name; and if it returns a non-nil list, that list will
372 be used as possible file names."
373 :group 'gnus-article-saving
374 :type '(repeat (choice (list :value (fun) function)
375 (cons :value ("" "") regexp (repeat string))
378 (defcustom gnus-strict-mime t
379 "*If nil, MIME-decode even if there is no Mime-Version header."
380 :group 'gnus-article-mime
383 (defcustom gnus-show-mime-method 'metamail-buffer
384 "Function to process a MIME message.
385 The function is called from the article buffer."
386 :group 'gnus-article-mime
389 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
390 "*Function to decode MIME encoded words.
391 The function is called from the article buffer."
392 :group 'gnus-article-mime
395 (defcustom gnus-page-delimiter "^\^L"
396 "*Regexp describing what to use as article page delimiters.
397 The default value is \"^\^L\", which is a form linefeed at the
398 beginning of a line."
400 :group 'gnus-article-various)
402 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
403 "*The format specification for the article mode line.
404 See `gnus-summary-mode-line-format' for a closer description."
406 :group 'gnus-article-various)
408 (defcustom gnus-article-mode-hook nil
409 "*A hook for Gnus article mode."
411 :group 'gnus-article-various)
413 (defcustom gnus-article-menu-hook nil
414 "*Hook run after the creation of the article mode menu."
416 :group 'gnus-article-various)
418 (defcustom gnus-article-prepare-hook nil
419 "*A hook called after an article has been prepared in the article buffer.
420 If you want to run a special decoding program like nkf, use this hook."
422 :group 'gnus-article-various)
424 (defcustom gnus-article-hide-pgp-hook nil
425 "*A hook called after successfully hiding a PGP signature."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-button-face 'bold
430 "Face used for highlighting buttons in the article buffer.
432 An article button is a piece of text that you can activate by pressing
433 `RET' or `mouse-2' above it."
435 :group 'gnus-article-buttons)
437 (defcustom gnus-article-mouse-face 'highlight
438 "Face used for mouse highlighting in the article buffer.
440 Article buttons will be displayed in this face when the cursor is
443 :group 'gnus-article-buttons)
445 (defcustom gnus-signature-face 'gnus-signature-face
446 "Face used for highlighting a signature in the article buffer.
447 Obsolete; use the face `gnus-signature-face' for customizations instead."
449 :group 'gnus-article-highlight
450 :group 'gnus-article-signature)
452 (defface gnus-signature-face
455 "Face used for highlighting a signature in the article buffer."
456 :group 'gnus-article-highlight
457 :group 'gnus-article-signature)
459 (defface gnus-header-from-face
462 (:foreground "spring green"))
465 (:foreground "red3"))
468 "Face used for displaying from headers."
469 :group 'gnus-article-headers
470 :group 'gnus-article-highlight)
472 (defface gnus-header-subject-face
475 (:foreground "SeaGreen3"))
478 (:foreground "red4"))
480 (:bold t :italic t)))
481 "Face used for displaying subject headers."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-newsgroups-face
488 (:foreground "yellow" :italic t))
491 (:foreground "MidnightBlue" :italic t))
494 "Face used for displaying newsgroups headers."
495 :group 'gnus-article-headers
496 :group 'gnus-article-highlight)
498 (defface gnus-header-name-face
501 (:foreground "SeaGreen"))
504 (:foreground "maroon"))
507 "Face used for displaying header names."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-content-face
514 (:foreground "forest green" :italic t))
517 (:foreground "indianred4" :italic t))
519 (:italic t))) "Face used for displaying header content."
520 :group 'gnus-article-headers
521 :group 'gnus-article-highlight)
523 (defcustom gnus-header-face-alist
524 '(("From" nil gnus-header-from-face)
525 ("Subject" nil gnus-header-subject-face)
526 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
527 ("" gnus-header-name-face gnus-header-content-face))
528 "*Controls highlighting of article header.
530 An alist of the form (HEADER NAME CONTENT).
532 HEADER is a regular expression which should match the name of an
533 header header and NAME and CONTENT are either face names or nil.
535 The name of each header field will be displayed using the face
536 specified by the first element in the list where HEADER match the
537 header name and NAME is non-nil. Similarly, the content will be
538 displayed by the first non-nil matching CONTENT face."
539 :group 'gnus-article-headers
540 :group 'gnus-article-highlight
541 :type '(repeat (list (regexp :tag "Header")
543 (item :tag "skip" nil)
544 (face :value default))
545 (choice :tag "Content"
546 (item :tag "skip" nil)
547 (face :value default)))))
549 ;;; Internal variables
551 (defvar article-lapsed-timer nil)
552 (defvar gnus-article-current-summary nil)
554 (defvar gnus-article-mode-syntax-table
555 (let ((table (copy-syntax-table text-mode-syntax-table)))
556 (modify-syntax-entry ?- "w" table)
557 (modify-syntax-entry ?> ")" table)
558 (modify-syntax-entry ?< "(" table)
560 "Syntax table used in article mode buffers.
561 Initialized from `text-mode-syntax-table.")
563 (defvar gnus-save-article-buffer nil)
565 (defvar gnus-article-mode-line-format-alist
566 (nconc '((?w (gnus-article-wash-status) ?s))
567 gnus-summary-mode-line-format-alist))
569 (defvar gnus-number-of-articles-to-be-saved nil)
571 (defvar gnus-inhibit-hiding nil)
573 (defsubst gnus-article-hide-text (b e props)
574 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
575 (add-text-properties b e props)
576 (when (memq 'intangible props)
578 (max (1- b) (point-min))
579 b 'intangible (cddr (memq 'intangible props)))))
581 (defsubst gnus-article-unhide-text (b e)
582 "Remove hidden text properties from region between B and E."
583 (remove-text-properties b e gnus-hidden-properties)
584 (when (memq 'intangible gnus-hidden-properties)
585 (put-text-property (max (1- b) (point-min))
588 (defun gnus-article-hide-text-type (b e type)
589 "Hide text of TYPE between B and E."
590 (gnus-article-hide-text
591 b e (cons 'article-type (cons type gnus-hidden-properties))))
593 (defun gnus-article-unhide-text-type (b e type)
594 "Unhide text of TYPE between B and E."
595 (remove-text-properties
596 b e (cons 'article-type (cons type gnus-hidden-properties)))
597 (when (memq 'intangible gnus-hidden-properties)
598 (put-text-property (max (1- b) (point-min))
601 (defun gnus-article-hide-text-of-type (type)
602 "Hide text of TYPE in the current buffer."
604 (let ((b (point-min))
606 (while (setq b (text-property-any b e 'article-type type))
607 (add-text-properties b (incf b) gnus-hidden-properties)))))
609 (defun gnus-article-delete-text-of-type (type)
610 "Delete text of TYPE in the current buffer."
612 (let ((b (point-min)))
613 (while (setq b (text-property-any b (point-max) 'article-type type))
615 b (or (text-property-not-all b (point-max) 'article-type type)
618 (defun gnus-article-delete-invisible-text ()
619 "Delete all invisible text in the current buffer."
621 (let ((b (point-min)))
622 (while (setq b (text-property-any b (point-max) 'invisible t))
624 b (or (text-property-not-all b (point-max) 'invisible t)
627 (defun gnus-article-text-type-exists-p (type)
628 "Say whether any text of type TYPE exists in the buffer."
629 (text-property-any (point-min) (point-max) 'article-type type))
631 (defsubst gnus-article-header-rank ()
632 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
633 (let ((list gnus-sorted-header-list)
636 (when (looking-at (car list))
638 (setq list (cdr list))
642 (defun article-hide-headers (&optional arg delete)
643 "Toggle whether to hide unwanted headers and possibly sort them as well.
644 If given a negative prefix, always show; if given a positive prefix,
646 (interactive (gnus-article-hidden-arg))
648 (if (gnus-article-check-hidden-text 'headers arg)
649 ;; Show boring headers as well.
650 (gnus-article-show-hidden-text 'boring-headers)
651 ;; This function might be inhibited.
652 (unless gnus-inhibit-hiding
655 (let ((buffer-read-only nil)
657 (props (nconc (list 'article-type 'headers)
658 gnus-hidden-properties))
659 (max (1+ (length gnus-sorted-header-list)))
660 (ignored (when (not gnus-visible-headers)
661 (cond ((stringp gnus-ignored-headers)
662 gnus-ignored-headers)
663 ((listp gnus-ignored-headers)
664 (mapconcat 'identity gnus-ignored-headers
667 (cond ((stringp gnus-visible-headers)
668 gnus-visible-headers)
669 ((and gnus-visible-headers
670 (listp gnus-visible-headers))
671 (mapconcat 'identity gnus-visible-headers "\\|"))))
672 (inhibit-point-motion-hooks t)
674 ;; First we narrow to just the headers.
676 (goto-char (point-min))
677 ;; Hide any "From " lines at the beginning of (mail) articles.
678 (while (looking-at "From ")
682 (delete-region (point-min) (point))
683 (gnus-article-hide-text (point-min) (point) props)))
684 ;; Then treat the rest of the header lines.
687 (if (search-forward "\n\n" nil t) ; if there's a body
688 (progn (forward-line -1) (point))
690 ;; Then we use the two regular expressions
691 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
692 ;; select which header lines is to remain visible in the
694 (goto-char (point-min))
695 (while (re-search-forward "^[^ \t]*:" nil t)
697 ;; Mark the rank of the header.
699 (point) (1+ (point)) 'message-rank
700 (if (or (and visible (looking-at visible))
702 (not (looking-at ignored))))
703 (gnus-article-header-rank)
706 (message-sort-headers-1)
707 (when (setq beg (text-property-any
708 (point-min) (point-max) 'message-rank (+ 2 max)))
709 ;; We make the unwanted headers invisible.
711 (delete-region beg (point-max))
712 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
713 (gnus-article-hide-text-type beg (point-max) 'headers))
714 ;; Work around XEmacs lossage.
715 (put-text-property (point-min) beg 'invisible nil))))))))
717 (defun article-hide-boring-headers (&optional arg)
718 "Toggle hiding of headers that aren't very interesting.
719 If given a negative prefix, always show; if given a positive prefix,
721 (interactive (gnus-article-hidden-arg))
722 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
723 (not gnus-show-all-headers))
726 (let ((buffer-read-only nil)
727 (list gnus-boring-article-headers)
728 (inhibit-point-motion-hooks t)
730 (nnheader-narrow-to-headers)
732 (setq elem (pop list))
733 (goto-char (point-min))
735 ;; Hide empty headers.
737 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
739 (gnus-article-hide-text-type
740 (progn (beginning-of-line) (point))
743 (if (re-search-forward "^[^ \t]" nil t)
747 ;; Hide boring Newsgroups header.
748 ((eq elem 'newsgroups)
749 (when (equal (gnus-fetch-field "newsgroups")
750 (gnus-group-real-name
751 (if (boundp 'gnus-newsgroup-name)
754 (gnus-article-hide-header "newsgroups")))
755 ((eq elem 'followup-to)
756 (when (equal (message-fetch-field "followup-to")
757 (message-fetch-field "newsgroups"))
758 (gnus-article-hide-header "followup-to")))
760 (let ((from (message-fetch-field "from"))
761 (reply-to (message-fetch-field "reply-to")))
766 (nth 1 (mail-extract-address-components from))
767 (nth 1 (mail-extract-address-components reply-to)))))
768 (gnus-article-hide-header "reply-to"))))
770 (let ((date (message-fetch-field "date")))
772 (< (gnus-days-between (current-time-string) date)
774 (gnus-article-hide-header "date"))))
776 (let ((to (message-fetch-field "to")))
777 (when (> (length to) 1024)
778 (gnus-article-hide-header "to"))))
781 (goto-char (point-min))
782 (while (re-search-forward "^to:" nil t)
783 (setq to-count (1+ to-count)))
785 (while (> to-count 0)
786 (goto-char (point-min))
788 (re-search-forward "^to:" nil nil to-count)
790 (narrow-to-region (point) (point-max))
791 (gnus-article-hide-header "to"))
792 (setq to-count (1- to-count)))))))))))))
794 (defun gnus-article-hide-header (header)
796 (goto-char (point-min))
797 (when (re-search-forward (concat "^" header ":") nil t)
798 (gnus-article-hide-text-type
799 (progn (beginning-of-line) (point))
802 (if (re-search-forward "^[^ \t]" nil t)
807 (defun article-treat-dumbquotes ()
808 "Translate M******** sm*rtq**t*s into proper text."
810 (article-translate-characters "\221\222\223\223" "`'\"\""))
812 (defun article-translate-characters (from to)
813 "Translate all characters in the body of the article according to FROM and TO.
814 FROM is a string of characters to translate from; to is a string of
815 characters to translate to."
817 (goto-char (point-min))
818 (when (search-forward "\n\n" nil t)
819 (let ((buffer-read-only nil)
820 (x (make-string 225 ?x))
822 (while (< (incf i) (length x))
825 (while (< i (length from))
826 (aset x (aref from i) (aref to i))
828 (translate-region (point) (point-max) x)))))
830 (defun article-treat-overstrike ()
831 "Translate overstrikes into bold text."
834 (goto-char (point-min))
835 (when (search-forward "\n\n" nil t)
836 (let ((buffer-read-only nil))
837 (while (search-forward "\b" nil t)
838 (let ((next (following-char))
839 (previous (char-after (- (point) 2))))
840 ;; We do the boldification/underlining by hiding the
841 ;; overstrikes and putting the proper text property
845 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
846 (put-text-property (point) (1+ (point)) 'face 'bold))
848 (gnus-article-hide-text-type
849 (1- (point)) (1+ (point)) 'overstrike)
851 (- (point) 2) (1- (point)) 'face 'underline))
853 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
855 (point) (1+ (point)) 'face 'underline)))))))))
857 (defun article-fill ()
858 "Format too long lines."
861 (let ((buffer-read-only nil))
863 (goto-char (point-min))
864 (search-forward "\n\n" nil t)
866 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
867 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
868 (adaptive-fill-mode t))
870 (and (>= (current-column) (min fill-column (window-width)))
871 (/= (preceding-char) ?:)
872 (fill-paragraph nil))
875 (defun article-remove-cr ()
876 "Remove carriage returns from an article."
879 (let ((buffer-read-only nil))
880 (goto-char (point-min))
881 (while (search-forward "\r" nil t)
882 (replace-match "" t t)))))
884 (defun article-remove-trailing-blank-lines ()
885 "Remove all trailing blank lines from the article."
888 (let ((buffer-read-only nil))
889 (goto-char (point-max))
893 (while (and (not (bobp))
894 (looking-at "^[ \t]*$"))
899 (defun article-display-x-face (&optional force)
900 "Look for an X-Face header and display it if present."
901 (interactive (list 'force))
903 ;; Delete the old process, if any.
904 (when (process-status "article-x-face")
905 (delete-process "article-x-face"))
906 (let ((inhibit-point-motion-hooks t)
910 (nnheader-narrow-to-headers)
911 (setq from (message-fetch-field "from"))
912 (goto-char (point-min))
913 (while (and gnus-article-x-face-command
916 ;; Check whether this face is censored.
917 (not gnus-article-x-face-too-ugly)
918 (and gnus-article-x-face-too-ugly from
919 (not (string-match gnus-article-x-face-too-ugly
921 ;; Has to be present.
922 (re-search-forward "^X-Face: " nil t))
923 ;; This used to try to do multiple faces (`while' instead of
924 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
925 ;; work (b) it can crash some versions of Emacs (c) are
926 ;; multiple faces really something to encourage?
927 (when (stringp gnus-article-x-face-command)
929 ;; We now have the area of the buffer where the X-Face is stored.
932 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
933 ;; We display the face.
934 (if (symbolp gnus-article-x-face-command)
935 ;; The command is a lisp function, so we call it.
936 (if (gnus-functionp gnus-article-x-face-command)
937 (funcall gnus-article-x-face-command beg end)
938 (error "%s is not a function" gnus-article-x-face-command))
939 ;; The command is a string, so we interpret the command
940 ;; as a, well, command, and fork it off.
941 (let ((process-connection-type nil))
942 (process-kill-without-query
944 "article-x-face" nil shell-file-name shell-command-switch
945 gnus-article-x-face-command))
946 (process-send-region "article-x-face" beg end)
947 (process-send-eof "article-x-face"))))))))))
949 (defun gnus-article-decode-mime-words ()
950 "Decode all MIME-encoded words in the article."
953 (set-buffer gnus-article-buffer)
954 (let ((inhibit-point-motion-hooks t)
956 (rfc2047-decode-region (point-min) (point-max)))))
958 (defun gnus-article-decode-charset (&optional prompt)
959 "Decode charset-encoded text in the article.
960 If PROMPT (the prefix), prompt for a coding system to use."
963 (set-buffer gnus-article-buffer)
964 (let* ((inhibit-point-motion-hooks t)
965 (ct (message-fetch-field "Content-Type" t))
966 (cte (message-fetch-field "Content-Transfer-Encoding" t))
969 (mm-read-coding-system "Charset to decode: "))
971 (mm-content-type-charset ct))
973 (gnus-group-find-parameter
974 gnus-newsgroup-name 'charset))))
977 (goto-char (point-min))
978 (search-forward "\n\n" nil 'move)
979 (narrow-to-region (point) (point-max))
981 charset (and cte (intern (downcase (gnus-strip-whitespace cte)))))))))
983 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
984 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
985 (defun article-decode-rfc1522 ()
986 "Remove QP encoding from headers."
987 (let ((inhibit-point-motion-hooks t)
988 (buffer-read-only nil))
990 (message-narrow-to-head)
991 (rfc2047-decode-region (point-min) (point-max)))))
993 (defun article-de-quoted-unreadable (&optional force)
994 "Translate a quoted-printable-encoded article.
995 If FORCE, decode the article whether it is marked as quoted-printable
997 (interactive (list 'force))
999 (let ((buffer-read-only nil)
1000 (type (gnus-fetch-field "content-transfer-encoding")))
1001 (gnus-article-decode-rfc1522)
1003 (and type (string-match "quoted-printable" (downcase type))))
1004 (goto-char (point-min))
1005 (search-forward "\n\n" nil 'move)
1006 (quoted-printable-decode-region (point) (point-max))))))
1008 (defun article-mime-decode-quoted-printable-buffer ()
1009 "Decode Quoted-Printable in the current buffer."
1010 (quoted-printable-decode-region (point-min) (point-max)))
1012 (defun article-hide-pgp (&optional arg)
1013 "Toggle hiding of any PGP headers and signatures in the current article.
1014 If given a negative prefix, always show; if given a positive prefix,
1016 (interactive (gnus-article-hidden-arg))
1017 (unless (gnus-article-check-hidden-text 'pgp arg)
1019 (let ((inhibit-point-motion-hooks t)
1020 buffer-read-only beg end)
1022 (goto-char (point-min))
1023 ;; Hide the "header".
1024 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1025 (delete-region (1+ (match-beginning 0)) (match-end 0))
1027 ;; Hide the actual signature.
1028 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1029 (setq end (1+ (match-beginning 0)))
1032 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1034 ;; Perhaps we shouldn't hide to the end of the buffer
1035 ;; if there is no end to the signature?
1037 ;; Hide "- " PGP quotation markers.
1039 (narrow-to-region beg end)
1040 (goto-char (point-min))
1041 (while (re-search-forward "^- " nil t)
1043 (match-beginning 0) (match-end 0)))
1045 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1047 (defun article-hide-pem (&optional arg)
1048 "Toggle hiding of any PEM headers and signatures in the current article.
1049 If given a negative prefix, always show; if given a positive prefix,
1051 (interactive (gnus-article-hidden-arg))
1052 (unless (gnus-article-check-hidden-text 'pem arg)
1054 (let (buffer-read-only end)
1056 (goto-char (point-min))
1057 ;; hide the horrendously ugly "header".
1058 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1061 (setq end (1+ (match-beginning 0)))
1062 (gnus-article-hide-text-type
1064 (if (search-forward "\n\n" nil t)
1068 ;; hide the trailer as well
1069 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1072 (gnus-article-hide-text-type
1073 (match-beginning 0) (match-end 0) 'pem))))))
1075 (defun article-hide-signature (&optional arg)
1076 "Hide the signature in the current article.
1077 If given a negative prefix, always show; if given a positive prefix,
1079 (interactive (gnus-article-hidden-arg))
1080 (unless (gnus-article-check-hidden-text 'signature arg)
1083 (let ((buffer-read-only nil))
1084 (when (gnus-article-narrow-to-signature)
1085 (gnus-article-hide-text-type
1086 (point-min) (point-max) 'signature)))))))
1088 (defun article-strip-leading-blank-lines ()
1089 "Remove all blank lines from the beginning of the article."
1092 (let ((inhibit-point-motion-hooks t)
1094 (goto-char (point-min))
1095 (when (search-forward "\n\n" nil t)
1096 (while (and (not (eobp))
1097 (looking-at "[ \t]*$"))
1098 (gnus-delete-line))))))
1100 (defun article-strip-multiple-blank-lines ()
1101 "Replace consecutive blank lines with one empty line."
1104 (let ((inhibit-point-motion-hooks t)
1106 ;; First make all blank lines empty.
1107 (goto-char (point-min))
1108 (search-forward "\n\n" nil t)
1109 (while (re-search-forward "^[ \t]+$" nil t)
1110 (replace-match "" nil t))
1111 ;; Then replace multiple empty lines with a single empty line.
1112 (goto-char (point-min))
1113 (search-forward "\n\n" nil t)
1114 (while (re-search-forward "\n\n\n+" nil t)
1115 (replace-match "\n\n" t t)))))
1117 (defun article-strip-leading-space ()
1118 "Remove all white space from the beginning of the lines in the article."
1121 (let ((inhibit-point-motion-hooks t)
1123 (goto-char (point-min))
1124 (search-forward "\n\n" nil t)
1125 (while (re-search-forward "^[ \t]+" nil t)
1126 (replace-match "" t t)))))
1128 (defun article-strip-blank-lines ()
1129 "Strip leading, trailing and multiple blank lines."
1131 (article-strip-leading-blank-lines)
1132 (article-remove-trailing-blank-lines)
1133 (article-strip-multiple-blank-lines))
1135 (defun article-strip-all-blank-lines ()
1136 "Strip all blank lines."
1139 (let ((inhibit-point-motion-hooks t)
1141 (goto-char (point-min))
1142 (search-forward "\n\n" nil t)
1143 (while (re-search-forward "^[ \t]*\n" nil t)
1144 (replace-match "" t t)))))
1146 (defvar mime::preview/content-list)
1147 (defvar mime::preview-content-info/point-min)
1148 (defun gnus-article-narrow-to-signature ()
1149 "Narrow to the signature; return t if a signature is found, else nil."
1151 (let ((inhibit-point-motion-hooks t))
1152 (when (and (boundp 'mime::preview/content-list)
1153 mime::preview/content-list)
1154 ;; We have a MIMEish article, so we use the MIME data to narrow.
1155 (let ((pcinfo (car (last mime::preview/content-list))))
1158 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1161 (when (gnus-article-search-signature)
1163 ;; Check whether we have some limits to what we consider
1164 ;; to be a signature.
1165 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1166 (list gnus-signature-limit)))
1168 (while (setq limit (pop limits))
1169 (if (or (and (integerp limit)
1170 (< (- (point-max) (point)) limit))
1172 (< (count-lines (point) (point-max)) limit))
1173 (and (gnus-functionp limit)
1175 (and (stringp limit)
1176 (not (re-search-forward limit nil t))))
1177 () ; This limit did not succeed.
1181 (narrow-to-region (point) (point-max))
1184 (defun gnus-article-search-signature ()
1185 "Search the current buffer for the signature separator.
1186 Put point at the beginning of the signature separator."
1187 (let ((cur (point)))
1188 (goto-char (point-max))
1189 (if (if (stringp gnus-signature-separator)
1190 (re-search-backward gnus-signature-separator nil t)
1191 (let ((seps gnus-signature-separator))
1193 (not (re-search-backward (car seps) nil t)))
1201 (autoload 'w3-display "w3-parse")
1202 (autoload 'w3-do-setup "w3" "" t)
1203 (autoload 'w3-region "w3-display" "" t))
1205 (defun gnus-article-treat-html ()
1208 (let ((cbuf (current-buffer)))
1209 (set-buffer gnus-article-buffer)
1210 (let (buf buffer-read-only b e)
1212 (goto-char (point-min))
1214 (if (search-forward "\n\n" nil t)
1217 (setq e (point-max)))
1219 (insert-buffer-substring gnus-article-buffer b e)
1221 (save-window-excursion
1222 (w3-region (point-min) (point-max))
1223 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1225 (delete-region (point-min) (point-max))
1228 (goto-char (point-min))
1229 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1230 (set-buffer cbuf))))
1232 (defun gnus-article-hidden-arg ()
1233 "Return the current prefix arg as a number, or 0 if no prefix."
1234 (list (if current-prefix-arg
1235 (prefix-numeric-value current-prefix-arg)
1238 (defun gnus-article-check-hidden-text (type arg)
1239 "Return nil if hiding is necessary.
1240 Arg can be nil or a number. Nil and positive means hide, negative
1241 means show, 0 means toggle."
1245 (let ((hide (gnus-article-hidden-text-p type)))
1251 (gnus-article-show-hidden-text type))
1253 (if (eq hide 'hidden)
1254 (gnus-article-show-hidden-text type)
1257 (defun gnus-article-hidden-text-p (type)
1258 "Say whether the current buffer contains hidden text of type TYPE."
1259 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1261 (not (get-text-property pos 'invisible)))
1263 (text-property-any (1+ pos) (point-max) 'article-type type)))
1268 (defun gnus-article-show-hidden-text (type &optional hide)
1269 "Show all hidden text of type TYPE.
1270 If HIDE, hide the text instead."
1272 (let ((buffer-read-only nil)
1273 (inhibit-point-motion-hooks t)
1276 (while (setq beg (text-property-any end (point-max) 'article-type type))
1279 (text-property-not-all beg (point-max) 'article-type type)
1282 (gnus-article-hide-text beg end gnus-hidden-properties)
1283 (gnus-article-unhide-text beg end))
1287 (defconst article-time-units
1288 `((year . ,(* 365.25 24 60 60))
1289 (week . ,(* 7 24 60 60))
1290 (day . ,(* 24 60 60))
1294 "Mapping from time units to seconds.")
1296 (defun article-date-ut (&optional type highlight header)
1297 "Convert DATE date to universal time in the current article.
1298 If TYPE is `local', convert to local time; if it is `lapsed', output
1299 how much time has lapsed since DATE."
1300 (interactive (list 'ut t))
1301 (let* ((header (or header
1302 (mail-header-date gnus-current-headers)
1303 (message-fetch-field "date")
1305 (date (if (vectorp header) (mail-header-date header)
1307 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1308 (inhibit-point-motion-hooks t)
1309 bface eface newline)
1310 (when (and date (not (string= date "")))
1313 (nnheader-narrow-to-headers)
1314 (let ((buffer-read-only nil))
1315 ;; Delete any old Date headers.
1316 (if (re-search-forward date-regexp nil t)
1318 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1319 eface (get-text-property (1- (gnus-point-at-eol))
1321 (delete-region (progn (beginning-of-line) (point))
1322 (progn (end-of-line) (point)))
1323 (beginning-of-line))
1324 (goto-char (point-max))
1326 (insert (article-make-date-line date type))
1329 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1330 (put-text-property (match-beginning 1) (1+ (match-end 1))
1332 (put-text-property (match-beginning 2) (match-end 2)
1336 (insert "\n"))))))))
1338 (defun article-make-date-line (date type)
1339 "Return a DATE line of TYPE."
1341 ;; Convert to the local timezone. We have to slap a
1342 ;; `condition-case' round the calls to the timezone
1343 ;; functions since they aren't particularly resistant to
1346 (concat "Date: " (condition-case ()
1347 (timezone-make-date-arpa-standard date)
1349 ;; Convert to Universal Time.
1353 (timezone-make-date-arpa-standard date nil "UT")
1355 ;; Get the original date from the article.
1356 ((eq type 'original)
1357 (concat "Date: " date))
1358 ;; Let the user define the format.
1360 (if (gnus-functionp gnus-article-time-format)
1362 gnus-article-time-format
1365 (timezone-make-date-arpa-standard
1369 (format-time-string gnus-article-time-format
1372 (timezone-make-date-arpa-standard
1373 date nil "UT")))))))
1378 (format-time-string "%Y%M%DT%h%m%s"
1381 (timezone-make-date-arpa-standard
1383 ;; Do an X-Sent lapsed format.
1385 ;; If the date is seriously mangled, the timezone functions are
1386 ;; liable to bug out, so we ignore all errors.
1387 (let* ((now (current-time))
1392 (timezone-make-date-arpa-standard
1393 (current-time-string now)
1394 (current-time-zone now) "UT"))
1396 (timezone-make-date-arpa-standard
1398 (real-sec (and real-time
1399 (+ (* (float (car real-time)) 65536)
1401 (sec (and real-time (abs real-sec)))
1411 ;; This is a bit convoluted, but basically we go
1412 ;; through the time units for years, weeks, etc,
1413 ;; and divide things to see whether that results
1414 ;; in positive answers.
1417 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1418 ;; The (remaining) seconds are too few to
1419 ;; be divided into this time unit.
1421 ;; It's big enough, so we output it.
1422 (setq sec (- sec (* num (cdr unit))))
1424 (concat (if prev ", " "") (int-to-string
1426 " " (symbol-name (car unit))
1427 (if (> num 1) "s" ""))
1429 article-time-units "")
1430 ;; If dates are odd, then it might appear like the
1431 ;; article was sent in the future.
1434 " in the future"))))))
1436 (error "Unknown conversion type: %s" type))))
1438 (defun article-date-local (&optional highlight)
1439 "Convert the current article date to the local timezone."
1440 (interactive (list t))
1441 (article-date-ut 'local highlight))
1443 (defun article-date-original (&optional highlight)
1444 "Convert the current article date to what it was originally.
1445 This is only useful if you have used some other date conversion
1446 function and want to see what the date was before converting."
1447 (interactive (list t))
1448 (article-date-ut 'original highlight))
1450 (defun article-date-lapsed (&optional highlight)
1451 "Convert the current article date to time lapsed since it was sent."
1452 (interactive (list t))
1453 (article-date-ut 'lapsed highlight))
1455 (defun article-update-date-lapsed ()
1456 "Function to be run from a timer to update the lapsed time line."
1457 (let (deactivate-mark)
1460 (when (gnus-buffer-live-p gnus-article-buffer)
1461 (set-buffer gnus-article-buffer)
1462 (goto-char (point-min))
1463 (when (re-search-forward "^X-Sent:" nil t)
1464 (article-date-lapsed t)))))))
1466 (defun gnus-start-date-timer (&optional n)
1467 "Start a timer to update the X-Sent header in the article buffers.
1468 The numerical prefix says how frequently (in seconds) the function
1473 (gnus-stop-date-timer)
1474 (setq article-lapsed-timer
1475 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1477 (defun gnus-stop-date-timer ()
1478 "Stop the X-Sent timer."
1480 (when article-lapsed-timer
1481 (nnheader-cancel-timer article-lapsed-timer)
1482 (setq article-lapsed-timer nil)))
1484 (defun article-date-user (&optional highlight)
1485 "Convert the current article date to the user-defined format.
1486 This format is defined by the `gnus-article-time-format' variable."
1487 (interactive (list t))
1488 (article-date-ut 'user highlight))
1490 (defun article-date-iso8601 (&optional highlight)
1491 "Convert the current article date to ISO8601."
1492 (interactive (list t))
1493 (article-date-ut 'iso8601 highlight))
1495 (defun article-show-all ()
1496 "Show all hidden text in the article buffer."
1499 (let ((buffer-read-only nil))
1500 (gnus-article-unhide-text (point-min) (point-max)))))
1502 (defun article-emphasize (&optional arg)
1503 "Emphasize text according to `gnus-emphasis-alist'."
1504 (interactive (gnus-article-hidden-arg))
1505 (unless (gnus-article-check-hidden-text 'emphasis arg)
1507 (let ((alist gnus-emphasis-alist)
1508 (buffer-read-only nil)
1509 (props (append '(article-type emphasis)
1510 gnus-hidden-properties))
1511 regexp elem beg invisible visible face)
1512 (goto-char (point-min))
1513 (search-forward "\n\n" nil t)
1515 (while (setq elem (pop alist))
1517 (setq regexp (car elem)
1518 invisible (nth 1 elem)
1519 visible (nth 2 elem)
1521 (while (re-search-forward regexp nil t)
1522 (when (and (match-beginning visible) (match-beginning invisible))
1523 (gnus-article-hide-text
1524 (match-beginning invisible) (match-end invisible) props)
1525 (gnus-article-unhide-text-type
1526 (match-beginning visible) (match-end visible) 'emphasis)
1527 (gnus-put-text-property-excluding-newlines
1528 (match-beginning visible) (match-end visible) 'face face)
1529 (goto-char (match-end invisible)))))))))
1531 (defvar gnus-summary-article-menu)
1532 (defvar gnus-summary-post-menu)
1534 ;;; Saving functions.
1536 (defun gnus-article-save (save-buffer file &optional num)
1537 "Save the currently selected article."
1538 (unless gnus-save-all-headers
1539 ;; Remove headers according to `gnus-saved-headers'.
1540 (let ((gnus-visible-headers
1541 (or gnus-saved-headers gnus-visible-headers))
1542 (gnus-article-buffer save-buffer))
1544 (set-buffer save-buffer)
1545 (article-hide-headers 1 t))))
1546 (save-window-excursion
1547 (if (not gnus-default-article-saver)
1548 (error "No default saver is defined")
1549 ;; !!! Magic! The saving functions all save
1550 ;; `gnus-original-article-buffer' (or so they think), but we
1551 ;; bind that variable to our save-buffer.
1552 (set-buffer gnus-article-buffer)
1553 (let* ((gnus-save-article-buffer save-buffer)
1556 ((not gnus-prompt-before-saving) 'default)
1557 ((eq gnus-prompt-before-saving 'always) nil)
1559 (gnus-number-of-articles-to-be-saved
1560 (when (eq gnus-prompt-before-saving t)
1562 (set-buffer gnus-article-current-summary)
1563 (funcall gnus-default-article-saver filename)))))
1565 (defun gnus-read-save-file-name (prompt &optional filename
1566 function group headers variable)
1568 (funcall function group headers (symbol-value variable)))
1573 ((eq filename 'default)
1579 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1582 (if (and gnus-number-of-articles-to-be-saved
1583 (> gnus-number-of-articles-to-be-saved 1))
1584 (format "these %d articles"
1585 gnus-number-of-articles-to-be-saved)
1588 ;; Let the split methods have their say.
1590 ;; No split name was found.
1593 (concat prompt " (default "
1594 (file-name-nondirectory default-name) ") ")
1595 (file-name-directory default-name)
1597 ;; A single group name is returned.
1598 ((stringp split-name)
1600 (funcall function split-name headers
1601 (symbol-value variable)))
1603 (concat prompt " (default "
1604 (file-name-nondirectory default-name) ") ")
1605 (file-name-directory default-name)
1607 ;; A single split name was found
1608 ((= 1 (length split-name))
1609 (let* ((name (expand-file-name
1610 (car split-name) gnus-article-save-directory))
1611 (dir (cond ((file-directory-p name)
1612 (file-name-as-directory name))
1613 ((file-exists-p name) name)
1614 (t gnus-article-save-directory))))
1616 (concat prompt " (default " name ") ")
1618 ;; A list of splits was found.
1620 (setq split-name (nreverse split-name))
1622 (let ((file-name-history
1623 (nconc split-name file-name-history)))
1627 (concat prompt " (`M-p' for defaults) ")
1628 gnus-article-save-directory
1630 gnus-article-save-directory)))
1631 (car (push result file-name-history)))))))
1632 ;; Create the directory.
1633 (gnus-make-directory (file-name-directory file))
1634 ;; If we have read a directory, we append the default file name.
1635 (when (file-directory-p file)
1636 (setq file (concat (file-name-as-directory file)
1637 (file-name-nondirectory default-name))))
1638 ;; Possibly translate some characters.
1639 (nnheader-translate-file-chars file)))))
1640 (gnus-make-directory (file-name-directory result))
1641 (set variable result)))
1643 (defun gnus-article-archive-name (group)
1644 "Return the first instance of an \"Archive-name\" in the current buffer."
1645 (let ((case-fold-search t))
1646 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1647 (nnheader-concat gnus-article-save-directory
1648 (match-string 1)))))
1650 (defun gnus-article-nndoc-name (group)
1651 "If GROUP is an nndoc group, return the name of the parent group."
1652 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1653 (gnus-group-get-parameter group 'save-article-group)))
1655 (defun gnus-summary-save-in-rmail (&optional filename)
1656 "Append this article to Rmail file.
1657 Optional argument FILENAME specifies file name.
1658 Directory to save to is default to `gnus-article-save-directory'."
1659 (setq filename (gnus-read-save-file-name
1660 "Save %s in rmail file:" filename
1661 gnus-rmail-save-name gnus-newsgroup-name
1662 gnus-current-headers 'gnus-newsgroup-last-rmail))
1663 (gnus-eval-in-buffer-window gnus-save-article-buffer
1667 (gnus-output-to-rmail filename))))
1670 (defun gnus-summary-save-in-mail (&optional filename)
1671 "Append this article to Unix mail file.
1672 Optional argument FILENAME specifies file name.
1673 Directory to save to is default to `gnus-article-save-directory'."
1674 (setq filename (gnus-read-save-file-name
1675 "Save %s in Unix mail file:" filename
1676 gnus-mail-save-name gnus-newsgroup-name
1677 gnus-current-headers 'gnus-newsgroup-last-mail))
1678 (gnus-eval-in-buffer-window gnus-save-article-buffer
1682 (if (and (file-readable-p filename)
1683 (mail-file-babyl-p filename))
1684 (gnus-output-to-rmail filename t)
1685 (gnus-output-to-mail filename)))))
1688 (defun gnus-summary-save-in-file (&optional filename overwrite)
1689 "Append this article to file.
1690 Optional argument FILENAME specifies file name.
1691 Directory to save to is default to `gnus-article-save-directory'."
1692 (setq filename (gnus-read-save-file-name
1693 "Save %s in file:" filename
1694 gnus-file-save-name gnus-newsgroup-name
1695 gnus-current-headers 'gnus-newsgroup-last-file))
1696 (gnus-eval-in-buffer-window gnus-save-article-buffer
1700 (when (and overwrite
1701 (file-exists-p filename))
1702 (delete-file filename))
1703 (gnus-output-to-file filename))))
1706 (defun gnus-summary-write-to-file (&optional filename)
1707 "Write this article to a file.
1708 Optional argument FILENAME specifies file name.
1709 The directory to save in defaults to `gnus-article-save-directory'."
1710 (gnus-summary-save-in-file nil t))
1712 (defun gnus-summary-save-body-in-file (&optional filename)
1713 "Append this article body to a file.
1714 Optional argument FILENAME specifies file name.
1715 The directory to save in defaults to `gnus-article-save-directory'."
1716 (setq filename (gnus-read-save-file-name
1717 "Save %s body in file:" filename
1718 gnus-file-save-name gnus-newsgroup-name
1719 gnus-current-headers 'gnus-newsgroup-last-file))
1720 (gnus-eval-in-buffer-window gnus-save-article-buffer
1724 (goto-char (point-min))
1725 (when (search-forward "\n\n" nil t)
1726 (narrow-to-region (point) (point-max)))
1727 (gnus-output-to-file filename))))
1730 (defun gnus-summary-save-in-pipe (&optional command)
1731 "Pipe this article to subprocess."
1733 (cond ((eq command 'default)
1734 gnus-last-shell-command)
1738 "Shell command on %s: "
1739 (if (and gnus-number-of-articles-to-be-saved
1740 (> gnus-number-of-articles-to-be-saved 1))
1741 (format "these %d articles"
1742 gnus-number-of-articles-to-be-saved)
1744 gnus-last-shell-command))))
1745 (when (string-equal command "")
1746 (setq command gnus-last-shell-command))
1747 (gnus-eval-in-buffer-window gnus-article-buffer
1750 (shell-command-on-region (point-min) (point-max) command nil)))
1751 (setq gnus-last-shell-command command))
1753 ;;; Article file names when saving.
1755 (defun gnus-capitalize-newsgroup (newsgroup)
1756 "Capitalize NEWSGROUP name."
1757 (when (not (zerop (length newsgroup)))
1758 (concat (char-to-string (upcase (aref newsgroup 0)))
1759 (substring newsgroup 1))))
1761 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1762 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1763 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1764 Otherwise, it is like ~/News/news/group/num."
1767 (concat (if (gnus-use-long-file-name 'not-save)
1768 (gnus-capitalize-newsgroup newsgroup)
1769 (gnus-newsgroup-directory-form newsgroup))
1770 "/" (int-to-string (mail-header-number headers)))
1771 gnus-article-save-directory)))
1773 (string-equal (file-name-directory default)
1774 (file-name-directory last-file))
1775 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1777 (or last-file default))))
1779 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1780 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1781 If variable `gnus-use-long-file-name' is non-nil, it is
1782 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1785 (concat (if (gnus-use-long-file-name 'not-save)
1787 (gnus-newsgroup-directory-form newsgroup))
1788 "/" (int-to-string (mail-header-number headers)))
1789 gnus-article-save-directory)))
1791 (string-equal (file-name-directory default)
1792 (file-name-directory last-file))
1793 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1795 (or last-file default))))
1797 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1798 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1799 If variable `gnus-use-long-file-name' is non-nil, it is
1800 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1803 (if (gnus-use-long-file-name 'not-save)
1804 (gnus-capitalize-newsgroup newsgroup)
1805 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1806 gnus-article-save-directory)))
1808 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1809 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1810 If variable `gnus-use-long-file-name' is non-nil, it is
1811 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1814 (if (gnus-use-long-file-name 'not-save)
1816 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1817 gnus-article-save-directory)))
1824 (setq afunc (car func)
1827 gfunc (intern (format "gnus-%s" func))))
1829 (if (not (fboundp afunc))
1831 `(lambda (&optional interactive &rest args)
1832 ,(documentation afunc t)
1833 (interactive (list t))
1835 (set-buffer gnus-article-buffer)
1837 (call-interactively ',afunc)
1838 (apply ',afunc args))))))))
1839 '(article-hide-headers
1840 article-hide-boring-headers
1841 article-treat-overstrike
1842 (article-fill . gnus-article-word-wrap)
1844 article-display-x-face
1845 article-de-quoted-unreadable
1846 article-mime-decode-quoted-printable
1849 article-hide-signature
1850 article-remove-trailing-blank-lines
1851 article-strip-leading-blank-lines
1852 article-strip-multiple-blank-lines
1853 article-strip-leading-space
1854 article-strip-blank-lines
1855 article-strip-all-blank-lines
1857 article-date-iso8601
1858 article-date-original
1863 article-treat-dumbquotes
1864 (article-show-all . gnus-article-show-all-headers))))
1867 ;;; Gnus article mode
1870 (put 'gnus-article-mode 'mode-class 'special)
1872 (gnus-define-keys gnus-article-mode-map
1873 " " gnus-article-goto-next-page
1874 "\177" gnus-article-goto-prev-page
1875 [delete] gnus-article-goto-prev-page
1876 "\C-c^" gnus-article-refer-article
1877 "h" gnus-article-show-summary
1878 "s" gnus-article-show-summary
1879 "\C-c\C-m" gnus-article-mail
1880 "?" gnus-article-describe-briefly
1881 gnus-mouse-2 gnus-article-push-button
1882 "\r" gnus-article-press-button
1883 "\t" gnus-article-next-button
1884 "\M-\t" gnus-article-prev-button
1885 "e" gnus-article-edit
1886 "<" beginning-of-buffer
1888 "\C-c\C-i" gnus-info-find-node
1891 "\C-d" gnus-article-read-summary-keys
1892 "\M-*" gnus-article-read-summary-keys
1893 "\M-#" gnus-article-read-summary-keys
1894 "\M-^" gnus-article-read-summary-keys
1895 "\M-g" gnus-article-read-summary-keys)
1897 (substitute-key-definition
1898 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1900 (defun gnus-article-make-menu-bar ()
1901 (gnus-turn-off-edit-menu 'article)
1902 (unless (boundp 'gnus-article-article-menu)
1904 gnus-article-article-menu gnus-article-mode-map ""
1906 ["Scroll forwards" gnus-article-goto-next-page t]
1907 ["Scroll backwards" gnus-article-goto-prev-page t]
1908 ["Show summary" gnus-article-show-summary t]
1909 ["Fetch Message-ID at point" gnus-article-refer-article t]
1910 ["Mail to address at point" gnus-article-mail t]
1911 ["Send a bug report" gnus-bug t]))
1914 gnus-article-treatment-menu gnus-article-mode-map ""
1916 ["Hide headers" gnus-article-hide-headers t]
1917 ["Hide signature" gnus-article-hide-signature t]
1918 ["Hide citation" gnus-article-hide-citation t]
1919 ["Treat overstrike" gnus-article-treat-overstrike t]
1920 ["Remove carriage return" gnus-article-remove-cr t]
1921 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1923 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1925 (when (boundp 'gnus-summary-post-menu)
1926 (define-key gnus-article-mode-map [menu-bar post]
1927 (cons "Post" gnus-summary-post-menu)))
1929 (gnus-run-hooks 'gnus-article-menu-hook)))
1931 (defun gnus-article-mode ()
1932 "Major mode for displaying an article.
1934 All normal editing commands are switched off.
1936 The following commands are available in addition to all summary mode
1938 \\<gnus-article-mode-map>
1939 \\[gnus-article-next-page]\t Scroll the article one page forwards
1940 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1941 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1942 \\[gnus-article-show-summary]\t Display the summary buffer
1943 \\[gnus-article-mail]\t Send a reply to the address near point
1944 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1945 \\[gnus-info-find-node]\t Go to the Gnus info node"
1947 (when (gnus-visual-p 'article-menu 'menu)
1948 (gnus-article-make-menu-bar))
1949 (gnus-simplify-mode-line)
1950 (setq mode-name "Article")
1951 (setq major-mode 'gnus-article-mode)
1952 (make-local-variable 'minor-mode-alist)
1953 (unless (assq 'gnus-show-mime minor-mode-alist)
1954 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1955 (use-local-map gnus-article-mode-map)
1956 (gnus-update-format-specifications nil 'article-mode)
1957 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1958 (make-local-variable 'gnus-page-broken)
1959 (make-local-variable 'gnus-button-marker-list)
1960 (make-local-variable 'gnus-article-current-summary)
1961 (gnus-set-default-directory)
1962 (buffer-disable-undo (current-buffer))
1963 (setq buffer-read-only t)
1964 (set-syntax-table gnus-article-mode-syntax-table)
1965 (mm-enable-multibyte)
1966 (gnus-run-hooks 'gnus-article-mode-hook))
1968 (defun gnus-article-setup-buffer ()
1969 "Initialize the article buffer."
1970 (let* ((name (if gnus-single-article-buffer "*Article*"
1971 (concat "*Article " gnus-newsgroup-name "*")))
1973 (progn (string-match "\\*Article" name)
1974 (concat " *Original Article"
1975 (substring name (match-end 0))))))
1976 (setq gnus-article-buffer name)
1977 (setq gnus-original-article-buffer original)
1978 ;; This might be a variable local to the summary buffer.
1979 (unless gnus-single-article-buffer
1981 (set-buffer gnus-summary-buffer)
1982 (setq gnus-article-buffer name)
1983 (setq gnus-original-article-buffer original)
1984 (gnus-set-global-variables)))
1985 ;; Init original article buffer.
1987 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1988 (buffer-disable-undo (current-buffer))
1989 (setq major-mode 'gnus-original-article-mode)
1990 (make-local-variable 'gnus-original-article))
1991 (if (get-buffer name)
1994 (buffer-disable-undo (current-buffer))
1995 (setq buffer-read-only t)
1996 (unless (eq major-mode 'gnus-article-mode)
1997 (gnus-article-mode))
2000 (set-buffer (gnus-get-buffer-create name))
2002 (make-local-variable 'gnus-summary-buffer)
2003 (current-buffer)))))
2005 ;; Set article window start at LINE, where LINE is the number of lines
2006 ;; from the head of the article.
2007 (defun gnus-article-set-window-start (&optional line)
2009 (get-buffer-window gnus-article-buffer t)
2011 (set-buffer gnus-article-buffer)
2012 (goto-char (point-min))
2015 (gnus-message 6 "Moved to bookmark")
2016 (search-forward "\n\n" nil t)
2020 (defun gnus-article-prepare (article &optional all-headers header)
2021 "Prepare ARTICLE in article mode buffer.
2022 ARTICLE should either be an article number or a Message-ID.
2023 If ARTICLE is an id, HEADER should be the article headers.
2024 If ALL-HEADERS is non-nil, no headers are hidden."
2026 ;; Make sure we start in a summary buffer.
2027 (unless (eq major-mode 'gnus-summary-mode)
2028 (set-buffer gnus-summary-buffer))
2029 (setq gnus-summary-buffer (current-buffer))
2030 (let* ((gnus-article (if header (mail-header-number header) article))
2031 (summary-buffer (current-buffer))
2032 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2033 (group gnus-newsgroup-name)
2036 (gnus-article-setup-buffer)
2037 (set-buffer gnus-article-buffer)
2038 ;; Deactivate active regions.
2039 (when (and (boundp 'transient-mark-mode)
2040 transient-mark-mode)
2041 (setq mark-active nil))
2042 (if (not (setq result (let ((buffer-read-only nil))
2043 (gnus-request-article-this-buffer
2045 ;; There is no such article.
2047 (when (and (numberp article)
2048 (not (memq article gnus-newsgroup-sparse)))
2049 (setq gnus-article-current
2050 (cons gnus-newsgroup-name article))
2051 (set-buffer gnus-summary-buffer)
2052 (setq gnus-current-article article)
2053 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2055 (gnus-summary-set-agent-mark article)
2056 (message "Message marked for downloading"))
2057 (gnus-summary-mark-article article gnus-canceled-mark)
2058 (unless (memq article gnus-newsgroup-sparse)
2060 "No such article (may have expired or been canceled)")))))
2061 (if (or (eq result 'pseudo)
2062 (eq result 'nneething))
2065 (set-buffer summary-buffer)
2066 (push article gnus-newsgroup-history)
2067 (setq gnus-last-article gnus-current-article
2068 gnus-current-article 0
2069 gnus-current-headers nil
2070 gnus-article-current nil)
2071 (if (eq result 'nneething)
2072 (gnus-configure-windows 'summary)
2073 (gnus-configure-windows 'article))
2074 (gnus-set-global-variables))
2075 (gnus-set-mode-line 'article))
2076 ;; The result from the `request' was an actual article -
2077 ;; or at least some text that is now displayed in the
2079 (when (and (numberp article)
2080 (not (eq article gnus-current-article)))
2081 ;; Seems like a new article has been selected.
2082 ;; `gnus-current-article' must be an article number.
2084 (set-buffer summary-buffer)
2085 (push article gnus-newsgroup-history)
2086 (setq gnus-last-article gnus-current-article
2087 gnus-current-article article
2088 gnus-current-headers
2089 (gnus-summary-article-header gnus-current-article)
2090 gnus-article-current
2091 (cons gnus-newsgroup-name gnus-current-article))
2092 (unless (vectorp gnus-current-headers)
2093 (setq gnus-current-headers nil))
2094 (gnus-summary-goto-subject gnus-current-article)
2095 (when (gnus-summary-show-thread)
2096 ;; If the summary buffer really was folded, the
2097 ;; previous goto may not actually have gone to
2098 ;; the right article, but the thread root instead.
2100 (gnus-summary-goto-subject gnus-current-article))
2101 (gnus-run-hooks 'gnus-mark-article-hook)
2102 (gnus-set-mode-line 'summary)
2103 (when (gnus-visual-p 'article-highlight 'highlight)
2104 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2105 ;; Set the global newsgroup variables here.
2106 ;; Suggested by Jim Sisolak
2107 ;; <sisolak@trans4.neep.wisc.edu>.
2108 (gnus-set-global-variables)
2109 (setq gnus-have-all-headers
2110 (or all-headers gnus-show-all-headers))))
2111 (when (or (numberp article)
2113 ;; Hooks for getting information from the article.
2114 ;; This hook must be called before being narrowed.
2115 (let (buffer-read-only)
2116 (gnus-run-hooks 'gnus-tmp-internal-hook)
2117 (gnus-run-hooks 'gnus-article-prepare-hook)
2118 ;; Decode MIME message.
2119 (when gnus-show-mime
2120 (if (or (not gnus-strict-mime)
2121 (gnus-fetch-field "Mime-Version"))
2122 (let ((coding-system-for-write 'binary)
2123 (coding-system-for-read 'binary))
2124 (funcall gnus-show-mime-method))
2125 (funcall gnus-decode-encoded-word-method)))
2126 ;; Perform the article display hooks.
2127 (gnus-run-hooks 'gnus-article-display-hook))
2129 (goto-char (point-min))
2130 (setq gnus-page-broken
2131 (when gnus-break-pages
2132 (gnus-narrow-to-page)
2134 (gnus-set-mode-line 'article)
2135 (gnus-configure-windows 'article)
2136 (goto-char (point-min))
2137 (search-forward "\n\n" nil t)
2138 (set-window-point (get-buffer-window (current-buffer)) (point))
2141 (defun gnus-article-wash-status ()
2142 "Return a string which display status of article washing."
2144 (set-buffer gnus-article-buffer)
2145 (let ((cite (gnus-article-hidden-text-p 'cite))
2146 (headers (gnus-article-hidden-text-p 'headers))
2147 (boring (gnus-article-hidden-text-p 'boring-headers))
2148 (pgp (gnus-article-hidden-text-p 'pgp))
2149 (pem (gnus-article-hidden-text-p 'pem))
2150 (signature (gnus-article-hidden-text-p 'signature))
2151 (overstrike (gnus-article-hidden-text-p 'overstrike))
2152 (emphasis (gnus-article-hidden-text-p 'emphasis))
2153 (mime gnus-show-mime))
2154 (format "%c%c%c%c%c%c%c"
2156 (if (or headers boring) ?h ? )
2157 (if (or pgp pem) ?p ? )
2158 (if signature ?s ? )
2159 (if overstrike ?o ? )
2161 (if emphasis ?e ? )))))
2163 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2165 (defun gnus-article-maybe-hide-headers ()
2166 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2167 Provided for backwards compatibility."
2168 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2170 (gnus-article-hide-headers)))
2174 (defun gnus-output-to-file (file-name)
2175 "Append the current article to a file named FILE-NAME."
2176 (let ((artbuf (current-buffer)))
2178 (insert-buffer-substring artbuf)
2179 ;; Append newline at end of the buffer as separator, and then
2181 (goto-char (point-max))
2183 (append-to-file (point-min) (point-max) file-name)
2186 (defun gnus-narrow-to-page (&optional arg)
2187 "Narrow the article buffer to a page.
2188 If given a numerical ARG, move forward ARG pages."
2190 (setq arg (if arg (prefix-numeric-value arg) 0))
2192 (set-buffer gnus-article-buffer)
2193 (goto-char (point-min))
2195 ;; Remove any old next/prev buttons.
2196 (when (gnus-visual-p 'page-marker)
2197 (let ((buffer-read-only nil))
2198 (gnus-remove-text-with-property 'gnus-prev)
2199 (gnus-remove-text-with-property 'gnus-next)))
2202 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2204 (re-search-forward page-delimiter nil 'move arg)))
2205 (goto-char (match-end 0)))
2208 (if (re-search-forward page-delimiter nil 'move)
2211 (when (and (gnus-visual-p 'page-marker)
2212 (not (= (point-min) 1)))
2214 (goto-char (point-min))
2215 (gnus-insert-prev-page-button)))
2216 (when (and (gnus-visual-p 'page-marker)
2217 (< (+ (point-max) 2) (buffer-size)))
2219 (goto-char (point-max))
2220 (gnus-insert-next-page-button)))))
2222 ;; Article mode commands
2224 (defun gnus-article-goto-next-page ()
2225 "Show the next page of the article."
2227 (when (gnus-article-next-page)
2228 (goto-char (point-min))
2229 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2231 (defun gnus-article-goto-prev-page ()
2232 "Show the next page of the article."
2234 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2235 (gnus-article-prev-page nil)))
2237 (defun gnus-article-next-page (&optional lines)
2238 "Show the next page of the current article.
2239 If end of article, return non-nil. Otherwise return nil.
2240 Argument LINES specifies lines to be scrolled up."
2242 (move-to-window-line -1)
2245 (and (pos-visible-in-window-p) ;Not continuation line.
2247 ;; Nothing in this page.
2248 (if (or (not gnus-page-broken)
2251 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2253 (gnus-narrow-to-page 1) ;Go to next page.
2255 ;; More in this page.
2256 (let ((scroll-in-place nil))
2260 ;; Long lines may cause an end-of-buffer error.
2261 (goto-char (point-max)))))
2262 (move-to-window-line 0)
2265 (defun gnus-article-prev-page (&optional lines)
2266 "Show previous page of current article.
2267 Argument LINES specifies lines to be scrolled down."
2269 (move-to-window-line 0)
2270 (if (and gnus-page-broken
2272 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2274 (gnus-narrow-to-page -1) ;Go to previous page.
2275 (goto-char (point-max))
2277 (let ((scroll-in-place nil))
2281 (beginning-of-buffer
2282 (goto-char (point-min))))
2283 (move-to-window-line 0)))))
2285 (defun gnus-article-refer-article ()
2286 "Read article specified by message-id around point."
2288 (let ((point (point)))
2289 (search-forward ">" nil t) ;Move point to end of "<....>".
2290 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2291 (let ((message-id (match-string 1)))
2293 (set-buffer gnus-summary-buffer)
2294 (gnus-summary-refer-article message-id))
2296 (error "No references around point"))))
2298 (defun gnus-article-show-summary ()
2299 "Reconfigure windows to show summary buffer."
2301 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2302 (error "There is no summary buffer for this article buffer")
2303 (gnus-article-set-globals)
2304 (gnus-configure-windows 'article)
2305 (gnus-summary-goto-subject gnus-current-article)
2306 (gnus-summary-position-point)))
2308 (defun gnus-article-describe-briefly ()
2309 "Describe article mode commands briefly."
2312 (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")))
2314 (defun gnus-article-summary-command ()
2315 "Execute the last keystroke in the summary buffer."
2317 (let ((obuf (current-buffer))
2318 (owin (current-window-configuration))
2320 (switch-to-buffer gnus-article-current-summary 'norecord)
2321 (setq func (lookup-key (current-local-map) (this-command-keys)))
2322 (call-interactively func)
2324 (set-window-configuration owin)
2325 (set-window-point (get-buffer-window (current-buffer)) (point))))
2327 (defun gnus-article-summary-command-nosave ()
2328 "Execute the last keystroke in the summary buffer."
2331 (pop-to-buffer gnus-article-current-summary 'norecord)
2332 (setq func (lookup-key (current-local-map) (this-command-keys)))
2333 (call-interactively func)))
2335 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2336 "Read a summary buffer key sequence and execute it from the article buffer."
2339 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2340 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2341 "=" "^" "\M-^" "|"))
2347 '("n" "Gn" "p" "Gp"))
2350 (set-buffer gnus-article-current-summary)
2351 (let (gnus-pick-mode)
2352 (push (or key last-command-event) unread-command-events)
2353 (setq keys (read-key-sequence nil))))
2356 (if (or (member keys nosaves)
2357 (member keys nosave-but-article)
2358 (member keys nosave-in-article))
2360 (save-window-excursion
2361 (pop-to-buffer gnus-article-current-summary 'norecord)
2362 ;; We disable the pick minor mode commands.
2363 (let (gnus-pick-mode)
2364 (setq func (lookup-key (current-local-map) keys))))
2367 (unless (member keys nosave-in-article)
2368 (set-buffer gnus-article-current-summary))
2369 (call-interactively func)
2370 (setq new-sum-point (point)))
2371 (when (member keys nosave-but-article)
2372 (pop-to-buffer gnus-article-buffer 'norecord)))
2373 ;; These commands should restore window configuration.
2374 (let ((obuf (current-buffer))
2375 (owin (current-window-configuration))
2377 (summary gnus-article-current-summary)
2378 func in-buffer selected)
2379 (if not-restore-window
2380 (pop-to-buffer summary 'norecord)
2381 (switch-to-buffer summary 'norecord))
2382 (setq in-buffer (current-buffer))
2383 ;; We disable the pick minor mode commands.
2384 (if (setq func (let (gnus-pick-mode)
2385 (lookup-key (current-local-map) keys)))
2387 (call-interactively func)
2388 (setq new-sum-point (point)))
2390 (when (eq in-buffer (current-buffer))
2391 (setq selected (gnus-summary-select-article))
2393 (unless not-restore-window
2394 (set-window-configuration owin))
2395 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2396 (set-window-point (get-buffer-window (current-buffer))
2398 (let ((win (get-buffer-window gnus-article-current-summary)))
2400 (set-window-point win new-sum-point))))))))
2402 (defun gnus-article-hide (&optional arg force)
2403 "Hide all the gruft in the current article.
2404 This means that PGP stuff, signatures, cited text and (some)
2405 headers will be hidden.
2406 If given a prefix, show the hidden text instead."
2407 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2408 (gnus-article-hide-headers arg)
2409 (gnus-article-hide-pgp arg)
2410 (gnus-article-hide-citation-maybe arg force)
2411 (gnus-article-hide-signature arg))
2413 (defun gnus-article-maybe-highlight ()
2414 "Do some article highlighting if article highlighting is requested."
2415 (when (gnus-visual-p 'article-highlight 'highlight)
2416 (gnus-article-highlight-some)))
2418 (defun gnus-check-group-server ()
2419 ;; Make sure the connection to the server is alive.
2420 (unless (gnus-server-opened
2421 (gnus-find-method-for-group gnus-newsgroup-name))
2422 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2423 (gnus-request-group gnus-newsgroup-name t)))
2425 (defun gnus-request-article-this-buffer (article group)
2426 "Get an article and insert it into this buffer."
2427 (let (do-update-line sparse-header)
2431 (gnus-kill-all-overlays)
2432 (setq group (or group gnus-newsgroup-name))
2434 ;; Using `gnus-request-article' directly will insert the article into
2435 ;; `nntp-server-buffer' - so we'll save some time by not having to
2436 ;; copy it from the server buffer into the article buffer.
2438 ;; We only request an article by message-id when we do not have the
2439 ;; headers for it, so we'll have to get those.
2440 (when (stringp article)
2441 (let ((gnus-override-method gnus-refer-article-method))
2442 (gnus-read-header article)))
2444 ;; If the article number is negative, that means that this article
2445 ;; doesn't belong in this newsgroup (possibly), so we find its
2446 ;; message-id and request it by id instead of number.
2447 (when (and (numberp article)
2449 (get-buffer gnus-summary-buffer)
2450 (gnus-buffer-exists-p gnus-summary-buffer))
2452 (set-buffer gnus-summary-buffer)
2453 (let ((header (gnus-summary-article-header article)))
2456 ((memq article gnus-newsgroup-sparse)
2457 ;; This is a sparse gap article.
2458 (setq do-update-line article)
2459 (setq article (mail-header-id header))
2460 (let ((gnus-override-method gnus-refer-article-method))
2461 (setq sparse-header (gnus-read-header article)))
2462 (setq gnus-newsgroup-sparse
2463 (delq article gnus-newsgroup-sparse)))
2465 ;; It's a real article.
2466 (setq article (mail-header-id header)))
2468 ;; It is an extracted pseudo-article.
2469 (setq article 'pseudo)
2470 (gnus-request-pseudo-article header))))
2472 (let ((method (gnus-find-method-for-group
2473 gnus-newsgroup-name)))
2474 (when (and (eq (car method) 'nneething)
2477 (file-name-as-directory
2478 (or (cadr (assq 'nneething-address method))
2480 (mail-header-subject header))))
2481 (when (file-directory-p dir)
2482 (setq article 'nneething)
2483 (gnus-group-enter-directory dir))))))))
2486 ;; Refuse to select canceled articles.
2487 ((and (numberp article)
2489 (get-buffer gnus-summary-buffer)
2490 (gnus-buffer-exists-p gnus-summary-buffer)
2491 (eq (cdr (save-excursion
2492 (set-buffer gnus-summary-buffer)
2493 (assq article gnus-newsgroup-reads)))
2494 gnus-canceled-mark))
2496 ;; We first check `gnus-original-article-buffer'.
2497 ((and (get-buffer gnus-original-article-buffer)
2500 (set-buffer gnus-original-article-buffer)
2501 (and (equal (car gnus-original-article) group)
2502 (eq (cdr gnus-original-article) article))))
2503 (insert-buffer-substring gnus-original-article-buffer)
2505 ;; Check the backlog.
2506 ((and gnus-keep-backlog
2507 (gnus-backlog-request-article group article (current-buffer)))
2509 ;; Check asynchronous pre-fetch.
2510 ((gnus-async-request-fetched-article group article (current-buffer))
2511 (gnus-async-prefetch-next group article gnus-summary-buffer)
2512 (when (and (numberp article) gnus-keep-backlog)
2513 (gnus-backlog-enter-article group article (current-buffer)))
2516 ((and gnus-use-cache
2518 (gnus-cache-request-article article group))
2520 ;; Get the article and put into the article buffer.
2521 ((or (stringp article) (numberp article))
2522 (let ((gnus-override-method
2523 (and (stringp article) gnus-refer-article-method))
2524 (buffer-read-only nil))
2526 (gnus-kill-all-overlays)
2527 (gnus-check-group-server)
2528 (when (gnus-request-article article group (current-buffer))
2529 (when (numberp article)
2530 (gnus-async-prefetch-next group article gnus-summary-buffer)
2531 (when gnus-keep-backlog
2532 (gnus-backlog-enter-article
2533 group article (current-buffer))))
2538 ;; Associate this article with the current summary buffer.
2539 (setq gnus-article-current-summary gnus-summary-buffer)
2541 ;; Take the article from the original article buffer
2542 ;; and place it in the buffer it's supposed to be in.
2543 (when (and (get-buffer gnus-article-buffer)
2544 (equal (buffer-name (current-buffer))
2545 (buffer-name (get-buffer gnus-article-buffer))))
2547 (if (get-buffer gnus-original-article-buffer)
2548 (set-buffer gnus-original-article-buffer)
2549 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2550 (buffer-disable-undo (current-buffer))
2551 (setq major-mode 'gnus-original-article-mode)
2552 (setq buffer-read-only t))
2553 (let (buffer-read-only)
2555 (insert-buffer-substring gnus-article-buffer))
2556 (setq gnus-original-article (cons group article))))
2558 ;; Update sparse articles.
2559 (when (and do-update-line
2560 (or (numberp article)
2562 (let ((buf (current-buffer)))
2563 (set-buffer gnus-summary-buffer)
2564 (gnus-summary-update-article do-update-line sparse-header)
2565 (gnus-summary-goto-subject do-update-line nil t)
2566 (set-window-point (get-buffer-window (current-buffer) t)
2568 (set-buffer buf))))))
2574 (defcustom gnus-article-edit-mode-hook nil
2575 "Hook run in article edit mode buffers."
2576 :group 'gnus-article-various
2579 (defvar gnus-article-edit-done-function nil)
2581 (defvar gnus-article-edit-mode-map nil)
2583 (unless gnus-article-edit-mode-map
2584 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2586 (gnus-define-keys gnus-article-edit-mode-map
2587 "\C-c\C-c" gnus-article-edit-done
2588 "\C-c\C-k" gnus-article-edit-exit)
2590 (gnus-define-keys (gnus-article-edit-wash-map
2591 "\C-c\C-w" gnus-article-edit-mode-map)
2592 "f" gnus-article-edit-full-stops))
2594 (defun gnus-article-edit-mode ()
2595 "Major mode for editing articles.
2596 This is an extended text-mode.
2598 \\{gnus-article-edit-mode-map}"
2600 (setq major-mode 'gnus-article-edit-mode)
2601 (setq mode-name "Article Edit")
2602 (use-local-map gnus-article-edit-mode-map)
2603 (make-local-variable 'gnus-article-edit-done-function)
2604 (make-local-variable 'gnus-prev-winconf)
2605 (setq buffer-read-only nil)
2606 (buffer-enable-undo)
2608 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2610 (defun gnus-article-edit (&optional force)
2611 "Edit the current article.
2612 This will have permanent effect only in mail groups.
2613 If FORCE is non-nil, allow editing of articles even in read-only
2616 (when (and (not force)
2617 (gnus-group-read-only-p))
2618 (error "The current newsgroup does not support article editing"))
2619 (gnus-article-date-original)
2620 (gnus-article-edit-article
2621 `(lambda (no-highlight)
2622 (gnus-summary-edit-article-done
2623 ,(or (mail-header-references gnus-current-headers) "")
2624 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2626 (defun gnus-article-edit-article (exit-func)
2627 "Start editing the contents of the current article buffer."
2628 (let ((winconf (current-window-configuration)))
2629 (set-buffer gnus-article-buffer)
2630 (gnus-article-edit-mode)
2631 (gnus-article-delete-text-of-type 'annotation)
2632 (gnus-set-text-properties (point-min) (point-max) nil)
2633 (gnus-configure-windows 'edit-article)
2634 (setq gnus-article-edit-done-function exit-func)
2635 (setq gnus-prev-winconf winconf)
2636 (gnus-message 6 "C-c C-c to end edits")))
2638 (defun gnus-article-edit-done (&optional arg)
2639 "Update the article edits and exit."
2644 (goto-char (point-min))
2645 (when (search-forward "\n\n" nil 1)
2646 (let ((lines (count-lines (point) (point-max)))
2647 (length (- (point-max) (point)))
2648 (case-fold-search t)
2649 (body (copy-marker (point))))
2650 (goto-char (point-min))
2651 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2652 (delete-region (match-beginning 1) (match-end 1))
2653 (insert (number-to-string length)))
2654 (goto-char (point-min))
2655 (when (re-search-forward
2656 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2657 (delete-region (match-beginning 1) (match-end 1))
2658 (insert (number-to-string length)))
2659 (goto-char (point-min))
2660 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2661 (delete-region (match-beginning 1) (match-end 1))
2662 (insert (number-to-string lines)))))))
2663 (let ((func gnus-article-edit-done-function)
2664 (buf (current-buffer))
2665 (start (window-start)))
2666 (gnus-article-edit-exit)
2669 (let ((buffer-read-only nil))
2670 (funcall func arg)))
2672 (set-window-start (get-buffer-window buf) start)
2673 (set-window-point (get-buffer-window buf) (point))))
2675 (defun gnus-article-edit-exit ()
2676 "Exit the article editing without updating."
2678 ;; We remove all text props from the article buffer.
2679 (let ((buf (format "%s" (buffer-string)))
2680 (curbuf (current-buffer))
2682 (window-start (window-start)))
2685 (let ((winconf gnus-prev-winconf))
2687 ;; The cache and backlog have to be flushed somewhat.
2688 (when gnus-use-cache
2689 (gnus-cache-update-article
2690 (car gnus-article-current) (cdr gnus-article-current)))
2691 (when gnus-keep-backlog
2692 (gnus-backlog-remove-article
2693 (car gnus-article-current) (cdr gnus-article-current)))
2694 ;; Flush original article as well.
2696 (when (get-buffer gnus-original-article-buffer)
2697 (set-buffer gnus-original-article-buffer)
2698 (setq gnus-original-article nil)))
2699 (set-window-configuration winconf)
2700 ;; Tippy-toe some to make sure that point remains where it was.
2701 (let ((buf (current-buffer)))
2703 (set-window-start (get-buffer-window (current-buffer)) window-start)
2705 (set-buffer buf)))))
2707 (defun gnus-article-edit-full-stops ()
2708 "Interactively repair spacing at end of sentences."
2711 (goto-char (point-min))
2712 (search-forward-regexp "^$" nil t)
2713 (let ((case-fold-search nil))
2714 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2717 ;;; Article highlights
2720 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2722 ;;; Internal Variables:
2724 (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\\)"
2725 "Regular expression that matches URLs."
2726 :group 'gnus-article-buttons
2729 (defcustom gnus-button-alist
2730 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2731 gnus-button-message-id 2)
2732 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2733 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2735 gnus-button-fetch-group 4)
2736 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2737 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2738 t gnus-button-message-id 3)
2739 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2740 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2741 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2742 ;; This is how URLs _should_ be embedded in text...
2743 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2745 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2746 "*Alist of regexps matching buttons in article bodies.
2748 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2749 REGEXP: is the string matching text around the button,
2750 BUTTON: is the number of the regexp grouping actually matching the button,
2751 FORM: is a lisp expression which must eval to true for the button to
2753 CALLBACK: is the function to call when the user push this button, and each
2754 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2756 CALLBACK can also be a variable, in that case the value of that
2757 variable it the real callback function."
2758 :group 'gnus-article-buttons
2759 :type '(repeat (list regexp
2760 (integer :tag "Button")
2762 (function :tag "Callback")
2765 (integer :tag "Regexp group")))))
2767 (defcustom gnus-header-button-alist
2768 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2769 0 t gnus-button-message-id 0)
2770 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2771 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2772 0 t gnus-button-mailto 0)
2773 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2774 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2775 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2776 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2777 gnus-button-message-id 3))
2778 "*Alist of headers and regexps to match buttons in article heads.
2780 This alist is very similar to `gnus-button-alist', except that each
2781 alist has an additional HEADER element first in each entry:
2783 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2785 HEADER is a regexp to match a header. For a fuller explanation, see
2786 `gnus-button-alist'."
2787 :group 'gnus-article-buttons
2788 :group 'gnus-article-headers
2789 :type '(repeat (list (regexp :tag "Header")
2791 (integer :tag "Button")
2793 (function :tag "Callback")
2796 (integer :tag "Regexp group")))))
2798 (defvar gnus-button-regexp nil)
2799 (defvar gnus-button-marker-list nil)
2800 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2802 (defvar gnus-button-last nil)
2803 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2807 (defun gnus-article-push-button (event)
2808 "Check text under the mouse pointer for a callback function.
2809 If the text under the mouse pointer has a `gnus-callback' property,
2810 call it with the value of the `gnus-data' text property."
2812 (set-buffer (window-buffer (posn-window (event-start event))))
2813 (let* ((pos (posn-point (event-start event)))
2814 (data (get-text-property pos 'gnus-data))
2815 (fun (get-text-property pos 'gnus-callback)))
2818 (funcall fun data))))
2820 (defun gnus-article-press-button ()
2821 "Check text at point for a callback function.
2822 If the text at point has a `gnus-callback' property,
2823 call it with the value of the `gnus-data' text property."
2825 (let* ((data (get-text-property (point) 'gnus-data))
2826 (fun (get-text-property (point) 'gnus-callback)))
2828 (funcall fun data))))
2830 (defun gnus-article-prev-button (n)
2831 "Move point to N buttons backward.
2832 If N is negative, move forward instead."
2834 (gnus-article-next-button (- n)))
2836 (defun gnus-article-next-button (n)
2837 "Move point to N buttons forward.
2838 If N is negative, move backward instead."
2840 (let ((function (if (< n 0) 'previous-single-property-change
2841 'next-single-property-change))
2842 (inhibit-point-motion-hooks t)
2844 (limit (if (< n 0) (point-min) (point-max))))
2846 (while (and (not (= limit (point)))
2848 ;; Skip past the current button.
2849 (when (get-text-property (point) 'gnus-callback)
2850 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2851 ;; Go to the next (or previous) button.
2852 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2853 ;; Put point at the start of the button.
2854 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2855 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2856 ;; Skip past intangible buttons.
2857 (when (get-text-property (point) 'intangible)
2861 (gnus-message 5 "No more buttons"))
2864 (defun gnus-article-highlight (&optional force)
2865 "Highlight current article.
2866 This function calls `gnus-article-highlight-headers',
2867 `gnus-article-highlight-citation',
2868 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2869 do the highlighting. See the documentation for those functions."
2870 (interactive (list 'force))
2871 (gnus-article-highlight-headers)
2872 (gnus-article-highlight-citation force)
2873 (gnus-article-highlight-signature)
2874 (gnus-article-add-buttons force)
2875 (gnus-article-add-buttons-to-head))
2877 (defun gnus-article-highlight-some (&optional force)
2878 "Highlight current article.
2879 This function calls `gnus-article-highlight-headers',
2880 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2881 do the highlighting. See the documentation for those functions."
2882 (interactive (list 'force))
2883 (gnus-article-highlight-headers)
2884 (gnus-article-highlight-signature)
2885 (gnus-article-add-buttons))
2887 (defun gnus-article-highlight-headers ()
2888 "Highlight article headers as specified by `gnus-header-face-alist'."
2891 (set-buffer gnus-article-buffer)
2893 (let ((alist gnus-header-face-alist)
2894 (buffer-read-only nil)
2895 (case-fold-search t)
2896 (inhibit-point-motion-hooks t)
2897 entry regexp header-face field-face from hpoints fpoints)
2898 (message-narrow-to-head)
2899 (while (setq entry (pop alist))
2900 (goto-char (point-min))
2901 (setq regexp (concat "^\\("
2902 (if (string-equal "" (nth 0 entry))
2906 header-face (nth 1 entry)
2907 field-face (nth 2 entry))
2908 (while (and (re-search-forward regexp nil t)
2912 (unless (search-forward ":" nil t)
2914 (when (and header-face
2915 (not (memq (point) hpoints)))
2916 (push (point) hpoints)
2917 (gnus-put-text-property from (point) 'face header-face))
2918 (when (and field-face
2919 (not (memq (setq from (point)) fpoints)))
2921 (if (re-search-forward "^[^ \t]" nil t)
2923 (goto-char (point-max)))
2924 (gnus-put-text-property from (point) 'face field-face))))))))
2926 (defun gnus-article-highlight-signature ()
2927 "Highlight the signature in an article.
2928 It does this by highlighting everything after
2929 `gnus-signature-separator' using `gnus-signature-face'."
2932 (set-buffer gnus-article-buffer)
2933 (let ((buffer-read-only nil)
2934 (inhibit-point-motion-hooks t))
2936 (when (and gnus-signature-face
2937 (gnus-article-narrow-to-signature))
2938 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2939 'face gnus-signature-face)
2941 (gnus-article-search-signature)
2942 (let ((start (match-beginning 0))
2943 (end (set-marker (make-marker) (1+ (match-end 0)))))
2944 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2947 (defun gnus-button-in-region-p (b e prop)
2948 "Say whether PROP exists in the region."
2949 (text-property-not-all b e prop nil))
2951 (defun gnus-article-add-buttons (&optional force)
2952 "Find external references in the article and make buttons of them.
2953 \"External references\" are things like Message-IDs and URLs, as
2954 specified by `gnus-button-alist'."
2955 (interactive (list 'force))
2957 (set-buffer gnus-article-buffer)
2958 (let ((buffer-read-only nil)
2959 (inhibit-point-motion-hooks t)
2960 (case-fold-search t)
2961 (alist gnus-button-alist)
2963 ;; Remove all old markers.
2965 (while (setq marker (pop gnus-button-marker-list))
2967 (when (setq entry (gnus-button-entry))
2968 (put-text-property (match-beginning (nth 1 entry))
2969 (match-end (nth 1 entry))
2970 'gnus-callback nil))
2971 (set-marker marker nil)))
2972 ;; We skip the headers.
2973 (goto-char (point-min))
2974 (unless (search-forward "\n\n" nil t)
2975 (goto-char (point-max)))
2977 (while (setq entry (pop alist))
2978 (setq regexp (car entry))
2980 (while (re-search-forward regexp nil t)
2981 (let* ((start (and entry (match-beginning (nth 1 entry))))
2982 (end (and entry (match-end (nth 1 entry))))
2983 (from (match-beginning 0)))
2984 (when (and (or (eq t (nth 2 entry))
2985 (eval (nth 2 entry)))
2986 (not (gnus-button-in-region-p
2987 start end 'gnus-callback)))
2988 ;; That optional form returned non-nil, so we add the
2990 (gnus-article-add-button
2991 start end 'gnus-button-push
2992 (car (push (set-marker (make-marker) from)
2993 gnus-button-marker-list))))))))))
2995 ;; Add buttons to the head of an article.
2996 (defun gnus-article-add-buttons-to-head ()
2997 "Add buttons to the head of the article."
3000 (set-buffer gnus-article-buffer)
3001 (let ((buffer-read-only nil)
3002 (inhibit-point-motion-hooks t)
3003 (case-fold-search t)
3004 (alist gnus-header-button-alist)
3006 (nnheader-narrow-to-headers)
3008 ;; Each alist entry.
3009 (setq entry (car alist)
3011 (goto-char (point-min))
3012 (while (re-search-forward (car entry) nil t)
3013 ;; Each header matching the entry.
3014 (setq beg (match-beginning 0))
3015 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3016 (match-beginning 0))
3019 (while (re-search-forward (nth 1 entry) end t)
3020 ;; Each match within a header.
3021 (let* ((entry (cdr entry))
3022 (start (match-beginning (nth 1 entry)))
3023 (end (match-end (nth 1 entry)))
3024 (form (nth 2 entry)))
3025 (goto-char (match-end 0))
3027 (gnus-article-add-button
3028 start end (nth 3 entry)
3029 (buffer-substring (match-beginning (nth 4 entry))
3030 (match-end (nth 4 entry)))))))
3034 ;;; External functions:
3036 (defun gnus-article-add-button (from to fun &optional data)
3037 "Create a button between FROM and TO with callback FUN and data DATA."
3038 (when gnus-article-button-face
3039 (gnus-overlay-put (gnus-make-overlay from to)
3040 'face gnus-article-button-face))
3041 (gnus-add-text-properties
3043 (nconc (and gnus-article-mouse-face
3044 (list gnus-mouse-face-prop gnus-article-mouse-face))
3045 (list 'gnus-callback fun)
3046 (and data (list 'gnus-data data)))))
3048 ;;; Internal functions:
3050 (defun gnus-article-set-globals ()
3052 (set-buffer gnus-summary-buffer)
3053 (gnus-set-global-variables)))
3055 (defun gnus-signature-toggle (end)
3057 (set-buffer gnus-article-buffer)
3058 (let ((buffer-read-only nil)
3059 (inhibit-point-motion-hooks t))
3060 (if (get-text-property end 'invisible)
3061 (gnus-article-unhide-text end (point-max))
3062 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3064 (defun gnus-button-entry ()
3065 ;; Return the first entry in `gnus-button-alist' matching this place.
3066 (let ((alist gnus-button-alist)
3069 (setq entry (pop alist))
3070 (if (looking-at (car entry))
3075 (defun gnus-button-push (marker)
3076 ;; Push button starting at MARKER.
3078 (set-buffer gnus-article-buffer)
3080 (let* ((entry (gnus-button-entry))
3081 (inhibit-point-motion-hooks t)
3083 (args (mapcar (lambda (group)
3084 (let ((string (match-string group)))
3085 (gnus-set-text-properties
3086 0 (length string) nil string)
3093 (fboundp (symbol-value fun)))
3094 (apply (symbol-value fun) args))
3096 (gnus-message 1 "You must define `%S' to use this button"
3097 (cons fun args)))))))
3099 (defun gnus-button-message-id (message-id)
3102 (set-buffer gnus-summary-buffer)
3103 (gnus-summary-refer-article message-id)))
3105 (defun gnus-button-fetch-group (address)
3106 "Fetch GROUP specified by ADDRESS."
3107 (if (not (string-match "[:/]" address))
3108 ;; This is just a simple group url.
3109 (gnus-group-read-ephemeral-group address gnus-select-method)
3110 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3112 (error "Can't parse %s" address)
3113 (gnus-group-read-ephemeral-group
3114 (match-string 4 address)
3115 `(nntp ,(match-string 1 address)
3116 (nntp-address ,(match-string 1 address))
3117 (nntp-port-number ,(if (match-end 3)
3118 (match-string 3 address)
3121 (defun gnus-url-parse-query-string (query &optional downcase)
3122 (let (retval pairs cur key val)
3123 (setq pairs (split-string query "&"))
3125 (setq cur (car pairs)
3127 (if (not (string-match "=" cur))
3129 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3130 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3132 (setq key (downcase key)))
3133 (setq cur (assoc key retval))
3135 (setcdr cur (cons val (cdr cur)))
3136 (setq retval (cons (list key val) retval)))))
3139 (defun gnus-url-unhex (x)
3146 (defun gnus-url-unhex-string (str &optional allow-newlines)
3147 "Remove %XXX embedded spaces, etc in a url.
3148 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3149 decoding of carriage returns and line feeds in the string, which is normally
3150 forbidden in URL encoding."
3151 (setq str (or str ""))
3153 (case-fold-search t))
3154 (while (string-match "%[0-9a-f][0-9a-f]" str)
3155 (let* ((start (match-beginning 0))
3156 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3158 (gnus-url-unhex (elt str (+ start 2))))))
3160 tmp (substring str 0 start)
3163 (char-to-string code))
3164 ((or (= code ?\n) (= code ?\r))
3166 (t (char-to-string code))))
3167 str (substring str (match-end 0)))))
3168 (setq tmp (concat tmp str))
3171 (defun gnus-url-mailto (url)
3172 ;; Send mail to someone
3173 (when (string-match "mailto:/*\\(.*\\)" url)
3174 (setq url (substring url (match-beginning 1) nil)))
3175 (let (to args subject func)
3176 (if (string-match (regexp-quote "?") url)
3177 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3178 args (gnus-url-parse-query-string
3179 (substring url (match-end 0) nil) t))
3180 (setq to (gnus-url-unhex-string url)))
3181 (setq args (cons (list "to" to) args)
3182 subject (cdr-safe (assoc "subject" args)))
3185 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3188 (message-position-on-field (caar args)))
3189 (insert (mapconcat 'identity (cdar args) ", "))
3190 (setq args (cdr args)))
3193 (message-goto-subject))))
3195 (defun gnus-button-mailto (address)
3197 (set-buffer (gnus-copy-article-buffer))
3198 (message-reply address))
3200 (defun gnus-button-reply (address)
3201 ;; Reply to ADDRESS.
3202 (message-reply address))
3204 (defun gnus-button-url (address)
3206 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3207 (if (listp browse-url-browser-function)
3208 (browse-url address)
3209 (funcall browse-url-browser-function address)))
3211 (defun gnus-button-embedded-url (address)
3213 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3214 (if (listp browse-url-browser-function)
3215 (browse-url (gnus-strip-whitespace address))
3216 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3218 ;;; Next/prev buttons in the article buffer.
3220 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3221 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3223 (defvar gnus-prev-page-map nil)
3224 (unless gnus-prev-page-map
3225 (setq gnus-prev-page-map (make-sparse-keymap))
3226 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3227 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3229 (defun gnus-insert-prev-page-button ()
3230 (let ((buffer-read-only nil))
3232 gnus-prev-page-line-format nil
3233 `(gnus-prev t local-map ,gnus-prev-page-map
3234 gnus-callback gnus-article-button-prev-page
3235 gnus-type annotation))))
3237 (defvar gnus-next-page-map nil)
3238 (unless gnus-next-page-map
3239 (setq gnus-next-page-map (make-keymap))
3240 (suppress-keymap gnus-prev-page-map)
3241 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3242 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3244 (defun gnus-button-next-page ()
3245 "Go to the next page."
3247 (let ((win (selected-window)))
3248 (select-window (get-buffer-window gnus-article-buffer t))
3249 (gnus-article-next-page)
3250 (select-window win)))
3252 (defun gnus-button-prev-page ()
3253 "Go to the prev page."
3255 (let ((win (selected-window)))
3256 (select-window (get-buffer-window gnus-article-buffer t))
3257 (gnus-article-prev-page)
3258 (select-window win)))
3260 (defun gnus-insert-next-page-button ()
3261 (let ((buffer-read-only nil))
3262 (gnus-eval-format gnus-next-page-line-format nil
3264 t local-map ,gnus-next-page-map
3265 gnus-callback gnus-article-button-next-page
3266 gnus-type annotation))))
3268 (defun gnus-article-button-next-page (arg)
3269 "Go to the next page."
3271 (let ((win (selected-window)))
3272 (select-window (get-buffer-window gnus-article-buffer t))
3273 (gnus-article-next-page)
3274 (select-window win)))
3276 (defun gnus-article-button-prev-page (arg)
3277 "Go to the prev page."
3279 (let ((win (selected-window)))
3280 (select-window (get-buffer-window gnus-article-buffer t))
3281 (gnus-article-prev-page)
3282 (select-window win)))
3288 (run-hooks 'gnus-art-load-hook)
3290 ;;; gnus-art.el ends here