1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
43 ;; Avoid byte-compile warnings.
44 (defvar gnus-article-decoded-p)
45 (defvar gnus-article-mime-handles)
54 (defgroup gnus-article nil
56 :link '(custom-manual "(gnus)The Article Buffer")
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
75 (defgroup gnus-article-signature nil
77 :link '(custom-manual "(gnus)Article Signature")
80 (defgroup gnus-article-headers nil
82 :link '(custom-manual "(gnus)Hiding Headers")
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
95 (defgroup gnus-article-saving nil
97 :link '(custom-manual "(gnus)Saving Articles")
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
115 (defcustom gnus-ignored-headers
116 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
117 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
118 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
119 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
120 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
121 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
122 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
123 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
124 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
125 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
126 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
127 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
128 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
129 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
130 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
131 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
132 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
133 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
134 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
135 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
136 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
137 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
138 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
139 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
140 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
141 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:")
142 "*All headers that start with this regexp will be hidden.
143 This variable can also be a list of regexps of headers to be ignored.
144 If `gnus-visible-headers' is non-nil, this variable will be ignored."
145 :type '(choice :custom-show nil
148 :group 'gnus-article-hiding)
150 (defcustom gnus-visible-headers
151 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
152 "*All headers that do not match this regexp will be hidden.
153 This variable can also be a list of regexp of headers to remain visible.
154 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
155 :type '(repeat :value-to-internal (lambda (widget value)
156 (custom-split-regexp-maybe value))
157 :match (lambda (widget value)
159 (widget-editable-list-match widget value)))
161 :group 'gnus-article-hiding)
163 (defcustom gnus-sorted-header-list
164 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
165 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
166 "*This variable is a list of regular expressions.
167 If it is non-nil, headers that match the regular expressions will
168 be placed first in the article buffer in the sequence specified by
170 :type '(repeat regexp)
171 :group 'gnus-article-hiding)
173 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
174 "Headers that are only to be displayed if they have interesting data.
175 Possible values in this list are `empty', `newsgroups', `followup-to',
176 `reply-to', `date', `long-to', and `many-to'."
177 :type '(set (const :tag "Headers with no content." empty)
178 (const :tag "Newsgroups with only one group." newsgroups)
179 (const :tag "Followup-to identical to newsgroups." followup-to)
180 (const :tag "Reply-to identical to from." reply-to)
181 (const :tag "Date less than four days old." date)
182 (const :tag "Very long To header." long-to)
183 (const :tag "Multiple To headers." many-to))
184 :group 'gnus-article-hiding)
186 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
187 "Regexp matching signature separator.
188 This can also be a list of regexps. In that case, it will be checked
189 from head to tail looking for a separator. Searches will be done from
190 the end of the buffer."
191 :type '(repeat string)
192 :group 'gnus-article-signature)
194 (defcustom gnus-signature-limit nil
195 "Provide a limit to what is considered a signature.
196 If it is a number, no signature may not be longer (in characters) than
197 that number. If it is a floating point number, no signature may be
198 longer (in lines) than that number. If it is a function, the function
199 will be called without any parameters, and if it returns nil, there is
200 no signature in the buffer. If it is a string, it will be used as a
201 regexp. If it matches, the text in question is not a signature."
202 :type '(choice (integer :value 200)
204 (function :value fun)
205 (regexp :value ".*"))
206 :group 'gnus-article-signature)
208 (defcustom gnus-hidden-properties '(invisible t intangible t)
209 "Property list to use for hiding text."
211 :group 'gnus-article-hiding)
213 (defcustom gnus-article-x-face-command
214 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
215 "*String or function to be executed to display an X-Face header.
216 If it is a string, the command will be executed in a sub-shell
217 asynchronously. The compressed face will be piped to this command."
218 :type 'string ;Leave function case to Lisp.
219 :group 'gnus-article-washing)
221 (defcustom gnus-article-x-face-too-ugly nil
222 "Regexp matching posters whose face shouldn't be shown automatically."
223 :type '(choice regexp (const nil))
224 :group 'gnus-article-washing)
226 (defcustom gnus-emphasis-alist
228 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
230 '(("_" "_" underline)
233 ("_/" "/_" underline-italic)
234 ("_\\*" "\\*_" underline-bold)
235 ("\\*/" "/\\*" bold-italic)
236 ("_\\*/" "/\\*_" underline-bold-italic))))
237 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
238 2 3 gnus-emphasis-underline)
242 (format format (car spec) (cadr spec))
243 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
245 "*Alist that says how to fontify certain phrases.
246 Each item looks like this:
248 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
250 The first element is a regular expression to be matched. The second
251 is a number that says what regular expression grouping used to find
252 the entire emphasized word. The third is a number that says what
253 regexp grouping should be displayed and highlighted. The fourth
254 is the face used for highlighting."
255 :type '(repeat (list :value ("" 0 0 default)
257 (integer :tag "Match group")
258 (integer :tag "Emphasize group")
260 :group 'gnus-article-emphasis)
262 (defface gnus-emphasis-bold '((t (:bold t)))
263 "Face used for displaying strong emphasized text (*word*)."
264 :group 'gnus-article-emphasis)
266 (defface gnus-emphasis-italic '((t (:italic t)))
267 "Face used for displaying italic emphasized text (/word/)."
268 :group 'gnus-article-emphasis)
270 (defface gnus-emphasis-underline '((t (:underline t)))
271 "Face used for displaying underlined emphasized text (_word_)."
272 :group 'gnus-article-emphasis)
274 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
275 "Face used for displaying underlined bold emphasized text (_*word*_)."
276 :group 'gnus-article-emphasis)
278 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
279 "Face used for displaying underlined italic emphasized text (_*word*_)."
280 :group 'gnus-article-emphasis)
282 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
283 "Face used for displaying bold italic emphasized text (/*word*/)."
284 :group 'gnus-article-emphasis)
286 (defface gnus-emphasis-underline-bold-italic
287 '((t (:bold t :italic t :underline t)))
288 "Face used for displaying underlined bold italic emphasized text.
289 Esample: (_/*word*/_)."
290 :group 'gnus-article-emphasis)
292 (defface gnus-emphasis-highlight-words
293 '((t (:background "black" :foreground "yellow")))
294 "Face used for displaying highlighted words."
295 :group 'gnus-article-emphasis)
297 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
298 "Format for display of Date headers in article bodies.
299 See `format-time-string' for the possible values.
301 The variable can also be function, which should return a complete Date
302 header. The function is called with one argument, the time, which can
303 be fed to `format-time-string'."
304 :type '(choice string symbol)
305 :link '(custom-manual "(gnus)Article Date")
306 :group 'gnus-article-washing)
309 (autoload 'mail-extract-address-components "mail-extr"))
311 (defcustom gnus-save-all-headers t
312 "*If non-nil, don't remove any headers before saving."
313 :group 'gnus-article-saving
316 (defcustom gnus-prompt-before-saving 'always
317 "*This variable says how much prompting is to be done when saving articles.
318 If it is nil, no prompting will be done, and the articles will be
319 saved to the default files. If this variable is `always', each and
320 every article that is saved will be preceded by a prompt, even when
321 saving large batches of articles. If this variable is neither nil not
322 `always', there the user will be prompted once for a file name for
323 each invocation of the saving commands."
324 :group 'gnus-article-saving
325 :type '(choice (item always)
326 (item :tag "never" nil)
327 (sexp :tag "once" :format "%t\n" :value t)))
329 (defcustom gnus-saved-headers gnus-visible-headers
330 "Headers to keep if `gnus-save-all-headers' is nil.
331 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
332 If that variable is nil, however, all headers that match this regexp
333 will be kept while the rest will be deleted before saving."
334 :group 'gnus-article-saving
337 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
338 "A function to save articles in your favourite format.
339 The function must be interactively callable (in other words, it must
340 be an Emacs command).
342 Gnus provides the following functions:
344 * gnus-summary-save-in-rmail (Rmail format)
345 * gnus-summary-save-in-mail (Unix mail format)
346 * gnus-summary-save-in-folder (MH folder)
347 * gnus-summary-save-in-file (article format)
348 * gnus-summary-save-in-vm (use VM's folder format)
349 * gnus-summary-write-to-file (article format -- overwrite)."
350 :group 'gnus-article-saving
351 :type '(radio (function-item gnus-summary-save-in-rmail)
352 (function-item gnus-summary-save-in-mail)
353 (function-item gnus-summary-save-in-folder)
354 (function-item gnus-summary-save-in-file)
355 (function-item gnus-summary-save-in-vm)
356 (function-item gnus-summary-write-to-file)))
358 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
359 "A function generating a file name to save articles in Rmail format.
360 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
361 :group 'gnus-article-saving
364 (defcustom gnus-mail-save-name 'gnus-plain-save-name
365 "A function generating a file name to save articles in Unix mail format.
366 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
367 :group 'gnus-article-saving
370 (defcustom gnus-folder-save-name 'gnus-folder-save-name
371 "A function generating a file name to save articles in MH folder.
372 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
373 :group 'gnus-article-saving
376 (defcustom gnus-file-save-name 'gnus-numeric-save-name
377 "A function generating a file name to save articles in article format.
378 The function is called with NEWSGROUP, HEADERS, and optional
380 :group 'gnus-article-saving
383 (defcustom gnus-split-methods
384 '((gnus-article-archive-name)
385 (gnus-article-nndoc-name))
386 "*Variable used to suggest where articles are to be saved.
387 For instance, if you would like to save articles related to Gnus in
388 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
389 you could set this variable to something like:
391 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
392 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
394 This variable is an alist where the where the key is the match and the
395 value is a list of possible files to save in if the match is non-nil.
397 If the match is a string, it is used as a regexp match on the
398 article. If the match is a symbol, that symbol will be funcalled
399 from the buffer of the article to be saved with the newsgroup as the
400 parameter. If it is a list, it will be evaled in the same buffer.
402 If this form or function returns a string, this string will be used as
403 a possible file name; and if it returns a non-nil list, that list will
404 be used as possible file names."
405 :group 'gnus-article-saving
406 :type '(repeat (choice (list :value (fun) function)
407 (cons :value ("" "") regexp (repeat string))
410 (defcustom gnus-article-display-method-for-mime
411 'gnus-article-display-mime-message
412 "Function to display a MIME message.
413 The function is called from the article buffer."
414 :group 'gnus-article-mime
417 (defcustom gnus-article-display-method-for-traditional
418 'gnus-article-display-traditional-message
419 "*Function to display a traditional message.
420 The function is called from the article buffer."
421 :group 'gnus-article-mime
424 (defcustom gnus-page-delimiter "^\^L"
425 "*Regexp describing what to use as article page delimiters.
426 The default value is \"^\^L\", which is a form linefeed at the
427 beginning of a line."
429 :group 'gnus-article-various)
431 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
432 "*The format specification for the article mode line.
433 See `gnus-summary-mode-line-format' for a closer description.
435 The following additional specs are available:
437 %w The article washing status.
438 %m The number of MIME parts in the article."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-mode-hook nil
443 "*A hook for Gnus article mode."
445 :group 'gnus-article-various)
447 (defcustom gnus-article-menu-hook nil
448 "*Hook run after the creation of the article mode menu."
450 :group 'gnus-article-various)
452 (defcustom gnus-article-prepare-hook nil
453 "*A hook called after an article has been prepared in the article buffer."
455 :group 'gnus-article-various)
457 (defcustom gnus-article-hide-pgp-hook nil
458 "*A hook called after successfully hiding a PGP signature."
460 :group 'gnus-article-various)
462 (defcustom gnus-article-button-face 'bold
463 "Face used for highlighting buttons in the article buffer.
465 An article button is a piece of text that you can activate by pressing
466 `RET' or `mouse-2' above it."
468 :group 'gnus-article-buttons)
470 (defcustom gnus-article-mouse-face 'highlight
471 "Face used for mouse highlighting in the article buffer.
473 Article buttons will be displayed in this face when the cursor is
476 :group 'gnus-article-buttons)
478 (defcustom gnus-signature-face 'gnus-signature-face
479 "Face used for highlighting a signature in the article buffer.
480 Obsolete; use the face `gnus-signature-face' for customizations instead."
482 :group 'gnus-article-highlight
483 :group 'gnus-article-signature)
485 (defface gnus-signature-face
488 "Face used for highlighting a signature in the article buffer."
489 :group 'gnus-article-highlight
490 :group 'gnus-article-signature)
492 (defface gnus-header-from-face
495 (:foreground "spring green"))
498 (:foreground "red3"))
501 "Face used for displaying from headers."
502 :group 'gnus-article-headers
503 :group 'gnus-article-highlight)
505 (defface gnus-header-subject-face
508 (:foreground "SeaGreen3"))
511 (:foreground "red4"))
513 (:bold t :italic t)))
514 "Face used for displaying subject headers."
515 :group 'gnus-article-headers
516 :group 'gnus-article-highlight)
518 (defface gnus-header-newsgroups-face
521 (:foreground "yellow" :italic t))
524 (:foreground "MidnightBlue" :italic t))
527 "Face used for displaying newsgroups headers."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defface gnus-header-name-face
534 (:foreground "SeaGreen"))
537 (:foreground "maroon"))
540 "Face used for displaying header names."
541 :group 'gnus-article-headers
542 :group 'gnus-article-highlight)
544 (defface gnus-header-content-face
547 (:foreground "forest green" :italic t))
550 (:foreground "indianred4" :italic t))
552 (:italic t))) "Face used for displaying header content."
553 :group 'gnus-article-headers
554 :group 'gnus-article-highlight)
556 (defcustom gnus-header-face-alist
557 '(("From" nil gnus-header-from-face)
558 ("Subject" nil gnus-header-subject-face)
559 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
560 ("" gnus-header-name-face gnus-header-content-face))
561 "*Controls highlighting of article header.
563 An alist of the form (HEADER NAME CONTENT).
565 HEADER is a regular expression which should match the name of an
566 header header and NAME and CONTENT are either face names or nil.
568 The name of each header field will be displayed using the face
569 specified by the first element in the list where HEADER match the
570 header name and NAME is non-nil. Similarly, the content will be
571 displayed by the first non-nil matching CONTENT face."
572 :group 'gnus-article-headers
573 :group 'gnus-article-highlight
574 :type '(repeat (list (regexp :tag "Header")
576 (item :tag "skip" nil)
577 (face :value default))
578 (choice :tag "Content"
579 (item :tag "skip" nil)
580 (face :value default)))))
582 (defcustom gnus-article-decode-hook nil
583 "*Hook run to decode charsets in articles."
584 :group 'gnus-article-headers
587 (defcustom gnus-display-mime-function 'gnus-display-mime
588 "Function to display MIME articles."
589 :group 'gnus-article-mime
592 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
593 "Function used to decode headers.")
595 (defvar gnus-article-dumbquotes-map
613 "Table for MS-to-Latin1 translation.")
615 (defcustom gnus-ignored-mime-types nil
616 "List of MIME types that should be ignored by Gnus."
617 :group 'gnus-article-mime
618 :type '(repeat regexp))
620 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
621 "List of MIME types that should not be given buttons when rendered inline."
622 :group 'gnus-article-mime
623 :type '(repeat regexp))
625 (defcustom gnus-article-mime-part-function nil
626 "Function called with a MIME handle as the argument.
627 This is meant for people who want to do something automatic based
628 on parts -- for instance, adding Vcard info to a database."
629 :group 'gnus-article-mime
632 (defcustom gnus-mime-multipart-functions nil
633 "An alist of MIME types to functions to display them.")
635 (defcustom gnus-article-date-lapsed-new-header nil
636 "Whether the X-Sent and Date headers can coexist.
637 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
638 either replace the old \"Date:\" header (if this variable is nil), or
639 be added below it (otherwise)."
640 :group 'gnus-article-headers
644 ;;; The treatment variables
647 (defvar gnus-part-display-hook nil
648 "Hook called on parts that are to receive treatment.")
650 (defvar gnus-article-treat-custom
651 '(choice (const :tag "Off" nil)
653 (const :tag "Header" head)
654 (const :tag "Last" last)
655 (const :tag "Mime" mime)
656 (integer :tag "Less")
657 (repeat :tag "Groups" regexp)
658 (sexp :tag "Predicate")))
660 (defvar gnus-article-treat-head-custom
661 '(choice (const :tag "Off" nil)
662 (const :tag "Header" head)))
664 (defvar gnus-article-treat-types '("text/plain")
667 (defvar gnus-inhibit-treatment nil
668 "Whether to inhibit treatment.")
670 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
671 "Highlight the signature.
672 Valid values are nil, t, `head', `last', an integer or a predicate.
673 See the manual for details."
674 :group 'gnus-article-treat
675 :type gnus-article-treat-custom)
676 (put 'gnus-treat-highlight-signature 'highlight t)
678 (defcustom gnus-treat-buttonize t
680 Valid values are nil, t, `head', `last', an integer or a predicate.
681 See the manual for details."
682 :group 'gnus-article-treat
683 :type gnus-article-treat-custom)
684 (put 'gnus-treat-buttonize 'highlight t)
686 (defcustom gnus-treat-buttonize-head 'head
687 "Add buttons to the head.
688 Valid values are nil, t, `head', `last', an integer or a predicate.
689 See the manual for details."
690 :group 'gnus-article-treat
691 :type gnus-article-treat-head-custom)
692 (put 'gnus-treat-buttonize-head 'highlight t)
694 (defcustom gnus-treat-emphasize t
696 Valid values are nil, t, `head', `last', an integer or a predicate.
697 See the manual for details."
698 :group 'gnus-article-treat
699 :type gnus-article-treat-custom)
700 (put 'gnus-treat-emphasize 'highlight t)
702 (defcustom gnus-treat-strip-cr nil
703 "Remove carriage returns.
704 Valid values are nil, t, `head', `last', an integer or a predicate.
705 See the manual for details."
706 :group 'gnus-article-treat
707 :type gnus-article-treat-custom)
709 (defcustom gnus-treat-hide-headers 'head
711 Valid values are nil, t, `head', `last', an integer or a predicate.
712 See the manual for details."
713 :group 'gnus-article-treat
714 :type gnus-article-treat-head-custom)
716 (defcustom gnus-treat-hide-boring-headers nil
717 "Hide boring headers.
718 Valid values are nil, t, `head', `last', an integer or a predicate.
719 See the manual for details."
720 :group 'gnus-article-treat
721 :type gnus-article-treat-head-custom)
723 (defcustom gnus-treat-hide-signature nil
725 Valid values are nil, t, `head', `last', an integer or a predicate.
726 See the manual for details."
727 :group 'gnus-article-treat
728 :type gnus-article-treat-custom)
730 (defcustom gnus-treat-fill-article nil
732 Valid values are nil, t, `head', `last', an integer or a predicate.
733 See the manual for details."
734 :group 'gnus-article-treat
735 :type gnus-article-treat-custom)
737 (defcustom gnus-treat-hide-citation nil
739 Valid values are nil, t, `head', `last', an integer or a predicate.
740 See the manual for details."
741 :group 'gnus-article-treat
742 :type gnus-article-treat-custom)
744 (defcustom gnus-treat-strip-list-identifiers 'head
745 "Strip list identifiers from `gnus-list-identifiers`.
746 Valid values are nil, t, `head', `last', an integer or a predicate.
747 See the manual for details."
748 :group 'gnus-article-treat
749 :type gnus-article-treat-custom)
751 (defcustom gnus-treat-strip-pgp t
752 "Strip PGP signatures.
753 Valid values are nil, t, `head', `last', an integer or a predicate.
754 See the manual for details."
755 :group 'gnus-article-treat
756 :type gnus-article-treat-custom)
758 (defcustom gnus-treat-strip-pem nil
759 "Strip PEM signatures.
760 Valid values are nil, t, `head', `last', an integer or a predicate.
761 See the manual for details."
762 :group 'gnus-article-treat
763 :type gnus-article-treat-custom)
765 (defcustom gnus-treat-strip-banner t
766 "Strip banners from articles.
767 The banner to be stripped is specified in the `banner' group parameter.
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-custom)
773 (defcustom gnus-treat-highlight-headers 'head
774 "Highlight the headers.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-head-custom)
779 (put 'gnus-treat-highlight-headers 'highlight t)
781 (defcustom gnus-treat-highlight-citation t
782 "Highlight cited text.
783 Valid values are nil, t, `head', `last', an integer or a predicate.
784 See the manual for details."
785 :group 'gnus-article-treat
786 :type gnus-article-treat-custom)
787 (put 'gnus-treat-highlight-citation 'highlight t)
789 (defcustom gnus-treat-date-ut nil
790 "Display the Date in UT (GMT).
791 Valid values are nil, t, `head', `last', an integer or a predicate.
792 See the manual for details."
793 :group 'gnus-article-treat
794 :type gnus-article-treat-head-custom)
796 (defcustom gnus-treat-date-local nil
797 "Display the Date in the local timezone.
798 Valid values are nil, t, `head', `last', an integer or a predicate.
799 See the manual for details."
800 :group 'gnus-article-treat
801 :type gnus-article-treat-head-custom)
803 (defcustom gnus-treat-date-lapsed nil
804 "Display the Date header in a way that says how much time has elapsed.
805 Valid values are nil, t, `head', `last', an integer or a predicate.
806 See the manual for details."
807 :group 'gnus-article-treat
808 :type gnus-article-treat-head-custom)
810 (defcustom gnus-treat-date-original nil
811 "Display the date in the original timezone.
812 Valid values are nil, t, `head', `last', an integer or a predicate.
813 See the manual for details."
814 :group 'gnus-article-treat
815 :type gnus-article-treat-head-custom)
817 (defcustom gnus-treat-date-iso8601 nil
818 "Display the date in the ISO8601 format.
819 Valid values are nil, t, `head', `last', an integer or a predicate.
820 See the manual for details."
821 :group 'gnus-article-treat
822 :type gnus-article-treat-head-custom)
824 (defcustom gnus-treat-date-user-defined nil
825 "Display the date in a user-defined format.
826 The format is defined by the `gnus-article-time-format' variable.
827 Valid values are nil, t, `head', `last', an integer or a predicate.
828 See the manual for details."
829 :group 'gnus-article-treat
830 :type gnus-article-treat-head-custom)
832 (defcustom gnus-treat-strip-headers-in-body t
833 "Strip the X-No-Archive header line from the beginning of the body.
834 Valid values are nil, t, `head', `last', an integer or a predicate.
835 See the manual for details."
836 :group 'gnus-article-treat
837 :type gnus-article-treat-custom)
839 (defcustom gnus-treat-strip-trailing-blank-lines nil
840 "Strip trailing blank lines.
841 Valid values are nil, t, `head', `last', an integer or a predicate.
842 See the manual for details."
843 :group 'gnus-article-treat
844 :type gnus-article-treat-custom)
846 (defcustom gnus-treat-strip-leading-blank-lines nil
847 "Strip leading blank lines.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See the manual for details."
850 :group 'gnus-article-treat
851 :type gnus-article-treat-custom)
853 (defcustom gnus-treat-strip-multiple-blank-lines nil
854 "Strip multiple blank lines.
855 Valid values are nil, t, `head', `last', an integer or a predicate.
856 See the manual for details."
857 :group 'gnus-article-treat
858 :type gnus-article-treat-custom)
860 (defcustom gnus-treat-overstrike t
861 "Treat overstrike highlighting.
862 Valid values are nil, t, `head', `last', an integer or a predicate.
863 See the manual for details."
864 :group 'gnus-article-treat
865 :type gnus-article-treat-custom)
866 (put 'gnus-treat-overstrike 'highlight t)
868 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
870 "Display X-Face headers.
871 Valid values are nil, t, `head', `last', an integer or a predicate.
872 See the manual for details."
873 :group 'gnus-article-treat
874 :type gnus-article-treat-head-custom)
875 (put 'gnus-treat-display-xface 'highlight t)
877 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-custom)
885 (put 'gnus-treat-display-smileys 'highlight t)
887 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-head-custom)
893 (put 'gnus-treat-display-picons 'highlight t)
895 (defcustom gnus-treat-capitalize-sentences nil
896 "Capitalize sentence-starting words.
897 Valid values are nil, t, `head', `last', an integer or a predicate.
898 See the manual for details."
899 :group 'gnus-article-treat
900 :type gnus-article-treat-custom)
902 (defcustom gnus-treat-fill-long-lines nil
904 Valid values are nil, t, `head', `last', an integer or a predicate.
905 See the manual for details."
906 :group 'gnus-article-treat
907 :type gnus-article-treat-custom)
909 (defcustom gnus-treat-play-sounds nil
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See the manual for details."
913 :group 'gnus-article-treat
914 :type gnus-article-treat-custom)
916 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
917 "Decode an article as `default-mime-charset'. For instance, if you want to
918 attempt to decode an article even if the value of `gnus-show-mime' is nil,
919 you could set this variable to something like: nil for don't decode, t for
920 decode the body, '(or header t) for the whole article, etc."
921 :group 'gnus-article-treat
922 :type '(radio (const :tag "Off" nil)
923 (const :tag "Decode body" t)
924 (const :tag "Decode all" (or head t))))
926 (defcustom gnus-treat-translate nil
927 "Translate articles from one language to another.
928 Valid values are nil, t, `head', `last', an integer or a predicate.
929 See the manual for details."
930 :group 'gnus-article-treat
931 :type gnus-article-treat-custom)
933 ;;; Internal variables
935 (defvar article-goto-body-goes-to-point-min-p nil)
936 (defvar gnus-article-wash-types nil)
937 (defvar gnus-article-emphasis-alist nil)
939 (defvar gnus-article-mime-handle-alist-1 nil)
940 (defvar gnus-treatment-function-alist
941 '((gnus-treat-decode-article-as-default-mime-charset
942 gnus-article-decode-article-as-default-mime-charset)
943 (gnus-treat-strip-banner gnus-article-strip-banner)
944 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
945 (gnus-treat-buttonize gnus-article-add-buttons)
946 (gnus-treat-fill-article gnus-article-fill-cited-article)
947 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
948 (gnus-treat-strip-cr gnus-article-remove-cr)
949 (gnus-treat-display-xface gnus-article-display-x-face)
950 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
951 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
952 (gnus-treat-hide-signature gnus-article-hide-signature)
953 (gnus-treat-hide-citation gnus-article-hide-citation)
954 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
955 (gnus-treat-strip-pgp gnus-article-hide-pgp)
956 (gnus-treat-strip-pem gnus-article-hide-pem)
957 (gnus-treat-highlight-headers gnus-article-highlight-headers)
958 (gnus-treat-emphasize gnus-article-emphasize)
959 (gnus-treat-highlight-citation gnus-article-highlight-citation)
960 (gnus-treat-highlight-signature gnus-article-highlight-signature)
961 (gnus-treat-date-ut gnus-article-date-ut)
962 (gnus-treat-date-local gnus-article-date-local)
963 (gnus-treat-date-lapsed gnus-article-date-lapsed)
964 (gnus-treat-date-original gnus-article-date-original)
965 (gnus-treat-date-user-defined gnus-article-date-user)
966 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
967 (gnus-treat-strip-trailing-blank-lines
968 gnus-article-remove-trailing-blank-lines)
969 (gnus-treat-strip-leading-blank-lines
970 gnus-article-strip-leading-blank-lines)
971 (gnus-treat-strip-multiple-blank-lines
972 gnus-article-strip-multiple-blank-lines)
973 (gnus-treat-overstrike gnus-article-treat-overstrike)
974 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
975 (gnus-treat-display-smileys gnus-smiley-display)
976 (gnus-treat-display-picons gnus-article-display-picons)
977 (gnus-treat-play-sounds gnus-earcon-display)))
979 (defvar gnus-article-mime-handle-alist nil)
980 (defvar article-lapsed-timer nil)
981 (defvar gnus-article-current-summary nil)
983 (defvar gnus-article-mode-syntax-table
984 (let ((table (copy-syntax-table text-mode-syntax-table)))
985 (modify-syntax-entry ?- "w" table)
986 (modify-syntax-entry ?> ")" table)
987 (modify-syntax-entry ?< "(" table)
989 "Syntax table used in article mode buffers.
990 Initialized from `text-mode-syntax-table.")
992 (defvar gnus-save-article-buffer nil)
994 (defvar gnus-article-mode-line-format-alist
995 (nconc '((?w (gnus-article-wash-status) ?s)
996 (?m (gnus-article-mime-part-status) ?s))
997 gnus-summary-mode-line-format-alist))
999 (defvar gnus-number-of-articles-to-be-saved nil)
1001 (defvar gnus-inhibit-hiding nil)
1003 (defsubst gnus-article-hide-text (b e props)
1004 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1005 (add-text-properties b e props)
1006 (when (memq 'intangible props)
1008 (max (1- b) (point-min))
1009 b 'intangible (cddr (memq 'intangible props)))))
1010 (defsubst gnus-article-unhide-text (b e)
1011 "Remove hidden text properties from region between B and E."
1012 (remove-text-properties b e gnus-hidden-properties)
1013 (when (memq 'intangible gnus-hidden-properties)
1014 (put-text-property (max (1- b) (point-min))
1015 b 'intangible nil)))
1017 (defun gnus-article-hide-text-type (b e type)
1018 "Hide text of TYPE between B and E."
1019 (push type gnus-article-wash-types)
1020 (gnus-article-hide-text
1021 b e (cons 'article-type (cons type gnus-hidden-properties))))
1023 (defun gnus-article-unhide-text-type (b e type)
1024 "Unhide text of TYPE between B and E."
1025 (setq gnus-article-wash-types
1026 (delq type gnus-article-wash-types))
1027 (remove-text-properties
1028 b e (cons 'article-type (cons type gnus-hidden-properties)))
1029 (when (memq 'intangible gnus-hidden-properties)
1030 (put-text-property (max (1- b) (point-min))
1031 b 'intangible nil)))
1033 (defun gnus-article-hide-text-of-type (type)
1034 "Hide text of TYPE in the current buffer."
1036 (let ((b (point-min))
1038 (while (setq b (text-property-any b e 'article-type type))
1039 (add-text-properties b (incf b) gnus-hidden-properties)))))
1041 (defun gnus-article-delete-text-of-type (type)
1042 "Delete text of TYPE in the current buffer."
1044 (let ((b (point-min)))
1045 (while (setq b (text-property-any b (point-max) 'article-type type))
1047 b (or (text-property-not-all b (point-max) 'article-type type)
1050 (defun gnus-article-delete-invisible-text ()
1051 "Delete all invisible text in the current buffer."
1053 (let ((b (point-min)))
1054 (while (setq b (text-property-any b (point-max) 'invisible t))
1056 b (or (text-property-not-all b (point-max) 'invisible t)
1059 (defun gnus-article-text-type-exists-p (type)
1060 "Say whether any text of type TYPE exists in the buffer."
1061 (text-property-any (point-min) (point-max) 'article-type type))
1063 (defsubst gnus-article-header-rank ()
1064 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1065 (let ((list gnus-sorted-header-list)
1068 (when (looking-at (car list))
1070 (setq list (cdr list))
1074 (defun article-hide-headers (&optional arg delete)
1075 "Hide unwanted headers and possibly sort them as well."
1076 (interactive (gnus-article-hidden-arg))
1077 ;; Lars said that this function might be inhibited.
1078 (if (gnus-article-check-hidden-text 'headers arg)
1080 ;; Show boring headers as well.
1081 (gnus-article-show-hidden-text 'boring-headers)
1082 (when (eq 1 (point-min))
1083 (set-window-start (get-buffer-window (current-buffer)) 1)))
1084 (unless gnus-inhibit-hiding
1087 (let ((buffer-read-only nil)
1088 (inhibit-read-only t)
1089 (case-fold-search t)
1090 (max (1+ (length gnus-sorted-header-list)))
1091 (ignored (when (not gnus-visible-headers)
1092 (cond ((stringp gnus-ignored-headers)
1093 gnus-ignored-headers)
1094 ((listp gnus-ignored-headers)
1095 (mapconcat 'identity gnus-ignored-headers
1098 (cond ((stringp gnus-visible-headers)
1099 gnus-visible-headers)
1100 ((and gnus-visible-headers
1101 (listp gnus-visible-headers))
1102 (mapconcat 'identity gnus-visible-headers "\\|"))))
1103 (inhibit-point-motion-hooks t)
1105 ;; First we narrow to just the headers.
1106 (article-narrow-to-head)
1107 ;; Hide any "From " lines at the beginning of (mail) articles.
1108 (while (looking-at "From ")
1112 (delete-region (point-min) (point))
1113 (gnus-article-hide-text (point-min) (point)
1114 (nconc (list 'article-type 'headers)
1115 gnus-hidden-properties))))
1116 ;; Then treat the rest of the header lines.
1117 ;; Then we use the two regular expressions
1118 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1119 ;; select which header lines is to remain visible in the
1121 (while (re-search-forward "^[^ \t]*:" nil t)
1123 ;; Mark the rank of the header.
1125 (point) (1+ (point)) 'message-rank
1126 (if (or (and visible (looking-at visible))
1128 (not (looking-at ignored))))
1129 (gnus-article-header-rank)
1132 (message-sort-headers-1)
1133 (when (setq beg (text-property-any
1134 (point-min) (point-max) 'message-rank (+ 2 max)))
1135 ;; We delete or make invisible the unwanted headers.
1138 (add-text-properties
1139 (point-min) (+ 5 (point-min))
1140 '(article-type headers dummy-invisible t))
1141 (delete-region beg (point-max)))
1142 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1145 (defun article-hide-boring-headers (&optional arg)
1146 "Toggle hiding of headers that aren't very interesting.
1147 If given a negative prefix, always show; if given a positive prefix,
1149 (interactive (gnus-article-hidden-arg))
1150 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1151 (not gnus-show-all-headers))
1154 (let ((buffer-read-only nil)
1155 (list gnus-boring-article-headers)
1156 (inhibit-point-motion-hooks t)
1158 (article-narrow-to-head)
1160 (setq elem (pop list))
1161 (goto-char (point-min))
1163 ;; Hide empty headers.
1165 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1167 (gnus-article-hide-text-type
1168 (progn (beginning-of-line) (point))
1171 (if (re-search-forward "^[^ \t]" nil t)
1175 ;; Hide boring Newsgroups header.
1176 ((eq elem 'newsgroups)
1177 (when (equal (gnus-fetch-field "newsgroups")
1178 (gnus-group-real-name
1179 (if (boundp 'gnus-newsgroup-name)
1182 (gnus-article-hide-header "newsgroups")))
1183 ((eq elem 'followup-to)
1184 (when (equal (message-fetch-field "followup-to")
1185 (message-fetch-field "newsgroups"))
1186 (gnus-article-hide-header "followup-to")))
1187 ((eq elem 'reply-to)
1188 (let ((from (message-fetch-field "from"))
1189 (reply-to (message-fetch-field "reply-to")))
1194 (nth 1 (funcall gnus-extract-address-components from))
1195 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1196 (gnus-article-hide-header "reply-to"))))
1198 (let ((date (message-fetch-field "date")))
1200 (< (days-between (current-time-string) date)
1202 (gnus-article-hide-header "date"))))
1204 (let ((to (message-fetch-field "to")))
1205 (when (> (length to) 1024)
1206 (gnus-article-hide-header "to"))))
1209 (goto-char (point-min))
1210 (while (re-search-forward "^to:" nil t)
1211 (setq to-count (1+ to-count)))
1212 (when (> to-count 1)
1213 (while (> to-count 0)
1214 (goto-char (point-min))
1216 (re-search-forward "^to:" nil nil to-count)
1218 (narrow-to-region (point) (point-max))
1219 (gnus-article-hide-header "to"))
1220 (setq to-count (1- to-count)))))))))))))
1222 (defun gnus-article-hide-header (header)
1224 (goto-char (point-min))
1225 (when (re-search-forward (concat "^" header ":") nil t)
1226 (gnus-article-hide-text-type
1227 (progn (beginning-of-line) (point))
1230 (if (re-search-forward "^[^ \t]" nil t)
1235 (defun article-toggle-headers (&optional arg)
1236 "Toggle hiding of headers. If given a negative prefix, always show;
1237 if given a positive prefix, always hide."
1238 (interactive (gnus-article-hidden-arg))
1239 (let ((force (when (numberp arg)
1240 (cond ((> arg 0) 'always-hide)
1241 ((< arg 0) 'always-show))))
1242 (window (get-buffer-window gnus-article-buffer))
1243 (header-end (point-min))
1244 header-start field-end field-start
1245 (inhibit-point-motion-hooks t)
1246 (inhibit-read-only t)
1250 (while (and (setq header-start
1251 (text-property-any header-end (point-max)
1252 'article-treated-header t))
1254 (text-property-not-all header-start (point-max)
1255 'article-treated-header t)))
1256 (setq field-end header-start)
1258 (;; Hide exposed invisible fields.
1259 (and (not (eq 'always-show force))
1261 (text-property-any field-end header-end
1262 'exposed-invisible-field t)))
1263 (while (and field-start
1264 (setq field-end (text-property-not-all
1265 field-start header-end
1266 'exposed-invisible-field t)))
1267 (add-text-properties field-start field-end gnus-hidden-properties)
1268 (setq field-start (text-property-any field-end header-end
1269 'exposed-invisible-field t)))
1270 (put-text-property header-start header-end
1271 'exposed-invisible-field nil))
1272 (;; Expose invisible fields.
1273 (and (not (eq 'always-hide force))
1275 (text-property-any field-end header-end 'invisible t)))
1276 (while (and field-start
1277 (setq field-end (text-property-not-all
1278 field-start header-end
1280 ;; If the invisible text is not terminated with newline, we
1281 ;; won't expose it. Because it may be created by x-face-mule.
1282 ;; BTW, XEmacs sometimes fail in putting a invisible text
1283 ;; property with `gnus-article-hide-text' (really?). In that
1284 ;; case, the invisible text might be started from the middle of
1285 ;; a line so we will expose the sort of thing.
1286 (when (or (not (or (eq header-start field-start)
1287 (eq ?\n (char-before field-start))))
1288 (eq ?\n (char-before field-end)))
1289 (remove-text-properties field-start field-end
1290 gnus-hidden-properties)
1291 (put-text-property field-start field-end
1292 'exposed-invisible-field t))
1293 (setq field-start (text-property-any field-end header-end
1296 (not (eq 'always-show force))
1297 (narrow-to-region header-start header-end)
1298 (article-hide-headers)
1299 ;; Re-display X-Face image under XEmacs.
1300 (when (and gnus-xemacs
1301 (gnus-functionp gnus-article-x-face-command))
1302 (let ((func (cadr (assq 'gnus-treat-display-xface
1303 gnus-treatment-function-alist)))
1305 (when (and (not gnus-inhibit-treatment)
1307 (gnus-treat-predicate gnus-treat-display-xface))
1309 (put-text-property header-start header-end 'read-only nil))))
1312 (goto-char (point-min))
1314 (set-window-start window (point-min))))))
1316 (defvar gnus-article-normalized-header-length 40
1317 "Length of normalized headers.")
1319 (defun article-normalize-headers ()
1320 "Make all header lines 40 characters long."
1322 (let ((buffer-read-only nil)
1326 (article-narrow-to-head)
1329 ((< (setq column (- (gnus-point-at-eol) (point)))
1330 gnus-article-normalized-header-length)
1332 (insert (make-string
1333 (- gnus-article-normalized-header-length column)
1335 ((> column gnus-article-normalized-header-length)
1336 (gnus-put-text-property
1338 (forward-char gnus-article-normalized-header-length)
1345 (forward-line 1))))))
1347 (defun article-treat-dumbquotes ()
1348 "Translate M******** sm*rtq**t*s into proper text.
1349 Note that this function guesses whether a character is a sm*rtq**t* or
1350 not, so it should only be used interactively."
1352 (article-translate-strings gnus-article-dumbquotes-map))
1354 (defun article-translate-characters (from to)
1355 "Translate all characters in the body of the article according to FROM and TO.
1356 FROM is a string of characters to translate from; to is a string of
1357 characters to translate to."
1359 (when (article-goto-body)
1360 (let ((buffer-read-only nil)
1361 (x (make-string 225 ?x))
1363 (while (< (incf i) (length x))
1366 (while (< i (length from))
1367 (aset x (aref from i) (aref to i))
1369 (translate-region (point) (point-max) x)))))
1371 (defun article-translate-strings (map)
1372 "Translate all string in the body of the article according to MAP.
1373 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1375 (when (article-goto-body)
1376 (let ((buffer-read-only nil)
1378 (while (setq elem (pop map))
1380 (while (search-forward (car elem) nil t)
1381 (replace-match (cadr elem)))))))))
1383 (defun article-treat-overstrike ()
1384 "Translate overstrikes into bold text."
1387 (when (article-goto-body)
1388 (let ((buffer-read-only nil))
1389 (while (search-forward "\b" nil t)
1390 (let ((next (char-after))
1391 (previous (char-after (- (point) 2))))
1392 ;; We do the boldification/underlining by hiding the
1393 ;; overstrikes and putting the proper text property
1397 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1398 (put-text-property (point) (1+ (point)) 'face 'bold))
1400 (gnus-article-hide-text-type
1401 (1- (point)) (1+ (point)) 'overstrike)
1403 (- (point) 2) (1- (point)) 'face 'underline))
1405 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1407 (point) (1+ (point)) 'face 'underline)))))))))
1409 (defun article-fill-long-lines ()
1410 "Fill lines that are wider than the window width."
1413 (let ((buffer-read-only nil)
1414 (width (window-width (get-buffer-window (current-buffer)))))
1417 (let ((adaptive-fill-mode nil))
1420 (when (>= (current-column) (min fill-column width))
1421 (narrow-to-region (point) (gnus-point-at-bol))
1422 (fill-paragraph nil)
1423 (goto-char (point-max))
1425 (forward-line 1)))))))
1427 (defun article-capitalize-sentences ()
1428 "Capitalize the first word in each sentence."
1431 (let ((buffer-read-only nil)
1432 (paragraph-start "^[\n\^L]"))
1436 (forward-sentence)))))
1438 (defun article-remove-cr ()
1439 "Remove trailing CRs and then translate remaining CRs into LFs."
1442 (let ((buffer-read-only nil))
1443 (goto-char (point-min))
1444 (while (re-search-forward "\r+$" nil t)
1445 (replace-match "" t t))
1446 (goto-char (point-min))
1447 (while (search-forward "\r" nil t)
1448 (replace-match "\n" t t)))))
1450 (defun article-remove-trailing-blank-lines ()
1451 "Remove all trailing blank lines from the article."
1454 (let ((buffer-read-only nil))
1455 (goto-char (point-max))
1459 (while (and (not (bobp))
1460 (looking-at "^[ \t]*$")
1461 (not (gnus-annotation-in-region-p
1462 (point) (gnus-point-at-eol))))
1467 (defun article-display-x-face (&optional force)
1468 "Look for an X-Face header and display it if present."
1469 (interactive (list 'force))
1471 ;; Delete the old process, if any.
1472 (when (process-status "article-x-face")
1473 (delete-process "article-x-face"))
1474 (let ((inhibit-point-motion-hooks t)
1475 (case-fold-search t)
1478 (article-narrow-to-head)
1479 (goto-char (point-min))
1480 (setq from (message-fetch-field "from"))
1481 (goto-char (point-min))
1482 (while (and gnus-article-x-face-command
1485 ;; Check whether this face is censored.
1486 (not gnus-article-x-face-too-ugly)
1487 (and gnus-article-x-face-too-ugly from
1488 (not (string-match gnus-article-x-face-too-ugly
1490 ;; Has to be present.
1491 (re-search-forward "^X-Face: " nil t))
1492 ;; This used to try to do multiple faces (`while' instead of
1493 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1494 ;; work (b) it can crash some versions of Emacs (c) are
1495 ;; multiple faces really something to encourage?
1496 (when (stringp gnus-article-x-face-command)
1498 ;; We now have the area of the buffer where the X-Face is stored.
1501 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1502 ;; We display the face.
1503 (if (symbolp gnus-article-x-face-command)
1504 ;; The command is a lisp function, so we call it.
1505 (if (gnus-functionp gnus-article-x-face-command)
1506 (funcall gnus-article-x-face-command beg end)
1507 (error "%s is not a function" gnus-article-x-face-command))
1508 ;; The command is a string, so we interpret the command
1509 ;; as a, well, command, and fork it off.
1510 (let ((process-connection-type nil))
1511 (process-kill-without-query
1513 "article-x-face" nil shell-file-name shell-command-switch
1514 gnus-article-x-face-command))
1515 (process-send-region "article-x-face" beg end)
1516 (process-send-eof "article-x-face"))))))))))
1518 (defun article-decode-mime-words ()
1519 "Decode all MIME-encoded words in the article."
1522 (set-buffer gnus-article-buffer)
1523 (let ((inhibit-point-motion-hooks t)
1525 (mail-parse-charset gnus-newsgroup-charset)
1526 (mail-parse-ignored-charsets
1527 (save-excursion (set-buffer gnus-summary-buffer)
1528 gnus-newsgroup-ignored-charsets)))
1529 (mail-decode-encoded-word-region (point-min) (point-max)))))
1531 (defun article-decode-charset (&optional prompt)
1532 "Decode charset-encoded text in the article.
1533 If PROMPT (the prefix), prompt for a coding system to use."
1537 (article-narrow-to-head)
1538 (let* ((inhibit-point-motion-hooks t)
1539 (case-fold-search t)
1540 (ct (message-fetch-field "Content-Type" t))
1541 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1542 (ctl (and ct (ignore-errors
1543 (mail-header-parse-content-type ct))))
1546 (mm-read-coding-system "Charset to decode: "))
1548 (mail-content-type-get ctl 'charset))))
1549 (mail-parse-charset gnus-newsgroup-charset)
1550 (mail-parse-ignored-charsets
1551 (save-excursion (condition-case nil
1552 (set-buffer gnus-summary-buffer)
1554 gnus-newsgroup-ignored-charsets))
1556 (if (and ctl (not (string-match "/" (car ctl))))
1558 (goto-char (point-max))
1561 (narrow-to-region (point) (point-max))
1562 (when (and (or (not ctl)
1563 (equal (car ctl) "text/plain"))
1566 charset (and cte (intern (downcase
1567 (gnus-strip-whitespace cte))))
1570 (defun article-decode-encoded-words ()
1571 "Remove encoded-word encoding from headers."
1572 (let (buffer-read-only)
1573 (let ((charset (save-excursion
1574 (set-buffer gnus-summary-buffer)
1575 default-mime-charset)))
1576 (mime-decode-header-in-buffer charset)
1579 (defun article-de-quoted-unreadable (&optional force)
1580 "Translate a quoted-printable-encoded article.
1581 If FORCE, decode the article whether it is marked as quoted-printable
1583 (interactive (list 'force))
1585 (let ((buffer-read-only nil)
1586 (type (gnus-fetch-field "content-transfer-encoding"))
1587 (charset gnus-newsgroup-charset))
1589 (and type (string-match "quoted-printable" (downcase type))))
1592 (narrow-to-region (point) (point-max))
1593 (quoted-printable-decode-region (point-min) (point-max))
1595 (mm-decode-body charset)))))))
1597 (defun article-hide-list-identifiers ()
1598 "Remove any list identifiers in `gnus-list-identifiers' from Subject
1599 header in the current article."
1603 (let ((inhibit-point-motion-hooks t)
1605 (article-narrow-to-head)
1606 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1607 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1609 (goto-char (point-min))
1610 (when (re-search-forward
1611 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1613 (delete-region (match-beginning 2) (match-end 0)))))))))
1615 (defun article-hide-pgp ()
1616 "Remove any PGP headers and signatures in the current article."
1620 (let ((inhibit-point-motion-hooks t)
1621 buffer-read-only beg end)
1623 ;; Hide the "header".
1624 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1625 (push 'pgp gnus-article-wash-types)
1626 (delete-region (match-beginning 0) (match-end 0))
1627 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1628 (when (looking-at "Hash:.*$")
1629 (delete-region (point) (1+ (gnus-point-at-eol))))
1631 ;; Hide the actual signature.
1632 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1633 (setq end (1+ (match-beginning 0)))
1636 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1638 ;; Perhaps we shouldn't hide to the end of the buffer
1639 ;; if there is no end to the signature?
1641 ;; Hide "- " PGP quotation markers.
1643 (narrow-to-region beg end)
1644 (goto-char (point-min))
1645 (while (re-search-forward "^- " nil t)
1647 (match-beginning 0) (match-end 0)))
1649 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1651 (defun article-hide-pem (&optional arg)
1652 "Toggle hiding of any PEM headers and signatures in the current article.
1653 If given a negative prefix, always show; if given a positive prefix,
1655 (interactive (gnus-article-hidden-arg))
1656 (unless (gnus-article-check-hidden-text 'pem arg)
1658 (let (buffer-read-only end)
1659 (goto-char (point-min))
1660 ;; Hide the horrendously ugly "header".
1661 (when (and (search-forward
1662 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1664 (setq end (1+ (match-beginning 0))))
1665 (push 'pem gnus-article-wash-types)
1666 (gnus-article-hide-text-type
1668 (if (search-forward "\n\n" nil t)
1672 ;; Hide the trailer as well
1673 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1675 (gnus-article-hide-text-type
1676 (match-beginning 0) (match-end 0) 'pem)))))))
1678 (defun article-strip-banner ()
1679 "Strip the banner specified by the `banner' group parameter."
1683 (let ((inhibit-point-motion-hooks t)
1684 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1685 (gnus-signature-limit nil)
1686 buffer-read-only beg end)
1690 ((eq banner 'signature)
1691 (when (gnus-article-narrow-to-signature)
1694 (delete-region (point) (point-max))))
1696 (while (re-search-forward banner nil t)
1697 (delete-region (match-beginning 0) (match-end 0))))))))))
1699 (defun article-babel ()
1700 "Translate article using an online translation service."
1704 (set-buffer gnus-article-buffer)
1705 (when (article-goto-body)
1706 (let* ((buffer-read-only nil)
1709 (orig (buffer-substring start end))
1710 (trans (babel-as-string orig)))
1712 (narrow-to-region start end)
1713 (delete-region start end)
1716 (defun article-hide-signature (&optional arg)
1717 "Hide the signature in the current article.
1718 If given a negative prefix, always show; if given a positive prefix,
1720 (interactive (gnus-article-hidden-arg))
1721 (unless (gnus-article-check-hidden-text 'signature arg)
1724 (let ((buffer-read-only nil))
1725 (when (gnus-article-narrow-to-signature)
1726 (gnus-article-hide-text-type
1727 (point-min) (point-max) 'signature)))))))
1729 (defun article-strip-headers-in-body ()
1730 "Strip offensive headers from bodies."
1734 (let ((case-fold-search t))
1735 (when (looking-at "x-no-archive:")
1736 (gnus-delete-line)))))
1738 (defun article-strip-leading-blank-lines ()
1739 "Remove all blank lines from the beginning of the article."
1742 (let ((inhibit-point-motion-hooks t)
1744 (when (article-goto-body)
1745 (while (and (not (eobp))
1746 (looking-at "[ \t]*$"))
1747 (gnus-delete-line))))))
1749 (defun article-narrow-to-head ()
1750 "Narrow the buffer to the head of the message.
1751 Point is left at the beginning of the narrowed-to region."
1753 (goto-char (point-min))
1754 (if (search-forward "\n\n" nil 1)
1757 (goto-char (point-min)))
1759 (defun article-goto-body ()
1760 "Place point at the start of the body."
1761 (goto-char (point-min))
1763 ;; This variable is only bound when dealing with separate
1765 (article-goto-body-goes-to-point-min-p
1767 ((search-forward "\n\n" nil t)
1770 (goto-char (point-max))
1773 (defun article-strip-multiple-blank-lines ()
1774 "Replace consecutive blank lines with one empty line."
1777 (let ((inhibit-point-motion-hooks t)
1779 ;; First make all blank lines empty.
1781 (while (re-search-forward "^[ \t]+$" nil t)
1782 (unless (gnus-annotation-in-region-p
1783 (match-beginning 0) (match-end 0))
1784 (replace-match "" nil t)))
1785 ;; Then replace multiple empty lines with a single empty line.
1787 (while (re-search-forward "\n\n\n+" nil t)
1788 (unless (gnus-annotation-in-region-p
1789 (match-beginning 0) (match-end 0))
1790 (replace-match "\n\n" t t))))))
1792 (defun article-strip-leading-space ()
1793 "Remove all white space from the beginning of the lines in the article."
1796 (let ((inhibit-point-motion-hooks t)
1799 (while (re-search-forward "^[ \t]+" nil t)
1800 (replace-match "" t t)))))
1802 (defun article-strip-trailing-space ()
1803 "Remove all white space from the end of the lines in the article."
1806 (let ((inhibit-point-motion-hooks t)
1809 (while (re-search-forward "[ \t]+$" nil t)
1810 (replace-match "" t t)))))
1812 (defun article-strip-blank-lines ()
1813 "Strip leading, trailing and multiple blank lines."
1815 (article-strip-leading-blank-lines)
1816 (article-remove-trailing-blank-lines)
1817 (article-strip-multiple-blank-lines))
1819 (defun article-strip-all-blank-lines ()
1820 "Strip all blank lines."
1823 (let ((inhibit-point-motion-hooks t)
1826 (while (re-search-forward "^[ \t]*\n" nil t)
1827 (replace-match "" t t)))))
1829 (defun gnus-article-narrow-to-signature ()
1830 "Narrow to the signature; return t if a signature is found, else nil."
1831 (let ((inhibit-point-motion-hooks t))
1832 (when (gnus-article-search-signature)
1834 ;; Check whether we have some limits to what we consider
1835 ;; to be a signature.
1836 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1837 (list gnus-signature-limit)))
1839 (while (setq limit (pop limits))
1840 (if (or (and (integerp limit)
1841 (< (- (point-max) (point)) limit))
1843 (< (count-lines (point) (point-max)) limit))
1844 (and (gnus-functionp limit)
1846 (and (stringp limit)
1847 (not (re-search-forward limit nil t))))
1848 () ; This limit did not succeed.
1852 (narrow-to-region (point) (point-max))
1855 (defun gnus-article-search-signature ()
1856 "Search the current buffer for the signature separator.
1857 Put point at the beginning of the signature separator."
1858 (let ((cur (point)))
1859 (goto-char (point-max))
1860 (if (if (stringp gnus-signature-separator)
1861 (re-search-backward gnus-signature-separator nil t)
1862 (let ((seps gnus-signature-separator))
1864 (not (re-search-backward (car seps) nil t)))
1871 (defun gnus-article-hidden-arg ()
1872 "Return the current prefix arg as a number, or 0 if no prefix."
1873 (list (if current-prefix-arg
1874 (prefix-numeric-value current-prefix-arg)
1877 (defun gnus-article-check-hidden-text (type arg)
1878 "Return nil if hiding is necessary.
1879 Arg can be nil or a number. Nil and positive means hide, negative
1880 means show, 0 means toggle."
1883 (let ((hide (gnus-article-hidden-text-p type)))
1889 (gnus-article-show-hidden-text type))
1891 (if (eq hide 'hidden)
1892 (gnus-article-show-hidden-text type)
1895 (defun gnus-article-hidden-text-p (type)
1896 "Say whether the current buffer contains hidden text of type TYPE."
1897 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1899 (not (get-text-property pos 'invisible))
1900 (not (get-text-property pos 'dummy-invisible)))
1902 (text-property-any (1+ pos) (point-max) 'article-type type)))
1907 (defun gnus-article-show-hidden-text (type &optional hide)
1908 "Show all hidden text of type TYPE.
1909 If HIDE, hide the text instead."
1911 (let ((buffer-read-only nil)
1912 (inhibit-point-motion-hooks t)
1915 (while (setq beg (text-property-any end (point-max) 'article-type type))
1918 (text-property-not-all beg (point-max) 'article-type type)
1921 (gnus-article-hide-text beg end gnus-hidden-properties)
1922 (gnus-article-unhide-text beg end))
1926 (defconst article-time-units
1927 `((year . ,(* 365.25 24 60 60))
1928 (week . ,(* 7 24 60 60))
1929 (day . ,(* 24 60 60))
1933 "Mapping from time units to seconds.")
1935 (defun article-date-ut (&optional type highlight header)
1936 "Convert DATE date to universal time in the current article.
1937 If TYPE is `local', convert to local time; if it is `lapsed', output
1938 how much time has lapsed since DATE. For `lapsed', the value of
1939 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1940 should replace the \"Date:\" one, or should be added below it."
1941 (interactive (list 'ut t))
1942 (let* ((header (or header
1943 (and (eq 1 (point-min))
1944 (mail-header-date (save-excursion
1945 (set-buffer gnus-summary-buffer)
1946 gnus-current-headers)))
1947 (message-fetch-field "date")
1949 (date (if (vectorp header) (mail-header-date header)
1951 (inhibit-point-motion-hooks t)
1952 bface eface date-pos)
1953 (when (and date (not (string= date "")))
1956 (article-narrow-to-head)
1957 (when (or (and (eq type 'lapsed)
1958 gnus-article-date-lapsed-new-header
1959 ;; Attempt to get the face of X-Sent first.
1960 (re-search-forward "^X-Sent:[ \t]" nil t))
1961 (re-search-forward "^Date:[ \t]" nil t)
1962 ;; If Date is missing, try again for X-Sent.
1963 (re-search-forward "^X-Sent:[ \t]" nil t))
1964 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1965 date (or (get-text-property (gnus-point-at-bol)
1968 eface (get-text-property (1- (gnus-point-at-eol))
1970 (let ((buffer-read-only nil))
1971 ;; Delete any old X-Sent headers.
1972 (when (setq date-pos
1973 (text-property-any (point-min) (point-max)
1974 'article-date-lapsed t))
1975 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
1976 (delete-region (match-beginning 0)
1977 (progn (forward-line 1) (point))))
1978 (goto-char (point-min))
1979 ;; Delete any old Date headers.
1980 (while (re-search-forward "^Date:[ \t]" nil t)
1982 (setq date-pos (match-beginning 0)))
1983 (unless (and (eq type 'lapsed)
1984 gnus-article-date-lapsed-new-header)
1985 (delete-region (match-beginning 0)
1986 (progn (message-next-header) (point)))))
1989 (goto-char date-pos)
1991 ;; Possibly, Date has been deleted.
1993 (when (and (eq type 'lapsed)
1994 gnus-article-date-lapsed-new-header
1995 (looking-at "Date:"))
1997 (goto-char (point-min)))
1998 (insert (article-make-date-line date type))
1999 (when (eq type 'lapsed)
2000 (put-text-property (gnus-point-at-bol) (point)
2001 'article-date-lapsed t))
2005 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2006 (put-text-property (match-beginning 1) (1+ (match-end 1))
2007 'original-date date)
2008 (put-text-property (match-beginning 1) (1+ (match-end 1))
2010 (put-text-property (match-beginning 2) (match-end 2)
2013 (defun article-make-date-line (date type)
2014 "Return a DATE line of TYPE."
2015 (let ((time (condition-case ()
2019 ;; Convert to the local timezone. We have to slap a
2020 ;; `condition-case' round the calls to the timezone
2021 ;; functions since they aren't particularly resistant to
2024 (let ((tz (car (current-time-zone time))))
2025 (format "Date: %s %s%02d%02d" (current-time-string time)
2026 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2027 (/ (% (abs tz) 3600) 60))))
2028 ;; Convert to Universal Time.
2031 (current-time-string
2032 (let* ((e (parse-time-string date))
2033 (tm (apply 'encode-time e))
2035 (ls (- (cadr tm) (car (current-time-zone time)))))
2036 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2037 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2040 ;; Get the original date from the article.
2041 ((eq type 'original)
2042 (concat "Date: " (if (string-match "\n+$" date)
2043 (substring date 0 (match-beginning 0))
2045 ;; Let the user define the format.
2047 (if (gnus-functionp gnus-article-time-format)
2048 (funcall gnus-article-time-format time)
2051 (format-time-string gnus-article-time-format time))))
2056 (format-time-string "%Y%m%dT%H%M%S" time)))
2057 ;; Do an X-Sent lapsed format.
2059 ;; If the date is seriously mangled, the timezone functions are
2060 ;; liable to bug out, so we ignore all errors.
2061 (let* ((now (current-time))
2062 (real-time (subtract-time now time))
2063 (real-sec (and real-time
2064 (+ (* (float (car real-time)) 65536)
2066 (sec (and real-time (abs real-sec)))
2076 ;; This is a bit convoluted, but basically we go
2077 ;; through the time units for years, weeks, etc,
2078 ;; and divide things to see whether that results
2079 ;; in positive answers.
2082 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2083 ;; The (remaining) seconds are too few to
2084 ;; be divided into this time unit.
2086 ;; It's big enough, so we output it.
2087 (setq sec (- sec (* num (cdr unit))))
2089 (concat (if prev ", " "") (int-to-string
2091 " " (symbol-name (car unit))
2092 (if (> num 1) "s" ""))
2094 article-time-units "")
2095 ;; If dates are odd, then it might appear like the
2096 ;; article was sent in the future.
2099 " in the future"))))))
2101 (error "Unknown conversion type: %s" type)))))
2103 (defun article-date-local (&optional highlight)
2104 "Convert the current article date to the local timezone."
2105 (interactive (list t))
2106 (article-date-ut 'local highlight))
2108 (defun article-date-original (&optional highlight)
2109 "Convert the current article date to what it was originally.
2110 This is only useful if you have used some other date conversion
2111 function and want to see what the date was before converting."
2112 (interactive (list t))
2113 (article-date-ut 'original highlight))
2115 (defun article-date-lapsed (&optional highlight)
2116 "Convert the current article date to time lapsed since it was sent."
2117 (interactive (list t))
2118 (article-date-ut 'lapsed highlight))
2120 (defun article-update-date-lapsed ()
2121 "Function to be run from a timer to update the lapsed time line."
2122 (let (deactivate-mark)
2127 (set-buffer (window-buffer w))
2128 (when (eq major-mode 'gnus-article-mode)
2129 (goto-char (point-min))
2130 (when (re-search-forward "^X-Sent:" nil t)
2131 (article-date-lapsed t))))
2134 (defun gnus-start-date-timer (&optional n)
2135 "Start a timer to update the X-Sent header in the article buffers.
2136 The numerical prefix says how frequently (in seconds) the function
2141 (gnus-stop-date-timer)
2142 (setq article-lapsed-timer
2143 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2145 (defun gnus-stop-date-timer ()
2146 "Stop the X-Sent timer."
2148 (when article-lapsed-timer
2149 (nnheader-cancel-timer article-lapsed-timer)
2150 (setq article-lapsed-timer nil)))
2152 (defun article-date-user (&optional highlight)
2153 "Convert the current article date to the user-defined format.
2154 This format is defined by the `gnus-article-time-format' variable."
2155 (interactive (list t))
2156 (article-date-ut 'user highlight))
2158 (defun article-date-iso8601 (&optional highlight)
2159 "Convert the current article date to ISO8601."
2160 (interactive (list t))
2161 (article-date-ut 'iso8601 highlight))
2163 (defun article-show-all ()
2164 "Show all hidden text in the article buffer."
2167 (let ((buffer-read-only nil))
2168 (gnus-article-unhide-text (point-min) (point-max)))))
2170 (defun article-emphasize (&optional arg)
2171 "Emphasize text according to `gnus-emphasis-alist'."
2172 (interactive (gnus-article-hidden-arg))
2173 (unless (gnus-article-check-hidden-text 'emphasis arg)
2175 (let ((alist (or (with-current-buffer gnus-summary-buffer
2176 gnus-article-emphasis-alist)
2177 gnus-emphasis-alist))
2178 (buffer-read-only nil)
2179 (props (append '(article-type emphasis)
2180 gnus-hidden-properties))
2181 regexp elem beg invisible visible face)
2184 (while (setq elem (pop alist))
2186 (setq regexp (car elem)
2187 invisible (nth 1 elem)
2188 visible (nth 2 elem)
2190 (while (re-search-forward regexp nil t)
2191 (when (and (match-beginning visible) (match-beginning invisible))
2192 (gnus-article-hide-text
2193 (match-beginning invisible) (match-end invisible) props)
2194 (gnus-article-unhide-text-type
2195 (match-beginning visible) (match-end visible) 'emphasis)
2196 (gnus-put-text-property-excluding-newlines
2197 (match-beginning visible) (match-end visible) 'face face)
2198 (goto-char (match-end invisible)))))))))
2200 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2201 "Setup newsgroup emphasis alist."
2202 (unless gnus-article-emphasis-alist
2203 (let ((name (and gnus-newsgroup-name
2204 (gnus-group-real-name gnus-newsgroup-name))))
2205 (make-local-variable 'gnus-article-emphasis-alist)
2206 (setq gnus-article-emphasis-alist
2208 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2209 (while (setq elem (pop alist))
2210 (when (and name (string-match (car elem) name))
2212 highlight (copy-list (cdr elem)))))
2214 (copy-list highlight-words)
2215 (if gnus-newsgroup-name
2216 (copy-list (gnus-group-find-parameter
2217 gnus-newsgroup-name 'highlight-words t)))
2218 gnus-emphasis-alist)))))
2220 (defvar gnus-summary-article-menu)
2221 (defvar gnus-summary-post-menu)
2223 ;;; Saving functions.
2225 (defun gnus-article-save (save-buffer file &optional num)
2226 "Save the currently selected article."
2227 (unless gnus-save-all-headers
2228 ;; Remove headers according to `gnus-saved-headers'.
2229 (let ((gnus-visible-headers
2230 (or gnus-saved-headers gnus-visible-headers))
2231 (gnus-article-buffer save-buffer))
2233 (set-buffer save-buffer)
2234 (article-hide-headers 1 t))))
2235 (save-window-excursion
2236 (if (not gnus-default-article-saver)
2237 (error "No default saver is defined")
2238 ;; !!! Magic! The saving functions all save
2239 ;; `gnus-save-article-buffer' (or so they think), but we
2240 ;; bind that variable to our save-buffer.
2241 (set-buffer gnus-article-buffer)
2242 (let* ((gnus-save-article-buffer save-buffer)
2245 ((not gnus-prompt-before-saving) 'default)
2246 ((eq gnus-prompt-before-saving 'always) nil)
2248 (gnus-number-of-articles-to-be-saved
2249 (when (eq gnus-prompt-before-saving t)
2251 (set-buffer gnus-article-current-summary)
2252 (funcall gnus-default-article-saver filename)))))
2254 (defun gnus-read-save-file-name (prompt &optional filename
2255 function group headers variable)
2257 (funcall function group headers (symbol-value variable)))
2262 ((eq filename 'default)
2268 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2271 (if (and gnus-number-of-articles-to-be-saved
2272 (> gnus-number-of-articles-to-be-saved 1))
2273 (format "these %d articles"
2274 gnus-number-of-articles-to-be-saved)
2277 ;; Let the split methods have their say.
2279 ;; No split name was found.
2282 (concat prompt " (default "
2283 (file-name-nondirectory default-name) ") ")
2284 (file-name-directory default-name)
2286 ;; A single group name is returned.
2287 ((stringp split-name)
2289 (funcall function split-name headers
2290 (symbol-value variable)))
2292 (concat prompt " (default "
2293 (file-name-nondirectory default-name) ") ")
2294 (file-name-directory default-name)
2296 ;; A single split name was found
2297 ((= 1 (length split-name))
2298 (let* ((name (expand-file-name
2299 (car split-name) gnus-article-save-directory))
2300 (dir (cond ((file-directory-p name)
2301 (file-name-as-directory name))
2302 ((file-exists-p name) name)
2303 (t gnus-article-save-directory))))
2305 (concat prompt " (default " name ") ")
2307 ;; A list of splits was found.
2309 (setq split-name (nreverse split-name))
2311 (let ((file-name-history
2312 (nconc split-name file-name-history)))
2316 (concat prompt " (`M-p' for defaults) ")
2317 gnus-article-save-directory
2319 gnus-article-save-directory)))
2320 (car (push result file-name-history)))))))
2321 ;; Create the directory.
2322 (gnus-make-directory (file-name-directory file))
2323 ;; If we have read a directory, we append the default file name.
2324 (when (file-directory-p file)
2325 (setq file (concat (file-name-as-directory file)
2326 (file-name-nondirectory default-name))))
2327 ;; Possibly translate some characters.
2328 (nnheader-translate-file-chars file)))))
2329 (gnus-make-directory (file-name-directory result))
2330 (set variable result)))
2332 (defun gnus-article-archive-name (group)
2333 "Return the first instance of an \"Archive-name\" in the current buffer."
2334 (let ((case-fold-search t))
2335 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2336 (nnheader-concat gnus-article-save-directory
2337 (match-string 1)))))
2339 (defun gnus-article-nndoc-name (group)
2340 "If GROUP is an nndoc group, return the name of the parent group."
2341 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2342 (gnus-group-get-parameter group 'save-article-group)))
2344 (defun gnus-summary-save-in-rmail (&optional filename)
2345 "Append this article to Rmail file.
2346 Optional argument FILENAME specifies file name.
2347 Directory to save to is default to `gnus-article-save-directory'."
2348 (setq filename (gnus-read-save-file-name
2349 "Save %s in rmail file:" filename
2350 gnus-rmail-save-name gnus-newsgroup-name
2351 gnus-current-headers 'gnus-newsgroup-last-rmail))
2352 (gnus-eval-in-buffer-window gnus-save-article-buffer
2356 (gnus-output-to-rmail filename))))
2359 (defun gnus-summary-save-in-mail (&optional filename)
2360 "Append this article to Unix mail file.
2361 Optional argument FILENAME specifies file name.
2362 Directory to save to is default to `gnus-article-save-directory'."
2363 (setq filename (gnus-read-save-file-name
2364 "Save %s in Unix mail file:" filename
2365 gnus-mail-save-name gnus-newsgroup-name
2366 gnus-current-headers 'gnus-newsgroup-last-mail))
2367 (gnus-eval-in-buffer-window gnus-save-article-buffer
2371 (if (and (file-readable-p filename)
2372 (mail-file-babyl-p filename))
2373 (rmail-output-to-rmail-file filename t)
2374 (gnus-output-to-mail filename)))))
2377 (defun gnus-summary-save-in-file (&optional filename overwrite)
2378 "Append this article to file.
2379 Optional argument FILENAME specifies file name.
2380 Directory to save to is default to `gnus-article-save-directory'."
2381 (setq filename (gnus-read-save-file-name
2382 "Save %s in file:" filename
2383 gnus-file-save-name gnus-newsgroup-name
2384 gnus-current-headers 'gnus-newsgroup-last-file))
2385 (gnus-eval-in-buffer-window gnus-save-article-buffer
2389 (when (and overwrite
2390 (file-exists-p filename))
2391 (delete-file filename))
2392 (gnus-output-to-file filename))))
2395 (defun gnus-summary-write-to-file (&optional filename)
2396 "Write this article to a file.
2397 Optional argument FILENAME specifies file name.
2398 The directory to save in defaults to `gnus-article-save-directory'."
2399 (gnus-summary-save-in-file nil t))
2401 (defun gnus-summary-save-body-in-file (&optional filename)
2402 "Append this article body to a file.
2403 Optional argument FILENAME specifies file name.
2404 The directory to save in defaults to `gnus-article-save-directory'."
2405 (setq filename (gnus-read-save-file-name
2406 "Save %s body in file:" filename
2407 gnus-file-save-name gnus-newsgroup-name
2408 gnus-current-headers 'gnus-newsgroup-last-file))
2409 (gnus-eval-in-buffer-window gnus-save-article-buffer
2413 (when (article-goto-body)
2414 (narrow-to-region (point) (point-max)))
2415 (gnus-output-to-file filename))))
2418 (defun gnus-summary-save-in-pipe (&optional command)
2419 "Pipe this article to subprocess."
2421 (cond ((and (eq command 'default)
2422 gnus-last-shell-command)
2423 gnus-last-shell-command)
2427 "Shell command on %s: "
2428 (if (and gnus-number-of-articles-to-be-saved
2429 (> gnus-number-of-articles-to-be-saved 1))
2430 (format "these %d articles"
2431 gnus-number-of-articles-to-be-saved)
2433 gnus-last-shell-command))))
2434 (when (string-equal command "")
2435 (setq command gnus-last-shell-command))
2436 (gnus-eval-in-buffer-window gnus-article-buffer
2439 (shell-command-on-region (point-min) (point-max) command nil)))
2440 (setq gnus-last-shell-command command))
2442 ;;; Article file names when saving.
2444 (defun gnus-capitalize-newsgroup (newsgroup)
2445 "Capitalize NEWSGROUP name."
2446 (when (not (zerop (length newsgroup)))
2447 (concat (char-to-string (upcase (aref newsgroup 0)))
2448 (substring newsgroup 1))))
2450 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2451 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2452 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2453 Otherwise, it is like ~/News/news/group/num."
2456 (concat (if (gnus-use-long-file-name 'not-save)
2457 (gnus-capitalize-newsgroup newsgroup)
2458 (gnus-newsgroup-directory-form newsgroup))
2459 "/" (int-to-string (mail-header-number headers)))
2460 gnus-article-save-directory)))
2462 (string-equal (file-name-directory default)
2463 (file-name-directory last-file))
2464 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2466 (or last-file default))))
2468 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2469 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2470 If variable `gnus-use-long-file-name' is non-nil, it is
2471 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2474 (concat (if (gnus-use-long-file-name 'not-save)
2476 (gnus-newsgroup-directory-form newsgroup))
2477 "/" (int-to-string (mail-header-number headers)))
2478 gnus-article-save-directory)))
2480 (string-equal (file-name-directory default)
2481 (file-name-directory last-file))
2482 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2484 (or last-file default))))
2486 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2487 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2488 If variable `gnus-use-long-file-name' is non-nil, it is
2489 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2492 (if (gnus-use-long-file-name 'not-save)
2493 (gnus-capitalize-newsgroup newsgroup)
2494 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2495 gnus-article-save-directory)))
2497 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2498 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2499 If variable `gnus-use-long-file-name' is non-nil, it is
2500 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2503 (if (gnus-use-long-file-name 'not-save)
2505 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2506 gnus-article-save-directory)))
2513 (setq afunc (car func)
2516 gfunc (intern (format "gnus-%s" func))))
2518 (if (not (fboundp afunc))
2520 `(lambda (&optional interactive &rest args)
2521 ,(documentation afunc t)
2522 (interactive (list t))
2524 (set-buffer gnus-article-buffer)
2526 (call-interactively ',afunc)
2527 (apply ',afunc args))))))))
2528 '(article-hide-headers
2529 article-hide-boring-headers
2530 article-toggle-headers
2531 article-treat-overstrike
2532 article-fill-long-lines
2533 article-capitalize-sentences
2535 article-display-x-face
2536 article-de-quoted-unreadable
2537 article-hide-list-identifiers
2539 article-strip-banner
2542 article-hide-signature
2543 article-strip-headers-in-body
2544 article-remove-trailing-blank-lines
2545 article-strip-leading-blank-lines
2546 article-strip-multiple-blank-lines
2547 article-strip-leading-space
2548 article-strip-trailing-space
2549 article-strip-blank-lines
2550 article-strip-all-blank-lines
2552 article-date-iso8601
2553 article-date-original
2555 article-decode-mime-words
2556 article-decode-charset
2557 article-decode-encoded-words
2561 article-treat-dumbquotes
2562 article-normalize-headers
2563 (article-show-all . gnus-article-show-all-headers))))
2566 ;;; Gnus article mode
2569 (put 'gnus-article-mode 'mode-class 'special)
2571 (gnus-define-keys gnus-article-mode-map
2572 " " gnus-article-goto-next-page
2573 "\177" gnus-article-goto-prev-page
2574 [delete] gnus-article-goto-prev-page
2575 [backspace] gnus-article-goto-prev-page
2576 "\C-c^" gnus-article-refer-article
2577 "h" gnus-article-show-summary
2578 "s" gnus-article-show-summary
2579 "\C-c\C-m" gnus-article-mail
2580 "?" gnus-article-describe-briefly
2581 gnus-mouse-2 gnus-article-push-button
2582 "\r" gnus-article-press-button
2583 "\t" gnus-article-next-button
2584 "\M-\t" gnus-article-prev-button
2585 "e" gnus-article-edit
2586 "<" beginning-of-buffer
2588 "\C-c\C-i" gnus-info-find-node
2591 "\C-d" gnus-article-read-summary-keys
2592 "\M-*" gnus-article-read-summary-keys
2593 "\M-#" gnus-article-read-summary-keys
2594 "\M-^" gnus-article-read-summary-keys
2595 "\M-g" gnus-article-read-summary-keys)
2597 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2600 (unless (lookup-key gnus-article-mode-map key)
2601 (define-key gnus-article-mode-map key
2602 'gnus-article-read-summary-keys)))
2607 (let ((key (car elt)))
2608 (and (> (length key) 0)
2609 (not (eq 'menu-bar (aref key 0)))
2610 (symbolp (lookup-key gnus-summary-mode-map key))
2612 (accessible-keymaps gnus-summary-mode-map))
2616 (push (char-to-string c) keys)
2620 (defun gnus-article-make-menu-bar ()
2621 (gnus-turn-off-edit-menu 'article)
2622 (unless (boundp 'gnus-article-article-menu)
2624 gnus-article-article-menu gnus-article-mode-map ""
2626 ["Scroll forwards" gnus-article-goto-next-page t]
2627 ["Scroll backwards" gnus-article-goto-prev-page t]
2628 ["Show summary" gnus-article-show-summary t]
2629 ["Fetch Message-ID at point" gnus-article-refer-article t]
2630 ["Mail to address at point" gnus-article-mail t]
2631 ["Send a bug report" gnus-bug t]))
2634 gnus-article-treatment-menu gnus-article-mode-map ""
2636 ["Hide headers" gnus-article-toggle-headers t]
2637 ["Hide signature" gnus-article-hide-signature t]
2638 ["Hide citation" gnus-article-hide-citation t]
2639 ["Treat overstrike" gnus-article-treat-overstrike t]
2640 ["Remove carriage return" gnus-article-remove-cr t]))
2642 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2644 (when (boundp 'gnus-summary-post-menu)
2645 (define-key gnus-article-mode-map [menu-bar post]
2646 (cons "Post" gnus-summary-post-menu)))
2648 (gnus-run-hooks 'gnus-article-menu-hook)))
2650 (defun gnus-article-mode ()
2651 "Major mode for displaying an article.
2653 All normal editing commands are switched off.
2655 The following commands are available in addition to all summary mode
2657 \\<gnus-article-mode-map>
2658 \\[gnus-article-next-page]\t Scroll the article one page forwards
2659 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2660 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2661 \\[gnus-article-show-summary]\t Display the summary buffer
2662 \\[gnus-article-mail]\t Send a reply to the address near point
2663 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2664 \\[gnus-info-find-node]\t Go to the Gnus info node"
2666 (when (gnus-visual-p 'article-menu 'menu)
2667 (gnus-article-make-menu-bar))
2668 (gnus-simplify-mode-line)
2669 (setq mode-name "Article")
2670 (setq major-mode 'gnus-article-mode)
2671 (make-local-variable 'minor-mode-alist)
2672 (unless (assq 'gnus-show-mime minor-mode-alist)
2673 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2674 (use-local-map gnus-article-mode-map)
2675 (gnus-update-format-specifications nil 'article-mode)
2676 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2677 (make-local-variable 'gnus-page-broken)
2678 (make-local-variable 'gnus-button-marker-list)
2679 (make-local-variable 'gnus-article-current-summary)
2680 (make-local-variable 'gnus-article-mime-handles)
2681 (make-local-variable 'gnus-article-decoded-p)
2682 (make-local-variable 'gnus-article-mime-handle-alist)
2683 (make-local-variable 'gnus-article-washed-types)
2684 (gnus-set-default-directory)
2685 (buffer-disable-undo)
2686 (setq buffer-read-only t)
2687 (set-syntax-table gnus-article-mode-syntax-table)
2688 (gnus-run-hooks 'gnus-article-mode-hook))
2690 (defun gnus-article-setup-buffer ()
2691 "Initialize the article buffer."
2692 (let* ((name (if gnus-single-article-buffer "*Article*"
2693 (concat "*Article " gnus-newsgroup-name "*")))
2695 (progn (string-match "\\*Article" name)
2696 (concat " *Original Article"
2697 (substring name (match-end 0))))))
2698 (setq gnus-article-buffer name)
2699 (setq gnus-original-article-buffer original)
2700 (setq gnus-article-mime-handle-alist nil)
2701 ;; This might be a variable local to the summary buffer.
2702 (unless gnus-single-article-buffer
2704 (set-buffer gnus-summary-buffer)
2705 (setq gnus-article-buffer name)
2706 (setq gnus-original-article-buffer original)
2707 (gnus-set-global-variables)))
2708 (gnus-article-setup-highlight-words)
2709 ;; Init original article buffer.
2711 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2712 (setq major-mode 'gnus-original-article-mode)
2713 (make-local-variable 'gnus-original-article))
2714 (if (get-buffer name)
2717 (kill-all-local-variables)
2718 (buffer-disable-undo)
2719 (setq buffer-read-only t)
2720 (unless (eq major-mode 'gnus-article-mode)
2721 (gnus-article-mode))
2724 (set-buffer (gnus-get-buffer-create name))
2726 (make-local-variable 'gnus-summary-buffer)
2727 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2728 (current-buffer)))))
2730 ;; Set article window start at LINE, where LINE is the number of lines
2731 ;; from the head of the article.
2732 (defun gnus-article-set-window-start (&optional line)
2734 (get-buffer-window gnus-article-buffer t)
2736 (set-buffer gnus-article-buffer)
2737 (goto-char (point-min))
2740 (gnus-message 6 "Moved to bookmark")
2741 (search-forward "\n\n" nil t)
2745 ;;; @@ article filters
2748 (defun gnus-article-display-mime-message ()
2749 "Article display method for MIME message."
2750 ;; called from `gnus-original-article-buffer'.
2751 (let (charset all-headers)
2752 (with-current-buffer gnus-summary-buffer
2753 (setq charset default-mime-charset
2754 all-headers gnus-have-all-headers))
2755 (make-local-variable 'default-mime-charset)
2756 (setq default-mime-charset charset)
2757 (with-current-buffer (get-buffer-create gnus-article-buffer)
2758 (make-local-variable 'default-mime-charset)
2759 (setq default-mime-charset charset))
2760 (mime-display-message mime-message-structure
2761 gnus-article-buffer nil gnus-article-mode-map)
2763 (gnus-article-hide-headers nil -1))
2765 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2766 (make-local-variable 'mime-button-mother-dispatcher)
2767 (setq mime-button-mother-dispatcher
2768 (function gnus-article-push-button))
2769 (run-hooks 'gnus-mime-article-prepare-hook))
2771 (defun gnus-article-display-traditional-message ()
2772 "Article display method for traditional message."
2773 (set-buffer gnus-article-buffer)
2774 (let (buffer-read-only)
2776 (insert-buffer-substring gnus-original-article-buffer)))
2778 (defun gnus-article-make-full-mail-header (&optional number charset)
2779 "Create a new mail header structure in a raw article buffer."
2780 (unless (and number charset)
2781 (save-current-buffer
2782 (set-buffer gnus-summary-buffer)
2784 (setq number (or (cdr gnus-article-current) 0)))
2786 (setq charset (or default-mime-charset 'x-ctext)))))
2787 (goto-char (point-min))
2788 (let ((header-end (if (search-forward "\n\n" nil t)
2790 (goto-char (point-max))))
2791 (chars (- (point-max) (point)))
2792 (lines (count-lines (point) (point-max)))
2793 (default-mime-charset charset)
2795 (narrow-to-region (point-min) header-end)
2796 (setq xref (std11-fetch-field "xref"))
2798 (make-full-mail-header
2800 (std11-fetch-field "subject")
2801 (std11-fetch-field "from")
2802 (std11-fetch-field "date")
2803 (std11-fetch-field "message-id")
2804 (std11-fetch-field "references")
2807 (when xref (concat "Xref: " xref)))
2810 (defun gnus-article-prepare (article &optional all-headers header)
2811 "Prepare ARTICLE in article mode buffer.
2812 ARTICLE should either be an article number or a Message-ID.
2813 If ARTICLE is an id, HEADER should be the article headers.
2814 If ALL-HEADERS is non-nil, no headers are hidden."
2816 ;; Make sure we start in a summary buffer.
2817 (unless (eq major-mode 'gnus-summary-mode)
2818 (set-buffer gnus-summary-buffer))
2819 (setq gnus-summary-buffer (current-buffer))
2820 (let* ((gnus-article (if header (mail-header-number header) article))
2821 (summary-buffer (current-buffer))
2822 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2823 (group gnus-newsgroup-name)
2826 (gnus-article-setup-buffer)
2827 (set-buffer gnus-original-article-buffer)
2828 ;; Deactivate active regions.
2829 (when (and (boundp 'transient-mark-mode)
2830 transient-mark-mode)
2831 (setq mark-active nil))
2832 (if (not (setq result (let ((buffer-read-only nil))
2833 (gnus-request-article-this-buffer
2835 ;; There is no such article.
2837 (when (and (numberp article)
2838 (not (memq article gnus-newsgroup-sparse)))
2839 (setq gnus-article-current
2840 (cons gnus-newsgroup-name article))
2841 (set-buffer gnus-summary-buffer)
2842 (setq gnus-current-article article)
2843 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2845 (gnus-summary-set-agent-mark article)
2846 (message "Message marked for downloading"))
2847 (gnus-summary-mark-article article gnus-canceled-mark)
2848 (unless (memq article gnus-newsgroup-sparse)
2850 "No such article (may have expired or been canceled)")))))
2851 (if (or (eq result 'pseudo)
2852 (eq result 'nneething))
2855 (set-buffer summary-buffer)
2856 (push article gnus-newsgroup-history)
2857 (setq gnus-last-article gnus-current-article
2858 gnus-current-article 0
2859 gnus-current-headers nil
2860 gnus-article-current nil)
2861 (if (eq result 'nneething)
2862 (gnus-configure-windows 'summary)
2863 (gnus-configure-windows 'article))
2864 (gnus-set-global-variables))
2865 (let ((gnus-article-mime-handle-alist-1
2866 gnus-article-mime-handle-alist))
2867 (gnus-set-mode-line 'article)))
2868 ;; The result from the `request' was an actual article -
2869 ;; or at least some text that is now displayed in the
2871 (when (and (numberp article)
2872 (not (eq article gnus-current-article)))
2873 ;; Seems like a new article has been selected.
2874 ;; `gnus-current-article' must be an article number.
2876 (set-buffer summary-buffer)
2877 (push article gnus-newsgroup-history)
2878 (setq gnus-last-article gnus-current-article
2879 gnus-current-article article
2880 gnus-current-headers
2881 (gnus-summary-article-header gnus-current-article)
2882 gnus-article-current
2883 (cons gnus-newsgroup-name gnus-current-article))
2884 (unless (vectorp gnus-current-headers)
2885 (setq gnus-current-headers nil))
2886 (gnus-summary-goto-subject gnus-current-article)
2887 (when (gnus-summary-show-thread)
2888 ;; If the summary buffer really was folded, the
2889 ;; previous goto may not actually have gone to
2890 ;; the right article, but the thread root instead.
2892 (gnus-summary-goto-subject gnus-current-article))
2893 (gnus-run-hooks 'gnus-mark-article-hook)
2894 (gnus-set-mode-line 'summary)
2895 (when (gnus-visual-p 'article-highlight 'highlight)
2896 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2897 ;; Set the global newsgroup variables here.
2898 (gnus-set-global-variables)
2899 (setq gnus-have-all-headers
2900 (or all-headers gnus-show-all-headers))))
2901 (when (or (numberp article)
2903 (gnus-article-prepare-display)
2905 (goto-char (point-min))
2906 (setq gnus-page-broken
2907 (when gnus-break-pages
2908 (gnus-narrow-to-page)
2910 (let ((gnus-article-mime-handle-alist-1
2911 gnus-article-mime-handle-alist))
2912 (gnus-set-mode-line 'article))
2914 (set-window-point (get-buffer-window (current-buffer)) (point))
2915 (gnus-configure-windows 'article)
2918 (defun gnus-article-prepare-mime-display (&optional number)
2919 (goto-char (point-min))
2920 (when (re-search-forward "^[^\t ]+:" nil t)
2921 (goto-char (match-beginning 0)))
2922 (let* ((entity (if (eq 1 (point-min))
2923 (get-text-property 1 'mime-view-entity)
2924 (get-text-property (point) 'mime-view-entity)))
2925 last-entity child-entity next type)
2926 (setq child-entity (mime-entity-children entity))
2928 (setq last-entity (nth (1- (length child-entity))
2930 (setq last-entity entity))
2932 (narrow-to-region (point)
2933 (if (search-forward "\n\n" nil t)
2936 (gnus-treat-article 'head)
2937 (put-text-property (point-min) (point-max) 'article-treated-header t)
2938 (goto-char (point-max)))
2939 (while (and (not (eobp))
2942 (or (next-single-property-change (point)
2945 (let ((types (mime-entity-content-type entity)))
2946 (while (eq 'multipart (mime-content-type-primary-type types))
2947 (setq entity (car (mime-entity-children entity))
2948 types (mime-entity-content-type entity)))
2950 (setq type (format "%s/%s"
2951 (mime-content-type-primary-type types)
2952 (mime-content-type-subtype types)))))
2953 (if (string-equal type "message/rfc822")
2956 (let ((children (mime-entity-children entity))
2959 (setq last-children (nth (1- (length children)) children))
2962 (not (eq last-children
2963 (get-text-property next 'mime-view-entity)))
2965 (next-single-property-change next
2966 'mime-view-entity))))))
2967 (setq next (or (next-single-property-change next 'mime-view-entity)
2970 (narrow-to-region (point) next)
2971 (gnus-article-prepare-mime-display)
2972 (goto-char (point-max)))
2973 (setq entity (get-text-property (point) 'mime-view-entity)))
2975 (narrow-to-region (point) next)
2976 ;; Kludge. We have to count true number, but for now,
2977 ;; part number is here only to achieve `last'.
2978 (gnus-treat-article nil 1
2979 (if (eq entity last-entity)
2982 (setq entity (get-text-property next 'mime-view-entity))
2983 (goto-char (point-max)))))))
2986 (defun gnus-article-prepare-display ()
2987 "Make the current buffer look like a nice article."
2988 (setq gnus-article-wash-types nil)
2989 (gnus-run-hooks 'gnus-tmp-internal-hook)
2990 (gnus-run-hooks 'gnus-article-prepare-hook)
2992 (let (mime-display-header-hook)
2993 (funcall (if gnus-show-mime
2995 (setq mime-message-structure gnus-current-headers)
2996 (mime-buffer-entity-set-buffer-internal
2997 mime-message-structure
2998 gnus-original-article-buffer)
2999 (mime-entity-set-representation-type-internal
3000 mime-message-structure 'mime-buffer-entity)
3001 (luna-send mime-message-structure
3002 'initialize-instance
3003 mime-message-structure)
3004 gnus-article-display-method-for-mime)
3005 gnus-article-display-method-for-traditional)))
3006 ;; Associate this article with the current summary buffer.
3007 (setq gnus-article-current-summary gnus-summary-buffer)
3008 ;; Call the treatment functions.
3009 (let ((inhibit-read-only t)
3014 (gnus-article-prepare-mime-display)
3015 (narrow-to-region (goto-char (point-min))
3016 (if (search-forward "\n\n" nil t)
3019 (gnus-treat-article 'head)
3020 (put-text-property (point-min) (point-max) 'article-treated-header t)
3021 (goto-char (point-max))
3023 (narrow-to-region (point) (point-max))
3024 (gnus-treat-article nil))
3025 (put-text-property (point-min) (point-max) 'read-only nil)))
3026 ;; Perform the article display hooks. Incidentally, this hook is
3027 ;; an obsolete variable by now.
3028 (gnus-run-hooks 'gnus-article-display-hook))
3030 (defun gnus-article-decode-article-as-default-mime-charset ()
3031 "Decode an article as `default-mime-charset'. It won't work if the
3032 value of the variable `gnus-show-mime' is non-nil."
3033 (unless gnus-show-mime
3034 (decode-mime-charset-region (point-min) (point-max)
3035 (with-current-buffer gnus-summary-buffer
3036 default-mime-charset))))
3039 ;;; Gnus MIME viewing functions
3042 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3043 "The following specs can be used:
3045 %T MIME type, along with additional info
3046 %n The `name' parameter
3047 %d The description, if any
3048 %l The length of the encoded part
3049 %p The part identifier number
3050 %e Dots if the part isn't displayed")
3052 (defvar gnus-mime-button-line-format-alist
3053 '((?t gnus-tmp-type ?s)
3054 (?T gnus-tmp-type-long ?s)
3055 (?n gnus-tmp-name ?s)
3056 (?d gnus-tmp-description ?s)
3058 (?l gnus-tmp-length ?d)
3059 (?e gnus-tmp-dots ?s)))
3061 (defvar gnus-mime-button-commands
3062 '((gnus-article-press-button "\r" "Toggle Display")
3063 (gnus-mime-view-part "v" "View Interactively...")
3064 (gnus-mime-view-part-as-type "t" "View As Type...")
3065 (gnus-mime-save-part "o" "Save...")
3066 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3067 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3068 (gnus-mime-internalize-part "E" "View Internally")
3069 (gnus-mime-externalize-part "e" "View Externally")
3070 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3072 (defun gnus-article-mime-part-status ()
3073 (with-current-buffer gnus-article-buffer
3074 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3075 (if (and entity (mime-entity-children entity))
3076 (format " (%d parts)" (length (mime-entity-children entity)))
3079 (defvar gnus-mime-button-map nil)
3080 (unless gnus-mime-button-map
3081 (setq gnus-mime-button-map (make-sparse-keymap))
3082 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3083 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3084 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3086 (define-key gnus-mime-button-map (cadr c) (car c)))
3087 gnus-mime-button-commands))
3089 (defun gnus-mime-button-menu (event)
3090 "Construct a context-sensitive menu of MIME commands."
3093 (let ((pos (event-start event)))
3094 (set-buffer (window-buffer (posn-window pos)))
3095 (goto-char (posn-point pos))
3096 (gnus-article-check-buffer)
3097 (let ((response (x-popup-menu
3099 ("" ,@(mapcar (lambda (c)
3100 (cons (caddr c) (car c)))
3101 gnus-mime-button-commands))))))
3103 (funcall response))))))
3105 (defun gnus-mime-view-all-parts (&optional handles)
3106 "View all the MIME parts."
3108 (save-current-buffer
3109 (set-buffer gnus-article-buffer)
3110 (let ((handles (or handles gnus-article-mime-handles))
3111 (mail-parse-charset gnus-newsgroup-charset)
3112 (mail-parse-ignored-charsets
3113 (save-excursion (set-buffer gnus-summary-buffer)
3114 gnus-newsgroup-ignored-charsets)))
3115 (if (stringp (car handles))
3116 (gnus-mime-view-all-parts (cdr handles))
3117 (mapcar 'mm-display-part handles)))))
3119 (defun gnus-mime-save-part ()
3120 "Save the MIME part under point."
3122 (gnus-article-check-buffer)
3123 (let ((data (get-text-property (point) 'gnus-data)))
3124 (mm-save-part data)))
3126 (defun gnus-mime-pipe-part ()
3127 "Pipe the MIME part under point to a process."
3129 (gnus-article-check-buffer)
3130 (let ((data (get-text-property (point) 'gnus-data)))
3131 (mm-pipe-part data)))
3133 (defun gnus-mime-view-part ()
3134 "Interactively choose a viewing method for the MIME part under point."
3136 (gnus-article-check-buffer)
3137 (let ((data (get-text-property (point) 'gnus-data)))
3138 (mm-interactively-view-part data)))
3140 (defun gnus-mime-view-part-as-type ()
3141 "Choose a MIME media type, and view the part as such."
3143 (list (completing-read "View as MIME type: " mailcap-mime-types)))
3144 (gnus-article-check-buffer)
3145 (let ((handle (get-text-property (point) 'gnus-data)))
3146 (gnus-mm-display-part handle)))
3148 (defun gnus-mime-copy-part (&optional handle)
3149 "Put the the MIME part under point into a new buffer."
3151 (gnus-article-check-buffer)
3152 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3153 (contents (mm-get-part handle))|
3154 (base (file-name-nondirectory
3156 (mail-content-type-get (mm-handle-type handle) 'name)
3157 (mail-content-type-get (mm-handle-type handle)
3160 (buffer (generate-new-buffer base)))
3161 (switch-to-buffer buffer)
3163 ;; We do it this way to make `normal-mode' set the appropriate mode.
3166 (setq buffer-file-name (expand-file-name base))
3168 (setq buffer-file-name nil))
3169 (goto-char (point-min))))
3171 (defun gnus-mime-inline-part (&optional handle)
3172 "Insert the MIME part under point into the current buffer."
3174 (gnus-article-check-buffer)
3175 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3179 (if (mm-handle-undisplayer handle)
3180 (mm-remove-part handle)
3181 (setq contents (mm-get-part handle))
3183 (mm-insert-inline handle contents)
3186 (defun gnus-mime-externalize-part (&optional handle)
3187 "View the MIME part under point with an external viewer."
3189 (gnus-article-check-buffer)
3190 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3191 (mm-user-display-methods nil)
3192 (mm-inline-large-images nil)
3193 (mail-parse-charset gnus-newsgroup-charset)
3194 (mail-parse-ignored-charsets
3195 (save-excursion (set-buffer gnus-summary-buffer)
3196 gnus-newsgroup-ignored-charsets)))
3197 (if (mm-handle-undisplayer handle)
3198 (mm-remove-part handle)
3199 (mm-display-part handle))))
3201 (defun gnus-mime-internalize-part (&optional handle)
3202 "View the MIME part under point with an internal viewer."
3204 (gnus-article-check-buffer)
3205 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3206 (mm-user-display-methods '((".*" . inline)))
3207 (mm-inline-large-images t)
3208 (mail-parse-charset gnus-newsgroup-charset)
3209 (mail-parse-ignored-charsets
3210 (save-excursion (set-buffer gnus-summary-buffer)
3211 gnus-newsgroup-ignored-charsets)))
3212 (if (mm-handle-undisplayer handle)
3213 (mm-remove-part handle)
3214 (mm-display-part handle))))
3216 (defun gnus-article-part-wrapper (n function)
3217 (save-current-buffer
3218 (set-buffer gnus-article-buffer)
3219 (when (> n (length gnus-article-mime-handle-alist))
3220 (error "No such part"))
3221 (gnus-article-goto-part n)
3222 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3223 (funcall function handle))))
3225 (defun gnus-article-pipe-part (n)
3226 "Pipe MIME part N, which is the numerical prefix."
3228 (gnus-article-part-wrapper n 'mm-pipe-part))
3230 (defun gnus-article-save-part (n)
3231 "Save MIME part N, which is the numerical prefix."
3233 (gnus-article-part-wrapper n 'mm-save-part))
3235 (defun gnus-article-interactively-view-part (n)
3236 "View MIME part N interactively, which is the numerical prefix."
3238 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3240 (defun gnus-article-copy-part (n)
3241 "Copy MIME part N, which is the numerical prefix."
3243 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3245 (defun gnus-article-externalize-part (n)
3246 "View MIME part N externally, which is the numerical prefix."
3248 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3250 (defun gnus-article-inline-part (n)
3251 "Inline MIME part N, which is the numerical prefix."
3253 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3255 (defun gnus-article-view-part (n)
3256 "View MIME part N, which is the numerical prefix."
3258 (save-current-buffer
3259 (set-buffer gnus-article-buffer)
3260 (when (> n (length gnus-article-mime-handle-alist))
3261 (error "No such part"))
3262 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3263 (when (gnus-article-goto-part n)
3264 (if (equal (car handle) "multipart/alternative")
3265 (gnus-article-press-button)
3266 (when (eq (gnus-mm-display-part handle) 'internal)
3267 (gnus-set-window-start)))))))
3269 (defun gnus-mm-display-part (handle)
3270 "Display HANDLE and fix MIME button."
3271 (let ((id (get-text-property (point) 'gnus-part))
3276 (let ((window (selected-window))
3277 (mail-parse-charset gnus-newsgroup-charset)
3278 (mail-parse-ignored-charsets
3279 (save-excursion (set-buffer gnus-summary-buffer)
3280 gnus-newsgroup-ignored-charsets)))
3283 (let ((win (get-buffer-window (current-buffer) t))
3286 (select-window win))
3289 (if (mm-handle-displayed-p handle)
3290 ;; This will remove the part.
3291 (mm-display-part handle)
3293 (narrow-to-region (point) (1+ (point)))
3294 (mm-display-part handle)
3295 ;; We narrow to the part itself and
3296 ;; then call the treatment functions.
3297 (goto-char (point-min))
3299 (narrow-to-region (point) (point-max))
3302 (1- (length gnus-article-mime-handles))
3303 (mm-handle-media-type handle)))))
3304 (select-window window))))
3306 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3307 (gnus-insert-mime-button
3308 handle id (list (mm-handle-displayed-p handle)))
3309 (goto-char point))))
3311 (defun gnus-article-goto-part (n)
3312 "Go to MIME part N."
3313 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3315 (goto-char point))))
3317 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3318 (let ((gnus-tmp-name
3319 (or (mail-content-type-get (mm-handle-type handle)
3321 (mail-content-type-get (mm-handle-disposition handle)
3324 (gnus-tmp-type (mm-handle-media-type handle))
3325 (gnus-tmp-description
3326 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3329 (if (if displayed (car displayed)
3330 (mm-handle-displayed-p handle))
3332 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3334 gnus-tmp-type-long b e)
3335 (when (string-match ".*/" gnus-tmp-name)
3336 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3337 (setq gnus-tmp-type-long (concat gnus-tmp-type
3338 (and (not (equal gnus-tmp-name ""))
3339 (concat "; " gnus-tmp-name))))
3340 (or (equal gnus-tmp-description "")
3341 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3346 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3347 `(local-map ,gnus-mime-button-map
3348 keymap ,gnus-mime-button-map
3349 gnus-callback gnus-mm-display-part
3350 gnus-part ,gnus-tmp-id
3351 article-type annotation
3354 (widget-convert-button 'link b e
3356 :action 'gnus-widget-press-button
3357 :button-keymap gnus-mime-button-map
3360 ;; Needed to properly clear the message
3361 ;; due to a bug in wid-edit
3362 (setq help-echo-owns-message t)
3364 "Click to %s the MIME part; %s for more options"
3365 (if (mm-handle-displayed-p
3366 (widget-get widget :mime-handle))
3368 (if gnus-xemacs "button3" "mouse-3"))))))
3370 (defun gnus-widget-press-button (elems el)
3371 (goto-char (widget-get elems :from))
3372 (gnus-article-press-button))
3374 (defvar gnus-displaying-mime nil)
3376 (defun gnus-display-mime (&optional ihandles)
3377 "Display the MIME parts."
3379 (save-selected-window
3380 (let ((window (get-buffer-window gnus-article-buffer))
3383 (select-window window)
3384 ;; We have to do this since selecting the window
3385 ;; may change the point. So we set the window point.
3386 (set-window-point window point)))
3387 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3388 buffer-read-only handle name type b e display)
3389 (when (and (not ihandles)
3390 (not gnus-displaying-mime))
3391 ;; Top-level call; we clean up.
3392 (when gnus-article-mime-handles
3393 (mm-destroy-parts gnus-article-mime-handles)
3394 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3395 (setq gnus-article-mime-handles handles)
3396 ;; We allow users to glean info from the handles.
3397 (when gnus-article-mime-part-function
3398 (gnus-mime-part-function handles)))
3400 (or (not (stringp (car handles)))
3403 (when (and (not ihandles)
3404 (not gnus-displaying-mime))
3405 ;; Clean up for mime parts.
3407 (delete-region (point) (point-max)))
3408 (let ((gnus-displaying-mime t))
3409 (gnus-mime-display-part handles)))
3412 (narrow-to-region (point) (point-max))
3413 (gnus-treat-article nil 1 1)
3416 ;; Highlight the headers.
3420 (narrow-to-region (point-min) (point))
3421 (gnus-treat-article 'head))))))))
3423 (defvar gnus-mime-display-multipart-as-mixed nil)
3425 (defun gnus-mime-display-part (handle)
3428 ((not (stringp (car handle)))
3429 (gnus-mime-display-single handle))
3430 ;; User-defined multipart
3431 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3432 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3434 ;; multipart/alternative
3435 ((and (equal (car handle) "multipart/alternative")
3436 (not gnus-mime-display-multipart-as-mixed))
3437 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3438 (push (cons id handle) gnus-article-mime-handle-alist)
3439 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3440 ;; multipart/related
3441 ((and (equal (car handle) "multipart/related")
3442 (not gnus-mime-display-multipart-as-mixed))
3443 ;;;!!!We should find the start part, but we just default
3444 ;;;!!!to the first part.
3445 (gnus-mime-display-part (cadr handle)))
3446 ;; Other multiparts are handled like multipart/mixed.
3448 (gnus-mime-display-mixed (cdr handle)))))
3450 (defun gnus-mime-part-function (handles)
3451 (if (stringp (car handles))
3452 (mapcar 'gnus-mime-part-function (cdr handles))
3453 (funcall gnus-article-mime-part-function handles)))
3455 (defun gnus-mime-display-mixed (handles)
3456 (mapcar 'gnus-mime-display-part handles))
3458 (defun gnus-mime-display-single (handle)
3459 (let ((type (mm-handle-media-type handle))
3460 (ignored gnus-ignored-mime-types)
3467 (when (string-match (pop ignored) type)
3468 (throw 'ignored nil)))
3469 (if (and (setq not-attachment
3470 (or (not (mm-handle-disposition handle))
3471 (equal (car (mm-handle-disposition handle))
3473 (mm-attachment-override-p handle)))
3474 (mm-automatic-display-p handle)
3475 (or (mm-inlined-p handle)
3476 (mm-automatic-external-display-p type)))
3478 (when (equal (mm-handle-media-supertype handle) "text")
3480 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3481 (push (cons id handle) gnus-article-mime-handle-alist)
3482 (when (or (not display)
3483 (not (gnus-unbuttonized-mime-type-p type)))
3484 (gnus-article-insert-newline)
3485 (gnus-insert-mime-button
3486 handle id (list (or display (and not-attachment text))))
3487 (gnus-article-insert-newline)
3488 (gnus-article-insert-newline)
3490 (let ((beg (point)))
3496 (let ((mail-parse-charset gnus-newsgroup-charset)
3497 (mail-parse-ignored-charsets
3498 (save-excursion (set-buffer gnus-summary-buffer)
3499 gnus-newsgroup-ignored-charsets)))
3500 (mm-display-part handle t))
3501 (goto-char (point-max)))
3502 ((and text not-attachment)
3506 (gnus-article-insert-newline)
3507 (mm-insert-inline handle (mm-get-part handle))
3508 (goto-char (point-max))))
3512 (narrow-to-region beg (point))
3514 nil (length gnus-article-mime-handle-alist)
3515 (1- (length gnus-article-mime-handles))
3516 (mm-handle-media-type handle)))))))))
3518 (defun gnus-unbuttonized-mime-type-p (type)
3519 "Say whether TYPE is to be unbuttonized."
3520 (unless gnus-inhibit-mime-unbuttonizing
3522 (let ((types gnus-unbuttonized-mime-types))
3524 (when (string-match (pop types) type)
3525 (throw 'found t)))))))
3527 (defun gnus-article-insert-newline ()
3528 "Insert a newline, but mark it as undeletable."
3529 (gnus-put-text-property
3530 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3532 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3533 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3536 handle buffer-read-only from props begend not-pref)
3537 (save-window-excursion
3540 (narrow-to-region (car ibegend)
3543 (goto-char (car ibegend))
3546 (delete-region (point-min) (point-max))
3547 (mm-remove-parts handles))
3548 (setq begend (list (point-marker)))
3550 (unless (setq not-pref (cadr (member preferred ihandles)))
3551 (setq not-pref (car ihandles)))
3553 (not (gnus-unbuttonized-mime-type-p
3554 "multipart/alternative")))
3555 (gnus-add-text-properties
3558 (insert (format "%d. " id))
3562 (unless ,(not ibegend)
3563 (setq gnus-article-mime-handle-alist
3564 ',gnus-article-mime-handle-alist))
3565 (gnus-mime-display-alternative
3566 ',ihandles ',not-pref ',begend ,id))
3567 local-map ,gnus-mime-button-map
3568 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3569 face ,gnus-article-button-face
3570 keymap ,gnus-mime-button-map
3573 (widget-convert-button 'link from (point)
3574 :action 'gnus-widget-press-button
3575 :button-keymap gnus-widget-button-keymap)
3577 (while (setq handle (pop handles))
3578 (gnus-add-text-properties
3581 (insert (format "(%c) %-18s"
3582 (if (equal handle preferred) ?* ? )
3583 (mm-handle-media-type handle)))
3587 (unless ,(not ibegend)
3588 (setq gnus-article-mime-handle-alist
3589 ',gnus-article-mime-handle-alist))
3590 (gnus-mime-display-alternative
3591 ',ihandles ',handle ',begend ,id))
3592 local-map ,gnus-mime-button-map
3593 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3594 face ,gnus-article-button-face
3595 keymap ,gnus-mime-button-map
3598 (widget-convert-button 'link from (point)
3599 :action 'gnus-widget-press-button
3600 :button-keymap gnus-widget-button-keymap)
3604 (if (stringp (car preferred))
3605 (gnus-display-mime preferred)
3606 (let ((mail-parse-charset gnus-newsgroup-charset)
3607 (mail-parse-ignored-charsets
3608 (save-excursion (set-buffer gnus-summary-buffer)
3609 gnus-newsgroup-ignored-charsets)))
3610 (mm-display-part preferred)
3614 (narrow-to-region (car begend) (point-max))
3616 nil (length gnus-article-mime-handle-alist)
3617 (1- (length gnus-article-mime-handles))
3618 (mm-handle-media-type handle))))))
3619 (goto-char (point-max))
3620 (setcdr begend (point-marker)))))
3622 (goto-char point))))
3624 (defun gnus-article-wash-status ()
3625 "Return a string which display status of article washing."
3627 (set-buffer gnus-article-buffer)
3628 (let ((cite (gnus-article-hidden-text-p 'cite))
3629 (headers (gnus-article-hidden-text-p 'headers))
3630 (boring (gnus-article-hidden-text-p 'boring-headers))
3631 (pgp (gnus-article-hidden-text-p 'pgp))
3632 (pem (gnus-article-hidden-text-p 'pem))
3633 (signature (gnus-article-hidden-text-p 'signature))
3634 (overstrike (gnus-article-hidden-text-p 'overstrike))
3635 (emphasis (gnus-article-hidden-text-p 'emphasis))
3636 (mime gnus-show-mime))
3637 (format "%c%c%c%c%c%c%c"
3639 (if (or headers boring) ?h ? )
3640 (if (or pgp pem) ?p ? )
3641 (if signature ?s ? )
3642 (if overstrike ?o ? )
3644 (if emphasis ?e ? )))))
3646 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3648 (defun gnus-article-maybe-hide-headers ()
3649 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3650 Provided for backwards compatibility."
3651 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3652 (not (save-excursion (set-buffer gnus-summary-buffer)
3653 gnus-have-all-headers)))
3654 (not gnus-inhibit-hiding))
3655 (gnus-article-hide-headers)))
3659 (defun gnus-output-to-file (file-name)
3660 "Append the current article to a file named FILE-NAME."
3661 (let ((artbuf (current-buffer)))
3663 (insert-buffer-substring artbuf)
3664 ;; Append newline at end of the buffer as separator, and then
3666 (goto-char (point-max))
3668 (write-region-as-binary (point-min) (point-max) file-name 'append)
3671 (defun gnus-narrow-to-page (&optional arg)
3672 "Narrow the article buffer to a page.
3673 If given a numerical ARG, move forward ARG pages."
3675 (setq arg (if arg (prefix-numeric-value arg) 0))
3677 (set-buffer gnus-article-buffer)
3678 (goto-char (point-min))
3680 ;; Remove any old next/prev buttons.
3681 (when (gnus-visual-p 'page-marker)
3682 (let ((buffer-read-only nil))
3683 (gnus-remove-text-with-property 'gnus-prev)
3684 (gnus-remove-text-with-property 'gnus-next)))
3687 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3689 (re-search-forward page-delimiter nil 'move arg)))
3690 (goto-char (match-end 0)))
3693 (if (re-search-forward page-delimiter nil 'move)
3696 (when (and (gnus-visual-p 'page-marker)
3697 (not (= (point-min) 1)))
3699 (goto-char (point-min))
3700 (gnus-insert-prev-page-button)))
3701 (when (and (gnus-visual-p 'page-marker)
3702 (< (+ (point-max) 2) (buffer-size)))
3704 (goto-char (point-max))
3705 (gnus-insert-next-page-button)))))
3707 ;; Article mode commands
3709 (defun gnus-article-goto-next-page ()
3710 "Show the next page of the article."
3712 (when (gnus-article-next-page)
3713 (goto-char (point-min))
3714 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3716 (defun gnus-article-goto-prev-page ()
3717 "Show the next page of the article."
3719 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3720 (gnus-article-prev-page nil)))
3722 (defun gnus-article-next-page (&optional lines)
3723 "Show the next page of the current article.
3724 If end of article, return non-nil. Otherwise return nil.
3725 Argument LINES specifies lines to be scrolled up."
3727 (let ((start (window-start))
3728 end-of-buffer end-of-page)
3730 (move-to-window-line -1)
3731 (if (<= (point) start)
3734 (setq start (point)))
3737 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3738 (setq end-of-buffer t))
3740 (setq end-of-page t)))
3742 (move-to-window-line lines)
3743 (unless (search-backward "\n\n" nil t)
3744 (setq start (point)))))
3745 (cond (end-of-buffer t)
3747 (gnus-narrow-to-page 1)
3751 (set-window-start (selected-window) start)
3755 (defun gnus-article-prev-page (&optional lines)
3756 "Show previous page of current article.
3757 Argument LINES specifies lines to be scrolled down."
3759 (let (beginning-of-buffer beginning-of-page)
3761 (move-to-window-line 0)
3762 (cond ((eq 1 (point))
3763 (setq beginning-of-buffer t))
3765 (setq beginning-of-page t))))
3766 (cond (beginning-of-buffer)
3768 (gnus-narrow-to-page -1))
3772 (beginning-of-buffer
3773 (goto-char (point-min))))))))
3775 (defun gnus-article-refer-article ()
3776 "Read article specified by message-id around point."
3778 (let ((point (point)))
3779 (search-forward ">" nil t) ;Move point to end of "<....>".
3780 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3781 (let ((message-id (match-string 1)))
3783 (set-buffer gnus-summary-buffer)
3784 (gnus-summary-refer-article message-id))
3786 (error "No references around point"))))
3788 (defun gnus-article-show-summary ()
3789 "Reconfigure windows to show summary buffer."
3791 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3792 (error "There is no summary buffer for this article buffer")
3793 (gnus-article-set-globals)
3794 (gnus-configure-windows 'article)
3795 (gnus-summary-goto-subject gnus-current-article)
3796 (gnus-summary-position-point)))
3798 (defun gnus-article-describe-briefly ()
3799 "Describe article mode commands briefly."
3801 (gnus-message 6 (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")))
3803 (defun gnus-article-summary-command ()
3804 "Execute the last keystroke in the summary buffer."
3806 (let ((obuf (current-buffer))
3807 (owin (current-window-configuration))
3809 (switch-to-buffer gnus-article-current-summary 'norecord)
3810 (setq func (lookup-key (current-local-map) (this-command-keys)))
3811 (call-interactively func)
3813 (set-window-configuration owin)
3814 (set-window-point (get-buffer-window (current-buffer)) (point))))
3816 (defun gnus-article-summary-command-nosave ()
3817 "Execute the last keystroke in the summary buffer."
3820 (pop-to-buffer gnus-article-current-summary 'norecord)
3821 (setq func (lookup-key (current-local-map) (this-command-keys)))
3822 (call-interactively func)))
3824 (defun gnus-article-check-buffer ()
3825 "Beep if not in an article buffer."
3826 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3827 (error "Command invoked outside of a Gnus article buffer")))
3829 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3830 "Read a summary buffer key sequence and execute it from the article buffer."
3832 (gnus-article-check-buffer)
3834 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3835 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3836 "=" "^" "\M-^" "|"))
3842 '("n" "Gn" "p" "Gp"))
3845 (set-buffer gnus-article-current-summary)
3846 (let (gnus-pick-mode)
3847 (push (or key last-command-event) unread-command-events)
3848 (setq keys (static-if (featurep 'xemacs)
3849 (events-to-keys (read-key-sequence nil))
3850 (read-key-sequence nil)))))
3853 (if (or (member keys nosaves)
3854 (member keys nosave-but-article)
3855 (member keys nosave-in-article))
3857 (save-window-excursion
3858 (pop-to-buffer gnus-article-current-summary 'norecord)
3859 ;; We disable the pick minor mode commands.
3860 (let (gnus-pick-mode)
3861 (setq func (lookup-key (current-local-map) keys))))
3864 (unless (member keys nosave-in-article)
3865 (set-buffer gnus-article-current-summary))
3866 (call-interactively func)
3867 (setq new-sum-point (point)))
3868 (when (member keys nosave-but-article)
3869 (pop-to-buffer gnus-article-buffer 'norecord)))
3870 ;; These commands should restore window configuration.
3871 (let ((obuf (current-buffer))
3872 (owin (current-window-configuration))
3874 (summary gnus-article-current-summary)
3875 func in-buffer selected)
3876 (if not-restore-window
3877 (pop-to-buffer summary 'norecord)
3878 (switch-to-buffer summary 'norecord))
3879 (setq in-buffer (current-buffer))
3880 ;; We disable the pick minor mode commands.
3881 (if (setq func (let (gnus-pick-mode)
3882 (lookup-key (current-local-map) keys)))
3884 (call-interactively func)
3885 (setq new-sum-point (point)))
3887 (when (eq in-buffer (current-buffer))
3888 (setq selected (gnus-summary-select-article))
3890 (unless not-restore-window
3891 (set-window-configuration owin))
3892 (when (eq selected 'old)
3894 (set-window-start (get-buffer-window (current-buffer))
3896 (set-window-point (get-buffer-window (current-buffer))
3898 (let ((win (get-buffer-window gnus-article-current-summary)))
3900 (set-window-point win new-sum-point))))))))
3902 (defun gnus-article-hide (&optional arg force)
3903 "Hide all the gruft in the current article.
3904 This means that PGP stuff, signatures, cited text and (some)
3905 headers will be hidden.
3906 If given a prefix, show the hidden text instead."
3907 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3908 (gnus-article-hide-headers arg)
3909 (gnus-article-hide-list-identifiers arg)
3910 (gnus-article-hide-pgp arg)
3911 (gnus-article-hide-citation-maybe arg force)
3912 (gnus-article-hide-signature arg))
3914 (defun gnus-article-maybe-highlight ()
3915 "Do some article highlighting if article highlighting is requested."
3916 (when (gnus-visual-p 'article-highlight 'highlight)
3917 (gnus-article-highlight-some)))
3919 (defun gnus-check-group-server ()
3920 ;; Make sure the connection to the server is alive.
3921 (unless (gnus-server-opened
3922 (gnus-find-method-for-group gnus-newsgroup-name))
3923 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3924 (gnus-request-group gnus-newsgroup-name t)))
3926 (defun gnus-request-article-this-buffer (article group)
3927 "Get an article and insert it into this buffer."
3928 (let (do-update-line sparse-header)
3932 (gnus-kill-all-overlays)
3933 (setq group (or group gnus-newsgroup-name))
3935 ;; Using `gnus-request-article' directly will insert the article into
3936 ;; `nntp-server-buffer' - so we'll save some time by not having to
3937 ;; copy it from the server buffer into the article buffer.
3939 ;; We only request an article by message-id when we do not have the
3940 ;; headers for it, so we'll have to get those.
3941 (when (stringp article)
3942 (let ((gnus-override-method gnus-refer-article-method))
3943 (gnus-read-header article)))
3945 ;; If the article number is negative, that means that this article
3946 ;; doesn't belong in this newsgroup (possibly), so we find its
3947 ;; message-id and request it by id instead of number.
3948 (when (and (numberp article)
3950 (get-buffer gnus-summary-buffer)
3951 (gnus-buffer-exists-p gnus-summary-buffer))
3953 (set-buffer gnus-summary-buffer)
3954 (let ((header (gnus-summary-article-header article)))
3957 ((memq article gnus-newsgroup-sparse)
3958 ;; This is a sparse gap article.
3959 (setq do-update-line article)
3960 (setq article (mail-header-id header))
3961 (let ((gnus-override-method gnus-refer-article-method))
3962 (setq sparse-header (gnus-read-header article)))
3963 (setq gnus-newsgroup-sparse
3964 (delq article gnus-newsgroup-sparse)))
3966 ;; It's a real article.
3967 (setq article (mail-header-id header)))
3969 ;; It is an extracted pseudo-article.
3970 (setq article 'pseudo)
3971 (gnus-request-pseudo-article header))))
3973 (let ((method (gnus-find-method-for-group
3974 gnus-newsgroup-name)))
3975 (when (and (eq (car method) 'nneething)
3978 (file-name-as-directory
3979 (or (cadr (assq 'nneething-address method))
3981 (mail-header-subject header))))
3982 (when (file-directory-p dir)
3983 (setq article 'nneething)
3984 (gnus-group-enter-directory dir))))))))
3987 ;; Refuse to select canceled articles.
3988 ((and (numberp article)
3990 (get-buffer gnus-summary-buffer)
3991 (gnus-buffer-exists-p gnus-summary-buffer)
3992 (eq (cdr (save-excursion
3993 (set-buffer gnus-summary-buffer)
3994 (assq article gnus-newsgroup-reads)))
3995 gnus-canceled-mark))
3997 ;; Check the backlog.
3998 ((and gnus-keep-backlog
3999 (gnus-backlog-request-article group article (current-buffer)))
4001 ;; Check asynchronous pre-fetch.
4002 ((gnus-async-request-fetched-article group article (current-buffer))
4003 (gnus-async-prefetch-next group article gnus-summary-buffer)
4004 (when (and (numberp article) gnus-keep-backlog)
4005 (gnus-backlog-enter-article group article (current-buffer)))
4008 ((and gnus-use-cache
4010 (gnus-cache-request-article article group))
4012 ;; Get the article and put into the article buffer.
4013 ((or (stringp article) (numberp article))
4014 (let ((gnus-override-method
4015 (and (stringp article) gnus-refer-article-method))
4016 (buffer-read-only nil))
4018 (gnus-kill-all-overlays)
4019 (gnus-check-group-server)
4020 (when (gnus-request-article article group (current-buffer))
4021 (when (numberp article)
4022 (gnus-async-prefetch-next group article gnus-summary-buffer)
4023 (when gnus-keep-backlog
4024 (gnus-backlog-enter-article
4025 group article (current-buffer))))
4030 ;; Associate this article with the current summary buffer.
4031 (setq gnus-article-current-summary gnus-summary-buffer)
4033 ;; Take the article from the original article buffer
4034 ;; and place it in the buffer it's supposed to be in.
4035 (when (and (get-buffer gnus-article-buffer)
4036 (equal (buffer-name (current-buffer))
4037 (buffer-name (get-buffer gnus-article-buffer))))
4039 (if (get-buffer gnus-original-article-buffer)
4040 (set-buffer gnus-original-article-buffer)
4041 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4042 (buffer-disable-undo)
4043 (setq major-mode 'gnus-original-article-mode)
4044 (setq buffer-read-only t))
4045 (let (buffer-read-only)
4047 (insert-buffer-substring gnus-article-buffer))
4048 (setq gnus-original-article (cons group article)))
4051 (run-hooks 'gnus-article-decode-hook)
4052 ;; Mark article as decoded or not.
4053 (setq gnus-article-decoded-p gnus-article-decode-hook))
4055 ;; Update sparse articles.
4056 (when (and do-update-line
4057 (or (numberp article)
4059 (let ((buf (current-buffer)))
4060 (set-buffer gnus-summary-buffer)
4061 (gnus-summary-update-article do-update-line sparse-header)
4062 (gnus-summary-goto-subject do-update-line nil t)
4063 (set-window-point (get-buffer-window (current-buffer) t)
4065 (set-buffer buf))))))
4071 (defcustom gnus-article-edit-mode-hook nil
4072 "Hook run in article edit mode buffers."
4073 :group 'gnus-article-various
4076 (defcustom gnus-article-edit-article-setup-function
4077 'gnus-article-mime-edit-article-setup
4078 "Function called to setup an editing article buffer."
4079 :group 'gnus-article-various
4082 (defvar gnus-article-edit-done-function nil)
4084 (defvar gnus-article-edit-mode-map nil)
4086 ;; Should we be using derived.el for this?
4087 (unless gnus-article-edit-mode-map
4088 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4089 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4091 (gnus-define-keys gnus-article-edit-mode-map
4092 "\C-c\C-c" gnus-article-edit-done
4093 "\C-c\C-k" gnus-article-edit-exit)
4095 (gnus-define-keys (gnus-article-edit-wash-map
4096 "\C-c\C-w" gnus-article-edit-mode-map)
4097 "f" gnus-article-edit-full-stops))
4099 (defun gnus-article-edit-mode ()
4100 "Major mode for editing articles.
4101 This is an extended text-mode.
4103 \\{gnus-article-edit-mode-map}"
4105 (setq major-mode 'gnus-article-edit-mode)
4106 (setq mode-name "Article Edit")
4107 (use-local-map gnus-article-edit-mode-map)
4108 (make-local-variable 'gnus-article-edit-done-function)
4109 (make-local-variable 'gnus-prev-winconf)
4110 (setq buffer-read-only nil)
4111 (buffer-enable-undo)
4113 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4115 (defun gnus-article-edit (&optional force)
4116 "Edit the current article.
4117 This will have permanent effect only in mail groups.
4118 If FORCE is non-nil, allow editing of articles even in read-only
4121 (when (and (not force)
4122 (gnus-group-read-only-p))
4123 (error "The current newsgroup does not support article editing"))
4124 (gnus-article-date-original)
4125 (gnus-article-edit-article
4127 `(lambda (no-highlight)
4129 (gnus-summary-edit-article-done
4130 ,(or (mail-header-references gnus-current-headers) "")
4131 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4133 (defun gnus-article-edit-article (start-func exit-func)
4134 "Start editing the contents of the current article buffer."
4135 (let ((winconf (current-window-configuration)))
4136 (set-buffer gnus-article-buffer)
4137 (gnus-article-edit-mode)
4138 (funcall start-func)
4139 (gnus-configure-windows 'edit-article)
4140 (setq gnus-article-edit-done-function exit-func)
4141 (setq gnus-prev-winconf winconf)
4142 (when gnus-article-edit-article-setup-function
4143 (funcall gnus-article-edit-article-setup-function))
4144 (gnus-message 6 "C-c C-c to end edits")))
4146 (defun gnus-article-edit-done (&optional arg)
4147 "Update the article edits and exit."
4152 (when (article-goto-body)
4153 (let ((lines (count-lines (point) (point-max)))
4154 (length (- (point-max) (point)))
4155 (case-fold-search t)
4156 (body (copy-marker (point))))
4157 (goto-char (point-min))
4158 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4159 (delete-region (match-beginning 1) (match-end 1))
4160 (insert (number-to-string length)))
4161 (goto-char (point-min))
4162 (when (re-search-forward
4163 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4164 (delete-region (match-beginning 1) (match-end 1))
4165 (insert (number-to-string length)))
4166 (goto-char (point-min))
4167 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4168 (delete-region (match-beginning 1) (match-end 1))
4169 (insert (number-to-string lines)))))))
4170 (let ((func gnus-article-edit-done-function)
4171 (buf (current-buffer))
4172 (start (window-start)))
4173 (remove-hook 'gnus-article-mode-hook
4174 'gnus-article-mime-edit-article-unwind)
4175 (gnus-article-edit-exit)
4178 (let ((buffer-read-only nil))
4180 ;; The cache and backlog have to be flushed somewhat.
4181 (when gnus-keep-backlog
4182 (gnus-backlog-remove-article
4183 (car gnus-article-current) (cdr gnus-article-current)))
4184 ;; Flush original article as well.
4186 (when (get-buffer gnus-original-article-buffer)
4187 (set-buffer gnus-original-article-buffer)
4188 (setq gnus-original-article nil)))
4189 (when gnus-use-cache
4190 (gnus-cache-update-article
4191 (car gnus-article-current) (cdr gnus-article-current))))
4193 (set-window-start (get-buffer-window buf) start)
4194 (set-window-point (get-buffer-window buf) (point))))
4196 (defun gnus-article-edit-exit ()
4197 "Exit the article editing without updating."
4199 ;; We remove all text props from the article buffer.
4200 (let ((buf (format "%s" (buffer-string)))
4201 (curbuf (current-buffer))
4203 (window-start (window-start)))
4206 (let ((winconf gnus-prev-winconf))
4208 (set-window-configuration winconf)
4209 ;; Tippy-toe some to make sure that point remains where it was.
4210 (save-current-buffer
4212 (set-window-start (get-buffer-window (current-buffer)) window-start)
4215 (defun gnus-article-edit-full-stops ()
4216 "Interactively repair spacing at end of sentences."
4219 (goto-char (point-min))
4220 (search-forward-regexp "^$" nil t)
4221 (let ((case-fold-search nil))
4222 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4225 ;;; Article editing with MIME-Edit
4228 (defcustom gnus-article-mime-edit-article-setup-hook nil
4229 "Hook run after setting up a MIME editing article buffer."
4230 :group 'gnus-article-various
4233 (defun gnus-article-mime-edit-article-unwind ()
4234 "Unwind `gnus-article-buffer' if article editing was given up."
4235 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4236 (when mime-edit-mode-flag
4237 (mime-edit-exit 'nomime 'no-error)
4239 (when (featurep 'font-lock)
4240 (setq font-lock-defaults nil)
4241 (font-lock-mode 0)))
4243 (defun gnus-article-mime-edit-article-setup ()
4244 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4245 after replacing with the original article."
4246 (setq gnus-show-mime t)
4247 (setq gnus-article-edit-done-function
4248 `(lambda (&rest args)
4249 (when mime-edit-mode-flag
4252 (goto-char (point-min))
4253 (let (case-fold-search)
4254 (when (re-search-forward
4255 (format "^%s$" (regexp-quote mail-header-separator))
4257 (replace-match "")))
4258 (when (featurep 'font-lock)
4259 (setq font-lock-defaults nil)
4261 (apply ,gnus-article-edit-done-function args)
4262 (set-buffer gnus-original-article-buffer)
4264 (insert-buffer gnus-article-buffer)
4265 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4266 (gnus-article-prepare-display)))
4267 (substitute-key-definition
4268 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4269 gnus-article-edit-mode-map)
4271 (insert-buffer gnus-original-article-buffer)
4273 (when (featurep 'font-lock)
4274 (set (make-local-variable 'font-lock-defaults)
4275 '(message-font-lock-keywords t))
4276 (font-lock-set-defaults)
4277 (turn-on-font-lock))
4278 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4279 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4281 (defun gnus-article-mime-edit-exit ()
4282 "Exit the article MIME editing without updating."
4284 (let ((winconf gnus-prev-winconf)
4286 (when mime-edit-mode-flag
4289 (goto-char (point-min))
4290 (let (case-fold-search)
4291 (when (re-search-forward
4292 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4293 (replace-match "")))
4294 (when (featurep 'font-lock)
4295 (setq font-lock-defaults nil)
4297 ;; We remove all text props from the article buffer.
4298 (setq buf (format "%s" (buffer-string)))
4299 (set-buffer (get-buffer-create gnus-original-article-buffer))
4302 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4303 (gnus-article-prepare-display)
4304 (set-window-configuration winconf)))
4307 ;;; Article highlights
4310 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4312 ;;; Internal Variables:
4314 (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\\)"
4315 "Regular expression that matches URLs."
4316 :group 'gnus-article-buttons
4319 (defcustom gnus-button-alist
4320 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4321 0 t gnus-button-message-id 2)
4322 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4323 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4325 gnus-button-fetch-group 4)
4326 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4327 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4328 t gnus-button-message-id 3)
4329 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4330 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4331 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4332 ;; This is how URLs _should_ be embedded in text...
4333 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
4335 (,gnus-button-url-regexp 0 t gnus-button-url 0))
4336 "*Alist of regexps matching buttons in article bodies.
4338 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4339 REGEXP: is the string matching text around the button,
4340 BUTTON: is the number of the regexp grouping actually matching the button,
4341 FORM: is a lisp expression which must eval to true for the button to
4343 CALLBACK: is the function to call when the user push this button, and each
4344 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4346 CALLBACK can also be a variable, in that case the value of that
4347 variable it the real callback function."
4348 :group 'gnus-article-buttons
4349 :type '(repeat (list regexp
4350 (integer :tag "Button")
4352 (function :tag "Callback")
4355 (integer :tag "Regexp group")))))
4357 (defcustom gnus-header-button-alist
4358 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4359 0 t gnus-button-message-id 0)
4360 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4361 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4362 0 t gnus-button-mailto 0)
4363 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4364 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4365 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4366 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4367 gnus-button-message-id 3))
4368 "*Alist of headers and regexps to match buttons in article heads.
4370 This alist is very similar to `gnus-button-alist', except that each
4371 alist has an additional HEADER element first in each entry:
4373 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4375 HEADER is a regexp to match a header. For a fuller explanation, see
4376 `gnus-button-alist'."
4377 :group 'gnus-article-buttons
4378 :group 'gnus-article-headers
4379 :type '(repeat (list (regexp :tag "Header")
4381 (integer :tag "Button")
4383 (function :tag "Callback")
4386 (integer :tag "Regexp group")))))
4388 (defvar gnus-button-regexp nil)
4389 (defvar gnus-button-marker-list nil)
4390 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4392 (defvar gnus-button-last nil)
4393 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4397 (defun gnus-article-push-button (event)
4398 "Check text under the mouse pointer for a callback function.
4399 If the text under the mouse pointer has a `gnus-callback' property,
4400 call it with the value of the `gnus-data' text property."
4402 (set-buffer (window-buffer (posn-window (event-start event))))
4403 (let* ((pos (posn-point (event-start event)))
4404 (data (get-text-property pos 'gnus-data))
4405 (fun (get-text-property pos 'gnus-callback)))
4408 (funcall fun data))))
4410 (defun gnus-article-press-button ()
4411 "Check text at point for a callback function.
4412 If the text at point has a `gnus-callback' property,
4413 call it with the value of the `gnus-data' text property."
4415 (let* ((data (get-text-property (point) 'gnus-data))
4416 (fun (get-text-property (point) 'gnus-callback)))
4418 (funcall fun data))))
4420 (defun gnus-article-prev-button (n)
4421 "Move point to N buttons backward.
4422 If N is negative, move forward instead."
4424 (gnus-article-next-button (- n)))
4426 (defun gnus-article-next-button (n)
4427 "Move point to N buttons forward.
4428 If N is negative, move backward instead."
4430 (let ((function (if (< n 0) 'previous-single-property-change
4431 'next-single-property-change))
4432 (inhibit-point-motion-hooks t)
4434 (limit (if (< n 0) (point-min) (point-max))))
4436 (while (and (not (= limit (point)))
4438 ;; Skip past the current button.
4439 (when (get-text-property (point) 'gnus-callback)
4440 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4441 ;; Go to the next (or previous) button.
4442 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4443 ;; Put point at the start of the button.
4444 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4445 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4446 ;; Skip past intangible buttons.
4447 (when (get-text-property (point) 'intangible)
4451 (gnus-message 5 "No more buttons"))
4454 (defun gnus-article-highlight (&optional force)
4455 "Highlight current article.
4456 This function calls `gnus-article-highlight-headers',
4457 `gnus-article-highlight-citation',
4458 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4459 do the highlighting. See the documentation for those functions."
4460 (interactive (list 'force))
4461 (gnus-article-highlight-headers)
4462 (gnus-article-highlight-citation force)
4463 (gnus-article-highlight-signature)
4464 (gnus-article-add-buttons force)
4465 (gnus-article-add-buttons-to-head))
4467 (defun gnus-article-highlight-some (&optional force)
4468 "Highlight current article.
4469 This function calls `gnus-article-highlight-headers',
4470 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4471 do the highlighting. See the documentation for those functions."
4472 (interactive (list 'force))
4473 (gnus-article-highlight-headers)
4474 (gnus-article-highlight-signature)
4475 (gnus-article-add-buttons))
4477 (defun gnus-article-highlight-headers ()
4478 "Highlight article headers as specified by `gnus-header-face-alist'."
4481 (set-buffer gnus-article-buffer)
4483 (let ((alist gnus-header-face-alist)
4484 (buffer-read-only nil)
4485 (case-fold-search t)
4486 (inhibit-point-motion-hooks t)
4487 entry regexp header-face field-face from hpoints fpoints)
4488 (article-narrow-to-head)
4489 (while (setq entry (pop alist))
4490 (goto-char (point-min))
4491 (setq regexp (concat "^\\("
4492 (if (string-equal "" (nth 0 entry))
4496 header-face (nth 1 entry)
4497 field-face (nth 2 entry))
4498 (while (and (re-search-forward regexp nil t)
4502 (unless (search-forward ":" nil t)
4504 (when (and header-face
4505 (not (memq (point) hpoints)))
4506 (push (point) hpoints)
4507 (gnus-put-text-property from (point) 'face header-face))
4508 (when (and field-face
4509 (not (memq (setq from (point)) fpoints)))
4511 (if (re-search-forward "^[^ \t]" nil t)
4513 (goto-char (point-max)))
4514 (gnus-put-text-property from (point) 'face field-face))))))))
4516 (defun gnus-article-highlight-signature ()
4517 "Highlight the signature in an article.
4518 It does this by highlighting everything after
4519 `gnus-signature-separator' using `gnus-signature-face'."
4522 (set-buffer gnus-article-buffer)
4523 (let ((buffer-read-only nil)
4524 (inhibit-point-motion-hooks t))
4526 (when (and gnus-signature-face
4527 (gnus-article-narrow-to-signature))
4528 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4529 'face gnus-signature-face)
4531 (gnus-article-search-signature)
4532 (let ((start (match-beginning 0))
4533 (end (set-marker (make-marker) (1+ (match-end 0)))))
4534 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4537 (defun gnus-button-in-region-p (b e prop)
4538 "Say whether PROP exists in the region."
4539 (text-property-not-all b e prop nil))
4541 (defun gnus-article-add-buttons (&optional force)
4542 "Find external references in the article and make buttons of them.
4543 \"External references\" are things like Message-IDs and URLs, as
4544 specified by `gnus-button-alist'."
4545 (interactive (list 'force))
4547 (set-buffer gnus-article-buffer)
4548 (let ((buffer-read-only nil)
4549 (inhibit-point-motion-hooks t)
4550 (case-fold-search t)
4551 (alist gnus-button-alist)
4553 ;; Remove all old markers.
4554 (let (marker entry new-list)
4555 (while (setq marker (pop gnus-button-marker-list))
4556 (if (or (< marker (point-min)) (>= marker (point-max)))
4557 (push marker new-list)
4559 (when (setq entry (gnus-button-entry))
4560 (put-text-property (match-beginning (nth 1 entry))
4561 (match-end (nth 1 entry))
4562 'gnus-callback nil))
4563 (set-marker marker nil)))
4564 (setq gnus-button-marker-list new-list))
4565 ;; We skip the headers.
4568 (while (setq entry (pop alist))
4569 (setq regexp (car entry))
4571 (while (re-search-forward regexp nil t)
4572 (let* ((start (and entry (match-beginning (nth 1 entry))))
4573 (end (and entry (match-end (nth 1 entry))))
4574 (from (match-beginning 0)))
4575 (when (and (or (eq t (nth 2 entry))
4576 (eval (nth 2 entry)))
4577 (not (gnus-button-in-region-p
4578 start end 'gnus-callback)))
4579 ;; That optional form returned non-nil, so we add the
4581 (gnus-article-add-button
4582 start end 'gnus-button-push
4583 (car (push (set-marker (make-marker) from)
4584 gnus-button-marker-list))))))))))
4586 ;; Add buttons to the head of an article.
4587 (defun gnus-article-add-buttons-to-head ()
4588 "Add buttons to the head of the article."
4591 (set-buffer gnus-article-buffer)
4593 (let ((buffer-read-only nil)
4594 (inhibit-point-motion-hooks t)
4595 (case-fold-search t)
4596 (alist gnus-header-button-alist)
4598 (article-narrow-to-head)
4600 ;; Each alist entry.
4601 (setq entry (car alist)
4603 (goto-char (point-min))
4604 (while (re-search-forward (car entry) nil t)
4605 ;; Each header matching the entry.
4606 (setq beg (match-beginning 0))
4607 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4608 (match-beginning 0))
4611 (while (re-search-forward (nth 1 entry) end t)
4612 ;; Each match within a header.
4613 (let* ((entry (cdr entry))
4614 (start (match-beginning (nth 1 entry)))
4615 (end (match-end (nth 1 entry)))
4616 (form (nth 2 entry)))
4617 (goto-char (match-end 0))
4619 (gnus-article-add-button
4620 start end (nth 3 entry)
4621 (buffer-substring (match-beginning (nth 4 entry))
4622 (match-end (nth 4 entry)))))))
4623 (goto-char end)))))))
4625 ;;; External functions:
4627 (defun gnus-article-add-button (from to fun &optional data)
4628 "Create a button between FROM and TO with callback FUN and data DATA."
4629 (when gnus-article-button-face
4630 (gnus-overlay-put (gnus-make-overlay from to)
4631 'face gnus-article-button-face))
4632 (gnus-add-text-properties
4634 (nconc (and gnus-article-mouse-face
4635 (list gnus-mouse-face-prop gnus-article-mouse-face))
4636 (list 'gnus-callback fun)
4637 (and data (list 'gnus-data data)))))
4639 ;;; Internal functions:
4641 (defun gnus-article-set-globals ()
4643 (set-buffer gnus-summary-buffer)
4644 (gnus-set-global-variables)))
4646 (defun gnus-signature-toggle (end)
4648 (set-buffer gnus-article-buffer)
4649 (let ((buffer-read-only nil)
4650 (inhibit-point-motion-hooks t))
4651 (if (get-text-property end 'invisible)
4652 (gnus-article-unhide-text end (point-max))
4653 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4655 (defun gnus-button-entry ()
4656 ;; Return the first entry in `gnus-button-alist' matching this place.
4657 (let ((alist gnus-button-alist)
4660 (setq entry (pop alist))
4661 (if (looking-at (car entry))
4666 (defun gnus-button-push (marker)
4667 ;; Push button starting at MARKER.
4670 (let* ((entry (gnus-button-entry))
4671 (inhibit-point-motion-hooks t)
4673 (args (mapcar (lambda (group)
4674 (let ((string (match-string group)))
4675 (gnus-set-text-properties
4676 0 (length string) nil string)
4683 (fboundp (symbol-value fun)))
4684 (apply (symbol-value fun) args))
4686 (gnus-message 1 "You must define `%S' to use this button"
4687 (cons fun args)))))))
4689 (defun gnus-button-message-id (message-id)
4692 (set-buffer gnus-summary-buffer)
4693 (gnus-summary-refer-article message-id)))
4695 (defun gnus-button-fetch-group (address)
4696 "Fetch GROUP specified by ADDRESS."
4697 (if (not (string-match "[:/]" address))
4698 ;; This is just a simple group url.
4699 (gnus-group-read-ephemeral-group address gnus-select-method)
4700 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4702 (error "Can't parse %s" address)
4703 (gnus-group-read-ephemeral-group
4704 (match-string 4 address)
4705 `(nntp ,(match-string 1 address)
4706 (nntp-address ,(match-string 1 address))
4707 (nntp-port-number ,(if (match-end 3)
4708 (match-string 3 address)
4711 (defun gnus-url-parse-query-string (query &optional downcase)
4712 (let (retval pairs cur key val)
4713 (setq pairs (split-string query "&"))
4715 (setq cur (car pairs)
4717 (if (not (string-match "=" cur))
4719 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4720 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4722 (setq key (downcase key)))
4723 (setq cur (assoc key retval))
4725 (setcdr cur (cons val (cdr cur)))
4726 (setq retval (cons (list key val) retval)))))
4729 (defun gnus-url-unhex (x)
4736 (defun gnus-url-unhex-string (str &optional allow-newlines)
4737 "Remove %XXX embedded spaces, etc in a url.
4738 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4739 decoding of carriage returns and line feeds in the string, which is normally
4740 forbidden in URL encoding."
4741 (setq str (or str ""))
4743 (case-fold-search t))
4744 (while (string-match "%[0-9a-f][0-9a-f]" str)
4745 (let* ((start (match-beginning 0))
4746 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4748 (gnus-url-unhex (elt str (+ start 2))))))
4750 tmp (substring str 0 start)
4753 (char-to-string code))
4754 ((or (= code ?\n) (= code ?\r))
4756 (t (char-to-string code))))
4757 str (substring str (match-end 0)))))
4758 (setq tmp (concat tmp str))
4761 (defun gnus-url-mailto (url)
4762 ;; Send mail to someone
4763 (when (string-match "mailto:/*\\(.*\\)" url)
4764 (setq url (substring url (match-beginning 1) nil)))
4765 (let (to args subject func)
4766 (if (string-match (regexp-quote "?") url)
4767 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4768 args (gnus-url-parse-query-string
4769 (substring url (match-end 0) nil) t))
4770 (setq to (gnus-url-unhex-string url)))
4771 (setq args (cons (list "to" to) args)
4772 subject (cdr-safe (assoc "subject" args)))
4773 (gnus-setup-message 'reply
4776 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4779 (message-position-on-field (caar args)))
4780 (insert (mapconcat 'identity (cdar args) ", "))
4781 (setq args (cdr args)))
4784 (message-goto-subject)))))
4786 (defun gnus-button-mailto (address)
4788 (set-buffer (gnus-copy-article-buffer))
4789 (gnus-setup-message 'reply
4790 (message-reply address)))
4792 (defun gnus-button-reply (address)
4793 ;; Reply to ADDRESS.
4794 (gnus-setup-message 'reply
4795 (message-reply address)))
4797 (defun gnus-button-url (address)
4799 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4800 (if (listp browse-url-browser-function)
4801 (browse-url address)
4802 (funcall browse-url-browser-function address)))
4804 (defun gnus-button-embedded-url (address)
4806 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4807 (if (listp browse-url-browser-function)
4808 (browse-url (gnus-strip-whitespace address))
4809 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4811 ;;; Next/prev buttons in the article buffer.
4813 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4814 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4816 (defvar gnus-prev-page-map nil)
4817 (unless gnus-prev-page-map
4818 (setq gnus-prev-page-map (make-sparse-keymap))
4819 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4820 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4822 (static-if (featurep 'xemacs)
4823 (defun gnus-insert-prev-page-button ()
4824 (let ((buffer-read-only nil))
4826 gnus-prev-page-line-format nil
4827 `(gnus-prev t local-map ,gnus-prev-page-map
4828 gnus-callback gnus-article-button-prev-page
4829 article-type annotation))))
4830 (defun gnus-insert-prev-page-button ()
4831 (let ((buffer-read-only nil)
4832 (situation (get-text-property (point-min) 'mime-view-situation)))
4833 (set-keymap-parent gnus-prev-page-map (current-local-map))
4835 gnus-prev-page-line-format nil
4836 `(gnus-prev t local-map ,gnus-prev-page-map
4837 gnus-callback gnus-article-button-prev-page
4838 article-type annotation
4839 mime-view-situation ,situation))))
4842 (defvar gnus-next-page-map nil)
4843 (unless gnus-next-page-map
4844 (setq gnus-next-page-map (make-sparse-keymap))
4845 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4846 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4848 (defun gnus-button-next-page ()
4849 "Go to the next page."
4851 (let ((win (selected-window)))
4852 (select-window (get-buffer-window gnus-article-buffer t))
4853 (gnus-article-next-page)
4854 (select-window win)))
4856 (defun gnus-button-prev-page ()
4857 "Go to the prev page."
4859 (let ((win (selected-window)))
4860 (select-window (get-buffer-window gnus-article-buffer t))
4861 (gnus-article-prev-page)
4862 (select-window win)))
4864 (static-if (featurep 'xemacs)
4865 (defun gnus-insert-next-page-button ()
4866 (let ((buffer-read-only nil))
4867 (gnus-eval-format gnus-next-page-line-format nil
4869 t local-map ,gnus-next-page-map
4870 gnus-callback gnus-article-button-next-page
4871 article-type annotation))))
4872 (defun gnus-insert-next-page-button ()
4873 (let ((buffer-read-only nil)
4874 (situation (get-text-property (point-min) 'mime-view-situation)))
4875 (set-keymap-parent gnus-next-page-map (current-local-map))
4876 (gnus-eval-format gnus-next-page-line-format nil
4878 t local-map ,gnus-next-page-map
4879 gnus-callback gnus-article-button-next-page
4880 article-type annotation
4881 mime-view-situation ,situation))))
4884 (defun gnus-article-button-next-page (arg)
4885 "Go to the next page."
4887 (let ((win (selected-window)))
4888 (select-window (get-buffer-window gnus-article-buffer t))
4889 (gnus-article-next-page)
4890 (select-window win)))
4892 (defun gnus-article-button-prev-page (arg)
4893 "Go to the prev page."
4895 (let ((win (selected-window)))
4896 (select-window (get-buffer-window gnus-article-buffer t))
4897 (gnus-article-prev-page)
4898 (select-window win)))
4900 (defvar gnus-decode-header-methods
4901 '(mail-decode-encoded-word-region)
4902 "List of methods used to decode headers.
4904 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4905 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4906 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4907 whose names match REGEXP.
4910 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4911 mail-decode-encoded-word-region
4912 (\"chinese\" . rfc1843-decode-region))
4915 (defvar gnus-decode-header-methods-cache nil)
4917 (defun gnus-multi-decode-header (start end)
4918 "Apply the functions from `gnus-encoded-word-methods' that match."
4919 (unless (and gnus-decode-header-methods-cache
4920 (eq gnus-newsgroup-name
4921 (car gnus-decode-header-methods-cache)))
4922 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4925 (nconc gnus-decode-header-methods-cache (list x))
4926 (if (and gnus-newsgroup-name
4927 (string-match (car x) gnus-newsgroup-name))
4928 (nconc gnus-decode-header-methods-cache
4930 gnus-decode-header-methods))
4931 (let ((xlist gnus-decode-header-methods-cache))
4934 (narrow-to-region start end)
4936 (funcall (pop xlist) (point-min) (point-max))))))
4939 ;;; Treatment top-level handling.
4942 (defun gnus-treat-article (condition &optional part-number total-parts type)
4943 (let ((length (- (point-max) (point-min)))
4944 (alist gnus-treatment-function-alist)
4945 (article-goto-body-goes-to-point-min-p t)
4949 (let ((list gnus-article-treat-types))
4951 (when (string-match (pop list) type)
4952 (throw 'found t)))))))
4953 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4954 (entity (static-unless (featurep 'xemacs)
4955 (when (eq 'head condition)
4956 (get-text-property (point-min) 'mime-view-entity))))
4958 (gnus-run-hooks 'gnus-part-display-hook)
4959 (unless gnus-inhibit-treatment
4960 (while (setq elem (pop alist))
4961 (setq val (symbol-value (car elem)))
4962 (when (and (or (consp val)
4964 (gnus-treat-predicate val)
4965 (or (not (get (car elem) 'highlight))
4968 (funcall (cadr elem)))))
4969 ;; FSF Emacsen does not inherit the existing text properties
4970 ;; in the new text, so we should do it for `mime-view-entity'.
4971 (static-unless (featurep 'xemacs)
4973 (put-text-property (point-min) (point-max)
4974 'mime-view-entity entity))))))
4976 ;; Dynamic variables.
4977 (defvar part-number)
4978 (defvar total-parts)
4982 (defun gnus-treat-predicate (val)
4987 (stringp (car val)))
4988 (apply 'gnus-or (mapcar `(lambda (s)
4989 (string-match s ,(or gnus-newsgroup-name "")))
4992 (let ((pred (pop val)))
4995 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4997 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4999 (not (gnus-treat-predicate (car val))))
5001 (equal (car val) type))
5003 (error "%S is not a valid predicate" pred)))))
5013 (eq part-number total-parts))
5017 (error "%S is not a valid value" val))))
5023 (defun gnus-article-header-presentation-method (entity situation)
5024 (mime-insert-header entity)
5027 (set-alist 'mime-header-presentation-method-alist
5028 'gnus-original-article-mode
5029 #'gnus-article-header-presentation-method)
5031 (defun gnus-mime-preview-quitting-method ()
5032 (mime-preview-kill-buffer)
5033 (delete-other-windows)
5034 (gnus-article-show-summary)
5035 (gnus-summary-select-article gnus-show-all-headers t))
5037 (set-alist 'mime-preview-quitting-method-alist
5038 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5040 (defun gnus-following-method (buf)
5043 (message-yank-original)
5045 (goto-char (point-min))
5048 (set-alist 'mime-preview-following-method-alist
5049 'gnus-original-article-mode #'gnus-following-method)
5051 (set-alist 'mime-preview-over-to-previous-method-alist
5052 'gnus-original-article-mode
5054 (if (> (point-min) 1)
5055 (gnus-article-prev-page)
5056 (gnus-article-read-summary-keys
5057 nil (gnus-character-to-event ?P)))))
5059 (set-alist 'mime-preview-over-to-next-method-alist
5060 'gnus-original-article-mode'
5062 (if (< (point-max) (buffer-size))
5063 (gnus-article-next-page)
5064 (gnus-article-read-summary-keys
5065 nil (gnus-character-to-event ?N)))))
5075 (run-hooks 'gnus-art-load-hook)
5077 ;;; gnus-art.el ends here