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 (defsubst gnus-article-unhide-text (b e)
640 "Remove hidden text properties from region between B and E."
641 (remove-text-properties b e gnus-hidden-properties)
642 (when (memq 'intangible gnus-hidden-properties)
643 (put-text-property (max (1- b) (point-min))
646 (defun gnus-article-hide-text-type (b e type)
647 "Hide text of TYPE between B and E."
648 (gnus-article-hide-text
649 b e (cons 'article-type (cons type gnus-hidden-properties))))
651 (defun gnus-article-unhide-text-type (b e type)
652 "Unhide text of TYPE between B and E."
653 (remove-text-properties
654 b e (cons 'article-type (cons type gnus-hidden-properties)))
655 (when (memq 'intangible gnus-hidden-properties)
656 (put-text-property (max (1- b) (point-min))
659 (defun gnus-article-hide-text-of-type (type)
660 "Hide text of TYPE in the current buffer."
662 (let ((b (point-min))
664 (while (setq b (text-property-any b e 'article-type type))
665 (add-text-properties b (incf b) gnus-hidden-properties)))))
667 (defun gnus-article-delete-text-of-type (type)
668 "Delete text of TYPE in the current buffer."
670 (let ((b (point-min)))
671 (while (setq b (text-property-any b (point-max) 'article-type type))
673 b (or (text-property-not-all b (point-max) 'article-type type)
676 (defun gnus-article-delete-invisible-text ()
677 "Delete all invisible text in the current buffer."
679 (let ((b (point-min)))
680 (while (setq b (text-property-any b (point-max) 'invisible t))
682 b (or (text-property-not-all b (point-max) 'invisible t)
685 (defun gnus-article-text-type-exists-p (type)
686 "Say whether any text of type TYPE exists in the buffer."
687 (text-property-any (point-min) (point-max) 'article-type type))
689 (defsubst gnus-article-header-rank ()
690 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
691 (let ((list gnus-sorted-header-list)
694 (when (looking-at (car list))
696 (setq list (cdr list))
700 (defun article-hide-headers (&optional arg delete)
701 "Toggle whether to hide unwanted headers and possibly sort them as well.
702 If given a negative prefix, always show; if given a positive prefix,
704 (interactive (gnus-article-hidden-arg))
706 (if (gnus-article-check-hidden-text 'headers arg)
707 ;; Show boring headers as well.
708 (gnus-article-show-hidden-text 'boring-headers)
709 ;; This function might be inhibited.
710 (unless gnus-inhibit-hiding
713 (let ((buffer-read-only nil)
715 (props (nconc (list 'article-type 'headers)
716 gnus-hidden-properties))
717 (max (1+ (length gnus-sorted-header-list)))
718 (ignored (when (not gnus-visible-headers)
719 (cond ((stringp gnus-ignored-headers)
720 gnus-ignored-headers)
721 ((listp gnus-ignored-headers)
722 (mapconcat 'identity gnus-ignored-headers
725 (cond ((stringp gnus-visible-headers)
726 gnus-visible-headers)
727 ((and gnus-visible-headers
728 (listp gnus-visible-headers))
729 (mapconcat 'identity gnus-visible-headers "\\|"))))
730 (inhibit-point-motion-hooks t)
732 ;; First we narrow to just the headers.
734 (goto-char (point-min))
735 ;; Hide any "From " lines at the beginning of (mail) articles.
736 (while (looking-at "From ")
740 (delete-region (point-min) (point))
741 (gnus-article-hide-text (point-min) (point) props)))
742 ;; Then treat the rest of the header lines.
745 (if (search-forward "\n\n" nil t) ; if there's a body
746 (progn (forward-line -1) (point))
748 ;; Then we use the two regular expressions
749 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
750 ;; select which header lines is to remain visible in the
752 (goto-char (point-min))
753 (while (re-search-forward "^[^ \t]*:" nil t)
755 ;; Mark the rank of the header.
757 (point) (1+ (point)) 'message-rank
758 (if (or (and visible (looking-at visible))
760 (not (looking-at ignored))))
761 (gnus-article-header-rank)
764 (message-sort-headers-1)
765 (when (setq beg (text-property-any
766 (point-min) (point-max) 'message-rank (+ 2 max)))
767 ;; We make the unwanted headers invisible.
769 (delete-region beg (point-max))
770 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
771 (gnus-article-hide-text-type beg (point-max) 'headers))
772 ;; Work around XEmacs lossage.
773 (put-text-property (point-min) beg 'invisible nil))))))))
775 (defun article-hide-boring-headers (&optional arg)
776 "Toggle hiding of headers that aren't very interesting.
777 If given a negative prefix, always show; if given a positive prefix,
779 (interactive (gnus-article-hidden-arg))
780 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
781 (not gnus-show-all-headers))
784 (let ((buffer-read-only nil)
785 (list gnus-boring-article-headers)
786 (inhibit-point-motion-hooks t)
788 (nnheader-narrow-to-headers)
790 (setq elem (pop list))
791 (goto-char (point-min))
793 ;; Hide empty headers.
795 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
797 (gnus-article-hide-text-type
798 (progn (beginning-of-line) (point))
801 (if (re-search-forward "^[^ \t]" nil t)
805 ;; Hide boring Newsgroups header.
806 ((eq elem 'newsgroups)
807 (when (equal (gnus-fetch-field "newsgroups")
808 (gnus-group-real-name
809 (if (boundp 'gnus-newsgroup-name)
812 (gnus-article-hide-header "newsgroups")))
813 ((eq elem 'followup-to)
814 (when (equal (message-fetch-field "followup-to")
815 (message-fetch-field "newsgroups"))
816 (gnus-article-hide-header "followup-to")))
818 (let ((from (message-fetch-field "from"))
819 (reply-to (message-fetch-field "reply-to")))
824 (nth 1 (mail-extract-address-components from))
825 (nth 1 (mail-extract-address-components reply-to)))))
826 (gnus-article-hide-header "reply-to"))))
828 (let ((date (message-fetch-field "date")))
830 (< (days-between (current-time-string) date)
832 (gnus-article-hide-header "date"))))
834 (let ((to (message-fetch-field "to")))
835 (when (> (length to) 1024)
836 (gnus-article-hide-header "to"))))
839 (goto-char (point-min))
840 (while (re-search-forward "^to:" nil t)
841 (setq to-count (1+ to-count)))
843 (while (> to-count 0)
844 (goto-char (point-min))
846 (re-search-forward "^to:" nil nil to-count)
848 (narrow-to-region (point) (point-max))
849 (gnus-article-hide-header "to"))
850 (setq to-count (1- to-count)))))))))))))
852 (defun gnus-article-hide-header (header)
854 (goto-char (point-min))
855 (when (re-search-forward (concat "^" header ":") nil t)
856 (gnus-article-hide-text-type
857 (progn (beginning-of-line) (point))
860 (if (re-search-forward "^[^ \t]" nil t)
865 (defun article-treat-dumbquotes ()
866 "Translate M******** sm*rtq**t*s into proper text."
868 (article-translate-strings gnus-article-dumbquotes-map))
870 (defun article-translate-characters (from to)
871 "Translate all characters in the body of the article according to FROM and TO.
872 FROM is a string of characters to translate from; to is a string of
873 characters to translate to."
875 (when (article-goto-body)
876 (let ((buffer-read-only nil)
877 (x (make-string 225 ?x))
879 (while (< (incf i) (length x))
882 (while (< i (length from))
883 (aset x (aref from i) (aref to i))
885 (translate-region (point) (point-max) x)))))
887 (defun article-translate-strings (map)
888 "Translate all string in the body of the article according to MAP.
889 MAP is an alist where the elements are on the form (\"from\" \"to\")."
891 (when (article-goto-body)
892 (let ((buffer-read-only nil)
894 (while (setq elem (pop map))
896 (while (search-forward (car elem) nil t)
897 (replace-match (cadr elem)))))))))
899 (defun article-treat-overstrike ()
900 "Translate overstrikes into bold text."
903 (when (article-goto-body)
904 (let ((buffer-read-only nil))
905 (while (search-forward "\b" nil t)
906 (let ((next (char-after))
907 (previous (char-after (- (point) 2))))
908 ;; We do the boldification/underlining by hiding the
909 ;; overstrikes and putting the proper text property
913 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
914 (put-text-property (point) (1+ (point)) 'face 'bold))
916 (gnus-article-hide-text-type
917 (1- (point)) (1+ (point)) 'overstrike)
919 (- (point) 2) (1- (point)) 'face 'underline))
921 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
923 (point) (1+ (point)) 'face 'underline)))))))))
925 (defun article-fill ()
926 "Format too long lines."
929 (let ((buffer-read-only nil))
933 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
934 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
935 (adaptive-fill-mode t))
937 (and (>= (current-column) (min fill-column (window-width)))
938 (/= (preceding-char) ?:)
939 (fill-paragraph nil))
942 (defun article-remove-cr ()
943 "Translate CRLF pairs into LF, and then CR into LF.."
946 (let ((buffer-read-only nil))
947 (goto-char (point-min))
948 (while (search-forward "\r$" nil t)
949 (replace-match "" t t))
950 (goto-char (point-min))
951 (while (search-forward "\r" nil t)
952 (replace-match "\n" t t)))))
954 (defun article-remove-trailing-blank-lines ()
955 "Remove all trailing blank lines from the article."
958 (let ((buffer-read-only nil))
959 (goto-char (point-max))
963 (while (and (not (bobp))
964 (looking-at "^[ \t]*$")
965 (not (gnus-annotation-in-region-p
966 (point) (gnus-point-at-eol))))
971 (defun article-display-x-face (&optional force)
972 "Look for an X-Face header and display it if present."
973 (interactive (list 'force))
975 ;; Delete the old process, if any.
976 (when (process-status "article-x-face")
977 (delete-process "article-x-face"))
978 (let ((inhibit-point-motion-hooks t)
982 (nnheader-narrow-to-headers)
983 (setq from (message-fetch-field "from"))
984 (goto-char (point-min))
985 (while (and gnus-article-x-face-command
988 ;; Check whether this face is censored.
989 (not gnus-article-x-face-too-ugly)
990 (and gnus-article-x-face-too-ugly from
991 (not (string-match gnus-article-x-face-too-ugly
993 ;; Has to be present.
994 (re-search-forward "^X-Face: " nil t))
995 ;; This used to try to do multiple faces (`while' instead of
996 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
997 ;; work (b) it can crash some versions of Emacs (c) are
998 ;; multiple faces really something to encourage?
999 (when (stringp gnus-article-x-face-command)
1001 ;; We now have the area of the buffer where the X-Face is stored.
1004 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1005 ;; We display the face.
1006 (if (symbolp gnus-article-x-face-command)
1007 ;; The command is a lisp function, so we call it.
1008 (if (gnus-functionp gnus-article-x-face-command)
1009 (funcall gnus-article-x-face-command beg end)
1010 (error "%s is not a function" gnus-article-x-face-command))
1011 ;; The command is a string, so we interpret the command
1012 ;; as a, well, command, and fork it off.
1013 (let ((process-connection-type nil))
1014 (process-kill-without-query
1016 "article-x-face" nil shell-file-name shell-command-switch
1017 gnus-article-x-face-command))
1018 (process-send-region "article-x-face" beg end)
1019 (process-send-eof "article-x-face"))))))))))
1021 (defun article-decode-mime-words ()
1022 "Decode all MIME-encoded words in the article."
1025 (set-buffer gnus-article-buffer)
1026 (let ((inhibit-point-motion-hooks t)
1028 (rfc2047-default-charset gnus-newsgroup-default-charset)
1029 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1030 (mail-decode-encoded-word-region (point-min) (point-max)))))
1032 (defun article-decode-charset (&optional prompt)
1033 "Decode charset-encoded text in the article.
1034 If PROMPT (the prefix), prompt for a coding system to use."
1038 (message-narrow-to-head)
1039 (let* ((inhibit-point-motion-hooks t)
1040 (case-fold-search t)
1041 (ct (message-fetch-field "Content-Type" t))
1042 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1043 (ctl (and ct (condition-case ()
1044 (mail-header-parse-content-type ct)
1048 (mm-read-coding-system "Charset to decode: "))
1050 (mail-content-type-get ctl 'charset))))
1051 (rfc2047-default-charset gnus-newsgroup-default-charset)
1052 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1054 (goto-char (point-max))
1057 (narrow-to-region (point) (point-max))
1058 (when (and (or (not ctl)
1059 (equal (car ctl) "text/plain"))
1062 charset (and cte (intern (downcase
1063 (gnus-strip-whitespace cte))))
1066 (defun article-decode-encoded-words ()
1067 "Remove encoded-word encoding from headers."
1068 (let ((inhibit-point-motion-hooks t)
1070 (rfc2047-default-charset gnus-newsgroup-default-charset)
1071 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1073 (message-narrow-to-head)
1074 (funcall gnus-decode-header-function (point-min) (point-max)))))
1076 (defun article-de-quoted-unreadable (&optional force)
1077 "Translate a quoted-printable-encoded article.
1078 If FORCE, decode the article whether it is marked as quoted-printable
1080 (interactive (list 'force))
1082 (let ((buffer-read-only nil)
1083 (type (gnus-fetch-field "content-transfer-encoding"))
1085 (or gnus-newsgroup-default-charset mm-default-coding-system))
1086 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1088 (and type (string-match "quoted-printable" (downcase type))))
1091 (narrow-to-region (point) (point-max))
1092 (quoted-printable-decode-region (point-min) (point-max))
1094 (mm-decode-body charset)))))))
1096 (defun article-hide-pgp (&optional arg)
1097 "Toggle hiding of any PGP headers and signatures in the current article.
1098 If given a negative prefix, always show; if given a positive prefix,
1100 (interactive (gnus-article-hidden-arg))
1101 (unless (gnus-article-check-hidden-text 'pgp arg)
1103 (let ((inhibit-point-motion-hooks t)
1104 buffer-read-only beg end)
1106 (goto-char (point-min))
1107 ;; Hide the "header".
1108 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1109 (delete-region (1+ (match-beginning 0)) (match-end 0))
1110 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1111 (when (looking-at "Hash:.*$")
1112 (delete-region (point) (1+ (gnus-point-at-eol))))
1114 ;; Hide the actual signature.
1115 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1116 (setq end (1+ (match-beginning 0)))
1119 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1121 ;; Perhaps we shouldn't hide to the end of the buffer
1122 ;; if there is no end to the signature?
1124 ;; Hide "- " PGP quotation markers.
1126 (narrow-to-region beg end)
1127 (goto-char (point-min))
1128 (while (re-search-forward "^- " nil t)
1130 (match-beginning 0) (match-end 0)))
1132 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1134 (defun article-hide-pem (&optional arg)
1135 "Toggle hiding of any PEM headers and signatures in the current article.
1136 If given a negative prefix, always show; if given a positive prefix,
1138 (interactive (gnus-article-hidden-arg))
1139 (unless (gnus-article-check-hidden-text 'pem arg)
1141 (let (buffer-read-only end)
1143 (goto-char (point-min))
1144 ;; hide the horrendously ugly "header".
1145 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1148 (setq end (1+ (match-beginning 0)))
1149 (gnus-article-hide-text-type
1151 (if (search-forward "\n\n" nil t)
1155 ;; hide the trailer as well
1156 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1159 (gnus-article-hide-text-type
1160 (match-beginning 0) (match-end 0) 'pem))))))
1162 (defun article-hide-signature (&optional arg)
1163 "Hide the signature in the current article.
1164 If given a negative prefix, always show; if given a positive prefix,
1166 (interactive (gnus-article-hidden-arg))
1167 (unless (gnus-article-check-hidden-text 'signature arg)
1170 (let ((buffer-read-only nil))
1171 (when (gnus-article-narrow-to-signature)
1172 (gnus-article-hide-text-type
1173 (point-min) (point-max) 'signature)))))))
1175 (defun article-strip-leading-blank-lines ()
1176 "Remove all blank lines from the beginning of the article."
1179 (let ((inhibit-point-motion-hooks t)
1181 (when (article-goto-body)
1182 (while (and (not (eobp))
1183 (looking-at "[ \t]*$"))
1184 (gnus-delete-line))))))
1186 (defun article-goto-body ()
1187 "Place point at the start of the body."
1188 (goto-char (point-min))
1189 (if (search-forward "\n\n" nil t)
1191 (goto-char (point-max))
1194 (defun article-strip-multiple-blank-lines ()
1195 "Replace consecutive blank lines with one empty line."
1198 (let ((inhibit-point-motion-hooks t)
1200 ;; First make all blank lines empty.
1202 (while (re-search-forward "^[ \t]+$" nil t)
1203 (unless (gnus-annotation-in-region-p
1204 (match-beginning 0) (match-end 0))
1205 (replace-match "" nil t)))
1206 ;; Then replace multiple empty lines with a single empty line.
1208 (while (re-search-forward "\n\n\n+" nil t)
1209 (unless (gnus-annotation-in-region-p
1210 (match-beginning 0) (match-end 0))
1211 (replace-match "\n\n" t t))))))
1213 (defun article-strip-leading-space ()
1214 "Remove all white space from the beginning of the lines in the article."
1217 (let ((inhibit-point-motion-hooks t)
1220 (while (re-search-forward "^[ \t]+" nil t)
1221 (replace-match "" t t)))))
1223 (defun article-strip-trailing-space ()
1224 "Remove all white space from the end of the lines in the article."
1227 (let ((inhibit-point-motion-hooks t)
1230 (while (re-search-forward "[ \t]+$" nil t)
1231 (replace-match "" t t)))))
1233 (defun article-strip-blank-lines ()
1234 "Strip leading, trailing and multiple blank lines."
1236 (article-strip-leading-blank-lines)
1237 (article-remove-trailing-blank-lines)
1238 (article-strip-multiple-blank-lines))
1240 (defun article-strip-all-blank-lines ()
1241 "Strip all blank lines."
1244 (let ((inhibit-point-motion-hooks t)
1247 (while (re-search-forward "^[ \t]*\n" nil t)
1248 (replace-match "" t t)))))
1250 (defun gnus-article-narrow-to-signature ()
1251 "Narrow to the signature; return t if a signature is found, else nil."
1253 (let ((inhibit-point-motion-hooks t))
1254 (when (gnus-article-search-signature)
1256 ;; Check whether we have some limits to what we consider
1257 ;; to be a signature.
1258 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1259 (list gnus-signature-limit)))
1261 (while (setq limit (pop limits))
1262 (if (or (and (integerp limit)
1263 (< (- (point-max) (point)) limit))
1265 (< (count-lines (point) (point-max)) limit))
1266 (and (gnus-functionp limit)
1268 (and (stringp limit)
1269 (not (re-search-forward limit nil t))))
1270 () ; This limit did not succeed.
1274 (narrow-to-region (point) (point-max))
1277 (defun gnus-article-search-signature ()
1278 "Search the current buffer for the signature separator.
1279 Put point at the beginning of the signature separator."
1280 (let ((cur (point)))
1281 (goto-char (point-max))
1282 (if (if (stringp gnus-signature-separator)
1283 (re-search-backward gnus-signature-separator nil t)
1284 (let ((seps gnus-signature-separator))
1286 (not (re-search-backward (car seps) nil t)))
1294 (autoload 'w3-display "w3-parse")
1295 (autoload 'w3-do-setup "w3" "" t)
1296 (autoload 'w3-region "w3-display" "" t))
1298 (defun gnus-article-treat-html ()
1301 (let ((cbuf (current-buffer)))
1302 (set-buffer gnus-article-buffer)
1303 (let (buf buffer-read-only b e)
1305 (goto-char (point-min))
1307 (if (search-forward "\n\n" nil t)
1310 (setq e (point-max)))
1312 (insert-buffer-substring gnus-article-buffer b e)
1314 (save-window-excursion
1315 (w3-region (point-min) (point-max))
1316 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1318 (delete-region (point-min) (point-max))
1321 (goto-char (point-min))
1322 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1323 (set-buffer cbuf))))
1325 (defun gnus-article-hidden-arg ()
1326 "Return the current prefix arg as a number, or 0 if no prefix."
1327 (list (if current-prefix-arg
1328 (prefix-numeric-value current-prefix-arg)
1331 (defun gnus-article-check-hidden-text (type arg)
1332 "Return nil if hiding is necessary.
1333 Arg can be nil or a number. Nil and positive means hide, negative
1334 means show, 0 means toggle."
1338 (let ((hide (gnus-article-hidden-text-p type)))
1344 (gnus-article-show-hidden-text type))
1346 (if (eq hide 'hidden)
1347 (gnus-article-show-hidden-text type)
1350 (defun gnus-article-hidden-text-p (type)
1351 "Say whether the current buffer contains hidden text of type TYPE."
1352 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1354 (not (get-text-property pos 'invisible)))
1356 (text-property-any (1+ pos) (point-max) 'article-type type)))
1361 (defun gnus-article-show-hidden-text (type &optional hide)
1362 "Show all hidden text of type TYPE.
1363 If HIDE, hide the text instead."
1365 (let ((buffer-read-only nil)
1366 (inhibit-point-motion-hooks t)
1369 (while (setq beg (text-property-any end (point-max) 'article-type type))
1372 (text-property-not-all beg (point-max) 'article-type type)
1375 (gnus-article-hide-text beg end gnus-hidden-properties)
1376 (gnus-article-unhide-text beg end))
1380 (defconst article-time-units
1381 `((year . ,(* 365.25 24 60 60))
1382 (week . ,(* 7 24 60 60))
1383 (day . ,(* 24 60 60))
1387 "Mapping from time units to seconds.")
1389 (defun article-date-ut (&optional type highlight header)
1390 "Convert DATE date to universal time in the current article.
1391 If TYPE is `local', convert to local time; if it is `lapsed', output
1392 how much time has lapsed since DATE."
1393 (interactive (list 'ut t))
1394 (let* ((header (or header
1395 (mail-header-date gnus-current-headers)
1396 (message-fetch-field "date")
1398 (date (if (vectorp header) (mail-header-date header)
1400 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1401 (inhibit-point-motion-hooks t)
1402 bface eface newline)
1403 (when (and date (not (string= date "")))
1406 (nnheader-narrow-to-headers)
1407 (let ((buffer-read-only nil))
1408 ;; Delete any old Date headers.
1409 (if (re-search-forward date-regexp nil t)
1411 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1412 eface (get-text-property (1- (gnus-point-at-eol))
1414 (delete-region (progn (beginning-of-line) (point))
1415 (progn (end-of-line) (point)))
1416 (beginning-of-line))
1417 (goto-char (point-max))
1419 (insert (article-make-date-line date type))
1422 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1423 (put-text-property (match-beginning 1) (1+ (match-end 1))
1425 (put-text-property (match-beginning 2) (match-end 2)
1429 (insert "\n"))))))))
1431 (defun article-make-date-line (date type)
1432 "Return a DATE line of TYPE."
1433 (let ((time (condition-case ()
1437 ;; Convert to the local timezone. We have to slap a
1438 ;; `condition-case' round the calls to the timezone
1439 ;; functions since they aren't particularly resistant to
1442 (let ((tz (car (current-time-zone))))
1443 (format "Date: %s %s%04d" (current-time-string time)
1444 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1445 ;; Convert to Universal Time.
1448 (current-time-string
1449 (let* ((e (parse-time-string date))
1450 (tm (apply 'encode-time e))
1452 (ls (- (cadr tm) (car (current-time-zone)))))
1453 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1454 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1457 ;; Get the original date from the article.
1458 ((eq type 'original)
1459 (concat "Date: " (if (string-match "\n+$" date)
1460 (substring date 0 (match-beginning 0))
1462 ;; Let the user define the format.
1464 (if (gnus-functionp gnus-article-time-format)
1465 (funcall gnus-article-time-format time)
1468 (format-time-string gnus-article-time-format time))))
1473 (format-time-string "%Y%M%DT%h%m%s" time)))
1474 ;; Do an X-Sent lapsed format.
1476 ;; If the date is seriously mangled, the timezone functions are
1477 ;; liable to bug out, so we ignore all errors.
1478 (let* ((now (current-time))
1479 (real-time (subtract-time now time))
1480 (real-sec (and real-time
1481 (+ (* (float (car real-time)) 65536)
1483 (sec (and real-time (abs real-sec)))
1493 ;; This is a bit convoluted, but basically we go
1494 ;; through the time units for years, weeks, etc,
1495 ;; and divide things to see whether that results
1496 ;; in positive answers.
1499 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1500 ;; The (remaining) seconds are too few to
1501 ;; be divided into this time unit.
1503 ;; It's big enough, so we output it.
1504 (setq sec (- sec (* num (cdr unit))))
1506 (concat (if prev ", " "") (int-to-string
1508 " " (symbol-name (car unit))
1509 (if (> num 1) "s" ""))
1511 article-time-units "")
1512 ;; If dates are odd, then it might appear like the
1513 ;; article was sent in the future.
1516 " in the future"))))))
1518 (error "Unknown conversion type: %s" type)))))
1520 (defun article-date-local (&optional highlight)
1521 "Convert the current article date to the local timezone."
1522 (interactive (list t))
1523 (article-date-ut 'local highlight))
1525 (defun article-date-original (&optional highlight)
1526 "Convert the current article date to what it was originally.
1527 This is only useful if you have used some other date conversion
1528 function and want to see what the date was before converting."
1529 (interactive (list t))
1530 (article-date-ut 'original highlight))
1532 (defun article-date-lapsed (&optional highlight)
1533 "Convert the current article date to time lapsed since it was sent."
1534 (interactive (list t))
1535 (article-date-ut 'lapsed highlight))
1537 (defun article-update-date-lapsed ()
1538 "Function to be run from a timer to update the lapsed time line."
1539 (let (deactivate-mark)
1544 (set-buffer (window-buffer w))
1545 (when (eq major-mode 'gnus-article-mode)
1546 (goto-char (point-min))
1547 (when (re-search-forward "^X-Sent:" nil t)
1548 (article-date-lapsed t)))))))))
1550 (defun gnus-start-date-timer (&optional n)
1551 "Start a timer to update the X-Sent header in the article buffers.
1552 The numerical prefix says how frequently (in seconds) the function
1557 (gnus-stop-date-timer)
1558 (setq article-lapsed-timer
1559 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1561 (defun gnus-stop-date-timer ()
1562 "Stop the X-Sent timer."
1564 (when article-lapsed-timer
1565 (nnheader-cancel-timer article-lapsed-timer)
1566 (setq article-lapsed-timer nil)))
1568 (defun article-date-user (&optional highlight)
1569 "Convert the current article date to the user-defined format.
1570 This format is defined by the `gnus-article-time-format' variable."
1571 (interactive (list t))
1572 (article-date-ut 'user highlight))
1574 (defun article-date-iso8601 (&optional highlight)
1575 "Convert the current article date to ISO8601."
1576 (interactive (list t))
1577 (article-date-ut 'iso8601 highlight))
1579 (defun article-show-all ()
1580 "Show all hidden text in the article buffer."
1583 (let ((buffer-read-only nil))
1584 (gnus-article-unhide-text (point-min) (point-max)))))
1586 (defun article-emphasize (&optional arg)
1587 "Emphasize text according to `gnus-emphasis-alist'."
1588 (interactive (gnus-article-hidden-arg))
1589 (unless (gnus-article-check-hidden-text 'emphasis arg)
1591 (let ((alist gnus-emphasis-alist)
1592 (buffer-read-only nil)
1593 (props (append '(article-type emphasis)
1594 gnus-hidden-properties))
1595 regexp elem beg invisible visible face)
1598 (while (setq elem (pop alist))
1600 (setq regexp (car elem)
1601 invisible (nth 1 elem)
1602 visible (nth 2 elem)
1604 (while (re-search-forward regexp nil t)
1605 (when (and (match-beginning visible) (match-beginning invisible))
1606 (gnus-article-hide-text
1607 (match-beginning invisible) (match-end invisible) props)
1608 (gnus-article-unhide-text-type
1609 (match-beginning visible) (match-end visible) 'emphasis)
1610 (gnus-put-text-property-excluding-newlines
1611 (match-beginning visible) (match-end visible) 'face face)
1612 (goto-char (match-end invisible)))))))))
1614 (defvar gnus-summary-article-menu)
1615 (defvar gnus-summary-post-menu)
1617 ;;; Saving functions.
1619 (defun gnus-article-save (save-buffer file &optional num)
1620 "Save the currently selected article."
1621 (unless gnus-save-all-headers
1622 ;; Remove headers according to `gnus-saved-headers'.
1623 (let ((gnus-visible-headers
1624 (or gnus-saved-headers gnus-visible-headers))
1625 (gnus-article-buffer save-buffer))
1627 (set-buffer save-buffer)
1628 (article-hide-headers 1 t))))
1629 (save-window-excursion
1630 (if (not gnus-default-article-saver)
1631 (error "No default saver is defined")
1632 ;; !!! Magic! The saving functions all save
1633 ;; `gnus-save-article-buffer' (or so they think), but we
1634 ;; bind that variable to our save-buffer.
1635 (set-buffer gnus-article-buffer)
1636 (let* ((gnus-save-article-buffer save-buffer)
1639 ((not gnus-prompt-before-saving) 'default)
1640 ((eq gnus-prompt-before-saving 'always) nil)
1642 (gnus-number-of-articles-to-be-saved
1643 (when (eq gnus-prompt-before-saving t)
1645 (set-buffer gnus-article-current-summary)
1646 (funcall gnus-default-article-saver filename)))))
1648 (defun gnus-read-save-file-name (prompt &optional filename
1649 function group headers variable)
1651 (funcall function group headers (symbol-value variable)))
1656 ((eq filename 'default)
1662 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1665 (if (and gnus-number-of-articles-to-be-saved
1666 (> gnus-number-of-articles-to-be-saved 1))
1667 (format "these %d articles"
1668 gnus-number-of-articles-to-be-saved)
1671 ;; Let the split methods have their say.
1673 ;; No split name was found.
1676 (concat prompt " (default "
1677 (file-name-nondirectory default-name) ") ")
1678 (file-name-directory default-name)
1680 ;; A single group name is returned.
1681 ((stringp split-name)
1683 (funcall function split-name headers
1684 (symbol-value variable)))
1686 (concat prompt " (default "
1687 (file-name-nondirectory default-name) ") ")
1688 (file-name-directory default-name)
1690 ;; A single split name was found
1691 ((= 1 (length split-name))
1692 (let* ((name (expand-file-name
1693 (car split-name) gnus-article-save-directory))
1694 (dir (cond ((file-directory-p name)
1695 (file-name-as-directory name))
1696 ((file-exists-p name) name)
1697 (t gnus-article-save-directory))))
1699 (concat prompt " (default " name ") ")
1701 ;; A list of splits was found.
1703 (setq split-name (nreverse split-name))
1705 (let ((file-name-history
1706 (nconc split-name file-name-history)))
1710 (concat prompt " (`M-p' for defaults) ")
1711 gnus-article-save-directory
1713 gnus-article-save-directory)))
1714 (car (push result file-name-history)))))))
1715 ;; Create the directory.
1716 (gnus-make-directory (file-name-directory file))
1717 ;; If we have read a directory, we append the default file name.
1718 (when (file-directory-p file)
1719 (setq file (concat (file-name-as-directory file)
1720 (file-name-nondirectory default-name))))
1721 ;; Possibly translate some characters.
1722 (nnheader-translate-file-chars file)))))
1723 (gnus-make-directory (file-name-directory result))
1724 (set variable result)))
1726 (defun gnus-article-archive-name (group)
1727 "Return the first instance of an \"Archive-name\" in the current buffer."
1728 (let ((case-fold-search t))
1729 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1730 (nnheader-concat gnus-article-save-directory
1731 (match-string 1)))))
1733 (defun gnus-article-nndoc-name (group)
1734 "If GROUP is an nndoc group, return the name of the parent group."
1735 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1736 (gnus-group-get-parameter group 'save-article-group)))
1738 (defun gnus-summary-save-in-rmail (&optional filename)
1739 "Append this article to Rmail file.
1740 Optional argument FILENAME specifies file name.
1741 Directory to save to is default to `gnus-article-save-directory'."
1742 (setq filename (gnus-read-save-file-name
1743 "Save %s in rmail file:" filename
1744 gnus-rmail-save-name gnus-newsgroup-name
1745 gnus-current-headers 'gnus-newsgroup-last-rmail))
1746 (gnus-eval-in-buffer-window gnus-save-article-buffer
1750 (gnus-output-to-rmail filename))))
1753 (defun gnus-summary-save-in-mail (&optional filename)
1754 "Append this article to Unix mail file.
1755 Optional argument FILENAME specifies file name.
1756 Directory to save to is default to `gnus-article-save-directory'."
1757 (setq filename (gnus-read-save-file-name
1758 "Save %s in Unix mail file:" filename
1759 gnus-mail-save-name gnus-newsgroup-name
1760 gnus-current-headers 'gnus-newsgroup-last-mail))
1761 (gnus-eval-in-buffer-window gnus-save-article-buffer
1765 (if (and (file-readable-p filename)
1766 (mail-file-babyl-p filename))
1767 (rmail-output-to-rmail-file filename t)
1768 (gnus-output-to-mail filename)))))
1771 (defun gnus-summary-save-in-file (&optional filename overwrite)
1772 "Append this article to file.
1773 Optional argument FILENAME specifies file name.
1774 Directory to save to is default to `gnus-article-save-directory'."
1775 (setq filename (gnus-read-save-file-name
1776 "Save %s in file:" filename
1777 gnus-file-save-name gnus-newsgroup-name
1778 gnus-current-headers 'gnus-newsgroup-last-file))
1779 (gnus-eval-in-buffer-window gnus-save-article-buffer
1783 (when (and overwrite
1784 (file-exists-p filename))
1785 (delete-file filename))
1786 (gnus-output-to-file filename))))
1789 (defun gnus-summary-write-to-file (&optional filename)
1790 "Write this article to a file.
1791 Optional argument FILENAME specifies file name.
1792 The directory to save in defaults to `gnus-article-save-directory'."
1793 (gnus-summary-save-in-file nil t))
1795 (defun gnus-summary-save-body-in-file (&optional filename)
1796 "Append this article body to a file.
1797 Optional argument FILENAME specifies file name.
1798 The directory to save in defaults to `gnus-article-save-directory'."
1799 (setq filename (gnus-read-save-file-name
1800 "Save %s body in file:" filename
1801 gnus-file-save-name gnus-newsgroup-name
1802 gnus-current-headers 'gnus-newsgroup-last-file))
1803 (gnus-eval-in-buffer-window gnus-save-article-buffer
1807 (when (article-goto-body)
1808 (narrow-to-region (point) (point-max)))
1809 (gnus-output-to-file filename))))
1812 (defun gnus-summary-save-in-pipe (&optional command)
1813 "Pipe this article to subprocess."
1815 (cond ((and (eq command 'default)
1816 gnus-last-shell-command)
1817 gnus-last-shell-command)
1821 "Shell command on %s: "
1822 (if (and gnus-number-of-articles-to-be-saved
1823 (> gnus-number-of-articles-to-be-saved 1))
1824 (format "these %d articles"
1825 gnus-number-of-articles-to-be-saved)
1827 gnus-last-shell-command))))
1828 (when (string-equal command "")
1829 (setq command gnus-last-shell-command))
1830 (gnus-eval-in-buffer-window gnus-article-buffer
1833 (shell-command-on-region (point-min) (point-max) command nil)))
1834 (setq gnus-last-shell-command command))
1836 ;;; Article file names when saving.
1838 (defun gnus-capitalize-newsgroup (newsgroup)
1839 "Capitalize NEWSGROUP name."
1840 (when (not (zerop (length newsgroup)))
1841 (concat (char-to-string (upcase (aref newsgroup 0)))
1842 (substring newsgroup 1))))
1844 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1845 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1846 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1847 Otherwise, it is like ~/News/news/group/num."
1850 (concat (if (gnus-use-long-file-name 'not-save)
1851 (gnus-capitalize-newsgroup newsgroup)
1852 (gnus-newsgroup-directory-form newsgroup))
1853 "/" (int-to-string (mail-header-number headers)))
1854 gnus-article-save-directory)))
1856 (string-equal (file-name-directory default)
1857 (file-name-directory last-file))
1858 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1860 (or last-file default))))
1862 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1863 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1864 If variable `gnus-use-long-file-name' is non-nil, it is
1865 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1868 (concat (if (gnus-use-long-file-name 'not-save)
1870 (gnus-newsgroup-directory-form newsgroup))
1871 "/" (int-to-string (mail-header-number headers)))
1872 gnus-article-save-directory)))
1874 (string-equal (file-name-directory default)
1875 (file-name-directory last-file))
1876 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1878 (or last-file default))))
1880 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1881 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1882 If variable `gnus-use-long-file-name' is non-nil, it is
1883 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1886 (if (gnus-use-long-file-name 'not-save)
1887 (gnus-capitalize-newsgroup newsgroup)
1888 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1889 gnus-article-save-directory)))
1891 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1892 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1893 If variable `gnus-use-long-file-name' is non-nil, it is
1894 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1897 (if (gnus-use-long-file-name 'not-save)
1899 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1900 gnus-article-save-directory)))
1907 (setq afunc (car func)
1910 gfunc (intern (format "gnus-%s" func))))
1912 (if (not (fboundp afunc))
1914 `(lambda (&optional interactive &rest args)
1915 ,(documentation afunc t)
1916 (interactive (list t))
1918 (set-buffer gnus-article-buffer)
1920 (call-interactively ',afunc)
1921 (apply ',afunc args))))))))
1922 '(article-hide-headers
1923 article-hide-boring-headers
1924 article-treat-overstrike
1925 (article-fill . gnus-article-word-wrap)
1927 article-display-x-face
1928 article-de-quoted-unreadable
1929 article-mime-decode-quoted-printable
1932 article-hide-signature
1933 article-remove-trailing-blank-lines
1934 article-strip-leading-blank-lines
1935 article-strip-multiple-blank-lines
1936 article-strip-leading-space
1937 article-strip-trailing-space
1938 article-strip-blank-lines
1939 article-strip-all-blank-lines
1941 article-date-iso8601
1942 article-date-original
1944 article-decode-mime-words
1945 article-decode-charset
1946 article-decode-encoded-words
1950 article-treat-dumbquotes
1951 (article-show-all . gnus-article-show-all-headers))))
1954 ;;; Gnus article mode
1957 (put 'gnus-article-mode 'mode-class 'special)
1959 (set-keymap-parent gnus-article-mode-map widget-keymap)
1961 (gnus-define-keys gnus-article-mode-map
1962 " " gnus-article-goto-next-page
1963 "\177" gnus-article-goto-prev-page
1964 [delete] gnus-article-goto-prev-page
1965 "\C-c^" gnus-article-refer-article
1966 "h" gnus-article-show-summary
1967 "s" gnus-article-show-summary
1968 "\C-c\C-m" gnus-article-mail
1969 "?" gnus-article-describe-briefly
1970 "e" gnus-article-edit
1971 "<" beginning-of-buffer
1973 "\C-c\C-i" gnus-info-find-node
1976 "\C-d" gnus-article-read-summary-keys
1977 "\M-*" gnus-article-read-summary-keys
1978 "\M-#" gnus-article-read-summary-keys
1979 "\M-^" gnus-article-read-summary-keys
1980 "\M-g" gnus-article-read-summary-keys)
1982 (substitute-key-definition
1983 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1985 (defun gnus-article-make-menu-bar ()
1986 (gnus-turn-off-edit-menu 'article)
1987 (unless (boundp 'gnus-article-article-menu)
1989 gnus-article-article-menu gnus-article-mode-map ""
1991 ["Scroll forwards" gnus-article-goto-next-page t]
1992 ["Scroll backwards" gnus-article-goto-prev-page t]
1993 ["Show summary" gnus-article-show-summary t]
1994 ["Fetch Message-ID at point" gnus-article-refer-article t]
1995 ["Mail to address at point" gnus-article-mail t]
1996 ["Send a bug report" gnus-bug t]))
1999 gnus-article-treatment-menu gnus-article-mode-map ""
2001 ["Hide headers" gnus-article-hide-headers t]
2002 ["Hide signature" gnus-article-hide-signature t]
2003 ["Hide citation" gnus-article-hide-citation t]
2004 ["Treat overstrike" gnus-article-treat-overstrike t]
2005 ["Remove carriage return" gnus-article-remove-cr t]
2006 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2008 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2010 (when (boundp 'gnus-summary-post-menu)
2011 (define-key gnus-article-mode-map [menu-bar post]
2012 (cons "Post" gnus-summary-post-menu)))
2014 (gnus-run-hooks 'gnus-article-menu-hook)))
2016 (defun gnus-article-mode ()
2017 "Major mode for displaying an article.
2019 All normal editing commands are switched off.
2021 The following commands are available in addition to all summary mode
2023 \\<gnus-article-mode-map>
2024 \\[gnus-article-next-page]\t Scroll the article one page forwards
2025 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2026 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2027 \\[gnus-article-show-summary]\t Display the summary buffer
2028 \\[gnus-article-mail]\t Send a reply to the address near point
2029 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2030 \\[gnus-info-find-node]\t Go to the Gnus info node"
2032 (when (gnus-visual-p 'article-menu 'menu)
2033 (gnus-article-make-menu-bar))
2034 (gnus-simplify-mode-line)
2035 (setq mode-name "Article")
2036 (setq major-mode 'gnus-article-mode)
2037 (make-local-variable 'minor-mode-alist)
2038 (use-local-map gnus-article-mode-map)
2039 (gnus-update-format-specifications nil 'article-mode)
2040 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2041 (make-local-variable 'gnus-page-broken)
2042 (make-local-variable 'gnus-button-marker-list)
2043 (make-local-variable 'gnus-article-current-summary)
2044 (make-local-variable 'gnus-article-mime-handles)
2045 (make-local-variable 'gnus-article-decoded-p)
2046 (make-local-variable 'gnus-article-mime-handle-alist)
2047 (gnus-set-default-directory)
2048 (buffer-disable-undo)
2049 (setq buffer-read-only t)
2050 (set-syntax-table gnus-article-mode-syntax-table)
2051 (mm-enable-multibyte)
2052 (gnus-run-hooks 'gnus-article-mode-hook))
2054 (defun gnus-article-setup-buffer ()
2055 "Initialize the article buffer."
2056 (let* ((name (if gnus-single-article-buffer "*Article*"
2057 (concat "*Article " gnus-newsgroup-name "*")))
2059 (progn (string-match "\\*Article" name)
2060 (concat " *Original Article"
2061 (substring name (match-end 0))))))
2062 (setq gnus-article-buffer name)
2063 (setq gnus-original-article-buffer original)
2064 (setq gnus-article-mime-handle-alist nil)
2065 ;; This might be a variable local to the summary buffer.
2066 (unless gnus-single-article-buffer
2068 (set-buffer gnus-summary-buffer)
2069 (setq gnus-article-buffer name)
2070 (setq gnus-original-article-buffer original)
2071 (gnus-set-global-variables)))
2072 ;; Init original article buffer.
2074 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2075 (mm-enable-multibyte)
2076 (setq major-mode 'gnus-original-article-mode)
2077 (make-local-variable 'gnus-original-article))
2078 (if (get-buffer name)
2081 (buffer-disable-undo)
2082 (setq buffer-read-only t)
2083 (unless (eq major-mode 'gnus-article-mode)
2084 (gnus-article-mode))
2087 (set-buffer (gnus-get-buffer-create name))
2089 (make-local-variable 'gnus-summary-buffer)
2090 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2091 (current-buffer)))))
2093 ;; Set article window start at LINE, where LINE is the number of lines
2094 ;; from the head of the article.
2095 (defun gnus-article-set-window-start (&optional line)
2097 (get-buffer-window gnus-article-buffer t)
2099 (set-buffer gnus-article-buffer)
2100 (goto-char (point-min))
2103 (gnus-message 6 "Moved to bookmark")
2104 (search-forward "\n\n" nil t)
2108 (defun gnus-article-prepare (article &optional all-headers header)
2109 "Prepare ARTICLE in article mode buffer.
2110 ARTICLE should either be an article number or a Message-ID.
2111 If ARTICLE is an id, HEADER should be the article headers.
2112 If ALL-HEADERS is non-nil, no headers are hidden."
2114 ;; Make sure we start in a summary buffer.
2115 (unless (eq major-mode 'gnus-summary-mode)
2116 (set-buffer gnus-summary-buffer))
2117 (setq gnus-summary-buffer (current-buffer))
2118 (let* ((gnus-article (if header (mail-header-number header) article))
2119 (summary-buffer (current-buffer))
2120 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2121 (group gnus-newsgroup-name)
2124 (gnus-article-setup-buffer)
2125 (set-buffer gnus-article-buffer)
2126 ;; Deactivate active regions.
2127 (when (and (boundp 'transient-mark-mode)
2128 transient-mark-mode)
2129 (setq mark-active nil))
2130 (if (not (setq result (let ((buffer-read-only nil))
2131 (gnus-request-article-this-buffer
2133 ;; There is no such article.
2135 (when (and (numberp article)
2136 (not (memq article gnus-newsgroup-sparse)))
2137 (setq gnus-article-current
2138 (cons gnus-newsgroup-name article))
2139 (set-buffer gnus-summary-buffer)
2140 (setq gnus-current-article article)
2141 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2143 (gnus-summary-set-agent-mark article)
2144 (message "Message marked for downloading"))
2145 (gnus-summary-mark-article article gnus-canceled-mark)
2146 (unless (memq article gnus-newsgroup-sparse)
2148 "No such article (may have expired or been canceled)")))))
2149 (if (or (eq result 'pseudo)
2150 (eq result 'nneething))
2153 (set-buffer summary-buffer)
2154 (push article gnus-newsgroup-history)
2155 (setq gnus-last-article gnus-current-article
2156 gnus-current-article 0
2157 gnus-current-headers nil
2158 gnus-article-current nil)
2159 (if (eq result 'nneething)
2160 (gnus-configure-windows 'summary)
2161 (gnus-configure-windows 'article))
2162 (gnus-set-global-variables))
2163 (let ((gnus-article-mime-handle-alist-1
2164 gnus-article-mime-handle-alist))
2165 (gnus-set-mode-line 'article)))
2166 ;; The result from the `request' was an actual article -
2167 ;; or at least some text that is now displayed in the
2169 (when (and (numberp article)
2170 (not (eq article gnus-current-article)))
2171 ;; Seems like a new article has been selected.
2172 ;; `gnus-current-article' must be an article number.
2174 (set-buffer summary-buffer)
2175 (push article gnus-newsgroup-history)
2176 (setq gnus-last-article gnus-current-article
2177 gnus-current-article article
2178 gnus-current-headers
2179 (gnus-summary-article-header gnus-current-article)
2180 gnus-article-current
2181 (cons gnus-newsgroup-name gnus-current-article))
2182 (unless (vectorp gnus-current-headers)
2183 (setq gnus-current-headers nil))
2184 (gnus-summary-goto-subject gnus-current-article)
2185 (when (gnus-summary-show-thread)
2186 ;; If the summary buffer really was folded, the
2187 ;; previous goto may not actually have gone to
2188 ;; the right article, but the thread root instead.
2190 (gnus-summary-goto-subject gnus-current-article))
2191 (gnus-run-hooks 'gnus-mark-article-hook)
2192 (gnus-set-mode-line 'summary)
2193 (when (gnus-visual-p 'article-highlight 'highlight)
2194 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2195 ;; Set the global newsgroup variables here.
2196 ;; Suggested by Jim Sisolak
2197 ;; <sisolak@trans4.neep.wisc.edu>.
2198 (gnus-set-global-variables)
2199 (setq gnus-have-all-headers
2200 (or all-headers gnus-show-all-headers))))
2201 (when (or (numberp article)
2203 (gnus-article-prepare-display)
2205 (goto-char (point-min))
2206 (setq gnus-page-broken
2207 (when gnus-break-pages
2208 (gnus-narrow-to-page)
2210 (let ((gnus-article-mime-handle-alist-1
2211 gnus-article-mime-handle-alist))
2212 (gnus-set-mode-line 'article))
2213 (gnus-configure-windows 'article)
2215 (set-window-point (get-buffer-window (current-buffer)) (point))
2218 (defun gnus-article-prepare-display ()
2219 "Make the current buffer look like a nice article."
2220 ;; Hooks for getting information from the article.
2221 ;; This hook must be called before being narrowed.
2222 (let ((gnus-article-buffer (current-buffer))
2224 (unless (eq major-mode 'gnus-article-mode)
2225 (gnus-article-mode))
2226 (setq buffer-read-only nil)
2227 (gnus-run-hooks 'gnus-tmp-internal-hook)
2228 (gnus-run-hooks 'gnus-article-prepare-hook)
2229 (when gnus-display-mime-function
2230 (let ((url-standalone-mode (not gnus-plugged)))
2231 (funcall gnus-display-mime-function)))
2232 ;; Perform the article display hooks.
2233 (gnus-run-hooks 'gnus-article-display-hook)))
2236 ;;; Gnus MIME viewing functions
2239 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2240 "The following specs can be used:
2242 %n The `name' parameter
2243 %d The description, if any
2244 %l The length of the encoded part
2245 %p The part identifier
2246 %e Dots if the part isn't displayed")
2248 (defvar gnus-mime-button-line-format-alist
2249 '((?t gnus-tmp-type ?s)
2250 (?n gnus-tmp-name ?s)
2251 (?d gnus-tmp-description ?s)
2253 (?l gnus-tmp-length ?d)
2254 (?e gnus-tmp-dots ?s)))
2256 (defvar gnus-mime-button-commands
2257 '((gnus-article-press-button "\r" "Toggle Display")
2258 ;(gnus-mime-view-part "\M-\r" "View Interactively...")
2259 (gnus-mime-view-part "v" "View Interactively...")
2260 (gnus-mime-save-part "o" "Save...")
2261 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2262 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2263 (gnus-mime-externalize-part "e" "View Externally")
2264 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2266 (defun gnus-article-mime-part-status ()
2267 (if gnus-article-mime-handle-alist-1
2268 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2271 (defvar gnus-mime-button-map nil)
2272 (unless gnus-mime-button-map
2273 (setq gnus-mime-button-map (make-sparse-keymap))
2274 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2275 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2276 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2278 (define-key gnus-mime-button-map (cadr c) (car c)))
2279 gnus-mime-button-commands))
2281 (defun gnus-mime-button-menu (event)
2282 "Construct a context-sensitive menu of MIME commands."
2284 (gnus-article-check-buffer)
2285 (let ((response (x-popup-menu
2287 ("" ,@(mapcar (lambda (c)
2288 (cons (caddr c) (car c)))
2289 gnus-mime-button-commands)))))
2290 (pos (event-start event)))
2292 (set-buffer (window-buffer (posn-window pos)))
2293 (goto-char (posn-point pos))
2294 (funcall response))))
2296 (defun gnus-mime-view-all-parts ()
2297 "View all the MIME parts."
2299 (save-current-buffer
2300 (set-buffer gnus-article-buffer)
2301 (let ((handles gnus-article-mime-handles)
2302 (rfc2047-default-charset gnus-newsgroup-default-charset)
2303 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2305 (mm-display-part (pop handles))))))
2307 (defun gnus-mime-save-part ()
2308 "Save the MIME part under point."
2310 (gnus-article-check-buffer)
2311 (let ((data (get-text-property (point) 'gnus-data)))
2312 (mm-save-part data)))
2314 (defun gnus-mime-pipe-part ()
2315 "Pipe the MIME part under point to a process."
2317 (gnus-article-check-buffer)
2318 (let ((data (get-text-property (point) 'gnus-data)))
2319 (mm-pipe-part data)))
2321 (defun gnus-mime-view-part ()
2322 "Interactively choose a view method for the MIME part under point."
2324 (gnus-article-check-buffer)
2325 (let ((data (get-text-property (point) 'gnus-data))
2326 ;(url-standalone-mode (not gnus-plugged))
2328 (mm-interactively-view-part data)))
2330 (defun gnus-mime-copy-part (&optional handle)
2331 "Put the the MIME part under point into a new buffer."
2333 (gnus-article-check-buffer)
2334 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2335 (contents (mm-get-part handle))
2336 (buffer (generate-new-buffer
2337 (file-name-nondirectory
2339 (mail-content-type-get (mm-handle-type handle) 'name)
2340 (mail-content-type-get (mm-handle-type handle)
2343 (switch-to-buffer buffer)
2346 (goto-char (point-min))))
2348 (defun gnus-mime-inline-part (&optional charset)
2349 "Insert the MIME part under point into the current buffer."
2350 (interactive "P") ; For compatibility reasons we are not using "z".
2351 (gnus-article-check-buffer)
2352 (let* ((data (get-text-property (point) 'gnus-data))
2353 (contents (mm-get-part data))
2354 ;(url-standalone-mode (not gnus-plugged))
2357 (if (mm-handle-undisplayer data)
2358 (mm-remove-part data)
2361 (unless (symbolp charset)
2362 (setq charset (mm-read-coding-system "Charset: ")))
2363 (setq contents (mm-decode-coding-string contents charset)))
2364 (mm-insert-inline data contents)
2367 (defun gnus-mime-externalize-part (&optional handle)
2368 "Insert the MIME part under point into the current buffer."
2370 (gnus-article-check-buffer)
2371 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2372 ;(url-standalone-mode (not gnus-plugged))
2373 (mm-user-display-methods nil)
2374 (rfc2047-default-charset gnus-newsgroup-default-charset)
2375 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2376 (if (mm-handle-undisplayer handle)
2377 (mm-remove-part handle)
2378 (mm-display-part handle))))
2380 (defun gnus-article-part-wrapper (n function)
2381 (save-current-buffer
2382 (set-buffer gnus-article-buffer)
2383 (when (> n (length gnus-article-mime-handle-alist))
2384 (error "No such part"))
2385 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2386 (funcall function handle))))
2388 (defun gnus-article-pipe-part (n)
2389 "Pipe MIME part N, which is the numerical prefix."
2391 (gnus-article-part-wrapper n 'mm-pipe-part))
2393 (defun gnus-article-save-part (n)
2394 "Save MIME part N, which is the numerical prefix."
2396 (gnus-article-part-wrapper n 'mm-save-part))
2398 (defun gnus-article-interactively-view-part (n)
2399 "Pipe MIME part N, which is the numerical prefix."
2401 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2403 (defun gnus-article-copy-part (n)
2404 "Pipe MIME part N, which is the numerical prefix."
2406 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2408 (defun gnus-article-externalize-part (n)
2409 "Pipe MIME part N, which is the numerical prefix."
2411 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2413 (defun gnus-article-view-part (n)
2414 "View MIME part N, which is the numerical prefix."
2416 (save-current-buffer
2417 (set-buffer gnus-article-buffer)
2418 (when (> n (length gnus-article-mime-handle-alist))
2419 (error "No such part"))
2420 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2421 (when (gnus-article-goto-part n)
2422 (if (equal (car handle) "multipart/alternative")
2423 (gnus-article-press-button)
2424 (when (eq (gnus-mm-display-part handle) 'internal)
2425 (gnus-set-window-start)))))))
2427 (defun gnus-mm-display-part (handle)
2428 "Display HANDLE and fix MIME button."
2429 (let ((id (get-text-property (point) 'gnus-part))
2432 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2433 (gnus-insert-mime-button
2434 handle id (list (not (mm-handle-displayed-p handle))))
2436 (let ((window (selected-window))
2437 (rfc2047-default-charset gnus-newsgroup-default-charset)
2438 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2441 (let ((win (get-buffer-window (current-buffer) t)))
2443 (select-window win))
2446 (mm-display-part handle))
2447 (select-window window))))
2448 (goto-char point))))
2450 (defun gnus-article-goto-part (n)
2451 "Go to MIME part N."
2452 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2454 (goto-char point))))
2456 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2457 (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2458 (gnus-tmp-type (car (mm-handle-type handle)))
2459 (gnus-tmp-description (mm-handle-description handle))
2461 (if (if displayed (car displayed)
2462 (mm-handle-displayed-p handle))
2464 (gnus-tmp-length (save-excursion
2465 (set-buffer (mm-handle-buffer handle))
2470 (concat " (" gnus-tmp-name ")")
2472 (setq gnus-tmp-description
2473 (if gnus-tmp-description
2474 (concat " (" gnus-tmp-description ")")
2480 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2481 `(local-map ,gnus-mime-button-map
2482 keymap ,gnus-mime-button-map
2483 gnus-callback gnus-mm-display-part
2484 gnus-part ,gnus-tmp-id
2485 article-type annotation
2488 (widget-convert-button 'link b e :action 'gnus-widget-press-button
2489 :button-keymap gnus-mime-button-map)))
2491 (defun gnus-widget-press-button (elems el)
2492 (goto-char (widget-get elems :from))
2493 (let ((url-standalone-mode (not gnus-plugged)))
2494 (gnus-article-press-button)))
2496 (defun gnus-display-mime (&optional ihandles)
2497 "Insert MIME buttons in the buffer."
2499 (save-selected-window
2500 (let ((window (get-buffer-window gnus-article-buffer)))
2502 (select-window window)))
2503 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2504 handle name type b e display)
2506 ;; Top-level call; we clean up.
2507 (mm-destroy-parts gnus-article-mime-handles)
2508 (setq gnus-article-mime-handles handles
2509 gnus-article-mime-handle-alist nil)
2510 ;; We allow users to glean info from the handles.
2511 (when gnus-article-mime-part-function
2512 (gnus-mime-part-function handles)))
2514 (or (not (stringp (car handles)))
2517 ;; Clean up for mime parts.
2519 (delete-region (point) (point-max)))
2520 (gnus-mime-display-part handles))))))
2522 (defun gnus-mime-display-part (handle)
2525 ((not (stringp (car handle)))
2526 (gnus-mime-display-single handle))
2527 ;; multipart/alternative
2528 ((equal (car handle) "multipart/alternative")
2529 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2530 (push (cons id handle) gnus-article-mime-handle-alist)
2531 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2532 ;; multipart/related
2533 ((equal (car handle) "multipart/related")
2534 ;;;!!!We should find the start part, but we just default
2535 ;;;!!!to the first part.
2536 (gnus-mime-display-part (cadr handle)))
2537 ;; Other multiparts are handled like multipart/mixed.
2539 (gnus-mime-display-mixed (cdr handle)))))
2541 (defun gnus-mime-part-function (handles)
2542 (if (stringp (car handles))
2543 (mapcar 'gnus-mime-part-function (cdr handles))
2544 (funcall gnus-article-mime-part-function handles)))
2546 (defun gnus-mime-display-mixed (handles)
2548 (while (setq handle (pop handles))
2549 (gnus-mime-display-part handle))))
2551 (defun gnus-mime-display-single (handle)
2552 (let ((type (car (mm-handle-type handle)))
2553 (ignored gnus-ignored-mime-types)
2559 (when (string-match (pop ignored) type)
2560 (throw 'ignored nil)))
2561 (if (and (mm-automatic-display-p type)
2562 (mm-inlinable-part-p type)
2563 (setq not-attachment
2564 (or (not (mm-handle-disposition handle))
2565 (equal (car (mm-handle-disposition handle))
2568 (when (equal (car (split-string type "/"))
2571 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2572 (push (cons id handle) gnus-article-mime-handle-alist)
2573 (when (or (not display)
2574 (not (gnus-unbuttonized-mime-type-p type)))
2575 (gnus-article-insert-newline)
2576 (gnus-insert-mime-button
2577 handle id (list (or display
2578 (and (not not-attachment) text))))
2579 (gnus-article-insert-newline)))
2580 (gnus-article-insert-newline)
2584 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2585 (mm-charset-iso-8859-1-forced
2586 gnus-newsgroup-iso-8859-1-forced))
2587 (mm-display-part handle t))
2588 (goto-char (point-max)))
2589 ((and text not-attachment)
2591 (gnus-article-insert-newline)
2592 (mm-insert-inline handle (mm-get-part handle))
2593 (goto-char (point-max))))))))
2595 (defun gnus-unbuttonized-mime-type-p (type)
2596 "Say whether TYPE is to be unbuttonized."
2597 (unless gnus-inhibit-mime-unbuttonizing
2599 (let ((types gnus-unbuttonized-mime-types))
2601 (when (string-match (pop types) type)
2602 (throw 'found t)))))))
2604 (defun gnus-article-insert-newline ()
2605 "Insert a newline, but mark it as undeletable."
2606 (gnus-put-text-property
2607 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2609 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2610 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2613 handle buffer-read-only from props begend not-pref)
2614 (save-window-excursion
2617 (narrow-to-region (car ibegend)
2620 (goto-char (car ibegend))
2623 (delete-region (point-min) (point-max))
2624 (mm-remove-parts handles))
2625 (setq begend (list (point-marker)))
2627 (unless (setq not-pref (cadr (member preferred ihandles)))
2628 (setq not-pref (car ihandles)))
2630 (not (gnus-unbuttonized-mime-type-p
2631 "multipart/alternative")))
2632 (gnus-add-text-properties
2635 (insert (format "%d. " id))
2639 (unless ,(not ibegend)
2640 (setq gnus-article-mime-handle-alist
2641 ',gnus-article-mime-handle-alist))
2642 (gnus-mime-display-alternative
2643 ',ihandles ',not-pref ',begend ,id))
2644 local-map ,gnus-mime-button-map
2645 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2646 face ,gnus-article-button-face
2647 keymap ,gnus-mime-button-map
2650 (widget-convert-button 'link from (point)
2651 :action 'gnus-widget-press-button
2652 :button-keymap gnus-widget-button-keymap)
2654 (while (setq handle (pop handles))
2655 (gnus-add-text-properties
2658 (insert (format "[%c] %-18s"
2659 (if (equal handle preferred) ?* ? )
2660 (if (stringp (car handle))
2662 (car (mm-handle-type handle)))))
2666 (unless ,(not ibegend)
2667 (setq gnus-article-mime-handle-alist
2668 ',gnus-article-mime-handle-alist))
2669 (gnus-mime-display-alternative
2670 ',ihandles ',handle ',begend ,id))
2671 local-map ,gnus-mime-button-map
2672 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2673 face ,gnus-article-button-face
2674 keymap ,gnus-mime-button-map
2677 (widget-convert-button 'link from (point)
2678 :action 'gnus-widget-press-button
2679 :button-keymap gnus-widget-button-keymap)
2683 (if (stringp (car preferred))
2684 (gnus-display-mime preferred)
2685 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2686 (mm-charset-iso-8859-1-forced
2687 gnus-newsgroup-iso-8859-1-forced))
2688 (mm-display-part preferred)))
2689 (goto-char (point-max))
2690 (setcdr begend (point-marker)))))
2692 (goto-char point))))
2694 (defun gnus-article-wash-status ()
2695 "Return a string which display status of article washing."
2697 (set-buffer gnus-article-buffer)
2698 (let ((cite (gnus-article-hidden-text-p 'cite))
2699 (headers (gnus-article-hidden-text-p 'headers))
2700 (boring (gnus-article-hidden-text-p 'boring-headers))
2701 (pgp (gnus-article-hidden-text-p 'pgp))
2702 (pem (gnus-article-hidden-text-p 'pem))
2703 (signature (gnus-article-hidden-text-p 'signature))
2704 (overstrike (gnus-article-hidden-text-p 'overstrike))
2705 (emphasis (gnus-article-hidden-text-p 'emphasis)))
2706 (format "%c%c%c%c%c%c"
2708 (if (or headers boring) ?h ? )
2709 (if (or pgp pem) ?p ? )
2710 (if signature ?s ? )
2711 (if overstrike ?o ? )
2712 (if emphasis ?e ? )))))
2714 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2716 (defun gnus-article-maybe-hide-headers ()
2717 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2718 Provided for backwards compatibility."
2719 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2721 (gnus-article-hide-headers)))
2725 (defun gnus-output-to-file (file-name)
2726 "Append the current article to a file named FILE-NAME."
2727 (let ((artbuf (current-buffer)))
2729 (insert-buffer-substring artbuf)
2730 ;; Append newline at end of the buffer as separator, and then
2732 (goto-char (point-max))
2734 (append-to-file (point-min) (point-max) file-name)
2737 (defun gnus-narrow-to-page (&optional arg)
2738 "Narrow the article buffer to a page.
2739 If given a numerical ARG, move forward ARG pages."
2741 (setq arg (if arg (prefix-numeric-value arg) 0))
2743 (set-buffer gnus-article-buffer)
2744 (goto-char (point-min))
2746 ;; Remove any old next/prev buttons.
2747 (when (gnus-visual-p 'page-marker)
2748 (let ((buffer-read-only nil))
2749 (gnus-remove-text-with-property 'gnus-prev)
2750 (gnus-remove-text-with-property 'gnus-next)))
2753 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2755 (re-search-forward page-delimiter nil 'move arg)))
2756 (goto-char (match-end 0)))
2759 (if (re-search-forward page-delimiter nil 'move)
2762 (when (and (gnus-visual-p 'page-marker)
2763 (not (= (point-min) 1)))
2765 (goto-char (point-min))
2766 (gnus-insert-prev-page-button)))
2767 (when (and (gnus-visual-p 'page-marker)
2768 (< (+ (point-max) 2) (buffer-size)))
2770 (goto-char (point-max))
2771 (gnus-insert-next-page-button)))))
2773 ;; Article mode commands
2775 (defun gnus-article-goto-next-page ()
2776 "Show the next page of the article."
2778 (when (gnus-article-next-page)
2779 (goto-char (point-min))
2780 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2782 (defun gnus-article-goto-prev-page ()
2783 "Show the next page of the article."
2785 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2786 (gnus-article-prev-page nil)))
2788 (defun gnus-article-next-page (&optional lines)
2789 "Show the next page of the current article.
2790 If end of article, return non-nil. Otherwise return nil.
2791 Argument LINES specifies lines to be scrolled up."
2793 (move-to-window-line -1)
2796 (and (pos-visible-in-window-p) ;Not continuation line.
2798 ;; Nothing in this page.
2799 (if (or (not gnus-page-broken)
2802 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2804 (gnus-narrow-to-page 1) ;Go to next page.
2806 ;; More in this page.
2807 (let ((scroll-in-place nil))
2811 ;; Long lines may cause an end-of-buffer error.
2812 (goto-char (point-max)))))
2813 (move-to-window-line 0)
2816 (defun gnus-article-prev-page (&optional lines)
2817 "Show previous page of current article.
2818 Argument LINES specifies lines to be scrolled down."
2820 (move-to-window-line 0)
2821 (if (and gnus-page-broken
2823 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2825 (gnus-narrow-to-page -1) ;Go to previous page.
2826 (goto-char (point-max))
2828 (let ((scroll-in-place nil))
2832 (beginning-of-buffer
2833 (goto-char (point-min))))
2834 (move-to-window-line 0)))))
2836 (defun gnus-article-refer-article ()
2837 "Read article specified by message-id around point."
2839 (let ((point (point)))
2840 (search-forward ">" nil t) ;Move point to end of "<....>".
2841 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2842 (let ((message-id (match-string 1)))
2844 (set-buffer gnus-summary-buffer)
2845 (gnus-summary-refer-article message-id))
2847 (error "No references around point"))))
2849 (defun gnus-article-show-summary ()
2850 "Reconfigure windows to show summary buffer."
2852 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2853 (error "There is no summary buffer for this article buffer")
2854 (gnus-article-set-globals)
2855 (gnus-configure-windows 'article)
2856 (gnus-summary-goto-subject gnus-current-article)
2857 (gnus-summary-position-point)))
2859 (defun gnus-article-describe-briefly ()
2860 "Describe article mode commands briefly."
2863 (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")))
2865 (defun gnus-article-summary-command ()
2866 "Execute the last keystroke in the summary buffer."
2868 (let ((obuf (current-buffer))
2869 (owin (current-window-configuration))
2871 (switch-to-buffer gnus-article-current-summary 'norecord)
2872 (setq func (lookup-key (current-local-map) (this-command-keys)))
2873 (call-interactively func)
2875 (set-window-configuration owin)
2876 (set-window-point (get-buffer-window (current-buffer)) (point))))
2878 (defun gnus-article-summary-command-nosave ()
2879 "Execute the last keystroke in the summary buffer."
2882 (pop-to-buffer gnus-article-current-summary 'norecord)
2883 (setq func (lookup-key (current-local-map) (this-command-keys)))
2884 (call-interactively func)))
2886 (defun gnus-article-check-buffer ()
2887 "Beep if not in an article buffer."
2888 (unless (equal major-mode 'gnus-article-mode)
2889 (error "Command invoked outside of a Gnus article buffer")))
2891 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2892 "Read a summary buffer key sequence and execute it from the article buffer."
2894 (gnus-article-check-buffer)
2896 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2897 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2898 "=" "^" "\M-^" "|"))
2904 '("n" "Gn" "p" "Gp"))
2907 (set-buffer gnus-article-current-summary)
2908 (let (gnus-pick-mode)
2909 (push (or key last-command-event) unread-command-events)
2910 (setq keys (read-key-sequence nil))))
2913 (if (or (member keys nosaves)
2914 (member keys nosave-but-article)
2915 (member keys nosave-in-article))
2917 (save-window-excursion
2918 (pop-to-buffer gnus-article-current-summary 'norecord)
2919 ;; We disable the pick minor mode commands.
2920 (let (gnus-pick-mode)
2921 (setq func (lookup-key (current-local-map) keys))))
2924 (unless (member keys nosave-in-article)
2925 (set-buffer gnus-article-current-summary))
2926 (call-interactively func)
2927 (setq new-sum-point (point)))
2928 (when (member keys nosave-but-article)
2929 (pop-to-buffer gnus-article-buffer 'norecord)))
2930 ;; These commands should restore window configuration.
2931 (let ((obuf (current-buffer))
2932 (owin (current-window-configuration))
2934 (summary gnus-article-current-summary)
2935 func in-buffer selected)
2936 (if not-restore-window
2937 (pop-to-buffer summary 'norecord)
2938 (switch-to-buffer summary 'norecord))
2939 (setq in-buffer (current-buffer))
2940 ;; We disable the pick minor mode commands.
2941 (if (setq func (let (gnus-pick-mode)
2942 (lookup-key (current-local-map) keys)))
2944 (call-interactively func)
2945 (setq new-sum-point (point)))
2947 (when (eq in-buffer (current-buffer))
2948 (setq selected (gnus-summary-select-article))
2950 (unless not-restore-window
2951 (set-window-configuration owin))
2952 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2953 (set-window-point (get-buffer-window (current-buffer))
2955 (let ((win (get-buffer-window gnus-article-current-summary)))
2957 (set-window-point win new-sum-point))))))))
2959 (defun gnus-article-hide (&optional arg force)
2960 "Hide all the gruft in the current article.
2961 This means that PGP stuff, signatures, cited text and (some)
2962 headers will be hidden.
2963 If given a prefix, show the hidden text instead."
2964 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2965 (gnus-article-hide-headers arg)
2966 (gnus-article-hide-pgp arg)
2967 (gnus-article-hide-citation-maybe arg force)
2968 (gnus-article-hide-signature arg))
2970 (defun gnus-article-maybe-highlight ()
2971 "Do some article highlighting if article highlighting is requested."
2972 (when (gnus-visual-p 'article-highlight 'highlight)
2973 (gnus-article-highlight-some)))
2975 (defun gnus-check-group-server ()
2976 ;; Make sure the connection to the server is alive.
2977 (unless (gnus-server-opened
2978 (gnus-find-method-for-group gnus-newsgroup-name))
2979 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2980 (gnus-request-group gnus-newsgroup-name t)))
2982 (defun gnus-request-article-this-buffer (article group)
2983 "Get an article and insert it into this buffer."
2984 (let (do-update-line sparse-header)
2988 (gnus-kill-all-overlays)
2989 (setq group (or group gnus-newsgroup-name))
2991 ;; Using `gnus-request-article' directly will insert the article into
2992 ;; `nntp-server-buffer' - so we'll save some time by not having to
2993 ;; copy it from the server buffer into the article buffer.
2995 ;; We only request an article by message-id when we do not have the
2996 ;; headers for it, so we'll have to get those.
2997 (when (stringp article)
2998 (let ((gnus-override-method gnus-refer-article-method))
2999 (gnus-read-header article)))
3001 ;; If the article number is negative, that means that this article
3002 ;; doesn't belong in this newsgroup (possibly), so we find its
3003 ;; message-id and request it by id instead of number.
3004 (when (and (numberp article)
3006 (get-buffer gnus-summary-buffer)
3007 (gnus-buffer-exists-p gnus-summary-buffer))
3009 (set-buffer gnus-summary-buffer)
3010 (let ((header (gnus-summary-article-header article)))
3013 ((memq article gnus-newsgroup-sparse)
3014 ;; This is a sparse gap article.
3015 (setq do-update-line article)
3016 (setq article (mail-header-id header))
3017 (let ((gnus-override-method gnus-refer-article-method))
3018 (setq sparse-header (gnus-read-header article)))
3019 (setq gnus-newsgroup-sparse
3020 (delq article gnus-newsgroup-sparse)))
3022 ;; It's a real article.
3023 (setq article (mail-header-id header)))
3025 ;; It is an extracted pseudo-article.
3026 (setq article 'pseudo)
3027 (gnus-request-pseudo-article header))))
3029 (let ((method (gnus-find-method-for-group
3030 gnus-newsgroup-name)))
3031 (when (and (eq (car method) 'nneething)
3034 (file-name-as-directory
3035 (or (cadr (assq 'nneething-address method))
3037 (mail-header-subject header))))
3038 (when (file-directory-p dir)
3039 (setq article 'nneething)
3040 (gnus-group-enter-directory dir))))))))
3043 ;; Refuse to select canceled articles.
3044 ((and (numberp article)
3046 (get-buffer gnus-summary-buffer)
3047 (gnus-buffer-exists-p gnus-summary-buffer)
3048 (eq (cdr (save-excursion
3049 (set-buffer gnus-summary-buffer)
3050 (assq article gnus-newsgroup-reads)))
3051 gnus-canceled-mark))
3053 ;; We first check `gnus-original-article-buffer'.
3054 ((and (get-buffer gnus-original-article-buffer)
3057 (set-buffer gnus-original-article-buffer)
3058 (and (equal (car gnus-original-article) group)
3059 (eq (cdr gnus-original-article) article))))
3060 (insert-buffer-substring gnus-original-article-buffer)
3062 ;; Check the backlog.
3063 ((and gnus-keep-backlog
3064 (gnus-backlog-request-article group article (current-buffer)))
3066 ;; Check asynchronous pre-fetch.
3067 ((gnus-async-request-fetched-article group article (current-buffer))
3068 (gnus-async-prefetch-next group article gnus-summary-buffer)
3069 (when (and (numberp article) gnus-keep-backlog)
3070 (gnus-backlog-enter-article group article (current-buffer)))
3073 ((and gnus-use-cache
3075 (gnus-cache-request-article article group))
3077 ;; Get the article and put into the article buffer.
3078 ((or (stringp article) (numberp article))
3079 (let ((gnus-override-method
3080 (and (stringp article) gnus-refer-article-method))
3081 (buffer-read-only nil))
3083 (gnus-kill-all-overlays)
3084 (gnus-check-group-server)
3085 (when (gnus-request-article article group (current-buffer))
3086 (when (numberp article)
3087 (gnus-async-prefetch-next group article gnus-summary-buffer)
3088 (when gnus-keep-backlog
3089 (gnus-backlog-enter-article
3090 group article (current-buffer))))
3095 ;; Associate this article with the current summary buffer.
3096 (setq gnus-article-current-summary gnus-summary-buffer)
3098 ;; Take the article from the original article buffer
3099 ;; and place it in the buffer it's supposed to be in.
3100 (when (and (get-buffer gnus-article-buffer)
3101 (equal (buffer-name (current-buffer))
3102 (buffer-name (get-buffer gnus-article-buffer))))
3104 (if (get-buffer gnus-original-article-buffer)
3105 (set-buffer gnus-original-article-buffer)
3106 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3107 (buffer-disable-undo)
3108 (setq major-mode 'gnus-original-article-mode)
3109 (setq buffer-read-only t))
3110 (let (buffer-read-only)
3112 (insert-buffer-substring gnus-article-buffer))
3113 (setq gnus-original-article (cons group article)))
3116 (run-hooks 'gnus-article-decode-hook)
3117 ;; Mark article as decoded or not.
3118 (setq gnus-article-decoded-p gnus-article-decode-hook))
3120 ;; Update sparse articles.
3121 (when (and do-update-line
3122 (or (numberp article)
3124 (let ((buf (current-buffer)))
3125 (set-buffer gnus-summary-buffer)
3126 (gnus-summary-update-article do-update-line sparse-header)
3127 (gnus-summary-goto-subject do-update-line nil t)
3128 (set-window-point (get-buffer-window (current-buffer) t)
3130 (set-buffer buf))))))
3136 (defcustom gnus-article-edit-mode-hook nil
3137 "Hook run in article edit mode buffers."
3138 :group 'gnus-article-various
3141 (defvar gnus-article-edit-done-function nil)
3143 (defvar gnus-article-edit-mode-map nil)
3145 ;; Should we be using derived.el for this?
3146 (unless gnus-article-edit-mode-map
3147 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3148 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3150 (gnus-define-keys gnus-article-edit-mode-map
3151 "\C-c\C-c" gnus-article-edit-done
3152 "\C-c\C-k" gnus-article-edit-exit)
3154 (gnus-define-keys (gnus-article-edit-wash-map
3155 "\C-c\C-w" gnus-article-edit-mode-map)
3156 "f" gnus-article-edit-full-stops))
3158 (defun gnus-article-edit-mode ()
3159 "Major mode for editing articles.
3160 This is an extended text-mode.
3162 \\{gnus-article-edit-mode-map}"
3164 (setq major-mode 'gnus-article-edit-mode)
3165 (setq mode-name "Article Edit")
3166 (use-local-map gnus-article-edit-mode-map)
3167 (make-local-variable 'gnus-article-edit-done-function)
3168 (make-local-variable 'gnus-prev-winconf)
3169 (setq buffer-read-only nil)
3170 (buffer-enable-undo)
3172 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3174 (defun gnus-article-edit (&optional force)
3175 "Edit the current article.
3176 This will have permanent effect only in mail groups.
3177 If FORCE is non-nil, allow editing of articles even in read-only
3180 (when (and (not force)
3181 (gnus-group-read-only-p))
3182 (error "The current newsgroup does not support article editing"))
3183 (gnus-article-date-original)
3184 (gnus-article-edit-article
3185 `(lambda (no-highlight)
3186 (gnus-summary-edit-article-done
3187 ,(or (mail-header-references gnus-current-headers) "")
3188 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3190 (defun gnus-article-edit-article (exit-func)
3191 "Start editing the contents of the current article buffer."
3192 (let ((winconf (current-window-configuration)))
3193 (set-buffer gnus-article-buffer)
3194 (gnus-article-edit-mode)
3195 (gnus-article-delete-text-of-type 'annotation)
3196 (gnus-set-text-properties (point-min) (point-max) nil)
3197 (gnus-configure-windows 'edit-article)
3198 (setq gnus-article-edit-done-function exit-func)
3199 (setq gnus-prev-winconf winconf)
3200 (gnus-message 6 "C-c C-c to end edits")))
3202 (defun gnus-article-edit-done (&optional arg)
3203 "Update the article edits and exit."
3208 (when (article-goto-body)
3209 (let ((lines (count-lines (point) (point-max)))
3210 (length (- (point-max) (point)))
3211 (case-fold-search t)
3212 (body (copy-marker (point))))
3213 (goto-char (point-min))
3214 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3215 (delete-region (match-beginning 1) (match-end 1))
3216 (insert (number-to-string length)))
3217 (goto-char (point-min))
3218 (when (re-search-forward
3219 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3220 (delete-region (match-beginning 1) (match-end 1))
3221 (insert (number-to-string length)))
3222 (goto-char (point-min))
3223 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3224 (delete-region (match-beginning 1) (match-end 1))
3225 (insert (number-to-string lines)))))))
3226 (let ((func gnus-article-edit-done-function)
3227 (buf (current-buffer))
3228 (start (window-start)))
3229 (gnus-article-edit-exit)
3232 (let ((buffer-read-only nil))
3234 ;; The cache and backlog have to be flushed somewhat.
3235 (when gnus-keep-backlog
3236 (gnus-backlog-remove-article
3237 (car gnus-article-current) (cdr gnus-article-current)))
3238 ;; Flush original article as well.
3240 (when (get-buffer gnus-original-article-buffer)
3241 (set-buffer gnus-original-article-buffer)
3242 (setq gnus-original-article nil)))
3243 (when gnus-use-cache
3244 (gnus-cache-update-article
3245 (car gnus-article-current) (cdr gnus-article-current))))
3247 (set-window-start (get-buffer-window buf) start)
3248 (set-window-point (get-buffer-window buf) (point))))
3250 (defun gnus-article-edit-exit ()
3251 "Exit the article editing without updating."
3253 ;; We remove all text props from the article buffer.
3254 (let ((buf (format "%s" (buffer-string)))
3255 (curbuf (current-buffer))
3257 (window-start (window-start)))
3260 (let ((winconf gnus-prev-winconf))
3262 (set-window-configuration winconf)
3263 ;; Tippy-toe some to make sure that point remains where it was.
3264 (save-current-buffer
3266 (set-window-start (get-buffer-window (current-buffer)) window-start)
3269 (defun gnus-article-edit-full-stops ()
3270 "Interactively repair spacing at end of sentences."
3273 (goto-char (point-min))
3274 (search-forward-regexp "^$" nil t)
3275 (let ((case-fold-search nil))
3276 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3279 ;;; Article highlights
3282 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3284 ;;; Internal Variables:
3286 (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\\)"
3287 "Regular expression that matches URLs."
3288 :group 'gnus-article-buttons
3291 (defcustom gnus-button-alist
3292 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3293 0 t gnus-button-message-id 2)
3294 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3295 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3297 gnus-button-fetch-group 4)
3298 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3299 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3300 t gnus-button-message-id 3)
3301 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3302 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3303 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3304 ;; This is how URLs _should_ be embedded in text...
3305 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3307 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3308 "*Alist of regexps matching buttons in article bodies.
3310 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3311 REGEXP: is the string matching text around the button,
3312 BUTTON: is the number of the regexp grouping actually matching the button,
3313 FORM: is a lisp expression which must eval to true for the button to
3315 CALLBACK: is the function to call when the user push this button, and each
3316 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3318 CALLBACK can also be a variable, in that case the value of that
3319 variable it the real callback function."
3320 :group 'gnus-article-buttons
3321 :type '(repeat (list regexp
3322 (integer :tag "Button")
3324 (function :tag "Callback")
3327 (integer :tag "Regexp group")))))
3329 (defcustom gnus-header-button-alist
3330 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3331 0 t gnus-button-message-id 0)
3332 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3333 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3334 0 t gnus-button-mailto 0)
3335 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3336 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3337 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3338 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3339 gnus-button-message-id 3))
3340 "*Alist of headers and regexps to match buttons in article heads.
3342 This alist is very similar to `gnus-button-alist', except that each
3343 alist has an additional HEADER element first in each entry:
3345 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3347 HEADER is a regexp to match a header. For a fuller explanation, see
3348 `gnus-button-alist'."
3349 :group 'gnus-article-buttons
3350 :group 'gnus-article-headers
3351 :type '(repeat (list (regexp :tag "Header")
3353 (integer :tag "Button")
3355 (function :tag "Callback")
3358 (integer :tag "Regexp group")))))
3360 (defvar gnus-button-regexp nil)
3361 (defvar gnus-button-marker-list nil)
3362 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3364 (defvar gnus-button-last nil)
3365 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3369 (defun gnus-article-push-button (event)
3370 "Check text under the mouse pointer for a callback function.
3371 If the text under the mouse pointer has a `gnus-callback' property,
3372 call it with the value of the `gnus-data' text property."
3374 (set-buffer (window-buffer (posn-window (event-start event))))
3375 (let* ((pos (posn-point (event-start event)))
3376 (data (get-text-property pos 'gnus-data))
3377 (fun (get-text-property pos 'gnus-callback)))
3380 (funcall fun data))))
3382 (defun gnus-article-press-button ()
3383 "Check text at point for a callback function.
3384 If the text at point has a `gnus-callback' property,
3385 call it with the value of the `gnus-data' text property."
3387 (let* ((data (get-text-property (point) 'gnus-data))
3388 (fun (get-text-property (point) 'gnus-callback)))
3390 (funcall fun data))))
3392 (defun gnus-article-highlight (&optional force)
3393 "Highlight current article.
3394 This function calls `gnus-article-highlight-headers',
3395 `gnus-article-highlight-citation',
3396 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3397 do the highlighting. See the documentation for those functions."
3398 (interactive (list 'force))
3399 (gnus-article-highlight-headers)
3400 (gnus-article-highlight-citation force)
3401 (gnus-article-highlight-signature)
3402 (gnus-article-add-buttons force)
3403 (gnus-article-add-buttons-to-head))
3405 (defun gnus-article-highlight-some (&optional force)
3406 "Highlight current article.
3407 This function calls `gnus-article-highlight-headers',
3408 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3409 do the highlighting. See the documentation for those functions."
3410 (interactive (list 'force))
3411 (gnus-article-highlight-headers)
3412 (gnus-article-highlight-signature)
3413 (gnus-article-add-buttons))
3415 (defun gnus-article-highlight-headers ()
3416 "Highlight article headers as specified by `gnus-header-face-alist'."
3419 (set-buffer gnus-article-buffer)
3421 (let ((alist gnus-header-face-alist)
3422 (buffer-read-only nil)
3423 (case-fold-search t)
3424 (inhibit-point-motion-hooks t)
3425 entry regexp header-face field-face from hpoints fpoints)
3426 (message-narrow-to-head)
3427 (while (setq entry (pop alist))
3428 (goto-char (point-min))
3429 (setq regexp (concat "^\\("
3430 (if (string-equal "" (nth 0 entry))
3434 header-face (nth 1 entry)
3435 field-face (nth 2 entry))
3436 (while (and (re-search-forward regexp nil t)
3440 (unless (search-forward ":" nil t)
3442 (when (and header-face
3443 (not (memq (point) hpoints)))
3444 (push (point) hpoints)
3445 (gnus-put-text-property from (point) 'face header-face))
3446 (when (and field-face
3447 (not (memq (setq from (point)) fpoints)))
3449 (if (re-search-forward "^[^ \t]" nil t)
3451 (goto-char (point-max)))
3452 (gnus-put-text-property from (point) 'face field-face))))))))
3454 (defun gnus-article-highlight-signature ()
3455 "Highlight the signature in an article.
3456 It does this by highlighting everything after
3457 `gnus-signature-separator' using `gnus-signature-face'."
3460 (set-buffer gnus-article-buffer)
3461 (let ((buffer-read-only nil)
3462 (inhibit-point-motion-hooks t))
3464 (when (and gnus-signature-face
3465 (gnus-article-narrow-to-signature))
3466 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3467 'face gnus-signature-face)
3469 (gnus-article-search-signature)
3470 (let ((start (match-beginning 0))
3471 (end (set-marker (make-marker) (1+ (match-end 0)))))
3472 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3475 (defun gnus-button-in-region-p (b e prop)
3476 "Say whether PROP exists in the region."
3477 (text-property-not-all b e prop nil))
3479 (defun gnus-article-add-buttons (&optional force)
3480 "Find external references in the article and make buttons of them.
3481 \"External references\" are things like Message-IDs and URLs, as
3482 specified by `gnus-button-alist'."
3483 (interactive (list 'force))
3485 (set-buffer gnus-article-buffer)
3486 (let ((buffer-read-only nil)
3487 (inhibit-point-motion-hooks t)
3488 (case-fold-search t)
3489 (alist gnus-button-alist)
3491 ;; Remove all old markers.
3493 (while (setq marker (pop gnus-button-marker-list))
3495 (when (setq entry (gnus-button-entry))
3496 (put-text-property (match-beginning (nth 1 entry))
3497 (match-end (nth 1 entry))
3498 'gnus-callback nil))
3499 (set-marker marker nil)))
3500 ;; We skip the headers.
3503 (while (setq entry (pop alist))
3504 (setq regexp (car entry))
3506 (while (re-search-forward regexp nil t)
3507 (let* ((start (and entry (match-beginning (nth 1 entry))))
3508 (end (and entry (match-end (nth 1 entry))))
3509 (from (match-beginning 0)))
3510 (when (and (or (eq t (nth 2 entry))
3511 (eval (nth 2 entry)))
3512 (not (gnus-button-in-region-p
3513 start end 'gnus-callback)))
3514 ;; That optional form returned non-nil, so we add the
3516 (gnus-article-add-button
3517 start end 'gnus-button-push
3518 (car (push (set-marker (make-marker) from)
3519 gnus-button-marker-list))))))))))
3521 ;; Add buttons to the head of an article.
3522 (defun gnus-article-add-buttons-to-head ()
3523 "Add buttons to the head of the article."
3526 (set-buffer gnus-article-buffer)
3527 (let ((buffer-read-only nil)
3528 (inhibit-point-motion-hooks t)
3529 (case-fold-search t)
3530 (alist gnus-header-button-alist)
3532 (nnheader-narrow-to-headers)
3534 ;; Each alist entry.
3535 (setq entry (car alist)
3537 (goto-char (point-min))
3538 (while (re-search-forward (car entry) nil t)
3539 ;; Each header matching the entry.
3540 (setq beg (match-beginning 0))
3541 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3542 (match-beginning 0))
3545 (while (re-search-forward (nth 1 entry) end t)
3546 ;; Each match within a header.
3547 (let* ((entry (cdr entry))
3548 (start (match-beginning (nth 1 entry)))
3549 (end (match-end (nth 1 entry)))
3550 (form (nth 2 entry)))
3551 (goto-char (match-end 0))
3553 (gnus-article-add-button
3554 start end (nth 3 entry)
3555 (buffer-substring (match-beginning (nth 4 entry))
3556 (match-end (nth 4 entry)))))))
3560 ;;; External functions:
3562 (defun gnus-article-add-button (from to fun &optional data)
3563 "Create a button between FROM and TO with callback FUN and data DATA."
3564 (when gnus-article-button-face
3565 (gnus-overlay-put (gnus-make-overlay from to)
3566 'face gnus-article-button-face))
3567 (gnus-add-text-properties
3569 (nconc (and gnus-article-mouse-face
3570 (list gnus-mouse-face-prop gnus-article-mouse-face))
3571 (list 'gnus-callback fun)
3572 (and data (list 'gnus-data data))))
3573 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3574 :button-keymap gnus-widget-button-keymap))
3576 ;;; Internal functions:
3578 (defun gnus-article-set-globals ()
3580 (set-buffer gnus-summary-buffer)
3581 (gnus-set-global-variables)))
3583 (defun gnus-signature-toggle (end)
3585 (set-buffer gnus-article-buffer)
3586 (let ((buffer-read-only nil)
3587 (inhibit-point-motion-hooks t))
3588 (if (get-text-property end 'invisible)
3589 (gnus-article-unhide-text end (point-max))
3590 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3592 (defun gnus-button-entry ()
3593 ;; Return the first entry in `gnus-button-alist' matching this place.
3594 (let ((alist gnus-button-alist)
3597 (setq entry (pop alist))
3598 (if (looking-at (car entry))
3603 (defun gnus-button-push (marker)
3604 ;; Push button starting at MARKER.
3607 (let* ((entry (gnus-button-entry))
3608 (inhibit-point-motion-hooks t)
3610 (args (mapcar (lambda (group)
3611 (let ((string (match-string group)))
3612 (gnus-set-text-properties
3613 0 (length string) nil string)
3620 (fboundp (symbol-value fun)))
3621 (apply (symbol-value fun) args))
3623 (gnus-message 1 "You must define `%S' to use this button"
3624 (cons fun args)))))))
3626 (defun gnus-button-message-id (message-id)
3629 (set-buffer gnus-summary-buffer)
3630 (gnus-summary-refer-article message-id)))
3632 (defun gnus-button-fetch-group (address)
3633 "Fetch GROUP specified by ADDRESS."
3634 (if (not (string-match "[:/]" address))
3635 ;; This is just a simple group url.
3636 (gnus-group-read-ephemeral-group address gnus-select-method)
3637 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3639 (error "Can't parse %s" address)
3640 (gnus-group-read-ephemeral-group
3641 (match-string 4 address)
3642 `(nntp ,(match-string 1 address)
3643 (nntp-address ,(match-string 1 address))
3644 (nntp-port-number ,(if (match-end 3)
3645 (match-string 3 address)
3648 (defun gnus-url-parse-query-string (query &optional downcase)
3649 (let (retval pairs cur key val)
3650 (setq pairs (split-string query "&"))
3652 (setq cur (car pairs)
3654 (if (not (string-match "=" cur))
3656 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3657 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3659 (setq key (downcase key)))
3660 (setq cur (assoc key retval))
3662 (setcdr cur (cons val (cdr cur)))
3663 (setq retval (cons (list key val) retval)))))
3666 (defun gnus-url-unhex (x)
3673 (defun gnus-url-unhex-string (str &optional allow-newlines)
3674 "Remove %XXX embedded spaces, etc in a url.
3675 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3676 decoding of carriage returns and line feeds in the string, which is normally
3677 forbidden in URL encoding."
3678 (setq str (or str ""))
3680 (case-fold-search t))
3681 (while (string-match "%[0-9a-f][0-9a-f]" str)
3682 (let* ((start (match-beginning 0))
3683 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3685 (gnus-url-unhex (elt str (+ start 2))))))
3687 tmp (substring str 0 start)
3690 (char-to-string code))
3691 ((or (= code ?\n) (= code ?\r))
3693 (t (char-to-string code))))
3694 str (substring str (match-end 0)))))
3695 (setq tmp (concat tmp str))
3698 (defun gnus-url-mailto (url)
3699 ;; Send mail to someone
3700 (when (string-match "mailto:/*\\(.*\\)" url)
3701 (setq url (substring url (match-beginning 1) nil)))
3702 (let (to args subject func)
3703 (if (string-match (regexp-quote "?") url)
3704 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3705 args (gnus-url-parse-query-string
3706 (substring url (match-end 0) nil) t))
3707 (setq to (gnus-url-unhex-string url)))
3708 (setq args (cons (list "to" to) args)
3709 subject (cdr-safe (assoc "subject" args)))
3712 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3715 (message-position-on-field (caar args)))
3716 (insert (mapconcat 'identity (cdar args) ", "))
3717 (setq args (cdr args)))
3720 (message-goto-subject))))
3722 (defun gnus-button-mailto (address)
3724 (set-buffer (gnus-copy-article-buffer))
3725 (message-reply address))
3727 (defun gnus-button-reply (address)
3728 ;; Reply to ADDRESS.
3729 (message-reply address))
3731 (defun gnus-button-url (address)
3733 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3734 (if (listp browse-url-browser-function)
3735 (browse-url address)
3736 (funcall browse-url-browser-function address)))
3738 (defun gnus-button-embedded-url (address)
3740 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3741 (if (listp browse-url-browser-function)
3742 (browse-url (gnus-strip-whitespace address))
3743 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3745 ;;; Next/prev buttons in the article buffer.
3747 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3748 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3750 (defvar gnus-prev-page-map nil)
3751 (unless gnus-prev-page-map
3752 (setq gnus-prev-page-map (make-sparse-keymap))
3753 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3754 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3756 (defun gnus-insert-prev-page-button ()
3757 (let ((buffer-read-only nil))
3759 gnus-prev-page-line-format nil
3760 `(gnus-prev t local-map ,gnus-prev-page-map
3761 gnus-callback gnus-article-button-prev-page
3762 article-type annotation))))
3764 (defvar gnus-next-page-map nil)
3765 (unless gnus-next-page-map
3766 (setq gnus-next-page-map (make-keymap))
3767 (suppress-keymap gnus-prev-page-map)
3768 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3769 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3771 (defun gnus-button-next-page ()
3772 "Go to the next page."
3774 (let ((win (selected-window)))
3775 (select-window (get-buffer-window gnus-article-buffer t))
3776 (gnus-article-next-page)
3777 (select-window win)))
3779 (defun gnus-button-prev-page ()
3780 "Go to the prev page."
3782 (let ((win (selected-window)))
3783 (select-window (get-buffer-window gnus-article-buffer t))
3784 (gnus-article-prev-page)
3785 (select-window win)))
3787 (defun gnus-insert-next-page-button ()
3788 (let ((buffer-read-only nil))
3789 (gnus-eval-format gnus-next-page-line-format nil
3791 t local-map ,gnus-next-page-map
3792 gnus-callback gnus-article-button-next-page
3793 article-type annotation))))
3795 (defun gnus-article-button-next-page (arg)
3796 "Go to the next page."
3798 (let ((win (selected-window)))
3799 (select-window (get-buffer-window gnus-article-buffer t))
3800 (gnus-article-next-page)
3801 (select-window win)))
3803 (defun gnus-article-button-prev-page (arg)
3804 "Go to the prev page."
3806 (let ((win (selected-window)))
3807 (select-window (get-buffer-window gnus-article-buffer t))
3808 (gnus-article-prev-page)
3809 (select-window win)))
3811 (defvar gnus-decode-header-methods
3812 '(gnus-decode-with-mail-decode-encoded-word-region)
3813 "List of methods used to decode headers
3815 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
3816 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
3817 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
3818 whose names match REGEXP.
3821 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
3822 mail-decode-encoded-word-region
3823 (\"chinese\" . rfc1843-decode-region))
3826 (defvar gnus-decode-header-methods-cache nil)
3828 (defun gnus-decode-with-mail-decode-encoded-word-region (start end)
3829 (let ((rfc2047-default-charset gnus-default-charset))
3830 (mail-decode-encoded-word-region start end)))
3832 (defun gnus-multi-decode-header (start end)
3833 "Apply the functions from `gnus-encoded-word-methods' that match."
3834 (unless (and gnus-decode-header-methods-cache
3835 (eq gnus-newsgroup-name
3836 (car gnus-decode-header-methods-cache)))
3837 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
3840 (nconc gnus-decode-header-methods-cache (list x))
3841 (if (and gnus-newsgroup-name
3842 (string-match (car x) gnus-newsgroup-name))
3843 (nconc gnus-decode-header-methods-cache
3845 gnus-decode-header-methods))
3846 (let ((xlist gnus-decode-header-methods-cache))
3849 (narrow-to-region start end)
3851 (funcall (pop xlist) (point-min) (point-max))))))
3857 (run-hooks 'gnus-art-load-hook)
3859 ;;; gnus-art.el ends here