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 "^X-Received:" "^Content-length:" "X-precedence:")
144 "*All headers that start with this regexp will be hidden.
145 This variable can also be a list of regexps of headers to be ignored.
146 If `gnus-visible-headers' is non-nil, this variable will be ignored."
147 :type '(choice :custom-show nil
150 :group 'gnus-article-hiding)
152 (defcustom gnus-visible-headers
153 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
154 "*All headers that do not match this regexp will be hidden.
155 This variable can also be a list of regexp of headers to remain visible.
156 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
157 :type '(repeat :value-to-internal (lambda (widget value)
158 (custom-split-regexp-maybe value))
159 :match (lambda (widget value)
161 (widget-editable-list-match widget value)))
163 :group 'gnus-article-hiding)
165 (defcustom gnus-sorted-header-list
166 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
167 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
168 "*This variable is a list of regular expressions.
169 If it is non-nil, headers that match the regular expressions will
170 be placed first in the article buffer in the sequence specified by
172 :type '(repeat regexp)
173 :group 'gnus-article-hiding)
175 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
176 "Headers that are only to be displayed if they have interesting data.
177 Possible values in this list are `empty', `newsgroups', `followup-to',
178 `reply-to', `date', `long-to', and `many-to'."
179 :type '(set (const :tag "Headers with no content." empty)
180 (const :tag "Newsgroups with only one group." newsgroups)
181 (const :tag "Followup-to identical to newsgroups." followup-to)
182 (const :tag "Reply-to identical to from." reply-to)
183 (const :tag "Date less than four days old." date)
184 (const :tag "Very long To header." long-to)
185 (const :tag "Multiple To headers." many-to))
186 :group 'gnus-article-hiding)
188 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
189 "Regexp matching signature separator.
190 This can also be a list of regexps. In that case, it will be checked
191 from head to tail looking for a separator. Searches will be done from
192 the end of the buffer."
193 :type '(repeat string)
194 :group 'gnus-article-signature)
196 (defcustom gnus-signature-limit nil
197 "Provide a limit to what is considered a signature.
198 If it is a number, no signature may not be longer (in characters) than
199 that number. If it is a floating point number, no signature may be
200 longer (in lines) than that number. If it is a function, the function
201 will be called without any parameters, and if it returns nil, there is
202 no signature in the buffer. If it is a string, it will be used as a
203 regexp. If it matches, the text in question is not a signature."
204 :type '(choice (integer :value 200)
206 (function :value fun)
207 (regexp :value ".*"))
208 :group 'gnus-article-signature)
210 (defcustom gnus-hidden-properties '(invisible t intangible t)
211 "Property list to use for hiding text."
213 :group 'gnus-article-hiding)
215 (defcustom gnus-article-x-face-command
216 (if (and (not gnus-xemacs)
218 (module-installed-p 'x-face-mule))
219 'x-face-mule-gnus-article-display-x-face
220 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
222 "*String or function to be executed to display an X-Face header.
223 If it is a string, the command will be executed in a sub-shell
224 asynchronously. The compressed face will be piped to this command."
225 :type 'string ;Leave function case to Lisp.
226 :group 'gnus-article-washing)
228 (defcustom gnus-article-x-face-too-ugly nil
229 "Regexp matching posters whose face shouldn't be shown automatically."
230 :type '(choice regexp (const nil))
231 :group 'gnus-article-washing)
233 (defcustom gnus-emphasis-alist
235 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
237 '(("_" "_" underline)
240 ("_/" "/_" underline-italic)
241 ("_\\*" "\\*_" underline-bold)
242 ("\\*/" "/\\*" bold-italic)
243 ("_\\*/" "/\\*_" underline-bold-italic))))
244 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
245 2 3 gnus-emphasis-underline)
249 (format format (car spec) (car (cdr spec)))
250 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
252 "*Alist that says how to fontify certain phrases.
253 Each item looks like this:
255 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
257 The first element is a regular expression to be matched. The second
258 is a number that says what regular expression grouping used to find
259 the entire emphasized word. The third is a number that says what
260 regexp grouping should be displayed and highlighted. The fourth
261 is the face used for highlighting."
262 :type '(repeat (list :value ("" 0 0 default)
264 (integer :tag "Match group")
265 (integer :tag "Emphasize group")
267 :group 'gnus-article-emphasis)
269 (defface gnus-emphasis-bold '((t (:bold t)))
270 "Face used for displaying strong emphasized text (*word*)."
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-italic '((t (:italic t)))
274 "Face used for displaying italic emphasized text (/word/)."
275 :group 'gnus-article-emphasis)
277 (defface gnus-emphasis-underline '((t (:underline t)))
278 "Face used for displaying underlined emphasized text (_word_)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
282 "Face used for displaying underlined bold emphasized text (_*word*_)."
283 :group 'gnus-article-emphasis)
285 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
286 "Face used for displaying underlined italic emphasized text (_/word/_)."
287 :group 'gnus-article-emphasis)
289 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
290 "Face used for displaying bold italic emphasized text (/*word*/)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-underline-bold-italic
294 '((t (:bold t :italic t :underline t)))
295 "Face used for displaying underlined bold italic emphasized text.
296 Esample: (_/*word*/_)."
297 :group 'gnus-article-emphasis)
299 (defface gnus-emphasis-highlight-words
300 '((t (:background "black" :foreground "yellow")))
301 "Face used for displaying highlighted words."
302 :group 'gnus-article-emphasis)
304 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
305 "Format for display of Date headers in article bodies.
306 See `format-time-string' for the possible values.
308 The variable can also be function, which should return a complete Date
309 header. The function is called with one argument, the time, which can
310 be fed to `format-time-string'."
311 :type '(choice string symbol)
312 :link '(custom-manual "(gnus)Article Date")
313 :group 'gnus-article-washing)
316 (autoload 'mail-extract-address-components "mail-extr"))
318 (defcustom gnus-save-all-headers t
319 "*If non-nil, don't remove any headers before saving."
320 :group 'gnus-article-saving
323 (defcustom gnus-prompt-before-saving 'always
324 "*This variable says how much prompting is to be done when saving articles.
325 If it is nil, no prompting will be done, and the articles will be
326 saved to the default files. If this variable is `always', each and
327 every article that is saved will be preceded by a prompt, even when
328 saving large batches of articles. If this variable is neither nil not
329 `always', there the user will be prompted once for a file name for
330 each invocation of the saving commands."
331 :group 'gnus-article-saving
332 :type '(choice (item always)
333 (item :tag "never" nil)
334 (sexp :tag "once" :format "%t\n" :value t)))
336 (defcustom gnus-saved-headers gnus-visible-headers
337 "Headers to keep if `gnus-save-all-headers' is nil.
338 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
339 If that variable is nil, however, all headers that match this regexp
340 will be kept while the rest will be deleted before saving."
341 :group 'gnus-article-saving
344 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
345 "A function to save articles in your favourite format.
346 The function must be interactively callable (in other words, it must
347 be an Emacs command).
349 Gnus provides the following functions:
351 * gnus-summary-save-in-rmail (Rmail format)
352 * gnus-summary-save-in-mail (Unix mail format)
353 * gnus-summary-save-in-folder (MH folder)
354 * gnus-summary-save-in-file (article format)
355 * gnus-summary-save-in-vm (use VM's folder format)
356 * gnus-summary-write-to-file (article format -- overwrite)."
357 :group 'gnus-article-saving
358 :type '(radio (function-item gnus-summary-save-in-rmail)
359 (function-item gnus-summary-save-in-mail)
360 (function-item gnus-summary-save-in-folder)
361 (function-item gnus-summary-save-in-file)
362 (function-item gnus-summary-save-in-vm)
363 (function-item gnus-summary-write-to-file)))
365 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
366 "A function generating a file name to save articles in Rmail format.
367 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
368 :group 'gnus-article-saving
371 (defcustom gnus-mail-save-name 'gnus-plain-save-name
372 "A function generating a file name to save articles in Unix mail format.
373 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
374 :group 'gnus-article-saving
377 (defcustom gnus-folder-save-name 'gnus-folder-save-name
378 "A function generating a file name to save articles in MH folder.
379 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
380 :group 'gnus-article-saving
383 (defcustom gnus-file-save-name 'gnus-numeric-save-name
384 "A function generating a file name to save articles in article format.
385 The function is called with NEWSGROUP, HEADERS, and optional
387 :group 'gnus-article-saving
390 (defcustom gnus-split-methods
391 '((gnus-article-archive-name)
392 (gnus-article-nndoc-name))
393 "*Variable used to suggest where articles are to be saved.
394 For instance, if you would like to save articles related to Gnus in
395 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
396 you could set this variable to something like:
398 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
399 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
401 This variable is an alist where the where the key is the match and the
402 value is a list of possible files to save in if the match is non-nil.
404 If the match is a string, it is used as a regexp match on the
405 article. If the match is a symbol, that symbol will be funcalled
406 from the buffer of the article to be saved with the newsgroup as the
407 parameter. If it is a list, it will be evaled in the same buffer.
409 If this form or function returns a string, this string will be used as
410 a possible file name; and if it returns a non-nil list, that list will
411 be used as possible file names."
412 :group 'gnus-article-saving
413 :type '(repeat (choice (list :value (fun) function)
414 (cons :value ("" "") regexp (repeat string))
417 (defcustom gnus-article-display-method-for-mime
418 'gnus-article-display-mime-message
419 "Function to display a MIME message.
420 The function is called from the article buffer."
421 :group 'gnus-article-mime
424 (defcustom gnus-article-display-method-for-traditional
425 'gnus-article-display-traditional-message
426 "*Function to display a traditional message.
427 The function is called from the article buffer."
428 :group 'gnus-article-mime
431 (defcustom gnus-page-delimiter "^\^L"
432 "*Regexp describing what to use as article page delimiters.
433 The default value is \"^\^L\", which is a form linefeed at the
434 beginning of a line."
436 :group 'gnus-article-various)
438 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
439 "*The format specification for the article mode line.
440 See `gnus-summary-mode-line-format' for a closer description.
442 The following additional specs are available:
444 %w The article washing status.
445 %m The number of MIME parts in the article."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-mode-hook nil
450 "*A hook for Gnus article mode."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-menu-hook nil
455 "*Hook run after the creation of the article mode menu."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-prepare-hook nil
460 "*A hook called after an article has been prepared in the article buffer."
462 :group 'gnus-article-various)
464 (defcustom gnus-article-hide-pgp-hook nil
465 "*A hook called after successfully hiding a PGP signature."
467 :group 'gnus-article-various)
469 (defcustom gnus-article-button-face 'bold
470 "Face used for highlighting buttons in the article buffer.
472 An article button is a piece of text that you can activate by pressing
473 `RET' or `mouse-2' above it."
475 :group 'gnus-article-buttons)
477 (defcustom gnus-article-mouse-face 'highlight
478 "Face used for mouse highlighting in the article buffer.
480 Article buttons will be displayed in this face when the cursor is
483 :group 'gnus-article-buttons)
485 (defcustom gnus-signature-face 'gnus-signature-face
486 "Face used for highlighting a signature in the article buffer.
487 Obsolete; use the face `gnus-signature-face' for customizations instead."
489 :group 'gnus-article-highlight
490 :group 'gnus-article-signature)
492 (defface gnus-signature-face
494 "Face used for highlighting a signature in the article buffer."
495 :group 'gnus-article-highlight
496 :group 'gnus-article-signature)
498 (defface gnus-header-from-face
501 (:foreground "spring green"))
504 (:foreground "red3"))
507 "Face used for displaying from headers."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-subject-face
514 (:foreground "SeaGreen3"))
517 (:foreground "red4"))
519 (:bold t :italic t)))
520 "Face used for displaying subject headers."
521 :group 'gnus-article-headers
522 :group 'gnus-article-highlight)
524 (defface gnus-header-newsgroups-face
527 (:foreground "yellow" :italic t))
530 (:foreground "MidnightBlue" :italic t))
533 "Face used for displaying newsgroups headers."
534 :group 'gnus-article-headers
535 :group 'gnus-article-highlight)
537 (defface gnus-header-name-face
540 (:foreground "SeaGreen"))
543 (:foreground "maroon"))
546 "Face used for displaying header names."
547 :group 'gnus-article-headers
548 :group 'gnus-article-highlight)
550 (defface gnus-header-content-face
553 (:foreground "forest green" :italic t))
556 (:foreground "indianred4" :italic t))
558 (:italic t))) "Face used for displaying header content."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight)
562 (defcustom gnus-header-face-alist
563 '(("From" nil gnus-header-from-face)
564 ("Subject" nil gnus-header-subject-face)
565 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
566 ("" gnus-header-name-face gnus-header-content-face))
567 "*Controls highlighting of article header.
569 An alist of the form (HEADER NAME CONTENT).
571 HEADER is a regular expression which should match the name of an
572 header header and NAME and CONTENT are either face names or nil.
574 The name of each header field will be displayed using the face
575 specified by the first element in the list where HEADER match the
576 header name and NAME is non-nil. Similarly, the content will be
577 displayed by the first non-nil matching CONTENT face."
578 :group 'gnus-article-headers
579 :group 'gnus-article-highlight
580 :type '(repeat (list (regexp :tag "Header")
582 (item :tag "skip" nil)
583 (face :value default))
584 (choice :tag "Content"
585 (item :tag "skip" nil)
586 (face :value default)))))
588 (defcustom gnus-article-decode-hook nil
589 "*Hook run to decode charsets in articles."
590 :group 'gnus-article-headers
593 (defcustom gnus-display-mime-function 'gnus-display-mime
594 "Function to display MIME articles."
595 :group 'gnus-article-mime
598 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
599 "Function used to decode headers.")
601 (defvar gnus-article-dumbquotes-map
619 "Table for MS-to-Latin1 translation.")
621 (defcustom gnus-ignored-mime-types nil
622 "List of MIME types that should be ignored by Gnus."
623 :group 'gnus-article-mime
624 :type '(repeat regexp))
626 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
627 "List of MIME types that should not be given buttons when rendered inline."
628 :group 'gnus-article-mime
629 :type '(repeat regexp))
631 (defcustom gnus-article-mime-part-function nil
632 "Function called with a MIME handle as the argument.
633 This is meant for people who want to do something automatic based
634 on parts -- for instance, adding Vcard info to a database."
635 :group 'gnus-article-mime
638 (defcustom gnus-mime-multipart-functions nil
639 "An alist of MIME types to functions to display them.")
641 (defcustom gnus-article-date-lapsed-new-header nil
642 "Whether the X-Sent and Date headers can coexist.
643 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
644 either replace the old \"Date:\" header (if this variable is nil), or
645 be added below it (otherwise)."
646 :group 'gnus-article-headers
649 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
650 "Function called with a MIME handle as the argument.
651 This is meant for people who want to view first matched part.
652 For `undisplayed-alternative' (default), the first undisplayed
653 part or alternative part is used. For `undisplayed', the first
654 undisplayed part is used. For a function, the first part which
655 the function return `t' is used. For `nil', the first part is
657 :group 'gnus-article-mime
659 (item :tag "first" :value nil)
660 (item :tag "undisplayed" :value undisplayed)
661 (item :tag "undisplayed or alternative"
662 :value undisplayed-alternative)
666 ;;; The treatment variables
669 (defvar gnus-part-display-hook nil
670 "Hook called on parts that are to receive treatment.")
672 (defvar gnus-article-treat-custom
673 '(choice (const :tag "Off" nil)
675 (const :tag "Header" head)
676 (const :tag "Last" last)
677 (const :tag "Mime" mime)
678 (integer :tag "Less")
679 (repeat :tag "Groups" regexp)
680 (sexp :tag "Predicate")))
682 (defvar gnus-article-treat-head-custom
683 '(choice (const :tag "Off" nil)
684 (const :tag "Header" head)))
686 (defvar gnus-article-treat-types '("text/plain")
689 (defvar gnus-inhibit-treatment nil
690 "Whether to inhibit treatment.")
692 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
693 "Highlight the signature.
694 Valid values are nil, t, `head', `last', an integer or a predicate.
695 See the manual for details."
696 :group 'gnus-article-treat
697 :type gnus-article-treat-custom)
698 (put 'gnus-treat-highlight-signature 'highlight t)
700 (defcustom gnus-treat-buttonize 100000
702 Valid values are nil, t, `head', `last', an integer or a predicate.
703 See the manual for details."
704 :group 'gnus-article-treat
705 :type gnus-article-treat-custom)
706 (put 'gnus-treat-buttonize 'highlight t)
708 (defcustom gnus-treat-buttonize-head 'head
709 "Add buttons to the head.
710 Valid values are nil, t, `head', `last', an integer or a predicate.
711 See the manual for details."
712 :group 'gnus-article-treat
713 :type gnus-article-treat-head-custom)
714 (put 'gnus-treat-buttonize-head 'highlight t)
716 (defcustom gnus-treat-emphasize nil
718 Valid values are nil, t, `head', `last', an integer or a predicate.
719 See the manual for details."
720 :group 'gnus-article-treat
721 :type gnus-article-treat-custom)
722 (put 'gnus-treat-emphasize 'highlight t)
724 (defcustom gnus-treat-strip-cr nil
725 "Remove carriage returns.
726 Valid values are nil, t, `head', `last', an integer or a predicate.
727 See the manual for details."
728 :group 'gnus-article-treat
729 :type gnus-article-treat-custom)
731 (defcustom gnus-treat-hide-headers 'head
733 Valid values are nil, t, `head', `last', an integer or a predicate.
734 See the manual for details."
735 :group 'gnus-article-treat
736 :type gnus-article-treat-head-custom)
738 (defcustom gnus-treat-hide-boring-headers nil
739 "Hide boring headers.
740 Valid values are nil, t, `head', `last', an integer or a predicate.
741 See the manual for details."
742 :group 'gnus-article-treat
743 :type gnus-article-treat-head-custom)
745 (defcustom gnus-treat-hide-signature nil
747 Valid values are nil, t, `head', `last', an integer or a predicate.
748 See the manual for details."
749 :group 'gnus-article-treat
750 :type gnus-article-treat-custom)
752 (defcustom gnus-treat-fill-article nil
754 Valid values are nil, t, `head', `last', an integer or a predicate.
755 See the manual for details."
756 :group 'gnus-article-treat
757 :type gnus-article-treat-custom)
759 (defcustom gnus-treat-hide-citation nil
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-custom)
766 (defcustom gnus-treat-strip-list-identifiers 'head
767 "Strip list identifiers from `gnus-list-identifiers`.
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-custom)
773 (defcustom gnus-treat-strip-pgp t
774 "Strip PGP signatures.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-custom)
780 (defcustom gnus-treat-strip-pem nil
781 "Strip PEM signatures.
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-custom)
787 (defcustom gnus-treat-strip-banner t
788 "Strip banners from articles.
789 The banner to be stripped is specified in the `banner' group parameter.
790 Valid values are nil, t, `head', `last', an integer or a predicate.
791 See the manual for details."
792 :group 'gnus-article-treat
793 :type gnus-article-treat-custom)
795 (defcustom gnus-treat-highlight-headers 'head
796 "Highlight the headers.
797 Valid values are nil, t, `head', `last', an integer or a predicate.
798 See the manual for details."
799 :group 'gnus-article-treat
800 :type gnus-article-treat-head-custom)
801 (put 'gnus-treat-highlight-headers 'highlight t)
803 (defcustom gnus-treat-highlight-citation t
804 "Highlight cited text.
805 Valid values are nil, t, `head', `last', an integer or a predicate.
806 See the manual for details."
807 :group 'gnus-article-treat
808 :type gnus-article-treat-custom)
809 (put 'gnus-treat-highlight-citation 'highlight t)
811 (defcustom gnus-treat-date-ut nil
812 "Display the Date in UT (GMT).
813 Valid values are nil, t, `head', `last', an integer or a predicate.
814 See the manual for details."
815 :group 'gnus-article-treat
816 :type gnus-article-treat-head-custom)
818 (defcustom gnus-treat-date-local nil
819 "Display the Date in the local timezone.
820 Valid values are nil, t, `head', `last', an integer or a predicate.
821 See the manual for details."
822 :group 'gnus-article-treat
823 :type gnus-article-treat-head-custom)
825 (defcustom gnus-treat-date-lapsed nil
826 "Display the Date header in a way that says how much time has elapsed.
827 Valid values are nil, t, `head', `last', an integer or a predicate.
828 See the manual for details."
829 :group 'gnus-article-treat
830 :type gnus-article-treat-head-custom)
832 (defcustom gnus-treat-date-original nil
833 "Display the date in the original timezone.
834 Valid values are nil, t, `head', `last', an integer or a predicate.
835 See the manual for details."
836 :group 'gnus-article-treat
837 :type gnus-article-treat-head-custom)
839 (defcustom gnus-treat-date-iso8601 nil
840 "Display the date in the ISO8601 format.
841 Valid values are nil, t, `head', `last', an integer or a predicate.
842 See the manual for details."
843 :group 'gnus-article-treat
844 :type gnus-article-treat-head-custom)
846 (defcustom gnus-treat-date-user-defined nil
847 "Display the date in a user-defined format.
848 The format is defined by the `gnus-article-time-format' variable.
849 Valid values are nil, t, `head', `last', an integer or a predicate.
850 See the manual for details."
851 :group 'gnus-article-treat
852 :type gnus-article-treat-head-custom)
854 (defcustom gnus-treat-strip-headers-in-body t
855 "Strip the X-No-Archive header line from the beginning of the body.
856 Valid values are nil, t, `head', `last', an integer or a predicate.
857 See the manual for details."
858 :group 'gnus-article-treat
859 :type gnus-article-treat-custom)
861 (defcustom gnus-treat-strip-trailing-blank-lines nil
862 "Strip trailing blank lines.
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See the manual for details."
865 :group 'gnus-article-treat
866 :type gnus-article-treat-custom)
868 (defcustom gnus-treat-strip-leading-blank-lines nil
869 "Strip leading blank lines.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See the manual for details."
872 :group 'gnus-article-treat
873 :type gnus-article-treat-custom)
875 (defcustom gnus-treat-strip-multiple-blank-lines nil
876 "Strip multiple blank lines.
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See the manual for details."
879 :group 'gnus-article-treat
880 :type gnus-article-treat-custom)
882 (defcustom gnus-treat-overstrike t
883 "Treat overstrike highlighting.
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-custom)
888 (put 'gnus-treat-overstrike 'highlight t)
890 (defcustom gnus-treat-display-xface
891 (if (or (and gnus-xemacs (featurep 'xface))
892 (eq 'x-face-mule-gnus-article-display-x-face
893 gnus-article-x-face-command))
896 "Display X-Face headers.
897 Valid values are nil, t, `head', `last', an integer or a predicate.
898 See the manual for details."
899 :group 'gnus-article-treat
900 :type gnus-article-treat-head-custom)
901 (put 'gnus-treat-display-xface 'highlight t)
903 (defcustom gnus-treat-display-smileys
904 (if (or (and gnus-xemacs (featurep 'xpm))
905 (and (not gnus-xemacs)
907 (module-installed-p 'gnus-bitmap)))
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See the manual for details."
913 :group 'gnus-article-treat
914 :type gnus-article-treat-custom)
915 (put 'gnus-treat-display-smileys 'highlight t)
917 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-head-custom)
923 (put 'gnus-treat-display-picons 'highlight t)
925 (defcustom gnus-treat-capitalize-sentences nil
926 "Capitalize sentence-starting words.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See the manual for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-custom)
932 (defcustom gnus-treat-fill-long-lines nil
934 Valid values are nil, t, `head', `last', an integer or a predicate.
935 See the manual for details."
936 :group 'gnus-article-treat
937 :type gnus-article-treat-custom)
939 (defcustom gnus-treat-play-sounds nil
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943 :group 'gnus-article-treat
944 :type gnus-article-treat-custom)
946 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
947 "Decode an article as `default-mime-charset'. For instance, if you want to
948 attempt to decode an article even if the value of `gnus-show-mime' is nil,
949 you could set this variable to something like: nil for don't decode, t for
950 decode the body, '(or header t) for the whole article, etc."
951 :group 'gnus-article-treat
952 :type '(radio (const :tag "Off" nil)
953 (const :tag "Decode body" t)
954 (const :tag "Decode all" (or head t))))
956 (defcustom gnus-treat-translate nil
957 "Translate articles from one language to another.
958 Valid values are nil, t, `head', `last', an integer or a predicate.
959 See the manual for details."
960 :group 'gnus-article-treat
961 :type gnus-article-treat-custom)
963 ;;; Internal variables
965 (defvar article-goto-body-goes-to-point-min-p nil)
966 (defvar gnus-article-wash-types nil)
967 (defvar gnus-article-emphasis-alist nil)
969 (defvar gnus-article-mime-handle-alist-1 nil)
970 (defvar gnus-treatment-function-alist
971 '((gnus-treat-decode-article-as-default-mime-charset
972 gnus-article-decode-article-as-default-mime-charset)
973 (gnus-treat-strip-banner gnus-article-strip-banner)
974 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
975 (gnus-treat-buttonize gnus-article-add-buttons)
976 (gnus-treat-fill-article gnus-article-fill-cited-article)
977 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
978 (gnus-treat-strip-cr gnus-article-remove-cr)
979 (gnus-treat-display-xface gnus-article-display-x-face)
980 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
981 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
982 (gnus-treat-hide-signature gnus-article-hide-signature)
983 (gnus-treat-hide-citation gnus-article-hide-citation)
984 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
985 (gnus-treat-strip-pgp gnus-article-hide-pgp)
986 (gnus-treat-strip-pem gnus-article-hide-pem)
987 (gnus-treat-highlight-headers gnus-article-highlight-headers)
988 (gnus-treat-emphasize gnus-article-emphasize)
989 (gnus-treat-highlight-citation gnus-article-highlight-citation)
990 (gnus-treat-highlight-signature gnus-article-highlight-signature)
991 (gnus-treat-date-ut gnus-article-date-ut)
992 (gnus-treat-date-local gnus-article-date-local)
993 (gnus-treat-date-lapsed gnus-article-date-lapsed)
994 (gnus-treat-date-original gnus-article-date-original)
995 (gnus-treat-date-user-defined gnus-article-date-user)
996 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
997 (gnus-treat-strip-trailing-blank-lines
998 gnus-article-remove-trailing-blank-lines)
999 (gnus-treat-strip-leading-blank-lines
1000 gnus-article-strip-leading-blank-lines)
1001 (gnus-treat-strip-multiple-blank-lines
1002 gnus-article-strip-multiple-blank-lines)
1003 (gnus-treat-overstrike gnus-article-treat-overstrike)
1004 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1005 (gnus-treat-display-smileys gnus-article-smiley-display)
1006 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1007 (gnus-treat-display-picons gnus-article-display-picons)
1008 (gnus-treat-play-sounds gnus-earcon-display)))
1010 (defvar gnus-article-mime-handle-alist nil)
1011 (defvar article-lapsed-timer nil)
1012 (defvar gnus-article-current-summary nil)
1014 (defvar gnus-article-mode-syntax-table
1015 (let ((table (copy-syntax-table text-mode-syntax-table)))
1016 (modify-syntax-entry ?- "w" table)
1017 (modify-syntax-entry ?> ")" table)
1018 (modify-syntax-entry ?< "(" table)
1020 "Syntax table used in article mode buffers.
1021 Initialized from `text-mode-syntax-table.")
1023 (defvar gnus-save-article-buffer nil)
1025 (defvar gnus-article-mode-line-format-alist
1026 (nconc '((?w (gnus-article-wash-status) ?s)
1027 (?m (gnus-article-mime-part-status) ?s))
1028 gnus-summary-mode-line-format-alist))
1030 (defvar gnus-number-of-articles-to-be-saved nil)
1032 (defvar gnus-inhibit-hiding nil)
1034 (defsubst gnus-article-hide-text (b e props)
1035 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1036 (add-text-properties b e props)
1037 (when (memq 'intangible props)
1039 (max (1- b) (point-min))
1040 b 'intangible (cddr (memq 'intangible props)))))
1041 (defsubst gnus-article-unhide-text (b e)
1042 "Remove hidden text properties from region between B and E."
1043 (remove-text-properties b e gnus-hidden-properties)
1044 (when (memq 'intangible gnus-hidden-properties)
1045 (put-text-property (max (1- b) (point-min))
1046 b 'intangible nil)))
1048 (defun gnus-article-hide-text-type (b e type)
1049 "Hide text of TYPE between B and E."
1050 (push type gnus-article-wash-types)
1051 (gnus-article-hide-text
1052 b e (cons 'article-type (cons type gnus-hidden-properties))))
1054 (defun gnus-article-unhide-text-type (b e type)
1055 "Unhide text of TYPE between B and E."
1056 (setq gnus-article-wash-types
1057 (delq type gnus-article-wash-types))
1058 (remove-text-properties
1059 b e (cons 'article-type (cons type gnus-hidden-properties)))
1060 (when (memq 'intangible gnus-hidden-properties)
1061 (put-text-property (max (1- b) (point-min))
1062 b 'intangible nil)))
1064 (defun gnus-article-hide-text-of-type (type)
1065 "Hide text of TYPE in the current buffer."
1067 (let ((b (point-min))
1069 (while (setq b (text-property-any b e 'article-type type))
1070 (add-text-properties b (incf b) gnus-hidden-properties)))))
1072 (defun gnus-article-delete-text-of-type (type)
1073 "Delete text of TYPE in the current buffer."
1075 (let ((b (point-min)))
1076 (while (setq b (text-property-any b (point-max) 'article-type type))
1078 b (or (text-property-not-all b (point-max) 'article-type type)
1081 (defun gnus-article-delete-invisible-text ()
1082 "Delete all invisible text in the current buffer."
1084 (let ((b (point-min)))
1085 (while (setq b (text-property-any b (point-max) 'invisible t))
1087 b (or (text-property-not-all b (point-max) 'invisible t)
1090 (defun gnus-article-text-type-exists-p (type)
1091 "Say whether any text of type TYPE exists in the buffer."
1092 (text-property-any (point-min) (point-max) 'article-type type))
1094 (defsubst gnus-article-header-rank ()
1095 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1096 (let ((list gnus-sorted-header-list)
1099 (when (looking-at (car list))
1101 (setq list (cdr list))
1105 (defun article-hide-headers (&optional arg delete)
1106 "Hide unwanted headers and possibly sort them as well."
1107 (interactive (gnus-article-hidden-arg))
1108 ;; Lars said that this function might be inhibited.
1109 (if (gnus-article-check-hidden-text 'headers arg)
1111 ;; Show boring headers as well.
1112 (gnus-article-show-hidden-text 'boring-headers)
1113 (when (eq 1 (point-min))
1114 (set-window-start (get-buffer-window (current-buffer)) 1)))
1115 (unless gnus-inhibit-hiding
1118 (let ((buffer-read-only nil)
1119 (inhibit-read-only t)
1120 (case-fold-search t)
1121 (max (1+ (length gnus-sorted-header-list)))
1122 (ignored (when (not gnus-visible-headers)
1123 (cond ((stringp gnus-ignored-headers)
1124 gnus-ignored-headers)
1125 ((listp gnus-ignored-headers)
1126 (mapconcat 'identity gnus-ignored-headers
1129 (cond ((stringp gnus-visible-headers)
1130 gnus-visible-headers)
1131 ((and gnus-visible-headers
1132 (listp gnus-visible-headers))
1133 (mapconcat 'identity gnus-visible-headers "\\|"))))
1134 (inhibit-point-motion-hooks t)
1136 ;; First we narrow to just the headers.
1137 (article-narrow-to-head)
1138 ;; Hide any "From " lines at the beginning of (mail) articles.
1139 (while (looking-at "From ")
1143 (delete-region (point-min) (point))
1144 (gnus-article-hide-text (point-min) (point)
1145 (nconc (list 'article-type 'headers)
1146 gnus-hidden-properties))))
1147 ;; Then treat the rest of the header lines.
1148 ;; Then we use the two regular expressions
1149 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1150 ;; select which header lines is to remain visible in the
1152 (while (re-search-forward "^[^ \t]*:" nil t)
1154 ;; Mark the rank of the header.
1156 (point) (1+ (point)) 'message-rank
1157 (if (or (and visible (looking-at visible))
1159 (not (looking-at ignored))))
1160 (gnus-article-header-rank)
1163 (message-sort-headers-1)
1164 (when (setq beg (text-property-any
1165 (point-min) (point-max) 'message-rank (+ 2 max)))
1166 ;; We delete or make invisible the unwanted headers.
1167 (push 'headers gnus-article-wash-types)
1170 (add-text-properties
1171 (point-min) (+ 5 (point-min))
1172 '(article-type headers dummy-invisible t))
1173 (delete-region beg (point-max)))
1174 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1177 (defun article-hide-boring-headers (&optional arg)
1178 "Toggle hiding of headers that aren't very interesting.
1179 If given a negative prefix, always show; if given a positive prefix,
1181 (interactive (gnus-article-hidden-arg))
1182 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1183 (not gnus-show-all-headers))
1186 (let ((buffer-read-only nil)
1187 (list gnus-boring-article-headers)
1188 (inhibit-point-motion-hooks t)
1190 (article-narrow-to-head)
1192 (setq elem (pop list))
1193 (goto-char (point-min))
1195 ;; Hide empty headers.
1197 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1199 (gnus-article-hide-text-type
1200 (progn (beginning-of-line) (point))
1203 (if (re-search-forward "^[^ \t]" nil t)
1207 ;; Hide boring Newsgroups header.
1208 ((eq elem 'newsgroups)
1209 (when (equal (gnus-fetch-field "newsgroups")
1210 (gnus-group-real-name
1211 (if (boundp 'gnus-newsgroup-name)
1214 (gnus-article-hide-header "newsgroups")))
1215 ((eq elem 'followup-to)
1216 (when (equal (message-fetch-field "followup-to")
1217 (message-fetch-field "newsgroups"))
1218 (gnus-article-hide-header "followup-to")))
1219 ((eq elem 'reply-to)
1220 (let ((from (message-fetch-field "from"))
1221 (reply-to (message-fetch-field "reply-to")))
1226 (nth 1 (funcall gnus-extract-address-components from))
1227 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1228 (gnus-article-hide-header "reply-to"))))
1230 (let ((date (message-fetch-field "date")))
1232 (< (days-between (current-time-string) date)
1234 (gnus-article-hide-header "date"))))
1236 (let ((to (message-fetch-field "to")))
1237 (when (> (length to) 1024)
1238 (gnus-article-hide-header "to"))))
1241 (goto-char (point-min))
1242 (while (re-search-forward "^to:" nil t)
1243 (setq to-count (1+ to-count)))
1244 (when (> to-count 1)
1245 (while (> to-count 0)
1246 (goto-char (point-min))
1248 (re-search-forward "^to:" nil nil to-count)
1250 (narrow-to-region (point) (point-max))
1251 (gnus-article-hide-header "to"))
1252 (setq to-count (1- to-count)))))))))))))
1254 (defun gnus-article-hide-header (header)
1256 (goto-char (point-min))
1257 (when (re-search-forward (concat "^" header ":") nil t)
1258 (gnus-article-hide-text-type
1259 (progn (beginning-of-line) (point))
1262 (if (re-search-forward "^[^ \t]" nil t)
1267 (defun article-toggle-headers (&optional arg)
1268 "Toggle hiding of headers. If given a negative prefix, always show;
1269 if given a positive prefix, always hide."
1270 (interactive (gnus-article-hidden-arg))
1271 (let ((force (when (numberp arg)
1272 (cond ((> arg 0) 'always-hide)
1273 ((< arg 0) 'always-show))))
1274 (window (get-buffer-window gnus-article-buffer))
1275 (header-end (point-min))
1276 header-start field-end field-start
1277 (inhibit-point-motion-hooks t)
1278 (inhibit-read-only t)
1282 (while (and (setq header-start
1283 (text-property-any header-end (point-max)
1284 'article-treated-header t))
1286 (text-property-not-all header-start (point-max)
1287 'article-treated-header t)))
1288 (setq field-end header-start)
1290 (;; Hide exposed invisible fields.
1291 (and (not (eq 'always-show force))
1293 (text-property-any field-end header-end
1294 'exposed-invisible-field t)))
1295 (while (and field-start
1296 (setq field-end (text-property-not-all
1297 field-start header-end
1298 'exposed-invisible-field t)))
1299 (add-text-properties field-start field-end gnus-hidden-properties)
1300 (setq field-start (text-property-any field-end header-end
1301 'exposed-invisible-field t)))
1302 (put-text-property header-start header-end
1303 'exposed-invisible-field nil))
1304 (;; Expose invisible fields.
1305 (and (not (eq 'always-hide force))
1307 (text-property-any field-end header-end 'invisible t)))
1308 (while (and field-start
1309 (setq field-end (text-property-not-all
1310 field-start header-end
1312 ;; If the invisible text is not terminated with newline, we
1313 ;; won't expose it. Because it may be created by x-face-mule.
1314 ;; BTW, XEmacs sometimes fail in putting a invisible text
1315 ;; property with `gnus-article-hide-text' (really?). In that
1316 ;; case, the invisible text might be started from the middle of
1317 ;; a line so we will expose the sort of thing.
1318 (when (or (not (or (eq header-start field-start)
1319 (eq ?\n (char-before field-start))))
1320 (eq ?\n (char-before field-end)))
1321 (remove-text-properties field-start field-end
1322 gnus-hidden-properties)
1323 (put-text-property field-start field-end
1324 'exposed-invisible-field t))
1325 (setq field-start (text-property-any field-end header-end
1328 (not (eq 'always-show force))
1329 (narrow-to-region header-start header-end)
1330 (article-hide-headers)
1331 ;; Re-display X-Face image under XEmacs.
1332 (when (and gnus-xemacs
1333 (gnus-functionp gnus-article-x-face-command))
1334 (let ((func (cadr (assq 'gnus-treat-display-xface
1335 gnus-treatment-function-alist)))
1337 (when (and (not gnus-inhibit-treatment)
1339 (gnus-treat-predicate gnus-treat-display-xface))
1341 (put-text-property header-start header-end 'read-only nil))))
1344 (goto-char (point-min))
1346 (set-window-start window (point-min))))))
1348 (defvar gnus-article-normalized-header-length 40
1349 "Length of normalized headers.")
1351 (defun article-normalize-headers ()
1352 "Make all header lines 40 characters long."
1354 (let ((buffer-read-only nil)
1358 (article-narrow-to-head)
1361 ((< (setq column (- (gnus-point-at-eol) (point)))
1362 gnus-article-normalized-header-length)
1364 (insert (make-string
1365 (- gnus-article-normalized-header-length column)
1367 ((> column gnus-article-normalized-header-length)
1368 (gnus-put-text-property
1370 (forward-char gnus-article-normalized-header-length)
1377 (forward-line 1))))))
1379 (defun article-treat-dumbquotes ()
1380 "Translate M******** sm*rtq**t*s into proper text.
1381 Note that this function guesses whether a character is a sm*rtq**t* or
1382 not, so it should only be used interactively."
1384 (article-translate-strings gnus-article-dumbquotes-map))
1386 (defun article-translate-characters (from to)
1387 "Translate all characters in the body of the article according to FROM and TO.
1388 FROM is a string of characters to translate from; to is a string of
1389 characters to translate to."
1391 (when (article-goto-body)
1392 (let ((buffer-read-only nil)
1393 (x (make-string 225 ?x))
1395 (while (< (incf i) (length x))
1398 (while (< i (length from))
1399 (aset x (aref from i) (aref to i))
1401 (translate-region (point) (point-max) x)))))
1403 (defun article-translate-strings (map)
1404 "Translate all string in the body of the article according to MAP.
1405 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1407 (when (article-goto-body)
1408 (let ((buffer-read-only nil)
1410 (while (setq elem (pop map))
1412 (while (search-forward (car elem) nil t)
1413 (replace-match (cadr elem)))))))))
1415 (defun article-treat-overstrike ()
1416 "Translate overstrikes into bold text."
1419 (when (article-goto-body)
1420 (let ((buffer-read-only nil))
1421 (while (search-forward "\b" nil t)
1422 (let ((next (char-after))
1426 previous (char-after))
1430 ;; We do the boldification/underlining by hiding the
1431 ;; overstrikes and putting the proper text property
1435 (gnus-article-hide-text-type start (point) 'overstrike)
1436 (put-text-property (point) end 'face 'bold))
1438 (gnus-article-hide-text-type
1439 (1- (point)) (1+ (point)) 'overstrike)
1441 start (1- (point)) 'face 'underline))
1443 (gnus-article-hide-text-type start (point) 'overstrike)
1445 (point) end 'face 'underline)))))))))
1447 (defun article-fill-long-lines ()
1448 "Fill lines that are wider than the window width."
1451 (let ((buffer-read-only nil)
1452 (width (window-width (get-buffer-window (current-buffer)))))
1455 (let ((adaptive-fill-mode nil))
1458 (when (>= (current-column) (min fill-column width))
1459 (narrow-to-region (point) (gnus-point-at-bol))
1460 (fill-paragraph nil)
1461 (goto-char (point-max))
1463 (forward-line 1)))))))
1465 (defun article-capitalize-sentences ()
1466 "Capitalize the first word in each sentence."
1469 (let ((buffer-read-only nil)
1470 (paragraph-start "^[\n\^L]"))
1474 (forward-sentence)))))
1476 (defun article-remove-cr ()
1477 "Remove trailing CRs and then translate remaining CRs into LFs."
1480 (let ((buffer-read-only nil))
1481 (goto-char (point-min))
1482 (while (re-search-forward "\r+$" nil t)
1483 (replace-match "" t t))
1484 (goto-char (point-min))
1485 (while (search-forward "\r" nil t)
1486 (replace-match "\n" t t)))))
1488 (defun article-remove-trailing-blank-lines ()
1489 "Remove all trailing blank lines from the article."
1492 (let ((buffer-read-only nil))
1493 (goto-char (point-max))
1497 (while (and (not (bobp))
1498 (looking-at "^[ \t]*$")
1499 (not (gnus-annotation-in-region-p
1500 (point) (gnus-point-at-eol))))
1505 (defun article-display-x-face (&optional force)
1506 "Look for an X-Face header and display it if present."
1507 (interactive (list 'force))
1509 ;; Delete the old process, if any.
1510 (when (process-status "article-x-face")
1511 (delete-process "article-x-face"))
1512 (let ((inhibit-point-motion-hooks t)
1513 (case-fold-search t)
1516 (article-narrow-to-head)
1517 (goto-char (point-min))
1518 (setq from (message-fetch-field "from"))
1519 (goto-char (point-min))
1520 (while (and gnus-article-x-face-command
1523 ;; Check whether this face is censored.
1524 (not gnus-article-x-face-too-ugly)
1525 (and gnus-article-x-face-too-ugly from
1526 (not (string-match gnus-article-x-face-too-ugly
1528 ;; Has to be present.
1529 (re-search-forward "^X-Face:[ \t]*" nil t))
1530 ;; This used to try to do multiple faces (`while' instead of
1531 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1532 ;; work (b) it can crash some versions of Emacs (c) are
1533 ;; multiple faces really something to encourage?
1534 (when (stringp gnus-article-x-face-command)
1536 ;; We now have the area of the buffer where the X-Face is stored.
1539 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1540 ;; We display the face.
1541 (if (symbolp gnus-article-x-face-command)
1542 ;; The command is a lisp function, so we call it.
1543 (if (gnus-functionp gnus-article-x-face-command)
1544 (funcall gnus-article-x-face-command beg end)
1545 (error "%s is not a function" gnus-article-x-face-command))
1546 ;; The command is a string, so we interpret the command
1547 ;; as a, well, command, and fork it off.
1548 (let ((process-connection-type nil))
1549 (process-kill-without-query
1551 "article-x-face" nil shell-file-name shell-command-switch
1552 gnus-article-x-face-command))
1553 (process-send-region "article-x-face" beg end)
1554 (process-send-eof "article-x-face"))))))))))
1556 (defun article-decode-mime-words ()
1557 "Decode all MIME-encoded words in the article."
1560 (set-buffer gnus-article-buffer)
1561 (let ((inhibit-point-motion-hooks t)
1563 (mail-parse-charset gnus-newsgroup-charset)
1564 (mail-parse-ignored-charsets
1565 (save-excursion (set-buffer gnus-summary-buffer)
1566 gnus-newsgroup-ignored-charsets)))
1567 (mail-decode-encoded-word-region (point-min) (point-max)))))
1569 (defun article-decode-charset (&optional prompt)
1570 "Decode charset-encoded text in the article.
1571 If PROMPT (the prefix), prompt for a coding system to use."
1573 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1575 (mail-parse-charset gnus-newsgroup-charset)
1576 (mail-parse-ignored-charsets
1577 (save-excursion (condition-case nil
1578 (set-buffer gnus-summary-buffer)
1580 gnus-newsgroup-ignored-charsets))
1584 (article-narrow-to-head)
1585 (setq ct (message-fetch-field "Content-Type" t)
1586 cte (message-fetch-field "Content-Transfer-Encoding" t)
1587 ctl (and ct (ignore-errors
1588 (mail-header-parse-content-type ct)))
1591 (mm-read-coding-system "Charset to decode: "))
1593 (mail-content-type-get ctl 'charset))))
1595 (setq cte (mail-header-strip cte)))
1596 (if (and ctl (not (string-match "/" (car ctl))))
1598 (goto-char (point-max)))
1601 (narrow-to-region (point) (point-max))
1602 (when (and (or (not ctl)
1603 (equal (car ctl) "text/plain")))
1605 charset (and cte (intern (downcase
1606 (gnus-strip-whitespace cte))))
1609 (defun article-decode-encoded-words ()
1610 "Remove encoded-word encoding from headers."
1611 (let (buffer-read-only)
1612 (let ((charset (save-excursion
1613 (set-buffer gnus-summary-buffer)
1614 default-mime-charset)))
1615 (mime-decode-header-in-buffer charset)
1618 (defun article-de-quoted-unreadable (&optional force)
1619 "Translate a quoted-printable-encoded article.
1620 If FORCE, decode the article whether it is marked as quoted-printable
1622 (interactive (list 'force))
1624 (let ((buffer-read-only nil)
1625 (type (gnus-fetch-field "content-transfer-encoding"))
1626 (charset gnus-newsgroup-charset))
1628 (and type (string-match "quoted-printable" (downcase type))))
1630 (quoted-printable-decode-region (point) (point-max) charset)))))
1635 (defun article-decode-HZ ()
1636 "Translate a HZ-encoded article."
1640 (let ((buffer-read-only nil))
1641 (rfc1843-decode-region (point-min) (point-max)))))
1643 (defun article-hide-list-identifiers ()
1644 "Remove list identifies from the Subject header.
1645 The `gnus-list-identifiers' variable specifies what to do."
1649 (let ((inhibit-point-motion-hooks t)
1651 (article-narrow-to-head)
1652 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1653 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1655 (goto-char (point-min))
1656 (when (re-search-forward
1657 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1659 (delete-region (match-beginning 2) (match-end 0)))))))))
1661 (defun article-hide-pgp ()
1662 "Remove any PGP headers and signatures in the current article."
1666 (let ((inhibit-point-motion-hooks t)
1667 buffer-read-only beg end)
1669 ;; Hide the "header".
1670 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1671 (push 'pgp gnus-article-wash-types)
1672 (delete-region (match-beginning 0) (match-end 0))
1673 ;; Remove armor headers (rfc2440 6.2)
1674 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1677 ;; Hide the actual signature.
1678 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1679 (setq end (1+ (match-beginning 0)))
1682 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1684 ;; Perhaps we shouldn't hide to the end of the buffer
1685 ;; if there is no end to the signature?
1687 ;; Hide "- " PGP quotation markers.
1689 (narrow-to-region beg end)
1690 (goto-char (point-min))
1691 (while (re-search-forward "^- " nil t)
1693 (match-beginning 0) (match-end 0)))
1695 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1697 (defun article-hide-pem (&optional arg)
1698 "Toggle hiding of any PEM headers and signatures in the current article.
1699 If given a negative prefix, always show; if given a positive prefix,
1701 (interactive (gnus-article-hidden-arg))
1702 (unless (gnus-article-check-hidden-text 'pem arg)
1704 (let (buffer-read-only end)
1705 (goto-char (point-min))
1706 ;; Hide the horrendously ugly "header".
1707 (when (and (search-forward
1708 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1710 (setq end (1+ (match-beginning 0))))
1711 (push 'pem gnus-article-wash-types)
1712 (gnus-article-hide-text-type
1714 (if (search-forward "\n\n" nil t)
1718 ;; Hide the trailer as well
1719 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1721 (gnus-article-hide-text-type
1722 (match-beginning 0) (match-end 0) 'pem)))))))
1724 (defun article-strip-banner ()
1725 "Strip the banner specified by the `banner' group parameter."
1729 (let ((inhibit-point-motion-hooks t)
1730 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1731 (gnus-signature-limit nil)
1732 buffer-read-only beg end)
1736 ((eq banner 'signature)
1737 (when (gnus-article-narrow-to-signature)
1740 (delete-region (point) (point-max))))
1742 (while (re-search-forward banner nil t)
1743 (delete-region (match-beginning 0) (match-end 0))))))))))
1745 (defun article-babel ()
1746 "Translate article using an online translation service."
1750 (set-buffer gnus-article-buffer)
1751 (when (article-goto-body)
1752 (let* ((buffer-read-only nil)
1755 (orig (buffer-substring start end))
1756 (trans (babel-as-string orig)))
1758 (narrow-to-region start end)
1759 (delete-region start end)
1762 (defun article-hide-signature (&optional arg)
1763 "Hide the signature in the current article.
1764 If given a negative prefix, always show; if given a positive prefix,
1766 (interactive (gnus-article-hidden-arg))
1772 (article-goto-body))
1773 (goto-char (point-min)))
1774 (unless (gnus-article-check-hidden-text 'signature arg)
1775 (let ((buffer-read-only nil)
1777 (while (setq button (text-property-any button (point-max)
1779 'gnus-signature-toggle))
1780 (setq button (text-property-not-all button (point-max)
1782 'gnus-signature-toggle))
1783 (when (and button (not (eobp)))
1784 (gnus-article-hide-text-type
1786 (next-single-property-change (1+ button) 'mime-view-entity
1790 (defun article-strip-headers-in-body ()
1791 "Strip offensive headers from bodies."
1795 (let ((case-fold-search t))
1796 (when (looking-at "x-no-archive:")
1797 (gnus-delete-line)))))
1799 (defun article-strip-leading-blank-lines ()
1800 "Remove all blank lines from the beginning of the article."
1803 (let ((inhibit-point-motion-hooks t)
1805 (when (article-goto-body)
1806 (while (and (not (eobp))
1807 (looking-at "[ \t]*$"))
1808 (gnus-delete-line))))))
1810 (defun article-narrow-to-head ()
1811 "Narrow the buffer to the head of the message.
1812 Point is left at the beginning of the narrowed-to region."
1814 (goto-char (point-min))
1815 (if (search-forward "\n\n" nil 1)
1818 (goto-char (point-min)))
1820 (defun article-goto-body ()
1821 "Place point at the start of the body."
1822 (goto-char (point-min))
1824 ;; This variable is only bound when dealing with separate
1826 (article-goto-body-goes-to-point-min-p
1828 ((search-forward "\n\n" nil t)
1831 (goto-char (point-max))
1834 (defun article-strip-multiple-blank-lines ()
1835 "Replace consecutive blank lines with one empty line."
1838 (let ((inhibit-point-motion-hooks t)
1840 ;; First make all blank lines empty.
1842 (while (re-search-forward "^[ \t]+$" nil t)
1843 (unless (gnus-annotation-in-region-p
1844 (match-beginning 0) (match-end 0))
1845 (replace-match "" nil t)))
1846 ;; Then replace multiple empty lines with a single empty line.
1848 (while (re-search-forward "\n\n\n+" nil t)
1849 (unless (gnus-annotation-in-region-p
1850 (match-beginning 0) (match-end 0))
1851 (replace-match "\n\n" t t))))))
1853 (defun article-strip-leading-space ()
1854 "Remove all white space from the beginning 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-trailing-space ()
1864 "Remove all white space from the end of the lines in the article."
1867 (let ((inhibit-point-motion-hooks t)
1870 (while (re-search-forward "[ \t]+$" nil t)
1871 (replace-match "" t t)))))
1873 (defun article-strip-blank-lines ()
1874 "Strip leading, trailing and multiple blank lines."
1876 (article-strip-leading-blank-lines)
1877 (article-remove-trailing-blank-lines)
1878 (article-strip-multiple-blank-lines))
1880 (defun article-strip-all-blank-lines ()
1881 "Strip all blank lines."
1884 (let ((inhibit-point-motion-hooks t)
1887 (while (re-search-forward "^[ \t]*\n" nil t)
1888 (replace-match "" t t)))))
1890 (defun gnus-article-narrow-to-signature ()
1891 "Narrow to the signature; return t if a signature is found, else nil."
1892 (let ((inhibit-point-motion-hooks t))
1893 (when (gnus-article-search-signature)
1895 ;; Check whether we have some limits to what we consider
1896 ;; to be a signature.
1897 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1898 (list gnus-signature-limit)))
1900 (while (setq limit (pop limits))
1901 (if (or (and (integerp limit)
1902 (< (- (point-max) (point)) limit))
1904 (< (count-lines (point) (point-max)) limit))
1905 (and (gnus-functionp limit)
1907 (and (stringp limit)
1908 (not (re-search-forward limit nil t))))
1909 () ; This limit did not succeed.
1913 (narrow-to-region (point) (point-max))
1916 (defun gnus-article-search-signature ()
1917 "Search the current buffer for the signature separator.
1918 Put point at the beginning of the signature separator."
1919 (let ((cur (point)))
1920 (goto-char (point-max))
1921 (if (if (stringp gnus-signature-separator)
1922 (re-search-backward gnus-signature-separator nil t)
1923 (let ((seps gnus-signature-separator))
1925 (not (re-search-backward (car seps) nil t)))
1932 (defun gnus-article-hidden-arg ()
1933 "Return the current prefix arg as a number, or 0 if no prefix."
1934 (list (if current-prefix-arg
1935 (prefix-numeric-value current-prefix-arg)
1938 (defun gnus-article-check-hidden-text (type arg)
1939 "Return nil if hiding is necessary.
1940 Arg can be nil or a number. Nil and positive means hide, negative
1941 means show, 0 means toggle."
1944 (let ((hide (gnus-article-hidden-text-p type)))
1950 (gnus-article-show-hidden-text type))
1952 (if (eq hide 'hidden)
1953 (gnus-article-show-hidden-text type)
1956 (defun gnus-article-hidden-text-p (type)
1957 "Say whether the current buffer contains hidden text of type TYPE."
1958 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1960 (not (get-text-property pos 'invisible))
1961 (not (get-text-property pos 'dummy-invisible)))
1963 (text-property-any (1+ pos) (point-max) 'article-type type)))
1968 (defun gnus-article-show-hidden-text (type &optional hide)
1969 "Show all hidden text of type TYPE.
1970 If HIDE, hide the text instead."
1972 (let ((buffer-read-only nil)
1973 (inhibit-point-motion-hooks t)
1976 (while (setq beg (text-property-any end (point-max) 'article-type type))
1979 (text-property-not-all beg (point-max) 'article-type type)
1982 (gnus-article-hide-text beg end gnus-hidden-properties)
1983 (gnus-article-unhide-text beg end))
1987 (defconst article-time-units
1988 `((year . ,(* 365.25 24 60 60))
1989 (week . ,(* 7 24 60 60))
1990 (day . ,(* 24 60 60))
1994 "Mapping from time units to seconds.")
1996 (defun article-date-ut (&optional type highlight header)
1997 "Convert DATE date to universal time in the current article.
1998 If TYPE is `local', convert to local time; if it is `lapsed', output
1999 how much time has lapsed since DATE. For `lapsed', the value of
2000 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2001 should replace the \"Date:\" one, or should be added below it."
2002 (interactive (list 'ut t))
2003 (let* ((header (or header
2004 (and (eq 1 (point-min))
2005 (mail-header-date (save-excursion
2006 (set-buffer gnus-summary-buffer)
2007 gnus-current-headers)))
2008 (message-fetch-field "date")
2010 (date (if (vectorp header) (mail-header-date header)
2012 (inhibit-point-motion-hooks t)
2013 bface eface date-pos)
2014 (when (and date (not (string= date "")))
2017 (article-narrow-to-head)
2018 (when (or (and (eq type 'lapsed)
2019 gnus-article-date-lapsed-new-header
2020 ;; Attempt to get the face of X-Sent first.
2021 (re-search-forward "^X-Sent:[ \t]" nil t))
2022 (re-search-forward "^Date:[ \t]" nil t)
2023 ;; If Date is missing, try again for X-Sent.
2024 (re-search-forward "^X-Sent:[ \t]" nil t))
2025 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2026 date (or (get-text-property (gnus-point-at-bol)
2029 eface (get-text-property (1- (gnus-point-at-eol))
2031 (let ((buffer-read-only nil))
2032 ;; Delete any old X-Sent headers.
2033 (when (setq date-pos
2034 (text-property-any (point-min) (point-max)
2035 'article-date-lapsed t))
2036 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2037 (delete-region (match-beginning 0)
2038 (progn (forward-line 1) (point))))
2039 (goto-char (point-min))
2040 ;; Delete any old Date headers.
2041 (while (re-search-forward "^Date:[ \t]" nil t)
2043 (setq date-pos (match-beginning 0)))
2044 (unless (and (eq type 'lapsed)
2045 gnus-article-date-lapsed-new-header)
2046 (delete-region (match-beginning 0)
2047 (progn (message-next-header) (point)))))
2050 (goto-char date-pos)
2052 ;; Possibly, Date has been deleted.
2054 (when (and (eq type 'lapsed)
2055 gnus-article-date-lapsed-new-header
2056 (looking-at "Date:"))
2058 (goto-char (point-min)))
2059 (insert (article-make-date-line date type))
2060 (when (eq type 'lapsed)
2061 (put-text-property (gnus-point-at-bol) (point)
2062 'article-date-lapsed t))
2066 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2067 (put-text-property (match-beginning 1) (1+ (match-end 1))
2068 'original-date date)
2069 (put-text-property (match-beginning 1) (1+ (match-end 1))
2071 (put-text-property (match-beginning 2) (match-end 2)
2074 (defun article-make-date-line (date type)
2075 "Return a DATE line of TYPE."
2076 (let ((time (condition-case ()
2080 ;; Convert to the local timezone. We have to slap a
2081 ;; `condition-case' round the calls to the timezone
2082 ;; functions since they aren't particularly resistant to
2085 (let ((tz (car (current-time-zone time))))
2086 (format "Date: %s %s%02d%02d" (current-time-string time)
2087 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2088 (/ (% (abs tz) 3600) 60))))
2089 ;; Convert to Universal Time.
2092 (current-time-string
2093 (let* ((e (parse-time-string date))
2094 (tm (apply 'encode-time e))
2096 (ls (- (cadr tm) (car (current-time-zone time)))))
2097 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2098 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2101 ;; Get the original date from the article.
2102 ((eq type 'original)
2103 (concat "Date: " (if (string-match "\n+$" date)
2104 (substring date 0 (match-beginning 0))
2106 ;; Let the user define the format.
2108 (if (gnus-functionp gnus-article-time-format)
2109 (funcall gnus-article-time-format time)
2112 (format-time-string gnus-article-time-format time))))
2115 (let ((tz (car (current-time-zone time))))
2118 (format-time-string "%Y%m%dT%H%M%S" time)
2119 (format "%s%02d%02d"
2120 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2121 (/ (% (abs tz) 3600) 60)))))
2122 ;; Do an X-Sent lapsed format.
2124 ;; If the date is seriously mangled, the timezone functions are
2125 ;; liable to bug out, so we ignore all errors.
2126 (let* ((now (current-time))
2127 (real-time (subtract-time now time))
2128 (real-sec (and real-time
2129 (+ (* (float (car real-time)) 65536)
2131 (sec (and real-time (abs real-sec)))
2141 ;; This is a bit convoluted, but basically we go
2142 ;; through the time units for years, weeks, etc,
2143 ;; and divide things to see whether that results
2144 ;; in positive answers.
2147 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2148 ;; The (remaining) seconds are too few to
2149 ;; be divided into this time unit.
2151 ;; It's big enough, so we output it.
2152 (setq sec (- sec (* num (cdr unit))))
2154 (concat (if prev ", " "") (int-to-string
2156 " " (symbol-name (car unit))
2157 (if (> num 1) "s" ""))
2159 article-time-units "")
2160 ;; If dates are odd, then it might appear like the
2161 ;; article was sent in the future.
2164 " in the future"))))))
2166 (error "Unknown conversion type: %s" type)))))
2168 (defun article-date-local (&optional highlight)
2169 "Convert the current article date to the local timezone."
2170 (interactive (list t))
2171 (article-date-ut 'local highlight))
2173 (defun article-date-original (&optional highlight)
2174 "Convert the current article date to what it was originally.
2175 This is only useful if you have used some other date conversion
2176 function and want to see what the date was before converting."
2177 (interactive (list t))
2178 (article-date-ut 'original highlight))
2180 (defun article-date-lapsed (&optional highlight)
2181 "Convert the current article date to time lapsed since it was sent."
2182 (interactive (list t))
2183 (article-date-ut 'lapsed highlight))
2185 (defun article-update-date-lapsed ()
2186 "Function to be run from a timer to update the lapsed time line."
2187 (let (deactivate-mark)
2192 (set-buffer (window-buffer w))
2193 (when (eq major-mode 'gnus-article-mode)
2194 (goto-char (point-min))
2195 (when (re-search-forward "^X-Sent:" nil t)
2196 (article-date-lapsed t))))
2199 (defun gnus-start-date-timer (&optional n)
2200 "Start a timer to update the X-Sent header in the article buffers.
2201 The numerical prefix says how frequently (in seconds) the function
2206 (gnus-stop-date-timer)
2207 (setq article-lapsed-timer
2208 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2210 (defun gnus-stop-date-timer ()
2211 "Stop the X-Sent timer."
2213 (when article-lapsed-timer
2214 (nnheader-cancel-timer article-lapsed-timer)
2215 (setq article-lapsed-timer nil)))
2217 (defun article-date-user (&optional highlight)
2218 "Convert the current article date to the user-defined format.
2219 This format is defined by the `gnus-article-time-format' variable."
2220 (interactive (list t))
2221 (article-date-ut 'user highlight))
2223 (defun article-date-iso8601 (&optional highlight)
2224 "Convert the current article date to ISO8601."
2225 (interactive (list t))
2226 (article-date-ut 'iso8601 highlight))
2228 (defun article-show-all ()
2229 "Show all hidden text in the article buffer."
2233 (let ((buffer-read-only nil))
2234 (gnus-article-unhide-text (point-min) (point-max))
2235 (gnus-remove-text-with-property 'gnus-prev)
2236 (gnus-remove-text-with-property 'gnus-next))))
2238 (defun article-show-all-headers ()
2239 "Show all hidden headers in the article buffer."
2244 (article-narrow-to-head)
2245 (let ((buffer-read-only nil))
2246 (gnus-article-unhide-text (point-min) (point-max))))))
2248 (defun article-emphasize (&optional arg)
2249 "Emphasize text according to `gnus-emphasis-alist'."
2250 (interactive (gnus-article-hidden-arg))
2251 (unless (gnus-article-check-hidden-text 'emphasis arg)
2255 (with-current-buffer gnus-summary-buffer
2256 gnus-article-emphasis-alist)
2258 gnus-emphasis-alist))
2259 (buffer-read-only nil)
2260 (props (append '(article-type emphasis)
2261 gnus-hidden-properties))
2262 regexp elem beg invisible visible face)
2265 (while (setq elem (pop alist))
2267 (setq regexp (car elem)
2268 invisible (nth 1 elem)
2269 visible (nth 2 elem)
2271 (while (re-search-forward regexp nil t)
2272 (when (and (match-beginning visible) (match-beginning invisible))
2273 (push 'emphasis gnus-article-wash-types)
2274 (gnus-article-hide-text
2275 (match-beginning invisible) (match-end invisible) props)
2276 (gnus-article-unhide-text-type
2277 (match-beginning visible) (match-end visible) 'emphasis)
2278 (gnus-put-text-property-excluding-newlines
2279 (match-beginning visible) (match-end visible) 'face face)
2280 (goto-char (match-end invisible)))))))))
2282 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2283 "Setup newsgroup emphasis alist."
2284 (unless gnus-article-emphasis-alist
2285 (let ((name (and gnus-newsgroup-name
2286 (gnus-group-real-name gnus-newsgroup-name))))
2287 (make-local-variable 'gnus-article-emphasis-alist)
2288 (setq gnus-article-emphasis-alist
2290 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2291 (while (setq elem (pop alist))
2292 (when (and name (string-match (car elem) name))
2294 highlight (copy-sequence (cdr elem)))))
2296 (copy-sequence highlight-words)
2297 (if gnus-newsgroup-name
2298 (copy-sequence (gnus-group-find-parameter
2299 gnus-newsgroup-name 'highlight-words t)))
2300 gnus-emphasis-alist)))))
2302 (defvar gnus-summary-article-menu)
2303 (defvar gnus-summary-post-menu)
2305 ;;; Saving functions.
2307 (defun gnus-article-save (save-buffer file &optional num)
2308 "Save the currently selected article."
2309 (unless gnus-save-all-headers
2310 ;; Remove headers according to `gnus-saved-headers'.
2311 (let ((gnus-visible-headers
2312 (or gnus-saved-headers gnus-visible-headers))
2313 (gnus-article-buffer save-buffer))
2315 (set-buffer save-buffer)
2316 (article-hide-headers 1 t))))
2317 (save-window-excursion
2318 (if (not gnus-default-article-saver)
2319 (error "No default saver is defined")
2320 ;; !!! Magic! The saving functions all save
2321 ;; `gnus-save-article-buffer' (or so they think), but we
2322 ;; bind that variable to our save-buffer.
2323 (set-buffer gnus-article-buffer)
2324 (let* ((gnus-save-article-buffer save-buffer)
2327 ((not gnus-prompt-before-saving) 'default)
2328 ((eq gnus-prompt-before-saving 'always) nil)
2330 (gnus-number-of-articles-to-be-saved
2331 (when (eq gnus-prompt-before-saving t)
2333 (set-buffer gnus-article-current-summary)
2334 (funcall gnus-default-article-saver filename)))))
2336 (defun gnus-read-save-file-name (prompt &optional filename
2337 function group headers variable)
2339 (funcall function group headers (symbol-value variable)))
2344 ((eq filename 'default)
2350 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2353 (if (and gnus-number-of-articles-to-be-saved
2354 (> gnus-number-of-articles-to-be-saved 1))
2355 (format "these %d articles"
2356 gnus-number-of-articles-to-be-saved)
2359 ;; Let the split methods have their say.
2361 ;; No split name was found.
2364 (concat prompt " (default "
2365 (file-name-nondirectory default-name) ") ")
2366 (file-name-directory default-name)
2368 ;; A single group name is returned.
2369 ((stringp split-name)
2371 (funcall function split-name headers
2372 (symbol-value variable)))
2374 (concat prompt " (default "
2375 (file-name-nondirectory default-name) ") ")
2376 (file-name-directory default-name)
2378 ;; A single split name was found
2379 ((= 1 (length split-name))
2380 (let* ((name (expand-file-name
2381 (car split-name) gnus-article-save-directory))
2382 (dir (cond ((file-directory-p name)
2383 (file-name-as-directory name))
2384 ((file-exists-p name) name)
2385 (t gnus-article-save-directory))))
2387 (concat prompt " (default " name ") ")
2389 ;; A list of splits was found.
2391 (setq split-name (nreverse split-name))
2393 (let ((file-name-history
2394 (nconc split-name file-name-history)))
2398 (concat prompt " (`M-p' for defaults) ")
2399 gnus-article-save-directory
2401 gnus-article-save-directory)))
2402 (car (push result file-name-history)))))))
2403 ;; Create the directory.
2404 (gnus-make-directory (file-name-directory file))
2405 ;; If we have read a directory, we append the default file name.
2406 (when (file-directory-p file)
2407 (setq file (concat (file-name-as-directory file)
2408 (file-name-nondirectory default-name))))
2409 ;; Possibly translate some characters.
2410 (nnheader-translate-file-chars file)))))
2411 (gnus-make-directory (file-name-directory result))
2412 (set variable result)))
2414 (defun gnus-article-archive-name (group)
2415 "Return the first instance of an \"Archive-name\" in the current buffer."
2416 (let ((case-fold-search t))
2417 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2418 (nnheader-concat gnus-article-save-directory
2419 (match-string 1)))))
2421 (defun gnus-article-nndoc-name (group)
2422 "If GROUP is an nndoc group, return the name of the parent group."
2423 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2424 (gnus-group-get-parameter group 'save-article-group)))
2426 (defun gnus-summary-save-in-rmail (&optional filename)
2427 "Append this article to Rmail file.
2428 Optional argument FILENAME specifies file name.
2429 Directory to save to is default to `gnus-article-save-directory'."
2430 (setq filename (gnus-read-save-file-name
2431 "Save %s in rmail file:" filename
2432 gnus-rmail-save-name gnus-newsgroup-name
2433 gnus-current-headers 'gnus-newsgroup-last-rmail))
2434 (gnus-eval-in-buffer-window gnus-save-article-buffer
2438 (gnus-output-to-rmail filename))))
2441 (defun gnus-summary-save-in-mail (&optional filename)
2442 "Append this article to Unix mail file.
2443 Optional argument FILENAME specifies file name.
2444 Directory to save to is default to `gnus-article-save-directory'."
2445 (setq filename (gnus-read-save-file-name
2446 "Save %s in Unix mail file:" filename
2447 gnus-mail-save-name gnus-newsgroup-name
2448 gnus-current-headers 'gnus-newsgroup-last-mail))
2449 (gnus-eval-in-buffer-window gnus-save-article-buffer
2453 (if (and (file-readable-p filename)
2454 (mail-file-babyl-p filename))
2455 (rmail-output-to-rmail-file filename t)
2456 (gnus-output-to-mail filename)))))
2459 (defun gnus-summary-save-in-file (&optional filename overwrite)
2460 "Append this article to file.
2461 Optional argument FILENAME specifies file name.
2462 Directory to save to is default to `gnus-article-save-directory'."
2463 (setq filename (gnus-read-save-file-name
2464 "Save %s in file:" filename
2465 gnus-file-save-name gnus-newsgroup-name
2466 gnus-current-headers 'gnus-newsgroup-last-file))
2467 (gnus-eval-in-buffer-window gnus-save-article-buffer
2471 (when (and overwrite
2472 (file-exists-p filename))
2473 (delete-file filename))
2474 (gnus-output-to-file filename))))
2477 (defun gnus-summary-write-to-file (&optional filename)
2478 "Write this article to a file.
2479 Optional argument FILENAME specifies file name.
2480 The directory to save in defaults to `gnus-article-save-directory'."
2481 (gnus-summary-save-in-file nil t))
2483 (defun gnus-summary-save-body-in-file (&optional filename)
2484 "Append this article body to a file.
2485 Optional argument FILENAME specifies file name.
2486 The directory to save in defaults to `gnus-article-save-directory'."
2487 (setq filename (gnus-read-save-file-name
2488 "Save %s body in file:" filename
2489 gnus-file-save-name gnus-newsgroup-name
2490 gnus-current-headers 'gnus-newsgroup-last-file))
2491 (gnus-eval-in-buffer-window gnus-save-article-buffer
2495 (when (article-goto-body)
2496 (narrow-to-region (point) (point-max)))
2497 (gnus-output-to-file filename))))
2500 (defun gnus-summary-save-in-pipe (&optional command)
2501 "Pipe this article to subprocess."
2503 (cond ((and (eq command 'default)
2504 gnus-last-shell-command)
2505 gnus-last-shell-command)
2509 "Shell command on %s: "
2510 (if (and gnus-number-of-articles-to-be-saved
2511 (> gnus-number-of-articles-to-be-saved 1))
2512 (format "these %d articles"
2513 gnus-number-of-articles-to-be-saved)
2515 gnus-last-shell-command))))
2516 (when (string-equal command "")
2517 (setq command gnus-last-shell-command))
2518 (gnus-eval-in-buffer-window gnus-article-buffer
2521 (shell-command-on-region (point-min) (point-max) command nil)))
2522 (setq gnus-last-shell-command command))
2524 ;;; Article file names when saving.
2526 (defun gnus-capitalize-newsgroup (newsgroup)
2527 "Capitalize NEWSGROUP name."
2528 (when (not (zerop (length newsgroup)))
2529 (concat (char-to-string (upcase (aref newsgroup 0)))
2530 (substring newsgroup 1))))
2532 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2533 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2534 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2535 Otherwise, it is like ~/News/news/group/num."
2538 (concat (if (gnus-use-long-file-name 'not-save)
2539 (gnus-capitalize-newsgroup newsgroup)
2540 (gnus-newsgroup-directory-form newsgroup))
2541 "/" (int-to-string (mail-header-number headers)))
2542 gnus-article-save-directory)))
2544 (string-equal (file-name-directory default)
2545 (file-name-directory last-file))
2546 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2548 (or last-file default))))
2550 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2551 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2552 If variable `gnus-use-long-file-name' is non-nil, it is
2553 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2556 (concat (if (gnus-use-long-file-name 'not-save)
2558 (gnus-newsgroup-directory-form newsgroup))
2559 "/" (int-to-string (mail-header-number headers)))
2560 gnus-article-save-directory)))
2562 (string-equal (file-name-directory default)
2563 (file-name-directory last-file))
2564 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2566 (or last-file default))))
2568 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2569 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2570 If variable `gnus-use-long-file-name' is non-nil, it is
2571 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2574 (if (gnus-use-long-file-name 'not-save)
2575 (gnus-capitalize-newsgroup newsgroup)
2576 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2577 gnus-article-save-directory)))
2579 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2580 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2581 If variable `gnus-use-long-file-name' is non-nil, it is
2582 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2585 (if (gnus-use-long-file-name 'not-save)
2587 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2588 gnus-article-save-directory)))
2595 (setq afunc (car func)
2598 gfunc (intern (format "gnus-%s" func))))
2600 (if (not (fboundp afunc))
2602 `(lambda (&optional interactive &rest args)
2603 ,(documentation afunc t)
2604 (interactive (list t))
2606 (set-buffer gnus-article-buffer)
2608 (call-interactively ',afunc)
2609 (apply ',afunc args))))))))
2610 '(article-hide-headers
2611 article-hide-boring-headers
2612 article-toggle-headers
2613 article-treat-overstrike
2614 article-fill-long-lines
2615 article-capitalize-sentences
2617 article-display-x-face
2618 article-de-quoted-unreadable
2620 article-hide-list-identifiers
2622 article-strip-banner
2625 article-hide-signature
2626 article-strip-headers-in-body
2627 article-remove-trailing-blank-lines
2628 article-strip-leading-blank-lines
2629 article-strip-multiple-blank-lines
2630 article-strip-leading-space
2631 article-strip-trailing-space
2632 article-strip-blank-lines
2633 article-strip-all-blank-lines
2635 article-date-iso8601
2636 article-date-original
2638 article-decode-mime-words
2639 article-decode-charset
2640 article-decode-encoded-words
2644 article-treat-dumbquotes
2645 article-normalize-headers
2646 (article-show-all-headers . gnus-article-show-all-headers)
2647 (article-show-all . gnus-article-show-all))))
2650 ;;; Gnus article mode
2653 (put 'gnus-article-mode 'mode-class 'special)
2655 (gnus-define-keys gnus-article-mode-map
2656 " " gnus-article-goto-next-page
2657 "\177" gnus-article-goto-prev-page
2658 [delete] gnus-article-goto-prev-page
2659 [backspace] gnus-article-goto-prev-page
2660 "\C-c^" gnus-article-refer-article
2661 "h" gnus-article-show-summary
2662 "s" gnus-article-show-summary
2663 "\C-c\C-m" gnus-article-mail
2664 "?" gnus-article-describe-briefly
2665 "e" gnus-summary-edit-article
2666 "<" beginning-of-buffer
2668 "\C-c\C-i" gnus-info-find-node
2671 "\C-d" gnus-article-read-summary-keys
2672 "\M-*" gnus-article-read-summary-keys
2673 "\M-#" gnus-article-read-summary-keys
2674 "\M-^" gnus-article-read-summary-keys
2675 "\M-g" gnus-article-read-summary-keys)
2677 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2680 (unless (lookup-key gnus-article-mode-map key)
2681 (define-key gnus-article-mode-map key
2682 'gnus-article-read-summary-keys)))
2687 (let ((key (car elt)))
2688 (and (> (length key) 0)
2689 (not (eq 'menu-bar (aref key 0)))
2690 (symbolp (lookup-key gnus-summary-mode-map key))
2692 (accessible-keymaps gnus-summary-mode-map))
2696 (push (char-to-string c) keys)
2700 (defun gnus-article-make-menu-bar ()
2701 (gnus-turn-off-edit-menu 'article)
2702 (unless (boundp 'gnus-article-article-menu)
2704 gnus-article-article-menu gnus-article-mode-map ""
2706 ["Scroll forwards" gnus-article-goto-next-page t]
2707 ["Scroll backwards" gnus-article-goto-prev-page t]
2708 ["Show summary" gnus-article-show-summary t]
2709 ["Fetch Message-ID at point" gnus-article-refer-article t]
2710 ["Mail to address at point" gnus-article-mail t]
2711 ["Send a bug report" gnus-bug t]))
2714 gnus-article-treatment-menu gnus-article-mode-map ""
2716 ["Hide headers" gnus-article-toggle-headers t]
2717 ["Hide signature" gnus-article-hide-signature t]
2718 ["Hide citation" gnus-article-hide-citation t]
2719 ["Treat overstrike" gnus-article-treat-overstrike t]
2720 ["Remove carriage return" gnus-article-remove-cr t]
2721 ["Decode HZ" gnus-article-decode-HZ t]))
2723 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2725 (when (boundp 'gnus-summary-post-menu)
2726 (define-key gnus-article-mode-map [menu-bar post]
2727 (cons "Post" gnus-summary-post-menu)))
2729 (gnus-run-hooks 'gnus-article-menu-hook)))
2731 (defun gnus-article-mode ()
2732 "Major mode for displaying an article.
2734 All normal editing commands are switched off.
2736 The following commands are available in addition to all summary mode
2738 \\<gnus-article-mode-map>
2739 \\[gnus-article-next-page]\t Scroll the article one page forwards
2740 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2741 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2742 \\[gnus-article-show-summary]\t Display the summary buffer
2743 \\[gnus-article-mail]\t Send a reply to the address near point
2744 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2745 \\[gnus-info-find-node]\t Go to the Gnus info node"
2747 (when (gnus-visual-p 'article-menu 'menu)
2748 (gnus-article-make-menu-bar))
2749 (gnus-simplify-mode-line)
2750 (setq mode-name "Article")
2751 (setq major-mode 'gnus-article-mode)
2752 (make-local-variable 'minor-mode-alist)
2753 (unless (assq 'gnus-show-mime minor-mode-alist)
2754 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2755 (use-local-map gnus-article-mode-map)
2756 (gnus-update-format-specifications nil 'article-mode)
2757 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2758 (make-local-variable 'gnus-page-broken)
2759 (make-local-variable 'gnus-button-marker-list)
2760 (make-local-variable 'gnus-article-current-summary)
2761 (make-local-variable 'gnus-article-mime-handles)
2762 (make-local-variable 'gnus-article-decoded-p)
2763 (make-local-variable 'gnus-article-mime-handle-alist)
2764 (make-local-variable 'gnus-article-washed-types)
2765 (gnus-set-default-directory)
2766 (buffer-disable-undo)
2767 (setq buffer-read-only t)
2768 (set-syntax-table gnus-article-mode-syntax-table)
2769 (gnus-run-hooks 'gnus-article-mode-hook))
2771 (defun gnus-article-setup-buffer ()
2772 "Initialize the article buffer."
2773 (let* ((name (if gnus-single-article-buffer "*Article*"
2774 (concat "*Article " gnus-newsgroup-name "*")))
2776 (progn (string-match "\\*Article" name)
2777 (concat " *Original Article"
2778 (substring name (match-end 0))))))
2779 (setq gnus-article-buffer name)
2780 (setq gnus-original-article-buffer original)
2781 (setq gnus-article-mime-handle-alist nil)
2782 ;; This might be a variable local to the summary buffer.
2783 (unless gnus-single-article-buffer
2785 (set-buffer gnus-summary-buffer)
2786 (setq gnus-article-buffer name)
2787 (setq gnus-original-article-buffer original)
2788 (gnus-set-global-variables)))
2789 (gnus-article-setup-highlight-words)
2790 ;; Init original article buffer.
2792 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2793 (setq major-mode 'gnus-original-article-mode)
2794 (make-local-variable 'gnus-original-article))
2795 (if (get-buffer name)
2798 (kill-all-local-variables)
2799 (buffer-disable-undo)
2800 (setq buffer-read-only t)
2801 (unless (eq major-mode 'gnus-article-mode)
2802 (gnus-article-mode))
2805 (set-buffer (gnus-get-buffer-create name))
2807 (make-local-variable 'gnus-summary-buffer)
2808 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2809 (current-buffer)))))
2811 ;; Set article window start at LINE, where LINE is the number of lines
2812 ;; from the head of the article.
2813 (defun gnus-article-set-window-start (&optional line)
2815 (get-buffer-window gnus-article-buffer t)
2817 (set-buffer gnus-article-buffer)
2818 (goto-char (point-min))
2821 (gnus-message 6 "Moved to bookmark")
2822 (search-forward "\n\n" nil t)
2826 ;;; @@ article filters
2829 (defun gnus-article-display-mime-message ()
2830 "Article display method for MIME message."
2831 ;; called from `gnus-original-article-buffer'.
2832 (let (charset all-headers)
2833 (with-current-buffer gnus-summary-buffer
2834 (setq charset default-mime-charset
2835 all-headers gnus-have-all-headers))
2836 (make-local-variable 'default-mime-charset)
2837 (setq default-mime-charset charset)
2838 (with-current-buffer (get-buffer-create gnus-article-buffer)
2839 (make-local-variable 'default-mime-charset)
2840 (setq default-mime-charset charset))
2841 (mime-display-message mime-message-structure
2842 gnus-article-buffer nil gnus-article-mode-map)
2844 (gnus-article-hide-headers nil -1))
2846 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2847 (make-local-variable 'mime-button-mother-dispatcher)
2848 (setq mime-button-mother-dispatcher
2849 (function gnus-article-push-button))
2850 (run-hooks 'gnus-mime-article-prepare-hook))
2852 (defun gnus-article-display-traditional-message ()
2853 "Article display method for traditional message."
2854 (set-buffer gnus-article-buffer)
2855 (let (buffer-read-only)
2857 (insert-buffer-substring gnus-original-article-buffer)))
2859 (defun gnus-article-make-full-mail-header (&optional number charset)
2860 "Create a new mail header structure in a raw article buffer."
2861 (unless (and number charset)
2862 (save-current-buffer
2863 (set-buffer gnus-summary-buffer)
2865 (setq number (or (cdr gnus-article-current) 0)))
2867 (setq charset (or default-mime-charset 'x-ctext)))))
2868 (goto-char (point-min))
2869 (let ((header-end (if (search-forward "\n\n" nil t)
2871 (goto-char (point-max))))
2872 (chars (- (point-max) (point)))
2873 (lines (count-lines (point) (point-max)))
2874 (default-mime-charset charset)
2876 (narrow-to-region (point-min) header-end)
2877 (setq xref (std11-fetch-field "xref"))
2879 (make-full-mail-header
2881 (std11-fetch-field "subject")
2882 (std11-fetch-field "from")
2883 (std11-fetch-field "date")
2884 (std11-fetch-field "message-id")
2885 (std11-fetch-field "references")
2888 (when xref (concat "Xref: " xref)))
2891 (defun gnus-article-prepare (article &optional all-headers header)
2892 "Prepare ARTICLE in article mode buffer.
2893 ARTICLE should either be an article number or a Message-ID.
2894 If ARTICLE is an id, HEADER should be the article headers.
2895 If ALL-HEADERS is non-nil, no headers are hidden."
2897 ;; Make sure we start in a summary buffer.
2898 (unless (eq major-mode 'gnus-summary-mode)
2899 (set-buffer gnus-summary-buffer))
2900 (setq gnus-summary-buffer (current-buffer))
2901 (let* ((gnus-article (if header (mail-header-number header) article))
2902 (summary-buffer (current-buffer))
2903 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2904 (group gnus-newsgroup-name)
2907 (gnus-article-setup-buffer)
2908 (set-buffer gnus-original-article-buffer)
2909 ;; Deactivate active regions.
2910 (when (and (boundp 'transient-mark-mode)
2911 transient-mark-mode)
2912 (setq mark-active nil))
2913 (if (not (setq result (let ((buffer-read-only nil))
2914 (gnus-request-article-this-buffer
2916 ;; There is no such article.
2918 (when (and (numberp article)
2919 (not (memq article gnus-newsgroup-sparse)))
2920 (setq gnus-article-current
2921 (cons gnus-newsgroup-name article))
2922 (set-buffer gnus-summary-buffer)
2923 (setq gnus-current-article article)
2924 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2926 (gnus-summary-set-agent-mark article)
2927 (message "Message marked for downloading"))
2928 (gnus-summary-mark-article article gnus-canceled-mark)
2929 (unless (memq article gnus-newsgroup-sparse)
2931 "No such article (may have expired or been canceled)")))))
2932 (if (or (eq result 'pseudo)
2933 (eq result 'nneething))
2936 (set-buffer summary-buffer)
2937 (push article gnus-newsgroup-history)
2938 (setq gnus-last-article gnus-current-article
2939 gnus-current-article 0
2940 gnus-current-headers nil
2941 gnus-article-current nil)
2942 (if (eq result 'nneething)
2943 (gnus-configure-windows 'summary)
2944 (gnus-configure-windows 'article))
2945 (gnus-set-global-variables))
2946 (let ((gnus-article-mime-handle-alist-1
2947 gnus-article-mime-handle-alist))
2948 (gnus-set-mode-line 'article)))
2949 ;; The result from the `request' was an actual article -
2950 ;; or at least some text that is now displayed in the
2952 (when (and (numberp article)
2953 (not (eq article gnus-current-article)))
2954 ;; Seems like a new article has been selected.
2955 ;; `gnus-current-article' must be an article number.
2957 (set-buffer summary-buffer)
2958 (push article gnus-newsgroup-history)
2959 (setq gnus-last-article gnus-current-article
2960 gnus-current-article article
2961 gnus-current-headers
2962 (gnus-summary-article-header gnus-current-article)
2963 gnus-article-current
2964 (cons gnus-newsgroup-name gnus-current-article))
2965 (unless (vectorp gnus-current-headers)
2966 (setq gnus-current-headers nil))
2967 (gnus-summary-goto-subject gnus-current-article)
2968 (when (gnus-summary-show-thread)
2969 ;; If the summary buffer really was folded, the
2970 ;; previous goto may not actually have gone to
2971 ;; the right article, but the thread root instead.
2973 (gnus-summary-goto-subject gnus-current-article))
2974 (gnus-run-hooks 'gnus-mark-article-hook)
2975 (gnus-set-mode-line 'summary)
2976 (when (gnus-visual-p 'article-highlight 'highlight)
2977 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2978 ;; Set the global newsgroup variables here.
2979 (gnus-set-global-variables)
2980 (setq gnus-have-all-headers
2981 (or all-headers gnus-show-all-headers))))
2982 (when (or (numberp article)
2984 (gnus-article-prepare-display)
2986 (goto-char (point-min))
2987 (setq gnus-page-broken
2988 (when gnus-break-pages
2989 (gnus-narrow-to-page)
2991 (let ((gnus-article-mime-handle-alist-1
2992 gnus-article-mime-handle-alist))
2993 (gnus-set-mode-line 'article))
2995 (set-window-point (get-buffer-window (current-buffer)) (point))
2996 (gnus-configure-windows 'article)
2999 (defun gnus-article-prepare-mime-display (&optional number)
3000 (goto-char (point-min))
3001 (when (re-search-forward "^[^\t ]+:" nil t)
3002 (goto-char (match-beginning 0)))
3003 (let ((entity (if (eq 1 (point-min))
3004 (get-text-property 1 'mime-view-entity)
3005 (get-text-property (point) 'mime-view-entity)))
3006 last-entity child-entity next type)
3007 (setq child-entity (mime-entity-children entity))
3009 (setq last-entity (nth (1- (length child-entity))
3011 (setq last-entity entity))
3013 (narrow-to-region (point)
3014 (if (search-forward "\n\n" nil t)
3017 (gnus-treat-article 'head)
3018 (put-text-property (point-min) (point-max) 'article-treated-header t)
3019 (goto-char (point-max)))
3020 (while (and (not (eobp)) entity)
3021 (setq next (set-marker
3023 (next-single-property-change (point) 'mime-view-entity
3025 (let ((types (mime-entity-content-type entity)))
3026 (while (eq 'multipart (mime-content-type-primary-type types))
3027 (setq entity (car (mime-entity-children entity))
3028 types (mime-entity-content-type entity)))
3030 (setq type (format "%s/%s"
3031 (mime-content-type-primary-type types)
3032 (mime-content-type-subtype types)))))
3033 (if (string-equal type "message/rfc822")
3036 (let ((children (mime-entity-children entity))
3039 (setq last-children (nth (1- (length children)) children))
3042 (not (eq last-children
3043 (get-text-property next 'mime-view-entity)))
3045 (next-single-property-change next
3047 nil (point-max)))))))
3048 (setq next (next-single-property-change next 'mime-view-entity
3051 (narrow-to-region (point) next)
3052 (gnus-article-prepare-mime-display)
3053 (goto-char (point-max)))
3054 (setq entity (get-text-property (point) 'mime-view-entity)))
3056 (narrow-to-region (point) next)
3057 ;; Kludge. We have to count true number, but for now,
3058 ;; part number is here only to achieve `last'.
3059 (gnus-treat-article nil 1
3060 (if (eq entity last-entity)
3063 (goto-char (point-max)))
3064 (setq entity (get-text-property next 'mime-view-entity))))))
3067 (defun gnus-article-prepare-display ()
3068 "Make the current buffer look like a nice article."
3069 (setq gnus-article-wash-types nil)
3070 (gnus-run-hooks 'gnus-tmp-internal-hook)
3071 (gnus-run-hooks 'gnus-article-prepare-hook)
3073 (let (mime-display-header-hook mime-display-text/plain-hook)
3074 (funcall (if gnus-show-mime
3076 (setq mime-message-structure gnus-current-headers)
3077 (mime-buffer-entity-set-buffer-internal
3078 mime-message-structure
3079 gnus-original-article-buffer)
3080 (mime-entity-set-representation-type-internal
3081 mime-message-structure 'mime-buffer-entity)
3082 (luna-send mime-message-structure
3083 'initialize-instance
3084 mime-message-structure)
3085 gnus-article-display-method-for-mime)
3086 gnus-article-display-method-for-traditional)))
3087 ;; Associate this article with the current summary buffer.
3088 (setq gnus-article-current-summary gnus-summary-buffer)
3089 ;; Call the treatment functions.
3090 (let ((inhibit-read-only t)
3095 (gnus-article-prepare-mime-display)
3096 (narrow-to-region (goto-char (point-min))
3097 (if (search-forward "\n\n" nil t)
3100 (gnus-treat-article 'head)
3101 (put-text-property (point-min) (point-max) 'article-treated-header t)
3102 (goto-char (point-max))
3104 (narrow-to-region (point) (point-max))
3105 (gnus-treat-article nil))
3106 (put-text-property (point-min) (point-max) 'read-only nil)))
3107 ;; Perform the article display hooks. Incidentally, this hook is
3108 ;; an obsolete variable by now.
3109 (gnus-run-hooks 'gnus-article-display-hook))
3111 (defun gnus-article-decode-article-as-default-mime-charset ()
3112 "Decode an article as `default-mime-charset'. It won't work if the
3113 value of the variable `gnus-show-mime' is non-nil."
3114 (unless gnus-show-mime
3115 (decode-mime-charset-region (point-min) (point-max)
3116 (with-current-buffer gnus-summary-buffer
3117 default-mime-charset))))
3120 ;;; Gnus MIME viewing functions
3123 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3124 "The following specs can be used:
3126 %T MIME type, along with additional info
3127 %n The `name' parameter
3128 %d The description, if any
3129 %l The length of the encoded part
3130 %p The part identifier number
3131 %e Dots if the part isn't displayed")
3133 (defvar gnus-mime-button-line-format-alist
3134 '((?t gnus-tmp-type ?s)
3135 (?T gnus-tmp-type-long ?s)
3136 (?n gnus-tmp-name ?s)
3137 (?d gnus-tmp-description ?s)
3139 (?l gnus-tmp-length ?d)
3140 (?e gnus-tmp-dots ?s)))
3142 (defvar gnus-mime-button-commands
3143 '((gnus-article-press-button "\r" "Toggle Display")
3144 (gnus-mime-view-part "v" "View Interactively...")
3145 (gnus-mime-view-part-as-type "t" "View As Type...")
3146 (gnus-mime-save-part "o" "Save...")
3147 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3148 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3149 (gnus-mime-internalize-part "E" "View Internally")
3150 (gnus-mime-externalize-part "e" "View Externally")
3151 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3153 (defun gnus-article-mime-part-status ()
3154 (with-current-buffer gnus-article-buffer
3155 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3156 (if (and entity (mime-entity-children entity))
3157 (format " (%d parts)" (length (mime-entity-children entity)))
3160 (defvar gnus-mime-button-map nil)
3161 (unless gnus-mime-button-map
3162 (setq gnus-mime-button-map (make-sparse-keymap))
3163 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3164 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3165 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3167 (define-key gnus-mime-button-map (cadr c) (car c)))
3168 gnus-mime-button-commands))
3170 (defun gnus-mime-button-menu (event)
3171 "Construct a context-sensitive menu of MIME commands."
3174 (let ((pos (event-start event)))
3175 (set-buffer (window-buffer (posn-window pos)))
3176 (goto-char (posn-point pos))
3177 (gnus-article-check-buffer)
3178 (let ((response (x-popup-menu
3180 ("" ,@(mapcar (lambda (c)
3181 (cons (caddr c) (car c)))
3182 gnus-mime-button-commands))))))
3184 (funcall response))))))
3186 (defun gnus-mime-view-all-parts (&optional handles)
3187 "View all the MIME parts."
3189 (save-current-buffer
3190 (set-buffer gnus-article-buffer)
3191 (let ((handles (or handles gnus-article-mime-handles))
3192 (mail-parse-charset gnus-newsgroup-charset)
3193 (mail-parse-ignored-charsets
3194 (save-excursion (set-buffer gnus-summary-buffer)
3195 gnus-newsgroup-ignored-charsets)))
3196 (if (stringp (car handles))
3197 (gnus-mime-view-all-parts (cdr handles))
3198 (mapcar 'mm-display-part handles)))))
3200 (defun gnus-mime-save-part ()
3201 "Save the MIME part under point."
3203 (gnus-article-check-buffer)
3204 (let ((data (get-text-property (point) 'gnus-data)))
3205 (mm-save-part data)))
3207 (defun gnus-mime-pipe-part ()
3208 "Pipe the MIME part under point to a process."
3210 (gnus-article-check-buffer)
3211 (let ((data (get-text-property (point) 'gnus-data)))
3212 (mm-pipe-part data)))
3214 (defun gnus-mime-view-part ()
3215 "Interactively choose a viewing method for the MIME part under point."
3217 (gnus-article-check-buffer)
3218 (let ((data (get-text-property (point) 'gnus-data)))
3219 (mm-interactively-view-part data)))
3221 (defun gnus-mime-view-part-as-type-internal ()
3222 (gnus-article-check-buffer)
3223 (let* ((name (mail-content-type-get
3224 (mm-handle-type (get-text-property (point) 'gnus-data))
3226 (def-type (and name (mm-default-file-encoding name))))
3227 (and def-type (cons def-type 0))))
3229 (defun gnus-mime-view-part-as-type (mime-type)
3230 "Choose a MIME media type, and view the part as such."
3232 (list (completing-read
3233 "View as MIME type: "
3234 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
3236 (gnus-mime-view-part-as-type-internal))))
3237 (gnus-article-check-buffer)
3238 (let ((handle (get-text-property (point) 'gnus-data)))
3239 (gnus-mm-display-part
3240 (mm-make-handle (mm-handle-buffer handle)
3241 (cons mime-type (cdr (mm-handle-type handle)))
3242 (mm-handle-encoding handle)
3243 (mm-handle-undisplayer handle)
3244 (mm-handle-disposition handle)
3245 (mm-handle-description handle)
3246 (mm-handle-cache handle)
3247 (mm-handle-id handle)))))
3249 (defun gnus-mime-copy-part (&optional handle)
3250 "Put the the MIME part under point into a new buffer."
3252 (gnus-article-check-buffer)
3253 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3254 (contents (mm-get-part handle))|
3255 (base (file-name-nondirectory
3257 (mail-content-type-get (mm-handle-type handle) 'name)
3258 (mail-content-type-get (mm-handle-type handle)
3261 (buffer (generate-new-buffer base)))
3262 (switch-to-buffer buffer)
3264 ;; We do it this way to make `normal-mode' set the appropriate mode.
3267 (setq buffer-file-name (expand-file-name base))
3269 (setq buffer-file-name nil))
3270 (goto-char (point-min))))
3272 (defun gnus-mime-inline-part (&optional handle)
3273 "Insert the MIME part under point into the current buffer."
3275 (gnus-article-check-buffer)
3276 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3280 (if (mm-handle-undisplayer handle)
3281 (mm-remove-part handle)
3282 (setq contents (mm-get-part handle))
3284 (mm-insert-inline handle contents)
3287 (defun gnus-mime-externalize-part (&optional handle)
3288 "View the MIME part under point with an external viewer."
3290 (gnus-article-check-buffer)
3291 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3292 (mm-user-display-methods nil)
3293 (mm-inline-large-images nil)
3294 (mail-parse-charset gnus-newsgroup-charset)
3295 (mail-parse-ignored-charsets
3296 (save-excursion (set-buffer gnus-summary-buffer)
3297 gnus-newsgroup-ignored-charsets)))
3298 (if (mm-handle-undisplayer handle)
3299 (mm-remove-part handle)
3300 (mm-display-part handle))))
3302 (defun gnus-mime-internalize-part (&optional handle)
3303 "View the MIME part under point with an internal viewer.
3304 In no internal viewer is available, use an external viewer."
3306 (gnus-article-check-buffer)
3307 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3308 (mm-inlined-types '(".*"))
3309 (mm-inline-large-images t)
3310 (mail-parse-charset gnus-newsgroup-charset)
3311 (mail-parse-ignored-charsets
3312 (save-excursion (set-buffer gnus-summary-buffer)
3313 gnus-newsgroup-ignored-charsets)))
3314 (if (mm-handle-undisplayer handle)
3315 (mm-remove-part handle)
3316 (mm-display-part handle))))
3318 (defun gnus-article-part-wrapper (n function)
3319 (save-current-buffer
3320 (set-buffer gnus-article-buffer)
3321 (when (> n (length gnus-article-mime-handle-alist))
3322 (error "No such part"))
3323 (gnus-article-goto-part n)
3324 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3325 (funcall function handle))))
3327 (defun gnus-article-pipe-part (n)
3328 "Pipe MIME part N, which is the numerical prefix."
3330 (gnus-article-part-wrapper n 'mm-pipe-part))
3332 (defun gnus-article-save-part (n)
3333 "Save MIME part N, which is the numerical prefix."
3335 (gnus-article-part-wrapper n 'mm-save-part))
3337 (defun gnus-article-interactively-view-part (n)
3338 "View MIME part N interactively, which is the numerical prefix."
3340 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3342 (defun gnus-article-copy-part (n)
3343 "Copy MIME part N, which is the numerical prefix."
3345 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3347 (defun gnus-article-externalize-part (n)
3348 "View MIME part N externally, which is the numerical prefix."
3350 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3352 (defun gnus-article-inline-part (n)
3353 "Inline MIME part N, which is the numerical prefix."
3355 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3357 (defun gnus-article-mime-match-handle-first (condition)
3359 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3360 (while (setq ihandle (pop alist))
3362 ((functionp condition)
3363 (funcall condition (cdr ihandle)))
3364 ((eq condition 'undisplayed)
3365 (not (or (mm-handle-undisplayer (cdr ihandle))
3366 (equal (mm-handle-media-type (cdr ihandle))
3367 "multipart/alternative"))))
3368 ((eq condition 'undisplayed-alternative)
3369 (not (mm-handle-undisplayer (cdr ihandle))))
3371 (gnus-article-goto-part (car ihandle))
3372 (or (not n) (< (car ihandle) n)))
3373 (setq n (car ihandle))))
3377 (defun gnus-article-view-part (&optional n)
3378 "View MIME part N, which is the numerical prefix."
3380 (save-current-buffer
3381 (set-buffer gnus-article-buffer)
3382 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3383 gnus-article-mime-match-handle-function)))
3384 (when (> n (length gnus-article-mime-handle-alist))
3385 (error "No such part"))
3386 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3387 (when (gnus-article-goto-part n)
3388 (if (equal (car handle) "multipart/alternative")
3389 (gnus-article-press-button)
3390 (when (eq (gnus-mm-display-part handle) 'internal)
3391 (gnus-set-window-start)))))))
3393 (defun gnus-mm-display-part (handle)
3394 "Display HANDLE and fix MIME button."
3395 (let ((id (get-text-property (point) 'gnus-part))
3400 (let ((window (selected-window))
3401 (mail-parse-charset gnus-newsgroup-charset)
3402 (mail-parse-ignored-charsets
3403 (save-excursion (set-buffer gnus-summary-buffer)
3404 gnus-newsgroup-ignored-charsets)))
3407 (let ((win (get-buffer-window (current-buffer) t))
3410 (select-window win))
3413 (if (mm-handle-displayed-p handle)
3414 ;; This will remove the part.
3415 (mm-display-part handle)
3417 (narrow-to-region (point) (1+ (point)))
3418 (mm-display-part handle)
3419 ;; We narrow to the part itself and
3420 ;; then call the treatment functions.
3421 (goto-char (point-min))
3423 (narrow-to-region (point) (point-max))
3426 (1- (length gnus-article-mime-handles))
3427 (mm-handle-media-type handle)))))
3428 (select-window window))))
3430 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3431 (gnus-insert-mime-button
3432 handle id (list (mm-handle-displayed-p handle)))
3433 (goto-char point))))
3435 (defun gnus-article-goto-part (n)
3436 "Go to MIME part N."
3437 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3439 (goto-char point))))
3441 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3442 (let ((gnus-tmp-name
3443 (or (mail-content-type-get (mm-handle-type handle)
3445 (mail-content-type-get (mm-handle-disposition handle)
3448 (gnus-tmp-type (mm-handle-media-type handle))
3449 (gnus-tmp-description
3450 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3453 (if (if displayed (car displayed)
3454 (mm-handle-displayed-p handle))
3456 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3458 gnus-tmp-type-long b e)
3459 (when (string-match ".*/" gnus-tmp-name)
3460 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3461 (setq gnus-tmp-type-long (concat gnus-tmp-type
3462 (and (not (equal gnus-tmp-name ""))
3463 (concat "; " gnus-tmp-name))))
3464 (or (equal gnus-tmp-description "")
3465 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3470 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3471 `(local-map ,gnus-mime-button-map
3472 keymap ,gnus-mime-button-map
3473 gnus-callback gnus-mm-display-part
3474 gnus-part ,gnus-tmp-id
3475 article-type annotation
3478 (widget-convert-button 'link b e
3480 :action 'gnus-widget-press-button
3481 :button-keymap gnus-mime-button-map
3484 ;; Needed to properly clear the message
3485 ;; due to a bug in wid-edit
3486 (setq help-echo-owns-message t)
3488 "Click to %s the MIME part; %s for more options"
3489 (if (mm-handle-displayed-p
3490 (widget-get widget :mime-handle))
3492 (if gnus-xemacs "button3" "mouse-3"))))))
3494 (defun gnus-widget-press-button (elems el)
3495 (goto-char (widget-get elems :from))
3496 (gnus-article-press-button))
3498 (defvar gnus-displaying-mime nil)
3500 (defun gnus-display-mime (&optional ihandles)
3501 "Display the MIME parts."
3503 (save-selected-window
3504 (let ((window (get-buffer-window gnus-article-buffer))
3507 (select-window window)
3508 ;; We have to do this since selecting the window
3509 ;; may change the point. So we set the window point.
3510 (set-window-point window point)))
3511 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3512 buffer-read-only handle name type b e display)
3513 (when (and (not ihandles)
3514 (not gnus-displaying-mime))
3515 ;; Top-level call; we clean up.
3516 (when gnus-article-mime-handles
3517 (mm-destroy-parts gnus-article-mime-handles)
3518 (setq gnus-article-mime-handle-alist nil));; A trick.
3519 (setq gnus-article-mime-handles handles)
3520 ;; We allow users to glean info from the handles.
3521 (when gnus-article-mime-part-function
3522 (gnus-mime-part-function handles)))
3524 (or (not (stringp (car handles)))
3527 (when (and (not ihandles)
3528 (not gnus-displaying-mime))
3529 ;; Clean up for mime parts.
3531 (delete-region (point) (point-max)))
3532 (let ((gnus-displaying-mime t))
3533 (gnus-mime-display-part handles)))
3536 (narrow-to-region (point) (point-max))
3537 (gnus-treat-article nil 1 1)
3540 ;; Highlight the headers.
3544 (narrow-to-region (point-min) (point))
3545 (gnus-treat-article 'head))))))))
3547 (defvar gnus-mime-display-multipart-as-mixed nil)
3549 (defun gnus-mime-display-part (handle)
3552 ((not (stringp (car handle)))
3553 (gnus-mime-display-single handle))
3554 ;; User-defined multipart
3555 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3556 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3558 ;; multipart/alternative
3559 ((and (equal (car handle) "multipart/alternative")
3560 (not gnus-mime-display-multipart-as-mixed))
3561 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3562 (push (cons id handle) gnus-article-mime-handle-alist)
3563 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3564 ;; multipart/related
3565 ((and (equal (car handle) "multipart/related")
3566 (not gnus-mime-display-multipart-as-mixed))
3567 ;;;!!!We should find the start part, but we just default
3568 ;;;!!!to the first part.
3569 (gnus-mime-display-part (cadr handle)))
3570 ;; Other multiparts are handled like multipart/mixed.
3572 (gnus-mime-display-mixed (cdr handle)))))
3574 (defun gnus-mime-part-function (handles)
3575 (if (stringp (car handles))
3576 (mapcar 'gnus-mime-part-function (cdr handles))
3577 (funcall gnus-article-mime-part-function handles)))
3579 (defun gnus-mime-display-mixed (handles)
3580 (mapcar 'gnus-mime-display-part handles))
3582 (defun gnus-mime-display-single (handle)
3583 (let ((type (mm-handle-media-type handle))
3584 (ignored gnus-ignored-mime-types)
3591 (when (string-match (pop ignored) type)
3592 (throw 'ignored nil)))
3593 (if (and (setq not-attachment
3594 (and (not (mm-inline-override-p handle))
3595 (or (not (mm-handle-disposition handle))
3596 (equal (car (mm-handle-disposition handle))
3598 (mm-attachment-override-p handle))))
3599 (mm-automatic-display-p handle)
3600 (or (mm-inlined-p handle)
3601 (mm-automatic-external-display-p type)))
3603 (when (equal (mm-handle-media-supertype handle) "text")
3605 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3606 (push (cons id handle) gnus-article-mime-handle-alist)
3607 (when (or (not display)
3608 (not (gnus-unbuttonized-mime-type-p type)))
3609 ;(gnus-article-insert-newline)
3610 (gnus-insert-mime-button
3611 handle id (list (or display (and not-attachment text))))
3612 (gnus-article-insert-newline)
3613 ;(gnus-article-insert-newline)
3615 (let ((beg (point)))
3621 (let ((mail-parse-charset gnus-newsgroup-charset)
3622 (mail-parse-ignored-charsets
3623 (save-excursion (condition-case ()
3624 (set-buffer gnus-summary-buffer)
3626 gnus-newsgroup-ignored-charsets)))
3627 (mm-display-part handle t))
3628 (goto-char (point-max)))
3629 ((and text not-attachment)
3633 (gnus-article-insert-newline)
3634 (mm-insert-inline handle (mm-get-part handle))
3635 (goto-char (point-max))))
3639 (narrow-to-region beg (point))
3641 nil (length gnus-article-mime-handle-alist)
3642 (1- (length gnus-article-mime-handles))
3643 (mm-handle-media-type handle)))))))))
3645 (defun gnus-unbuttonized-mime-type-p (type)
3646 "Say whether TYPE is to be unbuttonized."
3647 (unless gnus-inhibit-mime-unbuttonizing
3649 (let ((types gnus-unbuttonized-mime-types))
3651 (when (string-match (pop types) type)
3652 (throw 'found t)))))))
3654 (defun gnus-article-insert-newline ()
3655 "Insert a newline, but mark it as undeletable."
3656 (gnus-put-text-property
3657 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3659 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3660 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3663 handle buffer-read-only from props begend not-pref)
3664 (save-window-excursion
3667 (narrow-to-region (car ibegend)
3670 (goto-char (car ibegend))
3673 (delete-region (point-min) (point-max))
3674 (mm-remove-parts handles))
3675 (setq begend (list (point-marker)))
3677 (unless (setq not-pref (cadr (member preferred ihandles)))
3678 (setq not-pref (car ihandles)))
3680 (not (gnus-unbuttonized-mime-type-p
3681 "multipart/alternative")))
3682 (gnus-add-text-properties
3685 (insert (format "%d. " id))
3689 (unless ,(not ibegend)
3690 (setq gnus-article-mime-handle-alist
3691 ',gnus-article-mime-handle-alist))
3692 (gnus-mime-display-alternative
3693 ',ihandles ',not-pref ',begend ,id))
3694 local-map ,gnus-mime-button-map
3695 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3696 face ,gnus-article-button-face
3697 keymap ,gnus-mime-button-map
3700 (widget-convert-button 'link from (point)
3701 :action 'gnus-widget-press-button
3702 :button-keymap gnus-widget-button-keymap)
3704 (while (setq handle (pop handles))
3705 (gnus-add-text-properties
3708 (insert (format "(%c) %-18s"
3709 (if (equal handle preferred) ?* ? )
3710 (mm-handle-media-type handle)))
3714 (unless ,(not ibegend)
3715 (setq gnus-article-mime-handle-alist
3716 ',gnus-article-mime-handle-alist))
3717 (gnus-mime-display-alternative
3718 ',ihandles ',handle ',begend ,id))
3719 local-map ,gnus-mime-button-map
3720 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3721 face ,gnus-article-button-face
3722 keymap ,gnus-mime-button-map
3725 (widget-convert-button 'link from (point)
3726 :action 'gnus-widget-press-button
3727 :button-keymap gnus-widget-button-keymap)
3731 (if (stringp (car preferred))
3732 (gnus-display-mime preferred)
3733 (let ((mail-parse-charset gnus-newsgroup-charset)
3734 (mail-parse-ignored-charsets
3735 (save-excursion (set-buffer gnus-summary-buffer)
3736 gnus-newsgroup-ignored-charsets)))
3737 (mm-display-part preferred)
3741 (narrow-to-region (car begend) (point-max))
3743 nil (length gnus-article-mime-handle-alist)
3744 (1- (length gnus-article-mime-handles))
3745 (mm-handle-media-type handle))))))
3746 (goto-char (point-max))
3747 (setcdr begend (point-marker)))))
3749 (goto-char point))))
3751 (defun gnus-article-wash-status ()
3752 "Return a string which display status of article washing."
3754 (set-buffer gnus-article-buffer)
3755 (let ((cite (memq 'cite gnus-article-wash-types))
3756 (headers (memq 'headers gnus-article-wash-types))
3757 (boring (memq 'boring-headers gnus-article-wash-types))
3758 (pgp (memq 'pgp gnus-article-wash-types))
3759 (pem (memq 'pem gnus-article-wash-types))
3760 (signature (memq 'signature gnus-article-wash-types))
3761 (overstrike (memq 'overstrike gnus-article-wash-types))
3762 (emphasis (memq 'emphasis gnus-article-wash-types)))
3763 (format "%c%c%c%c%c%c%c"
3765 (if (or headers boring) ?h ? )
3766 (if (or pgp pem) ?p ? )
3767 (if signature ?s ? )
3768 (if overstrike ?o ? )
3769 (if gnus-show-mime ?m ? )
3770 (if emphasis ?e ? )))))
3772 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3774 (defun gnus-article-maybe-hide-headers ()
3775 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3776 Provided for backwards compatibility."
3777 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3778 (not (save-excursion (set-buffer gnus-summary-buffer)
3779 gnus-have-all-headers)))
3780 (not gnus-inhibit-hiding))
3781 (gnus-article-hide-headers)))
3785 (defun gnus-output-to-file (file-name)
3786 "Append the current article to a file named FILE-NAME."
3787 (let ((artbuf (current-buffer)))
3789 (insert-buffer-substring artbuf)
3790 ;; Append newline at end of the buffer as separator, and then
3792 (goto-char (point-max))
3794 (write-region-as-binary (point-min) (point-max) file-name 'append)
3797 (defun gnus-narrow-to-page (&optional arg)
3798 "Narrow the article buffer to a page.
3799 If given a numerical ARG, move forward ARG pages."
3801 (setq arg (if arg (prefix-numeric-value arg) 0))
3803 (set-buffer gnus-article-buffer)
3804 (goto-char (point-min))
3806 ;; Remove any old next/prev buttons.
3807 (when (gnus-visual-p 'page-marker)
3808 (let ((buffer-read-only nil))
3809 (gnus-remove-text-with-property 'gnus-prev)
3810 (gnus-remove-text-with-property 'gnus-next)))
3813 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3815 (re-search-forward page-delimiter nil 'move arg)))
3816 (goto-char (match-end 0)))
3819 (if (re-search-forward page-delimiter nil 'move)
3822 (when (and (gnus-visual-p 'page-marker)
3823 (not (= (point-min) 1)))
3825 (goto-char (point-min))
3826 (gnus-insert-prev-page-button)))
3827 (when (and (gnus-visual-p 'page-marker)
3828 (< (+ (point-max) 2) (buffer-size)))
3830 (goto-char (point-max))
3831 (gnus-insert-next-page-button)))))
3833 ;; Article mode commands
3835 (defun gnus-article-goto-next-page ()
3836 "Show the next page of the article."
3838 (when (gnus-article-next-page)
3839 (goto-char (point-min))
3840 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3842 (defun gnus-article-goto-prev-page ()
3843 "Show the next page of the article."
3845 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3846 (gnus-article-prev-page nil)))
3848 (defun gnus-article-next-page (&optional lines)
3849 "Show the next page of the current article.
3850 If end of article, return non-nil. Otherwise return nil.
3851 Argument LINES specifies lines to be scrolled up."
3853 (let ((start (window-start))
3854 end-of-buffer end-of-page)
3856 (move-to-window-line -1)
3857 (if (<= (point) start)
3860 (setq start (point)))
3863 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3864 (and (pos-visible-in-window-p)
3865 (setq end-of-buffer t)))
3867 (setq end-of-page t)))
3869 (move-to-window-line lines)
3870 (unless (search-backward "\n\n" nil t)
3871 (setq start (point)))))
3872 (cond (end-of-buffer t)
3874 (gnus-narrow-to-page 1)
3878 (set-window-start (selected-window) start)
3879 (let (window-pixel-scroll-increment)
3883 (defun gnus-article-prev-page (&optional lines)
3884 "Show previous page of current article.
3885 Argument LINES specifies lines to be scrolled down."
3887 (let (beginning-of-buffer beginning-of-page)
3889 (move-to-window-line 0)
3890 (cond ((eq 1 (point))
3891 (setq beginning-of-buffer t))
3893 (setq beginning-of-page t))))
3894 (cond (beginning-of-buffer)
3896 (gnus-narrow-to-page -1))
3899 (let (window-pixel-scroll-increment)
3900 (scroll-down lines))
3901 (beginning-of-buffer
3902 (goto-char (point-min))))))))
3904 (defun gnus-article-refer-article ()
3905 "Read article specified by message-id around point."
3907 (let ((point (point)))
3908 (search-forward ">" nil t) ;Move point to end of "<....>".
3909 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3910 (let ((message-id (match-string 1)))
3912 (set-buffer gnus-summary-buffer)
3913 (gnus-summary-refer-article message-id))
3915 (error "No references around point"))))
3917 (defun gnus-article-show-summary ()
3918 "Reconfigure windows to show summary buffer."
3920 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3921 (error "There is no summary buffer for this article buffer")
3922 (gnus-article-set-globals)
3923 (gnus-configure-windows 'article)
3924 (gnus-summary-goto-subject gnus-current-article)
3925 (gnus-summary-position-point)))
3927 (defun gnus-article-describe-briefly ()
3928 "Describe article mode commands briefly."
3930 (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")))
3932 (defun gnus-article-summary-command ()
3933 "Execute the last keystroke in the summary buffer."
3935 (let ((obuf (current-buffer))
3936 (owin (current-window-configuration))
3938 (switch-to-buffer gnus-article-current-summary 'norecord)
3939 (setq func (lookup-key (current-local-map) (this-command-keys)))
3940 (call-interactively func)
3942 (set-window-configuration owin)
3943 (set-window-point (get-buffer-window (current-buffer)) (point))))
3945 (defun gnus-article-summary-command-nosave ()
3946 "Execute the last keystroke in the summary buffer."
3949 (pop-to-buffer gnus-article-current-summary 'norecord)
3950 (setq func (lookup-key (current-local-map) (this-command-keys)))
3951 (call-interactively func)))
3953 (defun gnus-article-check-buffer ()
3954 "Beep if not in an article buffer."
3955 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3956 (error "Command invoked outside of a Gnus article buffer")))
3958 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3959 "Read a summary buffer key sequence and execute it from the article buffer."
3961 (gnus-article-check-buffer)
3963 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3964 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3965 "=" "^" "\M-^" "|"))
3971 '("n" "Gn" "p" "Gp"))
3974 (set-buffer gnus-article-current-summary)
3975 (let (gnus-pick-mode)
3976 (push (or key last-command-event) unread-command-events)
3977 (setq keys (static-if (featurep 'xemacs)
3978 (events-to-keys (read-key-sequence nil))
3979 (read-key-sequence nil)))))
3982 (if (or (member keys nosaves)
3983 (member keys nosave-but-article)
3984 (member keys nosave-in-article))
3986 (save-window-excursion
3987 (pop-to-buffer gnus-article-current-summary 'norecord)
3988 ;; We disable the pick minor mode commands.
3989 (let (gnus-pick-mode)
3990 (setq func (lookup-key (current-local-map) keys))))
3993 (unless (member keys nosave-in-article)
3994 (set-buffer gnus-article-current-summary))
3995 (call-interactively func)
3996 (setq new-sum-point (point)))
3997 (when (member keys nosave-but-article)
3998 (pop-to-buffer gnus-article-buffer 'norecord)))
3999 ;; These commands should restore window configuration.
4000 (let ((obuf (current-buffer))
4001 (owin (current-window-configuration))
4003 (summary gnus-article-current-summary)
4004 func in-buffer selected)
4005 (if not-restore-window
4006 (pop-to-buffer summary 'norecord)
4007 (switch-to-buffer summary 'norecord))
4008 (setq in-buffer (current-buffer))
4009 ;; We disable the pick minor mode commands.
4010 (if (setq func (let (gnus-pick-mode)
4011 (lookup-key (current-local-map) keys)))
4013 (call-interactively func)
4014 (setq new-sum-point (point)))
4016 (when (eq in-buffer (current-buffer))
4017 (setq selected (gnus-summary-select-article))
4019 (unless not-restore-window
4020 (set-window-configuration owin))
4021 (when (eq selected 'old)
4023 (set-window-start (get-buffer-window (current-buffer))
4025 (set-window-point (get-buffer-window (current-buffer))
4027 (let ((win (get-buffer-window gnus-article-current-summary)))
4029 (set-window-point win new-sum-point))))))))
4031 (defun gnus-article-hide (&optional arg force)
4032 "Hide all the gruft in the current article.
4033 This means that PGP stuff, signatures, cited text and (some)
4034 headers will be hidden.
4035 If given a prefix, show the hidden text instead."
4036 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4037 (gnus-article-hide-headers arg)
4038 (gnus-article-hide-list-identifiers arg)
4039 (gnus-article-hide-pgp arg)
4040 (gnus-article-hide-citation-maybe arg force)
4041 (gnus-article-hide-signature arg))
4043 (defun gnus-article-maybe-highlight ()
4044 "Do some article highlighting if article highlighting is requested."
4045 (when (gnus-visual-p 'article-highlight 'highlight)
4046 (gnus-article-highlight-some)))
4048 (defun gnus-check-group-server ()
4049 ;; Make sure the connection to the server is alive.
4050 (unless (gnus-server-opened
4051 (gnus-find-method-for-group gnus-newsgroup-name))
4052 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4053 (gnus-request-group gnus-newsgroup-name t)))
4055 (defun gnus-request-article-this-buffer (article group)
4056 "Get an article and insert it into this buffer."
4057 (let (do-update-line sparse-header)
4061 (gnus-kill-all-overlays)
4062 (setq group (or group gnus-newsgroup-name))
4064 ;; Using `gnus-request-article' directly will insert the article into
4065 ;; `nntp-server-buffer' - so we'll save some time by not having to
4066 ;; copy it from the server buffer into the article buffer.
4068 ;; We only request an article by message-id when we do not have the
4069 ;; headers for it, so we'll have to get those.
4070 (when (stringp article)
4071 (gnus-read-header article))
4073 ;; If the article number is negative, that means that this article
4074 ;; doesn't belong in this newsgroup (possibly), so we find its
4075 ;; message-id and request it by id instead of number.
4076 (when (and (numberp article)
4078 (get-buffer gnus-summary-buffer)
4079 (gnus-buffer-exists-p gnus-summary-buffer))
4081 (set-buffer gnus-summary-buffer)
4082 (let ((header (gnus-summary-article-header article)))
4085 ((memq article gnus-newsgroup-sparse)
4086 ;; This is a sparse gap article.
4087 (setq do-update-line article)
4088 (setq article (mail-header-id header))
4089 (setq sparse-header (gnus-read-header article))
4090 (setq gnus-newsgroup-sparse
4091 (delq article gnus-newsgroup-sparse)))
4093 ;; It's a real article.
4094 (setq article (mail-header-id header)))
4096 ;; It is an extracted pseudo-article.
4097 (setq article 'pseudo)
4098 (gnus-request-pseudo-article header))))
4100 (let ((method (gnus-find-method-for-group
4101 gnus-newsgroup-name)))
4102 (when (and (eq (car method) 'nneething)
4105 (file-name-as-directory
4106 (or (cadr (assq 'nneething-address method))
4108 (mail-header-subject header))))
4109 (when (file-directory-p dir)
4110 (setq article 'nneething)
4111 (gnus-group-enter-directory dir))))))))
4114 ;; Refuse to select canceled articles.
4115 ((and (numberp article)
4117 (get-buffer gnus-summary-buffer)
4118 (gnus-buffer-exists-p gnus-summary-buffer)
4119 (eq (cdr (save-excursion
4120 (set-buffer gnus-summary-buffer)
4121 (assq article gnus-newsgroup-reads)))
4122 gnus-canceled-mark))
4124 ;; Check the backlog.
4125 ((and gnus-keep-backlog
4126 (gnus-backlog-request-article group article (current-buffer)))
4128 ;; Check asynchronous pre-fetch.
4129 ((gnus-async-request-fetched-article group article (current-buffer))
4130 (gnus-async-prefetch-next group article gnus-summary-buffer)
4131 (when (and (numberp article) gnus-keep-backlog)
4132 (gnus-backlog-enter-article group article (current-buffer)))
4135 ((and gnus-use-cache
4137 (gnus-cache-request-article article group))
4139 ;; Get the article and put into the article buffer.
4140 ((or (stringp article)
4142 (let ((gnus-override-method gnus-override-method)
4143 (methods (and (stringp article)
4144 gnus-refer-article-method))
4146 (buffer-read-only nil))
4151 (when (and (null gnus-override-method)
4153 (setq gnus-override-method (pop methods)))
4155 (when (eq gnus-override-method 'current)
4156 (setq gnus-override-method gnus-current-select-method))
4158 (gnus-kill-all-overlays)
4159 (let ((gnus-newsgroup-name group))
4160 (gnus-check-group-server))
4161 (when (gnus-request-article article group (current-buffer))
4162 (when (numberp article)
4163 (gnus-async-prefetch-next group article
4164 gnus-summary-buffer)
4165 (when gnus-keep-backlog
4166 (gnus-backlog-enter-article
4167 group article (current-buffer))))
4168 (setq result 'article))
4171 (setq gnus-override-method (pop methods))
4172 (setq result 'done))))
4173 (and (eq result 'article) 'article)))
4177 ;; Associate this article with the current summary buffer.
4178 (setq gnus-article-current-summary gnus-summary-buffer)
4180 ;; Take the article from the original article buffer
4181 ;; and place it in the buffer it's supposed to be in.
4182 (when (and (get-buffer gnus-article-buffer)
4183 (equal (buffer-name (current-buffer))
4184 (buffer-name (get-buffer gnus-article-buffer))))
4186 (if (get-buffer gnus-original-article-buffer)
4187 (set-buffer gnus-original-article-buffer)
4188 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4189 (buffer-disable-undo)
4190 (setq major-mode 'gnus-original-article-mode)
4191 (setq buffer-read-only t))
4192 (let (buffer-read-only)
4194 (insert-buffer-substring gnus-article-buffer))
4195 (setq gnus-original-article (cons group article)))
4198 (run-hooks 'gnus-article-decode-hook)
4199 ;; Mark article as decoded or not.
4200 (setq gnus-article-decoded-p gnus-article-decode-hook))
4202 ;; Update sparse articles.
4203 (when (and do-update-line
4204 (or (numberp article)
4206 (let ((buf (current-buffer)))
4207 (set-buffer gnus-summary-buffer)
4208 (gnus-summary-update-article do-update-line sparse-header)
4209 (gnus-summary-goto-subject do-update-line nil t)
4210 (set-window-point (get-buffer-window (current-buffer) t)
4212 (set-buffer buf))))))
4218 (defcustom gnus-article-edit-mode-hook nil
4219 "Hook run in article edit mode buffers."
4220 :group 'gnus-article-various
4223 (defcustom gnus-article-edit-article-setup-function
4224 'gnus-article-mime-edit-article-setup
4225 "Function called to setup an editing article buffer."
4226 :group 'gnus-article-various
4229 (defvar gnus-article-edit-done-function nil)
4231 (defvar gnus-article-edit-mode-map nil)
4233 ;; Should we be using derived.el for this?
4234 (unless gnus-article-edit-mode-map
4235 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4236 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4238 (gnus-define-keys gnus-article-edit-mode-map
4239 "\C-c\C-c" gnus-article-edit-done
4240 "\C-c\C-k" gnus-article-edit-exit)
4242 (gnus-define-keys (gnus-article-edit-wash-map
4243 "\C-c\C-w" gnus-article-edit-mode-map)
4244 "f" gnus-article-edit-full-stops))
4246 (defun gnus-article-edit-mode ()
4247 "Major mode for editing articles.
4248 This is an extended text-mode.
4250 \\{gnus-article-edit-mode-map}"
4252 (setq major-mode 'gnus-article-edit-mode)
4253 (setq mode-name "Article Edit")
4254 (use-local-map gnus-article-edit-mode-map)
4255 (make-local-variable 'gnus-article-edit-done-function)
4256 (make-local-variable 'gnus-prev-winconf)
4257 (setq buffer-read-only nil)
4258 (buffer-enable-undo)
4260 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4262 (defun gnus-article-edit (&optional force)
4263 "Edit the current article.
4264 This will have permanent effect only in mail groups.
4265 If FORCE is non-nil, allow editing of articles even in read-only
4268 (when (and (not force)
4269 (gnus-group-read-only-p))
4270 (error "The current newsgroup does not support article editing"))
4271 (gnus-article-date-original)
4272 (gnus-article-edit-article
4274 `(lambda (no-highlight)
4276 (gnus-summary-edit-article-done
4277 ,(or (mail-header-references gnus-current-headers) "")
4278 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4280 (defun gnus-article-edit-article (start-func exit-func)
4281 "Start editing the contents of the current article buffer."
4282 (let ((winconf (current-window-configuration)))
4283 (set-buffer gnus-article-buffer)
4284 (gnus-article-edit-mode)
4285 (funcall start-func)
4286 (gnus-configure-windows 'edit-article)
4287 (setq gnus-article-edit-done-function exit-func)
4288 (setq gnus-prev-winconf winconf)
4289 (when gnus-article-edit-article-setup-function
4290 (funcall gnus-article-edit-article-setup-function))
4291 (gnus-message 6 "C-c C-c to end edits")))
4293 (defun gnus-article-edit-done (&optional arg)
4294 "Update the article edits and exit."
4299 (when (article-goto-body)
4300 (let ((lines (count-lines (point) (point-max)))
4301 (length (- (point-max) (point)))
4302 (case-fold-search t)
4303 (body (copy-marker (point))))
4304 (goto-char (point-min))
4305 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4306 (delete-region (match-beginning 1) (match-end 1))
4307 (insert (number-to-string length)))
4308 (goto-char (point-min))
4309 (when (re-search-forward
4310 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4311 (delete-region (match-beginning 1) (match-end 1))
4312 (insert (number-to-string length)))
4313 (goto-char (point-min))
4314 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4315 (delete-region (match-beginning 1) (match-end 1))
4316 (insert (number-to-string lines)))))))
4317 (let ((func gnus-article-edit-done-function)
4318 (buf (current-buffer))
4319 (start (window-start)))
4320 (remove-hook 'gnus-article-mode-hook
4321 'gnus-article-mime-edit-article-unwind)
4322 (gnus-article-edit-exit)
4325 (let ((buffer-read-only nil))
4327 ;; The cache and backlog have to be flushed somewhat.
4328 (when gnus-keep-backlog
4329 (gnus-backlog-remove-article
4330 (car gnus-article-current) (cdr gnus-article-current)))
4331 ;; Flush original article as well.
4333 (when (get-buffer gnus-original-article-buffer)
4334 (set-buffer gnus-original-article-buffer)
4335 (setq gnus-original-article nil)))
4336 (when gnus-use-cache
4337 (gnus-cache-update-article
4338 (car gnus-article-current) (cdr gnus-article-current))))
4340 (set-window-start (get-buffer-window buf) start)
4341 (set-window-point (get-buffer-window buf) (point))))
4343 (defun gnus-article-edit-exit ()
4344 "Exit the article editing without updating."
4346 ;; We remove all text props from the article buffer.
4347 (let ((buf (format "%s" (buffer-string)))
4348 (curbuf (current-buffer))
4350 (window-start (window-start)))
4353 (let ((winconf gnus-prev-winconf))
4355 (set-window-configuration winconf)
4356 ;; Tippy-toe some to make sure that point remains where it was.
4357 (save-current-buffer
4359 (set-window-start (get-buffer-window (current-buffer)) window-start)
4362 (defun gnus-article-edit-full-stops ()
4363 "Interactively repair spacing at end of sentences."
4366 (goto-char (point-min))
4367 (search-forward-regexp "^$" nil t)
4368 (let ((case-fold-search nil))
4369 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4372 ;;; Article editing with MIME-Edit
4375 (defcustom gnus-article-mime-edit-article-setup-hook nil
4376 "Hook run after setting up a MIME editing article buffer."
4377 :group 'gnus-article-various
4380 (defun gnus-article-mime-edit-article-unwind ()
4381 "Unwind `gnus-article-buffer' if article editing was given up."
4382 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4383 (when mime-edit-mode-flag
4384 (mime-edit-exit 'nomime 'no-error)
4386 (when (featurep 'font-lock)
4387 (setq font-lock-defaults nil)
4388 (font-lock-mode 0)))
4390 (defun gnus-article-mime-edit-article-setup ()
4391 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4392 after replacing with the original article."
4393 (setq gnus-show-mime t)
4394 (setq gnus-article-edit-done-function
4395 `(lambda (&rest args)
4396 (when mime-edit-mode-flag
4399 (goto-char (point-min))
4400 (let (case-fold-search)
4401 (when (re-search-forward
4402 (format "^%s$" (regexp-quote mail-header-separator))
4404 (replace-match "")))
4405 (when (featurep 'font-lock)
4406 (setq font-lock-defaults nil)
4408 (apply ,gnus-article-edit-done-function args)
4409 (set-buffer gnus-original-article-buffer)
4411 (insert-buffer gnus-article-buffer)
4412 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4413 (gnus-article-prepare-display)))
4414 (substitute-key-definition
4415 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4416 gnus-article-edit-mode-map)
4418 (insert-buffer gnus-original-article-buffer)
4420 (when (featurep 'font-lock)
4421 (set (make-local-variable 'font-lock-defaults)
4422 '(message-font-lock-keywords t))
4423 (font-lock-set-defaults)
4424 (turn-on-font-lock))
4425 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4426 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4428 (defun gnus-article-mime-edit-exit ()
4429 "Exit the article MIME editing without updating."
4431 (let ((winconf gnus-prev-winconf)
4433 (when mime-edit-mode-flag
4436 (goto-char (point-min))
4437 (let (case-fold-search)
4438 (when (re-search-forward
4439 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4440 (replace-match "")))
4441 (when (featurep 'font-lock)
4442 (setq font-lock-defaults nil)
4444 ;; We remove all text props from the article buffer.
4445 (setq buf (format "%s" (buffer-string)))
4446 (set-buffer (get-buffer-create gnus-original-article-buffer))
4449 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4450 (gnus-article-prepare-display)
4451 (set-window-configuration winconf)))
4454 ;;; Article highlights
4457 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4459 ;;; Internal Variables:
4461 (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\\)"
4462 "Regular expression that matches URLs."
4463 :group 'gnus-article-buttons
4466 (defcustom gnus-button-alist
4467 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4468 0 t gnus-button-message-id 2)
4469 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4470 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4472 gnus-button-fetch-group 4)
4473 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4474 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4475 t gnus-button-message-id 3)
4476 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4477 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4478 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4479 ;; This is how URLs _should_ be embedded in text...
4480 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4482 (,gnus-button-url-regexp 0 t browse-url 0))
4483 "*Alist of regexps matching buttons in article bodies.
4485 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4486 REGEXP: is the string matching text around the button,
4487 BUTTON: is the number of the regexp grouping actually matching the button,
4488 FORM: is a lisp expression which must eval to true for the button to
4490 CALLBACK: is the function to call when the user push this button, and each
4491 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4493 CALLBACK can also be a variable, in that case the value of that
4494 variable it the real callback function."
4495 :group 'gnus-article-buttons
4496 :type '(repeat (list regexp
4497 (integer :tag "Button")
4499 (function :tag "Callback")
4502 (integer :tag "Regexp group")))))
4504 (defcustom gnus-header-button-alist
4505 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4506 0 t gnus-button-message-id 0)
4507 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4508 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4509 0 t gnus-button-mailto 0)
4510 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4511 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4512 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4513 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4514 gnus-button-message-id 3))
4515 "*Alist of headers and regexps to match buttons in article heads.
4517 This alist is very similar to `gnus-button-alist', except that each
4518 alist has an additional HEADER element first in each entry:
4520 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4522 HEADER is a regexp to match a header. For a fuller explanation, see
4523 `gnus-button-alist'."
4524 :group 'gnus-article-buttons
4525 :group 'gnus-article-headers
4526 :type '(repeat (list (regexp :tag "Header")
4528 (integer :tag "Button")
4530 (function :tag "Callback")
4533 (integer :tag "Regexp group")))))
4535 (defvar gnus-button-regexp nil)
4536 (defvar gnus-button-marker-list nil)
4537 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4539 (defvar gnus-button-last nil)
4540 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4544 (defun gnus-article-push-button (event)
4545 "Check text under the mouse pointer for a callback function.
4546 If the text under the mouse pointer has a `gnus-callback' property,
4547 call it with the value of the `gnus-data' text property."
4549 (set-buffer (window-buffer (posn-window (event-start event))))
4550 (let* ((pos (posn-point (event-start event)))
4551 (data (get-text-property pos 'gnus-data))
4552 (fun (get-text-property pos 'gnus-callback)))
4555 (funcall fun data))))
4557 (defun gnus-article-press-button ()
4558 "Check text at point for a callback function.
4559 If the text at point has a `gnus-callback' property,
4560 call it with the value of the `gnus-data' text property."
4562 (let* ((data (get-text-property (point) 'gnus-data))
4563 (fun (get-text-property (point) 'gnus-callback)))
4565 (funcall fun data))))
4567 (defun gnus-article-prev-button (n)
4568 "Move point to N buttons backward.
4569 If N is negative, move forward instead."
4571 (gnus-article-next-button (- n)))
4573 (defun gnus-article-next-button (n)
4574 "Move point to N buttons forward.
4575 If N is negative, move backward instead."
4577 (let ((function (if (< n 0) 'previous-single-property-change
4578 'next-single-property-change))
4579 (inhibit-point-motion-hooks t)
4581 (limit (if (< n 0) (point-min) (point-max))))
4583 (while (and (not (= limit (point)))
4585 ;; Skip past the current button.
4586 (when (get-text-property (point) 'gnus-callback)
4587 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4588 ;; Go to the next (or previous) button.
4589 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4590 ;; Put point at the start of the button.
4591 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4592 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4593 ;; Skip past intangible buttons.
4594 (when (get-text-property (point) 'intangible)
4598 (gnus-message 5 "No more buttons"))
4601 (defun gnus-article-highlight (&optional force)
4602 "Highlight current article.
4603 This function calls `gnus-article-highlight-headers',
4604 `gnus-article-highlight-citation',
4605 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4606 do the highlighting. See the documentation for those functions."
4607 (interactive (list 'force))
4608 (gnus-article-highlight-headers)
4609 (gnus-article-highlight-citation force)
4610 (gnus-article-highlight-signature)
4611 (gnus-article-add-buttons force)
4612 (gnus-article-add-buttons-to-head))
4614 (defun gnus-article-highlight-some (&optional force)
4615 "Highlight current article.
4616 This function calls `gnus-article-highlight-headers',
4617 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4618 do the highlighting. See the documentation for those functions."
4619 (interactive (list 'force))
4620 (gnus-article-highlight-headers)
4621 (gnus-article-highlight-signature)
4622 (gnus-article-add-buttons))
4624 (defun gnus-article-highlight-headers ()
4625 "Highlight article headers as specified by `gnus-header-face-alist'."
4628 (set-buffer gnus-article-buffer)
4630 (let ((alist gnus-header-face-alist)
4631 (buffer-read-only nil)
4632 (case-fold-search t)
4633 (inhibit-point-motion-hooks t)
4634 entry regexp header-face field-face from hpoints fpoints)
4635 (article-narrow-to-head)
4636 (while (setq entry (pop alist))
4637 (goto-char (point-min))
4638 (setq regexp (concat "^\\("
4639 (if (string-equal "" (nth 0 entry))
4643 header-face (nth 1 entry)
4644 field-face (nth 2 entry))
4645 (while (and (re-search-forward regexp nil t)
4649 (unless (search-forward ":" nil t)
4651 (when (and header-face
4652 (not (memq (point) hpoints)))
4653 (push (point) hpoints)
4654 (gnus-put-text-property from (point) 'face header-face))
4655 (when (and field-face
4656 (not (memq (setq from (point)) fpoints)))
4658 (if (re-search-forward "^[^ \t]" nil t)
4660 (goto-char (point-max)))
4661 (gnus-put-text-property from (point) 'face field-face))))))))
4663 (defun gnus-article-highlight-signature ()
4664 "Highlight the signature in an article.
4665 It does this by highlighting everything after
4666 `gnus-signature-separator' using `gnus-signature-face'."
4668 (when gnus-signature-face
4670 (set-buffer gnus-article-buffer)
4671 (let ((buffer-read-only nil)
4672 (inhibit-point-motion-hooks t))
4674 (when (gnus-article-narrow-to-signature)
4675 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4676 'face gnus-signature-face)))))))
4678 (defun gnus-article-buttonize-signature ()
4679 "Add button to the signature."
4682 (set-buffer gnus-article-buffer)
4683 (let ((buffer-read-only nil)
4684 (inhibit-point-motion-hooks t))
4685 (when (gnus-article-search-signature)
4686 (gnus-article-add-button (match-beginning 0) (match-end 0)
4687 'gnus-signature-toggle
4688 (set-marker (make-marker)
4689 (1+ (match-end 0))))))))
4691 (defun gnus-button-in-region-p (b e prop)
4692 "Say whether PROP exists in the region."
4693 (text-property-not-all b e prop nil))
4695 (defun gnus-article-add-buttons (&optional force)
4696 "Find external references in the article and make buttons of them.
4697 \"External references\" are things like Message-IDs and URLs, as
4698 specified by `gnus-button-alist'."
4699 (interactive (list 'force))
4701 (set-buffer gnus-article-buffer)
4702 (let ((buffer-read-only nil)
4703 (inhibit-point-motion-hooks t)
4704 (case-fold-search t)
4705 (alist gnus-button-alist)
4707 ;; Remove all old markers.
4708 (let (marker entry new-list)
4709 (while (setq marker (pop gnus-button-marker-list))
4710 (if (or (< marker (point-min)) (>= marker (point-max)))
4711 (push marker new-list)
4713 (when (setq entry (gnus-button-entry))
4714 (put-text-property (match-beginning (nth 1 entry))
4715 (match-end (nth 1 entry))
4716 'gnus-callback nil))
4717 (set-marker marker nil)))
4718 (setq gnus-button-marker-list new-list))
4719 ;; We skip the headers.
4722 (while (setq entry (pop alist))
4723 (setq regexp (car entry))
4725 (while (re-search-forward regexp nil t)
4726 (let* ((start (and entry (match-beginning (nth 1 entry))))
4727 (end (and entry (match-end (nth 1 entry))))
4728 (from (match-beginning 0)))
4729 (when (and (or (eq t (nth 2 entry))
4730 (eval (nth 2 entry)))
4731 (not (gnus-button-in-region-p
4732 start end 'gnus-callback)))
4733 ;; That optional form returned non-nil, so we add the
4735 (gnus-article-add-button
4736 start end 'gnus-button-push
4737 (car (push (set-marker (make-marker) from)
4738 gnus-button-marker-list))))))))))
4740 ;; Add buttons to the head of an article.
4741 (defun gnus-article-add-buttons-to-head ()
4742 "Add buttons to the head of the article."
4745 (set-buffer gnus-article-buffer)
4747 (let ((buffer-read-only nil)
4748 (inhibit-point-motion-hooks t)
4749 (case-fold-search t)
4750 (alist gnus-header-button-alist)
4752 (article-narrow-to-head)
4754 ;; Each alist entry.
4755 (setq entry (car alist)
4757 (goto-char (point-min))
4758 (while (re-search-forward (car entry) nil t)
4759 ;; Each header matching the entry.
4760 (setq beg (match-beginning 0))
4761 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4762 (match-beginning 0))
4765 (while (re-search-forward (nth 1 entry) end t)
4766 ;; Each match within a header.
4767 (let* ((entry (cdr entry))
4768 (start (match-beginning (nth 1 entry)))
4769 (end (match-end (nth 1 entry)))
4770 (form (nth 2 entry)))
4771 (goto-char (match-end 0))
4773 (gnus-article-add-button
4774 start end (nth 3 entry)
4775 (buffer-substring (match-beginning (nth 4 entry))
4776 (match-end (nth 4 entry)))))))
4777 (goto-char end)))))))
4779 ;;; External functions:
4781 (defun gnus-article-add-button (from to fun &optional data)
4782 "Create a button between FROM and TO with callback FUN and data DATA."
4783 (when gnus-article-button-face
4784 (gnus-overlay-put (gnus-make-overlay from to)
4785 'face gnus-article-button-face))
4786 (gnus-add-text-properties
4788 (nconc (and gnus-article-mouse-face
4789 (list gnus-mouse-face-prop gnus-article-mouse-face))
4790 (list 'gnus-callback fun)
4791 (and data (list 'gnus-data data)))))
4793 ;;; Internal functions:
4795 (defun gnus-article-set-globals ()
4797 (set-buffer gnus-summary-buffer)
4798 (gnus-set-global-variables)))
4800 (defun gnus-signature-toggle (end)
4802 (set-buffer gnus-article-buffer)
4803 (let ((buffer-read-only nil)
4804 (inhibit-point-motion-hooks t)
4805 (limit (next-single-property-change end 'mime-view-entity
4807 (if (get-text-property end 'invisible)
4808 (gnus-article-unhide-text end limit)
4809 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4811 (defun gnus-button-entry ()
4812 ;; Return the first entry in `gnus-button-alist' matching this place.
4813 (let ((alist gnus-button-alist)
4816 (setq entry (pop alist))
4817 (if (looking-at (car entry))
4822 (defun gnus-button-push (marker)
4823 ;; Push button starting at MARKER.
4826 (let* ((entry (gnus-button-entry))
4827 (inhibit-point-motion-hooks t)
4829 (args (mapcar (lambda (group)
4830 (let ((string (match-string group)))
4831 (gnus-set-text-properties
4832 0 (length string) nil string)
4839 (fboundp (symbol-value fun)))
4840 (apply (symbol-value fun) args))
4842 (gnus-message 1 "You must define `%S' to use this button"
4843 (cons fun args)))))))
4845 (defun gnus-button-message-id (message-id)
4848 (set-buffer gnus-summary-buffer)
4849 (gnus-summary-refer-article message-id)))
4851 (defun gnus-button-fetch-group (address)
4852 "Fetch GROUP specified by ADDRESS."
4853 (if (not (string-match "[:/]" address))
4854 ;; This is just a simple group url.
4855 (gnus-group-read-ephemeral-group address gnus-select-method)
4856 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4858 (error "Can't parse %s" address)
4859 (gnus-group-read-ephemeral-group
4860 (match-string 4 address)
4861 `(nntp ,(match-string 1 address)
4862 (nntp-address ,(match-string 1 address))
4863 (nntp-port-number ,(if (match-end 3)
4864 (match-string 3 address)
4867 (defun gnus-url-parse-query-string (query &optional downcase)
4868 (let (retval pairs cur key val)
4869 (setq pairs (split-string query "&"))
4871 (setq cur (car pairs)
4873 (if (not (string-match "=" cur))
4875 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4876 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4878 (setq key (downcase key)))
4879 (setq cur (assoc key retval))
4881 (setcdr cur (cons val (cdr cur)))
4882 (setq retval (cons (list key val) retval)))))
4885 (defun gnus-url-unhex (x)
4892 (defun gnus-url-unhex-string (str &optional allow-newlines)
4893 "Remove %XXX embedded spaces, etc in a url.
4894 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4895 decoding of carriage returns and line feeds in the string, which is normally
4896 forbidden in URL encoding."
4897 (setq str (or str ""))
4899 (case-fold-search t))
4900 (while (string-match "%[0-9a-f][0-9a-f]" str)
4901 (let* ((start (match-beginning 0))
4902 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4904 (gnus-url-unhex (elt str (+ start 2))))))
4906 tmp (substring str 0 start)
4909 (char-to-string code))
4910 ((or (= code ?\n) (= code ?\r))
4912 (t (char-to-string code))))
4913 str (substring str (match-end 0)))))
4914 (setq tmp (concat tmp str))
4917 (defun gnus-url-mailto (url)
4918 ;; Send mail to someone
4919 (when (string-match "mailto:/*\\(.*\\)" url)
4920 (setq url (substring url (match-beginning 1) nil)))
4921 (let (to args subject func)
4922 (if (string-match (regexp-quote "?") url)
4923 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4924 args (gnus-url-parse-query-string
4925 (substring url (match-end 0) nil) t))
4926 (setq to (gnus-url-unhex-string url)))
4927 (setq args (cons (list "to" to) args)
4928 subject (cdr-safe (assoc "subject" args)))
4929 (gnus-setup-message 'reply
4932 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4935 (message-position-on-field (caar args)))
4936 (insert (mapconcat 'identity (cdar args) ", "))
4937 (setq args (cdr args)))
4940 (message-goto-subject)))))
4942 (defun gnus-button-mailto (address)
4944 (set-buffer (gnus-copy-article-buffer))
4945 (gnus-setup-message 'reply
4946 (message-reply address)))
4948 (defun gnus-button-reply (address)
4949 ;; Reply to ADDRESS.
4950 (gnus-setup-message 'reply
4951 (message-reply address)))
4953 (defun gnus-button-embedded-url (address)
4955 (browse-url (gnus-strip-whitespace address)))
4957 (defun gnus-article-smiley-display ()
4958 "Display \"smileys\" as small graphical icons."
4959 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
4961 ;;; Next/prev buttons in the article buffer.
4963 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4964 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4966 (defvar gnus-prev-page-map nil)
4967 (unless gnus-prev-page-map
4968 (setq gnus-prev-page-map (make-sparse-keymap))
4969 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4970 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4972 (static-if (featurep 'xemacs)
4973 (defun gnus-insert-prev-page-button ()
4974 (let ((buffer-read-only nil))
4976 gnus-prev-page-line-format nil
4977 `(gnus-prev t local-map ,gnus-prev-page-map
4978 gnus-callback gnus-article-button-prev-page
4979 article-type annotation))))
4980 (defun gnus-insert-prev-page-button ()
4981 (let ((buffer-read-only nil)
4982 (situation (get-text-property (point-min) 'mime-view-situation)))
4983 (set-keymap-parent gnus-prev-page-map (current-local-map))
4985 gnus-prev-page-line-format nil
4986 `(gnus-prev t local-map ,gnus-prev-page-map
4987 gnus-callback gnus-article-button-prev-page
4988 article-type annotation
4989 mime-view-situation ,situation))))
4992 (defvar gnus-next-page-map nil)
4993 (unless gnus-next-page-map
4994 (setq gnus-next-page-map (make-sparse-keymap))
4995 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4996 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4998 (defun gnus-button-next-page ()
4999 "Go to the next page."
5001 (let ((win (selected-window)))
5002 (select-window (get-buffer-window gnus-article-buffer t))
5003 (gnus-article-next-page)
5004 (select-window win)))
5006 (defun gnus-button-prev-page ()
5007 "Go to the prev page."
5009 (let ((win (selected-window)))
5010 (select-window (get-buffer-window gnus-article-buffer t))
5011 (gnus-article-prev-page)
5012 (select-window win)))
5014 (static-if (featurep 'xemacs)
5015 (defun gnus-insert-next-page-button ()
5016 (let ((buffer-read-only nil))
5017 (gnus-eval-format gnus-next-page-line-format nil
5019 t local-map ,gnus-next-page-map
5020 gnus-callback gnus-article-button-next-page
5021 article-type annotation))))
5022 (defun gnus-insert-next-page-button ()
5023 (let ((buffer-read-only nil)
5024 (situation (get-text-property (point-min) 'mime-view-situation)))
5025 (set-keymap-parent gnus-next-page-map (current-local-map))
5026 (gnus-eval-format gnus-next-page-line-format nil
5028 t local-map ,gnus-next-page-map
5029 gnus-callback gnus-article-button-next-page
5030 article-type annotation
5031 mime-view-situation ,situation))))
5034 (defun gnus-article-button-next-page (arg)
5035 "Go to the next page."
5037 (let ((win (selected-window)))
5038 (select-window (get-buffer-window gnus-article-buffer t))
5039 (gnus-article-next-page)
5040 (select-window win)))
5042 (defun gnus-article-button-prev-page (arg)
5043 "Go to the prev page."
5045 (let ((win (selected-window)))
5046 (select-window (get-buffer-window gnus-article-buffer t))
5047 (gnus-article-prev-page)
5048 (select-window win)))
5050 (defvar gnus-decode-header-methods
5051 '(mail-decode-encoded-word-region)
5052 "List of methods used to decode headers.
5054 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5055 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5056 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5057 whose names match REGEXP.
5060 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5061 mail-decode-encoded-word-region
5062 (\"chinese\" . rfc1843-decode-region))
5065 (defvar gnus-decode-header-methods-cache nil)
5067 (defun gnus-multi-decode-header (start end)
5068 "Apply the functions from `gnus-encoded-word-methods' that match."
5069 (unless (and gnus-decode-header-methods-cache
5070 (eq gnus-newsgroup-name
5071 (car gnus-decode-header-methods-cache)))
5072 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5075 (nconc gnus-decode-header-methods-cache (list x))
5076 (if (and gnus-newsgroup-name
5077 (string-match (car x) gnus-newsgroup-name))
5078 (nconc gnus-decode-header-methods-cache
5080 gnus-decode-header-methods))
5081 (let ((xlist gnus-decode-header-methods-cache))
5084 (narrow-to-region start end)
5086 (funcall (pop xlist) (point-min) (point-max))))))
5089 ;;; Treatment top-level handling.
5092 (defun gnus-treat-article (condition &optional part-number total-parts type)
5093 (let ((length (- (point-max) (point-min)))
5094 (alist gnus-treatment-function-alist)
5095 (article-goto-body-goes-to-point-min-p t)
5099 (let ((list gnus-article-treat-types))
5101 (when (string-match (pop list) type)
5102 (throw 'found t)))))))
5103 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5104 (entity (static-unless (featurep 'xemacs)
5105 (when (eq 'head condition)
5106 (get-text-property (point-min) 'mime-view-entity))))
5107 val elem buttonized)
5108 (gnus-run-hooks 'gnus-part-display-hook)
5109 (unless gnus-inhibit-treatment
5110 (while (setq elem (pop alist))
5111 (setq val (symbol-value (car elem)))
5112 (when (and (or (consp val)
5114 (gnus-treat-predicate val)
5115 (or (not (get (car elem) 'highlight))
5117 (when (and (not buttonized)
5119 '(gnus-treat-hide-signature
5120 gnus-treat-highlight-signature)))
5121 (gnus-article-buttonize-signature)
5122 (setq buttonized t))
5124 (funcall (cadr elem)))))
5125 ;; FSF Emacsen does not inherit the existing text properties
5126 ;; in the new text, so we should do it for `mime-view-entity'.
5127 (static-unless (featurep 'xemacs)
5129 (put-text-property (point-min) (point-max)
5130 'mime-view-entity entity))))))
5132 ;; Dynamic variables.
5133 (defvar part-number)
5134 (defvar total-parts)
5138 (defun gnus-treat-predicate (val)
5143 (stringp (car val)))
5144 (apply 'gnus-or (mapcar `(lambda (s)
5145 (string-match s ,(or gnus-newsgroup-name "")))
5148 (let ((pred (pop val)))
5151 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5153 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5155 (not (gnus-treat-predicate (car val))))
5157 (equal (car val) type))
5159 (error "%S is not a valid predicate" pred)))))
5169 (eq part-number total-parts))
5173 (error "%S is not a valid value" val))))
5179 (defun gnus-article-header-presentation-method (entity situation)
5180 (mime-insert-header entity)
5183 (set-alist 'mime-header-presentation-method-alist
5184 'gnus-original-article-mode
5185 #'gnus-article-header-presentation-method)
5187 (defun gnus-mime-preview-quitting-method ()
5188 (mime-preview-kill-buffer)
5189 (delete-other-windows)
5190 (gnus-article-show-summary)
5191 (gnus-summary-select-article gnus-show-all-headers t))
5193 (set-alist 'mime-preview-quitting-method-alist
5194 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5196 (set-alist 'mime-preview-following-method-alist
5197 'gnus-original-article-mode #'gnus-following-method)
5199 (set-alist 'mime-preview-over-to-previous-method-alist
5200 'gnus-original-article-mode
5202 (if (> (point-min) 1)
5203 (gnus-article-prev-page)
5204 (gnus-article-read-summary-keys
5205 nil (gnus-character-to-event ?P)))))
5207 (set-alist 'mime-preview-over-to-next-method-alist
5208 'gnus-original-article-mode'
5210 (if (< (point-max) (buffer-size))
5211 (gnus-article-next-page)
5212 (gnus-article-read-summary-keys
5213 nil (gnus-character-to-event ?N)))))
5223 (run-hooks 'gnus-art-load-hook)
5225 ;;; gnus-art.el ends here