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))
43 (defgroup gnus-article nil
45 :link '(custom-manual "(gnus)The Article Buffer")
48 (defgroup gnus-article-hiding nil
49 "Hiding article parts."
50 :link '(custom-manual "(gnus)Article Hiding")
53 (defgroup gnus-article-highlight nil
54 "Article highlighting."
55 :link '(custom-manual "(gnus)Article Highlighting")
59 (defgroup gnus-article-signature nil
61 :link '(custom-manual "(gnus)Article Signature")
64 (defgroup gnus-article-headers nil
66 :link '(custom-manual "(gnus)Hiding Headers")
69 (defgroup gnus-article-washing nil
70 "Special commands on articles."
71 :link '(custom-manual "(gnus)Article Washing")
74 (defgroup gnus-article-emphasis nil
75 "Fontisizing articles."
76 :link '(custom-manual "(gnus)Article Fontisizing")
79 (defgroup gnus-article-saving nil
81 :link '(custom-manual "(gnus)Saving Articles")
84 (defgroup gnus-article-mime nil
85 "Worshiping the MIME wonder."
86 :link '(custom-manual "(gnus)Using MIME")
89 (defgroup gnus-article-buttons nil
90 "Pushable buttons in the article buffer."
91 :link '(custom-manual "(gnus)Article Buttons")
94 (defgroup gnus-article-various nil
95 "Other article options."
96 :link '(custom-manual "(gnus)Misc Article")
99 (defcustom gnus-ignored-headers
100 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
101 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
102 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
103 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
104 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
105 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
106 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
107 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
108 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
109 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
110 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
111 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
112 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
113 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
114 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
115 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
116 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
117 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
119 "*All headers that start with this regexp will be hidden.
120 This variable can also be a list of regexps of headers to be ignored.
121 If `gnus-visible-headers' is non-nil, this variable will be ignored."
122 :type '(choice :custom-show nil
125 :group 'gnus-article-hiding)
127 (defcustom gnus-visible-headers
128 "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:"
129 "*All headers that do not match this regexp will be hidden.
130 This variable can also be a list of regexp of headers to remain visible.
131 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
132 :type '(repeat :value-to-internal (lambda (widget value)
133 (custom-split-regexp-maybe value))
134 :match (lambda (widget value)
136 (widget-editable-list-match widget value)))
138 :group 'gnus-article-hiding)
140 (defcustom gnus-sorted-header-list
141 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
142 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
143 "*This variable is a list of regular expressions.
144 If it is non-nil, headers that match the regular expressions will
145 be placed first in the article buffer in the sequence specified by
147 :type '(repeat regexp)
148 :group 'gnus-article-hiding)
150 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
151 "Headers that are only to be displayed if they have interesting data.
152 Possible values in this list are `empty', `newsgroups', `followup-to',
153 `reply-to', `date', `long-to', and `many-to'."
154 :type '(set (const :tag "Headers with no content." empty)
155 (const :tag "Newsgroups with only one group." newsgroups)
156 (const :tag "Followup-to identical to newsgroups." followup-to)
157 (const :tag "Reply-to identical to from." reply-to)
158 (const :tag "Date less than four days old." date)
159 (const :tag "Very long To header." long-to)
160 (const :tag "Multiple To headers." many-to))
161 :group 'gnus-article-hiding)
163 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
164 "Regexp matching signature separator.
165 This can also be a list of regexps. In that case, it will be checked
166 from head to tail looking for a separator. Searches will be done from
167 the end of the buffer."
168 :type '(repeat string)
169 :group 'gnus-article-signature)
171 (defcustom gnus-signature-limit nil
172 "Provide a limit to what is considered a signature.
173 If it is a number, no signature may not be longer (in characters) than
174 that number. If it is a floating point number, no signature may be
175 longer (in lines) than that number. If it is a function, the function
176 will be called without any parameters, and if it returns nil, there is
177 no signature in the buffer. If it is a string, it will be used as a
178 regexp. If it matches, the text in question is not a signature."
179 :type '(choice (integer :value 200)
181 (function :value fun)
182 (regexp :value ".*"))
183 :group 'gnus-article-signature)
185 (defcustom gnus-hidden-properties '(invisible t intangible t)
186 "Property list to use for hiding text."
188 :group 'gnus-article-hiding)
190 (defcustom gnus-article-x-face-command
191 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
192 "*String or function to be executed to display an X-Face header.
193 If it is a string, the command will be executed in a sub-shell
194 asynchronously. The compressed face will be piped to this command."
195 :type 'string ;Leave function case to Lisp.
196 :group 'gnus-article-washing)
198 (defcustom gnus-article-x-face-too-ugly nil
199 "Regexp matching posters whose face shouldn't be shown automatically."
200 :type '(choice regexp (const nil))
201 :group 'gnus-article-washing)
203 (defcustom gnus-emphasis-alist
205 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
207 '(("_" "_" underline)
210 ("_/" "/_" underline-italic)
211 ("_\\*" "\\*_" underline-bold)
212 ("\\*/" "/\\*" bold-italic)
213 ("_\\*/" "/\\*_" underline-bold-italic))))
214 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
215 2 3 gnus-emphasis-underline)
219 (format format (car spec) (cadr spec))
220 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
222 "*Alist that says how to fontify certain phrases.
223 Each item looks like this:
225 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
227 The first element is a regular expression to be matched. The second
228 is a number that says what regular expression grouping used to find
229 the entire emphasized word. The third is a number that says what
230 regexp grouping should be displayed and highlighted. The fourth
231 is the face used for highlighting."
232 :type '(repeat (list :value ("" 0 0 default)
234 (integer :tag "Match group")
235 (integer :tag "Emphasize group")
237 :group 'gnus-article-emphasis)
239 (defface gnus-emphasis-bold '((t (:bold t)))
240 "Face used for displaying strong emphasized text (*word*)."
241 :group 'gnus-article-emphasis)
243 (defface gnus-emphasis-italic '((t (:italic t)))
244 "Face used for displaying italic emphasized text (/word/)."
245 :group 'gnus-article-emphasis)
247 (defface gnus-emphasis-underline '((t (:underline t)))
248 "Face used for displaying underlined emphasized text (_word_)."
249 :group 'gnus-article-emphasis)
251 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
252 "Face used for displaying underlined bold emphasized text (_*word*_)."
253 :group 'gnus-article-emphasis)
255 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
256 "Face used for displaying underlined italic emphasized text (_*word*_)."
257 :group 'gnus-article-emphasis)
259 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
260 "Face used for displaying bold italic emphasized text (/*word*/)."
261 :group 'gnus-article-emphasis)
263 (defface gnus-emphasis-underline-bold-italic
264 '((t (:bold t :italic t :underline t)))
265 "Face used for displaying underlined bold italic emphasized text.
266 Esample: (_/*word*/_)."
267 :group 'gnus-article-emphasis)
269 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
270 "Format for display of Date headers in article bodies.
271 See `format-time-string' for the possible values.
273 The variable can also be function, which should return a complete Date
274 header. The function is called with one argument, the time, which can
275 be fed to `format-time-string'."
276 :type '(choice string symbol)
277 :link '(custom-manual "(gnus)Article Date")
278 :group 'gnus-article-washing)
281 (autoload 'mail-extract-address-components "mail-extr"))
283 (defcustom gnus-save-all-headers t
284 "*If non-nil, don't remove any headers before saving."
285 :group 'gnus-article-saving
288 (defcustom gnus-prompt-before-saving 'always
289 "*This variable says how much prompting is to be done when saving articles.
290 If it is nil, no prompting will be done, and the articles will be
291 saved to the default files. If this variable is `always', each and
292 every article that is saved will be preceded by a prompt, even when
293 saving large batches of articles. If this variable is neither nil not
294 `always', there the user will be prompted once for a file name for
295 each invocation of the saving commands."
296 :group 'gnus-article-saving
297 :type '(choice (item always)
298 (item :tag "never" nil)
299 (sexp :tag "once" :format "%t\n" :value t)))
301 (defcustom gnus-saved-headers gnus-visible-headers
302 "Headers to keep if `gnus-save-all-headers' is nil.
303 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
304 If that variable is nil, however, all headers that match this regexp
305 will be kept while the rest will be deleted before saving."
306 :group 'gnus-article-saving
309 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
310 "A function to save articles in your favourite format.
311 The function must be interactively callable (in other words, it must
312 be an Emacs command).
314 Gnus provides the following functions:
316 * gnus-summary-save-in-rmail (Rmail format)
317 * gnus-summary-save-in-mail (Unix mail format)
318 * gnus-summary-save-in-folder (MH folder)
319 * gnus-summary-save-in-file (article format)
320 * gnus-summary-save-in-vm (use VM's folder format)
321 * gnus-summary-write-to-file (article format -- overwrite)."
322 :group 'gnus-article-saving
323 :type '(radio (function-item gnus-summary-save-in-rmail)
324 (function-item gnus-summary-save-in-mail)
325 (function-item gnus-summary-save-in-folder)
326 (function-item gnus-summary-save-in-file)
327 (function-item gnus-summary-save-in-vm)
328 (function-item gnus-summary-write-to-file)))
330 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
331 "A function generating a file name to save articles in Rmail format.
332 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
333 :group 'gnus-article-saving
336 (defcustom gnus-mail-save-name 'gnus-plain-save-name
337 "A function generating a file name to save articles in Unix mail format.
338 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
339 :group 'gnus-article-saving
342 (defcustom gnus-folder-save-name 'gnus-folder-save-name
343 "A function generating a file name to save articles in MH folder.
344 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
345 :group 'gnus-article-saving
348 (defcustom gnus-file-save-name 'gnus-numeric-save-name
349 "A function generating a file name to save articles in article format.
350 The function is called with NEWSGROUP, HEADERS, and optional
352 :group 'gnus-article-saving
355 (defcustom gnus-split-methods
356 '((gnus-article-archive-name)
357 (gnus-article-nndoc-name))
358 "*Variable used to suggest where articles are to be saved.
359 For instance, if you would like to save articles related to Gnus in
360 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
361 you could set this variable to something like:
363 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
364 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
366 This variable is an alist where the where the key is the match and the
367 value is a list of possible files to save in if the match is non-nil.
369 If the match is a string, it is used as a regexp match on the
370 article. If the match is a symbol, that symbol will be funcalled
371 from the buffer of the article to be saved with the newsgroup as the
372 parameter. If it is a list, it will be evaled in the same buffer.
374 If this form or function returns a string, this string will be used as
375 a possible file name; and if it returns a non-nil list, that list will
376 be used as possible file names."
377 :group 'gnus-article-saving
378 :type '(repeat (choice (list :value (fun) function)
379 (cons :value ("" "") regexp (repeat string))
382 (defcustom gnus-page-delimiter "^\^L"
383 "*Regexp describing what to use as article page delimiters.
384 The default value is \"^\^L\", which is a form linefeed at the
385 beginning of a line."
387 :group 'gnus-article-various)
389 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
390 "*The format specification for the article mode line.
391 See `gnus-summary-mode-line-format' for a closer description."
393 :group 'gnus-article-various)
395 (defcustom gnus-article-mode-hook nil
396 "*A hook for Gnus article mode."
398 :group 'gnus-article-various)
400 (defcustom gnus-article-menu-hook nil
401 "*Hook run after the creation of the article mode menu."
403 :group 'gnus-article-various)
405 (defcustom gnus-article-prepare-hook nil
406 "*A hook called after an article has been prepared in the article buffer.
407 If you want to run a special decoding program like nkf, use this hook."
409 :group 'gnus-article-various)
411 (defcustom gnus-article-hide-pgp-hook nil
412 "*A hook called after successfully hiding a PGP signature."
414 :group 'gnus-article-various)
416 (defcustom gnus-article-button-face 'bold
417 "Face used for highlighting buttons in the article buffer.
419 An article button is a piece of text that you can activate by pressing
420 `RET' or `mouse-2' above it."
422 :group 'gnus-article-buttons)
424 (defcustom gnus-article-mouse-face 'highlight
425 "Face used for mouse highlighting in the article buffer.
427 Article buttons will be displayed in this face when the cursor is
430 :group 'gnus-article-buttons)
432 (defcustom gnus-signature-face 'gnus-signature-face
433 "Face used for highlighting a signature in the article buffer.
434 Obsolete; use the face `gnus-signature-face' for customizations instead."
436 :group 'gnus-article-highlight
437 :group 'gnus-article-signature)
439 (defface gnus-signature-face
442 "Face used for highlighting a signature in the article buffer."
443 :group 'gnus-article-highlight
444 :group 'gnus-article-signature)
446 (defface gnus-header-from-face
449 (:foreground "spring green"))
452 (:foreground "red3"))
455 "Face used for displaying from headers."
456 :group 'gnus-article-headers
457 :group 'gnus-article-highlight)
459 (defface gnus-header-subject-face
462 (:foreground "SeaGreen3"))
465 (:foreground "red4"))
467 (:bold t :italic t)))
468 "Face used for displaying subject headers."
469 :group 'gnus-article-headers
470 :group 'gnus-article-highlight)
472 (defface gnus-header-newsgroups-face
475 (:foreground "yellow" :italic t))
478 (:foreground "MidnightBlue" :italic t))
481 "Face used for displaying newsgroups headers."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-name-face
488 (:foreground "SeaGreen"))
491 (:foreground "maroon"))
494 "Face used for displaying header names."
495 :group 'gnus-article-headers
496 :group 'gnus-article-highlight)
498 (defface gnus-header-content-face
501 (:foreground "forest green" :italic t))
504 (:foreground "indianred4" :italic t))
506 (:italic t))) "Face used for displaying header content."
507 :group 'gnus-article-headers
508 :group 'gnus-article-highlight)
510 (defcustom gnus-header-face-alist
511 '(("From" nil gnus-header-from-face)
512 ("Subject" nil gnus-header-subject-face)
513 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
514 ("" gnus-header-name-face gnus-header-content-face))
515 "*Controls highlighting of article header.
517 An alist of the form (HEADER NAME CONTENT).
519 HEADER is a regular expression which should match the name of an
520 header header and NAME and CONTENT are either face names or nil.
522 The name of each header field will be displayed using the face
523 specified by the first element in the list where HEADER match the
524 header name and NAME is non-nil. Similarly, the content will be
525 displayed by the first non-nil matching CONTENT face."
526 :group 'gnus-article-headers
527 :group 'gnus-article-highlight
528 :type '(repeat (list (regexp :tag "Header")
530 (item :tag "skip" nil)
531 (face :value default))
532 (choice :tag "Content"
533 (item :tag "skip" nil)
534 (face :value default)))))
536 (defcustom gnus-article-decode-hook
537 '(article-decode-charset article-decode-encoded-words)
538 "*Hook run to decode charsets in articles."
539 :group 'gnus-article-headers
542 (defcustom gnus-display-mime-function 'gnus-display-mime
543 "Function to display MIME articles."
544 :group 'gnus-article-headers
547 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
548 "Function used to decode headers.")
550 (defvar gnus-article-dumbquotes-map
569 "Table for MS-to-Latin1 translation.")
571 (defcustom gnus-ignored-mime-types nil
572 "List of MIME types that should be ignored by Gnus."
574 :type '(repeat regexp))
576 (defcustom gnus-treat-body-highlight-signature t
577 "Highlight the signature."
579 :type '(choice (const :tag "Off" nil)
581 (const :tag "Last" last)
582 (integer :tag "Less")
583 (sexp :tag "Predicate")))
585 (defcustom gnus-article-mime-part-function nil
586 "Function called with a MIME handle as the argument."
590 ;;; Internal variables
592 (defvar gnus-treatment-function-alist
593 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
596 (defvar gnus-article-mime-handle-alist nil)
597 (defvar article-lapsed-timer nil)
598 (defvar gnus-article-current-summary nil)
600 (defvar gnus-article-mode-syntax-table
601 (let ((table (copy-syntax-table text-mode-syntax-table)))
602 (modify-syntax-entry ?- "w" table)
603 (modify-syntax-entry ?> ")" table)
604 (modify-syntax-entry ?< "(" table)
606 "Syntax table used in article mode buffers.
607 Initialized from `text-mode-syntax-table.")
609 (defvar gnus-save-article-buffer nil)
611 (defvar gnus-article-mode-line-format-alist
612 (nconc '((?w (gnus-article-wash-status) ?s))
613 gnus-summary-mode-line-format-alist))
615 (defvar gnus-number-of-articles-to-be-saved nil)
617 (defvar gnus-inhibit-hiding nil)
619 (defsubst gnus-article-hide-text (b e props)
620 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
621 (add-text-properties b e props)
622 (when (memq 'intangible props)
624 (max (1- b) (point-min))
625 b 'intangible (cddr (memq 'intangible props)))))
627 (defsubst gnus-article-unhide-text (b e)
628 "Remove hidden text properties from region between B and E."
629 (remove-text-properties b e gnus-hidden-properties)
630 (when (memq 'intangible gnus-hidden-properties)
631 (put-text-property (max (1- b) (point-min))
634 (defun gnus-article-hide-text-type (b e type)
635 "Hide text of TYPE between B and E."
636 (gnus-article-hide-text
637 b e (cons 'article-type (cons type gnus-hidden-properties))))
639 (defun gnus-article-unhide-text-type (b e type)
640 "Unhide text of TYPE between B and E."
641 (remove-text-properties
642 b e (cons 'article-type (cons type gnus-hidden-properties)))
643 (when (memq 'intangible gnus-hidden-properties)
644 (put-text-property (max (1- b) (point-min))
647 (defun gnus-article-hide-text-of-type (type)
648 "Hide text of TYPE in the current buffer."
650 (let ((b (point-min))
652 (while (setq b (text-property-any b e 'article-type type))
653 (add-text-properties b (incf b) gnus-hidden-properties)))))
655 (defun gnus-article-delete-text-of-type (type)
656 "Delete text of TYPE in the current buffer."
658 (let ((b (point-min)))
659 (while (setq b (text-property-any b (point-max) 'article-type type))
661 b (or (text-property-not-all b (point-max) 'article-type type)
664 (defun gnus-article-delete-invisible-text ()
665 "Delete all invisible text in the current buffer."
667 (let ((b (point-min)))
668 (while (setq b (text-property-any b (point-max) 'invisible t))
670 b (or (text-property-not-all b (point-max) 'invisible t)
673 (defun gnus-article-text-type-exists-p (type)
674 "Say whether any text of type TYPE exists in the buffer."
675 (text-property-any (point-min) (point-max) 'article-type type))
677 (defsubst gnus-article-header-rank ()
678 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
679 (let ((list gnus-sorted-header-list)
682 (when (looking-at (car list))
684 (setq list (cdr list))
688 (defun article-hide-headers (&optional arg delete)
689 "Toggle whether to hide unwanted headers and possibly sort them as well.
690 If given a negative prefix, always show; if given a positive prefix,
692 (interactive (gnus-article-hidden-arg))
694 (if (gnus-article-check-hidden-text 'headers arg)
695 ;; Show boring headers as well.
696 (gnus-article-show-hidden-text 'boring-headers)
697 ;; This function might be inhibited.
698 (unless gnus-inhibit-hiding
701 (let ((buffer-read-only nil)
703 (props (nconc (list 'article-type 'headers)
704 gnus-hidden-properties))
705 (max (1+ (length gnus-sorted-header-list)))
706 (ignored (when (not gnus-visible-headers)
707 (cond ((stringp gnus-ignored-headers)
708 gnus-ignored-headers)
709 ((listp gnus-ignored-headers)
710 (mapconcat 'identity gnus-ignored-headers
713 (cond ((stringp gnus-visible-headers)
714 gnus-visible-headers)
715 ((and gnus-visible-headers
716 (listp gnus-visible-headers))
717 (mapconcat 'identity gnus-visible-headers "\\|"))))
718 (inhibit-point-motion-hooks t)
720 ;; First we narrow to just the headers.
722 (goto-char (point-min))
723 ;; Hide any "From " lines at the beginning of (mail) articles.
724 (while (looking-at "From ")
728 (delete-region (point-min) (point))
729 (gnus-article-hide-text (point-min) (point) props)))
730 ;; Then treat the rest of the header lines.
733 (if (search-forward "\n\n" nil t) ; if there's a body
734 (progn (forward-line -1) (point))
736 ;; Then we use the two regular expressions
737 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
738 ;; select which header lines is to remain visible in the
740 (goto-char (point-min))
741 (while (re-search-forward "^[^ \t]*:" nil t)
743 ;; Mark the rank of the header.
745 (point) (1+ (point)) 'message-rank
746 (if (or (and visible (looking-at visible))
748 (not (looking-at ignored))))
749 (gnus-article-header-rank)
752 (message-sort-headers-1)
753 (when (setq beg (text-property-any
754 (point-min) (point-max) 'message-rank (+ 2 max)))
755 ;; We make the unwanted headers invisible.
757 (delete-region beg (point-max))
758 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
759 (gnus-article-hide-text-type beg (point-max) 'headers))
760 ;; Work around XEmacs lossage.
761 (put-text-property (point-min) beg 'invisible nil))))))))
763 (defun article-hide-boring-headers (&optional arg)
764 "Toggle hiding of headers that aren't very interesting.
765 If given a negative prefix, always show; if given a positive prefix,
767 (interactive (gnus-article-hidden-arg))
768 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
769 (not gnus-show-all-headers))
772 (let ((buffer-read-only nil)
773 (list gnus-boring-article-headers)
774 (inhibit-point-motion-hooks t)
776 (nnheader-narrow-to-headers)
778 (setq elem (pop list))
779 (goto-char (point-min))
781 ;; Hide empty headers.
783 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
785 (gnus-article-hide-text-type
786 (progn (beginning-of-line) (point))
789 (if (re-search-forward "^[^ \t]" nil t)
793 ;; Hide boring Newsgroups header.
794 ((eq elem 'newsgroups)
795 (when (equal (gnus-fetch-field "newsgroups")
796 (gnus-group-real-name
797 (if (boundp 'gnus-newsgroup-name)
800 (gnus-article-hide-header "newsgroups")))
801 ((eq elem 'followup-to)
802 (when (equal (message-fetch-field "followup-to")
803 (message-fetch-field "newsgroups"))
804 (gnus-article-hide-header "followup-to")))
806 (let ((from (message-fetch-field "from"))
807 (reply-to (message-fetch-field "reply-to")))
812 (nth 1 (mail-extract-address-components from))
813 (nth 1 (mail-extract-address-components reply-to)))))
814 (gnus-article-hide-header "reply-to"))))
816 (let ((date (message-fetch-field "date")))
818 (< (days-between (current-time-string) date)
820 (gnus-article-hide-header "date"))))
822 (let ((to (message-fetch-field "to")))
823 (when (> (length to) 1024)
824 (gnus-article-hide-header "to"))))
827 (goto-char (point-min))
828 (while (re-search-forward "^to:" nil t)
829 (setq to-count (1+ to-count)))
831 (while (> to-count 0)
832 (goto-char (point-min))
834 (re-search-forward "^to:" nil nil to-count)
836 (narrow-to-region (point) (point-max))
837 (gnus-article-hide-header "to"))
838 (setq to-count (1- to-count)))))))))))))
840 (defun gnus-article-hide-header (header)
842 (goto-char (point-min))
843 (when (re-search-forward (concat "^" header ":") nil t)
844 (gnus-article-hide-text-type
845 (progn (beginning-of-line) (point))
848 (if (re-search-forward "^[^ \t]" nil t)
853 (defun article-treat-dumbquotes ()
854 "Translate M******** sm*rtq**t*s into proper text."
856 (article-translate-strings gnus-article-dumbquotes-map))
858 (defun article-translate-characters (from to)
859 "Translate all characters in the body of the article according to FROM and TO.
860 FROM is a string of characters to translate from; to is a string of
861 characters to translate to."
863 (goto-char (point-min))
864 (when (search-forward "\n\n" nil t)
865 (let ((buffer-read-only nil)
866 (x (make-string 225 ?x))
868 (while (< (incf i) (length x))
871 (while (< i (length from))
872 (aset x (aref from i) (aref to i))
874 (translate-region (point) (point-max) x)))))
876 (defun article-translate-strings (map)
877 "Translate all string in the body of the article according to MAP.
878 MAP is an alist where the elements are on the form (\"from\" \"to\")."
880 (goto-char (point-min))
881 (when (search-forward "\n\n" nil t)
882 (let ((buffer-read-only nil)
884 (while (setq elem (pop map))
886 (while (search-forward (car elem) nil t)
887 (replace-match (cadr elem)))))))))
889 (defun article-treat-overstrike ()
890 "Translate overstrikes into bold text."
893 (goto-char (point-min))
894 (when (search-forward "\n\n" nil t)
895 (let ((buffer-read-only nil))
896 (while (search-forward "\b" nil t)
897 (let ((next (char-after))
898 (previous (char-after (- (point) 2))))
899 ;; We do the boldification/underlining by hiding the
900 ;; overstrikes and putting the proper text property
904 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
905 (put-text-property (point) (1+ (point)) 'face 'bold))
907 (gnus-article-hide-text-type
908 (1- (point)) (1+ (point)) 'overstrike)
910 (- (point) 2) (1- (point)) 'face 'underline))
912 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
914 (point) (1+ (point)) 'face 'underline)))))))))
916 (defun article-fill ()
917 "Format too long lines."
920 (let ((buffer-read-only nil))
922 (goto-char (point-min))
923 (search-forward "\n\n" nil t)
925 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
926 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
927 (adaptive-fill-mode t))
929 (and (>= (current-column) (min fill-column (window-width)))
930 (/= (preceding-char) ?:)
931 (fill-paragraph nil))
934 (defun article-remove-cr ()
935 "Translate CRLF pairs into LF, and then CR into LF.."
938 (let ((buffer-read-only nil))
939 (goto-char (point-min))
940 (while (search-forward "\r$" nil t)
941 (replace-match "" t t))
942 (goto-char (point-min))
943 (while (search-forward "\r" nil t)
944 (replace-match "\n" t t)))))
946 (defun article-remove-trailing-blank-lines ()
947 "Remove all trailing blank lines from the article."
950 (let ((buffer-read-only nil))
951 (goto-char (point-max))
955 (while (and (not (bobp))
956 (looking-at "^[ \t]*$")
957 (not (gnus-annotation-in-region-p
958 (point) (gnus-point-at-eol))))
963 (defun article-display-x-face (&optional force)
964 "Look for an X-Face header and display it if present."
965 (interactive (list 'force))
967 ;; Delete the old process, if any.
968 (when (process-status "article-x-face")
969 (delete-process "article-x-face"))
970 (let ((inhibit-point-motion-hooks t)
974 (nnheader-narrow-to-headers)
975 (setq from (message-fetch-field "from"))
976 (goto-char (point-min))
977 (while (and gnus-article-x-face-command
980 ;; Check whether this face is censored.
981 (not gnus-article-x-face-too-ugly)
982 (and gnus-article-x-face-too-ugly from
983 (not (string-match gnus-article-x-face-too-ugly
985 ;; Has to be present.
986 (re-search-forward "^X-Face: " nil t))
987 ;; This used to try to do multiple faces (`while' instead of
988 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
989 ;; work (b) it can crash some versions of Emacs (c) are
990 ;; multiple faces really something to encourage?
991 (when (stringp gnus-article-x-face-command)
993 ;; We now have the area of the buffer where the X-Face is stored.
996 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
997 ;; We display the face.
998 (if (symbolp gnus-article-x-face-command)
999 ;; The command is a lisp function, so we call it.
1000 (if (gnus-functionp gnus-article-x-face-command)
1001 (funcall gnus-article-x-face-command beg end)
1002 (error "%s is not a function" gnus-article-x-face-command))
1003 ;; The command is a string, so we interpret the command
1004 ;; as a, well, command, and fork it off.
1005 (let ((process-connection-type nil))
1006 (process-kill-without-query
1008 "article-x-face" nil shell-file-name shell-command-switch
1009 gnus-article-x-face-command))
1010 (process-send-region "article-x-face" beg end)
1011 (process-send-eof "article-x-face"))))))))))
1013 (defun article-decode-mime-words ()
1014 "Decode all MIME-encoded words in the article."
1017 (set-buffer gnus-article-buffer)
1018 (let ((inhibit-point-motion-hooks t)
1020 (mail-decode-encoded-word-region (point-min) (point-max)))))
1022 (defun article-decode-charset (&optional prompt)
1023 "Decode charset-encoded text in the article.
1024 If PROMPT (the prefix), prompt for a coding system to use."
1028 (message-narrow-to-head)
1029 (let* ((inhibit-point-motion-hooks t)
1030 (case-fold-search t)
1031 (ct (message-fetch-field "Content-Type" t))
1032 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1033 (ctl (and ct (condition-case ()
1034 (mail-header-parse-content-type ct)
1038 (mm-read-coding-system "Charset to decode: "))
1040 (mail-content-type-get ctl 'charset))
1041 (gnus-newsgroup-name
1042 (gnus-group-find-parameter
1043 gnus-newsgroup-name 'charset))))
1045 (goto-char (point-max))
1048 (narrow-to-region (point) (point-max))
1050 (equal (car ctl) "text/plain"))
1052 charset (and cte (intern (downcase
1053 (gnus-strip-whitespace cte))))
1056 (defun article-decode-encoded-words ()
1057 "Remove encoded-word encoding from headers."
1058 (let ((inhibit-point-motion-hooks t)
1059 (buffer-read-only nil))
1061 (message-narrow-to-head)
1062 (funcall gnus-decode-header-function (point-min) (point-max)))))
1064 (defun article-de-quoted-unreadable (&optional force)
1065 "Translate a quoted-printable-encoded article.
1066 If FORCE, decode the article whether it is marked as quoted-printable
1068 (interactive (list 'force))
1070 (let ((buffer-read-only nil)
1071 (type (gnus-fetch-field "content-transfer-encoding")))
1073 (and type (string-match "quoted-printable" (downcase type))))
1074 (goto-char (point-min))
1075 (search-forward "\n\n" nil 'move)
1077 (narrow-to-region (point) (point-max))
1078 (quoted-printable-decode-region (point-min) (point-max))
1079 (when mm-default-coding-system
1080 (mm-decode-body mm-default-coding-system)))))))
1082 (defun article-hide-pgp (&optional arg)
1083 "Toggle hiding of any PGP headers and signatures in the current article.
1084 If given a negative prefix, always show; if given a positive prefix,
1086 (interactive (gnus-article-hidden-arg))
1087 (unless (gnus-article-check-hidden-text 'pgp arg)
1089 (let ((inhibit-point-motion-hooks t)
1090 buffer-read-only beg end)
1092 (goto-char (point-min))
1093 ;; Hide the "header".
1094 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1095 (delete-region (1+ (match-beginning 0)) (match-end 0))
1096 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1097 (when (looking-at "Hash:.*$")
1098 (delete-region (point) (1+ (gnus-point-at-eol))))
1100 ;; Hide the actual signature.
1101 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1102 (setq end (1+ (match-beginning 0)))
1105 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1107 ;; Perhaps we shouldn't hide to the end of the buffer
1108 ;; if there is no end to the signature?
1110 ;; Hide "- " PGP quotation markers.
1112 (narrow-to-region beg end)
1113 (goto-char (point-min))
1114 (while (re-search-forward "^- " nil t)
1116 (match-beginning 0) (match-end 0)))
1118 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1120 (defun article-hide-pem (&optional arg)
1121 "Toggle hiding of any PEM headers and signatures in the current article.
1122 If given a negative prefix, always show; if given a positive prefix,
1124 (interactive (gnus-article-hidden-arg))
1125 (unless (gnus-article-check-hidden-text 'pem arg)
1127 (let (buffer-read-only end)
1129 (goto-char (point-min))
1130 ;; hide the horrendously ugly "header".
1131 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1134 (setq end (1+ (match-beginning 0)))
1135 (gnus-article-hide-text-type
1137 (if (search-forward "\n\n" nil t)
1141 ;; hide the trailer as well
1142 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1145 (gnus-article-hide-text-type
1146 (match-beginning 0) (match-end 0) 'pem))))))
1148 (defun article-hide-signature (&optional arg)
1149 "Hide the signature in the current article.
1150 If given a negative prefix, always show; if given a positive prefix,
1152 (interactive (gnus-article-hidden-arg))
1153 (unless (gnus-article-check-hidden-text 'signature arg)
1156 (let ((buffer-read-only nil))
1157 (when (gnus-article-narrow-to-signature)
1158 (gnus-article-hide-text-type
1159 (point-min) (point-max) 'signature)))))))
1161 (defun article-strip-leading-blank-lines ()
1162 "Remove all blank lines from the beginning of the article."
1165 (let ((inhibit-point-motion-hooks t)
1167 (goto-char (point-min))
1168 (when (search-forward "\n\n" nil t)
1169 (while (and (not (eobp))
1170 (looking-at "[ \t]*$"))
1171 (gnus-delete-line))))))
1173 (defun article-strip-multiple-blank-lines ()
1174 "Replace consecutive blank lines with one empty line."
1177 (let ((inhibit-point-motion-hooks t)
1179 ;; First make all blank lines empty.
1180 (goto-char (point-min))
1181 (search-forward "\n\n" nil t)
1182 (while (re-search-forward "^[ \t]+$" nil t)
1183 (unless (gnus-annotation-in-region-p
1184 (match-beginning 0) (match-end 0))
1185 (replace-match "" nil t)))
1186 ;; Then replace multiple empty lines with a single empty line.
1187 (goto-char (point-min))
1188 (search-forward "\n\n" nil t)
1189 (while (re-search-forward "\n\n\n+" nil t)
1190 (unless (gnus-annotation-in-region-p
1191 (match-beginning 0) (match-end 0))
1192 (replace-match "\n\n" t t))))))
1194 (defun article-strip-leading-space ()
1195 "Remove all white space from the beginning of the lines in the article."
1198 (let ((inhibit-point-motion-hooks t)
1200 (goto-char (point-min))
1201 (search-forward "\n\n" nil t)
1202 (while (re-search-forward "^[ \t]+" nil t)
1203 (replace-match "" t t)))))
1205 (defun article-strip-blank-lines ()
1206 "Strip leading, trailing and multiple blank lines."
1208 (article-strip-leading-blank-lines)
1209 (article-remove-trailing-blank-lines)
1210 (article-strip-multiple-blank-lines))
1212 (defun article-strip-all-blank-lines ()
1213 "Strip all blank lines."
1216 (let ((inhibit-point-motion-hooks t)
1218 (goto-char (point-min))
1219 (search-forward "\n\n" nil t)
1220 (while (re-search-forward "^[ \t]*\n" nil t)
1221 (replace-match "" t t)))))
1223 (defun gnus-article-narrow-to-signature ()
1224 "Narrow to the signature; return t if a signature is found, else nil."
1226 (let ((inhibit-point-motion-hooks t))
1227 (when (gnus-article-search-signature)
1229 ;; Check whether we have some limits to what we consider
1230 ;; to be a signature.
1231 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1232 (list gnus-signature-limit)))
1234 (while (setq limit (pop limits))
1235 (if (or (and (integerp limit)
1236 (< (- (point-max) (point)) limit))
1238 (< (count-lines (point) (point-max)) limit))
1239 (and (gnus-functionp limit)
1241 (and (stringp limit)
1242 (not (re-search-forward limit nil t))))
1243 () ; This limit did not succeed.
1247 (narrow-to-region (point) (point-max))
1250 (defun gnus-article-search-signature ()
1251 "Search the current buffer for the signature separator.
1252 Put point at the beginning of the signature separator."
1253 (let ((cur (point)))
1254 (goto-char (point-max))
1255 (if (if (stringp gnus-signature-separator)
1256 (re-search-backward gnus-signature-separator nil t)
1257 (let ((seps gnus-signature-separator))
1259 (not (re-search-backward (car seps) nil t)))
1267 (autoload 'w3-display "w3-parse")
1268 (autoload 'w3-do-setup "w3" "" t)
1269 (autoload 'w3-region "w3-display" "" t))
1271 (defun gnus-article-treat-html ()
1274 (let ((cbuf (current-buffer)))
1275 (set-buffer gnus-article-buffer)
1276 (let (buf buffer-read-only b e)
1278 (goto-char (point-min))
1280 (if (search-forward "\n\n" nil t)
1283 (setq e (point-max)))
1285 (insert-buffer-substring gnus-article-buffer b e)
1287 (save-window-excursion
1288 (w3-region (point-min) (point-max))
1289 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1291 (delete-region (point-min) (point-max))
1294 (goto-char (point-min))
1295 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1296 (set-buffer cbuf))))
1298 (defun gnus-article-hidden-arg ()
1299 "Return the current prefix arg as a number, or 0 if no prefix."
1300 (list (if current-prefix-arg
1301 (prefix-numeric-value current-prefix-arg)
1304 (defun gnus-article-check-hidden-text (type arg)
1305 "Return nil if hiding is necessary.
1306 Arg can be nil or a number. Nil and positive means hide, negative
1307 means show, 0 means toggle."
1311 (let ((hide (gnus-article-hidden-text-p type)))
1317 (gnus-article-show-hidden-text type))
1319 (if (eq hide 'hidden)
1320 (gnus-article-show-hidden-text type)
1323 (defun gnus-article-hidden-text-p (type)
1324 "Say whether the current buffer contains hidden text of type TYPE."
1325 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1327 (not (get-text-property pos 'invisible)))
1329 (text-property-any (1+ pos) (point-max) 'article-type type)))
1334 (defun gnus-article-show-hidden-text (type &optional hide)
1335 "Show all hidden text of type TYPE.
1336 If HIDE, hide the text instead."
1338 (let ((buffer-read-only nil)
1339 (inhibit-point-motion-hooks t)
1342 (while (setq beg (text-property-any end (point-max) 'article-type type))
1345 (text-property-not-all beg (point-max) 'article-type type)
1348 (gnus-article-hide-text beg end gnus-hidden-properties)
1349 (gnus-article-unhide-text beg end))
1353 (defconst article-time-units
1354 `((year . ,(* 365.25 24 60 60))
1355 (week . ,(* 7 24 60 60))
1356 (day . ,(* 24 60 60))
1360 "Mapping from time units to seconds.")
1362 (defun article-date-ut (&optional type highlight header)
1363 "Convert DATE date to universal time in the current article.
1364 If TYPE is `local', convert to local time; if it is `lapsed', output
1365 how much time has lapsed since DATE."
1366 (interactive (list 'ut t))
1367 (let* ((header (or header
1368 (mail-header-date gnus-current-headers)
1369 (message-fetch-field "date")
1371 (date (if (vectorp header) (mail-header-date header)
1373 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1374 (inhibit-point-motion-hooks t)
1375 bface eface newline)
1376 (when (and date (not (string= date "")))
1379 (nnheader-narrow-to-headers)
1380 (let ((buffer-read-only nil))
1381 ;; Delete any old Date headers.
1382 (if (re-search-forward date-regexp nil t)
1384 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1385 eface (get-text-property (1- (gnus-point-at-eol))
1387 (delete-region (progn (beginning-of-line) (point))
1388 (progn (end-of-line) (point)))
1389 (beginning-of-line))
1390 (goto-char (point-max))
1392 (insert (article-make-date-line date type))
1395 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1396 (put-text-property (match-beginning 1) (1+ (match-end 1))
1398 (put-text-property (match-beginning 2) (match-end 2)
1402 (insert "\n"))))))))
1404 (defun article-make-date-line (date type)
1405 "Return a DATE line of TYPE."
1406 (let ((time (condition-case ()
1410 ;; Convert to the local timezone. We have to slap a
1411 ;; `condition-case' round the calls to the timezone
1412 ;; functions since they aren't particularly resistant to
1415 (let ((tz (car (current-time-zone))))
1416 (format "Date: %s %s%04d" (current-time-string time)
1417 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1418 ;; Convert to Universal Time.
1421 (current-time-string
1422 (let* ((e (parse-time-string date))
1423 (tm (apply 'encode-time e))
1425 (ls (- (cadr tm) (car (current-time-zone)))))
1426 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1427 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1430 ;; Get the original date from the article.
1431 ((eq type 'original)
1432 (concat "Date: " (if (string-match "\n+$" date)
1433 (substring date 0 (match-beginning 0))
1435 ;; Let the user define the format.
1437 (if (gnus-functionp gnus-article-time-format)
1438 (funcall gnus-article-time-format time)
1441 (format-time-string gnus-article-time-format time))))
1446 (format-time-string "%Y%M%DT%h%m%s" time)))
1447 ;; Do an X-Sent lapsed format.
1449 ;; If the date is seriously mangled, the timezone functions are
1450 ;; liable to bug out, so we ignore all errors.
1451 (let* ((now (current-time))
1452 (real-time (subtract-time now time))
1453 (real-sec (and real-time
1454 (+ (* (float (car real-time)) 65536)
1456 (sec (and real-time (abs real-sec)))
1466 ;; This is a bit convoluted, but basically we go
1467 ;; through the time units for years, weeks, etc,
1468 ;; and divide things to see whether that results
1469 ;; in positive answers.
1472 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1473 ;; The (remaining) seconds are too few to
1474 ;; be divided into this time unit.
1476 ;; It's big enough, so we output it.
1477 (setq sec (- sec (* num (cdr unit))))
1479 (concat (if prev ", " "") (int-to-string
1481 " " (symbol-name (car unit))
1482 (if (> num 1) "s" ""))
1484 article-time-units "")
1485 ;; If dates are odd, then it might appear like the
1486 ;; article was sent in the future.
1489 " in the future"))))))
1491 (error "Unknown conversion type: %s" type)))))
1493 (defun article-date-local (&optional highlight)
1494 "Convert the current article date to the local timezone."
1495 (interactive (list t))
1496 (article-date-ut 'local highlight))
1498 (defun article-date-original (&optional highlight)
1499 "Convert the current article date to what it was originally.
1500 This is only useful if you have used some other date conversion
1501 function and want to see what the date was before converting."
1502 (interactive (list t))
1503 (article-date-ut 'original highlight))
1505 (defun article-date-lapsed (&optional highlight)
1506 "Convert the current article date to time lapsed since it was sent."
1507 (interactive (list t))
1508 (article-date-ut 'lapsed highlight))
1510 (defun article-update-date-lapsed ()
1511 "Function to be run from a timer to update the lapsed time line."
1512 (let (deactivate-mark)
1517 (set-buffer (window-buffer w))
1518 (when (eq major-mode 'gnus-article-mode)
1519 (goto-char (point-min))
1520 (when (re-search-forward "^X-Sent:" nil t)
1521 (article-date-lapsed t)))))))))
1523 (defun gnus-start-date-timer (&optional n)
1524 "Start a timer to update the X-Sent header in the article buffers.
1525 The numerical prefix says how frequently (in seconds) the function
1530 (gnus-stop-date-timer)
1531 (setq article-lapsed-timer
1532 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1534 (defun gnus-stop-date-timer ()
1535 "Stop the X-Sent timer."
1537 (when article-lapsed-timer
1538 (nnheader-cancel-timer article-lapsed-timer)
1539 (setq article-lapsed-timer nil)))
1541 (defun article-date-user (&optional highlight)
1542 "Convert the current article date to the user-defined format.
1543 This format is defined by the `gnus-article-time-format' variable."
1544 (interactive (list t))
1545 (article-date-ut 'user highlight))
1547 (defun article-date-iso8601 (&optional highlight)
1548 "Convert the current article date to ISO8601."
1549 (interactive (list t))
1550 (article-date-ut 'iso8601 highlight))
1552 (defun article-show-all ()
1553 "Show all hidden text in the article buffer."
1556 (let ((buffer-read-only nil))
1557 (gnus-article-unhide-text (point-min) (point-max)))))
1559 (defun article-emphasize (&optional arg)
1560 "Emphasize text according to `gnus-emphasis-alist'."
1561 (interactive (gnus-article-hidden-arg))
1562 (unless (gnus-article-check-hidden-text 'emphasis arg)
1564 (let ((alist gnus-emphasis-alist)
1565 (buffer-read-only nil)
1566 (props (append '(article-type emphasis)
1567 gnus-hidden-properties))
1568 regexp elem beg invisible visible face)
1569 (goto-char (point-min))
1570 (search-forward "\n\n" nil t)
1572 (while (setq elem (pop alist))
1574 (setq regexp (car elem)
1575 invisible (nth 1 elem)
1576 visible (nth 2 elem)
1578 (while (re-search-forward regexp nil t)
1579 (when (and (match-beginning visible) (match-beginning invisible))
1580 (gnus-article-hide-text
1581 (match-beginning invisible) (match-end invisible) props)
1582 (gnus-article-unhide-text-type
1583 (match-beginning visible) (match-end visible) 'emphasis)
1584 (gnus-put-text-property-excluding-newlines
1585 (match-beginning visible) (match-end visible) 'face face)
1586 (goto-char (match-end invisible)))))))))
1588 (defvar gnus-summary-article-menu)
1589 (defvar gnus-summary-post-menu)
1591 ;;; Saving functions.
1593 (defun gnus-article-save (save-buffer file &optional num)
1594 "Save the currently selected article."
1595 (unless gnus-save-all-headers
1596 ;; Remove headers according to `gnus-saved-headers'.
1597 (let ((gnus-visible-headers
1598 (or gnus-saved-headers gnus-visible-headers))
1599 (gnus-article-buffer save-buffer))
1601 (set-buffer save-buffer)
1602 (article-hide-headers 1 t))))
1603 (save-window-excursion
1604 (if (not gnus-default-article-saver)
1605 (error "No default saver is defined")
1606 ;; !!! Magic! The saving functions all save
1607 ;; `gnus-save-article-buffer' (or so they think), but we
1608 ;; bind that variable to our save-buffer.
1609 (set-buffer gnus-article-buffer)
1610 (let* ((gnus-save-article-buffer save-buffer)
1613 ((not gnus-prompt-before-saving) 'default)
1614 ((eq gnus-prompt-before-saving 'always) nil)
1616 (gnus-number-of-articles-to-be-saved
1617 (when (eq gnus-prompt-before-saving t)
1619 (set-buffer gnus-article-current-summary)
1620 (funcall gnus-default-article-saver filename)))))
1622 (defun gnus-read-save-file-name (prompt &optional filename
1623 function group headers variable)
1625 (funcall function group headers (symbol-value variable)))
1630 ((eq filename 'default)
1636 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1639 (if (and gnus-number-of-articles-to-be-saved
1640 (> gnus-number-of-articles-to-be-saved 1))
1641 (format "these %d articles"
1642 gnus-number-of-articles-to-be-saved)
1645 ;; Let the split methods have their say.
1647 ;; No split name was found.
1650 (concat prompt " (default "
1651 (file-name-nondirectory default-name) ") ")
1652 (file-name-directory default-name)
1654 ;; A single group name is returned.
1655 ((stringp split-name)
1657 (funcall function split-name headers
1658 (symbol-value variable)))
1660 (concat prompt " (default "
1661 (file-name-nondirectory default-name) ") ")
1662 (file-name-directory default-name)
1664 ;; A single split name was found
1665 ((= 1 (length split-name))
1666 (let* ((name (expand-file-name
1667 (car split-name) gnus-article-save-directory))
1668 (dir (cond ((file-directory-p name)
1669 (file-name-as-directory name))
1670 ((file-exists-p name) name)
1671 (t gnus-article-save-directory))))
1673 (concat prompt " (default " name ") ")
1675 ;; A list of splits was found.
1677 (setq split-name (nreverse split-name))
1679 (let ((file-name-history
1680 (nconc split-name file-name-history)))
1684 (concat prompt " (`M-p' for defaults) ")
1685 gnus-article-save-directory
1687 gnus-article-save-directory)))
1688 (car (push result file-name-history)))))))
1689 ;; Create the directory.
1690 (gnus-make-directory (file-name-directory file))
1691 ;; If we have read a directory, we append the default file name.
1692 (when (file-directory-p file)
1693 (setq file (concat (file-name-as-directory file)
1694 (file-name-nondirectory default-name))))
1695 ;; Possibly translate some characters.
1696 (nnheader-translate-file-chars file)))))
1697 (gnus-make-directory (file-name-directory result))
1698 (set variable result)))
1700 (defun gnus-article-archive-name (group)
1701 "Return the first instance of an \"Archive-name\" in the current buffer."
1702 (let ((case-fold-search t))
1703 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1704 (nnheader-concat gnus-article-save-directory
1705 (match-string 1)))))
1707 (defun gnus-article-nndoc-name (group)
1708 "If GROUP is an nndoc group, return the name of the parent group."
1709 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1710 (gnus-group-get-parameter group 'save-article-group)))
1712 (defun gnus-summary-save-in-rmail (&optional filename)
1713 "Append this article to Rmail file.
1714 Optional argument FILENAME specifies file name.
1715 Directory to save to is default to `gnus-article-save-directory'."
1716 (setq filename (gnus-read-save-file-name
1717 "Save %s in rmail file:" filename
1718 gnus-rmail-save-name gnus-newsgroup-name
1719 gnus-current-headers 'gnus-newsgroup-last-rmail))
1720 (gnus-eval-in-buffer-window gnus-save-article-buffer
1724 (gnus-output-to-rmail filename))))
1727 (defun gnus-summary-save-in-mail (&optional filename)
1728 "Append this article to Unix mail file.
1729 Optional argument FILENAME specifies file name.
1730 Directory to save to is default to `gnus-article-save-directory'."
1731 (setq filename (gnus-read-save-file-name
1732 "Save %s in Unix mail file:" filename
1733 gnus-mail-save-name gnus-newsgroup-name
1734 gnus-current-headers 'gnus-newsgroup-last-mail))
1735 (gnus-eval-in-buffer-window gnus-save-article-buffer
1739 (if (and (file-readable-p filename)
1740 (mail-file-babyl-p filename))
1741 (rmail-output-to-rmail-file filename t)
1742 (gnus-output-to-mail filename)))))
1745 (defun gnus-summary-save-in-file (&optional filename overwrite)
1746 "Append this article to file.
1747 Optional argument FILENAME specifies file name.
1748 Directory to save to is default to `gnus-article-save-directory'."
1749 (setq filename (gnus-read-save-file-name
1750 "Save %s in file:" filename
1751 gnus-file-save-name gnus-newsgroup-name
1752 gnus-current-headers 'gnus-newsgroup-last-file))
1753 (gnus-eval-in-buffer-window gnus-save-article-buffer
1757 (when (and overwrite
1758 (file-exists-p filename))
1759 (delete-file filename))
1760 (gnus-output-to-file filename))))
1763 (defun gnus-summary-write-to-file (&optional filename)
1764 "Write this article to a file.
1765 Optional argument FILENAME specifies file name.
1766 The directory to save in defaults to `gnus-article-save-directory'."
1767 (gnus-summary-save-in-file nil t))
1769 (defun gnus-summary-save-body-in-file (&optional filename)
1770 "Append this article body to a file.
1771 Optional argument FILENAME specifies file name.
1772 The directory to save in defaults to `gnus-article-save-directory'."
1773 (setq filename (gnus-read-save-file-name
1774 "Save %s body in file:" filename
1775 gnus-file-save-name gnus-newsgroup-name
1776 gnus-current-headers 'gnus-newsgroup-last-file))
1777 (gnus-eval-in-buffer-window gnus-save-article-buffer
1781 (goto-char (point-min))
1782 (when (search-forward "\n\n" nil t)
1783 (narrow-to-region (point) (point-max)))
1784 (gnus-output-to-file filename))))
1787 (defun gnus-summary-save-in-pipe (&optional command)
1788 "Pipe this article to subprocess."
1790 (cond ((and (eq command 'default)
1791 gnus-last-shell-command)
1792 gnus-last-shell-command)
1796 "Shell command on %s: "
1797 (if (and gnus-number-of-articles-to-be-saved
1798 (> gnus-number-of-articles-to-be-saved 1))
1799 (format "these %d articles"
1800 gnus-number-of-articles-to-be-saved)
1802 gnus-last-shell-command))))
1803 (when (string-equal command "")
1804 (setq command gnus-last-shell-command))
1805 (gnus-eval-in-buffer-window gnus-article-buffer
1808 (shell-command-on-region (point-min) (point-max) command nil)))
1809 (setq gnus-last-shell-command command))
1811 ;;; Article file names when saving.
1813 (defun gnus-capitalize-newsgroup (newsgroup)
1814 "Capitalize NEWSGROUP name."
1815 (when (not (zerop (length newsgroup)))
1816 (concat (char-to-string (upcase (aref newsgroup 0)))
1817 (substring newsgroup 1))))
1819 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1820 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1821 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1822 Otherwise, it is like ~/News/news/group/num."
1825 (concat (if (gnus-use-long-file-name 'not-save)
1826 (gnus-capitalize-newsgroup newsgroup)
1827 (gnus-newsgroup-directory-form newsgroup))
1828 "/" (int-to-string (mail-header-number headers)))
1829 gnus-article-save-directory)))
1831 (string-equal (file-name-directory default)
1832 (file-name-directory last-file))
1833 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1835 (or last-file default))))
1837 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1838 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1839 If variable `gnus-use-long-file-name' is non-nil, it is
1840 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1843 (concat (if (gnus-use-long-file-name 'not-save)
1845 (gnus-newsgroup-directory-form newsgroup))
1846 "/" (int-to-string (mail-header-number headers)))
1847 gnus-article-save-directory)))
1849 (string-equal (file-name-directory default)
1850 (file-name-directory last-file))
1851 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1853 (or last-file default))))
1855 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1856 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1857 If variable `gnus-use-long-file-name' is non-nil, it is
1858 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1861 (if (gnus-use-long-file-name 'not-save)
1862 (gnus-capitalize-newsgroup newsgroup)
1863 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1864 gnus-article-save-directory)))
1866 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1867 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1868 If variable `gnus-use-long-file-name' is non-nil, it is
1869 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1872 (if (gnus-use-long-file-name 'not-save)
1874 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1875 gnus-article-save-directory)))
1882 (setq afunc (car func)
1885 gfunc (intern (format "gnus-%s" func))))
1887 (if (not (fboundp afunc))
1889 `(lambda (&optional interactive &rest args)
1890 ,(documentation afunc t)
1891 (interactive (list t))
1893 (set-buffer gnus-article-buffer)
1895 (call-interactively ',afunc)
1896 (apply ',afunc args))))))))
1897 '(article-hide-headers
1898 article-hide-boring-headers
1899 article-treat-overstrike
1900 (article-fill . gnus-article-word-wrap)
1902 article-display-x-face
1903 article-de-quoted-unreadable
1904 article-mime-decode-quoted-printable
1907 article-hide-signature
1908 article-remove-trailing-blank-lines
1909 article-strip-leading-blank-lines
1910 article-strip-multiple-blank-lines
1911 article-strip-leading-space
1912 article-strip-blank-lines
1913 article-strip-all-blank-lines
1915 article-date-iso8601
1916 article-date-original
1918 article-decode-mime-words
1919 article-decode-charset
1920 article-decode-encoded-words
1924 article-treat-dumbquotes
1925 (article-show-all . gnus-article-show-all-headers))))
1928 ;;; Gnus article mode
1931 (put 'gnus-article-mode 'mode-class 'special)
1933 (set-keymap-parent gnus-article-mode-map widget-keymap)
1935 (gnus-define-keys gnus-article-mode-map
1936 " " gnus-article-goto-next-page
1937 "\177" gnus-article-goto-prev-page
1938 [delete] gnus-article-goto-prev-page
1939 "\C-c^" gnus-article-refer-article
1940 "h" gnus-article-show-summary
1941 "s" gnus-article-show-summary
1942 "\C-c\C-m" gnus-article-mail
1943 "?" gnus-article-describe-briefly
1944 "e" gnus-article-edit
1945 "<" beginning-of-buffer
1947 "\C-c\C-i" gnus-info-find-node
1950 "\C-d" gnus-article-read-summary-keys
1951 "\M-*" gnus-article-read-summary-keys
1952 "\M-#" gnus-article-read-summary-keys
1953 "\M-^" gnus-article-read-summary-keys
1954 "\M-g" gnus-article-read-summary-keys)
1956 (substitute-key-definition
1957 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1959 (defun gnus-article-make-menu-bar ()
1960 (gnus-turn-off-edit-menu 'article)
1961 (unless (boundp 'gnus-article-article-menu)
1963 gnus-article-article-menu gnus-article-mode-map ""
1965 ["Scroll forwards" gnus-article-goto-next-page t]
1966 ["Scroll backwards" gnus-article-goto-prev-page t]
1967 ["Show summary" gnus-article-show-summary t]
1968 ["Fetch Message-ID at point" gnus-article-refer-article t]
1969 ["Mail to address at point" gnus-article-mail t]
1970 ["Send a bug report" gnus-bug t]))
1973 gnus-article-treatment-menu gnus-article-mode-map ""
1975 ["Hide headers" gnus-article-hide-headers t]
1976 ["Hide signature" gnus-article-hide-signature t]
1977 ["Hide citation" gnus-article-hide-citation t]
1978 ["Treat overstrike" gnus-article-treat-overstrike t]
1979 ["Remove carriage return" gnus-article-remove-cr t]
1980 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1982 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1984 (when (boundp 'gnus-summary-post-menu)
1985 (define-key gnus-article-mode-map [menu-bar post]
1986 (cons "Post" gnus-summary-post-menu)))
1988 (gnus-run-hooks 'gnus-article-menu-hook)))
1990 (defun gnus-article-mode ()
1991 "Major mode for displaying an article.
1993 All normal editing commands are switched off.
1995 The following commands are available in addition to all summary mode
1997 \\<gnus-article-mode-map>
1998 \\[gnus-article-next-page]\t Scroll the article one page forwards
1999 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2000 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2001 \\[gnus-article-show-summary]\t Display the summary buffer
2002 \\[gnus-article-mail]\t Send a reply to the address near point
2003 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2004 \\[gnus-info-find-node]\t Go to the Gnus info node"
2006 (when (gnus-visual-p 'article-menu 'menu)
2007 (gnus-article-make-menu-bar))
2008 (gnus-simplify-mode-line)
2009 (setq mode-name "Article")
2010 (setq major-mode 'gnus-article-mode)
2011 (make-local-variable 'minor-mode-alist)
2012 (use-local-map gnus-article-mode-map)
2013 (gnus-update-format-specifications nil 'article-mode)
2014 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2015 (make-local-variable 'gnus-page-broken)
2016 (make-local-variable 'gnus-button-marker-list)
2017 (make-local-variable 'gnus-article-current-summary)
2018 (make-local-variable 'gnus-article-mime-handles)
2019 (make-local-variable 'gnus-article-decoded-p)
2020 (make-local-variable 'gnus-article-mime-handle-alist)
2021 (gnus-set-default-directory)
2022 (buffer-disable-undo)
2023 (setq buffer-read-only t)
2024 (set-syntax-table gnus-article-mode-syntax-table)
2025 (mm-enable-multibyte)
2026 (gnus-run-hooks 'gnus-article-mode-hook))
2028 (defun gnus-article-setup-buffer ()
2029 "Initialize the article buffer."
2030 (let* ((name (if gnus-single-article-buffer "*Article*"
2031 (concat "*Article " gnus-newsgroup-name "*")))
2033 (progn (string-match "\\*Article" name)
2034 (concat " *Original Article"
2035 (substring name (match-end 0))))))
2036 (setq gnus-article-buffer name)
2037 (setq gnus-original-article-buffer original)
2038 (setq gnus-article-mime-handle-alist nil)
2039 ;; This might be a variable local to the summary buffer.
2040 (unless gnus-single-article-buffer
2042 (set-buffer gnus-summary-buffer)
2043 (setq gnus-article-buffer name)
2044 (setq gnus-original-article-buffer original)
2045 (gnus-set-global-variables)))
2046 ;; Init original article buffer.
2048 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2049 (mm-enable-multibyte)
2050 (setq major-mode 'gnus-original-article-mode)
2051 (make-local-variable 'gnus-original-article))
2052 (if (get-buffer name)
2055 (buffer-disable-undo)
2056 (setq buffer-read-only t)
2057 (unless (eq major-mode 'gnus-article-mode)
2058 (gnus-article-mode))
2061 (set-buffer (gnus-get-buffer-create name))
2063 (make-local-variable 'gnus-summary-buffer)
2064 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2065 (current-buffer)))))
2067 ;; Set article window start at LINE, where LINE is the number of lines
2068 ;; from the head of the article.
2069 (defun gnus-article-set-window-start (&optional line)
2071 (get-buffer-window gnus-article-buffer t)
2073 (set-buffer gnus-article-buffer)
2074 (goto-char (point-min))
2077 (gnus-message 6 "Moved to bookmark")
2078 (search-forward "\n\n" nil t)
2082 (defun gnus-article-prepare (article &optional all-headers header)
2083 "Prepare ARTICLE in article mode buffer.
2084 ARTICLE should either be an article number or a Message-ID.
2085 If ARTICLE is an id, HEADER should be the article headers.
2086 If ALL-HEADERS is non-nil, no headers are hidden."
2088 ;; Make sure we start in a summary buffer.
2089 (unless (eq major-mode 'gnus-summary-mode)
2090 (set-buffer gnus-summary-buffer))
2091 (setq gnus-summary-buffer (current-buffer))
2092 (let* ((gnus-article (if header (mail-header-number header) article))
2093 (summary-buffer (current-buffer))
2094 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2095 (group gnus-newsgroup-name)
2098 (gnus-article-setup-buffer)
2099 (set-buffer gnus-article-buffer)
2100 ;; Deactivate active regions.
2101 (when (and (boundp 'transient-mark-mode)
2102 transient-mark-mode)
2103 (setq mark-active nil))
2104 (if (not (setq result (let ((buffer-read-only nil))
2105 (gnus-request-article-this-buffer
2107 ;; There is no such article.
2109 (when (and (numberp article)
2110 (not (memq article gnus-newsgroup-sparse)))
2111 (setq gnus-article-current
2112 (cons gnus-newsgroup-name article))
2113 (set-buffer gnus-summary-buffer)
2114 (setq gnus-current-article article)
2115 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2117 (gnus-summary-set-agent-mark article)
2118 (message "Message marked for downloading"))
2119 (gnus-summary-mark-article article gnus-canceled-mark)
2120 (unless (memq article gnus-newsgroup-sparse)
2122 "No such article (may have expired or been canceled)")))))
2123 (if (or (eq result 'pseudo)
2124 (eq result 'nneething))
2127 (set-buffer summary-buffer)
2128 (push article gnus-newsgroup-history)
2129 (setq gnus-last-article gnus-current-article
2130 gnus-current-article 0
2131 gnus-current-headers nil
2132 gnus-article-current nil)
2133 (if (eq result 'nneething)
2134 (gnus-configure-windows 'summary)
2135 (gnus-configure-windows 'article))
2136 (gnus-set-global-variables))
2137 (gnus-set-mode-line 'article))
2138 ;; The result from the `request' was an actual article -
2139 ;; or at least some text that is now displayed in the
2141 (when (and (numberp article)
2142 (not (eq article gnus-current-article)))
2143 ;; Seems like a new article has been selected.
2144 ;; `gnus-current-article' must be an article number.
2146 (set-buffer summary-buffer)
2147 (push article gnus-newsgroup-history)
2148 (setq gnus-last-article gnus-current-article
2149 gnus-current-article article
2150 gnus-current-headers
2151 (gnus-summary-article-header gnus-current-article)
2152 gnus-article-current
2153 (cons gnus-newsgroup-name gnus-current-article))
2154 (unless (vectorp gnus-current-headers)
2155 (setq gnus-current-headers nil))
2156 (gnus-summary-goto-subject gnus-current-article)
2157 (when (gnus-summary-show-thread)
2158 ;; If the summary buffer really was folded, the
2159 ;; previous goto may not actually have gone to
2160 ;; the right article, but the thread root instead.
2162 (gnus-summary-goto-subject gnus-current-article))
2163 (gnus-run-hooks 'gnus-mark-article-hook)
2164 (gnus-set-mode-line 'summary)
2165 (when (gnus-visual-p 'article-highlight 'highlight)
2166 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2167 ;; Set the global newsgroup variables here.
2168 ;; Suggested by Jim Sisolak
2169 ;; <sisolak@trans4.neep.wisc.edu>.
2170 (gnus-set-global-variables)
2171 (setq gnus-have-all-headers
2172 (or all-headers gnus-show-all-headers))))
2173 (when (or (numberp article)
2175 (gnus-article-prepare-display)
2177 (goto-char (point-min))
2178 (setq gnus-page-broken
2179 (when gnus-break-pages
2180 (gnus-narrow-to-page)
2182 (gnus-set-mode-line 'article)
2183 (gnus-configure-windows 'article)
2184 (goto-char (point-min))
2185 (search-forward "\n\n" nil t)
2186 (set-window-point (get-buffer-window (current-buffer)) (point))
2189 (defun gnus-article-prepare-display ()
2190 "Make the current buffer look like a nice article."
2191 ;; Hooks for getting information from the article.
2192 ;; This hook must be called before being narrowed.
2193 (let ((gnus-article-buffer (current-buffer))
2195 (unless (eq major-mode 'gnus-article-mode)
2196 (gnus-article-mode))
2197 (setq buffer-read-only nil)
2198 (gnus-run-hooks 'gnus-tmp-internal-hook)
2199 (gnus-run-hooks 'gnus-article-prepare-hook)
2200 (when gnus-display-mime-function
2201 (let ((url-standalone-mode (not gnus-plugged)))
2202 (funcall gnus-display-mime-function)))
2203 ;; Perform the article display hooks.
2204 (gnus-run-hooks 'gnus-article-display-hook)))
2207 ;;; Gnus MIME viewing functions
2210 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2211 "The following specs can be used:
2213 %n The `name' parameter
2214 %d The description, if any
2215 %l The length of the encoded part
2216 %p The part identifier
2217 %e Dots if the part isn't displayed")
2219 (defvar gnus-mime-button-line-format-alist
2220 '((?t gnus-tmp-type ?s)
2221 (?n gnus-tmp-name ?s)
2222 (?d gnus-tmp-description ?s)
2224 (?l gnus-tmp-length ?d)
2225 (?e gnus-tmp-dots ?s)))
2227 (defvar gnus-mime-button-commands
2228 '((gnus-article-press-button "\r" "Toggle Display")
2229 ;(gnus-mime-view-part "\M-\r" "View Interactively...")
2230 (gnus-mime-view-part "v" "View Interactively...")
2231 (gnus-mime-save-part "o" "Save...")
2232 (gnus-mime-copy-part "c" "View In Buffer")
2233 (gnus-mime-inline-part "i" "View Inline")
2234 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2236 (defvar gnus-mime-button-map nil)
2237 (unless gnus-mime-button-map
2238 (setq gnus-mime-button-map (make-sparse-keymap))
2239 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2240 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2241 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2243 (define-key gnus-mime-button-map (cadr c) (car c)))
2244 gnus-mime-button-commands))
2246 (defun gnus-mime-button-menu (event)
2247 "Construct a context-sensitive menu of MIME commands."
2249 (let ((response (x-popup-menu
2251 ("" ,@(mapcar (lambda (c)
2252 (cons (caddr c) (car c)))
2253 gnus-mime-button-commands)))))
2254 (pos (event-start event)))
2256 (set-buffer (window-buffer (posn-window pos)))
2257 (goto-char (posn-point pos))
2258 (funcall response))))
2260 (defun gnus-mime-view-all-parts ()
2261 "View all the MIME parts."
2263 (let ((handles gnus-article-mime-handles))
2265 (mm-display-part (pop handles)))))
2267 (defun gnus-mime-save-part ()
2268 "Save the MIME part under point."
2270 (let ((data (get-text-property (point) 'gnus-data)))
2271 (mm-save-part data)))
2273 (defun gnus-mime-pipe-part ()
2274 "Pipe the MIME part under point to a process."
2276 (let ((data (get-text-property (point) 'gnus-data)))
2277 (mm-pipe-part data)))
2279 (defun gnus-mime-view-part ()
2280 "Interactively choose a view method for the MIME part under point."
2282 (let ((data (get-text-property (point) 'gnus-data))
2283 (url-standalone-mode (not gnus-plugged)))
2284 (mm-interactively-view-part data)))
2286 (defun gnus-mime-copy-part ()
2287 "Put the the MIME part under point into a new buffer."
2289 (let* ((handle (get-text-property (point) 'gnus-data))
2290 (contents (mm-get-part handle))
2291 (buffer (generate-new-buffer
2292 (file-name-nondirectory
2294 (mail-content-type-get (mm-handle-type handle) 'name)
2295 (mail-content-type-get (mm-handle-type handle)
2298 (switch-to-buffer buffer)
2301 (goto-char (point-min))))
2303 (defun gnus-mime-inline-part ()
2304 "Insert the MIME part under point into the current buffer."
2306 (let* ((data (get-text-property (point) 'gnus-data))
2307 (contents (mm-get-part data))
2308 (url-standalone-mode (not gnus-plugged))
2311 (if (mm-handle-undisplayer data)
2312 (mm-remove-part data)
2314 (mm-insert-inline data contents)
2317 (defun gnus-article-view-part (n)
2318 "View MIME part N, which is the numerical prefix."
2320 (save-current-buffer
2321 (set-buffer gnus-article-buffer)
2322 (when (> n (length gnus-article-mime-handle-alist))
2323 (error "No such part"))
2324 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2325 (when (gnus-article-goto-part n)
2326 (if (equal (car handle) "multipart/alternative")
2327 (gnus-article-press-button)
2328 (when (eq (gnus-mm-display-part handle) 'internal)
2329 (gnus-set-window-start)))))))
2331 (defun gnus-mm-display-part (handle)
2332 "Display HANDLE and fix MIME button."
2333 (let ((id (get-text-property (point) 'gnus-part))
2336 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2337 (gnus-insert-mime-button
2338 handle id (list (not (mm-handle-displayed-p handle))))
2340 (let ((window (selected-window)))
2343 (let ((win (get-buffer-window (current-buffer) t)))
2345 (select-window win))
2348 (mm-display-part handle))
2349 (select-window window))))
2350 (goto-char point))))
2352 (defun gnus-article-goto-part (n)
2353 "Go to MIME part N."
2354 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2356 (goto-char point))))
2358 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2359 (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2360 (gnus-tmp-type (car (mm-handle-type handle)))
2361 (gnus-tmp-description (mm-handle-description handle))
2363 (if (if displayed (car displayed)
2364 (mm-handle-displayed-p handle))
2366 (gnus-tmp-length (save-excursion
2367 (set-buffer (mm-handle-buffer handle))
2372 (concat " (" gnus-tmp-name ")")
2374 (setq gnus-tmp-description
2375 (if gnus-tmp-description
2376 (concat " (" gnus-tmp-description ")")
2382 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2383 `(local-map ,gnus-mime-button-map
2384 keymap ,gnus-mime-button-map
2385 gnus-callback gnus-mm-display-part
2386 gnus-part ,gnus-tmp-id
2387 article-type annotation
2390 (widget-convert-button 'link b e :action 'gnus-widget-press-button
2391 :button-keymap gnus-mime-button-map)))
2393 (defun gnus-widget-press-button (elems el)
2394 (goto-char (widget-get elems :from))
2395 (let ((url-standalone-mode (not gnus-plugged)))
2396 (gnus-article-press-button)))
2398 (defun gnus-display-mime (&optional ihandles)
2399 "Insert MIME buttons in the buffer."
2400 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2401 handle name type b e display)
2403 ;; Top-level call; we clean up.
2404 (mm-destroy-parts gnus-article-mime-handles)
2405 (setq gnus-article-mime-handles handles
2406 gnus-article-mime-handle-alist nil)
2407 ;; We allow users to glean info from the handles.
2408 (when gnus-article-mime-part-function
2409 (gnus-mime-part-function handles)))
2411 (or (not (stringp (car handles)))
2414 ;; Clean up for mime parts.
2415 (goto-char (point-min))
2416 (search-forward "\n\n" nil t)
2417 (delete-region (point) (point-max)))
2418 (if (stringp (car handles))
2419 (if (equal (car handles) "multipart/alternative")
2420 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2421 (push (cons id handles) gnus-article-mime-handle-alist)
2422 (gnus-mime-display-alternative (cdr handles) nil nil id))
2423 (gnus-mime-display-mixed (cdr handles)))
2424 (gnus-mime-display-single handles)))))
2426 (defun gnus-mime-part-function (handles)
2427 (if (stringp (car handles))
2428 (mapcar 'gnus-mime-part-function (cdr handles))
2429 (funcall gnus-article-mime-part-function handles)))
2431 (defun gnus-mime-display-mixed (handles)
2433 (while (setq handle (pop handles))
2434 (if (stringp (car handle))
2435 (if (equal (car handle) "multipart/alternative")
2436 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2437 (push (cons id handle) gnus-article-mime-handle-alist)
2438 (gnus-mime-display-alternative (cdr handle) nil nil id))
2439 (gnus-mime-display-mixed (cdr handle)))
2440 (gnus-mime-display-single handle)))))
2442 (defun gnus-mime-display-single (handle)
2443 (let ((type (car (mm-handle-type handle)))
2444 (ignored gnus-ignored-mime-types)
2449 (when (string-match (pop ignored) type)
2450 (throw 'ignored nil)))
2451 (if (and (mm-automatic-display-p type)
2452 (mm-inlinable-part-p type)
2453 (or (not (mm-handle-disposition handle))
2454 (equal (car (mm-handle-disposition handle))
2457 (when (equal (car (split-string type "/"))
2460 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2461 (push (cons id handle) gnus-article-mime-handle-alist)
2462 (gnus-insert-mime-button handle id (list (or display text))))
2467 (mm-display-part handle t)
2468 (goto-char (point-max)))
2472 (mm-insert-inline handle (mm-get-part handle))
2473 (goto-char (point-max))))))))
2475 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2476 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2479 handle buffer-read-only from props begend not-pref)
2483 (narrow-to-region (car ibegend) (cdr ibegend))
2484 (delete-region (point-min) (point-max))
2485 (mm-remove-parts handles))
2486 (setq begend (list (point-marker)))
2488 (unless (setq not-pref (cadr (member preferred ihandles)))
2489 (setq not-pref (car ihandles)))
2490 (gnus-add-text-properties
2493 (insert (format "%d. " id))
2497 (gnus-mime-display-alternative
2498 ',ihandles ',not-pref
2500 local-map ,gnus-mime-button-map
2501 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2502 face ,gnus-article-button-face
2503 keymap ,gnus-mime-button-map
2506 (widget-convert-button 'link from (point)
2507 :action 'gnus-widget-press-button
2508 :button-keymap gnus-widget-button-keymap)
2510 (while (setq handle (pop handles))
2511 (gnus-add-text-properties
2514 (insert (format "[%c] %-18s"
2515 (if (equal handle preferred) ?* ? )
2516 (if (stringp (car handle))
2518 (car (mm-handle-type handle)))))
2522 (gnus-mime-display-alternative
2525 local-map ,gnus-mime-button-map
2526 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2527 face ,gnus-article-button-face
2528 keymap ,gnus-mime-button-map
2531 (widget-convert-button 'link from (point)
2532 :action 'gnus-widget-press-button
2533 :button-keymap gnus-widget-button-keymap)
2537 (if (stringp (car preferred))
2538 (gnus-display-mime preferred)
2539 (mm-display-part preferred)
2540 (goto-char (point-max))
2541 (setcdr begend (point-marker)))))
2543 (goto-char point)))))
2545 (defun gnus-article-wash-status ()
2546 "Return a string which display status of article washing."
2548 (set-buffer gnus-article-buffer)
2549 (let ((cite (gnus-article-hidden-text-p 'cite))
2550 (headers (gnus-article-hidden-text-p 'headers))
2551 (boring (gnus-article-hidden-text-p 'boring-headers))
2552 (pgp (gnus-article-hidden-text-p 'pgp))
2553 (pem (gnus-article-hidden-text-p 'pem))
2554 (signature (gnus-article-hidden-text-p 'signature))
2555 (overstrike (gnus-article-hidden-text-p 'overstrike))
2556 (emphasis (gnus-article-hidden-text-p 'emphasis)))
2557 (format "%c%c%c%c%c%c"
2559 (if (or headers boring) ?h ? )
2560 (if (or pgp pem) ?p ? )
2561 (if signature ?s ? )
2562 (if overstrike ?o ? )
2563 (if emphasis ?e ? )))))
2565 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2567 (defun gnus-article-maybe-hide-headers ()
2568 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2569 Provided for backwards compatibility."
2570 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2572 (gnus-article-hide-headers)))
2576 (defun gnus-output-to-file (file-name)
2577 "Append the current article to a file named FILE-NAME."
2578 (let ((artbuf (current-buffer)))
2580 (insert-buffer-substring artbuf)
2581 ;; Append newline at end of the buffer as separator, and then
2583 (goto-char (point-max))
2585 (append-to-file (point-min) (point-max) file-name)
2588 (defun gnus-narrow-to-page (&optional arg)
2589 "Narrow the article buffer to a page.
2590 If given a numerical ARG, move forward ARG pages."
2592 (setq arg (if arg (prefix-numeric-value arg) 0))
2594 (set-buffer gnus-article-buffer)
2595 (goto-char (point-min))
2597 ;; Remove any old next/prev buttons.
2598 (when (gnus-visual-p 'page-marker)
2599 (let ((buffer-read-only nil))
2600 (gnus-remove-text-with-property 'gnus-prev)
2601 (gnus-remove-text-with-property 'gnus-next)))
2604 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2606 (re-search-forward page-delimiter nil 'move arg)))
2607 (goto-char (match-end 0)))
2610 (if (re-search-forward page-delimiter nil 'move)
2613 (when (and (gnus-visual-p 'page-marker)
2614 (not (= (point-min) 1)))
2616 (goto-char (point-min))
2617 (gnus-insert-prev-page-button)))
2618 (when (and (gnus-visual-p 'page-marker)
2619 (< (+ (point-max) 2) (buffer-size)))
2621 (goto-char (point-max))
2622 (gnus-insert-next-page-button)))))
2624 ;; Article mode commands
2626 (defun gnus-article-goto-next-page ()
2627 "Show the next page of the article."
2629 (when (gnus-article-next-page)
2630 (goto-char (point-min))
2631 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2633 (defun gnus-article-goto-prev-page ()
2634 "Show the next page of the article."
2636 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2637 (gnus-article-prev-page nil)))
2639 (defun gnus-article-next-page (&optional lines)
2640 "Show the next page of the current article.
2641 If end of article, return non-nil. Otherwise return nil.
2642 Argument LINES specifies lines to be scrolled up."
2644 (move-to-window-line -1)
2647 (and (pos-visible-in-window-p) ;Not continuation line.
2649 ;; Nothing in this page.
2650 (if (or (not gnus-page-broken)
2653 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2655 (gnus-narrow-to-page 1) ;Go to next page.
2657 ;; More in this page.
2658 (let ((scroll-in-place nil))
2662 ;; Long lines may cause an end-of-buffer error.
2663 (goto-char (point-max)))))
2664 (move-to-window-line 0)
2667 (defun gnus-article-prev-page (&optional lines)
2668 "Show previous page of current article.
2669 Argument LINES specifies lines to be scrolled down."
2671 (move-to-window-line 0)
2672 (if (and gnus-page-broken
2674 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2676 (gnus-narrow-to-page -1) ;Go to previous page.
2677 (goto-char (point-max))
2679 (let ((scroll-in-place nil))
2683 (beginning-of-buffer
2684 (goto-char (point-min))))
2685 (move-to-window-line 0)))))
2687 (defun gnus-article-refer-article ()
2688 "Read article specified by message-id around point."
2690 (let ((point (point)))
2691 (search-forward ">" nil t) ;Move point to end of "<....>".
2692 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2693 (let ((message-id (match-string 1)))
2695 (set-buffer gnus-summary-buffer)
2696 (gnus-summary-refer-article message-id))
2698 (error "No references around point"))))
2700 (defun gnus-article-show-summary ()
2701 "Reconfigure windows to show summary buffer."
2703 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2704 (error "There is no summary buffer for this article buffer")
2705 (gnus-article-set-globals)
2706 (gnus-configure-windows 'article)
2707 (gnus-summary-goto-subject gnus-current-article)
2708 (gnus-summary-position-point)))
2710 (defun gnus-article-describe-briefly ()
2711 "Describe article mode commands briefly."
2714 (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")))
2716 (defun gnus-article-summary-command ()
2717 "Execute the last keystroke in the summary buffer."
2719 (let ((obuf (current-buffer))
2720 (owin (current-window-configuration))
2722 (switch-to-buffer gnus-article-current-summary 'norecord)
2723 (setq func (lookup-key (current-local-map) (this-command-keys)))
2724 (call-interactively func)
2726 (set-window-configuration owin)
2727 (set-window-point (get-buffer-window (current-buffer)) (point))))
2729 (defun gnus-article-summary-command-nosave ()
2730 "Execute the last keystroke in the summary buffer."
2733 (pop-to-buffer gnus-article-current-summary 'norecord)
2734 (setq func (lookup-key (current-local-map) (this-command-keys)))
2735 (call-interactively func)))
2737 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2738 "Read a summary buffer key sequence and execute it from the article buffer."
2741 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2742 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2743 "=" "^" "\M-^" "|"))
2749 '("n" "Gn" "p" "Gp"))
2752 (set-buffer gnus-article-current-summary)
2753 (let (gnus-pick-mode)
2754 (push (or key last-command-event) unread-command-events)
2755 (setq keys (read-key-sequence nil))))
2758 (if (or (member keys nosaves)
2759 (member keys nosave-but-article)
2760 (member keys nosave-in-article))
2762 (save-window-excursion
2763 (pop-to-buffer gnus-article-current-summary 'norecord)
2764 ;; We disable the pick minor mode commands.
2765 (let (gnus-pick-mode)
2766 (setq func (lookup-key (current-local-map) keys))))
2769 (unless (member keys nosave-in-article)
2770 (set-buffer gnus-article-current-summary))
2771 (call-interactively func)
2772 (setq new-sum-point (point)))
2773 (when (member keys nosave-but-article)
2774 (pop-to-buffer gnus-article-buffer 'norecord)))
2775 ;; These commands should restore window configuration.
2776 (let ((obuf (current-buffer))
2777 (owin (current-window-configuration))
2779 (summary gnus-article-current-summary)
2780 func in-buffer selected)
2781 (if not-restore-window
2782 (pop-to-buffer summary 'norecord)
2783 (switch-to-buffer summary 'norecord))
2784 (setq in-buffer (current-buffer))
2785 ;; We disable the pick minor mode commands.
2786 (if (setq func (let (gnus-pick-mode)
2787 (lookup-key (current-local-map) keys)))
2789 (call-interactively func)
2790 (setq new-sum-point (point)))
2792 (when (eq in-buffer (current-buffer))
2793 (setq selected (gnus-summary-select-article))
2795 (unless not-restore-window
2796 (set-window-configuration owin))
2797 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2798 (set-window-point (get-buffer-window (current-buffer))
2800 (let ((win (get-buffer-window gnus-article-current-summary)))
2802 (set-window-point win new-sum-point))))))))
2804 (defun gnus-article-hide (&optional arg force)
2805 "Hide all the gruft in the current article.
2806 This means that PGP stuff, signatures, cited text and (some)
2807 headers will be hidden.
2808 If given a prefix, show the hidden text instead."
2809 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2810 (gnus-article-hide-headers arg)
2811 (gnus-article-hide-pgp arg)
2812 (gnus-article-hide-citation-maybe arg force)
2813 (gnus-article-hide-signature arg))
2815 (defun gnus-article-maybe-highlight ()
2816 "Do some article highlighting if article highlighting is requested."
2817 (when (gnus-visual-p 'article-highlight 'highlight)
2818 (gnus-article-highlight-some)))
2820 (defun gnus-check-group-server ()
2821 ;; Make sure the connection to the server is alive.
2822 (unless (gnus-server-opened
2823 (gnus-find-method-for-group gnus-newsgroup-name))
2824 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2825 (gnus-request-group gnus-newsgroup-name t)))
2827 (defun gnus-request-article-this-buffer (article group)
2828 "Get an article and insert it into this buffer."
2829 (let (do-update-line sparse-header)
2833 (gnus-kill-all-overlays)
2834 (setq group (or group gnus-newsgroup-name))
2836 ;; Using `gnus-request-article' directly will insert the article into
2837 ;; `nntp-server-buffer' - so we'll save some time by not having to
2838 ;; copy it from the server buffer into the article buffer.
2840 ;; We only request an article by message-id when we do not have the
2841 ;; headers for it, so we'll have to get those.
2842 (when (stringp article)
2843 (let ((gnus-override-method gnus-refer-article-method))
2844 (gnus-read-header article)))
2846 ;; If the article number is negative, that means that this article
2847 ;; doesn't belong in this newsgroup (possibly), so we find its
2848 ;; message-id and request it by id instead of number.
2849 (when (and (numberp article)
2851 (get-buffer gnus-summary-buffer)
2852 (gnus-buffer-exists-p gnus-summary-buffer))
2854 (set-buffer gnus-summary-buffer)
2855 (let ((header (gnus-summary-article-header article)))
2858 ((memq article gnus-newsgroup-sparse)
2859 ;; This is a sparse gap article.
2860 (setq do-update-line article)
2861 (setq article (mail-header-id header))
2862 (let ((gnus-override-method gnus-refer-article-method))
2863 (setq sparse-header (gnus-read-header article)))
2864 (setq gnus-newsgroup-sparse
2865 (delq article gnus-newsgroup-sparse)))
2867 ;; It's a real article.
2868 (setq article (mail-header-id header)))
2870 ;; It is an extracted pseudo-article.
2871 (setq article 'pseudo)
2872 (gnus-request-pseudo-article header))))
2874 (let ((method (gnus-find-method-for-group
2875 gnus-newsgroup-name)))
2876 (when (and (eq (car method) 'nneething)
2879 (file-name-as-directory
2880 (or (cadr (assq 'nneething-address method))
2882 (mail-header-subject header))))
2883 (when (file-directory-p dir)
2884 (setq article 'nneething)
2885 (gnus-group-enter-directory dir))))))))
2888 ;; Refuse to select canceled articles.
2889 ((and (numberp article)
2891 (get-buffer gnus-summary-buffer)
2892 (gnus-buffer-exists-p gnus-summary-buffer)
2893 (eq (cdr (save-excursion
2894 (set-buffer gnus-summary-buffer)
2895 (assq article gnus-newsgroup-reads)))
2896 gnus-canceled-mark))
2898 ;; We first check `gnus-original-article-buffer'.
2899 ((and (get-buffer gnus-original-article-buffer)
2902 (set-buffer gnus-original-article-buffer)
2903 (and (equal (car gnus-original-article) group)
2904 (eq (cdr gnus-original-article) article))))
2905 (insert-buffer-substring gnus-original-article-buffer)
2907 ;; Check the backlog.
2908 ((and gnus-keep-backlog
2909 (gnus-backlog-request-article group article (current-buffer)))
2911 ;; Check asynchronous pre-fetch.
2912 ((gnus-async-request-fetched-article group article (current-buffer))
2913 (gnus-async-prefetch-next group article gnus-summary-buffer)
2914 (when (and (numberp article) gnus-keep-backlog)
2915 (gnus-backlog-enter-article group article (current-buffer)))
2918 ((and gnus-use-cache
2920 (gnus-cache-request-article article group))
2922 ;; Get the article and put into the article buffer.
2923 ((or (stringp article) (numberp article))
2924 (let ((gnus-override-method
2925 (and (stringp article) gnus-refer-article-method))
2926 (buffer-read-only nil))
2928 (gnus-kill-all-overlays)
2929 (gnus-check-group-server)
2930 (when (gnus-request-article article group (current-buffer))
2931 (when (numberp article)
2932 (gnus-async-prefetch-next group article gnus-summary-buffer)
2933 (when gnus-keep-backlog
2934 (gnus-backlog-enter-article
2935 group article (current-buffer))))
2940 ;; Associate this article with the current summary buffer.
2941 (setq gnus-article-current-summary gnus-summary-buffer)
2943 ;; Take the article from the original article buffer
2944 ;; and place it in the buffer it's supposed to be in.
2945 (when (and (get-buffer gnus-article-buffer)
2946 (equal (buffer-name (current-buffer))
2947 (buffer-name (get-buffer gnus-article-buffer))))
2949 (if (get-buffer gnus-original-article-buffer)
2950 (set-buffer gnus-original-article-buffer)
2951 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2952 (buffer-disable-undo)
2953 (setq major-mode 'gnus-original-article-mode)
2954 (setq buffer-read-only t))
2955 (let (buffer-read-only)
2957 (insert-buffer-substring gnus-article-buffer))
2958 (setq gnus-original-article (cons group article)))
2961 (run-hooks 'gnus-article-decode-hook)
2962 ;; Mark article as decoded or not.
2963 (setq gnus-article-decoded-p gnus-article-decode-hook))
2965 ;; Update sparse articles.
2966 (when (and do-update-line
2967 (or (numberp article)
2969 (let ((buf (current-buffer)))
2970 (set-buffer gnus-summary-buffer)
2971 (gnus-summary-update-article do-update-line sparse-header)
2972 (gnus-summary-goto-subject do-update-line nil t)
2973 (set-window-point (get-buffer-window (current-buffer) t)
2975 (set-buffer buf))))))
2981 (defcustom gnus-article-edit-mode-hook nil
2982 "Hook run in article edit mode buffers."
2983 :group 'gnus-article-various
2986 (defvar gnus-article-edit-done-function nil)
2988 (defvar gnus-article-edit-mode-map nil)
2990 ;; Should we be using derived.el for this?
2991 (unless gnus-article-edit-mode-map
2992 (setq gnus-article-edit-mode-map (make-sparse-keymap))
2993 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
2995 (gnus-define-keys gnus-article-edit-mode-map
2996 "\C-c\C-c" gnus-article-edit-done
2997 "\C-c\C-k" gnus-article-edit-exit)
2999 (gnus-define-keys (gnus-article-edit-wash-map
3000 "\C-c\C-w" gnus-article-edit-mode-map)
3001 "f" gnus-article-edit-full-stops))
3003 (defun gnus-article-edit-mode ()
3004 "Major mode for editing articles.
3005 This is an extended text-mode.
3007 \\{gnus-article-edit-mode-map}"
3009 (setq major-mode 'gnus-article-edit-mode)
3010 (setq mode-name "Article Edit")
3011 (use-local-map gnus-article-edit-mode-map)
3012 (make-local-variable 'gnus-article-edit-done-function)
3013 (make-local-variable 'gnus-prev-winconf)
3014 (setq buffer-read-only nil)
3015 (buffer-enable-undo)
3017 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3019 (defun gnus-article-edit (&optional force)
3020 "Edit the current article.
3021 This will have permanent effect only in mail groups.
3022 If FORCE is non-nil, allow editing of articles even in read-only
3025 (when (and (not force)
3026 (gnus-group-read-only-p))
3027 (error "The current newsgroup does not support article editing"))
3028 (gnus-article-date-original)
3029 (gnus-article-edit-article
3030 `(lambda (no-highlight)
3031 (gnus-summary-edit-article-done
3032 ,(or (mail-header-references gnus-current-headers) "")
3033 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3035 (defun gnus-article-edit-article (exit-func)
3036 "Start editing the contents of the current article buffer."
3037 (let ((winconf (current-window-configuration)))
3038 (set-buffer gnus-article-buffer)
3039 (gnus-article-edit-mode)
3040 (gnus-article-delete-text-of-type 'annotation)
3041 (gnus-set-text-properties (point-min) (point-max) nil)
3042 (gnus-configure-windows 'edit-article)
3043 (setq gnus-article-edit-done-function exit-func)
3044 (setq gnus-prev-winconf winconf)
3045 (gnus-message 6 "C-c C-c to end edits")))
3047 (defun gnus-article-edit-done (&optional arg)
3048 "Update the article edits and exit."
3053 (goto-char (point-min))
3054 (when (search-forward "\n\n" nil 1)
3055 (let ((lines (count-lines (point) (point-max)))
3056 (length (- (point-max) (point)))
3057 (case-fold-search t)
3058 (body (copy-marker (point))))
3059 (goto-char (point-min))
3060 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3061 (delete-region (match-beginning 1) (match-end 1))
3062 (insert (number-to-string length)))
3063 (goto-char (point-min))
3064 (when (re-search-forward
3065 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3066 (delete-region (match-beginning 1) (match-end 1))
3067 (insert (number-to-string length)))
3068 (goto-char (point-min))
3069 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3070 (delete-region (match-beginning 1) (match-end 1))
3071 (insert (number-to-string lines)))))))
3072 (let ((func gnus-article-edit-done-function)
3073 (buf (current-buffer))
3074 (start (window-start)))
3075 (gnus-article-edit-exit)
3078 (let ((buffer-read-only nil))
3080 ;; The cache and backlog have to be flushed somewhat.
3081 (when gnus-keep-backlog
3082 (gnus-backlog-remove-article
3083 (car gnus-article-current) (cdr gnus-article-current)))
3084 ;; Flush original article as well.
3086 (when (get-buffer gnus-original-article-buffer)
3087 (set-buffer gnus-original-article-buffer)
3088 (setq gnus-original-article nil)))
3089 (when gnus-use-cache
3090 (gnus-cache-update-article
3091 (car gnus-article-current) (cdr gnus-article-current))))
3093 (set-window-start (get-buffer-window buf) start)
3094 (set-window-point (get-buffer-window buf) (point))))
3096 (defun gnus-article-edit-exit ()
3097 "Exit the article editing without updating."
3099 ;; We remove all text props from the article buffer.
3100 (let ((buf (format "%s" (buffer-string)))
3101 (curbuf (current-buffer))
3103 (window-start (window-start)))
3106 (let ((winconf gnus-prev-winconf))
3108 (set-window-configuration winconf)
3109 ;; Tippy-toe some to make sure that point remains where it was.
3110 (save-current-buffer
3112 (set-window-start (get-buffer-window (current-buffer)) window-start)
3115 (defun gnus-article-edit-full-stops ()
3116 "Interactively repair spacing at end of sentences."
3119 (goto-char (point-min))
3120 (search-forward-regexp "^$" nil t)
3121 (let ((case-fold-search nil))
3122 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3125 ;;; Article highlights
3128 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3130 ;;; Internal Variables:
3132 (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\\)"
3133 "Regular expression that matches URLs."
3134 :group 'gnus-article-buttons
3137 (defcustom gnus-button-alist
3138 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^)!;:,>\n\t ]*\\)>"
3139 0 t gnus-button-message-id 2)
3140 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3141 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3143 gnus-button-fetch-group 4)
3144 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3145 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3146 t gnus-button-message-id 3)
3147 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3148 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3149 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3150 ;; This is how URLs _should_ be embedded in text...
3151 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3153 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3154 "*Alist of regexps matching buttons in article bodies.
3156 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3157 REGEXP: is the string matching text around the button,
3158 BUTTON: is the number of the regexp grouping actually matching the button,
3159 FORM: is a lisp expression which must eval to true for the button to
3161 CALLBACK: is the function to call when the user push this button, and each
3162 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3164 CALLBACK can also be a variable, in that case the value of that
3165 variable it the real callback function."
3166 :group 'gnus-article-buttons
3167 :type '(repeat (list regexp
3168 (integer :tag "Button")
3170 (function :tag "Callback")
3173 (integer :tag "Regexp group")))))
3175 (defcustom gnus-header-button-alist
3176 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3177 0 t gnus-button-message-id 0)
3178 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3179 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3180 0 t gnus-button-mailto 0)
3181 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3182 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3183 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3184 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3185 gnus-button-message-id 3))
3186 "*Alist of headers and regexps to match buttons in article heads.
3188 This alist is very similar to `gnus-button-alist', except that each
3189 alist has an additional HEADER element first in each entry:
3191 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3193 HEADER is a regexp to match a header. For a fuller explanation, see
3194 `gnus-button-alist'."
3195 :group 'gnus-article-buttons
3196 :group 'gnus-article-headers
3197 :type '(repeat (list (regexp :tag "Header")
3199 (integer :tag "Button")
3201 (function :tag "Callback")
3204 (integer :tag "Regexp group")))))
3206 (defvar gnus-button-regexp nil)
3207 (defvar gnus-button-marker-list nil)
3208 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3210 (defvar gnus-button-last nil)
3211 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3215 (defun gnus-article-push-button (event)
3216 "Check text under the mouse pointer for a callback function.
3217 If the text under the mouse pointer has a `gnus-callback' property,
3218 call it with the value of the `gnus-data' text property."
3220 (set-buffer (window-buffer (posn-window (event-start event))))
3221 (let* ((pos (posn-point (event-start event)))
3222 (data (get-text-property pos 'gnus-data))
3223 (fun (get-text-property pos 'gnus-callback)))
3226 (funcall fun data))))
3228 (defun gnus-article-press-button ()
3229 "Check text at point for a callback function.
3230 If the text at point has a `gnus-callback' property,
3231 call it with the value of the `gnus-data' text property."
3233 (let* ((data (get-text-property (point) 'gnus-data))
3234 (fun (get-text-property (point) 'gnus-callback)))
3236 (funcall fun data))))
3238 (defun gnus-article-highlight (&optional force)
3239 "Highlight current article.
3240 This function calls `gnus-article-highlight-headers',
3241 `gnus-article-highlight-citation',
3242 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3243 do the highlighting. See the documentation for those functions."
3244 (interactive (list 'force))
3245 (gnus-article-highlight-headers)
3246 (gnus-article-highlight-citation force)
3247 (gnus-article-highlight-signature)
3248 (gnus-article-add-buttons force)
3249 (gnus-article-add-buttons-to-head))
3251 (defun gnus-article-highlight-some (&optional force)
3252 "Highlight current article.
3253 This function calls `gnus-article-highlight-headers',
3254 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3255 do the highlighting. See the documentation for those functions."
3256 (interactive (list 'force))
3257 (gnus-article-highlight-headers)
3258 (gnus-article-highlight-signature)
3259 (gnus-article-add-buttons))
3261 (defun gnus-article-highlight-headers ()
3262 "Highlight article headers as specified by `gnus-header-face-alist'."
3265 (set-buffer gnus-article-buffer)
3267 (let ((alist gnus-header-face-alist)
3268 (buffer-read-only nil)
3269 (case-fold-search t)
3270 (inhibit-point-motion-hooks t)
3271 entry regexp header-face field-face from hpoints fpoints)
3272 (message-narrow-to-head)
3273 (while (setq entry (pop alist))
3274 (goto-char (point-min))
3275 (setq regexp (concat "^\\("
3276 (if (string-equal "" (nth 0 entry))
3280 header-face (nth 1 entry)
3281 field-face (nth 2 entry))
3282 (while (and (re-search-forward regexp nil t)
3286 (unless (search-forward ":" nil t)
3288 (when (and header-face
3289 (not (memq (point) hpoints)))
3290 (push (point) hpoints)
3291 (gnus-put-text-property from (point) 'face header-face))
3292 (when (and field-face
3293 (not (memq (setq from (point)) fpoints)))
3295 (if (re-search-forward "^[^ \t]" nil t)
3297 (goto-char (point-max)))
3298 (gnus-put-text-property from (point) 'face field-face))))))))
3300 (defun gnus-article-highlight-signature ()
3301 "Highlight the signature in an article.
3302 It does this by highlighting everything after
3303 `gnus-signature-separator' using `gnus-signature-face'."
3306 (set-buffer gnus-article-buffer)
3307 (let ((buffer-read-only nil)
3308 (inhibit-point-motion-hooks t))
3310 (when (and gnus-signature-face
3311 (gnus-article-narrow-to-signature))
3312 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3313 'face gnus-signature-face)
3315 (gnus-article-search-signature)
3316 (let ((start (match-beginning 0))
3317 (end (set-marker (make-marker) (1+ (match-end 0)))))
3318 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3321 (defun gnus-button-in-region-p (b e prop)
3322 "Say whether PROP exists in the region."
3323 (text-property-not-all b e prop nil))
3325 (defun gnus-article-add-buttons (&optional force)
3326 "Find external references in the article and make buttons of them.
3327 \"External references\" are things like Message-IDs and URLs, as
3328 specified by `gnus-button-alist'."
3329 (interactive (list 'force))
3331 (set-buffer gnus-article-buffer)
3332 (let ((buffer-read-only nil)
3333 (inhibit-point-motion-hooks t)
3334 (case-fold-search t)
3335 (alist gnus-button-alist)
3337 ;; Remove all old markers.
3339 (while (setq marker (pop gnus-button-marker-list))
3341 (when (setq entry (gnus-button-entry))
3342 (put-text-property (match-beginning (nth 1 entry))
3343 (match-end (nth 1 entry))
3344 'gnus-callback nil))
3345 (set-marker marker nil)))
3346 ;; We skip the headers.
3347 (goto-char (point-min))
3348 (unless (search-forward "\n\n" nil t)
3349 (goto-char (point-max)))
3351 (while (setq entry (pop alist))
3352 (setq regexp (car entry))
3354 (while (re-search-forward regexp nil t)
3355 (let* ((start (and entry (match-beginning (nth 1 entry))))
3356 (end (and entry (match-end (nth 1 entry))))
3357 (from (match-beginning 0)))
3358 (when (and (or (eq t (nth 2 entry))
3359 (eval (nth 2 entry)))
3360 (not (gnus-button-in-region-p
3361 start end 'gnus-callback)))
3362 ;; That optional form returned non-nil, so we add the
3364 (gnus-article-add-button
3365 start end 'gnus-button-push
3366 (car (push (set-marker (make-marker) from)
3367 gnus-button-marker-list))))))))))
3369 ;; Add buttons to the head of an article.
3370 (defun gnus-article-add-buttons-to-head ()
3371 "Add buttons to the head of the article."
3374 (set-buffer gnus-article-buffer)
3375 (let ((buffer-read-only nil)
3376 (inhibit-point-motion-hooks t)
3377 (case-fold-search t)
3378 (alist gnus-header-button-alist)
3380 (nnheader-narrow-to-headers)
3382 ;; Each alist entry.
3383 (setq entry (car alist)
3385 (goto-char (point-min))
3386 (while (re-search-forward (car entry) nil t)
3387 ;; Each header matching the entry.
3388 (setq beg (match-beginning 0))
3389 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3390 (match-beginning 0))
3393 (while (re-search-forward (nth 1 entry) end t)
3394 ;; Each match within a header.
3395 (let* ((entry (cdr entry))
3396 (start (match-beginning (nth 1 entry)))
3397 (end (match-end (nth 1 entry)))
3398 (form (nth 2 entry)))
3399 (goto-char (match-end 0))
3401 (gnus-article-add-button
3402 start end (nth 3 entry)
3403 (buffer-substring (match-beginning (nth 4 entry))
3404 (match-end (nth 4 entry)))))))
3408 ;;; External functions:
3410 (defun gnus-article-add-button (from to fun &optional data)
3411 "Create a button between FROM and TO with callback FUN and data DATA."
3412 (when gnus-article-button-face
3413 (gnus-overlay-put (gnus-make-overlay from to)
3414 'face gnus-article-button-face))
3415 (gnus-add-text-properties
3417 (nconc (and gnus-article-mouse-face
3418 (list gnus-mouse-face-prop gnus-article-mouse-face))
3419 (list 'gnus-callback fun)
3420 (and data (list 'gnus-data data))))
3421 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3422 :button-keymap gnus-widget-button-keymap))
3424 ;;; Internal functions:
3426 (defun gnus-article-set-globals ()
3428 (set-buffer gnus-summary-buffer)
3429 (gnus-set-global-variables)))
3431 (defun gnus-signature-toggle (end)
3433 (set-buffer gnus-article-buffer)
3434 (let ((buffer-read-only nil)
3435 (inhibit-point-motion-hooks t))
3436 (if (get-text-property end 'invisible)
3437 (gnus-article-unhide-text end (point-max))
3438 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3440 (defun gnus-button-entry ()
3441 ;; Return the first entry in `gnus-button-alist' matching this place.
3442 (let ((alist gnus-button-alist)
3445 (setq entry (pop alist))
3446 (if (looking-at (car entry))
3451 (defun gnus-button-push (marker)
3452 ;; Push button starting at MARKER.
3455 (let* ((entry (gnus-button-entry))
3456 (inhibit-point-motion-hooks t)
3458 (args (mapcar (lambda (group)
3459 (let ((string (match-string group)))
3460 (gnus-set-text-properties
3461 0 (length string) nil string)
3468 (fboundp (symbol-value fun)))
3469 (apply (symbol-value fun) args))
3471 (gnus-message 1 "You must define `%S' to use this button"
3472 (cons fun args)))))))
3474 (defun gnus-button-message-id (message-id)
3477 (set-buffer gnus-summary-buffer)
3478 (gnus-summary-refer-article message-id)))
3480 (defun gnus-button-fetch-group (address)
3481 "Fetch GROUP specified by ADDRESS."
3482 (if (not (string-match "[:/]" address))
3483 ;; This is just a simple group url.
3484 (gnus-group-read-ephemeral-group address gnus-select-method)
3485 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3487 (error "Can't parse %s" address)
3488 (gnus-group-read-ephemeral-group
3489 (match-string 4 address)
3490 `(nntp ,(match-string 1 address)
3491 (nntp-address ,(match-string 1 address))
3492 (nntp-port-number ,(if (match-end 3)
3493 (match-string 3 address)
3496 (defun gnus-url-parse-query-string (query &optional downcase)
3497 (let (retval pairs cur key val)
3498 (setq pairs (split-string query "&"))
3500 (setq cur (car pairs)
3502 (if (not (string-match "=" cur))
3504 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3505 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3507 (setq key (downcase key)))
3508 (setq cur (assoc key retval))
3510 (setcdr cur (cons val (cdr cur)))
3511 (setq retval (cons (list key val) retval)))))
3514 (defun gnus-url-unhex (x)
3521 (defun gnus-url-unhex-string (str &optional allow-newlines)
3522 "Remove %XXX embedded spaces, etc in a url.
3523 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3524 decoding of carriage returns and line feeds in the string, which is normally
3525 forbidden in URL encoding."
3526 (setq str (or str ""))
3528 (case-fold-search t))
3529 (while (string-match "%[0-9a-f][0-9a-f]" str)
3530 (let* ((start (match-beginning 0))
3531 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3533 (gnus-url-unhex (elt str (+ start 2))))))
3535 tmp (substring str 0 start)
3538 (char-to-string code))
3539 ((or (= code ?\n) (= code ?\r))
3541 (t (char-to-string code))))
3542 str (substring str (match-end 0)))))
3543 (setq tmp (concat tmp str))
3546 (defun gnus-url-mailto (url)
3547 ;; Send mail to someone
3548 (when (string-match "mailto:/*\\(.*\\)" url)
3549 (setq url (substring url (match-beginning 1) nil)))
3550 (let (to args subject func)
3551 (if (string-match (regexp-quote "?") url)
3552 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3553 args (gnus-url-parse-query-string
3554 (substring url (match-end 0) nil) t))
3555 (setq to (gnus-url-unhex-string url)))
3556 (setq args (cons (list "to" to) args)
3557 subject (cdr-safe (assoc "subject" args)))
3560 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3563 (message-position-on-field (caar args)))
3564 (insert (mapconcat 'identity (cdar args) ", "))
3565 (setq args (cdr args)))
3568 (message-goto-subject))))
3570 (defun gnus-button-mailto (address)
3572 (set-buffer (gnus-copy-article-buffer))
3573 (message-reply address))
3575 (defun gnus-button-reply (address)
3576 ;; Reply to ADDRESS.
3577 (message-reply address))
3579 (defun gnus-button-url (address)
3581 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3582 (if (listp browse-url-browser-function)
3583 (browse-url address)
3584 (funcall browse-url-browser-function address)))
3586 (defun gnus-button-embedded-url (address)
3588 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3589 (if (listp browse-url-browser-function)
3590 (browse-url (gnus-strip-whitespace address))
3591 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3593 ;;; Next/prev buttons in the article buffer.
3595 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3596 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3598 (defvar gnus-prev-page-map nil)
3599 (unless gnus-prev-page-map
3600 (setq gnus-prev-page-map (make-sparse-keymap))
3601 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3602 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3604 (defun gnus-insert-prev-page-button ()
3605 (let ((buffer-read-only nil))
3607 gnus-prev-page-line-format nil
3608 `(gnus-prev t local-map ,gnus-prev-page-map
3609 gnus-callback gnus-article-button-prev-page
3610 article-type annotation))))
3612 (defvar gnus-next-page-map nil)
3613 (unless gnus-next-page-map
3614 (setq gnus-next-page-map (make-keymap))
3615 (suppress-keymap gnus-prev-page-map)
3616 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3617 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3619 (defun gnus-button-next-page ()
3620 "Go to the next page."
3622 (let ((win (selected-window)))
3623 (select-window (get-buffer-window gnus-article-buffer t))
3624 (gnus-article-next-page)
3625 (select-window win)))
3627 (defun gnus-button-prev-page ()
3628 "Go to the prev page."
3630 (let ((win (selected-window)))
3631 (select-window (get-buffer-window gnus-article-buffer t))
3632 (gnus-article-prev-page)
3633 (select-window win)))
3635 (defun gnus-insert-next-page-button ()
3636 (let ((buffer-read-only nil))
3637 (gnus-eval-format gnus-next-page-line-format nil
3639 t local-map ,gnus-next-page-map
3640 gnus-callback gnus-article-button-next-page
3641 article-type annotation))))
3643 (defun gnus-article-button-next-page (arg)
3644 "Go to the next page."
3646 (let ((win (selected-window)))
3647 (select-window (get-buffer-window gnus-article-buffer t))
3648 (gnus-article-next-page)
3649 (select-window win)))
3651 (defun gnus-article-button-prev-page (arg)
3652 "Go to the prev page."
3654 (let ((win (selected-window)))
3655 (select-window (get-buffer-window gnus-article-buffer t))
3656 (gnus-article-prev-page)
3657 (select-window win)))
3659 (defvar gnus-decode-header-methods
3660 '(mail-decode-encoded-word-region)
3661 "List of methods used to decode headers
3663 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
3664 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
3665 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
3666 whose names match REGEXP.
3669 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
3670 mail-decode-encoded-word-region
3671 (\"chinese\" . rfc1843-decode-region))
3674 (defvar gnus-decode-header-methods-cache nil)
3676 (defun gnus-multi-decode-header (start end)
3677 "Apply the functions from `gnus-encoded-word-methods' that match."
3678 (unless (and gnus-decode-header-methods-cache
3679 (eq gnus-newsgroup-name
3680 (car gnus-decode-header-methods-cache)))
3681 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
3684 (nconc gnus-decode-header-methods-cache (list x))
3685 (if (and gnus-newsgroup-name
3686 (string-match (car x) gnus-newsgroup-name))
3687 (nconc gnus-decode-header-methods-cache
3689 gnus-decode-header-methods))
3690 (let ((xlist gnus-decode-header-methods-cache))
3693 (narrow-to-region start end)
3695 (funcall (pop xlist) (point-min) (point-max))))))
3701 (run-hooks 'gnus-art-load-hook)
3703 ;;; gnus-art.el ends here