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.
44 ;; Avoid byte-compile warnings.
45 (defvar gnus-article-decoded-p)
46 (defvar gnus-article-mime-handles)
56 (defgroup gnus-article nil
58 :link '(custom-manual "(gnus)The Article Buffer")
61 (defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
71 (defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
77 (defgroup gnus-article-signature nil
79 :link '(custom-manual "(gnus)Article Signature")
82 (defgroup gnus-article-headers nil
84 :link '(custom-manual "(gnus)Hiding Headers")
87 (defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
92 (defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
97 (defgroup gnus-article-saving nil
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
102 (defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
107 (defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
112 (defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
117 (defcustom gnus-ignored-headers
118 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
119 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
120 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
121 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
122 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
123 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
124 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
125 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
126 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
127 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
128 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
129 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
130 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
131 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
132 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
133 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
134 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
135 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
136 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
137 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
138 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
139 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
140 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
141 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
142 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
143 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:")
144 "*All headers that start with this regexp will be hidden.
145 This variable can also be a list of regexps of headers to be ignored.
146 If `gnus-visible-headers' is non-nil, this variable will be ignored."
147 :type '(choice :custom-show nil
150 :group 'gnus-article-hiding)
152 (defcustom gnus-visible-headers
153 "^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:"
154 "*All headers that do not match this regexp will be hidden.
155 This variable can also be a list of regexp of headers to remain visible.
156 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
157 :type '(repeat :value-to-internal (lambda (widget value)
158 (custom-split-regexp-maybe value))
159 :match (lambda (widget value)
161 (widget-editable-list-match widget value)))
163 :group 'gnus-article-hiding)
165 (defcustom gnus-sorted-header-list
166 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
167 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
168 "*This variable is a list of regular expressions.
169 If it is non-nil, headers that match the regular expressions will
170 be placed first in the article buffer in the sequence specified by
172 :type '(repeat regexp)
173 :group 'gnus-article-hiding)
175 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
176 "Headers that are only to be displayed if they have interesting data.
177 Possible values in this list are `empty', `newsgroups', `followup-to',
178 `reply-to', `date', `long-to', and `many-to'."
179 :type '(set (const :tag "Headers with no content." empty)
180 (const :tag "Newsgroups with only one group." newsgroups)
181 (const :tag "Followup-to identical to newsgroups." followup-to)
182 (const :tag "Reply-to identical to from." reply-to)
183 (const :tag "Date less than four days old." date)
184 (const :tag "Very long To header." long-to)
185 (const :tag "Multiple To headers." many-to))
186 :group 'gnus-article-hiding)
188 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
189 "Regexp matching signature separator.
190 This can also be a list of regexps. In that case, it will be checked
191 from head to tail looking for a separator. Searches will be done from
192 the end of the buffer."
193 :type '(repeat string)
194 :group 'gnus-article-signature)
196 (defcustom gnus-signature-limit nil
197 "Provide a limit to what is considered a signature.
198 If it is a number, no signature may not be longer (in characters) than
199 that number. If it is a floating point number, no signature may be
200 longer (in lines) than that number. If it is a function, the function
201 will be called without any parameters, and if it returns nil, there is
202 no signature in the buffer. If it is a string, it will be used as a
203 regexp. If it matches, the text in question is not a signature."
204 :type '(choice (integer :value 200)
206 (function :value fun)
207 (regexp :value ".*"))
208 :group 'gnus-article-signature)
210 (defcustom gnus-hidden-properties '(invisible t intangible t)
211 "Property list to use for hiding text."
213 :group 'gnus-article-hiding)
215 (defcustom gnus-article-x-face-command
216 (if (and (not gnus-xemacs)
218 (module-installed-p 'x-face-mule))
219 'x-face-mule-gnus-article-display-x-face
220 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
222 "*String or function to be executed to display an X-Face header.
223 If it is a string, the command will be executed in a sub-shell
224 asynchronously. The compressed face will be piped to this command."
225 :type 'string ;Leave function case to Lisp.
226 :group 'gnus-article-washing)
228 (defcustom gnus-article-x-face-too-ugly nil
229 "Regexp matching posters whose face shouldn't be shown automatically."
230 :type '(choice regexp (const nil))
231 :group 'gnus-article-washing)
233 (defcustom gnus-emphasis-alist
235 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
237 '(("_" "_" underline)
240 ("_/" "/_" underline-italic)
241 ("_\\*" "\\*_" underline-bold)
242 ("\\*/" "/\\*" bold-italic)
243 ("_\\*/" "/\\*_" underline-bold-italic))))
244 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
245 2 3 gnus-emphasis-underline)
249 (format format (car spec) (cadr spec))
250 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
252 "*Alist that says how to fontify certain phrases.
253 Each item looks like this:
255 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
257 The first element is a regular expression to be matched. The second
258 is a number that says what regular expression grouping used to find
259 the entire emphasized word. The third is a number that says what
260 regexp grouping should be displayed and highlighted. The fourth
261 is the face used for highlighting."
262 :type '(repeat (list :value ("" 0 0 default)
264 (integer :tag "Match group")
265 (integer :tag "Emphasize group")
267 :group 'gnus-article-emphasis)
269 (defface gnus-emphasis-bold '((t (:bold t)))
270 "Face used for displaying strong emphasized text (*word*)."
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-italic '((t (:italic t)))
274 "Face used for displaying italic emphasized text (/word/)."
275 :group 'gnus-article-emphasis)
277 (defface gnus-emphasis-underline '((t (:underline t)))
278 "Face used for displaying underlined emphasized text (_word_)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
282 "Face used for displaying underlined bold emphasized text (_*word*_)."
283 :group 'gnus-article-emphasis)
285 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
286 "Face used for displaying underlined italic emphasized text (_*word*_)."
287 :group 'gnus-article-emphasis)
289 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
290 "Face used for displaying bold italic emphasized text (/*word*/)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-underline-bold-italic
294 '((t (:bold t :italic t :underline t)))
295 "Face used for displaying underlined bold italic emphasized text.
296 Esample: (_/*word*/_)."
297 :group 'gnus-article-emphasis)
299 (defface gnus-emphasis-highlight-words
300 '((t (:background "black" :foreground "yellow")))
301 "Face used for displaying highlighted words."
302 :group 'gnus-article-emphasis)
304 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
305 "Format for display of Date headers in article bodies.
306 See `format-time-string' for the possible values.
308 The variable can also be function, which should return a complete Date
309 header. The function is called with one argument, the time, which can
310 be fed to `format-time-string'."
311 :type '(choice string symbol)
312 :link '(custom-manual "(gnus)Article Date")
313 :group 'gnus-article-washing)
316 (autoload 'mail-extract-address-components "mail-extr"))
318 (defcustom gnus-save-all-headers t
319 "*If non-nil, don't remove any headers before saving."
320 :group 'gnus-article-saving
323 (defcustom gnus-prompt-before-saving 'always
324 "*This variable says how much prompting is to be done when saving articles.
325 If it is nil, no prompting will be done, and the articles will be
326 saved to the default files. If this variable is `always', each and
327 every article that is saved will be preceded by a prompt, even when
328 saving large batches of articles. If this variable is neither nil not
329 `always', there the user will be prompted once for a file name for
330 each invocation of the saving commands."
331 :group 'gnus-article-saving
332 :type '(choice (item always)
333 (item :tag "never" nil)
334 (sexp :tag "once" :format "%t\n" :value t)))
336 (defcustom gnus-saved-headers gnus-visible-headers
337 "Headers to keep if `gnus-save-all-headers' is nil.
338 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
339 If that variable is nil, however, all headers that match this regexp
340 will be kept while the rest will be deleted before saving."
341 :group 'gnus-article-saving
344 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
345 "A function to save articles in your favourite format.
346 The function must be interactively callable (in other words, it must
347 be an Emacs command).
349 Gnus provides the following functions:
351 * gnus-summary-save-in-rmail (Rmail format)
352 * gnus-summary-save-in-mail (Unix mail format)
353 * gnus-summary-save-in-folder (MH folder)
354 * gnus-summary-save-in-file (article format)
355 * gnus-summary-save-in-vm (use VM's folder format)
356 * gnus-summary-write-to-file (article format -- overwrite)."
357 :group 'gnus-article-saving
358 :type '(radio (function-item gnus-summary-save-in-rmail)
359 (function-item gnus-summary-save-in-mail)
360 (function-item gnus-summary-save-in-folder)
361 (function-item gnus-summary-save-in-file)
362 (function-item gnus-summary-save-in-vm)
363 (function-item gnus-summary-write-to-file)))
365 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
366 "A function generating a file name to save articles in Rmail format.
367 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
368 :group 'gnus-article-saving
371 (defcustom gnus-mail-save-name 'gnus-plain-save-name
372 "A function generating a file name to save articles in Unix mail format.
373 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
374 :group 'gnus-article-saving
377 (defcustom gnus-folder-save-name 'gnus-folder-save-name
378 "A function generating a file name to save articles in MH folder.
379 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
380 :group 'gnus-article-saving
383 (defcustom gnus-file-save-name 'gnus-numeric-save-name
384 "A function generating a file name to save articles in article format.
385 The function is called with NEWSGROUP, HEADERS, and optional
387 :group 'gnus-article-saving
390 (defcustom gnus-split-methods
391 '((gnus-article-archive-name)
392 (gnus-article-nndoc-name))
393 "*Variable used to suggest where articles are to be saved.
394 For instance, if you would like to save articles related to Gnus in
395 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
396 you could set this variable to something like:
398 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
399 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
401 This variable is an alist where the where the key is the match and the
402 value is a list of possible files to save in if the match is non-nil.
404 If the match is a string, it is used as a regexp match on the
405 article. If the match is a symbol, that symbol will be funcalled
406 from the buffer of the article to be saved with the newsgroup as the
407 parameter. If it is a list, it will be evaled in the same buffer.
409 If this form or function returns a string, this string will be used as
410 a possible file name; and if it returns a non-nil list, that list will
411 be used as possible file names."
412 :group 'gnus-article-saving
413 :type '(repeat (choice (list :value (fun) function)
414 (cons :value ("" "") regexp (repeat string))
417 (defcustom gnus-article-display-method-for-mime
418 'gnus-article-display-mime-message
419 "Function to display a MIME message.
420 The function is called from the article buffer."
421 :group 'gnus-article-mime
424 (defcustom gnus-article-display-method-for-traditional
425 'gnus-article-display-traditional-message
426 "*Function to display a traditional message.
427 The function is called from the article buffer."
428 :group 'gnus-article-mime
431 (defcustom gnus-page-delimiter "^\^L"
432 "*Regexp describing what to use as article page delimiters.
433 The default value is \"^\^L\", which is a form linefeed at the
434 beginning of a line."
436 :group 'gnus-article-various)
438 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
439 "*The format specification for the article mode line.
440 See `gnus-summary-mode-line-format' for a closer description.
442 The following additional specs are available:
444 %w The article washing status.
445 %m The number of MIME parts in the article."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-mode-hook nil
450 "*A hook for Gnus article mode."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-menu-hook nil
455 "*Hook run after the creation of the article mode menu."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-prepare-hook nil
460 "*A hook called after an article has been prepared in the article buffer."
462 :group 'gnus-article-various)
464 (defcustom gnus-article-hide-pgp-hook nil
465 "*A hook called after successfully hiding a PGP signature."
467 :group 'gnus-article-various)
469 (defcustom gnus-article-button-face 'bold
470 "Face used for highlighting buttons in the article buffer.
472 An article button is a piece of text that you can activate by pressing
473 `RET' or `mouse-2' above it."
475 :group 'gnus-article-buttons)
477 (defcustom gnus-article-mouse-face 'highlight
478 "Face used for mouse highlighting in the article buffer.
480 Article buttons will be displayed in this face when the cursor is
483 :group 'gnus-article-buttons)
485 (defcustom gnus-signature-face 'gnus-signature-face
486 "Face used for highlighting a signature in the article buffer.
487 Obsolete; use the face `gnus-signature-face' for customizations instead."
489 :group 'gnus-article-highlight
490 :group 'gnus-article-signature)
492 (defface gnus-signature-face
494 "Face used for highlighting a signature in the article buffer."
495 :group 'gnus-article-highlight
496 :group 'gnus-article-signature)
498 (defface gnus-header-from-face
501 (:foreground "spring green"))
504 (:foreground "red3"))
507 "Face used for displaying from headers."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-subject-face
514 (:foreground "SeaGreen3"))
517 (:foreground "red4"))
519 (:bold t :italic t)))
520 "Face used for displaying subject headers."
521 :group 'gnus-article-headers
522 :group 'gnus-article-highlight)
524 (defface gnus-header-newsgroups-face
527 (:foreground "yellow" :italic t))
530 (:foreground "MidnightBlue" :italic t))
533 "Face used for displaying newsgroups headers."
534 :group 'gnus-article-headers
535 :group 'gnus-article-highlight)
537 (defface gnus-header-name-face
540 (:foreground "SeaGreen"))
543 (:foreground "maroon"))
546 "Face used for displaying header names."
547 :group 'gnus-article-headers
548 :group 'gnus-article-highlight)
550 (defface gnus-header-content-face
553 (:foreground "forest green" :italic t))
556 (:foreground "indianred4" :italic t))
558 (:italic t))) "Face used for displaying header content."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight)
562 (defcustom gnus-header-face-alist
563 '(("From" nil gnus-header-from-face)
564 ("Subject" nil gnus-header-subject-face)
565 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
566 ("" gnus-header-name-face gnus-header-content-face))
567 "*Controls highlighting of article header.
569 An alist of the form (HEADER NAME CONTENT).
571 HEADER is a regular expression which should match the name of an
572 header header and NAME and CONTENT are either face names or nil.
574 The name of each header field will be displayed using the face
575 specified by the first element in the list where HEADER match the
576 header name and NAME is non-nil. Similarly, the content will be
577 displayed by the first non-nil matching CONTENT face."
578 :group 'gnus-article-headers
579 :group 'gnus-article-highlight
580 :type '(repeat (list (regexp :tag "Header")
582 (item :tag "skip" nil)
583 (face :value default))
584 (choice :tag "Content"
585 (item :tag "skip" nil)
586 (face :value default)))))
588 (defcustom gnus-article-decode-hook nil
589 "*Hook run to decode charsets in articles."
590 :group 'gnus-article-headers
593 (defcustom gnus-display-mime-function 'gnus-display-mime
594 "Function to display MIME articles."
595 :group 'gnus-article-mime
598 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
599 "Function used to decode headers.")
601 (defvar gnus-article-dumbquotes-map
619 "Table for MS-to-Latin1 translation.")
621 (defcustom gnus-ignored-mime-types nil
622 "List of MIME types that should be ignored by Gnus."
623 :group 'gnus-article-mime
624 :type '(repeat regexp))
626 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
627 "List of MIME types that should not be given buttons when rendered inline."
628 :group 'gnus-article-mime
629 :type '(repeat regexp))
631 (defcustom gnus-article-mime-part-function nil
632 "Function called with a MIME handle as the argument.
633 This is meant for people who want to do something automatic based
634 on parts -- for instance, adding Vcard info to a database."
635 :group 'gnus-article-mime
638 (defcustom gnus-mime-multipart-functions nil
639 "An alist of MIME types to functions to display them.")
641 (defcustom gnus-article-date-lapsed-new-header nil
642 "Whether the X-Sent and Date headers can coexist.
643 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
644 either replace the old \"Date:\" header (if this variable is nil), or
645 be added below it (otherwise)."
646 :group 'gnus-article-headers
650 ;;; The treatment variables
653 (defvar gnus-part-display-hook nil
654 "Hook called on parts that are to receive treatment.")
656 (defvar gnus-article-treat-custom
657 '(choice (const :tag "Off" nil)
659 (const :tag "Header" head)
660 (const :tag "Last" last)
661 (const :tag "Mime" mime)
662 (integer :tag "Less")
663 (repeat :tag "Groups" regexp)
664 (sexp :tag "Predicate")))
666 (defvar gnus-article-treat-head-custom
667 '(choice (const :tag "Off" nil)
668 (const :tag "Header" head)))
670 (defvar gnus-article-treat-types '("text/plain")
673 (defvar gnus-inhibit-treatment nil
674 "Whether to inhibit treatment.")
676 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
677 "Highlight the signature.
678 Valid values are nil, t, `head', `last', an integer or a predicate.
679 See the manual for details."
680 :group 'gnus-article-treat
681 :type gnus-article-treat-custom)
682 (put 'gnus-treat-highlight-signature 'highlight t)
684 (defcustom gnus-treat-buttonize t
686 Valid values are nil, t, `head', `last', an integer or a predicate.
687 See the manual for details."
688 :group 'gnus-article-treat
689 :type gnus-article-treat-custom)
690 (put 'gnus-treat-buttonize 'highlight t)
692 (defcustom gnus-treat-buttonize-head 'head
693 "Add buttons to the head.
694 Valid values are nil, t, `head', `last', an integer or a predicate.
695 See the manual for details."
696 :group 'gnus-article-treat
697 :type gnus-article-treat-head-custom)
698 (put 'gnus-treat-buttonize-head 'highlight t)
700 (defcustom gnus-treat-emphasize nil
702 Valid values are nil, t, `head', `last', an integer or a predicate.
703 See the manual for details."
704 :group 'gnus-article-treat
705 :type gnus-article-treat-custom)
706 (put 'gnus-treat-emphasize 'highlight t)
708 (defcustom gnus-treat-strip-cr nil
709 "Remove carriage returns.
710 Valid values are nil, t, `head', `last', an integer or a predicate.
711 See the manual for details."
712 :group 'gnus-article-treat
713 :type gnus-article-treat-custom)
715 (defcustom gnus-treat-hide-headers 'head
717 Valid values are nil, t, `head', `last', an integer or a predicate.
718 See the manual for details."
719 :group 'gnus-article-treat
720 :type gnus-article-treat-head-custom)
722 (defcustom gnus-treat-hide-boring-headers nil
723 "Hide boring headers.
724 Valid values are nil, t, `head', `last', an integer or a predicate.
725 See the manual for details."
726 :group 'gnus-article-treat
727 :type gnus-article-treat-head-custom)
729 (defcustom gnus-treat-hide-signature nil
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733 :group 'gnus-article-treat
734 :type gnus-article-treat-custom)
736 (defcustom gnus-treat-fill-article nil
738 Valid values are nil, t, `head', `last', an integer or a predicate.
739 See the manual for details."
740 :group 'gnus-article-treat
741 :type gnus-article-treat-custom)
743 (defcustom gnus-treat-hide-citation nil
745 Valid values are nil, t, `head', `last', an integer or a predicate.
746 See the manual for details."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-custom)
750 (defcustom gnus-treat-strip-list-identifiers 'head
751 "Strip list identifiers from `gnus-list-identifiers`.
752 Valid values are nil, t, `head', `last', an integer or a predicate.
753 See the manual for details."
754 :group 'gnus-article-treat
755 :type gnus-article-treat-custom)
757 (defcustom gnus-treat-strip-pgp t
758 "Strip PGP signatures.
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-custom)
764 (defcustom gnus-treat-strip-pem nil
765 "Strip PEM signatures.
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-custom)
771 (defcustom gnus-treat-strip-banner t
772 "Strip banners from articles.
773 The banner to be stripped is specified in the `banner' group parameter.
774 Valid values are nil, t, `head', `last', an integer or a predicate.
775 See the manual for details."
776 :group 'gnus-article-treat
777 :type gnus-article-treat-custom)
779 (defcustom gnus-treat-highlight-headers 'head
780 "Highlight the headers.
781 Valid values are nil, t, `head', `last', an integer or a predicate.
782 See the manual for details."
783 :group 'gnus-article-treat
784 :type gnus-article-treat-head-custom)
785 (put 'gnus-treat-highlight-headers 'highlight t)
787 (defcustom gnus-treat-highlight-citation t
788 "Highlight cited text.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
793 (put 'gnus-treat-highlight-citation 'highlight t)
795 (defcustom gnus-treat-date-ut nil
796 "Display the Date in UT (GMT).
797 Valid values are nil, t, `head', `last', an integer or a predicate.
798 See the manual for details."
799 :group 'gnus-article-treat
800 :type gnus-article-treat-head-custom)
802 (defcustom gnus-treat-date-local nil
803 "Display the Date in the local timezone.
804 Valid values are nil, t, `head', `last', an integer or a predicate.
805 See the manual for details."
806 :group 'gnus-article-treat
807 :type gnus-article-treat-head-custom)
809 (defcustom gnus-treat-date-lapsed nil
810 "Display the Date header in a way that says how much time has elapsed.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-head-custom)
816 (defcustom gnus-treat-date-original nil
817 "Display the date in the original timezone.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-head-custom)
823 (defcustom gnus-treat-date-iso8601 nil
824 "Display the date in the ISO8601 format.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-head-custom)
830 (defcustom gnus-treat-date-user-defined nil
831 "Display the date in a user-defined format.
832 The format is defined by the `gnus-article-time-format' variable.
833 Valid values are nil, t, `head', `last', an integer or a predicate.
834 See the manual for details."
835 :group 'gnus-article-treat
836 :type gnus-article-treat-head-custom)
838 (defcustom gnus-treat-strip-headers-in-body t
839 "Strip the X-No-Archive header line from the beginning of the body.
840 Valid values are nil, t, `head', `last', an integer or a predicate.
841 See the manual for details."
842 :group 'gnus-article-treat
843 :type gnus-article-treat-custom)
845 (defcustom gnus-treat-strip-trailing-blank-lines nil
846 "Strip trailing blank lines.
847 Valid values are nil, t, `head', `last', an integer or a predicate.
848 See the manual for details."
849 :group 'gnus-article-treat
850 :type gnus-article-treat-custom)
852 (defcustom gnus-treat-strip-leading-blank-lines nil
853 "Strip leading blank lines.
854 Valid values are nil, t, `head', `last', an integer or a predicate.
855 See the manual for details."
856 :group 'gnus-article-treat
857 :type gnus-article-treat-custom)
859 (defcustom gnus-treat-strip-multiple-blank-lines nil
860 "Strip multiple blank lines.
861 Valid values are nil, t, `head', `last', an integer or a predicate.
862 See the manual for details."
863 :group 'gnus-article-treat
864 :type gnus-article-treat-custom)
866 (defcustom gnus-treat-overstrike t
867 "Treat overstrike highlighting.
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-custom)
872 (put 'gnus-treat-overstrike 'highlight t)
874 (defcustom gnus-treat-display-xface
875 (if (or (and gnus-xemacs (featurep 'xface))
876 (eq 'x-face-mule-gnus-article-display-x-face
877 gnus-article-x-face-command))
880 "Display X-Face headers.
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-head-custom)
885 (put 'gnus-treat-display-xface 'highlight t)
887 (defcustom gnus-treat-display-smileys
888 (if (or (and gnus-xemacs (featurep 'xpm))
889 (and (not gnus-xemacs)
891 (module-installed-p 'smiley-mule)))
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-custom)
899 (put 'gnus-treat-display-smileys 'highlight t)
901 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
903 Valid values are nil, t, `head', `last', an integer or a predicate.
904 See the manual for details."
905 :group 'gnus-article-treat
906 :type gnus-article-treat-head-custom)
907 (put 'gnus-treat-display-picons 'highlight t)
909 (defcustom gnus-treat-capitalize-sentences nil
910 "Capitalize sentence-starting words.
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-fill-long-lines nil
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-custom)
923 (defcustom gnus-treat-play-sounds nil
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-custom)
930 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
931 "Decode an article as `default-mime-charset'. For instance, if you want to
932 attempt to decode an article even if the value of `gnus-show-mime' is nil,
933 you could set this variable to something like: nil for don't decode, t for
934 decode the body, '(or header t) for the whole article, etc."
935 :group 'gnus-article-treat
936 :type '(radio (const :tag "Off" nil)
937 (const :tag "Decode body" t)
938 (const :tag "Decode all" (or head t))))
940 (defcustom gnus-treat-translate nil
941 "Translate articles from one language to another.
942 Valid values are nil, t, `head', `last', an integer or a predicate.
943 See the manual for details."
944 :group 'gnus-article-treat
945 :type gnus-article-treat-custom)
947 ;;; Internal variables
949 (defvar article-goto-body-goes-to-point-min-p nil)
950 (defvar gnus-article-wash-types nil)
951 (defvar gnus-article-emphasis-alist nil)
953 (defvar gnus-article-mime-handle-alist-1 nil)
954 (defvar gnus-treatment-function-alist
955 '((gnus-treat-decode-article-as-default-mime-charset
956 gnus-article-decode-article-as-default-mime-charset)
957 (gnus-treat-strip-banner gnus-article-strip-banner)
958 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
959 (gnus-treat-buttonize gnus-article-add-buttons)
960 (gnus-treat-fill-article gnus-article-fill-cited-article)
961 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
962 (gnus-treat-strip-cr gnus-article-remove-cr)
963 (gnus-treat-display-xface gnus-article-display-x-face)
964 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
965 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
966 (gnus-treat-hide-signature gnus-article-hide-signature)
967 (gnus-treat-hide-citation gnus-article-hide-citation)
968 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
969 (gnus-treat-strip-pgp gnus-article-hide-pgp)
970 (gnus-treat-strip-pem gnus-article-hide-pem)
971 (gnus-treat-highlight-headers gnus-article-highlight-headers)
972 (gnus-treat-emphasize gnus-article-emphasize)
973 (gnus-treat-highlight-citation gnus-article-highlight-citation)
974 (gnus-treat-highlight-signature gnus-article-highlight-signature)
975 (gnus-treat-date-ut gnus-article-date-ut)
976 (gnus-treat-date-local gnus-article-date-local)
977 (gnus-treat-date-lapsed gnus-article-date-lapsed)
978 (gnus-treat-date-original gnus-article-date-original)
979 (gnus-treat-date-user-defined gnus-article-date-user)
980 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
981 (gnus-treat-strip-trailing-blank-lines
982 gnus-article-remove-trailing-blank-lines)
983 (gnus-treat-strip-leading-blank-lines
984 gnus-article-strip-leading-blank-lines)
985 (gnus-treat-strip-multiple-blank-lines
986 gnus-article-strip-multiple-blank-lines)
987 (gnus-treat-overstrike gnus-article-treat-overstrike)
988 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
989 (gnus-treat-display-smileys gnus-smiley-display)
990 (gnus-treat-display-picons gnus-article-display-picons)
991 (gnus-treat-play-sounds gnus-earcon-display)))
993 (defvar gnus-article-mime-handle-alist nil)
994 (defvar article-lapsed-timer nil)
995 (defvar gnus-article-current-summary nil)
997 (defvar gnus-article-mode-syntax-table
998 (let ((table (copy-syntax-table text-mode-syntax-table)))
999 (modify-syntax-entry ?- "w" table)
1000 (modify-syntax-entry ?> ")" table)
1001 (modify-syntax-entry ?< "(" table)
1003 "Syntax table used in article mode buffers.
1004 Initialized from `text-mode-syntax-table.")
1006 (defvar gnus-save-article-buffer nil)
1008 (defvar gnus-article-mode-line-format-alist
1009 (nconc '((?w (gnus-article-wash-status) ?s)
1010 (?m (gnus-article-mime-part-status) ?s))
1011 gnus-summary-mode-line-format-alist))
1013 (defvar gnus-number-of-articles-to-be-saved nil)
1015 (defvar gnus-inhibit-hiding nil)
1017 (defsubst gnus-article-hide-text (b e props)
1018 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1019 (add-text-properties b e props)
1020 (when (memq 'intangible props)
1022 (max (1- b) (point-min))
1023 b 'intangible (cddr (memq 'intangible props)))))
1024 (defsubst gnus-article-unhide-text (b e)
1025 "Remove hidden text properties from region between B and E."
1026 (remove-text-properties b e gnus-hidden-properties)
1027 (when (memq 'intangible gnus-hidden-properties)
1028 (put-text-property (max (1- b) (point-min))
1029 b 'intangible nil)))
1031 (defun gnus-article-hide-text-type (b e type)
1032 "Hide text of TYPE between B and E."
1033 (push type gnus-article-wash-types)
1034 (gnus-article-hide-text
1035 b e (cons 'article-type (cons type gnus-hidden-properties))))
1037 (defun gnus-article-unhide-text-type (b e type)
1038 "Unhide text of TYPE between B and E."
1039 (setq gnus-article-wash-types
1040 (delq type gnus-article-wash-types))
1041 (remove-text-properties
1042 b e (cons 'article-type (cons type gnus-hidden-properties)))
1043 (when (memq 'intangible gnus-hidden-properties)
1044 (put-text-property (max (1- b) (point-min))
1045 b 'intangible nil)))
1047 (defun gnus-article-hide-text-of-type (type)
1048 "Hide text of TYPE in the current buffer."
1050 (let ((b (point-min))
1052 (while (setq b (text-property-any b e 'article-type type))
1053 (add-text-properties b (incf b) gnus-hidden-properties)))))
1055 (defun gnus-article-delete-text-of-type (type)
1056 "Delete text of TYPE in the current buffer."
1058 (let ((b (point-min)))
1059 (while (setq b (text-property-any b (point-max) 'article-type type))
1061 b (or (text-property-not-all b (point-max) 'article-type type)
1064 (defun gnus-article-delete-invisible-text ()
1065 "Delete all invisible text in the current buffer."
1067 (let ((b (point-min)))
1068 (while (setq b (text-property-any b (point-max) 'invisible t))
1070 b (or (text-property-not-all b (point-max) 'invisible t)
1073 (defun gnus-article-text-type-exists-p (type)
1074 "Say whether any text of type TYPE exists in the buffer."
1075 (text-property-any (point-min) (point-max) 'article-type type))
1077 (defsubst gnus-article-header-rank ()
1078 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1079 (let ((list gnus-sorted-header-list)
1082 (when (looking-at (car list))
1084 (setq list (cdr list))
1088 (defun article-hide-headers (&optional arg delete)
1089 "Hide unwanted headers and possibly sort them as well."
1090 (interactive (gnus-article-hidden-arg))
1091 ;; Lars said that this function might be inhibited.
1092 (if (gnus-article-check-hidden-text 'headers arg)
1094 ;; Show boring headers as well.
1095 (gnus-article-show-hidden-text 'boring-headers)
1096 (when (eq 1 (point-min))
1097 (set-window-start (get-buffer-window (current-buffer)) 1)))
1098 (unless gnus-inhibit-hiding
1101 (let ((buffer-read-only nil)
1102 (inhibit-read-only t)
1103 (case-fold-search t)
1104 (max (1+ (length gnus-sorted-header-list)))
1105 (ignored (when (not gnus-visible-headers)
1106 (cond ((stringp gnus-ignored-headers)
1107 gnus-ignored-headers)
1108 ((listp gnus-ignored-headers)
1109 (mapconcat 'identity gnus-ignored-headers
1112 (cond ((stringp gnus-visible-headers)
1113 gnus-visible-headers)
1114 ((and gnus-visible-headers
1115 (listp gnus-visible-headers))
1116 (mapconcat 'identity gnus-visible-headers "\\|"))))
1117 (inhibit-point-motion-hooks t)
1119 ;; First we narrow to just the headers.
1120 (article-narrow-to-head)
1121 ;; Hide any "From " lines at the beginning of (mail) articles.
1122 (while (looking-at "From ")
1126 (delete-region (point-min) (point))
1127 (gnus-article-hide-text (point-min) (point)
1128 (nconc (list 'article-type 'headers)
1129 gnus-hidden-properties))))
1130 ;; Then treat the rest of the header lines.
1131 ;; Then we use the two regular expressions
1132 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1133 ;; select which header lines is to remain visible in the
1135 (while (re-search-forward "^[^ \t]*:" nil t)
1137 ;; Mark the rank of the header.
1139 (point) (1+ (point)) 'message-rank
1140 (if (or (and visible (looking-at visible))
1142 (not (looking-at ignored))))
1143 (gnus-article-header-rank)
1146 (message-sort-headers-1)
1147 (when (setq beg (text-property-any
1148 (point-min) (point-max) 'message-rank (+ 2 max)))
1149 ;; We delete or make invisible the unwanted headers.
1152 (add-text-properties
1153 (point-min) (+ 5 (point-min))
1154 '(article-type headers dummy-invisible t))
1155 (delete-region beg (point-max)))
1156 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1159 (defun article-hide-boring-headers (&optional arg)
1160 "Toggle hiding of headers that aren't very interesting.
1161 If given a negative prefix, always show; if given a positive prefix,
1163 (interactive (gnus-article-hidden-arg))
1164 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1165 (not gnus-show-all-headers))
1168 (let ((buffer-read-only nil)
1169 (list gnus-boring-article-headers)
1170 (inhibit-point-motion-hooks t)
1172 (article-narrow-to-head)
1174 (setq elem (pop list))
1175 (goto-char (point-min))
1177 ;; Hide empty headers.
1179 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1181 (gnus-article-hide-text-type
1182 (progn (beginning-of-line) (point))
1185 (if (re-search-forward "^[^ \t]" nil t)
1189 ;; Hide boring Newsgroups header.
1190 ((eq elem 'newsgroups)
1191 (when (equal (gnus-fetch-field "newsgroups")
1192 (gnus-group-real-name
1193 (if (boundp 'gnus-newsgroup-name)
1196 (gnus-article-hide-header "newsgroups")))
1197 ((eq elem 'followup-to)
1198 (when (equal (message-fetch-field "followup-to")
1199 (message-fetch-field "newsgroups"))
1200 (gnus-article-hide-header "followup-to")))
1201 ((eq elem 'reply-to)
1202 (let ((from (message-fetch-field "from"))
1203 (reply-to (message-fetch-field "reply-to")))
1208 (nth 1 (funcall gnus-extract-address-components from))
1209 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1210 (gnus-article-hide-header "reply-to"))))
1212 (let ((date (message-fetch-field "date")))
1214 (< (days-between (current-time-string) date)
1216 (gnus-article-hide-header "date"))))
1218 (let ((to (message-fetch-field "to")))
1219 (when (> (length to) 1024)
1220 (gnus-article-hide-header "to"))))
1223 (goto-char (point-min))
1224 (while (re-search-forward "^to:" nil t)
1225 (setq to-count (1+ to-count)))
1226 (when (> to-count 1)
1227 (while (> to-count 0)
1228 (goto-char (point-min))
1230 (re-search-forward "^to:" nil nil to-count)
1232 (narrow-to-region (point) (point-max))
1233 (gnus-article-hide-header "to"))
1234 (setq to-count (1- to-count)))))))))))))
1236 (defun gnus-article-hide-header (header)
1238 (goto-char (point-min))
1239 (when (re-search-forward (concat "^" header ":") nil t)
1240 (gnus-article-hide-text-type
1241 (progn (beginning-of-line) (point))
1244 (if (re-search-forward "^[^ \t]" nil t)
1249 (defun article-toggle-headers (&optional arg)
1250 "Toggle hiding of headers. If given a negative prefix, always show;
1251 if given a positive prefix, always hide."
1252 (interactive (gnus-article-hidden-arg))
1253 (let ((force (when (numberp arg)
1254 (cond ((> arg 0) 'always-hide)
1255 ((< arg 0) 'always-show))))
1256 (window (get-buffer-window gnus-article-buffer))
1257 (header-end (point-min))
1258 header-start field-end field-start
1259 (inhibit-point-motion-hooks t)
1260 (inhibit-read-only t)
1264 (while (and (setq header-start
1265 (text-property-any header-end (point-max)
1266 'article-treated-header t))
1268 (text-property-not-all header-start (point-max)
1269 'article-treated-header t)))
1270 (setq field-end header-start)
1272 (;; Hide exposed invisible fields.
1273 (and (not (eq 'always-show force))
1275 (text-property-any field-end header-end
1276 'exposed-invisible-field t)))
1277 (while (and field-start
1278 (setq field-end (text-property-not-all
1279 field-start header-end
1280 'exposed-invisible-field t)))
1281 (add-text-properties field-start field-end gnus-hidden-properties)
1282 (setq field-start (text-property-any field-end header-end
1283 'exposed-invisible-field t)))
1284 (put-text-property header-start header-end
1285 'exposed-invisible-field nil))
1286 (;; Expose invisible fields.
1287 (and (not (eq 'always-hide force))
1289 (text-property-any field-end header-end 'invisible t)))
1290 (while (and field-start
1291 (setq field-end (text-property-not-all
1292 field-start header-end
1294 ;; If the invisible text is not terminated with newline, we
1295 ;; won't expose it. Because it may be created by x-face-mule.
1296 ;; BTW, XEmacs sometimes fail in putting a invisible text
1297 ;; property with `gnus-article-hide-text' (really?). In that
1298 ;; case, the invisible text might be started from the middle of
1299 ;; a line so we will expose the sort of thing.
1300 (when (or (not (or (eq header-start field-start)
1301 (eq ?\n (char-before field-start))))
1302 (eq ?\n (char-before field-end)))
1303 (remove-text-properties field-start field-end
1304 gnus-hidden-properties)
1305 (put-text-property field-start field-end
1306 'exposed-invisible-field t))
1307 (setq field-start (text-property-any field-end header-end
1310 (not (eq 'always-show force))
1311 (narrow-to-region header-start header-end)
1312 (article-hide-headers)
1313 ;; Re-display X-Face image under XEmacs.
1314 (when (and gnus-xemacs
1315 (gnus-functionp gnus-article-x-face-command))
1316 (let ((func (cadr (assq 'gnus-treat-display-xface
1317 gnus-treatment-function-alist)))
1319 (when (and (not gnus-inhibit-treatment)
1321 (gnus-treat-predicate gnus-treat-display-xface))
1323 (put-text-property header-start header-end 'read-only nil))))
1326 (goto-char (point-min))
1328 (set-window-start window (point-min))))))
1330 (defvar gnus-article-normalized-header-length 40
1331 "Length of normalized headers.")
1333 (defun article-normalize-headers ()
1334 "Make all header lines 40 characters long."
1336 (let ((buffer-read-only nil)
1340 (article-narrow-to-head)
1343 ((< (setq column (- (gnus-point-at-eol) (point)))
1344 gnus-article-normalized-header-length)
1346 (insert (make-string
1347 (- gnus-article-normalized-header-length column)
1349 ((> column gnus-article-normalized-header-length)
1350 (gnus-put-text-property
1352 (forward-char gnus-article-normalized-header-length)
1359 (forward-line 1))))))
1361 (defun article-treat-dumbquotes ()
1362 "Translate M******** sm*rtq**t*s into proper text.
1363 Note that this function guesses whether a character is a sm*rtq**t* or
1364 not, so it should only be used interactively."
1366 (article-translate-strings gnus-article-dumbquotes-map))
1368 (defun article-translate-characters (from to)
1369 "Translate all characters in the body of the article according to FROM and TO.
1370 FROM is a string of characters to translate from; to is a string of
1371 characters to translate to."
1373 (when (article-goto-body)
1374 (let ((buffer-read-only nil)
1375 (x (make-string 225 ?x))
1377 (while (< (incf i) (length x))
1380 (while (< i (length from))
1381 (aset x (aref from i) (aref to i))
1383 (translate-region (point) (point-max) x)))))
1385 (defun article-translate-strings (map)
1386 "Translate all string in the body of the article according to MAP.
1387 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1389 (when (article-goto-body)
1390 (let ((buffer-read-only nil)
1392 (while (setq elem (pop map))
1394 (while (search-forward (car elem) nil t)
1395 (replace-match (cadr elem)))))))))
1397 (defun article-treat-overstrike ()
1398 "Translate overstrikes into bold text."
1401 (when (article-goto-body)
1402 (let ((buffer-read-only nil))
1403 (while (search-forward "\b" nil t)
1404 (let ((next (char-after))
1405 (previous (char-after (- (point) 2))))
1406 ;; We do the boldification/underlining by hiding the
1407 ;; overstrikes and putting the proper text property
1411 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1412 (put-text-property (point) (1+ (point)) 'face 'bold))
1414 (gnus-article-hide-text-type
1415 (1- (point)) (1+ (point)) 'overstrike)
1417 (- (point) 2) (1- (point)) 'face 'underline))
1419 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1421 (point) (1+ (point)) 'face 'underline)))))))))
1423 (defun article-fill-long-lines ()
1424 "Fill lines that are wider than the window width."
1427 (let ((buffer-read-only nil)
1428 (width (window-width (get-buffer-window (current-buffer)))))
1431 (let ((adaptive-fill-mode nil))
1434 (when (>= (current-column) (min fill-column width))
1435 (narrow-to-region (point) (gnus-point-at-bol))
1436 (fill-paragraph nil)
1437 (goto-char (point-max))
1439 (forward-line 1)))))))
1441 (defun article-capitalize-sentences ()
1442 "Capitalize the first word in each sentence."
1445 (let ((buffer-read-only nil)
1446 (paragraph-start "^[\n\^L]"))
1450 (forward-sentence)))))
1452 (defun article-remove-cr ()
1453 "Remove trailing CRs and then translate remaining CRs into LFs."
1456 (let ((buffer-read-only nil))
1457 (goto-char (point-min))
1458 (while (re-search-forward "\r+$" nil t)
1459 (replace-match "" t t))
1460 (goto-char (point-min))
1461 (while (search-forward "\r" nil t)
1462 (replace-match "\n" t t)))))
1464 (defun article-remove-trailing-blank-lines ()
1465 "Remove all trailing blank lines from the article."
1468 (let ((buffer-read-only nil))
1469 (goto-char (point-max))
1473 (while (and (not (bobp))
1474 (looking-at "^[ \t]*$")
1475 (not (gnus-annotation-in-region-p
1476 (point) (gnus-point-at-eol))))
1481 (defun article-display-x-face (&optional force)
1482 "Look for an X-Face header and display it if present."
1483 (interactive (list 'force))
1485 ;; Delete the old process, if any.
1486 (when (process-status "article-x-face")
1487 (delete-process "article-x-face"))
1488 (let ((inhibit-point-motion-hooks t)
1489 (case-fold-search t)
1492 (article-narrow-to-head)
1493 (goto-char (point-min))
1494 (setq from (message-fetch-field "from"))
1495 (goto-char (point-min))
1496 (while (and gnus-article-x-face-command
1499 ;; Check whether this face is censored.
1500 (not gnus-article-x-face-too-ugly)
1501 (and gnus-article-x-face-too-ugly from
1502 (not (string-match gnus-article-x-face-too-ugly
1504 ;; Has to be present.
1505 (re-search-forward "^X-Face: " nil t))
1506 ;; This used to try to do multiple faces (`while' instead of
1507 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1508 ;; work (b) it can crash some versions of Emacs (c) are
1509 ;; multiple faces really something to encourage?
1510 (when (stringp gnus-article-x-face-command)
1512 ;; We now have the area of the buffer where the X-Face is stored.
1515 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1516 ;; We display the face.
1517 (if (symbolp gnus-article-x-face-command)
1518 ;; The command is a lisp function, so we call it.
1519 (if (gnus-functionp gnus-article-x-face-command)
1520 (funcall gnus-article-x-face-command beg end)
1521 (error "%s is not a function" gnus-article-x-face-command))
1522 ;; The command is a string, so we interpret the command
1523 ;; as a, well, command, and fork it off.
1524 (let ((process-connection-type nil))
1525 (process-kill-without-query
1527 "article-x-face" nil shell-file-name shell-command-switch
1528 gnus-article-x-face-command))
1529 (process-send-region "article-x-face" beg end)
1530 (process-send-eof "article-x-face"))))))))))
1532 (defun article-decode-mime-words ()
1533 "Decode all MIME-encoded words in the article."
1536 (set-buffer gnus-article-buffer)
1537 (let ((inhibit-point-motion-hooks t)
1539 (mail-parse-charset gnus-newsgroup-charset)
1540 (mail-parse-ignored-charsets
1541 (save-excursion (set-buffer gnus-summary-buffer)
1542 gnus-newsgroup-ignored-charsets)))
1543 (mail-decode-encoded-word-region (point-min) (point-max)))))
1545 (defun article-decode-charset (&optional prompt)
1546 "Decode charset-encoded text in the article.
1547 If PROMPT (the prefix), prompt for a coding system to use."
1551 (article-narrow-to-head)
1552 (let* ((inhibit-point-motion-hooks t)
1553 (case-fold-search t)
1554 (ct (message-fetch-field "Content-Type" t))
1555 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1556 (ctl (and ct (ignore-errors
1557 (mail-header-parse-content-type ct))))
1560 (mm-read-coding-system "Charset to decode: "))
1562 (mail-content-type-get ctl 'charset))))
1563 (mail-parse-charset gnus-newsgroup-charset)
1564 (mail-parse-ignored-charsets
1565 (save-excursion (condition-case nil
1566 (set-buffer gnus-summary-buffer)
1568 gnus-newsgroup-ignored-charsets))
1570 (if (and ctl (not (string-match "/" (car ctl))))
1572 (goto-char (point-max))
1575 (narrow-to-region (point) (point-max))
1576 (when (and (or (not ctl)
1577 (equal (car ctl) "text/plain"))
1580 charset (and cte (intern (downcase
1581 (gnus-strip-whitespace cte))))
1584 (defun article-decode-encoded-words ()
1585 "Remove encoded-word encoding from headers."
1586 (let (buffer-read-only)
1587 (let ((charset (save-excursion
1588 (set-buffer gnus-summary-buffer)
1589 default-mime-charset)))
1590 (mime-decode-header-in-buffer charset)
1593 (defun article-de-quoted-unreadable (&optional force)
1594 "Translate a quoted-printable-encoded article.
1595 If FORCE, decode the article whether it is marked as quoted-printable
1597 (interactive (list 'force))
1599 (let ((buffer-read-only nil)
1600 (type (gnus-fetch-field "content-transfer-encoding"))
1601 (charset gnus-newsgroup-charset))
1603 (and type (string-match "quoted-printable" (downcase type))))
1606 (narrow-to-region (point) (point-max))
1607 (quoted-printable-decode-region (point-min) (point-max))
1609 (mm-decode-body charset)))))))
1611 (defun article-hide-list-identifiers ()
1612 "Remove any list identifiers in `gnus-list-identifiers' from Subject
1613 header in the current article."
1617 (let ((inhibit-point-motion-hooks t)
1619 (article-narrow-to-head)
1620 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1621 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1623 (goto-char (point-min))
1624 (when (re-search-forward
1625 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1627 (delete-region (match-beginning 2) (match-end 0)))))))))
1629 (defun article-hide-pgp ()
1630 "Remove any PGP headers and signatures in the current article."
1634 (let ((inhibit-point-motion-hooks t)
1635 buffer-read-only beg end)
1637 ;; Hide the "header".
1638 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1639 (push 'pgp gnus-article-wash-types)
1640 (delete-region (match-beginning 0) (match-end 0))
1641 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1642 (when (looking-at "Hash:.*$")
1643 (delete-region (point) (1+ (gnus-point-at-eol))))
1645 ;; Hide the actual signature.
1646 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1647 (setq end (1+ (match-beginning 0)))
1650 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1652 ;; Perhaps we shouldn't hide to the end of the buffer
1653 ;; if there is no end to the signature?
1655 ;; Hide "- " PGP quotation markers.
1657 (narrow-to-region beg end)
1658 (goto-char (point-min))
1659 (while (re-search-forward "^- " nil t)
1661 (match-beginning 0) (match-end 0)))
1663 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1665 (defun article-hide-pem (&optional arg)
1666 "Toggle hiding of any PEM headers and signatures in the current article.
1667 If given a negative prefix, always show; if given a positive prefix,
1669 (interactive (gnus-article-hidden-arg))
1670 (unless (gnus-article-check-hidden-text 'pem arg)
1672 (let (buffer-read-only end)
1673 (goto-char (point-min))
1674 ;; Hide the horrendously ugly "header".
1675 (when (and (search-forward
1676 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1678 (setq end (1+ (match-beginning 0))))
1679 (push 'pem gnus-article-wash-types)
1680 (gnus-article-hide-text-type
1682 (if (search-forward "\n\n" nil t)
1686 ;; Hide the trailer as well
1687 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1689 (gnus-article-hide-text-type
1690 (match-beginning 0) (match-end 0) 'pem)))))))
1692 (defun article-strip-banner ()
1693 "Strip the banner specified by the `banner' group parameter."
1697 (let ((inhibit-point-motion-hooks t)
1698 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1699 (gnus-signature-limit nil)
1700 buffer-read-only beg end)
1704 ((eq banner 'signature)
1705 (when (gnus-article-narrow-to-signature)
1708 (delete-region (point) (point-max))))
1710 (while (re-search-forward banner nil t)
1711 (delete-region (match-beginning 0) (match-end 0))))))))))
1713 (defun article-babel ()
1714 "Translate article using an online translation service."
1718 (set-buffer gnus-article-buffer)
1719 (when (article-goto-body)
1720 (let* ((buffer-read-only nil)
1723 (orig (buffer-substring start end))
1724 (trans (babel-as-string orig)))
1726 (narrow-to-region start end)
1727 (delete-region start end)
1730 (defun article-hide-signature (&optional arg)
1731 "Hide the signature in the current article.
1732 If given a negative prefix, always show; if given a positive prefix,
1734 (interactive (gnus-article-hidden-arg))
1740 (article-goto-body))
1741 (goto-char (point-min)))
1742 (unless (gnus-article-check-hidden-text 'signature arg)
1743 (let ((buffer-read-only nil)
1745 (while (setq button (text-property-any button (point-max)
1747 'gnus-signature-toggle))
1748 (setq button (text-property-not-all button (point-max)
1750 'gnus-signature-toggle))
1751 (when (and button (not (eobp)))
1752 (gnus-article-hide-text-type
1754 (or (next-single-property-change (1+ button) 'mime-view-entity)
1758 (defun article-strip-headers-in-body ()
1759 "Strip offensive headers from bodies."
1763 (let ((case-fold-search t))
1764 (when (looking-at "x-no-archive:")
1765 (gnus-delete-line)))))
1767 (defun article-strip-leading-blank-lines ()
1768 "Remove all blank lines from the beginning of the article."
1771 (let ((inhibit-point-motion-hooks t)
1773 (when (article-goto-body)
1774 (while (and (not (eobp))
1775 (looking-at "[ \t]*$"))
1776 (gnus-delete-line))))))
1778 (defun article-narrow-to-head ()
1779 "Narrow the buffer to the head of the message.
1780 Point is left at the beginning of the narrowed-to region."
1782 (goto-char (point-min))
1783 (if (search-forward "\n\n" nil 1)
1786 (goto-char (point-min)))
1788 (defun article-goto-body ()
1789 "Place point at the start of the body."
1790 (goto-char (point-min))
1792 ;; This variable is only bound when dealing with separate
1794 (article-goto-body-goes-to-point-min-p
1796 ((search-forward "\n\n" nil t)
1799 (goto-char (point-max))
1802 (defun article-strip-multiple-blank-lines ()
1803 "Replace consecutive blank lines with one empty line."
1806 (let ((inhibit-point-motion-hooks t)
1808 ;; First make all blank lines empty.
1810 (while (re-search-forward "^[ \t]+$" nil t)
1811 (unless (gnus-annotation-in-region-p
1812 (match-beginning 0) (match-end 0))
1813 (replace-match "" nil t)))
1814 ;; Then replace multiple empty lines with a single empty line.
1816 (while (re-search-forward "\n\n\n+" nil t)
1817 (unless (gnus-annotation-in-region-p
1818 (match-beginning 0) (match-end 0))
1819 (replace-match "\n\n" t t))))))
1821 (defun article-strip-leading-space ()
1822 "Remove all white space from the beginning of the lines in the article."
1825 (let ((inhibit-point-motion-hooks t)
1828 (while (re-search-forward "^[ \t]+" nil t)
1829 (replace-match "" t t)))))
1831 (defun article-strip-trailing-space ()
1832 "Remove all white space from the end of the lines in the article."
1835 (let ((inhibit-point-motion-hooks t)
1838 (while (re-search-forward "[ \t]+$" nil t)
1839 (replace-match "" t t)))))
1841 (defun article-strip-blank-lines ()
1842 "Strip leading, trailing and multiple blank lines."
1844 (article-strip-leading-blank-lines)
1845 (article-remove-trailing-blank-lines)
1846 (article-strip-multiple-blank-lines))
1848 (defun article-strip-all-blank-lines ()
1849 "Strip all blank lines."
1852 (let ((inhibit-point-motion-hooks t)
1855 (while (re-search-forward "^[ \t]*\n" nil t)
1856 (replace-match "" t t)))))
1858 (defun gnus-article-narrow-to-signature ()
1859 "Narrow to the signature; return t if a signature is found, else nil."
1860 (let ((inhibit-point-motion-hooks t))
1861 (when (gnus-article-search-signature)
1863 ;; Check whether we have some limits to what we consider
1864 ;; to be a signature.
1865 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1866 (list gnus-signature-limit)))
1868 (while (setq limit (pop limits))
1869 (if (or (and (integerp limit)
1870 (< (- (point-max) (point)) limit))
1872 (< (count-lines (point) (point-max)) limit))
1873 (and (gnus-functionp limit)
1875 (and (stringp limit)
1876 (not (re-search-forward limit nil t))))
1877 () ; This limit did not succeed.
1881 (narrow-to-region (point) (point-max))
1884 (defun gnus-article-search-signature ()
1885 "Search the current buffer for the signature separator.
1886 Put point at the beginning of the signature separator."
1887 (let ((cur (point)))
1888 (goto-char (point-max))
1889 (if (if (stringp gnus-signature-separator)
1890 (re-search-backward gnus-signature-separator nil t)
1891 (let ((seps gnus-signature-separator))
1893 (not (re-search-backward (car seps) nil t)))
1900 (defun gnus-article-hidden-arg ()
1901 "Return the current prefix arg as a number, or 0 if no prefix."
1902 (list (if current-prefix-arg
1903 (prefix-numeric-value current-prefix-arg)
1906 (defun gnus-article-check-hidden-text (type arg)
1907 "Return nil if hiding is necessary.
1908 Arg can be nil or a number. Nil and positive means hide, negative
1909 means show, 0 means toggle."
1912 (let ((hide (gnus-article-hidden-text-p type)))
1918 (gnus-article-show-hidden-text type))
1920 (if (eq hide 'hidden)
1921 (gnus-article-show-hidden-text type)
1924 (defun gnus-article-hidden-text-p (type)
1925 "Say whether the current buffer contains hidden text of type TYPE."
1926 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1928 (not (get-text-property pos 'invisible))
1929 (not (get-text-property pos 'dummy-invisible)))
1931 (text-property-any (1+ pos) (point-max) 'article-type type)))
1936 (defun gnus-article-show-hidden-text (type &optional hide)
1937 "Show all hidden text of type TYPE.
1938 If HIDE, hide the text instead."
1940 (let ((buffer-read-only nil)
1941 (inhibit-point-motion-hooks t)
1944 (while (setq beg (text-property-any end (point-max) 'article-type type))
1947 (text-property-not-all beg (point-max) 'article-type type)
1950 (gnus-article-hide-text beg end gnus-hidden-properties)
1951 (gnus-article-unhide-text beg end))
1955 (defconst article-time-units
1956 `((year . ,(* 365.25 24 60 60))
1957 (week . ,(* 7 24 60 60))
1958 (day . ,(* 24 60 60))
1962 "Mapping from time units to seconds.")
1964 (defun article-date-ut (&optional type highlight header)
1965 "Convert DATE date to universal time in the current article.
1966 If TYPE is `local', convert to local time; if it is `lapsed', output
1967 how much time has lapsed since DATE. For `lapsed', the value of
1968 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1969 should replace the \"Date:\" one, or should be added below it."
1970 (interactive (list 'ut t))
1971 (let* ((header (or header
1972 (and (eq 1 (point-min))
1973 (mail-header-date (save-excursion
1974 (set-buffer gnus-summary-buffer)
1975 gnus-current-headers)))
1976 (message-fetch-field "date")
1978 (date (if (vectorp header) (mail-header-date header)
1980 (inhibit-point-motion-hooks t)
1981 bface eface date-pos)
1982 (when (and date (not (string= date "")))
1985 (article-narrow-to-head)
1986 (when (or (and (eq type 'lapsed)
1987 gnus-article-date-lapsed-new-header
1988 ;; Attempt to get the face of X-Sent first.
1989 (re-search-forward "^X-Sent:[ \t]" nil t))
1990 (re-search-forward "^Date:[ \t]" nil t)
1991 ;; If Date is missing, try again for X-Sent.
1992 (re-search-forward "^X-Sent:[ \t]" nil t))
1993 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1994 date (or (get-text-property (gnus-point-at-bol)
1997 eface (get-text-property (1- (gnus-point-at-eol))
1999 (let ((buffer-read-only nil))
2000 ;; Delete any old X-Sent headers.
2001 (when (setq date-pos
2002 (text-property-any (point-min) (point-max)
2003 'article-date-lapsed t))
2004 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2005 (delete-region (match-beginning 0)
2006 (progn (forward-line 1) (point))))
2007 (goto-char (point-min))
2008 ;; Delete any old Date headers.
2009 (while (re-search-forward "^Date:[ \t]" nil t)
2011 (setq date-pos (match-beginning 0)))
2012 (unless (and (eq type 'lapsed)
2013 gnus-article-date-lapsed-new-header)
2014 (delete-region (match-beginning 0)
2015 (progn (message-next-header) (point)))))
2018 (goto-char date-pos)
2020 ;; Possibly, Date has been deleted.
2022 (when (and (eq type 'lapsed)
2023 gnus-article-date-lapsed-new-header
2024 (looking-at "Date:"))
2026 (goto-char (point-min)))
2027 (insert (article-make-date-line date type))
2028 (when (eq type 'lapsed)
2029 (put-text-property (gnus-point-at-bol) (point)
2030 'article-date-lapsed t))
2034 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2035 (put-text-property (match-beginning 1) (1+ (match-end 1))
2036 'original-date date)
2037 (put-text-property (match-beginning 1) (1+ (match-end 1))
2039 (put-text-property (match-beginning 2) (match-end 2)
2042 (defun article-make-date-line (date type)
2043 "Return a DATE line of TYPE."
2044 (let ((time (condition-case ()
2048 ;; Convert to the local timezone. We have to slap a
2049 ;; `condition-case' round the calls to the timezone
2050 ;; functions since they aren't particularly resistant to
2053 (let ((tz (car (current-time-zone time))))
2054 (format "Date: %s %s%02d%02d" (current-time-string time)
2055 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2056 (/ (% (abs tz) 3600) 60))))
2057 ;; Convert to Universal Time.
2060 (current-time-string
2061 (let* ((e (parse-time-string date))
2062 (tm (apply 'encode-time e))
2064 (ls (- (cadr tm) (car (current-time-zone time)))))
2065 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2066 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2069 ;; Get the original date from the article.
2070 ((eq type 'original)
2071 (concat "Date: " (if (string-match "\n+$" date)
2072 (substring date 0 (match-beginning 0))
2074 ;; Let the user define the format.
2076 (if (gnus-functionp gnus-article-time-format)
2077 (funcall gnus-article-time-format time)
2080 (format-time-string gnus-article-time-format time))))
2085 (format-time-string "%Y%m%dT%H%M%S" time)))
2086 ;; Do an X-Sent lapsed format.
2088 ;; If the date is seriously mangled, the timezone functions are
2089 ;; liable to bug out, so we ignore all errors.
2090 (let* ((now (current-time))
2091 (real-time (subtract-time now time))
2092 (real-sec (and real-time
2093 (+ (* (float (car real-time)) 65536)
2095 (sec (and real-time (abs real-sec)))
2105 ;; This is a bit convoluted, but basically we go
2106 ;; through the time units for years, weeks, etc,
2107 ;; and divide things to see whether that results
2108 ;; in positive answers.
2111 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2112 ;; The (remaining) seconds are too few to
2113 ;; be divided into this time unit.
2115 ;; It's big enough, so we output it.
2116 (setq sec (- sec (* num (cdr unit))))
2118 (concat (if prev ", " "") (int-to-string
2120 " " (symbol-name (car unit))
2121 (if (> num 1) "s" ""))
2123 article-time-units "")
2124 ;; If dates are odd, then it might appear like the
2125 ;; article was sent in the future.
2128 " in the future"))))))
2130 (error "Unknown conversion type: %s" type)))))
2132 (defun article-date-local (&optional highlight)
2133 "Convert the current article date to the local timezone."
2134 (interactive (list t))
2135 (article-date-ut 'local highlight))
2137 (defun article-date-original (&optional highlight)
2138 "Convert the current article date to what it was originally.
2139 This is only useful if you have used some other date conversion
2140 function and want to see what the date was before converting."
2141 (interactive (list t))
2142 (article-date-ut 'original highlight))
2144 (defun article-date-lapsed (&optional highlight)
2145 "Convert the current article date to time lapsed since it was sent."
2146 (interactive (list t))
2147 (article-date-ut 'lapsed highlight))
2149 (defun article-update-date-lapsed ()
2150 "Function to be run from a timer to update the lapsed time line."
2151 (let (deactivate-mark)
2156 (set-buffer (window-buffer w))
2157 (when (eq major-mode 'gnus-article-mode)
2158 (goto-char (point-min))
2159 (when (re-search-forward "^X-Sent:" nil t)
2160 (article-date-lapsed t))))
2163 (defun gnus-start-date-timer (&optional n)
2164 "Start a timer to update the X-Sent header in the article buffers.
2165 The numerical prefix says how frequently (in seconds) the function
2170 (gnus-stop-date-timer)
2171 (setq article-lapsed-timer
2172 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2174 (defun gnus-stop-date-timer ()
2175 "Stop the X-Sent timer."
2177 (when article-lapsed-timer
2178 (nnheader-cancel-timer article-lapsed-timer)
2179 (setq article-lapsed-timer nil)))
2181 (defun article-date-user (&optional highlight)
2182 "Convert the current article date to the user-defined format.
2183 This format is defined by the `gnus-article-time-format' variable."
2184 (interactive (list t))
2185 (article-date-ut 'user highlight))
2187 (defun article-date-iso8601 (&optional highlight)
2188 "Convert the current article date to ISO8601."
2189 (interactive (list t))
2190 (article-date-ut 'iso8601 highlight))
2192 (defun article-show-all ()
2193 "Show all hidden text in the article buffer."
2197 (let ((buffer-read-only nil))
2198 (gnus-article-unhide-text (point-min) (point-max))
2199 (gnus-remove-text-with-property 'gnus-prev)
2200 (gnus-remove-text-with-property 'gnus-next))))
2202 (defun article-show-all-headers ()
2203 "Show all hidden headers in the article buffer."
2208 (article-narrow-to-head)
2209 (let ((buffer-read-only nil))
2210 (gnus-article-unhide-text (point-min) (point-max))))))
2212 (defun article-emphasize (&optional arg)
2213 "Emphasize text according to `gnus-emphasis-alist'."
2214 (interactive (gnus-article-hidden-arg))
2215 (unless (gnus-article-check-hidden-text 'emphasis arg)
2217 (let ((alist (or (with-current-buffer gnus-summary-buffer
2218 gnus-article-emphasis-alist)
2219 gnus-emphasis-alist))
2220 (buffer-read-only nil)
2221 (props (append '(article-type emphasis)
2222 gnus-hidden-properties))
2223 regexp elem beg invisible visible face)
2226 (while (setq elem (pop alist))
2228 (setq regexp (car elem)
2229 invisible (nth 1 elem)
2230 visible (nth 2 elem)
2232 (while (re-search-forward regexp nil t)
2233 (when (and (match-beginning visible) (match-beginning invisible))
2234 (gnus-article-hide-text
2235 (match-beginning invisible) (match-end invisible) props)
2236 (gnus-article-unhide-text-type
2237 (match-beginning visible) (match-end visible) 'emphasis)
2238 (gnus-put-text-property-excluding-newlines
2239 (match-beginning visible) (match-end visible) 'face face)
2240 (goto-char (match-end invisible)))))))))
2242 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2243 "Setup newsgroup emphasis alist."
2244 (unless gnus-article-emphasis-alist
2245 (let ((name (and gnus-newsgroup-name
2246 (gnus-group-real-name gnus-newsgroup-name))))
2247 (make-local-variable 'gnus-article-emphasis-alist)
2248 (setq gnus-article-emphasis-alist
2250 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2251 (while (setq elem (pop alist))
2252 (when (and name (string-match (car elem) name))
2254 highlight (copy-list (cdr elem)))))
2256 (copy-list highlight-words)
2257 (if gnus-newsgroup-name
2258 (copy-list (gnus-group-find-parameter
2259 gnus-newsgroup-name 'highlight-words t)))
2260 gnus-emphasis-alist)))))
2262 (defvar gnus-summary-article-menu)
2263 (defvar gnus-summary-post-menu)
2265 ;;; Saving functions.
2267 (defun gnus-article-save (save-buffer file &optional num)
2268 "Save the currently selected article."
2269 (unless gnus-save-all-headers
2270 ;; Remove headers according to `gnus-saved-headers'.
2271 (let ((gnus-visible-headers
2272 (or gnus-saved-headers gnus-visible-headers))
2273 (gnus-article-buffer save-buffer))
2275 (set-buffer save-buffer)
2276 (article-hide-headers 1 t))))
2277 (save-window-excursion
2278 (if (not gnus-default-article-saver)
2279 (error "No default saver is defined")
2280 ;; !!! Magic! The saving functions all save
2281 ;; `gnus-save-article-buffer' (or so they think), but we
2282 ;; bind that variable to our save-buffer.
2283 (set-buffer gnus-article-buffer)
2284 (let* ((gnus-save-article-buffer save-buffer)
2287 ((not gnus-prompt-before-saving) 'default)
2288 ((eq gnus-prompt-before-saving 'always) nil)
2290 (gnus-number-of-articles-to-be-saved
2291 (when (eq gnus-prompt-before-saving t)
2293 (set-buffer gnus-article-current-summary)
2294 (funcall gnus-default-article-saver filename)))))
2296 (defun gnus-read-save-file-name (prompt &optional filename
2297 function group headers variable)
2299 (funcall function group headers (symbol-value variable)))
2304 ((eq filename 'default)
2310 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2313 (if (and gnus-number-of-articles-to-be-saved
2314 (> gnus-number-of-articles-to-be-saved 1))
2315 (format "these %d articles"
2316 gnus-number-of-articles-to-be-saved)
2319 ;; Let the split methods have their say.
2321 ;; No split name was found.
2324 (concat prompt " (default "
2325 (file-name-nondirectory default-name) ") ")
2326 (file-name-directory default-name)
2328 ;; A single group name is returned.
2329 ((stringp split-name)
2331 (funcall function split-name headers
2332 (symbol-value variable)))
2334 (concat prompt " (default "
2335 (file-name-nondirectory default-name) ") ")
2336 (file-name-directory default-name)
2338 ;; A single split name was found
2339 ((= 1 (length split-name))
2340 (let* ((name (expand-file-name
2341 (car split-name) gnus-article-save-directory))
2342 (dir (cond ((file-directory-p name)
2343 (file-name-as-directory name))
2344 ((file-exists-p name) name)
2345 (t gnus-article-save-directory))))
2347 (concat prompt " (default " name ") ")
2349 ;; A list of splits was found.
2351 (setq split-name (nreverse split-name))
2353 (let ((file-name-history
2354 (nconc split-name file-name-history)))
2358 (concat prompt " (`M-p' for defaults) ")
2359 gnus-article-save-directory
2361 gnus-article-save-directory)))
2362 (car (push result file-name-history)))))))
2363 ;; Create the directory.
2364 (gnus-make-directory (file-name-directory file))
2365 ;; If we have read a directory, we append the default file name.
2366 (when (file-directory-p file)
2367 (setq file (concat (file-name-as-directory file)
2368 (file-name-nondirectory default-name))))
2369 ;; Possibly translate some characters.
2370 (nnheader-translate-file-chars file)))))
2371 (gnus-make-directory (file-name-directory result))
2372 (set variable result)))
2374 (defun gnus-article-archive-name (group)
2375 "Return the first instance of an \"Archive-name\" in the current buffer."
2376 (let ((case-fold-search t))
2377 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2378 (nnheader-concat gnus-article-save-directory
2379 (match-string 1)))))
2381 (defun gnus-article-nndoc-name (group)
2382 "If GROUP is an nndoc group, return the name of the parent group."
2383 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2384 (gnus-group-get-parameter group 'save-article-group)))
2386 (defun gnus-summary-save-in-rmail (&optional filename)
2387 "Append this article to Rmail file.
2388 Optional argument FILENAME specifies file name.
2389 Directory to save to is default to `gnus-article-save-directory'."
2390 (setq filename (gnus-read-save-file-name
2391 "Save %s in rmail file:" filename
2392 gnus-rmail-save-name gnus-newsgroup-name
2393 gnus-current-headers 'gnus-newsgroup-last-rmail))
2394 (gnus-eval-in-buffer-window gnus-save-article-buffer
2398 (gnus-output-to-rmail filename))))
2401 (defun gnus-summary-save-in-mail (&optional filename)
2402 "Append this article to Unix mail file.
2403 Optional argument FILENAME specifies file name.
2404 Directory to save to is default to `gnus-article-save-directory'."
2405 (setq filename (gnus-read-save-file-name
2406 "Save %s in Unix mail file:" filename
2407 gnus-mail-save-name gnus-newsgroup-name
2408 gnus-current-headers 'gnus-newsgroup-last-mail))
2409 (gnus-eval-in-buffer-window gnus-save-article-buffer
2413 (if (and (file-readable-p filename)
2414 (mail-file-babyl-p filename))
2415 (rmail-output-to-rmail-file filename t)
2416 (gnus-output-to-mail filename)))))
2419 (defun gnus-summary-save-in-file (&optional filename overwrite)
2420 "Append this article to file.
2421 Optional argument FILENAME specifies file name.
2422 Directory to save to is default to `gnus-article-save-directory'."
2423 (setq filename (gnus-read-save-file-name
2424 "Save %s in file:" filename
2425 gnus-file-save-name gnus-newsgroup-name
2426 gnus-current-headers 'gnus-newsgroup-last-file))
2427 (gnus-eval-in-buffer-window gnus-save-article-buffer
2431 (when (and overwrite
2432 (file-exists-p filename))
2433 (delete-file filename))
2434 (gnus-output-to-file filename))))
2437 (defun gnus-summary-write-to-file (&optional filename)
2438 "Write this article to a file.
2439 Optional argument FILENAME specifies file name.
2440 The directory to save in defaults to `gnus-article-save-directory'."
2441 (gnus-summary-save-in-file nil t))
2443 (defun gnus-summary-save-body-in-file (&optional filename)
2444 "Append this article body to a file.
2445 Optional argument FILENAME specifies file name.
2446 The directory to save in defaults to `gnus-article-save-directory'."
2447 (setq filename (gnus-read-save-file-name
2448 "Save %s body in file:" filename
2449 gnus-file-save-name gnus-newsgroup-name
2450 gnus-current-headers 'gnus-newsgroup-last-file))
2451 (gnus-eval-in-buffer-window gnus-save-article-buffer
2455 (when (article-goto-body)
2456 (narrow-to-region (point) (point-max)))
2457 (gnus-output-to-file filename))))
2460 (defun gnus-summary-save-in-pipe (&optional command)
2461 "Pipe this article to subprocess."
2463 (cond ((and (eq command 'default)
2464 gnus-last-shell-command)
2465 gnus-last-shell-command)
2469 "Shell command on %s: "
2470 (if (and gnus-number-of-articles-to-be-saved
2471 (> gnus-number-of-articles-to-be-saved 1))
2472 (format "these %d articles"
2473 gnus-number-of-articles-to-be-saved)
2475 gnus-last-shell-command))))
2476 (when (string-equal command "")
2477 (setq command gnus-last-shell-command))
2478 (gnus-eval-in-buffer-window gnus-article-buffer
2481 (shell-command-on-region (point-min) (point-max) command nil)))
2482 (setq gnus-last-shell-command command))
2484 ;;; Article file names when saving.
2486 (defun gnus-capitalize-newsgroup (newsgroup)
2487 "Capitalize NEWSGROUP name."
2488 (when (not (zerop (length newsgroup)))
2489 (concat (char-to-string (upcase (aref newsgroup 0)))
2490 (substring newsgroup 1))))
2492 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2493 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2494 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2495 Otherwise, it is like ~/News/news/group/num."
2498 (concat (if (gnus-use-long-file-name 'not-save)
2499 (gnus-capitalize-newsgroup newsgroup)
2500 (gnus-newsgroup-directory-form newsgroup))
2501 "/" (int-to-string (mail-header-number headers)))
2502 gnus-article-save-directory)))
2504 (string-equal (file-name-directory default)
2505 (file-name-directory last-file))
2506 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2508 (or last-file default))))
2510 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2511 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2512 If variable `gnus-use-long-file-name' is non-nil, it is
2513 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2516 (concat (if (gnus-use-long-file-name 'not-save)
2518 (gnus-newsgroup-directory-form newsgroup))
2519 "/" (int-to-string (mail-header-number headers)))
2520 gnus-article-save-directory)))
2522 (string-equal (file-name-directory default)
2523 (file-name-directory last-file))
2524 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2526 (or last-file default))))
2528 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2529 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2530 If variable `gnus-use-long-file-name' is non-nil, it is
2531 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2534 (if (gnus-use-long-file-name 'not-save)
2535 (gnus-capitalize-newsgroup newsgroup)
2536 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2537 gnus-article-save-directory)))
2539 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2540 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2541 If variable `gnus-use-long-file-name' is non-nil, it is
2542 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2545 (if (gnus-use-long-file-name 'not-save)
2547 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2548 gnus-article-save-directory)))
2555 (setq afunc (car func)
2558 gfunc (intern (format "gnus-%s" func))))
2560 (if (not (fboundp afunc))
2562 `(lambda (&optional interactive &rest args)
2563 ,(documentation afunc t)
2564 (interactive (list t))
2566 (set-buffer gnus-article-buffer)
2568 (call-interactively ',afunc)
2569 (apply ',afunc args))))))))
2570 '(article-hide-headers
2571 article-hide-boring-headers
2572 article-toggle-headers
2573 article-treat-overstrike
2574 article-fill-long-lines
2575 article-capitalize-sentences
2577 article-display-x-face
2578 article-de-quoted-unreadable
2579 article-hide-list-identifiers
2581 article-strip-banner
2584 article-hide-signature
2585 article-strip-headers-in-body
2586 article-remove-trailing-blank-lines
2587 article-strip-leading-blank-lines
2588 article-strip-multiple-blank-lines
2589 article-strip-leading-space
2590 article-strip-trailing-space
2591 article-strip-blank-lines
2592 article-strip-all-blank-lines
2594 article-date-iso8601
2595 article-date-original
2597 article-decode-mime-words
2598 article-decode-charset
2599 article-decode-encoded-words
2603 article-treat-dumbquotes
2604 article-normalize-headers
2605 (article-show-all-headers . gnus-article-show-all-headers)
2606 (article-show-all . gnus-article-show-all))))
2609 ;;; Gnus article mode
2612 (put 'gnus-article-mode 'mode-class 'special)
2614 (gnus-define-keys gnus-article-mode-map
2615 " " gnus-article-goto-next-page
2616 "\177" gnus-article-goto-prev-page
2617 [delete] gnus-article-goto-prev-page
2618 [backspace] gnus-article-goto-prev-page
2619 "\C-c^" gnus-article-refer-article
2620 "h" gnus-article-show-summary
2621 "s" gnus-article-show-summary
2622 "\C-c\C-m" gnus-article-mail
2623 "?" gnus-article-describe-briefly
2624 gnus-mouse-2 gnus-article-push-button
2625 "\r" gnus-article-press-button
2626 "\t" gnus-article-next-button
2627 "\M-\t" gnus-article-prev-button
2628 "e" gnus-article-edit
2629 "<" beginning-of-buffer
2631 "\C-c\C-i" gnus-info-find-node
2634 "\C-d" gnus-article-read-summary-keys
2635 "\M-*" gnus-article-read-summary-keys
2636 "\M-#" gnus-article-read-summary-keys
2637 "\M-^" gnus-article-read-summary-keys
2638 "\M-g" gnus-article-read-summary-keys)
2640 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2643 (unless (lookup-key gnus-article-mode-map key)
2644 (define-key gnus-article-mode-map key
2645 'gnus-article-read-summary-keys)))
2650 (let ((key (car elt)))
2651 (and (> (length key) 0)
2652 (not (eq 'menu-bar (aref key 0)))
2653 (symbolp (lookup-key gnus-summary-mode-map key))
2655 (accessible-keymaps gnus-summary-mode-map))
2659 (push (char-to-string c) keys)
2663 (defun gnus-article-make-menu-bar ()
2664 (gnus-turn-off-edit-menu 'article)
2665 (unless (boundp 'gnus-article-article-menu)
2667 gnus-article-article-menu gnus-article-mode-map ""
2669 ["Scroll forwards" gnus-article-goto-next-page t]
2670 ["Scroll backwards" gnus-article-goto-prev-page t]
2671 ["Show summary" gnus-article-show-summary t]
2672 ["Fetch Message-ID at point" gnus-article-refer-article t]
2673 ["Mail to address at point" gnus-article-mail t]
2674 ["Send a bug report" gnus-bug t]))
2677 gnus-article-treatment-menu gnus-article-mode-map ""
2679 ["Hide headers" gnus-article-toggle-headers t]
2680 ["Hide signature" gnus-article-hide-signature t]
2681 ["Hide citation" gnus-article-hide-citation t]
2682 ["Treat overstrike" gnus-article-treat-overstrike t]
2683 ["Remove carriage return" gnus-article-remove-cr t]))
2685 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2687 (when (boundp 'gnus-summary-post-menu)
2688 (define-key gnus-article-mode-map [menu-bar post]
2689 (cons "Post" gnus-summary-post-menu)))
2691 (gnus-run-hooks 'gnus-article-menu-hook)))
2693 (defun gnus-article-mode ()
2694 "Major mode for displaying an article.
2696 All normal editing commands are switched off.
2698 The following commands are available in addition to all summary mode
2700 \\<gnus-article-mode-map>
2701 \\[gnus-article-next-page]\t Scroll the article one page forwards
2702 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2703 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2704 \\[gnus-article-show-summary]\t Display the summary buffer
2705 \\[gnus-article-mail]\t Send a reply to the address near point
2706 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2707 \\[gnus-info-find-node]\t Go to the Gnus info node"
2709 (when (gnus-visual-p 'article-menu 'menu)
2710 (gnus-article-make-menu-bar))
2711 (gnus-simplify-mode-line)
2712 (setq mode-name "Article")
2713 (setq major-mode 'gnus-article-mode)
2714 (make-local-variable 'minor-mode-alist)
2715 (unless (assq 'gnus-show-mime minor-mode-alist)
2716 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2717 (use-local-map gnus-article-mode-map)
2718 (gnus-update-format-specifications nil 'article-mode)
2719 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2720 (make-local-variable 'gnus-page-broken)
2721 (make-local-variable 'gnus-button-marker-list)
2722 (make-local-variable 'gnus-article-current-summary)
2723 (make-local-variable 'gnus-article-mime-handles)
2724 (make-local-variable 'gnus-article-decoded-p)
2725 (make-local-variable 'gnus-article-mime-handle-alist)
2726 (make-local-variable 'gnus-article-washed-types)
2727 (gnus-set-default-directory)
2728 (buffer-disable-undo)
2729 (setq buffer-read-only t)
2730 (set-syntax-table gnus-article-mode-syntax-table)
2731 (gnus-run-hooks 'gnus-article-mode-hook))
2733 (defun gnus-article-setup-buffer ()
2734 "Initialize the article buffer."
2735 (let* ((name (if gnus-single-article-buffer "*Article*"
2736 (concat "*Article " gnus-newsgroup-name "*")))
2738 (progn (string-match "\\*Article" name)
2739 (concat " *Original Article"
2740 (substring name (match-end 0))))))
2741 (setq gnus-article-buffer name)
2742 (setq gnus-original-article-buffer original)
2743 (setq gnus-article-mime-handle-alist nil)
2744 ;; This might be a variable local to the summary buffer.
2745 (unless gnus-single-article-buffer
2747 (set-buffer gnus-summary-buffer)
2748 (setq gnus-article-buffer name)
2749 (setq gnus-original-article-buffer original)
2750 (gnus-set-global-variables)))
2751 (gnus-article-setup-highlight-words)
2752 ;; Init original article buffer.
2754 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2755 (setq major-mode 'gnus-original-article-mode)
2756 (make-local-variable 'gnus-original-article))
2757 (if (get-buffer name)
2760 (kill-all-local-variables)
2761 (buffer-disable-undo)
2762 (setq buffer-read-only t)
2763 (unless (eq major-mode 'gnus-article-mode)
2764 (gnus-article-mode))
2767 (set-buffer (gnus-get-buffer-create name))
2769 (make-local-variable 'gnus-summary-buffer)
2770 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2771 (current-buffer)))))
2773 ;; Set article window start at LINE, where LINE is the number of lines
2774 ;; from the head of the article.
2775 (defun gnus-article-set-window-start (&optional line)
2777 (get-buffer-window gnus-article-buffer t)
2779 (set-buffer gnus-article-buffer)
2780 (goto-char (point-min))
2783 (gnus-message 6 "Moved to bookmark")
2784 (search-forward "\n\n" nil t)
2788 ;;; @@ article filters
2791 (defun gnus-article-display-mime-message ()
2792 "Article display method for MIME message."
2793 ;; called from `gnus-original-article-buffer'.
2794 (let (charset all-headers)
2795 (with-current-buffer gnus-summary-buffer
2796 (setq charset default-mime-charset
2797 all-headers gnus-have-all-headers))
2798 (make-local-variable 'default-mime-charset)
2799 (setq default-mime-charset charset)
2800 (with-current-buffer (get-buffer-create gnus-article-buffer)
2801 (make-local-variable 'default-mime-charset)
2802 (setq default-mime-charset charset))
2803 (mime-display-message mime-message-structure
2804 gnus-article-buffer nil gnus-article-mode-map)
2806 (gnus-article-hide-headers nil -1))
2808 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2809 (make-local-variable 'mime-button-mother-dispatcher)
2810 (setq mime-button-mother-dispatcher
2811 (function gnus-article-push-button))
2812 (run-hooks 'gnus-mime-article-prepare-hook))
2814 (defun gnus-article-display-traditional-message ()
2815 "Article display method for traditional message."
2816 (set-buffer gnus-article-buffer)
2817 (let (buffer-read-only)
2819 (insert-buffer-substring gnus-original-article-buffer)))
2821 (defun gnus-article-make-full-mail-header (&optional number charset)
2822 "Create a new mail header structure in a raw article buffer."
2823 (unless (and number charset)
2824 (save-current-buffer
2825 (set-buffer gnus-summary-buffer)
2827 (setq number (or (cdr gnus-article-current) 0)))
2829 (setq charset (or default-mime-charset 'x-ctext)))))
2830 (goto-char (point-min))
2831 (let ((header-end (if (search-forward "\n\n" nil t)
2833 (goto-char (point-max))))
2834 (chars (- (point-max) (point)))
2835 (lines (count-lines (point) (point-max)))
2836 (default-mime-charset charset)
2838 (narrow-to-region (point-min) header-end)
2839 (setq xref (std11-fetch-field "xref"))
2841 (make-full-mail-header
2843 (std11-fetch-field "subject")
2844 (std11-fetch-field "from")
2845 (std11-fetch-field "date")
2846 (std11-fetch-field "message-id")
2847 (std11-fetch-field "references")
2850 (when xref (concat "Xref: " xref)))
2853 (defun gnus-article-prepare (article &optional all-headers header)
2854 "Prepare ARTICLE in article mode buffer.
2855 ARTICLE should either be an article number or a Message-ID.
2856 If ARTICLE is an id, HEADER should be the article headers.
2857 If ALL-HEADERS is non-nil, no headers are hidden."
2859 ;; Make sure we start in a summary buffer.
2860 (unless (eq major-mode 'gnus-summary-mode)
2861 (set-buffer gnus-summary-buffer))
2862 (setq gnus-summary-buffer (current-buffer))
2863 (let* ((gnus-article (if header (mail-header-number header) article))
2864 (summary-buffer (current-buffer))
2865 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2866 (group gnus-newsgroup-name)
2869 (gnus-article-setup-buffer)
2870 (set-buffer gnus-original-article-buffer)
2871 ;; Deactivate active regions.
2872 (when (and (boundp 'transient-mark-mode)
2873 transient-mark-mode)
2874 (setq mark-active nil))
2875 (if (not (setq result (let ((buffer-read-only nil))
2876 (gnus-request-article-this-buffer
2878 ;; There is no such article.
2880 (when (and (numberp article)
2881 (not (memq article gnus-newsgroup-sparse)))
2882 (setq gnus-article-current
2883 (cons gnus-newsgroup-name article))
2884 (set-buffer gnus-summary-buffer)
2885 (setq gnus-current-article article)
2886 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2888 (gnus-summary-set-agent-mark article)
2889 (message "Message marked for downloading"))
2890 (gnus-summary-mark-article article gnus-canceled-mark)
2891 (unless (memq article gnus-newsgroup-sparse)
2893 "No such article (may have expired or been canceled)")))))
2894 (if (or (eq result 'pseudo)
2895 (eq result 'nneething))
2898 (set-buffer summary-buffer)
2899 (push article gnus-newsgroup-history)
2900 (setq gnus-last-article gnus-current-article
2901 gnus-current-article 0
2902 gnus-current-headers nil
2903 gnus-article-current nil)
2904 (if (eq result 'nneething)
2905 (gnus-configure-windows 'summary)
2906 (gnus-configure-windows 'article))
2907 (gnus-set-global-variables))
2908 (let ((gnus-article-mime-handle-alist-1
2909 gnus-article-mime-handle-alist))
2910 (gnus-set-mode-line 'article)))
2911 ;; The result from the `request' was an actual article -
2912 ;; or at least some text that is now displayed in the
2914 (when (and (numberp article)
2915 (not (eq article gnus-current-article)))
2916 ;; Seems like a new article has been selected.
2917 ;; `gnus-current-article' must be an article number.
2919 (set-buffer summary-buffer)
2920 (push article gnus-newsgroup-history)
2921 (setq gnus-last-article gnus-current-article
2922 gnus-current-article article
2923 gnus-current-headers
2924 (gnus-summary-article-header gnus-current-article)
2925 gnus-article-current
2926 (cons gnus-newsgroup-name gnus-current-article))
2927 (unless (vectorp gnus-current-headers)
2928 (setq gnus-current-headers nil))
2929 (gnus-summary-goto-subject gnus-current-article)
2930 (when (gnus-summary-show-thread)
2931 ;; If the summary buffer really was folded, the
2932 ;; previous goto may not actually have gone to
2933 ;; the right article, but the thread root instead.
2935 (gnus-summary-goto-subject gnus-current-article))
2936 (gnus-run-hooks 'gnus-mark-article-hook)
2937 (gnus-set-mode-line 'summary)
2938 (when (gnus-visual-p 'article-highlight 'highlight)
2939 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2940 ;; Set the global newsgroup variables here.
2941 (gnus-set-global-variables)
2942 (setq gnus-have-all-headers
2943 (or all-headers gnus-show-all-headers))))
2944 (when (or (numberp article)
2946 (gnus-article-prepare-display)
2948 (goto-char (point-min))
2949 (setq gnus-page-broken
2950 (when gnus-break-pages
2951 (gnus-narrow-to-page)
2953 (let ((gnus-article-mime-handle-alist-1
2954 gnus-article-mime-handle-alist))
2955 (gnus-set-mode-line 'article))
2957 (set-window-point (get-buffer-window (current-buffer)) (point))
2958 (gnus-configure-windows 'article)
2961 (defun gnus-article-prepare-mime-display (&optional number)
2962 (goto-char (point-min))
2963 (when (re-search-forward "^[^\t ]+:" nil t)
2964 (goto-char (match-beginning 0)))
2965 (let ((entity (if (eq 1 (point-min))
2966 (get-text-property 1 'mime-view-entity)
2967 (get-text-property (point) 'mime-view-entity)))
2968 last-entity child-entity next type)
2969 (setq child-entity (mime-entity-children entity))
2971 (setq last-entity (nth (1- (length child-entity))
2973 (setq last-entity entity))
2975 (narrow-to-region (point)
2976 (if (search-forward "\n\n" nil t)
2979 (gnus-treat-article 'head)
2980 (put-text-property (point-min) (point-max) 'article-treated-header t)
2981 (goto-char (point-max)))
2982 (while (and (not (eobp))
2987 (or (next-single-property-change (point)
2990 (let ((types (mime-entity-content-type entity)))
2991 (while (eq 'multipart (mime-content-type-primary-type types))
2992 (setq entity (car (mime-entity-children entity))
2993 types (mime-entity-content-type entity)))
2995 (setq type (format "%s/%s"
2996 (mime-content-type-primary-type types)
2997 (mime-content-type-subtype types)))))
2998 (if (string-equal type "message/rfc822")
3001 (let ((children (mime-entity-children entity))
3004 (setq last-children (nth (1- (length children)) children))
3007 (not (eq last-children
3008 (get-text-property next 'mime-view-entity)))
3010 (next-single-property-change next
3011 'mime-view-entity))))))
3012 (setq next (or (next-single-property-change next 'mime-view-entity)
3015 (narrow-to-region (point) next)
3016 (gnus-article-prepare-mime-display)
3017 (goto-char (point-max)))
3018 (setq entity (get-text-property (point) 'mime-view-entity)))
3020 (narrow-to-region (point) next)
3021 ;; Kludge. We have to count true number, but for now,
3022 ;; part number is here only to achieve `last'.
3023 (gnus-treat-article nil 1
3024 (if (eq entity last-entity)
3027 (setq entity (get-text-property next 'mime-view-entity))
3028 (goto-char (point-max)))))))
3031 (defun gnus-article-prepare-display ()
3032 "Make the current buffer look like a nice article."
3033 (setq gnus-article-wash-types nil)
3034 (gnus-run-hooks 'gnus-tmp-internal-hook)
3035 (gnus-run-hooks 'gnus-article-prepare-hook)
3037 (let (mime-display-header-hook mime-display-text/plain-hook)
3038 (funcall (if gnus-show-mime
3040 (setq mime-message-structure gnus-current-headers)
3041 (mime-buffer-entity-set-buffer-internal
3042 mime-message-structure
3043 gnus-original-article-buffer)
3044 (mime-entity-set-representation-type-internal
3045 mime-message-structure 'mime-buffer-entity)
3046 (luna-send mime-message-structure
3047 'initialize-instance
3048 mime-message-structure)
3049 gnus-article-display-method-for-mime)
3050 gnus-article-display-method-for-traditional)))
3051 ;; Associate this article with the current summary buffer.
3052 (setq gnus-article-current-summary gnus-summary-buffer)
3053 ;; Call the treatment functions.
3054 (let ((inhibit-read-only t)
3059 (gnus-article-prepare-mime-display)
3060 (narrow-to-region (goto-char (point-min))
3061 (if (search-forward "\n\n" nil t)
3064 (gnus-treat-article 'head)
3065 (put-text-property (point-min) (point-max) 'article-treated-header t)
3066 (goto-char (point-max))
3068 (narrow-to-region (point) (point-max))
3069 (gnus-treat-article nil))
3070 (put-text-property (point-min) (point-max) 'read-only nil)))
3071 ;; Perform the article display hooks. Incidentally, this hook is
3072 ;; an obsolete variable by now.
3073 (gnus-run-hooks 'gnus-article-display-hook))
3075 (defun gnus-article-decode-article-as-default-mime-charset ()
3076 "Decode an article as `default-mime-charset'. It won't work if the
3077 value of the variable `gnus-show-mime' is non-nil."
3078 (unless gnus-show-mime
3079 (decode-mime-charset-region (point-min) (point-max)
3080 (with-current-buffer gnus-summary-buffer
3081 default-mime-charset))))
3084 ;;; Gnus MIME viewing functions
3087 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3088 "The following specs can be used:
3090 %T MIME type, along with additional info
3091 %n The `name' parameter
3092 %d The description, if any
3093 %l The length of the encoded part
3094 %p The part identifier number
3095 %e Dots if the part isn't displayed")
3097 (defvar gnus-mime-button-line-format-alist
3098 '((?t gnus-tmp-type ?s)
3099 (?T gnus-tmp-type-long ?s)
3100 (?n gnus-tmp-name ?s)
3101 (?d gnus-tmp-description ?s)
3103 (?l gnus-tmp-length ?d)
3104 (?e gnus-tmp-dots ?s)))
3106 (defvar gnus-mime-button-commands
3107 '((gnus-article-press-button "\r" "Toggle Display")
3108 (gnus-mime-view-part "v" "View Interactively...")
3109 (gnus-mime-view-part-as-type "t" "View As Type...")
3110 (gnus-mime-save-part "o" "Save...")
3111 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3112 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3113 (gnus-mime-internalize-part "E" "View Internally")
3114 (gnus-mime-externalize-part "e" "View Externally")
3115 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3117 (defun gnus-article-mime-part-status ()
3118 (with-current-buffer gnus-article-buffer
3119 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3120 (if (and entity (mime-entity-children entity))
3121 (format " (%d parts)" (length (mime-entity-children entity)))
3124 (defvar gnus-mime-button-map nil)
3125 (unless gnus-mime-button-map
3126 (setq gnus-mime-button-map (make-sparse-keymap))
3127 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3128 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3129 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3131 (define-key gnus-mime-button-map (cadr c) (car c)))
3132 gnus-mime-button-commands))
3134 (defun gnus-mime-button-menu (event)
3135 "Construct a context-sensitive menu of MIME commands."
3138 (let ((pos (event-start event)))
3139 (set-buffer (window-buffer (posn-window pos)))
3140 (goto-char (posn-point pos))
3141 (gnus-article-check-buffer)
3142 (let ((response (x-popup-menu
3144 ("" ,@(mapcar (lambda (c)
3145 (cons (caddr c) (car c)))
3146 gnus-mime-button-commands))))))
3148 (funcall response))))))
3150 (defun gnus-mime-view-all-parts (&optional handles)
3151 "View all the MIME parts."
3153 (save-current-buffer
3154 (set-buffer gnus-article-buffer)
3155 (let ((handles (or handles gnus-article-mime-handles))
3156 (mail-parse-charset gnus-newsgroup-charset)
3157 (mail-parse-ignored-charsets
3158 (save-excursion (set-buffer gnus-summary-buffer)
3159 gnus-newsgroup-ignored-charsets)))
3160 (if (stringp (car handles))
3161 (gnus-mime-view-all-parts (cdr handles))
3162 (mapcar 'mm-display-part handles)))))
3164 (defun gnus-mime-save-part ()
3165 "Save the MIME part under point."
3167 (gnus-article-check-buffer)
3168 (let ((data (get-text-property (point) 'gnus-data)))
3169 (mm-save-part data)))
3171 (defun gnus-mime-pipe-part ()
3172 "Pipe the MIME part under point to a process."
3174 (gnus-article-check-buffer)
3175 (let ((data (get-text-property (point) 'gnus-data)))
3176 (mm-pipe-part data)))
3178 (defun gnus-mime-view-part ()
3179 "Interactively choose a viewing method for the MIME part under point."
3181 (gnus-article-check-buffer)
3182 (let ((data (get-text-property (point) 'gnus-data)))
3183 (mm-interactively-view-part data)))
3185 (defun gnus-mime-view-part-as-type ()
3186 "Choose a MIME media type, and view the part as such."
3188 (list (completing-read "View as MIME type: " mailcap-mime-types)))
3189 (gnus-article-check-buffer)
3190 (let ((handle (get-text-property (point) 'gnus-data)))
3191 (gnus-mm-display-part handle)))
3193 (defun gnus-mime-copy-part (&optional handle)
3194 "Put the the MIME part under point into a new buffer."
3196 (gnus-article-check-buffer)
3197 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3198 (contents (mm-get-part handle))|
3199 (base (file-name-nondirectory
3201 (mail-content-type-get (mm-handle-type handle) 'name)
3202 (mail-content-type-get (mm-handle-type handle)
3205 (buffer (generate-new-buffer base)))
3206 (switch-to-buffer buffer)
3208 ;; We do it this way to make `normal-mode' set the appropriate mode.
3211 (setq buffer-file-name (expand-file-name base))
3213 (setq buffer-file-name nil))
3214 (goto-char (point-min))))
3216 (defun gnus-mime-inline-part (&optional handle)
3217 "Insert the MIME part under point into the current buffer."
3219 (gnus-article-check-buffer)
3220 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3224 (if (mm-handle-undisplayer handle)
3225 (mm-remove-part handle)
3226 (setq contents (mm-get-part handle))
3228 (mm-insert-inline handle contents)
3231 (defun gnus-mime-externalize-part (&optional handle)
3232 "View the MIME part under point with an external viewer."
3234 (gnus-article-check-buffer)
3235 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3236 (mm-user-display-methods nil)
3237 (mm-inline-large-images nil)
3238 (mail-parse-charset gnus-newsgroup-charset)
3239 (mail-parse-ignored-charsets
3240 (save-excursion (set-buffer gnus-summary-buffer)
3241 gnus-newsgroup-ignored-charsets)))
3242 (if (mm-handle-undisplayer handle)
3243 (mm-remove-part handle)
3244 (mm-display-part handle))))
3246 (defun gnus-mime-internalize-part (&optional handle)
3247 "View the MIME part under point with an internal viewer."
3249 (gnus-article-check-buffer)
3250 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3251 (mm-user-display-methods '((".*" . inline)))
3252 (mm-inline-large-images t)
3253 (mail-parse-charset gnus-newsgroup-charset)
3254 (mail-parse-ignored-charsets
3255 (save-excursion (set-buffer gnus-summary-buffer)
3256 gnus-newsgroup-ignored-charsets)))
3257 (if (mm-handle-undisplayer handle)
3258 (mm-remove-part handle)
3259 (mm-display-part handle))))
3261 (defun gnus-article-part-wrapper (n function)
3262 (save-current-buffer
3263 (set-buffer gnus-article-buffer)
3264 (when (> n (length gnus-article-mime-handle-alist))
3265 (error "No such part"))
3266 (gnus-article-goto-part n)
3267 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3268 (funcall function handle))))
3270 (defun gnus-article-pipe-part (n)
3271 "Pipe MIME part N, which is the numerical prefix."
3273 (gnus-article-part-wrapper n 'mm-pipe-part))
3275 (defun gnus-article-save-part (n)
3276 "Save MIME part N, which is the numerical prefix."
3278 (gnus-article-part-wrapper n 'mm-save-part))
3280 (defun gnus-article-interactively-view-part (n)
3281 "View MIME part N interactively, which is the numerical prefix."
3283 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3285 (defun gnus-article-copy-part (n)
3286 "Copy MIME part N, which is the numerical prefix."
3288 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3290 (defun gnus-article-externalize-part (n)
3291 "View MIME part N externally, which is the numerical prefix."
3293 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3295 (defun gnus-article-inline-part (n)
3296 "Inline MIME part N, which is the numerical prefix."
3298 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3300 (defun gnus-article-view-part (n)
3301 "View MIME part N, which is the numerical prefix."
3303 (save-current-buffer
3304 (set-buffer gnus-article-buffer)
3305 (when (> n (length gnus-article-mime-handle-alist))
3306 (error "No such part"))
3307 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3308 (when (gnus-article-goto-part n)
3309 (if (equal (car handle) "multipart/alternative")
3310 (gnus-article-press-button)
3311 (when (eq (gnus-mm-display-part handle) 'internal)
3312 (gnus-set-window-start)))))))
3314 (defun gnus-mm-display-part (handle)
3315 "Display HANDLE and fix MIME button."
3316 (let ((id (get-text-property (point) 'gnus-part))
3321 (let ((window (selected-window))
3322 (mail-parse-charset gnus-newsgroup-charset)
3323 (mail-parse-ignored-charsets
3324 (save-excursion (set-buffer gnus-summary-buffer)
3325 gnus-newsgroup-ignored-charsets)))
3328 (let ((win (get-buffer-window (current-buffer) t))
3331 (select-window win))
3334 (if (mm-handle-displayed-p handle)
3335 ;; This will remove the part.
3336 (mm-display-part handle)
3338 (narrow-to-region (point) (1+ (point)))
3339 (mm-display-part handle)
3340 ;; We narrow to the part itself and
3341 ;; then call the treatment functions.
3342 (goto-char (point-min))
3344 (narrow-to-region (point) (point-max))
3347 (1- (length gnus-article-mime-handles))
3348 (mm-handle-media-type handle)))))
3349 (select-window window))))
3351 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3352 (gnus-insert-mime-button
3353 handle id (list (mm-handle-displayed-p handle)))
3354 (goto-char point))))
3356 (defun gnus-article-goto-part (n)
3357 "Go to MIME part N."
3358 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3360 (goto-char point))))
3362 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3363 (let ((gnus-tmp-name
3364 (or (mail-content-type-get (mm-handle-type handle)
3366 (mail-content-type-get (mm-handle-disposition handle)
3369 (gnus-tmp-type (mm-handle-media-type handle))
3370 (gnus-tmp-description
3371 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3374 (if (if displayed (car displayed)
3375 (mm-handle-displayed-p handle))
3377 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3379 gnus-tmp-type-long b e)
3380 (when (string-match ".*/" gnus-tmp-name)
3381 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3382 (setq gnus-tmp-type-long (concat gnus-tmp-type
3383 (and (not (equal gnus-tmp-name ""))
3384 (concat "; " gnus-tmp-name))))
3385 (or (equal gnus-tmp-description "")
3386 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3391 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3392 `(local-map ,gnus-mime-button-map
3393 keymap ,gnus-mime-button-map
3394 gnus-callback gnus-mm-display-part
3395 gnus-part ,gnus-tmp-id
3396 article-type annotation
3399 (widget-convert-button 'link b e
3401 :action 'gnus-widget-press-button
3402 :button-keymap gnus-mime-button-map
3405 ;; Needed to properly clear the message
3406 ;; due to a bug in wid-edit
3407 (setq help-echo-owns-message t)
3409 "Click to %s the MIME part; %s for more options"
3410 (if (mm-handle-displayed-p
3411 (widget-get widget :mime-handle))
3413 (if gnus-xemacs "button3" "mouse-3"))))))
3415 (defun gnus-widget-press-button (elems el)
3416 (goto-char (widget-get elems :from))
3417 (gnus-article-press-button))
3419 (defvar gnus-displaying-mime nil)
3421 (defun gnus-display-mime (&optional ihandles)
3422 "Display the MIME parts."
3424 (save-selected-window
3425 (let ((window (get-buffer-window gnus-article-buffer))
3428 (select-window window)
3429 ;; We have to do this since selecting the window
3430 ;; may change the point. So we set the window point.
3431 (set-window-point window point)))
3432 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3433 buffer-read-only handle name type b e display)
3434 (when (and (not ihandles)
3435 (not gnus-displaying-mime))
3436 ;; Top-level call; we clean up.
3437 (when gnus-article-mime-handles
3438 (mm-destroy-parts gnus-article-mime-handles)
3439 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3440 (setq gnus-article-mime-handles handles)
3441 ;; We allow users to glean info from the handles.
3442 (when gnus-article-mime-part-function
3443 (gnus-mime-part-function handles)))
3445 (or (not (stringp (car handles)))
3448 (when (and (not ihandles)
3449 (not gnus-displaying-mime))
3450 ;; Clean up for mime parts.
3452 (delete-region (point) (point-max)))
3453 (let ((gnus-displaying-mime t))
3454 (gnus-mime-display-part handles)))
3457 (narrow-to-region (point) (point-max))
3458 (gnus-treat-article nil 1 1)
3461 ;; Highlight the headers.
3465 (narrow-to-region (point-min) (point))
3466 (gnus-treat-article 'head))))))))
3468 (defvar gnus-mime-display-multipart-as-mixed nil)
3470 (defun gnus-mime-display-part (handle)
3473 ((not (stringp (car handle)))
3474 (gnus-mime-display-single handle))
3475 ;; User-defined multipart
3476 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3477 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3479 ;; multipart/alternative
3480 ((and (equal (car handle) "multipart/alternative")
3481 (not gnus-mime-display-multipart-as-mixed))
3482 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3483 (push (cons id handle) gnus-article-mime-handle-alist)
3484 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3485 ;; multipart/related
3486 ((and (equal (car handle) "multipart/related")
3487 (not gnus-mime-display-multipart-as-mixed))
3488 ;;;!!!We should find the start part, but we just default
3489 ;;;!!!to the first part.
3490 (gnus-mime-display-part (cadr handle)))
3491 ;; Other multiparts are handled like multipart/mixed.
3493 (gnus-mime-display-mixed (cdr handle)))))
3495 (defun gnus-mime-part-function (handles)
3496 (if (stringp (car handles))
3497 (mapcar 'gnus-mime-part-function (cdr handles))
3498 (funcall gnus-article-mime-part-function handles)))
3500 (defun gnus-mime-display-mixed (handles)
3501 (mapcar 'gnus-mime-display-part handles))
3503 (defun gnus-mime-display-single (handle)
3504 (let ((type (mm-handle-media-type handle))
3505 (ignored gnus-ignored-mime-types)
3512 (when (string-match (pop ignored) type)
3513 (throw 'ignored nil)))
3514 (if (and (setq not-attachment
3515 (or (not (mm-handle-disposition handle))
3516 (equal (car (mm-handle-disposition handle))
3518 (mm-attachment-override-p handle)))
3519 (mm-automatic-display-p handle)
3520 (or (mm-inlined-p handle)
3521 (mm-automatic-external-display-p type)))
3523 (when (equal (mm-handle-media-supertype handle) "text")
3525 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3526 (push (cons id handle) gnus-article-mime-handle-alist)
3527 (when (or (not display)
3528 (not (gnus-unbuttonized-mime-type-p type)))
3529 (gnus-article-insert-newline)
3530 (gnus-insert-mime-button
3531 handle id (list (or display (and not-attachment text))))
3532 (gnus-article-insert-newline)
3533 (gnus-article-insert-newline)
3535 (let ((beg (point)))
3541 (let ((mail-parse-charset gnus-newsgroup-charset)
3542 (mail-parse-ignored-charsets
3543 (save-excursion (set-buffer gnus-summary-buffer)
3544 gnus-newsgroup-ignored-charsets)))
3545 (mm-display-part handle t))
3546 (goto-char (point-max)))
3547 ((and text not-attachment)
3551 (gnus-article-insert-newline)
3552 (mm-insert-inline handle (mm-get-part handle))
3553 (goto-char (point-max))))
3557 (narrow-to-region beg (point))
3559 nil (length gnus-article-mime-handle-alist)
3560 (1- (length gnus-article-mime-handles))
3561 (mm-handle-media-type handle)))))))))
3563 (defun gnus-unbuttonized-mime-type-p (type)
3564 "Say whether TYPE is to be unbuttonized."
3565 (unless gnus-inhibit-mime-unbuttonizing
3567 (let ((types gnus-unbuttonized-mime-types))
3569 (when (string-match (pop types) type)
3570 (throw 'found t)))))))
3572 (defun gnus-article-insert-newline ()
3573 "Insert a newline, but mark it as undeletable."
3574 (gnus-put-text-property
3575 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3577 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3578 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3581 handle buffer-read-only from props begend not-pref)
3582 (save-window-excursion
3585 (narrow-to-region (car ibegend)
3588 (goto-char (car ibegend))
3591 (delete-region (point-min) (point-max))
3592 (mm-remove-parts handles))
3593 (setq begend (list (point-marker)))
3595 (unless (setq not-pref (cadr (member preferred ihandles)))
3596 (setq not-pref (car ihandles)))
3598 (not (gnus-unbuttonized-mime-type-p
3599 "multipart/alternative")))
3600 (gnus-add-text-properties
3603 (insert (format "%d. " id))
3607 (unless ,(not ibegend)
3608 (setq gnus-article-mime-handle-alist
3609 ',gnus-article-mime-handle-alist))
3610 (gnus-mime-display-alternative
3611 ',ihandles ',not-pref ',begend ,id))
3612 local-map ,gnus-mime-button-map
3613 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3614 face ,gnus-article-button-face
3615 keymap ,gnus-mime-button-map
3618 (widget-convert-button 'link from (point)
3619 :action 'gnus-widget-press-button
3620 :button-keymap gnus-widget-button-keymap)
3622 (while (setq handle (pop handles))
3623 (gnus-add-text-properties
3626 (insert (format "(%c) %-18s"
3627 (if (equal handle preferred) ?* ? )
3628 (mm-handle-media-type handle)))
3632 (unless ,(not ibegend)
3633 (setq gnus-article-mime-handle-alist
3634 ',gnus-article-mime-handle-alist))
3635 (gnus-mime-display-alternative
3636 ',ihandles ',handle ',begend ,id))
3637 local-map ,gnus-mime-button-map
3638 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3639 face ,gnus-article-button-face
3640 keymap ,gnus-mime-button-map
3643 (widget-convert-button 'link from (point)
3644 :action 'gnus-widget-press-button
3645 :button-keymap gnus-widget-button-keymap)
3649 (if (stringp (car preferred))
3650 (gnus-display-mime preferred)
3651 (let ((mail-parse-charset gnus-newsgroup-charset)
3652 (mail-parse-ignored-charsets
3653 (save-excursion (set-buffer gnus-summary-buffer)
3654 gnus-newsgroup-ignored-charsets)))
3655 (mm-display-part preferred)
3659 (narrow-to-region (car begend) (point-max))
3661 nil (length gnus-article-mime-handle-alist)
3662 (1- (length gnus-article-mime-handles))
3663 (mm-handle-media-type handle))))))
3664 (goto-char (point-max))
3665 (setcdr begend (point-marker)))))
3667 (goto-char point))))
3669 (defun gnus-article-wash-status ()
3670 "Return a string which display status of article washing."
3672 (set-buffer gnus-article-buffer)
3673 (let ((cite (gnus-article-hidden-text-p 'cite))
3674 (headers (gnus-article-hidden-text-p 'headers))
3675 (boring (gnus-article-hidden-text-p 'boring-headers))
3676 (pgp (gnus-article-hidden-text-p 'pgp))
3677 (pem (gnus-article-hidden-text-p 'pem))
3678 (signature (gnus-article-hidden-text-p 'signature))
3679 (overstrike (gnus-article-hidden-text-p 'overstrike))
3680 (emphasis (gnus-article-hidden-text-p 'emphasis))
3681 (mime gnus-show-mime))
3682 (format "%c%c%c%c%c%c%c"
3684 (if (or headers boring) ?h ? )
3685 (if (or pgp pem) ?p ? )
3686 (if signature ?s ? )
3687 (if overstrike ?o ? )
3689 (if emphasis ?e ? )))))
3691 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3693 (defun gnus-article-maybe-hide-headers ()
3694 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3695 Provided for backwards compatibility."
3696 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3697 (not (save-excursion (set-buffer gnus-summary-buffer)
3698 gnus-have-all-headers)))
3699 (not gnus-inhibit-hiding))
3700 (gnus-article-hide-headers)))
3704 (defun gnus-output-to-file (file-name)
3705 "Append the current article to a file named FILE-NAME."
3706 (let ((artbuf (current-buffer)))
3708 (insert-buffer-substring artbuf)
3709 ;; Append newline at end of the buffer as separator, and then
3711 (goto-char (point-max))
3713 (write-region-as-binary (point-min) (point-max) file-name 'append)
3716 (defun gnus-narrow-to-page (&optional arg)
3717 "Narrow the article buffer to a page.
3718 If given a numerical ARG, move forward ARG pages."
3720 (setq arg (if arg (prefix-numeric-value arg) 0))
3722 (set-buffer gnus-article-buffer)
3723 (goto-char (point-min))
3725 ;; Remove any old next/prev buttons.
3726 (when (gnus-visual-p 'page-marker)
3727 (let ((buffer-read-only nil))
3728 (gnus-remove-text-with-property 'gnus-prev)
3729 (gnus-remove-text-with-property 'gnus-next)))
3732 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3734 (re-search-forward page-delimiter nil 'move arg)))
3735 (goto-char (match-end 0)))
3738 (if (re-search-forward page-delimiter nil 'move)
3741 (when (and (gnus-visual-p 'page-marker)
3742 (not (= (point-min) 1)))
3744 (goto-char (point-min))
3745 (gnus-insert-prev-page-button)))
3746 (when (and (gnus-visual-p 'page-marker)
3747 (< (+ (point-max) 2) (buffer-size)))
3749 (goto-char (point-max))
3750 (gnus-insert-next-page-button)))))
3752 ;; Article mode commands
3754 (defun gnus-article-goto-next-page ()
3755 "Show the next page of the article."
3757 (when (gnus-article-next-page)
3758 (goto-char (point-min))
3759 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3761 (defun gnus-article-goto-prev-page ()
3762 "Show the next page of the article."
3764 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3765 (gnus-article-prev-page nil)))
3767 (defun gnus-article-next-page (&optional lines)
3768 "Show the next page of the current article.
3769 If end of article, return non-nil. Otherwise return nil.
3770 Argument LINES specifies lines to be scrolled up."
3772 (let ((start (window-start))
3773 end-of-buffer end-of-page)
3775 (move-to-window-line -1)
3776 (if (<= (point) start)
3779 (setq start (point)))
3782 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3783 (setq end-of-buffer t))
3785 (setq end-of-page t)))
3787 (move-to-window-line lines)
3788 (unless (search-backward "\n\n" nil t)
3789 (setq start (point)))))
3790 (cond (end-of-buffer t)
3792 (gnus-narrow-to-page 1)
3796 (set-window-start (selected-window) start)
3800 (defun gnus-article-prev-page (&optional lines)
3801 "Show previous page of current article.
3802 Argument LINES specifies lines to be scrolled down."
3804 (let (beginning-of-buffer beginning-of-page)
3806 (move-to-window-line 0)
3807 (cond ((eq 1 (point))
3808 (setq beginning-of-buffer t))
3810 (setq beginning-of-page t))))
3811 (cond (beginning-of-buffer)
3813 (gnus-narrow-to-page -1))
3817 (beginning-of-buffer
3818 (goto-char (point-min))))))))
3820 (defun gnus-article-refer-article ()
3821 "Read article specified by message-id around point."
3823 (let ((point (point)))
3824 (search-forward ">" nil t) ;Move point to end of "<....>".
3825 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3826 (let ((message-id (match-string 1)))
3828 (set-buffer gnus-summary-buffer)
3829 (gnus-summary-refer-article message-id))
3831 (error "No references around point"))))
3833 (defun gnus-article-show-summary ()
3834 "Reconfigure windows to show summary buffer."
3836 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3837 (error "There is no summary buffer for this article buffer")
3838 (gnus-article-set-globals)
3839 (gnus-configure-windows 'article)
3840 (gnus-summary-goto-subject gnus-current-article)
3841 (gnus-summary-position-point)))
3843 (defun gnus-article-describe-briefly ()
3844 "Describe article mode commands briefly."
3846 (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")))
3848 (defun gnus-article-summary-command ()
3849 "Execute the last keystroke in the summary buffer."
3851 (let ((obuf (current-buffer))
3852 (owin (current-window-configuration))
3854 (switch-to-buffer gnus-article-current-summary 'norecord)
3855 (setq func (lookup-key (current-local-map) (this-command-keys)))
3856 (call-interactively func)
3858 (set-window-configuration owin)
3859 (set-window-point (get-buffer-window (current-buffer)) (point))))
3861 (defun gnus-article-summary-command-nosave ()
3862 "Execute the last keystroke in the summary buffer."
3865 (pop-to-buffer gnus-article-current-summary 'norecord)
3866 (setq func (lookup-key (current-local-map) (this-command-keys)))
3867 (call-interactively func)))
3869 (defun gnus-article-check-buffer ()
3870 "Beep if not in an article buffer."
3871 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3872 (error "Command invoked outside of a Gnus article buffer")))
3874 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3875 "Read a summary buffer key sequence and execute it from the article buffer."
3877 (gnus-article-check-buffer)
3879 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3880 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3881 "=" "^" "\M-^" "|"))
3887 '("n" "Gn" "p" "Gp"))
3890 (set-buffer gnus-article-current-summary)
3891 (let (gnus-pick-mode)
3892 (push (or key last-command-event) unread-command-events)
3893 (setq keys (static-if (featurep 'xemacs)
3894 (events-to-keys (read-key-sequence nil))
3895 (read-key-sequence nil)))))
3898 (if (or (member keys nosaves)
3899 (member keys nosave-but-article)
3900 (member keys nosave-in-article))
3902 (save-window-excursion
3903 (pop-to-buffer gnus-article-current-summary 'norecord)
3904 ;; We disable the pick minor mode commands.
3905 (let (gnus-pick-mode)
3906 (setq func (lookup-key (current-local-map) keys))))
3909 (unless (member keys nosave-in-article)
3910 (set-buffer gnus-article-current-summary))
3911 (call-interactively func)
3912 (setq new-sum-point (point)))
3913 (when (member keys nosave-but-article)
3914 (pop-to-buffer gnus-article-buffer 'norecord)))
3915 ;; These commands should restore window configuration.
3916 (let ((obuf (current-buffer))
3917 (owin (current-window-configuration))
3919 (summary gnus-article-current-summary)
3920 func in-buffer selected)
3921 (if not-restore-window
3922 (pop-to-buffer summary 'norecord)
3923 (switch-to-buffer summary 'norecord))
3924 (setq in-buffer (current-buffer))
3925 ;; We disable the pick minor mode commands.
3926 (if (setq func (let (gnus-pick-mode)
3927 (lookup-key (current-local-map) keys)))
3929 (call-interactively func)
3930 (setq new-sum-point (point)))
3932 (when (eq in-buffer (current-buffer))
3933 (setq selected (gnus-summary-select-article))
3935 (unless not-restore-window
3936 (set-window-configuration owin))
3937 (when (eq selected 'old)
3939 (set-window-start (get-buffer-window (current-buffer))
3941 (set-window-point (get-buffer-window (current-buffer))
3943 (let ((win (get-buffer-window gnus-article-current-summary)))
3945 (set-window-point win new-sum-point))))))))
3947 (defun gnus-article-hide (&optional arg force)
3948 "Hide all the gruft in the current article.
3949 This means that PGP stuff, signatures, cited text and (some)
3950 headers will be hidden.
3951 If given a prefix, show the hidden text instead."
3952 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3953 (gnus-article-hide-headers arg)
3954 (gnus-article-hide-list-identifiers arg)
3955 (gnus-article-hide-pgp arg)
3956 (gnus-article-hide-citation-maybe arg force)
3957 (gnus-article-hide-signature arg))
3959 (defun gnus-article-maybe-highlight ()
3960 "Do some article highlighting if article highlighting is requested."
3961 (when (gnus-visual-p 'article-highlight 'highlight)
3962 (gnus-article-highlight-some)))
3964 (defun gnus-check-group-server ()
3965 ;; Make sure the connection to the server is alive.
3966 (unless (gnus-server-opened
3967 (gnus-find-method-for-group gnus-newsgroup-name))
3968 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3969 (gnus-request-group gnus-newsgroup-name t)))
3971 (defun gnus-request-article-this-buffer (article group)
3972 "Get an article and insert it into this buffer."
3973 (let (do-update-line sparse-header)
3977 (gnus-kill-all-overlays)
3978 (setq group (or group gnus-newsgroup-name))
3980 ;; Using `gnus-request-article' directly will insert the article into
3981 ;; `nntp-server-buffer' - so we'll save some time by not having to
3982 ;; copy it from the server buffer into the article buffer.
3984 ;; We only request an article by message-id when we do not have the
3985 ;; headers for it, so we'll have to get those.
3986 (when (stringp article)
3987 (let ((gnus-override-method gnus-refer-article-method))
3988 (gnus-read-header article)))
3990 ;; If the article number is negative, that means that this article
3991 ;; doesn't belong in this newsgroup (possibly), so we find its
3992 ;; message-id and request it by id instead of number.
3993 (when (and (numberp article)
3995 (get-buffer gnus-summary-buffer)
3996 (gnus-buffer-exists-p gnus-summary-buffer))
3998 (set-buffer gnus-summary-buffer)
3999 (let ((header (gnus-summary-article-header article)))
4002 ((memq article gnus-newsgroup-sparse)
4003 ;; This is a sparse gap article.
4004 (setq do-update-line article)
4005 (setq article (mail-header-id header))
4006 (let ((gnus-override-method gnus-refer-article-method))
4007 (setq sparse-header (gnus-read-header article)))
4008 (setq gnus-newsgroup-sparse
4009 (delq article gnus-newsgroup-sparse)))
4011 ;; It's a real article.
4012 (setq article (mail-header-id header)))
4014 ;; It is an extracted pseudo-article.
4015 (setq article 'pseudo)
4016 (gnus-request-pseudo-article header))))
4018 (let ((method (gnus-find-method-for-group
4019 gnus-newsgroup-name)))
4020 (when (and (eq (car method) 'nneething)
4023 (file-name-as-directory
4024 (or (cadr (assq 'nneething-address method))
4026 (mail-header-subject header))))
4027 (when (file-directory-p dir)
4028 (setq article 'nneething)
4029 (gnus-group-enter-directory dir))))))))
4032 ;; Refuse to select canceled articles.
4033 ((and (numberp article)
4035 (get-buffer gnus-summary-buffer)
4036 (gnus-buffer-exists-p gnus-summary-buffer)
4037 (eq (cdr (save-excursion
4038 (set-buffer gnus-summary-buffer)
4039 (assq article gnus-newsgroup-reads)))
4040 gnus-canceled-mark))
4042 ;; Check the backlog.
4043 ((and gnus-keep-backlog
4044 (gnus-backlog-request-article group article (current-buffer)))
4046 ;; Check asynchronous pre-fetch.
4047 ((gnus-async-request-fetched-article group article (current-buffer))
4048 (gnus-async-prefetch-next group article gnus-summary-buffer)
4049 (when (and (numberp article) gnus-keep-backlog)
4050 (gnus-backlog-enter-article group article (current-buffer)))
4053 ((and gnus-use-cache
4055 (gnus-cache-request-article article group))
4057 ;; Get the article and put into the article buffer.
4058 ((or (stringp article) (numberp article))
4059 (let ((gnus-override-method
4060 (and (stringp article) gnus-refer-article-method))
4061 (buffer-read-only nil))
4063 (gnus-kill-all-overlays)
4064 (gnus-check-group-server)
4065 (when (gnus-request-article article group (current-buffer))
4066 (when (numberp article)
4067 (gnus-async-prefetch-next group article gnus-summary-buffer)
4068 (when gnus-keep-backlog
4069 (gnus-backlog-enter-article
4070 group article (current-buffer))))
4075 ;; Associate this article with the current summary buffer.
4076 (setq gnus-article-current-summary gnus-summary-buffer)
4078 ;; Take the article from the original article buffer
4079 ;; and place it in the buffer it's supposed to be in.
4080 (when (and (get-buffer gnus-article-buffer)
4081 (equal (buffer-name (current-buffer))
4082 (buffer-name (get-buffer gnus-article-buffer))))
4084 (if (get-buffer gnus-original-article-buffer)
4085 (set-buffer gnus-original-article-buffer)
4086 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4087 (buffer-disable-undo)
4088 (setq major-mode 'gnus-original-article-mode)
4089 (setq buffer-read-only t))
4090 (let (buffer-read-only)
4092 (insert-buffer-substring gnus-article-buffer))
4093 (setq gnus-original-article (cons group article)))
4096 (run-hooks 'gnus-article-decode-hook)
4097 ;; Mark article as decoded or not.
4098 (setq gnus-article-decoded-p gnus-article-decode-hook))
4100 ;; Update sparse articles.
4101 (when (and do-update-line
4102 (or (numberp article)
4104 (let ((buf (current-buffer)))
4105 (set-buffer gnus-summary-buffer)
4106 (gnus-summary-update-article do-update-line sparse-header)
4107 (gnus-summary-goto-subject do-update-line nil t)
4108 (set-window-point (get-buffer-window (current-buffer) t)
4110 (set-buffer buf))))))
4116 (defcustom gnus-article-edit-mode-hook nil
4117 "Hook run in article edit mode buffers."
4118 :group 'gnus-article-various
4121 (defcustom gnus-article-edit-article-setup-function
4122 'gnus-article-mime-edit-article-setup
4123 "Function called to setup an editing article buffer."
4124 :group 'gnus-article-various
4127 (defvar gnus-article-edit-done-function nil)
4129 (defvar gnus-article-edit-mode-map nil)
4131 ;; Should we be using derived.el for this?
4132 (unless gnus-article-edit-mode-map
4133 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4134 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4136 (gnus-define-keys gnus-article-edit-mode-map
4137 "\C-c\C-c" gnus-article-edit-done
4138 "\C-c\C-k" gnus-article-edit-exit)
4140 (gnus-define-keys (gnus-article-edit-wash-map
4141 "\C-c\C-w" gnus-article-edit-mode-map)
4142 "f" gnus-article-edit-full-stops))
4144 (defun gnus-article-edit-mode ()
4145 "Major mode for editing articles.
4146 This is an extended text-mode.
4148 \\{gnus-article-edit-mode-map}"
4150 (setq major-mode 'gnus-article-edit-mode)
4151 (setq mode-name "Article Edit")
4152 (use-local-map gnus-article-edit-mode-map)
4153 (make-local-variable 'gnus-article-edit-done-function)
4154 (make-local-variable 'gnus-prev-winconf)
4155 (setq buffer-read-only nil)
4156 (buffer-enable-undo)
4158 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4160 (defun gnus-article-edit (&optional force)
4161 "Edit the current article.
4162 This will have permanent effect only in mail groups.
4163 If FORCE is non-nil, allow editing of articles even in read-only
4166 (when (and (not force)
4167 (gnus-group-read-only-p))
4168 (error "The current newsgroup does not support article editing"))
4169 (gnus-article-date-original)
4170 (gnus-article-edit-article
4172 `(lambda (no-highlight)
4174 (gnus-summary-edit-article-done
4175 ,(or (mail-header-references gnus-current-headers) "")
4176 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4178 (defun gnus-article-edit-article (start-func exit-func)
4179 "Start editing the contents of the current article buffer."
4180 (let ((winconf (current-window-configuration)))
4181 (set-buffer gnus-article-buffer)
4182 (gnus-article-edit-mode)
4183 (funcall start-func)
4184 (gnus-configure-windows 'edit-article)
4185 (setq gnus-article-edit-done-function exit-func)
4186 (setq gnus-prev-winconf winconf)
4187 (when gnus-article-edit-article-setup-function
4188 (funcall gnus-article-edit-article-setup-function))
4189 (gnus-message 6 "C-c C-c to end edits")))
4191 (defun gnus-article-edit-done (&optional arg)
4192 "Update the article edits and exit."
4197 (when (article-goto-body)
4198 (let ((lines (count-lines (point) (point-max)))
4199 (length (- (point-max) (point)))
4200 (case-fold-search t)
4201 (body (copy-marker (point))))
4202 (goto-char (point-min))
4203 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4204 (delete-region (match-beginning 1) (match-end 1))
4205 (insert (number-to-string length)))
4206 (goto-char (point-min))
4207 (when (re-search-forward
4208 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4209 (delete-region (match-beginning 1) (match-end 1))
4210 (insert (number-to-string length)))
4211 (goto-char (point-min))
4212 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4213 (delete-region (match-beginning 1) (match-end 1))
4214 (insert (number-to-string lines)))))))
4215 (let ((func gnus-article-edit-done-function)
4216 (buf (current-buffer))
4217 (start (window-start)))
4218 (remove-hook 'gnus-article-mode-hook
4219 'gnus-article-mime-edit-article-unwind)
4220 (gnus-article-edit-exit)
4223 (let ((buffer-read-only nil))
4225 ;; The cache and backlog have to be flushed somewhat.
4226 (when gnus-keep-backlog
4227 (gnus-backlog-remove-article
4228 (car gnus-article-current) (cdr gnus-article-current)))
4229 ;; Flush original article as well.
4231 (when (get-buffer gnus-original-article-buffer)
4232 (set-buffer gnus-original-article-buffer)
4233 (setq gnus-original-article nil)))
4234 (when gnus-use-cache
4235 (gnus-cache-update-article
4236 (car gnus-article-current) (cdr gnus-article-current))))
4238 (set-window-start (get-buffer-window buf) start)
4239 (set-window-point (get-buffer-window buf) (point))))
4241 (defun gnus-article-edit-exit ()
4242 "Exit the article editing without updating."
4244 ;; We remove all text props from the article buffer.
4245 (let ((buf (format "%s" (buffer-string)))
4246 (curbuf (current-buffer))
4248 (window-start (window-start)))
4251 (let ((winconf gnus-prev-winconf))
4253 (set-window-configuration winconf)
4254 ;; Tippy-toe some to make sure that point remains where it was.
4255 (save-current-buffer
4257 (set-window-start (get-buffer-window (current-buffer)) window-start)
4260 (defun gnus-article-edit-full-stops ()
4261 "Interactively repair spacing at end of sentences."
4264 (goto-char (point-min))
4265 (search-forward-regexp "^$" nil t)
4266 (let ((case-fold-search nil))
4267 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4270 ;;; Article editing with MIME-Edit
4273 (defcustom gnus-article-mime-edit-article-setup-hook nil
4274 "Hook run after setting up a MIME editing article buffer."
4275 :group 'gnus-article-various
4278 (defun gnus-article-mime-edit-article-unwind ()
4279 "Unwind `gnus-article-buffer' if article editing was given up."
4280 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4281 (when mime-edit-mode-flag
4282 (mime-edit-exit 'nomime 'no-error)
4284 (when (featurep 'font-lock)
4285 (setq font-lock-defaults nil)
4286 (font-lock-mode 0)))
4288 (defun gnus-article-mime-edit-article-setup ()
4289 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4290 after replacing with the original article."
4291 (setq gnus-show-mime t)
4292 (setq gnus-article-edit-done-function
4293 `(lambda (&rest args)
4294 (when mime-edit-mode-flag
4297 (goto-char (point-min))
4298 (let (case-fold-search)
4299 (when (re-search-forward
4300 (format "^%s$" (regexp-quote mail-header-separator))
4302 (replace-match "")))
4303 (when (featurep 'font-lock)
4304 (setq font-lock-defaults nil)
4306 (apply ,gnus-article-edit-done-function args)
4307 (set-buffer gnus-original-article-buffer)
4309 (insert-buffer gnus-article-buffer)
4310 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4311 (gnus-article-prepare-display)))
4312 (substitute-key-definition
4313 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4314 gnus-article-edit-mode-map)
4316 (insert-buffer gnus-original-article-buffer)
4318 (when (featurep 'font-lock)
4319 (set (make-local-variable 'font-lock-defaults)
4320 '(message-font-lock-keywords t))
4321 (font-lock-set-defaults)
4322 (turn-on-font-lock))
4323 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4324 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4326 (defun gnus-article-mime-edit-exit ()
4327 "Exit the article MIME editing without updating."
4329 (let ((winconf gnus-prev-winconf)
4331 (when mime-edit-mode-flag
4334 (goto-char (point-min))
4335 (let (case-fold-search)
4336 (when (re-search-forward
4337 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4338 (replace-match "")))
4339 (when (featurep 'font-lock)
4340 (setq font-lock-defaults nil)
4342 ;; We remove all text props from the article buffer.
4343 (setq buf (format "%s" (buffer-string)))
4344 (set-buffer (get-buffer-create gnus-original-article-buffer))
4347 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4348 (gnus-article-prepare-display)
4349 (set-window-configuration winconf)))
4352 ;;; Article highlights
4355 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4357 ;;; Internal Variables:
4359 (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\\)"
4360 "Regular expression that matches URLs."
4361 :group 'gnus-article-buttons
4364 (defcustom gnus-button-alist
4365 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4366 0 t gnus-button-message-id 2)
4367 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4368 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4370 gnus-button-fetch-group 4)
4371 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4372 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4373 t gnus-button-message-id 3)
4374 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4375 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4376 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4377 ;; This is how URLs _should_ be embedded in text...
4378 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
4380 (,gnus-button-url-regexp 0 t gnus-button-url 0))
4381 "*Alist of regexps matching buttons in article bodies.
4383 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4384 REGEXP: is the string matching text around the button,
4385 BUTTON: is the number of the regexp grouping actually matching the button,
4386 FORM: is a lisp expression which must eval to true for the button to
4388 CALLBACK: is the function to call when the user push this button, and each
4389 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4391 CALLBACK can also be a variable, in that case the value of that
4392 variable it the real callback function."
4393 :group 'gnus-article-buttons
4394 :type '(repeat (list regexp
4395 (integer :tag "Button")
4397 (function :tag "Callback")
4400 (integer :tag "Regexp group")))))
4402 (defcustom gnus-header-button-alist
4403 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4404 0 t gnus-button-message-id 0)
4405 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4406 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4407 0 t gnus-button-mailto 0)
4408 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4409 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4410 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4411 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4412 gnus-button-message-id 3))
4413 "*Alist of headers and regexps to match buttons in article heads.
4415 This alist is very similar to `gnus-button-alist', except that each
4416 alist has an additional HEADER element first in each entry:
4418 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4420 HEADER is a regexp to match a header. For a fuller explanation, see
4421 `gnus-button-alist'."
4422 :group 'gnus-article-buttons
4423 :group 'gnus-article-headers
4424 :type '(repeat (list (regexp :tag "Header")
4426 (integer :tag "Button")
4428 (function :tag "Callback")
4431 (integer :tag "Regexp group")))))
4433 (defvar gnus-button-regexp nil)
4434 (defvar gnus-button-marker-list nil)
4435 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4437 (defvar gnus-button-last nil)
4438 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4442 (defun gnus-article-push-button (event)
4443 "Check text under the mouse pointer for a callback function.
4444 If the text under the mouse pointer has a `gnus-callback' property,
4445 call it with the value of the `gnus-data' text property."
4447 (set-buffer (window-buffer (posn-window (event-start event))))
4448 (let* ((pos (posn-point (event-start event)))
4449 (data (get-text-property pos 'gnus-data))
4450 (fun (get-text-property pos 'gnus-callback)))
4453 (funcall fun data))))
4455 (defun gnus-article-press-button ()
4456 "Check text at point for a callback function.
4457 If the text at point has a `gnus-callback' property,
4458 call it with the value of the `gnus-data' text property."
4460 (let* ((data (get-text-property (point) 'gnus-data))
4461 (fun (get-text-property (point) 'gnus-callback)))
4463 (funcall fun data))))
4465 (defun gnus-article-prev-button (n)
4466 "Move point to N buttons backward.
4467 If N is negative, move forward instead."
4469 (gnus-article-next-button (- n)))
4471 (defun gnus-article-next-button (n)
4472 "Move point to N buttons forward.
4473 If N is negative, move backward instead."
4475 (let ((function (if (< n 0) 'previous-single-property-change
4476 'next-single-property-change))
4477 (inhibit-point-motion-hooks t)
4479 (limit (if (< n 0) (point-min) (point-max))))
4481 (while (and (not (= limit (point)))
4483 ;; Skip past the current button.
4484 (when (get-text-property (point) 'gnus-callback)
4485 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4486 ;; Go to the next (or previous) button.
4487 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4488 ;; Put point at the start of the button.
4489 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4490 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4491 ;; Skip past intangible buttons.
4492 (when (get-text-property (point) 'intangible)
4496 (gnus-message 5 "No more buttons"))
4499 (defun gnus-article-highlight (&optional force)
4500 "Highlight current article.
4501 This function calls `gnus-article-highlight-headers',
4502 `gnus-article-highlight-citation',
4503 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4504 do the highlighting. See the documentation for those functions."
4505 (interactive (list 'force))
4506 (gnus-article-highlight-headers)
4507 (gnus-article-highlight-citation force)
4508 (gnus-article-highlight-signature)
4509 (gnus-article-add-buttons force)
4510 (gnus-article-add-buttons-to-head))
4512 (defun gnus-article-highlight-some (&optional force)
4513 "Highlight current article.
4514 This function calls `gnus-article-highlight-headers',
4515 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4516 do the highlighting. See the documentation for those functions."
4517 (interactive (list 'force))
4518 (gnus-article-highlight-headers)
4519 (gnus-article-highlight-signature)
4520 (gnus-article-add-buttons))
4522 (defun gnus-article-highlight-headers ()
4523 "Highlight article headers as specified by `gnus-header-face-alist'."
4526 (set-buffer gnus-article-buffer)
4528 (let ((alist gnus-header-face-alist)
4529 (buffer-read-only nil)
4530 (case-fold-search t)
4531 (inhibit-point-motion-hooks t)
4532 entry regexp header-face field-face from hpoints fpoints)
4533 (article-narrow-to-head)
4534 (while (setq entry (pop alist))
4535 (goto-char (point-min))
4536 (setq regexp (concat "^\\("
4537 (if (string-equal "" (nth 0 entry))
4541 header-face (nth 1 entry)
4542 field-face (nth 2 entry))
4543 (while (and (re-search-forward regexp nil t)
4547 (unless (search-forward ":" nil t)
4549 (when (and header-face
4550 (not (memq (point) hpoints)))
4551 (push (point) hpoints)
4552 (gnus-put-text-property from (point) 'face header-face))
4553 (when (and field-face
4554 (not (memq (setq from (point)) fpoints)))
4556 (if (re-search-forward "^[^ \t]" nil t)
4558 (goto-char (point-max)))
4559 (gnus-put-text-property from (point) 'face field-face))))))))
4561 (defun gnus-article-highlight-signature ()
4562 "Highlight the signature in an article.
4563 It does this by highlighting everything after
4564 `gnus-signature-separator' using `gnus-signature-face'."
4566 (when gnus-signature-face
4568 (set-buffer gnus-article-buffer)
4569 (let ((buffer-read-only nil)
4570 (inhibit-point-motion-hooks t))
4572 (when (gnus-article-narrow-to-signature)
4573 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4574 'face gnus-signature-face)))))))
4576 (defun gnus-article-buttonize-signature ()
4577 "Add button to the signature."
4580 (set-buffer gnus-article-buffer)
4581 (let ((buffer-read-only nil)
4582 (inhibit-point-motion-hooks t))
4583 (when (gnus-article-search-signature)
4584 (gnus-article-add-button (match-beginning 0) (match-end 0)
4585 'gnus-signature-toggle
4586 (set-marker (make-marker)
4587 (1+ (match-end 0))))))))
4589 (defun gnus-button-in-region-p (b e prop)
4590 "Say whether PROP exists in the region."
4591 (text-property-not-all b e prop nil))
4593 (defun gnus-article-add-buttons (&optional force)
4594 "Find external references in the article and make buttons of them.
4595 \"External references\" are things like Message-IDs and URLs, as
4596 specified by `gnus-button-alist'."
4597 (interactive (list 'force))
4599 (set-buffer gnus-article-buffer)
4600 (let ((buffer-read-only nil)
4601 (inhibit-point-motion-hooks t)
4602 (case-fold-search t)
4603 (alist gnus-button-alist)
4605 ;; Remove all old markers.
4606 (let (marker entry new-list)
4607 (while (setq marker (pop gnus-button-marker-list))
4608 (if (or (< marker (point-min)) (>= marker (point-max)))
4609 (push marker new-list)
4611 (when (setq entry (gnus-button-entry))
4612 (put-text-property (match-beginning (nth 1 entry))
4613 (match-end (nth 1 entry))
4614 'gnus-callback nil))
4615 (set-marker marker nil)))
4616 (setq gnus-button-marker-list new-list))
4617 ;; We skip the headers.
4620 (while (setq entry (pop alist))
4621 (setq regexp (car entry))
4623 (while (re-search-forward regexp nil t)
4624 (let* ((start (and entry (match-beginning (nth 1 entry))))
4625 (end (and entry (match-end (nth 1 entry))))
4626 (from (match-beginning 0)))
4627 (when (and (or (eq t (nth 2 entry))
4628 (eval (nth 2 entry)))
4629 (not (gnus-button-in-region-p
4630 start end 'gnus-callback)))
4631 ;; That optional form returned non-nil, so we add the
4633 (gnus-article-add-button
4634 start end 'gnus-button-push
4635 (car (push (set-marker (make-marker) from)
4636 gnus-button-marker-list))))))))))
4638 ;; Add buttons to the head of an article.
4639 (defun gnus-article-add-buttons-to-head ()
4640 "Add buttons to the head of the article."
4643 (set-buffer gnus-article-buffer)
4645 (let ((buffer-read-only nil)
4646 (inhibit-point-motion-hooks t)
4647 (case-fold-search t)
4648 (alist gnus-header-button-alist)
4650 (article-narrow-to-head)
4652 ;; Each alist entry.
4653 (setq entry (car alist)
4655 (goto-char (point-min))
4656 (while (re-search-forward (car entry) nil t)
4657 ;; Each header matching the entry.
4658 (setq beg (match-beginning 0))
4659 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4660 (match-beginning 0))
4663 (while (re-search-forward (nth 1 entry) end t)
4664 ;; Each match within a header.
4665 (let* ((entry (cdr entry))
4666 (start (match-beginning (nth 1 entry)))
4667 (end (match-end (nth 1 entry)))
4668 (form (nth 2 entry)))
4669 (goto-char (match-end 0))
4671 (gnus-article-add-button
4672 start end (nth 3 entry)
4673 (buffer-substring (match-beginning (nth 4 entry))
4674 (match-end (nth 4 entry)))))))
4675 (goto-char end)))))))
4677 ;;; External functions:
4679 (defun gnus-article-add-button (from to fun &optional data)
4680 "Create a button between FROM and TO with callback FUN and data DATA."
4681 (when gnus-article-button-face
4682 (gnus-overlay-put (gnus-make-overlay from to)
4683 'face gnus-article-button-face))
4684 (gnus-add-text-properties
4686 (nconc (and gnus-article-mouse-face
4687 (list gnus-mouse-face-prop gnus-article-mouse-face))
4688 (list 'gnus-callback fun)
4689 (and data (list 'gnus-data data)))))
4691 ;;; Internal functions:
4693 (defun gnus-article-set-globals ()
4695 (set-buffer gnus-summary-buffer)
4696 (gnus-set-global-variables)))
4698 (defun gnus-signature-toggle (end)
4700 (set-buffer gnus-article-buffer)
4701 (let ((buffer-read-only nil)
4702 (inhibit-point-motion-hooks t)
4703 (limit (or (next-single-property-change end 'mime-view-entity)
4705 (if (get-text-property end 'invisible)
4706 (gnus-article-unhide-text end limit)
4707 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4709 (defun gnus-button-entry ()
4710 ;; Return the first entry in `gnus-button-alist' matching this place.
4711 (let ((alist gnus-button-alist)
4714 (setq entry (pop alist))
4715 (if (looking-at (car entry))
4720 (defun gnus-button-push (marker)
4721 ;; Push button starting at MARKER.
4724 (let* ((entry (gnus-button-entry))
4725 (inhibit-point-motion-hooks t)
4727 (args (mapcar (lambda (group)
4728 (let ((string (match-string group)))
4729 (gnus-set-text-properties
4730 0 (length string) nil string)
4737 (fboundp (symbol-value fun)))
4738 (apply (symbol-value fun) args))
4740 (gnus-message 1 "You must define `%S' to use this button"
4741 (cons fun args)))))))
4743 (defun gnus-button-message-id (message-id)
4746 (set-buffer gnus-summary-buffer)
4747 (gnus-summary-refer-article message-id)))
4749 (defun gnus-button-fetch-group (address)
4750 "Fetch GROUP specified by ADDRESS."
4751 (if (not (string-match "[:/]" address))
4752 ;; This is just a simple group url.
4753 (gnus-group-read-ephemeral-group address gnus-select-method)
4754 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4756 (error "Can't parse %s" address)
4757 (gnus-group-read-ephemeral-group
4758 (match-string 4 address)
4759 `(nntp ,(match-string 1 address)
4760 (nntp-address ,(match-string 1 address))
4761 (nntp-port-number ,(if (match-end 3)
4762 (match-string 3 address)
4765 (defun gnus-url-parse-query-string (query &optional downcase)
4766 (let (retval pairs cur key val)
4767 (setq pairs (split-string query "&"))
4769 (setq cur (car pairs)
4771 (if (not (string-match "=" cur))
4773 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4774 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4776 (setq key (downcase key)))
4777 (setq cur (assoc key retval))
4779 (setcdr cur (cons val (cdr cur)))
4780 (setq retval (cons (list key val) retval)))))
4783 (defun gnus-url-unhex (x)
4790 (defun gnus-url-unhex-string (str &optional allow-newlines)
4791 "Remove %XXX embedded spaces, etc in a url.
4792 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4793 decoding of carriage returns and line feeds in the string, which is normally
4794 forbidden in URL encoding."
4795 (setq str (or str ""))
4797 (case-fold-search t))
4798 (while (string-match "%[0-9a-f][0-9a-f]" str)
4799 (let* ((start (match-beginning 0))
4800 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4802 (gnus-url-unhex (elt str (+ start 2))))))
4804 tmp (substring str 0 start)
4807 (char-to-string code))
4808 ((or (= code ?\n) (= code ?\r))
4810 (t (char-to-string code))))
4811 str (substring str (match-end 0)))))
4812 (setq tmp (concat tmp str))
4815 (defun gnus-url-mailto (url)
4816 ;; Send mail to someone
4817 (when (string-match "mailto:/*\\(.*\\)" url)
4818 (setq url (substring url (match-beginning 1) nil)))
4819 (let (to args subject func)
4820 (if (string-match (regexp-quote "?") url)
4821 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4822 args (gnus-url-parse-query-string
4823 (substring url (match-end 0) nil) t))
4824 (setq to (gnus-url-unhex-string url)))
4825 (setq args (cons (list "to" to) args)
4826 subject (cdr-safe (assoc "subject" args)))
4827 (gnus-setup-message 'reply
4830 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4833 (message-position-on-field (caar args)))
4834 (insert (mapconcat 'identity (cdar args) ", "))
4835 (setq args (cdr args)))
4838 (message-goto-subject)))))
4840 (defun gnus-button-mailto (address)
4842 (set-buffer (gnus-copy-article-buffer))
4843 (gnus-setup-message 'reply
4844 (message-reply address)))
4846 (defun gnus-button-reply (address)
4847 ;; Reply to ADDRESS.
4848 (gnus-setup-message 'reply
4849 (message-reply address)))
4851 (defun gnus-button-url (address)
4853 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4854 (if (listp browse-url-browser-function)
4855 (browse-url address)
4856 (funcall browse-url-browser-function address)))
4858 (defun gnus-button-embedded-url (address)
4860 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4861 (if (listp browse-url-browser-function)
4862 (browse-url (gnus-strip-whitespace address))
4863 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4865 ;;; Next/prev buttons in the article buffer.
4867 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4868 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4870 (defvar gnus-prev-page-map nil)
4871 (unless gnus-prev-page-map
4872 (setq gnus-prev-page-map (make-sparse-keymap))
4873 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4874 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4876 (static-if (featurep 'xemacs)
4877 (defun gnus-insert-prev-page-button ()
4878 (let ((buffer-read-only nil))
4880 gnus-prev-page-line-format nil
4881 `(gnus-prev t local-map ,gnus-prev-page-map
4882 gnus-callback gnus-article-button-prev-page
4883 article-type annotation))))
4884 (defun gnus-insert-prev-page-button ()
4885 (let ((buffer-read-only nil)
4886 (situation (get-text-property (point-min) 'mime-view-situation)))
4887 (set-keymap-parent gnus-prev-page-map (current-local-map))
4889 gnus-prev-page-line-format nil
4890 `(gnus-prev t local-map ,gnus-prev-page-map
4891 gnus-callback gnus-article-button-prev-page
4892 article-type annotation
4893 mime-view-situation ,situation))))
4896 (defvar gnus-next-page-map nil)
4897 (unless gnus-next-page-map
4898 (setq gnus-next-page-map (make-sparse-keymap))
4899 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4900 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4902 (defun gnus-button-next-page ()
4903 "Go to the next page."
4905 (let ((win (selected-window)))
4906 (select-window (get-buffer-window gnus-article-buffer t))
4907 (gnus-article-next-page)
4908 (select-window win)))
4910 (defun gnus-button-prev-page ()
4911 "Go to the prev page."
4913 (let ((win (selected-window)))
4914 (select-window (get-buffer-window gnus-article-buffer t))
4915 (gnus-article-prev-page)
4916 (select-window win)))
4918 (static-if (featurep 'xemacs)
4919 (defun gnus-insert-next-page-button ()
4920 (let ((buffer-read-only nil))
4921 (gnus-eval-format gnus-next-page-line-format nil
4923 t local-map ,gnus-next-page-map
4924 gnus-callback gnus-article-button-next-page
4925 article-type annotation))))
4926 (defun gnus-insert-next-page-button ()
4927 (let ((buffer-read-only nil)
4928 (situation (get-text-property (point-min) 'mime-view-situation)))
4929 (set-keymap-parent gnus-next-page-map (current-local-map))
4930 (gnus-eval-format gnus-next-page-line-format nil
4932 t local-map ,gnus-next-page-map
4933 gnus-callback gnus-article-button-next-page
4934 article-type annotation
4935 mime-view-situation ,situation))))
4938 (defun gnus-article-button-next-page (arg)
4939 "Go to the next page."
4941 (let ((win (selected-window)))
4942 (select-window (get-buffer-window gnus-article-buffer t))
4943 (gnus-article-next-page)
4944 (select-window win)))
4946 (defun gnus-article-button-prev-page (arg)
4947 "Go to the prev page."
4949 (let ((win (selected-window)))
4950 (select-window (get-buffer-window gnus-article-buffer t))
4951 (gnus-article-prev-page)
4952 (select-window win)))
4954 (defvar gnus-decode-header-methods
4955 '(mail-decode-encoded-word-region)
4956 "List of methods used to decode headers.
4958 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4959 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4960 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4961 whose names match REGEXP.
4964 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4965 mail-decode-encoded-word-region
4966 (\"chinese\" . rfc1843-decode-region))
4969 (defvar gnus-decode-header-methods-cache nil)
4971 (defun gnus-multi-decode-header (start end)
4972 "Apply the functions from `gnus-encoded-word-methods' that match."
4973 (unless (and gnus-decode-header-methods-cache
4974 (eq gnus-newsgroup-name
4975 (car gnus-decode-header-methods-cache)))
4976 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4979 (nconc gnus-decode-header-methods-cache (list x))
4980 (if (and gnus-newsgroup-name
4981 (string-match (car x) gnus-newsgroup-name))
4982 (nconc gnus-decode-header-methods-cache
4984 gnus-decode-header-methods))
4985 (let ((xlist gnus-decode-header-methods-cache))
4988 (narrow-to-region start end)
4990 (funcall (pop xlist) (point-min) (point-max))))))
4993 ;;; Treatment top-level handling.
4996 (defun gnus-treat-article (condition &optional part-number total-parts type)
4997 (let ((length (- (point-max) (point-min)))
4998 (alist gnus-treatment-function-alist)
4999 (article-goto-body-goes-to-point-min-p t)
5003 (let ((list gnus-article-treat-types))
5005 (when (string-match (pop list) type)
5006 (throw 'found t)))))))
5007 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5008 (entity (static-unless (featurep 'xemacs)
5009 (when (eq 'head condition)
5010 (get-text-property (point-min) 'mime-view-entity))))
5011 val elem buttonized)
5012 (gnus-run-hooks 'gnus-part-display-hook)
5013 (unless gnus-inhibit-treatment
5014 (while (setq elem (pop alist))
5015 (setq val (symbol-value (car elem)))
5016 (when (and (or (consp val)
5018 (gnus-treat-predicate val)
5019 (or (not (get (car elem) 'highlight))
5021 (when (and (not buttonized)
5023 '(gnus-treat-hide-signature
5024 gnus-treat-highlight-signature)))
5025 (gnus-article-buttonize-signature)
5026 (setq buttonized t))
5028 (funcall (cadr elem)))))
5029 ;; FSF Emacsen does not inherit the existing text properties
5030 ;; in the new text, so we should do it for `mime-view-entity'.
5031 (static-unless (featurep 'xemacs)
5033 (put-text-property (point-min) (point-max)
5034 'mime-view-entity entity))))))
5036 ;; Dynamic variables.
5037 (defvar part-number)
5038 (defvar total-parts)
5042 (defun gnus-treat-predicate (val)
5047 (stringp (car val)))
5048 (apply 'gnus-or (mapcar `(lambda (s)
5049 (string-match s ,(or gnus-newsgroup-name "")))
5052 (let ((pred (pop val)))
5055 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5057 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5059 (not (gnus-treat-predicate (car val))))
5061 (equal (car val) type))
5063 (error "%S is not a valid predicate" pred)))))
5073 (eq part-number total-parts))
5077 (error "%S is not a valid value" val))))
5083 (defun gnus-article-header-presentation-method (entity situation)
5084 (mime-insert-header entity)
5087 (set-alist 'mime-header-presentation-method-alist
5088 'gnus-original-article-mode
5089 #'gnus-article-header-presentation-method)
5091 (defun gnus-mime-preview-quitting-method ()
5092 (mime-preview-kill-buffer)
5093 (delete-other-windows)
5094 (gnus-article-show-summary)
5095 (gnus-summary-select-article gnus-show-all-headers t))
5097 (set-alist 'mime-preview-quitting-method-alist
5098 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5100 (defun gnus-following-method (buf)
5103 (message-yank-original)
5105 (goto-char (point-min))
5108 (set-alist 'mime-preview-following-method-alist
5109 'gnus-original-article-mode #'gnus-following-method)
5111 (set-alist 'mime-preview-over-to-previous-method-alist
5112 'gnus-original-article-mode
5114 (if (> (point-min) 1)
5115 (gnus-article-prev-page)
5116 (gnus-article-read-summary-keys
5117 nil (gnus-character-to-event ?P)))))
5119 (set-alist 'mime-preview-over-to-next-method-alist
5120 'gnus-original-article-mode'
5122 (if (< (point-max) (buffer-size))
5123 (gnus-article-next-page)
5124 (gnus-article-read-summary-keys
5125 nil (gnus-character-to-event ?N)))))
5135 (run-hooks 'gnus-art-load-hook)
5137 ;;; gnus-art.el ends here