1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
43 (defgroup gnus-article nil
45 :link '(custom-manual "(gnus)The Article Buffer")
48 (defgroup gnus-article-hiding nil
49 "Hiding article parts."
50 :link '(custom-manual "(gnus)Article Hiding")
53 (defgroup gnus-article-highlight nil
54 "Article highlighting."
55 :link '(custom-manual "(gnus)Article Highlighting")
59 (defgroup gnus-article-signature nil
61 :link '(custom-manual "(gnus)Article Signature")
64 (defgroup gnus-article-headers nil
66 :link '(custom-manual "(gnus)Hiding Headers")
69 (defgroup gnus-article-washing nil
70 "Special commands on articles."
71 :link '(custom-manual "(gnus)Article Washing")
74 (defgroup gnus-article-emphasis nil
75 "Fontisizing articles."
76 :link '(custom-manual "(gnus)Article Fontisizing")
79 (defgroup gnus-article-saving nil
81 :link '(custom-manual "(gnus)Saving Articles")
84 (defgroup gnus-article-mime nil
85 "Worshiping the MIME wonder."
86 :link '(custom-manual "(gnus)Using MIME")
89 (defgroup gnus-article-buttons nil
90 "Pushable buttons in the article buffer."
91 :link '(custom-manual "(gnus)Article Buttons")
94 (defgroup gnus-article-various nil
95 "Other article options."
96 :link '(custom-manual "(gnus)Misc Article")
99 (defcustom gnus-ignored-headers
100 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
101 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
102 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
103 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
104 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
105 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
106 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
107 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
108 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
109 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
110 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
111 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
112 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
113 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
114 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
115 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
116 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
117 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
119 "*All headers that start with this regexp will be hidden.
120 This variable can also be a list of regexps of headers to be ignored.
121 If `gnus-visible-headers' is non-nil, this variable will be ignored."
122 :type '(choice :custom-show nil
125 :group 'gnus-article-hiding)
127 (defcustom gnus-visible-headers
128 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
129 "*All headers that do not match this regexp will be hidden.
130 This variable can also be a list of regexp of headers to remain visible.
131 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
132 :type '(repeat :value-to-internal (lambda (widget value)
133 (custom-split-regexp-maybe value))
134 :match (lambda (widget value)
136 (widget-editable-list-match widget value)))
138 :group 'gnus-article-hiding)
140 (defcustom gnus-sorted-header-list
141 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
142 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
143 "*This variable is a list of regular expressions.
144 If it is non-nil, headers that match the regular expressions will
145 be placed first in the article buffer in the sequence specified by
147 :type '(repeat regexp)
148 :group 'gnus-article-hiding)
150 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
151 "Headers that are only to be displayed if they have interesting data.
152 Possible values in this list are `empty', `newsgroups', `followup-to',
153 `reply-to', `date', `long-to', and `many-to'."
154 :type '(set (const :tag "Headers with no content." empty)
155 (const :tag "Newsgroups with only one group." newsgroups)
156 (const :tag "Followup-to identical to newsgroups." followup-to)
157 (const :tag "Reply-to identical to from." reply-to)
158 (const :tag "Date less than four days old." date)
159 (const :tag "Very long To header." long-to)
160 (const :tag "Multiple To headers." many-to))
161 :group 'gnus-article-hiding)
163 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
164 "Regexp matching signature separator.
165 This can also be a list of regexps. In that case, it will be checked
166 from head to tail looking for a separator. Searches will be done from
167 the end of the buffer."
168 :type '(repeat string)
169 :group 'gnus-article-signature)
171 (defcustom gnus-signature-limit nil
172 "Provide a limit to what is considered a signature.
173 If it is a number, no signature may not be longer (in characters) than
174 that number. If it is a floating point number, no signature may be
175 longer (in lines) than that number. If it is a function, the function
176 will be called without any parameters, and if it returns nil, there is
177 no signature in the buffer. If it is a string, it will be used as a
178 regexp. If it matches, the text in question is not a signature."
179 :type '(choice (integer :value 200)
181 (function :value fun)
182 (regexp :value ".*"))
183 :group 'gnus-article-signature)
185 (defcustom gnus-hidden-properties '(invisible t intangible t)
186 "Property list to use for hiding text."
188 :group 'gnus-article-hiding)
190 (defcustom gnus-article-x-face-command
191 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
192 "*String or function to be executed to display an X-Face header.
193 If it is a string, the command will be executed in a sub-shell
194 asynchronously. The compressed face will be piped to this command."
195 :type 'string ;Leave function case to Lisp.
196 :group 'gnus-article-washing)
198 (defcustom gnus-article-x-face-too-ugly nil
199 "Regexp matching posters whose face shouldn't be shown automatically."
200 :type '(choice regexp (const nil))
201 :group 'gnus-article-washing)
203 (defcustom gnus-emphasis-alist
205 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
207 '(("_" "_" underline)
210 ("_/" "/_" underline-italic)
211 ("_\\*" "\\*_" underline-bold)
212 ("\\*/" "/\\*" bold-italic)
213 ("_\\*/" "/\\*_" underline-bold-italic))))
214 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
215 2 3 gnus-emphasis-underline)
219 (format format (car spec) (cadr spec))
220 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
222 "*Alist that says how to fontify certain phrases.
223 Each item looks like this:
225 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
227 The first element is a regular expression to be matched. The second
228 is a number that says what regular expression grouping used to find
229 the entire emphasized word. The third is a number that says what
230 regexp grouping should be displayed and highlighted. The fourth
231 is the face used for highlighting."
232 :type '(repeat (list :value ("" 0 0 default)
234 (integer :tag "Match group")
235 (integer :tag "Emphasize group")
237 :group 'gnus-article-emphasis)
239 (defface gnus-emphasis-bold '((t (:bold t)))
240 "Face used for displaying strong emphasized text (*word*)."
241 :group 'gnus-article-emphasis)
243 (defface gnus-emphasis-italic '((t (:italic t)))
244 "Face used for displaying italic emphasized text (/word/)."
245 :group 'gnus-article-emphasis)
247 (defface gnus-emphasis-underline '((t (:underline t)))
248 "Face used for displaying underlined emphasized text (_word_)."
249 :group 'gnus-article-emphasis)
251 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
252 "Face used for displaying underlined bold emphasized text (_*word*_)."
253 :group 'gnus-article-emphasis)
255 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
256 "Face used for displaying underlined italic emphasized text (_*word*_)."
257 :group 'gnus-article-emphasis)
259 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
260 "Face used for displaying bold italic emphasized text (/*word*/)."
261 :group 'gnus-article-emphasis)
263 (defface gnus-emphasis-underline-bold-italic
264 '((t (:bold t :italic t :underline t)))
265 "Face used for displaying underlined bold italic emphasized text.
266 Esample: (_/*word*/_)."
267 :group 'gnus-article-emphasis)
269 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
270 "Format for display of Date headers in article bodies.
271 See `format-time-string' for the possible values.
273 The variable can also be function, which should return a complete Date
274 header. The function is called with one argument, the time, which can
275 be fed to `format-time-string'."
276 :type '(choice string symbol)
277 :link '(custom-manual "(gnus)Article Date")
278 :group 'gnus-article-washing)
281 (autoload 'mail-extract-address-components "mail-extr"))
283 (defcustom gnus-save-all-headers t
284 "*If non-nil, don't remove any headers before saving."
285 :group 'gnus-article-saving
288 (defcustom gnus-prompt-before-saving 'always
289 "*This variable says how much prompting is to be done when saving articles.
290 If it is nil, no prompting will be done, and the articles will be
291 saved to the default files. If this variable is `always', each and
292 every article that is saved will be preceded by a prompt, even when
293 saving large batches of articles. If this variable is neither nil not
294 `always', there the user will be prompted once for a file name for
295 each invocation of the saving commands."
296 :group 'gnus-article-saving
297 :type '(choice (item always)
298 (item :tag "never" nil)
299 (sexp :tag "once" :format "%t\n" :value t)))
301 (defcustom gnus-saved-headers gnus-visible-headers
302 "Headers to keep if `gnus-save-all-headers' is nil.
303 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
304 If that variable is nil, however, all headers that match this regexp
305 will be kept while the rest will be deleted before saving."
306 :group 'gnus-article-saving
309 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
310 "A function to save articles in your favourite format.
311 The function must be interactively callable (in other words, it must
312 be an Emacs command).
314 Gnus provides the following functions:
316 * gnus-summary-save-in-rmail (Rmail format)
317 * gnus-summary-save-in-mail (Unix mail format)
318 * gnus-summary-save-in-folder (MH folder)
319 * gnus-summary-save-in-file (article format)
320 * gnus-summary-save-in-vm (use VM's folder format)
321 * gnus-summary-write-to-file (article format -- overwrite)."
322 :group 'gnus-article-saving
323 :type '(radio (function-item gnus-summary-save-in-rmail)
324 (function-item gnus-summary-save-in-mail)
325 (function-item gnus-summary-save-in-folder)
326 (function-item gnus-summary-save-in-file)
327 (function-item gnus-summary-save-in-vm)
328 (function-item gnus-summary-write-to-file)))
330 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
331 "A function generating a file name to save articles in Rmail format.
332 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
333 :group 'gnus-article-saving
336 (defcustom gnus-mail-save-name 'gnus-plain-save-name
337 "A function generating a file name to save articles in Unix mail format.
338 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
339 :group 'gnus-article-saving
342 (defcustom gnus-folder-save-name 'gnus-folder-save-name
343 "A function generating a file name to save articles in MH folder.
344 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
345 :group 'gnus-article-saving
348 (defcustom gnus-file-save-name 'gnus-numeric-save-name
349 "A function generating a file name to save articles in article format.
350 The function is called with NEWSGROUP, HEADERS, and optional
352 :group 'gnus-article-saving
355 (defcustom gnus-split-methods
356 '((gnus-article-archive-name)
357 (gnus-article-nndoc-name))
358 "*Variable used to suggest where articles are to be saved.
359 For instance, if you would like to save articles related to Gnus in
360 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
361 you could set this variable to something like:
363 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
364 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
366 This variable is an alist where the where the key is the match and the
367 value is a list of possible files to save in if the match is non-nil.
369 If the match is a string, it is used as a regexp match on the
370 article. If the match is a symbol, that symbol will be funcalled
371 from the buffer of the article to be saved with the newsgroup as the
372 parameter. If it is a list, it will be evaled in the same buffer.
374 If this form or function returns a string, this string will be used as
375 a possible file name; and if it returns a non-nil list, that list will
376 be used as possible file names."
377 :group 'gnus-article-saving
378 :type '(repeat (choice (list :value (fun) function)
379 (cons :value ("" "") regexp (repeat string))
382 (defcustom gnus-page-delimiter "^\^L"
383 "*Regexp describing what to use as article page delimiters.
384 The default value is \"^\^L\", which is a form linefeed at the
385 beginning of a line."
387 :group 'gnus-article-various)
389 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
390 "*The format specification for the article mode line.
391 See `gnus-summary-mode-line-format' for a closer description."
393 :group 'gnus-article-various)
395 (defcustom gnus-article-mode-hook nil
396 "*A hook for Gnus article mode."
398 :group 'gnus-article-various)
400 (defcustom gnus-article-menu-hook nil
401 "*Hook run after the creation of the article mode menu."
403 :group 'gnus-article-various)
405 (defcustom gnus-article-prepare-hook nil
406 "*A hook called after an article has been prepared in the article buffer.
407 If you want to run a special decoding program like nkf, use this hook."
409 :group 'gnus-article-various)
411 (defcustom gnus-article-hide-pgp-hook nil
412 "*A hook called after successfully hiding a PGP signature."
414 :group 'gnus-article-various)
416 (defcustom gnus-article-button-face 'bold
417 "Face used for highlighting buttons in the article buffer.
419 An article button is a piece of text that you can activate by pressing
420 `RET' or `mouse-2' above it."
422 :group 'gnus-article-buttons)
424 (defcustom gnus-article-mouse-face 'highlight
425 "Face used for mouse highlighting in the article buffer.
427 Article buttons will be displayed in this face when the cursor is
430 :group 'gnus-article-buttons)
432 (defcustom gnus-signature-face 'gnus-signature-face
433 "Face used for highlighting a signature in the article buffer.
434 Obsolete; use the face `gnus-signature-face' for customizations instead."
436 :group 'gnus-article-highlight
437 :group 'gnus-article-signature)
439 (defface gnus-signature-face
442 "Face used for highlighting a signature in the article buffer."
443 :group 'gnus-article-highlight
444 :group 'gnus-article-signature)
446 (defface gnus-header-from-face
449 (:foreground "spring green"))
452 (:foreground "red3"))
455 "Face used for displaying from headers."
456 :group 'gnus-article-headers
457 :group 'gnus-article-highlight)
459 (defface gnus-header-subject-face
462 (:foreground "SeaGreen3"))
465 (:foreground "red4"))
467 (:bold t :italic t)))
468 "Face used for displaying subject headers."
469 :group 'gnus-article-headers
470 :group 'gnus-article-highlight)
472 (defface gnus-header-newsgroups-face
475 (:foreground "yellow" :italic t))
478 (:foreground "MidnightBlue" :italic t))
481 "Face used for displaying newsgroups headers."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-name-face
488 (:foreground "SeaGreen"))
491 (:foreground "maroon"))
494 "Face used for displaying header names."
495 :group 'gnus-article-headers
496 :group 'gnus-article-highlight)
498 (defface gnus-header-content-face
501 (:foreground "forest green" :italic t))
504 (:foreground "indianred4" :italic t))
506 (:italic t))) "Face used for displaying header content."
507 :group 'gnus-article-headers
508 :group 'gnus-article-highlight)
510 (defcustom gnus-header-face-alist
511 '(("From" nil gnus-header-from-face)
512 ("Subject" nil gnus-header-subject-face)
513 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
514 ("" gnus-header-name-face gnus-header-content-face))
515 "*Controls highlighting of article header.
517 An alist of the form (HEADER NAME CONTENT).
519 HEADER is a regular expression which should match the name of an
520 header header and NAME and CONTENT are either face names or nil.
522 The name of each header field will be displayed using the face
523 specified by the first element in the list where HEADER match the
524 header name and NAME is non-nil. Similarly, the content will be
525 displayed by the first non-nil matching CONTENT face."
526 :group 'gnus-article-headers
527 :group 'gnus-article-highlight
528 :type '(repeat (list (regexp :tag "Header")
530 (item :tag "skip" nil)
531 (face :value default))
532 (choice :tag "Content"
533 (item :tag "skip" nil)
534 (face :value default)))))
536 (defcustom gnus-article-decode-hook
537 '(article-decode-charset article-decode-encoded-words)
538 "*Hook run to decode charsets in articles."
539 :group 'gnus-article-headers
542 (defcustom gnus-display-mime-function 'gnus-display-mime
543 "Function to display MIME articles."
544 :group 'gnus-article-headers
547 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
548 "Function used to decode headers.")
550 (defvar gnus-article-dumbquotes-map
569 "Table for MS-to-Latin1 translation.")
571 (defcustom gnus-ignored-mime-types nil
572 "List of MIME types that should be ignored by Gnus."
574 :type '(repeat regexp))
576 (defcustom gnus-treat-body-highlight-signature t
577 "Highlight the signature."
579 :type '(choice (const :tag "Off" nil)
581 (const :tag "Last" last)
582 (integer :tag "Less")
583 (sexp :tag "Predicate")))
585 ;;; Internal variables
587 (defvar gnus-treatment-function-alist
588 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
591 (defvar gnus-article-mime-handle-alist nil)
592 (defvar article-lapsed-timer nil)
593 (defvar gnus-article-current-summary nil)
595 (defvar gnus-article-mode-syntax-table
596 (let ((table (copy-syntax-table text-mode-syntax-table)))
597 (modify-syntax-entry ?- "w" table)
598 (modify-syntax-entry ?> ")" table)
599 (modify-syntax-entry ?< "(" table)
601 "Syntax table used in article mode buffers.
602 Initialized from `text-mode-syntax-table.")
604 (defvar gnus-save-article-buffer nil)
606 (defvar gnus-article-mode-line-format-alist
607 (nconc '((?w (gnus-article-wash-status) ?s))
608 gnus-summary-mode-line-format-alist))
610 (defvar gnus-number-of-articles-to-be-saved nil)
612 (defvar gnus-inhibit-hiding nil)
614 (defsubst gnus-article-hide-text (b e props)
615 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
616 (add-text-properties b e props)
617 (when (memq 'intangible props)
619 (max (1- b) (point-min))
620 b 'intangible (cddr (memq 'intangible props)))))
622 (defsubst gnus-article-unhide-text (b e)
623 "Remove hidden text properties from region between B and E."
624 (remove-text-properties b e gnus-hidden-properties)
625 (when (memq 'intangible gnus-hidden-properties)
626 (put-text-property (max (1- b) (point-min))
629 (defun gnus-article-hide-text-type (b e type)
630 "Hide text of TYPE between B and E."
631 (gnus-article-hide-text
632 b e (cons 'article-type (cons type gnus-hidden-properties))))
634 (defun gnus-article-unhide-text-type (b e type)
635 "Unhide text of TYPE between B and E."
636 (remove-text-properties
637 b e (cons 'article-type (cons type gnus-hidden-properties)))
638 (when (memq 'intangible gnus-hidden-properties)
639 (put-text-property (max (1- b) (point-min))
642 (defun gnus-article-hide-text-of-type (type)
643 "Hide text of TYPE in the current buffer."
645 (let ((b (point-min))
647 (while (setq b (text-property-any b e 'article-type type))
648 (add-text-properties b (incf b) gnus-hidden-properties)))))
650 (defun gnus-article-delete-text-of-type (type)
651 "Delete text of TYPE in the current buffer."
653 (let ((b (point-min)))
654 (while (setq b (text-property-any b (point-max) 'article-type type))
656 b (or (text-property-not-all b (point-max) 'article-type type)
659 (defun gnus-article-delete-invisible-text ()
660 "Delete all invisible text in the current buffer."
662 (let ((b (point-min)))
663 (while (setq b (text-property-any b (point-max) 'invisible t))
665 b (or (text-property-not-all b (point-max) 'invisible t)
668 (defun gnus-article-text-type-exists-p (type)
669 "Say whether any text of type TYPE exists in the buffer."
670 (text-property-any (point-min) (point-max) 'article-type type))
672 (defsubst gnus-article-header-rank ()
673 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
674 (let ((list gnus-sorted-header-list)
677 (when (looking-at (car list))
679 (setq list (cdr list))
683 (defun article-hide-headers (&optional arg delete)
684 "Toggle whether to hide unwanted headers and possibly sort them as well.
685 If given a negative prefix, always show; if given a positive prefix,
687 (interactive (gnus-article-hidden-arg))
689 (if (gnus-article-check-hidden-text 'headers arg)
690 ;; Show boring headers as well.
691 (gnus-article-show-hidden-text 'boring-headers)
692 ;; This function might be inhibited.
693 (unless gnus-inhibit-hiding
696 (let ((buffer-read-only nil)
698 (props (nconc (list 'article-type 'headers)
699 gnus-hidden-properties))
700 (max (1+ (length gnus-sorted-header-list)))
701 (ignored (when (not gnus-visible-headers)
702 (cond ((stringp gnus-ignored-headers)
703 gnus-ignored-headers)
704 ((listp gnus-ignored-headers)
705 (mapconcat 'identity gnus-ignored-headers
708 (cond ((stringp gnus-visible-headers)
709 gnus-visible-headers)
710 ((and gnus-visible-headers
711 (listp gnus-visible-headers))
712 (mapconcat 'identity gnus-visible-headers "\\|"))))
713 (inhibit-point-motion-hooks t)
715 ;; First we narrow to just the headers.
717 (goto-char (point-min))
718 ;; Hide any "From " lines at the beginning of (mail) articles.
719 (while (looking-at "From ")
723 (delete-region (point-min) (point))
724 (gnus-article-hide-text (point-min) (point) props)))
725 ;; Then treat the rest of the header lines.
728 (if (search-forward "\n\n" nil t) ; if there's a body
729 (progn (forward-line -1) (point))
731 ;; Then we use the two regular expressions
732 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
733 ;; select which header lines is to remain visible in the
735 (goto-char (point-min))
736 (while (re-search-forward "^[^ \t]*:" nil t)
738 ;; Mark the rank of the header.
740 (point) (1+ (point)) 'message-rank
741 (if (or (and visible (looking-at visible))
743 (not (looking-at ignored))))
744 (gnus-article-header-rank)
747 (message-sort-headers-1)
748 (when (setq beg (text-property-any
749 (point-min) (point-max) 'message-rank (+ 2 max)))
750 ;; We make the unwanted headers invisible.
752 (delete-region beg (point-max))
753 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
754 (gnus-article-hide-text-type beg (point-max) 'headers))
755 ;; Work around XEmacs lossage.
756 (put-text-property (point-min) beg 'invisible nil))))))))
758 (defun article-hide-boring-headers (&optional arg)
759 "Toggle hiding of headers that aren't very interesting.
760 If given a negative prefix, always show; if given a positive prefix,
762 (interactive (gnus-article-hidden-arg))
763 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
764 (not gnus-show-all-headers))
767 (let ((buffer-read-only nil)
768 (list gnus-boring-article-headers)
769 (inhibit-point-motion-hooks t)
771 (nnheader-narrow-to-headers)
773 (setq elem (pop list))
774 (goto-char (point-min))
776 ;; Hide empty headers.
778 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
780 (gnus-article-hide-text-type
781 (progn (beginning-of-line) (point))
784 (if (re-search-forward "^[^ \t]" nil t)
788 ;; Hide boring Newsgroups header.
789 ((eq elem 'newsgroups)
790 (when (equal (gnus-fetch-field "newsgroups")
791 (gnus-group-real-name
792 (if (boundp 'gnus-newsgroup-name)
795 (gnus-article-hide-header "newsgroups")))
796 ((eq elem 'followup-to)
797 (when (equal (message-fetch-field "followup-to")
798 (message-fetch-field "newsgroups"))
799 (gnus-article-hide-header "followup-to")))
801 (let ((from (message-fetch-field "from"))
802 (reply-to (message-fetch-field "reply-to")))
807 (nth 1 (mail-extract-address-components from))
808 (nth 1 (mail-extract-address-components reply-to)))))
809 (gnus-article-hide-header "reply-to"))))
811 (let ((date (message-fetch-field "date")))
813 (< (days-between (current-time-string) date)
815 (gnus-article-hide-header "date"))))
817 (let ((to (message-fetch-field "to")))
818 (when (> (length to) 1024)
819 (gnus-article-hide-header "to"))))
822 (goto-char (point-min))
823 (while (re-search-forward "^to:" nil t)
824 (setq to-count (1+ to-count)))
826 (while (> to-count 0)
827 (goto-char (point-min))
829 (re-search-forward "^to:" nil nil to-count)
831 (narrow-to-region (point) (point-max))
832 (gnus-article-hide-header "to"))
833 (setq to-count (1- to-count)))))))))))))
835 (defun gnus-article-hide-header (header)
837 (goto-char (point-min))
838 (when (re-search-forward (concat "^" header ":") nil t)
839 (gnus-article-hide-text-type
840 (progn (beginning-of-line) (point))
843 (if (re-search-forward "^[^ \t]" nil t)
848 (defun article-treat-dumbquotes ()
849 "Translate M******** sm*rtq**t*s into proper text."
851 (article-translate-strings gnus-article-dumbquotes-map))
853 (defun article-translate-characters (from to)
854 "Translate all characters in the body of the article according to FROM and TO.
855 FROM is a string of characters to translate from; to is a string of
856 characters to translate to."
858 (goto-char (point-min))
859 (when (search-forward "\n\n" nil t)
860 (let ((buffer-read-only nil)
861 (x (make-string 225 ?x))
863 (while (< (incf i) (length x))
866 (while (< i (length from))
867 (aset x (aref from i) (aref to i))
869 (translate-region (point) (point-max) x)))))
871 (defun article-translate-strings (map)
872 "Translate all string in the body of the article according to MAP.
873 MAP is an alist where the elements are on the form (\"from\" \"to\")."
875 (goto-char (point-min))
876 (when (search-forward "\n\n" nil t)
877 (let ((buffer-read-only nil)
879 (while (setq elem (pop map))
881 (while (search-forward (car elem) nil t)
882 (replace-match (cadr elem)))))))))
884 (defun article-treat-overstrike ()
885 "Translate overstrikes into bold text."
888 (goto-char (point-min))
889 (when (search-forward "\n\n" nil t)
890 (let ((buffer-read-only nil))
891 (while (search-forward "\b" nil t)
892 (let ((next (char-after))
893 (previous (char-after (- (point) 2))))
894 ;; We do the boldification/underlining by hiding the
895 ;; overstrikes and putting the proper text property
899 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
900 (put-text-property (point) (1+ (point)) 'face 'bold))
902 (gnus-article-hide-text-type
903 (1- (point)) (1+ (point)) 'overstrike)
905 (- (point) 2) (1- (point)) 'face 'underline))
907 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
909 (point) (1+ (point)) 'face 'underline)))))))))
911 (defun article-fill ()
912 "Format too long lines."
915 (let ((buffer-read-only nil))
917 (goto-char (point-min))
918 (search-forward "\n\n" nil t)
920 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
921 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
922 (adaptive-fill-mode t))
924 (and (>= (current-column) (min fill-column (window-width)))
925 (/= (preceding-char) ?:)
926 (fill-paragraph nil))
929 (defun article-remove-cr ()
930 "Translate CRLF pairs into LF, and then CR into LF.."
933 (let ((buffer-read-only nil))
934 (goto-char (point-min))
935 (while (search-forward "\r$" nil t)
936 (replace-match "" t t))
937 (goto-char (point-min))
938 (while (search-forward "\r" nil t)
939 (replace-match "\n" t t)))))
941 (defun article-remove-trailing-blank-lines ()
942 "Remove all trailing blank lines from the article."
945 (let ((buffer-read-only nil))
946 (goto-char (point-max))
950 (while (and (not (bobp))
951 (looking-at "^[ \t]*$")
952 (not (gnus-annotation-in-region-p
953 (point) (gnus-point-at-eol))))
958 (defun article-display-x-face (&optional force)
959 "Look for an X-Face header and display it if present."
960 (interactive (list 'force))
962 ;; Delete the old process, if any.
963 (when (process-status "article-x-face")
964 (delete-process "article-x-face"))
965 (let ((inhibit-point-motion-hooks t)
969 (nnheader-narrow-to-headers)
970 (setq from (message-fetch-field "from"))
971 (goto-char (point-min))
972 (while (and gnus-article-x-face-command
975 ;; Check whether this face is censored.
976 (not gnus-article-x-face-too-ugly)
977 (and gnus-article-x-face-too-ugly from
978 (not (string-match gnus-article-x-face-too-ugly
980 ;; Has to be present.
981 (re-search-forward "^X-Face: " nil t))
982 ;; This used to try to do multiple faces (`while' instead of
983 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
984 ;; work (b) it can crash some versions of Emacs (c) are
985 ;; multiple faces really something to encourage?
986 (when (stringp gnus-article-x-face-command)
988 ;; We now have the area of the buffer where the X-Face is stored.
991 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
992 ;; We display the face.
993 (if (symbolp gnus-article-x-face-command)
994 ;; The command is a lisp function, so we call it.
995 (if (gnus-functionp gnus-article-x-face-command)
996 (funcall gnus-article-x-face-command beg end)
997 (error "%s is not a function" gnus-article-x-face-command))
998 ;; The command is a string, so we interpret the command
999 ;; as a, well, command, and fork it off.
1000 (let ((process-connection-type nil))
1001 (process-kill-without-query
1003 "article-x-face" nil shell-file-name shell-command-switch
1004 gnus-article-x-face-command))
1005 (process-send-region "article-x-face" beg end)
1006 (process-send-eof "article-x-face"))))))))))
1008 (defun article-decode-mime-words ()
1009 "Decode all MIME-encoded words in the article."
1012 (set-buffer gnus-article-buffer)
1013 (let ((inhibit-point-motion-hooks t)
1015 (mail-decode-encoded-word-region (point-min) (point-max)))))
1017 (defun article-decode-charset (&optional prompt)
1018 "Decode charset-encoded text in the article.
1019 If PROMPT (the prefix), prompt for a coding system to use."
1023 (message-narrow-to-head)
1024 (let* ((inhibit-point-motion-hooks t)
1025 (case-fold-search t)
1026 (ct (message-fetch-field "Content-Type" t))
1027 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1028 (ctl (and ct (condition-case ()
1029 (mail-header-parse-content-type ct)
1033 (mm-read-coding-system "Charset to decode: "))
1035 (mail-content-type-get ctl 'charset))
1036 (gnus-newsgroup-name
1037 (gnus-group-find-parameter
1038 gnus-newsgroup-name 'charset))))
1040 (goto-char (point-max))
1043 (narrow-to-region (point) (point-max))
1045 (equal (car ctl) "text/plain"))
1047 charset (and cte (intern (downcase
1048 (gnus-strip-whitespace cte))))
1051 (defun article-decode-encoded-words ()
1052 "Remove encoded-word encoding from headers."
1053 (let ((inhibit-point-motion-hooks t)
1054 (buffer-read-only nil))
1056 (message-narrow-to-head)
1057 (funcall gnus-decode-header-function (point-min) (point-max)))))
1059 (defun article-de-quoted-unreadable (&optional force)
1060 "Translate a quoted-printable-encoded article.
1061 If FORCE, decode the article whether it is marked as quoted-printable
1063 (interactive (list 'force))
1065 (let ((buffer-read-only nil)
1066 (type (gnus-fetch-field "content-transfer-encoding")))
1068 (and type (string-match "quoted-printable" (downcase type))))
1069 (goto-char (point-min))
1070 (search-forward "\n\n" nil 'move)
1072 (narrow-to-region (point) (point-max))
1073 (quoted-printable-decode-region (point-min) (point-max))
1074 (when mm-default-coding-system
1075 (mm-decode-body mm-default-coding-system)))))))
1077 (defun article-hide-pgp (&optional arg)
1078 "Toggle hiding of any PGP headers and signatures in the current article.
1079 If given a negative prefix, always show; if given a positive prefix,
1081 (interactive (gnus-article-hidden-arg))
1082 (unless (gnus-article-check-hidden-text 'pgp arg)
1084 (let ((inhibit-point-motion-hooks t)
1085 buffer-read-only beg end)
1087 (goto-char (point-min))
1088 ;; Hide the "header".
1089 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1090 (delete-region (1+ (match-beginning 0)) (match-end 0))
1091 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1092 (when (looking-at "Hash:.*$")
1093 (delete-region (point) (1+ (gnus-point-at-eol))))
1095 ;; Hide the actual signature.
1096 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1097 (setq end (1+ (match-beginning 0)))
1100 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1102 ;; Perhaps we shouldn't hide to the end of the buffer
1103 ;; if there is no end to the signature?
1105 ;; Hide "- " PGP quotation markers.
1107 (narrow-to-region beg end)
1108 (goto-char (point-min))
1109 (while (re-search-forward "^- " nil t)
1111 (match-beginning 0) (match-end 0)))
1113 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1115 (defun article-hide-pem (&optional arg)
1116 "Toggle hiding of any PEM headers and signatures in the current article.
1117 If given a negative prefix, always show; if given a positive prefix,
1119 (interactive (gnus-article-hidden-arg))
1120 (unless (gnus-article-check-hidden-text 'pem arg)
1122 (let (buffer-read-only end)
1124 (goto-char (point-min))
1125 ;; hide the horrendously ugly "header".
1126 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1129 (setq end (1+ (match-beginning 0)))
1130 (gnus-article-hide-text-type
1132 (if (search-forward "\n\n" nil t)
1136 ;; hide the trailer as well
1137 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1140 (gnus-article-hide-text-type
1141 (match-beginning 0) (match-end 0) 'pem))))))
1143 (defun article-hide-signature (&optional arg)
1144 "Hide the signature in the current article.
1145 If given a negative prefix, always show; if given a positive prefix,
1147 (interactive (gnus-article-hidden-arg))
1148 (unless (gnus-article-check-hidden-text 'signature arg)
1151 (let ((buffer-read-only nil))
1152 (when (gnus-article-narrow-to-signature)
1153 (gnus-article-hide-text-type
1154 (point-min) (point-max) 'signature)))))))
1156 (defun article-strip-leading-blank-lines ()
1157 "Remove all blank lines from the beginning of the article."
1160 (let ((inhibit-point-motion-hooks t)
1162 (goto-char (point-min))
1163 (when (search-forward "\n\n" nil t)
1164 (while (and (not (eobp))
1165 (looking-at "[ \t]*$"))
1166 (gnus-delete-line))))))
1168 (defun article-strip-multiple-blank-lines ()
1169 "Replace consecutive blank lines with one empty line."
1172 (let ((inhibit-point-motion-hooks t)
1174 ;; First make all blank lines empty.
1175 (goto-char (point-min))
1176 (search-forward "\n\n" nil t)
1177 (while (re-search-forward "^[ \t]+$" nil t)
1178 (unless (gnus-annotation-in-region-p
1179 (match-beginning 0) (match-end 0))
1180 (replace-match "" nil t)))
1181 ;; Then replace multiple empty lines with a single empty line.
1182 (goto-char (point-min))
1183 (search-forward "\n\n" nil t)
1184 (while (re-search-forward "\n\n\n+" nil t)
1185 (unless (gnus-annotation-in-region-p
1186 (match-beginning 0) (match-end 0))
1187 (replace-match "\n\n" t t))))))
1189 (defun article-strip-leading-space ()
1190 "Remove all white space from the beginning of the lines in the article."
1193 (let ((inhibit-point-motion-hooks t)
1195 (goto-char (point-min))
1196 (search-forward "\n\n" nil t)
1197 (while (re-search-forward "^[ \t]+" nil t)
1198 (replace-match "" t t)))))
1200 (defun article-strip-blank-lines ()
1201 "Strip leading, trailing and multiple blank lines."
1203 (article-strip-leading-blank-lines)
1204 (article-remove-trailing-blank-lines)
1205 (article-strip-multiple-blank-lines))
1207 (defun article-strip-all-blank-lines ()
1208 "Strip all blank lines."
1211 (let ((inhibit-point-motion-hooks t)
1213 (goto-char (point-min))
1214 (search-forward "\n\n" nil t)
1215 (while (re-search-forward "^[ \t]*\n" nil t)
1216 (replace-match "" t t)))))
1218 (defun gnus-article-narrow-to-signature ()
1219 "Narrow to the signature; return t if a signature is found, else nil."
1221 (let ((inhibit-point-motion-hooks t))
1222 (when (gnus-article-search-signature)
1224 ;; Check whether we have some limits to what we consider
1225 ;; to be a signature.
1226 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1227 (list gnus-signature-limit)))
1229 (while (setq limit (pop limits))
1230 (if (or (and (integerp limit)
1231 (< (- (point-max) (point)) limit))
1233 (< (count-lines (point) (point-max)) limit))
1234 (and (gnus-functionp limit)
1236 (and (stringp limit)
1237 (not (re-search-forward limit nil t))))
1238 () ; This limit did not succeed.
1242 (narrow-to-region (point) (point-max))
1245 (defun gnus-article-search-signature ()
1246 "Search the current buffer for the signature separator.
1247 Put point at the beginning of the signature separator."
1248 (let ((cur (point)))
1249 (goto-char (point-max))
1250 (if (if (stringp gnus-signature-separator)
1251 (re-search-backward gnus-signature-separator nil t)
1252 (let ((seps gnus-signature-separator))
1254 (not (re-search-backward (car seps) nil t)))
1262 (autoload 'w3-display "w3-parse")
1263 (autoload 'w3-do-setup "w3" "" t)
1264 (autoload 'w3-region "w3-display" "" t))
1266 (defun gnus-article-treat-html ()
1269 (let ((cbuf (current-buffer)))
1270 (set-buffer gnus-article-buffer)
1271 (let (buf buffer-read-only b e)
1273 (goto-char (point-min))
1275 (if (search-forward "\n\n" nil t)
1278 (setq e (point-max)))
1280 (insert-buffer-substring gnus-article-buffer b e)
1282 (save-window-excursion
1283 (w3-region (point-min) (point-max))
1284 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1286 (delete-region (point-min) (point-max))
1289 (goto-char (point-min))
1290 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1291 (set-buffer cbuf))))
1293 (defun gnus-article-hidden-arg ()
1294 "Return the current prefix arg as a number, or 0 if no prefix."
1295 (list (if current-prefix-arg
1296 (prefix-numeric-value current-prefix-arg)
1299 (defun gnus-article-check-hidden-text (type arg)
1300 "Return nil if hiding is necessary.
1301 Arg can be nil or a number. Nil and positive means hide, negative
1302 means show, 0 means toggle."
1306 (let ((hide (gnus-article-hidden-text-p type)))
1312 (gnus-article-show-hidden-text type))
1314 (if (eq hide 'hidden)
1315 (gnus-article-show-hidden-text type)
1318 (defun gnus-article-hidden-text-p (type)
1319 "Say whether the current buffer contains hidden text of type TYPE."
1320 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1322 (not (get-text-property pos 'invisible)))
1324 (text-property-any (1+ pos) (point-max) 'article-type type)))
1329 (defun gnus-article-show-hidden-text (type &optional hide)
1330 "Show all hidden text of type TYPE.
1331 If HIDE, hide the text instead."
1333 (let ((buffer-read-only nil)
1334 (inhibit-point-motion-hooks t)
1337 (while (setq beg (text-property-any end (point-max) 'article-type type))
1340 (text-property-not-all beg (point-max) 'article-type type)
1343 (gnus-article-hide-text beg end gnus-hidden-properties)
1344 (gnus-article-unhide-text beg end))
1348 (defconst article-time-units
1349 `((year . ,(* 365.25 24 60 60))
1350 (week . ,(* 7 24 60 60))
1351 (day . ,(* 24 60 60))
1355 "Mapping from time units to seconds.")
1357 (defun article-date-ut (&optional type highlight header)
1358 "Convert DATE date to universal time in the current article.
1359 If TYPE is `local', convert to local time; if it is `lapsed', output
1360 how much time has lapsed since DATE."
1361 (interactive (list 'ut t))
1362 (let* ((header (or header
1363 (mail-header-date gnus-current-headers)
1364 (message-fetch-field "date")
1366 (date (if (vectorp header) (mail-header-date header)
1368 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1369 (inhibit-point-motion-hooks t)
1370 bface eface newline)
1371 (when (and date (not (string= date "")))
1374 (nnheader-narrow-to-headers)
1375 (let ((buffer-read-only nil))
1376 ;; Delete any old Date headers.
1377 (if (re-search-forward date-regexp nil t)
1379 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1380 eface (get-text-property (1- (gnus-point-at-eol))
1382 (delete-region (progn (beginning-of-line) (point))
1383 (progn (end-of-line) (point)))
1384 (beginning-of-line))
1385 (goto-char (point-max))
1387 (insert (article-make-date-line date type))
1390 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1391 (put-text-property (match-beginning 1) (1+ (match-end 1))
1393 (put-text-property (match-beginning 2) (match-end 2)
1397 (insert "\n"))))))))
1399 (defun article-make-date-line (date type)
1400 "Return a DATE line of TYPE."
1401 (let ((time (condition-case ()
1405 ;; Convert to the local timezone. We have to slap a
1406 ;; `condition-case' round the calls to the timezone
1407 ;; functions since they aren't particularly resistant to
1410 (let ((tz (car (current-time-zone))))
1411 (format "Date: %s %s%04d" (current-time-string time)
1412 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1413 ;; Convert to Universal Time.
1416 (current-time-string
1417 (let* ((e (parse-time-string date))
1418 (tm (apply 'encode-time e))
1420 (ls (- (cadr tm) (car (current-time-zone)))))
1421 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1422 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1425 ;; Get the original date from the article.
1426 ((eq type 'original)
1427 (concat "Date: " (if (string-match "\n+$" date)
1428 (substring date 0 (match-beginning 0))
1430 ;; Let the user define the format.
1432 (if (gnus-functionp gnus-article-time-format)
1433 (funcall gnus-article-time-format time)
1436 (format-time-string gnus-article-time-format time))))
1441 (format-time-string "%Y%M%DT%h%m%s" time)))
1442 ;; Do an X-Sent lapsed format.
1444 ;; If the date is seriously mangled, the timezone functions are
1445 ;; liable to bug out, so we ignore all errors.
1446 (let* ((now (current-time))
1447 (real-time (subtract-time now time))
1448 (real-sec (and real-time
1449 (+ (* (float (car real-time)) 65536)
1451 (sec (and real-time (abs real-sec)))
1461 ;; This is a bit convoluted, but basically we go
1462 ;; through the time units for years, weeks, etc,
1463 ;; and divide things to see whether that results
1464 ;; in positive answers.
1467 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1468 ;; The (remaining) seconds are too few to
1469 ;; be divided into this time unit.
1471 ;; It's big enough, so we output it.
1472 (setq sec (- sec (* num (cdr unit))))
1474 (concat (if prev ", " "") (int-to-string
1476 " " (symbol-name (car unit))
1477 (if (> num 1) "s" ""))
1479 article-time-units "")
1480 ;; If dates are odd, then it might appear like the
1481 ;; article was sent in the future.
1484 " in the future"))))))
1486 (error "Unknown conversion type: %s" type)))))
1488 (defun article-date-local (&optional highlight)
1489 "Convert the current article date to the local timezone."
1490 (interactive (list t))
1491 (article-date-ut 'local highlight))
1493 (defun article-date-original (&optional highlight)
1494 "Convert the current article date to what it was originally.
1495 This is only useful if you have used some other date conversion
1496 function and want to see what the date was before converting."
1497 (interactive (list t))
1498 (article-date-ut 'original highlight))
1500 (defun article-date-lapsed (&optional highlight)
1501 "Convert the current article date to time lapsed since it was sent."
1502 (interactive (list t))
1503 (article-date-ut 'lapsed highlight))
1505 (defun article-update-date-lapsed ()
1506 "Function to be run from a timer to update the lapsed time line."
1507 (let (deactivate-mark)
1512 (set-buffer (window-buffer w))
1513 (when (eq major-mode 'gnus-article-mode)
1514 (goto-char (point-min))
1515 (when (re-search-forward "^X-Sent:" nil t)
1516 (article-date-lapsed t)))))))))
1518 (defun gnus-start-date-timer (&optional n)
1519 "Start a timer to update the X-Sent header in the article buffers.
1520 The numerical prefix says how frequently (in seconds) the function
1525 (gnus-stop-date-timer)
1526 (setq article-lapsed-timer
1527 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1529 (defun gnus-stop-date-timer ()
1530 "Stop the X-Sent timer."
1532 (when article-lapsed-timer
1533 (nnheader-cancel-timer article-lapsed-timer)
1534 (setq article-lapsed-timer nil)))
1536 (defun article-date-user (&optional highlight)
1537 "Convert the current article date to the user-defined format.
1538 This format is defined by the `gnus-article-time-format' variable."
1539 (interactive (list t))
1540 (article-date-ut 'user highlight))
1542 (defun article-date-iso8601 (&optional highlight)
1543 "Convert the current article date to ISO8601."
1544 (interactive (list t))
1545 (article-date-ut 'iso8601 highlight))
1547 (defun article-show-all ()
1548 "Show all hidden text in the article buffer."
1551 (let ((buffer-read-only nil))
1552 (gnus-article-unhide-text (point-min) (point-max)))))
1554 (defun article-emphasize (&optional arg)
1555 "Emphasize text according to `gnus-emphasis-alist'."
1556 (interactive (gnus-article-hidden-arg))
1557 (unless (gnus-article-check-hidden-text 'emphasis arg)
1559 (let ((alist gnus-emphasis-alist)
1560 (buffer-read-only nil)
1561 (props (append '(article-type emphasis)
1562 gnus-hidden-properties))
1563 regexp elem beg invisible visible face)
1564 (goto-char (point-min))
1565 (search-forward "\n\n" nil t)
1567 (while (setq elem (pop alist))
1569 (setq regexp (car elem)
1570 invisible (nth 1 elem)
1571 visible (nth 2 elem)
1573 (while (re-search-forward regexp nil t)
1574 (when (and (match-beginning visible) (match-beginning invisible))
1575 (gnus-article-hide-text
1576 (match-beginning invisible) (match-end invisible) props)
1577 (gnus-article-unhide-text-type
1578 (match-beginning visible) (match-end visible) 'emphasis)
1579 (gnus-put-text-property-excluding-newlines
1580 (match-beginning visible) (match-end visible) 'face face)
1581 (goto-char (match-end invisible)))))))))
1583 (defvar gnus-summary-article-menu)
1584 (defvar gnus-summary-post-menu)
1586 ;;; Saving functions.
1588 (defun gnus-article-save (save-buffer file &optional num)
1589 "Save the currently selected article."
1590 (unless gnus-save-all-headers
1591 ;; Remove headers according to `gnus-saved-headers'.
1592 (let ((gnus-visible-headers
1593 (or gnus-saved-headers gnus-visible-headers))
1594 (gnus-article-buffer save-buffer))
1596 (set-buffer save-buffer)
1597 (article-hide-headers 1 t))))
1598 (save-window-excursion
1599 (if (not gnus-default-article-saver)
1600 (error "No default saver is defined")
1601 ;; !!! Magic! The saving functions all save
1602 ;; `gnus-save-article-buffer' (or so they think), but we
1603 ;; bind that variable to our save-buffer.
1604 (set-buffer gnus-article-buffer)
1605 (let* ((gnus-save-article-buffer save-buffer)
1608 ((not gnus-prompt-before-saving) 'default)
1609 ((eq gnus-prompt-before-saving 'always) nil)
1611 (gnus-number-of-articles-to-be-saved
1612 (when (eq gnus-prompt-before-saving t)
1614 (set-buffer gnus-article-current-summary)
1615 (funcall gnus-default-article-saver filename)))))
1617 (defun gnus-read-save-file-name (prompt &optional filename
1618 function group headers variable)
1620 (funcall function group headers (symbol-value variable)))
1625 ((eq filename 'default)
1631 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1634 (if (and gnus-number-of-articles-to-be-saved
1635 (> gnus-number-of-articles-to-be-saved 1))
1636 (format "these %d articles"
1637 gnus-number-of-articles-to-be-saved)
1640 ;; Let the split methods have their say.
1642 ;; No split name was found.
1645 (concat prompt " (default "
1646 (file-name-nondirectory default-name) ") ")
1647 (file-name-directory default-name)
1649 ;; A single group name is returned.
1650 ((stringp split-name)
1652 (funcall function split-name headers
1653 (symbol-value variable)))
1655 (concat prompt " (default "
1656 (file-name-nondirectory default-name) ") ")
1657 (file-name-directory default-name)
1659 ;; A single split name was found
1660 ((= 1 (length split-name))
1661 (let* ((name (expand-file-name
1662 (car split-name) gnus-article-save-directory))
1663 (dir (cond ((file-directory-p name)
1664 (file-name-as-directory name))
1665 ((file-exists-p name) name)
1666 (t gnus-article-save-directory))))
1668 (concat prompt " (default " name ") ")
1670 ;; A list of splits was found.
1672 (setq split-name (nreverse split-name))
1674 (let ((file-name-history
1675 (nconc split-name file-name-history)))
1679 (concat prompt " (`M-p' for defaults) ")
1680 gnus-article-save-directory
1682 gnus-article-save-directory)))
1683 (car (push result file-name-history)))))))
1684 ;; Create the directory.
1685 (gnus-make-directory (file-name-directory file))
1686 ;; If we have read a directory, we append the default file name.
1687 (when (file-directory-p file)
1688 (setq file (concat (file-name-as-directory file)
1689 (file-name-nondirectory default-name))))
1690 ;; Possibly translate some characters.
1691 (nnheader-translate-file-chars file)))))
1692 (gnus-make-directory (file-name-directory result))
1693 (set variable result)))
1695 (defun gnus-article-archive-name (group)
1696 "Return the first instance of an \"Archive-name\" in the current buffer."
1697 (let ((case-fold-search t))
1698 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1699 (nnheader-concat gnus-article-save-directory
1700 (match-string 1)))))
1702 (defun gnus-article-nndoc-name (group)
1703 "If GROUP is an nndoc group, return the name of the parent group."
1704 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1705 (gnus-group-get-parameter group 'save-article-group)))
1707 (defun gnus-summary-save-in-rmail (&optional filename)
1708 "Append this article to Rmail file.
1709 Optional argument FILENAME specifies file name.
1710 Directory to save to is default to `gnus-article-save-directory'."
1711 (setq filename (gnus-read-save-file-name
1712 "Save %s in rmail file:" filename
1713 gnus-rmail-save-name gnus-newsgroup-name
1714 gnus-current-headers 'gnus-newsgroup-last-rmail))
1715 (gnus-eval-in-buffer-window gnus-save-article-buffer
1719 (gnus-output-to-rmail filename))))
1722 (defun gnus-summary-save-in-mail (&optional filename)
1723 "Append this article to Unix mail file.
1724 Optional argument FILENAME specifies file name.
1725 Directory to save to is default to `gnus-article-save-directory'."
1726 (setq filename (gnus-read-save-file-name
1727 "Save %s in Unix mail file:" filename
1728 gnus-mail-save-name gnus-newsgroup-name
1729 gnus-current-headers 'gnus-newsgroup-last-mail))
1730 (gnus-eval-in-buffer-window gnus-save-article-buffer
1734 (if (and (file-readable-p filename)
1735 (mail-file-babyl-p filename))
1736 (rmail-output-to-rmail-file filename t)
1737 (gnus-output-to-mail filename)))))
1740 (defun gnus-summary-save-in-file (&optional filename overwrite)
1741 "Append this article to file.
1742 Optional argument FILENAME specifies file name.
1743 Directory to save to is default to `gnus-article-save-directory'."
1744 (setq filename (gnus-read-save-file-name
1745 "Save %s in file:" filename
1746 gnus-file-save-name gnus-newsgroup-name
1747 gnus-current-headers 'gnus-newsgroup-last-file))
1748 (gnus-eval-in-buffer-window gnus-save-article-buffer
1752 (when (and overwrite
1753 (file-exists-p filename))
1754 (delete-file filename))
1755 (gnus-output-to-file filename))))
1758 (defun gnus-summary-write-to-file (&optional filename)
1759 "Write this article to a file.
1760 Optional argument FILENAME specifies file name.
1761 The directory to save in defaults to `gnus-article-save-directory'."
1762 (gnus-summary-save-in-file nil t))
1764 (defun gnus-summary-save-body-in-file (&optional filename)
1765 "Append this article body to a file.
1766 Optional argument FILENAME specifies file name.
1767 The directory to save in defaults to `gnus-article-save-directory'."
1768 (setq filename (gnus-read-save-file-name
1769 "Save %s body in file:" filename
1770 gnus-file-save-name gnus-newsgroup-name
1771 gnus-current-headers 'gnus-newsgroup-last-file))
1772 (gnus-eval-in-buffer-window gnus-save-article-buffer
1776 (goto-char (point-min))
1777 (when (search-forward "\n\n" nil t)
1778 (narrow-to-region (point) (point-max)))
1779 (gnus-output-to-file filename))))
1782 (defun gnus-summary-save-in-pipe (&optional command)
1783 "Pipe this article to subprocess."
1785 (cond ((and (eq command 'default)
1786 gnus-last-shell-command)
1787 gnus-last-shell-command)
1791 "Shell command on %s: "
1792 (if (and gnus-number-of-articles-to-be-saved
1793 (> gnus-number-of-articles-to-be-saved 1))
1794 (format "these %d articles"
1795 gnus-number-of-articles-to-be-saved)
1797 gnus-last-shell-command))))
1798 (when (string-equal command "")
1799 (setq command gnus-last-shell-command))
1800 (gnus-eval-in-buffer-window gnus-article-buffer
1803 (shell-command-on-region (point-min) (point-max) command nil)))
1804 (setq gnus-last-shell-command command))
1806 ;;; Article file names when saving.
1808 (defun gnus-capitalize-newsgroup (newsgroup)
1809 "Capitalize NEWSGROUP name."
1810 (when (not (zerop (length newsgroup)))
1811 (concat (char-to-string (upcase (aref newsgroup 0)))
1812 (substring newsgroup 1))))
1814 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1815 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1816 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1817 Otherwise, it is like ~/News/news/group/num."
1820 (concat (if (gnus-use-long-file-name 'not-save)
1821 (gnus-capitalize-newsgroup newsgroup)
1822 (gnus-newsgroup-directory-form newsgroup))
1823 "/" (int-to-string (mail-header-number headers)))
1824 gnus-article-save-directory)))
1826 (string-equal (file-name-directory default)
1827 (file-name-directory last-file))
1828 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1830 (or last-file default))))
1832 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1833 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1834 If variable `gnus-use-long-file-name' is non-nil, it is
1835 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1838 (concat (if (gnus-use-long-file-name 'not-save)
1840 (gnus-newsgroup-directory-form newsgroup))
1841 "/" (int-to-string (mail-header-number headers)))
1842 gnus-article-save-directory)))
1844 (string-equal (file-name-directory default)
1845 (file-name-directory last-file))
1846 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1848 (or last-file default))))
1850 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1851 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1852 If variable `gnus-use-long-file-name' is non-nil, it is
1853 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1856 (if (gnus-use-long-file-name 'not-save)
1857 (gnus-capitalize-newsgroup newsgroup)
1858 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1859 gnus-article-save-directory)))
1861 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1862 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1863 If variable `gnus-use-long-file-name' is non-nil, it is
1864 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1867 (if (gnus-use-long-file-name 'not-save)
1869 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1870 gnus-article-save-directory)))
1877 (setq afunc (car func)
1880 gfunc (intern (format "gnus-%s" func))))
1882 (if (not (fboundp afunc))
1884 `(lambda (&optional interactive &rest args)
1885 ,(documentation afunc t)
1886 (interactive (list t))
1888 (set-buffer gnus-article-buffer)
1890 (call-interactively ',afunc)
1891 (apply ',afunc args))))))))
1892 '(article-hide-headers
1893 article-hide-boring-headers
1894 article-treat-overstrike
1895 (article-fill . gnus-article-word-wrap)
1897 article-display-x-face
1898 article-de-quoted-unreadable
1899 article-mime-decode-quoted-printable
1902 article-hide-signature
1903 article-remove-trailing-blank-lines
1904 article-strip-leading-blank-lines
1905 article-strip-multiple-blank-lines
1906 article-strip-leading-space
1907 article-strip-blank-lines
1908 article-strip-all-blank-lines
1910 article-date-iso8601
1911 article-date-original
1913 article-decode-mime-words
1914 article-decode-charset
1915 article-decode-encoded-words
1919 article-treat-dumbquotes
1920 (article-show-all . gnus-article-show-all-headers))))
1923 ;;; Gnus article mode
1926 (put 'gnus-article-mode 'mode-class 'special)
1928 (set-keymap-parent gnus-article-mode-map widget-keymap)
1930 (gnus-define-keys gnus-article-mode-map
1931 " " gnus-article-goto-next-page
1932 "\177" gnus-article-goto-prev-page
1933 [delete] gnus-article-goto-prev-page
1934 "\C-c^" gnus-article-refer-article
1935 "h" gnus-article-show-summary
1936 "s" gnus-article-show-summary
1937 "\C-c\C-m" gnus-article-mail
1938 "?" gnus-article-describe-briefly
1939 "e" gnus-article-edit
1940 "<" beginning-of-buffer
1942 "\C-c\C-i" gnus-info-find-node
1945 "\C-d" gnus-article-read-summary-keys
1946 "\M-*" gnus-article-read-summary-keys
1947 "\M-#" gnus-article-read-summary-keys
1948 "\M-^" gnus-article-read-summary-keys
1949 "\M-g" gnus-article-read-summary-keys)
1951 (substitute-key-definition
1952 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1954 (defun gnus-article-make-menu-bar ()
1955 (gnus-turn-off-edit-menu 'article)
1956 (unless (boundp 'gnus-article-article-menu)
1958 gnus-article-article-menu gnus-article-mode-map ""
1960 ["Scroll forwards" gnus-article-goto-next-page t]
1961 ["Scroll backwards" gnus-article-goto-prev-page t]
1962 ["Show summary" gnus-article-show-summary t]
1963 ["Fetch Message-ID at point" gnus-article-refer-article t]
1964 ["Mail to address at point" gnus-article-mail t]
1965 ["Send a bug report" gnus-bug t]))
1968 gnus-article-treatment-menu gnus-article-mode-map ""
1970 ["Hide headers" gnus-article-hide-headers t]
1971 ["Hide signature" gnus-article-hide-signature t]
1972 ["Hide citation" gnus-article-hide-citation t]
1973 ["Treat overstrike" gnus-article-treat-overstrike t]
1974 ["Remove carriage return" gnus-article-remove-cr t]
1975 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1977 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1979 (when (boundp 'gnus-summary-post-menu)
1980 (define-key gnus-article-mode-map [menu-bar post]
1981 (cons "Post" gnus-summary-post-menu)))
1983 (gnus-run-hooks 'gnus-article-menu-hook)))
1985 (defun gnus-article-mode ()
1986 "Major mode for displaying an article.
1988 All normal editing commands are switched off.
1990 The following commands are available in addition to all summary mode
1992 \\<gnus-article-mode-map>
1993 \\[gnus-article-next-page]\t Scroll the article one page forwards
1994 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1995 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1996 \\[gnus-article-show-summary]\t Display the summary buffer
1997 \\[gnus-article-mail]\t Send a reply to the address near point
1998 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1999 \\[gnus-info-find-node]\t Go to the Gnus info node"
2001 (when (gnus-visual-p 'article-menu 'menu)
2002 (gnus-article-make-menu-bar))
2003 (gnus-simplify-mode-line)
2004 (setq mode-name "Article")
2005 (setq major-mode 'gnus-article-mode)
2006 (make-local-variable 'minor-mode-alist)
2007 (use-local-map gnus-article-mode-map)
2008 (gnus-update-format-specifications nil 'article-mode)
2009 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2010 (make-local-variable 'gnus-page-broken)
2011 (make-local-variable 'gnus-button-marker-list)
2012 (make-local-variable 'gnus-article-current-summary)
2013 (make-local-variable 'gnus-article-mime-handles)
2014 (make-local-variable 'gnus-article-decoded-p)
2015 (make-local-variable 'gnus-article-mime-handle-alist)
2016 (gnus-set-default-directory)
2017 (buffer-disable-undo)
2018 (setq buffer-read-only t)
2019 (set-syntax-table gnus-article-mode-syntax-table)
2020 (mm-enable-multibyte)
2021 (gnus-run-hooks 'gnus-article-mode-hook))
2023 (defun gnus-article-setup-buffer ()
2024 "Initialize the article buffer."
2025 (let* ((name (if gnus-single-article-buffer "*Article*"
2026 (concat "*Article " gnus-newsgroup-name "*")))
2028 (progn (string-match "\\*Article" name)
2029 (concat " *Original Article"
2030 (substring name (match-end 0))))))
2031 (setq gnus-article-buffer name)
2032 (setq gnus-original-article-buffer original)
2033 (setq gnus-article-mime-handle-alist nil)
2034 ;; This might be a variable local to the summary buffer.
2035 (unless gnus-single-article-buffer
2037 (set-buffer gnus-summary-buffer)
2038 (setq gnus-article-buffer name)
2039 (setq gnus-original-article-buffer original)
2040 (gnus-set-global-variables)))
2041 ;; Init original article buffer.
2043 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2044 (mm-enable-multibyte)
2045 (setq major-mode 'gnus-original-article-mode)
2046 (make-local-variable 'gnus-original-article))
2047 (if (get-buffer name)
2050 (buffer-disable-undo)
2051 (setq buffer-read-only t)
2052 (unless (eq major-mode 'gnus-article-mode)
2053 (gnus-article-mode))
2056 (set-buffer (gnus-get-buffer-create name))
2058 (make-local-variable 'gnus-summary-buffer)
2059 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2060 (current-buffer)))))
2062 ;; Set article window start at LINE, where LINE is the number of lines
2063 ;; from the head of the article.
2064 (defun gnus-article-set-window-start (&optional line)
2066 (get-buffer-window gnus-article-buffer t)
2068 (set-buffer gnus-article-buffer)
2069 (goto-char (point-min))
2072 (gnus-message 6 "Moved to bookmark")
2073 (search-forward "\n\n" nil t)
2077 (defun gnus-article-prepare (article &optional all-headers header)
2078 "Prepare ARTICLE in article mode buffer.
2079 ARTICLE should either be an article number or a Message-ID.
2080 If ARTICLE is an id, HEADER should be the article headers.
2081 If ALL-HEADERS is non-nil, no headers are hidden."
2083 ;; Make sure we start in a summary buffer.
2084 (unless (eq major-mode 'gnus-summary-mode)
2085 (set-buffer gnus-summary-buffer))
2086 (setq gnus-summary-buffer (current-buffer))
2087 (let* ((gnus-article (if header (mail-header-number header) article))
2088 (summary-buffer (current-buffer))
2089 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2090 (group gnus-newsgroup-name)
2093 (gnus-article-setup-buffer)
2094 (set-buffer gnus-article-buffer)
2095 ;; Deactivate active regions.
2096 (when (and (boundp 'transient-mark-mode)
2097 transient-mark-mode)
2098 (setq mark-active nil))
2099 (if (not (setq result (let ((buffer-read-only nil))
2100 (gnus-request-article-this-buffer
2102 ;; There is no such article.
2104 (when (and (numberp article)
2105 (not (memq article gnus-newsgroup-sparse)))
2106 (setq gnus-article-current
2107 (cons gnus-newsgroup-name article))
2108 (set-buffer gnus-summary-buffer)
2109 (setq gnus-current-article article)
2110 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2112 (gnus-summary-set-agent-mark article)
2113 (message "Message marked for downloading"))
2114 (gnus-summary-mark-article article gnus-canceled-mark)
2115 (unless (memq article gnus-newsgroup-sparse)
2117 "No such article (may have expired or been canceled)")))))
2118 (if (or (eq result 'pseudo)
2119 (eq result 'nneething))
2122 (set-buffer summary-buffer)
2123 (push article gnus-newsgroup-history)
2124 (setq gnus-last-article gnus-current-article
2125 gnus-current-article 0
2126 gnus-current-headers nil
2127 gnus-article-current nil)
2128 (if (eq result 'nneething)
2129 (gnus-configure-windows 'summary)
2130 (gnus-configure-windows 'article))
2131 (gnus-set-global-variables))
2132 (gnus-set-mode-line 'article))
2133 ;; The result from the `request' was an actual article -
2134 ;; or at least some text that is now displayed in the
2136 (when (and (numberp article)
2137 (not (eq article gnus-current-article)))
2138 ;; Seems like a new article has been selected.
2139 ;; `gnus-current-article' must be an article number.
2141 (set-buffer summary-buffer)
2142 (push article gnus-newsgroup-history)
2143 (setq gnus-last-article gnus-current-article
2144 gnus-current-article article
2145 gnus-current-headers
2146 (gnus-summary-article-header gnus-current-article)
2147 gnus-article-current
2148 (cons gnus-newsgroup-name gnus-current-article))
2149 (unless (vectorp gnus-current-headers)
2150 (setq gnus-current-headers nil))
2151 (gnus-summary-goto-subject gnus-current-article)
2152 (when (gnus-summary-show-thread)
2153 ;; If the summary buffer really was folded, the
2154 ;; previous goto may not actually have gone to
2155 ;; the right article, but the thread root instead.
2157 (gnus-summary-goto-subject gnus-current-article))
2158 (gnus-run-hooks 'gnus-mark-article-hook)
2159 (gnus-set-mode-line 'summary)
2160 (when (gnus-visual-p 'article-highlight 'highlight)
2161 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2162 ;; Set the global newsgroup variables here.
2163 ;; Suggested by Jim Sisolak
2164 ;; <sisolak@trans4.neep.wisc.edu>.
2165 (gnus-set-global-variables)
2166 (setq gnus-have-all-headers
2167 (or all-headers gnus-show-all-headers))))
2168 (when (or (numberp article)
2170 (gnus-article-prepare-display)
2172 (goto-char (point-min))
2173 (setq gnus-page-broken
2174 (when gnus-break-pages
2175 (gnus-narrow-to-page)
2177 (gnus-set-mode-line 'article)
2178 (gnus-configure-windows 'article)
2179 (goto-char (point-min))
2180 (search-forward "\n\n" nil t)
2181 (set-window-point (get-buffer-window (current-buffer)) (point))
2184 (defun gnus-article-prepare-display ()
2185 "Make the current buffer look like a nice article."
2186 ;; Hooks for getting information from the article.
2187 ;; This hook must be called before being narrowed.
2188 (let ((gnus-article-buffer (current-buffer))
2190 (unless (eq major-mode 'gnus-article-mode)
2191 (gnus-article-mode))
2192 (setq buffer-read-only nil)
2193 (gnus-run-hooks 'gnus-tmp-internal-hook)
2194 (gnus-run-hooks 'gnus-article-prepare-hook)
2195 (when gnus-display-mime-function
2196 (let ((url-standalone-mode (not gnus-plugged)))
2197 (funcall gnus-display-mime-function)))
2198 ;; Perform the article display hooks.
2199 (gnus-run-hooks 'gnus-article-display-hook)))
2202 ;;; Gnus MIME viewing functions
2205 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2206 "The following specs can be used:
2208 %n The `name' parameter
2209 %d The description, if any
2210 %l The length of the encoded part
2211 %p The part identifier
2212 %e Dots if the part isn't displayed")
2214 (defvar gnus-mime-button-line-format-alist
2215 '((?t gnus-tmp-type ?s)
2216 (?n gnus-tmp-name ?s)
2217 (?d gnus-tmp-description ?s)
2219 (?l gnus-tmp-length ?d)
2220 (?e gnus-tmp-dots ?s)))
2222 (defvar gnus-mime-button-commands
2223 '((gnus-article-press-button "\r" "Toggle Display")
2224 ;(gnus-mime-view-part "\M-\r" "View Interactively...")
2225 (gnus-mime-view-part "v" "View Interactively...")
2226 (gnus-mime-save-part "o" "Save...")
2227 (gnus-mime-copy-part "c" "View In Buffer")
2228 (gnus-mime-inline-part "i" "View Inline")
2229 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2231 (defvar gnus-mime-button-map nil)
2232 (unless gnus-mime-button-map
2233 (setq gnus-mime-button-map (make-sparse-keymap))
2234 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2235 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2236 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2238 (define-key gnus-mime-button-map (cadr c) (car c)))
2239 gnus-mime-button-commands))
2241 (defun gnus-mime-button-menu (event)
2242 "Construct a context-sensitive menu of MIME commands."
2244 (let ((response (x-popup-menu
2246 ("" ,@(mapcar (lambda (c)
2247 (cons (caddr c) (car c)))
2248 gnus-mime-button-commands)))))
2249 (pos (event-start event)))
2251 (set-buffer (window-buffer (posn-window pos)))
2252 (goto-char (posn-point pos))
2253 (funcall response))))
2255 (defun gnus-mime-view-all-parts ()
2256 "View all the MIME parts."
2258 (let ((handles gnus-article-mime-handles))
2260 (mm-display-part (pop handles)))))
2262 (defun gnus-mime-save-part ()
2263 "Save the MIME part under point."
2265 (let ((data (get-text-property (point) 'gnus-data)))
2266 (mm-save-part data)))
2268 (defun gnus-mime-pipe-part ()
2269 "Pipe the MIME part under point to a process."
2271 (let ((data (get-text-property (point) 'gnus-data)))
2272 (mm-pipe-part data)))
2274 (defun gnus-mime-view-part ()
2275 "Interactively choose a view method for the MIME part under point."
2277 (let ((data (get-text-property (point) 'gnus-data))
2278 (url-standalone-mode (not gnus-plugged)))
2279 (mm-interactively-view-part data)))
2281 (defun gnus-mime-copy-part ()
2282 "Put the the MIME part under point into a new buffer."
2284 (let* ((handle (get-text-property (point) 'gnus-data))
2285 (contents (mm-get-part handle))
2286 (buffer (generate-new-buffer
2287 (file-name-nondirectory
2289 (mail-content-type-get (mm-handle-type handle) 'name)
2290 (mail-content-type-get (mm-handle-type handle)
2293 (switch-to-buffer buffer)
2296 (goto-char (point-min))))
2298 (defun gnus-mime-inline-part ()
2299 "Insert the MIME part under point into the current buffer."
2301 (let* ((data (get-text-property (point) 'gnus-data))
2302 (contents (mm-get-part data))
2303 (url-standalone-mode (not gnus-plugged))
2306 (if (mm-handle-undisplayer data)
2307 (mm-remove-part data)
2309 (mm-insert-inline data contents)
2312 (defun gnus-article-view-part (n)
2313 "View MIME part N, which is the numerical prefix."
2315 (save-current-buffer
2316 (set-buffer gnus-article-buffer)
2317 (when (> n (length gnus-article-mime-handle-alist))
2318 (error "No such part"))
2319 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2320 (gnus-article-goto-part n)
2321 (if (equal (car handle) "multipart/alternative")
2322 (gnus-article-press-button)
2323 (when (eq (gnus-mm-display-part handle) 'internal)
2324 (gnus-set-window-start))))))
2326 (defun gnus-mm-display-part (handle)
2327 "Display HANDLE and fix MIME button."
2328 (let ((id (get-text-property (point) 'gnus-part))
2331 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2332 (gnus-insert-mime-button
2333 handle id (list (not (mm-handle-displayed-p handle))))
2335 (let ((window (selected-window)))
2339 (select-window (get-buffer-window (current-buffer) t))
2340 (mm-display-part handle))
2341 (select-window window))))
2342 (goto-char point))))
2344 (defun gnus-article-goto-part (n)
2345 "Go to MIME part N."
2346 (goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
2348 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2349 (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2350 (gnus-tmp-type (car (mm-handle-type handle)))
2351 (gnus-tmp-description (mm-handle-description handle))
2353 (if (if displayed (car displayed)
2354 (mm-handle-displayed-p handle))
2356 (gnus-tmp-length (save-excursion
2357 (set-buffer (mm-handle-buffer handle))
2362 (concat " (" gnus-tmp-name ")")
2364 (setq gnus-tmp-description
2365 (if gnus-tmp-description
2366 (concat " (" gnus-tmp-description ")")
2370 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2371 `(local-map ,gnus-mime-button-map
2372 keymap ,gnus-mime-button-map
2373 gnus-callback gnus-mm-display-part
2374 gnus-part ,gnus-tmp-id
2375 article-type annotation
2378 (widget-convert-button 'link b e :action 'gnus-widget-press-button
2379 :button-keymap gnus-mime-button-map)))
2381 (defun gnus-widget-press-button (elems el)
2382 (goto-char (widget-get elems :from))
2383 (let ((url-standalone-mode (not gnus-plugged)))
2384 (gnus-article-press-button)))
2386 (defun gnus-display-mime (&optional ihandles)
2387 "Insert MIME buttons in the buffer."
2388 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2389 handle name type b e display)
2392 ;; Top-level call; we clean up.
2393 (mm-destroy-parts gnus-article-mime-handles)
2394 (setq gnus-article-mime-handles handles
2395 gnus-article-mime-handle-alist nil)
2396 (goto-char (point-min))
2397 (search-forward "\n\n" nil t)
2398 (delete-region (point) (point-max)))
2399 (if (stringp (car handles))
2400 (if (equal (car handles) "multipart/alternative")
2401 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2402 (push (cons id handles) gnus-article-mime-handle-alist)
2403 (gnus-mime-display-alternative (cdr handles) nil nil id))
2404 (gnus-mime-display-mixed (cdr handles)))
2405 (gnus-mime-display-single handles)))))
2407 (defun gnus-mime-display-mixed (handles)
2409 (while (setq handle (pop handles))
2410 (if (stringp (car handle))
2411 (if (equal (car handle) "multipart/alternative")
2412 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2413 (push (cons id handle) gnus-article-mime-handle-alist)
2414 (gnus-mime-display-alternative (cdr handle) nil nil id))
2415 (gnus-mime-display-mixed (cdr handle)))
2416 (gnus-mime-display-single handle)))))
2418 (defun gnus-mime-display-single (handle)
2419 (let ((type (car (mm-handle-type handle)))
2420 (ignored gnus-ignored-mime-types)
2425 (when (string-match (pop ignored) type)
2426 (throw 'ignored nil)))
2427 (if (and (mm-automatic-display-p type)
2428 (mm-inlinable-part-p type)
2429 (or (not (mm-handle-disposition handle))
2430 (equal (car (mm-handle-disposition handle))
2433 (when (equal (car (split-string type "/"))
2436 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2437 (push (cons id handle) gnus-article-mime-handle-alist)
2438 (gnus-insert-mime-button handle id (list (or display text))))
2443 (mm-display-part handle t)
2444 (goto-char (point-max)))
2448 (mm-insert-inline handle (mm-get-part handle))
2449 (goto-char (point-max))))))))
2451 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2452 (let* ((preferred (mm-preferred-alternative handles preferred))
2455 handle buffer-read-only from props begend not-pref)
2458 (narrow-to-region (car ibegend) (cdr ibegend))
2459 (delete-region (point-min) (point-max))
2460 (mm-remove-parts handles))
2461 (setq begend (list (point-marker)))
2463 (unless (setq not-pref (cadr (member preferred ihandles)))
2464 (setq not-pref (car ihandles)))
2465 (gnus-add-text-properties
2468 (insert (format "%d. " id))
2472 (gnus-mime-display-alternative
2473 ',ihandles ,(if (stringp (car not-pref))
2475 (car (mm-handle-type not-pref)))
2477 local-map ,gnus-mime-button-map
2478 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2479 face ,gnus-article-button-face
2480 keymap ,gnus-mime-button-map
2483 (widget-convert-button 'link from (point)
2484 :action 'gnus-widget-press-button
2485 :button-keymap gnus-widget-button-keymap)
2487 (while (setq handle (pop handles))
2488 (gnus-add-text-properties
2491 (insert (format "[%c] %-18s"
2492 (if (equal handle preferred) ?* ? )
2493 (if (stringp (car handle))
2495 (car (mm-handle-type handle)))))
2499 (gnus-mime-display-alternative
2500 ',ihandles ,(if (stringp (car handle))
2502 (car (mm-handle-type handle)))
2504 local-map ,gnus-mime-button-map
2505 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2506 face ,gnus-article-button-face
2507 keymap ,gnus-mime-button-map
2510 (widget-convert-button 'link from (point)
2511 :action 'gnus-widget-press-button
2512 :button-keymap gnus-widget-button-keymap)
2516 (if (stringp (car preferred))
2517 (gnus-display-mime preferred)
2518 (mm-display-part preferred)
2519 (goto-char (point-max))
2520 (setcdr begend (point-marker)))))
2522 (goto-char point))))
2524 (defun gnus-article-wash-status ()
2525 "Return a string which display status of article washing."
2527 (set-buffer gnus-article-buffer)
2528 (let ((cite (gnus-article-hidden-text-p 'cite))
2529 (headers (gnus-article-hidden-text-p 'headers))
2530 (boring (gnus-article-hidden-text-p 'boring-headers))
2531 (pgp (gnus-article-hidden-text-p 'pgp))
2532 (pem (gnus-article-hidden-text-p 'pem))
2533 (signature (gnus-article-hidden-text-p 'signature))
2534 (overstrike (gnus-article-hidden-text-p 'overstrike))
2535 (emphasis (gnus-article-hidden-text-p 'emphasis)))
2536 (format "%c%c%c%c%c%c"
2538 (if (or headers boring) ?h ? )
2539 (if (or pgp pem) ?p ? )
2540 (if signature ?s ? )
2541 (if overstrike ?o ? )
2542 (if emphasis ?e ? )))))
2544 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2546 (defun gnus-article-maybe-hide-headers ()
2547 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2548 Provided for backwards compatibility."
2549 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2551 (gnus-article-hide-headers)))
2555 (defun gnus-output-to-file (file-name)
2556 "Append the current article to a file named FILE-NAME."
2557 (let ((artbuf (current-buffer)))
2559 (insert-buffer-substring artbuf)
2560 ;; Append newline at end of the buffer as separator, and then
2562 (goto-char (point-max))
2564 (append-to-file (point-min) (point-max) file-name)
2567 (defun gnus-narrow-to-page (&optional arg)
2568 "Narrow the article buffer to a page.
2569 If given a numerical ARG, move forward ARG pages."
2571 (setq arg (if arg (prefix-numeric-value arg) 0))
2573 (set-buffer gnus-article-buffer)
2574 (goto-char (point-min))
2576 ;; Remove any old next/prev buttons.
2577 (when (gnus-visual-p 'page-marker)
2578 (let ((buffer-read-only nil))
2579 (gnus-remove-text-with-property 'gnus-prev)
2580 (gnus-remove-text-with-property 'gnus-next)))
2583 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2585 (re-search-forward page-delimiter nil 'move arg)))
2586 (goto-char (match-end 0)))
2589 (if (re-search-forward page-delimiter nil 'move)
2592 (when (and (gnus-visual-p 'page-marker)
2593 (not (= (point-min) 1)))
2595 (goto-char (point-min))
2596 (gnus-insert-prev-page-button)))
2597 (when (and (gnus-visual-p 'page-marker)
2598 (< (+ (point-max) 2) (buffer-size)))
2600 (goto-char (point-max))
2601 (gnus-insert-next-page-button)))))
2603 ;; Article mode commands
2605 (defun gnus-article-goto-next-page ()
2606 "Show the next page of the article."
2608 (when (gnus-article-next-page)
2609 (goto-char (point-min))
2610 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2612 (defun gnus-article-goto-prev-page ()
2613 "Show the next page of the article."
2615 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2616 (gnus-article-prev-page nil)))
2618 (defun gnus-article-next-page (&optional lines)
2619 "Show the next page of the current article.
2620 If end of article, return non-nil. Otherwise return nil.
2621 Argument LINES specifies lines to be scrolled up."
2623 (move-to-window-line -1)
2626 (and (pos-visible-in-window-p) ;Not continuation line.
2628 ;; Nothing in this page.
2629 (if (or (not gnus-page-broken)
2632 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2634 (gnus-narrow-to-page 1) ;Go to next page.
2636 ;; More in this page.
2637 (let ((scroll-in-place nil))
2641 ;; Long lines may cause an end-of-buffer error.
2642 (goto-char (point-max)))))
2643 (move-to-window-line 0)
2646 (defun gnus-article-prev-page (&optional lines)
2647 "Show previous page of current article.
2648 Argument LINES specifies lines to be scrolled down."
2650 (move-to-window-line 0)
2651 (if (and gnus-page-broken
2653 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2655 (gnus-narrow-to-page -1) ;Go to previous page.
2656 (goto-char (point-max))
2658 (let ((scroll-in-place nil))
2662 (beginning-of-buffer
2663 (goto-char (point-min))))
2664 (move-to-window-line 0)))))
2666 (defun gnus-article-refer-article ()
2667 "Read article specified by message-id around point."
2669 (let ((point (point)))
2670 (search-forward ">" nil t) ;Move point to end of "<....>".
2671 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2672 (let ((message-id (match-string 1)))
2674 (set-buffer gnus-summary-buffer)
2675 (gnus-summary-refer-article message-id))
2677 (error "No references around point"))))
2679 (defun gnus-article-show-summary ()
2680 "Reconfigure windows to show summary buffer."
2682 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2683 (error "There is no summary buffer for this article buffer")
2684 (gnus-article-set-globals)
2685 (gnus-configure-windows 'article)
2686 (gnus-summary-goto-subject gnus-current-article)
2687 (gnus-summary-position-point)))
2689 (defun gnus-article-describe-briefly ()
2690 "Describe article mode commands briefly."
2693 (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")))
2695 (defun gnus-article-summary-command ()
2696 "Execute the last keystroke in the summary buffer."
2698 (let ((obuf (current-buffer))
2699 (owin (current-window-configuration))
2701 (switch-to-buffer gnus-article-current-summary 'norecord)
2702 (setq func (lookup-key (current-local-map) (this-command-keys)))
2703 (call-interactively func)
2705 (set-window-configuration owin)
2706 (set-window-point (get-buffer-window (current-buffer)) (point))))
2708 (defun gnus-article-summary-command-nosave ()
2709 "Execute the last keystroke in the summary buffer."
2712 (pop-to-buffer gnus-article-current-summary 'norecord)
2713 (setq func (lookup-key (current-local-map) (this-command-keys)))
2714 (call-interactively func)))
2716 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2717 "Read a summary buffer key sequence and execute it from the article buffer."
2720 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2721 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2722 "=" "^" "\M-^" "|"))
2728 '("n" "Gn" "p" "Gp"))
2731 (set-buffer gnus-article-current-summary)
2732 (let (gnus-pick-mode)
2733 (push (or key last-command-event) unread-command-events)
2734 (setq keys (read-key-sequence nil))))
2737 (if (or (member keys nosaves)
2738 (member keys nosave-but-article)
2739 (member keys nosave-in-article))
2741 (save-window-excursion
2742 (pop-to-buffer gnus-article-current-summary 'norecord)
2743 ;; We disable the pick minor mode commands.
2744 (let (gnus-pick-mode)
2745 (setq func (lookup-key (current-local-map) keys))))
2748 (unless (member keys nosave-in-article)
2749 (set-buffer gnus-article-current-summary))
2750 (call-interactively func)
2751 (setq new-sum-point (point)))
2752 (when (member keys nosave-but-article)
2753 (pop-to-buffer gnus-article-buffer 'norecord)))
2754 ;; These commands should restore window configuration.
2755 (let ((obuf (current-buffer))
2756 (owin (current-window-configuration))
2758 (summary gnus-article-current-summary)
2759 func in-buffer selected)
2760 (if not-restore-window
2761 (pop-to-buffer summary 'norecord)
2762 (switch-to-buffer summary 'norecord))
2763 (setq in-buffer (current-buffer))
2764 ;; We disable the pick minor mode commands.
2765 (if (setq func (let (gnus-pick-mode)
2766 (lookup-key (current-local-map) keys)))
2768 (call-interactively func)
2769 (setq new-sum-point (point)))
2771 (when (eq in-buffer (current-buffer))
2772 (setq selected (gnus-summary-select-article))
2774 (unless not-restore-window
2775 (set-window-configuration owin))
2776 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2777 (set-window-point (get-buffer-window (current-buffer))
2779 (let ((win (get-buffer-window gnus-article-current-summary)))
2781 (set-window-point win new-sum-point))))))))
2783 (defun gnus-article-hide (&optional arg force)
2784 "Hide all the gruft in the current article.
2785 This means that PGP stuff, signatures, cited text and (some)
2786 headers will be hidden.
2787 If given a prefix, show the hidden text instead."
2788 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2789 (gnus-article-hide-headers arg)
2790 (gnus-article-hide-pgp arg)
2791 (gnus-article-hide-citation-maybe arg force)
2792 (gnus-article-hide-signature arg))
2794 (defun gnus-article-maybe-highlight ()
2795 "Do some article highlighting if article highlighting is requested."
2796 (when (gnus-visual-p 'article-highlight 'highlight)
2797 (gnus-article-highlight-some)))
2799 (defun gnus-check-group-server ()
2800 ;; Make sure the connection to the server is alive.
2801 (unless (gnus-server-opened
2802 (gnus-find-method-for-group gnus-newsgroup-name))
2803 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2804 (gnus-request-group gnus-newsgroup-name t)))
2806 (defun gnus-request-article-this-buffer (article group)
2807 "Get an article and insert it into this buffer."
2808 (let (do-update-line sparse-header)
2812 (gnus-kill-all-overlays)
2813 (setq group (or group gnus-newsgroup-name))
2815 ;; Using `gnus-request-article' directly will insert the article into
2816 ;; `nntp-server-buffer' - so we'll save some time by not having to
2817 ;; copy it from the server buffer into the article buffer.
2819 ;; We only request an article by message-id when we do not have the
2820 ;; headers for it, so we'll have to get those.
2821 (when (stringp article)
2822 (let ((gnus-override-method gnus-refer-article-method))
2823 (gnus-read-header article)))
2825 ;; If the article number is negative, that means that this article
2826 ;; doesn't belong in this newsgroup (possibly), so we find its
2827 ;; message-id and request it by id instead of number.
2828 (when (and (numberp article)
2830 (get-buffer gnus-summary-buffer)
2831 (gnus-buffer-exists-p gnus-summary-buffer))
2833 (set-buffer gnus-summary-buffer)
2834 (let ((header (gnus-summary-article-header article)))
2837 ((memq article gnus-newsgroup-sparse)
2838 ;; This is a sparse gap article.
2839 (setq do-update-line article)
2840 (setq article (mail-header-id header))
2841 (let ((gnus-override-method gnus-refer-article-method))
2842 (setq sparse-header (gnus-read-header article)))
2843 (setq gnus-newsgroup-sparse
2844 (delq article gnus-newsgroup-sparse)))
2846 ;; It's a real article.
2847 (setq article (mail-header-id header)))
2849 ;; It is an extracted pseudo-article.
2850 (setq article 'pseudo)
2851 (gnus-request-pseudo-article header))))
2853 (let ((method (gnus-find-method-for-group
2854 gnus-newsgroup-name)))
2855 (when (and (eq (car method) 'nneething)
2858 (file-name-as-directory
2859 (or (cadr (assq 'nneething-address method))
2861 (mail-header-subject header))))
2862 (when (file-directory-p dir)
2863 (setq article 'nneething)
2864 (gnus-group-enter-directory dir))))))))
2867 ;; Refuse to select canceled articles.
2868 ((and (numberp article)
2870 (get-buffer gnus-summary-buffer)
2871 (gnus-buffer-exists-p gnus-summary-buffer)
2872 (eq (cdr (save-excursion
2873 (set-buffer gnus-summary-buffer)
2874 (assq article gnus-newsgroup-reads)))
2875 gnus-canceled-mark))
2877 ;; We first check `gnus-original-article-buffer'.
2878 ((and (get-buffer gnus-original-article-buffer)
2881 (set-buffer gnus-original-article-buffer)
2882 (and (equal (car gnus-original-article) group)
2883 (eq (cdr gnus-original-article) article))))
2884 (insert-buffer-substring gnus-original-article-buffer)
2886 ;; Check the backlog.
2887 ((and gnus-keep-backlog
2888 (gnus-backlog-request-article group article (current-buffer)))
2890 ;; Check asynchronous pre-fetch.
2891 ((gnus-async-request-fetched-article group article (current-buffer))
2892 (gnus-async-prefetch-next group article gnus-summary-buffer)
2893 (when (and (numberp article) gnus-keep-backlog)
2894 (gnus-backlog-enter-article group article (current-buffer)))
2897 ((and gnus-use-cache
2899 (gnus-cache-request-article article group))
2901 ;; Get the article and put into the article buffer.
2902 ((or (stringp article) (numberp article))
2903 (let ((gnus-override-method
2904 (and (stringp article) gnus-refer-article-method))
2905 (buffer-read-only nil))
2907 (gnus-kill-all-overlays)
2908 (gnus-check-group-server)
2909 (when (gnus-request-article article group (current-buffer))
2910 (when (numberp article)
2911 (gnus-async-prefetch-next group article gnus-summary-buffer)
2912 (when gnus-keep-backlog
2913 (gnus-backlog-enter-article
2914 group article (current-buffer))))
2919 ;; Associate this article with the current summary buffer.
2920 (setq gnus-article-current-summary gnus-summary-buffer)
2922 ;; Take the article from the original article buffer
2923 ;; and place it in the buffer it's supposed to be in.
2924 (when (and (get-buffer gnus-article-buffer)
2925 (equal (buffer-name (current-buffer))
2926 (buffer-name (get-buffer gnus-article-buffer))))
2928 (if (get-buffer gnus-original-article-buffer)
2929 (set-buffer gnus-original-article-buffer)
2930 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2931 (buffer-disable-undo)
2932 (setq major-mode 'gnus-original-article-mode)
2933 (setq buffer-read-only t))
2934 (let (buffer-read-only)
2936 (insert-buffer-substring gnus-article-buffer))
2937 (setq gnus-original-article (cons group article)))
2940 (run-hooks 'gnus-article-decode-hook)
2941 ;; Mark article as decoded or not.
2942 (setq gnus-article-decoded-p gnus-article-decode-hook))
2944 ;; Update sparse articles.
2945 (when (and do-update-line
2946 (or (numberp article)
2948 (let ((buf (current-buffer)))
2949 (set-buffer gnus-summary-buffer)
2950 (gnus-summary-update-article do-update-line sparse-header)
2951 (gnus-summary-goto-subject do-update-line nil t)
2952 (set-window-point (get-buffer-window (current-buffer) t)
2954 (set-buffer buf))))))
2960 (defcustom gnus-article-edit-mode-hook nil
2961 "Hook run in article edit mode buffers."
2962 :group 'gnus-article-various
2965 (defvar gnus-article-edit-done-function nil)
2967 (defvar gnus-article-edit-mode-map nil)
2969 ;; Should we be using derived.el for this?
2970 (unless gnus-article-edit-mode-map
2971 (setq gnus-article-edit-mode-map (make-sparse-keymap))
2972 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
2974 (gnus-define-keys gnus-article-edit-mode-map
2975 "\C-c\C-c" gnus-article-edit-done
2976 "\C-c\C-k" gnus-article-edit-exit)
2978 (gnus-define-keys (gnus-article-edit-wash-map
2979 "\C-c\C-w" gnus-article-edit-mode-map)
2980 "f" gnus-article-edit-full-stops))
2982 (defun gnus-article-edit-mode ()
2983 "Major mode for editing articles.
2984 This is an extended text-mode.
2986 \\{gnus-article-edit-mode-map}"
2988 (setq major-mode 'gnus-article-edit-mode)
2989 (setq mode-name "Article Edit")
2990 (use-local-map gnus-article-edit-mode-map)
2991 (make-local-variable 'gnus-article-edit-done-function)
2992 (make-local-variable 'gnus-prev-winconf)
2993 (setq buffer-read-only nil)
2994 (buffer-enable-undo)
2996 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2998 (defun gnus-article-edit (&optional force)
2999 "Edit the current article.
3000 This will have permanent effect only in mail groups.
3001 If FORCE is non-nil, allow editing of articles even in read-only
3004 (when (and (not force)
3005 (gnus-group-read-only-p))
3006 (error "The current newsgroup does not support article editing"))
3007 (gnus-article-date-original)
3008 (gnus-article-edit-article
3009 `(lambda (no-highlight)
3010 (gnus-summary-edit-article-done
3011 ,(or (mail-header-references gnus-current-headers) "")
3012 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3014 (defun gnus-article-edit-article (exit-func)
3015 "Start editing the contents of the current article buffer."
3016 (let ((winconf (current-window-configuration)))
3017 (set-buffer gnus-article-buffer)
3018 (gnus-article-edit-mode)
3019 (gnus-article-delete-text-of-type 'annotation)
3020 (gnus-set-text-properties (point-min) (point-max) nil)
3021 (gnus-configure-windows 'edit-article)
3022 (setq gnus-article-edit-done-function exit-func)
3023 (setq gnus-prev-winconf winconf)
3024 (gnus-message 6 "C-c C-c to end edits")))
3026 (defun gnus-article-edit-done (&optional arg)
3027 "Update the article edits and exit."
3032 (goto-char (point-min))
3033 (when (search-forward "\n\n" nil 1)
3034 (let ((lines (count-lines (point) (point-max)))
3035 (length (- (point-max) (point)))
3036 (case-fold-search t)
3037 (body (copy-marker (point))))
3038 (goto-char (point-min))
3039 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3040 (delete-region (match-beginning 1) (match-end 1))
3041 (insert (number-to-string length)))
3042 (goto-char (point-min))
3043 (when (re-search-forward
3044 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3045 (delete-region (match-beginning 1) (match-end 1))
3046 (insert (number-to-string length)))
3047 (goto-char (point-min))
3048 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3049 (delete-region (match-beginning 1) (match-end 1))
3050 (insert (number-to-string lines)))))))
3051 (let ((func gnus-article-edit-done-function)
3052 (buf (current-buffer))
3053 (start (window-start)))
3054 (gnus-article-edit-exit)
3057 (let ((buffer-read-only nil))
3059 ;; The cache and backlog have to be flushed somewhat.
3060 (when gnus-keep-backlog
3061 (gnus-backlog-remove-article
3062 (car gnus-article-current) (cdr gnus-article-current)))
3063 ;; Flush original article as well.
3065 (when (get-buffer gnus-original-article-buffer)
3066 (set-buffer gnus-original-article-buffer)
3067 (setq gnus-original-article nil)))
3068 (when gnus-use-cache
3069 (gnus-cache-update-article
3070 (car gnus-article-current) (cdr gnus-article-current))))
3072 (set-window-start (get-buffer-window buf) start)
3073 (set-window-point (get-buffer-window buf) (point))))
3075 (defun gnus-article-edit-exit ()
3076 "Exit the article editing without updating."
3078 ;; We remove all text props from the article buffer.
3079 (let ((buf (format "%s" (buffer-string)))
3080 (curbuf (current-buffer))
3082 (window-start (window-start)))
3085 (let ((winconf gnus-prev-winconf))
3087 (set-window-configuration winconf)
3088 ;; Tippy-toe some to make sure that point remains where it was.
3089 (save-current-buffer
3091 (set-window-start (get-buffer-window (current-buffer)) window-start)
3094 (defun gnus-article-edit-full-stops ()
3095 "Interactively repair spacing at end of sentences."
3098 (goto-char (point-min))
3099 (search-forward-regexp "^$" nil t)
3100 (let ((case-fold-search nil))
3101 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3104 ;;; Article highlights
3107 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3109 ;;; Internal Variables:
3111 (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\\)"
3112 "Regular expression that matches URLs."
3113 :group 'gnus-article-buttons
3116 (defcustom gnus-button-alist
3117 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^)!;:,>\n\t ]*\\)>"
3118 0 t gnus-button-message-id 2)
3119 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3120 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3122 gnus-button-fetch-group 4)
3123 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3124 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3125 t gnus-button-message-id 3)
3126 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3127 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3128 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3129 ;; This is how URLs _should_ be embedded in text...
3130 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3132 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3133 "*Alist of regexps matching buttons in article bodies.
3135 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3136 REGEXP: is the string matching text around the button,
3137 BUTTON: is the number of the regexp grouping actually matching the button,
3138 FORM: is a lisp expression which must eval to true for the button to
3140 CALLBACK: is the function to call when the user push this button, and each
3141 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3143 CALLBACK can also be a variable, in that case the value of that
3144 variable it the real callback function."
3145 :group 'gnus-article-buttons
3146 :type '(repeat (list regexp
3147 (integer :tag "Button")
3149 (function :tag "Callback")
3152 (integer :tag "Regexp group")))))
3154 (defcustom gnus-header-button-alist
3155 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3156 0 t gnus-button-message-id 0)
3157 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3158 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3159 0 t gnus-button-mailto 0)
3160 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3161 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3162 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3163 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3164 gnus-button-message-id 3))
3165 "*Alist of headers and regexps to match buttons in article heads.
3167 This alist is very similar to `gnus-button-alist', except that each
3168 alist has an additional HEADER element first in each entry:
3170 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3172 HEADER is a regexp to match a header. For a fuller explanation, see
3173 `gnus-button-alist'."
3174 :group 'gnus-article-buttons
3175 :group 'gnus-article-headers
3176 :type '(repeat (list (regexp :tag "Header")
3178 (integer :tag "Button")
3180 (function :tag "Callback")
3183 (integer :tag "Regexp group")))))
3185 (defvar gnus-button-regexp nil)
3186 (defvar gnus-button-marker-list nil)
3187 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3189 (defvar gnus-button-last nil)
3190 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3194 (defun gnus-article-push-button (event)
3195 "Check text under the mouse pointer for a callback function.
3196 If the text under the mouse pointer has a `gnus-callback' property,
3197 call it with the value of the `gnus-data' text property."
3199 (set-buffer (window-buffer (posn-window (event-start event))))
3200 (let* ((pos (posn-point (event-start event)))
3201 (data (get-text-property pos 'gnus-data))
3202 (fun (get-text-property pos 'gnus-callback)))
3205 (funcall fun data))))
3207 (defun gnus-article-press-button ()
3208 "Check text at point for a callback function.
3209 If the text at point has a `gnus-callback' property,
3210 call it with the value of the `gnus-data' text property."
3212 (let* ((data (get-text-property (point) 'gnus-data))
3213 (fun (get-text-property (point) 'gnus-callback)))
3215 (funcall fun data))))
3217 (defun gnus-article-highlight (&optional force)
3218 "Highlight current article.
3219 This function calls `gnus-article-highlight-headers',
3220 `gnus-article-highlight-citation',
3221 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3222 do the highlighting. See the documentation for those functions."
3223 (interactive (list 'force))
3224 (gnus-article-highlight-headers)
3225 (gnus-article-highlight-citation force)
3226 (gnus-article-highlight-signature)
3227 (gnus-article-add-buttons force)
3228 (gnus-article-add-buttons-to-head))
3230 (defun gnus-article-highlight-some (&optional force)
3231 "Highlight current article.
3232 This function calls `gnus-article-highlight-headers',
3233 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3234 do the highlighting. See the documentation for those functions."
3235 (interactive (list 'force))
3236 (gnus-article-highlight-headers)
3237 (gnus-article-highlight-signature)
3238 (gnus-article-add-buttons))
3240 (defun gnus-article-highlight-headers ()
3241 "Highlight article headers as specified by `gnus-header-face-alist'."
3244 (set-buffer gnus-article-buffer)
3246 (let ((alist gnus-header-face-alist)
3247 (buffer-read-only nil)
3248 (case-fold-search t)
3249 (inhibit-point-motion-hooks t)
3250 entry regexp header-face field-face from hpoints fpoints)
3251 (message-narrow-to-head)
3252 (while (setq entry (pop alist))
3253 (goto-char (point-min))
3254 (setq regexp (concat "^\\("
3255 (if (string-equal "" (nth 0 entry))
3259 header-face (nth 1 entry)
3260 field-face (nth 2 entry))
3261 (while (and (re-search-forward regexp nil t)
3265 (unless (search-forward ":" nil t)
3267 (when (and header-face
3268 (not (memq (point) hpoints)))
3269 (push (point) hpoints)
3270 (gnus-put-text-property from (point) 'face header-face))
3271 (when (and field-face
3272 (not (memq (setq from (point)) fpoints)))
3274 (if (re-search-forward "^[^ \t]" nil t)
3276 (goto-char (point-max)))
3277 (gnus-put-text-property from (point) 'face field-face))))))))
3279 (defun gnus-article-highlight-signature ()
3280 "Highlight the signature in an article.
3281 It does this by highlighting everything after
3282 `gnus-signature-separator' using `gnus-signature-face'."
3285 (set-buffer gnus-article-buffer)
3286 (let ((buffer-read-only nil)
3287 (inhibit-point-motion-hooks t))
3289 (when (and gnus-signature-face
3290 (gnus-article-narrow-to-signature))
3291 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3292 'face gnus-signature-face)
3294 (gnus-article-search-signature)
3295 (let ((start (match-beginning 0))
3296 (end (set-marker (make-marker) (1+ (match-end 0)))))
3297 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3300 (defun gnus-button-in-region-p (b e prop)
3301 "Say whether PROP exists in the region."
3302 (text-property-not-all b e prop nil))
3304 (defun gnus-article-add-buttons (&optional force)
3305 "Find external references in the article and make buttons of them.
3306 \"External references\" are things like Message-IDs and URLs, as
3307 specified by `gnus-button-alist'."
3308 (interactive (list 'force))
3310 (set-buffer gnus-article-buffer)
3311 (let ((buffer-read-only nil)
3312 (inhibit-point-motion-hooks t)
3313 (case-fold-search t)
3314 (alist gnus-button-alist)
3316 ;; Remove all old markers.
3318 (while (setq marker (pop gnus-button-marker-list))
3320 (when (setq entry (gnus-button-entry))
3321 (put-text-property (match-beginning (nth 1 entry))
3322 (match-end (nth 1 entry))
3323 'gnus-callback nil))
3324 (set-marker marker nil)))
3325 ;; We skip the headers.
3326 (goto-char (point-min))
3327 (unless (search-forward "\n\n" nil t)
3328 (goto-char (point-max)))
3330 (while (setq entry (pop alist))
3331 (setq regexp (car entry))
3333 (while (re-search-forward regexp nil t)
3334 (let* ((start (and entry (match-beginning (nth 1 entry))))
3335 (end (and entry (match-end (nth 1 entry))))
3336 (from (match-beginning 0)))
3337 (when (and (or (eq t (nth 2 entry))
3338 (eval (nth 2 entry)))
3339 (not (gnus-button-in-region-p
3340 start end 'gnus-callback)))
3341 ;; That optional form returned non-nil, so we add the
3343 (gnus-article-add-button
3344 start end 'gnus-button-push
3345 (car (push (set-marker (make-marker) from)
3346 gnus-button-marker-list))))))))))
3348 ;; Add buttons to the head of an article.
3349 (defun gnus-article-add-buttons-to-head ()
3350 "Add buttons to the head of the article."
3353 (set-buffer gnus-article-buffer)
3354 (let ((buffer-read-only nil)
3355 (inhibit-point-motion-hooks t)
3356 (case-fold-search t)
3357 (alist gnus-header-button-alist)
3359 (nnheader-narrow-to-headers)
3361 ;; Each alist entry.
3362 (setq entry (car alist)
3364 (goto-char (point-min))
3365 (while (re-search-forward (car entry) nil t)
3366 ;; Each header matching the entry.
3367 (setq beg (match-beginning 0))
3368 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3369 (match-beginning 0))
3372 (while (re-search-forward (nth 1 entry) end t)
3373 ;; Each match within a header.
3374 (let* ((entry (cdr entry))
3375 (start (match-beginning (nth 1 entry)))
3376 (end (match-end (nth 1 entry)))
3377 (form (nth 2 entry)))
3378 (goto-char (match-end 0))
3380 (gnus-article-add-button
3381 start end (nth 3 entry)
3382 (buffer-substring (match-beginning (nth 4 entry))
3383 (match-end (nth 4 entry)))))))
3387 ;;; External functions:
3389 (defun gnus-article-add-button (from to fun &optional data)
3390 "Create a button between FROM and TO with callback FUN and data DATA."
3391 (when gnus-article-button-face
3392 (gnus-overlay-put (gnus-make-overlay from to)
3393 'face gnus-article-button-face))
3394 (gnus-add-text-properties
3396 (nconc (and gnus-article-mouse-face
3397 (list gnus-mouse-face-prop gnus-article-mouse-face))
3398 (list 'gnus-callback fun)
3399 (and data (list 'gnus-data data))))
3400 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3401 :button-keymap gnus-widget-button-keymap))
3403 ;;; Internal functions:
3405 (defun gnus-article-set-globals ()
3407 (set-buffer gnus-summary-buffer)
3408 (gnus-set-global-variables)))
3410 (defun gnus-signature-toggle (end)
3412 (set-buffer gnus-article-buffer)
3413 (let ((buffer-read-only nil)
3414 (inhibit-point-motion-hooks t))
3415 (if (get-text-property end 'invisible)
3416 (gnus-article-unhide-text end (point-max))
3417 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3419 (defun gnus-button-entry ()
3420 ;; Return the first entry in `gnus-button-alist' matching this place.
3421 (let ((alist gnus-button-alist)
3424 (setq entry (pop alist))
3425 (if (looking-at (car entry))
3430 (defun gnus-button-push (marker)
3431 ;; Push button starting at MARKER.
3434 (let* ((entry (gnus-button-entry))
3435 (inhibit-point-motion-hooks t)
3437 (args (mapcar (lambda (group)
3438 (let ((string (match-string group)))
3439 (gnus-set-text-properties
3440 0 (length string) nil string)
3447 (fboundp (symbol-value fun)))
3448 (apply (symbol-value fun) args))
3450 (gnus-message 1 "You must define `%S' to use this button"
3451 (cons fun args)))))))
3453 (defun gnus-button-message-id (message-id)
3456 (set-buffer gnus-summary-buffer)
3457 (gnus-summary-refer-article message-id)))
3459 (defun gnus-button-fetch-group (address)
3460 "Fetch GROUP specified by ADDRESS."
3461 (if (not (string-match "[:/]" address))
3462 ;; This is just a simple group url.
3463 (gnus-group-read-ephemeral-group address gnus-select-method)
3464 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3466 (error "Can't parse %s" address)
3467 (gnus-group-read-ephemeral-group
3468 (match-string 4 address)
3469 `(nntp ,(match-string 1 address)
3470 (nntp-address ,(match-string 1 address))
3471 (nntp-port-number ,(if (match-end 3)
3472 (match-string 3 address)
3475 (defun gnus-url-parse-query-string (query &optional downcase)
3476 (let (retval pairs cur key val)
3477 (setq pairs (split-string query "&"))
3479 (setq cur (car pairs)
3481 (if (not (string-match "=" cur))
3483 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3484 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3486 (setq key (downcase key)))
3487 (setq cur (assoc key retval))
3489 (setcdr cur (cons val (cdr cur)))
3490 (setq retval (cons (list key val) retval)))))
3493 (defun gnus-url-unhex (x)
3500 (defun gnus-url-unhex-string (str &optional allow-newlines)
3501 "Remove %XXX embedded spaces, etc in a url.
3502 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3503 decoding of carriage returns and line feeds in the string, which is normally
3504 forbidden in URL encoding."
3505 (setq str (or str ""))
3507 (case-fold-search t))
3508 (while (string-match "%[0-9a-f][0-9a-f]" str)
3509 (let* ((start (match-beginning 0))
3510 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3512 (gnus-url-unhex (elt str (+ start 2))))))
3514 tmp (substring str 0 start)
3517 (char-to-string code))
3518 ((or (= code ?\n) (= code ?\r))
3520 (t (char-to-string code))))
3521 str (substring str (match-end 0)))))
3522 (setq tmp (concat tmp str))
3525 (defun gnus-url-mailto (url)
3526 ;; Send mail to someone
3527 (when (string-match "mailto:/*\\(.*\\)" url)
3528 (setq url (substring url (match-beginning 1) nil)))
3529 (let (to args subject func)
3530 (if (string-match (regexp-quote "?") url)
3531 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3532 args (gnus-url-parse-query-string
3533 (substring url (match-end 0) nil) t))
3534 (setq to (gnus-url-unhex-string url)))
3535 (setq args (cons (list "to" to) args)
3536 subject (cdr-safe (assoc "subject" args)))
3539 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3542 (message-position-on-field (caar args)))
3543 (insert (mapconcat 'identity (cdar args) ", "))
3544 (setq args (cdr args)))
3547 (message-goto-subject))))
3549 (defun gnus-button-mailto (address)
3551 (set-buffer (gnus-copy-article-buffer))
3552 (message-reply address))
3554 (defun gnus-button-reply (address)
3555 ;; Reply to ADDRESS.
3556 (message-reply address))
3558 (defun gnus-button-url (address)
3560 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3561 (if (listp browse-url-browser-function)
3562 (browse-url address)
3563 (funcall browse-url-browser-function address)))
3565 (defun gnus-button-embedded-url (address)
3567 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3568 (if (listp browse-url-browser-function)
3569 (browse-url (gnus-strip-whitespace address))
3570 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3572 ;;; Next/prev buttons in the article buffer.
3574 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3575 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3577 (defvar gnus-prev-page-map nil)
3578 (unless gnus-prev-page-map
3579 (setq gnus-prev-page-map (make-sparse-keymap))
3580 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3581 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3583 (defun gnus-insert-prev-page-button ()
3584 (let ((buffer-read-only nil))
3586 gnus-prev-page-line-format nil
3587 `(gnus-prev t local-map ,gnus-prev-page-map
3588 gnus-callback gnus-article-button-prev-page
3589 article-type annotation))))
3591 (defvar gnus-next-page-map nil)
3592 (unless gnus-next-page-map
3593 (setq gnus-next-page-map (make-keymap))
3594 (suppress-keymap gnus-prev-page-map)
3595 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3596 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3598 (defun gnus-button-next-page ()
3599 "Go to the next page."
3601 (let ((win (selected-window)))
3602 (select-window (get-buffer-window gnus-article-buffer t))
3603 (gnus-article-next-page)
3604 (select-window win)))
3606 (defun gnus-button-prev-page ()
3607 "Go to the prev page."
3609 (let ((win (selected-window)))
3610 (select-window (get-buffer-window gnus-article-buffer t))
3611 (gnus-article-prev-page)
3612 (select-window win)))
3614 (defun gnus-insert-next-page-button ()
3615 (let ((buffer-read-only nil))
3616 (gnus-eval-format gnus-next-page-line-format nil
3618 t local-map ,gnus-next-page-map
3619 gnus-callback gnus-article-button-next-page
3620 article-type annotation))))
3622 (defun gnus-article-button-next-page (arg)
3623 "Go to the next page."
3625 (let ((win (selected-window)))
3626 (select-window (get-buffer-window gnus-article-buffer t))
3627 (gnus-article-next-page)
3628 (select-window win)))
3630 (defun gnus-article-button-prev-page (arg)
3631 "Go to the prev page."
3633 (let ((win (selected-window)))
3634 (select-window (get-buffer-window gnus-article-buffer t))
3635 (gnus-article-prev-page)
3636 (select-window win)))
3638 (defvar gnus-decode-header-methods
3639 '(mail-decode-encoded-word-region)
3640 "List of methods used to decode headers
3642 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
3643 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
3644 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
3645 whose names match REGEXP.
3648 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
3649 mail-decode-encoded-word-region
3650 (\"chinese\" . rfc1843-decode-region))
3653 (defvar gnus-decode-header-methods-cache nil)
3655 (defun gnus-multi-decode-header (start end)
3656 "Apply the functions from `gnus-encoded-word-methods' that match."
3657 (unless (and gnus-decode-header-methods-cache
3658 (eq gnus-newsgroup-name
3659 (car gnus-decode-header-methods-cache)))
3660 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
3663 (nconc gnus-decode-header-methods-cache (list x))
3664 (if (and gnus-newsgroup-name
3665 (string-match (car x) gnus-newsgroup-name))
3666 (nconc gnus-decode-header-methods-cache
3668 gnus-decode-header-methods))
3669 (let ((xlist gnus-decode-header-methods-cache))
3672 (narrow-to-region start end)
3674 (funcall (pop xlist) (point-min) (point-max))))))
3680 (run-hooks 'gnus-art-load-hook)
3682 ;;; gnus-art.el ends here