1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
38 (defgroup gnus-article nil
40 :link '(custom-manual "(gnus)The Article Buffer")
43 (defgroup gnus-article-hiding nil
44 "Hiding article parts."
45 :link '(custom-manual "(gnus)Article Hiding")
48 (defgroup gnus-article-highlight nil
49 "Article highlighting."
50 :link '(custom-manual "(gnus)Article Highlighting")
54 (defgroup gnus-article-signature nil
56 :link '(custom-manual "(gnus)Article Signature")
59 (defgroup gnus-article-headers nil
61 :link '(custom-manual "(gnus)Hiding Headers")
64 (defgroup gnus-article-washing nil
65 "Special commands on articles."
66 :link '(custom-manual "(gnus)Article Washing")
69 (defgroup gnus-article-emphasis nil
70 "Fontisizing articles."
71 :link '(custom-manual "(gnus)Article Fontisizing")
74 (defgroup gnus-article-saving nil
76 :link '(custom-manual "(gnus)Saving Articles")
79 (defgroup gnus-article-mime nil
80 "Worshiping the MIME wonder."
81 :link '(custom-manual "(gnus)Using MIME")
84 (defgroup gnus-article-buttons nil
85 "Pushable buttons in the article buffer."
86 :link '(custom-manual "(gnus)Article Buttons")
89 (defgroup gnus-article-various nil
90 "Other article options."
91 :link '(custom-manual "(gnus)Misc Article")
94 (defcustom gnus-ignored-headers
95 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
96 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
97 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
98 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
99 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
100 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
101 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
102 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
103 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
104 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
105 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
106 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
107 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
108 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
109 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
110 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
111 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
112 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
114 "*All headers that start with this regexp will be hidden.
115 This variable can also be a list of regexps of headers to be ignored.
116 If `gnus-visible-headers' is non-nil, this variable will be ignored."
117 :type '(choice :custom-show nil
120 :group 'gnus-article-hiding)
122 (defcustom gnus-visible-headers
123 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
124 "*All headers that do not match this regexp will be hidden.
125 This variable can also be a list of regexp of headers to remain visible.
126 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
127 :type '(repeat :value-to-internal (lambda (widget value)
128 (custom-split-regexp-maybe value))
129 :match (lambda (widget value)
131 (widget-editable-list-match widget value)))
133 :group 'gnus-article-hiding)
135 (defcustom gnus-sorted-header-list
136 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
137 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
138 "*This variable is a list of regular expressions.
139 If it is non-nil, headers that match the regular expressions will
140 be placed first in the article buffer in the sequence specified by
142 :type '(repeat regexp)
143 :group 'gnus-article-hiding)
145 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
146 "Headers that are only to be displayed if they have interesting data.
147 Possible values in this list are `empty', `newsgroups', `followup-to',
148 `reply-to', `date', `long-to', and `many-to'."
149 :type '(set (const :tag "Headers with no content." empty)
150 (const :tag "Newsgroups with only one group." newsgroups)
151 (const :tag "Followup-to identical to newsgroups." followup-to)
152 (const :tag "Reply-to identical to from." reply-to)
153 (const :tag "Date less than four days old." date)
154 (const :tag "Very long To header." long-to)
155 (const :tag "Multiple To headers." many-to))
156 :group 'gnus-article-hiding)
158 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
159 "Regexp matching signature separator.
160 This can also be a list of regexps. In that case, it will be checked
161 from head to tail looking for a separator. Searches will be done from
162 the end of the buffer."
163 :type '(repeat string)
164 :group 'gnus-article-signature)
166 (defcustom gnus-signature-limit nil
167 "Provide a limit to what is considered a signature.
168 If it is a number, no signature may not be longer (in characters) than
169 that number. If it is a floating point number, no signature may be
170 longer (in lines) than that number. If it is a function, the function
171 will be called without any parameters, and if it returns nil, there is
172 no signature in the buffer. If it is a string, it will be used as a
173 regexp. If it matches, the text in question is not a signature."
174 :type '(choice (integer :value 200)
176 (function :value fun)
177 (regexp :value ".*"))
178 :group 'gnus-article-signature)
180 (defcustom gnus-hidden-properties '(invisible t intangible t)
181 "Property list to use for hiding text."
183 :group 'gnus-article-hiding)
185 (defcustom gnus-article-x-face-command
186 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
187 "*String or function to be executed to display an X-Face header.
188 If it is a string, the command will be executed in a sub-shell
189 asynchronously. The compressed face will be piped to this command."
190 :type 'string ;Leave function case to Lisp.
191 :group 'gnus-article-washing)
193 (defcustom gnus-article-x-face-too-ugly nil
194 "Regexp matching posters whose face shouldn't be shown automatically."
195 :type '(choice regexp (const nil))
196 :group 'gnus-article-washing)
198 (defcustom gnus-emphasis-alist
200 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
202 '(("_" "_" underline)
205 ("_/" "/_" underline-italic)
206 ("_\\*" "\\*_" underline-bold)
207 ("\\*/" "/\\*" bold-italic)
208 ("_\\*/" "/\\*_" underline-bold-italic))))
209 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
210 2 3 gnus-emphasis-underline)
214 (format format (car spec) (cadr spec))
215 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
217 "*Alist that says how to fontify certain phrases.
218 Each item looks like this:
220 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
222 The first element is a regular expression to be matched. The second
223 is a number that says what regular expression grouping used to find
224 the entire emphasized word. The third is a number that says what
225 regexp grouping should be displayed and highlighted. The fourth
226 is the face used for highlighting."
227 :type '(repeat (list :value ("" 0 0 default)
229 (integer :tag "Match group")
230 (integer :tag "Emphasize group")
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-bold '((t (:bold t)))
235 "Face used for displaying strong emphasized text (*word*)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-italic '((t (:italic t)))
239 "Face used for displaying italic emphasized text (/word/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline '((t (:underline t)))
243 "Face used for displaying underlined emphasized text (_word_)."
244 :group 'gnus-article-emphasis)
246 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
247 "Face used for displaying underlined bold emphasized text (_*word*_)."
248 :group 'gnus-article-emphasis)
250 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
251 "Face used for displaying underlined italic emphasized text (_*word*_)."
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
255 "Face used for displaying bold italic emphasized text (/*word*/)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-underline-bold-italic
259 '((t (:bold t :italic t :underline t)))
260 "Face used for displaying underlined bold italic emphasized text.
261 Esample: (_/*word*/_)."
262 :group 'gnus-article-emphasis)
264 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
265 "Format for display of Date headers in article bodies.
266 See `format-time-string' for the possible values.
268 The variable can also be function, which should return a complete Date
269 header. The function is called with one argument, the time, which can
270 be fed to `format-time-string'."
271 :type '(choice string symbol)
272 :link '(custom-manual "(gnus)Article Date")
273 :group 'gnus-article-washing)
276 (autoload 'mail-extract-address-components "mail-extr"))
278 (defcustom gnus-save-all-headers t
279 "*If non-nil, don't remove any headers before saving."
280 :group 'gnus-article-saving
283 (defcustom gnus-prompt-before-saving 'always
284 "*This variable says how much prompting is to be done when saving articles.
285 If it is nil, no prompting will be done, and the articles will be
286 saved to the default files. If this variable is `always', each and
287 every article that is saved will be preceded by a prompt, even when
288 saving large batches of articles. If this variable is neither nil not
289 `always', there the user will be prompted once for a file name for
290 each invocation of the saving commands."
291 :group 'gnus-article-saving
292 :type '(choice (item always)
293 (item :tag "never" nil)
294 (sexp :tag "once" :format "%t\n" :value t)))
296 (defcustom gnus-saved-headers gnus-visible-headers
297 "Headers to keep if `gnus-save-all-headers' is nil.
298 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
299 If that variable is nil, however, all headers that match this regexp
300 will be kept while the rest will be deleted before saving."
301 :group 'gnus-article-saving
304 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
305 "A function to save articles in your favourite format.
306 The function must be interactively callable (in other words, it must
307 be an Emacs command).
309 Gnus provides the following functions:
311 * gnus-summary-save-in-rmail (Rmail format)
312 * gnus-summary-save-in-mail (Unix mail format)
313 * gnus-summary-save-in-folder (MH folder)
314 * gnus-summary-save-in-file (article format)
315 * gnus-summary-save-in-vm (use VM's folder format)
316 * gnus-summary-write-to-file (article format -- overwrite)."
317 :group 'gnus-article-saving
318 :type '(radio (function-item gnus-summary-save-in-rmail)
319 (function-item gnus-summary-save-in-mail)
320 (function-item gnus-summary-save-in-folder)
321 (function-item gnus-summary-save-in-file)
322 (function-item gnus-summary-save-in-vm)
323 (function-item gnus-summary-write-to-file)))
325 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
326 "A function generating a file name to save articles in Rmail format.
327 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
328 :group 'gnus-article-saving
331 (defcustom gnus-mail-save-name 'gnus-plain-save-name
332 "A function generating a file name to save articles in Unix mail format.
333 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
334 :group 'gnus-article-saving
337 (defcustom gnus-folder-save-name 'gnus-folder-save-name
338 "A function generating a file name to save articles in MH folder.
339 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
340 :group 'gnus-article-saving
343 (defcustom gnus-file-save-name 'gnus-numeric-save-name
344 "A function generating a file name to save articles in article format.
345 The function is called with NEWSGROUP, HEADERS, and optional
347 :group 'gnus-article-saving
350 (defcustom gnus-split-methods
351 '((gnus-article-archive-name)
352 (gnus-article-nndoc-name))
353 "*Variable used to suggest where articles are to be saved.
354 For instance, if you would like to save articles related to Gnus in
355 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
356 you could set this variable to something like:
358 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
359 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
361 This variable is an alist where the where the key is the match and the
362 value is a list of possible files to save in if the match is non-nil.
364 If the match is a string, it is used as a regexp match on the
365 article. If the match is a symbol, that symbol will be funcalled
366 from the buffer of the article to be saved with the newsgroup as the
367 parameter. If it is a list, it will be evaled in the same buffer.
369 If this form or function returns a string, this string will be used as
370 a possible file name; and if it returns a non-nil list, that list will
371 be used as possible file names."
372 :group 'gnus-article-saving
373 :type '(repeat (choice (list :value (fun) function)
374 (cons :value ("" "") regexp (repeat string))
377 (defcustom gnus-strict-mime t
378 "*If nil, MIME-decode even if there is no Mime-Version header."
379 :group 'gnus-article-mime
382 (defcustom gnus-show-mime-method 'metamail-buffer
383 "Function to process a MIME message.
384 The function is called from the article buffer."
385 :group 'gnus-article-mime
388 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
389 "*Function to decode MIME encoded words.
390 The function is called from the article buffer."
391 :group 'gnus-article-mime
394 (defcustom gnus-page-delimiter "^\^L"
395 "*Regexp describing what to use as article page delimiters.
396 The default value is \"^\^L\", which is a form linefeed at the
397 beginning of a line."
399 :group 'gnus-article-various)
401 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
402 "*The format specification for the article mode line.
403 See `gnus-summary-mode-line-format' for a closer description."
405 :group 'gnus-article-various)
407 (defcustom gnus-article-mode-hook nil
408 "*A hook for Gnus article mode."
410 :group 'gnus-article-various)
412 (defcustom gnus-article-menu-hook nil
413 "*Hook run after the creation of the article mode menu."
415 :group 'gnus-article-various)
417 (defcustom gnus-article-prepare-hook nil
418 "*A hook called after an article has been prepared in the article buffer.
419 If you want to run a special decoding program like nkf, use this hook."
421 :group 'gnus-article-various)
423 (defcustom gnus-article-hide-pgp-hook nil
424 "*A hook called after successfully hiding a PGP signature."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-button-face 'bold
429 "Face used for highlighting buttons in the article buffer.
431 An article button is a piece of text that you can activate by pressing
432 `RET' or `mouse-2' above it."
434 :group 'gnus-article-buttons)
436 (defcustom gnus-article-mouse-face 'highlight
437 "Face used for mouse highlighting in the article buffer.
439 Article buttons will be displayed in this face when the cursor is
442 :group 'gnus-article-buttons)
444 (defcustom gnus-signature-face 'gnus-signature-face
445 "Face used for highlighting a signature in the article buffer.
446 Obsolete; use the face `gnus-signature-face' for customizations instead."
448 :group 'gnus-article-highlight
449 :group 'gnus-article-signature)
451 (defface gnus-signature-face
454 "Face used for highlighting a signature in the article buffer."
455 :group 'gnus-article-highlight
456 :group 'gnus-article-signature)
458 (defface gnus-header-from-face
461 (:foreground "spring green"))
464 (:foreground "red3"))
467 "Face used for displaying from headers."
468 :group 'gnus-article-headers
469 :group 'gnus-article-highlight)
471 (defface gnus-header-subject-face
474 (:foreground "SeaGreen3"))
477 (:foreground "red4"))
479 (:bold t :italic t)))
480 "Face used for displaying subject headers."
481 :group 'gnus-article-headers
482 :group 'gnus-article-highlight)
484 (defface gnus-header-newsgroups-face
487 (:foreground "yellow" :italic t))
490 (:foreground "MidnightBlue" :italic t))
493 "Face used for displaying newsgroups headers."
494 :group 'gnus-article-headers
495 :group 'gnus-article-highlight)
497 (defface gnus-header-name-face
500 (:foreground "SeaGreen"))
503 (:foreground "maroon"))
506 "Face used for displaying header names."
507 :group 'gnus-article-headers
508 :group 'gnus-article-highlight)
510 (defface gnus-header-content-face
513 (:foreground "forest green" :italic t))
516 (:foreground "indianred4" :italic t))
518 (:italic t))) "Face used for displaying header content."
519 :group 'gnus-article-headers
520 :group 'gnus-article-highlight)
522 (defcustom gnus-header-face-alist
523 '(("From" nil gnus-header-from-face)
524 ("Subject" nil gnus-header-subject-face)
525 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
526 ("" gnus-header-name-face gnus-header-content-face))
527 "*Controls highlighting of article header.
529 An alist of the form (HEADER NAME CONTENT).
531 HEADER is a regular expression which should match the name of an
532 header header and NAME and CONTENT are either face names or nil.
534 The name of each header field will be displayed using the face
535 specified by the first element in the list where HEADER match the
536 header name and NAME is non-nil. Similarly, the content will be
537 displayed by the first non-nil matching CONTENT face."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight
540 :type '(repeat (list (regexp :tag "Header")
542 (item :tag "skip" nil)
543 (face :value default))
544 (choice :tag "Content"
545 (item :tag "skip" nil)
546 (face :value default)))))
548 ;;; Internal variables
550 (defvar article-lapsed-timer nil)
551 (defvar gnus-article-current-summary nil)
553 (defvar gnus-article-mode-syntax-table
554 (let ((table (copy-syntax-table text-mode-syntax-table)))
555 (modify-syntax-entry ?- "w" table)
556 (modify-syntax-entry ?> ")" table)
557 (modify-syntax-entry ?< "(" table)
559 "Syntax table used in article mode buffers.
560 Initialized from `text-mode-syntax-table.")
562 (defvar gnus-save-article-buffer nil)
564 (defvar gnus-article-mode-line-format-alist
565 (nconc '((?w (gnus-article-wash-status) ?s))
566 gnus-summary-mode-line-format-alist))
568 (defvar gnus-number-of-articles-to-be-saved nil)
570 (defvar gnus-inhibit-hiding nil)
572 (defsubst gnus-article-hide-text (b e props)
573 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
574 (add-text-properties b e props)
575 (when (memq 'intangible props)
577 (max (1- b) (point-min))
578 b 'intangible (cddr (memq 'intangible props)))))
580 (defsubst gnus-article-unhide-text (b e)
581 "Remove hidden text properties from region between B and E."
582 (remove-text-properties b e gnus-hidden-properties)
583 (when (memq 'intangible gnus-hidden-properties)
584 (put-text-property (max (1- b) (point-min))
587 (defun gnus-article-hide-text-type (b e type)
588 "Hide text of TYPE between B and E."
589 (gnus-article-hide-text
590 b e (cons 'article-type (cons type gnus-hidden-properties))))
592 (defun gnus-article-unhide-text-type (b e type)
593 "Unhide text of TYPE between B and E."
594 (remove-text-properties
595 b e (cons 'article-type (cons type gnus-hidden-properties)))
596 (when (memq 'intangible gnus-hidden-properties)
597 (put-text-property (max (1- b) (point-min))
600 (defun gnus-article-hide-text-of-type (type)
601 "Hide text of TYPE in the current buffer."
603 (let ((b (point-min))
605 (while (setq b (text-property-any b e 'article-type type))
606 (add-text-properties b (incf b) gnus-hidden-properties)))))
608 (defun gnus-article-delete-text-of-type (type)
609 "Delete text of TYPE in the current buffer."
611 (let ((b (point-min)))
612 (while (setq b (text-property-any b (point-max) 'article-type type))
614 b (or (text-property-not-all b (point-max) 'article-type type)
617 (defun gnus-article-delete-invisible-text ()
618 "Delete all invisible text in the current buffer."
620 (let ((b (point-min)))
621 (while (setq b (text-property-any b (point-max) 'invisible t))
623 b (or (text-property-not-all b (point-max) 'invisible t)
626 (defun gnus-article-text-type-exists-p (type)
627 "Say whether any text of type TYPE exists in the buffer."
628 (text-property-any (point-min) (point-max) 'article-type type))
630 (defsubst gnus-article-header-rank ()
631 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
632 (let ((list gnus-sorted-header-list)
635 (when (looking-at (car list))
637 (setq list (cdr list))
641 (defun article-hide-headers (&optional arg delete)
642 "Toggle whether to hide unwanted headers and possibly sort them as well.
643 If given a negative prefix, always show; if given a positive prefix,
645 (interactive (gnus-article-hidden-arg))
647 (if (gnus-article-check-hidden-text 'headers arg)
648 ;; Show boring headers as well.
649 (gnus-article-show-hidden-text 'boring-headers)
650 ;; This function might be inhibited.
651 (unless gnus-inhibit-hiding
654 (let ((buffer-read-only nil)
656 (props (nconc (list 'article-type 'headers)
657 gnus-hidden-properties))
658 (max (1+ (length gnus-sorted-header-list)))
659 (ignored (when (not gnus-visible-headers)
660 (cond ((stringp gnus-ignored-headers)
661 gnus-ignored-headers)
662 ((listp gnus-ignored-headers)
663 (mapconcat 'identity gnus-ignored-headers
666 (cond ((stringp gnus-visible-headers)
667 gnus-visible-headers)
668 ((and gnus-visible-headers
669 (listp gnus-visible-headers))
670 (mapconcat 'identity gnus-visible-headers "\\|"))))
671 (inhibit-point-motion-hooks t)
673 ;; First we narrow to just the headers.
675 (goto-char (point-min))
676 ;; Hide any "From " lines at the beginning of (mail) articles.
677 (while (looking-at "From ")
681 (delete-region (point-min) (point))
682 (gnus-article-hide-text (point-min) (point) props)))
683 ;; Then treat the rest of the header lines.
686 (if (search-forward "\n\n" nil t) ; if there's a body
687 (progn (forward-line -1) (point))
689 ;; Then we use the two regular expressions
690 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
691 ;; select which header lines is to remain visible in the
693 (goto-char (point-min))
694 (while (re-search-forward "^[^ \t]*:" nil t)
696 ;; Mark the rank of the header.
698 (point) (1+ (point)) 'message-rank
699 (if (or (and visible (looking-at visible))
701 (not (looking-at ignored))))
702 (gnus-article-header-rank)
705 (message-sort-headers-1)
706 (when (setq beg (text-property-any
707 (point-min) (point-max) 'message-rank (+ 2 max)))
708 ;; We make the unwanted headers invisible.
710 (delete-region beg (point-max))
711 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
712 (gnus-article-hide-text-type beg (point-max) 'headers))
713 ;; Work around XEmacs lossage.
714 (put-text-property (point-min) beg 'invisible nil))))))))
716 (defun article-hide-boring-headers (&optional arg)
717 "Toggle hiding of headers that aren't very interesting.
718 If given a negative prefix, always show; if given a positive prefix,
720 (interactive (gnus-article-hidden-arg))
721 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
722 (not gnus-show-all-headers))
725 (let ((buffer-read-only nil)
726 (list gnus-boring-article-headers)
727 (inhibit-point-motion-hooks t)
729 (nnheader-narrow-to-headers)
731 (setq elem (pop list))
732 (goto-char (point-min))
734 ;; Hide empty headers.
736 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
738 (gnus-article-hide-text-type
739 (progn (beginning-of-line) (point))
742 (if (re-search-forward "^[^ \t]" nil t)
746 ;; Hide boring Newsgroups header.
747 ((eq elem 'newsgroups)
748 (when (equal (gnus-fetch-field "newsgroups")
749 (gnus-group-real-name
750 (if (boundp 'gnus-newsgroup-name)
753 (gnus-article-hide-header "newsgroups")))
754 ((eq elem 'followup-to)
755 (when (equal (message-fetch-field "followup-to")
756 (message-fetch-field "newsgroups"))
757 (gnus-article-hide-header "followup-to")))
759 (let ((from (message-fetch-field "from"))
760 (reply-to (message-fetch-field "reply-to")))
765 (nth 1 (mail-extract-address-components from))
766 (nth 1 (mail-extract-address-components reply-to)))))
767 (gnus-article-hide-header "reply-to"))))
769 (let ((date (message-fetch-field "date")))
771 (< (days-between (current-time-string) date)
773 (gnus-article-hide-header "date"))))
775 (let ((to (message-fetch-field "to")))
776 (when (> (length to) 1024)
777 (gnus-article-hide-header "to"))))
780 (goto-char (point-min))
781 (while (re-search-forward "^to:" nil t)
782 (setq to-count (1+ to-count)))
784 (while (> to-count 0)
785 (goto-char (point-min))
787 (re-search-forward "^to:" nil nil to-count)
789 (narrow-to-region (point) (point-max))
790 (gnus-article-hide-header "to"))
791 (setq to-count (1- to-count)))))))))))))
793 (defun gnus-article-hide-header (header)
795 (goto-char (point-min))
796 (when (re-search-forward (concat "^" header ":") nil t)
797 (gnus-article-hide-text-type
798 (progn (beginning-of-line) (point))
801 (if (re-search-forward "^[^ \t]" nil t)
806 (defun article-treat-dumbquotes ()
807 "Translate M******** sm*rtq**t*s into proper text."
809 (article-translate-characters "\221\222\223\223" "`'\"\""))
811 (defun article-translate-characters (from to)
812 "Translate all characters in the body of the article according to FROM and TO.
813 FROM is a string of characters to translate from; to is a string of
814 characters to translate to."
816 (goto-char (point-min))
817 (when (search-forward "\n\n" nil t)
818 (let ((buffer-read-only nil)
819 (x (make-string 225 ?x))
821 (while (< (incf i) (length x))
824 (while (< i (length from))
825 (aset x (aref from i) (aref to i))
827 (translate-region (point) (point-max) x)))))
829 (defun article-treat-overstrike ()
830 "Translate overstrikes into bold text."
833 (goto-char (point-min))
834 (when (search-forward "\n\n" nil t)
835 (let ((buffer-read-only nil))
836 (while (search-forward "\b" nil t)
837 (let ((next (following-char))
838 (previous (char-after (- (point) 2))))
839 ;; We do the boldification/underlining by hiding the
840 ;; overstrikes and putting the proper text property
844 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
845 (put-text-property (point) (1+ (point)) 'face 'bold))
847 (gnus-article-hide-text-type
848 (1- (point)) (1+ (point)) 'overstrike)
850 (- (point) 2) (1- (point)) 'face 'underline))
852 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
854 (point) (1+ (point)) 'face 'underline)))))))))
856 (defun article-fill ()
857 "Format too long lines."
860 (let ((buffer-read-only nil))
862 (goto-char (point-min))
863 (search-forward "\n\n" nil t)
865 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
866 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
867 (adaptive-fill-mode t))
869 (and (>= (current-column) (min fill-column (window-width)))
870 (/= (preceding-char) ?:)
871 (fill-paragraph nil))
874 (defun article-remove-cr ()
875 "Remove carriage returns from an article."
878 (let ((buffer-read-only nil))
879 (goto-char (point-min))
880 (while (search-forward "\r" nil t)
881 (replace-match "" t t)))))
883 (defun article-remove-trailing-blank-lines ()
884 "Remove all trailing blank lines from the article."
887 (let ((buffer-read-only nil))
888 (goto-char (point-max))
892 (while (and (not (bobp))
893 (looking-at "^[ \t]*$"))
898 (defun article-display-x-face (&optional force)
899 "Look for an X-Face header and display it if present."
900 (interactive (list 'force))
902 ;; Delete the old process, if any.
903 (when (process-status "article-x-face")
904 (delete-process "article-x-face"))
905 (let ((inhibit-point-motion-hooks t)
909 (nnheader-narrow-to-headers)
910 (setq from (message-fetch-field "from"))
911 (goto-char (point-min))
912 (while (and gnus-article-x-face-command
915 ;; Check whether this face is censored.
916 (not gnus-article-x-face-too-ugly)
917 (and gnus-article-x-face-too-ugly from
918 (not (string-match gnus-article-x-face-too-ugly
920 ;; Has to be present.
921 (re-search-forward "^X-Face: " nil t))
922 ;; This used to try to do multiple faces (`while' instead of
923 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
924 ;; work (b) it can crash some versions of Emacs (c) are
925 ;; multiple faces really something to encourage?
926 (when (stringp gnus-article-x-face-command)
928 ;; We now have the area of the buffer where the X-Face is stored.
931 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
932 ;; We display the face.
933 (if (symbolp gnus-article-x-face-command)
934 ;; The command is a lisp function, so we call it.
935 (if (gnus-functionp gnus-article-x-face-command)
936 (funcall gnus-article-x-face-command beg end)
937 (error "%s is not a function" gnus-article-x-face-command))
938 ;; The command is a string, so we interpret the command
939 ;; as a, well, command, and fork it off.
940 (let ((process-connection-type nil))
941 (process-kill-without-query
943 "article-x-face" nil shell-file-name shell-command-switch
944 gnus-article-x-face-command))
945 (process-send-region "article-x-face" beg end)
946 (process-send-eof "article-x-face"))))))))))
948 (defun gnus-article-decode-mime-words ()
949 "Decode all MIME-encoded words in the article."
952 (set-buffer gnus-article-buffer)
953 (let ((inhibit-point-motion-hooks t)
955 (rfc2047-decode-region (point-min) (point-max)))))
957 (defun gnus-article-decode-charset (&optional prompt)
958 "Decode charset-encoded text in the article.
959 If PROMPT (the prefix), prompt for a coding system to use."
962 (set-buffer gnus-article-buffer)
964 (message-narrow-to-head)
965 (let* ((inhibit-point-motion-hooks t)
966 (ct (message-fetch-field "Content-Type" t))
967 (cte (message-fetch-field "Content-Transfer-Encoding" t))
970 (mm-read-coding-system "Charset to decode: "))
972 (mm-content-type-charset ct))
974 (gnus-group-find-parameter
975 gnus-newsgroup-name 'charset))))
977 (goto-char (point-max))
979 (narrow-to-region (point) (point-max))
981 (string-match "text/plain" ct))
983 charset (and cte (intern (downcase
984 (gnus-strip-whitespace cte))))))))))
986 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
987 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
988 (defun article-decode-rfc1522 ()
989 "Remove QP encoding from headers."
990 (let ((inhibit-point-motion-hooks t)
991 (buffer-read-only nil))
993 (message-narrow-to-head)
994 (rfc2047-decode-region (point-min) (point-max)))))
996 (defun article-de-quoted-unreadable (&optional force)
997 "Translate a quoted-printable-encoded article.
998 If FORCE, decode the article whether it is marked as quoted-printable
1000 (interactive (list 'force))
1002 (let ((buffer-read-only nil)
1003 (type (gnus-fetch-field "content-transfer-encoding")))
1004 (gnus-article-decode-rfc1522)
1006 (and type (string-match "quoted-printable" (downcase type))))
1007 (goto-char (point-min))
1008 (search-forward "\n\n" nil 'move)
1009 (quoted-printable-decode-region (point) (point-max))))))
1011 (defun article-mime-decode-quoted-printable-buffer ()
1012 "Decode Quoted-Printable in the current buffer."
1013 (quoted-printable-decode-region (point-min) (point-max)))
1015 (defun article-hide-pgp (&optional arg)
1016 "Toggle hiding of any PGP headers and signatures in the current article.
1017 If given a negative prefix, always show; if given a positive prefix,
1019 (interactive (gnus-article-hidden-arg))
1020 (unless (gnus-article-check-hidden-text 'pgp arg)
1022 (let ((inhibit-point-motion-hooks t)
1023 buffer-read-only beg end)
1025 (goto-char (point-min))
1026 ;; Hide the "header".
1027 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1028 (delete-region (1+ (match-beginning 0)) (match-end 0))
1030 ;; Hide the actual signature.
1031 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1032 (setq end (1+ (match-beginning 0)))
1035 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1037 ;; Perhaps we shouldn't hide to the end of the buffer
1038 ;; if there is no end to the signature?
1040 ;; Hide "- " PGP quotation markers.
1042 (narrow-to-region beg end)
1043 (goto-char (point-min))
1044 (while (re-search-forward "^- " nil t)
1046 (match-beginning 0) (match-end 0)))
1048 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1050 (defun article-hide-pem (&optional arg)
1051 "Toggle hiding of any PEM headers and signatures in the current article.
1052 If given a negative prefix, always show; if given a positive prefix,
1054 (interactive (gnus-article-hidden-arg))
1055 (unless (gnus-article-check-hidden-text 'pem arg)
1057 (let (buffer-read-only end)
1059 (goto-char (point-min))
1060 ;; hide the horrendously ugly "header".
1061 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1064 (setq end (1+ (match-beginning 0)))
1065 (gnus-article-hide-text-type
1067 (if (search-forward "\n\n" nil t)
1071 ;; hide the trailer as well
1072 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1075 (gnus-article-hide-text-type
1076 (match-beginning 0) (match-end 0) 'pem))))))
1078 (defun article-hide-signature (&optional arg)
1079 "Hide the signature in the current article.
1080 If given a negative prefix, always show; if given a positive prefix,
1082 (interactive (gnus-article-hidden-arg))
1083 (unless (gnus-article-check-hidden-text 'signature arg)
1086 (let ((buffer-read-only nil))
1087 (when (gnus-article-narrow-to-signature)
1088 (gnus-article-hide-text-type
1089 (point-min) (point-max) 'signature)))))))
1091 (defun article-strip-leading-blank-lines ()
1092 "Remove all blank lines from the beginning of the article."
1095 (let ((inhibit-point-motion-hooks t)
1097 (goto-char (point-min))
1098 (when (search-forward "\n\n" nil t)
1099 (while (and (not (eobp))
1100 (looking-at "[ \t]*$"))
1101 (gnus-delete-line))))))
1103 (defun article-strip-multiple-blank-lines ()
1104 "Replace consecutive blank lines with one empty line."
1107 (let ((inhibit-point-motion-hooks t)
1109 ;; First make all blank lines empty.
1110 (goto-char (point-min))
1111 (search-forward "\n\n" nil t)
1112 (while (re-search-forward "^[ \t]+$" nil t)
1113 (replace-match "" nil t))
1114 ;; Then replace multiple empty lines with a single empty line.
1115 (goto-char (point-min))
1116 (search-forward "\n\n" nil t)
1117 (while (re-search-forward "\n\n\n+" nil t)
1118 (replace-match "\n\n" t t)))))
1120 (defun article-strip-leading-space ()
1121 "Remove all white space from the beginning of the lines in the article."
1124 (let ((inhibit-point-motion-hooks t)
1126 (goto-char (point-min))
1127 (search-forward "\n\n" nil t)
1128 (while (re-search-forward "^[ \t]+" nil t)
1129 (replace-match "" t t)))))
1131 (defun article-strip-blank-lines ()
1132 "Strip leading, trailing and multiple blank lines."
1134 (article-strip-leading-blank-lines)
1135 (article-remove-trailing-blank-lines)
1136 (article-strip-multiple-blank-lines))
1138 (defun article-strip-all-blank-lines ()
1139 "Strip all blank lines."
1142 (let ((inhibit-point-motion-hooks t)
1144 (goto-char (point-min))
1145 (search-forward "\n\n" nil t)
1146 (while (re-search-forward "^[ \t]*\n" nil t)
1147 (replace-match "" t t)))))
1149 (defvar mime::preview/content-list)
1150 (defvar mime::preview-content-info/point-min)
1151 (defun gnus-article-narrow-to-signature ()
1152 "Narrow to the signature; return t if a signature is found, else nil."
1154 (let ((inhibit-point-motion-hooks t))
1155 (when (and (boundp 'mime::preview/content-list)
1156 mime::preview/content-list)
1157 ;; We have a MIMEish article, so we use the MIME data to narrow.
1158 (let ((pcinfo (car (last mime::preview/content-list))))
1161 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1164 (when (gnus-article-search-signature)
1166 ;; Check whether we have some limits to what we consider
1167 ;; to be a signature.
1168 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1169 (list gnus-signature-limit)))
1171 (while (setq limit (pop limits))
1172 (if (or (and (integerp limit)
1173 (< (- (point-max) (point)) limit))
1175 (< (count-lines (point) (point-max)) limit))
1176 (and (gnus-functionp limit)
1178 (and (stringp limit)
1179 (not (re-search-forward limit nil t))))
1180 () ; This limit did not succeed.
1184 (narrow-to-region (point) (point-max))
1187 (defun gnus-article-search-signature ()
1188 "Search the current buffer for the signature separator.
1189 Put point at the beginning of the signature separator."
1190 (let ((cur (point)))
1191 (goto-char (point-max))
1192 (if (if (stringp gnus-signature-separator)
1193 (re-search-backward gnus-signature-separator nil t)
1194 (let ((seps gnus-signature-separator))
1196 (not (re-search-backward (car seps) nil t)))
1204 (autoload 'w3-display "w3-parse")
1205 (autoload 'w3-do-setup "w3" "" t)
1206 (autoload 'w3-region "w3-display" "" t))
1208 (defun gnus-article-treat-html ()
1211 (let ((cbuf (current-buffer)))
1212 (set-buffer gnus-article-buffer)
1213 (let (buf buffer-read-only b e)
1215 (goto-char (point-min))
1217 (if (search-forward "\n\n" nil t)
1220 (setq e (point-max)))
1222 (insert-buffer-substring gnus-article-buffer b e)
1224 (save-window-excursion
1225 (w3-region (point-min) (point-max))
1226 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1228 (delete-region (point-min) (point-max))
1231 (goto-char (point-min))
1232 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1233 (set-buffer cbuf))))
1235 (defun gnus-article-hidden-arg ()
1236 "Return the current prefix arg as a number, or 0 if no prefix."
1237 (list (if current-prefix-arg
1238 (prefix-numeric-value current-prefix-arg)
1241 (defun gnus-article-check-hidden-text (type arg)
1242 "Return nil if hiding is necessary.
1243 Arg can be nil or a number. Nil and positive means hide, negative
1244 means show, 0 means toggle."
1248 (let ((hide (gnus-article-hidden-text-p type)))
1254 (gnus-article-show-hidden-text type))
1256 (if (eq hide 'hidden)
1257 (gnus-article-show-hidden-text type)
1260 (defun gnus-article-hidden-text-p (type)
1261 "Say whether the current buffer contains hidden text of type TYPE."
1262 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1264 (not (get-text-property pos 'invisible)))
1266 (text-property-any (1+ pos) (point-max) 'article-type type)))
1271 (defun gnus-article-show-hidden-text (type &optional hide)
1272 "Show all hidden text of type TYPE.
1273 If HIDE, hide the text instead."
1275 (let ((buffer-read-only nil)
1276 (inhibit-point-motion-hooks t)
1279 (while (setq beg (text-property-any end (point-max) 'article-type type))
1282 (text-property-not-all beg (point-max) 'article-type type)
1285 (gnus-article-hide-text beg end gnus-hidden-properties)
1286 (gnus-article-unhide-text beg end))
1290 (defconst article-time-units
1291 `((year . ,(* 365.25 24 60 60))
1292 (week . ,(* 7 24 60 60))
1293 (day . ,(* 24 60 60))
1297 "Mapping from time units to seconds.")
1299 (defun article-date-ut (&optional type highlight header)
1300 "Convert DATE date to universal time in the current article.
1301 If TYPE is `local', convert to local time; if it is `lapsed', output
1302 how much time has lapsed since DATE."
1303 (interactive (list 'ut t))
1304 (let* ((header (or header
1305 (mail-header-date gnus-current-headers)
1306 (message-fetch-field "date")
1308 (date (if (vectorp header) (mail-header-date header)
1310 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1311 (inhibit-point-motion-hooks t)
1312 bface eface newline)
1313 (when (and date (not (string= date "")))
1316 (nnheader-narrow-to-headers)
1317 (let ((buffer-read-only nil))
1318 ;; Delete any old Date headers.
1319 (if (re-search-forward date-regexp nil t)
1321 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1322 eface (get-text-property (1- (gnus-point-at-eol))
1324 (delete-region (progn (beginning-of-line) (point))
1325 (progn (end-of-line) (point)))
1326 (beginning-of-line))
1327 (goto-char (point-max))
1329 (insert (article-make-date-line date type))
1332 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1333 (put-text-property (match-beginning 1) (1+ (match-end 1))
1335 (put-text-property (match-beginning 2) (match-end 2)
1339 (insert "\n"))))))))
1341 (defun article-make-date-line (date type)
1342 "Return a DATE line of TYPE."
1344 ;; Convert to the local timezone. We have to slap a
1345 ;; `condition-case' round the calls to the timezone
1346 ;; functions since they aren't particularly resistant to
1349 (concat "Date: " (current-time-string (date-to-time date))))
1350 ;; Convert to Universal Time.
1353 (current-time-string
1354 (let ((e (parse-time-string date)))
1357 ;; Get the original date from the article.
1358 ((eq type 'original)
1359 (concat "Date: " date))
1360 ;; Let the user define the format.
1362 (if (gnus-functionp gnus-article-time-format)
1363 (funcall gnus-article-time-format (date-to-time date))
1366 (format-time-string gnus-article-time-format (date-to-time date)))))
1371 (format-time-string "%Y%M%DT%h%m%s" (date-to-time date))))
1372 ;; Do an X-Sent lapsed format.
1374 ;; If the date is seriously mangled, the timezone functions are
1375 ;; liable to bug out, so we ignore all errors.
1376 (let* ((now (current-time))
1377 (real-time (subtract-time now (date-to-time date)))
1378 (real-sec (and real-time
1379 (+ (* (float (car real-time)) 65536)
1381 (sec (and real-time (abs real-sec)))
1391 ;; This is a bit convoluted, but basically we go
1392 ;; through the time units for years, weeks, etc,
1393 ;; and divide things to see whether that results
1394 ;; in positive answers.
1397 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1398 ;; The (remaining) seconds are too few to
1399 ;; be divided into this time unit.
1401 ;; It's big enough, so we output it.
1402 (setq sec (- sec (* num (cdr unit))))
1404 (concat (if prev ", " "") (int-to-string
1406 " " (symbol-name (car unit))
1407 (if (> num 1) "s" ""))
1409 article-time-units "")
1410 ;; If dates are odd, then it might appear like the
1411 ;; article was sent in the future.
1414 " in the future"))))))
1416 (error "Unknown conversion type: %s" type))))
1418 (defun article-date-local (&optional highlight)
1419 "Convert the current article date to the local timezone."
1420 (interactive (list t))
1421 (article-date-ut 'local highlight))
1423 (defun article-date-original (&optional highlight)
1424 "Convert the current article date to what it was originally.
1425 This is only useful if you have used some other date conversion
1426 function and want to see what the date was before converting."
1427 (interactive (list t))
1428 (article-date-ut 'original highlight))
1430 (defun article-date-lapsed (&optional highlight)
1431 "Convert the current article date to time lapsed since it was sent."
1432 (interactive (list t))
1433 (article-date-ut 'lapsed highlight))
1435 (defun article-update-date-lapsed ()
1436 "Function to be run from a timer to update the lapsed time line."
1437 (let (deactivate-mark)
1440 (when (gnus-buffer-live-p gnus-article-buffer)
1441 (set-buffer gnus-article-buffer)
1442 (goto-char (point-min))
1443 (when (re-search-forward "^X-Sent:" nil t)
1444 (article-date-lapsed t)))))))
1446 (defun gnus-start-date-timer (&optional n)
1447 "Start a timer to update the X-Sent header in the article buffers.
1448 The numerical prefix says how frequently (in seconds) the function
1453 (gnus-stop-date-timer)
1454 (setq article-lapsed-timer
1455 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1457 (defun gnus-stop-date-timer ()
1458 "Stop the X-Sent timer."
1460 (when article-lapsed-timer
1461 (nnheader-cancel-timer article-lapsed-timer)
1462 (setq article-lapsed-timer nil)))
1464 (defun article-date-user (&optional highlight)
1465 "Convert the current article date to the user-defined format.
1466 This format is defined by the `gnus-article-time-format' variable."
1467 (interactive (list t))
1468 (article-date-ut 'user highlight))
1470 (defun article-date-iso8601 (&optional highlight)
1471 "Convert the current article date to ISO8601."
1472 (interactive (list t))
1473 (article-date-ut 'iso8601 highlight))
1475 (defun article-show-all ()
1476 "Show all hidden text in the article buffer."
1479 (let ((buffer-read-only nil))
1480 (gnus-article-unhide-text (point-min) (point-max)))))
1482 (defun article-emphasize (&optional arg)
1483 "Emphasize text according to `gnus-emphasis-alist'."
1484 (interactive (gnus-article-hidden-arg))
1485 (unless (gnus-article-check-hidden-text 'emphasis arg)
1487 (let ((alist gnus-emphasis-alist)
1488 (buffer-read-only nil)
1489 (props (append '(article-type emphasis)
1490 gnus-hidden-properties))
1491 regexp elem beg invisible visible face)
1492 (goto-char (point-min))
1493 (search-forward "\n\n" nil t)
1495 (while (setq elem (pop alist))
1497 (setq regexp (car elem)
1498 invisible (nth 1 elem)
1499 visible (nth 2 elem)
1501 (while (re-search-forward regexp nil t)
1502 (when (and (match-beginning visible) (match-beginning invisible))
1503 (gnus-article-hide-text
1504 (match-beginning invisible) (match-end invisible) props)
1505 (gnus-article-unhide-text-type
1506 (match-beginning visible) (match-end visible) 'emphasis)
1507 (gnus-put-text-property-excluding-newlines
1508 (match-beginning visible) (match-end visible) 'face face)
1509 (goto-char (match-end invisible)))))))))
1511 (defvar gnus-summary-article-menu)
1512 (defvar gnus-summary-post-menu)
1514 ;;; Saving functions.
1516 (defun gnus-article-save (save-buffer file &optional num)
1517 "Save the currently selected article."
1518 (unless gnus-save-all-headers
1519 ;; Remove headers according to `gnus-saved-headers'.
1520 (let ((gnus-visible-headers
1521 (or gnus-saved-headers gnus-visible-headers))
1522 (gnus-article-buffer save-buffer))
1524 (set-buffer save-buffer)
1525 (article-hide-headers 1 t))))
1526 (save-window-excursion
1527 (if (not gnus-default-article-saver)
1528 (error "No default saver is defined")
1529 ;; !!! Magic! The saving functions all save
1530 ;; `gnus-original-article-buffer' (or so they think), but we
1531 ;; bind that variable to our save-buffer.
1532 (set-buffer gnus-article-buffer)
1533 (let* ((gnus-save-article-buffer save-buffer)
1536 ((not gnus-prompt-before-saving) 'default)
1537 ((eq gnus-prompt-before-saving 'always) nil)
1539 (gnus-number-of-articles-to-be-saved
1540 (when (eq gnus-prompt-before-saving t)
1542 (set-buffer gnus-article-current-summary)
1543 (funcall gnus-default-article-saver filename)))))
1545 (defun gnus-read-save-file-name (prompt &optional filename
1546 function group headers variable)
1548 (funcall function group headers (symbol-value variable)))
1553 ((eq filename 'default)
1559 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1562 (if (and gnus-number-of-articles-to-be-saved
1563 (> gnus-number-of-articles-to-be-saved 1))
1564 (format "these %d articles"
1565 gnus-number-of-articles-to-be-saved)
1568 ;; Let the split methods have their say.
1570 ;; No split name was found.
1573 (concat prompt " (default "
1574 (file-name-nondirectory default-name) ") ")
1575 (file-name-directory default-name)
1577 ;; A single group name is returned.
1578 ((stringp split-name)
1580 (funcall function split-name headers
1581 (symbol-value variable)))
1583 (concat prompt " (default "
1584 (file-name-nondirectory default-name) ") ")
1585 (file-name-directory default-name)
1587 ;; A single split name was found
1588 ((= 1 (length split-name))
1589 (let* ((name (expand-file-name
1590 (car split-name) gnus-article-save-directory))
1591 (dir (cond ((file-directory-p name)
1592 (file-name-as-directory name))
1593 ((file-exists-p name) name)
1594 (t gnus-article-save-directory))))
1596 (concat prompt " (default " name ") ")
1598 ;; A list of splits was found.
1600 (setq split-name (nreverse split-name))
1602 (let ((file-name-history
1603 (nconc split-name file-name-history)))
1607 (concat prompt " (`M-p' for defaults) ")
1608 gnus-article-save-directory
1610 gnus-article-save-directory)))
1611 (car (push result file-name-history)))))))
1612 ;; Create the directory.
1613 (gnus-make-directory (file-name-directory file))
1614 ;; If we have read a directory, we append the default file name.
1615 (when (file-directory-p file)
1616 (setq file (concat (file-name-as-directory file)
1617 (file-name-nondirectory default-name))))
1618 ;; Possibly translate some characters.
1619 (nnheader-translate-file-chars file)))))
1620 (gnus-make-directory (file-name-directory result))
1621 (set variable result)))
1623 (defun gnus-article-archive-name (group)
1624 "Return the first instance of an \"Archive-name\" in the current buffer."
1625 (let ((case-fold-search t))
1626 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1627 (nnheader-concat gnus-article-save-directory
1628 (match-string 1)))))
1630 (defun gnus-article-nndoc-name (group)
1631 "If GROUP is an nndoc group, return the name of the parent group."
1632 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1633 (gnus-group-get-parameter group 'save-article-group)))
1635 (defun gnus-summary-save-in-rmail (&optional filename)
1636 "Append this article to Rmail file.
1637 Optional argument FILENAME specifies file name.
1638 Directory to save to is default to `gnus-article-save-directory'."
1639 (setq filename (gnus-read-save-file-name
1640 "Save %s in rmail file:" filename
1641 gnus-rmail-save-name gnus-newsgroup-name
1642 gnus-current-headers 'gnus-newsgroup-last-rmail))
1643 (gnus-eval-in-buffer-window gnus-save-article-buffer
1647 (rmail-output-to-rmail-file filename))))
1650 (defun gnus-summary-save-in-mail (&optional filename)
1651 "Append this article to Unix mail file.
1652 Optional argument FILENAME specifies file name.
1653 Directory to save to is default to `gnus-article-save-directory'."
1654 (setq filename (gnus-read-save-file-name
1655 "Save %s in Unix mail file:" filename
1656 gnus-mail-save-name gnus-newsgroup-name
1657 gnus-current-headers 'gnus-newsgroup-last-mail))
1658 (gnus-eval-in-buffer-window gnus-save-article-buffer
1662 (if (and (file-readable-p filename)
1663 (mail-file-babyl-p filename))
1664 (rmail-output-to-rmail-file filename t)
1665 (gnus-output-to-mail filename)))))
1668 (defun gnus-summary-save-in-file (&optional filename overwrite)
1669 "Append this article to file.
1670 Optional argument FILENAME specifies file name.
1671 Directory to save to is default to `gnus-article-save-directory'."
1672 (setq filename (gnus-read-save-file-name
1673 "Save %s in file:" filename
1674 gnus-file-save-name gnus-newsgroup-name
1675 gnus-current-headers 'gnus-newsgroup-last-file))
1676 (gnus-eval-in-buffer-window gnus-save-article-buffer
1680 (when (and overwrite
1681 (file-exists-p filename))
1682 (delete-file filename))
1683 (gnus-output-to-file filename))))
1686 (defun gnus-summary-write-to-file (&optional filename)
1687 "Write this article to a file.
1688 Optional argument FILENAME specifies file name.
1689 The directory to save in defaults to `gnus-article-save-directory'."
1690 (gnus-summary-save-in-file nil t))
1692 (defun gnus-summary-save-body-in-file (&optional filename)
1693 "Append this article body to a file.
1694 Optional argument FILENAME specifies file name.
1695 The directory to save in defaults to `gnus-article-save-directory'."
1696 (setq filename (gnus-read-save-file-name
1697 "Save %s body in file:" filename
1698 gnus-file-save-name gnus-newsgroup-name
1699 gnus-current-headers 'gnus-newsgroup-last-file))
1700 (gnus-eval-in-buffer-window gnus-save-article-buffer
1704 (goto-char (point-min))
1705 (when (search-forward "\n\n" nil t)
1706 (narrow-to-region (point) (point-max)))
1707 (gnus-output-to-file filename))))
1710 (defun gnus-summary-save-in-pipe (&optional command)
1711 "Pipe this article to subprocess."
1713 (cond ((eq command 'default)
1714 gnus-last-shell-command)
1718 "Shell command on %s: "
1719 (if (and gnus-number-of-articles-to-be-saved
1720 (> gnus-number-of-articles-to-be-saved 1))
1721 (format "these %d articles"
1722 gnus-number-of-articles-to-be-saved)
1724 gnus-last-shell-command))))
1725 (when (string-equal command "")
1726 (setq command gnus-last-shell-command))
1727 (gnus-eval-in-buffer-window gnus-article-buffer
1730 (shell-command-on-region (point-min) (point-max) command nil)))
1731 (setq gnus-last-shell-command command))
1733 ;;; Article file names when saving.
1735 (defun gnus-capitalize-newsgroup (newsgroup)
1736 "Capitalize NEWSGROUP name."
1737 (when (not (zerop (length newsgroup)))
1738 (concat (char-to-string (upcase (aref newsgroup 0)))
1739 (substring newsgroup 1))))
1741 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1742 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1743 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1744 Otherwise, it is like ~/News/news/group/num."
1747 (concat (if (gnus-use-long-file-name 'not-save)
1748 (gnus-capitalize-newsgroup newsgroup)
1749 (gnus-newsgroup-directory-form newsgroup))
1750 "/" (int-to-string (mail-header-number headers)))
1751 gnus-article-save-directory)))
1753 (string-equal (file-name-directory default)
1754 (file-name-directory last-file))
1755 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1757 (or last-file default))))
1759 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1760 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1761 If variable `gnus-use-long-file-name' is non-nil, it is
1762 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1765 (concat (if (gnus-use-long-file-name 'not-save)
1767 (gnus-newsgroup-directory-form newsgroup))
1768 "/" (int-to-string (mail-header-number headers)))
1769 gnus-article-save-directory)))
1771 (string-equal (file-name-directory default)
1772 (file-name-directory last-file))
1773 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1775 (or last-file default))))
1777 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1778 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1779 If variable `gnus-use-long-file-name' is non-nil, it is
1780 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1783 (if (gnus-use-long-file-name 'not-save)
1784 (gnus-capitalize-newsgroup newsgroup)
1785 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1786 gnus-article-save-directory)))
1788 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1789 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1790 If variable `gnus-use-long-file-name' is non-nil, it is
1791 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1794 (if (gnus-use-long-file-name 'not-save)
1796 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1797 gnus-article-save-directory)))
1804 (setq afunc (car func)
1807 gfunc (intern (format "gnus-%s" func))))
1809 (if (not (fboundp afunc))
1811 `(lambda (&optional interactive &rest args)
1812 ,(documentation afunc t)
1813 (interactive (list t))
1815 (set-buffer gnus-article-buffer)
1817 (call-interactively ',afunc)
1818 (apply ',afunc args))))))))
1819 '(article-hide-headers
1820 article-hide-boring-headers
1821 article-treat-overstrike
1822 (article-fill . gnus-article-word-wrap)
1824 article-display-x-face
1825 article-de-quoted-unreadable
1826 article-mime-decode-quoted-printable
1829 article-hide-signature
1830 article-remove-trailing-blank-lines
1831 article-strip-leading-blank-lines
1832 article-strip-multiple-blank-lines
1833 article-strip-leading-space
1834 article-strip-blank-lines
1835 article-strip-all-blank-lines
1837 article-date-iso8601
1838 article-date-original
1843 article-treat-dumbquotes
1844 (article-show-all . gnus-article-show-all-headers))))
1847 ;;; Gnus article mode
1850 (put 'gnus-article-mode 'mode-class 'special)
1852 (gnus-define-keys gnus-article-mode-map
1853 " " gnus-article-goto-next-page
1854 "\177" gnus-article-goto-prev-page
1855 [delete] gnus-article-goto-prev-page
1856 "\C-c^" gnus-article-refer-article
1857 "h" gnus-article-show-summary
1858 "s" gnus-article-show-summary
1859 "\C-c\C-m" gnus-article-mail
1860 "?" gnus-article-describe-briefly
1861 gnus-mouse-2 gnus-article-push-button
1862 "\r" gnus-article-press-button
1863 "\t" gnus-article-next-button
1864 "\M-\t" gnus-article-prev-button
1865 "e" gnus-article-edit
1866 "<" beginning-of-buffer
1868 "\C-c\C-i" gnus-info-find-node
1871 "\C-d" gnus-article-read-summary-keys
1872 "\M-*" gnus-article-read-summary-keys
1873 "\M-#" gnus-article-read-summary-keys
1874 "\M-^" gnus-article-read-summary-keys
1875 "\M-g" gnus-article-read-summary-keys)
1877 (substitute-key-definition
1878 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1880 (defun gnus-article-make-menu-bar ()
1881 (gnus-turn-off-edit-menu 'article)
1882 (unless (boundp 'gnus-article-article-menu)
1884 gnus-article-article-menu gnus-article-mode-map ""
1886 ["Scroll forwards" gnus-article-goto-next-page t]
1887 ["Scroll backwards" gnus-article-goto-prev-page t]
1888 ["Show summary" gnus-article-show-summary t]
1889 ["Fetch Message-ID at point" gnus-article-refer-article t]
1890 ["Mail to address at point" gnus-article-mail t]
1891 ["Send a bug report" gnus-bug t]))
1894 gnus-article-treatment-menu gnus-article-mode-map ""
1896 ["Hide headers" gnus-article-hide-headers t]
1897 ["Hide signature" gnus-article-hide-signature t]
1898 ["Hide citation" gnus-article-hide-citation t]
1899 ["Treat overstrike" gnus-article-treat-overstrike t]
1900 ["Remove carriage return" gnus-article-remove-cr t]
1901 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1903 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1905 (when (boundp 'gnus-summary-post-menu)
1906 (define-key gnus-article-mode-map [menu-bar post]
1907 (cons "Post" gnus-summary-post-menu)))
1909 (gnus-run-hooks 'gnus-article-menu-hook)))
1911 (defun gnus-article-mode ()
1912 "Major mode for displaying an article.
1914 All normal editing commands are switched off.
1916 The following commands are available in addition to all summary mode
1918 \\<gnus-article-mode-map>
1919 \\[gnus-article-next-page]\t Scroll the article one page forwards
1920 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1921 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1922 \\[gnus-article-show-summary]\t Display the summary buffer
1923 \\[gnus-article-mail]\t Send a reply to the address near point
1924 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1925 \\[gnus-info-find-node]\t Go to the Gnus info node"
1927 (when (gnus-visual-p 'article-menu 'menu)
1928 (gnus-article-make-menu-bar))
1929 (gnus-simplify-mode-line)
1930 (setq mode-name "Article")
1931 (setq major-mode 'gnus-article-mode)
1932 (make-local-variable 'minor-mode-alist)
1933 (unless (assq 'gnus-show-mime minor-mode-alist)
1934 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1935 (use-local-map gnus-article-mode-map)
1936 (gnus-update-format-specifications nil 'article-mode)
1937 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1938 (make-local-variable 'gnus-page-broken)
1939 (make-local-variable 'gnus-button-marker-list)
1940 (make-local-variable 'gnus-article-current-summary)
1941 (gnus-set-default-directory)
1942 (buffer-disable-undo (current-buffer))
1943 (setq buffer-read-only t)
1944 (set-syntax-table gnus-article-mode-syntax-table)
1945 (mm-enable-multibyte)
1946 (gnus-run-hooks 'gnus-article-mode-hook))
1948 (defun gnus-article-setup-buffer ()
1949 "Initialize the article buffer."
1950 (let* ((name (if gnus-single-article-buffer "*Article*"
1951 (concat "*Article " gnus-newsgroup-name "*")))
1953 (progn (string-match "\\*Article" name)
1954 (concat " *Original Article"
1955 (substring name (match-end 0))))))
1956 (setq gnus-article-buffer name)
1957 (setq gnus-original-article-buffer original)
1958 ;; This might be a variable local to the summary buffer.
1959 (unless gnus-single-article-buffer
1961 (set-buffer gnus-summary-buffer)
1962 (setq gnus-article-buffer name)
1963 (setq gnus-original-article-buffer original)
1964 (gnus-set-global-variables)))
1965 ;; Init original article buffer.
1967 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1968 (mm-enable-multibyte)
1969 (setq major-mode 'gnus-original-article-mode)
1970 (make-local-variable 'gnus-original-article))
1971 (if (get-buffer name)
1974 (buffer-disable-undo (current-buffer))
1975 (setq buffer-read-only t)
1976 (unless (eq major-mode 'gnus-article-mode)
1977 (gnus-article-mode))
1980 (set-buffer (gnus-get-buffer-create name))
1982 (make-local-variable 'gnus-summary-buffer)
1983 (current-buffer)))))
1985 ;; Set article window start at LINE, where LINE is the number of lines
1986 ;; from the head of the article.
1987 (defun gnus-article-set-window-start (&optional line)
1989 (get-buffer-window gnus-article-buffer t)
1991 (set-buffer gnus-article-buffer)
1992 (goto-char (point-min))
1995 (gnus-message 6 "Moved to bookmark")
1996 (search-forward "\n\n" nil t)
2000 (defun gnus-article-prepare (article &optional all-headers header)
2001 "Prepare ARTICLE in article mode buffer.
2002 ARTICLE should either be an article number or a Message-ID.
2003 If ARTICLE is an id, HEADER should be the article headers.
2004 If ALL-HEADERS is non-nil, no headers are hidden."
2006 ;; Make sure we start in a summary buffer.
2007 (unless (eq major-mode 'gnus-summary-mode)
2008 (set-buffer gnus-summary-buffer))
2009 (setq gnus-summary-buffer (current-buffer))
2010 (let* ((gnus-article (if header (mail-header-number header) article))
2011 (summary-buffer (current-buffer))
2012 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2013 (group gnus-newsgroup-name)
2016 (gnus-article-setup-buffer)
2017 (set-buffer gnus-article-buffer)
2018 ;; Deactivate active regions.
2019 (when (and (boundp 'transient-mark-mode)
2020 transient-mark-mode)
2021 (setq mark-active nil))
2022 (if (not (setq result (let ((buffer-read-only nil))
2023 (gnus-request-article-this-buffer
2025 ;; There is no such article.
2027 (when (and (numberp article)
2028 (not (memq article gnus-newsgroup-sparse)))
2029 (setq gnus-article-current
2030 (cons gnus-newsgroup-name article))
2031 (set-buffer gnus-summary-buffer)
2032 (setq gnus-current-article article)
2033 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2035 (gnus-summary-set-agent-mark article)
2036 (message "Message marked for downloading"))
2037 (gnus-summary-mark-article article gnus-canceled-mark)
2038 (unless (memq article gnus-newsgroup-sparse)
2040 "No such article (may have expired or been canceled)")))))
2041 (if (or (eq result 'pseudo)
2042 (eq result 'nneething))
2045 (set-buffer summary-buffer)
2046 (push article gnus-newsgroup-history)
2047 (setq gnus-last-article gnus-current-article
2048 gnus-current-article 0
2049 gnus-current-headers nil
2050 gnus-article-current nil)
2051 (if (eq result 'nneething)
2052 (gnus-configure-windows 'summary)
2053 (gnus-configure-windows 'article))
2054 (gnus-set-global-variables))
2055 (gnus-set-mode-line 'article))
2056 ;; The result from the `request' was an actual article -
2057 ;; or at least some text that is now displayed in the
2059 (when (and (numberp article)
2060 (not (eq article gnus-current-article)))
2061 ;; Seems like a new article has been selected.
2062 ;; `gnus-current-article' must be an article number.
2064 (set-buffer summary-buffer)
2065 (push article gnus-newsgroup-history)
2066 (setq gnus-last-article gnus-current-article
2067 gnus-current-article article
2068 gnus-current-headers
2069 (gnus-summary-article-header gnus-current-article)
2070 gnus-article-current
2071 (cons gnus-newsgroup-name gnus-current-article))
2072 (unless (vectorp gnus-current-headers)
2073 (setq gnus-current-headers nil))
2074 (gnus-summary-goto-subject gnus-current-article)
2075 (when (gnus-summary-show-thread)
2076 ;; If the summary buffer really was folded, the
2077 ;; previous goto may not actually have gone to
2078 ;; the right article, but the thread root instead.
2080 (gnus-summary-goto-subject gnus-current-article))
2081 (gnus-run-hooks 'gnus-mark-article-hook)
2082 (gnus-set-mode-line 'summary)
2083 (when (gnus-visual-p 'article-highlight 'highlight)
2084 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2085 ;; Set the global newsgroup variables here.
2086 ;; Suggested by Jim Sisolak
2087 ;; <sisolak@trans4.neep.wisc.edu>.
2088 (gnus-set-global-variables)
2089 (setq gnus-have-all-headers
2090 (or all-headers gnus-show-all-headers))))
2091 (when (or (numberp article)
2093 ;; Hooks for getting information from the article.
2094 ;; This hook must be called before being narrowed.
2095 (let (buffer-read-only)
2096 (gnus-run-hooks 'gnus-tmp-internal-hook)
2097 (gnus-run-hooks 'gnus-article-prepare-hook)
2098 ;; Decode MIME message.
2099 (when gnus-show-mime
2100 (if (or (not gnus-strict-mime)
2101 (gnus-fetch-field "Mime-Version"))
2102 (let ((coding-system-for-write 'binary)
2103 (coding-system-for-read 'binary))
2104 (funcall gnus-show-mime-method))
2105 (funcall gnus-decode-encoded-word-method)))
2106 ;; Perform the article display hooks.
2107 (gnus-run-hooks 'gnus-article-display-hook))
2109 (goto-char (point-min))
2110 (setq gnus-page-broken
2111 (when gnus-break-pages
2112 (gnus-narrow-to-page)
2114 (gnus-set-mode-line 'article)
2115 (gnus-configure-windows 'article)
2116 (goto-char (point-min))
2117 (search-forward "\n\n" nil t)
2118 (set-window-point (get-buffer-window (current-buffer)) (point))
2121 (defun gnus-article-wash-status ()
2122 "Return a string which display status of article washing."
2124 (set-buffer gnus-article-buffer)
2125 (let ((cite (gnus-article-hidden-text-p 'cite))
2126 (headers (gnus-article-hidden-text-p 'headers))
2127 (boring (gnus-article-hidden-text-p 'boring-headers))
2128 (pgp (gnus-article-hidden-text-p 'pgp))
2129 (pem (gnus-article-hidden-text-p 'pem))
2130 (signature (gnus-article-hidden-text-p 'signature))
2131 (overstrike (gnus-article-hidden-text-p 'overstrike))
2132 (emphasis (gnus-article-hidden-text-p 'emphasis))
2133 (mime gnus-show-mime))
2134 (format "%c%c%c%c%c%c%c"
2136 (if (or headers boring) ?h ? )
2137 (if (or pgp pem) ?p ? )
2138 (if signature ?s ? )
2139 (if overstrike ?o ? )
2141 (if emphasis ?e ? )))))
2143 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2145 (defun gnus-article-maybe-hide-headers ()
2146 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2147 Provided for backwards compatibility."
2148 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2150 (gnus-article-hide-headers)))
2154 (defun gnus-output-to-file (file-name)
2155 "Append the current article to a file named FILE-NAME."
2156 (let ((artbuf (current-buffer)))
2158 (insert-buffer-substring artbuf)
2159 ;; Append newline at end of the buffer as separator, and then
2161 (goto-char (point-max))
2163 (append-to-file (point-min) (point-max) file-name)
2166 (defun gnus-narrow-to-page (&optional arg)
2167 "Narrow the article buffer to a page.
2168 If given a numerical ARG, move forward ARG pages."
2170 (setq arg (if arg (prefix-numeric-value arg) 0))
2172 (set-buffer gnus-article-buffer)
2173 (goto-char (point-min))
2175 ;; Remove any old next/prev buttons.
2176 (when (gnus-visual-p 'page-marker)
2177 (let ((buffer-read-only nil))
2178 (gnus-remove-text-with-property 'gnus-prev)
2179 (gnus-remove-text-with-property 'gnus-next)))
2182 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2184 (re-search-forward page-delimiter nil 'move arg)))
2185 (goto-char (match-end 0)))
2188 (if (re-search-forward page-delimiter nil 'move)
2191 (when (and (gnus-visual-p 'page-marker)
2192 (not (= (point-min) 1)))
2194 (goto-char (point-min))
2195 (gnus-insert-prev-page-button)))
2196 (when (and (gnus-visual-p 'page-marker)
2197 (< (+ (point-max) 2) (buffer-size)))
2199 (goto-char (point-max))
2200 (gnus-insert-next-page-button)))))
2202 ;; Article mode commands
2204 (defun gnus-article-goto-next-page ()
2205 "Show the next page of the article."
2207 (when (gnus-article-next-page)
2208 (goto-char (point-min))
2209 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2211 (defun gnus-article-goto-prev-page ()
2212 "Show the next page of the article."
2214 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2215 (gnus-article-prev-page nil)))
2217 (defun gnus-article-next-page (&optional lines)
2218 "Show the next page of the current article.
2219 If end of article, return non-nil. Otherwise return nil.
2220 Argument LINES specifies lines to be scrolled up."
2222 (move-to-window-line -1)
2225 (and (pos-visible-in-window-p) ;Not continuation line.
2227 ;; Nothing in this page.
2228 (if (or (not gnus-page-broken)
2231 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2233 (gnus-narrow-to-page 1) ;Go to next page.
2235 ;; More in this page.
2236 (let ((scroll-in-place nil))
2240 ;; Long lines may cause an end-of-buffer error.
2241 (goto-char (point-max)))))
2242 (move-to-window-line 0)
2245 (defun gnus-article-prev-page (&optional lines)
2246 "Show previous page of current article.
2247 Argument LINES specifies lines to be scrolled down."
2249 (move-to-window-line 0)
2250 (if (and gnus-page-broken
2252 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2254 (gnus-narrow-to-page -1) ;Go to previous page.
2255 (goto-char (point-max))
2257 (let ((scroll-in-place nil))
2261 (beginning-of-buffer
2262 (goto-char (point-min))))
2263 (move-to-window-line 0)))))
2265 (defun gnus-article-refer-article ()
2266 "Read article specified by message-id around point."
2268 (let ((point (point)))
2269 (search-forward ">" nil t) ;Move point to end of "<....>".
2270 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2271 (let ((message-id (match-string 1)))
2273 (set-buffer gnus-summary-buffer)
2274 (gnus-summary-refer-article message-id))
2276 (error "No references around point"))))
2278 (defun gnus-article-show-summary ()
2279 "Reconfigure windows to show summary buffer."
2281 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2282 (error "There is no summary buffer for this article buffer")
2283 (gnus-article-set-globals)
2284 (gnus-configure-windows 'article)
2285 (gnus-summary-goto-subject gnus-current-article)
2286 (gnus-summary-position-point)))
2288 (defun gnus-article-describe-briefly ()
2289 "Describe article mode commands briefly."
2292 (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")))
2294 (defun gnus-article-summary-command ()
2295 "Execute the last keystroke in the summary buffer."
2297 (let ((obuf (current-buffer))
2298 (owin (current-window-configuration))
2300 (switch-to-buffer gnus-article-current-summary 'norecord)
2301 (setq func (lookup-key (current-local-map) (this-command-keys)))
2302 (call-interactively func)
2304 (set-window-configuration owin)
2305 (set-window-point (get-buffer-window (current-buffer)) (point))))
2307 (defun gnus-article-summary-command-nosave ()
2308 "Execute the last keystroke in the summary buffer."
2311 (pop-to-buffer gnus-article-current-summary 'norecord)
2312 (setq func (lookup-key (current-local-map) (this-command-keys)))
2313 (call-interactively func)))
2315 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2316 "Read a summary buffer key sequence and execute it from the article buffer."
2319 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2320 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2321 "=" "^" "\M-^" "|"))
2327 '("n" "Gn" "p" "Gp"))
2330 (set-buffer gnus-article-current-summary)
2331 (let (gnus-pick-mode)
2332 (push (or key last-command-event) unread-command-events)
2333 (setq keys (read-key-sequence nil))))
2336 (if (or (member keys nosaves)
2337 (member keys nosave-but-article)
2338 (member keys nosave-in-article))
2340 (save-window-excursion
2341 (pop-to-buffer gnus-article-current-summary 'norecord)
2342 ;; We disable the pick minor mode commands.
2343 (let (gnus-pick-mode)
2344 (setq func (lookup-key (current-local-map) keys))))
2347 (unless (member keys nosave-in-article)
2348 (set-buffer gnus-article-current-summary))
2349 (call-interactively func)
2350 (setq new-sum-point (point)))
2351 (when (member keys nosave-but-article)
2352 (pop-to-buffer gnus-article-buffer 'norecord)))
2353 ;; These commands should restore window configuration.
2354 (let ((obuf (current-buffer))
2355 (owin (current-window-configuration))
2357 (summary gnus-article-current-summary)
2358 func in-buffer selected)
2359 (if not-restore-window
2360 (pop-to-buffer summary 'norecord)
2361 (switch-to-buffer summary 'norecord))
2362 (setq in-buffer (current-buffer))
2363 ;; We disable the pick minor mode commands.
2364 (if (setq func (let (gnus-pick-mode)
2365 (lookup-key (current-local-map) keys)))
2367 (call-interactively func)
2368 (setq new-sum-point (point)))
2370 (when (eq in-buffer (current-buffer))
2371 (setq selected (gnus-summary-select-article))
2373 (unless not-restore-window
2374 (set-window-configuration owin))
2375 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2376 (set-window-point (get-buffer-window (current-buffer))
2378 (let ((win (get-buffer-window gnus-article-current-summary)))
2380 (set-window-point win new-sum-point))))))))
2382 (defun gnus-article-hide (&optional arg force)
2383 "Hide all the gruft in the current article.
2384 This means that PGP stuff, signatures, cited text and (some)
2385 headers will be hidden.
2386 If given a prefix, show the hidden text instead."
2387 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2388 (gnus-article-hide-headers arg)
2389 (gnus-article-hide-pgp arg)
2390 (gnus-article-hide-citation-maybe arg force)
2391 (gnus-article-hide-signature arg))
2393 (defun gnus-article-maybe-highlight ()
2394 "Do some article highlighting if article highlighting is requested."
2395 (when (gnus-visual-p 'article-highlight 'highlight)
2396 (gnus-article-highlight-some)))
2398 (defun gnus-check-group-server ()
2399 ;; Make sure the connection to the server is alive.
2400 (unless (gnus-server-opened
2401 (gnus-find-method-for-group gnus-newsgroup-name))
2402 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2403 (gnus-request-group gnus-newsgroup-name t)))
2405 (defun gnus-request-article-this-buffer (article group)
2406 "Get an article and insert it into this buffer."
2407 (let (do-update-line sparse-header)
2411 (gnus-kill-all-overlays)
2412 (setq group (or group gnus-newsgroup-name))
2414 ;; Using `gnus-request-article' directly will insert the article into
2415 ;; `nntp-server-buffer' - so we'll save some time by not having to
2416 ;; copy it from the server buffer into the article buffer.
2418 ;; We only request an article by message-id when we do not have the
2419 ;; headers for it, so we'll have to get those.
2420 (when (stringp article)
2421 (let ((gnus-override-method gnus-refer-article-method))
2422 (gnus-read-header article)))
2424 ;; If the article number is negative, that means that this article
2425 ;; doesn't belong in this newsgroup (possibly), so we find its
2426 ;; message-id and request it by id instead of number.
2427 (when (and (numberp article)
2429 (get-buffer gnus-summary-buffer)
2430 (gnus-buffer-exists-p gnus-summary-buffer))
2432 (set-buffer gnus-summary-buffer)
2433 (let ((header (gnus-summary-article-header article)))
2436 ((memq article gnus-newsgroup-sparse)
2437 ;; This is a sparse gap article.
2438 (setq do-update-line article)
2439 (setq article (mail-header-id header))
2440 (let ((gnus-override-method gnus-refer-article-method))
2441 (setq sparse-header (gnus-read-header article)))
2442 (setq gnus-newsgroup-sparse
2443 (delq article gnus-newsgroup-sparse)))
2445 ;; It's a real article.
2446 (setq article (mail-header-id header)))
2448 ;; It is an extracted pseudo-article.
2449 (setq article 'pseudo)
2450 (gnus-request-pseudo-article header))))
2452 (let ((method (gnus-find-method-for-group
2453 gnus-newsgroup-name)))
2454 (when (and (eq (car method) 'nneething)
2457 (file-name-as-directory
2458 (or (cadr (assq 'nneething-address method))
2460 (mail-header-subject header))))
2461 (when (file-directory-p dir)
2462 (setq article 'nneething)
2463 (gnus-group-enter-directory dir))))))))
2466 ;; Refuse to select canceled articles.
2467 ((and (numberp article)
2469 (get-buffer gnus-summary-buffer)
2470 (gnus-buffer-exists-p gnus-summary-buffer)
2471 (eq (cdr (save-excursion
2472 (set-buffer gnus-summary-buffer)
2473 (assq article gnus-newsgroup-reads)))
2474 gnus-canceled-mark))
2476 ;; We first check `gnus-original-article-buffer'.
2477 ((and (get-buffer gnus-original-article-buffer)
2480 (set-buffer gnus-original-article-buffer)
2481 (and (equal (car gnus-original-article) group)
2482 (eq (cdr gnus-original-article) article))))
2483 (insert-buffer-substring gnus-original-article-buffer)
2485 ;; Check the backlog.
2486 ((and gnus-keep-backlog
2487 (gnus-backlog-request-article group article (current-buffer)))
2489 ;; Check asynchronous pre-fetch.
2490 ((gnus-async-request-fetched-article group article (current-buffer))
2491 (gnus-async-prefetch-next group article gnus-summary-buffer)
2492 (when (and (numberp article) gnus-keep-backlog)
2493 (gnus-backlog-enter-article group article (current-buffer)))
2496 ((and gnus-use-cache
2498 (gnus-cache-request-article article group))
2500 ;; Get the article and put into the article buffer.
2501 ((or (stringp article) (numberp article))
2502 (let ((gnus-override-method
2503 (and (stringp article) gnus-refer-article-method))
2504 (buffer-read-only nil))
2506 (gnus-kill-all-overlays)
2507 (gnus-check-group-server)
2508 (when (gnus-request-article article group (current-buffer))
2509 (when (numberp article)
2510 (gnus-async-prefetch-next group article gnus-summary-buffer)
2511 (when gnus-keep-backlog
2512 (gnus-backlog-enter-article
2513 group article (current-buffer))))
2518 ;; Associate this article with the current summary buffer.
2519 (setq gnus-article-current-summary gnus-summary-buffer)
2521 ;; Take the article from the original article buffer
2522 ;; and place it in the buffer it's supposed to be in.
2523 (when (and (get-buffer gnus-article-buffer)
2524 (equal (buffer-name (current-buffer))
2525 (buffer-name (get-buffer gnus-article-buffer))))
2527 (if (get-buffer gnus-original-article-buffer)
2528 (set-buffer gnus-original-article-buffer)
2529 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2530 (buffer-disable-undo (current-buffer))
2531 (setq major-mode 'gnus-original-article-mode)
2532 (setq buffer-read-only t))
2533 (let (buffer-read-only)
2535 (insert-buffer-substring gnus-article-buffer))
2536 (setq gnus-original-article (cons group article))))
2538 ;; Update sparse articles.
2539 (when (and do-update-line
2540 (or (numberp article)
2542 (let ((buf (current-buffer)))
2543 (set-buffer gnus-summary-buffer)
2544 (gnus-summary-update-article do-update-line sparse-header)
2545 (gnus-summary-goto-subject do-update-line nil t)
2546 (set-window-point (get-buffer-window (current-buffer) t)
2548 (set-buffer buf))))))
2554 (defcustom gnus-article-edit-mode-hook nil
2555 "Hook run in article edit mode buffers."
2556 :group 'gnus-article-various
2559 (defvar gnus-article-edit-done-function nil)
2561 (defvar gnus-article-edit-mode-map nil)
2563 (unless gnus-article-edit-mode-map
2564 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2566 (gnus-define-keys gnus-article-edit-mode-map
2567 "\C-c\C-c" gnus-article-edit-done
2568 "\C-c\C-k" gnus-article-edit-exit)
2570 (gnus-define-keys (gnus-article-edit-wash-map
2571 "\C-c\C-w" gnus-article-edit-mode-map)
2572 "f" gnus-article-edit-full-stops))
2574 (defun gnus-article-edit-mode ()
2575 "Major mode for editing articles.
2576 This is an extended text-mode.
2578 \\{gnus-article-edit-mode-map}"
2580 (setq major-mode 'gnus-article-edit-mode)
2581 (setq mode-name "Article Edit")
2582 (use-local-map gnus-article-edit-mode-map)
2583 (make-local-variable 'gnus-article-edit-done-function)
2584 (make-local-variable 'gnus-prev-winconf)
2585 (setq buffer-read-only nil)
2586 (buffer-enable-undo)
2588 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2590 (defun gnus-article-edit (&optional force)
2591 "Edit the current article.
2592 This will have permanent effect only in mail groups.
2593 If FORCE is non-nil, allow editing of articles even in read-only
2596 (when (and (not force)
2597 (gnus-group-read-only-p))
2598 (error "The current newsgroup does not support article editing"))
2599 (gnus-article-date-original)
2600 (gnus-article-edit-article
2601 `(lambda (no-highlight)
2602 (gnus-summary-edit-article-done
2603 ,(or (mail-header-references gnus-current-headers) "")
2604 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2606 (defun gnus-article-edit-article (exit-func)
2607 "Start editing the contents of the current article buffer."
2608 (let ((winconf (current-window-configuration)))
2609 (set-buffer gnus-article-buffer)
2610 (gnus-article-edit-mode)
2611 (gnus-article-delete-text-of-type 'annotation)
2612 (gnus-set-text-properties (point-min) (point-max) nil)
2613 (gnus-configure-windows 'edit-article)
2614 (setq gnus-article-edit-done-function exit-func)
2615 (setq gnus-prev-winconf winconf)
2616 (gnus-message 6 "C-c C-c to end edits")))
2618 (defun gnus-article-edit-done (&optional arg)
2619 "Update the article edits and exit."
2624 (goto-char (point-min))
2625 (when (search-forward "\n\n" nil 1)
2626 (let ((lines (count-lines (point) (point-max)))
2627 (length (- (point-max) (point)))
2628 (case-fold-search t)
2629 (body (copy-marker (point))))
2630 (goto-char (point-min))
2631 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2632 (delete-region (match-beginning 1) (match-end 1))
2633 (insert (number-to-string length)))
2634 (goto-char (point-min))
2635 (when (re-search-forward
2636 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2637 (delete-region (match-beginning 1) (match-end 1))
2638 (insert (number-to-string length)))
2639 (goto-char (point-min))
2640 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2641 (delete-region (match-beginning 1) (match-end 1))
2642 (insert (number-to-string lines)))))))
2643 (let ((func gnus-article-edit-done-function)
2644 (buf (current-buffer))
2645 (start (window-start)))
2646 (gnus-article-edit-exit)
2649 (let ((buffer-read-only nil))
2650 (funcall func arg)))
2652 (set-window-start (get-buffer-window buf) start)
2653 (set-window-point (get-buffer-window buf) (point))))
2655 (defun gnus-article-edit-exit ()
2656 "Exit the article editing without updating."
2658 ;; We remove all text props from the article buffer.
2659 (let ((buf (format "%s" (buffer-string)))
2660 (curbuf (current-buffer))
2662 (window-start (window-start)))
2665 (let ((winconf gnus-prev-winconf))
2667 ;; The cache and backlog have to be flushed somewhat.
2668 (when gnus-use-cache
2669 (gnus-cache-update-article
2670 (car gnus-article-current) (cdr gnus-article-current)))
2671 (when gnus-keep-backlog
2672 (gnus-backlog-remove-article
2673 (car gnus-article-current) (cdr gnus-article-current)))
2674 ;; Flush original article as well.
2676 (when (get-buffer gnus-original-article-buffer)
2677 (set-buffer gnus-original-article-buffer)
2678 (setq gnus-original-article nil)))
2679 (set-window-configuration winconf)
2680 ;; Tippy-toe some to make sure that point remains where it was.
2681 (let ((buf (current-buffer)))
2683 (set-window-start (get-buffer-window (current-buffer)) window-start)
2685 (set-buffer buf)))))
2687 (defun gnus-article-edit-full-stops ()
2688 "Interactively repair spacing at end of sentences."
2691 (goto-char (point-min))
2692 (search-forward-regexp "^$" nil t)
2693 (let ((case-fold-search nil))
2694 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2697 ;;; Article highlights
2700 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2702 ;;; Internal Variables:
2704 (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\\)"
2705 "Regular expression that matches URLs."
2706 :group 'gnus-article-buttons
2709 (defcustom gnus-button-alist
2710 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2711 gnus-button-message-id 2)
2712 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2713 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2715 gnus-button-fetch-group 4)
2716 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2717 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2718 t gnus-button-message-id 3)
2719 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2720 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2721 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2722 ;; This is how URLs _should_ be embedded in text...
2723 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2725 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2726 "*Alist of regexps matching buttons in article bodies.
2728 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2729 REGEXP: is the string matching text around the button,
2730 BUTTON: is the number of the regexp grouping actually matching the button,
2731 FORM: is a lisp expression which must eval to true for the button to
2733 CALLBACK: is the function to call when the user push this button, and each
2734 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2736 CALLBACK can also be a variable, in that case the value of that
2737 variable it the real callback function."
2738 :group 'gnus-article-buttons
2739 :type '(repeat (list regexp
2740 (integer :tag "Button")
2742 (function :tag "Callback")
2745 (integer :tag "Regexp group")))))
2747 (defcustom gnus-header-button-alist
2748 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2749 0 t gnus-button-message-id 0)
2750 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2751 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2752 0 t gnus-button-mailto 0)
2753 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2754 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2755 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2756 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2757 gnus-button-message-id 3))
2758 "*Alist of headers and regexps to match buttons in article heads.
2760 This alist is very similar to `gnus-button-alist', except that each
2761 alist has an additional HEADER element first in each entry:
2763 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2765 HEADER is a regexp to match a header. For a fuller explanation, see
2766 `gnus-button-alist'."
2767 :group 'gnus-article-buttons
2768 :group 'gnus-article-headers
2769 :type '(repeat (list (regexp :tag "Header")
2771 (integer :tag "Button")
2773 (function :tag "Callback")
2776 (integer :tag "Regexp group")))))
2778 (defvar gnus-button-regexp nil)
2779 (defvar gnus-button-marker-list nil)
2780 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2782 (defvar gnus-button-last nil)
2783 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2787 (defun gnus-article-push-button (event)
2788 "Check text under the mouse pointer for a callback function.
2789 If the text under the mouse pointer has a `gnus-callback' property,
2790 call it with the value of the `gnus-data' text property."
2792 (set-buffer (window-buffer (posn-window (event-start event))))
2793 (let* ((pos (posn-point (event-start event)))
2794 (data (get-text-property pos 'gnus-data))
2795 (fun (get-text-property pos 'gnus-callback)))
2798 (funcall fun data))))
2800 (defun gnus-article-press-button ()
2801 "Check text at point for a callback function.
2802 If the text at point has a `gnus-callback' property,
2803 call it with the value of the `gnus-data' text property."
2805 (let* ((data (get-text-property (point) 'gnus-data))
2806 (fun (get-text-property (point) 'gnus-callback)))
2808 (funcall fun data))))
2810 (defun gnus-article-prev-button (n)
2811 "Move point to N buttons backward.
2812 If N is negative, move forward instead."
2814 (gnus-article-next-button (- n)))
2816 (defun gnus-article-next-button (n)
2817 "Move point to N buttons forward.
2818 If N is negative, move backward instead."
2820 (let ((function (if (< n 0) 'previous-single-property-change
2821 'next-single-property-change))
2822 (inhibit-point-motion-hooks t)
2824 (limit (if (< n 0) (point-min) (point-max))))
2826 (while (and (not (= limit (point)))
2828 ;; Skip past the current button.
2829 (when (get-text-property (point) 'gnus-callback)
2830 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2831 ;; Go to the next (or previous) button.
2832 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2833 ;; Put point at the start of the button.
2834 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2835 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2836 ;; Skip past intangible buttons.
2837 (when (get-text-property (point) 'intangible)
2841 (gnus-message 5 "No more buttons"))
2844 (defun gnus-article-highlight (&optional force)
2845 "Highlight current article.
2846 This function calls `gnus-article-highlight-headers',
2847 `gnus-article-highlight-citation',
2848 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2849 do the highlighting. See the documentation for those functions."
2850 (interactive (list 'force))
2851 (gnus-article-highlight-headers)
2852 (gnus-article-highlight-citation force)
2853 (gnus-article-highlight-signature)
2854 (gnus-article-add-buttons force)
2855 (gnus-article-add-buttons-to-head))
2857 (defun gnus-article-highlight-some (&optional force)
2858 "Highlight current article.
2859 This function calls `gnus-article-highlight-headers',
2860 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2861 do the highlighting. See the documentation for those functions."
2862 (interactive (list 'force))
2863 (gnus-article-highlight-headers)
2864 (gnus-article-highlight-signature)
2865 (gnus-article-add-buttons))
2867 (defun gnus-article-highlight-headers ()
2868 "Highlight article headers as specified by `gnus-header-face-alist'."
2871 (set-buffer gnus-article-buffer)
2873 (let ((alist gnus-header-face-alist)
2874 (buffer-read-only nil)
2875 (case-fold-search t)
2876 (inhibit-point-motion-hooks t)
2877 entry regexp header-face field-face from hpoints fpoints)
2878 (message-narrow-to-head)
2879 (while (setq entry (pop alist))
2880 (goto-char (point-min))
2881 (setq regexp (concat "^\\("
2882 (if (string-equal "" (nth 0 entry))
2886 header-face (nth 1 entry)
2887 field-face (nth 2 entry))
2888 (while (and (re-search-forward regexp nil t)
2892 (unless (search-forward ":" nil t)
2894 (when (and header-face
2895 (not (memq (point) hpoints)))
2896 (push (point) hpoints)
2897 (gnus-put-text-property from (point) 'face header-face))
2898 (when (and field-face
2899 (not (memq (setq from (point)) fpoints)))
2901 (if (re-search-forward "^[^ \t]" nil t)
2903 (goto-char (point-max)))
2904 (gnus-put-text-property from (point) 'face field-face))))))))
2906 (defun gnus-article-highlight-signature ()
2907 "Highlight the signature in an article.
2908 It does this by highlighting everything after
2909 `gnus-signature-separator' using `gnus-signature-face'."
2912 (set-buffer gnus-article-buffer)
2913 (let ((buffer-read-only nil)
2914 (inhibit-point-motion-hooks t))
2916 (when (and gnus-signature-face
2917 (gnus-article-narrow-to-signature))
2918 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2919 'face gnus-signature-face)
2921 (gnus-article-search-signature)
2922 (let ((start (match-beginning 0))
2923 (end (set-marker (make-marker) (1+ (match-end 0)))))
2924 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2927 (defun gnus-button-in-region-p (b e prop)
2928 "Say whether PROP exists in the region."
2929 (text-property-not-all b e prop nil))
2931 (defun gnus-article-add-buttons (&optional force)
2932 "Find external references in the article and make buttons of them.
2933 \"External references\" are things like Message-IDs and URLs, as
2934 specified by `gnus-button-alist'."
2935 (interactive (list 'force))
2937 (set-buffer gnus-article-buffer)
2938 (let ((buffer-read-only nil)
2939 (inhibit-point-motion-hooks t)
2940 (case-fold-search t)
2941 (alist gnus-button-alist)
2943 ;; Remove all old markers.
2945 (while (setq marker (pop gnus-button-marker-list))
2947 (when (setq entry (gnus-button-entry))
2948 (put-text-property (match-beginning (nth 1 entry))
2949 (match-end (nth 1 entry))
2950 'gnus-callback nil))
2951 (set-marker marker nil)))
2952 ;; We skip the headers.
2953 (goto-char (point-min))
2954 (unless (search-forward "\n\n" nil t)
2955 (goto-char (point-max)))
2957 (while (setq entry (pop alist))
2958 (setq regexp (car entry))
2960 (while (re-search-forward regexp nil t)
2961 (let* ((start (and entry (match-beginning (nth 1 entry))))
2962 (end (and entry (match-end (nth 1 entry))))
2963 (from (match-beginning 0)))
2964 (when (and (or (eq t (nth 2 entry))
2965 (eval (nth 2 entry)))
2966 (not (gnus-button-in-region-p
2967 start end 'gnus-callback)))
2968 ;; That optional form returned non-nil, so we add the
2970 (gnus-article-add-button
2971 start end 'gnus-button-push
2972 (car (push (set-marker (make-marker) from)
2973 gnus-button-marker-list))))))))))
2975 ;; Add buttons to the head of an article.
2976 (defun gnus-article-add-buttons-to-head ()
2977 "Add buttons to the head of the article."
2980 (set-buffer gnus-article-buffer)
2981 (let ((buffer-read-only nil)
2982 (inhibit-point-motion-hooks t)
2983 (case-fold-search t)
2984 (alist gnus-header-button-alist)
2986 (nnheader-narrow-to-headers)
2988 ;; Each alist entry.
2989 (setq entry (car alist)
2991 (goto-char (point-min))
2992 (while (re-search-forward (car entry) nil t)
2993 ;; Each header matching the entry.
2994 (setq beg (match-beginning 0))
2995 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2996 (match-beginning 0))
2999 (while (re-search-forward (nth 1 entry) end t)
3000 ;; Each match within a header.
3001 (let* ((entry (cdr entry))
3002 (start (match-beginning (nth 1 entry)))
3003 (end (match-end (nth 1 entry)))
3004 (form (nth 2 entry)))
3005 (goto-char (match-end 0))
3007 (gnus-article-add-button
3008 start end (nth 3 entry)
3009 (buffer-substring (match-beginning (nth 4 entry))
3010 (match-end (nth 4 entry)))))))
3014 ;;; External functions:
3016 (defun gnus-article-add-button (from to fun &optional data)
3017 "Create a button between FROM and TO with callback FUN and data DATA."
3018 (when gnus-article-button-face
3019 (gnus-overlay-put (gnus-make-overlay from to)
3020 'face gnus-article-button-face))
3021 (gnus-add-text-properties
3023 (nconc (and gnus-article-mouse-face
3024 (list gnus-mouse-face-prop gnus-article-mouse-face))
3025 (list 'gnus-callback fun)
3026 (and data (list 'gnus-data data)))))
3028 ;;; Internal functions:
3030 (defun gnus-article-set-globals ()
3032 (set-buffer gnus-summary-buffer)
3033 (gnus-set-global-variables)))
3035 (defun gnus-signature-toggle (end)
3037 (set-buffer gnus-article-buffer)
3038 (let ((buffer-read-only nil)
3039 (inhibit-point-motion-hooks t))
3040 (if (get-text-property end 'invisible)
3041 (gnus-article-unhide-text end (point-max))
3042 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3044 (defun gnus-button-entry ()
3045 ;; Return the first entry in `gnus-button-alist' matching this place.
3046 (let ((alist gnus-button-alist)
3049 (setq entry (pop alist))
3050 (if (looking-at (car entry))
3055 (defun gnus-button-push (marker)
3056 ;; Push button starting at MARKER.
3058 (set-buffer gnus-article-buffer)
3060 (let* ((entry (gnus-button-entry))
3061 (inhibit-point-motion-hooks t)
3063 (args (mapcar (lambda (group)
3064 (let ((string (match-string group)))
3065 (gnus-set-text-properties
3066 0 (length string) nil string)
3073 (fboundp (symbol-value fun)))
3074 (apply (symbol-value fun) args))
3076 (gnus-message 1 "You must define `%S' to use this button"
3077 (cons fun args)))))))
3079 (defun gnus-button-message-id (message-id)
3082 (set-buffer gnus-summary-buffer)
3083 (gnus-summary-refer-article message-id)))
3085 (defun gnus-button-fetch-group (address)
3086 "Fetch GROUP specified by ADDRESS."
3087 (if (not (string-match "[:/]" address))
3088 ;; This is just a simple group url.
3089 (gnus-group-read-ephemeral-group address gnus-select-method)
3090 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3092 (error "Can't parse %s" address)
3093 (gnus-group-read-ephemeral-group
3094 (match-string 4 address)
3095 `(nntp ,(match-string 1 address)
3096 (nntp-address ,(match-string 1 address))
3097 (nntp-port-number ,(if (match-end 3)
3098 (match-string 3 address)
3101 (defun gnus-url-parse-query-string (query &optional downcase)
3102 (let (retval pairs cur key val)
3103 (setq pairs (split-string query "&"))
3105 (setq cur (car pairs)
3107 (if (not (string-match "=" cur))
3109 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3110 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3112 (setq key (downcase key)))
3113 (setq cur (assoc key retval))
3115 (setcdr cur (cons val (cdr cur)))
3116 (setq retval (cons (list key val) retval)))))
3119 (defun gnus-url-unhex (x)
3126 (defun gnus-url-unhex-string (str &optional allow-newlines)
3127 "Remove %XXX embedded spaces, etc in a url.
3128 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3129 decoding of carriage returns and line feeds in the string, which is normally
3130 forbidden in URL encoding."
3131 (setq str (or str ""))
3133 (case-fold-search t))
3134 (while (string-match "%[0-9a-f][0-9a-f]" str)
3135 (let* ((start (match-beginning 0))
3136 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3138 (gnus-url-unhex (elt str (+ start 2))))))
3140 tmp (substring str 0 start)
3143 (char-to-string code))
3144 ((or (= code ?\n) (= code ?\r))
3146 (t (char-to-string code))))
3147 str (substring str (match-end 0)))))
3148 (setq tmp (concat tmp str))
3151 (defun gnus-url-mailto (url)
3152 ;; Send mail to someone
3153 (when (string-match "mailto:/*\\(.*\\)" url)
3154 (setq url (substring url (match-beginning 1) nil)))
3155 (let (to args subject func)
3156 (if (string-match (regexp-quote "?") url)
3157 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3158 args (gnus-url-parse-query-string
3159 (substring url (match-end 0) nil) t))
3160 (setq to (gnus-url-unhex-string url)))
3161 (setq args (cons (list "to" to) args)
3162 subject (cdr-safe (assoc "subject" args)))
3165 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3168 (message-position-on-field (caar args)))
3169 (insert (mapconcat 'identity (cdar args) ", "))
3170 (setq args (cdr args)))
3173 (message-goto-subject))))
3175 (defun gnus-button-mailto (address)
3177 (set-buffer (gnus-copy-article-buffer))
3178 (message-reply address))
3180 (defun gnus-button-reply (address)
3181 ;; Reply to ADDRESS.
3182 (message-reply address))
3184 (defun gnus-button-url (address)
3186 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3187 (if (listp browse-url-browser-function)
3188 (browse-url address)
3189 (funcall browse-url-browser-function address)))
3191 (defun gnus-button-embedded-url (address)
3193 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3194 (if (listp browse-url-browser-function)
3195 (browse-url (gnus-strip-whitespace address))
3196 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3198 ;;; Next/prev buttons in the article buffer.
3200 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3201 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3203 (defvar gnus-prev-page-map nil)
3204 (unless gnus-prev-page-map
3205 (setq gnus-prev-page-map (make-sparse-keymap))
3206 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3207 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3209 (defun gnus-insert-prev-page-button ()
3210 (let ((buffer-read-only nil))
3212 gnus-prev-page-line-format nil
3213 `(gnus-prev t local-map ,gnus-prev-page-map
3214 gnus-callback gnus-article-button-prev-page
3215 gnus-type annotation))))
3217 (defvar gnus-next-page-map nil)
3218 (unless gnus-next-page-map
3219 (setq gnus-next-page-map (make-keymap))
3220 (suppress-keymap gnus-prev-page-map)
3221 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3222 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3224 (defun gnus-button-next-page ()
3225 "Go to the next page."
3227 (let ((win (selected-window)))
3228 (select-window (get-buffer-window gnus-article-buffer t))
3229 (gnus-article-next-page)
3230 (select-window win)))
3232 (defun gnus-button-prev-page ()
3233 "Go to the prev page."
3235 (let ((win (selected-window)))
3236 (select-window (get-buffer-window gnus-article-buffer t))
3237 (gnus-article-prev-page)
3238 (select-window win)))
3240 (defun gnus-insert-next-page-button ()
3241 (let ((buffer-read-only nil))
3242 (gnus-eval-format gnus-next-page-line-format nil
3244 t local-map ,gnus-next-page-map
3245 gnus-callback gnus-article-button-next-page
3246 gnus-type annotation))))
3248 (defun gnus-article-button-next-page (arg)
3249 "Go to the next page."
3251 (let ((win (selected-window)))
3252 (select-window (get-buffer-window gnus-article-buffer t))
3253 (gnus-article-next-page)
3254 (select-window win)))
3256 (defun gnus-article-button-prev-page (arg)
3257 "Go to the prev page."
3259 (let ((win (selected-window)))
3260 (select-window (get-buffer-window gnus-article-buffer t))
3261 (gnus-article-prev-page)
3262 (select-window win)))
3268 (run-hooks 'gnus-art-load-hook)
3270 ;;; gnus-art.el ends here