1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
43 (defgroup gnus-article nil
45 :link '(custom-manual "(gnus)The Article Buffer")
48 (defgroup gnus-article-hiding nil
49 "Hiding article parts."
50 :link '(custom-manual "(gnus)Article Hiding")
53 (defgroup gnus-article-highlight nil
54 "Article highlighting."
55 :link '(custom-manual "(gnus)Article Highlighting")
59 (defgroup gnus-article-signature nil
61 :link '(custom-manual "(gnus)Article Signature")
64 (defgroup gnus-article-headers nil
66 :link '(custom-manual "(gnus)Hiding Headers")
69 (defgroup gnus-article-washing nil
70 "Special commands on articles."
71 :link '(custom-manual "(gnus)Article Washing")
74 (defgroup gnus-article-emphasis nil
75 "Fontisizing articles."
76 :link '(custom-manual "(gnus)Article Fontisizing")
79 (defgroup gnus-article-saving nil
81 :link '(custom-manual "(gnus)Saving Articles")
84 (defgroup gnus-article-mime nil
85 "Worshiping the MIME wonder."
86 :link '(custom-manual "(gnus)Using MIME")
89 (defgroup gnus-article-buttons nil
90 "Pushable buttons in the article buffer."
91 :link '(custom-manual "(gnus)Article Buttons")
94 (defgroup gnus-article-various nil
95 "Other article options."
96 :link '(custom-manual "(gnus)Misc Article")
99 (defcustom gnus-ignored-headers
100 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
101 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
102 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
103 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
104 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
105 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
106 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
107 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
108 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
109 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
110 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
111 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
112 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
113 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
114 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
115 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
116 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
117 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
119 "*All headers that start with this regexp will be hidden.
120 This variable can also be a list of regexps of headers to be ignored.
121 If `gnus-visible-headers' is non-nil, this variable will be ignored."
122 :type '(choice :custom-show nil
125 :group 'gnus-article-hiding)
127 (defcustom gnus-visible-headers
128 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
129 "*All headers that do not match this regexp will be hidden.
130 This variable can also be a list of regexp of headers to remain visible.
131 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
132 :type '(repeat :value-to-internal (lambda (widget value)
133 (custom-split-regexp-maybe value))
134 :match (lambda (widget value)
136 (widget-editable-list-match widget value)))
138 :group 'gnus-article-hiding)
140 (defcustom gnus-sorted-header-list
141 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
142 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
143 "*This variable is a list of regular expressions.
144 If it is non-nil, headers that match the regular expressions will
145 be placed first in the article buffer in the sequence specified by
147 :type '(repeat regexp)
148 :group 'gnus-article-hiding)
150 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
151 "Headers that are only to be displayed if they have interesting data.
152 Possible values in this list are `empty', `newsgroups', `followup-to',
153 `reply-to', `date', `long-to', and `many-to'."
154 :type '(set (const :tag "Headers with no content." empty)
155 (const :tag "Newsgroups with only one group." newsgroups)
156 (const :tag "Followup-to identical to newsgroups." followup-to)
157 (const :tag "Reply-to identical to from." reply-to)
158 (const :tag "Date less than four days old." date)
159 (const :tag "Very long To header." long-to)
160 (const :tag "Multiple To headers." many-to))
161 :group 'gnus-article-hiding)
163 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
164 "Regexp matching signature separator.
165 This can also be a list of regexps. In that case, it will be checked
166 from head to tail looking for a separator. Searches will be done from
167 the end of the buffer."
168 :type '(repeat string)
169 :group 'gnus-article-signature)
171 (defcustom gnus-signature-limit nil
172 "Provide a limit to what is considered a signature.
173 If it is a number, no signature may not be longer (in characters) than
174 that number. If it is a floating point number, no signature may be
175 longer (in lines) than that number. If it is a function, the function
176 will be called without any parameters, and if it returns nil, there is
177 no signature in the buffer. If it is a string, it will be used as a
178 regexp. If it matches, the text in question is not a signature."
179 :type '(choice (integer :value 200)
181 (function :value fun)
182 (regexp :value ".*"))
183 :group 'gnus-article-signature)
185 (defcustom gnus-hidden-properties '(invisible t intangible t)
186 "Property list to use for hiding text."
188 :group 'gnus-article-hiding)
190 (defcustom gnus-article-x-face-command
191 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
192 "*String or function to be executed to display an X-Face header.
193 If it is a string, the command will be executed in a sub-shell
194 asynchronously. The compressed face will be piped to this command."
195 :type 'string ;Leave function case to Lisp.
196 :group 'gnus-article-washing)
198 (defcustom gnus-article-x-face-too-ugly nil
199 "Regexp matching posters whose face shouldn't be shown automatically."
200 :type '(choice regexp (const nil))
201 :group 'gnus-article-washing)
203 (defcustom gnus-emphasis-alist
205 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
207 '(("_" "_" underline)
210 ("_/" "/_" underline-italic)
211 ("_\\*" "\\*_" underline-bold)
212 ("\\*/" "/\\*" bold-italic)
213 ("_\\*/" "/\\*_" underline-bold-italic))))
214 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
215 2 3 gnus-emphasis-underline)
219 (format format (car spec) (cadr spec))
220 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
222 "*Alist that says how to fontify certain phrases.
223 Each item looks like this:
225 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
227 The first element is a regular expression to be matched. The second
228 is a number that says what regular expression grouping used to find
229 the entire emphasized word. The third is a number that says what
230 regexp grouping should be displayed and highlighted. The fourth
231 is the face used for highlighting."
232 :type '(repeat (list :value ("" 0 0 default)
234 (integer :tag "Match group")
235 (integer :tag "Emphasize group")
237 :group 'gnus-article-emphasis)
239 (defface gnus-emphasis-bold '((t (:bold t)))
240 "Face used for displaying strong emphasized text (*word*)."
241 :group 'gnus-article-emphasis)
243 (defface gnus-emphasis-italic '((t (:italic t)))
244 "Face used for displaying italic emphasized text (/word/)."
245 :group 'gnus-article-emphasis)
247 (defface gnus-emphasis-underline '((t (:underline t)))
248 "Face used for displaying underlined emphasized text (_word_)."
249 :group 'gnus-article-emphasis)
251 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
252 "Face used for displaying underlined bold emphasized text (_*word*_)."
253 :group 'gnus-article-emphasis)
255 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
256 "Face used for displaying underlined italic emphasized text (_*word*_)."
257 :group 'gnus-article-emphasis)
259 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
260 "Face used for displaying bold italic emphasized text (/*word*/)."
261 :group 'gnus-article-emphasis)
263 (defface gnus-emphasis-underline-bold-italic
264 '((t (:bold t :italic t :underline t)))
265 "Face used for displaying underlined bold italic emphasized text.
266 Esample: (_/*word*/_)."
267 :group 'gnus-article-emphasis)
269 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
270 "Format for display of Date headers in article bodies.
271 See `format-time-string' for the possible values.
273 The variable can also be function, which should return a complete Date
274 header. The function is called with one argument, the time, which can
275 be fed to `format-time-string'."
276 :type '(choice string symbol)
277 :link '(custom-manual "(gnus)Article Date")
278 :group 'gnus-article-washing)
281 (autoload 'mail-extract-address-components "mail-extr"))
283 (defcustom gnus-save-all-headers t
284 "*If non-nil, don't remove any headers before saving."
285 :group 'gnus-article-saving
288 (defcustom gnus-prompt-before-saving 'always
289 "*This variable says how much prompting is to be done when saving articles.
290 If it is nil, no prompting will be done, and the articles will be
291 saved to the default files. If this variable is `always', each and
292 every article that is saved will be preceded by a prompt, even when
293 saving large batches of articles. If this variable is neither nil not
294 `always', there the user will be prompted once for a file name for
295 each invocation of the saving commands."
296 :group 'gnus-article-saving
297 :type '(choice (item always)
298 (item :tag "never" nil)
299 (sexp :tag "once" :format "%t\n" :value t)))
301 (defcustom gnus-saved-headers gnus-visible-headers
302 "Headers to keep if `gnus-save-all-headers' is nil.
303 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
304 If that variable is nil, however, all headers that match this regexp
305 will be kept while the rest will be deleted before saving."
306 :group 'gnus-article-saving
309 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
310 "A function to save articles in your favourite format.
311 The function must be interactively callable (in other words, it must
312 be an Emacs command).
314 Gnus provides the following functions:
316 * gnus-summary-save-in-rmail (Rmail format)
317 * gnus-summary-save-in-mail (Unix mail format)
318 * gnus-summary-save-in-folder (MH folder)
319 * gnus-summary-save-in-file (article format)
320 * gnus-summary-save-in-vm (use VM's folder format)
321 * gnus-summary-write-to-file (article format -- overwrite)."
322 :group 'gnus-article-saving
323 :type '(radio (function-item gnus-summary-save-in-rmail)
324 (function-item gnus-summary-save-in-mail)
325 (function-item gnus-summary-save-in-folder)
326 (function-item gnus-summary-save-in-file)
327 (function-item gnus-summary-save-in-vm)
328 (function-item gnus-summary-write-to-file)))
330 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
331 "A function generating a file name to save articles in Rmail format.
332 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
333 :group 'gnus-article-saving
336 (defcustom gnus-mail-save-name 'gnus-plain-save-name
337 "A function generating a file name to save articles in Unix mail format.
338 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
339 :group 'gnus-article-saving
342 (defcustom gnus-folder-save-name 'gnus-folder-save-name
343 "A function generating a file name to save articles in MH folder.
344 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
345 :group 'gnus-article-saving
348 (defcustom gnus-file-save-name 'gnus-numeric-save-name
349 "A function generating a file name to save articles in article format.
350 The function is called with NEWSGROUP, HEADERS, and optional
352 :group 'gnus-article-saving
355 (defcustom gnus-split-methods
356 '((gnus-article-archive-name)
357 (gnus-article-nndoc-name))
358 "*Variable used to suggest where articles are to be saved.
359 For instance, if you would like to save articles related to Gnus in
360 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
361 you could set this variable to something like:
363 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
364 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
366 This variable is an alist where the where the key is the match and the
367 value is a list of possible files to save in if the match is non-nil.
369 If the match is a string, it is used as a regexp match on the
370 article. If the match is a symbol, that symbol will be funcalled
371 from the buffer of the article to be saved with the newsgroup as the
372 parameter. If it is a list, it will be evaled in the same buffer.
374 If this form or function returns a string, this string will be used as
375 a possible file name; and if it returns a non-nil list, that list will
376 be used as possible file names."
377 :group 'gnus-article-saving
378 :type '(repeat (choice (list :value (fun) function)
379 (cons :value ("" "") regexp (repeat string))
382 (defcustom gnus-page-delimiter "^\^L"
383 "*Regexp describing what to use as article page delimiters.
384 The default value is \"^\^L\", which is a form linefeed at the
385 beginning of a line."
387 :group 'gnus-article-various)
389 (defcustom gnus-article-mode-line-format "Gnus: %g %S%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
574 "Table for MS-to-Latin1 translation.")
576 (defcustom gnus-ignored-mime-types nil
577 "List of MIME types that should be ignored by Gnus."
578 :group 'gnus-article-mime
579 :type '(repeat regexp))
581 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
582 "List of MIME types that should not be given buttons when rendered."
583 :group 'gnus-article-mime
584 :type '(repeat regexp))
586 (defcustom gnus-treat-body-highlight-signature t
587 "Highlight the signature."
589 :type '(choice (const :tag "Off" nil)
591 (const :tag "Last" last)
592 (integer :tag "Less")
593 (sexp :tag "Predicate")))
595 (defcustom gnus-article-mime-part-function nil
596 "Function called with a MIME handle as the argument."
597 :group 'gnus-article-mime
600 ;;; Internal variables
602 (defvar gnus-article-mime-handle-alist-1 nil)
603 (defvar gnus-treatment-function-alist
604 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
607 (defvar gnus-article-mime-handle-alist nil)
608 (defvar article-lapsed-timer nil)
609 (defvar gnus-article-current-summary nil)
611 (defvar gnus-article-mode-syntax-table
612 (let ((table (copy-syntax-table text-mode-syntax-table)))
613 (modify-syntax-entry ?- "w" table)
614 (modify-syntax-entry ?> ")" table)
615 (modify-syntax-entry ?< "(" table)
617 "Syntax table used in article mode buffers.
618 Initialized from `text-mode-syntax-table.")
620 (defvar gnus-save-article-buffer nil)
622 (defvar gnus-article-mode-line-format-alist
623 (nconc '((?w (gnus-article-wash-status) ?s)
624 (?m (gnus-article-mime-part-status) ?s))
625 gnus-summary-mode-line-format-alist))
627 (defvar gnus-number-of-articles-to-be-saved nil)
629 (defvar gnus-inhibit-hiding nil)
631 (defsubst gnus-article-hide-text (b e props)
632 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
633 (add-text-properties b e props)
634 (when (memq 'intangible props)
636 (max (1- b) (point-min))
637 b 'intangible (cddr (memq 'intangible props)))))
639 (defmacro gnus-with-article (article &rest forms)
640 "Select ARTICLE and perform FORMS in the original article buffer.
641 Then replace the article with the result."
643 ;; We don't want the article to be marked as read.
644 (let (gnus-mark-article-hook)
645 (gnus-summary-select-article t t nil ,article))
646 (set-buffer gnus-original-article-buffer)
648 (if (not (gnus-check-backend-function
649 'request-replace-article (car gnus-article-current)))
650 (gnus-message 5 "Read-only group; not replacing")
651 (unless (gnus-request-replace-article
652 ,article (car gnus-article-current)
654 (error "Couldn't replace article")))
655 ;; The cache and backlog have to be flushed somewhat.
656 (when gnus-keep-backlog
657 (gnus-backlog-remove-article
658 (car gnus-article-current) (cdr gnus-article-current)))
660 (gnus-cache-update-article
661 (car gnus-article-current) (cdr gnus-article-current)))))
663 (put 'gnus-with-article 'lisp-indent-function 1)
664 (put 'gnus-with-article 'edebug-form-spec '(form body))
666 (defsubst gnus-article-unhide-text (b e)
667 "Remove hidden text properties from region between B and E."
668 (remove-text-properties b e gnus-hidden-properties)
669 (when (memq 'intangible gnus-hidden-properties)
670 (put-text-property (max (1- b) (point-min))
673 (defun gnus-article-hide-text-type (b e type)
674 "Hide text of TYPE between B and E."
675 (gnus-article-hide-text
676 b e (cons 'article-type (cons type gnus-hidden-properties))))
678 (defun gnus-article-unhide-text-type (b e type)
679 "Unhide text of TYPE between B and E."
680 (remove-text-properties
681 b e (cons 'article-type (cons type gnus-hidden-properties)))
682 (when (memq 'intangible gnus-hidden-properties)
683 (put-text-property (max (1- b) (point-min))
686 (defun gnus-article-hide-text-of-type (type)
687 "Hide text of TYPE in the current buffer."
689 (let ((b (point-min))
691 (while (setq b (text-property-any b e 'article-type type))
692 (add-text-properties b (incf b) gnus-hidden-properties)))))
694 (defun gnus-article-delete-text-of-type (type)
695 "Delete text of TYPE in the current buffer."
697 (let ((b (point-min)))
698 (while (setq b (text-property-any b (point-max) 'article-type type))
700 b (or (text-property-not-all b (point-max) 'article-type type)
703 (defun gnus-article-delete-invisible-text ()
704 "Delete all invisible text in the current buffer."
706 (let ((b (point-min)))
707 (while (setq b (text-property-any b (point-max) 'invisible t))
709 b (or (text-property-not-all b (point-max) 'invisible t)
712 (defun gnus-article-text-type-exists-p (type)
713 "Say whether any text of type TYPE exists in the buffer."
714 (text-property-any (point-min) (point-max) 'article-type type))
716 (defsubst gnus-article-header-rank ()
717 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
718 (let ((list gnus-sorted-header-list)
721 (when (looking-at (car list))
723 (setq list (cdr list))
727 (defun article-hide-headers (&optional arg delete)
728 "Toggle whether to hide unwanted headers and possibly sort them as well.
729 If given a negative prefix, always show; if given a positive prefix,
731 (interactive (gnus-article-hidden-arg))
733 (if (gnus-article-check-hidden-text 'headers arg)
734 ;; Show boring headers as well.
735 (gnus-article-show-hidden-text 'boring-headers)
736 ;; This function might be inhibited.
737 (unless gnus-inhibit-hiding
740 (let ((buffer-read-only nil)
742 (props (nconc (list 'article-type 'headers)
743 gnus-hidden-properties))
744 (max (1+ (length gnus-sorted-header-list)))
745 (ignored (when (not gnus-visible-headers)
746 (cond ((stringp gnus-ignored-headers)
747 gnus-ignored-headers)
748 ((listp gnus-ignored-headers)
749 (mapconcat 'identity gnus-ignored-headers
752 (cond ((stringp gnus-visible-headers)
753 gnus-visible-headers)
754 ((and gnus-visible-headers
755 (listp gnus-visible-headers))
756 (mapconcat 'identity gnus-visible-headers "\\|"))))
757 (inhibit-point-motion-hooks t)
759 ;; First we narrow to just the headers.
761 (goto-char (point-min))
762 ;; Hide any "From " lines at the beginning of (mail) articles.
763 (while (looking-at "From ")
767 (delete-region (point-min) (point))
768 (gnus-article-hide-text (point-min) (point) props)))
769 ;; Then treat the rest of the header lines.
772 (if (search-forward "\n\n" nil t) ; if there's a body
773 (progn (forward-line -1) (point))
775 ;; Then we use the two regular expressions
776 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
777 ;; select which header lines is to remain visible in the
779 (goto-char (point-min))
780 (while (re-search-forward "^[^ \t]*:" nil t)
782 ;; Mark the rank of the header.
784 (point) (1+ (point)) 'message-rank
785 (if (or (and visible (looking-at visible))
787 (not (looking-at ignored))))
788 (gnus-article-header-rank)
791 (message-sort-headers-1)
792 (when (setq beg (text-property-any
793 (point-min) (point-max) 'message-rank (+ 2 max)))
794 ;; We make the unwanted headers invisible.
796 (delete-region beg (point-max))
797 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
798 (gnus-article-hide-text-type beg (point-max) 'headers))
799 ;; Work around XEmacs lossage.
800 (put-text-property (point-min) beg 'invisible nil))))))))
802 (defun article-hide-boring-headers (&optional arg)
803 "Toggle hiding of headers that aren't very interesting.
804 If given a negative prefix, always show; if given a positive prefix,
806 (interactive (gnus-article-hidden-arg))
807 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
808 (not gnus-show-all-headers))
811 (let ((buffer-read-only nil)
812 (list gnus-boring-article-headers)
813 (inhibit-point-motion-hooks t)
815 (nnheader-narrow-to-headers)
817 (setq elem (pop list))
818 (goto-char (point-min))
820 ;; Hide empty headers.
822 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
824 (gnus-article-hide-text-type
825 (progn (beginning-of-line) (point))
828 (if (re-search-forward "^[^ \t]" nil t)
832 ;; Hide boring Newsgroups header.
833 ((eq elem 'newsgroups)
834 (when (equal (gnus-fetch-field "newsgroups")
835 (gnus-group-real-name
836 (if (boundp 'gnus-newsgroup-name)
839 (gnus-article-hide-header "newsgroups")))
840 ((eq elem 'followup-to)
841 (when (equal (message-fetch-field "followup-to")
842 (message-fetch-field "newsgroups"))
843 (gnus-article-hide-header "followup-to")))
845 (let ((from (message-fetch-field "from"))
846 (reply-to (message-fetch-field "reply-to")))
851 (nth 1 (mail-extract-address-components from))
852 (nth 1 (mail-extract-address-components reply-to)))))
853 (gnus-article-hide-header "reply-to"))))
855 (let ((date (message-fetch-field "date")))
857 (< (days-between (current-time-string) date)
859 (gnus-article-hide-header "date"))))
861 (let ((to (message-fetch-field "to")))
862 (when (> (length to) 1024)
863 (gnus-article-hide-header "to"))))
866 (goto-char (point-min))
867 (while (re-search-forward "^to:" nil t)
868 (setq to-count (1+ to-count)))
870 (while (> to-count 0)
871 (goto-char (point-min))
873 (re-search-forward "^to:" nil nil to-count)
875 (narrow-to-region (point) (point-max))
876 (gnus-article-hide-header "to"))
877 (setq to-count (1- to-count)))))))))))))
879 (defun gnus-article-hide-header (header)
881 (goto-char (point-min))
882 (when (re-search-forward (concat "^" header ":") nil t)
883 (gnus-article-hide-text-type
884 (progn (beginning-of-line) (point))
887 (if (re-search-forward "^[^ \t]" nil t)
892 (defvar gnus-article-normalized-header-length 40
893 "Length of normalized headers.")
895 (defun article-normalize-headers ()
896 "Make all header lines 40 characters long."
898 (let ((buffer-read-only nil)
902 (message-narrow-to-head)
905 ((< (setq column (- (gnus-point-at-eol) (point)))
906 gnus-article-normalized-header-length)
909 (- gnus-article-normalized-header-length column)
911 ((> column gnus-article-normalized-header-length)
912 (gnus-put-text-property
914 (forward-char gnus-article-normalized-header-length)
921 (forward-line 1))))))
923 (defun article-treat-dumbquotes ()
924 "Translate M******** sm*rtq**t*s into proper text.
925 Note that this function guesses whether a character is a sm*rtq**t* or
926 not, so it should only be used interactively."
928 (article-translate-strings gnus-article-dumbquotes-map))
930 (defun article-translate-characters (from to)
931 "Translate all characters in the body of the article according to FROM and TO.
932 FROM is a string of characters to translate from; to is a string of
933 characters to translate to."
935 (when (article-goto-body)
936 (let ((buffer-read-only nil)
937 (x (make-string 225 ?x))
939 (while (< (incf i) (length x))
942 (while (< i (length from))
943 (aset x (aref from i) (aref to i))
945 (translate-region (point) (point-max) x)))))
947 (defun article-translate-strings (map)
948 "Translate all string in the body of the article according to MAP.
949 MAP is an alist where the elements are on the form (\"from\" \"to\")."
951 (when (article-goto-body)
952 (let ((buffer-read-only nil)
954 (while (setq elem (pop map))
956 (while (search-forward (car elem) nil t)
957 (replace-match (cadr elem)))))))))
959 (defun article-treat-overstrike ()
960 "Translate overstrikes into bold text."
963 (when (article-goto-body)
964 (let ((buffer-read-only nil))
965 (while (search-forward "\b" nil t)
966 (let ((next (char-after))
967 (previous (char-after (- (point) 2))))
968 ;; We do the boldification/underlining by hiding the
969 ;; overstrikes and putting the proper text property
973 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
974 (put-text-property (point) (1+ (point)) 'face 'bold))
976 (gnus-article-hide-text-type
977 (1- (point)) (1+ (point)) 'overstrike)
979 (- (point) 2) (1- (point)) 'face 'underline))
981 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
983 (point) (1+ (point)) 'face 'underline)))))))))
985 (defun article-fill ()
986 "Format too long lines."
989 (let ((buffer-read-only nil))
993 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
994 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
995 (adaptive-fill-mode t))
997 (and (>= (current-column) (min fill-column (window-width)))
998 (/= (preceding-char) ?:)
999 (fill-paragraph nil))
1000 (end-of-line 2))))))
1002 (defun article-remove-cr ()
1003 "Translate CRLF pairs into LF, and then CR into LF.."
1006 (let ((buffer-read-only nil))
1007 (goto-char (point-min))
1008 (while (search-forward "\r$" nil t)
1009 (replace-match "" t t))
1010 (goto-char (point-min))
1011 (while (search-forward "\r" nil t)
1012 (replace-match "\n" t t)))))
1014 (defun article-remove-trailing-blank-lines ()
1015 "Remove all trailing blank lines from the article."
1018 (let ((buffer-read-only nil))
1019 (goto-char (point-max))
1023 (while (and (not (bobp))
1024 (looking-at "^[ \t]*$")
1025 (not (gnus-annotation-in-region-p
1026 (point) (gnus-point-at-eol))))
1031 (defun article-display-x-face (&optional force)
1032 "Look for an X-Face header and display it if present."
1033 (interactive (list 'force))
1035 ;; Delete the old process, if any.
1036 (when (process-status "article-x-face")
1037 (delete-process "article-x-face"))
1038 (let ((inhibit-point-motion-hooks t)
1039 (case-fold-search t)
1042 (nnheader-narrow-to-headers)
1043 (setq from (message-fetch-field "from"))
1044 (goto-char (point-min))
1045 (while (and gnus-article-x-face-command
1048 ;; Check whether this face is censored.
1049 (not gnus-article-x-face-too-ugly)
1050 (and gnus-article-x-face-too-ugly from
1051 (not (string-match gnus-article-x-face-too-ugly
1053 ;; Has to be present.
1054 (re-search-forward "^X-Face: " nil t))
1055 ;; This used to try to do multiple faces (`while' instead of
1056 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1057 ;; work (b) it can crash some versions of Emacs (c) are
1058 ;; multiple faces really something to encourage?
1059 (when (stringp gnus-article-x-face-command)
1061 ;; We now have the area of the buffer where the X-Face is stored.
1064 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1065 ;; We display the face.
1066 (if (symbolp gnus-article-x-face-command)
1067 ;; The command is a lisp function, so we call it.
1068 (if (gnus-functionp gnus-article-x-face-command)
1069 (funcall gnus-article-x-face-command beg end)
1070 (error "%s is not a function" gnus-article-x-face-command))
1071 ;; The command is a string, so we interpret the command
1072 ;; as a, well, command, and fork it off.
1073 (let ((process-connection-type nil))
1074 (process-kill-without-query
1076 "article-x-face" nil shell-file-name shell-command-switch
1077 gnus-article-x-face-command))
1078 (process-send-region "article-x-face" beg end)
1079 (process-send-eof "article-x-face"))))))))))
1081 (defun article-decode-mime-words ()
1082 "Decode all MIME-encoded words in the article."
1085 (set-buffer gnus-article-buffer)
1086 (let ((inhibit-point-motion-hooks t)
1088 (rfc2047-default-charset gnus-newsgroup-default-charset)
1089 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1090 (mail-decode-encoded-word-region (point-min) (point-max)))))
1092 (defun article-decode-charset (&optional prompt)
1093 "Decode charset-encoded text in the article.
1094 If PROMPT (the prefix), prompt for a coding system to use."
1098 (message-narrow-to-head)
1099 (let* ((inhibit-point-motion-hooks t)
1100 (case-fold-search t)
1101 (ct (message-fetch-field "Content-Type" t))
1102 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1103 (ctl (and ct (condition-case ()
1104 (mail-header-parse-content-type ct)
1108 (mm-read-coding-system "Charset to decode: "))
1110 (mail-content-type-get ctl 'charset))))
1111 (rfc2047-default-charset gnus-newsgroup-default-charset)
1112 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1114 (goto-char (point-max))
1117 (narrow-to-region (point) (point-max))
1118 (when (and (or (not ctl)
1119 (equal (car ctl) "text/plain"))
1122 charset (and cte (intern (downcase
1123 (gnus-strip-whitespace cte))))
1126 (defun article-decode-encoded-words ()
1127 "Remove encoded-word encoding from headers."
1128 (let ((inhibit-point-motion-hooks t)
1129 (rfc2047-default-charset gnus-newsgroup-default-charset)
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 gnus-current-headers)
1455 (message-fetch-field "date")
1457 (date (if (vectorp header) (mail-header-date header)
1459 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1460 (inhibit-point-motion-hooks t)
1461 bface eface newline)
1462 (when (and date (not (string= date "")))
1465 (nnheader-narrow-to-headers)
1466 (let ((buffer-read-only nil))
1467 ;; Delete any old Date headers.
1468 (if (re-search-forward date-regexp nil t)
1470 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1471 eface (get-text-property (1- (gnus-point-at-eol))
1473 (delete-region (progn (beginning-of-line) (point))
1474 (progn (end-of-line) (point)))
1475 (beginning-of-line))
1476 (goto-char (point-max))
1478 (insert (article-make-date-line date type))
1481 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1482 (put-text-property (match-beginning 1) (1+ (match-end 1))
1484 (put-text-property (match-beginning 2) (match-end 2)
1488 (insert "\n"))))))))
1490 (defun article-make-date-line (date type)
1491 "Return a DATE line of TYPE."
1492 (let ((time (condition-case ()
1496 ;; Convert to the local timezone. We have to slap a
1497 ;; `condition-case' round the calls to the timezone
1498 ;; functions since they aren't particularly resistant to
1501 (let ((tz (car (current-time-zone))))
1502 (format "Date: %s %s%04d" (current-time-string time)
1503 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1504 ;; Convert to Universal Time.
1507 (current-time-string
1508 (let* ((e (parse-time-string date))
1509 (tm (apply 'encode-time e))
1511 (ls (- (cadr tm) (car (current-time-zone)))))
1512 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1513 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1516 ;; Get the original date from the article.
1517 ((eq type 'original)
1518 (concat "Date: " (if (string-match "\n+$" date)
1519 (substring date 0 (match-beginning 0))
1521 ;; Let the user define the format.
1523 (if (gnus-functionp gnus-article-time-format)
1524 (funcall gnus-article-time-format time)
1527 (format-time-string gnus-article-time-format time))))
1532 (format-time-string "%Y%M%DT%h%m%s" time)))
1533 ;; Do an X-Sent lapsed format.
1535 ;; If the date is seriously mangled, the timezone functions are
1536 ;; liable to bug out, so we ignore all errors.
1537 (let* ((now (current-time))
1538 (real-time (subtract-time now time))
1539 (real-sec (and real-time
1540 (+ (* (float (car real-time)) 65536)
1542 (sec (and real-time (abs real-sec)))
1552 ;; This is a bit convoluted, but basically we go
1553 ;; through the time units for years, weeks, etc,
1554 ;; and divide things to see whether that results
1555 ;; in positive answers.
1558 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1559 ;; The (remaining) seconds are too few to
1560 ;; be divided into this time unit.
1562 ;; It's big enough, so we output it.
1563 (setq sec (- sec (* num (cdr unit))))
1565 (concat (if prev ", " "") (int-to-string
1567 " " (symbol-name (car unit))
1568 (if (> num 1) "s" ""))
1570 article-time-units "")
1571 ;; If dates are odd, then it might appear like the
1572 ;; article was sent in the future.
1575 " in the future"))))))
1577 (error "Unknown conversion type: %s" type)))))
1579 (defun article-date-local (&optional highlight)
1580 "Convert the current article date to the local timezone."
1581 (interactive (list t))
1582 (article-date-ut 'local highlight))
1584 (defun article-date-original (&optional highlight)
1585 "Convert the current article date to what it was originally.
1586 This is only useful if you have used some other date conversion
1587 function and want to see what the date was before converting."
1588 (interactive (list t))
1589 (article-date-ut 'original highlight))
1591 (defun article-date-lapsed (&optional highlight)
1592 "Convert the current article date to time lapsed since it was sent."
1593 (interactive (list t))
1594 (article-date-ut 'lapsed highlight))
1596 (defun article-update-date-lapsed ()
1597 "Function to be run from a timer to update the lapsed time line."
1598 (let (deactivate-mark)
1603 (set-buffer (window-buffer w))
1604 (when (eq major-mode 'gnus-article-mode)
1605 (goto-char (point-min))
1606 (when (re-search-forward "^X-Sent:" nil t)
1607 (article-date-lapsed t)))))))))
1609 (defun gnus-start-date-timer (&optional n)
1610 "Start a timer to update the X-Sent header in the article buffers.
1611 The numerical prefix says how frequently (in seconds) the function
1616 (gnus-stop-date-timer)
1617 (setq article-lapsed-timer
1618 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1620 (defun gnus-stop-date-timer ()
1621 "Stop the X-Sent timer."
1623 (when article-lapsed-timer
1624 (nnheader-cancel-timer article-lapsed-timer)
1625 (setq article-lapsed-timer nil)))
1627 (defun article-date-user (&optional highlight)
1628 "Convert the current article date to the user-defined format.
1629 This format is defined by the `gnus-article-time-format' variable."
1630 (interactive (list t))
1631 (article-date-ut 'user highlight))
1633 (defun article-date-iso8601 (&optional highlight)
1634 "Convert the current article date to ISO8601."
1635 (interactive (list t))
1636 (article-date-ut 'iso8601 highlight))
1638 (defun article-show-all ()
1639 "Show all hidden text in the article buffer."
1642 (let ((buffer-read-only nil))
1643 (gnus-article-unhide-text (point-min) (point-max)))))
1645 (defun article-emphasize (&optional arg)
1646 "Emphasize text according to `gnus-emphasis-alist'."
1647 (interactive (gnus-article-hidden-arg))
1648 (unless (gnus-article-check-hidden-text 'emphasis arg)
1650 (let ((alist gnus-emphasis-alist)
1651 (buffer-read-only nil)
1652 (props (append '(article-type emphasis)
1653 gnus-hidden-properties))
1654 regexp elem beg invisible visible face)
1657 (while (setq elem (pop alist))
1659 (setq regexp (car elem)
1660 invisible (nth 1 elem)
1661 visible (nth 2 elem)
1663 (while (re-search-forward regexp nil t)
1664 (when (and (match-beginning visible) (match-beginning invisible))
1665 (gnus-article-hide-text
1666 (match-beginning invisible) (match-end invisible) props)
1667 (gnus-article-unhide-text-type
1668 (match-beginning visible) (match-end visible) 'emphasis)
1669 (gnus-put-text-property-excluding-newlines
1670 (match-beginning visible) (match-end visible) 'face face)
1671 (goto-char (match-end invisible)))))))))
1673 (defvar gnus-summary-article-menu)
1674 (defvar gnus-summary-post-menu)
1676 ;;; Saving functions.
1678 (defun gnus-article-save (save-buffer file &optional num)
1679 "Save the currently selected article."
1680 (unless gnus-save-all-headers
1681 ;; Remove headers according to `gnus-saved-headers'.
1682 (let ((gnus-visible-headers
1683 (or gnus-saved-headers gnus-visible-headers))
1684 (gnus-article-buffer save-buffer))
1686 (set-buffer save-buffer)
1687 (article-hide-headers 1 t))))
1688 (save-window-excursion
1689 (if (not gnus-default-article-saver)
1690 (error "No default saver is defined")
1691 ;; !!! Magic! The saving functions all save
1692 ;; `gnus-save-article-buffer' (or so they think), but we
1693 ;; bind that variable to our save-buffer.
1694 (set-buffer gnus-article-buffer)
1695 (let* ((gnus-save-article-buffer save-buffer)
1698 ((not gnus-prompt-before-saving) 'default)
1699 ((eq gnus-prompt-before-saving 'always) nil)
1701 (gnus-number-of-articles-to-be-saved
1702 (when (eq gnus-prompt-before-saving t)
1704 (set-buffer gnus-article-current-summary)
1705 (funcall gnus-default-article-saver filename)))))
1707 (defun gnus-read-save-file-name (prompt &optional filename
1708 function group headers variable)
1710 (funcall function group headers (symbol-value variable)))
1715 ((eq filename 'default)
1721 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1724 (if (and gnus-number-of-articles-to-be-saved
1725 (> gnus-number-of-articles-to-be-saved 1))
1726 (format "these %d articles"
1727 gnus-number-of-articles-to-be-saved)
1730 ;; Let the split methods have their say.
1732 ;; No split name was found.
1735 (concat prompt " (default "
1736 (file-name-nondirectory default-name) ") ")
1737 (file-name-directory default-name)
1739 ;; A single group name is returned.
1740 ((stringp split-name)
1742 (funcall function split-name headers
1743 (symbol-value variable)))
1745 (concat prompt " (default "
1746 (file-name-nondirectory default-name) ") ")
1747 (file-name-directory default-name)
1749 ;; A single split name was found
1750 ((= 1 (length split-name))
1751 (let* ((name (expand-file-name
1752 (car split-name) gnus-article-save-directory))
1753 (dir (cond ((file-directory-p name)
1754 (file-name-as-directory name))
1755 ((file-exists-p name) name)
1756 (t gnus-article-save-directory))))
1758 (concat prompt " (default " name ") ")
1760 ;; A list of splits was found.
1762 (setq split-name (nreverse split-name))
1764 (let ((file-name-history
1765 (nconc split-name file-name-history)))
1769 (concat prompt " (`M-p' for defaults) ")
1770 gnus-article-save-directory
1772 gnus-article-save-directory)))
1773 (car (push result file-name-history)))))))
1774 ;; Create the directory.
1775 (gnus-make-directory (file-name-directory file))
1776 ;; If we have read a directory, we append the default file name.
1777 (when (file-directory-p file)
1778 (setq file (concat (file-name-as-directory file)
1779 (file-name-nondirectory default-name))))
1780 ;; Possibly translate some characters.
1781 (nnheader-translate-file-chars file)))))
1782 (gnus-make-directory (file-name-directory result))
1783 (set variable result)))
1785 (defun gnus-article-archive-name (group)
1786 "Return the first instance of an \"Archive-name\" in the current buffer."
1787 (let ((case-fold-search t))
1788 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1789 (nnheader-concat gnus-article-save-directory
1790 (match-string 1)))))
1792 (defun gnus-article-nndoc-name (group)
1793 "If GROUP is an nndoc group, return the name of the parent group."
1794 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1795 (gnus-group-get-parameter group 'save-article-group)))
1797 (defun gnus-summary-save-in-rmail (&optional filename)
1798 "Append this article to Rmail file.
1799 Optional argument FILENAME specifies file name.
1800 Directory to save to is default to `gnus-article-save-directory'."
1801 (setq filename (gnus-read-save-file-name
1802 "Save %s in rmail file:" filename
1803 gnus-rmail-save-name gnus-newsgroup-name
1804 gnus-current-headers 'gnus-newsgroup-last-rmail))
1805 (gnus-eval-in-buffer-window gnus-save-article-buffer
1809 (gnus-output-to-rmail filename))))
1812 (defun gnus-summary-save-in-mail (&optional filename)
1813 "Append this article to Unix mail file.
1814 Optional argument FILENAME specifies file name.
1815 Directory to save to is default to `gnus-article-save-directory'."
1816 (setq filename (gnus-read-save-file-name
1817 "Save %s in Unix mail file:" filename
1818 gnus-mail-save-name gnus-newsgroup-name
1819 gnus-current-headers 'gnus-newsgroup-last-mail))
1820 (gnus-eval-in-buffer-window gnus-save-article-buffer
1824 (if (and (file-readable-p filename)
1825 (mail-file-babyl-p filename))
1826 (rmail-output-to-rmail-file filename t)
1827 (gnus-output-to-mail filename)))))
1830 (defun gnus-summary-save-in-file (&optional filename overwrite)
1831 "Append this article to file.
1832 Optional argument FILENAME specifies file name.
1833 Directory to save to is default to `gnus-article-save-directory'."
1834 (setq filename (gnus-read-save-file-name
1835 "Save %s in file:" filename
1836 gnus-file-save-name gnus-newsgroup-name
1837 gnus-current-headers 'gnus-newsgroup-last-file))
1838 (gnus-eval-in-buffer-window gnus-save-article-buffer
1842 (when (and overwrite
1843 (file-exists-p filename))
1844 (delete-file filename))
1845 (gnus-output-to-file filename))))
1848 (defun gnus-summary-write-to-file (&optional filename)
1849 "Write this article to a file.
1850 Optional argument FILENAME specifies file name.
1851 The directory to save in defaults to `gnus-article-save-directory'."
1852 (gnus-summary-save-in-file nil t))
1854 (defun gnus-summary-save-body-in-file (&optional filename)
1855 "Append this article body to a file.
1856 Optional argument FILENAME specifies file name.
1857 The directory to save in defaults to `gnus-article-save-directory'."
1858 (setq filename (gnus-read-save-file-name
1859 "Save %s body in file:" filename
1860 gnus-file-save-name gnus-newsgroup-name
1861 gnus-current-headers 'gnus-newsgroup-last-file))
1862 (gnus-eval-in-buffer-window gnus-save-article-buffer
1866 (when (article-goto-body)
1867 (narrow-to-region (point) (point-max)))
1868 (gnus-output-to-file filename))))
1871 (defun gnus-summary-save-in-pipe (&optional command)
1872 "Pipe this article to subprocess."
1874 (cond ((and (eq command 'default)
1875 gnus-last-shell-command)
1876 gnus-last-shell-command)
1880 "Shell command on %s: "
1881 (if (and gnus-number-of-articles-to-be-saved
1882 (> gnus-number-of-articles-to-be-saved 1))
1883 (format "these %d articles"
1884 gnus-number-of-articles-to-be-saved)
1886 gnus-last-shell-command))))
1887 (when (string-equal command "")
1888 (setq command gnus-last-shell-command))
1889 (gnus-eval-in-buffer-window gnus-article-buffer
1892 (shell-command-on-region (point-min) (point-max) command nil)))
1893 (setq gnus-last-shell-command command))
1895 ;;; Article file names when saving.
1897 (defun gnus-capitalize-newsgroup (newsgroup)
1898 "Capitalize NEWSGROUP name."
1899 (when (not (zerop (length newsgroup)))
1900 (concat (char-to-string (upcase (aref newsgroup 0)))
1901 (substring newsgroup 1))))
1903 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1904 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1905 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1906 Otherwise, it is like ~/News/news/group/num."
1909 (concat (if (gnus-use-long-file-name 'not-save)
1910 (gnus-capitalize-newsgroup newsgroup)
1911 (gnus-newsgroup-directory-form newsgroup))
1912 "/" (int-to-string (mail-header-number headers)))
1913 gnus-article-save-directory)))
1915 (string-equal (file-name-directory default)
1916 (file-name-directory last-file))
1917 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1919 (or last-file default))))
1921 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1922 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1923 If variable `gnus-use-long-file-name' is non-nil, it is
1924 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1927 (concat (if (gnus-use-long-file-name 'not-save)
1929 (gnus-newsgroup-directory-form newsgroup))
1930 "/" (int-to-string (mail-header-number headers)))
1931 gnus-article-save-directory)))
1933 (string-equal (file-name-directory default)
1934 (file-name-directory last-file))
1935 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1937 (or last-file default))))
1939 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1940 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1941 If variable `gnus-use-long-file-name' is non-nil, it is
1942 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1945 (if (gnus-use-long-file-name 'not-save)
1946 (gnus-capitalize-newsgroup newsgroup)
1947 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1948 gnus-article-save-directory)))
1950 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1951 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1952 If variable `gnus-use-long-file-name' is non-nil, it is
1953 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1956 (if (gnus-use-long-file-name 'not-save)
1958 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1959 gnus-article-save-directory)))
1966 (setq afunc (car func)
1969 gfunc (intern (format "gnus-%s" func))))
1971 (if (not (fboundp afunc))
1973 `(lambda (&optional interactive &rest args)
1974 ,(documentation afunc t)
1975 (interactive (list t))
1977 (set-buffer gnus-article-buffer)
1979 (call-interactively ',afunc)
1980 (apply ',afunc args))))))))
1981 '(article-hide-headers
1982 article-hide-boring-headers
1983 article-treat-overstrike
1984 (article-fill . gnus-article-word-wrap)
1986 article-display-x-face
1987 article-de-quoted-unreadable
1988 article-mime-decode-quoted-printable
1991 article-hide-signature
1992 article-remove-trailing-blank-lines
1993 article-strip-leading-blank-lines
1994 article-strip-multiple-blank-lines
1995 article-strip-leading-space
1996 article-strip-trailing-space
1997 article-strip-blank-lines
1998 article-strip-all-blank-lines
2000 article-date-iso8601
2001 article-date-original
2003 article-decode-mime-words
2004 article-decode-charset
2005 article-decode-encoded-words
2009 article-treat-dumbquotes
2010 article-normalize-headers
2011 (article-show-all . gnus-article-show-all-headers))))
2014 ;;; Gnus article mode
2017 (put 'gnus-article-mode 'mode-class 'special)
2019 (set-keymap-parent gnus-article-mode-map widget-keymap)
2021 (gnus-define-keys gnus-article-mode-map
2022 " " gnus-article-goto-next-page
2023 "\177" gnus-article-goto-prev-page
2024 [delete] gnus-article-goto-prev-page
2025 "\C-c^" gnus-article-refer-article
2026 "h" gnus-article-show-summary
2027 "s" gnus-article-show-summary
2028 "\C-c\C-m" gnus-article-mail
2029 "?" gnus-article-describe-briefly
2030 "e" gnus-article-edit
2031 "<" beginning-of-buffer
2033 "\C-c\C-i" gnus-info-find-node
2036 "\C-d" gnus-article-read-summary-keys
2037 "\M-*" gnus-article-read-summary-keys
2038 "\M-#" gnus-article-read-summary-keys
2039 "\M-^" gnus-article-read-summary-keys
2040 "\M-g" gnus-article-read-summary-keys)
2042 (substitute-key-definition
2043 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2045 (defun gnus-article-make-menu-bar ()
2046 (gnus-turn-off-edit-menu 'article)
2047 (unless (boundp 'gnus-article-article-menu)
2049 gnus-article-article-menu gnus-article-mode-map ""
2051 ["Scroll forwards" gnus-article-goto-next-page t]
2052 ["Scroll backwards" gnus-article-goto-prev-page t]
2053 ["Show summary" gnus-article-show-summary t]
2054 ["Fetch Message-ID at point" gnus-article-refer-article t]
2055 ["Mail to address at point" gnus-article-mail t]
2056 ["Send a bug report" gnus-bug t]))
2059 gnus-article-treatment-menu gnus-article-mode-map ""
2061 ["Hide headers" gnus-article-hide-headers t]
2062 ["Hide signature" gnus-article-hide-signature t]
2063 ["Hide citation" gnus-article-hide-citation t]
2064 ["Treat overstrike" gnus-article-treat-overstrike t]
2065 ["Remove carriage return" gnus-article-remove-cr t]
2066 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2068 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2070 (when (boundp 'gnus-summary-post-menu)
2071 (define-key gnus-article-mode-map [menu-bar post]
2072 (cons "Post" gnus-summary-post-menu)))
2074 (gnus-run-hooks 'gnus-article-menu-hook)))
2076 (defun gnus-article-mode ()
2077 "Major mode for displaying an article.
2079 All normal editing commands are switched off.
2081 The following commands are available in addition to all summary mode
2083 \\<gnus-article-mode-map>
2084 \\[gnus-article-next-page]\t Scroll the article one page forwards
2085 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2086 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2087 \\[gnus-article-show-summary]\t Display the summary buffer
2088 \\[gnus-article-mail]\t Send a reply to the address near point
2089 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2090 \\[gnus-info-find-node]\t Go to the Gnus info node"
2092 (when (gnus-visual-p 'article-menu 'menu)
2093 (gnus-article-make-menu-bar))
2094 (gnus-simplify-mode-line)
2095 (setq mode-name "Article")
2096 (setq major-mode 'gnus-article-mode)
2097 (make-local-variable 'minor-mode-alist)
2098 (use-local-map gnus-article-mode-map)
2099 (gnus-update-format-specifications nil 'article-mode)
2100 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2101 (make-local-variable 'gnus-page-broken)
2102 (make-local-variable 'gnus-button-marker-list)
2103 (make-local-variable 'gnus-article-current-summary)
2104 (make-local-variable 'gnus-article-mime-handles)
2105 (make-local-variable 'gnus-article-decoded-p)
2106 (make-local-variable 'gnus-article-mime-handle-alist)
2107 (gnus-set-default-directory)
2108 (buffer-disable-undo)
2109 (setq buffer-read-only t)
2110 (set-syntax-table gnus-article-mode-syntax-table)
2111 (mm-enable-multibyte)
2112 (gnus-run-hooks 'gnus-article-mode-hook))
2114 (defun gnus-article-setup-buffer ()
2115 "Initialize the article buffer."
2116 (let* ((name (if gnus-single-article-buffer "*Article*"
2117 (concat "*Article " gnus-newsgroup-name "*")))
2119 (progn (string-match "\\*Article" name)
2120 (concat " *Original Article"
2121 (substring name (match-end 0))))))
2122 (setq gnus-article-buffer name)
2123 (setq gnus-original-article-buffer original)
2124 (setq gnus-article-mime-handle-alist nil)
2125 ;; This might be a variable local to the summary buffer.
2126 (unless gnus-single-article-buffer
2128 (set-buffer gnus-summary-buffer)
2129 (setq gnus-article-buffer name)
2130 (setq gnus-original-article-buffer original)
2131 (gnus-set-global-variables)))
2132 ;; Init original article buffer.
2134 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2135 (mm-enable-multibyte)
2136 (setq major-mode 'gnus-original-article-mode)
2137 (make-local-variable 'gnus-original-article))
2138 (if (get-buffer name)
2141 (buffer-disable-undo)
2142 (setq buffer-read-only t)
2143 (unless (eq major-mode 'gnus-article-mode)
2144 (gnus-article-mode))
2147 (set-buffer (gnus-get-buffer-create name))
2149 (make-local-variable 'gnus-summary-buffer)
2150 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2151 (current-buffer)))))
2153 ;; Set article window start at LINE, where LINE is the number of lines
2154 ;; from the head of the article.
2155 (defun gnus-article-set-window-start (&optional line)
2157 (get-buffer-window gnus-article-buffer t)
2159 (set-buffer gnus-article-buffer)
2160 (goto-char (point-min))
2163 (gnus-message 6 "Moved to bookmark")
2164 (search-forward "\n\n" nil t)
2168 (defun gnus-article-prepare (article &optional all-headers header)
2169 "Prepare ARTICLE in article mode buffer.
2170 ARTICLE should either be an article number or a Message-ID.
2171 If ARTICLE is an id, HEADER should be the article headers.
2172 If ALL-HEADERS is non-nil, no headers are hidden."
2174 ;; Make sure we start in a summary buffer.
2175 (unless (eq major-mode 'gnus-summary-mode)
2176 (set-buffer gnus-summary-buffer))
2177 (setq gnus-summary-buffer (current-buffer))
2178 (let* ((gnus-article (if header (mail-header-number header) article))
2179 (summary-buffer (current-buffer))
2180 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2181 (group gnus-newsgroup-name)
2184 (gnus-article-setup-buffer)
2185 (set-buffer gnus-article-buffer)
2186 ;; Deactivate active regions.
2187 (when (and (boundp 'transient-mark-mode)
2188 transient-mark-mode)
2189 (setq mark-active nil))
2190 (if (not (setq result (let ((buffer-read-only nil))
2191 (gnus-request-article-this-buffer
2193 ;; There is no such article.
2195 (when (and (numberp article)
2196 (not (memq article gnus-newsgroup-sparse)))
2197 (setq gnus-article-current
2198 (cons gnus-newsgroup-name article))
2199 (set-buffer gnus-summary-buffer)
2200 (setq gnus-current-article article)
2201 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2203 (gnus-summary-set-agent-mark article)
2204 (message "Message marked for downloading"))
2205 (gnus-summary-mark-article article gnus-canceled-mark)
2206 (unless (memq article gnus-newsgroup-sparse)
2208 "No such article (may have expired or been canceled)")))))
2209 (if (or (eq result 'pseudo)
2210 (eq result 'nneething))
2213 (set-buffer summary-buffer)
2214 (push article gnus-newsgroup-history)
2215 (setq gnus-last-article gnus-current-article
2216 gnus-current-article 0
2217 gnus-current-headers nil
2218 gnus-article-current nil)
2219 (if (eq result 'nneething)
2220 (gnus-configure-windows 'summary)
2221 (gnus-configure-windows 'article))
2222 (gnus-set-global-variables))
2223 (let ((gnus-article-mime-handle-alist-1
2224 gnus-article-mime-handle-alist))
2225 (gnus-set-mode-line 'article)))
2226 ;; The result from the `request' was an actual article -
2227 ;; or at least some text that is now displayed in the
2229 (when (and (numberp article)
2230 (not (eq article gnus-current-article)))
2231 ;; Seems like a new article has been selected.
2232 ;; `gnus-current-article' must be an article number.
2234 (set-buffer summary-buffer)
2235 (push article gnus-newsgroup-history)
2236 (setq gnus-last-article gnus-current-article
2237 gnus-current-article article
2238 gnus-current-headers
2239 (gnus-summary-article-header gnus-current-article)
2240 gnus-article-current
2241 (cons gnus-newsgroup-name gnus-current-article))
2242 (unless (vectorp gnus-current-headers)
2243 (setq gnus-current-headers nil))
2244 (gnus-summary-goto-subject gnus-current-article)
2245 (when (gnus-summary-show-thread)
2246 ;; If the summary buffer really was folded, the
2247 ;; previous goto may not actually have gone to
2248 ;; the right article, but the thread root instead.
2250 (gnus-summary-goto-subject gnus-current-article))
2251 (gnus-run-hooks 'gnus-mark-article-hook)
2252 (gnus-set-mode-line 'summary)
2253 (when (gnus-visual-p 'article-highlight 'highlight)
2254 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2255 ;; Set the global newsgroup variables here.
2256 ;; Suggested by Jim Sisolak
2257 ;; <sisolak@trans4.neep.wisc.edu>.
2258 (gnus-set-global-variables)
2259 (setq gnus-have-all-headers
2260 (or all-headers gnus-show-all-headers))))
2261 (when (or (numberp article)
2263 (gnus-article-prepare-display)
2265 (goto-char (point-min))
2266 (setq gnus-page-broken
2267 (when gnus-break-pages
2268 (gnus-narrow-to-page)
2270 (let ((gnus-article-mime-handle-alist-1
2271 gnus-article-mime-handle-alist))
2272 (gnus-set-mode-line 'article))
2273 (gnus-configure-windows 'article)
2275 (set-window-point (get-buffer-window (current-buffer)) (point))
2278 (defun gnus-article-prepare-display ()
2279 "Make the current buffer look like a nice article."
2280 ;; Hooks for getting information from the article.
2281 ;; This hook must be called before being narrowed.
2282 (let ((gnus-article-buffer (current-buffer))
2284 (unless (eq major-mode 'gnus-article-mode)
2285 (gnus-article-mode))
2286 (setq buffer-read-only nil)
2287 (gnus-run-hooks 'gnus-tmp-internal-hook)
2288 (gnus-run-hooks 'gnus-article-prepare-hook)
2289 (when gnus-display-mime-function
2291 (let ((url-standalone-mode (not gnus-plugged)))
2292 (funcall gnus-display-mime-function)))
2293 ;; Perform the article display hooks.
2294 (gnus-run-hooks 'gnus-article-display-hook)))
2297 ;;; Gnus MIME viewing functions
2300 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2301 "The following specs can be used:
2303 %T MIME type, along with additional info
2304 %n The `name' parameter
2305 %d The description, if any
2306 %l The length of the encoded part
2307 %p The part identifier number
2308 %e Dots if the part isn't displayed")
2310 (defvar gnus-mime-button-line-format-alist
2311 '((?t gnus-tmp-type ?s)
2312 (?T gnus-tmp-type-long ?s)
2313 (?n gnus-tmp-name ?s)
2314 (?d gnus-tmp-description ?s)
2316 (?l gnus-tmp-length ?d)
2317 (?e gnus-tmp-dots ?s)))
2319 (defvar gnus-mime-button-commands
2320 '((gnus-article-press-button "\r" "Toggle Display")
2321 (gnus-mime-view-part "v" "View Interactively...")
2322 (gnus-mime-save-part "o" "Save...")
2323 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2324 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2325 (gnus-mime-internalize-part "E" "View Internally")
2326 (gnus-mime-externalize-part "e" "View Externally")
2327 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2329 (defun gnus-article-mime-part-status ()
2330 (if gnus-article-mime-handle-alist-1
2331 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2334 (defvar gnus-mime-button-map nil)
2335 (unless gnus-mime-button-map
2336 (setq gnus-mime-button-map (make-sparse-keymap))
2337 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2338 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2339 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2341 (define-key gnus-mime-button-map (cadr c) (car c)))
2342 gnus-mime-button-commands))
2344 (defun gnus-mime-button-menu (event)
2345 "Construct a context-sensitive menu of MIME commands."
2347 (gnus-article-check-buffer)
2348 (let ((response (x-popup-menu
2350 ("" ,@(mapcar (lambda (c)
2351 (cons (caddr c) (car c)))
2352 gnus-mime-button-commands)))))
2353 (pos (event-start event)))
2355 (set-buffer (window-buffer (posn-window pos)))
2356 (goto-char (posn-point pos))
2357 (funcall response))))
2359 (defun gnus-mime-view-all-parts (&optional handles)
2360 "View all the MIME parts."
2362 (save-current-buffer
2363 (set-buffer gnus-article-buffer)
2364 (let ((handles (or handles gnus-article-mime-handles))
2365 (rfc2047-default-charset gnus-newsgroup-default-charset)
2366 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2367 (if (stringp (car handles))
2368 (gnus-mime-view-all-parts (cdr handles))
2369 (mapcar 'mm-display-part handles)))))
2371 (defun gnus-mime-save-part ()
2372 "Save the MIME part under point."
2374 (gnus-article-check-buffer)
2375 (let ((data (get-text-property (point) 'gnus-data)))
2376 (mm-save-part data)))
2378 (defun gnus-mime-pipe-part ()
2379 "Pipe the MIME part under point to a process."
2381 (gnus-article-check-buffer)
2382 (let ((data (get-text-property (point) 'gnus-data)))
2383 (mm-pipe-part data)))
2385 (defun gnus-mime-view-part ()
2386 "Interactively choose a view method for the MIME part under point."
2388 (gnus-article-check-buffer)
2390 (let ((data (get-text-property (point) 'gnus-data))
2391 (url-standalone-mode (not gnus-plugged)))
2392 (mm-interactively-view-part data)))
2394 (defun gnus-mime-copy-part (&optional handle)
2395 "Put the the MIME part under point into a new buffer."
2397 (gnus-article-check-buffer)
2398 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2399 (contents (mm-get-part handle))|
2400 (base (file-name-nondirectory
2402 (mail-content-type-get (mm-handle-type handle) 'name)
2403 (mail-content-type-get (mm-handle-type handle)
2406 (buffer (generate-new-buffer base)))
2407 (switch-to-buffer buffer)
2409 ;; We do it this way to make `normal-mode' set the appropriate mode.
2412 (setq buffer-file-name (expand-file-name base))
2414 (setq buffer-file-name nil))
2415 (goto-char (point-min))))
2417 (defun gnus-mime-inline-part (&optional charset)
2418 "Insert the MIME part under point into the current buffer."
2419 (interactive "P") ; For compatibility reasons we are not using "z".
2420 (gnus-article-check-buffer)
2422 (let* ((data (get-text-property (point) 'gnus-data))
2424 (url-standalone-mode (not gnus-plugged))
2427 (if (mm-handle-undisplayer data)
2428 (mm-remove-part data)
2429 (setq contents (mm-get-part data))
2432 (unless (symbolp charset)
2433 (setq charset (mm-read-coding-system "Charset: ")))
2434 (setq contents (mm-decode-coding-string contents charset)))
2435 (mm-insert-inline data contents)
2438 (defun gnus-mime-externalize-part (&optional handle)
2439 "View the MIME part under point with an external viewer."
2441 (gnus-article-check-buffer)
2443 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2444 (url-standalone-mode (not gnus-plugged))
2445 (mm-user-display-methods nil)
2446 (mm-all-images-fit t)
2447 (rfc2047-default-charset gnus-newsgroup-default-charset)
2448 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2449 (if (mm-handle-undisplayer handle)
2450 (mm-remove-part handle)
2451 (mm-display-part handle))))
2453 (defun gnus-mime-internalize-part (&optional handle)
2454 "View the MIME part under point with an internal viewer."
2456 (gnus-article-check-buffer)
2458 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2459 (url-standalone-mode (not gnus-plugged))
2460 (mm-user-display-methods '((".*" . inline)))
2461 (mm-all-images-fit t)
2462 (rfc2047-default-charset gnus-newsgroup-default-charset)
2463 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2464 (if (mm-handle-undisplayer handle)
2465 (mm-remove-part handle)
2466 (mm-display-part handle))))
2468 (defun gnus-article-part-wrapper (n function)
2469 (save-current-buffer
2470 (set-buffer gnus-article-buffer)
2471 (when (> n (length gnus-article-mime-handle-alist))
2472 (error "No such part"))
2473 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2474 (funcall function handle))))
2476 (defun gnus-article-pipe-part (n)
2477 "Pipe MIME part N, which is the numerical prefix."
2479 (gnus-article-part-wrapper n 'mm-pipe-part))
2481 (defun gnus-article-save-part (n)
2482 "Save MIME part N, which is the numerical prefix."
2484 (gnus-article-part-wrapper n 'mm-save-part))
2486 (defun gnus-article-interactively-view-part (n)
2487 "Pipe MIME part N, which is the numerical prefix."
2489 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2491 (defun gnus-article-copy-part (n)
2492 "Pipe MIME part N, which is the numerical prefix."
2494 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2496 (defun gnus-article-externalize-part (n)
2497 "Pipe MIME part N, which is the numerical prefix."
2499 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2501 (defun gnus-article-view-part (n)
2502 "View MIME part N, which is the numerical prefix."
2504 (save-current-buffer
2505 (set-buffer gnus-article-buffer)
2506 (when (> n (length gnus-article-mime-handle-alist))
2507 (error "No such part"))
2508 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2509 (when (gnus-article-goto-part n)
2510 (if (equal (car handle) "multipart/alternative")
2511 (gnus-article-press-button)
2512 (when (eq (gnus-mm-display-part handle) 'internal)
2513 (gnus-set-window-start)))))))
2515 (defun gnus-mm-display-part (handle)
2516 "Display HANDLE and fix MIME button."
2517 (let ((id (get-text-property (point) 'gnus-part))
2520 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2521 (gnus-insert-mime-button
2522 handle id (list (not (mm-handle-displayed-p handle))))
2524 (let ((window (selected-window))
2525 (rfc2047-default-charset gnus-newsgroup-default-charset)
2526 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2529 (let ((win (get-buffer-window (current-buffer) t)))
2531 (select-window win))
2534 (mm-display-part handle))
2535 (select-window window))))
2536 (goto-char point))))
2538 (defun gnus-article-goto-part (n)
2539 "Go to MIME part N."
2540 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2542 (goto-char point))))
2544 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2545 (let ((gnus-tmp-name
2546 (or (mail-content-type-get (mm-handle-type handle)
2548 (mail-content-type-get (mm-handle-disposition handle)
2551 (gnus-tmp-type (car (mm-handle-type handle)))
2552 (gnus-tmp-description (or (mm-handle-description handle)
2555 (if (if displayed (car displayed)
2556 (mm-handle-displayed-p handle))
2558 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2560 gnus-tmp-type-long b e)
2561 (when (string-match ".*/" gnus-tmp-name)
2562 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2563 (setq gnus-tmp-type-long (concat gnus-tmp-type
2564 (and (not (equal gnus-tmp-name ""))
2565 (concat "; " gnus-tmp-name))))
2566 (or (equal gnus-tmp-description "")
2567 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2572 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2573 `(local-map ,gnus-mime-button-map
2574 keymap ,gnus-mime-button-map
2575 gnus-callback gnus-mm-display-part
2576 gnus-part ,gnus-tmp-id
2577 article-type annotation
2580 (widget-convert-button 'link b e
2582 :action 'gnus-widget-press-button
2583 :button-keymap gnus-mime-button-map
2586 ;; Needed to properly clear the message
2587 ;; due to a bug in wid-edit
2588 (setq help-echo-owns-message t)
2590 "Click to %s the MIME part; %s for more options"
2591 (if (mm-handle-displayed-p
2592 (widget-get widget :mime-handle))
2594 (if gnus-xemacs "button3" "mouse-3"))))))
2596 (defun gnus-widget-press-button (elems el)
2597 (goto-char (widget-get elems :from))
2599 (let ((url-standalone-mode (not gnus-plugged)))
2600 (gnus-article-press-button)))
2602 (defun gnus-display-mime (&optional ihandles)
2603 "Insert MIME buttons in the buffer."
2605 (save-selected-window
2606 (let ((window (get-buffer-window gnus-article-buffer))
2609 (select-window window)
2610 ;; We have to do this since selecting the window
2611 ;; may change the point. So we set the window point.
2612 (set-window-point window point)))
2613 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2614 handle name type b e display)
2616 ;; Top-level call; we clean up.
2617 (mm-destroy-parts gnus-article-mime-handles)
2618 (setq gnus-article-mime-handles handles
2619 gnus-article-mime-handle-alist nil)
2620 ;; We allow users to glean info from the handles.
2621 (when gnus-article-mime-part-function
2622 (gnus-mime-part-function handles)))
2624 (or (not (stringp (car handles)))
2627 ;; Clean up for mime parts.
2629 (delete-region (point) (point-max)))
2630 (gnus-mime-display-part handles))))))
2632 (defun gnus-mime-display-part (handle)
2635 ((not (stringp (car handle)))
2636 (gnus-mime-display-single handle))
2637 ;; multipart/alternative
2638 ((equal (car handle) "multipart/alternative")
2639 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2640 (push (cons id handle) gnus-article-mime-handle-alist)
2641 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2642 ;; multipart/related
2643 ((equal (car handle) "multipart/related")
2644 ;;;!!!We should find the start part, but we just default
2645 ;;;!!!to the first part.
2646 (gnus-mime-display-part (cadr handle)))
2647 ;; Other multiparts are handled like multipart/mixed.
2649 (gnus-mime-display-mixed (cdr handle)))))
2651 (defun gnus-mime-part-function (handles)
2652 (if (stringp (car handles))
2653 (mapcar 'gnus-mime-part-function (cdr handles))
2654 (funcall gnus-article-mime-part-function handles)))
2656 (defun gnus-mime-display-mixed (handles)
2657 (mapcar 'gnus-mime-display-part handles))
2659 (defun gnus-mime-display-single (handle)
2660 (let ((type (car (mm-handle-type handle)))
2661 (ignored gnus-ignored-mime-types)
2668 (when (string-match (pop ignored) type)
2669 (throw 'ignored nil)))
2670 (if (and (setq not-attachment
2671 (or (not (mm-handle-disposition handle))
2672 (equal (car (mm-handle-disposition handle))
2674 (mm-automatic-display-p type)
2675 (or (mm-inlinable-part-p type)
2676 (mm-automatic-external-display-p type)))
2678 (when (equal (car (split-string type "/"))
2681 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2682 (push (cons id handle) gnus-article-mime-handle-alist)
2683 (when (or (not display)
2684 (not (gnus-unbuttonized-mime-type-p type)))
2685 (gnus-article-insert-newline)
2686 (gnus-insert-mime-button
2687 handle id (list (or display
2688 (and not-attachment text))))
2689 (gnus-article-insert-newline)
2690 (gnus-article-insert-newline)
2696 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2697 (mm-charset-iso-8859-1-forced
2698 gnus-newsgroup-iso-8859-1-forced))
2699 (mm-display-part handle t))
2700 (goto-char (point-max)))
2701 ((and text not-attachment)
2704 (gnus-article-insert-newline)
2705 (mm-insert-inline handle (mm-get-part handle))
2706 (goto-char (point-max))))))))
2708 (defun gnus-unbuttonized-mime-type-p (type)
2709 "Say whether TYPE is to be unbuttonized."
2710 (unless gnus-inhibit-mime-unbuttonizing
2712 (let ((types gnus-unbuttonized-mime-types))
2714 (when (string-match (pop types) type)
2715 (throw 'found t)))))))
2717 (defun gnus-article-insert-newline ()
2718 "Insert a newline, but mark it as undeletable."
2719 (gnus-put-text-property
2720 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2722 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2723 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2726 handle buffer-read-only from props begend not-pref)
2727 (save-window-excursion
2730 (narrow-to-region (car ibegend)
2733 (goto-char (car ibegend))
2736 (delete-region (point-min) (point-max))
2737 (mm-remove-parts handles))
2738 (setq begend (list (point-marker)))
2740 (unless (setq not-pref (cadr (member preferred ihandles)))
2741 (setq not-pref (car ihandles)))
2743 (not (gnus-unbuttonized-mime-type-p
2744 "multipart/alternative")))
2745 (gnus-add-text-properties
2748 (insert (format "%d. " id))
2752 (unless ,(not ibegend)
2753 (setq gnus-article-mime-handle-alist
2754 ',gnus-article-mime-handle-alist))
2755 (gnus-mime-display-alternative
2756 ',ihandles ',not-pref ',begend ,id))
2757 local-map ,gnus-mime-button-map
2758 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2759 face ,gnus-article-button-face
2760 keymap ,gnus-mime-button-map
2763 (widget-convert-button 'link from (point)
2764 :action 'gnus-widget-press-button
2765 :button-keymap gnus-widget-button-keymap)
2767 (while (setq handle (pop handles))
2768 (gnus-add-text-properties
2771 (insert (format "(%c) %-18s"
2772 (if (equal handle preferred) ?* ? )
2773 (if (stringp (car handle))
2775 (car (mm-handle-type handle)))))
2779 (unless ,(not ibegend)
2780 (setq gnus-article-mime-handle-alist
2781 ',gnus-article-mime-handle-alist))
2782 (gnus-mime-display-alternative
2783 ',ihandles ',handle ',begend ,id))
2784 local-map ,gnus-mime-button-map
2785 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2786 face ,gnus-article-button-face
2787 keymap ,gnus-mime-button-map
2790 (widget-convert-button 'link from (point)
2791 :action 'gnus-widget-press-button
2792 :button-keymap gnus-widget-button-keymap)
2796 (if (stringp (car preferred))
2797 (gnus-display-mime preferred)
2798 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2799 (mm-charset-iso-8859-1-forced
2800 gnus-newsgroup-iso-8859-1-forced))
2801 (mm-display-part preferred)))
2802 (goto-char (point-max))
2803 (setcdr begend (point-marker)))))
2805 (goto-char point))))
2807 (defun gnus-article-wash-status ()
2808 "Return a string which display status of article washing."
2810 (set-buffer gnus-article-buffer)
2811 (let ((cite (gnus-article-hidden-text-p 'cite))
2812 (headers (gnus-article-hidden-text-p 'headers))
2813 (boring (gnus-article-hidden-text-p 'boring-headers))
2814 (pgp (gnus-article-hidden-text-p 'pgp))
2815 (pem (gnus-article-hidden-text-p 'pem))
2816 (signature (gnus-article-hidden-text-p 'signature))
2817 (overstrike (gnus-article-hidden-text-p 'overstrike))
2818 (emphasis (gnus-article-hidden-text-p 'emphasis)))
2819 (format "%c%c%c%c%c%c"
2821 (if (or headers boring) ?h ? )
2822 (if (or pgp pem) ?p ? )
2823 (if signature ?s ? )
2824 (if overstrike ?o ? )
2825 (if emphasis ?e ? )))))
2827 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2829 (defun gnus-article-maybe-hide-headers ()
2830 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2831 Provided for backwards compatibility."
2832 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2834 (gnus-article-hide-headers)))
2838 (defun gnus-output-to-file (file-name)
2839 "Append the current article to a file named FILE-NAME."
2840 (let ((artbuf (current-buffer)))
2842 (insert-buffer-substring artbuf)
2843 ;; Append newline at end of the buffer as separator, and then
2845 (goto-char (point-max))
2847 (append-to-file (point-min) (point-max) file-name)
2850 (defun gnus-narrow-to-page (&optional arg)
2851 "Narrow the article buffer to a page.
2852 If given a numerical ARG, move forward ARG pages."
2854 (setq arg (if arg (prefix-numeric-value arg) 0))
2856 (set-buffer gnus-article-buffer)
2857 (goto-char (point-min))
2859 ;; Remove any old next/prev buttons.
2860 (when (gnus-visual-p 'page-marker)
2861 (let ((buffer-read-only nil))
2862 (gnus-remove-text-with-property 'gnus-prev)
2863 (gnus-remove-text-with-property 'gnus-next)))
2866 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2868 (re-search-forward page-delimiter nil 'move arg)))
2869 (goto-char (match-end 0)))
2872 (if (re-search-forward page-delimiter nil 'move)
2875 (when (and (gnus-visual-p 'page-marker)
2876 (not (= (point-min) 1)))
2878 (goto-char (point-min))
2879 (gnus-insert-prev-page-button)))
2880 (when (and (gnus-visual-p 'page-marker)
2881 (< (+ (point-max) 2) (buffer-size)))
2883 (goto-char (point-max))
2884 (gnus-insert-next-page-button)))))
2886 ;; Article mode commands
2888 (defun gnus-article-goto-next-page ()
2889 "Show the next page of the article."
2891 (when (gnus-article-next-page)
2892 (goto-char (point-min))
2893 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2895 (defun gnus-article-goto-prev-page ()
2896 "Show the next page of the article."
2898 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2899 (gnus-article-prev-page nil)))
2901 (defun gnus-article-next-page (&optional lines)
2902 "Show the next page of the current article.
2903 If end of article, return non-nil. Otherwise return nil.
2904 Argument LINES specifies lines to be scrolled up."
2906 (move-to-window-line -1)
2909 (and (pos-visible-in-window-p) ;Not continuation line.
2911 ;; Nothing in this page.
2912 (if (or (not gnus-page-broken)
2915 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2917 (gnus-narrow-to-page 1) ;Go to next page.
2919 ;; More in this page.
2920 (let ((scroll-in-place nil))
2924 ;; Long lines may cause an end-of-buffer error.
2925 (goto-char (point-max)))))
2926 (move-to-window-line 0)
2929 (defun gnus-article-prev-page (&optional lines)
2930 "Show previous page of current article.
2931 Argument LINES specifies lines to be scrolled down."
2933 (move-to-window-line 0)
2934 (if (and gnus-page-broken
2936 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2938 (gnus-narrow-to-page -1) ;Go to previous page.
2939 (goto-char (point-max))
2941 (let ((scroll-in-place nil))
2945 (beginning-of-buffer
2946 (goto-char (point-min))))
2947 (move-to-window-line 0)))))
2949 (defun gnus-article-refer-article ()
2950 "Read article specified by message-id around point."
2952 (let ((point (point)))
2953 (search-forward ">" nil t) ;Move point to end of "<....>".
2954 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2955 (let ((message-id (match-string 1)))
2957 (set-buffer gnus-summary-buffer)
2958 (gnus-summary-refer-article message-id))
2960 (error "No references around point"))))
2962 (defun gnus-article-show-summary ()
2963 "Reconfigure windows to show summary buffer."
2965 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2966 (error "There is no summary buffer for this article buffer")
2967 (gnus-article-set-globals)
2968 (gnus-configure-windows 'article)
2969 (gnus-summary-goto-subject gnus-current-article)
2970 (gnus-summary-position-point)))
2972 (defun gnus-article-describe-briefly ()
2973 "Describe article mode commands briefly."
2976 (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")))
2978 (defun gnus-article-summary-command ()
2979 "Execute the last keystroke in the summary buffer."
2981 (let ((obuf (current-buffer))
2982 (owin (current-window-configuration))
2984 (switch-to-buffer gnus-article-current-summary 'norecord)
2985 (setq func (lookup-key (current-local-map) (this-command-keys)))
2986 (call-interactively func)
2988 (set-window-configuration owin)
2989 (set-window-point (get-buffer-window (current-buffer)) (point))))
2991 (defun gnus-article-summary-command-nosave ()
2992 "Execute the last keystroke in the summary buffer."
2995 (pop-to-buffer gnus-article-current-summary 'norecord)
2996 (setq func (lookup-key (current-local-map) (this-command-keys)))
2997 (call-interactively func)))
2999 (defun gnus-article-check-buffer ()
3000 "Beep if not in an article buffer."
3001 (unless (equal major-mode 'gnus-article-mode)
3002 (error "Command invoked outside of a Gnus article buffer")))
3004 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3005 "Read a summary buffer key sequence and execute it from the article buffer."
3007 (gnus-article-check-buffer)
3009 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3010 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3011 "=" "^" "\M-^" "|"))
3017 '("n" "Gn" "p" "Gp"))
3020 (set-buffer gnus-article-current-summary)
3021 (let (gnus-pick-mode)
3022 (push (or key last-command-event) unread-command-events)
3023 (setq keys (read-key-sequence nil))))
3026 (if (or (member keys nosaves)
3027 (member keys nosave-but-article)
3028 (member keys nosave-in-article))
3030 (save-window-excursion
3031 (pop-to-buffer gnus-article-current-summary 'norecord)
3032 ;; We disable the pick minor mode commands.
3033 (let (gnus-pick-mode)
3034 (setq func (lookup-key (current-local-map) keys))))
3037 (unless (member keys nosave-in-article)
3038 (set-buffer gnus-article-current-summary))
3039 (call-interactively func)
3040 (setq new-sum-point (point)))
3041 (when (member keys nosave-but-article)
3042 (pop-to-buffer gnus-article-buffer 'norecord)))
3043 ;; These commands should restore window configuration.
3044 (let ((obuf (current-buffer))
3045 (owin (current-window-configuration))
3047 (summary gnus-article-current-summary)
3048 func in-buffer selected)
3049 (if not-restore-window
3050 (pop-to-buffer summary 'norecord)
3051 (switch-to-buffer summary 'norecord))
3052 (setq in-buffer (current-buffer))
3053 ;; We disable the pick minor mode commands.
3054 (if (setq func (let (gnus-pick-mode)
3055 (lookup-key (current-local-map) keys)))
3057 (call-interactively func)
3058 (setq new-sum-point (point)))
3060 (when (eq in-buffer (current-buffer))
3061 (setq selected (gnus-summary-select-article))
3063 (unless not-restore-window
3064 (set-window-configuration owin))
3065 (unless (or (not (eq selected 'old)) (member keys up-to-top))
3066 (set-window-point (get-buffer-window (current-buffer))
3068 (let ((win (get-buffer-window gnus-article-current-summary)))
3070 (set-window-point win new-sum-point))))))))
3072 (defun gnus-article-hide (&optional arg force)
3073 "Hide all the gruft in the current article.
3074 This means that PGP stuff, signatures, cited text and (some)
3075 headers will be hidden.
3076 If given a prefix, show the hidden text instead."
3077 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3078 (gnus-article-hide-headers arg)
3079 (gnus-article-hide-pgp arg)
3080 (gnus-article-hide-citation-maybe arg force)
3081 (gnus-article-hide-signature arg))
3083 (defun gnus-article-maybe-highlight ()
3084 "Do some article highlighting if article highlighting is requested."
3085 (when (gnus-visual-p 'article-highlight 'highlight)
3086 (gnus-article-highlight-some)))
3088 (defun gnus-check-group-server ()
3089 ;; Make sure the connection to the server is alive.
3090 (unless (gnus-server-opened
3091 (gnus-find-method-for-group gnus-newsgroup-name))
3092 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3093 (gnus-request-group gnus-newsgroup-name t)))
3095 (defun gnus-request-article-this-buffer (article group)
3096 "Get an article and insert it into this buffer."
3097 (let (do-update-line sparse-header)
3101 (gnus-kill-all-overlays)
3102 (setq group (or group gnus-newsgroup-name))
3104 ;; Using `gnus-request-article' directly will insert the article into
3105 ;; `nntp-server-buffer' - so we'll save some time by not having to
3106 ;; copy it from the server buffer into the article buffer.
3108 ;; We only request an article by message-id when we do not have the
3109 ;; headers for it, so we'll have to get those.
3110 (when (stringp article)
3111 (let ((gnus-override-method gnus-refer-article-method))
3112 (gnus-read-header article)))
3114 ;; If the article number is negative, that means that this article
3115 ;; doesn't belong in this newsgroup (possibly), so we find its
3116 ;; message-id and request it by id instead of number.
3117 (when (and (numberp article)
3119 (get-buffer gnus-summary-buffer)
3120 (gnus-buffer-exists-p gnus-summary-buffer))
3122 (set-buffer gnus-summary-buffer)
3123 (let ((header (gnus-summary-article-header article)))
3126 ((memq article gnus-newsgroup-sparse)
3127 ;; This is a sparse gap article.
3128 (setq do-update-line article)
3129 (setq article (mail-header-id header))
3130 (let ((gnus-override-method gnus-refer-article-method))
3131 (setq sparse-header (gnus-read-header article)))
3132 (setq gnus-newsgroup-sparse
3133 (delq article gnus-newsgroup-sparse)))
3135 ;; It's a real article.
3136 (setq article (mail-header-id header)))
3138 ;; It is an extracted pseudo-article.
3139 (setq article 'pseudo)
3140 (gnus-request-pseudo-article header))))
3142 (let ((method (gnus-find-method-for-group
3143 gnus-newsgroup-name)))
3144 (when (and (eq (car method) 'nneething)
3147 (file-name-as-directory
3148 (or (cadr (assq 'nneething-address method))
3150 (mail-header-subject header))))
3151 (when (file-directory-p dir)
3152 (setq article 'nneething)
3153 (gnus-group-enter-directory dir))))))))
3156 ;; Refuse to select canceled articles.
3157 ((and (numberp article)
3159 (get-buffer gnus-summary-buffer)
3160 (gnus-buffer-exists-p gnus-summary-buffer)
3161 (eq (cdr (save-excursion
3162 (set-buffer gnus-summary-buffer)
3163 (assq article gnus-newsgroup-reads)))
3164 gnus-canceled-mark))
3166 ;; We first check `gnus-original-article-buffer'.
3167 ((and (get-buffer gnus-original-article-buffer)
3170 (set-buffer gnus-original-article-buffer)
3171 (and (equal (car gnus-original-article) group)
3172 (eq (cdr gnus-original-article) article))))
3173 (insert-buffer-substring gnus-original-article-buffer)
3175 ;; Check the backlog.
3176 ((and gnus-keep-backlog
3177 (gnus-backlog-request-article group article (current-buffer)))
3179 ;; Check asynchronous pre-fetch.
3180 ((gnus-async-request-fetched-article group article (current-buffer))
3181 (gnus-async-prefetch-next group article gnus-summary-buffer)
3182 (when (and (numberp article) gnus-keep-backlog)
3183 (gnus-backlog-enter-article group article (current-buffer)))
3186 ((and gnus-use-cache
3188 (gnus-cache-request-article article group))
3190 ;; Get the article and put into the article buffer.
3191 ((or (stringp article) (numberp article))
3192 (let ((gnus-override-method
3193 (and (stringp article) gnus-refer-article-method))
3194 (buffer-read-only nil))
3196 (gnus-kill-all-overlays)
3197 (gnus-check-group-server)
3198 (when (gnus-request-article article group (current-buffer))
3199 (when (numberp article)
3200 (gnus-async-prefetch-next group article gnus-summary-buffer)
3201 (when gnus-keep-backlog
3202 (gnus-backlog-enter-article
3203 group article (current-buffer))))
3208 ;; Associate this article with the current summary buffer.
3209 (setq gnus-article-current-summary gnus-summary-buffer)
3211 ;; Take the article from the original article buffer
3212 ;; and place it in the buffer it's supposed to be in.
3213 (when (and (get-buffer gnus-article-buffer)
3214 (equal (buffer-name (current-buffer))
3215 (buffer-name (get-buffer gnus-article-buffer))))
3217 (if (get-buffer gnus-original-article-buffer)
3218 (set-buffer gnus-original-article-buffer)
3219 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3220 (buffer-disable-undo)
3221 (setq major-mode 'gnus-original-article-mode)
3222 (setq buffer-read-only t))
3223 (let (buffer-read-only)
3225 (insert-buffer-substring gnus-article-buffer))
3226 (setq gnus-original-article (cons group article)))
3229 (run-hooks 'gnus-article-decode-hook)
3230 ;; Mark article as decoded or not.
3231 (setq gnus-article-decoded-p gnus-article-decode-hook))
3233 ;; Update sparse articles.
3234 (when (and do-update-line
3235 (or (numberp article)
3237 (let ((buf (current-buffer)))
3238 (set-buffer gnus-summary-buffer)
3239 (gnus-summary-update-article do-update-line sparse-header)
3240 (gnus-summary-goto-subject do-update-line nil t)
3241 (set-window-point (get-buffer-window (current-buffer) t)
3243 (set-buffer buf))))))
3249 (defcustom gnus-article-edit-mode-hook nil
3250 "Hook run in article edit mode buffers."
3251 :group 'gnus-article-various
3254 (defvar gnus-article-edit-done-function nil)
3256 (defvar gnus-article-edit-mode-map nil)
3258 ;; Should we be using derived.el for this?
3259 (unless gnus-article-edit-mode-map
3260 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3261 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3263 (gnus-define-keys gnus-article-edit-mode-map
3264 "\C-c\C-c" gnus-article-edit-done
3265 "\C-c\C-k" gnus-article-edit-exit)
3267 (gnus-define-keys (gnus-article-edit-wash-map
3268 "\C-c\C-w" gnus-article-edit-mode-map)
3269 "f" gnus-article-edit-full-stops))
3271 (defun gnus-article-edit-mode ()
3272 "Major mode for editing articles.
3273 This is an extended text-mode.
3275 \\{gnus-article-edit-mode-map}"
3277 (setq major-mode 'gnus-article-edit-mode)
3278 (setq mode-name "Article Edit")
3279 (use-local-map gnus-article-edit-mode-map)
3280 (make-local-variable 'gnus-article-edit-done-function)
3281 (make-local-variable 'gnus-prev-winconf)
3282 (setq buffer-read-only nil)
3283 (buffer-enable-undo)
3285 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3287 (defun gnus-article-edit (&optional force)
3288 "Edit the current article.
3289 This will have permanent effect only in mail groups.
3290 If FORCE is non-nil, allow editing of articles even in read-only
3293 (when (and (not force)
3294 (gnus-group-read-only-p))
3295 (error "The current newsgroup does not support article editing"))
3296 (gnus-article-date-original)
3297 (gnus-article-edit-article
3298 `(lambda (no-highlight)
3299 (gnus-summary-edit-article-done
3300 ,(or (mail-header-references gnus-current-headers) "")
3301 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3303 (defun gnus-article-edit-article (exit-func)
3304 "Start editing the contents of the current article buffer."
3305 (let ((winconf (current-window-configuration)))
3306 (set-buffer gnus-article-buffer)
3307 (gnus-article-edit-mode)
3308 (gnus-article-delete-text-of-type 'annotation)
3309 (gnus-set-text-properties (point-min) (point-max) nil)
3310 (gnus-configure-windows 'edit-article)
3311 (setq gnus-article-edit-done-function exit-func)
3312 (setq gnus-prev-winconf winconf)
3313 (gnus-message 6 "C-c C-c to end edits")))
3315 (defun gnus-article-edit-done (&optional arg)
3316 "Update the article edits and exit."
3321 (when (article-goto-body)
3322 (let ((lines (count-lines (point) (point-max)))
3323 (length (- (point-max) (point)))
3324 (case-fold-search t)
3325 (body (copy-marker (point))))
3326 (goto-char (point-min))
3327 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3328 (delete-region (match-beginning 1) (match-end 1))
3329 (insert (number-to-string length)))
3330 (goto-char (point-min))
3331 (when (re-search-forward
3332 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3333 (delete-region (match-beginning 1) (match-end 1))
3334 (insert (number-to-string length)))
3335 (goto-char (point-min))
3336 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3337 (delete-region (match-beginning 1) (match-end 1))
3338 (insert (number-to-string lines)))))))
3339 (let ((func gnus-article-edit-done-function)
3340 (buf (current-buffer))
3341 (start (window-start)))
3342 (gnus-article-edit-exit)
3345 (let ((buffer-read-only nil))
3347 ;; The cache and backlog have to be flushed somewhat.
3348 (when gnus-keep-backlog
3349 (gnus-backlog-remove-article
3350 (car gnus-article-current) (cdr gnus-article-current)))
3351 ;; Flush original article as well.
3353 (when (get-buffer gnus-original-article-buffer)
3354 (set-buffer gnus-original-article-buffer)
3355 (setq gnus-original-article nil)))
3356 (when gnus-use-cache
3357 (gnus-cache-update-article
3358 (car gnus-article-current) (cdr gnus-article-current))))
3360 (set-window-start (get-buffer-window buf) start)
3361 (set-window-point (get-buffer-window buf) (point))))
3363 (defun gnus-article-edit-exit ()
3364 "Exit the article editing without updating."
3366 ;; We remove all text props from the article buffer.
3367 (let ((buf (format "%s" (buffer-string)))
3368 (curbuf (current-buffer))
3370 (window-start (window-start)))
3373 (let ((winconf gnus-prev-winconf))
3375 (set-window-configuration winconf)
3376 ;; Tippy-toe some to make sure that point remains where it was.
3377 (save-current-buffer
3379 (set-window-start (get-buffer-window (current-buffer)) window-start)
3382 (defun gnus-article-edit-full-stops ()
3383 "Interactively repair spacing at end of sentences."
3386 (goto-char (point-min))
3387 (search-forward-regexp "^$" nil t)
3388 (let ((case-fold-search nil))
3389 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3392 ;;; Article highlights
3395 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3397 ;;; Internal Variables:
3399 (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\\)"
3400 "Regular expression that matches URLs."
3401 :group 'gnus-article-buttons
3404 (defcustom gnus-button-alist
3405 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3406 0 t gnus-button-message-id 2)
3407 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3408 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3410 gnus-button-fetch-group 4)
3411 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3412 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3413 t gnus-button-message-id 3)
3414 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3415 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3416 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3417 ;; This is how URLs _should_ be embedded in text...
3418 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3420 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3421 "*Alist of regexps matching buttons in article bodies.
3423 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3424 REGEXP: is the string matching text around the button,
3425 BUTTON: is the number of the regexp grouping actually matching the button,
3426 FORM: is a lisp expression which must eval to true for the button to
3428 CALLBACK: is the function to call when the user push this button, and each
3429 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3431 CALLBACK can also be a variable, in that case the value of that
3432 variable it the real callback function."
3433 :group 'gnus-article-buttons
3434 :type '(repeat (list regexp
3435 (integer :tag "Button")
3437 (function :tag "Callback")
3440 (integer :tag "Regexp group")))))
3442 (defcustom gnus-header-button-alist
3443 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3444 0 t gnus-button-message-id 0)
3445 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3446 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3447 0 t gnus-button-mailto 0)
3448 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3449 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3450 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3451 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3452 gnus-button-message-id 3))
3453 "*Alist of headers and regexps to match buttons in article heads.
3455 This alist is very similar to `gnus-button-alist', except that each
3456 alist has an additional HEADER element first in each entry:
3458 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3460 HEADER is a regexp to match a header. For a fuller explanation, see
3461 `gnus-button-alist'."
3462 :group 'gnus-article-buttons
3463 :group 'gnus-article-headers
3464 :type '(repeat (list (regexp :tag "Header")
3466 (integer :tag "Button")
3468 (function :tag "Callback")
3471 (integer :tag "Regexp group")))))
3473 (defvar gnus-button-regexp nil)
3474 (defvar gnus-button-marker-list nil)
3475 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3477 (defvar gnus-button-last nil)
3478 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3482 (defun gnus-article-push-button (event)
3483 "Check text under the mouse pointer for a callback function.
3484 If the text under the mouse pointer has a `gnus-callback' property,
3485 call it with the value of the `gnus-data' text property."
3487 (set-buffer (window-buffer (posn-window (event-start event))))
3488 (let* ((pos (posn-point (event-start event)))
3489 (data (get-text-property pos 'gnus-data))
3490 (fun (get-text-property pos 'gnus-callback)))
3493 (funcall fun data))))
3495 (defun gnus-article-press-button ()
3496 "Check text at point for a callback function.
3497 If the text at point has a `gnus-callback' property,
3498 call it with the value of the `gnus-data' text property."
3500 (let* ((data (get-text-property (point) 'gnus-data))
3501 (fun (get-text-property (point) 'gnus-callback)))
3503 (funcall fun data))))
3505 (defun gnus-article-highlight (&optional force)
3506 "Highlight current article.
3507 This function calls `gnus-article-highlight-headers',
3508 `gnus-article-highlight-citation',
3509 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3510 do the highlighting. See the documentation for those functions."
3511 (interactive (list 'force))
3512 (gnus-article-highlight-headers)
3513 (gnus-article-highlight-citation force)
3514 (gnus-article-highlight-signature)
3515 (gnus-article-add-buttons force)
3516 (gnus-article-add-buttons-to-head))
3518 (defun gnus-article-highlight-some (&optional force)
3519 "Highlight current article.
3520 This function calls `gnus-article-highlight-headers',
3521 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3522 do the highlighting. See the documentation for those functions."
3523 (interactive (list 'force))
3524 (gnus-article-highlight-headers)
3525 (gnus-article-highlight-signature)
3526 (gnus-article-add-buttons))
3528 (defun gnus-article-highlight-headers ()
3529 "Highlight article headers as specified by `gnus-header-face-alist'."
3532 (set-buffer gnus-article-buffer)
3534 (let ((alist gnus-header-face-alist)
3535 (buffer-read-only nil)
3536 (case-fold-search t)
3537 (inhibit-point-motion-hooks t)
3538 entry regexp header-face field-face from hpoints fpoints)
3539 (message-narrow-to-head)
3540 (while (setq entry (pop alist))
3541 (goto-char (point-min))
3542 (setq regexp (concat "^\\("
3543 (if (string-equal "" (nth 0 entry))
3547 header-face (nth 1 entry)
3548 field-face (nth 2 entry))
3549 (while (and (re-search-forward regexp nil t)
3553 (unless (search-forward ":" nil t)
3555 (when (and header-face
3556 (not (memq (point) hpoints)))
3557 (push (point) hpoints)
3558 (gnus-put-text-property from (point) 'face header-face))
3559 (when (and field-face
3560 (not (memq (setq from (point)) fpoints)))
3562 (if (re-search-forward "^[^ \t]" nil t)
3564 (goto-char (point-max)))
3565 (gnus-put-text-property from (point) 'face field-face))))))))
3567 (defun gnus-article-highlight-signature ()
3568 "Highlight the signature in an article.
3569 It does this by highlighting everything after
3570 `gnus-signature-separator' using `gnus-signature-face'."
3573 (set-buffer gnus-article-buffer)
3574 (let ((buffer-read-only nil)
3575 (inhibit-point-motion-hooks t))
3577 (when (and gnus-signature-face
3578 (gnus-article-narrow-to-signature))
3579 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3580 'face gnus-signature-face)
3582 (gnus-article-search-signature)
3583 (let ((start (match-beginning 0))
3584 (end (set-marker (make-marker) (1+ (match-end 0)))))
3585 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3588 (defun gnus-button-in-region-p (b e prop)
3589 "Say whether PROP exists in the region."
3590 (text-property-not-all b e prop nil))
3592 (defun gnus-article-add-buttons (&optional force)
3593 "Find external references in the article and make buttons of them.
3594 \"External references\" are things like Message-IDs and URLs, as
3595 specified by `gnus-button-alist'."
3596 (interactive (list 'force))
3598 (set-buffer gnus-article-buffer)
3599 (let ((buffer-read-only nil)
3600 (inhibit-point-motion-hooks t)
3601 (case-fold-search t)
3602 (alist gnus-button-alist)
3604 ;; Remove all old markers.
3606 (while (setq marker (pop gnus-button-marker-list))
3608 (when (setq entry (gnus-button-entry))
3609 (put-text-property (match-beginning (nth 1 entry))
3610 (match-end (nth 1 entry))
3611 'gnus-callback nil))
3612 (set-marker marker nil)))
3613 ;; We skip the headers.
3616 (while (setq entry (pop alist))
3617 (setq regexp (car entry))
3619 (while (re-search-forward regexp nil t)
3620 (let* ((start (and entry (match-beginning (nth 1 entry))))
3621 (end (and entry (match-end (nth 1 entry))))
3622 (from (match-beginning 0)))
3623 (when (and (or (eq t (nth 2 entry))
3624 (eval (nth 2 entry)))
3625 (not (gnus-button-in-region-p
3626 start end 'gnus-callback)))
3627 ;; That optional form returned non-nil, so we add the
3629 (gnus-article-add-button
3630 start end 'gnus-button-push
3631 (car (push (set-marker (make-marker) from)
3632 gnus-button-marker-list))))))))))
3634 ;; Add buttons to the head of an article.
3635 (defun gnus-article-add-buttons-to-head ()
3636 "Add buttons to the head of the article."
3639 (set-buffer gnus-article-buffer)
3640 (let ((buffer-read-only nil)
3641 (inhibit-point-motion-hooks t)
3642 (case-fold-search t)
3643 (alist gnus-header-button-alist)
3645 (nnheader-narrow-to-headers)
3647 ;; Each alist entry.
3648 (setq entry (car alist)
3650 (goto-char (point-min))
3651 (while (re-search-forward (car entry) nil t)
3652 ;; Each header matching the entry.
3653 (setq beg (match-beginning 0))
3654 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3655 (match-beginning 0))
3658 (while (re-search-forward (nth 1 entry) end t)
3659 ;; Each match within a header.
3660 (let* ((entry (cdr entry))
3661 (start (match-beginning (nth 1 entry)))
3662 (end (match-end (nth 1 entry)))
3663 (form (nth 2 entry)))
3664 (goto-char (match-end 0))
3666 (gnus-article-add-button
3667 start end (nth 3 entry)
3668 (buffer-substring (match-beginning (nth 4 entry))
3669 (match-end (nth 4 entry)))))))
3673 ;;; External functions:
3675 (defun gnus-article-add-button (from to fun &optional data)
3676 "Create a button between FROM and TO with callback FUN and data DATA."
3677 (when gnus-article-button-face
3678 (gnus-overlay-put (gnus-make-overlay from to)
3679 'face gnus-article-button-face))
3680 (gnus-add-text-properties
3682 (nconc (and gnus-article-mouse-face
3683 (list gnus-mouse-face-prop gnus-article-mouse-face))
3684 (list 'gnus-callback fun)
3685 (and data (list 'gnus-data data))))
3686 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3687 :button-keymap gnus-widget-button-keymap))
3689 ;;; Internal functions:
3691 (defun gnus-article-set-globals ()
3693 (set-buffer gnus-summary-buffer)
3694 (gnus-set-global-variables)))
3696 (defun gnus-signature-toggle (end)
3698 (set-buffer gnus-article-buffer)
3699 (let ((buffer-read-only nil)
3700 (inhibit-point-motion-hooks t))
3701 (if (get-text-property end 'invisible)
3702 (gnus-article-unhide-text end (point-max))
3703 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3705 (defun gnus-button-entry ()
3706 ;; Return the first entry in `gnus-button-alist' matching this place.
3707 (let ((alist gnus-button-alist)
3710 (setq entry (pop alist))
3711 (if (looking-at (car entry))
3716 (defun gnus-button-push (marker)
3717 ;; Push button starting at MARKER.
3720 (let* ((entry (gnus-button-entry))
3721 (inhibit-point-motion-hooks t)
3723 (args (mapcar (lambda (group)
3724 (let ((string (match-string group)))
3725 (gnus-set-text-properties
3726 0 (length string) nil string)
3733 (fboundp (symbol-value fun)))
3734 (apply (symbol-value fun) args))
3736 (gnus-message 1 "You must define `%S' to use this button"
3737 (cons fun args)))))))
3739 (defun gnus-button-message-id (message-id)
3742 (set-buffer gnus-summary-buffer)
3743 (gnus-summary-refer-article message-id)))
3745 (defun gnus-button-fetch-group (address)
3746 "Fetch GROUP specified by ADDRESS."
3747 (if (not (string-match "[:/]" address))
3748 ;; This is just a simple group url.
3749 (gnus-group-read-ephemeral-group address gnus-select-method)
3750 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3752 (error "Can't parse %s" address)
3753 (gnus-group-read-ephemeral-group
3754 (match-string 4 address)
3755 `(nntp ,(match-string 1 address)
3756 (nntp-address ,(match-string 1 address))
3757 (nntp-port-number ,(if (match-end 3)
3758 (match-string 3 address)
3761 (defun gnus-url-parse-query-string (query &optional downcase)
3762 (let (retval pairs cur key val)
3763 (setq pairs (split-string query "&"))
3765 (setq cur (car pairs)
3767 (if (not (string-match "=" cur))
3769 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3770 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3772 (setq key (downcase key)))
3773 (setq cur (assoc key retval))
3775 (setcdr cur (cons val (cdr cur)))
3776 (setq retval (cons (list key val) retval)))))
3779 (defun gnus-url-unhex (x)
3786 (defun gnus-url-unhex-string (str &optional allow-newlines)
3787 "Remove %XXX embedded spaces, etc in a url.
3788 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3789 decoding of carriage returns and line feeds in the string, which is normally
3790 forbidden in URL encoding."
3791 (setq str (or str ""))
3793 (case-fold-search t))
3794 (while (string-match "%[0-9a-f][0-9a-f]" str)
3795 (let* ((start (match-beginning 0))
3796 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3798 (gnus-url-unhex (elt str (+ start 2))))))
3800 tmp (substring str 0 start)
3803 (char-to-string code))
3804 ((or (= code ?\n) (= code ?\r))
3806 (t (char-to-string code))))
3807 str (substring str (match-end 0)))))
3808 (setq tmp (concat tmp str))
3811 (defun gnus-url-mailto (url)
3812 ;; Send mail to someone
3813 (when (string-match "mailto:/*\\(.*\\)" url)
3814 (setq url (substring url (match-beginning 1) nil)))
3815 (let (to args subject func)
3816 (if (string-match (regexp-quote "?") url)
3817 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3818 args (gnus-url-parse-query-string
3819 (substring url (match-end 0) nil) t))
3820 (setq to (gnus-url-unhex-string url)))
3821 (setq args (cons (list "to" to) args)
3822 subject (cdr-safe (assoc "subject" args)))
3825 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3828 (message-position-on-field (caar args)))
3829 (insert (mapconcat 'identity (cdar args) ", "))
3830 (setq args (cdr args)))
3833 (message-goto-subject))))
3835 (defun gnus-button-mailto (address)
3837 (set-buffer (gnus-copy-article-buffer))
3838 (message-reply address))
3840 (defun gnus-button-reply (address)
3841 ;; Reply to ADDRESS.
3842 (message-reply address))
3844 (defun gnus-button-url (address)
3846 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3847 (if (listp browse-url-browser-function)
3848 (browse-url address)
3849 (funcall browse-url-browser-function address)))
3851 (defun gnus-button-embedded-url (address)
3853 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3854 (if (listp browse-url-browser-function)
3855 (browse-url (gnus-strip-whitespace address))
3856 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3858 ;;; Next/prev buttons in the article buffer.
3860 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3861 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3863 (defvar gnus-prev-page-map nil)
3864 (unless gnus-prev-page-map
3865 (setq gnus-prev-page-map (make-sparse-keymap))
3866 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3867 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3869 (defun gnus-insert-prev-page-button ()
3870 (let ((buffer-read-only nil))
3872 gnus-prev-page-line-format nil
3873 `(gnus-prev t local-map ,gnus-prev-page-map
3874 gnus-callback gnus-article-button-prev-page
3875 article-type annotation))))
3877 (defvar gnus-next-page-map nil)
3878 (unless gnus-next-page-map
3879 (setq gnus-next-page-map (make-keymap))
3880 (suppress-keymap gnus-prev-page-map)
3881 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3882 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3884 (defun gnus-button-next-page ()
3885 "Go to the next page."
3887 (let ((win (selected-window)))
3888 (select-window (get-buffer-window gnus-article-buffer t))
3889 (gnus-article-next-page)
3890 (select-window win)))
3892 (defun gnus-button-prev-page ()
3893 "Go to the prev page."
3895 (let ((win (selected-window)))
3896 (select-window (get-buffer-window gnus-article-buffer t))
3897 (gnus-article-prev-page)
3898 (select-window win)))
3900 (defun gnus-insert-next-page-button ()
3901 (let ((buffer-read-only nil))
3902 (gnus-eval-format gnus-next-page-line-format nil
3904 t local-map ,gnus-next-page-map
3905 gnus-callback gnus-article-button-next-page
3906 article-type annotation))))
3908 (defun gnus-article-button-next-page (arg)
3909 "Go to the next page."
3911 (let ((win (selected-window)))
3912 (select-window (get-buffer-window gnus-article-buffer t))
3913 (gnus-article-next-page)
3914 (select-window win)))
3916 (defun gnus-article-button-prev-page (arg)
3917 "Go to the prev page."
3919 (let ((win (selected-window)))
3920 (select-window (get-buffer-window gnus-article-buffer t))
3921 (gnus-article-prev-page)
3922 (select-window win)))
3924 (defvar gnus-decode-header-methods
3925 '(gnus-decode-with-mail-decode-encoded-word-region)
3926 "List of methods used to decode headers.
3928 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
3929 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
3930 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
3931 whose names match REGEXP.
3934 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
3935 mail-decode-encoded-word-region
3936 (\"chinese\" . rfc1843-decode-region))
3939 (defvar gnus-decode-header-methods-cache nil)
3941 (defun gnus-decode-with-mail-decode-encoded-word-region (start end)
3942 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
3943 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
3944 (mail-decode-encoded-word-region start end)))
3946 (defun gnus-multi-decode-header (start end)
3947 "Apply the functions from `gnus-encoded-word-methods' that match."
3948 (unless (and gnus-decode-header-methods-cache
3949 (eq gnus-newsgroup-name
3950 (car gnus-decode-header-methods-cache)))
3951 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
3954 (nconc gnus-decode-header-methods-cache (list x))
3955 (if (and gnus-newsgroup-name
3956 (string-match (car x) gnus-newsgroup-name))
3957 (nconc gnus-decode-header-methods-cache
3959 gnus-decode-header-methods))
3960 (let ((xlist gnus-decode-header-methods-cache))
3963 (narrow-to-region start end)
3965 (funcall (pop xlist) (point-min) (point-max))))))
3971 (run-hooks 'gnus-art-load-hook)
3973 ;;; gnus-art.el ends here