1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'static))
43 ;; Avoid byte-compile warnings.
44 (defvar gnus-article-decoded-p)
45 (defvar gnus-article-mime-handles)
55 (defgroup gnus-article nil
57 :link '(custom-manual "(gnus)The Article Buffer")
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
76 (defgroup gnus-article-signature nil
78 :link '(custom-manual "(gnus)Article Signature")
81 (defgroup gnus-article-headers nil
83 :link '(custom-manual "(gnus)Hiding Headers")
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
96 (defgroup gnus-article-saving nil
98 :link '(custom-manual "(gnus)Saving Articles")
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
116 (defcustom gnus-ignored-headers
117 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
118 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
119 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
120 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
121 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
122 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
123 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
124 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
125 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
126 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
127 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
128 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
129 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
130 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
131 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
132 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
133 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
134 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
135 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
136 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
137 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
138 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
139 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
140 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
141 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
142 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:")
143 "*All headers that start with this regexp will be hidden.
144 This variable can also be a list of regexps of headers to be ignored.
145 If `gnus-visible-headers' is non-nil, this variable will be ignored."
146 :type '(choice :custom-show nil
149 :group 'gnus-article-hiding)
151 (defcustom gnus-visible-headers
152 "^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:"
153 "*All headers that do not match this regexp will be hidden.
154 This variable can also be a list of regexp of headers to remain visible.
155 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
156 :type '(repeat :value-to-internal (lambda (widget value)
157 (custom-split-regexp-maybe value))
158 :match (lambda (widget value)
160 (widget-editable-list-match widget value)))
162 :group 'gnus-article-hiding)
164 (defcustom gnus-sorted-header-list
165 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
166 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
167 "*This variable is a list of regular expressions.
168 If it is non-nil, headers that match the regular expressions will
169 be placed first in the article buffer in the sequence specified by
171 :type '(repeat regexp)
172 :group 'gnus-article-hiding)
174 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
175 "Headers that are only to be displayed if they have interesting data.
176 Possible values in this list are `empty', `newsgroups', `followup-to',
177 `reply-to', `date', `long-to', and `many-to'."
178 :type '(set (const :tag "Headers with no content." empty)
179 (const :tag "Newsgroups with only one group." newsgroups)
180 (const :tag "Followup-to identical to newsgroups." followup-to)
181 (const :tag "Reply-to identical to from." reply-to)
182 (const :tag "Date less than four days old." date)
183 (const :tag "Very long To header." long-to)
184 (const :tag "Multiple To headers." many-to))
185 :group 'gnus-article-hiding)
187 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
188 "Regexp matching signature separator.
189 This can also be a list of regexps. In that case, it will be checked
190 from head to tail looking for a separator. Searches will be done from
191 the end of the buffer."
192 :type '(repeat string)
193 :group 'gnus-article-signature)
195 (defcustom gnus-signature-limit nil
196 "Provide a limit to what is considered a signature.
197 If it is a number, no signature may not be longer (in characters) than
198 that number. If it is a floating point number, no signature may be
199 longer (in lines) than that number. If it is a function, the function
200 will be called without any parameters, and if it returns nil, there is
201 no signature in the buffer. If it is a string, it will be used as a
202 regexp. If it matches, the text in question is not a signature."
203 :type '(choice (integer :value 200)
205 (function :value fun)
206 (regexp :value ".*"))
207 :group 'gnus-article-signature)
209 (defcustom gnus-hidden-properties '(invisible t intangible t)
210 "Property list to use for hiding text."
212 :group 'gnus-article-hiding)
214 (defcustom gnus-article-x-face-command
215 (if (and (not gnus-xemacs)
217 (module-installed-p 'x-face-mule))
218 'x-face-mule-gnus-article-display-x-face
219 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
221 "*String or function to be executed to display an X-Face header.
222 If it is a string, the command will be executed in a sub-shell
223 asynchronously. The compressed face will be piped to this command."
224 :type 'string ;Leave function case to Lisp.
225 :group 'gnus-article-washing)
227 (defcustom gnus-article-x-face-too-ugly nil
228 "Regexp matching posters whose face shouldn't be shown automatically."
229 :type '(choice regexp (const nil))
230 :group 'gnus-article-washing)
232 (defcustom gnus-emphasis-alist
234 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
236 '(("_" "_" underline)
239 ("_/" "/_" underline-italic)
240 ("_\\*" "\\*_" underline-bold)
241 ("\\*/" "/\\*" bold-italic)
242 ("_\\*/" "/\\*_" underline-bold-italic))))
243 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
244 2 3 gnus-emphasis-underline)
248 (format format (car spec) (car (cdr spec)))
249 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
251 "*Alist that says how to fontify certain phrases.
252 Each item looks like this:
254 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
256 The first element is a regular expression to be matched. The second
257 is a number that says what regular expression grouping used to find
258 the entire emphasized word. The third is a number that says what
259 regexp grouping should be displayed and highlighted. The fourth
260 is the face used for highlighting."
261 :type '(repeat (list :value ("" 0 0 default)
263 (integer :tag "Match group")
264 (integer :tag "Emphasize group")
266 :group 'gnus-article-emphasis)
268 (defface gnus-emphasis-bold '((t (:bold t)))
269 "Face used for displaying strong emphasized text (*word*)."
270 :group 'gnus-article-emphasis)
272 (defface gnus-emphasis-italic '((t (:italic t)))
273 "Face used for displaying italic emphasized text (/word/)."
274 :group 'gnus-article-emphasis)
276 (defface gnus-emphasis-underline '((t (:underline t)))
277 "Face used for displaying underlined emphasized text (_word_)."
278 :group 'gnus-article-emphasis)
280 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
281 "Face used for displaying underlined bold emphasized text (_*word*_)."
282 :group 'gnus-article-emphasis)
284 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
285 "Face used for displaying underlined italic emphasized text (_*word*_)."
286 :group 'gnus-article-emphasis)
288 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
289 "Face used for displaying bold italic emphasized text (/*word*/)."
290 :group 'gnus-article-emphasis)
292 (defface gnus-emphasis-underline-bold-italic
293 '((t (:bold t :italic t :underline t)))
294 "Face used for displaying underlined bold italic emphasized text.
295 Esample: (_/*word*/_)."
296 :group 'gnus-article-emphasis)
298 (defface gnus-emphasis-highlight-words
299 '((t (:background "black" :foreground "yellow")))
300 "Face used for displaying highlighted words."
301 :group 'gnus-article-emphasis)
303 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
304 "Format for display of Date headers in article bodies.
305 See `format-time-string' for the possible values.
307 The variable can also be function, which should return a complete Date
308 header. The function is called with one argument, the time, which can
309 be fed to `format-time-string'."
310 :type '(choice string symbol)
311 :link '(custom-manual "(gnus)Article Date")
312 :group 'gnus-article-washing)
315 (autoload 'mail-extract-address-components "mail-extr"))
317 (defcustom gnus-save-all-headers t
318 "*If non-nil, don't remove any headers before saving."
319 :group 'gnus-article-saving
322 (defcustom gnus-prompt-before-saving 'always
323 "*This variable says how much prompting is to be done when saving articles.
324 If it is nil, no prompting will be done, and the articles will be
325 saved to the default files. If this variable is `always', each and
326 every article that is saved will be preceded by a prompt, even when
327 saving large batches of articles. If this variable is neither nil not
328 `always', there the user will be prompted once for a file name for
329 each invocation of the saving commands."
330 :group 'gnus-article-saving
331 :type '(choice (item always)
332 (item :tag "never" nil)
333 (sexp :tag "once" :format "%t\n" :value t)))
335 (defcustom gnus-saved-headers gnus-visible-headers
336 "Headers to keep if `gnus-save-all-headers' is nil.
337 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
338 If that variable is nil, however, all headers that match this regexp
339 will be kept while the rest will be deleted before saving."
340 :group 'gnus-article-saving
343 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
344 "A function to save articles in your favourite format.
345 The function must be interactively callable (in other words, it must
346 be an Emacs command).
348 Gnus provides the following functions:
350 * gnus-summary-save-in-rmail (Rmail format)
351 * gnus-summary-save-in-mail (Unix mail format)
352 * gnus-summary-save-in-folder (MH folder)
353 * gnus-summary-save-in-file (article format)
354 * gnus-summary-save-in-vm (use VM's folder format)
355 * gnus-summary-write-to-file (article format -- overwrite)."
356 :group 'gnus-article-saving
357 :type '(radio (function-item gnus-summary-save-in-rmail)
358 (function-item gnus-summary-save-in-mail)
359 (function-item gnus-summary-save-in-folder)
360 (function-item gnus-summary-save-in-file)
361 (function-item gnus-summary-save-in-vm)
362 (function-item gnus-summary-write-to-file)))
364 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
365 "A function generating a file name to save articles in Rmail format.
366 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
367 :group 'gnus-article-saving
370 (defcustom gnus-mail-save-name 'gnus-plain-save-name
371 "A function generating a file name to save articles in Unix mail format.
372 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
373 :group 'gnus-article-saving
376 (defcustom gnus-folder-save-name 'gnus-folder-save-name
377 "A function generating a file name to save articles in MH folder.
378 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
379 :group 'gnus-article-saving
382 (defcustom gnus-file-save-name 'gnus-numeric-save-name
383 "A function generating a file name to save articles in article format.
384 The function is called with NEWSGROUP, HEADERS, and optional
386 :group 'gnus-article-saving
389 (defcustom gnus-split-methods
390 '((gnus-article-archive-name)
391 (gnus-article-nndoc-name))
392 "*Variable used to suggest where articles are to be saved.
393 For instance, if you would like to save articles related to Gnus in
394 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
395 you could set this variable to something like:
397 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
398 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
400 This variable is an alist where the where the key is the match and the
401 value is a list of possible files to save in if the match is non-nil.
403 If the match is a string, it is used as a regexp match on the
404 article. If the match is a symbol, that symbol will be funcalled
405 from the buffer of the article to be saved with the newsgroup as the
406 parameter. If it is a list, it will be evaled in the same buffer.
408 If this form or function returns a string, this string will be used as
409 a possible file name; and if it returns a non-nil list, that list will
410 be used as possible file names."
411 :group 'gnus-article-saving
412 :type '(repeat (choice (list :value (fun) function)
413 (cons :value ("" "") regexp (repeat string))
416 (defcustom gnus-article-display-method-for-mime
417 'gnus-article-display-mime-message
418 "Function to display a MIME message.
419 The function is called from the article buffer."
420 :group 'gnus-article-mime
423 (defcustom gnus-article-display-method-for-traditional
424 'gnus-article-display-traditional-message
425 "*Function to display a traditional message.
426 The function is called from the article buffer."
427 :group 'gnus-article-mime
430 (defcustom gnus-page-delimiter "^\^L"
431 "*Regexp describing what to use as article page delimiters.
432 The default value is \"^\^L\", which is a form linefeed at the
433 beginning of a line."
435 :group 'gnus-article-various)
437 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
438 "*The format specification for the article mode line.
439 See `gnus-summary-mode-line-format' for a closer description.
441 The following additional specs are available:
443 %w The article washing status.
444 %m The number of MIME parts in the article."
446 :group 'gnus-article-various)
448 (defcustom gnus-article-mode-hook nil
449 "*A hook for Gnus article mode."
451 :group 'gnus-article-various)
453 (defcustom gnus-article-menu-hook nil
454 "*Hook run after the creation of the article mode menu."
456 :group 'gnus-article-various)
458 (defcustom gnus-article-prepare-hook nil
459 "*A hook called after an article has been prepared in the article buffer."
461 :group 'gnus-article-various)
463 (defcustom gnus-article-hide-pgp-hook nil
464 "*A hook called after successfully hiding a PGP signature."
466 :group 'gnus-article-various)
468 (defcustom gnus-article-button-face 'bold
469 "Face used for highlighting buttons in the article buffer.
471 An article button is a piece of text that you can activate by pressing
472 `RET' or `mouse-2' above it."
474 :group 'gnus-article-buttons)
476 (defcustom gnus-article-mouse-face 'highlight
477 "Face used for mouse highlighting in the article buffer.
479 Article buttons will be displayed in this face when the cursor is
482 :group 'gnus-article-buttons)
484 (defcustom gnus-signature-face 'gnus-signature-face
485 "Face used for highlighting a signature in the article buffer.
486 Obsolete; use the face `gnus-signature-face' for customizations instead."
488 :group 'gnus-article-highlight
489 :group 'gnus-article-signature)
491 (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
648 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
649 "Function called with a MIME handle as the argument.
650 This is meant for people who want to view first matched part.
651 For `undisplayed-alternative' (default), the first undisplayed
652 part or alternative part is used. For `undisplayed', the first
653 undisplayed part is used. For a function, the first part which
654 the function return `t' is used. For `nil', the first part is
656 :group 'gnus-article-mime
658 (item :tag "first" :value nil)
659 (item :tag "undisplayed" :value undisplayed)
660 (item :tag "undisplayed or alternative"
661 :value undisplayed-alternative)
665 ;;; The treatment variables
668 (defvar gnus-part-display-hook nil
669 "Hook called on parts that are to receive treatment.")
671 (defvar gnus-article-treat-custom
672 '(choice (const :tag "Off" nil)
674 (const :tag "Header" head)
675 (const :tag "Last" last)
676 (const :tag "Mime" mime)
677 (integer :tag "Less")
678 (repeat :tag "Groups" regexp)
679 (sexp :tag "Predicate")))
681 (defvar gnus-article-treat-head-custom
682 '(choice (const :tag "Off" nil)
683 (const :tag "Header" head)))
685 (defvar gnus-article-treat-types '("text/plain")
688 (defvar gnus-inhibit-treatment nil
689 "Whether to inhibit treatment.")
691 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
692 "Highlight the signature.
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-custom)
697 (put 'gnus-treat-highlight-signature 'highlight t)
699 (defcustom gnus-treat-buttonize t
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-buttonize 'highlight t)
707 (defcustom gnus-treat-buttonize-head 'head
708 "Add buttons to the head.
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-head-custom)
713 (put 'gnus-treat-buttonize-head 'highlight t)
715 (defcustom gnus-treat-emphasize nil
717 Valid values are nil, t, `head', `last', an integer or a predicate.
718 See the manual for details."
719 :group 'gnus-article-treat
720 :type gnus-article-treat-custom)
721 (put 'gnus-treat-emphasize 'highlight t)
723 (defcustom gnus-treat-strip-cr nil
724 "Remove carriage returns.
725 Valid values are nil, t, `head', `last', an integer or a predicate.
726 See the manual for details."
727 :group 'gnus-article-treat
728 :type gnus-article-treat-custom)
730 (defcustom gnus-treat-hide-headers 'head
732 Valid values are nil, t, `head', `last', an integer or a predicate.
733 See the manual for details."
734 :group 'gnus-article-treat
735 :type gnus-article-treat-head-custom)
737 (defcustom gnus-treat-hide-boring-headers nil
738 "Hide boring headers.
739 Valid values are nil, t, `head', `last', an integer or a predicate.
740 See the manual for details."
741 :group 'gnus-article-treat
742 :type gnus-article-treat-head-custom)
744 (defcustom gnus-treat-hide-signature nil
746 Valid values are nil, t, `head', `last', an integer or a predicate.
747 See the manual for details."
748 :group 'gnus-article-treat
749 :type gnus-article-treat-custom)
751 (defcustom gnus-treat-fill-article nil
753 Valid values are nil, t, `head', `last', an integer or a predicate.
754 See the manual for details."
755 :group 'gnus-article-treat
756 :type gnus-article-treat-custom)
758 (defcustom gnus-treat-hide-citation nil
760 Valid values are nil, t, `head', `last', an integer or a predicate.
761 See the manual for details."
762 :group 'gnus-article-treat
763 :type gnus-article-treat-custom)
765 (defcustom gnus-treat-strip-list-identifiers 'head
766 "Strip list identifiers from `gnus-list-identifiers`.
767 Valid values are nil, t, `head', `last', an integer or a predicate.
768 See the manual for details."
769 :group 'gnus-article-treat
770 :type gnus-article-treat-custom)
772 (defcustom gnus-treat-strip-pgp t
773 "Strip PGP signatures.
774 Valid values are nil, t, `head', `last', an integer or a predicate.
775 See the manual for details."
776 :group 'gnus-article-treat
777 :type gnus-article-treat-custom)
779 (defcustom gnus-treat-strip-pem nil
780 "Strip PEM signatures.
781 Valid values are nil, t, `head', `last', an integer or a predicate.
782 See the manual for details."
783 :group 'gnus-article-treat
784 :type gnus-article-treat-custom)
786 (defcustom gnus-treat-strip-banner t
787 "Strip banners from articles.
788 The banner to be stripped is specified in the `banner' group parameter.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
794 (defcustom gnus-treat-highlight-headers 'head
795 "Highlight the headers.
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)
800 (put 'gnus-treat-highlight-headers 'highlight t)
802 (defcustom gnus-treat-highlight-citation t
803 "Highlight cited text.
804 Valid values are nil, t, `head', `last', an integer or a predicate.
805 See the manual for details."
806 :group 'gnus-article-treat
807 :type gnus-article-treat-custom)
808 (put 'gnus-treat-highlight-citation 'highlight t)
810 (defcustom gnus-treat-date-ut nil
811 "Display the Date in UT (GMT).
812 Valid values are nil, t, `head', `last', an integer or a predicate.
813 See the manual for details."
814 :group 'gnus-article-treat
815 :type gnus-article-treat-head-custom)
817 (defcustom gnus-treat-date-local nil
818 "Display the Date in the local timezone.
819 Valid values are nil, t, `head', `last', an integer or a predicate.
820 See the manual for details."
821 :group 'gnus-article-treat
822 :type gnus-article-treat-head-custom)
824 (defcustom gnus-treat-date-lapsed nil
825 "Display the Date header in a way that says how much time has elapsed.
826 Valid values are nil, t, `head', `last', an integer or a predicate.
827 See the manual for details."
828 :group 'gnus-article-treat
829 :type gnus-article-treat-head-custom)
831 (defcustom gnus-treat-date-original nil
832 "Display the date in the original timezone.
833 Valid values are nil, t, `head', `last', an integer or a predicate.
834 See the manual for details."
835 :group 'gnus-article-treat
836 :type gnus-article-treat-head-custom)
838 (defcustom gnus-treat-date-iso8601 nil
839 "Display the date in the ISO8601 format.
840 Valid values are nil, t, `head', `last', an integer or a predicate.
841 See the manual for details."
842 :group 'gnus-article-treat
843 :type gnus-article-treat-head-custom)
845 (defcustom gnus-treat-date-user-defined nil
846 "Display the date in a user-defined format.
847 The format is defined by the `gnus-article-time-format' variable.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See the manual for details."
850 :group 'gnus-article-treat
851 :type gnus-article-treat-head-custom)
853 (defcustom gnus-treat-strip-headers-in-body t
854 "Strip the X-No-Archive header line from the beginning of the body.
855 Valid values are nil, t, `head', `last', an integer or a predicate.
856 See the manual for details."
857 :group 'gnus-article-treat
858 :type gnus-article-treat-custom)
860 (defcustom gnus-treat-strip-trailing-blank-lines nil
861 "Strip trailing blank lines.
862 Valid values are nil, t, `head', `last', an integer or a predicate.
863 See the manual for details."
864 :group 'gnus-article-treat
865 :type gnus-article-treat-custom)
867 (defcustom gnus-treat-strip-leading-blank-lines nil
868 "Strip leading blank lines.
869 Valid values are nil, t, `head', `last', an integer or a predicate.
870 See the manual for details."
871 :group 'gnus-article-treat
872 :type gnus-article-treat-custom)
874 (defcustom gnus-treat-strip-multiple-blank-lines nil
875 "Strip multiple blank lines.
876 Valid values are nil, t, `head', `last', an integer or a predicate.
877 See the manual for details."
878 :group 'gnus-article-treat
879 :type gnus-article-treat-custom)
881 (defcustom gnus-treat-overstrike t
882 "Treat overstrike highlighting.
883 Valid values are nil, t, `head', `last', an integer or a predicate.
884 See the manual for details."
885 :group 'gnus-article-treat
886 :type gnus-article-treat-custom)
887 (put 'gnus-treat-overstrike 'highlight t)
889 (defcustom gnus-treat-display-xface
890 (if (or (and gnus-xemacs (featurep 'xface))
891 (eq 'x-face-mule-gnus-article-display-x-face
892 gnus-article-x-face-command))
895 "Display X-Face headers.
896 Valid values are nil, t, `head', `last', an integer or a predicate.
897 See the manual for details."
898 :group 'gnus-article-treat
899 :type gnus-article-treat-head-custom)
900 (put 'gnus-treat-display-xface 'highlight t)
902 (defcustom gnus-treat-display-smileys
903 (if (or (and gnus-xemacs (featurep 'xpm))
904 (and (not gnus-xemacs)
906 (module-installed-p 'smiley-mule)))
910 Valid values are nil, t, `head', `last', an integer or a predicate.
911 See the manual for details."
912 :group 'gnus-article-treat
913 :type gnus-article-treat-custom)
914 (put 'gnus-treat-display-smileys 'highlight t)
916 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-head-custom)
922 (put 'gnus-treat-display-picons 'highlight t)
924 (defcustom gnus-treat-capitalize-sentences nil
925 "Capitalize sentence-starting words.
926 Valid values are nil, t, `head', `last', an integer or a predicate.
927 See the manual for details."
928 :group 'gnus-article-treat
929 :type gnus-article-treat-custom)
931 (defcustom gnus-treat-fill-long-lines nil
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
935 :group 'gnus-article-treat
936 :type gnus-article-treat-custom)
938 (defcustom gnus-treat-play-sounds nil
940 Valid values are nil, t, `head', `last', an integer or a predicate.
941 See the manual for details."
942 :group 'gnus-article-treat
943 :type gnus-article-treat-custom)
945 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
946 "Decode an article as `default-mime-charset'. For instance, if you want to
947 attempt to decode an article even if the value of `gnus-show-mime' is nil,
948 you could set this variable to something like: nil for don't decode, t for
949 decode the body, '(or header t) for the whole article, etc."
950 :group 'gnus-article-treat
951 :type '(radio (const :tag "Off" nil)
952 (const :tag "Decode body" t)
953 (const :tag "Decode all" (or head t))))
955 (defcustom gnus-treat-translate nil
956 "Translate articles from one language to another.
957 Valid values are nil, t, `head', `last', an integer or a predicate.
958 See the manual for details."
959 :group 'gnus-article-treat
960 :type gnus-article-treat-custom)
962 ;;; Internal variables
964 (defvar article-goto-body-goes-to-point-min-p nil)
965 (defvar gnus-article-wash-types nil)
966 (defvar gnus-article-emphasis-alist nil)
968 (defvar gnus-article-mime-handle-alist-1 nil)
969 (defvar gnus-treatment-function-alist
970 '((gnus-treat-decode-article-as-default-mime-charset
971 gnus-article-decode-article-as-default-mime-charset)
972 (gnus-treat-strip-banner gnus-article-strip-banner)
973 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
974 (gnus-treat-buttonize gnus-article-add-buttons)
975 (gnus-treat-fill-article gnus-article-fill-cited-article)
976 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
977 (gnus-treat-strip-cr gnus-article-remove-cr)
978 (gnus-treat-display-xface gnus-article-display-x-face)
979 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
980 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
981 (gnus-treat-hide-signature gnus-article-hide-signature)
982 (gnus-treat-hide-citation gnus-article-hide-citation)
983 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
984 (gnus-treat-strip-pgp gnus-article-hide-pgp)
985 (gnus-treat-strip-pem gnus-article-hide-pem)
986 (gnus-treat-highlight-headers gnus-article-highlight-headers)
987 (gnus-treat-emphasize gnus-article-emphasize)
988 (gnus-treat-highlight-citation gnus-article-highlight-citation)
989 (gnus-treat-highlight-signature gnus-article-highlight-signature)
990 (gnus-treat-date-ut gnus-article-date-ut)
991 (gnus-treat-date-local gnus-article-date-local)
992 (gnus-treat-date-lapsed gnus-article-date-lapsed)
993 (gnus-treat-date-original gnus-article-date-original)
994 (gnus-treat-date-user-defined gnus-article-date-user)
995 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
996 (gnus-treat-strip-trailing-blank-lines
997 gnus-article-remove-trailing-blank-lines)
998 (gnus-treat-strip-leading-blank-lines
999 gnus-article-strip-leading-blank-lines)
1000 (gnus-treat-strip-multiple-blank-lines
1001 gnus-article-strip-multiple-blank-lines)
1002 (gnus-treat-overstrike gnus-article-treat-overstrike)
1003 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1004 (gnus-treat-display-smileys gnus-smiley-display)
1005 (gnus-treat-display-picons gnus-article-display-picons)
1006 (gnus-treat-play-sounds gnus-earcon-display)))
1008 (defvar gnus-article-mime-handle-alist nil)
1009 (defvar article-lapsed-timer nil)
1010 (defvar gnus-article-current-summary nil)
1012 (defvar gnus-article-mode-syntax-table
1013 (let ((table (copy-syntax-table text-mode-syntax-table)))
1014 (modify-syntax-entry ?- "w" table)
1015 (modify-syntax-entry ?> ")" table)
1016 (modify-syntax-entry ?< "(" table)
1018 "Syntax table used in article mode buffers.
1019 Initialized from `text-mode-syntax-table.")
1021 (defvar gnus-save-article-buffer nil)
1023 (defvar gnus-article-mode-line-format-alist
1024 (nconc '((?w (gnus-article-wash-status) ?s)
1025 (?m (gnus-article-mime-part-status) ?s))
1026 gnus-summary-mode-line-format-alist))
1028 (defvar gnus-number-of-articles-to-be-saved nil)
1030 (defvar gnus-inhibit-hiding nil)
1032 (defsubst gnus-article-hide-text (b e props)
1033 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1034 (add-text-properties b e props)
1035 (when (memq 'intangible props)
1037 (max (1- b) (point-min))
1038 b 'intangible (cddr (memq 'intangible props)))))
1039 (defsubst gnus-article-unhide-text (b e)
1040 "Remove hidden text properties from region between B and E."
1041 (remove-text-properties b e gnus-hidden-properties)
1042 (when (memq 'intangible gnus-hidden-properties)
1043 (put-text-property (max (1- b) (point-min))
1044 b 'intangible nil)))
1046 (defun gnus-article-hide-text-type (b e type)
1047 "Hide text of TYPE between B and E."
1048 (push type gnus-article-wash-types)
1049 (gnus-article-hide-text
1050 b e (cons 'article-type (cons type gnus-hidden-properties))))
1052 (defun gnus-article-unhide-text-type (b e type)
1053 "Unhide text of TYPE between B and E."
1054 (setq gnus-article-wash-types
1055 (delq type gnus-article-wash-types))
1056 (remove-text-properties
1057 b e (cons 'article-type (cons type gnus-hidden-properties)))
1058 (when (memq 'intangible gnus-hidden-properties)
1059 (put-text-property (max (1- b) (point-min))
1060 b 'intangible nil)))
1062 (defun gnus-article-hide-text-of-type (type)
1063 "Hide text of TYPE in the current buffer."
1065 (let ((b (point-min))
1067 (while (setq b (text-property-any b e 'article-type type))
1068 (add-text-properties b (incf b) gnus-hidden-properties)))))
1070 (defun gnus-article-delete-text-of-type (type)
1071 "Delete text of TYPE in the current buffer."
1073 (let ((b (point-min)))
1074 (while (setq b (text-property-any b (point-max) 'article-type type))
1076 b (or (text-property-not-all b (point-max) 'article-type type)
1079 (defun gnus-article-delete-invisible-text ()
1080 "Delete all invisible text in the current buffer."
1082 (let ((b (point-min)))
1083 (while (setq b (text-property-any b (point-max) 'invisible t))
1085 b (or (text-property-not-all b (point-max) 'invisible t)
1088 (defun gnus-article-text-type-exists-p (type)
1089 "Say whether any text of type TYPE exists in the buffer."
1090 (text-property-any (point-min) (point-max) 'article-type type))
1092 (defsubst gnus-article-header-rank ()
1093 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1094 (let ((list gnus-sorted-header-list)
1097 (when (looking-at (car list))
1099 (setq list (cdr list))
1103 (defun article-hide-headers (&optional arg delete)
1104 "Hide unwanted headers and possibly sort them as well."
1105 (interactive (gnus-article-hidden-arg))
1106 ;; Lars said that this function might be inhibited.
1107 (if (gnus-article-check-hidden-text 'headers arg)
1109 ;; Show boring headers as well.
1110 (gnus-article-show-hidden-text 'boring-headers)
1111 (when (eq 1 (point-min))
1112 (set-window-start (get-buffer-window (current-buffer)) 1)))
1113 (unless gnus-inhibit-hiding
1116 (let ((buffer-read-only nil)
1117 (inhibit-read-only t)
1118 (case-fold-search t)
1119 (max (1+ (length gnus-sorted-header-list)))
1120 (ignored (when (not gnus-visible-headers)
1121 (cond ((stringp gnus-ignored-headers)
1122 gnus-ignored-headers)
1123 ((listp gnus-ignored-headers)
1124 (mapconcat 'identity gnus-ignored-headers
1127 (cond ((stringp gnus-visible-headers)
1128 gnus-visible-headers)
1129 ((and gnus-visible-headers
1130 (listp gnus-visible-headers))
1131 (mapconcat 'identity gnus-visible-headers "\\|"))))
1132 (inhibit-point-motion-hooks t)
1134 ;; First we narrow to just the headers.
1135 (article-narrow-to-head)
1136 ;; Hide any "From " lines at the beginning of (mail) articles.
1137 (while (looking-at "From ")
1141 (delete-region (point-min) (point))
1142 (gnus-article-hide-text (point-min) (point)
1143 (nconc (list 'article-type 'headers)
1144 gnus-hidden-properties))))
1145 ;; Then treat the rest of the header lines.
1146 ;; Then we use the two regular expressions
1147 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1148 ;; select which header lines is to remain visible in the
1150 (while (re-search-forward "^[^ \t]*:" nil t)
1152 ;; Mark the rank of the header.
1154 (point) (1+ (point)) 'message-rank
1155 (if (or (and visible (looking-at visible))
1157 (not (looking-at ignored))))
1158 (gnus-article-header-rank)
1161 (message-sort-headers-1)
1162 (when (setq beg (text-property-any
1163 (point-min) (point-max) 'message-rank (+ 2 max)))
1164 ;; We delete or make invisible the unwanted headers.
1165 (push 'headers gnus-article-wash-types)
1168 (add-text-properties
1169 (point-min) (+ 5 (point-min))
1170 '(article-type headers dummy-invisible t))
1171 (delete-region beg (point-max)))
1172 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1175 (defun article-hide-boring-headers (&optional arg)
1176 "Toggle hiding of headers that aren't very interesting.
1177 If given a negative prefix, always show; if given a positive prefix,
1179 (interactive (gnus-article-hidden-arg))
1180 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1181 (not gnus-show-all-headers))
1184 (let ((buffer-read-only nil)
1185 (list gnus-boring-article-headers)
1186 (inhibit-point-motion-hooks t)
1188 (article-narrow-to-head)
1190 (setq elem (pop list))
1191 (goto-char (point-min))
1193 ;; Hide empty headers.
1195 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1197 (gnus-article-hide-text-type
1198 (progn (beginning-of-line) (point))
1201 (if (re-search-forward "^[^ \t]" nil t)
1205 ;; Hide boring Newsgroups header.
1206 ((eq elem 'newsgroups)
1207 (when (equal (gnus-fetch-field "newsgroups")
1208 (gnus-group-real-name
1209 (if (boundp 'gnus-newsgroup-name)
1212 (gnus-article-hide-header "newsgroups")))
1213 ((eq elem 'followup-to)
1214 (when (equal (message-fetch-field "followup-to")
1215 (message-fetch-field "newsgroups"))
1216 (gnus-article-hide-header "followup-to")))
1217 ((eq elem 'reply-to)
1218 (let ((from (message-fetch-field "from"))
1219 (reply-to (message-fetch-field "reply-to")))
1224 (nth 1 (funcall gnus-extract-address-components from))
1225 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1226 (gnus-article-hide-header "reply-to"))))
1228 (let ((date (message-fetch-field "date")))
1230 (< (days-between (current-time-string) date)
1232 (gnus-article-hide-header "date"))))
1234 (let ((to (message-fetch-field "to")))
1235 (when (> (length to) 1024)
1236 (gnus-article-hide-header "to"))))
1239 (goto-char (point-min))
1240 (while (re-search-forward "^to:" nil t)
1241 (setq to-count (1+ to-count)))
1242 (when (> to-count 1)
1243 (while (> to-count 0)
1244 (goto-char (point-min))
1246 (re-search-forward "^to:" nil nil to-count)
1248 (narrow-to-region (point) (point-max))
1249 (gnus-article-hide-header "to"))
1250 (setq to-count (1- to-count)))))))))))))
1252 (defun gnus-article-hide-header (header)
1254 (goto-char (point-min))
1255 (when (re-search-forward (concat "^" header ":") nil t)
1256 (gnus-article-hide-text-type
1257 (progn (beginning-of-line) (point))
1260 (if (re-search-forward "^[^ \t]" nil t)
1265 (defun article-toggle-headers (&optional arg)
1266 "Toggle hiding of headers. If given a negative prefix, always show;
1267 if given a positive prefix, always hide."
1268 (interactive (gnus-article-hidden-arg))
1269 (let ((force (when (numberp arg)
1270 (cond ((> arg 0) 'always-hide)
1271 ((< arg 0) 'always-show))))
1272 (window (get-buffer-window gnus-article-buffer))
1273 (header-end (point-min))
1274 header-start field-end field-start
1275 (inhibit-point-motion-hooks t)
1276 (inhibit-read-only t)
1280 (while (and (setq header-start
1281 (text-property-any header-end (point-max)
1282 'article-treated-header t))
1284 (text-property-not-all header-start (point-max)
1285 'article-treated-header t)))
1286 (setq field-end header-start)
1288 (;; Hide exposed invisible fields.
1289 (and (not (eq 'always-show force))
1291 (text-property-any field-end header-end
1292 'exposed-invisible-field t)))
1293 (while (and field-start
1294 (setq field-end (text-property-not-all
1295 field-start header-end
1296 'exposed-invisible-field t)))
1297 (add-text-properties field-start field-end gnus-hidden-properties)
1298 (setq field-start (text-property-any field-end header-end
1299 'exposed-invisible-field t)))
1300 (put-text-property header-start header-end
1301 'exposed-invisible-field nil))
1302 (;; Expose invisible fields.
1303 (and (not (eq 'always-hide force))
1305 (text-property-any field-end header-end 'invisible t)))
1306 (while (and field-start
1307 (setq field-end (text-property-not-all
1308 field-start header-end
1310 ;; If the invisible text is not terminated with newline, we
1311 ;; won't expose it. Because it may be created by x-face-mule.
1312 ;; BTW, XEmacs sometimes fail in putting a invisible text
1313 ;; property with `gnus-article-hide-text' (really?). In that
1314 ;; case, the invisible text might be started from the middle of
1315 ;; a line so we will expose the sort of thing.
1316 (when (or (not (or (eq header-start field-start)
1317 (eq ?\n (char-before field-start))))
1318 (eq ?\n (char-before field-end)))
1319 (remove-text-properties field-start field-end
1320 gnus-hidden-properties)
1321 (put-text-property field-start field-end
1322 'exposed-invisible-field t))
1323 (setq field-start (text-property-any field-end header-end
1326 (not (eq 'always-show force))
1327 (narrow-to-region header-start header-end)
1328 (article-hide-headers)
1329 ;; Re-display X-Face image under XEmacs.
1330 (when (and gnus-xemacs
1331 (gnus-functionp gnus-article-x-face-command))
1332 (let ((func (cadr (assq 'gnus-treat-display-xface
1333 gnus-treatment-function-alist)))
1335 (when (and (not gnus-inhibit-treatment)
1337 (gnus-treat-predicate gnus-treat-display-xface))
1339 (put-text-property header-start header-end 'read-only nil))))
1342 (goto-char (point-min))
1344 (set-window-start window (point-min))))))
1346 (defvar gnus-article-normalized-header-length 40
1347 "Length of normalized headers.")
1349 (defun article-normalize-headers ()
1350 "Make all header lines 40 characters long."
1352 (let ((buffer-read-only nil)
1356 (article-narrow-to-head)
1359 ((< (setq column (- (gnus-point-at-eol) (point)))
1360 gnus-article-normalized-header-length)
1362 (insert (make-string
1363 (- gnus-article-normalized-header-length column)
1365 ((> column gnus-article-normalized-header-length)
1366 (gnus-put-text-property
1368 (forward-char gnus-article-normalized-header-length)
1375 (forward-line 1))))))
1377 (defun article-treat-dumbquotes ()
1378 "Translate M******** sm*rtq**t*s into proper text.
1379 Note that this function guesses whether a character is a sm*rtq**t* or
1380 not, so it should only be used interactively."
1382 (article-translate-strings gnus-article-dumbquotes-map))
1384 (defun article-translate-characters (from to)
1385 "Translate all characters in the body of the article according to FROM and TO.
1386 FROM is a string of characters to translate from; to is a string of
1387 characters to translate to."
1389 (when (article-goto-body)
1390 (let ((buffer-read-only nil)
1391 (x (make-string 225 ?x))
1393 (while (< (incf i) (length x))
1396 (while (< i (length from))
1397 (aset x (aref from i) (aref to i))
1399 (translate-region (point) (point-max) x)))))
1401 (defun article-translate-strings (map)
1402 "Translate all string in the body of the article according to MAP.
1403 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1405 (when (article-goto-body)
1406 (let ((buffer-read-only nil)
1408 (while (setq elem (pop map))
1410 (while (search-forward (car elem) nil t)
1411 (replace-match (cadr elem)))))))))
1413 (defun article-treat-overstrike ()
1414 "Translate overstrikes into bold text."
1417 (when (article-goto-body)
1418 (let ((buffer-read-only nil))
1419 (while (search-forward "\b" nil t)
1420 (let ((next (char-after))
1424 previous (char-after))
1428 ;; We do the boldification/underlining by hiding the
1429 ;; overstrikes and putting the proper text property
1433 (gnus-article-hide-text-type start (point) 'overstrike)
1434 (put-text-property (point) end 'face 'bold))
1436 (gnus-article-hide-text-type
1437 (1- (point)) (1+ (point)) 'overstrike)
1439 start (1- (point)) 'face 'underline))
1441 (gnus-article-hide-text-type start (point) 'overstrike)
1443 (point) end 'face 'underline)))))))))
1445 (defun article-fill-long-lines ()
1446 "Fill lines that are wider than the window width."
1449 (let ((buffer-read-only nil)
1450 (width (window-width (get-buffer-window (current-buffer)))))
1453 (let ((adaptive-fill-mode nil))
1456 (when (>= (current-column) (min fill-column width))
1457 (narrow-to-region (point) (gnus-point-at-bol))
1458 (fill-paragraph nil)
1459 (goto-char (point-max))
1461 (forward-line 1)))))))
1463 (defun article-capitalize-sentences ()
1464 "Capitalize the first word in each sentence."
1467 (let ((buffer-read-only nil)
1468 (paragraph-start "^[\n\^L]"))
1472 (forward-sentence)))))
1474 (defun article-remove-cr ()
1475 "Remove trailing CRs and then translate remaining CRs into LFs."
1478 (let ((buffer-read-only nil))
1479 (goto-char (point-min))
1480 (while (re-search-forward "\r+$" nil t)
1481 (replace-match "" t t))
1482 (goto-char (point-min))
1483 (while (search-forward "\r" nil t)
1484 (replace-match "\n" t t)))))
1486 (defun article-remove-trailing-blank-lines ()
1487 "Remove all trailing blank lines from the article."
1490 (let ((buffer-read-only nil))
1491 (goto-char (point-max))
1495 (while (and (not (bobp))
1496 (looking-at "^[ \t]*$")
1497 (not (gnus-annotation-in-region-p
1498 (point) (gnus-point-at-eol))))
1503 (defun article-display-x-face (&optional force)
1504 "Look for an X-Face header and display it if present."
1505 (interactive (list 'force))
1507 ;; Delete the old process, if any.
1508 (when (process-status "article-x-face")
1509 (delete-process "article-x-face"))
1510 (let ((inhibit-point-motion-hooks t)
1511 (case-fold-search t)
1514 (article-narrow-to-head)
1515 (goto-char (point-min))
1516 (setq from (message-fetch-field "from"))
1517 (goto-char (point-min))
1518 (while (and gnus-article-x-face-command
1521 ;; Check whether this face is censored.
1522 (not gnus-article-x-face-too-ugly)
1523 (and gnus-article-x-face-too-ugly from
1524 (not (string-match gnus-article-x-face-too-ugly
1526 ;; Has to be present.
1527 (re-search-forward "^X-Face: " nil t))
1528 ;; This used to try to do multiple faces (`while' instead of
1529 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1530 ;; work (b) it can crash some versions of Emacs (c) are
1531 ;; multiple faces really something to encourage?
1532 (when (stringp gnus-article-x-face-command)
1534 ;; We now have the area of the buffer where the X-Face is stored.
1537 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1538 ;; We display the face.
1539 (if (symbolp gnus-article-x-face-command)
1540 ;; The command is a lisp function, so we call it.
1541 (if (gnus-functionp gnus-article-x-face-command)
1542 (funcall gnus-article-x-face-command beg end)
1543 (error "%s is not a function" gnus-article-x-face-command))
1544 ;; The command is a string, so we interpret the command
1545 ;; as a, well, command, and fork it off.
1546 (let ((process-connection-type nil))
1547 (process-kill-without-query
1549 "article-x-face" nil shell-file-name shell-command-switch
1550 gnus-article-x-face-command))
1551 (process-send-region "article-x-face" beg end)
1552 (process-send-eof "article-x-face"))))))))))
1554 (defun article-decode-mime-words ()
1555 "Decode all MIME-encoded words in the article."
1558 (set-buffer gnus-article-buffer)
1559 (let ((inhibit-point-motion-hooks t)
1561 (mail-parse-charset gnus-newsgroup-charset)
1562 (mail-parse-ignored-charsets
1563 (save-excursion (set-buffer gnus-summary-buffer)
1564 gnus-newsgroup-ignored-charsets)))
1565 (mail-decode-encoded-word-region (point-min) (point-max)))))
1567 (defun article-decode-charset (&optional prompt)
1568 "Decode charset-encoded text in the article.
1569 If PROMPT (the prefix), prompt for a coding system to use."
1573 (article-narrow-to-head)
1574 (let* ((inhibit-point-motion-hooks t)
1575 (case-fold-search t)
1576 (ct (message-fetch-field "Content-Type" t))
1577 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1578 (ctl (and ct (ignore-errors
1579 (mail-header-parse-content-type ct))))
1582 (mm-read-coding-system "Charset to decode: "))
1584 (mail-content-type-get ctl 'charset))))
1585 (mail-parse-charset gnus-newsgroup-charset)
1586 (mail-parse-ignored-charsets
1587 (save-excursion (condition-case nil
1588 (set-buffer gnus-summary-buffer)
1590 gnus-newsgroup-ignored-charsets))
1592 (if (and ctl (not (string-match "/" (car ctl))))
1594 (goto-char (point-max))
1597 (narrow-to-region (point) (point-max))
1598 (when (and (or (not ctl)
1599 (equal (car ctl) "text/plain"))
1602 charset (and cte (intern (downcase
1603 (gnus-strip-whitespace cte))))
1606 (defun article-decode-encoded-words ()
1607 "Remove encoded-word encoding from headers."
1608 (let (buffer-read-only)
1609 (let ((charset (save-excursion
1610 (set-buffer gnus-summary-buffer)
1611 default-mime-charset)))
1612 (mime-decode-header-in-buffer charset)
1615 (defun article-de-quoted-unreadable (&optional force)
1616 "Translate a quoted-printable-encoded article.
1617 If FORCE, decode the article whether it is marked as quoted-printable
1619 (interactive (list 'force))
1621 (let ((buffer-read-only nil)
1622 (type (gnus-fetch-field "content-transfer-encoding"))
1623 (charset gnus-newsgroup-charset))
1625 (and type (string-match "quoted-printable" (downcase type))))
1628 (narrow-to-region (point) (point-max))
1629 (quoted-printable-decode-region (point-min) (point-max))
1631 (mm-decode-body charset)))))))
1633 (defun article-hide-list-identifiers ()
1634 "Remove any list identifiers in `gnus-list-identifiers' from Subject
1635 header in the current article."
1639 (let ((inhibit-point-motion-hooks t)
1641 (article-narrow-to-head)
1642 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1643 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1645 (goto-char (point-min))
1646 (when (re-search-forward
1647 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1649 (delete-region (match-beginning 2) (match-end 0)))))))))
1651 (defun article-hide-pgp ()
1652 "Remove any PGP headers and signatures in the current article."
1656 (let ((inhibit-point-motion-hooks t)
1657 buffer-read-only beg end)
1659 ;; Hide the "header".
1660 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1661 (push 'pgp gnus-article-wash-types)
1662 (delete-region (match-beginning 0) (match-end 0))
1663 ;; Remove armor headers (rfc2440 6.2)
1664 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1667 ;; Hide the actual signature.
1668 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1669 (setq end (1+ (match-beginning 0)))
1672 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1674 ;; Perhaps we shouldn't hide to the end of the buffer
1675 ;; if there is no end to the signature?
1677 ;; Hide "- " PGP quotation markers.
1679 (narrow-to-region beg end)
1680 (goto-char (point-min))
1681 (while (re-search-forward "^- " nil t)
1683 (match-beginning 0) (match-end 0)))
1685 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1687 (defun article-hide-pem (&optional arg)
1688 "Toggle hiding of any PEM headers and signatures in the current article.
1689 If given a negative prefix, always show; if given a positive prefix,
1691 (interactive (gnus-article-hidden-arg))
1692 (unless (gnus-article-check-hidden-text 'pem arg)
1694 (let (buffer-read-only end)
1695 (goto-char (point-min))
1696 ;; Hide the horrendously ugly "header".
1697 (when (and (search-forward
1698 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1700 (setq end (1+ (match-beginning 0))))
1701 (push 'pem gnus-article-wash-types)
1702 (gnus-article-hide-text-type
1704 (if (search-forward "\n\n" nil t)
1708 ;; Hide the trailer as well
1709 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1711 (gnus-article-hide-text-type
1712 (match-beginning 0) (match-end 0) 'pem)))))))
1714 (defun article-strip-banner ()
1715 "Strip the banner specified by the `banner' group parameter."
1719 (let ((inhibit-point-motion-hooks t)
1720 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1721 (gnus-signature-limit nil)
1722 buffer-read-only beg end)
1726 ((eq banner 'signature)
1727 (when (gnus-article-narrow-to-signature)
1730 (delete-region (point) (point-max))))
1732 (while (re-search-forward banner nil t)
1733 (delete-region (match-beginning 0) (match-end 0))))))))))
1735 (defun article-babel ()
1736 "Translate article using an online translation service."
1740 (set-buffer gnus-article-buffer)
1741 (when (article-goto-body)
1742 (let* ((buffer-read-only nil)
1745 (orig (buffer-substring start end))
1746 (trans (babel-as-string orig)))
1748 (narrow-to-region start end)
1749 (delete-region start end)
1752 (defun article-hide-signature (&optional arg)
1753 "Hide the signature in the current article.
1754 If given a negative prefix, always show; if given a positive prefix,
1756 (interactive (gnus-article-hidden-arg))
1762 (article-goto-body))
1763 (goto-char (point-min)))
1764 (unless (gnus-article-check-hidden-text 'signature arg)
1765 (let ((buffer-read-only nil)
1767 (while (setq button (text-property-any button (point-max)
1769 'gnus-signature-toggle))
1770 (setq button (text-property-not-all button (point-max)
1772 'gnus-signature-toggle))
1773 (when (and button (not (eobp)))
1774 (gnus-article-hide-text-type
1776 (next-single-property-change (1+ button) 'mime-view-entity
1780 (defun article-strip-headers-in-body ()
1781 "Strip offensive headers from bodies."
1785 (let ((case-fold-search t))
1786 (when (looking-at "x-no-archive:")
1787 (gnus-delete-line)))))
1789 (defun article-strip-leading-blank-lines ()
1790 "Remove all blank lines from the beginning of the article."
1793 (let ((inhibit-point-motion-hooks t)
1795 (when (article-goto-body)
1796 (while (and (not (eobp))
1797 (looking-at "[ \t]*$"))
1798 (gnus-delete-line))))))
1800 (defun article-narrow-to-head ()
1801 "Narrow the buffer to the head of the message.
1802 Point is left at the beginning of the narrowed-to region."
1804 (goto-char (point-min))
1805 (if (search-forward "\n\n" nil 1)
1808 (goto-char (point-min)))
1810 (defun article-goto-body ()
1811 "Place point at the start of the body."
1812 (goto-char (point-min))
1814 ;; This variable is only bound when dealing with separate
1816 (article-goto-body-goes-to-point-min-p
1818 ((search-forward "\n\n" nil t)
1821 (goto-char (point-max))
1824 (defun article-strip-multiple-blank-lines ()
1825 "Replace consecutive blank lines with one empty line."
1828 (let ((inhibit-point-motion-hooks t)
1830 ;; First make all blank lines empty.
1832 (while (re-search-forward "^[ \t]+$" nil t)
1833 (unless (gnus-annotation-in-region-p
1834 (match-beginning 0) (match-end 0))
1835 (replace-match "" nil t)))
1836 ;; Then replace multiple empty lines with a single empty line.
1838 (while (re-search-forward "\n\n\n+" nil t)
1839 (unless (gnus-annotation-in-region-p
1840 (match-beginning 0) (match-end 0))
1841 (replace-match "\n\n" t t))))))
1843 (defun article-strip-leading-space ()
1844 "Remove all white space from the beginning of the lines in the article."
1847 (let ((inhibit-point-motion-hooks t)
1850 (while (re-search-forward "^[ \t]+" nil t)
1851 (replace-match "" t t)))))
1853 (defun article-strip-trailing-space ()
1854 "Remove all white space from the end of the lines in the article."
1857 (let ((inhibit-point-motion-hooks t)
1860 (while (re-search-forward "[ \t]+$" nil t)
1861 (replace-match "" t t)))))
1863 (defun article-strip-blank-lines ()
1864 "Strip leading, trailing and multiple blank lines."
1866 (article-strip-leading-blank-lines)
1867 (article-remove-trailing-blank-lines)
1868 (article-strip-multiple-blank-lines))
1870 (defun article-strip-all-blank-lines ()
1871 "Strip all blank lines."
1874 (let ((inhibit-point-motion-hooks t)
1877 (while (re-search-forward "^[ \t]*\n" nil t)
1878 (replace-match "" t t)))))
1880 (defun gnus-article-narrow-to-signature ()
1881 "Narrow to the signature; return t if a signature is found, else nil."
1882 (let ((inhibit-point-motion-hooks t))
1883 (when (gnus-article-search-signature)
1885 ;; Check whether we have some limits to what we consider
1886 ;; to be a signature.
1887 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1888 (list gnus-signature-limit)))
1890 (while (setq limit (pop limits))
1891 (if (or (and (integerp limit)
1892 (< (- (point-max) (point)) limit))
1894 (< (count-lines (point) (point-max)) limit))
1895 (and (gnus-functionp limit)
1897 (and (stringp limit)
1898 (not (re-search-forward limit nil t))))
1899 () ; This limit did not succeed.
1903 (narrow-to-region (point) (point-max))
1906 (defun gnus-article-search-signature ()
1907 "Search the current buffer for the signature separator.
1908 Put point at the beginning of the signature separator."
1909 (let ((cur (point)))
1910 (goto-char (point-max))
1911 (if (if (stringp gnus-signature-separator)
1912 (re-search-backward gnus-signature-separator nil t)
1913 (let ((seps gnus-signature-separator))
1915 (not (re-search-backward (car seps) nil t)))
1922 (defun gnus-article-hidden-arg ()
1923 "Return the current prefix arg as a number, or 0 if no prefix."
1924 (list (if current-prefix-arg
1925 (prefix-numeric-value current-prefix-arg)
1928 (defun gnus-article-check-hidden-text (type arg)
1929 "Return nil if hiding is necessary.
1930 Arg can be nil or a number. Nil and positive means hide, negative
1931 means show, 0 means toggle."
1934 (let ((hide (gnus-article-hidden-text-p type)))
1940 (gnus-article-show-hidden-text type))
1942 (if (eq hide 'hidden)
1943 (gnus-article-show-hidden-text type)
1946 (defun gnus-article-hidden-text-p (type)
1947 "Say whether the current buffer contains hidden text of type TYPE."
1948 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1950 (not (get-text-property pos 'invisible))
1951 (not (get-text-property pos 'dummy-invisible)))
1953 (text-property-any (1+ pos) (point-max) 'article-type type)))
1958 (defun gnus-article-show-hidden-text (type &optional hide)
1959 "Show all hidden text of type TYPE.
1960 If HIDE, hide the text instead."
1962 (let ((buffer-read-only nil)
1963 (inhibit-point-motion-hooks t)
1966 (while (setq beg (text-property-any end (point-max) 'article-type type))
1969 (text-property-not-all beg (point-max) 'article-type type)
1972 (gnus-article-hide-text beg end gnus-hidden-properties)
1973 (gnus-article-unhide-text beg end))
1977 (defconst article-time-units
1978 `((year . ,(* 365.25 24 60 60))
1979 (week . ,(* 7 24 60 60))
1980 (day . ,(* 24 60 60))
1984 "Mapping from time units to seconds.")
1986 (defun article-date-ut (&optional type highlight header)
1987 "Convert DATE date to universal time in the current article.
1988 If TYPE is `local', convert to local time; if it is `lapsed', output
1989 how much time has lapsed since DATE. For `lapsed', the value of
1990 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1991 should replace the \"Date:\" one, or should be added below it."
1992 (interactive (list 'ut t))
1993 (let* ((header (or header
1994 (and (eq 1 (point-min))
1995 (mail-header-date (save-excursion
1996 (set-buffer gnus-summary-buffer)
1997 gnus-current-headers)))
1998 (message-fetch-field "date")
2000 (date (if (vectorp header) (mail-header-date header)
2002 (inhibit-point-motion-hooks t)
2003 bface eface date-pos)
2004 (when (and date (not (string= date "")))
2007 (article-narrow-to-head)
2008 (when (or (and (eq type 'lapsed)
2009 gnus-article-date-lapsed-new-header
2010 ;; Attempt to get the face of X-Sent first.
2011 (re-search-forward "^X-Sent:[ \t]" nil t))
2012 (re-search-forward "^Date:[ \t]" nil t)
2013 ;; If Date is missing, try again for X-Sent.
2014 (re-search-forward "^X-Sent:[ \t]" nil t))
2015 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2016 date (or (get-text-property (gnus-point-at-bol)
2019 eface (get-text-property (1- (gnus-point-at-eol))
2021 (let ((buffer-read-only nil))
2022 ;; Delete any old X-Sent headers.
2023 (when (setq date-pos
2024 (text-property-any (point-min) (point-max)
2025 'article-date-lapsed t))
2026 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2027 (delete-region (match-beginning 0)
2028 (progn (forward-line 1) (point))))
2029 (goto-char (point-min))
2030 ;; Delete any old Date headers.
2031 (while (re-search-forward "^Date:[ \t]" nil t)
2033 (setq date-pos (match-beginning 0)))
2034 (unless (and (eq type 'lapsed)
2035 gnus-article-date-lapsed-new-header)
2036 (delete-region (match-beginning 0)
2037 (progn (message-next-header) (point)))))
2040 (goto-char date-pos)
2042 ;; Possibly, Date has been deleted.
2044 (when (and (eq type 'lapsed)
2045 gnus-article-date-lapsed-new-header
2046 (looking-at "Date:"))
2048 (goto-char (point-min)))
2049 (insert (article-make-date-line date type))
2050 (when (eq type 'lapsed)
2051 (put-text-property (gnus-point-at-bol) (point)
2052 'article-date-lapsed t))
2056 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2057 (put-text-property (match-beginning 1) (1+ (match-end 1))
2058 'original-date date)
2059 (put-text-property (match-beginning 1) (1+ (match-end 1))
2061 (put-text-property (match-beginning 2) (match-end 2)
2064 (defun article-make-date-line (date type)
2065 "Return a DATE line of TYPE."
2066 (let ((time (condition-case ()
2070 ;; Convert to the local timezone. We have to slap a
2071 ;; `condition-case' round the calls to the timezone
2072 ;; functions since they aren't particularly resistant to
2075 (let ((tz (car (current-time-zone time))))
2076 (format "Date: %s %s%02d%02d" (current-time-string time)
2077 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2078 (/ (% (abs tz) 3600) 60))))
2079 ;; Convert to Universal Time.
2082 (current-time-string
2083 (let* ((e (parse-time-string date))
2084 (tm (apply 'encode-time e))
2086 (ls (- (cadr tm) (car (current-time-zone time)))))
2087 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2088 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2091 ;; Get the original date from the article.
2092 ((eq type 'original)
2093 (concat "Date: " (if (string-match "\n+$" date)
2094 (substring date 0 (match-beginning 0))
2096 ;; Let the user define the format.
2098 (if (gnus-functionp gnus-article-time-format)
2099 (funcall gnus-article-time-format time)
2102 (format-time-string gnus-article-time-format time))))
2105 (let ((tz (car (current-time-zone time))))
2108 (format-time-string "%Y%m%dT%H%M%S" time)
2109 (format "%s%02d%02d"
2110 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2111 (/ (% (abs tz) 3600) 60)))))
2112 ;; Do an X-Sent lapsed format.
2114 ;; If the date is seriously mangled, the timezone functions are
2115 ;; liable to bug out, so we ignore all errors.
2116 (let* ((now (current-time))
2117 (real-time (subtract-time now time))
2118 (real-sec (and real-time
2119 (+ (* (float (car real-time)) 65536)
2121 (sec (and real-time (abs real-sec)))
2131 ;; This is a bit convoluted, but basically we go
2132 ;; through the time units for years, weeks, etc,
2133 ;; and divide things to see whether that results
2134 ;; in positive answers.
2137 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2138 ;; The (remaining) seconds are too few to
2139 ;; be divided into this time unit.
2141 ;; It's big enough, so we output it.
2142 (setq sec (- sec (* num (cdr unit))))
2144 (concat (if prev ", " "") (int-to-string
2146 " " (symbol-name (car unit))
2147 (if (> num 1) "s" ""))
2149 article-time-units "")
2150 ;; If dates are odd, then it might appear like the
2151 ;; article was sent in the future.
2154 " in the future"))))))
2156 (error "Unknown conversion type: %s" type)))))
2158 (defun article-date-local (&optional highlight)
2159 "Convert the current article date to the local timezone."
2160 (interactive (list t))
2161 (article-date-ut 'local highlight))
2163 (defun article-date-original (&optional highlight)
2164 "Convert the current article date to what it was originally.
2165 This is only useful if you have used some other date conversion
2166 function and want to see what the date was before converting."
2167 (interactive (list t))
2168 (article-date-ut 'original highlight))
2170 (defun article-date-lapsed (&optional highlight)
2171 "Convert the current article date to time lapsed since it was sent."
2172 (interactive (list t))
2173 (article-date-ut 'lapsed highlight))
2175 (defun article-update-date-lapsed ()
2176 "Function to be run from a timer to update the lapsed time line."
2177 (let (deactivate-mark)
2182 (set-buffer (window-buffer w))
2183 (when (eq major-mode 'gnus-article-mode)
2184 (goto-char (point-min))
2185 (when (re-search-forward "^X-Sent:" nil t)
2186 (article-date-lapsed t))))
2189 (defun gnus-start-date-timer (&optional n)
2190 "Start a timer to update the X-Sent header in the article buffers.
2191 The numerical prefix says how frequently (in seconds) the function
2196 (gnus-stop-date-timer)
2197 (setq article-lapsed-timer
2198 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2200 (defun gnus-stop-date-timer ()
2201 "Stop the X-Sent timer."
2203 (when article-lapsed-timer
2204 (nnheader-cancel-timer article-lapsed-timer)
2205 (setq article-lapsed-timer nil)))
2207 (defun article-date-user (&optional highlight)
2208 "Convert the current article date to the user-defined format.
2209 This format is defined by the `gnus-article-time-format' variable."
2210 (interactive (list t))
2211 (article-date-ut 'user highlight))
2213 (defun article-date-iso8601 (&optional highlight)
2214 "Convert the current article date to ISO8601."
2215 (interactive (list t))
2216 (article-date-ut 'iso8601 highlight))
2218 (defun article-show-all ()
2219 "Show all hidden text in the article buffer."
2223 (let ((buffer-read-only nil))
2224 (gnus-article-unhide-text (point-min) (point-max))
2225 (gnus-remove-text-with-property 'gnus-prev)
2226 (gnus-remove-text-with-property 'gnus-next))))
2228 (defun article-show-all-headers ()
2229 "Show all hidden headers in the article buffer."
2234 (article-narrow-to-head)
2235 (let ((buffer-read-only nil))
2236 (gnus-article-unhide-text (point-min) (point-max))))))
2238 (defun article-emphasize (&optional arg)
2239 "Emphasize text according to `gnus-emphasis-alist'."
2240 (interactive (gnus-article-hidden-arg))
2241 (unless (gnus-article-check-hidden-text 'emphasis arg)
2243 (let ((alist (or (with-current-buffer gnus-summary-buffer
2244 gnus-article-emphasis-alist)
2245 gnus-emphasis-alist))
2246 (buffer-read-only nil)
2247 (props (append '(article-type emphasis)
2248 gnus-hidden-properties))
2249 regexp elem beg invisible visible face)
2252 (while (setq elem (pop alist))
2254 (setq regexp (car elem)
2255 invisible (nth 1 elem)
2256 visible (nth 2 elem)
2258 (while (re-search-forward regexp nil t)
2259 (when (and (match-beginning visible) (match-beginning invisible))
2260 (push 'emphasis gnus-article-wash-types)
2261 (gnus-article-hide-text
2262 (match-beginning invisible) (match-end invisible) props)
2263 (gnus-article-unhide-text-type
2264 (match-beginning visible) (match-end visible) 'emphasis)
2265 (gnus-put-text-property-excluding-newlines
2266 (match-beginning visible) (match-end visible) 'face face)
2267 (goto-char (match-end invisible)))))))))
2269 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2270 "Setup newsgroup emphasis alist."
2271 (unless gnus-article-emphasis-alist
2272 (let ((name (and gnus-newsgroup-name
2273 (gnus-group-real-name gnus-newsgroup-name))))
2274 (make-local-variable 'gnus-article-emphasis-alist)
2275 (setq gnus-article-emphasis-alist
2277 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2278 (while (setq elem (pop alist))
2279 (when (and name (string-match (car elem) name))
2281 highlight (copy-sequence (cdr elem)))))
2283 (copy-sequence highlight-words)
2284 (if gnus-newsgroup-name
2285 (copy-sequence (gnus-group-find-parameter
2286 gnus-newsgroup-name 'highlight-words t)))
2287 gnus-emphasis-alist)))))
2289 (defvar gnus-summary-article-menu)
2290 (defvar gnus-summary-post-menu)
2292 ;;; Saving functions.
2294 (defun gnus-article-save (save-buffer file &optional num)
2295 "Save the currently selected article."
2296 (unless gnus-save-all-headers
2297 ;; Remove headers according to `gnus-saved-headers'.
2298 (let ((gnus-visible-headers
2299 (or gnus-saved-headers gnus-visible-headers))
2300 (gnus-article-buffer save-buffer))
2302 (set-buffer save-buffer)
2303 (article-hide-headers 1 t))))
2304 (save-window-excursion
2305 (if (not gnus-default-article-saver)
2306 (error "No default saver is defined")
2307 ;; !!! Magic! The saving functions all save
2308 ;; `gnus-save-article-buffer' (or so they think), but we
2309 ;; bind that variable to our save-buffer.
2310 (set-buffer gnus-article-buffer)
2311 (let* ((gnus-save-article-buffer save-buffer)
2314 ((not gnus-prompt-before-saving) 'default)
2315 ((eq gnus-prompt-before-saving 'always) nil)
2317 (gnus-number-of-articles-to-be-saved
2318 (when (eq gnus-prompt-before-saving t)
2320 (set-buffer gnus-article-current-summary)
2321 (funcall gnus-default-article-saver filename)))))
2323 (defun gnus-read-save-file-name (prompt &optional filename
2324 function group headers variable)
2326 (funcall function group headers (symbol-value variable)))
2331 ((eq filename 'default)
2337 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2340 (if (and gnus-number-of-articles-to-be-saved
2341 (> gnus-number-of-articles-to-be-saved 1))
2342 (format "these %d articles"
2343 gnus-number-of-articles-to-be-saved)
2346 ;; Let the split methods have their say.
2348 ;; No split name was found.
2351 (concat prompt " (default "
2352 (file-name-nondirectory default-name) ") ")
2353 (file-name-directory default-name)
2355 ;; A single group name is returned.
2356 ((stringp split-name)
2358 (funcall function split-name headers
2359 (symbol-value variable)))
2361 (concat prompt " (default "
2362 (file-name-nondirectory default-name) ") ")
2363 (file-name-directory default-name)
2365 ;; A single split name was found
2366 ((= 1 (length split-name))
2367 (let* ((name (expand-file-name
2368 (car split-name) gnus-article-save-directory))
2369 (dir (cond ((file-directory-p name)
2370 (file-name-as-directory name))
2371 ((file-exists-p name) name)
2372 (t gnus-article-save-directory))))
2374 (concat prompt " (default " name ") ")
2376 ;; A list of splits was found.
2378 (setq split-name (nreverse split-name))
2380 (let ((file-name-history
2381 (nconc split-name file-name-history)))
2385 (concat prompt " (`M-p' for defaults) ")
2386 gnus-article-save-directory
2388 gnus-article-save-directory)))
2389 (car (push result file-name-history)))))))
2390 ;; Create the directory.
2391 (gnus-make-directory (file-name-directory file))
2392 ;; If we have read a directory, we append the default file name.
2393 (when (file-directory-p file)
2394 (setq file (concat (file-name-as-directory file)
2395 (file-name-nondirectory default-name))))
2396 ;; Possibly translate some characters.
2397 (nnheader-translate-file-chars file)))))
2398 (gnus-make-directory (file-name-directory result))
2399 (set variable result)))
2401 (defun gnus-article-archive-name (group)
2402 "Return the first instance of an \"Archive-name\" in the current buffer."
2403 (let ((case-fold-search t))
2404 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2405 (nnheader-concat gnus-article-save-directory
2406 (match-string 1)))))
2408 (defun gnus-article-nndoc-name (group)
2409 "If GROUP is an nndoc group, return the name of the parent group."
2410 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2411 (gnus-group-get-parameter group 'save-article-group)))
2413 (defun gnus-summary-save-in-rmail (&optional filename)
2414 "Append this article to Rmail file.
2415 Optional argument FILENAME specifies file name.
2416 Directory to save to is default to `gnus-article-save-directory'."
2417 (setq filename (gnus-read-save-file-name
2418 "Save %s in rmail file:" filename
2419 gnus-rmail-save-name gnus-newsgroup-name
2420 gnus-current-headers 'gnus-newsgroup-last-rmail))
2421 (gnus-eval-in-buffer-window gnus-save-article-buffer
2425 (gnus-output-to-rmail filename))))
2428 (defun gnus-summary-save-in-mail (&optional filename)
2429 "Append this article to Unix mail file.
2430 Optional argument FILENAME specifies file name.
2431 Directory to save to is default to `gnus-article-save-directory'."
2432 (setq filename (gnus-read-save-file-name
2433 "Save %s in Unix mail file:" filename
2434 gnus-mail-save-name gnus-newsgroup-name
2435 gnus-current-headers 'gnus-newsgroup-last-mail))
2436 (gnus-eval-in-buffer-window gnus-save-article-buffer
2440 (if (and (file-readable-p filename)
2441 (mail-file-babyl-p filename))
2442 (rmail-output-to-rmail-file filename t)
2443 (gnus-output-to-mail filename)))))
2446 (defun gnus-summary-save-in-file (&optional filename overwrite)
2447 "Append this article to file.
2448 Optional argument FILENAME specifies file name.
2449 Directory to save to is default to `gnus-article-save-directory'."
2450 (setq filename (gnus-read-save-file-name
2451 "Save %s in file:" filename
2452 gnus-file-save-name gnus-newsgroup-name
2453 gnus-current-headers 'gnus-newsgroup-last-file))
2454 (gnus-eval-in-buffer-window gnus-save-article-buffer
2458 (when (and overwrite
2459 (file-exists-p filename))
2460 (delete-file filename))
2461 (gnus-output-to-file filename))))
2464 (defun gnus-summary-write-to-file (&optional filename)
2465 "Write this article to a file.
2466 Optional argument FILENAME specifies file name.
2467 The directory to save in defaults to `gnus-article-save-directory'."
2468 (gnus-summary-save-in-file nil t))
2470 (defun gnus-summary-save-body-in-file (&optional filename)
2471 "Append this article body to a file.
2472 Optional argument FILENAME specifies file name.
2473 The directory to save in defaults to `gnus-article-save-directory'."
2474 (setq filename (gnus-read-save-file-name
2475 "Save %s body in file:" filename
2476 gnus-file-save-name gnus-newsgroup-name
2477 gnus-current-headers 'gnus-newsgroup-last-file))
2478 (gnus-eval-in-buffer-window gnus-save-article-buffer
2482 (when (article-goto-body)
2483 (narrow-to-region (point) (point-max)))
2484 (gnus-output-to-file filename))))
2487 (defun gnus-summary-save-in-pipe (&optional command)
2488 "Pipe this article to subprocess."
2490 (cond ((and (eq command 'default)
2491 gnus-last-shell-command)
2492 gnus-last-shell-command)
2496 "Shell command on %s: "
2497 (if (and gnus-number-of-articles-to-be-saved
2498 (> gnus-number-of-articles-to-be-saved 1))
2499 (format "these %d articles"
2500 gnus-number-of-articles-to-be-saved)
2502 gnus-last-shell-command))))
2503 (when (string-equal command "")
2504 (setq command gnus-last-shell-command))
2505 (gnus-eval-in-buffer-window gnus-article-buffer
2508 (shell-command-on-region (point-min) (point-max) command nil)))
2509 (setq gnus-last-shell-command command))
2511 ;;; Article file names when saving.
2513 (defun gnus-capitalize-newsgroup (newsgroup)
2514 "Capitalize NEWSGROUP name."
2515 (when (not (zerop (length newsgroup)))
2516 (concat (char-to-string (upcase (aref newsgroup 0)))
2517 (substring newsgroup 1))))
2519 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2520 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2521 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2522 Otherwise, it is like ~/News/news/group/num."
2525 (concat (if (gnus-use-long-file-name 'not-save)
2526 (gnus-capitalize-newsgroup newsgroup)
2527 (gnus-newsgroup-directory-form newsgroup))
2528 "/" (int-to-string (mail-header-number headers)))
2529 gnus-article-save-directory)))
2531 (string-equal (file-name-directory default)
2532 (file-name-directory last-file))
2533 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2535 (or last-file default))))
2537 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2538 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2539 If variable `gnus-use-long-file-name' is non-nil, it is
2540 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2543 (concat (if (gnus-use-long-file-name 'not-save)
2545 (gnus-newsgroup-directory-form newsgroup))
2546 "/" (int-to-string (mail-header-number headers)))
2547 gnus-article-save-directory)))
2549 (string-equal (file-name-directory default)
2550 (file-name-directory last-file))
2551 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2553 (or last-file default))))
2555 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2556 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2557 If variable `gnus-use-long-file-name' is non-nil, it is
2558 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2561 (if (gnus-use-long-file-name 'not-save)
2562 (gnus-capitalize-newsgroup newsgroup)
2563 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2564 gnus-article-save-directory)))
2566 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2567 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2568 If variable `gnus-use-long-file-name' is non-nil, it is
2569 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2572 (if (gnus-use-long-file-name 'not-save)
2574 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2575 gnus-article-save-directory)))
2582 (setq afunc (car func)
2585 gfunc (intern (format "gnus-%s" func))))
2587 (if (not (fboundp afunc))
2589 `(lambda (&optional interactive &rest args)
2590 ,(documentation afunc t)
2591 (interactive (list t))
2593 (set-buffer gnus-article-buffer)
2595 (call-interactively ',afunc)
2596 (apply ',afunc args))))))))
2597 '(article-hide-headers
2598 article-hide-boring-headers
2599 article-toggle-headers
2600 article-treat-overstrike
2601 article-fill-long-lines
2602 article-capitalize-sentences
2604 article-display-x-face
2605 article-de-quoted-unreadable
2606 article-hide-list-identifiers
2608 article-strip-banner
2611 article-hide-signature
2612 article-strip-headers-in-body
2613 article-remove-trailing-blank-lines
2614 article-strip-leading-blank-lines
2615 article-strip-multiple-blank-lines
2616 article-strip-leading-space
2617 article-strip-trailing-space
2618 article-strip-blank-lines
2619 article-strip-all-blank-lines
2621 article-date-iso8601
2622 article-date-original
2624 article-decode-mime-words
2625 article-decode-charset
2626 article-decode-encoded-words
2630 article-treat-dumbquotes
2631 article-normalize-headers
2632 (article-show-all-headers . gnus-article-show-all-headers)
2633 (article-show-all . gnus-article-show-all))))
2636 ;;; Gnus article mode
2639 (put 'gnus-article-mode 'mode-class 'special)
2641 (gnus-define-keys gnus-article-mode-map
2642 " " gnus-article-goto-next-page
2643 "\177" gnus-article-goto-prev-page
2644 [delete] gnus-article-goto-prev-page
2645 [backspace] gnus-article-goto-prev-page
2646 "\C-c^" gnus-article-refer-article
2647 "h" gnus-article-show-summary
2648 "s" gnus-article-show-summary
2649 "\C-c\C-m" gnus-article-mail
2650 "?" gnus-article-describe-briefly
2651 gnus-mouse-2 gnus-article-push-button
2652 "\r" gnus-article-press-button
2653 "\t" gnus-article-next-button
2654 "\M-\t" gnus-article-prev-button
2655 "e" gnus-article-edit
2656 "<" beginning-of-buffer
2658 "\C-c\C-i" gnus-info-find-node
2661 "\C-d" gnus-article-read-summary-keys
2662 "\M-*" gnus-article-read-summary-keys
2663 "\M-#" gnus-article-read-summary-keys
2664 "\M-^" gnus-article-read-summary-keys
2665 "\M-g" gnus-article-read-summary-keys)
2667 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2670 (unless (lookup-key gnus-article-mode-map key)
2671 (define-key gnus-article-mode-map key
2672 'gnus-article-read-summary-keys)))
2677 (let ((key (car elt)))
2678 (and (> (length key) 0)
2679 (not (eq 'menu-bar (aref key 0)))
2680 (symbolp (lookup-key gnus-summary-mode-map key))
2682 (accessible-keymaps gnus-summary-mode-map))
2686 (push (char-to-string c) keys)
2690 (defun gnus-article-make-menu-bar ()
2691 (gnus-turn-off-edit-menu 'article)
2692 (unless (boundp 'gnus-article-article-menu)
2694 gnus-article-article-menu gnus-article-mode-map ""
2696 ["Scroll forwards" gnus-article-goto-next-page t]
2697 ["Scroll backwards" gnus-article-goto-prev-page t]
2698 ["Show summary" gnus-article-show-summary t]
2699 ["Fetch Message-ID at point" gnus-article-refer-article t]
2700 ["Mail to address at point" gnus-article-mail t]
2701 ["Send a bug report" gnus-bug t]))
2704 gnus-article-treatment-menu gnus-article-mode-map ""
2706 ["Hide headers" gnus-article-toggle-headers t]
2707 ["Hide signature" gnus-article-hide-signature t]
2708 ["Hide citation" gnus-article-hide-citation t]
2709 ["Treat overstrike" gnus-article-treat-overstrike t]
2710 ["Remove carriage return" gnus-article-remove-cr t]))
2712 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2714 (when (boundp 'gnus-summary-post-menu)
2715 (define-key gnus-article-mode-map [menu-bar post]
2716 (cons "Post" gnus-summary-post-menu)))
2718 (gnus-run-hooks 'gnus-article-menu-hook)))
2720 (defun gnus-article-mode ()
2721 "Major mode for displaying an article.
2723 All normal editing commands are switched off.
2725 The following commands are available in addition to all summary mode
2727 \\<gnus-article-mode-map>
2728 \\[gnus-article-next-page]\t Scroll the article one page forwards
2729 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2730 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2731 \\[gnus-article-show-summary]\t Display the summary buffer
2732 \\[gnus-article-mail]\t Send a reply to the address near point
2733 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2734 \\[gnus-info-find-node]\t Go to the Gnus info node"
2736 (when (gnus-visual-p 'article-menu 'menu)
2737 (gnus-article-make-menu-bar))
2738 (gnus-simplify-mode-line)
2739 (setq mode-name "Article")
2740 (setq major-mode 'gnus-article-mode)
2741 (make-local-variable 'minor-mode-alist)
2742 (unless (assq 'gnus-show-mime minor-mode-alist)
2743 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2744 (use-local-map gnus-article-mode-map)
2745 (gnus-update-format-specifications nil 'article-mode)
2746 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2747 (make-local-variable 'gnus-page-broken)
2748 (make-local-variable 'gnus-button-marker-list)
2749 (make-local-variable 'gnus-article-current-summary)
2750 (make-local-variable 'gnus-article-mime-handles)
2751 (make-local-variable 'gnus-article-decoded-p)
2752 (make-local-variable 'gnus-article-mime-handle-alist)
2753 (make-local-variable 'gnus-article-washed-types)
2754 (gnus-set-default-directory)
2755 (buffer-disable-undo)
2756 (setq buffer-read-only t)
2757 (set-syntax-table gnus-article-mode-syntax-table)
2758 (gnus-run-hooks 'gnus-article-mode-hook))
2760 (defun gnus-article-setup-buffer ()
2761 "Initialize the article buffer."
2762 (let* ((name (if gnus-single-article-buffer "*Article*"
2763 (concat "*Article " gnus-newsgroup-name "*")))
2765 (progn (string-match "\\*Article" name)
2766 (concat " *Original Article"
2767 (substring name (match-end 0))))))
2768 (setq gnus-article-buffer name)
2769 (setq gnus-original-article-buffer original)
2770 (setq gnus-article-mime-handle-alist nil)
2771 ;; This might be a variable local to the summary buffer.
2772 (unless gnus-single-article-buffer
2774 (set-buffer gnus-summary-buffer)
2775 (setq gnus-article-buffer name)
2776 (setq gnus-original-article-buffer original)
2777 (gnus-set-global-variables)))
2778 (gnus-article-setup-highlight-words)
2779 ;; Init original article buffer.
2781 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2782 (setq major-mode 'gnus-original-article-mode)
2783 (make-local-variable 'gnus-original-article))
2784 (if (get-buffer name)
2787 (kill-all-local-variables)
2788 (buffer-disable-undo)
2789 (setq buffer-read-only t)
2790 (unless (eq major-mode 'gnus-article-mode)
2791 (gnus-article-mode))
2794 (set-buffer (gnus-get-buffer-create name))
2796 (make-local-variable 'gnus-summary-buffer)
2797 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2798 (current-buffer)))))
2800 ;; Set article window start at LINE, where LINE is the number of lines
2801 ;; from the head of the article.
2802 (defun gnus-article-set-window-start (&optional line)
2804 (get-buffer-window gnus-article-buffer t)
2806 (set-buffer gnus-article-buffer)
2807 (goto-char (point-min))
2810 (gnus-message 6 "Moved to bookmark")
2811 (search-forward "\n\n" nil t)
2815 ;;; @@ article filters
2818 (defun gnus-article-display-mime-message ()
2819 "Article display method for MIME message."
2820 ;; called from `gnus-original-article-buffer'.
2821 (let (charset all-headers)
2822 (with-current-buffer gnus-summary-buffer
2823 (setq charset default-mime-charset
2824 all-headers gnus-have-all-headers))
2825 (make-local-variable 'default-mime-charset)
2826 (setq default-mime-charset charset)
2827 (with-current-buffer (get-buffer-create gnus-article-buffer)
2828 (make-local-variable 'default-mime-charset)
2829 (setq default-mime-charset charset))
2830 (mime-display-message mime-message-structure
2831 gnus-article-buffer nil gnus-article-mode-map)
2833 (gnus-article-hide-headers nil -1))
2835 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2836 (make-local-variable 'mime-button-mother-dispatcher)
2837 (setq mime-button-mother-dispatcher
2838 (function gnus-article-push-button))
2839 (run-hooks 'gnus-mime-article-prepare-hook))
2841 (defun gnus-article-display-traditional-message ()
2842 "Article display method for traditional message."
2843 (set-buffer gnus-article-buffer)
2844 (let (buffer-read-only)
2846 (insert-buffer-substring gnus-original-article-buffer)))
2848 (defun gnus-article-make-full-mail-header (&optional number charset)
2849 "Create a new mail header structure in a raw article buffer."
2850 (unless (and number charset)
2851 (save-current-buffer
2852 (set-buffer gnus-summary-buffer)
2854 (setq number (or (cdr gnus-article-current) 0)))
2856 (setq charset (or default-mime-charset 'x-ctext)))))
2857 (goto-char (point-min))
2858 (let ((header-end (if (search-forward "\n\n" nil t)
2860 (goto-char (point-max))))
2861 (chars (- (point-max) (point)))
2862 (lines (count-lines (point) (point-max)))
2863 (default-mime-charset charset)
2865 (narrow-to-region (point-min) header-end)
2866 (setq xref (std11-fetch-field "xref"))
2868 (make-full-mail-header
2870 (std11-fetch-field "subject")
2871 (std11-fetch-field "from")
2872 (std11-fetch-field "date")
2873 (std11-fetch-field "message-id")
2874 (std11-fetch-field "references")
2877 (when xref (concat "Xref: " xref)))
2880 (defun gnus-article-prepare (article &optional all-headers header)
2881 "Prepare ARTICLE in article mode buffer.
2882 ARTICLE should either be an article number or a Message-ID.
2883 If ARTICLE is an id, HEADER should be the article headers.
2884 If ALL-HEADERS is non-nil, no headers are hidden."
2886 ;; Make sure we start in a summary buffer.
2887 (unless (eq major-mode 'gnus-summary-mode)
2888 (set-buffer gnus-summary-buffer))
2889 (setq gnus-summary-buffer (current-buffer))
2890 (let* ((gnus-article (if header (mail-header-number header) article))
2891 (summary-buffer (current-buffer))
2892 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2893 (group gnus-newsgroup-name)
2896 (gnus-article-setup-buffer)
2897 (set-buffer gnus-original-article-buffer)
2898 ;; Deactivate active regions.
2899 (when (and (boundp 'transient-mark-mode)
2900 transient-mark-mode)
2901 (setq mark-active nil))
2902 (if (not (setq result (let ((buffer-read-only nil))
2903 (gnus-request-article-this-buffer
2905 ;; There is no such article.
2907 (when (and (numberp article)
2908 (not (memq article gnus-newsgroup-sparse)))
2909 (setq gnus-article-current
2910 (cons gnus-newsgroup-name article))
2911 (set-buffer gnus-summary-buffer)
2912 (setq gnus-current-article article)
2913 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2915 (gnus-summary-set-agent-mark article)
2916 (message "Message marked for downloading"))
2917 (gnus-summary-mark-article article gnus-canceled-mark)
2918 (unless (memq article gnus-newsgroup-sparse)
2920 "No such article (may have expired or been canceled)")))))
2921 (if (or (eq result 'pseudo)
2922 (eq result 'nneething))
2925 (set-buffer summary-buffer)
2926 (push article gnus-newsgroup-history)
2927 (setq gnus-last-article gnus-current-article
2928 gnus-current-article 0
2929 gnus-current-headers nil
2930 gnus-article-current nil)
2931 (if (eq result 'nneething)
2932 (gnus-configure-windows 'summary)
2933 (gnus-configure-windows 'article))
2934 (gnus-set-global-variables))
2935 (let ((gnus-article-mime-handle-alist-1
2936 gnus-article-mime-handle-alist))
2937 (gnus-set-mode-line 'article)))
2938 ;; The result from the `request' was an actual article -
2939 ;; or at least some text that is now displayed in the
2941 (when (and (numberp article)
2942 (not (eq article gnus-current-article)))
2943 ;; Seems like a new article has been selected.
2944 ;; `gnus-current-article' must be an article number.
2946 (set-buffer summary-buffer)
2947 (push article gnus-newsgroup-history)
2948 (setq gnus-last-article gnus-current-article
2949 gnus-current-article article
2950 gnus-current-headers
2951 (gnus-summary-article-header gnus-current-article)
2952 gnus-article-current
2953 (cons gnus-newsgroup-name gnus-current-article))
2954 (unless (vectorp gnus-current-headers)
2955 (setq gnus-current-headers nil))
2956 (gnus-summary-goto-subject gnus-current-article)
2957 (when (gnus-summary-show-thread)
2958 ;; If the summary buffer really was folded, the
2959 ;; previous goto may not actually have gone to
2960 ;; the right article, but the thread root instead.
2962 (gnus-summary-goto-subject gnus-current-article))
2963 (gnus-run-hooks 'gnus-mark-article-hook)
2964 (gnus-set-mode-line 'summary)
2965 (when (gnus-visual-p 'article-highlight 'highlight)
2966 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2967 ;; Set the global newsgroup variables here.
2968 (gnus-set-global-variables)
2969 (setq gnus-have-all-headers
2970 (or all-headers gnus-show-all-headers))))
2971 (when (or (numberp article)
2973 (gnus-article-prepare-display)
2975 (goto-char (point-min))
2976 (setq gnus-page-broken
2977 (when gnus-break-pages
2978 (gnus-narrow-to-page)
2980 (let ((gnus-article-mime-handle-alist-1
2981 gnus-article-mime-handle-alist))
2982 (gnus-set-mode-line 'article))
2984 (set-window-point (get-buffer-window (current-buffer)) (point))
2985 (gnus-configure-windows 'article)
2988 (defun gnus-article-prepare-mime-display (&optional number)
2989 (goto-char (point-min))
2990 (when (re-search-forward "^[^\t ]+:" nil t)
2991 (goto-char (match-beginning 0)))
2992 (let ((entity (if (eq 1 (point-min))
2993 (get-text-property 1 'mime-view-entity)
2994 (get-text-property (point) 'mime-view-entity)))
2995 last-entity child-entity next type)
2996 (setq child-entity (mime-entity-children entity))
2998 (setq last-entity (nth (1- (length child-entity))
3000 (setq last-entity entity))
3002 (narrow-to-region (point)
3003 (if (search-forward "\n\n" nil t)
3006 (gnus-treat-article 'head)
3007 (put-text-property (point-min) (point-max) 'article-treated-header t)
3008 (goto-char (point-max)))
3009 (while (and (not (eobp)) entity)
3010 (setq next (set-marker
3012 (next-single-property-change (point) 'mime-view-entity
3014 (let ((types (mime-entity-content-type entity)))
3015 (while (eq 'multipart (mime-content-type-primary-type types))
3016 (setq entity (car (mime-entity-children entity))
3017 types (mime-entity-content-type entity)))
3019 (setq type (format "%s/%s"
3020 (mime-content-type-primary-type types)
3021 (mime-content-type-subtype types)))))
3022 (if (string-equal type "message/rfc822")
3025 (let ((children (mime-entity-children entity))
3028 (setq last-children (nth (1- (length children)) children))
3031 (not (eq last-children
3032 (get-text-property next 'mime-view-entity)))
3034 (next-single-property-change next
3036 nil (point-max)))))))
3037 (setq next (next-single-property-change next 'mime-view-entity
3040 (narrow-to-region (point) next)
3041 (gnus-article-prepare-mime-display)
3042 (goto-char (point-max)))
3043 (setq entity (get-text-property (point) 'mime-view-entity)))
3045 (narrow-to-region (point) next)
3046 ;; Kludge. We have to count true number, but for now,
3047 ;; part number is here only to achieve `last'.
3048 (gnus-treat-article nil 1
3049 (if (eq entity last-entity)
3052 (setq entity (get-text-property next 'mime-view-entity))
3053 (goto-char (point-max)))))))
3056 (defun gnus-article-prepare-display ()
3057 "Make the current buffer look like a nice article."
3058 (setq gnus-article-wash-types nil)
3059 (gnus-run-hooks 'gnus-tmp-internal-hook)
3060 (gnus-run-hooks 'gnus-article-prepare-hook)
3062 (let (mime-display-header-hook mime-display-text/plain-hook)
3063 (funcall (if gnus-show-mime
3065 (setq mime-message-structure gnus-current-headers)
3066 (mime-buffer-entity-set-buffer-internal
3067 mime-message-structure
3068 gnus-original-article-buffer)
3069 (mime-entity-set-representation-type-internal
3070 mime-message-structure 'mime-buffer-entity)
3071 (luna-send mime-message-structure
3072 'initialize-instance
3073 mime-message-structure)
3074 gnus-article-display-method-for-mime)
3075 gnus-article-display-method-for-traditional)))
3076 ;; Associate this article with the current summary buffer.
3077 (setq gnus-article-current-summary gnus-summary-buffer)
3078 ;; Call the treatment functions.
3079 (let ((inhibit-read-only t)
3084 (gnus-article-prepare-mime-display)
3085 (narrow-to-region (goto-char (point-min))
3086 (if (search-forward "\n\n" nil t)
3089 (gnus-treat-article 'head)
3090 (put-text-property (point-min) (point-max) 'article-treated-header t)
3091 (goto-char (point-max))
3093 (narrow-to-region (point) (point-max))
3094 (gnus-treat-article nil))
3095 (put-text-property (point-min) (point-max) 'read-only nil)))
3096 ;; Perform the article display hooks. Incidentally, this hook is
3097 ;; an obsolete variable by now.
3098 (gnus-run-hooks 'gnus-article-display-hook))
3100 (defun gnus-article-decode-article-as-default-mime-charset ()
3101 "Decode an article as `default-mime-charset'. It won't work if the
3102 value of the variable `gnus-show-mime' is non-nil."
3103 (unless gnus-show-mime
3104 (decode-mime-charset-region (point-min) (point-max)
3105 (with-current-buffer gnus-summary-buffer
3106 default-mime-charset))))
3109 ;;; Gnus MIME viewing functions
3112 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3113 "The following specs can be used:
3115 %T MIME type, along with additional info
3116 %n The `name' parameter
3117 %d The description, if any
3118 %l The length of the encoded part
3119 %p The part identifier number
3120 %e Dots if the part isn't displayed")
3122 (defvar gnus-mime-button-line-format-alist
3123 '((?t gnus-tmp-type ?s)
3124 (?T gnus-tmp-type-long ?s)
3125 (?n gnus-tmp-name ?s)
3126 (?d gnus-tmp-description ?s)
3128 (?l gnus-tmp-length ?d)
3129 (?e gnus-tmp-dots ?s)))
3131 (defvar gnus-mime-button-commands
3132 '((gnus-article-press-button "\r" "Toggle Display")
3133 (gnus-mime-view-part "v" "View Interactively...")
3134 (gnus-mime-view-part-as-type "t" "View As Type...")
3135 (gnus-mime-save-part "o" "Save...")
3136 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3137 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3138 (gnus-mime-internalize-part "E" "View Internally")
3139 (gnus-mime-externalize-part "e" "View Externally")
3140 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3142 (defun gnus-article-mime-part-status ()
3143 (with-current-buffer gnus-article-buffer
3144 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3145 (if (and entity (mime-entity-children entity))
3146 (format " (%d parts)" (length (mime-entity-children entity)))
3149 (defvar gnus-mime-button-map nil)
3150 (unless gnus-mime-button-map
3151 (setq gnus-mime-button-map (make-sparse-keymap))
3152 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3153 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3154 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3156 (define-key gnus-mime-button-map (cadr c) (car c)))
3157 gnus-mime-button-commands))
3159 (defun gnus-mime-button-menu (event)
3160 "Construct a context-sensitive menu of MIME commands."
3163 (let ((pos (event-start event)))
3164 (set-buffer (window-buffer (posn-window pos)))
3165 (goto-char (posn-point pos))
3166 (gnus-article-check-buffer)
3167 (let ((response (x-popup-menu
3169 ("" ,@(mapcar (lambda (c)
3170 (cons (caddr c) (car c)))
3171 gnus-mime-button-commands))))))
3173 (funcall response))))))
3175 (defun gnus-mime-view-all-parts (&optional handles)
3176 "View all the MIME parts."
3178 (save-current-buffer
3179 (set-buffer gnus-article-buffer)
3180 (let ((handles (or handles gnus-article-mime-handles))
3181 (mail-parse-charset gnus-newsgroup-charset)
3182 (mail-parse-ignored-charsets
3183 (save-excursion (set-buffer gnus-summary-buffer)
3184 gnus-newsgroup-ignored-charsets)))
3185 (if (stringp (car handles))
3186 (gnus-mime-view-all-parts (cdr handles))
3187 (mapcar 'mm-display-part handles)))))
3189 (defun gnus-mime-save-part ()
3190 "Save the MIME part under point."
3192 (gnus-article-check-buffer)
3193 (let ((data (get-text-property (point) 'gnus-data)))
3194 (mm-save-part data)))
3196 (defun gnus-mime-pipe-part ()
3197 "Pipe the MIME part under point to a process."
3199 (gnus-article-check-buffer)
3200 (let ((data (get-text-property (point) 'gnus-data)))
3201 (mm-pipe-part data)))
3203 (defun gnus-mime-view-part ()
3204 "Interactively choose a viewing method for the MIME part under point."
3206 (gnus-article-check-buffer)
3207 (let ((data (get-text-property (point) 'gnus-data)))
3208 (mm-interactively-view-part data)))
3210 (defun gnus-mime-view-part-as-type ()
3211 "Choose a MIME media type, and view the part as such."
3213 (list (completing-read "View as MIME type: " mailcap-mime-types)))
3214 (gnus-article-check-buffer)
3215 (let ((handle (get-text-property (point) 'gnus-data)))
3216 (gnus-mm-display-part handle)))
3218 (defun gnus-mime-copy-part (&optional handle)
3219 "Put the the MIME part under point into a new buffer."
3221 (gnus-article-check-buffer)
3222 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3223 (contents (mm-get-part handle))|
3224 (base (file-name-nondirectory
3226 (mail-content-type-get (mm-handle-type handle) 'name)
3227 (mail-content-type-get (mm-handle-type handle)
3230 (buffer (generate-new-buffer base)))
3231 (switch-to-buffer buffer)
3233 ;; We do it this way to make `normal-mode' set the appropriate mode.
3236 (setq buffer-file-name (expand-file-name base))
3238 (setq buffer-file-name nil))
3239 (goto-char (point-min))))
3241 (defun gnus-mime-inline-part (&optional handle)
3242 "Insert the MIME part under point into the current buffer."
3244 (gnus-article-check-buffer)
3245 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3249 (if (mm-handle-undisplayer handle)
3250 (mm-remove-part handle)
3251 (setq contents (mm-get-part handle))
3253 (mm-insert-inline handle contents)
3256 (defun gnus-mime-externalize-part (&optional handle)
3257 "View the MIME part under point with an external viewer."
3259 (gnus-article-check-buffer)
3260 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3261 (mm-user-display-methods nil)
3262 (mm-inline-large-images nil)
3263 (mail-parse-charset gnus-newsgroup-charset)
3264 (mail-parse-ignored-charsets
3265 (save-excursion (set-buffer gnus-summary-buffer)
3266 gnus-newsgroup-ignored-charsets)))
3267 (if (mm-handle-undisplayer handle)
3268 (mm-remove-part handle)
3269 (mm-display-part handle))))
3271 (defun gnus-mime-internalize-part (&optional handle)
3272 "View the MIME part under point with an internal viewer."
3274 (gnus-article-check-buffer)
3275 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3276 (mm-user-display-methods '((".*" . inline)))
3277 (mm-inline-large-images t)
3278 (mail-parse-charset gnus-newsgroup-charset)
3279 (mail-parse-ignored-charsets
3280 (save-excursion (set-buffer gnus-summary-buffer)
3281 gnus-newsgroup-ignored-charsets)))
3282 (if (mm-handle-undisplayer handle)
3283 (mm-remove-part handle)
3284 (mm-display-part handle))))
3286 (defun gnus-article-part-wrapper (n function)
3287 (save-current-buffer
3288 (set-buffer gnus-article-buffer)
3289 (when (> n (length gnus-article-mime-handle-alist))
3290 (error "No such part"))
3291 (gnus-article-goto-part n)
3292 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3293 (funcall function handle))))
3295 (defun gnus-article-pipe-part (n)
3296 "Pipe MIME part N, which is the numerical prefix."
3298 (gnus-article-part-wrapper n 'mm-pipe-part))
3300 (defun gnus-article-save-part (n)
3301 "Save MIME part N, which is the numerical prefix."
3303 (gnus-article-part-wrapper n 'mm-save-part))
3305 (defun gnus-article-interactively-view-part (n)
3306 "View MIME part N interactively, which is the numerical prefix."
3308 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3310 (defun gnus-article-copy-part (n)
3311 "Copy MIME part N, which is the numerical prefix."
3313 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3315 (defun gnus-article-externalize-part (n)
3316 "View MIME part N externally, which is the numerical prefix."
3318 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3320 (defun gnus-article-inline-part (n)
3321 "Inline MIME part N, which is the numerical prefix."
3323 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3325 (defun gnus-article-mime-match-handle-first (condition)
3327 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3328 (while (setq ihandle (pop alist))
3330 ((functionp condition)
3331 (funcall condition (cdr ihandle)))
3332 ((eq condition 'undisplayed)
3333 (not (or (mm-handle-undisplayer (cdr ihandle))
3334 (equal (mm-handle-media-type (cdr ihandle))
3335 "multipart/alternative"))))
3336 ((eq condition 'undisplayed-alternative)
3337 (not (mm-handle-undisplayer (cdr ihandle))))
3339 (gnus-article-goto-part (car ihandle))
3340 (or (not n) (< (car ihandle) n)))
3341 (setq n (car ihandle))))
3345 (defun gnus-article-view-part (&optional n)
3346 "View MIME part N, which is the numerical prefix."
3348 (save-current-buffer
3349 (set-buffer gnus-article-buffer)
3350 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3351 gnus-article-mime-match-handle-function)))
3352 (when (> n (length gnus-article-mime-handle-alist))
3353 (error "No such part"))
3354 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3355 (when (gnus-article-goto-part n)
3356 (if (equal (car handle) "multipart/alternative")
3357 (gnus-article-press-button)
3358 (when (eq (gnus-mm-display-part handle) 'internal)
3359 (gnus-set-window-start)))))))
3361 (defun gnus-mm-display-part (handle)
3362 "Display HANDLE and fix MIME button."
3363 (let ((id (get-text-property (point) 'gnus-part))
3368 (let ((window (selected-window))
3369 (mail-parse-charset gnus-newsgroup-charset)
3370 (mail-parse-ignored-charsets
3371 (save-excursion (set-buffer gnus-summary-buffer)
3372 gnus-newsgroup-ignored-charsets)))
3375 (let ((win (get-buffer-window (current-buffer) t))
3378 (select-window win))
3381 (if (mm-handle-displayed-p handle)
3382 ;; This will remove the part.
3383 (mm-display-part handle)
3385 (narrow-to-region (point) (1+ (point)))
3386 (mm-display-part handle)
3387 ;; We narrow to the part itself and
3388 ;; then call the treatment functions.
3389 (goto-char (point-min))
3391 (narrow-to-region (point) (point-max))
3394 (1- (length gnus-article-mime-handles))
3395 (mm-handle-media-type handle)))))
3396 (select-window window))))
3398 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3399 (gnus-insert-mime-button
3400 handle id (list (mm-handle-displayed-p handle)))
3401 (goto-char point))))
3403 (defun gnus-article-goto-part (n)
3404 "Go to MIME part N."
3405 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3407 (goto-char point))))
3409 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3410 (let ((gnus-tmp-name
3411 (or (mail-content-type-get (mm-handle-type handle)
3413 (mail-content-type-get (mm-handle-disposition handle)
3416 (gnus-tmp-type (mm-handle-media-type handle))
3417 (gnus-tmp-description
3418 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3421 (if (if displayed (car displayed)
3422 (mm-handle-displayed-p handle))
3424 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3426 gnus-tmp-type-long b e)
3427 (when (string-match ".*/" gnus-tmp-name)
3428 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3429 (setq gnus-tmp-type-long (concat gnus-tmp-type
3430 (and (not (equal gnus-tmp-name ""))
3431 (concat "; " gnus-tmp-name))))
3432 (or (equal gnus-tmp-description "")
3433 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3438 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3439 `(local-map ,gnus-mime-button-map
3440 keymap ,gnus-mime-button-map
3441 gnus-callback gnus-mm-display-part
3442 gnus-part ,gnus-tmp-id
3443 article-type annotation
3446 (widget-convert-button 'link b e
3448 :action 'gnus-widget-press-button
3449 :button-keymap gnus-mime-button-map
3452 ;; Needed to properly clear the message
3453 ;; due to a bug in wid-edit
3454 (setq help-echo-owns-message t)
3456 "Click to %s the MIME part; %s for more options"
3457 (if (mm-handle-displayed-p
3458 (widget-get widget :mime-handle))
3460 (if gnus-xemacs "button3" "mouse-3"))))))
3462 (defun gnus-widget-press-button (elems el)
3463 (goto-char (widget-get elems :from))
3464 (gnus-article-press-button))
3466 (defvar gnus-displaying-mime nil)
3468 (defun gnus-display-mime (&optional ihandles)
3469 "Display the MIME parts."
3471 (save-selected-window
3472 (let ((window (get-buffer-window gnus-article-buffer))
3475 (select-window window)
3476 ;; We have to do this since selecting the window
3477 ;; may change the point. So we set the window point.
3478 (set-window-point window point)))
3479 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3480 buffer-read-only handle name type b e display)
3481 (when (and (not ihandles)
3482 (not gnus-displaying-mime))
3483 ;; Top-level call; we clean up.
3484 (when gnus-article-mime-handles
3485 (mm-destroy-parts gnus-article-mime-handles)
3486 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3487 (setq gnus-article-mime-handles handles)
3488 ;; We allow users to glean info from the handles.
3489 (when gnus-article-mime-part-function
3490 (gnus-mime-part-function handles)))
3492 (or (not (stringp (car handles)))
3495 (when (and (not ihandles)
3496 (not gnus-displaying-mime))
3497 ;; Clean up for mime parts.
3499 (delete-region (point) (point-max)))
3500 (let ((gnus-displaying-mime t))
3501 (gnus-mime-display-part handles)))
3504 (narrow-to-region (point) (point-max))
3505 (gnus-treat-article nil 1 1)
3508 ;; Highlight the headers.
3512 (narrow-to-region (point-min) (point))
3513 (gnus-treat-article 'head))))))))
3515 (defvar gnus-mime-display-multipart-as-mixed nil)
3517 (defun gnus-mime-display-part (handle)
3520 ((not (stringp (car handle)))
3521 (gnus-mime-display-single handle))
3522 ;; User-defined multipart
3523 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3524 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3526 ;; multipart/alternative
3527 ((and (equal (car handle) "multipart/alternative")
3528 (not gnus-mime-display-multipart-as-mixed))
3529 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3530 (push (cons id handle) gnus-article-mime-handle-alist)
3531 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3532 ;; multipart/related
3533 ((and (equal (car handle) "multipart/related")
3534 (not gnus-mime-display-multipart-as-mixed))
3535 ;;;!!!We should find the start part, but we just default
3536 ;;;!!!to the first part.
3537 (gnus-mime-display-part (cadr handle)))
3538 ;; Other multiparts are handled like multipart/mixed.
3540 (gnus-mime-display-mixed (cdr handle)))))
3542 (defun gnus-mime-part-function (handles)
3543 (if (stringp (car handles))
3544 (mapcar 'gnus-mime-part-function (cdr handles))
3545 (funcall gnus-article-mime-part-function handles)))
3547 (defun gnus-mime-display-mixed (handles)
3548 (mapcar 'gnus-mime-display-part handles))
3550 (defun gnus-mime-display-single (handle)
3551 (let ((type (mm-handle-media-type handle))
3552 (ignored gnus-ignored-mime-types)
3559 (when (string-match (pop ignored) type)
3560 (throw 'ignored nil)))
3561 (if (and (setq not-attachment
3562 (or (not (mm-handle-disposition handle))
3563 (equal (car (mm-handle-disposition handle))
3565 (mm-attachment-override-p handle)))
3566 (mm-automatic-display-p handle)
3567 (or (mm-inlined-p handle)
3568 (mm-automatic-external-display-p type)))
3570 (when (equal (mm-handle-media-supertype handle) "text")
3572 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3573 (push (cons id handle) gnus-article-mime-handle-alist)
3574 (when (or (not display)
3575 (not (gnus-unbuttonized-mime-type-p type)))
3576 (gnus-article-insert-newline)
3577 (gnus-insert-mime-button
3578 handle id (list (or display (and not-attachment text))))
3579 (gnus-article-insert-newline)
3580 (gnus-article-insert-newline)
3582 (let ((beg (point)))
3588 (let ((mail-parse-charset gnus-newsgroup-charset)
3589 (mail-parse-ignored-charsets
3590 (save-excursion (set-buffer gnus-summary-buffer)
3591 gnus-newsgroup-ignored-charsets)))
3592 (mm-display-part handle t))
3593 (goto-char (point-max)))
3594 ((and text not-attachment)
3598 (gnus-article-insert-newline)
3599 (mm-insert-inline handle (mm-get-part handle))
3600 (goto-char (point-max))))
3604 (narrow-to-region beg (point))
3606 nil (length gnus-article-mime-handle-alist)
3607 (1- (length gnus-article-mime-handles))
3608 (mm-handle-media-type handle)))))))))
3610 (defun gnus-unbuttonized-mime-type-p (type)
3611 "Say whether TYPE is to be unbuttonized."
3612 (unless gnus-inhibit-mime-unbuttonizing
3614 (let ((types gnus-unbuttonized-mime-types))
3616 (when (string-match (pop types) type)
3617 (throw 'found t)))))))
3619 (defun gnus-article-insert-newline ()
3620 "Insert a newline, but mark it as undeletable."
3621 (gnus-put-text-property
3622 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3624 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3625 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3628 handle buffer-read-only from props begend not-pref)
3629 (save-window-excursion
3632 (narrow-to-region (car ibegend)
3635 (goto-char (car ibegend))
3638 (delete-region (point-min) (point-max))
3639 (mm-remove-parts handles))
3640 (setq begend (list (point-marker)))
3642 (unless (setq not-pref (cadr (member preferred ihandles)))
3643 (setq not-pref (car ihandles)))
3645 (not (gnus-unbuttonized-mime-type-p
3646 "multipart/alternative")))
3647 (gnus-add-text-properties
3650 (insert (format "%d. " id))
3654 (unless ,(not ibegend)
3655 (setq gnus-article-mime-handle-alist
3656 ',gnus-article-mime-handle-alist))
3657 (gnus-mime-display-alternative
3658 ',ihandles ',not-pref ',begend ,id))
3659 local-map ,gnus-mime-button-map
3660 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3661 face ,gnus-article-button-face
3662 keymap ,gnus-mime-button-map
3665 (widget-convert-button 'link from (point)
3666 :action 'gnus-widget-press-button
3667 :button-keymap gnus-widget-button-keymap)
3669 (while (setq handle (pop handles))
3670 (gnus-add-text-properties
3673 (insert (format "(%c) %-18s"
3674 (if (equal handle preferred) ?* ? )
3675 (mm-handle-media-type handle)))
3679 (unless ,(not ibegend)
3680 (setq gnus-article-mime-handle-alist
3681 ',gnus-article-mime-handle-alist))
3682 (gnus-mime-display-alternative
3683 ',ihandles ',handle ',begend ,id))
3684 local-map ,gnus-mime-button-map
3685 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3686 face ,gnus-article-button-face
3687 keymap ,gnus-mime-button-map
3690 (widget-convert-button 'link from (point)
3691 :action 'gnus-widget-press-button
3692 :button-keymap gnus-widget-button-keymap)
3696 (if (stringp (car preferred))
3697 (gnus-display-mime preferred)
3698 (let ((mail-parse-charset gnus-newsgroup-charset)
3699 (mail-parse-ignored-charsets
3700 (save-excursion (set-buffer gnus-summary-buffer)
3701 gnus-newsgroup-ignored-charsets)))
3702 (mm-display-part preferred)
3706 (narrow-to-region (car begend) (point-max))
3708 nil (length gnus-article-mime-handle-alist)
3709 (1- (length gnus-article-mime-handles))
3710 (mm-handle-media-type handle))))))
3711 (goto-char (point-max))
3712 (setcdr begend (point-marker)))))
3714 (goto-char point))))
3716 (defun gnus-article-wash-status ()
3717 "Return a string which display status of article washing."
3719 (set-buffer gnus-article-buffer)
3720 (let ((cite (memq 'cite gnus-article-wash-types))
3721 (headers (memq 'headers gnus-article-wash-types))
3722 (boring (memq 'boring-headers gnus-article-wash-types))
3723 (pgp (memq 'pgp gnus-article-wash-types))
3724 (pem (memq 'pem gnus-article-wash-types))
3725 (signature (memq 'signature gnus-article-wash-types))
3726 (overstrike (memq 'overstrike gnus-article-wash-types))
3727 (emphasis (memq 'emphasis gnus-article-wash-types)))
3728 (format "%c%c%c%c%c%c%c"
3730 (if (or headers boring) ?h ? )
3731 (if (or pgp pem) ?p ? )
3732 (if signature ?s ? )
3733 (if overstrike ?o ? )
3734 (if gnus-show-mime ?m ? )
3735 (if emphasis ?e ? )))))
3737 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3739 (defun gnus-article-maybe-hide-headers ()
3740 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3741 Provided for backwards compatibility."
3742 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3743 (not (save-excursion (set-buffer gnus-summary-buffer)
3744 gnus-have-all-headers)))
3745 (not gnus-inhibit-hiding))
3746 (gnus-article-hide-headers)))
3750 (defun gnus-output-to-file (file-name)
3751 "Append the current article to a file named FILE-NAME."
3752 (let ((artbuf (current-buffer)))
3754 (insert-buffer-substring artbuf)
3755 ;; Append newline at end of the buffer as separator, and then
3757 (goto-char (point-max))
3759 (write-region-as-binary (point-min) (point-max) file-name 'append)
3762 (defun gnus-narrow-to-page (&optional arg)
3763 "Narrow the article buffer to a page.
3764 If given a numerical ARG, move forward ARG pages."
3766 (setq arg (if arg (prefix-numeric-value arg) 0))
3768 (set-buffer gnus-article-buffer)
3769 (goto-char (point-min))
3771 ;; Remove any old next/prev buttons.
3772 (when (gnus-visual-p 'page-marker)
3773 (let ((buffer-read-only nil))
3774 (gnus-remove-text-with-property 'gnus-prev)
3775 (gnus-remove-text-with-property 'gnus-next)))
3778 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3780 (re-search-forward page-delimiter nil 'move arg)))
3781 (goto-char (match-end 0)))
3784 (if (re-search-forward page-delimiter nil 'move)
3787 (when (and (gnus-visual-p 'page-marker)
3788 (not (= (point-min) 1)))
3790 (goto-char (point-min))
3791 (gnus-insert-prev-page-button)))
3792 (when (and (gnus-visual-p 'page-marker)
3793 (< (+ (point-max) 2) (buffer-size)))
3795 (goto-char (point-max))
3796 (gnus-insert-next-page-button)))))
3798 ;; Article mode commands
3800 (defun gnus-article-goto-next-page ()
3801 "Show the next page of the article."
3803 (when (gnus-article-next-page)
3804 (goto-char (point-min))
3805 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3807 (defun gnus-article-goto-prev-page ()
3808 "Show the next page of the article."
3810 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3811 (gnus-article-prev-page nil)))
3813 (defun gnus-article-next-page (&optional lines)
3814 "Show the next page of the current article.
3815 If end of article, return non-nil. Otherwise return nil.
3816 Argument LINES specifies lines to be scrolled up."
3818 (let ((start (window-start))
3819 end-of-buffer end-of-page)
3821 (move-to-window-line -1)
3822 (if (<= (point) start)
3825 (setq start (point)))
3828 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3829 (setq end-of-buffer t))
3831 (setq end-of-page t)))
3833 (move-to-window-line lines)
3834 (unless (search-backward "\n\n" nil t)
3835 (setq start (point)))))
3836 (cond (end-of-buffer t)
3838 (gnus-narrow-to-page 1)
3842 (set-window-start (selected-window) start)
3846 (defun gnus-article-prev-page (&optional lines)
3847 "Show previous page of current article.
3848 Argument LINES specifies lines to be scrolled down."
3850 (let (beginning-of-buffer beginning-of-page)
3852 (move-to-window-line 0)
3853 (cond ((eq 1 (point))
3854 (setq beginning-of-buffer t))
3856 (setq beginning-of-page t))))
3857 (cond (beginning-of-buffer)
3859 (gnus-narrow-to-page -1))
3863 (beginning-of-buffer
3864 (goto-char (point-min))))))))
3866 (defun gnus-article-refer-article ()
3867 "Read article specified by message-id around point."
3869 (let ((point (point)))
3870 (search-forward ">" nil t) ;Move point to end of "<....>".
3871 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3872 (let ((message-id (match-string 1)))
3874 (set-buffer gnus-summary-buffer)
3875 (gnus-summary-refer-article message-id))
3877 (error "No references around point"))))
3879 (defun gnus-article-show-summary ()
3880 "Reconfigure windows to show summary buffer."
3882 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3883 (error "There is no summary buffer for this article buffer")
3884 (gnus-article-set-globals)
3885 (gnus-configure-windows 'article)
3886 (gnus-summary-goto-subject gnus-current-article)
3887 (gnus-summary-position-point)))
3889 (defun gnus-article-describe-briefly ()
3890 "Describe article mode commands briefly."
3892 (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")))
3894 (defun gnus-article-summary-command ()
3895 "Execute the last keystroke in the summary buffer."
3897 (let ((obuf (current-buffer))
3898 (owin (current-window-configuration))
3900 (switch-to-buffer gnus-article-current-summary 'norecord)
3901 (setq func (lookup-key (current-local-map) (this-command-keys)))
3902 (call-interactively func)
3904 (set-window-configuration owin)
3905 (set-window-point (get-buffer-window (current-buffer)) (point))))
3907 (defun gnus-article-summary-command-nosave ()
3908 "Execute the last keystroke in the summary buffer."
3911 (pop-to-buffer gnus-article-current-summary 'norecord)
3912 (setq func (lookup-key (current-local-map) (this-command-keys)))
3913 (call-interactively func)))
3915 (defun gnus-article-check-buffer ()
3916 "Beep if not in an article buffer."
3917 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3918 (error "Command invoked outside of a Gnus article buffer")))
3920 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3921 "Read a summary buffer key sequence and execute it from the article buffer."
3923 (gnus-article-check-buffer)
3925 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3926 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3927 "=" "^" "\M-^" "|"))
3933 '("n" "Gn" "p" "Gp"))
3936 (set-buffer gnus-article-current-summary)
3937 (let (gnus-pick-mode)
3938 (push (or key last-command-event) unread-command-events)
3939 (setq keys (static-if (featurep 'xemacs)
3940 (events-to-keys (read-key-sequence nil))
3941 (read-key-sequence nil)))))
3944 (if (or (member keys nosaves)
3945 (member keys nosave-but-article)
3946 (member keys nosave-in-article))
3948 (save-window-excursion
3949 (pop-to-buffer gnus-article-current-summary 'norecord)
3950 ;; We disable the pick minor mode commands.
3951 (let (gnus-pick-mode)
3952 (setq func (lookup-key (current-local-map) keys))))
3955 (unless (member keys nosave-in-article)
3956 (set-buffer gnus-article-current-summary))
3957 (call-interactively func)
3958 (setq new-sum-point (point)))
3959 (when (member keys nosave-but-article)
3960 (pop-to-buffer gnus-article-buffer 'norecord)))
3961 ;; These commands should restore window configuration.
3962 (let ((obuf (current-buffer))
3963 (owin (current-window-configuration))
3965 (summary gnus-article-current-summary)
3966 func in-buffer selected)
3967 (if not-restore-window
3968 (pop-to-buffer summary 'norecord)
3969 (switch-to-buffer summary 'norecord))
3970 (setq in-buffer (current-buffer))
3971 ;; We disable the pick minor mode commands.
3972 (if (setq func (let (gnus-pick-mode)
3973 (lookup-key (current-local-map) keys)))
3975 (call-interactively func)
3976 (setq new-sum-point (point)))
3978 (when (eq in-buffer (current-buffer))
3979 (setq selected (gnus-summary-select-article))
3981 (unless not-restore-window
3982 (set-window-configuration owin))
3983 (when (eq selected 'old)
3985 (set-window-start (get-buffer-window (current-buffer))
3987 (set-window-point (get-buffer-window (current-buffer))
3989 (let ((win (get-buffer-window gnus-article-current-summary)))
3991 (set-window-point win new-sum-point))))))))
3993 (defun gnus-article-hide (&optional arg force)
3994 "Hide all the gruft in the current article.
3995 This means that PGP stuff, signatures, cited text and (some)
3996 headers will be hidden.
3997 If given a prefix, show the hidden text instead."
3998 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3999 (gnus-article-hide-headers arg)
4000 (gnus-article-hide-list-identifiers arg)
4001 (gnus-article-hide-pgp arg)
4002 (gnus-article-hide-citation-maybe arg force)
4003 (gnus-article-hide-signature arg))
4005 (defun gnus-article-maybe-highlight ()
4006 "Do some article highlighting if article highlighting is requested."
4007 (when (gnus-visual-p 'article-highlight 'highlight)
4008 (gnus-article-highlight-some)))
4010 (defun gnus-check-group-server ()
4011 ;; Make sure the connection to the server is alive.
4012 (unless (gnus-server-opened
4013 (gnus-find-method-for-group gnus-newsgroup-name))
4014 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4015 (gnus-request-group gnus-newsgroup-name t)))
4017 (defun gnus-request-article-this-buffer (article group)
4018 "Get an article and insert it into this buffer."
4019 (let (do-update-line sparse-header)
4023 (gnus-kill-all-overlays)
4024 (setq group (or group gnus-newsgroup-name))
4026 ;; Using `gnus-request-article' directly will insert the article into
4027 ;; `nntp-server-buffer' - so we'll save some time by not having to
4028 ;; copy it from the server buffer into the article buffer.
4030 ;; We only request an article by message-id when we do not have the
4031 ;; headers for it, so we'll have to get those.
4032 (when (stringp article)
4033 (let ((gnus-override-method gnus-refer-article-method))
4034 (gnus-read-header article)))
4036 ;; If the article number is negative, that means that this article
4037 ;; doesn't belong in this newsgroup (possibly), so we find its
4038 ;; message-id and request it by id instead of number.
4039 (when (and (numberp article)
4041 (get-buffer gnus-summary-buffer)
4042 (gnus-buffer-exists-p gnus-summary-buffer))
4044 (set-buffer gnus-summary-buffer)
4045 (let ((header (gnus-summary-article-header article)))
4048 ((memq article gnus-newsgroup-sparse)
4049 ;; This is a sparse gap article.
4050 (setq do-update-line article)
4051 (setq article (mail-header-id header))
4052 (let ((gnus-override-method gnus-refer-article-method))
4053 (setq sparse-header (gnus-read-header article)))
4054 (setq gnus-newsgroup-sparse
4055 (delq article gnus-newsgroup-sparse)))
4057 ;; It's a real article.
4058 (setq article (mail-header-id header)))
4060 ;; It is an extracted pseudo-article.
4061 (setq article 'pseudo)
4062 (gnus-request-pseudo-article header))))
4064 (let ((method (gnus-find-method-for-group
4065 gnus-newsgroup-name)))
4066 (when (and (eq (car method) 'nneething)
4069 (file-name-as-directory
4070 (or (cadr (assq 'nneething-address method))
4072 (mail-header-subject header))))
4073 (when (file-directory-p dir)
4074 (setq article 'nneething)
4075 (gnus-group-enter-directory dir))))))))
4078 ;; Refuse to select canceled articles.
4079 ((and (numberp article)
4081 (get-buffer gnus-summary-buffer)
4082 (gnus-buffer-exists-p gnus-summary-buffer)
4083 (eq (cdr (save-excursion
4084 (set-buffer gnus-summary-buffer)
4085 (assq article gnus-newsgroup-reads)))
4086 gnus-canceled-mark))
4088 ;; Check the backlog.
4089 ((and gnus-keep-backlog
4090 (gnus-backlog-request-article group article (current-buffer)))
4092 ;; Check asynchronous pre-fetch.
4093 ((gnus-async-request-fetched-article group article (current-buffer))
4094 (gnus-async-prefetch-next group article gnus-summary-buffer)
4095 (when (and (numberp article) gnus-keep-backlog)
4096 (gnus-backlog-enter-article group article (current-buffer)))
4099 ((and gnus-use-cache
4101 (gnus-cache-request-article article group))
4103 ;; Get the article and put into the article buffer.
4104 ((or (stringp article) (numberp article))
4105 (let ((gnus-override-method
4106 (and (stringp article) gnus-refer-article-method))
4107 (buffer-read-only nil))
4109 (gnus-kill-all-overlays)
4110 (gnus-check-group-server)
4111 (when (gnus-request-article article group (current-buffer))
4112 (when (numberp article)
4113 (gnus-async-prefetch-next group article gnus-summary-buffer)
4114 (when gnus-keep-backlog
4115 (gnus-backlog-enter-article
4116 group article (current-buffer))))
4121 ;; Associate this article with the current summary buffer.
4122 (setq gnus-article-current-summary gnus-summary-buffer)
4124 ;; Take the article from the original article buffer
4125 ;; and place it in the buffer it's supposed to be in.
4126 (when (and (get-buffer gnus-article-buffer)
4127 (equal (buffer-name (current-buffer))
4128 (buffer-name (get-buffer gnus-article-buffer))))
4130 (if (get-buffer gnus-original-article-buffer)
4131 (set-buffer gnus-original-article-buffer)
4132 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4133 (buffer-disable-undo)
4134 (setq major-mode 'gnus-original-article-mode)
4135 (setq buffer-read-only t))
4136 (let (buffer-read-only)
4138 (insert-buffer-substring gnus-article-buffer))
4139 (setq gnus-original-article (cons group article)))
4142 (run-hooks 'gnus-article-decode-hook)
4143 ;; Mark article as decoded or not.
4144 (setq gnus-article-decoded-p gnus-article-decode-hook))
4146 ;; Update sparse articles.
4147 (when (and do-update-line
4148 (or (numberp article)
4150 (let ((buf (current-buffer)))
4151 (set-buffer gnus-summary-buffer)
4152 (gnus-summary-update-article do-update-line sparse-header)
4153 (gnus-summary-goto-subject do-update-line nil t)
4154 (set-window-point (get-buffer-window (current-buffer) t)
4156 (set-buffer buf))))))
4162 (defcustom gnus-article-edit-mode-hook nil
4163 "Hook run in article edit mode buffers."
4164 :group 'gnus-article-various
4167 (defcustom gnus-article-edit-article-setup-function
4168 'gnus-article-mime-edit-article-setup
4169 "Function called to setup an editing article buffer."
4170 :group 'gnus-article-various
4173 (defvar gnus-article-edit-done-function nil)
4175 (defvar gnus-article-edit-mode-map nil)
4177 ;; Should we be using derived.el for this?
4178 (unless gnus-article-edit-mode-map
4179 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4180 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4182 (gnus-define-keys gnus-article-edit-mode-map
4183 "\C-c\C-c" gnus-article-edit-done
4184 "\C-c\C-k" gnus-article-edit-exit)
4186 (gnus-define-keys (gnus-article-edit-wash-map
4187 "\C-c\C-w" gnus-article-edit-mode-map)
4188 "f" gnus-article-edit-full-stops))
4190 (defun gnus-article-edit-mode ()
4191 "Major mode for editing articles.
4192 This is an extended text-mode.
4194 \\{gnus-article-edit-mode-map}"
4196 (setq major-mode 'gnus-article-edit-mode)
4197 (setq mode-name "Article Edit")
4198 (use-local-map gnus-article-edit-mode-map)
4199 (make-local-variable 'gnus-article-edit-done-function)
4200 (make-local-variable 'gnus-prev-winconf)
4201 (setq buffer-read-only nil)
4202 (buffer-enable-undo)
4204 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4206 (defun gnus-article-edit (&optional force)
4207 "Edit the current article.
4208 This will have permanent effect only in mail groups.
4209 If FORCE is non-nil, allow editing of articles even in read-only
4212 (when (and (not force)
4213 (gnus-group-read-only-p))
4214 (error "The current newsgroup does not support article editing"))
4215 (gnus-article-date-original)
4216 (gnus-article-edit-article
4218 `(lambda (no-highlight)
4220 (gnus-summary-edit-article-done
4221 ,(or (mail-header-references gnus-current-headers) "")
4222 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4224 (defun gnus-article-edit-article (start-func exit-func)
4225 "Start editing the contents of the current article buffer."
4226 (let ((winconf (current-window-configuration)))
4227 (set-buffer gnus-article-buffer)
4228 (gnus-article-edit-mode)
4229 (funcall start-func)
4230 (gnus-configure-windows 'edit-article)
4231 (setq gnus-article-edit-done-function exit-func)
4232 (setq gnus-prev-winconf winconf)
4233 (when gnus-article-edit-article-setup-function
4234 (funcall gnus-article-edit-article-setup-function))
4235 (gnus-message 6 "C-c C-c to end edits")))
4237 (defun gnus-article-edit-done (&optional arg)
4238 "Update the article edits and exit."
4243 (when (article-goto-body)
4244 (let ((lines (count-lines (point) (point-max)))
4245 (length (- (point-max) (point)))
4246 (case-fold-search t)
4247 (body (copy-marker (point))))
4248 (goto-char (point-min))
4249 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4250 (delete-region (match-beginning 1) (match-end 1))
4251 (insert (number-to-string length)))
4252 (goto-char (point-min))
4253 (when (re-search-forward
4254 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4255 (delete-region (match-beginning 1) (match-end 1))
4256 (insert (number-to-string length)))
4257 (goto-char (point-min))
4258 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4259 (delete-region (match-beginning 1) (match-end 1))
4260 (insert (number-to-string lines)))))))
4261 (let ((func gnus-article-edit-done-function)
4262 (buf (current-buffer))
4263 (start (window-start)))
4264 (remove-hook 'gnus-article-mode-hook
4265 'gnus-article-mime-edit-article-unwind)
4266 (gnus-article-edit-exit)
4269 (let ((buffer-read-only nil))
4271 ;; The cache and backlog have to be flushed somewhat.
4272 (when gnus-keep-backlog
4273 (gnus-backlog-remove-article
4274 (car gnus-article-current) (cdr gnus-article-current)))
4275 ;; Flush original article as well.
4277 (when (get-buffer gnus-original-article-buffer)
4278 (set-buffer gnus-original-article-buffer)
4279 (setq gnus-original-article nil)))
4280 (when gnus-use-cache
4281 (gnus-cache-update-article
4282 (car gnus-article-current) (cdr gnus-article-current))))
4284 (set-window-start (get-buffer-window buf) start)
4285 (set-window-point (get-buffer-window buf) (point))))
4287 (defun gnus-article-edit-exit ()
4288 "Exit the article editing without updating."
4290 ;; We remove all text props from the article buffer.
4291 (let ((buf (format "%s" (buffer-string)))
4292 (curbuf (current-buffer))
4294 (window-start (window-start)))
4297 (let ((winconf gnus-prev-winconf))
4299 (set-window-configuration winconf)
4300 ;; Tippy-toe some to make sure that point remains where it was.
4301 (save-current-buffer
4303 (set-window-start (get-buffer-window (current-buffer)) window-start)
4306 (defun gnus-article-edit-full-stops ()
4307 "Interactively repair spacing at end of sentences."
4310 (goto-char (point-min))
4311 (search-forward-regexp "^$" nil t)
4312 (let ((case-fold-search nil))
4313 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4316 ;;; Article editing with MIME-Edit
4319 (defcustom gnus-article-mime-edit-article-setup-hook nil
4320 "Hook run after setting up a MIME editing article buffer."
4321 :group 'gnus-article-various
4324 (defun gnus-article-mime-edit-article-unwind ()
4325 "Unwind `gnus-article-buffer' if article editing was given up."
4326 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4327 (when mime-edit-mode-flag
4328 (mime-edit-exit 'nomime 'no-error)
4330 (when (featurep 'font-lock)
4331 (setq font-lock-defaults nil)
4332 (font-lock-mode 0)))
4334 (defun gnus-article-mime-edit-article-setup ()
4335 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4336 after replacing with the original article."
4337 (setq gnus-show-mime t)
4338 (setq gnus-article-edit-done-function
4339 `(lambda (&rest args)
4340 (when mime-edit-mode-flag
4343 (goto-char (point-min))
4344 (let (case-fold-search)
4345 (when (re-search-forward
4346 (format "^%s$" (regexp-quote mail-header-separator))
4348 (replace-match "")))
4349 (when (featurep 'font-lock)
4350 (setq font-lock-defaults nil)
4352 (apply ,gnus-article-edit-done-function args)
4353 (set-buffer gnus-original-article-buffer)
4355 (insert-buffer gnus-article-buffer)
4356 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4357 (gnus-article-prepare-display)))
4358 (substitute-key-definition
4359 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4360 gnus-article-edit-mode-map)
4362 (insert-buffer gnus-original-article-buffer)
4364 (when (featurep 'font-lock)
4365 (set (make-local-variable 'font-lock-defaults)
4366 '(message-font-lock-keywords t))
4367 (font-lock-set-defaults)
4368 (turn-on-font-lock))
4369 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4370 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4372 (defun gnus-article-mime-edit-exit ()
4373 "Exit the article MIME editing without updating."
4375 (let ((winconf gnus-prev-winconf)
4377 (when mime-edit-mode-flag
4380 (goto-char (point-min))
4381 (let (case-fold-search)
4382 (when (re-search-forward
4383 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4384 (replace-match "")))
4385 (when (featurep 'font-lock)
4386 (setq font-lock-defaults nil)
4388 ;; We remove all text props from the article buffer.
4389 (setq buf (format "%s" (buffer-string)))
4390 (set-buffer (get-buffer-create gnus-original-article-buffer))
4393 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4394 (gnus-article-prepare-display)
4395 (set-window-configuration winconf)))
4398 ;;; Article highlights
4401 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4403 ;;; Internal Variables:
4405 (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\\)"
4406 "Regular expression that matches URLs."
4407 :group 'gnus-article-buttons
4410 (defcustom gnus-button-alist
4411 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4412 0 t gnus-button-message-id 2)
4413 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4414 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4416 gnus-button-fetch-group 4)
4417 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4418 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4419 t gnus-button-message-id 3)
4420 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4421 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4422 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4423 ;; This is how URLs _should_ be embedded in text...
4424 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
4426 (,gnus-button-url-regexp 0 t gnus-button-url 0))
4427 "*Alist of regexps matching buttons in article bodies.
4429 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4430 REGEXP: is the string matching text around the button,
4431 BUTTON: is the number of the regexp grouping actually matching the button,
4432 FORM: is a lisp expression which must eval to true for the button to
4434 CALLBACK: is the function to call when the user push this button, and each
4435 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4437 CALLBACK can also be a variable, in that case the value of that
4438 variable it the real callback function."
4439 :group 'gnus-article-buttons
4440 :type '(repeat (list regexp
4441 (integer :tag "Button")
4443 (function :tag "Callback")
4446 (integer :tag "Regexp group")))))
4448 (defcustom gnus-header-button-alist
4449 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4450 0 t gnus-button-message-id 0)
4451 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4452 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4453 0 t gnus-button-mailto 0)
4454 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4455 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4456 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4457 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4458 gnus-button-message-id 3))
4459 "*Alist of headers and regexps to match buttons in article heads.
4461 This alist is very similar to `gnus-button-alist', except that each
4462 alist has an additional HEADER element first in each entry:
4464 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4466 HEADER is a regexp to match a header. For a fuller explanation, see
4467 `gnus-button-alist'."
4468 :group 'gnus-article-buttons
4469 :group 'gnus-article-headers
4470 :type '(repeat (list (regexp :tag "Header")
4472 (integer :tag "Button")
4474 (function :tag "Callback")
4477 (integer :tag "Regexp group")))))
4479 (defvar gnus-button-regexp nil)
4480 (defvar gnus-button-marker-list nil)
4481 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4483 (defvar gnus-button-last nil)
4484 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4488 (defun gnus-article-push-button (event)
4489 "Check text under the mouse pointer for a callback function.
4490 If the text under the mouse pointer has a `gnus-callback' property,
4491 call it with the value of the `gnus-data' text property."
4493 (set-buffer (window-buffer (posn-window (event-start event))))
4494 (let* ((pos (posn-point (event-start event)))
4495 (data (get-text-property pos 'gnus-data))
4496 (fun (get-text-property pos 'gnus-callback)))
4499 (funcall fun data))))
4501 (defun gnus-article-press-button ()
4502 "Check text at point for a callback function.
4503 If the text at point has a `gnus-callback' property,
4504 call it with the value of the `gnus-data' text property."
4506 (let* ((data (get-text-property (point) 'gnus-data))
4507 (fun (get-text-property (point) 'gnus-callback)))
4509 (funcall fun data))))
4511 (defun gnus-article-prev-button (n)
4512 "Move point to N buttons backward.
4513 If N is negative, move forward instead."
4515 (gnus-article-next-button (- n)))
4517 (defun gnus-article-next-button (n)
4518 "Move point to N buttons forward.
4519 If N is negative, move backward instead."
4521 (let ((function (if (< n 0) 'previous-single-property-change
4522 'next-single-property-change))
4523 (inhibit-point-motion-hooks t)
4525 (limit (if (< n 0) (point-min) (point-max))))
4527 (while (and (not (= limit (point)))
4529 ;; Skip past the current button.
4530 (when (get-text-property (point) 'gnus-callback)
4531 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4532 ;; Go to the next (or previous) button.
4533 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4534 ;; Put point at the start of the button.
4535 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4536 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4537 ;; Skip past intangible buttons.
4538 (when (get-text-property (point) 'intangible)
4542 (gnus-message 5 "No more buttons"))
4545 (defun gnus-article-highlight (&optional force)
4546 "Highlight current article.
4547 This function calls `gnus-article-highlight-headers',
4548 `gnus-article-highlight-citation',
4549 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4550 do the highlighting. See the documentation for those functions."
4551 (interactive (list 'force))
4552 (gnus-article-highlight-headers)
4553 (gnus-article-highlight-citation force)
4554 (gnus-article-highlight-signature)
4555 (gnus-article-add-buttons force)
4556 (gnus-article-add-buttons-to-head))
4558 (defun gnus-article-highlight-some (&optional force)
4559 "Highlight current article.
4560 This function calls `gnus-article-highlight-headers',
4561 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4562 do the highlighting. See the documentation for those functions."
4563 (interactive (list 'force))
4564 (gnus-article-highlight-headers)
4565 (gnus-article-highlight-signature)
4566 (gnus-article-add-buttons))
4568 (defun gnus-article-highlight-headers ()
4569 "Highlight article headers as specified by `gnus-header-face-alist'."
4572 (set-buffer gnus-article-buffer)
4574 (let ((alist gnus-header-face-alist)
4575 (buffer-read-only nil)
4576 (case-fold-search t)
4577 (inhibit-point-motion-hooks t)
4578 entry regexp header-face field-face from hpoints fpoints)
4579 (article-narrow-to-head)
4580 (while (setq entry (pop alist))
4581 (goto-char (point-min))
4582 (setq regexp (concat "^\\("
4583 (if (string-equal "" (nth 0 entry))
4587 header-face (nth 1 entry)
4588 field-face (nth 2 entry))
4589 (while (and (re-search-forward regexp nil t)
4593 (unless (search-forward ":" nil t)
4595 (when (and header-face
4596 (not (memq (point) hpoints)))
4597 (push (point) hpoints)
4598 (gnus-put-text-property from (point) 'face header-face))
4599 (when (and field-face
4600 (not (memq (setq from (point)) fpoints)))
4602 (if (re-search-forward "^[^ \t]" nil t)
4604 (goto-char (point-max)))
4605 (gnus-put-text-property from (point) 'face field-face))))))))
4607 (defun gnus-article-highlight-signature ()
4608 "Highlight the signature in an article.
4609 It does this by highlighting everything after
4610 `gnus-signature-separator' using `gnus-signature-face'."
4612 (when gnus-signature-face
4614 (set-buffer gnus-article-buffer)
4615 (let ((buffer-read-only nil)
4616 (inhibit-point-motion-hooks t))
4618 (when (gnus-article-narrow-to-signature)
4619 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4620 'face gnus-signature-face)))))))
4622 (defun gnus-article-buttonize-signature ()
4623 "Add button to the signature."
4626 (set-buffer gnus-article-buffer)
4627 (let ((buffer-read-only nil)
4628 (inhibit-point-motion-hooks t))
4629 (when (gnus-article-search-signature)
4630 (gnus-article-add-button (match-beginning 0) (match-end 0)
4631 'gnus-signature-toggle
4632 (set-marker (make-marker)
4633 (1+ (match-end 0))))))))
4635 (defun gnus-button-in-region-p (b e prop)
4636 "Say whether PROP exists in the region."
4637 (text-property-not-all b e prop nil))
4639 (defun gnus-article-add-buttons (&optional force)
4640 "Find external references in the article and make buttons of them.
4641 \"External references\" are things like Message-IDs and URLs, as
4642 specified by `gnus-button-alist'."
4643 (interactive (list 'force))
4645 (set-buffer gnus-article-buffer)
4646 (let ((buffer-read-only nil)
4647 (inhibit-point-motion-hooks t)
4648 (case-fold-search t)
4649 (alist gnus-button-alist)
4651 ;; Remove all old markers.
4652 (let (marker entry new-list)
4653 (while (setq marker (pop gnus-button-marker-list))
4654 (if (or (< marker (point-min)) (>= marker (point-max)))
4655 (push marker new-list)
4657 (when (setq entry (gnus-button-entry))
4658 (put-text-property (match-beginning (nth 1 entry))
4659 (match-end (nth 1 entry))
4660 'gnus-callback nil))
4661 (set-marker marker nil)))
4662 (setq gnus-button-marker-list new-list))
4663 ;; We skip the headers.
4666 (while (setq entry (pop alist))
4667 (setq regexp (car entry))
4669 (while (re-search-forward regexp nil t)
4670 (let* ((start (and entry (match-beginning (nth 1 entry))))
4671 (end (and entry (match-end (nth 1 entry))))
4672 (from (match-beginning 0)))
4673 (when (and (or (eq t (nth 2 entry))
4674 (eval (nth 2 entry)))
4675 (not (gnus-button-in-region-p
4676 start end 'gnus-callback)))
4677 ;; That optional form returned non-nil, so we add the
4679 (gnus-article-add-button
4680 start end 'gnus-button-push
4681 (car (push (set-marker (make-marker) from)
4682 gnus-button-marker-list))))))))))
4684 ;; Add buttons to the head of an article.
4685 (defun gnus-article-add-buttons-to-head ()
4686 "Add buttons to the head of the article."
4689 (set-buffer gnus-article-buffer)
4691 (let ((buffer-read-only nil)
4692 (inhibit-point-motion-hooks t)
4693 (case-fold-search t)
4694 (alist gnus-header-button-alist)
4696 (article-narrow-to-head)
4698 ;; Each alist entry.
4699 (setq entry (car alist)
4701 (goto-char (point-min))
4702 (while (re-search-forward (car entry) nil t)
4703 ;; Each header matching the entry.
4704 (setq beg (match-beginning 0))
4705 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4706 (match-beginning 0))
4709 (while (re-search-forward (nth 1 entry) end t)
4710 ;; Each match within a header.
4711 (let* ((entry (cdr entry))
4712 (start (match-beginning (nth 1 entry)))
4713 (end (match-end (nth 1 entry)))
4714 (form (nth 2 entry)))
4715 (goto-char (match-end 0))
4717 (gnus-article-add-button
4718 start end (nth 3 entry)
4719 (buffer-substring (match-beginning (nth 4 entry))
4720 (match-end (nth 4 entry)))))))
4721 (goto-char end)))))))
4723 ;;; External functions:
4725 (defun gnus-article-add-button (from to fun &optional data)
4726 "Create a button between FROM and TO with callback FUN and data DATA."
4727 (when gnus-article-button-face
4728 (gnus-overlay-put (gnus-make-overlay from to)
4729 'face gnus-article-button-face))
4730 (gnus-add-text-properties
4732 (nconc (and gnus-article-mouse-face
4733 (list gnus-mouse-face-prop gnus-article-mouse-face))
4734 (list 'gnus-callback fun)
4735 (and data (list 'gnus-data data)))))
4737 ;;; Internal functions:
4739 (defun gnus-article-set-globals ()
4741 (set-buffer gnus-summary-buffer)
4742 (gnus-set-global-variables)))
4744 (defun gnus-signature-toggle (end)
4746 (set-buffer gnus-article-buffer)
4747 (let ((buffer-read-only nil)
4748 (inhibit-point-motion-hooks t)
4749 (limit (next-single-property-change end 'mime-view-entity
4751 (if (get-text-property end 'invisible)
4752 (gnus-article-unhide-text end limit)
4753 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4755 (defun gnus-button-entry ()
4756 ;; Return the first entry in `gnus-button-alist' matching this place.
4757 (let ((alist gnus-button-alist)
4760 (setq entry (pop alist))
4761 (if (looking-at (car entry))
4766 (defun gnus-button-push (marker)
4767 ;; Push button starting at MARKER.
4770 (let* ((entry (gnus-button-entry))
4771 (inhibit-point-motion-hooks t)
4773 (args (mapcar (lambda (group)
4774 (let ((string (match-string group)))
4775 (gnus-set-text-properties
4776 0 (length string) nil string)
4783 (fboundp (symbol-value fun)))
4784 (apply (symbol-value fun) args))
4786 (gnus-message 1 "You must define `%S' to use this button"
4787 (cons fun args)))))))
4789 (defun gnus-button-message-id (message-id)
4792 (set-buffer gnus-summary-buffer)
4793 (gnus-summary-refer-article message-id)))
4795 (defun gnus-button-fetch-group (address)
4796 "Fetch GROUP specified by ADDRESS."
4797 (if (not (string-match "[:/]" address))
4798 ;; This is just a simple group url.
4799 (gnus-group-read-ephemeral-group address gnus-select-method)
4800 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4802 (error "Can't parse %s" address)
4803 (gnus-group-read-ephemeral-group
4804 (match-string 4 address)
4805 `(nntp ,(match-string 1 address)
4806 (nntp-address ,(match-string 1 address))
4807 (nntp-port-number ,(if (match-end 3)
4808 (match-string 3 address)
4811 (defun gnus-url-parse-query-string (query &optional downcase)
4812 (let (retval pairs cur key val)
4813 (setq pairs (split-string query "&"))
4815 (setq cur (car pairs)
4817 (if (not (string-match "=" cur))
4819 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4820 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4822 (setq key (downcase key)))
4823 (setq cur (assoc key retval))
4825 (setcdr cur (cons val (cdr cur)))
4826 (setq retval (cons (list key val) retval)))))
4829 (defun gnus-url-unhex (x)
4836 (defun gnus-url-unhex-string (str &optional allow-newlines)
4837 "Remove %XXX embedded spaces, etc in a url.
4838 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4839 decoding of carriage returns and line feeds in the string, which is normally
4840 forbidden in URL encoding."
4841 (setq str (or str ""))
4843 (case-fold-search t))
4844 (while (string-match "%[0-9a-f][0-9a-f]" str)
4845 (let* ((start (match-beginning 0))
4846 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4848 (gnus-url-unhex (elt str (+ start 2))))))
4850 tmp (substring str 0 start)
4853 (char-to-string code))
4854 ((or (= code ?\n) (= code ?\r))
4856 (t (char-to-string code))))
4857 str (substring str (match-end 0)))))
4858 (setq tmp (concat tmp str))
4861 (defun gnus-url-mailto (url)
4862 ;; Send mail to someone
4863 (when (string-match "mailto:/*\\(.*\\)" url)
4864 (setq url (substring url (match-beginning 1) nil)))
4865 (let (to args subject func)
4866 (if (string-match (regexp-quote "?") url)
4867 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4868 args (gnus-url-parse-query-string
4869 (substring url (match-end 0) nil) t))
4870 (setq to (gnus-url-unhex-string url)))
4871 (setq args (cons (list "to" to) args)
4872 subject (cdr-safe (assoc "subject" args)))
4873 (gnus-setup-message 'reply
4876 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4879 (message-position-on-field (caar args)))
4880 (insert (mapconcat 'identity (cdar args) ", "))
4881 (setq args (cdr args)))
4884 (message-goto-subject)))))
4886 (defun gnus-button-mailto (address)
4888 (set-buffer (gnus-copy-article-buffer))
4889 (gnus-setup-message 'reply
4890 (message-reply address)))
4892 (defun gnus-button-reply (address)
4893 ;; Reply to ADDRESS.
4894 (gnus-setup-message 'reply
4895 (message-reply address)))
4897 (defun gnus-button-url (address)
4899 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4900 (if (listp browse-url-browser-function)
4901 (browse-url address)
4902 (funcall browse-url-browser-function address)))
4904 (defun gnus-button-embedded-url (address)
4906 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4907 (if (listp browse-url-browser-function)
4908 (browse-url (gnus-strip-whitespace address))
4909 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4911 ;;; Next/prev buttons in the article buffer.
4913 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4914 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4916 (defvar gnus-prev-page-map nil)
4917 (unless gnus-prev-page-map
4918 (setq gnus-prev-page-map (make-sparse-keymap))
4919 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4920 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4922 (static-if (featurep 'xemacs)
4923 (defun gnus-insert-prev-page-button ()
4924 (let ((buffer-read-only nil))
4926 gnus-prev-page-line-format nil
4927 `(gnus-prev t local-map ,gnus-prev-page-map
4928 gnus-callback gnus-article-button-prev-page
4929 article-type annotation))))
4930 (defun gnus-insert-prev-page-button ()
4931 (let ((buffer-read-only nil)
4932 (situation (get-text-property (point-min) 'mime-view-situation)))
4933 (set-keymap-parent gnus-prev-page-map (current-local-map))
4935 gnus-prev-page-line-format nil
4936 `(gnus-prev t local-map ,gnus-prev-page-map
4937 gnus-callback gnus-article-button-prev-page
4938 article-type annotation
4939 mime-view-situation ,situation))))
4942 (defvar gnus-next-page-map nil)
4943 (unless gnus-next-page-map
4944 (setq gnus-next-page-map (make-sparse-keymap))
4945 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4946 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4948 (defun gnus-button-next-page ()
4949 "Go to the next page."
4951 (let ((win (selected-window)))
4952 (select-window (get-buffer-window gnus-article-buffer t))
4953 (gnus-article-next-page)
4954 (select-window win)))
4956 (defun gnus-button-prev-page ()
4957 "Go to the prev page."
4959 (let ((win (selected-window)))
4960 (select-window (get-buffer-window gnus-article-buffer t))
4961 (gnus-article-prev-page)
4962 (select-window win)))
4964 (static-if (featurep 'xemacs)
4965 (defun gnus-insert-next-page-button ()
4966 (let ((buffer-read-only nil))
4967 (gnus-eval-format gnus-next-page-line-format nil
4969 t local-map ,gnus-next-page-map
4970 gnus-callback gnus-article-button-next-page
4971 article-type annotation))))
4972 (defun gnus-insert-next-page-button ()
4973 (let ((buffer-read-only nil)
4974 (situation (get-text-property (point-min) 'mime-view-situation)))
4975 (set-keymap-parent gnus-next-page-map (current-local-map))
4976 (gnus-eval-format gnus-next-page-line-format nil
4978 t local-map ,gnus-next-page-map
4979 gnus-callback gnus-article-button-next-page
4980 article-type annotation
4981 mime-view-situation ,situation))))
4984 (defun gnus-article-button-next-page (arg)
4985 "Go to the next page."
4987 (let ((win (selected-window)))
4988 (select-window (get-buffer-window gnus-article-buffer t))
4989 (gnus-article-next-page)
4990 (select-window win)))
4992 (defun gnus-article-button-prev-page (arg)
4993 "Go to the prev page."
4995 (let ((win (selected-window)))
4996 (select-window (get-buffer-window gnus-article-buffer t))
4997 (gnus-article-prev-page)
4998 (select-window win)))
5000 (defvar gnus-decode-header-methods
5001 '(mail-decode-encoded-word-region)
5002 "List of methods used to decode headers.
5004 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
5005 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5006 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5007 whose names match REGEXP.
5010 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5011 mail-decode-encoded-word-region
5012 (\"chinese\" . rfc1843-decode-region))
5015 (defvar gnus-decode-header-methods-cache nil)
5017 (defun gnus-multi-decode-header (start end)
5018 "Apply the functions from `gnus-encoded-word-methods' that match."
5019 (unless (and gnus-decode-header-methods-cache
5020 (eq gnus-newsgroup-name
5021 (car gnus-decode-header-methods-cache)))
5022 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5025 (nconc gnus-decode-header-methods-cache (list x))
5026 (if (and gnus-newsgroup-name
5027 (string-match (car x) gnus-newsgroup-name))
5028 (nconc gnus-decode-header-methods-cache
5030 gnus-decode-header-methods))
5031 (let ((xlist gnus-decode-header-methods-cache))
5034 (narrow-to-region start end)
5036 (funcall (pop xlist) (point-min) (point-max))))))
5039 ;;; Treatment top-level handling.
5042 (defun gnus-treat-article (condition &optional part-number total-parts type)
5043 (let ((length (- (point-max) (point-min)))
5044 (alist gnus-treatment-function-alist)
5045 (article-goto-body-goes-to-point-min-p t)
5049 (let ((list gnus-article-treat-types))
5051 (when (string-match (pop list) type)
5052 (throw 'found t)))))))
5053 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5054 (entity (static-unless (featurep 'xemacs)
5055 (when (eq 'head condition)
5056 (get-text-property (point-min) 'mime-view-entity))))
5057 val elem buttonized)
5058 (gnus-run-hooks 'gnus-part-display-hook)
5059 (unless gnus-inhibit-treatment
5060 (while (setq elem (pop alist))
5061 (setq val (symbol-value (car elem)))
5062 (when (and (or (consp val)
5064 (gnus-treat-predicate val)
5065 (or (not (get (car elem) 'highlight))
5067 (when (and (not buttonized)
5069 '(gnus-treat-hide-signature
5070 gnus-treat-highlight-signature)))
5071 (gnus-article-buttonize-signature)
5072 (setq buttonized t))
5074 (funcall (cadr elem)))))
5075 ;; FSF Emacsen does not inherit the existing text properties
5076 ;; in the new text, so we should do it for `mime-view-entity'.
5077 (static-unless (featurep 'xemacs)
5079 (put-text-property (point-min) (point-max)
5080 'mime-view-entity entity))))))
5082 ;; Dynamic variables.
5083 (defvar part-number)
5084 (defvar total-parts)
5088 (defun gnus-treat-predicate (val)
5093 (stringp (car val)))
5094 (apply 'gnus-or (mapcar `(lambda (s)
5095 (string-match s ,(or gnus-newsgroup-name "")))
5098 (let ((pred (pop val)))
5101 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5103 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5105 (not (gnus-treat-predicate (car val))))
5107 (equal (car val) type))
5109 (error "%S is not a valid predicate" pred)))))
5119 (eq part-number total-parts))
5123 (error "%S is not a valid value" val))))
5129 (defun gnus-article-header-presentation-method (entity situation)
5130 (mime-insert-header entity)
5133 (set-alist 'mime-header-presentation-method-alist
5134 'gnus-original-article-mode
5135 #'gnus-article-header-presentation-method)
5137 (defun gnus-mime-preview-quitting-method ()
5138 (mime-preview-kill-buffer)
5139 (delete-other-windows)
5140 (gnus-article-show-summary)
5141 (gnus-summary-select-article gnus-show-all-headers t))
5143 (set-alist 'mime-preview-quitting-method-alist
5144 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5146 (set-alist 'mime-preview-following-method-alist
5147 'gnus-original-article-mode #'gnus-following-method)
5149 (set-alist 'mime-preview-over-to-previous-method-alist
5150 'gnus-original-article-mode
5152 (if (> (point-min) 1)
5153 (gnus-article-prev-page)
5154 (gnus-article-read-summary-keys
5155 nil (gnus-character-to-event ?P)))))
5157 (set-alist 'mime-preview-over-to-next-method-alist
5158 'gnus-original-article-mode'
5160 (if (< (point-max) (buffer-size))
5161 (gnus-article-next-page)
5162 (gnus-article-read-summary-keys
5163 nil (gnus-character-to-event ?N)))))
5173 (run-hooks 'gnus-art-load-hook)
5175 ;;; gnus-art.el ends here