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 (module-installed-p 'x-face-mule)
217 'x-face-mule-gnus-article-display-x-face
218 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
220 "*String or function to be executed to display an X-Face header.
221 If it is a string, the command will be executed in a sub-shell
222 asynchronously. The compressed face will be piped to this command."
223 :type 'string ;Leave function case to Lisp.
224 :group 'gnus-article-washing)
226 (defcustom gnus-article-x-face-too-ugly nil
227 "Regexp matching posters whose face shouldn't be shown automatically."
228 :type '(choice regexp (const nil))
229 :group 'gnus-article-washing)
231 (defcustom gnus-emphasis-alist
233 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
235 '(("_" "_" underline)
238 ("_/" "/_" underline-italic)
239 ("_\\*" "\\*_" underline-bold)
240 ("\\*/" "/\\*" bold-italic)
241 ("_\\*/" "/\\*_" underline-bold-italic))))
242 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
243 2 3 gnus-emphasis-underline)
247 (format format (car spec) (cadr spec))
248 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
250 "*Alist that says how to fontify certain phrases.
251 Each item looks like this:
253 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
255 The first element is a regular expression to be matched. The second
256 is a number that says what regular expression grouping used to find
257 the entire emphasized word. The third is a number that says what
258 regexp grouping should be displayed and highlighted. The fourth
259 is the face used for highlighting."
260 :type '(repeat (list :value ("" 0 0 default)
262 (integer :tag "Match group")
263 (integer :tag "Emphasize group")
265 :group 'gnus-article-emphasis)
267 (defface gnus-emphasis-bold '((t (:bold t)))
268 "Face used for displaying strong emphasized text (*word*)."
269 :group 'gnus-article-emphasis)
271 (defface gnus-emphasis-italic '((t (:italic t)))
272 "Face used for displaying italic emphasized text (/word/)."
273 :group 'gnus-article-emphasis)
275 (defface gnus-emphasis-underline '((t (:underline t)))
276 "Face used for displaying underlined emphasized text (_word_)."
277 :group 'gnus-article-emphasis)
279 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
280 "Face used for displaying underlined bold emphasized text (_*word*_)."
281 :group 'gnus-article-emphasis)
283 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
284 "Face used for displaying underlined italic emphasized text (_*word*_)."
285 :group 'gnus-article-emphasis)
287 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
288 "Face used for displaying bold italic emphasized text (/*word*/)."
289 :group 'gnus-article-emphasis)
291 (defface gnus-emphasis-underline-bold-italic
292 '((t (:bold t :italic t :underline t)))
293 "Face used for displaying underlined bold italic emphasized text.
294 Esample: (_/*word*/_)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-highlight-words
298 '((t (:background "black" :foreground "yellow")))
299 "Face used for displaying highlighted words."
300 :group 'gnus-article-emphasis)
302 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
303 "Format for display of Date headers in article bodies.
304 See `format-time-string' for the possible values.
306 The variable can also be function, which should return a complete Date
307 header. The function is called with one argument, the time, which can
308 be fed to `format-time-string'."
309 :type '(choice string symbol)
310 :link '(custom-manual "(gnus)Article Date")
311 :group 'gnus-article-washing)
314 (autoload 'mail-extract-address-components "mail-extr"))
316 (defcustom gnus-save-all-headers t
317 "*If non-nil, don't remove any headers before saving."
318 :group 'gnus-article-saving
321 (defcustom gnus-prompt-before-saving 'always
322 "*This variable says how much prompting is to be done when saving articles.
323 If it is nil, no prompting will be done, and the articles will be
324 saved to the default files. If this variable is `always', each and
325 every article that is saved will be preceded by a prompt, even when
326 saving large batches of articles. If this variable is neither nil not
327 `always', there the user will be prompted once for a file name for
328 each invocation of the saving commands."
329 :group 'gnus-article-saving
330 :type '(choice (item always)
331 (item :tag "never" nil)
332 (sexp :tag "once" :format "%t\n" :value t)))
334 (defcustom gnus-saved-headers gnus-visible-headers
335 "Headers to keep if `gnus-save-all-headers' is nil.
336 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
337 If that variable is nil, however, all headers that match this regexp
338 will be kept while the rest will be deleted before saving."
339 :group 'gnus-article-saving
342 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
343 "A function to save articles in your favourite format.
344 The function must be interactively callable (in other words, it must
345 be an Emacs command).
347 Gnus provides the following functions:
349 * gnus-summary-save-in-rmail (Rmail format)
350 * gnus-summary-save-in-mail (Unix mail format)
351 * gnus-summary-save-in-folder (MH folder)
352 * gnus-summary-save-in-file (article format)
353 * gnus-summary-save-in-vm (use VM's folder format)
354 * gnus-summary-write-to-file (article format -- overwrite)."
355 :group 'gnus-article-saving
356 :type '(radio (function-item gnus-summary-save-in-rmail)
357 (function-item gnus-summary-save-in-mail)
358 (function-item gnus-summary-save-in-folder)
359 (function-item gnus-summary-save-in-file)
360 (function-item gnus-summary-save-in-vm)
361 (function-item gnus-summary-write-to-file)))
363 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
364 "A function generating a file name to save articles in Rmail format.
365 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
366 :group 'gnus-article-saving
369 (defcustom gnus-mail-save-name 'gnus-plain-save-name
370 "A function generating a file name to save articles in Unix mail format.
371 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
372 :group 'gnus-article-saving
375 (defcustom gnus-folder-save-name 'gnus-folder-save-name
376 "A function generating a file name to save articles in MH folder.
377 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
378 :group 'gnus-article-saving
381 (defcustom gnus-file-save-name 'gnus-numeric-save-name
382 "A function generating a file name to save articles in article format.
383 The function is called with NEWSGROUP, HEADERS, and optional
385 :group 'gnus-article-saving
388 (defcustom gnus-split-methods
389 '((gnus-article-archive-name)
390 (gnus-article-nndoc-name))
391 "*Variable used to suggest where articles are to be saved.
392 For instance, if you would like to save articles related to Gnus in
393 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
394 you could set this variable to something like:
396 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
397 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
399 This variable is an alist where the where the key is the match and the
400 value is a list of possible files to save in if the match is non-nil.
402 If the match is a string, it is used as a regexp match on the
403 article. If the match is a symbol, that symbol will be funcalled
404 from the buffer of the article to be saved with the newsgroup as the
405 parameter. If it is a list, it will be evaled in the same buffer.
407 If this form or function returns a string, this string will be used as
408 a possible file name; and if it returns a non-nil list, that list will
409 be used as possible file names."
410 :group 'gnus-article-saving
411 :type '(repeat (choice (list :value (fun) function)
412 (cons :value ("" "") regexp (repeat string))
415 (defcustom gnus-article-display-method-for-mime
416 'gnus-article-display-mime-message
417 "Function to display a MIME message.
418 The function is called from the article buffer."
419 :group 'gnus-article-mime
422 (defcustom gnus-article-display-method-for-traditional
423 'gnus-article-display-traditional-message
424 "*Function to display a traditional message.
425 The function is called from the article buffer."
426 :group 'gnus-article-mime
429 (defcustom gnus-page-delimiter "^\^L"
430 "*Regexp describing what to use as article page delimiters.
431 The default value is \"^\^L\", which is a form linefeed at the
432 beginning of a line."
434 :group 'gnus-article-various)
436 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
437 "*The format specification for the article mode line.
438 See `gnus-summary-mode-line-format' for a closer description.
440 The following additional specs are available:
442 %w The article washing status.
443 %m The number of MIME parts in the article."
445 :group 'gnus-article-various)
447 (defcustom gnus-article-mode-hook nil
448 "*A hook for Gnus article mode."
450 :group 'gnus-article-various)
452 (defcustom gnus-article-menu-hook nil
453 "*Hook run after the creation of the article mode menu."
455 :group 'gnus-article-various)
457 (defcustom gnus-article-prepare-hook nil
458 "*A hook called after an article has been prepared in the article buffer."
460 :group 'gnus-article-various)
462 (defcustom gnus-article-hide-pgp-hook nil
463 "*A hook called after successfully hiding a PGP signature."
465 :group 'gnus-article-various)
467 (defcustom gnus-article-button-face 'bold
468 "Face used for highlighting buttons in the article buffer.
470 An article button is a piece of text that you can activate by pressing
471 `RET' or `mouse-2' above it."
473 :group 'gnus-article-buttons)
475 (defcustom gnus-article-mouse-face 'highlight
476 "Face used for mouse highlighting in the article buffer.
478 Article buttons will be displayed in this face when the cursor is
481 :group 'gnus-article-buttons)
483 (defcustom gnus-signature-face 'gnus-signature-face
484 "Face used for highlighting a signature in the article buffer.
485 Obsolete; use the face `gnus-signature-face' for customizations instead."
487 :group 'gnus-article-highlight
488 :group 'gnus-article-signature)
490 (defface gnus-signature-face
493 "Face used for highlighting a signature in the article buffer."
494 :group 'gnus-article-highlight
495 :group 'gnus-article-signature)
497 (defface gnus-header-from-face
500 (:foreground "spring green"))
503 (:foreground "red3"))
506 "Face used for displaying from headers."
507 :group 'gnus-article-headers
508 :group 'gnus-article-highlight)
510 (defface gnus-header-subject-face
513 (:foreground "SeaGreen3"))
516 (:foreground "red4"))
518 (:bold t :italic t)))
519 "Face used for displaying subject headers."
520 :group 'gnus-article-headers
521 :group 'gnus-article-highlight)
523 (defface gnus-header-newsgroups-face
526 (:foreground "yellow" :italic t))
529 (:foreground "MidnightBlue" :italic t))
532 "Face used for displaying newsgroups headers."
533 :group 'gnus-article-headers
534 :group 'gnus-article-highlight)
536 (defface gnus-header-name-face
539 (:foreground "SeaGreen"))
542 (:foreground "maroon"))
545 "Face used for displaying header names."
546 :group 'gnus-article-headers
547 :group 'gnus-article-highlight)
549 (defface gnus-header-content-face
552 (:foreground "forest green" :italic t))
555 (:foreground "indianred4" :italic t))
557 (:italic t))) "Face used for displaying header content."
558 :group 'gnus-article-headers
559 :group 'gnus-article-highlight)
561 (defcustom gnus-header-face-alist
562 '(("From" nil gnus-header-from-face)
563 ("Subject" nil gnus-header-subject-face)
564 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
565 ("" gnus-header-name-face gnus-header-content-face))
566 "*Controls highlighting of article header.
568 An alist of the form (HEADER NAME CONTENT).
570 HEADER is a regular expression which should match the name of an
571 header header and NAME and CONTENT are either face names or nil.
573 The name of each header field will be displayed using the face
574 specified by the first element in the list where HEADER match the
575 header name and NAME is non-nil. Similarly, the content will be
576 displayed by the first non-nil matching CONTENT face."
577 :group 'gnus-article-headers
578 :group 'gnus-article-highlight
579 :type '(repeat (list (regexp :tag "Header")
581 (item :tag "skip" nil)
582 (face :value default))
583 (choice :tag "Content"
584 (item :tag "skip" nil)
585 (face :value default)))))
587 (defcustom gnus-article-decode-hook nil
588 "*Hook run to decode charsets in articles."
589 :group 'gnus-article-headers
592 (defcustom gnus-display-mime-function 'gnus-display-mime
593 "Function to display MIME articles."
594 :group 'gnus-article-mime
597 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
598 "Function used to decode headers.")
600 (defvar gnus-article-dumbquotes-map
618 "Table for MS-to-Latin1 translation.")
620 (defcustom gnus-ignored-mime-types nil
621 "List of MIME types that should be ignored by Gnus."
622 :group 'gnus-article-mime
623 :type '(repeat regexp))
625 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
626 "List of MIME types that should not be given buttons when rendered inline."
627 :group 'gnus-article-mime
628 :type '(repeat regexp))
630 (defcustom gnus-article-mime-part-function nil
631 "Function called with a MIME handle as the argument.
632 This is meant for people who want to do something automatic based
633 on parts -- for instance, adding Vcard info to a database."
634 :group 'gnus-article-mime
637 (defcustom gnus-mime-multipart-functions nil
638 "An alist of MIME types to functions to display them.")
640 (defcustom gnus-article-date-lapsed-new-header nil
641 "Whether the X-Sent and Date headers can coexist.
642 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
643 either replace the old \"Date:\" header (if this variable is nil), or
644 be added below it (otherwise)."
645 :group 'gnus-article-headers
649 ;;; The treatment variables
652 (defvar gnus-part-display-hook nil
653 "Hook called on parts that are to receive treatment.")
655 (defvar gnus-article-treat-custom
656 '(choice (const :tag "Off" nil)
658 (const :tag "Header" head)
659 (const :tag "Last" last)
660 (const :tag "Mime" mime)
661 (integer :tag "Less")
662 (repeat :tag "Groups" regexp)
663 (sexp :tag "Predicate")))
665 (defvar gnus-article-treat-head-custom
666 '(choice (const :tag "Off" nil)
667 (const :tag "Header" head)))
669 (defvar gnus-article-treat-types '("text/plain")
672 (defvar gnus-inhibit-treatment nil
673 "Whether to inhibit treatment.")
675 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
676 "Highlight the signature.
677 Valid values are nil, t, `head', `last', an integer or a predicate.
678 See the manual for details."
679 :group 'gnus-article-treat
680 :type gnus-article-treat-custom)
681 (put 'gnus-treat-highlight-signature 'highlight t)
683 (defcustom gnus-treat-buttonize t
685 Valid values are nil, t, `head', `last', an integer or a predicate.
686 See the manual for details."
687 :group 'gnus-article-treat
688 :type gnus-article-treat-custom)
689 (put 'gnus-treat-buttonize 'highlight t)
691 (defcustom gnus-treat-buttonize-head 'head
692 "Add buttons to the head.
693 Valid values are nil, t, `head', `last', an integer or a predicate.
694 See the manual for details."
695 :group 'gnus-article-treat
696 :type gnus-article-treat-head-custom)
697 (put 'gnus-treat-buttonize-head 'highlight t)
699 (defcustom gnus-treat-emphasize nil
701 Valid values are nil, t, `head', `last', an integer or a predicate.
702 See the manual for details."
703 :group 'gnus-article-treat
704 :type gnus-article-treat-custom)
705 (put 'gnus-treat-emphasize 'highlight t)
707 (defcustom gnus-treat-strip-cr nil
708 "Remove carriage returns.
709 Valid values are nil, t, `head', `last', an integer or a predicate.
710 See the manual for details."
711 :group 'gnus-article-treat
712 :type gnus-article-treat-custom)
714 (defcustom gnus-treat-hide-headers 'head
716 Valid values are nil, t, `head', `last', an integer or a predicate.
717 See the manual for details."
718 :group 'gnus-article-treat
719 :type gnus-article-treat-head-custom)
721 (defcustom gnus-treat-hide-boring-headers nil
722 "Hide boring headers.
723 Valid values are nil, t, `head', `last', an integer or a predicate.
724 See the manual for details."
725 :group 'gnus-article-treat
726 :type gnus-article-treat-head-custom)
728 (defcustom gnus-treat-hide-signature nil
730 Valid values are nil, t, `head', `last', an integer or a predicate.
731 See the manual for details."
732 :group 'gnus-article-treat
733 :type gnus-article-treat-custom)
735 (defcustom gnus-treat-fill-article nil
737 Valid values are nil, t, `head', `last', an integer or a predicate.
738 See the manual for details."
739 :group 'gnus-article-treat
740 :type gnus-article-treat-custom)
742 (defcustom gnus-treat-hide-citation nil
744 Valid values are nil, t, `head', `last', an integer or a predicate.
745 See the manual for details."
746 :group 'gnus-article-treat
747 :type gnus-article-treat-custom)
749 (defcustom gnus-treat-strip-list-identifiers 'head
750 "Strip list identifiers from `gnus-list-identifiers`.
751 Valid values are nil, t, `head', `last', an integer or a predicate.
752 See the manual for details."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-custom)
756 (defcustom gnus-treat-strip-pgp t
757 "Strip PGP signatures.
758 Valid values are nil, t, `head', `last', an integer or a predicate.
759 See the manual for details."
760 :group 'gnus-article-treat
761 :type gnus-article-treat-custom)
763 (defcustom gnus-treat-strip-pem nil
764 "Strip PEM signatures.
765 Valid values are nil, t, `head', `last', an integer or a predicate.
766 See the manual for details."
767 :group 'gnus-article-treat
768 :type gnus-article-treat-custom)
770 (defcustom gnus-treat-strip-banner t
771 "Strip banners from articles.
772 The banner to be stripped is specified in the `banner' group parameter.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-custom)
778 (defcustom gnus-treat-highlight-headers 'head
779 "Highlight the headers.
780 Valid values are nil, t, `head', `last', an integer or a predicate.
781 See the manual for details."
782 :group 'gnus-article-treat
783 :type gnus-article-treat-head-custom)
784 (put 'gnus-treat-highlight-headers 'highlight t)
786 (defcustom gnus-treat-highlight-citation t
787 "Highlight cited text.
788 Valid values are nil, t, `head', `last', an integer or a predicate.
789 See the manual for details."
790 :group 'gnus-article-treat
791 :type gnus-article-treat-custom)
792 (put 'gnus-treat-highlight-citation 'highlight t)
794 (defcustom gnus-treat-date-ut nil
795 "Display the Date in UT (GMT).
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-head-custom)
801 (defcustom gnus-treat-date-local nil
802 "Display the Date in the local timezone.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-head-custom)
808 (defcustom gnus-treat-date-lapsed nil
809 "Display the Date header in a way that says how much time has elapsed.
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-head-custom)
815 (defcustom gnus-treat-date-original nil
816 "Display the date in the original timezone.
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-head-custom)
822 (defcustom gnus-treat-date-iso8601 nil
823 "Display the date in the ISO8601 format.
824 Valid values are nil, t, `head', `last', an integer or a predicate.
825 See the manual for details."
826 :group 'gnus-article-treat
827 :type gnus-article-treat-head-custom)
829 (defcustom gnus-treat-date-user-defined nil
830 "Display the date in a user-defined format.
831 The format is defined by the `gnus-article-time-format' variable.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-head-custom)
837 (defcustom gnus-treat-strip-headers-in-body t
838 "Strip the X-No-Archive header line from the beginning of the body.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-custom)
844 (defcustom gnus-treat-strip-trailing-blank-lines nil
845 "Strip trailing blank lines.
846 Valid values are nil, t, `head', `last', an integer or a predicate.
847 See the manual for details."
848 :group 'gnus-article-treat
849 :type gnus-article-treat-custom)
851 (defcustom gnus-treat-strip-leading-blank-lines nil
852 "Strip leading blank lines.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-custom)
858 (defcustom gnus-treat-strip-multiple-blank-lines nil
859 "Strip multiple blank lines.
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862 :group 'gnus-article-treat
863 :type gnus-article-treat-custom)
865 (defcustom gnus-treat-overstrike t
866 "Treat overstrike highlighting.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
871 (put 'gnus-treat-overstrike 'highlight t)
873 (defcustom gnus-treat-display-xface
874 (if (or (and gnus-xemacs (featurep 'xface))
875 (eq 'x-face-mule-gnus-article-display-x-face
876 gnus-article-x-face-command))
879 "Display X-Face headers.
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882 :group 'gnus-article-treat
883 :type gnus-article-treat-head-custom)
884 (put 'gnus-treat-display-xface 'highlight t)
886 (defcustom gnus-treat-display-smileys
887 (if (or (and gnus-xemacs (featurep 'xpm))
888 (module-installed-p 'smiley-mule))
892 Valid values are nil, t, `head', `last', an integer or a predicate.
893 See the manual for details."
894 :group 'gnus-article-treat
895 :type gnus-article-treat-custom)
896 (put 'gnus-treat-display-smileys 'highlight t)
898 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
900 Valid values are nil, t, `head', `last', an integer or a predicate.
901 See the manual for details."
902 :group 'gnus-article-treat
903 :type gnus-article-treat-head-custom)
904 (put 'gnus-treat-display-picons 'highlight t)
906 (defcustom gnus-treat-capitalize-sentences nil
907 "Capitalize sentence-starting words.
908 Valid values are nil, t, `head', `last', an integer or a predicate.
909 See the manual for details."
910 :group 'gnus-article-treat
911 :type gnus-article-treat-custom)
913 (defcustom gnus-treat-fill-long-lines nil
915 Valid values are nil, t, `head', `last', an integer or a predicate.
916 See the manual for details."
917 :group 'gnus-article-treat
918 :type gnus-article-treat-custom)
920 (defcustom gnus-treat-play-sounds nil
922 Valid values are nil, t, `head', `last', an integer or a predicate.
923 See the manual for details."
924 :group 'gnus-article-treat
925 :type gnus-article-treat-custom)
927 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
928 "Decode an article as `default-mime-charset'. For instance, if you want to
929 attempt to decode an article even if the value of `gnus-show-mime' is nil,
930 you could set this variable to something like: nil for don't decode, t for
931 decode the body, '(or header t) for the whole article, etc."
932 :group 'gnus-article-treat
933 :type '(radio (const :tag "Off" nil)
934 (const :tag "Decode body" t)
935 (const :tag "Decode all" (or head t))))
937 (defcustom gnus-treat-translate nil
938 "Translate articles from one language to another.
939 Valid values are nil, t, `head', `last', an integer or a predicate.
940 See the manual for details."
941 :group 'gnus-article-treat
942 :type gnus-article-treat-custom)
944 ;;; Internal variables
946 (defvar article-goto-body-goes-to-point-min-p nil)
947 (defvar gnus-article-wash-types nil)
948 (defvar gnus-article-emphasis-alist nil)
950 (defvar gnus-article-mime-handle-alist-1 nil)
951 (defvar gnus-treatment-function-alist
952 '((gnus-treat-decode-article-as-default-mime-charset
953 gnus-article-decode-article-as-default-mime-charset)
954 (gnus-treat-strip-banner gnus-article-strip-banner)
955 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
956 (gnus-treat-buttonize gnus-article-add-buttons)
957 (gnus-treat-fill-article gnus-article-fill-cited-article)
958 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
959 (gnus-treat-strip-cr gnus-article-remove-cr)
960 (gnus-treat-display-xface gnus-article-display-x-face)
961 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
962 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
963 (gnus-treat-hide-signature gnus-article-hide-signature)
964 (gnus-treat-hide-citation gnus-article-hide-citation)
965 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
966 (gnus-treat-strip-pgp gnus-article-hide-pgp)
967 (gnus-treat-strip-pem gnus-article-hide-pem)
968 (gnus-treat-highlight-headers gnus-article-highlight-headers)
969 (gnus-treat-emphasize gnus-article-emphasize)
970 (gnus-treat-highlight-citation gnus-article-highlight-citation)
971 (gnus-treat-highlight-signature gnus-article-highlight-signature)
972 (gnus-treat-date-ut gnus-article-date-ut)
973 (gnus-treat-date-local gnus-article-date-local)
974 (gnus-treat-date-lapsed gnus-article-date-lapsed)
975 (gnus-treat-date-original gnus-article-date-original)
976 (gnus-treat-date-user-defined gnus-article-date-user)
977 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
978 (gnus-treat-strip-trailing-blank-lines
979 gnus-article-remove-trailing-blank-lines)
980 (gnus-treat-strip-leading-blank-lines
981 gnus-article-strip-leading-blank-lines)
982 (gnus-treat-strip-multiple-blank-lines
983 gnus-article-strip-multiple-blank-lines)
984 (gnus-treat-overstrike gnus-article-treat-overstrike)
985 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
986 (gnus-treat-display-smileys gnus-smiley-display)
987 (gnus-treat-display-picons gnus-article-display-picons)
988 (gnus-treat-play-sounds gnus-earcon-display)))
990 (defvar gnus-article-mime-handle-alist nil)
991 (defvar article-lapsed-timer nil)
992 (defvar gnus-article-current-summary nil)
994 (defvar gnus-article-mode-syntax-table
995 (let ((table (copy-syntax-table text-mode-syntax-table)))
996 (modify-syntax-entry ?- "w" table)
997 (modify-syntax-entry ?> ")" table)
998 (modify-syntax-entry ?< "(" table)
1000 "Syntax table used in article mode buffers.
1001 Initialized from `text-mode-syntax-table.")
1003 (defvar gnus-save-article-buffer nil)
1005 (defvar gnus-article-mode-line-format-alist
1006 (nconc '((?w (gnus-article-wash-status) ?s)
1007 (?m (gnus-article-mime-part-status) ?s))
1008 gnus-summary-mode-line-format-alist))
1010 (defvar gnus-number-of-articles-to-be-saved nil)
1012 (defvar gnus-inhibit-hiding nil)
1014 (defsubst gnus-article-hide-text (b e props)
1015 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1016 (add-text-properties b e props)
1017 (when (memq 'intangible props)
1019 (max (1- b) (point-min))
1020 b 'intangible (cddr (memq 'intangible props)))))
1021 (defsubst gnus-article-unhide-text (b e)
1022 "Remove hidden text properties from region between B and E."
1023 (remove-text-properties b e gnus-hidden-properties)
1024 (when (memq 'intangible gnus-hidden-properties)
1025 (put-text-property (max (1- b) (point-min))
1026 b 'intangible nil)))
1028 (defun gnus-article-hide-text-type (b e type)
1029 "Hide text of TYPE between B and E."
1030 (push type gnus-article-wash-types)
1031 (gnus-article-hide-text
1032 b e (cons 'article-type (cons type gnus-hidden-properties))))
1034 (defun gnus-article-unhide-text-type (b e type)
1035 "Unhide text of TYPE between B and E."
1036 (setq gnus-article-wash-types
1037 (delq type gnus-article-wash-types))
1038 (remove-text-properties
1039 b e (cons 'article-type (cons type gnus-hidden-properties)))
1040 (when (memq 'intangible gnus-hidden-properties)
1041 (put-text-property (max (1- b) (point-min))
1042 b 'intangible nil)))
1044 (defun gnus-article-hide-text-of-type (type)
1045 "Hide text of TYPE in the current buffer."
1047 (let ((b (point-min))
1049 (while (setq b (text-property-any b e 'article-type type))
1050 (add-text-properties b (incf b) gnus-hidden-properties)))))
1052 (defun gnus-article-delete-text-of-type (type)
1053 "Delete text of TYPE in the current buffer."
1055 (let ((b (point-min)))
1056 (while (setq b (text-property-any b (point-max) 'article-type type))
1058 b (or (text-property-not-all b (point-max) 'article-type type)
1061 (defun gnus-article-delete-invisible-text ()
1062 "Delete all invisible text in the current buffer."
1064 (let ((b (point-min)))
1065 (while (setq b (text-property-any b (point-max) 'invisible t))
1067 b (or (text-property-not-all b (point-max) 'invisible t)
1070 (defun gnus-article-text-type-exists-p (type)
1071 "Say whether any text of type TYPE exists in the buffer."
1072 (text-property-any (point-min) (point-max) 'article-type type))
1074 (defsubst gnus-article-header-rank ()
1075 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1076 (let ((list gnus-sorted-header-list)
1079 (when (looking-at (car list))
1081 (setq list (cdr list))
1085 (defun article-hide-headers (&optional arg delete)
1086 "Hide unwanted headers and possibly sort them as well."
1087 (interactive (gnus-article-hidden-arg))
1088 ;; Lars said that this function might be inhibited.
1089 (if (gnus-article-check-hidden-text 'headers arg)
1091 ;; Show boring headers as well.
1092 (gnus-article-show-hidden-text 'boring-headers)
1093 (when (eq 1 (point-min))
1094 (set-window-start (get-buffer-window (current-buffer)) 1)))
1095 (unless gnus-inhibit-hiding
1098 (let ((buffer-read-only nil)
1099 (inhibit-read-only t)
1100 (case-fold-search t)
1101 (max (1+ (length gnus-sorted-header-list)))
1102 (ignored (when (not gnus-visible-headers)
1103 (cond ((stringp gnus-ignored-headers)
1104 gnus-ignored-headers)
1105 ((listp gnus-ignored-headers)
1106 (mapconcat 'identity gnus-ignored-headers
1109 (cond ((stringp gnus-visible-headers)
1110 gnus-visible-headers)
1111 ((and gnus-visible-headers
1112 (listp gnus-visible-headers))
1113 (mapconcat 'identity gnus-visible-headers "\\|"))))
1114 (inhibit-point-motion-hooks t)
1116 ;; First we narrow to just the headers.
1117 (article-narrow-to-head)
1118 ;; Hide any "From " lines at the beginning of (mail) articles.
1119 (while (looking-at "From ")
1123 (delete-region (point-min) (point))
1124 (gnus-article-hide-text (point-min) (point)
1125 (nconc (list 'article-type 'headers)
1126 gnus-hidden-properties))))
1127 ;; Then treat the rest of the header lines.
1128 ;; Then we use the two regular expressions
1129 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1130 ;; select which header lines is to remain visible in the
1132 (while (re-search-forward "^[^ \t]*:" nil t)
1134 ;; Mark the rank of the header.
1136 (point) (1+ (point)) 'message-rank
1137 (if (or (and visible (looking-at visible))
1139 (not (looking-at ignored))))
1140 (gnus-article-header-rank)
1143 (message-sort-headers-1)
1144 (when (setq beg (text-property-any
1145 (point-min) (point-max) 'message-rank (+ 2 max)))
1146 ;; We delete or make invisible the unwanted headers.
1149 (add-text-properties
1150 (point-min) (+ 5 (point-min))
1151 '(article-type headers dummy-invisible t))
1152 (delete-region beg (point-max)))
1153 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1156 (defun article-hide-boring-headers (&optional arg)
1157 "Toggle hiding of headers that aren't very interesting.
1158 If given a negative prefix, always show; if given a positive prefix,
1160 (interactive (gnus-article-hidden-arg))
1161 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1162 (not gnus-show-all-headers))
1165 (let ((buffer-read-only nil)
1166 (list gnus-boring-article-headers)
1167 (inhibit-point-motion-hooks t)
1169 (article-narrow-to-head)
1171 (setq elem (pop list))
1172 (goto-char (point-min))
1174 ;; Hide empty headers.
1176 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1178 (gnus-article-hide-text-type
1179 (progn (beginning-of-line) (point))
1182 (if (re-search-forward "^[^ \t]" nil t)
1186 ;; Hide boring Newsgroups header.
1187 ((eq elem 'newsgroups)
1188 (when (equal (gnus-fetch-field "newsgroups")
1189 (gnus-group-real-name
1190 (if (boundp 'gnus-newsgroup-name)
1193 (gnus-article-hide-header "newsgroups")))
1194 ((eq elem 'followup-to)
1195 (when (equal (message-fetch-field "followup-to")
1196 (message-fetch-field "newsgroups"))
1197 (gnus-article-hide-header "followup-to")))
1198 ((eq elem 'reply-to)
1199 (let ((from (message-fetch-field "from"))
1200 (reply-to (message-fetch-field "reply-to")))
1205 (nth 1 (funcall gnus-extract-address-components from))
1206 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1207 (gnus-article-hide-header "reply-to"))))
1209 (let ((date (message-fetch-field "date")))
1211 (< (days-between (current-time-string) date)
1213 (gnus-article-hide-header "date"))))
1215 (let ((to (message-fetch-field "to")))
1216 (when (> (length to) 1024)
1217 (gnus-article-hide-header "to"))))
1220 (goto-char (point-min))
1221 (while (re-search-forward "^to:" nil t)
1222 (setq to-count (1+ to-count)))
1223 (when (> to-count 1)
1224 (while (> to-count 0)
1225 (goto-char (point-min))
1227 (re-search-forward "^to:" nil nil to-count)
1229 (narrow-to-region (point) (point-max))
1230 (gnus-article-hide-header "to"))
1231 (setq to-count (1- to-count)))))))))))))
1233 (defun gnus-article-hide-header (header)
1235 (goto-char (point-min))
1236 (when (re-search-forward (concat "^" header ":") nil t)
1237 (gnus-article-hide-text-type
1238 (progn (beginning-of-line) (point))
1241 (if (re-search-forward "^[^ \t]" nil t)
1246 (defun article-toggle-headers (&optional arg)
1247 "Toggle hiding of headers. If given a negative prefix, always show;
1248 if given a positive prefix, always hide."
1249 (interactive (gnus-article-hidden-arg))
1250 (let ((force (when (numberp arg)
1251 (cond ((> arg 0) 'always-hide)
1252 ((< arg 0) 'always-show))))
1253 (window (get-buffer-window gnus-article-buffer))
1254 (header-end (point-min))
1255 header-start field-end field-start
1256 (inhibit-point-motion-hooks t)
1257 (inhibit-read-only t)
1261 (while (and (setq header-start
1262 (text-property-any header-end (point-max)
1263 'article-treated-header t))
1265 (text-property-not-all header-start (point-max)
1266 'article-treated-header t)))
1267 (setq field-end header-start)
1269 (;; Hide exposed invisible fields.
1270 (and (not (eq 'always-show force))
1272 (text-property-any field-end header-end
1273 'exposed-invisible-field t)))
1274 (while (and field-start
1275 (setq field-end (text-property-not-all
1276 field-start header-end
1277 'exposed-invisible-field t)))
1278 (add-text-properties field-start field-end gnus-hidden-properties)
1279 (setq field-start (text-property-any field-end header-end
1280 'exposed-invisible-field t)))
1281 (put-text-property header-start header-end
1282 'exposed-invisible-field nil))
1283 (;; Expose invisible fields.
1284 (and (not (eq 'always-hide force))
1286 (text-property-any field-end header-end 'invisible t)))
1287 (while (and field-start
1288 (setq field-end (text-property-not-all
1289 field-start header-end
1291 ;; If the invisible text is not terminated with newline, we
1292 ;; won't expose it. Because it may be created by x-face-mule.
1293 ;; BTW, XEmacs sometimes fail in putting a invisible text
1294 ;; property with `gnus-article-hide-text' (really?). In that
1295 ;; case, the invisible text might be started from the middle of
1296 ;; a line so we will expose the sort of thing.
1297 (when (or (not (or (eq header-start field-start)
1298 (eq ?\n (char-before field-start))))
1299 (eq ?\n (char-before field-end)))
1300 (remove-text-properties field-start field-end
1301 gnus-hidden-properties)
1302 (put-text-property field-start field-end
1303 'exposed-invisible-field t))
1304 (setq field-start (text-property-any field-end header-end
1307 (not (eq 'always-show force))
1308 (narrow-to-region header-start header-end)
1309 (article-hide-headers)
1310 ;; Re-display X-Face image under XEmacs.
1311 (when (and gnus-xemacs
1312 (gnus-functionp gnus-article-x-face-command))
1313 (let ((func (cadr (assq 'gnus-treat-display-xface
1314 gnus-treatment-function-alist)))
1316 (when (and (not gnus-inhibit-treatment)
1318 (gnus-treat-predicate gnus-treat-display-xface))
1320 (put-text-property header-start header-end 'read-only nil))))
1323 (goto-char (point-min))
1325 (set-window-start window (point-min))))))
1327 (defvar gnus-article-normalized-header-length 40
1328 "Length of normalized headers.")
1330 (defun article-normalize-headers ()
1331 "Make all header lines 40 characters long."
1333 (let ((buffer-read-only nil)
1337 (article-narrow-to-head)
1340 ((< (setq column (- (gnus-point-at-eol) (point)))
1341 gnus-article-normalized-header-length)
1343 (insert (make-string
1344 (- gnus-article-normalized-header-length column)
1346 ((> column gnus-article-normalized-header-length)
1347 (gnus-put-text-property
1349 (forward-char gnus-article-normalized-header-length)
1356 (forward-line 1))))))
1358 (defun article-treat-dumbquotes ()
1359 "Translate M******** sm*rtq**t*s into proper text.
1360 Note that this function guesses whether a character is a sm*rtq**t* or
1361 not, so it should only be used interactively."
1363 (article-translate-strings gnus-article-dumbquotes-map))
1365 (defun article-translate-characters (from to)
1366 "Translate all characters in the body of the article according to FROM and TO.
1367 FROM is a string of characters to translate from; to is a string of
1368 characters to translate to."
1370 (when (article-goto-body)
1371 (let ((buffer-read-only nil)
1372 (x (make-string 225 ?x))
1374 (while (< (incf i) (length x))
1377 (while (< i (length from))
1378 (aset x (aref from i) (aref to i))
1380 (translate-region (point) (point-max) x)))))
1382 (defun article-translate-strings (map)
1383 "Translate all string in the body of the article according to MAP.
1384 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1386 (when (article-goto-body)
1387 (let ((buffer-read-only nil)
1389 (while (setq elem (pop map))
1391 (while (search-forward (car elem) nil t)
1392 (replace-match (cadr elem)))))))))
1394 (defun article-treat-overstrike ()
1395 "Translate overstrikes into bold text."
1398 (when (article-goto-body)
1399 (let ((buffer-read-only nil))
1400 (while (search-forward "\b" nil t)
1401 (let ((next (char-after))
1402 (previous (char-after (- (point) 2))))
1403 ;; We do the boldification/underlining by hiding the
1404 ;; overstrikes and putting the proper text property
1408 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1409 (put-text-property (point) (1+ (point)) 'face 'bold))
1411 (gnus-article-hide-text-type
1412 (1- (point)) (1+ (point)) 'overstrike)
1414 (- (point) 2) (1- (point)) 'face 'underline))
1416 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1418 (point) (1+ (point)) 'face 'underline)))))))))
1420 (defun article-fill-long-lines ()
1421 "Fill lines that are wider than the window width."
1424 (let ((buffer-read-only nil)
1425 (width (window-width (get-buffer-window (current-buffer)))))
1428 (let ((adaptive-fill-mode nil))
1431 (when (>= (current-column) (min fill-column width))
1432 (narrow-to-region (point) (gnus-point-at-bol))
1433 (fill-paragraph nil)
1434 (goto-char (point-max))
1436 (forward-line 1)))))))
1438 (defun article-capitalize-sentences ()
1439 "Capitalize the first word in each sentence."
1442 (let ((buffer-read-only nil)
1443 (paragraph-start "^[\n\^L]"))
1447 (forward-sentence)))))
1449 (defun article-remove-cr ()
1450 "Remove trailing CRs and then translate remaining CRs into LFs."
1453 (let ((buffer-read-only nil))
1454 (goto-char (point-min))
1455 (while (re-search-forward "\r+$" nil t)
1456 (replace-match "" t t))
1457 (goto-char (point-min))
1458 (while (search-forward "\r" nil t)
1459 (replace-match "\n" t t)))))
1461 (defun article-remove-trailing-blank-lines ()
1462 "Remove all trailing blank lines from the article."
1465 (let ((buffer-read-only nil))
1466 (goto-char (point-max))
1470 (while (and (not (bobp))
1471 (looking-at "^[ \t]*$")
1472 (not (gnus-annotation-in-region-p
1473 (point) (gnus-point-at-eol))))
1478 (defun article-display-x-face (&optional force)
1479 "Look for an X-Face header and display it if present."
1480 (interactive (list 'force))
1482 ;; Delete the old process, if any.
1483 (when (process-status "article-x-face")
1484 (delete-process "article-x-face"))
1485 (let ((inhibit-point-motion-hooks t)
1486 (case-fold-search t)
1489 (article-narrow-to-head)
1490 (goto-char (point-min))
1491 (setq from (message-fetch-field "from"))
1492 (goto-char (point-min))
1493 (while (and gnus-article-x-face-command
1496 ;; Check whether this face is censored.
1497 (not gnus-article-x-face-too-ugly)
1498 (and gnus-article-x-face-too-ugly from
1499 (not (string-match gnus-article-x-face-too-ugly
1501 ;; Has to be present.
1502 (re-search-forward "^X-Face: " nil t))
1503 ;; This used to try to do multiple faces (`while' instead of
1504 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1505 ;; work (b) it can crash some versions of Emacs (c) are
1506 ;; multiple faces really something to encourage?
1507 (when (stringp gnus-article-x-face-command)
1509 ;; We now have the area of the buffer where the X-Face is stored.
1512 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1513 ;; We display the face.
1514 (if (symbolp gnus-article-x-face-command)
1515 ;; The command is a lisp function, so we call it.
1516 (if (gnus-functionp gnus-article-x-face-command)
1517 (funcall gnus-article-x-face-command beg end)
1518 (error "%s is not a function" gnus-article-x-face-command))
1519 ;; The command is a string, so we interpret the command
1520 ;; as a, well, command, and fork it off.
1521 (let ((process-connection-type nil))
1522 (process-kill-without-query
1524 "article-x-face" nil shell-file-name shell-command-switch
1525 gnus-article-x-face-command))
1526 (process-send-region "article-x-face" beg end)
1527 (process-send-eof "article-x-face"))))))))))
1529 (defun article-decode-mime-words ()
1530 "Decode all MIME-encoded words in the article."
1533 (set-buffer gnus-article-buffer)
1534 (let ((inhibit-point-motion-hooks t)
1536 (mail-parse-charset gnus-newsgroup-charset)
1537 (mail-parse-ignored-charsets
1538 (save-excursion (set-buffer gnus-summary-buffer)
1539 gnus-newsgroup-ignored-charsets)))
1540 (mail-decode-encoded-word-region (point-min) (point-max)))))
1542 (defun article-decode-charset (&optional prompt)
1543 "Decode charset-encoded text in the article.
1544 If PROMPT (the prefix), prompt for a coding system to use."
1548 (article-narrow-to-head)
1549 (let* ((inhibit-point-motion-hooks t)
1550 (case-fold-search t)
1551 (ct (message-fetch-field "Content-Type" t))
1552 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1553 (ctl (and ct (ignore-errors
1554 (mail-header-parse-content-type ct))))
1557 (mm-read-coding-system "Charset to decode: "))
1559 (mail-content-type-get ctl 'charset))))
1560 (mail-parse-charset gnus-newsgroup-charset)
1561 (mail-parse-ignored-charsets
1562 (save-excursion (condition-case nil
1563 (set-buffer gnus-summary-buffer)
1565 gnus-newsgroup-ignored-charsets))
1567 (if (and ctl (not (string-match "/" (car ctl))))
1569 (goto-char (point-max))
1572 (narrow-to-region (point) (point-max))
1573 (when (and (or (not ctl)
1574 (equal (car ctl) "text/plain"))
1577 charset (and cte (intern (downcase
1578 (gnus-strip-whitespace cte))))
1581 (defun article-decode-encoded-words ()
1582 "Remove encoded-word encoding from headers."
1583 (let (buffer-read-only)
1584 (let ((charset (save-excursion
1585 (set-buffer gnus-summary-buffer)
1586 default-mime-charset)))
1587 (mime-decode-header-in-buffer charset)
1590 (defun article-de-quoted-unreadable (&optional force)
1591 "Translate a quoted-printable-encoded article.
1592 If FORCE, decode the article whether it is marked as quoted-printable
1594 (interactive (list 'force))
1596 (let ((buffer-read-only nil)
1597 (type (gnus-fetch-field "content-transfer-encoding"))
1598 (charset gnus-newsgroup-charset))
1600 (and type (string-match "quoted-printable" (downcase type))))
1603 (narrow-to-region (point) (point-max))
1604 (quoted-printable-decode-region (point-min) (point-max))
1606 (mm-decode-body charset)))))))
1608 (defun article-hide-list-identifiers ()
1609 "Remove any list identifiers in `gnus-list-identifiers' from Subject
1610 header in the current article."
1614 (let ((inhibit-point-motion-hooks t)
1616 (article-narrow-to-head)
1617 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1618 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1620 (goto-char (point-min))
1621 (when (re-search-forward
1622 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1624 (delete-region (match-beginning 2) (match-end 0)))))))))
1626 (defun article-hide-pgp ()
1627 "Remove any PGP headers and signatures in the current article."
1631 (let ((inhibit-point-motion-hooks t)
1632 buffer-read-only beg end)
1634 ;; Hide the "header".
1635 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1636 (push 'pgp gnus-article-wash-types)
1637 (delete-region (match-beginning 0) (match-end 0))
1638 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1639 (when (looking-at "Hash:.*$")
1640 (delete-region (point) (1+ (gnus-point-at-eol))))
1642 ;; Hide the actual signature.
1643 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1644 (setq end (1+ (match-beginning 0)))
1647 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1649 ;; Perhaps we shouldn't hide to the end of the buffer
1650 ;; if there is no end to the signature?
1652 ;; Hide "- " PGP quotation markers.
1654 (narrow-to-region beg end)
1655 (goto-char (point-min))
1656 (while (re-search-forward "^- " nil t)
1658 (match-beginning 0) (match-end 0)))
1660 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1662 (defun article-hide-pem (&optional arg)
1663 "Toggle hiding of any PEM headers and signatures in the current article.
1664 If given a negative prefix, always show; if given a positive prefix,
1666 (interactive (gnus-article-hidden-arg))
1667 (unless (gnus-article-check-hidden-text 'pem arg)
1669 (let (buffer-read-only end)
1670 (goto-char (point-min))
1671 ;; Hide the horrendously ugly "header".
1672 (when (and (search-forward
1673 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1675 (setq end (1+ (match-beginning 0))))
1676 (push 'pem gnus-article-wash-types)
1677 (gnus-article-hide-text-type
1679 (if (search-forward "\n\n" nil t)
1683 ;; Hide the trailer as well
1684 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1686 (gnus-article-hide-text-type
1687 (match-beginning 0) (match-end 0) 'pem)))))))
1689 (defun article-strip-banner ()
1690 "Strip the banner specified by the `banner' group parameter."
1694 (let ((inhibit-point-motion-hooks t)
1695 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1696 (gnus-signature-limit nil)
1697 buffer-read-only beg end)
1701 ((eq banner 'signature)
1702 (when (gnus-article-narrow-to-signature)
1705 (delete-region (point) (point-max))))
1707 (while (re-search-forward banner nil t)
1708 (delete-region (match-beginning 0) (match-end 0))))))))))
1710 (defun article-babel ()
1711 "Translate article using an online translation service."
1715 (set-buffer gnus-article-buffer)
1716 (when (article-goto-body)
1717 (let* ((buffer-read-only nil)
1720 (orig (buffer-substring start end))
1721 (trans (babel-as-string orig)))
1723 (narrow-to-region start end)
1724 (delete-region start end)
1727 (defun article-hide-signature (&optional arg)
1728 "Hide the signature in the current article.
1729 If given a negative prefix, always show; if given a positive prefix,
1731 (interactive (gnus-article-hidden-arg))
1737 (article-goto-body))
1738 (goto-char (point-min)))
1739 (unless (gnus-article-check-hidden-text 'signature arg)
1740 (let ((buffer-read-only nil)
1742 (while (setq button (text-property-any button (point-max)
1744 'gnus-signature-toggle))
1745 (setq button (text-property-not-all button (point-max)
1747 'gnus-signature-toggle))
1748 (when (and button (not (eobp)))
1749 (gnus-article-hide-text-type
1751 (or (next-single-property-change (1+ button) 'mime-view-entity)
1755 (defun article-strip-headers-in-body ()
1756 "Strip offensive headers from bodies."
1760 (let ((case-fold-search t))
1761 (when (looking-at "x-no-archive:")
1762 (gnus-delete-line)))))
1764 (defun article-strip-leading-blank-lines ()
1765 "Remove all blank lines from the beginning of the article."
1768 (let ((inhibit-point-motion-hooks t)
1770 (when (article-goto-body)
1771 (while (and (not (eobp))
1772 (looking-at "[ \t]*$"))
1773 (gnus-delete-line))))))
1775 (defun article-narrow-to-head ()
1776 "Narrow the buffer to the head of the message.
1777 Point is left at the beginning of the narrowed-to region."
1779 (goto-char (point-min))
1780 (if (search-forward "\n\n" nil 1)
1783 (goto-char (point-min)))
1785 (defun article-goto-body ()
1786 "Place point at the start of the body."
1787 (goto-char (point-min))
1789 ;; This variable is only bound when dealing with separate
1791 (article-goto-body-goes-to-point-min-p
1793 ((search-forward "\n\n" nil t)
1796 (goto-char (point-max))
1799 (defun article-strip-multiple-blank-lines ()
1800 "Replace consecutive blank lines with one empty line."
1803 (let ((inhibit-point-motion-hooks t)
1805 ;; First make all blank lines empty.
1807 (while (re-search-forward "^[ \t]+$" nil t)
1808 (unless (gnus-annotation-in-region-p
1809 (match-beginning 0) (match-end 0))
1810 (replace-match "" nil t)))
1811 ;; Then replace multiple empty lines with a single empty line.
1813 (while (re-search-forward "\n\n\n+" nil t)
1814 (unless (gnus-annotation-in-region-p
1815 (match-beginning 0) (match-end 0))
1816 (replace-match "\n\n" t t))))))
1818 (defun article-strip-leading-space ()
1819 "Remove all white space from the beginning of the lines in the article."
1822 (let ((inhibit-point-motion-hooks t)
1825 (while (re-search-forward "^[ \t]+" nil t)
1826 (replace-match "" t t)))))
1828 (defun article-strip-trailing-space ()
1829 "Remove all white space from the end of the lines in the article."
1832 (let ((inhibit-point-motion-hooks t)
1835 (while (re-search-forward "[ \t]+$" nil t)
1836 (replace-match "" t t)))))
1838 (defun article-strip-blank-lines ()
1839 "Strip leading, trailing and multiple blank lines."
1841 (article-strip-leading-blank-lines)
1842 (article-remove-trailing-blank-lines)
1843 (article-strip-multiple-blank-lines))
1845 (defun article-strip-all-blank-lines ()
1846 "Strip all blank lines."
1849 (let ((inhibit-point-motion-hooks t)
1852 (while (re-search-forward "^[ \t]*\n" nil t)
1853 (replace-match "" t t)))))
1855 (defun gnus-article-narrow-to-signature ()
1856 "Narrow to the signature; return t if a signature is found, else nil."
1857 (let ((inhibit-point-motion-hooks t))
1858 (when (gnus-article-search-signature)
1860 ;; Check whether we have some limits to what we consider
1861 ;; to be a signature.
1862 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1863 (list gnus-signature-limit)))
1865 (while (setq limit (pop limits))
1866 (if (or (and (integerp limit)
1867 (< (- (point-max) (point)) limit))
1869 (< (count-lines (point) (point-max)) limit))
1870 (and (gnus-functionp limit)
1872 (and (stringp limit)
1873 (not (re-search-forward limit nil t))))
1874 () ; This limit did not succeed.
1878 (narrow-to-region (point) (point-max))
1881 (defun gnus-article-search-signature ()
1882 "Search the current buffer for the signature separator.
1883 Put point at the beginning of the signature separator."
1884 (let ((cur (point)))
1885 (goto-char (point-max))
1886 (if (if (stringp gnus-signature-separator)
1887 (re-search-backward gnus-signature-separator nil t)
1888 (let ((seps gnus-signature-separator))
1890 (not (re-search-backward (car seps) nil t)))
1897 (defun gnus-article-hidden-arg ()
1898 "Return the current prefix arg as a number, or 0 if no prefix."
1899 (list (if current-prefix-arg
1900 (prefix-numeric-value current-prefix-arg)
1903 (defun gnus-article-check-hidden-text (type arg)
1904 "Return nil if hiding is necessary.
1905 Arg can be nil or a number. Nil and positive means hide, negative
1906 means show, 0 means toggle."
1909 (let ((hide (gnus-article-hidden-text-p type)))
1915 (gnus-article-show-hidden-text type))
1917 (if (eq hide 'hidden)
1918 (gnus-article-show-hidden-text type)
1921 (defun gnus-article-hidden-text-p (type)
1922 "Say whether the current buffer contains hidden text of type TYPE."
1923 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1925 (not (get-text-property pos 'invisible))
1926 (not (get-text-property pos 'dummy-invisible)))
1928 (text-property-any (1+ pos) (point-max) 'article-type type)))
1933 (defun gnus-article-show-hidden-text (type &optional hide)
1934 "Show all hidden text of type TYPE.
1935 If HIDE, hide the text instead."
1937 (let ((buffer-read-only nil)
1938 (inhibit-point-motion-hooks t)
1941 (while (setq beg (text-property-any end (point-max) 'article-type type))
1944 (text-property-not-all beg (point-max) 'article-type type)
1947 (gnus-article-hide-text beg end gnus-hidden-properties)
1948 (gnus-article-unhide-text beg end))
1952 (defconst article-time-units
1953 `((year . ,(* 365.25 24 60 60))
1954 (week . ,(* 7 24 60 60))
1955 (day . ,(* 24 60 60))
1959 "Mapping from time units to seconds.")
1961 (defun article-date-ut (&optional type highlight header)
1962 "Convert DATE date to universal time in the current article.
1963 If TYPE is `local', convert to local time; if it is `lapsed', output
1964 how much time has lapsed since DATE. For `lapsed', the value of
1965 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1966 should replace the \"Date:\" one, or should be added below it."
1967 (interactive (list 'ut t))
1968 (let* ((header (or header
1969 (and (eq 1 (point-min))
1970 (mail-header-date (save-excursion
1971 (set-buffer gnus-summary-buffer)
1972 gnus-current-headers)))
1973 (message-fetch-field "date")
1975 (date (if (vectorp header) (mail-header-date header)
1977 (inhibit-point-motion-hooks t)
1978 bface eface date-pos)
1979 (when (and date (not (string= date "")))
1982 (article-narrow-to-head)
1983 (when (or (and (eq type 'lapsed)
1984 gnus-article-date-lapsed-new-header
1985 ;; Attempt to get the face of X-Sent first.
1986 (re-search-forward "^X-Sent:[ \t]" nil t))
1987 (re-search-forward "^Date:[ \t]" nil t)
1988 ;; If Date is missing, try again for X-Sent.
1989 (re-search-forward "^X-Sent:[ \t]" nil t))
1990 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1991 date (or (get-text-property (gnus-point-at-bol)
1994 eface (get-text-property (1- (gnus-point-at-eol))
1996 (let ((buffer-read-only nil))
1997 ;; Delete any old X-Sent headers.
1998 (when (setq date-pos
1999 (text-property-any (point-min) (point-max)
2000 'article-date-lapsed t))
2001 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2002 (delete-region (match-beginning 0)
2003 (progn (forward-line 1) (point))))
2004 (goto-char (point-min))
2005 ;; Delete any old Date headers.
2006 (while (re-search-forward "^Date:[ \t]" nil t)
2008 (setq date-pos (match-beginning 0)))
2009 (unless (and (eq type 'lapsed)
2010 gnus-article-date-lapsed-new-header)
2011 (delete-region (match-beginning 0)
2012 (progn (message-next-header) (point)))))
2015 (goto-char date-pos)
2017 ;; Possibly, Date has been deleted.
2019 (when (and (eq type 'lapsed)
2020 gnus-article-date-lapsed-new-header
2021 (looking-at "Date:"))
2023 (goto-char (point-min)))
2024 (insert (article-make-date-line date type))
2025 (when (eq type 'lapsed)
2026 (put-text-property (gnus-point-at-bol) (point)
2027 'article-date-lapsed t))
2031 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2032 (put-text-property (match-beginning 1) (1+ (match-end 1))
2033 'original-date date)
2034 (put-text-property (match-beginning 1) (1+ (match-end 1))
2036 (put-text-property (match-beginning 2) (match-end 2)
2039 (defun article-make-date-line (date type)
2040 "Return a DATE line of TYPE."
2041 (let ((time (condition-case ()
2045 ;; Convert to the local timezone. We have to slap a
2046 ;; `condition-case' round the calls to the timezone
2047 ;; functions since they aren't particularly resistant to
2050 (let ((tz (car (current-time-zone time))))
2051 (format "Date: %s %s%02d%02d" (current-time-string time)
2052 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2053 (/ (% (abs tz) 3600) 60))))
2054 ;; Convert to Universal Time.
2057 (current-time-string
2058 (let* ((e (parse-time-string date))
2059 (tm (apply 'encode-time e))
2061 (ls (- (cadr tm) (car (current-time-zone time)))))
2062 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2063 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2066 ;; Get the original date from the article.
2067 ((eq type 'original)
2068 (concat "Date: " (if (string-match "\n+$" date)
2069 (substring date 0 (match-beginning 0))
2071 ;; Let the user define the format.
2073 (if (gnus-functionp gnus-article-time-format)
2074 (funcall gnus-article-time-format time)
2077 (format-time-string gnus-article-time-format time))))
2082 (format-time-string "%Y%m%dT%H%M%S" time)))
2083 ;; Do an X-Sent lapsed format.
2085 ;; If the date is seriously mangled, the timezone functions are
2086 ;; liable to bug out, so we ignore all errors.
2087 (let* ((now (current-time))
2088 (real-time (subtract-time now time))
2089 (real-sec (and real-time
2090 (+ (* (float (car real-time)) 65536)
2092 (sec (and real-time (abs real-sec)))
2102 ;; This is a bit convoluted, but basically we go
2103 ;; through the time units for years, weeks, etc,
2104 ;; and divide things to see whether that results
2105 ;; in positive answers.
2108 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2109 ;; The (remaining) seconds are too few to
2110 ;; be divided into this time unit.
2112 ;; It's big enough, so we output it.
2113 (setq sec (- sec (* num (cdr unit))))
2115 (concat (if prev ", " "") (int-to-string
2117 " " (symbol-name (car unit))
2118 (if (> num 1) "s" ""))
2120 article-time-units "")
2121 ;; If dates are odd, then it might appear like the
2122 ;; article was sent in the future.
2125 " in the future"))))))
2127 (error "Unknown conversion type: %s" type)))))
2129 (defun article-date-local (&optional highlight)
2130 "Convert the current article date to the local timezone."
2131 (interactive (list t))
2132 (article-date-ut 'local highlight))
2134 (defun article-date-original (&optional highlight)
2135 "Convert the current article date to what it was originally.
2136 This is only useful if you have used some other date conversion
2137 function and want to see what the date was before converting."
2138 (interactive (list t))
2139 (article-date-ut 'original highlight))
2141 (defun article-date-lapsed (&optional highlight)
2142 "Convert the current article date to time lapsed since it was sent."
2143 (interactive (list t))
2144 (article-date-ut 'lapsed highlight))
2146 (defun article-update-date-lapsed ()
2147 "Function to be run from a timer to update the lapsed time line."
2148 (let (deactivate-mark)
2153 (set-buffer (window-buffer w))
2154 (when (eq major-mode 'gnus-article-mode)
2155 (goto-char (point-min))
2156 (when (re-search-forward "^X-Sent:" nil t)
2157 (article-date-lapsed t))))
2160 (defun gnus-start-date-timer (&optional n)
2161 "Start a timer to update the X-Sent header in the article buffers.
2162 The numerical prefix says how frequently (in seconds) the function
2167 (gnus-stop-date-timer)
2168 (setq article-lapsed-timer
2169 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2171 (defun gnus-stop-date-timer ()
2172 "Stop the X-Sent timer."
2174 (when article-lapsed-timer
2175 (nnheader-cancel-timer article-lapsed-timer)
2176 (setq article-lapsed-timer nil)))
2178 (defun article-date-user (&optional highlight)
2179 "Convert the current article date to the user-defined format.
2180 This format is defined by the `gnus-article-time-format' variable."
2181 (interactive (list t))
2182 (article-date-ut 'user highlight))
2184 (defun article-date-iso8601 (&optional highlight)
2185 "Convert the current article date to ISO8601."
2186 (interactive (list t))
2187 (article-date-ut 'iso8601 highlight))
2189 (defun article-show-all ()
2190 "Show all hidden text in the article buffer."
2194 (let ((buffer-read-only nil))
2195 (gnus-article-unhide-text (point-min) (point-max))
2196 (gnus-remove-text-with-property 'gnus-prev)
2197 (gnus-remove-text-with-property 'gnus-next))))
2199 (defun article-show-all-headers ()
2200 "Show all hidden headers in the article buffer."
2205 (article-narrow-to-head)
2206 (let ((buffer-read-only nil))
2207 (gnus-article-unhide-text (point-min) (point-max))))))
2209 (defun article-emphasize (&optional arg)
2210 "Emphasize text according to `gnus-emphasis-alist'."
2211 (interactive (gnus-article-hidden-arg))
2212 (unless (gnus-article-check-hidden-text 'emphasis arg)
2214 (let ((alist (or (with-current-buffer gnus-summary-buffer
2215 gnus-article-emphasis-alist)
2216 gnus-emphasis-alist))
2217 (buffer-read-only nil)
2218 (props (append '(article-type emphasis)
2219 gnus-hidden-properties))
2220 regexp elem beg invisible visible face)
2223 (while (setq elem (pop alist))
2225 (setq regexp (car elem)
2226 invisible (nth 1 elem)
2227 visible (nth 2 elem)
2229 (while (re-search-forward regexp nil t)
2230 (when (and (match-beginning visible) (match-beginning invisible))
2231 (gnus-article-hide-text
2232 (match-beginning invisible) (match-end invisible) props)
2233 (gnus-article-unhide-text-type
2234 (match-beginning visible) (match-end visible) 'emphasis)
2235 (gnus-put-text-property-excluding-newlines
2236 (match-beginning visible) (match-end visible) 'face face)
2237 (goto-char (match-end invisible)))))))))
2239 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2240 "Setup newsgroup emphasis alist."
2241 (unless gnus-article-emphasis-alist
2242 (let ((name (and gnus-newsgroup-name
2243 (gnus-group-real-name gnus-newsgroup-name))))
2244 (make-local-variable 'gnus-article-emphasis-alist)
2245 (setq gnus-article-emphasis-alist
2247 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2248 (while (setq elem (pop alist))
2249 (when (and name (string-match (car elem) name))
2251 highlight (copy-list (cdr elem)))))
2253 (copy-list highlight-words)
2254 (if gnus-newsgroup-name
2255 (copy-list (gnus-group-find-parameter
2256 gnus-newsgroup-name 'highlight-words t)))
2257 gnus-emphasis-alist)))))
2259 (defvar gnus-summary-article-menu)
2260 (defvar gnus-summary-post-menu)
2262 ;;; Saving functions.
2264 (defun gnus-article-save (save-buffer file &optional num)
2265 "Save the currently selected article."
2266 (unless gnus-save-all-headers
2267 ;; Remove headers according to `gnus-saved-headers'.
2268 (let ((gnus-visible-headers
2269 (or gnus-saved-headers gnus-visible-headers))
2270 (gnus-article-buffer save-buffer))
2272 (set-buffer save-buffer)
2273 (article-hide-headers 1 t))))
2274 (save-window-excursion
2275 (if (not gnus-default-article-saver)
2276 (error "No default saver is defined")
2277 ;; !!! Magic! The saving functions all save
2278 ;; `gnus-save-article-buffer' (or so they think), but we
2279 ;; bind that variable to our save-buffer.
2280 (set-buffer gnus-article-buffer)
2281 (let* ((gnus-save-article-buffer save-buffer)
2284 ((not gnus-prompt-before-saving) 'default)
2285 ((eq gnus-prompt-before-saving 'always) nil)
2287 (gnus-number-of-articles-to-be-saved
2288 (when (eq gnus-prompt-before-saving t)
2290 (set-buffer gnus-article-current-summary)
2291 (funcall gnus-default-article-saver filename)))))
2293 (defun gnus-read-save-file-name (prompt &optional filename
2294 function group headers variable)
2296 (funcall function group headers (symbol-value variable)))
2301 ((eq filename 'default)
2307 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2310 (if (and gnus-number-of-articles-to-be-saved
2311 (> gnus-number-of-articles-to-be-saved 1))
2312 (format "these %d articles"
2313 gnus-number-of-articles-to-be-saved)
2316 ;; Let the split methods have their say.
2318 ;; No split name was found.
2321 (concat prompt " (default "
2322 (file-name-nondirectory default-name) ") ")
2323 (file-name-directory default-name)
2325 ;; A single group name is returned.
2326 ((stringp split-name)
2328 (funcall function split-name headers
2329 (symbol-value variable)))
2331 (concat prompt " (default "
2332 (file-name-nondirectory default-name) ") ")
2333 (file-name-directory default-name)
2335 ;; A single split name was found
2336 ((= 1 (length split-name))
2337 (let* ((name (expand-file-name
2338 (car split-name) gnus-article-save-directory))
2339 (dir (cond ((file-directory-p name)
2340 (file-name-as-directory name))
2341 ((file-exists-p name) name)
2342 (t gnus-article-save-directory))))
2344 (concat prompt " (default " name ") ")
2346 ;; A list of splits was found.
2348 (setq split-name (nreverse split-name))
2350 (let ((file-name-history
2351 (nconc split-name file-name-history)))
2355 (concat prompt " (`M-p' for defaults) ")
2356 gnus-article-save-directory
2358 gnus-article-save-directory)))
2359 (car (push result file-name-history)))))))
2360 ;; Create the directory.
2361 (gnus-make-directory (file-name-directory file))
2362 ;; If we have read a directory, we append the default file name.
2363 (when (file-directory-p file)
2364 (setq file (concat (file-name-as-directory file)
2365 (file-name-nondirectory default-name))))
2366 ;; Possibly translate some characters.
2367 (nnheader-translate-file-chars file)))))
2368 (gnus-make-directory (file-name-directory result))
2369 (set variable result)))
2371 (defun gnus-article-archive-name (group)
2372 "Return the first instance of an \"Archive-name\" in the current buffer."
2373 (let ((case-fold-search t))
2374 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2375 (nnheader-concat gnus-article-save-directory
2376 (match-string 1)))))
2378 (defun gnus-article-nndoc-name (group)
2379 "If GROUP is an nndoc group, return the name of the parent group."
2380 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2381 (gnus-group-get-parameter group 'save-article-group)))
2383 (defun gnus-summary-save-in-rmail (&optional filename)
2384 "Append this article to Rmail file.
2385 Optional argument FILENAME specifies file name.
2386 Directory to save to is default to `gnus-article-save-directory'."
2387 (setq filename (gnus-read-save-file-name
2388 "Save %s in rmail file:" filename
2389 gnus-rmail-save-name gnus-newsgroup-name
2390 gnus-current-headers 'gnus-newsgroup-last-rmail))
2391 (gnus-eval-in-buffer-window gnus-save-article-buffer
2395 (gnus-output-to-rmail filename))))
2398 (defun gnus-summary-save-in-mail (&optional filename)
2399 "Append this article to Unix mail file.
2400 Optional argument FILENAME specifies file name.
2401 Directory to save to is default to `gnus-article-save-directory'."
2402 (setq filename (gnus-read-save-file-name
2403 "Save %s in Unix mail file:" filename
2404 gnus-mail-save-name gnus-newsgroup-name
2405 gnus-current-headers 'gnus-newsgroup-last-mail))
2406 (gnus-eval-in-buffer-window gnus-save-article-buffer
2410 (if (and (file-readable-p filename)
2411 (mail-file-babyl-p filename))
2412 (rmail-output-to-rmail-file filename t)
2413 (gnus-output-to-mail filename)))))
2416 (defun gnus-summary-save-in-file (&optional filename overwrite)
2417 "Append this article to file.
2418 Optional argument FILENAME specifies file name.
2419 Directory to save to is default to `gnus-article-save-directory'."
2420 (setq filename (gnus-read-save-file-name
2421 "Save %s in file:" filename
2422 gnus-file-save-name gnus-newsgroup-name
2423 gnus-current-headers 'gnus-newsgroup-last-file))
2424 (gnus-eval-in-buffer-window gnus-save-article-buffer
2428 (when (and overwrite
2429 (file-exists-p filename))
2430 (delete-file filename))
2431 (gnus-output-to-file filename))))
2434 (defun gnus-summary-write-to-file (&optional filename)
2435 "Write this article to a file.
2436 Optional argument FILENAME specifies file name.
2437 The directory to save in defaults to `gnus-article-save-directory'."
2438 (gnus-summary-save-in-file nil t))
2440 (defun gnus-summary-save-body-in-file (&optional filename)
2441 "Append this article body to a file.
2442 Optional argument FILENAME specifies file name.
2443 The directory to save in defaults to `gnus-article-save-directory'."
2444 (setq filename (gnus-read-save-file-name
2445 "Save %s body in file:" filename
2446 gnus-file-save-name gnus-newsgroup-name
2447 gnus-current-headers 'gnus-newsgroup-last-file))
2448 (gnus-eval-in-buffer-window gnus-save-article-buffer
2452 (when (article-goto-body)
2453 (narrow-to-region (point) (point-max)))
2454 (gnus-output-to-file filename))))
2457 (defun gnus-summary-save-in-pipe (&optional command)
2458 "Pipe this article to subprocess."
2460 (cond ((and (eq command 'default)
2461 gnus-last-shell-command)
2462 gnus-last-shell-command)
2466 "Shell command on %s: "
2467 (if (and gnus-number-of-articles-to-be-saved
2468 (> gnus-number-of-articles-to-be-saved 1))
2469 (format "these %d articles"
2470 gnus-number-of-articles-to-be-saved)
2472 gnus-last-shell-command))))
2473 (when (string-equal command "")
2474 (setq command gnus-last-shell-command))
2475 (gnus-eval-in-buffer-window gnus-article-buffer
2478 (shell-command-on-region (point-min) (point-max) command nil)))
2479 (setq gnus-last-shell-command command))
2481 ;;; Article file names when saving.
2483 (defun gnus-capitalize-newsgroup (newsgroup)
2484 "Capitalize NEWSGROUP name."
2485 (when (not (zerop (length newsgroup)))
2486 (concat (char-to-string (upcase (aref newsgroup 0)))
2487 (substring newsgroup 1))))
2489 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2490 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2491 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2492 Otherwise, it is like ~/News/news/group/num."
2495 (concat (if (gnus-use-long-file-name 'not-save)
2496 (gnus-capitalize-newsgroup newsgroup)
2497 (gnus-newsgroup-directory-form newsgroup))
2498 "/" (int-to-string (mail-header-number headers)))
2499 gnus-article-save-directory)))
2501 (string-equal (file-name-directory default)
2502 (file-name-directory last-file))
2503 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2505 (or last-file default))))
2507 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2508 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2509 If variable `gnus-use-long-file-name' is non-nil, it is
2510 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2513 (concat (if (gnus-use-long-file-name 'not-save)
2515 (gnus-newsgroup-directory-form newsgroup))
2516 "/" (int-to-string (mail-header-number headers)))
2517 gnus-article-save-directory)))
2519 (string-equal (file-name-directory default)
2520 (file-name-directory last-file))
2521 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2523 (or last-file default))))
2525 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2526 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2527 If variable `gnus-use-long-file-name' is non-nil, it is
2528 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2531 (if (gnus-use-long-file-name 'not-save)
2532 (gnus-capitalize-newsgroup newsgroup)
2533 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2534 gnus-article-save-directory)))
2536 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2537 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2538 If variable `gnus-use-long-file-name' is non-nil, it is
2539 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2542 (if (gnus-use-long-file-name 'not-save)
2544 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2545 gnus-article-save-directory)))
2552 (setq afunc (car func)
2555 gfunc (intern (format "gnus-%s" func))))
2557 (if (not (fboundp afunc))
2559 `(lambda (&optional interactive &rest args)
2560 ,(documentation afunc t)
2561 (interactive (list t))
2563 (set-buffer gnus-article-buffer)
2565 (call-interactively ',afunc)
2566 (apply ',afunc args))))))))
2567 '(article-hide-headers
2568 article-hide-boring-headers
2569 article-toggle-headers
2570 article-treat-overstrike
2571 article-fill-long-lines
2572 article-capitalize-sentences
2574 article-display-x-face
2575 article-de-quoted-unreadable
2576 article-hide-list-identifiers
2578 article-strip-banner
2581 article-hide-signature
2582 article-strip-headers-in-body
2583 article-remove-trailing-blank-lines
2584 article-strip-leading-blank-lines
2585 article-strip-multiple-blank-lines
2586 article-strip-leading-space
2587 article-strip-trailing-space
2588 article-strip-blank-lines
2589 article-strip-all-blank-lines
2591 article-date-iso8601
2592 article-date-original
2594 article-decode-mime-words
2595 article-decode-charset
2596 article-decode-encoded-words
2600 article-treat-dumbquotes
2601 article-normalize-headers
2602 (article-show-all-headers . gnus-article-show-all-headers)
2603 (article-show-all . gnus-article-show-all))))
2606 ;;; Gnus article mode
2609 (put 'gnus-article-mode 'mode-class 'special)
2611 (gnus-define-keys gnus-article-mode-map
2612 " " gnus-article-goto-next-page
2613 "\177" gnus-article-goto-prev-page
2614 [delete] gnus-article-goto-prev-page
2615 [backspace] gnus-article-goto-prev-page
2616 "\C-c^" gnus-article-refer-article
2617 "h" gnus-article-show-summary
2618 "s" gnus-article-show-summary
2619 "\C-c\C-m" gnus-article-mail
2620 "?" gnus-article-describe-briefly
2621 gnus-mouse-2 gnus-article-push-button
2622 "\r" gnus-article-press-button
2623 "\t" gnus-article-next-button
2624 "\M-\t" gnus-article-prev-button
2625 "e" gnus-article-edit
2626 "<" beginning-of-buffer
2628 "\C-c\C-i" gnus-info-find-node
2631 "\C-d" gnus-article-read-summary-keys
2632 "\M-*" gnus-article-read-summary-keys
2633 "\M-#" gnus-article-read-summary-keys
2634 "\M-^" gnus-article-read-summary-keys
2635 "\M-g" gnus-article-read-summary-keys)
2637 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2640 (unless (lookup-key gnus-article-mode-map key)
2641 (define-key gnus-article-mode-map key
2642 'gnus-article-read-summary-keys)))
2647 (let ((key (car elt)))
2648 (and (> (length key) 0)
2649 (not (eq 'menu-bar (aref key 0)))
2650 (symbolp (lookup-key gnus-summary-mode-map key))
2652 (accessible-keymaps gnus-summary-mode-map))
2656 (push (char-to-string c) keys)
2660 (defun gnus-article-make-menu-bar ()
2661 (gnus-turn-off-edit-menu 'article)
2662 (unless (boundp 'gnus-article-article-menu)
2664 gnus-article-article-menu gnus-article-mode-map ""
2666 ["Scroll forwards" gnus-article-goto-next-page t]
2667 ["Scroll backwards" gnus-article-goto-prev-page t]
2668 ["Show summary" gnus-article-show-summary t]
2669 ["Fetch Message-ID at point" gnus-article-refer-article t]
2670 ["Mail to address at point" gnus-article-mail t]
2671 ["Send a bug report" gnus-bug t]))
2674 gnus-article-treatment-menu gnus-article-mode-map ""
2676 ["Hide headers" gnus-article-toggle-headers t]
2677 ["Hide signature" gnus-article-hide-signature t]
2678 ["Hide citation" gnus-article-hide-citation t]
2679 ["Treat overstrike" gnus-article-treat-overstrike t]
2680 ["Remove carriage return" gnus-article-remove-cr t]))
2682 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2684 (when (boundp 'gnus-summary-post-menu)
2685 (define-key gnus-article-mode-map [menu-bar post]
2686 (cons "Post" gnus-summary-post-menu)))
2688 (gnus-run-hooks 'gnus-article-menu-hook)))
2690 (defun gnus-article-mode ()
2691 "Major mode for displaying an article.
2693 All normal editing commands are switched off.
2695 The following commands are available in addition to all summary mode
2697 \\<gnus-article-mode-map>
2698 \\[gnus-article-next-page]\t Scroll the article one page forwards
2699 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2700 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2701 \\[gnus-article-show-summary]\t Display the summary buffer
2702 \\[gnus-article-mail]\t Send a reply to the address near point
2703 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2704 \\[gnus-info-find-node]\t Go to the Gnus info node"
2706 (when (gnus-visual-p 'article-menu 'menu)
2707 (gnus-article-make-menu-bar))
2708 (gnus-simplify-mode-line)
2709 (setq mode-name "Article")
2710 (setq major-mode 'gnus-article-mode)
2711 (make-local-variable 'minor-mode-alist)
2712 (unless (assq 'gnus-show-mime minor-mode-alist)
2713 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2714 (use-local-map gnus-article-mode-map)
2715 (gnus-update-format-specifications nil 'article-mode)
2716 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2717 (make-local-variable 'gnus-page-broken)
2718 (make-local-variable 'gnus-button-marker-list)
2719 (make-local-variable 'gnus-article-current-summary)
2720 (make-local-variable 'gnus-article-mime-handles)
2721 (make-local-variable 'gnus-article-decoded-p)
2722 (make-local-variable 'gnus-article-mime-handle-alist)
2723 (make-local-variable 'gnus-article-washed-types)
2724 (gnus-set-default-directory)
2725 (buffer-disable-undo)
2726 (setq buffer-read-only t)
2727 (set-syntax-table gnus-article-mode-syntax-table)
2728 (gnus-run-hooks 'gnus-article-mode-hook))
2730 (defun gnus-article-setup-buffer ()
2731 "Initialize the article buffer."
2732 (let* ((name (if gnus-single-article-buffer "*Article*"
2733 (concat "*Article " gnus-newsgroup-name "*")))
2735 (progn (string-match "\\*Article" name)
2736 (concat " *Original Article"
2737 (substring name (match-end 0))))))
2738 (setq gnus-article-buffer name)
2739 (setq gnus-original-article-buffer original)
2740 (setq gnus-article-mime-handle-alist nil)
2741 ;; This might be a variable local to the summary buffer.
2742 (unless gnus-single-article-buffer
2744 (set-buffer gnus-summary-buffer)
2745 (setq gnus-article-buffer name)
2746 (setq gnus-original-article-buffer original)
2747 (gnus-set-global-variables)))
2748 (gnus-article-setup-highlight-words)
2749 ;; Init original article buffer.
2751 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2752 (setq major-mode 'gnus-original-article-mode)
2753 (make-local-variable 'gnus-original-article))
2754 (if (get-buffer name)
2757 (kill-all-local-variables)
2758 (buffer-disable-undo)
2759 (setq buffer-read-only t)
2760 (unless (eq major-mode 'gnus-article-mode)
2761 (gnus-article-mode))
2764 (set-buffer (gnus-get-buffer-create name))
2766 (make-local-variable 'gnus-summary-buffer)
2767 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2768 (current-buffer)))))
2770 ;; Set article window start at LINE, where LINE is the number of lines
2771 ;; from the head of the article.
2772 (defun gnus-article-set-window-start (&optional line)
2774 (get-buffer-window gnus-article-buffer t)
2776 (set-buffer gnus-article-buffer)
2777 (goto-char (point-min))
2780 (gnus-message 6 "Moved to bookmark")
2781 (search-forward "\n\n" nil t)
2785 ;;; @@ article filters
2788 (defun gnus-article-display-mime-message ()
2789 "Article display method for MIME message."
2790 ;; called from `gnus-original-article-buffer'.
2791 (let (charset all-headers)
2792 (with-current-buffer gnus-summary-buffer
2793 (setq charset default-mime-charset
2794 all-headers gnus-have-all-headers))
2795 (make-local-variable 'default-mime-charset)
2796 (setq default-mime-charset charset)
2797 (with-current-buffer (get-buffer-create gnus-article-buffer)
2798 (make-local-variable 'default-mime-charset)
2799 (setq default-mime-charset charset))
2800 (mime-display-message mime-message-structure
2801 gnus-article-buffer nil gnus-article-mode-map)
2803 (gnus-article-hide-headers nil -1))
2805 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2806 (make-local-variable 'mime-button-mother-dispatcher)
2807 (setq mime-button-mother-dispatcher
2808 (function gnus-article-push-button))
2809 (run-hooks 'gnus-mime-article-prepare-hook))
2811 (defun gnus-article-display-traditional-message ()
2812 "Article display method for traditional message."
2813 (set-buffer gnus-article-buffer)
2814 (let (buffer-read-only)
2816 (insert-buffer-substring gnus-original-article-buffer)))
2818 (defun gnus-article-make-full-mail-header (&optional number charset)
2819 "Create a new mail header structure in a raw article buffer."
2820 (unless (and number charset)
2821 (save-current-buffer
2822 (set-buffer gnus-summary-buffer)
2824 (setq number (or (cdr gnus-article-current) 0)))
2826 (setq charset (or default-mime-charset 'x-ctext)))))
2827 (goto-char (point-min))
2828 (let ((header-end (if (search-forward "\n\n" nil t)
2830 (goto-char (point-max))))
2831 (chars (- (point-max) (point)))
2832 (lines (count-lines (point) (point-max)))
2833 (default-mime-charset charset)
2835 (narrow-to-region (point-min) header-end)
2836 (setq xref (std11-fetch-field "xref"))
2838 (make-full-mail-header
2840 (std11-fetch-field "subject")
2841 (std11-fetch-field "from")
2842 (std11-fetch-field "date")
2843 (std11-fetch-field "message-id")
2844 (std11-fetch-field "references")
2847 (when xref (concat "Xref: " xref)))
2850 (defun gnus-article-prepare (article &optional all-headers header)
2851 "Prepare ARTICLE in article mode buffer.
2852 ARTICLE should either be an article number or a Message-ID.
2853 If ARTICLE is an id, HEADER should be the article headers.
2854 If ALL-HEADERS is non-nil, no headers are hidden."
2856 ;; Make sure we start in a summary buffer.
2857 (unless (eq major-mode 'gnus-summary-mode)
2858 (set-buffer gnus-summary-buffer))
2859 (setq gnus-summary-buffer (current-buffer))
2860 (let* ((gnus-article (if header (mail-header-number header) article))
2861 (summary-buffer (current-buffer))
2862 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2863 (group gnus-newsgroup-name)
2866 (gnus-article-setup-buffer)
2867 (set-buffer gnus-original-article-buffer)
2868 ;; Deactivate active regions.
2869 (when (and (boundp 'transient-mark-mode)
2870 transient-mark-mode)
2871 (setq mark-active nil))
2872 (if (not (setq result (let ((buffer-read-only nil))
2873 (gnus-request-article-this-buffer
2875 ;; There is no such article.
2877 (when (and (numberp article)
2878 (not (memq article gnus-newsgroup-sparse)))
2879 (setq gnus-article-current
2880 (cons gnus-newsgroup-name article))
2881 (set-buffer gnus-summary-buffer)
2882 (setq gnus-current-article article)
2883 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2885 (gnus-summary-set-agent-mark article)
2886 (message "Message marked for downloading"))
2887 (gnus-summary-mark-article article gnus-canceled-mark)
2888 (unless (memq article gnus-newsgroup-sparse)
2890 "No such article (may have expired or been canceled)")))))
2891 (if (or (eq result 'pseudo)
2892 (eq result 'nneething))
2895 (set-buffer summary-buffer)
2896 (push article gnus-newsgroup-history)
2897 (setq gnus-last-article gnus-current-article
2898 gnus-current-article 0
2899 gnus-current-headers nil
2900 gnus-article-current nil)
2901 (if (eq result 'nneething)
2902 (gnus-configure-windows 'summary)
2903 (gnus-configure-windows 'article))
2904 (gnus-set-global-variables))
2905 (let ((gnus-article-mime-handle-alist-1
2906 gnus-article-mime-handle-alist))
2907 (gnus-set-mode-line 'article)))
2908 ;; The result from the `request' was an actual article -
2909 ;; or at least some text that is now displayed in the
2911 (when (and (numberp article)
2912 (not (eq article gnus-current-article)))
2913 ;; Seems like a new article has been selected.
2914 ;; `gnus-current-article' must be an article number.
2916 (set-buffer summary-buffer)
2917 (push article gnus-newsgroup-history)
2918 (setq gnus-last-article gnus-current-article
2919 gnus-current-article article
2920 gnus-current-headers
2921 (gnus-summary-article-header gnus-current-article)
2922 gnus-article-current
2923 (cons gnus-newsgroup-name gnus-current-article))
2924 (unless (vectorp gnus-current-headers)
2925 (setq gnus-current-headers nil))
2926 (gnus-summary-goto-subject gnus-current-article)
2927 (when (gnus-summary-show-thread)
2928 ;; If the summary buffer really was folded, the
2929 ;; previous goto may not actually have gone to
2930 ;; the right article, but the thread root instead.
2932 (gnus-summary-goto-subject gnus-current-article))
2933 (gnus-run-hooks 'gnus-mark-article-hook)
2934 (gnus-set-mode-line 'summary)
2935 (when (gnus-visual-p 'article-highlight 'highlight)
2936 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2937 ;; Set the global newsgroup variables here.
2938 (gnus-set-global-variables)
2939 (setq gnus-have-all-headers
2940 (or all-headers gnus-show-all-headers))))
2941 (when (or (numberp article)
2943 (gnus-article-prepare-display)
2945 (goto-char (point-min))
2946 (setq gnus-page-broken
2947 (when gnus-break-pages
2948 (gnus-narrow-to-page)
2950 (let ((gnus-article-mime-handle-alist-1
2951 gnus-article-mime-handle-alist))
2952 (gnus-set-mode-line 'article))
2954 (set-window-point (get-buffer-window (current-buffer)) (point))
2955 (gnus-configure-windows 'article)
2958 (defun gnus-article-prepare-mime-display (&optional number)
2959 (goto-char (point-min))
2960 (when (re-search-forward "^[^\t ]+:" nil t)
2961 (goto-char (match-beginning 0)))
2962 (let ((entity (if (eq 1 (point-min))
2963 (get-text-property 1 'mime-view-entity)
2964 (get-text-property (point) 'mime-view-entity)))
2965 last-entity child-entity next type)
2966 (setq child-entity (mime-entity-children entity))
2968 (setq last-entity (nth (1- (length child-entity))
2970 (setq last-entity entity))
2972 (narrow-to-region (point)
2973 (if (search-forward "\n\n" nil t)
2976 (gnus-treat-article 'head)
2977 (put-text-property (point-min) (point-max) 'article-treated-header t)
2978 (goto-char (point-max)))
2979 (while (and (not (eobp))
2984 (or (next-single-property-change (point)
2987 (let ((types (mime-entity-content-type entity)))
2988 (while (eq 'multipart (mime-content-type-primary-type types))
2989 (setq entity (car (mime-entity-children entity))
2990 types (mime-entity-content-type entity)))
2992 (setq type (format "%s/%s"
2993 (mime-content-type-primary-type types)
2994 (mime-content-type-subtype types)))))
2995 (if (string-equal type "message/rfc822")
2998 (let ((children (mime-entity-children entity))
3001 (setq last-children (nth (1- (length children)) children))
3004 (not (eq last-children
3005 (get-text-property next 'mime-view-entity)))
3007 (next-single-property-change next
3008 'mime-view-entity))))))
3009 (setq next (or (next-single-property-change next 'mime-view-entity)
3012 (narrow-to-region (point) next)
3013 (gnus-article-prepare-mime-display)
3014 (goto-char (point-max)))
3015 (setq entity (get-text-property (point) 'mime-view-entity)))
3017 (narrow-to-region (point) next)
3018 ;; Kludge. We have to count true number, but for now,
3019 ;; part number is here only to achieve `last'.
3020 (gnus-treat-article nil 1
3021 (if (eq entity last-entity)
3024 (setq entity (get-text-property next 'mime-view-entity))
3025 (goto-char (point-max)))))))
3028 (defun gnus-article-prepare-display ()
3029 "Make the current buffer look like a nice article."
3030 (setq gnus-article-wash-types nil)
3031 (gnus-run-hooks 'gnus-tmp-internal-hook)
3032 (gnus-run-hooks 'gnus-article-prepare-hook)
3034 (let (mime-display-header-hook mime-display-text/plain-hook)
3035 (funcall (if gnus-show-mime
3037 (setq mime-message-structure gnus-current-headers)
3038 (mime-buffer-entity-set-buffer-internal
3039 mime-message-structure
3040 gnus-original-article-buffer)
3041 (mime-entity-set-representation-type-internal
3042 mime-message-structure 'mime-buffer-entity)
3043 (luna-send mime-message-structure
3044 'initialize-instance
3045 mime-message-structure)
3046 gnus-article-display-method-for-mime)
3047 gnus-article-display-method-for-traditional)))
3048 ;; Associate this article with the current summary buffer.
3049 (setq gnus-article-current-summary gnus-summary-buffer)
3050 ;; Call the treatment functions.
3051 (let ((inhibit-read-only t)
3056 (gnus-article-prepare-mime-display)
3057 (narrow-to-region (goto-char (point-min))
3058 (if (search-forward "\n\n" nil t)
3061 (gnus-treat-article 'head)
3062 (put-text-property (point-min) (point-max) 'article-treated-header t)
3063 (goto-char (point-max))
3065 (narrow-to-region (point) (point-max))
3066 (gnus-treat-article nil))
3067 (put-text-property (point-min) (point-max) 'read-only nil)))
3068 ;; Perform the article display hooks. Incidentally, this hook is
3069 ;; an obsolete variable by now.
3070 (gnus-run-hooks 'gnus-article-display-hook))
3072 (defun gnus-article-decode-article-as-default-mime-charset ()
3073 "Decode an article as `default-mime-charset'. It won't work if the
3074 value of the variable `gnus-show-mime' is non-nil."
3075 (unless gnus-show-mime
3076 (decode-mime-charset-region (point-min) (point-max)
3077 (with-current-buffer gnus-summary-buffer
3078 default-mime-charset))))
3081 ;;; Gnus MIME viewing functions
3084 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3085 "The following specs can be used:
3087 %T MIME type, along with additional info
3088 %n The `name' parameter
3089 %d The description, if any
3090 %l The length of the encoded part
3091 %p The part identifier number
3092 %e Dots if the part isn't displayed")
3094 (defvar gnus-mime-button-line-format-alist
3095 '((?t gnus-tmp-type ?s)
3096 (?T gnus-tmp-type-long ?s)
3097 (?n gnus-tmp-name ?s)
3098 (?d gnus-tmp-description ?s)
3100 (?l gnus-tmp-length ?d)
3101 (?e gnus-tmp-dots ?s)))
3103 (defvar gnus-mime-button-commands
3104 '((gnus-article-press-button "\r" "Toggle Display")
3105 (gnus-mime-view-part "v" "View Interactively...")
3106 (gnus-mime-view-part-as-type "t" "View As Type...")
3107 (gnus-mime-save-part "o" "Save...")
3108 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3109 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3110 (gnus-mime-internalize-part "E" "View Internally")
3111 (gnus-mime-externalize-part "e" "View Externally")
3112 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3114 (defun gnus-article-mime-part-status ()
3115 (with-current-buffer gnus-article-buffer
3116 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3117 (if (and entity (mime-entity-children entity))
3118 (format " (%d parts)" (length (mime-entity-children entity)))
3121 (defvar gnus-mime-button-map nil)
3122 (unless gnus-mime-button-map
3123 (setq gnus-mime-button-map (make-sparse-keymap))
3124 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3125 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3126 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3128 (define-key gnus-mime-button-map (cadr c) (car c)))
3129 gnus-mime-button-commands))
3131 (defun gnus-mime-button-menu (event)
3132 "Construct a context-sensitive menu of MIME commands."
3135 (let ((pos (event-start event)))
3136 (set-buffer (window-buffer (posn-window pos)))
3137 (goto-char (posn-point pos))
3138 (gnus-article-check-buffer)
3139 (let ((response (x-popup-menu
3141 ("" ,@(mapcar (lambda (c)
3142 (cons (caddr c) (car c)))
3143 gnus-mime-button-commands))))))
3145 (funcall response))))))
3147 (defun gnus-mime-view-all-parts (&optional handles)
3148 "View all the MIME parts."
3150 (save-current-buffer
3151 (set-buffer gnus-article-buffer)
3152 (let ((handles (or handles gnus-article-mime-handles))
3153 (mail-parse-charset gnus-newsgroup-charset)
3154 (mail-parse-ignored-charsets
3155 (save-excursion (set-buffer gnus-summary-buffer)
3156 gnus-newsgroup-ignored-charsets)))
3157 (if (stringp (car handles))
3158 (gnus-mime-view-all-parts (cdr handles))
3159 (mapcar 'mm-display-part handles)))))
3161 (defun gnus-mime-save-part ()
3162 "Save the MIME part under point."
3164 (gnus-article-check-buffer)
3165 (let ((data (get-text-property (point) 'gnus-data)))
3166 (mm-save-part data)))
3168 (defun gnus-mime-pipe-part ()
3169 "Pipe the MIME part under point to a process."
3171 (gnus-article-check-buffer)
3172 (let ((data (get-text-property (point) 'gnus-data)))
3173 (mm-pipe-part data)))
3175 (defun gnus-mime-view-part ()
3176 "Interactively choose a viewing method for the MIME part under point."
3178 (gnus-article-check-buffer)
3179 (let ((data (get-text-property (point) 'gnus-data)))
3180 (mm-interactively-view-part data)))
3182 (defun gnus-mime-view-part-as-type ()
3183 "Choose a MIME media type, and view the part as such."
3185 (list (completing-read "View as MIME type: " mailcap-mime-types)))
3186 (gnus-article-check-buffer)
3187 (let ((handle (get-text-property (point) 'gnus-data)))
3188 (gnus-mm-display-part handle)))
3190 (defun gnus-mime-copy-part (&optional handle)
3191 "Put the the MIME part under point into a new buffer."
3193 (gnus-article-check-buffer)
3194 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3195 (contents (mm-get-part handle))|
3196 (base (file-name-nondirectory
3198 (mail-content-type-get (mm-handle-type handle) 'name)
3199 (mail-content-type-get (mm-handle-type handle)
3202 (buffer (generate-new-buffer base)))
3203 (switch-to-buffer buffer)
3205 ;; We do it this way to make `normal-mode' set the appropriate mode.
3208 (setq buffer-file-name (expand-file-name base))
3210 (setq buffer-file-name nil))
3211 (goto-char (point-min))))
3213 (defun gnus-mime-inline-part (&optional handle)
3214 "Insert the MIME part under point into the current buffer."
3216 (gnus-article-check-buffer)
3217 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3221 (if (mm-handle-undisplayer handle)
3222 (mm-remove-part handle)
3223 (setq contents (mm-get-part handle))
3225 (mm-insert-inline handle contents)
3228 (defun gnus-mime-externalize-part (&optional handle)
3229 "View the MIME part under point with an external viewer."
3231 (gnus-article-check-buffer)
3232 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3233 (mm-user-display-methods nil)
3234 (mm-inline-large-images nil)
3235 (mail-parse-charset gnus-newsgroup-charset)
3236 (mail-parse-ignored-charsets
3237 (save-excursion (set-buffer gnus-summary-buffer)
3238 gnus-newsgroup-ignored-charsets)))
3239 (if (mm-handle-undisplayer handle)
3240 (mm-remove-part handle)
3241 (mm-display-part handle))))
3243 (defun gnus-mime-internalize-part (&optional handle)
3244 "View the MIME part under point with an internal viewer."
3246 (gnus-article-check-buffer)
3247 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3248 (mm-user-display-methods '((".*" . inline)))
3249 (mm-inline-large-images t)
3250 (mail-parse-charset gnus-newsgroup-charset)
3251 (mail-parse-ignored-charsets
3252 (save-excursion (set-buffer gnus-summary-buffer)
3253 gnus-newsgroup-ignored-charsets)))
3254 (if (mm-handle-undisplayer handle)
3255 (mm-remove-part handle)
3256 (mm-display-part handle))))
3258 (defun gnus-article-part-wrapper (n function)
3259 (save-current-buffer
3260 (set-buffer gnus-article-buffer)
3261 (when (> n (length gnus-article-mime-handle-alist))
3262 (error "No such part"))
3263 (gnus-article-goto-part n)
3264 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3265 (funcall function handle))))
3267 (defun gnus-article-pipe-part (n)
3268 "Pipe MIME part N, which is the numerical prefix."
3270 (gnus-article-part-wrapper n 'mm-pipe-part))
3272 (defun gnus-article-save-part (n)
3273 "Save MIME part N, which is the numerical prefix."
3275 (gnus-article-part-wrapper n 'mm-save-part))
3277 (defun gnus-article-interactively-view-part (n)
3278 "View MIME part N interactively, which is the numerical prefix."
3280 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3282 (defun gnus-article-copy-part (n)
3283 "Copy MIME part N, which is the numerical prefix."
3285 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3287 (defun gnus-article-externalize-part (n)
3288 "View MIME part N externally, which is the numerical prefix."
3290 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3292 (defun gnus-article-inline-part (n)
3293 "Inline MIME part N, which is the numerical prefix."
3295 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3297 (defun gnus-article-view-part (n)
3298 "View MIME part N, which is the numerical prefix."
3300 (save-current-buffer
3301 (set-buffer gnus-article-buffer)
3302 (when (> n (length gnus-article-mime-handle-alist))
3303 (error "No such part"))
3304 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3305 (when (gnus-article-goto-part n)
3306 (if (equal (car handle) "multipart/alternative")
3307 (gnus-article-press-button)
3308 (when (eq (gnus-mm-display-part handle) 'internal)
3309 (gnus-set-window-start)))))))
3311 (defun gnus-mm-display-part (handle)
3312 "Display HANDLE and fix MIME button."
3313 (let ((id (get-text-property (point) 'gnus-part))
3318 (let ((window (selected-window))
3319 (mail-parse-charset gnus-newsgroup-charset)
3320 (mail-parse-ignored-charsets
3321 (save-excursion (set-buffer gnus-summary-buffer)
3322 gnus-newsgroup-ignored-charsets)))
3325 (let ((win (get-buffer-window (current-buffer) t))
3328 (select-window win))
3331 (if (mm-handle-displayed-p handle)
3332 ;; This will remove the part.
3333 (mm-display-part handle)
3335 (narrow-to-region (point) (1+ (point)))
3336 (mm-display-part handle)
3337 ;; We narrow to the part itself and
3338 ;; then call the treatment functions.
3339 (goto-char (point-min))
3341 (narrow-to-region (point) (point-max))
3344 (1- (length gnus-article-mime-handles))
3345 (mm-handle-media-type handle)))))
3346 (select-window window))))
3348 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3349 (gnus-insert-mime-button
3350 handle id (list (mm-handle-displayed-p handle)))
3351 (goto-char point))))
3353 (defun gnus-article-goto-part (n)
3354 "Go to MIME part N."
3355 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3357 (goto-char point))))
3359 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3360 (let ((gnus-tmp-name
3361 (or (mail-content-type-get (mm-handle-type handle)
3363 (mail-content-type-get (mm-handle-disposition handle)
3366 (gnus-tmp-type (mm-handle-media-type handle))
3367 (gnus-tmp-description
3368 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3371 (if (if displayed (car displayed)
3372 (mm-handle-displayed-p handle))
3374 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3376 gnus-tmp-type-long b e)
3377 (when (string-match ".*/" gnus-tmp-name)
3378 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3379 (setq gnus-tmp-type-long (concat gnus-tmp-type
3380 (and (not (equal gnus-tmp-name ""))
3381 (concat "; " gnus-tmp-name))))
3382 (or (equal gnus-tmp-description "")
3383 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3388 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3389 `(local-map ,gnus-mime-button-map
3390 keymap ,gnus-mime-button-map
3391 gnus-callback gnus-mm-display-part
3392 gnus-part ,gnus-tmp-id
3393 article-type annotation
3396 (widget-convert-button 'link b e
3398 :action 'gnus-widget-press-button
3399 :button-keymap gnus-mime-button-map
3402 ;; Needed to properly clear the message
3403 ;; due to a bug in wid-edit
3404 (setq help-echo-owns-message t)
3406 "Click to %s the MIME part; %s for more options"
3407 (if (mm-handle-displayed-p
3408 (widget-get widget :mime-handle))
3410 (if gnus-xemacs "button3" "mouse-3"))))))
3412 (defun gnus-widget-press-button (elems el)
3413 (goto-char (widget-get elems :from))
3414 (gnus-article-press-button))
3416 (defvar gnus-displaying-mime nil)
3418 (defun gnus-display-mime (&optional ihandles)
3419 "Display the MIME parts."
3421 (save-selected-window
3422 (let ((window (get-buffer-window gnus-article-buffer))
3425 (select-window window)
3426 ;; We have to do this since selecting the window
3427 ;; may change the point. So we set the window point.
3428 (set-window-point window point)))
3429 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3430 buffer-read-only handle name type b e display)
3431 (when (and (not ihandles)
3432 (not gnus-displaying-mime))
3433 ;; Top-level call; we clean up.
3434 (when gnus-article-mime-handles
3435 (mm-destroy-parts gnus-article-mime-handles)
3436 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3437 (setq gnus-article-mime-handles handles)
3438 ;; We allow users to glean info from the handles.
3439 (when gnus-article-mime-part-function
3440 (gnus-mime-part-function handles)))
3442 (or (not (stringp (car handles)))
3445 (when (and (not ihandles)
3446 (not gnus-displaying-mime))
3447 ;; Clean up for mime parts.
3449 (delete-region (point) (point-max)))
3450 (let ((gnus-displaying-mime t))
3451 (gnus-mime-display-part handles)))
3454 (narrow-to-region (point) (point-max))
3455 (gnus-treat-article nil 1 1)
3458 ;; Highlight the headers.
3462 (narrow-to-region (point-min) (point))
3463 (gnus-treat-article 'head))))))))
3465 (defvar gnus-mime-display-multipart-as-mixed nil)
3467 (defun gnus-mime-display-part (handle)
3470 ((not (stringp (car handle)))
3471 (gnus-mime-display-single handle))
3472 ;; User-defined multipart
3473 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3474 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3476 ;; multipart/alternative
3477 ((and (equal (car handle) "multipart/alternative")
3478 (not gnus-mime-display-multipart-as-mixed))
3479 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3480 (push (cons id handle) gnus-article-mime-handle-alist)
3481 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3482 ;; multipart/related
3483 ((and (equal (car handle) "multipart/related")
3484 (not gnus-mime-display-multipart-as-mixed))
3485 ;;;!!!We should find the start part, but we just default
3486 ;;;!!!to the first part.
3487 (gnus-mime-display-part (cadr handle)))
3488 ;; Other multiparts are handled like multipart/mixed.
3490 (gnus-mime-display-mixed (cdr handle)))))
3492 (defun gnus-mime-part-function (handles)
3493 (if (stringp (car handles))
3494 (mapcar 'gnus-mime-part-function (cdr handles))
3495 (funcall gnus-article-mime-part-function handles)))
3497 (defun gnus-mime-display-mixed (handles)
3498 (mapcar 'gnus-mime-display-part handles))
3500 (defun gnus-mime-display-single (handle)
3501 (let ((type (mm-handle-media-type handle))
3502 (ignored gnus-ignored-mime-types)
3509 (when (string-match (pop ignored) type)
3510 (throw 'ignored nil)))
3511 (if (and (setq not-attachment
3512 (or (not (mm-handle-disposition handle))
3513 (equal (car (mm-handle-disposition handle))
3515 (mm-attachment-override-p handle)))
3516 (mm-automatic-display-p handle)
3517 (or (mm-inlined-p handle)
3518 (mm-automatic-external-display-p type)))
3520 (when (equal (mm-handle-media-supertype handle) "text")
3522 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3523 (push (cons id handle) gnus-article-mime-handle-alist)
3524 (when (or (not display)
3525 (not (gnus-unbuttonized-mime-type-p type)))
3526 (gnus-article-insert-newline)
3527 (gnus-insert-mime-button
3528 handle id (list (or display (and not-attachment text))))
3529 (gnus-article-insert-newline)
3530 (gnus-article-insert-newline)
3532 (let ((beg (point)))
3538 (let ((mail-parse-charset gnus-newsgroup-charset)
3539 (mail-parse-ignored-charsets
3540 (save-excursion (set-buffer gnus-summary-buffer)
3541 gnus-newsgroup-ignored-charsets)))
3542 (mm-display-part handle t))
3543 (goto-char (point-max)))
3544 ((and text not-attachment)
3548 (gnus-article-insert-newline)
3549 (mm-insert-inline handle (mm-get-part handle))
3550 (goto-char (point-max))))
3554 (narrow-to-region beg (point))
3556 nil (length gnus-article-mime-handle-alist)
3557 (1- (length gnus-article-mime-handles))
3558 (mm-handle-media-type handle)))))))))
3560 (defun gnus-unbuttonized-mime-type-p (type)
3561 "Say whether TYPE is to be unbuttonized."
3562 (unless gnus-inhibit-mime-unbuttonizing
3564 (let ((types gnus-unbuttonized-mime-types))
3566 (when (string-match (pop types) type)
3567 (throw 'found t)))))))
3569 (defun gnus-article-insert-newline ()
3570 "Insert a newline, but mark it as undeletable."
3571 (gnus-put-text-property
3572 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3574 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3575 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3578 handle buffer-read-only from props begend not-pref)
3579 (save-window-excursion
3582 (narrow-to-region (car ibegend)
3585 (goto-char (car ibegend))
3588 (delete-region (point-min) (point-max))
3589 (mm-remove-parts handles))
3590 (setq begend (list (point-marker)))
3592 (unless (setq not-pref (cadr (member preferred ihandles)))
3593 (setq not-pref (car ihandles)))
3595 (not (gnus-unbuttonized-mime-type-p
3596 "multipart/alternative")))
3597 (gnus-add-text-properties
3600 (insert (format "%d. " id))
3604 (unless ,(not ibegend)
3605 (setq gnus-article-mime-handle-alist
3606 ',gnus-article-mime-handle-alist))
3607 (gnus-mime-display-alternative
3608 ',ihandles ',not-pref ',begend ,id))
3609 local-map ,gnus-mime-button-map
3610 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3611 face ,gnus-article-button-face
3612 keymap ,gnus-mime-button-map
3615 (widget-convert-button 'link from (point)
3616 :action 'gnus-widget-press-button
3617 :button-keymap gnus-widget-button-keymap)
3619 (while (setq handle (pop handles))
3620 (gnus-add-text-properties
3623 (insert (format "(%c) %-18s"
3624 (if (equal handle preferred) ?* ? )
3625 (mm-handle-media-type handle)))
3629 (unless ,(not ibegend)
3630 (setq gnus-article-mime-handle-alist
3631 ',gnus-article-mime-handle-alist))
3632 (gnus-mime-display-alternative
3633 ',ihandles ',handle ',begend ,id))
3634 local-map ,gnus-mime-button-map
3635 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3636 face ,gnus-article-button-face
3637 keymap ,gnus-mime-button-map
3640 (widget-convert-button 'link from (point)
3641 :action 'gnus-widget-press-button
3642 :button-keymap gnus-widget-button-keymap)
3646 (if (stringp (car preferred))
3647 (gnus-display-mime preferred)
3648 (let ((mail-parse-charset gnus-newsgroup-charset)
3649 (mail-parse-ignored-charsets
3650 (save-excursion (set-buffer gnus-summary-buffer)
3651 gnus-newsgroup-ignored-charsets)))
3652 (mm-display-part preferred)
3656 (narrow-to-region (car begend) (point-max))
3658 nil (length gnus-article-mime-handle-alist)
3659 (1- (length gnus-article-mime-handles))
3660 (mm-handle-media-type handle))))))
3661 (goto-char (point-max))
3662 (setcdr begend (point-marker)))))
3664 (goto-char point))))
3666 (defun gnus-article-wash-status ()
3667 "Return a string which display status of article washing."
3669 (set-buffer gnus-article-buffer)
3670 (let ((cite (gnus-article-hidden-text-p 'cite))
3671 (headers (gnus-article-hidden-text-p 'headers))
3672 (boring (gnus-article-hidden-text-p 'boring-headers))
3673 (pgp (gnus-article-hidden-text-p 'pgp))
3674 (pem (gnus-article-hidden-text-p 'pem))
3675 (signature (gnus-article-hidden-text-p 'signature))
3676 (overstrike (gnus-article-hidden-text-p 'overstrike))
3677 (emphasis (gnus-article-hidden-text-p 'emphasis))
3678 (mime gnus-show-mime))
3679 (format "%c%c%c%c%c%c%c"
3681 (if (or headers boring) ?h ? )
3682 (if (or pgp pem) ?p ? )
3683 (if signature ?s ? )
3684 (if overstrike ?o ? )
3686 (if emphasis ?e ? )))))
3688 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3690 (defun gnus-article-maybe-hide-headers ()
3691 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3692 Provided for backwards compatibility."
3693 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3694 (not (save-excursion (set-buffer gnus-summary-buffer)
3695 gnus-have-all-headers)))
3696 (not gnus-inhibit-hiding))
3697 (gnus-article-hide-headers)))
3701 (defun gnus-output-to-file (file-name)
3702 "Append the current article to a file named FILE-NAME."
3703 (let ((artbuf (current-buffer)))
3705 (insert-buffer-substring artbuf)
3706 ;; Append newline at end of the buffer as separator, and then
3708 (goto-char (point-max))
3710 (write-region-as-binary (point-min) (point-max) file-name 'append)
3713 (defun gnus-narrow-to-page (&optional arg)
3714 "Narrow the article buffer to a page.
3715 If given a numerical ARG, move forward ARG pages."
3717 (setq arg (if arg (prefix-numeric-value arg) 0))
3719 (set-buffer gnus-article-buffer)
3720 (goto-char (point-min))
3722 ;; Remove any old next/prev buttons.
3723 (when (gnus-visual-p 'page-marker)
3724 (let ((buffer-read-only nil))
3725 (gnus-remove-text-with-property 'gnus-prev)
3726 (gnus-remove-text-with-property 'gnus-next)))
3729 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3731 (re-search-forward page-delimiter nil 'move arg)))
3732 (goto-char (match-end 0)))
3735 (if (re-search-forward page-delimiter nil 'move)
3738 (when (and (gnus-visual-p 'page-marker)
3739 (not (= (point-min) 1)))
3741 (goto-char (point-min))
3742 (gnus-insert-prev-page-button)))
3743 (when (and (gnus-visual-p 'page-marker)
3744 (< (+ (point-max) 2) (buffer-size)))
3746 (goto-char (point-max))
3747 (gnus-insert-next-page-button)))))
3749 ;; Article mode commands
3751 (defun gnus-article-goto-next-page ()
3752 "Show the next page of the article."
3754 (when (gnus-article-next-page)
3755 (goto-char (point-min))
3756 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3758 (defun gnus-article-goto-prev-page ()
3759 "Show the next page of the article."
3761 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3762 (gnus-article-prev-page nil)))
3764 (defun gnus-article-next-page (&optional lines)
3765 "Show the next page of the current article.
3766 If end of article, return non-nil. Otherwise return nil.
3767 Argument LINES specifies lines to be scrolled up."
3769 (let ((start (window-start))
3770 end-of-buffer end-of-page)
3772 (move-to-window-line -1)
3773 (if (<= (point) start)
3776 (setq start (point)))
3779 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3780 (setq end-of-buffer t))
3782 (setq end-of-page t)))
3784 (move-to-window-line lines)
3785 (unless (search-backward "\n\n" nil t)
3786 (setq start (point)))))
3787 (cond (end-of-buffer t)
3789 (gnus-narrow-to-page 1)
3793 (set-window-start (selected-window) start)
3797 (defun gnus-article-prev-page (&optional lines)
3798 "Show previous page of current article.
3799 Argument LINES specifies lines to be scrolled down."
3801 (let (beginning-of-buffer beginning-of-page)
3803 (move-to-window-line 0)
3804 (cond ((eq 1 (point))
3805 (setq beginning-of-buffer t))
3807 (setq beginning-of-page t))))
3808 (cond (beginning-of-buffer)
3810 (gnus-narrow-to-page -1))
3814 (beginning-of-buffer
3815 (goto-char (point-min))))))))
3817 (defun gnus-article-refer-article ()
3818 "Read article specified by message-id around point."
3820 (let ((point (point)))
3821 (search-forward ">" nil t) ;Move point to end of "<....>".
3822 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3823 (let ((message-id (match-string 1)))
3825 (set-buffer gnus-summary-buffer)
3826 (gnus-summary-refer-article message-id))
3828 (error "No references around point"))))
3830 (defun gnus-article-show-summary ()
3831 "Reconfigure windows to show summary buffer."
3833 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3834 (error "There is no summary buffer for this article buffer")
3835 (gnus-article-set-globals)
3836 (gnus-configure-windows 'article)
3837 (gnus-summary-goto-subject gnus-current-article)
3838 (gnus-summary-position-point)))
3840 (defun gnus-article-describe-briefly ()
3841 "Describe article mode commands briefly."
3843 (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")))
3845 (defun gnus-article-summary-command ()
3846 "Execute the last keystroke in the summary buffer."
3848 (let ((obuf (current-buffer))
3849 (owin (current-window-configuration))
3851 (switch-to-buffer gnus-article-current-summary 'norecord)
3852 (setq func (lookup-key (current-local-map) (this-command-keys)))
3853 (call-interactively func)
3855 (set-window-configuration owin)
3856 (set-window-point (get-buffer-window (current-buffer)) (point))))
3858 (defun gnus-article-summary-command-nosave ()
3859 "Execute the last keystroke in the summary buffer."
3862 (pop-to-buffer gnus-article-current-summary 'norecord)
3863 (setq func (lookup-key (current-local-map) (this-command-keys)))
3864 (call-interactively func)))
3866 (defun gnus-article-check-buffer ()
3867 "Beep if not in an article buffer."
3868 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3869 (error "Command invoked outside of a Gnus article buffer")))
3871 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3872 "Read a summary buffer key sequence and execute it from the article buffer."
3874 (gnus-article-check-buffer)
3876 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3877 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3878 "=" "^" "\M-^" "|"))
3884 '("n" "Gn" "p" "Gp"))
3887 (set-buffer gnus-article-current-summary)
3888 (let (gnus-pick-mode)
3889 (push (or key last-command-event) unread-command-events)
3890 (setq keys (static-if (featurep 'xemacs)
3891 (events-to-keys (read-key-sequence nil))
3892 (read-key-sequence nil)))))
3895 (if (or (member keys nosaves)
3896 (member keys nosave-but-article)
3897 (member keys nosave-in-article))
3899 (save-window-excursion
3900 (pop-to-buffer gnus-article-current-summary 'norecord)
3901 ;; We disable the pick minor mode commands.
3902 (let (gnus-pick-mode)
3903 (setq func (lookup-key (current-local-map) keys))))
3906 (unless (member keys nosave-in-article)
3907 (set-buffer gnus-article-current-summary))
3908 (call-interactively func)
3909 (setq new-sum-point (point)))
3910 (when (member keys nosave-but-article)
3911 (pop-to-buffer gnus-article-buffer 'norecord)))
3912 ;; These commands should restore window configuration.
3913 (let ((obuf (current-buffer))
3914 (owin (current-window-configuration))
3916 (summary gnus-article-current-summary)
3917 func in-buffer selected)
3918 (if not-restore-window
3919 (pop-to-buffer summary 'norecord)
3920 (switch-to-buffer summary 'norecord))
3921 (setq in-buffer (current-buffer))
3922 ;; We disable the pick minor mode commands.
3923 (if (setq func (let (gnus-pick-mode)
3924 (lookup-key (current-local-map) keys)))
3926 (call-interactively func)
3927 (setq new-sum-point (point)))
3929 (when (eq in-buffer (current-buffer))
3930 (setq selected (gnus-summary-select-article))
3932 (unless not-restore-window
3933 (set-window-configuration owin))
3934 (when (eq selected 'old)
3936 (set-window-start (get-buffer-window (current-buffer))
3938 (set-window-point (get-buffer-window (current-buffer))
3940 (let ((win (get-buffer-window gnus-article-current-summary)))
3942 (set-window-point win new-sum-point))))))))
3944 (defun gnus-article-hide (&optional arg force)
3945 "Hide all the gruft in the current article.
3946 This means that PGP stuff, signatures, cited text and (some)
3947 headers will be hidden.
3948 If given a prefix, show the hidden text instead."
3949 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3950 (gnus-article-hide-headers arg)
3951 (gnus-article-hide-list-identifiers arg)
3952 (gnus-article-hide-pgp arg)
3953 (gnus-article-hide-citation-maybe arg force)
3954 (gnus-article-hide-signature arg))
3956 (defun gnus-article-maybe-highlight ()
3957 "Do some article highlighting if article highlighting is requested."
3958 (when (gnus-visual-p 'article-highlight 'highlight)
3959 (gnus-article-highlight-some)))
3961 (defun gnus-check-group-server ()
3962 ;; Make sure the connection to the server is alive.
3963 (unless (gnus-server-opened
3964 (gnus-find-method-for-group gnus-newsgroup-name))
3965 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3966 (gnus-request-group gnus-newsgroup-name t)))
3968 (defun gnus-request-article-this-buffer (article group)
3969 "Get an article and insert it into this buffer."
3970 (let (do-update-line sparse-header)
3974 (gnus-kill-all-overlays)
3975 (setq group (or group gnus-newsgroup-name))
3977 ;; Using `gnus-request-article' directly will insert the article into
3978 ;; `nntp-server-buffer' - so we'll save some time by not having to
3979 ;; copy it from the server buffer into the article buffer.
3981 ;; We only request an article by message-id when we do not have the
3982 ;; headers for it, so we'll have to get those.
3983 (when (stringp article)
3984 (let ((gnus-override-method gnus-refer-article-method))
3985 (gnus-read-header article)))
3987 ;; If the article number is negative, that means that this article
3988 ;; doesn't belong in this newsgroup (possibly), so we find its
3989 ;; message-id and request it by id instead of number.
3990 (when (and (numberp article)
3992 (get-buffer gnus-summary-buffer)
3993 (gnus-buffer-exists-p gnus-summary-buffer))
3995 (set-buffer gnus-summary-buffer)
3996 (let ((header (gnus-summary-article-header article)))
3999 ((memq article gnus-newsgroup-sparse)
4000 ;; This is a sparse gap article.
4001 (setq do-update-line article)
4002 (setq article (mail-header-id header))
4003 (let ((gnus-override-method gnus-refer-article-method))
4004 (setq sparse-header (gnus-read-header article)))
4005 (setq gnus-newsgroup-sparse
4006 (delq article gnus-newsgroup-sparse)))
4008 ;; It's a real article.
4009 (setq article (mail-header-id header)))
4011 ;; It is an extracted pseudo-article.
4012 (setq article 'pseudo)
4013 (gnus-request-pseudo-article header))))
4015 (let ((method (gnus-find-method-for-group
4016 gnus-newsgroup-name)))
4017 (when (and (eq (car method) 'nneething)
4020 (file-name-as-directory
4021 (or (cadr (assq 'nneething-address method))
4023 (mail-header-subject header))))
4024 (when (file-directory-p dir)
4025 (setq article 'nneething)
4026 (gnus-group-enter-directory dir))))))))
4029 ;; Refuse to select canceled articles.
4030 ((and (numberp article)
4032 (get-buffer gnus-summary-buffer)
4033 (gnus-buffer-exists-p gnus-summary-buffer)
4034 (eq (cdr (save-excursion
4035 (set-buffer gnus-summary-buffer)
4036 (assq article gnus-newsgroup-reads)))
4037 gnus-canceled-mark))
4039 ;; Check the backlog.
4040 ((and gnus-keep-backlog
4041 (gnus-backlog-request-article group article (current-buffer)))
4043 ;; Check asynchronous pre-fetch.
4044 ((gnus-async-request-fetched-article group article (current-buffer))
4045 (gnus-async-prefetch-next group article gnus-summary-buffer)
4046 (when (and (numberp article) gnus-keep-backlog)
4047 (gnus-backlog-enter-article group article (current-buffer)))
4050 ((and gnus-use-cache
4052 (gnus-cache-request-article article group))
4054 ;; Get the article and put into the article buffer.
4055 ((or (stringp article) (numberp article))
4056 (let ((gnus-override-method
4057 (and (stringp article) gnus-refer-article-method))
4058 (buffer-read-only nil))
4060 (gnus-kill-all-overlays)
4061 (gnus-check-group-server)
4062 (when (gnus-request-article article group (current-buffer))
4063 (when (numberp article)
4064 (gnus-async-prefetch-next group article gnus-summary-buffer)
4065 (when gnus-keep-backlog
4066 (gnus-backlog-enter-article
4067 group article (current-buffer))))
4072 ;; Associate this article with the current summary buffer.
4073 (setq gnus-article-current-summary gnus-summary-buffer)
4075 ;; Take the article from the original article buffer
4076 ;; and place it in the buffer it's supposed to be in.
4077 (when (and (get-buffer gnus-article-buffer)
4078 (equal (buffer-name (current-buffer))
4079 (buffer-name (get-buffer gnus-article-buffer))))
4081 (if (get-buffer gnus-original-article-buffer)
4082 (set-buffer gnus-original-article-buffer)
4083 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4084 (buffer-disable-undo)
4085 (setq major-mode 'gnus-original-article-mode)
4086 (setq buffer-read-only t))
4087 (let (buffer-read-only)
4089 (insert-buffer-substring gnus-article-buffer))
4090 (setq gnus-original-article (cons group article)))
4093 (run-hooks 'gnus-article-decode-hook)
4094 ;; Mark article as decoded or not.
4095 (setq gnus-article-decoded-p gnus-article-decode-hook))
4097 ;; Update sparse articles.
4098 (when (and do-update-line
4099 (or (numberp article)
4101 (let ((buf (current-buffer)))
4102 (set-buffer gnus-summary-buffer)
4103 (gnus-summary-update-article do-update-line sparse-header)
4104 (gnus-summary-goto-subject do-update-line nil t)
4105 (set-window-point (get-buffer-window (current-buffer) t)
4107 (set-buffer buf))))))
4113 (defcustom gnus-article-edit-mode-hook nil
4114 "Hook run in article edit mode buffers."
4115 :group 'gnus-article-various
4118 (defcustom gnus-article-edit-article-setup-function
4119 'gnus-article-mime-edit-article-setup
4120 "Function called to setup an editing article buffer."
4121 :group 'gnus-article-various
4124 (defvar gnus-article-edit-done-function nil)
4126 (defvar gnus-article-edit-mode-map nil)
4128 ;; Should we be using derived.el for this?
4129 (unless gnus-article-edit-mode-map
4130 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4131 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4133 (gnus-define-keys gnus-article-edit-mode-map
4134 "\C-c\C-c" gnus-article-edit-done
4135 "\C-c\C-k" gnus-article-edit-exit)
4137 (gnus-define-keys (gnus-article-edit-wash-map
4138 "\C-c\C-w" gnus-article-edit-mode-map)
4139 "f" gnus-article-edit-full-stops))
4141 (defun gnus-article-edit-mode ()
4142 "Major mode for editing articles.
4143 This is an extended text-mode.
4145 \\{gnus-article-edit-mode-map}"
4147 (setq major-mode 'gnus-article-edit-mode)
4148 (setq mode-name "Article Edit")
4149 (use-local-map gnus-article-edit-mode-map)
4150 (make-local-variable 'gnus-article-edit-done-function)
4151 (make-local-variable 'gnus-prev-winconf)
4152 (setq buffer-read-only nil)
4153 (buffer-enable-undo)
4155 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4157 (defun gnus-article-edit (&optional force)
4158 "Edit the current article.
4159 This will have permanent effect only in mail groups.
4160 If FORCE is non-nil, allow editing of articles even in read-only
4163 (when (and (not force)
4164 (gnus-group-read-only-p))
4165 (error "The current newsgroup does not support article editing"))
4166 (gnus-article-date-original)
4167 (gnus-article-edit-article
4169 `(lambda (no-highlight)
4171 (gnus-summary-edit-article-done
4172 ,(or (mail-header-references gnus-current-headers) "")
4173 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4175 (defun gnus-article-edit-article (start-func exit-func)
4176 "Start editing the contents of the current article buffer."
4177 (let ((winconf (current-window-configuration)))
4178 (set-buffer gnus-article-buffer)
4179 (gnus-article-edit-mode)
4180 (funcall start-func)
4181 (gnus-configure-windows 'edit-article)
4182 (setq gnus-article-edit-done-function exit-func)
4183 (setq gnus-prev-winconf winconf)
4184 (when gnus-article-edit-article-setup-function
4185 (funcall gnus-article-edit-article-setup-function))
4186 (gnus-message 6 "C-c C-c to end edits")))
4188 (defun gnus-article-edit-done (&optional arg)
4189 "Update the article edits and exit."
4194 (when (article-goto-body)
4195 (let ((lines (count-lines (point) (point-max)))
4196 (length (- (point-max) (point)))
4197 (case-fold-search t)
4198 (body (copy-marker (point))))
4199 (goto-char (point-min))
4200 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4201 (delete-region (match-beginning 1) (match-end 1))
4202 (insert (number-to-string length)))
4203 (goto-char (point-min))
4204 (when (re-search-forward
4205 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4206 (delete-region (match-beginning 1) (match-end 1))
4207 (insert (number-to-string length)))
4208 (goto-char (point-min))
4209 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4210 (delete-region (match-beginning 1) (match-end 1))
4211 (insert (number-to-string lines)))))))
4212 (let ((func gnus-article-edit-done-function)
4213 (buf (current-buffer))
4214 (start (window-start)))
4215 (remove-hook 'gnus-article-mode-hook
4216 'gnus-article-mime-edit-article-unwind)
4217 (gnus-article-edit-exit)
4220 (let ((buffer-read-only nil))
4222 ;; The cache and backlog have to be flushed somewhat.
4223 (when gnus-keep-backlog
4224 (gnus-backlog-remove-article
4225 (car gnus-article-current) (cdr gnus-article-current)))
4226 ;; Flush original article as well.
4228 (when (get-buffer gnus-original-article-buffer)
4229 (set-buffer gnus-original-article-buffer)
4230 (setq gnus-original-article nil)))
4231 (when gnus-use-cache
4232 (gnus-cache-update-article
4233 (car gnus-article-current) (cdr gnus-article-current))))
4235 (set-window-start (get-buffer-window buf) start)
4236 (set-window-point (get-buffer-window buf) (point))))
4238 (defun gnus-article-edit-exit ()
4239 "Exit the article editing without updating."
4241 ;; We remove all text props from the article buffer.
4242 (let ((buf (format "%s" (buffer-string)))
4243 (curbuf (current-buffer))
4245 (window-start (window-start)))
4248 (let ((winconf gnus-prev-winconf))
4250 (set-window-configuration winconf)
4251 ;; Tippy-toe some to make sure that point remains where it was.
4252 (save-current-buffer
4254 (set-window-start (get-buffer-window (current-buffer)) window-start)
4257 (defun gnus-article-edit-full-stops ()
4258 "Interactively repair spacing at end of sentences."
4261 (goto-char (point-min))
4262 (search-forward-regexp "^$" nil t)
4263 (let ((case-fold-search nil))
4264 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4267 ;;; Article editing with MIME-Edit
4270 (defcustom gnus-article-mime-edit-article-setup-hook nil
4271 "Hook run after setting up a MIME editing article buffer."
4272 :group 'gnus-article-various
4275 (defun gnus-article-mime-edit-article-unwind ()
4276 "Unwind `gnus-article-buffer' if article editing was given up."
4277 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4278 (when mime-edit-mode-flag
4279 (mime-edit-exit 'nomime 'no-error)
4281 (when (featurep 'font-lock)
4282 (setq font-lock-defaults nil)
4283 (font-lock-mode 0)))
4285 (defun gnus-article-mime-edit-article-setup ()
4286 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4287 after replacing with the original article."
4288 (setq gnus-show-mime t)
4289 (setq gnus-article-edit-done-function
4290 `(lambda (&rest args)
4291 (when mime-edit-mode-flag
4294 (goto-char (point-min))
4295 (let (case-fold-search)
4296 (when (re-search-forward
4297 (format "^%s$" (regexp-quote mail-header-separator))
4299 (replace-match "")))
4300 (when (featurep 'font-lock)
4301 (setq font-lock-defaults nil)
4303 (apply ,gnus-article-edit-done-function args)
4304 (set-buffer gnus-original-article-buffer)
4306 (insert-buffer gnus-article-buffer)
4307 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4308 (gnus-article-prepare-display)))
4309 (substitute-key-definition
4310 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4311 gnus-article-edit-mode-map)
4313 (insert-buffer gnus-original-article-buffer)
4315 (when (featurep 'font-lock)
4316 (set (make-local-variable 'font-lock-defaults)
4317 '(message-font-lock-keywords t))
4318 (font-lock-set-defaults)
4319 (turn-on-font-lock))
4320 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4321 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4323 (defun gnus-article-mime-edit-exit ()
4324 "Exit the article MIME editing without updating."
4326 (let ((winconf gnus-prev-winconf)
4328 (when mime-edit-mode-flag
4331 (goto-char (point-min))
4332 (let (case-fold-search)
4333 (when (re-search-forward
4334 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4335 (replace-match "")))
4336 (when (featurep 'font-lock)
4337 (setq font-lock-defaults nil)
4339 ;; We remove all text props from the article buffer.
4340 (setq buf (format "%s" (buffer-string)))
4341 (set-buffer (get-buffer-create gnus-original-article-buffer))
4344 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4345 (gnus-article-prepare-display)
4346 (set-window-configuration winconf)))
4349 ;;; Article highlights
4352 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4354 ;;; Internal Variables:
4356 (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\\)"
4357 "Regular expression that matches URLs."
4358 :group 'gnus-article-buttons
4361 (defcustom gnus-button-alist
4362 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4363 0 t gnus-button-message-id 2)
4364 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4365 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4367 gnus-button-fetch-group 4)
4368 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4369 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4370 t gnus-button-message-id 3)
4371 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4372 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4373 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4374 ;; This is how URLs _should_ be embedded in text...
4375 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
4377 (,gnus-button-url-regexp 0 t gnus-button-url 0))
4378 "*Alist of regexps matching buttons in article bodies.
4380 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4381 REGEXP: is the string matching text around the button,
4382 BUTTON: is the number of the regexp grouping actually matching the button,
4383 FORM: is a lisp expression which must eval to true for the button to
4385 CALLBACK: is the function to call when the user push this button, and each
4386 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4388 CALLBACK can also be a variable, in that case the value of that
4389 variable it the real callback function."
4390 :group 'gnus-article-buttons
4391 :type '(repeat (list regexp
4392 (integer :tag "Button")
4394 (function :tag "Callback")
4397 (integer :tag "Regexp group")))))
4399 (defcustom gnus-header-button-alist
4400 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4401 0 t gnus-button-message-id 0)
4402 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4403 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4404 0 t gnus-button-mailto 0)
4405 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4406 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4407 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4408 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4409 gnus-button-message-id 3))
4410 "*Alist of headers and regexps to match buttons in article heads.
4412 This alist is very similar to `gnus-button-alist', except that each
4413 alist has an additional HEADER element first in each entry:
4415 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4417 HEADER is a regexp to match a header. For a fuller explanation, see
4418 `gnus-button-alist'."
4419 :group 'gnus-article-buttons
4420 :group 'gnus-article-headers
4421 :type '(repeat (list (regexp :tag "Header")
4423 (integer :tag "Button")
4425 (function :tag "Callback")
4428 (integer :tag "Regexp group")))))
4430 (defvar gnus-button-regexp nil)
4431 (defvar gnus-button-marker-list nil)
4432 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4434 (defvar gnus-button-last nil)
4435 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4439 (defun gnus-article-push-button (event)
4440 "Check text under the mouse pointer for a callback function.
4441 If the text under the mouse pointer has a `gnus-callback' property,
4442 call it with the value of the `gnus-data' text property."
4444 (set-buffer (window-buffer (posn-window (event-start event))))
4445 (let* ((pos (posn-point (event-start event)))
4446 (data (get-text-property pos 'gnus-data))
4447 (fun (get-text-property pos 'gnus-callback)))
4450 (funcall fun data))))
4452 (defun gnus-article-press-button ()
4453 "Check text at point for a callback function.
4454 If the text at point has a `gnus-callback' property,
4455 call it with the value of the `gnus-data' text property."
4457 (let* ((data (get-text-property (point) 'gnus-data))
4458 (fun (get-text-property (point) 'gnus-callback)))
4460 (funcall fun data))))
4462 (defun gnus-article-prev-button (n)
4463 "Move point to N buttons backward.
4464 If N is negative, move forward instead."
4466 (gnus-article-next-button (- n)))
4468 (defun gnus-article-next-button (n)
4469 "Move point to N buttons forward.
4470 If N is negative, move backward instead."
4472 (let ((function (if (< n 0) 'previous-single-property-change
4473 'next-single-property-change))
4474 (inhibit-point-motion-hooks t)
4476 (limit (if (< n 0) (point-min) (point-max))))
4478 (while (and (not (= limit (point)))
4480 ;; Skip past the current button.
4481 (when (get-text-property (point) 'gnus-callback)
4482 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4483 ;; Go to the next (or previous) button.
4484 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4485 ;; Put point at the start of the button.
4486 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4487 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4488 ;; Skip past intangible buttons.
4489 (when (get-text-property (point) 'intangible)
4493 (gnus-message 5 "No more buttons"))
4496 (defun gnus-article-highlight (&optional force)
4497 "Highlight current article.
4498 This function calls `gnus-article-highlight-headers',
4499 `gnus-article-highlight-citation',
4500 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4501 do the highlighting. See the documentation for those functions."
4502 (interactive (list 'force))
4503 (gnus-article-highlight-headers)
4504 (gnus-article-highlight-citation force)
4505 (gnus-article-highlight-signature)
4506 (gnus-article-add-buttons force)
4507 (gnus-article-add-buttons-to-head))
4509 (defun gnus-article-highlight-some (&optional force)
4510 "Highlight current article.
4511 This function calls `gnus-article-highlight-headers',
4512 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4513 do the highlighting. See the documentation for those functions."
4514 (interactive (list 'force))
4515 (gnus-article-highlight-headers)
4516 (gnus-article-highlight-signature)
4517 (gnus-article-add-buttons))
4519 (defun gnus-article-highlight-headers ()
4520 "Highlight article headers as specified by `gnus-header-face-alist'."
4523 (set-buffer gnus-article-buffer)
4525 (let ((alist gnus-header-face-alist)
4526 (buffer-read-only nil)
4527 (case-fold-search t)
4528 (inhibit-point-motion-hooks t)
4529 entry regexp header-face field-face from hpoints fpoints)
4530 (article-narrow-to-head)
4531 (while (setq entry (pop alist))
4532 (goto-char (point-min))
4533 (setq regexp (concat "^\\("
4534 (if (string-equal "" (nth 0 entry))
4538 header-face (nth 1 entry)
4539 field-face (nth 2 entry))
4540 (while (and (re-search-forward regexp nil t)
4544 (unless (search-forward ":" nil t)
4546 (when (and header-face
4547 (not (memq (point) hpoints)))
4548 (push (point) hpoints)
4549 (gnus-put-text-property from (point) 'face header-face))
4550 (when (and field-face
4551 (not (memq (setq from (point)) fpoints)))
4553 (if (re-search-forward "^[^ \t]" nil t)
4555 (goto-char (point-max)))
4556 (gnus-put-text-property from (point) 'face field-face))))))))
4558 (defun gnus-article-highlight-signature ()
4559 "Highlight the signature in an article.
4560 It does this by highlighting everything after
4561 `gnus-signature-separator' using `gnus-signature-face'."
4563 (when gnus-signature-face
4565 (set-buffer gnus-article-buffer)
4566 (let ((buffer-read-only nil)
4567 (inhibit-point-motion-hooks t))
4569 (when (gnus-article-narrow-to-signature)
4570 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4571 'face gnus-signature-face)))))))
4573 (defun gnus-article-buttonize-signature ()
4574 "Add button to the signature."
4577 (set-buffer gnus-article-buffer)
4578 (let ((buffer-read-only nil)
4579 (inhibit-point-motion-hooks t))
4580 (when (gnus-article-search-signature)
4581 (gnus-article-add-button (match-beginning 0) (match-end 0)
4582 'gnus-signature-toggle
4583 (set-marker (make-marker)
4584 (1+ (match-end 0))))))))
4586 (defun gnus-button-in-region-p (b e prop)
4587 "Say whether PROP exists in the region."
4588 (text-property-not-all b e prop nil))
4590 (defun gnus-article-add-buttons (&optional force)
4591 "Find external references in the article and make buttons of them.
4592 \"External references\" are things like Message-IDs and URLs, as
4593 specified by `gnus-button-alist'."
4594 (interactive (list 'force))
4596 (set-buffer gnus-article-buffer)
4597 (let ((buffer-read-only nil)
4598 (inhibit-point-motion-hooks t)
4599 (case-fold-search t)
4600 (alist gnus-button-alist)
4602 ;; Remove all old markers.
4603 (let (marker entry new-list)
4604 (while (setq marker (pop gnus-button-marker-list))
4605 (if (or (< marker (point-min)) (>= marker (point-max)))
4606 (push marker new-list)
4608 (when (setq entry (gnus-button-entry))
4609 (put-text-property (match-beginning (nth 1 entry))
4610 (match-end (nth 1 entry))
4611 'gnus-callback nil))
4612 (set-marker marker nil)))
4613 (setq gnus-button-marker-list new-list))
4614 ;; We skip the headers.
4617 (while (setq entry (pop alist))
4618 (setq regexp (car entry))
4620 (while (re-search-forward regexp nil t)
4621 (let* ((start (and entry (match-beginning (nth 1 entry))))
4622 (end (and entry (match-end (nth 1 entry))))
4623 (from (match-beginning 0)))
4624 (when (and (or (eq t (nth 2 entry))
4625 (eval (nth 2 entry)))
4626 (not (gnus-button-in-region-p
4627 start end 'gnus-callback)))
4628 ;; That optional form returned non-nil, so we add the
4630 (gnus-article-add-button
4631 start end 'gnus-button-push
4632 (car (push (set-marker (make-marker) from)
4633 gnus-button-marker-list))))))))))
4635 ;; Add buttons to the head of an article.
4636 (defun gnus-article-add-buttons-to-head ()
4637 "Add buttons to the head of the article."
4640 (set-buffer gnus-article-buffer)
4642 (let ((buffer-read-only nil)
4643 (inhibit-point-motion-hooks t)
4644 (case-fold-search t)
4645 (alist gnus-header-button-alist)
4647 (article-narrow-to-head)
4649 ;; Each alist entry.
4650 (setq entry (car alist)
4652 (goto-char (point-min))
4653 (while (re-search-forward (car entry) nil t)
4654 ;; Each header matching the entry.
4655 (setq beg (match-beginning 0))
4656 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4657 (match-beginning 0))
4660 (while (re-search-forward (nth 1 entry) end t)
4661 ;; Each match within a header.
4662 (let* ((entry (cdr entry))
4663 (start (match-beginning (nth 1 entry)))
4664 (end (match-end (nth 1 entry)))
4665 (form (nth 2 entry)))
4666 (goto-char (match-end 0))
4668 (gnus-article-add-button
4669 start end (nth 3 entry)
4670 (buffer-substring (match-beginning (nth 4 entry))
4671 (match-end (nth 4 entry)))))))
4672 (goto-char end)))))))
4674 ;;; External functions:
4676 (defun gnus-article-add-button (from to fun &optional data)
4677 "Create a button between FROM and TO with callback FUN and data DATA."
4678 (when gnus-article-button-face
4679 (gnus-overlay-put (gnus-make-overlay from to)
4680 'face gnus-article-button-face))
4681 (gnus-add-text-properties
4683 (nconc (and gnus-article-mouse-face
4684 (list gnus-mouse-face-prop gnus-article-mouse-face))
4685 (list 'gnus-callback fun)
4686 (and data (list 'gnus-data data)))))
4688 ;;; Internal functions:
4690 (defun gnus-article-set-globals ()
4692 (set-buffer gnus-summary-buffer)
4693 (gnus-set-global-variables)))
4695 (defun gnus-signature-toggle (end)
4697 (set-buffer gnus-article-buffer)
4698 (let ((buffer-read-only nil)
4699 (inhibit-point-motion-hooks t)
4700 (limit (or (next-single-property-change end 'mime-view-entity)
4702 (if (get-text-property end 'invisible)
4703 (gnus-article-unhide-text end limit)
4704 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4706 (defun gnus-button-entry ()
4707 ;; Return the first entry in `gnus-button-alist' matching this place.
4708 (let ((alist gnus-button-alist)
4711 (setq entry (pop alist))
4712 (if (looking-at (car entry))
4717 (defun gnus-button-push (marker)
4718 ;; Push button starting at MARKER.
4721 (let* ((entry (gnus-button-entry))
4722 (inhibit-point-motion-hooks t)
4724 (args (mapcar (lambda (group)
4725 (let ((string (match-string group)))
4726 (gnus-set-text-properties
4727 0 (length string) nil string)
4734 (fboundp (symbol-value fun)))
4735 (apply (symbol-value fun) args))
4737 (gnus-message 1 "You must define `%S' to use this button"
4738 (cons fun args)))))))
4740 (defun gnus-button-message-id (message-id)
4743 (set-buffer gnus-summary-buffer)
4744 (gnus-summary-refer-article message-id)))
4746 (defun gnus-button-fetch-group (address)
4747 "Fetch GROUP specified by ADDRESS."
4748 (if (not (string-match "[:/]" address))
4749 ;; This is just a simple group url.
4750 (gnus-group-read-ephemeral-group address gnus-select-method)
4751 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4753 (error "Can't parse %s" address)
4754 (gnus-group-read-ephemeral-group
4755 (match-string 4 address)
4756 `(nntp ,(match-string 1 address)
4757 (nntp-address ,(match-string 1 address))
4758 (nntp-port-number ,(if (match-end 3)
4759 (match-string 3 address)
4762 (defun gnus-url-parse-query-string (query &optional downcase)
4763 (let (retval pairs cur key val)
4764 (setq pairs (split-string query "&"))
4766 (setq cur (car pairs)
4768 (if (not (string-match "=" cur))
4770 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4771 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4773 (setq key (downcase key)))
4774 (setq cur (assoc key retval))
4776 (setcdr cur (cons val (cdr cur)))
4777 (setq retval (cons (list key val) retval)))))
4780 (defun gnus-url-unhex (x)
4787 (defun gnus-url-unhex-string (str &optional allow-newlines)
4788 "Remove %XXX embedded spaces, etc in a url.
4789 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4790 decoding of carriage returns and line feeds in the string, which is normally
4791 forbidden in URL encoding."
4792 (setq str (or str ""))
4794 (case-fold-search t))
4795 (while (string-match "%[0-9a-f][0-9a-f]" str)
4796 (let* ((start (match-beginning 0))
4797 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4799 (gnus-url-unhex (elt str (+ start 2))))))
4801 tmp (substring str 0 start)
4804 (char-to-string code))
4805 ((or (= code ?\n) (= code ?\r))
4807 (t (char-to-string code))))
4808 str (substring str (match-end 0)))))
4809 (setq tmp (concat tmp str))
4812 (defun gnus-url-mailto (url)
4813 ;; Send mail to someone
4814 (when (string-match "mailto:/*\\(.*\\)" url)
4815 (setq url (substring url (match-beginning 1) nil)))
4816 (let (to args subject func)
4817 (if (string-match (regexp-quote "?") url)
4818 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4819 args (gnus-url-parse-query-string
4820 (substring url (match-end 0) nil) t))
4821 (setq to (gnus-url-unhex-string url)))
4822 (setq args (cons (list "to" to) args)
4823 subject (cdr-safe (assoc "subject" args)))
4824 (gnus-setup-message 'reply
4827 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4830 (message-position-on-field (caar args)))
4831 (insert (mapconcat 'identity (cdar args) ", "))
4832 (setq args (cdr args)))
4835 (message-goto-subject)))))
4837 (defun gnus-button-mailto (address)
4839 (set-buffer (gnus-copy-article-buffer))
4840 (gnus-setup-message 'reply
4841 (message-reply address)))
4843 (defun gnus-button-reply (address)
4844 ;; Reply to ADDRESS.
4845 (gnus-setup-message 'reply
4846 (message-reply address)))
4848 (defun gnus-button-url (address)
4850 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4851 (if (listp browse-url-browser-function)
4852 (browse-url address)
4853 (funcall browse-url-browser-function address)))
4855 (defun gnus-button-embedded-url (address)
4857 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4858 (if (listp browse-url-browser-function)
4859 (browse-url (gnus-strip-whitespace address))
4860 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4862 ;;; Next/prev buttons in the article buffer.
4864 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4865 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4867 (defvar gnus-prev-page-map nil)
4868 (unless gnus-prev-page-map
4869 (setq gnus-prev-page-map (make-sparse-keymap))
4870 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4871 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4873 (static-if (featurep 'xemacs)
4874 (defun gnus-insert-prev-page-button ()
4875 (let ((buffer-read-only nil))
4877 gnus-prev-page-line-format nil
4878 `(gnus-prev t local-map ,gnus-prev-page-map
4879 gnus-callback gnus-article-button-prev-page
4880 article-type annotation))))
4881 (defun gnus-insert-prev-page-button ()
4882 (let ((buffer-read-only nil)
4883 (situation (get-text-property (point-min) 'mime-view-situation)))
4884 (set-keymap-parent gnus-prev-page-map (current-local-map))
4886 gnus-prev-page-line-format nil
4887 `(gnus-prev t local-map ,gnus-prev-page-map
4888 gnus-callback gnus-article-button-prev-page
4889 article-type annotation
4890 mime-view-situation ,situation))))
4893 (defvar gnus-next-page-map nil)
4894 (unless gnus-next-page-map
4895 (setq gnus-next-page-map (make-sparse-keymap))
4896 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4897 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4899 (defun gnus-button-next-page ()
4900 "Go to the next page."
4902 (let ((win (selected-window)))
4903 (select-window (get-buffer-window gnus-article-buffer t))
4904 (gnus-article-next-page)
4905 (select-window win)))
4907 (defun gnus-button-prev-page ()
4908 "Go to the prev page."
4910 (let ((win (selected-window)))
4911 (select-window (get-buffer-window gnus-article-buffer t))
4912 (gnus-article-prev-page)
4913 (select-window win)))
4915 (static-if (featurep 'xemacs)
4916 (defun gnus-insert-next-page-button ()
4917 (let ((buffer-read-only nil))
4918 (gnus-eval-format gnus-next-page-line-format nil
4920 t local-map ,gnus-next-page-map
4921 gnus-callback gnus-article-button-next-page
4922 article-type annotation))))
4923 (defun gnus-insert-next-page-button ()
4924 (let ((buffer-read-only nil)
4925 (situation (get-text-property (point-min) 'mime-view-situation)))
4926 (set-keymap-parent gnus-next-page-map (current-local-map))
4927 (gnus-eval-format gnus-next-page-line-format nil
4929 t local-map ,gnus-next-page-map
4930 gnus-callback gnus-article-button-next-page
4931 article-type annotation
4932 mime-view-situation ,situation))))
4935 (defun gnus-article-button-next-page (arg)
4936 "Go to the next page."
4938 (let ((win (selected-window)))
4939 (select-window (get-buffer-window gnus-article-buffer t))
4940 (gnus-article-next-page)
4941 (select-window win)))
4943 (defun gnus-article-button-prev-page (arg)
4944 "Go to the prev page."
4946 (let ((win (selected-window)))
4947 (select-window (get-buffer-window gnus-article-buffer t))
4948 (gnus-article-prev-page)
4949 (select-window win)))
4951 (defvar gnus-decode-header-methods
4952 '(mail-decode-encoded-word-region)
4953 "List of methods used to decode headers.
4955 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4956 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4957 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4958 whose names match REGEXP.
4961 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4962 mail-decode-encoded-word-region
4963 (\"chinese\" . rfc1843-decode-region))
4966 (defvar gnus-decode-header-methods-cache nil)
4968 (defun gnus-multi-decode-header (start end)
4969 "Apply the functions from `gnus-encoded-word-methods' that match."
4970 (unless (and gnus-decode-header-methods-cache
4971 (eq gnus-newsgroup-name
4972 (car gnus-decode-header-methods-cache)))
4973 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4976 (nconc gnus-decode-header-methods-cache (list x))
4977 (if (and gnus-newsgroup-name
4978 (string-match (car x) gnus-newsgroup-name))
4979 (nconc gnus-decode-header-methods-cache
4981 gnus-decode-header-methods))
4982 (let ((xlist gnus-decode-header-methods-cache))
4985 (narrow-to-region start end)
4987 (funcall (pop xlist) (point-min) (point-max))))))
4990 ;;; Treatment top-level handling.
4993 (defun gnus-treat-article (condition &optional part-number total-parts type)
4994 (let ((length (- (point-max) (point-min)))
4995 (alist gnus-treatment-function-alist)
4996 (article-goto-body-goes-to-point-min-p t)
5000 (let ((list gnus-article-treat-types))
5002 (when (string-match (pop list) type)
5003 (throw 'found t)))))))
5004 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5005 (entity (static-unless (featurep 'xemacs)
5006 (when (eq 'head condition)
5007 (get-text-property (point-min) 'mime-view-entity))))
5008 val elem buttonized)
5009 (gnus-run-hooks 'gnus-part-display-hook)
5010 (unless gnus-inhibit-treatment
5011 (while (setq elem (pop alist))
5012 (setq val (symbol-value (car elem)))
5013 (when (and (or (consp val)
5015 (gnus-treat-predicate val)
5016 (or (not (get (car elem) 'highlight))
5018 (when (and (not buttonized)
5020 '(gnus-treat-hide-signature
5021 gnus-treat-highlight-signature)))
5022 (gnus-article-buttonize-signature)
5023 (setq buttonized t))
5025 (funcall (cadr elem)))))
5026 ;; FSF Emacsen does not inherit the existing text properties
5027 ;; in the new text, so we should do it for `mime-view-entity'.
5028 (static-unless (featurep 'xemacs)
5030 (put-text-property (point-min) (point-max)
5031 'mime-view-entity entity))))))
5033 ;; Dynamic variables.
5034 (defvar part-number)
5035 (defvar total-parts)
5039 (defun gnus-treat-predicate (val)
5044 (stringp (car val)))
5045 (apply 'gnus-or (mapcar `(lambda (s)
5046 (string-match s ,(or gnus-newsgroup-name "")))
5049 (let ((pred (pop val)))
5052 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5054 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5056 (not (gnus-treat-predicate (car val))))
5058 (equal (car val) type))
5060 (error "%S is not a valid predicate" pred)))))
5070 (eq part-number total-parts))
5074 (error "%S is not a valid value" val))))
5080 (defun gnus-article-header-presentation-method (entity situation)
5081 (mime-insert-header entity)
5084 (set-alist 'mime-header-presentation-method-alist
5085 'gnus-original-article-mode
5086 #'gnus-article-header-presentation-method)
5088 (defun gnus-mime-preview-quitting-method ()
5089 (mime-preview-kill-buffer)
5090 (delete-other-windows)
5091 (gnus-article-show-summary)
5092 (gnus-summary-select-article gnus-show-all-headers t))
5094 (set-alist 'mime-preview-quitting-method-alist
5095 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5097 (defun gnus-following-method (buf)
5100 (message-yank-original)
5102 (goto-char (point-min))
5105 (set-alist 'mime-preview-following-method-alist
5106 'gnus-original-article-mode #'gnus-following-method)
5108 (set-alist 'mime-preview-over-to-previous-method-alist
5109 'gnus-original-article-mode
5111 (if (> (point-min) 1)
5112 (gnus-article-prev-page)
5113 (gnus-article-read-summary-keys
5114 nil (gnus-character-to-event ?P)))))
5116 (set-alist 'mime-preview-over-to-next-method-alist
5117 'gnus-original-article-mode'
5119 (if (< (point-max) (buffer-size))
5120 (gnus-article-next-page)
5121 (gnus-article-read-summary-keys
5122 nil (gnus-character-to-event ?N)))))
5132 (run-hooks 'gnus-art-load-hook)
5134 ;;; gnus-art.el ends here