1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98,99 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:\\|^[BGF]?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%m"
390 "*The format specification for the article mode line.
391 See `gnus-summary-mode-line-format' for a closer description.
393 The following additional specs are available:
395 %w The article washing status.
396 %m The number of MIME parts in the article."
398 :group 'gnus-article-various)
400 (defcustom gnus-article-mode-hook nil
401 "*A hook for Gnus article mode."
403 :group 'gnus-article-various)
405 (defcustom gnus-article-menu-hook nil
406 "*Hook run after the creation of the article mode menu."
408 :group 'gnus-article-various)
410 (defcustom gnus-article-prepare-hook nil
411 "*A hook called after an article has been prepared in the article buffer.
412 If you want to run a special decoding program like nkf, use this hook."
414 :group 'gnus-article-various)
416 (defcustom gnus-article-hide-pgp-hook nil
417 "*A hook called after successfully hiding a PGP signature."
419 :group 'gnus-article-various)
421 (defcustom gnus-article-button-face 'bold
422 "Face used for highlighting buttons in the article buffer.
424 An article button is a piece of text that you can activate by pressing
425 `RET' or `mouse-2' above it."
427 :group 'gnus-article-buttons)
429 (defcustom gnus-article-mouse-face 'highlight
430 "Face used for mouse highlighting in the article buffer.
432 Article buttons will be displayed in this face when the cursor is
435 :group 'gnus-article-buttons)
437 (defcustom gnus-signature-face 'gnus-signature-face
438 "Face used for highlighting a signature in the article buffer.
439 Obsolete; use the face `gnus-signature-face' for customizations instead."
441 :group 'gnus-article-highlight
442 :group 'gnus-article-signature)
444 (defface gnus-signature-face
447 "Face used for highlighting a signature in the article buffer."
448 :group 'gnus-article-highlight
449 :group 'gnus-article-signature)
451 (defface gnus-header-from-face
454 (:foreground "spring green"))
457 (:foreground "red3"))
460 "Face used for displaying from headers."
461 :group 'gnus-article-headers
462 :group 'gnus-article-highlight)
464 (defface gnus-header-subject-face
467 (:foreground "SeaGreen3"))
470 (:foreground "red4"))
472 (:bold t :italic t)))
473 "Face used for displaying subject headers."
474 :group 'gnus-article-headers
475 :group 'gnus-article-highlight)
477 (defface gnus-header-newsgroups-face
480 (:foreground "yellow" :italic t))
483 (:foreground "MidnightBlue" :italic t))
486 "Face used for displaying newsgroups headers."
487 :group 'gnus-article-headers
488 :group 'gnus-article-highlight)
490 (defface gnus-header-name-face
493 (:foreground "SeaGreen"))
496 (:foreground "maroon"))
499 "Face used for displaying header names."
500 :group 'gnus-article-headers
501 :group 'gnus-article-highlight)
503 (defface gnus-header-content-face
506 (:foreground "forest green" :italic t))
509 (:foreground "indianred4" :italic t))
511 (:italic t))) "Face used for displaying header content."
512 :group 'gnus-article-headers
513 :group 'gnus-article-highlight)
515 (defcustom gnus-header-face-alist
516 '(("From" nil gnus-header-from-face)
517 ("Subject" nil gnus-header-subject-face)
518 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
519 ("" gnus-header-name-face gnus-header-content-face))
520 "*Controls highlighting of article header.
522 An alist of the form (HEADER NAME CONTENT).
524 HEADER is a regular expression which should match the name of an
525 header header and NAME and CONTENT are either face names or nil.
527 The name of each header field will be displayed using the face
528 specified by the first element in the list where HEADER match the
529 header name and NAME is non-nil. Similarly, the content will be
530 displayed by the first non-nil matching CONTENT face."
531 :group 'gnus-article-headers
532 :group 'gnus-article-highlight
533 :type '(repeat (list (regexp :tag "Header")
535 (item :tag "skip" nil)
536 (face :value default))
537 (choice :tag "Content"
538 (item :tag "skip" nil)
539 (face :value default)))))
541 (defcustom gnus-article-decode-hook
542 '(article-decode-charset article-decode-encoded-words)
543 "*Hook run to decode charsets in articles."
544 :group 'gnus-article-headers
547 (defcustom gnus-display-mime-function 'gnus-display-mime
548 "Function to display MIME articles."
549 :group 'gnus-article-mime
552 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
553 "Function used to decode headers.")
555 (defvar gnus-article-dumbquotes-map
573 "Table for MS-to-Latin1 translation.")
575 (defcustom gnus-ignored-mime-types nil
576 "List of MIME types that should be ignored by Gnus."
577 :group 'gnus-article-mime
578 :type '(repeat regexp))
580 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
581 "List of MIME types that should not be given buttons when rendered."
582 :group 'gnus-article-mime
583 :type '(repeat regexp))
585 (defcustom gnus-treat-body-highlight-signature t
586 "Highlight the signature."
588 :type '(choice (const :tag "Off" nil)
590 (const :tag "Last" last)
591 (integer :tag "Less")
592 (sexp :tag "Predicate")))
594 (defcustom gnus-article-mime-part-function nil
595 "Function called with a MIME handle as the argument."
596 :group 'gnus-article-mime
599 ;;; Internal variables
601 (defvar gnus-article-mime-handle-alist-1 nil)
602 (defvar gnus-treatment-function-alist
603 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
606 (defvar gnus-article-mime-handle-alist nil)
607 (defvar article-lapsed-timer nil)
608 (defvar gnus-article-current-summary nil)
610 (defvar gnus-article-mode-syntax-table
611 (let ((table (copy-syntax-table text-mode-syntax-table)))
612 (modify-syntax-entry ?- "w" table)
613 (modify-syntax-entry ?> ")" table)
614 (modify-syntax-entry ?< "(" table)
616 "Syntax table used in article mode buffers.
617 Initialized from `text-mode-syntax-table.")
619 (defvar gnus-save-article-buffer nil)
621 (defvar gnus-article-mode-line-format-alist
622 (nconc '((?w (gnus-article-wash-status) ?s)
623 (?m (gnus-article-mime-part-status) ?s))
624 gnus-summary-mode-line-format-alist))
626 (defvar gnus-number-of-articles-to-be-saved nil)
628 (defvar gnus-inhibit-hiding nil)
630 (defsubst gnus-article-hide-text (b e props)
631 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
632 (add-text-properties b e props)
633 (when (memq 'intangible props)
635 (max (1- b) (point-min))
636 b 'intangible (cddr (memq 'intangible props)))))
638 (defmacro gnus-with-article (article &rest forms)
639 "Select ARTICLE and perform FORMS in the original article buffer.
640 Then replace the article with the result."
642 ;; We don't want the article to be marked as read.
643 (let (gnus-mark-article-hook)
644 (gnus-summary-select-article t t nil ,article))
645 (set-buffer gnus-original-article-buffer)
647 (if (not (gnus-check-backend-function
648 'request-replace-article (car gnus-article-current)))
649 (gnus-message 5 "Read-only group; not replacing")
650 (unless (gnus-request-replace-article
651 ,article (car gnus-article-current)
653 (error "Couldn't replace article")))
654 ;; The cache and backlog have to be flushed somewhat.
655 (when gnus-keep-backlog
656 (gnus-backlog-remove-article
657 (car gnus-article-current) (cdr gnus-article-current)))
659 (gnus-cache-update-article
660 (car gnus-article-current) (cdr gnus-article-current)))))
662 (put 'gnus-with-article 'lisp-indent-function 1)
663 (put 'gnus-with-article 'edebug-form-spec '(form body))
665 (defsubst gnus-article-unhide-text (b e)
666 "Remove hidden text properties from region between B and E."
667 (remove-text-properties b e gnus-hidden-properties)
668 (when (memq 'intangible gnus-hidden-properties)
669 (put-text-property (max (1- b) (point-min))
672 (defun gnus-article-hide-text-type (b e type)
673 "Hide text of TYPE between B and E."
674 (gnus-article-hide-text
675 b e (cons 'article-type (cons type gnus-hidden-properties))))
677 (defun gnus-article-unhide-text-type (b e type)
678 "Unhide text of TYPE between B and E."
679 (remove-text-properties
680 b e (cons 'article-type (cons type gnus-hidden-properties)))
681 (when (memq 'intangible gnus-hidden-properties)
682 (put-text-property (max (1- b) (point-min))
685 (defun gnus-article-hide-text-of-type (type)
686 "Hide text of TYPE in the current buffer."
688 (let ((b (point-min))
690 (while (setq b (text-property-any b e 'article-type type))
691 (add-text-properties b (incf b) gnus-hidden-properties)))))
693 (defun gnus-article-delete-text-of-type (type)
694 "Delete text of TYPE in the current buffer."
696 (let ((b (point-min)))
697 (while (setq b (text-property-any b (point-max) 'article-type type))
699 b (or (text-property-not-all b (point-max) 'article-type type)
702 (defun gnus-article-delete-invisible-text ()
703 "Delete all invisible text in the current buffer."
705 (let ((b (point-min)))
706 (while (setq b (text-property-any b (point-max) 'invisible t))
708 b (or (text-property-not-all b (point-max) 'invisible t)
711 (defun gnus-article-text-type-exists-p (type)
712 "Say whether any text of type TYPE exists in the buffer."
713 (text-property-any (point-min) (point-max) 'article-type type))
715 (defsubst gnus-article-header-rank ()
716 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
717 (let ((list gnus-sorted-header-list)
720 (when (looking-at (car list))
722 (setq list (cdr list))
726 (defun article-hide-headers (&optional arg delete)
727 "Toggle whether to hide unwanted headers and possibly sort them as well.
728 If given a negative prefix, always show; if given a positive prefix,
730 (interactive (gnus-article-hidden-arg))
732 (if (gnus-article-check-hidden-text 'headers arg)
733 ;; Show boring headers as well.
734 (gnus-article-show-hidden-text 'boring-headers)
735 ;; This function might be inhibited.
736 (unless gnus-inhibit-hiding
739 (let ((buffer-read-only nil)
741 (props (nconc (list 'article-type 'headers)
742 gnus-hidden-properties))
743 (max (1+ (length gnus-sorted-header-list)))
744 (ignored (when (not gnus-visible-headers)
745 (cond ((stringp gnus-ignored-headers)
746 gnus-ignored-headers)
747 ((listp gnus-ignored-headers)
748 (mapconcat 'identity gnus-ignored-headers
751 (cond ((stringp gnus-visible-headers)
752 gnus-visible-headers)
753 ((and gnus-visible-headers
754 (listp gnus-visible-headers))
755 (mapconcat 'identity gnus-visible-headers "\\|"))))
756 (inhibit-point-motion-hooks t)
758 ;; First we narrow to just the headers.
760 (goto-char (point-min))
761 ;; Hide any "From " lines at the beginning of (mail) articles.
762 (while (looking-at "From ")
766 (delete-region (point-min) (point))
767 (gnus-article-hide-text (point-min) (point) props)))
768 ;; Then treat the rest of the header lines.
771 (if (search-forward "\n\n" nil t) ; if there's a body
772 (progn (forward-line -1) (point))
774 ;; Then we use the two regular expressions
775 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
776 ;; select which header lines is to remain visible in the
778 (goto-char (point-min))
779 (while (re-search-forward "^[^ \t]*:" nil t)
781 ;; Mark the rank of the header.
783 (point) (1+ (point)) 'message-rank
784 (if (or (and visible (looking-at visible))
786 (not (looking-at ignored))))
787 (gnus-article-header-rank)
790 (message-sort-headers-1)
791 (when (setq beg (text-property-any
792 (point-min) (point-max) 'message-rank (+ 2 max)))
793 ;; We make the unwanted headers invisible.
795 (delete-region beg (point-max))
796 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
797 (gnus-article-hide-text-type beg (point-max) 'headers))
798 ;; Work around XEmacs lossage.
799 (put-text-property (point-min) beg 'invisible nil))))))))
801 (defun article-hide-boring-headers (&optional arg)
802 "Toggle hiding of headers that aren't very interesting.
803 If given a negative prefix, always show; if given a positive prefix,
805 (interactive (gnus-article-hidden-arg))
806 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
807 (not gnus-show-all-headers))
810 (let ((buffer-read-only nil)
811 (list gnus-boring-article-headers)
812 (inhibit-point-motion-hooks t)
814 (nnheader-narrow-to-headers)
816 (setq elem (pop list))
817 (goto-char (point-min))
819 ;; Hide empty headers.
821 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
823 (gnus-article-hide-text-type
824 (progn (beginning-of-line) (point))
827 (if (re-search-forward "^[^ \t]" nil t)
831 ;; Hide boring Newsgroups header.
832 ((eq elem 'newsgroups)
833 (when (equal (gnus-fetch-field "newsgroups")
834 (gnus-group-real-name
835 (if (boundp 'gnus-newsgroup-name)
838 (gnus-article-hide-header "newsgroups")))
839 ((eq elem 'followup-to)
840 (when (equal (message-fetch-field "followup-to")
841 (message-fetch-field "newsgroups"))
842 (gnus-article-hide-header "followup-to")))
844 (let ((from (message-fetch-field "from"))
845 (reply-to (message-fetch-field "reply-to")))
850 (nth 1 (mail-extract-address-components from))
851 (nth 1 (mail-extract-address-components reply-to)))))
852 (gnus-article-hide-header "reply-to"))))
854 (let ((date (message-fetch-field "date")))
856 (< (days-between (current-time-string) date)
858 (gnus-article-hide-header "date"))))
860 (let ((to (message-fetch-field "to")))
861 (when (> (length to) 1024)
862 (gnus-article-hide-header "to"))))
865 (goto-char (point-min))
866 (while (re-search-forward "^to:" nil t)
867 (setq to-count (1+ to-count)))
869 (while (> to-count 0)
870 (goto-char (point-min))
872 (re-search-forward "^to:" nil nil to-count)
874 (narrow-to-region (point) (point-max))
875 (gnus-article-hide-header "to"))
876 (setq to-count (1- to-count)))))))))))))
878 (defun gnus-article-hide-header (header)
880 (goto-char (point-min))
881 (when (re-search-forward (concat "^" header ":") nil t)
882 (gnus-article-hide-text-type
883 (progn (beginning-of-line) (point))
886 (if (re-search-forward "^[^ \t]" nil t)
891 (defvar gnus-article-normalized-header-length 40
892 "Length of normalized headers.")
894 (defun article-normalize-headers ()
895 "Make all header lines 40 characters long."
897 (let ((buffer-read-only nil)
901 (message-narrow-to-head)
904 ((< (setq column (- (gnus-point-at-eol) (point)))
905 gnus-article-normalized-header-length)
908 (- gnus-article-normalized-header-length column)
910 ((> column gnus-article-normalized-header-length)
911 (gnus-put-text-property
913 (forward-char gnus-article-normalized-header-length)
920 (forward-line 1))))))
922 (defun article-treat-dumbquotes ()
923 "Translate M******** sm*rtq**t*s into proper text.
924 Note that this function guesses whether a character is a sm*rtq**t* or
925 not, so it should only be used interactively."
927 (article-translate-strings gnus-article-dumbquotes-map))
929 (defun article-translate-characters (from to)
930 "Translate all characters in the body of the article according to FROM and TO.
931 FROM is a string of characters to translate from; to is a string of
932 characters to translate to."
934 (when (article-goto-body)
935 (let ((buffer-read-only nil)
936 (x (make-string 225 ?x))
938 (while (< (incf i) (length x))
941 (while (< i (length from))
942 (aset x (aref from i) (aref to i))
944 (translate-region (point) (point-max) x)))))
946 (defun article-translate-strings (map)
947 "Translate all string in the body of the article according to MAP.
948 MAP is an alist where the elements are on the form (\"from\" \"to\")."
950 (when (article-goto-body)
951 (let ((buffer-read-only nil)
953 (while (setq elem (pop map))
955 (while (search-forward (car elem) nil t)
956 (replace-match (cadr elem)))))))))
958 (defun article-treat-overstrike ()
959 "Translate overstrikes into bold text."
962 (when (article-goto-body)
963 (let ((buffer-read-only nil))
964 (while (search-forward "\b" nil t)
965 (let ((next (char-after))
966 (previous (char-after (- (point) 2))))
967 ;; We do the boldification/underlining by hiding the
968 ;; overstrikes and putting the proper text property
972 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
973 (put-text-property (point) (1+ (point)) 'face 'bold))
975 (gnus-article-hide-text-type
976 (1- (point)) (1+ (point)) 'overstrike)
978 (- (point) 2) (1- (point)) 'face 'underline))
980 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
982 (point) (1+ (point)) 'face 'underline)))))))))
984 (defun article-fill ()
985 "Format too long lines."
988 (let ((buffer-read-only nil))
992 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
993 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
994 (adaptive-fill-mode t))
996 (and (>= (current-column) (min fill-column (window-width)))
997 (/= (preceding-char) ?:)
998 (fill-paragraph nil))
1001 (defun article-remove-cr ()
1002 "Translate CRLF pairs into LF, and then CR into LF.."
1005 (let ((buffer-read-only nil))
1006 (goto-char (point-min))
1007 (while (search-forward "\r$" nil t)
1008 (replace-match "" t t))
1009 (goto-char (point-min))
1010 (while (search-forward "\r" nil t)
1011 (replace-match "\n" t t)))))
1013 (defun article-remove-trailing-blank-lines ()
1014 "Remove all trailing blank lines from the article."
1017 (let ((buffer-read-only nil))
1018 (goto-char (point-max))
1022 (while (and (not (bobp))
1023 (looking-at "^[ \t]*$")
1024 (not (gnus-annotation-in-region-p
1025 (point) (gnus-point-at-eol))))
1030 (defun article-display-x-face (&optional force)
1031 "Look for an X-Face header and display it if present."
1032 (interactive (list 'force))
1034 ;; Delete the old process, if any.
1035 (when (process-status "article-x-face")
1036 (delete-process "article-x-face"))
1037 (let ((inhibit-point-motion-hooks t)
1038 (case-fold-search t)
1041 (nnheader-narrow-to-headers)
1042 (setq from (message-fetch-field "from"))
1043 (goto-char (point-min))
1044 (while (and gnus-article-x-face-command
1047 ;; Check whether this face is censored.
1048 (not gnus-article-x-face-too-ugly)
1049 (and gnus-article-x-face-too-ugly from
1050 (not (string-match gnus-article-x-face-too-ugly
1052 ;; Has to be present.
1053 (re-search-forward "^X-Face: " nil t))
1054 ;; This used to try to do multiple faces (`while' instead of
1055 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1056 ;; work (b) it can crash some versions of Emacs (c) are
1057 ;; multiple faces really something to encourage?
1058 (when (stringp gnus-article-x-face-command)
1060 ;; We now have the area of the buffer where the X-Face is stored.
1063 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1064 ;; We display the face.
1065 (if (symbolp gnus-article-x-face-command)
1066 ;; The command is a lisp function, so we call it.
1067 (if (gnus-functionp gnus-article-x-face-command)
1068 (funcall gnus-article-x-face-command beg end)
1069 (error "%s is not a function" gnus-article-x-face-command))
1070 ;; The command is a string, so we interpret the command
1071 ;; as a, well, command, and fork it off.
1072 (let ((process-connection-type nil))
1073 (process-kill-without-query
1075 "article-x-face" nil shell-file-name shell-command-switch
1076 gnus-article-x-face-command))
1077 (process-send-region "article-x-face" beg end)
1078 (process-send-eof "article-x-face"))))))))))
1080 (defun article-decode-mime-words ()
1081 "Decode all MIME-encoded words in the article."
1084 (set-buffer gnus-article-buffer)
1085 (let ((inhibit-point-motion-hooks t)
1087 (rfc2047-default-charset gnus-newsgroup-default-charset)
1088 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1089 (mail-decode-encoded-word-region (point-min) (point-max)))))
1091 (defun article-decode-charset (&optional prompt)
1092 "Decode charset-encoded text in the article.
1093 If PROMPT (the prefix), prompt for a coding system to use."
1097 (message-narrow-to-head)
1098 (let* ((inhibit-point-motion-hooks t)
1099 (case-fold-search t)
1100 (ct (message-fetch-field "Content-Type" t))
1101 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1102 (ctl (and ct (condition-case ()
1103 (mail-header-parse-content-type ct)
1107 (mm-read-coding-system "Charset to decode: "))
1109 (mail-content-type-get ctl 'charset))))
1110 (rfc2047-default-charset gnus-newsgroup-default-charset)
1111 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1113 (goto-char (point-max))
1116 (narrow-to-region (point) (point-max))
1117 (when (and (or (not ctl)
1118 (equal (car ctl) "text/plain"))
1121 charset (and cte (intern (downcase
1122 (gnus-strip-whitespace cte))))
1125 (defun article-decode-encoded-words ()
1126 "Remove encoded-word encoding from headers."
1127 (let ((inhibit-point-motion-hooks t)
1128 (rfc2047-default-charset gnus-newsgroup-default-charset)
1129 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1132 (message-narrow-to-head)
1133 (funcall gnus-decode-header-function (point-min) (point-max)))))
1135 (defun article-de-quoted-unreadable (&optional force)
1136 "Translate a quoted-printable-encoded article.
1137 If FORCE, decode the article whether it is marked as quoted-printable
1139 (interactive (list 'force))
1141 (let ((buffer-read-only nil)
1142 (type (gnus-fetch-field "content-transfer-encoding"))
1144 (or gnus-newsgroup-default-charset mm-default-coding-system))
1145 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1147 (and type (string-match "quoted-printable" (downcase type))))
1150 (narrow-to-region (point) (point-max))
1151 (quoted-printable-decode-region (point-min) (point-max))
1153 (mm-decode-body charset)))))))
1155 (defun article-hide-pgp (&optional arg)
1156 "Toggle hiding of any PGP headers and signatures in the current article.
1157 If given a negative prefix, always show; if given a positive prefix,
1159 (interactive (gnus-article-hidden-arg))
1160 (unless (gnus-article-check-hidden-text 'pgp arg)
1162 (let ((inhibit-point-motion-hooks t)
1163 buffer-read-only beg end)
1165 (goto-char (point-min))
1166 ;; Hide the "header".
1167 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1168 (delete-region (1+ (match-beginning 0)) (match-end 0))
1169 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1170 (when (looking-at "Hash:.*$")
1171 (delete-region (point) (1+ (gnus-point-at-eol))))
1173 ;; Hide the actual signature.
1174 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1175 (setq end (1+ (match-beginning 0)))
1178 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1180 ;; Perhaps we shouldn't hide to the end of the buffer
1181 ;; if there is no end to the signature?
1183 ;; Hide "- " PGP quotation markers.
1185 (narrow-to-region beg end)
1186 (goto-char (point-min))
1187 (while (re-search-forward "^- " nil t)
1189 (match-beginning 0) (match-end 0)))
1191 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1193 (defun article-hide-pem (&optional arg)
1194 "Toggle hiding of any PEM headers and signatures in the current article.
1195 If given a negative prefix, always show; if given a positive prefix,
1197 (interactive (gnus-article-hidden-arg))
1198 (unless (gnus-article-check-hidden-text 'pem arg)
1200 (let (buffer-read-only end)
1202 (goto-char (point-min))
1203 ;; hide the horrendously ugly "header".
1204 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1207 (setq end (1+ (match-beginning 0)))
1208 (gnus-article-hide-text-type
1210 (if (search-forward "\n\n" nil t)
1214 ;; hide the trailer as well
1215 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1218 (gnus-article-hide-text-type
1219 (match-beginning 0) (match-end 0) 'pem))))))
1221 (defun article-hide-signature (&optional arg)
1222 "Hide the signature in the current article.
1223 If given a negative prefix, always show; if given a positive prefix,
1225 (interactive (gnus-article-hidden-arg))
1226 (unless (gnus-article-check-hidden-text 'signature arg)
1229 (let ((buffer-read-only nil))
1230 (when (gnus-article-narrow-to-signature)
1231 (gnus-article-hide-text-type
1232 (point-min) (point-max) 'signature)))))))
1234 (defun article-strip-leading-blank-lines ()
1235 "Remove all blank lines from the beginning of the article."
1238 (let ((inhibit-point-motion-hooks t)
1240 (when (article-goto-body)
1241 (while (and (not (eobp))
1242 (looking-at "[ \t]*$"))
1243 (gnus-delete-line))))))
1245 (defun article-goto-body ()
1246 "Place point at the start of the body."
1247 (goto-char (point-min))
1248 (if (search-forward "\n\n" nil t)
1250 (goto-char (point-max))
1253 (defun article-strip-multiple-blank-lines ()
1254 "Replace consecutive blank lines with one empty line."
1257 (let ((inhibit-point-motion-hooks t)
1259 ;; First make all blank lines empty.
1261 (while (re-search-forward "^[ \t]+$" nil t)
1262 (unless (gnus-annotation-in-region-p
1263 (match-beginning 0) (match-end 0))
1264 (replace-match "" nil t)))
1265 ;; Then replace multiple empty lines with a single empty line.
1267 (while (re-search-forward "\n\n\n+" nil t)
1268 (unless (gnus-annotation-in-region-p
1269 (match-beginning 0) (match-end 0))
1270 (replace-match "\n\n" t t))))))
1272 (defun article-strip-leading-space ()
1273 "Remove all white space from the beginning of the lines in the article."
1276 (let ((inhibit-point-motion-hooks t)
1279 (while (re-search-forward "^[ \t]+" nil t)
1280 (replace-match "" t t)))))
1282 (defun article-strip-trailing-space ()
1283 "Remove all white space from the end of the lines in the article."
1286 (let ((inhibit-point-motion-hooks t)
1289 (while (re-search-forward "[ \t]+$" nil t)
1290 (replace-match "" t t)))))
1292 (defun article-strip-blank-lines ()
1293 "Strip leading, trailing and multiple blank lines."
1295 (article-strip-leading-blank-lines)
1296 (article-remove-trailing-blank-lines)
1297 (article-strip-multiple-blank-lines))
1299 (defun article-strip-all-blank-lines ()
1300 "Strip all blank lines."
1303 (let ((inhibit-point-motion-hooks t)
1306 (while (re-search-forward "^[ \t]*\n" nil t)
1307 (replace-match "" t t)))))
1309 (defun gnus-article-narrow-to-signature ()
1310 "Narrow to the signature; return t if a signature is found, else nil."
1312 (let ((inhibit-point-motion-hooks t))
1313 (when (gnus-article-search-signature)
1315 ;; Check whether we have some limits to what we consider
1316 ;; to be a signature.
1317 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1318 (list gnus-signature-limit)))
1320 (while (setq limit (pop limits))
1321 (if (or (and (integerp limit)
1322 (< (- (point-max) (point)) limit))
1324 (< (count-lines (point) (point-max)) limit))
1325 (and (gnus-functionp limit)
1327 (and (stringp limit)
1328 (not (re-search-forward limit nil t))))
1329 () ; This limit did not succeed.
1333 (narrow-to-region (point) (point-max))
1336 (defun gnus-article-search-signature ()
1337 "Search the current buffer for the signature separator.
1338 Put point at the beginning of the signature separator."
1339 (let ((cur (point)))
1340 (goto-char (point-max))
1341 (if (if (stringp gnus-signature-separator)
1342 (re-search-backward gnus-signature-separator nil t)
1343 (let ((seps gnus-signature-separator))
1345 (not (re-search-backward (car seps) nil t)))
1353 (autoload 'w3-display "w3-parse")
1354 (autoload 'w3-do-setup "w3" "" t)
1355 (autoload 'w3-region "w3-display" "" t))
1357 (defun gnus-article-treat-html ()
1360 (let ((cbuf (current-buffer)))
1361 (set-buffer gnus-article-buffer)
1362 (let (buf buffer-read-only b e)
1364 (goto-char (point-min))
1366 (if (search-forward "\n\n" nil t)
1369 (setq e (point-max)))
1371 (insert-buffer-substring gnus-article-buffer b e)
1373 (save-window-excursion
1374 (w3-region (point-min) (point-max))
1375 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1377 (delete-region (point-min) (point-max))
1380 (goto-char (point-min))
1381 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1382 (set-buffer cbuf))))
1384 (defun gnus-article-hidden-arg ()
1385 "Return the current prefix arg as a number, or 0 if no prefix."
1386 (list (if current-prefix-arg
1387 (prefix-numeric-value current-prefix-arg)
1390 (defun gnus-article-check-hidden-text (type arg)
1391 "Return nil if hiding is necessary.
1392 Arg can be nil or a number. Nil and positive means hide, negative
1393 means show, 0 means toggle."
1397 (let ((hide (gnus-article-hidden-text-p type)))
1403 (gnus-article-show-hidden-text type))
1405 (if (eq hide 'hidden)
1406 (gnus-article-show-hidden-text type)
1409 (defun gnus-article-hidden-text-p (type)
1410 "Say whether the current buffer contains hidden text of type TYPE."
1411 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1413 (not (get-text-property pos 'invisible)))
1415 (text-property-any (1+ pos) (point-max) 'article-type type)))
1420 (defun gnus-article-show-hidden-text (type &optional hide)
1421 "Show all hidden text of type TYPE.
1422 If HIDE, hide the text instead."
1424 (let ((buffer-read-only nil)
1425 (inhibit-point-motion-hooks t)
1428 (while (setq beg (text-property-any end (point-max) 'article-type type))
1431 (text-property-not-all beg (point-max) 'article-type type)
1434 (gnus-article-hide-text beg end gnus-hidden-properties)
1435 (gnus-article-unhide-text beg end))
1439 (defconst article-time-units
1440 `((year . ,(* 365.25 24 60 60))
1441 (week . ,(* 7 24 60 60))
1442 (day . ,(* 24 60 60))
1446 "Mapping from time units to seconds.")
1448 (defun article-date-ut (&optional type highlight header)
1449 "Convert DATE date to universal time in the current article.
1450 If TYPE is `local', convert to local time; if it is `lapsed', output
1451 how much time has lapsed since DATE."
1452 (interactive (list 'ut t))
1453 (let* ((header (or header
1454 (mail-header-date (save-excursion
1455 (set-buffer gnus-summary-buffer)
1456 gnus-current-headers))
1457 (message-fetch-field "date")
1459 (date (if (vectorp header) (mail-header-date header)
1461 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1462 (inhibit-point-motion-hooks t)
1463 bface eface newline)
1464 (when (and date (not (string= date "")))
1467 (nnheader-narrow-to-headers)
1468 (let ((buffer-read-only nil))
1469 ;; Delete any old Date headers.
1470 (if (re-search-forward date-regexp nil t)
1472 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1473 eface (get-text-property (1- (gnus-point-at-eol))
1475 (delete-region (progn (beginning-of-line) (point))
1476 (progn (end-of-line) (point)))
1477 (beginning-of-line))
1478 (goto-char (point-max))
1480 (insert (article-make-date-line date type))
1483 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1484 (put-text-property (match-beginning 1) (1+ (match-end 1))
1486 (put-text-property (match-beginning 2) (match-end 2)
1490 (insert "\n"))))))))
1492 (defun article-make-date-line (date type)
1493 "Return a DATE line of TYPE."
1494 (let ((time (condition-case ()
1498 ;; Convert to the local timezone. We have to slap a
1499 ;; `condition-case' round the calls to the timezone
1500 ;; functions since they aren't particularly resistant to
1503 (let ((tz (car (current-time-zone))))
1504 (format "Date: %s %s%04d" (current-time-string time)
1505 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1506 ;; Convert to Universal Time.
1509 (current-time-string
1510 (let* ((e (parse-time-string date))
1511 (tm (apply 'encode-time e))
1513 (ls (- (cadr tm) (car (current-time-zone)))))
1514 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1515 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1518 ;; Get the original date from the article.
1519 ((eq type 'original)
1520 (concat "Date: " (if (string-match "\n+$" date)
1521 (substring date 0 (match-beginning 0))
1523 ;; Let the user define the format.
1525 (if (gnus-functionp gnus-article-time-format)
1526 (funcall gnus-article-time-format time)
1529 (format-time-string gnus-article-time-format time))))
1534 (format-time-string "%Y%M%DT%h%m%s" time)))
1535 ;; Do an X-Sent lapsed format.
1537 ;; If the date is seriously mangled, the timezone functions are
1538 ;; liable to bug out, so we ignore all errors.
1539 (let* ((now (current-time))
1540 (real-time (subtract-time now time))
1541 (real-sec (and real-time
1542 (+ (* (float (car real-time)) 65536)
1544 (sec (and real-time (abs real-sec)))
1554 ;; This is a bit convoluted, but basically we go
1555 ;; through the time units for years, weeks, etc,
1556 ;; and divide things to see whether that results
1557 ;; in positive answers.
1560 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1561 ;; The (remaining) seconds are too few to
1562 ;; be divided into this time unit.
1564 ;; It's big enough, so we output it.
1565 (setq sec (- sec (* num (cdr unit))))
1567 (concat (if prev ", " "") (int-to-string
1569 " " (symbol-name (car unit))
1570 (if (> num 1) "s" ""))
1572 article-time-units "")
1573 ;; If dates are odd, then it might appear like the
1574 ;; article was sent in the future.
1577 " in the future"))))))
1579 (error "Unknown conversion type: %s" type)))))
1581 (defun article-date-local (&optional highlight)
1582 "Convert the current article date to the local timezone."
1583 (interactive (list t))
1584 (article-date-ut 'local highlight))
1586 (defun article-date-original (&optional highlight)
1587 "Convert the current article date to what it was originally.
1588 This is only useful if you have used some other date conversion
1589 function and want to see what the date was before converting."
1590 (interactive (list t))
1591 (article-date-ut 'original highlight))
1593 (defun article-date-lapsed (&optional highlight)
1594 "Convert the current article date to time lapsed since it was sent."
1595 (interactive (list t))
1596 (article-date-ut 'lapsed highlight))
1598 (defun article-update-date-lapsed ()
1599 "Function to be run from a timer to update the lapsed time line."
1600 (let (deactivate-mark)
1605 (set-buffer (window-buffer w))
1606 (when (eq major-mode 'gnus-article-mode)
1607 (goto-char (point-min))
1608 (when (re-search-forward "^X-Sent:" nil t)
1609 (article-date-lapsed t))))
1612 (defun gnus-start-date-timer (&optional n)
1613 "Start a timer to update the X-Sent header in the article buffers.
1614 The numerical prefix says how frequently (in seconds) the function
1619 (gnus-stop-date-timer)
1620 (setq article-lapsed-timer
1621 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1623 (defun gnus-stop-date-timer ()
1624 "Stop the X-Sent timer."
1626 (when article-lapsed-timer
1627 (nnheader-cancel-timer article-lapsed-timer)
1628 (setq article-lapsed-timer nil)))
1630 (defun article-date-user (&optional highlight)
1631 "Convert the current article date to the user-defined format.
1632 This format is defined by the `gnus-article-time-format' variable."
1633 (interactive (list t))
1634 (article-date-ut 'user highlight))
1636 (defun article-date-iso8601 (&optional highlight)
1637 "Convert the current article date to ISO8601."
1638 (interactive (list t))
1639 (article-date-ut 'iso8601 highlight))
1641 (defun article-show-all ()
1642 "Show all hidden text in the article buffer."
1645 (let ((buffer-read-only nil))
1646 (gnus-article-unhide-text (point-min) (point-max)))))
1648 (defun article-emphasize (&optional arg)
1649 "Emphasize text according to `gnus-emphasis-alist'."
1650 (interactive (gnus-article-hidden-arg))
1651 (unless (gnus-article-check-hidden-text 'emphasis arg)
1653 (let ((alist gnus-emphasis-alist)
1654 (buffer-read-only nil)
1655 (props (append '(article-type emphasis)
1656 gnus-hidden-properties))
1657 regexp elem beg invisible visible face)
1660 (while (setq elem (pop alist))
1662 (setq regexp (car elem)
1663 invisible (nth 1 elem)
1664 visible (nth 2 elem)
1666 (while (re-search-forward regexp nil t)
1667 (when (and (match-beginning visible) (match-beginning invisible))
1668 (gnus-article-hide-text
1669 (match-beginning invisible) (match-end invisible) props)
1670 (gnus-article-unhide-text-type
1671 (match-beginning visible) (match-end visible) 'emphasis)
1672 (gnus-put-text-property-excluding-newlines
1673 (match-beginning visible) (match-end visible) 'face face)
1674 (goto-char (match-end invisible)))))))))
1676 (defvar gnus-summary-article-menu)
1677 (defvar gnus-summary-post-menu)
1679 ;;; Saving functions.
1681 (defun gnus-article-save (save-buffer file &optional num)
1682 "Save the currently selected article."
1683 (unless gnus-save-all-headers
1684 ;; Remove headers according to `gnus-saved-headers'.
1685 (let ((gnus-visible-headers
1686 (or gnus-saved-headers gnus-visible-headers))
1687 (gnus-article-buffer save-buffer))
1689 (set-buffer save-buffer)
1690 (article-hide-headers 1 t))))
1691 (save-window-excursion
1692 (if (not gnus-default-article-saver)
1693 (error "No default saver is defined")
1694 ;; !!! Magic! The saving functions all save
1695 ;; `gnus-save-article-buffer' (or so they think), but we
1696 ;; bind that variable to our save-buffer.
1697 (set-buffer gnus-article-buffer)
1698 (let* ((gnus-save-article-buffer save-buffer)
1701 ((not gnus-prompt-before-saving) 'default)
1702 ((eq gnus-prompt-before-saving 'always) nil)
1704 (gnus-number-of-articles-to-be-saved
1705 (when (eq gnus-prompt-before-saving t)
1707 (set-buffer gnus-article-current-summary)
1708 (funcall gnus-default-article-saver filename)))))
1710 (defun gnus-read-save-file-name (prompt &optional filename
1711 function group headers variable)
1713 (funcall function group headers (symbol-value variable)))
1718 ((eq filename 'default)
1724 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1727 (if (and gnus-number-of-articles-to-be-saved
1728 (> gnus-number-of-articles-to-be-saved 1))
1729 (format "these %d articles"
1730 gnus-number-of-articles-to-be-saved)
1733 ;; Let the split methods have their say.
1735 ;; No split name was found.
1738 (concat prompt " (default "
1739 (file-name-nondirectory default-name) ") ")
1740 (file-name-directory default-name)
1742 ;; A single group name is returned.
1743 ((stringp split-name)
1745 (funcall function split-name headers
1746 (symbol-value variable)))
1748 (concat prompt " (default "
1749 (file-name-nondirectory default-name) ") ")
1750 (file-name-directory default-name)
1752 ;; A single split name was found
1753 ((= 1 (length split-name))
1754 (let* ((name (expand-file-name
1755 (car split-name) gnus-article-save-directory))
1756 (dir (cond ((file-directory-p name)
1757 (file-name-as-directory name))
1758 ((file-exists-p name) name)
1759 (t gnus-article-save-directory))))
1761 (concat prompt " (default " name ") ")
1763 ;; A list of splits was found.
1765 (setq split-name (nreverse split-name))
1767 (let ((file-name-history
1768 (nconc split-name file-name-history)))
1772 (concat prompt " (`M-p' for defaults) ")
1773 gnus-article-save-directory
1775 gnus-article-save-directory)))
1776 (car (push result file-name-history)))))))
1777 ;; Create the directory.
1778 (gnus-make-directory (file-name-directory file))
1779 ;; If we have read a directory, we append the default file name.
1780 (when (file-directory-p file)
1781 (setq file (concat (file-name-as-directory file)
1782 (file-name-nondirectory default-name))))
1783 ;; Possibly translate some characters.
1784 (nnheader-translate-file-chars file)))))
1785 (gnus-make-directory (file-name-directory result))
1786 (set variable result)))
1788 (defun gnus-article-archive-name (group)
1789 "Return the first instance of an \"Archive-name\" in the current buffer."
1790 (let ((case-fold-search t))
1791 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1792 (nnheader-concat gnus-article-save-directory
1793 (match-string 1)))))
1795 (defun gnus-article-nndoc-name (group)
1796 "If GROUP is an nndoc group, return the name of the parent group."
1797 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1798 (gnus-group-get-parameter group 'save-article-group)))
1800 (defun gnus-summary-save-in-rmail (&optional filename)
1801 "Append this article to Rmail file.
1802 Optional argument FILENAME specifies file name.
1803 Directory to save to is default to `gnus-article-save-directory'."
1804 (setq filename (gnus-read-save-file-name
1805 "Save %s in rmail file:" filename
1806 gnus-rmail-save-name gnus-newsgroup-name
1807 gnus-current-headers 'gnus-newsgroup-last-rmail))
1808 (gnus-eval-in-buffer-window gnus-save-article-buffer
1812 (gnus-output-to-rmail filename))))
1815 (defun gnus-summary-save-in-mail (&optional filename)
1816 "Append this article to Unix mail file.
1817 Optional argument FILENAME specifies file name.
1818 Directory to save to is default to `gnus-article-save-directory'."
1819 (setq filename (gnus-read-save-file-name
1820 "Save %s in Unix mail file:" filename
1821 gnus-mail-save-name gnus-newsgroup-name
1822 gnus-current-headers 'gnus-newsgroup-last-mail))
1823 (gnus-eval-in-buffer-window gnus-save-article-buffer
1827 (if (and (file-readable-p filename)
1828 (mail-file-babyl-p filename))
1829 (rmail-output-to-rmail-file filename t)
1830 (gnus-output-to-mail filename)))))
1833 (defun gnus-summary-save-in-file (&optional filename overwrite)
1834 "Append this article to file.
1835 Optional argument FILENAME specifies file name.
1836 Directory to save to is default to `gnus-article-save-directory'."
1837 (setq filename (gnus-read-save-file-name
1838 "Save %s in file:" filename
1839 gnus-file-save-name gnus-newsgroup-name
1840 gnus-current-headers 'gnus-newsgroup-last-file))
1841 (gnus-eval-in-buffer-window gnus-save-article-buffer
1845 (when (and overwrite
1846 (file-exists-p filename))
1847 (delete-file filename))
1848 (gnus-output-to-file filename))))
1851 (defun gnus-summary-write-to-file (&optional filename)
1852 "Write this article to a file.
1853 Optional argument FILENAME specifies file name.
1854 The directory to save in defaults to `gnus-article-save-directory'."
1855 (gnus-summary-save-in-file nil t))
1857 (defun gnus-summary-save-body-in-file (&optional filename)
1858 "Append this article body to a file.
1859 Optional argument FILENAME specifies file name.
1860 The directory to save in defaults to `gnus-article-save-directory'."
1861 (setq filename (gnus-read-save-file-name
1862 "Save %s body in file:" filename
1863 gnus-file-save-name gnus-newsgroup-name
1864 gnus-current-headers 'gnus-newsgroup-last-file))
1865 (gnus-eval-in-buffer-window gnus-save-article-buffer
1869 (when (article-goto-body)
1870 (narrow-to-region (point) (point-max)))
1871 (gnus-output-to-file filename))))
1874 (defun gnus-summary-save-in-pipe (&optional command)
1875 "Pipe this article to subprocess."
1877 (cond ((and (eq command 'default)
1878 gnus-last-shell-command)
1879 gnus-last-shell-command)
1883 "Shell command on %s: "
1884 (if (and gnus-number-of-articles-to-be-saved
1885 (> gnus-number-of-articles-to-be-saved 1))
1886 (format "these %d articles"
1887 gnus-number-of-articles-to-be-saved)
1889 gnus-last-shell-command))))
1890 (when (string-equal command "")
1891 (setq command gnus-last-shell-command))
1892 (gnus-eval-in-buffer-window gnus-article-buffer
1895 (shell-command-on-region (point-min) (point-max) command nil)))
1896 (setq gnus-last-shell-command command))
1898 ;;; Article file names when saving.
1900 (defun gnus-capitalize-newsgroup (newsgroup)
1901 "Capitalize NEWSGROUP name."
1902 (when (not (zerop (length newsgroup)))
1903 (concat (char-to-string (upcase (aref newsgroup 0)))
1904 (substring newsgroup 1))))
1906 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1907 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1908 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1909 Otherwise, it is like ~/News/news/group/num."
1912 (concat (if (gnus-use-long-file-name 'not-save)
1913 (gnus-capitalize-newsgroup newsgroup)
1914 (gnus-newsgroup-directory-form newsgroup))
1915 "/" (int-to-string (mail-header-number headers)))
1916 gnus-article-save-directory)))
1918 (string-equal (file-name-directory default)
1919 (file-name-directory last-file))
1920 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1922 (or last-file default))))
1924 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1925 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1926 If variable `gnus-use-long-file-name' is non-nil, it is
1927 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1930 (concat (if (gnus-use-long-file-name 'not-save)
1932 (gnus-newsgroup-directory-form newsgroup))
1933 "/" (int-to-string (mail-header-number headers)))
1934 gnus-article-save-directory)))
1936 (string-equal (file-name-directory default)
1937 (file-name-directory last-file))
1938 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1940 (or last-file default))))
1942 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1943 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1944 If variable `gnus-use-long-file-name' is non-nil, it is
1945 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1948 (if (gnus-use-long-file-name 'not-save)
1949 (gnus-capitalize-newsgroup newsgroup)
1950 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1951 gnus-article-save-directory)))
1953 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1954 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1955 If variable `gnus-use-long-file-name' is non-nil, it is
1956 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1959 (if (gnus-use-long-file-name 'not-save)
1961 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1962 gnus-article-save-directory)))
1969 (setq afunc (car func)
1972 gfunc (intern (format "gnus-%s" func))))
1974 (if (not (fboundp afunc))
1976 `(lambda (&optional interactive &rest args)
1977 ,(documentation afunc t)
1978 (interactive (list t))
1980 (set-buffer gnus-article-buffer)
1982 (call-interactively ',afunc)
1983 (apply ',afunc args))))))))
1984 '(article-hide-headers
1985 article-hide-boring-headers
1986 article-treat-overstrike
1987 (article-fill . gnus-article-word-wrap)
1989 article-display-x-face
1990 article-de-quoted-unreadable
1991 article-mime-decode-quoted-printable
1994 article-hide-signature
1995 article-remove-trailing-blank-lines
1996 article-strip-leading-blank-lines
1997 article-strip-multiple-blank-lines
1998 article-strip-leading-space
1999 article-strip-trailing-space
2000 article-strip-blank-lines
2001 article-strip-all-blank-lines
2003 article-date-iso8601
2004 article-date-original
2006 article-decode-mime-words
2007 article-decode-charset
2008 article-decode-encoded-words
2012 article-treat-dumbquotes
2013 article-normalize-headers
2014 (article-show-all . gnus-article-show-all-headers))))
2017 ;;; Gnus article mode
2020 (put 'gnus-article-mode 'mode-class 'special)
2022 (set-keymap-parent gnus-article-mode-map widget-keymap)
2024 (gnus-define-keys gnus-article-mode-map
2025 " " gnus-article-goto-next-page
2026 "\177" gnus-article-goto-prev-page
2027 [delete] gnus-article-goto-prev-page
2028 "\C-c^" gnus-article-refer-article
2029 "h" gnus-article-show-summary
2030 "s" gnus-article-show-summary
2031 "\C-c\C-m" gnus-article-mail
2032 "?" gnus-article-describe-briefly
2033 "e" gnus-article-edit
2034 "<" beginning-of-buffer
2036 "\C-c\C-i" gnus-info-find-node
2039 "\C-d" gnus-article-read-summary-keys
2040 "\M-*" gnus-article-read-summary-keys
2041 "\M-#" gnus-article-read-summary-keys
2042 "\M-^" gnus-article-read-summary-keys
2043 "\M-g" gnus-article-read-summary-keys)
2045 (substitute-key-definition
2046 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2048 (defun gnus-article-make-menu-bar ()
2049 (gnus-turn-off-edit-menu 'article)
2050 (unless (boundp 'gnus-article-article-menu)
2052 gnus-article-article-menu gnus-article-mode-map ""
2054 ["Scroll forwards" gnus-article-goto-next-page t]
2055 ["Scroll backwards" gnus-article-goto-prev-page t]
2056 ["Show summary" gnus-article-show-summary t]
2057 ["Fetch Message-ID at point" gnus-article-refer-article t]
2058 ["Mail to address at point" gnus-article-mail t]
2059 ["Send a bug report" gnus-bug t]))
2062 gnus-article-treatment-menu gnus-article-mode-map ""
2064 ["Hide headers" gnus-article-hide-headers t]
2065 ["Hide signature" gnus-article-hide-signature t]
2066 ["Hide citation" gnus-article-hide-citation t]
2067 ["Treat overstrike" gnus-article-treat-overstrike t]
2068 ["Remove carriage return" gnus-article-remove-cr t]
2069 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2071 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2073 (when (boundp 'gnus-summary-post-menu)
2074 (define-key gnus-article-mode-map [menu-bar post]
2075 (cons "Post" gnus-summary-post-menu)))
2077 (gnus-run-hooks 'gnus-article-menu-hook)))
2079 (defun gnus-article-mode ()
2080 "Major mode for displaying an article.
2082 All normal editing commands are switched off.
2084 The following commands are available in addition to all summary mode
2086 \\<gnus-article-mode-map>
2087 \\[gnus-article-next-page]\t Scroll the article one page forwards
2088 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2089 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2090 \\[gnus-article-show-summary]\t Display the summary buffer
2091 \\[gnus-article-mail]\t Send a reply to the address near point
2092 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2093 \\[gnus-info-find-node]\t Go to the Gnus info node"
2095 (when (gnus-visual-p 'article-menu 'menu)
2096 (gnus-article-make-menu-bar))
2097 (gnus-simplify-mode-line)
2098 (setq mode-name "Article")
2099 (setq major-mode 'gnus-article-mode)
2100 (make-local-variable 'minor-mode-alist)
2101 (use-local-map gnus-article-mode-map)
2102 (gnus-update-format-specifications nil 'article-mode)
2103 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2104 (make-local-variable 'gnus-page-broken)
2105 (make-local-variable 'gnus-button-marker-list)
2106 (make-local-variable 'gnus-article-current-summary)
2107 (make-local-variable 'gnus-article-mime-handles)
2108 (make-local-variable 'gnus-article-decoded-p)
2109 (make-local-variable 'gnus-article-mime-handle-alist)
2110 (gnus-set-default-directory)
2111 (buffer-disable-undo)
2112 (setq buffer-read-only t)
2113 (set-syntax-table gnus-article-mode-syntax-table)
2114 (mm-enable-multibyte)
2115 (gnus-run-hooks 'gnus-article-mode-hook))
2117 (defun gnus-article-setup-buffer ()
2118 "Initialize the article buffer."
2119 (let* ((name (if gnus-single-article-buffer "*Article*"
2120 (concat "*Article " gnus-newsgroup-name "*")))
2122 (progn (string-match "\\*Article" name)
2123 (concat " *Original Article"
2124 (substring name (match-end 0))))))
2125 (setq gnus-article-buffer name)
2126 (setq gnus-original-article-buffer original)
2127 (setq gnus-article-mime-handle-alist nil)
2128 ;; This might be a variable local to the summary buffer.
2129 (unless gnus-single-article-buffer
2131 (set-buffer gnus-summary-buffer)
2132 (setq gnus-article-buffer name)
2133 (setq gnus-original-article-buffer original)
2134 (gnus-set-global-variables)))
2135 ;; Init original article buffer.
2137 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2138 (mm-enable-multibyte)
2139 (setq major-mode 'gnus-original-article-mode)
2140 (make-local-variable 'gnus-original-article))
2141 (if (get-buffer name)
2144 (buffer-disable-undo)
2145 (setq buffer-read-only t)
2146 (unless (eq major-mode 'gnus-article-mode)
2147 (gnus-article-mode))
2150 (set-buffer (gnus-get-buffer-create name))
2152 (make-local-variable 'gnus-summary-buffer)
2153 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2154 (current-buffer)))))
2156 ;; Set article window start at LINE, where LINE is the number of lines
2157 ;; from the head of the article.
2158 (defun gnus-article-set-window-start (&optional line)
2160 (get-buffer-window gnus-article-buffer t)
2162 (set-buffer gnus-article-buffer)
2163 (goto-char (point-min))
2166 (gnus-message 6 "Moved to bookmark")
2167 (search-forward "\n\n" nil t)
2171 (defun gnus-article-prepare (article &optional all-headers header)
2172 "Prepare ARTICLE in article mode buffer.
2173 ARTICLE should either be an article number or a Message-ID.
2174 If ARTICLE is an id, HEADER should be the article headers.
2175 If ALL-HEADERS is non-nil, no headers are hidden."
2177 ;; Make sure we start in a summary buffer.
2178 (unless (eq major-mode 'gnus-summary-mode)
2179 (set-buffer gnus-summary-buffer))
2180 (setq gnus-summary-buffer (current-buffer))
2181 (let* ((gnus-article (if header (mail-header-number header) article))
2182 (summary-buffer (current-buffer))
2183 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2184 (group gnus-newsgroup-name)
2187 (gnus-article-setup-buffer)
2188 (set-buffer gnus-article-buffer)
2189 ;; Deactivate active regions.
2190 (when (and (boundp 'transient-mark-mode)
2191 transient-mark-mode)
2192 (setq mark-active nil))
2193 (if (not (setq result (let ((buffer-read-only nil))
2194 (gnus-request-article-this-buffer
2196 ;; There is no such article.
2198 (when (and (numberp article)
2199 (not (memq article gnus-newsgroup-sparse)))
2200 (setq gnus-article-current
2201 (cons gnus-newsgroup-name article))
2202 (set-buffer gnus-summary-buffer)
2203 (setq gnus-current-article article)
2204 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2206 (gnus-summary-set-agent-mark article)
2207 (message "Message marked for downloading"))
2208 (gnus-summary-mark-article article gnus-canceled-mark)
2209 (unless (memq article gnus-newsgroup-sparse)
2211 "No such article (may have expired or been canceled)")))))
2212 (if (or (eq result 'pseudo)
2213 (eq result 'nneething))
2216 (set-buffer summary-buffer)
2217 (push article gnus-newsgroup-history)
2218 (setq gnus-last-article gnus-current-article
2219 gnus-current-article 0
2220 gnus-current-headers nil
2221 gnus-article-current nil)
2222 (if (eq result 'nneething)
2223 (gnus-configure-windows 'summary)
2224 (gnus-configure-windows 'article))
2225 (gnus-set-global-variables))
2226 (let ((gnus-article-mime-handle-alist-1
2227 gnus-article-mime-handle-alist))
2228 (gnus-set-mode-line 'article)))
2229 ;; The result from the `request' was an actual article -
2230 ;; or at least some text that is now displayed in the
2232 (when (and (numberp article)
2233 (not (eq article gnus-current-article)))
2234 ;; Seems like a new article has been selected.
2235 ;; `gnus-current-article' must be an article number.
2237 (set-buffer summary-buffer)
2238 (push article gnus-newsgroup-history)
2239 (setq gnus-last-article gnus-current-article
2240 gnus-current-article article
2241 gnus-current-headers
2242 (gnus-summary-article-header gnus-current-article)
2243 gnus-article-current
2244 (cons gnus-newsgroup-name gnus-current-article))
2245 (unless (vectorp gnus-current-headers)
2246 (setq gnus-current-headers nil))
2247 (gnus-summary-goto-subject gnus-current-article)
2248 (when (gnus-summary-show-thread)
2249 ;; If the summary buffer really was folded, the
2250 ;; previous goto may not actually have gone to
2251 ;; the right article, but the thread root instead.
2253 (gnus-summary-goto-subject gnus-current-article))
2254 (gnus-run-hooks 'gnus-mark-article-hook)
2255 (gnus-set-mode-line 'summary)
2256 (when (gnus-visual-p 'article-highlight 'highlight)
2257 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2258 ;; Set the global newsgroup variables here.
2259 ;; Suggested by Jim Sisolak
2260 ;; <sisolak@trans4.neep.wisc.edu>.
2261 (gnus-set-global-variables)
2262 (setq gnus-have-all-headers
2263 (or all-headers gnus-show-all-headers))))
2264 (when (or (numberp article)
2266 (gnus-article-prepare-display)
2268 (goto-char (point-min))
2269 (setq gnus-page-broken
2270 (when gnus-break-pages
2271 (gnus-narrow-to-page)
2273 (let ((gnus-article-mime-handle-alist-1
2274 gnus-article-mime-handle-alist))
2275 (gnus-set-mode-line 'article))
2276 (gnus-configure-windows 'article)
2278 (set-window-point (get-buffer-window (current-buffer)) (point))
2282 (defun gnus-article-prepare-display ()
2283 "Make the current buffer look like a nice article."
2284 ;; Hooks for getting information from the article.
2285 ;; This hook must be called before being narrowed.
2286 (let ((gnus-article-buffer (current-buffer))
2288 (unless (eq major-mode 'gnus-article-mode)
2289 (gnus-article-mode))
2290 (setq buffer-read-only nil)
2291 (gnus-run-hooks 'gnus-tmp-internal-hook)
2292 (gnus-run-hooks 'gnus-article-prepare-hook)
2293 (when gnus-display-mime-function
2294 (funcall gnus-display-mime-function))
2295 ;; Perform the article display hooks.
2296 (gnus-run-hooks 'gnus-article-display-hook)))
2299 ;;; Gnus MIME viewing functions
2302 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2303 "The following specs can be used:
2305 %T MIME type, along with additional info
2306 %n The `name' parameter
2307 %d The description, if any
2308 %l The length of the encoded part
2309 %p The part identifier number
2310 %e Dots if the part isn't displayed")
2312 (defvar gnus-mime-button-line-format-alist
2313 '((?t gnus-tmp-type ?s)
2314 (?T gnus-tmp-type-long ?s)
2315 (?n gnus-tmp-name ?s)
2316 (?d gnus-tmp-description ?s)
2318 (?l gnus-tmp-length ?d)
2319 (?e gnus-tmp-dots ?s)))
2321 (defvar gnus-mime-button-commands
2322 '((gnus-article-press-button "\r" "Toggle Display")
2323 (gnus-mime-view-part "v" "View Interactively...")
2324 (gnus-mime-save-part "o" "Save...")
2325 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2326 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2327 (gnus-mime-internalize-part "E" "View Internally")
2328 (gnus-mime-externalize-part "e" "View Externally")
2329 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2331 (defun gnus-article-mime-part-status ()
2332 (if gnus-article-mime-handle-alist-1
2333 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2336 (defvar gnus-mime-button-map nil)
2337 (unless gnus-mime-button-map
2338 (setq gnus-mime-button-map (make-sparse-keymap))
2339 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2340 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2341 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2343 (define-key gnus-mime-button-map (cadr c) (car c)))
2344 gnus-mime-button-commands))
2346 (defun gnus-mime-button-menu (event)
2347 "Construct a context-sensitive menu of MIME commands."
2350 (let ((pos (event-start event)))
2351 (set-buffer (window-buffer (posn-window pos)))
2352 (goto-char (posn-point pos))
2353 (gnus-article-check-buffer)
2354 (let ((response (x-popup-menu
2356 ("" ,@(mapcar (lambda (c)
2357 (cons (caddr c) (car c)))
2358 gnus-mime-button-commands))))))
2360 (funcall response))))))
2362 (defun gnus-mime-view-all-parts (&optional handles)
2363 "View all the MIME parts."
2365 (save-current-buffer
2366 (set-buffer gnus-article-buffer)
2367 (let ((handles (or handles gnus-article-mime-handles))
2368 (rfc2047-default-charset gnus-newsgroup-default-charset)
2369 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2370 (if (stringp (car handles))
2371 (gnus-mime-view-all-parts (cdr handles))
2372 (mapcar 'mm-display-part handles)))))
2374 (defun gnus-mime-save-part ()
2375 "Save the MIME part under point."
2377 (gnus-article-check-buffer)
2378 (let ((data (get-text-property (point) 'gnus-data)))
2379 (mm-save-part data)))
2381 (defun gnus-mime-pipe-part ()
2382 "Pipe the MIME part under point to a process."
2384 (gnus-article-check-buffer)
2385 (let ((data (get-text-property (point) 'gnus-data)))
2386 (mm-pipe-part data)))
2388 (defun gnus-mime-view-part ()
2389 "Interactively choose a view method for the MIME part under point."
2391 (gnus-article-check-buffer)
2392 (let ((data (get-text-property (point) 'gnus-data)))
2393 (mm-interactively-view-part data)))
2395 (defun gnus-mime-copy-part (&optional handle)
2396 "Put the the MIME part under point into a new buffer."
2398 (gnus-article-check-buffer)
2399 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2400 (contents (mm-get-part handle))|
2401 (base (file-name-nondirectory
2403 (mail-content-type-get (mm-handle-type handle) 'name)
2404 (mail-content-type-get (mm-handle-type handle)
2407 (buffer (generate-new-buffer base)))
2408 (switch-to-buffer buffer)
2410 ;; We do it this way to make `normal-mode' set the appropriate mode.
2413 (setq buffer-file-name (expand-file-name base))
2415 (setq buffer-file-name nil))
2416 (goto-char (point-min))))
2418 (defun gnus-mime-inline-part (&optional charset)
2419 "Insert the MIME part under point into the current buffer."
2420 (interactive "P") ; For compatibility reasons we are not using "z".
2421 (gnus-article-check-buffer)
2422 (let* ((data (get-text-property (point) 'gnus-data))
2426 (if (mm-handle-undisplayer data)
2427 (mm-remove-part data)
2428 (setq contents (mm-get-part data))
2431 (unless (symbolp charset)
2432 (setq charset (mm-read-coding-system "Charset: ")))
2433 (setq contents (mm-decode-coding-string contents charset)))
2434 (mm-insert-inline data contents)
2437 (defun gnus-mime-externalize-part (&optional handle)
2438 "View the MIME part under point with an external viewer."
2440 (gnus-article-check-buffer)
2441 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2442 (mm-user-display-methods nil)
2443 (mm-all-images-fit t)
2444 (rfc2047-default-charset gnus-newsgroup-default-charset)
2445 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2446 (if (mm-handle-undisplayer handle)
2447 (mm-remove-part handle)
2448 (mm-display-part handle))))
2450 (defun gnus-mime-internalize-part (&optional handle)
2451 "View the MIME part under point with an internal viewer."
2453 (gnus-article-check-buffer)
2454 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2455 (mm-user-display-methods '((".*" . inline)))
2456 (mm-all-images-fit t)
2457 (rfc2047-default-charset gnus-newsgroup-default-charset)
2458 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2459 (if (mm-handle-undisplayer handle)
2460 (mm-remove-part handle)
2461 (mm-display-part handle))))
2463 (defun gnus-article-part-wrapper (n function)
2464 (save-current-buffer
2465 (set-buffer gnus-article-buffer)
2466 (when (> n (length gnus-article-mime-handle-alist))
2467 (error "No such part"))
2468 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2469 (funcall function handle))))
2471 (defun gnus-article-pipe-part (n)
2472 "Pipe MIME part N, which is the numerical prefix."
2474 (gnus-article-part-wrapper n 'mm-pipe-part))
2476 (defun gnus-article-save-part (n)
2477 "Save MIME part N, which is the numerical prefix."
2479 (gnus-article-part-wrapper n 'mm-save-part))
2481 (defun gnus-article-interactively-view-part (n)
2482 "Pipe MIME part N, which is the numerical prefix."
2484 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2486 (defun gnus-article-copy-part (n)
2487 "Pipe MIME part N, which is the numerical prefix."
2489 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2491 (defun gnus-article-externalize-part (n)
2492 "Pipe MIME part N, which is the numerical prefix."
2494 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2496 (defun gnus-article-view-part (n)
2497 "View MIME part N, which is the numerical prefix."
2499 (save-current-buffer
2500 (set-buffer gnus-article-buffer)
2501 (when (> n (length gnus-article-mime-handle-alist))
2502 (error "No such part"))
2503 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2504 (when (gnus-article-goto-part n)
2505 (if (equal (car handle) "multipart/alternative")
2506 (gnus-article-press-button)
2507 (when (eq (gnus-mm-display-part handle) 'internal)
2508 (gnus-set-window-start)))))))
2510 (defun gnus-mm-display-part (handle)
2511 "Display HANDLE and fix MIME button."
2512 (let ((id (get-text-property (point) 'gnus-part))
2515 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2516 (gnus-insert-mime-button
2517 handle id (list (not (mm-handle-displayed-p handle))))
2519 (let ((window (selected-window))
2520 (rfc2047-default-charset gnus-newsgroup-default-charset)
2521 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2524 (let ((win (get-buffer-window (current-buffer) t)))
2526 (select-window win))
2529 (mm-display-part handle))
2530 (select-window window))))
2531 (goto-char point))))
2533 (defun gnus-article-goto-part (n)
2534 "Go to MIME part N."
2535 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2537 (goto-char point))))
2539 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2540 (let ((gnus-tmp-name
2541 (or (mail-content-type-get (mm-handle-type handle)
2543 (mail-content-type-get (mm-handle-disposition handle)
2546 (gnus-tmp-type (car (mm-handle-type handle)))
2547 (gnus-tmp-description
2548 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2551 (if (if displayed (car displayed)
2552 (mm-handle-displayed-p handle))
2554 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2556 gnus-tmp-type-long b e)
2557 (when (string-match ".*/" gnus-tmp-name)
2558 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2559 (setq gnus-tmp-type-long (concat gnus-tmp-type
2560 (and (not (equal gnus-tmp-name ""))
2561 (concat "; " gnus-tmp-name))))
2562 (or (equal gnus-tmp-description "")
2563 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2568 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2569 `(local-map ,gnus-mime-button-map
2570 keymap ,gnus-mime-button-map
2571 gnus-callback gnus-mm-display-part
2572 gnus-part ,gnus-tmp-id
2573 article-type annotation
2576 (widget-convert-button 'link b e
2578 :action 'gnus-widget-press-button
2579 :button-keymap gnus-mime-button-map
2582 ;; Needed to properly clear the message
2583 ;; due to a bug in wid-edit
2584 (setq help-echo-owns-message t)
2586 "Click to %s the MIME part; %s for more options"
2587 (if (mm-handle-displayed-p
2588 (widget-get widget :mime-handle))
2590 (if gnus-xemacs "button3" "mouse-3"))))))
2592 (defun gnus-widget-press-button (elems el)
2593 (goto-char (widget-get elems :from))
2594 (gnus-article-press-button))
2596 (defun gnus-display-mime (&optional ihandles)
2597 "Insert MIME buttons in the buffer."
2599 (save-selected-window
2600 (let ((window (get-buffer-window gnus-article-buffer))
2603 (select-window window)
2604 ;; We have to do this since selecting the window
2605 ;; may change the point. So we set the window point.
2606 (set-window-point window point)))
2607 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2608 handle name type b e display)
2610 ;; Top-level call; we clean up.
2611 (mm-destroy-parts gnus-article-mime-handles)
2612 (setq gnus-article-mime-handles handles
2613 gnus-article-mime-handle-alist nil)
2614 ;; We allow users to glean info from the handles.
2615 (when gnus-article-mime-part-function
2616 (gnus-mime-part-function handles)))
2618 (or (not (stringp (car handles)))
2621 ;; Clean up for mime parts.
2623 (delete-region (point) (point-max)))
2624 (gnus-mime-display-part handles))))))
2626 (defvar gnus-mime-display-multipart-as-mixed nil)
2628 (defun gnus-mime-display-part (handle)
2631 ((not (stringp (car handle)))
2632 (gnus-mime-display-single handle))
2633 ;; multipart/alternative
2634 ((and (equal (car handle) "multipart/alternative")
2635 (not gnus-mime-display-multipart-as-mixed))
2636 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2637 (push (cons id handle) gnus-article-mime-handle-alist)
2638 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2639 ;; multipart/related
2640 ((and (equal (car handle) "multipart/related")
2641 (not gnus-mime-display-multipart-as-mixed))
2642 ;;;!!!We should find the start part, but we just default
2643 ;;;!!!to the first part.
2644 (gnus-mime-display-part (cadr handle)))
2645 ;; Other multiparts are handled like multipart/mixed.
2647 (gnus-mime-display-mixed (cdr handle)))))
2649 (defun gnus-mime-part-function (handles)
2650 (if (stringp (car handles))
2651 (mapcar 'gnus-mime-part-function (cdr handles))
2652 (funcall gnus-article-mime-part-function handles)))
2654 (defun gnus-mime-display-mixed (handles)
2655 (mapcar 'gnus-mime-display-part handles))
2657 (defun gnus-mime-display-single (handle)
2658 (let ((type (car (mm-handle-type handle)))
2659 (ignored gnus-ignored-mime-types)
2666 (when (string-match (pop ignored) type)
2667 (throw 'ignored nil)))
2668 (if (and (setq not-attachment
2669 (or (not (mm-handle-disposition handle))
2670 (equal (car (mm-handle-disposition handle))
2672 (mm-automatic-display-p type)
2673 (or (mm-inlinable-part-p type)
2674 (mm-automatic-external-display-p type)))
2676 (when (equal (car (split-string type "/"))
2679 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2680 (push (cons id handle) gnus-article-mime-handle-alist)
2681 (when (or (not display)
2682 (not (gnus-unbuttonized-mime-type-p type)))
2683 (gnus-article-insert-newline)
2684 (gnus-insert-mime-button
2685 handle id (list (or display (and not-attachment text))))
2686 (gnus-article-insert-newline)
2687 (gnus-article-insert-newline)
2693 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2694 (mm-charset-iso-8859-1-forced
2695 gnus-newsgroup-iso-8859-1-forced))
2696 (mm-display-part handle t))
2697 (goto-char (point-max)))
2698 ((and text not-attachment)
2701 (gnus-article-insert-newline)
2702 (mm-insert-inline handle (mm-get-part handle))
2703 (goto-char (point-max))))))))
2705 (defun gnus-unbuttonized-mime-type-p (type)
2706 "Say whether TYPE is to be unbuttonized."
2707 (unless gnus-inhibit-mime-unbuttonizing
2709 (let ((types gnus-unbuttonized-mime-types))
2711 (when (string-match (pop types) type)
2712 (throw 'found t)))))))
2714 (defun gnus-article-insert-newline ()
2715 "Insert a newline, but mark it as undeletable."
2716 (gnus-put-text-property
2717 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2719 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2720 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2723 handle buffer-read-only from props begend not-pref)
2724 (save-window-excursion
2727 (narrow-to-region (car ibegend)
2730 (goto-char (car ibegend))
2733 (delete-region (point-min) (point-max))
2734 (mm-remove-parts handles))
2735 (setq begend (list (point-marker)))
2737 (unless (setq not-pref (cadr (member preferred ihandles)))
2738 (setq not-pref (car ihandles)))
2740 (not (gnus-unbuttonized-mime-type-p
2741 "multipart/alternative")))
2742 (gnus-add-text-properties
2745 (insert (format "%d. " id))
2749 (unless ,(not ibegend)
2750 (setq gnus-article-mime-handle-alist
2751 ',gnus-article-mime-handle-alist))
2752 (gnus-mime-display-alternative
2753 ',ihandles ',not-pref ',begend ,id))
2754 local-map ,gnus-mime-button-map
2755 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2756 face ,gnus-article-button-face
2757 keymap ,gnus-mime-button-map
2760 (widget-convert-button 'link from (point)
2761 :action 'gnus-widget-press-button
2762 :button-keymap gnus-widget-button-keymap)
2764 (while (setq handle (pop handles))
2765 (gnus-add-text-properties
2768 (insert (format "(%c) %-18s"
2769 (if (equal handle preferred) ?* ? )
2770 (if (stringp (car handle))
2772 (car (mm-handle-type handle)))))
2776 (unless ,(not ibegend)
2777 (setq gnus-article-mime-handle-alist
2778 ',gnus-article-mime-handle-alist))
2779 (gnus-mime-display-alternative
2780 ',ihandles ',handle ',begend ,id))
2781 local-map ,gnus-mime-button-map
2782 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2783 face ,gnus-article-button-face
2784 keymap ,gnus-mime-button-map
2787 (widget-convert-button 'link from (point)
2788 :action 'gnus-widget-press-button
2789 :button-keymap gnus-widget-button-keymap)
2793 (if (stringp (car preferred))
2794 (gnus-display-mime preferred)
2795 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2796 (mm-charset-iso-8859-1-forced
2797 gnus-newsgroup-iso-8859-1-forced))
2798 (mm-display-part preferred)))
2799 (goto-char (point-max))
2800 (setcdr begend (point-marker)))))
2802 (goto-char point))))
2804 (defun gnus-article-wash-status ()
2805 "Return a string which display status of article washing."
2807 (set-buffer gnus-article-buffer)
2808 (let ((cite (gnus-article-hidden-text-p 'cite))
2809 (headers (gnus-article-hidden-text-p 'headers))
2810 (boring (gnus-article-hidden-text-p 'boring-headers))
2811 (pgp (gnus-article-hidden-text-p 'pgp))
2812 (pem (gnus-article-hidden-text-p 'pem))
2813 (signature (gnus-article-hidden-text-p 'signature))
2814 (overstrike (gnus-article-hidden-text-p 'overstrike))
2815 (emphasis (gnus-article-hidden-text-p 'emphasis)))
2816 (format "%c%c%c%c%c%c"
2818 (if (or headers boring) ?h ? )
2819 (if (or pgp pem) ?p ? )
2820 (if signature ?s ? )
2821 (if overstrike ?o ? )
2822 (if emphasis ?e ? )))))
2824 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2826 (defun gnus-article-maybe-hide-headers ()
2827 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2828 Provided for backwards compatibility."
2829 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
2830 (not (save-excursion (set-buffer gnus-summary-buffer)
2831 gnus-have-all-headers)))
2832 (not gnus-inhibit-hiding))
2833 (gnus-article-hide-headers)))
2837 (defun gnus-output-to-file (file-name)
2838 "Append the current article to a file named FILE-NAME."
2839 (let ((artbuf (current-buffer)))
2841 (insert-buffer-substring artbuf)
2842 ;; Append newline at end of the buffer as separator, and then
2844 (goto-char (point-max))
2846 (append-to-file (point-min) (point-max) file-name)
2849 (defun gnus-narrow-to-page (&optional arg)
2850 "Narrow the article buffer to a page.
2851 If given a numerical ARG, move forward ARG pages."
2853 (setq arg (if arg (prefix-numeric-value arg) 0))
2855 (set-buffer gnus-article-buffer)
2856 (goto-char (point-min))
2858 ;; Remove any old next/prev buttons.
2859 (when (gnus-visual-p 'page-marker)
2860 (let ((buffer-read-only nil))
2861 (gnus-remove-text-with-property 'gnus-prev)
2862 (gnus-remove-text-with-property 'gnus-next)))
2865 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2867 (re-search-forward page-delimiter nil 'move arg)))
2868 (goto-char (match-end 0)))
2871 (if (re-search-forward page-delimiter nil 'move)
2874 (when (and (gnus-visual-p 'page-marker)
2875 (not (= (point-min) 1)))
2877 (goto-char (point-min))
2878 (gnus-insert-prev-page-button)))
2879 (when (and (gnus-visual-p 'page-marker)
2880 (< (+ (point-max) 2) (buffer-size)))
2882 (goto-char (point-max))
2883 (gnus-insert-next-page-button)))))
2885 ;; Article mode commands
2887 (defun gnus-article-goto-next-page ()
2888 "Show the next page of the article."
2890 (when (gnus-article-next-page)
2891 (goto-char (point-min))
2892 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2894 (defun gnus-article-goto-prev-page ()
2895 "Show the next page of the article."
2897 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2898 (gnus-article-prev-page nil)))
2900 (defun gnus-article-next-page (&optional lines)
2901 "Show the next page of the current article.
2902 If end of article, return non-nil. Otherwise return nil.
2903 Argument LINES specifies lines to be scrolled up."
2905 (move-to-window-line -1)
2908 (and (pos-visible-in-window-p) ;Not continuation line.
2910 ;; Nothing in this page.
2911 (if (or (not gnus-page-broken)
2914 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2916 (gnus-narrow-to-page 1) ;Go to next page.
2918 ;; More in this page.
2919 (let ((scroll-in-place nil))
2923 ;; Long lines may cause an end-of-buffer error.
2924 (goto-char (point-max)))))
2925 (move-to-window-line 0)
2928 (defun gnus-article-prev-page (&optional lines)
2929 "Show previous page of current article.
2930 Argument LINES specifies lines to be scrolled down."
2932 (move-to-window-line 0)
2933 (if (and gnus-page-broken
2935 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2937 (gnus-narrow-to-page -1) ;Go to previous page.
2938 (goto-char (point-max))
2940 (let ((scroll-in-place nil))
2944 (beginning-of-buffer
2945 (goto-char (point-min))))
2946 (move-to-window-line 0)))))
2948 (defun gnus-article-refer-article ()
2949 "Read article specified by message-id around point."
2951 (let ((point (point)))
2952 (search-forward ">" nil t) ;Move point to end of "<....>".
2953 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2954 (let ((message-id (match-string 1)))
2956 (set-buffer gnus-summary-buffer)
2957 (gnus-summary-refer-article message-id))
2959 (error "No references around point"))))
2961 (defun gnus-article-show-summary ()
2962 "Reconfigure windows to show summary buffer."
2964 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2965 (error "There is no summary buffer for this article buffer")
2966 (gnus-article-set-globals)
2967 (gnus-configure-windows 'article)
2968 (gnus-summary-goto-subject gnus-current-article)
2969 (gnus-summary-position-point)))
2971 (defun gnus-article-describe-briefly ()
2972 "Describe article mode commands briefly."
2975 (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")))
2977 (defun gnus-article-summary-command ()
2978 "Execute the last keystroke in the summary buffer."
2980 (let ((obuf (current-buffer))
2981 (owin (current-window-configuration))
2983 (switch-to-buffer gnus-article-current-summary 'norecord)
2984 (setq func (lookup-key (current-local-map) (this-command-keys)))
2985 (call-interactively func)
2987 (set-window-configuration owin)
2988 (set-window-point (get-buffer-window (current-buffer)) (point))))
2990 (defun gnus-article-summary-command-nosave ()
2991 "Execute the last keystroke in the summary buffer."
2994 (pop-to-buffer gnus-article-current-summary 'norecord)
2995 (setq func (lookup-key (current-local-map) (this-command-keys)))
2996 (call-interactively func)))
2998 (defun gnus-article-check-buffer ()
2999 "Beep if not in an article buffer."
3000 (unless (equal major-mode 'gnus-article-mode)
3001 (error "Command invoked outside of a Gnus article buffer")))
3003 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3004 "Read a summary buffer key sequence and execute it from the article buffer."
3006 (gnus-article-check-buffer)
3008 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3009 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3010 "=" "^" "\M-^" "|"))
3016 '("n" "Gn" "p" "Gp"))
3019 (set-buffer gnus-article-current-summary)
3020 (let (gnus-pick-mode)
3021 (push (or key last-command-event) unread-command-events)
3022 (setq keys (read-key-sequence nil))))
3025 (if (or (member keys nosaves)
3026 (member keys nosave-but-article)
3027 (member keys nosave-in-article))
3029 (save-window-excursion
3030 (pop-to-buffer gnus-article-current-summary 'norecord)
3031 ;; We disable the pick minor mode commands.
3032 (let (gnus-pick-mode)
3033 (setq func (lookup-key (current-local-map) keys))))
3036 (unless (member keys nosave-in-article)
3037 (set-buffer gnus-article-current-summary))
3038 (call-interactively func)
3039 (setq new-sum-point (point)))
3040 (when (member keys nosave-but-article)
3041 (pop-to-buffer gnus-article-buffer 'norecord)))
3042 ;; These commands should restore window configuration.
3043 (let ((obuf (current-buffer))
3044 (owin (current-window-configuration))
3046 (summary gnus-article-current-summary)
3047 func in-buffer selected)
3048 (if not-restore-window
3049 (pop-to-buffer summary 'norecord)
3050 (switch-to-buffer summary 'norecord))
3051 (setq in-buffer (current-buffer))
3052 ;; We disable the pick minor mode commands.
3053 (if (setq func (let (gnus-pick-mode)
3054 (lookup-key (current-local-map) keys)))
3056 (call-interactively func)
3057 (setq new-sum-point (point)))
3059 (when (eq in-buffer (current-buffer))
3060 (setq selected (gnus-summary-select-article))
3062 (unless not-restore-window
3063 (set-window-configuration owin))
3064 (unless (or (not (eq selected 'old)) (member keys up-to-top))
3065 (set-window-point (get-buffer-window (current-buffer))
3067 (let ((win (get-buffer-window gnus-article-current-summary)))
3069 (set-window-point win new-sum-point))))))))
3071 (defun gnus-article-hide (&optional arg force)
3072 "Hide all the gruft in the current article.
3073 This means that PGP stuff, signatures, cited text and (some)
3074 headers will be hidden.
3075 If given a prefix, show the hidden text instead."
3076 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3077 (gnus-article-hide-headers arg)
3078 (gnus-article-hide-pgp arg)
3079 (gnus-article-hide-citation-maybe arg force)
3080 (gnus-article-hide-signature arg))
3082 (defun gnus-article-maybe-highlight ()
3083 "Do some article highlighting if article highlighting is requested."
3084 (when (gnus-visual-p 'article-highlight 'highlight)
3085 (gnus-article-highlight-some)))
3087 (defun gnus-check-group-server ()
3088 ;; Make sure the connection to the server is alive.
3089 (unless (gnus-server-opened
3090 (gnus-find-method-for-group gnus-newsgroup-name))
3091 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3092 (gnus-request-group gnus-newsgroup-name t)))
3094 (defun gnus-request-article-this-buffer (article group)
3095 "Get an article and insert it into this buffer."
3096 (let (do-update-line sparse-header)
3100 (gnus-kill-all-overlays)
3101 (setq group (or group gnus-newsgroup-name))
3103 ;; Using `gnus-request-article' directly will insert the article into
3104 ;; `nntp-server-buffer' - so we'll save some time by not having to
3105 ;; copy it from the server buffer into the article buffer.
3107 ;; We only request an article by message-id when we do not have the
3108 ;; headers for it, so we'll have to get those.
3109 (when (stringp article)
3110 (let ((gnus-override-method gnus-refer-article-method))
3111 (gnus-read-header article)))
3113 ;; If the article number is negative, that means that this article
3114 ;; doesn't belong in this newsgroup (possibly), so we find its
3115 ;; message-id and request it by id instead of number.
3116 (when (and (numberp article)
3118 (get-buffer gnus-summary-buffer)
3119 (gnus-buffer-exists-p gnus-summary-buffer))
3121 (set-buffer gnus-summary-buffer)
3122 (let ((header (gnus-summary-article-header article)))
3125 ((memq article gnus-newsgroup-sparse)
3126 ;; This is a sparse gap article.
3127 (setq do-update-line article)
3128 (setq article (mail-header-id header))
3129 (let ((gnus-override-method gnus-refer-article-method))
3130 (setq sparse-header (gnus-read-header article)))
3131 (setq gnus-newsgroup-sparse
3132 (delq article gnus-newsgroup-sparse)))
3134 ;; It's a real article.
3135 (setq article (mail-header-id header)))
3137 ;; It is an extracted pseudo-article.
3138 (setq article 'pseudo)
3139 (gnus-request-pseudo-article header))))
3141 (let ((method (gnus-find-method-for-group
3142 gnus-newsgroup-name)))
3143 (when (and (eq (car method) 'nneething)
3146 (file-name-as-directory
3147 (or (cadr (assq 'nneething-address method))
3149 (mail-header-subject header))))
3150 (when (file-directory-p dir)
3151 (setq article 'nneething)
3152 (gnus-group-enter-directory dir))))))))
3155 ;; Refuse to select canceled articles.
3156 ((and (numberp article)
3158 (get-buffer gnus-summary-buffer)
3159 (gnus-buffer-exists-p gnus-summary-buffer)
3160 (eq (cdr (save-excursion
3161 (set-buffer gnus-summary-buffer)
3162 (assq article gnus-newsgroup-reads)))
3163 gnus-canceled-mark))
3165 ;; We first check `gnus-original-article-buffer'.
3166 ((and (get-buffer gnus-original-article-buffer)
3169 (set-buffer gnus-original-article-buffer)
3170 (and (equal (car gnus-original-article) group)
3171 (eq (cdr gnus-original-article) article))))
3172 (insert-buffer-substring gnus-original-article-buffer)
3174 ;; Check the backlog.
3175 ((and gnus-keep-backlog
3176 (gnus-backlog-request-article group article (current-buffer)))
3178 ;; Check asynchronous pre-fetch.
3179 ((gnus-async-request-fetched-article group article (current-buffer))
3180 (gnus-async-prefetch-next group article gnus-summary-buffer)
3181 (when (and (numberp article) gnus-keep-backlog)
3182 (gnus-backlog-enter-article group article (current-buffer)))
3185 ((and gnus-use-cache
3187 (gnus-cache-request-article article group))
3189 ;; Get the article and put into the article buffer.
3190 ((or (stringp article) (numberp article))
3191 (let ((gnus-override-method
3192 (and (stringp article) gnus-refer-article-method))
3193 (buffer-read-only nil))
3195 (gnus-kill-all-overlays)
3196 (gnus-check-group-server)
3197 (when (gnus-request-article article group (current-buffer))
3198 (when (numberp article)
3199 (gnus-async-prefetch-next group article gnus-summary-buffer)
3200 (when gnus-keep-backlog
3201 (gnus-backlog-enter-article
3202 group article (current-buffer))))
3207 ;; Associate this article with the current summary buffer.
3208 (setq gnus-article-current-summary gnus-summary-buffer)
3210 ;; Take the article from the original article buffer
3211 ;; and place it in the buffer it's supposed to be in.
3212 (when (and (get-buffer gnus-article-buffer)
3213 (equal (buffer-name (current-buffer))
3214 (buffer-name (get-buffer gnus-article-buffer))))
3216 (if (get-buffer gnus-original-article-buffer)
3217 (set-buffer gnus-original-article-buffer)
3218 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3219 (buffer-disable-undo)
3220 (setq major-mode 'gnus-original-article-mode)
3221 (setq buffer-read-only t))
3222 (let (buffer-read-only)
3224 (insert-buffer-substring gnus-article-buffer))
3225 (setq gnus-original-article (cons group article)))
3228 (run-hooks 'gnus-article-decode-hook)
3229 ;; Mark article as decoded or not.
3230 (setq gnus-article-decoded-p gnus-article-decode-hook))
3232 ;; Update sparse articles.
3233 (when (and do-update-line
3234 (or (numberp article)
3236 (let ((buf (current-buffer)))
3237 (set-buffer gnus-summary-buffer)
3238 (gnus-summary-update-article do-update-line sparse-header)
3239 (gnus-summary-goto-subject do-update-line nil t)
3240 (set-window-point (get-buffer-window (current-buffer) t)
3242 (set-buffer buf))))))
3248 (defcustom gnus-article-edit-mode-hook nil
3249 "Hook run in article edit mode buffers."
3250 :group 'gnus-article-various
3253 (defvar gnus-article-edit-done-function nil)
3255 (defvar gnus-article-edit-mode-map nil)
3257 ;; Should we be using derived.el for this?
3258 (unless gnus-article-edit-mode-map
3259 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3260 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3262 (gnus-define-keys gnus-article-edit-mode-map
3263 "\C-c\C-c" gnus-article-edit-done
3264 "\C-c\C-k" gnus-article-edit-exit)
3266 (gnus-define-keys (gnus-article-edit-wash-map
3267 "\C-c\C-w" gnus-article-edit-mode-map)
3268 "f" gnus-article-edit-full-stops))
3270 (defun gnus-article-edit-mode ()
3271 "Major mode for editing articles.
3272 This is an extended text-mode.
3274 \\{gnus-article-edit-mode-map}"
3276 (setq major-mode 'gnus-article-edit-mode)
3277 (setq mode-name "Article Edit")
3278 (use-local-map gnus-article-edit-mode-map)
3279 (make-local-variable 'gnus-article-edit-done-function)
3280 (make-local-variable 'gnus-prev-winconf)
3281 (setq buffer-read-only nil)
3282 (buffer-enable-undo)
3284 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3286 (defun gnus-article-edit (&optional force)
3287 "Edit the current article.
3288 This will have permanent effect only in mail groups.
3289 If FORCE is non-nil, allow editing of articles even in read-only
3292 (when (and (not force)
3293 (gnus-group-read-only-p))
3294 (error "The current newsgroup does not support article editing"))
3295 (gnus-article-date-original)
3296 (gnus-article-edit-article
3297 `(lambda (no-highlight)
3298 (gnus-summary-edit-article-done
3299 ,(or (mail-header-references gnus-current-headers) "")
3300 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3302 (defun gnus-article-edit-article (exit-func)
3303 "Start editing the contents of the current article buffer."
3304 (let ((winconf (current-window-configuration)))
3305 (set-buffer gnus-article-buffer)
3306 (gnus-article-edit-mode)
3307 (gnus-article-delete-text-of-type 'annotation)
3308 (gnus-set-text-properties (point-min) (point-max) nil)
3309 (gnus-configure-windows 'edit-article)
3310 (setq gnus-article-edit-done-function exit-func)
3311 (setq gnus-prev-winconf winconf)
3312 (gnus-message 6 "C-c C-c to end edits")))
3314 (defun gnus-article-edit-done (&optional arg)
3315 "Update the article edits and exit."
3320 (when (article-goto-body)
3321 (let ((lines (count-lines (point) (point-max)))
3322 (length (- (point-max) (point)))
3323 (case-fold-search t)
3324 (body (copy-marker (point))))
3325 (goto-char (point-min))
3326 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3327 (delete-region (match-beginning 1) (match-end 1))
3328 (insert (number-to-string length)))
3329 (goto-char (point-min))
3330 (when (re-search-forward
3331 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3332 (delete-region (match-beginning 1) (match-end 1))
3333 (insert (number-to-string length)))
3334 (goto-char (point-min))
3335 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3336 (delete-region (match-beginning 1) (match-end 1))
3337 (insert (number-to-string lines)))))))
3338 (let ((func gnus-article-edit-done-function)
3339 (buf (current-buffer))
3340 (start (window-start)))
3341 (gnus-article-edit-exit)
3344 (let ((buffer-read-only nil))
3346 ;; The cache and backlog have to be flushed somewhat.
3347 (when gnus-keep-backlog
3348 (gnus-backlog-remove-article
3349 (car gnus-article-current) (cdr gnus-article-current)))
3350 ;; Flush original article as well.
3352 (when (get-buffer gnus-original-article-buffer)
3353 (set-buffer gnus-original-article-buffer)
3354 (setq gnus-original-article nil)))
3355 (when gnus-use-cache
3356 (gnus-cache-update-article
3357 (car gnus-article-current) (cdr gnus-article-current))))
3359 (set-window-start (get-buffer-window buf) start)
3360 (set-window-point (get-buffer-window buf) (point))))
3362 (defun gnus-article-edit-exit ()
3363 "Exit the article editing without updating."
3365 ;; We remove all text props from the article buffer.
3366 (let ((buf (format "%s" (buffer-string)))
3367 (curbuf (current-buffer))
3369 (window-start (window-start)))
3372 (let ((winconf gnus-prev-winconf))
3374 (set-window-configuration winconf)
3375 ;; Tippy-toe some to make sure that point remains where it was.
3376 (save-current-buffer
3378 (set-window-start (get-buffer-window (current-buffer)) window-start)
3381 (defun gnus-article-edit-full-stops ()
3382 "Interactively repair spacing at end of sentences."
3385 (goto-char (point-min))
3386 (search-forward-regexp "^$" nil t)
3387 (let ((case-fold-search nil))
3388 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3391 ;;; Article highlights
3394 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3396 ;;; Internal Variables:
3398 (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\\)"
3399 "Regular expression that matches URLs."
3400 :group 'gnus-article-buttons
3403 (defcustom gnus-button-alist
3404 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3405 0 t gnus-button-message-id 2)
3406 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3407 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3409 gnus-button-fetch-group 4)
3410 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3411 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3412 t gnus-button-message-id 3)
3413 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3414 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3415 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3416 ;; This is how URLs _should_ be embedded in text...
3417 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3419 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3420 "*Alist of regexps matching buttons in article bodies.
3422 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3423 REGEXP: is the string matching text around the button,
3424 BUTTON: is the number of the regexp grouping actually matching the button,
3425 FORM: is a lisp expression which must eval to true for the button to
3427 CALLBACK: is the function to call when the user push this button, and each
3428 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3430 CALLBACK can also be a variable, in that case the value of that
3431 variable it the real callback function."
3432 :group 'gnus-article-buttons
3433 :type '(repeat (list regexp
3434 (integer :tag "Button")
3436 (function :tag "Callback")
3439 (integer :tag "Regexp group")))))
3441 (defcustom gnus-header-button-alist
3442 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3443 0 t gnus-button-message-id 0)
3444 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3445 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3446 0 t gnus-button-mailto 0)
3447 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3448 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3449 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3450 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3451 gnus-button-message-id 3))
3452 "*Alist of headers and regexps to match buttons in article heads.
3454 This alist is very similar to `gnus-button-alist', except that each
3455 alist has an additional HEADER element first in each entry:
3457 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3459 HEADER is a regexp to match a header. For a fuller explanation, see
3460 `gnus-button-alist'."
3461 :group 'gnus-article-buttons
3462 :group 'gnus-article-headers
3463 :type '(repeat (list (regexp :tag "Header")
3465 (integer :tag "Button")
3467 (function :tag "Callback")
3470 (integer :tag "Regexp group")))))
3472 (defvar gnus-button-regexp nil)
3473 (defvar gnus-button-marker-list nil)
3474 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3476 (defvar gnus-button-last nil)
3477 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3481 (defun gnus-article-push-button (event)
3482 "Check text under the mouse pointer for a callback function.
3483 If the text under the mouse pointer has a `gnus-callback' property,
3484 call it with the value of the `gnus-data' text property."
3486 (set-buffer (window-buffer (posn-window (event-start event))))
3487 (let* ((pos (posn-point (event-start event)))
3488 (data (get-text-property pos 'gnus-data))
3489 (fun (get-text-property pos 'gnus-callback)))
3492 (funcall fun data))))
3494 (defun gnus-article-press-button ()
3495 "Check text at point for a callback function.
3496 If the text at point has a `gnus-callback' property,
3497 call it with the value of the `gnus-data' text property."
3499 (let* ((data (get-text-property (point) 'gnus-data))
3500 (fun (get-text-property (point) 'gnus-callback)))
3502 (funcall fun data))))
3504 (defun gnus-article-highlight (&optional force)
3505 "Highlight current article.
3506 This function calls `gnus-article-highlight-headers',
3507 `gnus-article-highlight-citation',
3508 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3509 do the highlighting. See the documentation for those functions."
3510 (interactive (list 'force))
3511 (gnus-article-highlight-headers)
3512 (gnus-article-highlight-citation force)
3513 (gnus-article-highlight-signature)
3514 (gnus-article-add-buttons force)
3515 (gnus-article-add-buttons-to-head))
3517 (defun gnus-article-highlight-some (&optional force)
3518 "Highlight current article.
3519 This function calls `gnus-article-highlight-headers',
3520 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3521 do the highlighting. See the documentation for those functions."
3522 (interactive (list 'force))
3523 (gnus-article-highlight-headers)
3524 (gnus-article-highlight-signature)
3525 (gnus-article-add-buttons))
3527 (defun gnus-article-highlight-headers ()
3528 "Highlight article headers as specified by `gnus-header-face-alist'."
3531 (set-buffer gnus-article-buffer)
3533 (let ((alist gnus-header-face-alist)
3534 (buffer-read-only nil)
3535 (case-fold-search t)
3536 (inhibit-point-motion-hooks t)
3537 entry regexp header-face field-face from hpoints fpoints)
3538 (message-narrow-to-head)
3539 (while (setq entry (pop alist))
3540 (goto-char (point-min))
3541 (setq regexp (concat "^\\("
3542 (if (string-equal "" (nth 0 entry))
3546 header-face (nth 1 entry)
3547 field-face (nth 2 entry))
3548 (while (and (re-search-forward regexp nil t)
3552 (unless (search-forward ":" nil t)
3554 (when (and header-face
3555 (not (memq (point) hpoints)))
3556 (push (point) hpoints)
3557 (gnus-put-text-property from (point) 'face header-face))
3558 (when (and field-face
3559 (not (memq (setq from (point)) fpoints)))
3561 (if (re-search-forward "^[^ \t]" nil t)
3563 (goto-char (point-max)))
3564 (gnus-put-text-property from (point) 'face field-face))))))))
3566 (defun gnus-article-highlight-signature ()
3567 "Highlight the signature in an article.
3568 It does this by highlighting everything after
3569 `gnus-signature-separator' using `gnus-signature-face'."
3572 (set-buffer gnus-article-buffer)
3573 (let ((buffer-read-only nil)
3574 (inhibit-point-motion-hooks t))
3576 (when (and gnus-signature-face
3577 (gnus-article-narrow-to-signature))
3578 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3579 'face gnus-signature-face)
3581 (gnus-article-search-signature)
3582 (let ((start (match-beginning 0))
3583 (end (set-marker (make-marker) (1+ (match-end 0)))))
3584 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3587 (defun gnus-button-in-region-p (b e prop)
3588 "Say whether PROP exists in the region."
3589 (text-property-not-all b e prop nil))
3591 (defun gnus-article-add-buttons (&optional force)
3592 "Find external references in the article and make buttons of them.
3593 \"External references\" are things like Message-IDs and URLs, as
3594 specified by `gnus-button-alist'."
3595 (interactive (list 'force))
3597 (set-buffer gnus-article-buffer)
3598 (let ((buffer-read-only nil)
3599 (inhibit-point-motion-hooks t)
3600 (case-fold-search t)
3601 (alist gnus-button-alist)
3603 ;; Remove all old markers.
3605 (while (setq marker (pop gnus-button-marker-list))
3607 (when (setq entry (gnus-button-entry))
3608 (put-text-property (match-beginning (nth 1 entry))
3609 (match-end (nth 1 entry))
3610 'gnus-callback nil))
3611 (set-marker marker nil)))
3612 ;; We skip the headers.
3615 (while (setq entry (pop alist))
3616 (setq regexp (car entry))
3618 (while (re-search-forward regexp nil t)
3619 (let* ((start (and entry (match-beginning (nth 1 entry))))
3620 (end (and entry (match-end (nth 1 entry))))
3621 (from (match-beginning 0)))
3622 (when (and (or (eq t (nth 2 entry))
3623 (eval (nth 2 entry)))
3624 (not (gnus-button-in-region-p
3625 start end 'gnus-callback)))
3626 ;; That optional form returned non-nil, so we add the
3628 (gnus-article-add-button
3629 start end 'gnus-button-push
3630 (car (push (set-marker (make-marker) from)
3631 gnus-button-marker-list))))))))))
3633 ;; Add buttons to the head of an article.
3634 (defun gnus-article-add-buttons-to-head ()
3635 "Add buttons to the head of the article."
3638 (set-buffer gnus-article-buffer)
3639 (let ((buffer-read-only nil)
3640 (inhibit-point-motion-hooks t)
3641 (case-fold-search t)
3642 (alist gnus-header-button-alist)
3644 (nnheader-narrow-to-headers)
3646 ;; Each alist entry.
3647 (setq entry (car alist)
3649 (goto-char (point-min))
3650 (while (re-search-forward (car entry) nil t)
3651 ;; Each header matching the entry.
3652 (setq beg (match-beginning 0))
3653 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3654 (match-beginning 0))
3657 (while (re-search-forward (nth 1 entry) end t)
3658 ;; Each match within a header.
3659 (let* ((entry (cdr entry))
3660 (start (match-beginning (nth 1 entry)))
3661 (end (match-end (nth 1 entry)))
3662 (form (nth 2 entry)))
3663 (goto-char (match-end 0))
3665 (gnus-article-add-button
3666 start end (nth 3 entry)
3667 (buffer-substring (match-beginning (nth 4 entry))
3668 (match-end (nth 4 entry)))))))
3672 ;;; External functions:
3674 (defun gnus-article-add-button (from to fun &optional data)
3675 "Create a button between FROM and TO with callback FUN and data DATA."
3676 (when gnus-article-button-face
3677 (gnus-overlay-put (gnus-make-overlay from to)
3678 'face gnus-article-button-face))
3679 (gnus-add-text-properties
3681 (nconc (and gnus-article-mouse-face
3682 (list gnus-mouse-face-prop gnus-article-mouse-face))
3683 (list 'gnus-callback fun)
3684 (and data (list 'gnus-data data))))
3685 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3686 :button-keymap gnus-widget-button-keymap))
3688 ;;; Internal functions:
3690 (defun gnus-article-set-globals ()
3692 (set-buffer gnus-summary-buffer)
3693 (gnus-set-global-variables)))
3695 (defun gnus-signature-toggle (end)
3697 (set-buffer gnus-article-buffer)
3698 (let ((buffer-read-only nil)
3699 (inhibit-point-motion-hooks t))
3700 (if (get-text-property end 'invisible)
3701 (gnus-article-unhide-text end (point-max))
3702 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3704 (defun gnus-button-entry ()
3705 ;; Return the first entry in `gnus-button-alist' matching this place.
3706 (let ((alist gnus-button-alist)
3709 (setq entry (pop alist))
3710 (if (looking-at (car entry))
3715 (defun gnus-button-push (marker)
3716 ;; Push button starting at MARKER.
3719 (let* ((entry (gnus-button-entry))
3720 (inhibit-point-motion-hooks t)
3722 (args (mapcar (lambda (group)
3723 (let ((string (match-string group)))
3724 (gnus-set-text-properties
3725 0 (length string) nil string)
3732 (fboundp (symbol-value fun)))
3733 (apply (symbol-value fun) args))
3735 (gnus-message 1 "You must define `%S' to use this button"
3736 (cons fun args)))))))
3738 (defun gnus-button-message-id (message-id)
3741 (set-buffer gnus-summary-buffer)
3742 (gnus-summary-refer-article message-id)))
3744 (defun gnus-button-fetch-group (address)
3745 "Fetch GROUP specified by ADDRESS."
3746 (if (not (string-match "[:/]" address))
3747 ;; This is just a simple group url.
3748 (gnus-group-read-ephemeral-group address gnus-select-method)
3749 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3751 (error "Can't parse %s" address)
3752 (gnus-group-read-ephemeral-group
3753 (match-string 4 address)
3754 `(nntp ,(match-string 1 address)
3755 (nntp-address ,(match-string 1 address))
3756 (nntp-port-number ,(if (match-end 3)
3757 (match-string 3 address)
3760 (defun gnus-url-parse-query-string (query &optional downcase)
3761 (let (retval pairs cur key val)
3762 (setq pairs (split-string query "&"))
3764 (setq cur (car pairs)
3766 (if (not (string-match "=" cur))
3768 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3769 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3771 (setq key (downcase key)))
3772 (setq cur (assoc key retval))
3774 (setcdr cur (cons val (cdr cur)))
3775 (setq retval (cons (list key val) retval)))))
3778 (defun gnus-url-unhex (x)
3785 (defun gnus-url-unhex-string (str &optional allow-newlines)
3786 "Remove %XXX embedded spaces, etc in a url.
3787 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3788 decoding of carriage returns and line feeds in the string, which is normally
3789 forbidden in URL encoding."
3790 (setq str (or str ""))
3792 (case-fold-search t))
3793 (while (string-match "%[0-9a-f][0-9a-f]" str)
3794 (let* ((start (match-beginning 0))
3795 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3797 (gnus-url-unhex (elt str (+ start 2))))))
3799 tmp (substring str 0 start)
3802 (char-to-string code))
3803 ((or (= code ?\n) (= code ?\r))
3805 (t (char-to-string code))))
3806 str (substring str (match-end 0)))))
3807 (setq tmp (concat tmp str))
3810 (defun gnus-url-mailto (url)
3811 ;; Send mail to someone
3812 (when (string-match "mailto:/*\\(.*\\)" url)
3813 (setq url (substring url (match-beginning 1) nil)))
3814 (let (to args subject func)
3815 (if (string-match (regexp-quote "?") url)
3816 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3817 args (gnus-url-parse-query-string
3818 (substring url (match-end 0) nil) t))
3819 (setq to (gnus-url-unhex-string url)))
3820 (setq args (cons (list "to" to) args)
3821 subject (cdr-safe (assoc "subject" args)))
3824 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3827 (message-position-on-field (caar args)))
3828 (insert (mapconcat 'identity (cdar args) ", "))
3829 (setq args (cdr args)))
3832 (message-goto-subject))))
3834 (defun gnus-button-mailto (address)
3836 (set-buffer (gnus-copy-article-buffer))
3837 (message-reply address))
3839 (defun gnus-button-reply (address)
3840 ;; Reply to ADDRESS.
3841 (message-reply address))
3843 (defun gnus-button-url (address)
3845 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3846 (if (listp browse-url-browser-function)
3847 (browse-url address)
3848 (funcall browse-url-browser-function address)))
3850 (defun gnus-button-embedded-url (address)
3852 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3853 (if (listp browse-url-browser-function)
3854 (browse-url (gnus-strip-whitespace address))
3855 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3857 ;;; Next/prev buttons in the article buffer.
3859 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3860 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3862 (defvar gnus-prev-page-map nil)
3863 (unless gnus-prev-page-map
3864 (setq gnus-prev-page-map (make-sparse-keymap))
3865 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3866 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3868 (defun gnus-insert-prev-page-button ()
3869 (let ((buffer-read-only nil))
3871 gnus-prev-page-line-format nil
3872 `(gnus-prev t local-map ,gnus-prev-page-map
3873 gnus-callback gnus-article-button-prev-page
3874 article-type annotation))))
3876 (defvar gnus-next-page-map nil)
3877 (unless gnus-next-page-map
3878 (setq gnus-next-page-map (make-keymap))
3879 (suppress-keymap gnus-prev-page-map)
3880 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3881 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3883 (defun gnus-button-next-page ()
3884 "Go to the next page."
3886 (let ((win (selected-window)))
3887 (select-window (get-buffer-window gnus-article-buffer t))
3888 (gnus-article-next-page)
3889 (select-window win)))
3891 (defun gnus-button-prev-page ()
3892 "Go to the prev page."
3894 (let ((win (selected-window)))
3895 (select-window (get-buffer-window gnus-article-buffer t))
3896 (gnus-article-prev-page)
3897 (select-window win)))
3899 (defun gnus-insert-next-page-button ()
3900 (let ((buffer-read-only nil))
3901 (gnus-eval-format gnus-next-page-line-format nil
3903 t local-map ,gnus-next-page-map
3904 gnus-callback gnus-article-button-next-page
3905 article-type annotation))))
3907 (defun gnus-article-button-next-page (arg)
3908 "Go to the next page."
3910 (let ((win (selected-window)))
3911 (select-window (get-buffer-window gnus-article-buffer t))
3912 (gnus-article-next-page)
3913 (select-window win)))
3915 (defun gnus-article-button-prev-page (arg)
3916 "Go to the prev page."
3918 (let ((win (selected-window)))
3919 (select-window (get-buffer-window gnus-article-buffer t))
3920 (gnus-article-prev-page)
3921 (select-window win)))
3923 (defvar gnus-decode-header-methods
3924 '(mail-decode-encoded-word-region)
3925 "List of methods used to decode headers.
3927 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
3928 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
3929 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
3930 whose names match REGEXP.
3933 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
3934 mail-decode-encoded-word-region
3935 (\"chinese\" . rfc1843-decode-region))
3938 (defvar gnus-decode-header-methods-cache nil)
3940 (defun gnus-multi-decode-header (start end)
3941 "Apply the functions from `gnus-encoded-word-methods' that match."
3942 (unless (and gnus-decode-header-methods-cache
3943 (eq gnus-newsgroup-name
3944 (car gnus-decode-header-methods-cache)))
3945 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
3948 (nconc gnus-decode-header-methods-cache (list x))
3949 (if (and gnus-newsgroup-name
3950 (string-match (car x) gnus-newsgroup-name))
3951 (nconc gnus-decode-header-methods-cache
3953 gnus-decode-header-methods))
3954 (let ((xlist gnus-decode-header-methods-cache))
3957 (narrow-to-region start end)
3959 (funcall (pop xlist) (point-min) (point-max))))))
3965 (run-hooks 'gnus-art-load-hook)
3967 ;;; gnus-art.el ends here