1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
44 ;; Avoid byte-compile warnings.
45 (defvar gnus-article-decoded-p)
46 (defvar gnus-article-mime-handles)
56 (defgroup gnus-article nil
58 :link '(custom-manual "(gnus)The Article Buffer")
61 (defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
71 (defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
77 (defgroup gnus-article-signature nil
79 :link '(custom-manual "(gnus)Article Signature")
82 (defgroup gnus-article-headers nil
84 :link '(custom-manual "(gnus)Hiding Headers")
87 (defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
92 (defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
97 (defgroup gnus-article-saving nil
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
102 (defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
107 (defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
112 (defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
117 (defcustom gnus-ignored-headers
118 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
119 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
120 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
121 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
122 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
123 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
124 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
125 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
126 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
127 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
128 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
129 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
130 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
131 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
132 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
133 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
134 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
135 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
136 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
137 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
138 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
139 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
140 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
141 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
142 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
143 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:")
144 "*All headers that start with this regexp will be hidden.
145 This variable can also be a list of regexps of headers to be ignored.
146 If `gnus-visible-headers' is non-nil, this variable will be ignored."
147 :type '(choice :custom-show nil
150 :group 'gnus-article-hiding)
152 (defcustom gnus-visible-headers
153 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
154 "*All headers that do not match this regexp will be hidden.
155 This variable can also be a list of regexp of headers to remain visible.
156 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
157 :type '(repeat :value-to-internal (lambda (widget value)
158 (custom-split-regexp-maybe value))
159 :match (lambda (widget value)
161 (widget-editable-list-match widget value)))
163 :group 'gnus-article-hiding)
165 (defcustom gnus-sorted-header-list
166 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
167 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
168 "*This variable is a list of regular expressions.
169 If it is non-nil, headers that match the regular expressions will
170 be placed first in the article buffer in the sequence specified by
172 :type '(repeat regexp)
173 :group 'gnus-article-hiding)
175 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
176 "Headers that are only to be displayed if they have interesting data.
177 Possible values in this list are `empty', `newsgroups', `followup-to',
178 `reply-to', `date', `long-to', and `many-to'."
179 :type '(set (const :tag "Headers with no content." empty)
180 (const :tag "Newsgroups with only one group." newsgroups)
181 (const :tag "Followup-to identical to newsgroups." followup-to)
182 (const :tag "Reply-to identical to from." reply-to)
183 (const :tag "Date less than four days old." date)
184 (const :tag "Very long To header." long-to)
185 (const :tag "Multiple To headers." many-to))
186 :group 'gnus-article-hiding)
188 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
189 "Regexp matching signature separator.
190 This can also be a list of regexps. In that case, it will be checked
191 from head to tail looking for a separator. Searches will be done from
192 the end of the buffer."
193 :type '(repeat string)
194 :group 'gnus-article-signature)
196 (defcustom gnus-signature-limit nil
197 "Provide a limit to what is considered a signature.
198 If it is a number, no signature may not be longer (in characters) than
199 that number. If it is a floating point number, no signature may be
200 longer (in lines) than that number. If it is a function, the function
201 will be called without any parameters, and if it returns nil, there is
202 no signature in the buffer. If it is a string, it will be used as a
203 regexp. If it matches, the text in question is not a signature."
204 :type '(choice (integer :value 200)
206 (function :value fun)
207 (regexp :value ".*"))
208 :group 'gnus-article-signature)
210 (defcustom gnus-hidden-properties '(invisible t intangible t)
211 "Property list to use for hiding text."
213 :group 'gnus-article-hiding)
215 (defcustom gnus-article-x-face-command
216 (if (and (not gnus-xemacs)
218 (module-installed-p 'x-face-mule))
219 'x-face-mule-gnus-article-display-x-face
220 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
222 "*String or function to be executed to display an X-Face header.
223 If it is a string, the command will be executed in a sub-shell
224 asynchronously. The compressed face will be piped to this command."
225 :type 'string ;Leave function case to Lisp.
226 :group 'gnus-article-washing)
228 (defcustom gnus-article-x-face-too-ugly nil
229 "Regexp matching posters whose face shouldn't be shown automatically."
230 :type '(choice regexp (const nil))
231 :group 'gnus-article-washing)
233 (defcustom gnus-emphasis-alist
235 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
237 '(("_" "_" underline)
240 ("_/" "/_" underline-italic)
241 ("_\\*" "\\*_" underline-bold)
242 ("\\*/" "/\\*" bold-italic)
243 ("_\\*/" "/\\*_" underline-bold-italic))))
244 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
245 2 3 gnus-emphasis-underline)
249 (format format (car spec) (cadr spec))
250 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
252 "*Alist that says how to fontify certain phrases.
253 Each item looks like this:
255 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
257 The first element is a regular expression to be matched. The second
258 is a number that says what regular expression grouping used to find
259 the entire emphasized word. The third is a number that says what
260 regexp grouping should be displayed and highlighted. The fourth
261 is the face used for highlighting."
262 :type '(repeat (list :value ("" 0 0 default)
264 (integer :tag "Match group")
265 (integer :tag "Emphasize group")
267 :group 'gnus-article-emphasis)
269 (defface gnus-emphasis-bold '((t (:bold t)))
270 "Face used for displaying strong emphasized text (*word*)."
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-italic '((t (:italic t)))
274 "Face used for displaying italic emphasized text (/word/)."
275 :group 'gnus-article-emphasis)
277 (defface gnus-emphasis-underline '((t (:underline t)))
278 "Face used for displaying underlined emphasized text (_word_)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
282 "Face used for displaying underlined bold emphasized text (_*word*_)."
283 :group 'gnus-article-emphasis)
285 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
286 "Face used for displaying underlined italic emphasized text (_*word*_)."
287 :group 'gnus-article-emphasis)
289 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
290 "Face used for displaying bold italic emphasized text (/*word*/)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-underline-bold-italic
294 '((t (:bold t :italic t :underline t)))
295 "Face used for displaying underlined bold italic emphasized text.
296 Esample: (_/*word*/_)."
297 :group 'gnus-article-emphasis)
299 (defface gnus-emphasis-highlight-words
300 '((t (:background "black" :foreground "yellow")))
301 "Face used for displaying highlighted words."
302 :group 'gnus-article-emphasis)
304 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
305 "Format for display of Date headers in article bodies.
306 See `format-time-string' for the possible values.
308 The variable can also be function, which should return a complete Date
309 header. The function is called with one argument, the time, which can
310 be fed to `format-time-string'."
311 :type '(choice string symbol)
312 :link '(custom-manual "(gnus)Article Date")
313 :group 'gnus-article-washing)
316 (autoload 'mail-extract-address-components "mail-extr"))
318 (defcustom gnus-save-all-headers t
319 "*If non-nil, don't remove any headers before saving."
320 :group 'gnus-article-saving
323 (defcustom gnus-prompt-before-saving 'always
324 "*This variable says how much prompting is to be done when saving articles.
325 If it is nil, no prompting will be done, and the articles will be
326 saved to the default files. If this variable is `always', each and
327 every article that is saved will be preceded by a prompt, even when
328 saving large batches of articles. If this variable is neither nil not
329 `always', there the user will be prompted once for a file name for
330 each invocation of the saving commands."
331 :group 'gnus-article-saving
332 :type '(choice (item always)
333 (item :tag "never" nil)
334 (sexp :tag "once" :format "%t\n" :value t)))
336 (defcustom gnus-saved-headers gnus-visible-headers
337 "Headers to keep if `gnus-save-all-headers' is nil.
338 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
339 If that variable is nil, however, all headers that match this regexp
340 will be kept while the rest will be deleted before saving."
341 :group 'gnus-article-saving
344 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
345 "A function to save articles in your favourite format.
346 The function must be interactively callable (in other words, it must
347 be an Emacs command).
349 Gnus provides the following functions:
351 * gnus-summary-save-in-rmail (Rmail format)
352 * gnus-summary-save-in-mail (Unix mail format)
353 * gnus-summary-save-in-folder (MH folder)
354 * gnus-summary-save-in-file (article format)
355 * gnus-summary-save-in-vm (use VM's folder format)
356 * gnus-summary-write-to-file (article format -- overwrite)."
357 :group 'gnus-article-saving
358 :type '(radio (function-item gnus-summary-save-in-rmail)
359 (function-item gnus-summary-save-in-mail)
360 (function-item gnus-summary-save-in-folder)
361 (function-item gnus-summary-save-in-file)
362 (function-item gnus-summary-save-in-vm)
363 (function-item gnus-summary-write-to-file)))
365 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
366 "A function generating a file name to save articles in Rmail format.
367 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
368 :group 'gnus-article-saving
371 (defcustom gnus-mail-save-name 'gnus-plain-save-name
372 "A function generating a file name to save articles in Unix mail format.
373 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
374 :group 'gnus-article-saving
377 (defcustom gnus-folder-save-name 'gnus-folder-save-name
378 "A function generating a file name to save articles in MH folder.
379 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
380 :group 'gnus-article-saving
383 (defcustom gnus-file-save-name 'gnus-numeric-save-name
384 "A function generating a file name to save articles in article format.
385 The function is called with NEWSGROUP, HEADERS, and optional
387 :group 'gnus-article-saving
390 (defcustom gnus-split-methods
391 '((gnus-article-archive-name)
392 (gnus-article-nndoc-name))
393 "*Variable used to suggest where articles are to be saved.
394 For instance, if you would like to save articles related to Gnus in
395 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
396 you could set this variable to something like:
398 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
399 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
401 This variable is an alist where the where the key is the match and the
402 value is a list of possible files to save in if the match is non-nil.
404 If the match is a string, it is used as a regexp match on the
405 article. If the match is a symbol, that symbol will be funcalled
406 from the buffer of the article to be saved with the newsgroup as the
407 parameter. If it is a list, it will be evaled in the same buffer.
409 If this form or function returns a string, this string will be used as
410 a possible file name; and if it returns a non-nil list, that list will
411 be used as possible file names."
412 :group 'gnus-article-saving
413 :type '(repeat (choice (list :value (fun) function)
414 (cons :value ("" "") regexp (repeat string))
417 (defcustom gnus-article-display-method-for-mime
418 'gnus-article-display-mime-message
419 "Function to display a MIME message.
420 The function is called from the article buffer."
421 :group 'gnus-article-mime
424 (defcustom gnus-article-display-method-for-traditional
425 'gnus-article-display-traditional-message
426 "*Function to display a traditional message.
427 The function is called from the article buffer."
428 :group 'gnus-article-mime
431 (defcustom gnus-page-delimiter "^\^L"
432 "*Regexp describing what to use as article page delimiters.
433 The default value is \"^\^L\", which is a form linefeed at the
434 beginning of a line."
436 :group 'gnus-article-various)
438 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
439 "*The format specification for the article mode line.
440 See `gnus-summary-mode-line-format' for a closer description.
442 The following additional specs are available:
444 %w The article washing status.
445 %m The number of MIME parts in the article."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-mode-hook nil
450 "*A hook for Gnus article mode."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-menu-hook nil
455 "*Hook run after the creation of the article mode menu."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-prepare-hook nil
460 "*A hook called after an article has been prepared in the article buffer."
462 :group 'gnus-article-various)
464 (defcustom gnus-article-hide-pgp-hook nil
465 "*A hook called after successfully hiding a PGP signature."
467 :group 'gnus-article-various)
469 (defcustom gnus-article-button-face 'bold
470 "Face used for highlighting buttons in the article buffer.
472 An article button is a piece of text that you can activate by pressing
473 `RET' or `mouse-2' above it."
475 :group 'gnus-article-buttons)
477 (defcustom gnus-article-mouse-face 'highlight
478 "Face used for mouse highlighting in the article buffer.
480 Article buttons will be displayed in this face when the cursor is
483 :group 'gnus-article-buttons)
485 (defcustom gnus-signature-face 'gnus-signature-face
486 "Face used for highlighting a signature in the article buffer.
487 Obsolete; use the face `gnus-signature-face' for customizations instead."
489 :group 'gnus-article-highlight
490 :group 'gnus-article-signature)
492 (defface gnus-signature-face
494 "Face used for highlighting a signature in the article buffer."
495 :group 'gnus-article-highlight
496 :group 'gnus-article-signature)
498 (defface gnus-header-from-face
501 (:foreground "spring green"))
504 (:foreground "red3"))
507 "Face used for displaying from headers."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-subject-face
514 (:foreground "SeaGreen3"))
517 (:foreground "red4"))
519 (:bold t :italic t)))
520 "Face used for displaying subject headers."
521 :group 'gnus-article-headers
522 :group 'gnus-article-highlight)
524 (defface gnus-header-newsgroups-face
527 (:foreground "yellow" :italic t))
530 (:foreground "MidnightBlue" :italic t))
533 "Face used for displaying newsgroups headers."
534 :group 'gnus-article-headers
535 :group 'gnus-article-highlight)
537 (defface gnus-header-name-face
540 (:foreground "SeaGreen"))
543 (:foreground "maroon"))
546 "Face used for displaying header names."
547 :group 'gnus-article-headers
548 :group 'gnus-article-highlight)
550 (defface gnus-header-content-face
553 (:foreground "forest green" :italic t))
556 (:foreground "indianred4" :italic t))
558 (:italic t))) "Face used for displaying header content."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight)
562 (defcustom gnus-header-face-alist
563 '(("From" nil gnus-header-from-face)
564 ("Subject" nil gnus-header-subject-face)
565 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
566 ("" gnus-header-name-face gnus-header-content-face))
567 "*Controls highlighting of article header.
569 An alist of the form (HEADER NAME CONTENT).
571 HEADER is a regular expression which should match the name of an
572 header header and NAME and CONTENT are either face names or nil.
574 The name of each header field will be displayed using the face
575 specified by the first element in the list where HEADER match the
576 header name and NAME is non-nil. Similarly, the content will be
577 displayed by the first non-nil matching CONTENT face."
578 :group 'gnus-article-headers
579 :group 'gnus-article-highlight
580 :type '(repeat (list (regexp :tag "Header")
582 (item :tag "skip" nil)
583 (face :value default))
584 (choice :tag "Content"
585 (item :tag "skip" nil)
586 (face :value default)))))
588 (defcustom gnus-article-decode-hook nil
589 "*Hook run to decode charsets in articles."
590 :group 'gnus-article-headers
593 (defcustom gnus-display-mime-function 'gnus-display-mime
594 "Function to display MIME articles."
595 :group 'gnus-article-mime
598 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
599 "Function used to decode headers.")
601 (defvar gnus-article-dumbquotes-map
619 "Table for MS-to-Latin1 translation.")
621 (defcustom gnus-ignored-mime-types nil
622 "List of MIME types that should be ignored by Gnus."
623 :group 'gnus-article-mime
624 :type '(repeat regexp))
626 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
627 "List of MIME types that should not be given buttons when rendered inline."
628 :group 'gnus-article-mime
629 :type '(repeat regexp))
631 (defcustom gnus-article-mime-part-function nil
632 "Function called with a MIME handle as the argument.
633 This is meant for people who want to do something automatic based
634 on parts -- for instance, adding Vcard info to a database."
635 :group 'gnus-article-mime
638 (defcustom gnus-mime-multipart-functions nil
639 "An alist of MIME types to functions to display them.")
641 (defcustom gnus-article-date-lapsed-new-header nil
642 "Whether the X-Sent and Date headers can coexist.
643 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
644 either replace the old \"Date:\" header (if this variable is nil), or
645 be added below it (otherwise)."
646 :group 'gnus-article-headers
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 t
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 'smiley-mule)))
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-smiley-display)
1006 (gnus-treat-display-picons gnus-article-display-picons)
1007 (gnus-treat-play-sounds gnus-earcon-display)))
1009 (defvar gnus-article-mime-handle-alist nil)
1010 (defvar article-lapsed-timer nil)
1011 (defvar gnus-article-current-summary nil)
1013 (defvar gnus-article-mode-syntax-table
1014 (let ((table (copy-syntax-table text-mode-syntax-table)))
1015 (modify-syntax-entry ?- "w" table)
1016 (modify-syntax-entry ?> ")" table)
1017 (modify-syntax-entry ?< "(" table)
1019 "Syntax table used in article mode buffers.
1020 Initialized from `text-mode-syntax-table.")
1022 (defvar gnus-save-article-buffer nil)
1024 (defvar gnus-article-mode-line-format-alist
1025 (nconc '((?w (gnus-article-wash-status) ?s)
1026 (?m (gnus-article-mime-part-status) ?s))
1027 gnus-summary-mode-line-format-alist))
1029 (defvar gnus-number-of-articles-to-be-saved nil)
1031 (defvar gnus-inhibit-hiding nil)
1033 (defsubst gnus-article-hide-text (b e props)
1034 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1035 (add-text-properties b e props)
1036 (when (memq 'intangible props)
1038 (max (1- b) (point-min))
1039 b 'intangible (cddr (memq 'intangible props)))))
1040 (defsubst gnus-article-unhide-text (b e)
1041 "Remove hidden text properties from region between B and E."
1042 (remove-text-properties b e gnus-hidden-properties)
1043 (when (memq 'intangible gnus-hidden-properties)
1044 (put-text-property (max (1- b) (point-min))
1045 b 'intangible nil)))
1047 (defun gnus-article-hide-text-type (b e type)
1048 "Hide text of TYPE between B and E."
1049 (push type gnus-article-wash-types)
1050 (gnus-article-hide-text
1051 b e (cons 'article-type (cons type gnus-hidden-properties))))
1053 (defun gnus-article-unhide-text-type (b e type)
1054 "Unhide text of TYPE between B and E."
1055 (setq gnus-article-wash-types
1056 (delq type gnus-article-wash-types))
1057 (remove-text-properties
1058 b e (cons 'article-type (cons type gnus-hidden-properties)))
1059 (when (memq 'intangible gnus-hidden-properties)
1060 (put-text-property (max (1- b) (point-min))
1061 b 'intangible nil)))
1063 (defun gnus-article-hide-text-of-type (type)
1064 "Hide text of TYPE in the current buffer."
1066 (let ((b (point-min))
1068 (while (setq b (text-property-any b e 'article-type type))
1069 (add-text-properties b (incf b) gnus-hidden-properties)))))
1071 (defun gnus-article-delete-text-of-type (type)
1072 "Delete text of TYPE in the current buffer."
1074 (let ((b (point-min)))
1075 (while (setq b (text-property-any b (point-max) 'article-type type))
1077 b (or (text-property-not-all b (point-max) 'article-type type)
1080 (defun gnus-article-delete-invisible-text ()
1081 "Delete all invisible text in the current buffer."
1083 (let ((b (point-min)))
1084 (while (setq b (text-property-any b (point-max) 'invisible t))
1086 b (or (text-property-not-all b (point-max) 'invisible t)
1089 (defun gnus-article-text-type-exists-p (type)
1090 "Say whether any text of type TYPE exists in the buffer."
1091 (text-property-any (point-min) (point-max) 'article-type type))
1093 (defsubst gnus-article-header-rank ()
1094 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1095 (let ((list gnus-sorted-header-list)
1098 (when (looking-at (car list))
1100 (setq list (cdr list))
1104 (defun article-hide-headers (&optional arg delete)
1105 "Hide unwanted headers and possibly sort them as well."
1106 (interactive (gnus-article-hidden-arg))
1107 ;; Lars said that this function might be inhibited.
1108 (if (gnus-article-check-hidden-text 'headers arg)
1110 ;; Show boring headers as well.
1111 (gnus-article-show-hidden-text 'boring-headers)
1112 (when (eq 1 (point-min))
1113 (set-window-start (get-buffer-window (current-buffer)) 1)))
1114 (unless gnus-inhibit-hiding
1117 (let ((buffer-read-only nil)
1118 (inhibit-read-only t)
1119 (case-fold-search t)
1120 (max (1+ (length gnus-sorted-header-list)))
1121 (ignored (when (not gnus-visible-headers)
1122 (cond ((stringp gnus-ignored-headers)
1123 gnus-ignored-headers)
1124 ((listp gnus-ignored-headers)
1125 (mapconcat 'identity gnus-ignored-headers
1128 (cond ((stringp gnus-visible-headers)
1129 gnus-visible-headers)
1130 ((and gnus-visible-headers
1131 (listp gnus-visible-headers))
1132 (mapconcat 'identity gnus-visible-headers "\\|"))))
1133 (inhibit-point-motion-hooks t)
1135 ;; First we narrow to just the headers.
1136 (article-narrow-to-head)
1137 ;; Hide any "From " lines at the beginning of (mail) articles.
1138 (while (looking-at "From ")
1142 (delete-region (point-min) (point))
1143 (gnus-article-hide-text (point-min) (point)
1144 (nconc (list 'article-type 'headers)
1145 gnus-hidden-properties))))
1146 ;; Then treat the rest of the header lines.
1147 ;; Then we use the two regular expressions
1148 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1149 ;; select which header lines is to remain visible in the
1151 (while (re-search-forward "^[^ \t]*:" nil t)
1153 ;; Mark the rank of the header.
1155 (point) (1+ (point)) 'message-rank
1156 (if (or (and visible (looking-at visible))
1158 (not (looking-at ignored))))
1159 (gnus-article-header-rank)
1162 (message-sort-headers-1)
1163 (when (setq beg (text-property-any
1164 (point-min) (point-max) 'message-rank (+ 2 max)))
1165 ;; We delete or make invisible the unwanted headers.
1166 (push 'headers gnus-article-wash-types)
1169 (add-text-properties
1170 (point-min) (+ 5 (point-min))
1171 '(article-type headers dummy-invisible t))
1172 (delete-region beg (point-max)))
1173 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1176 (defun article-hide-boring-headers (&optional arg)
1177 "Toggle hiding of headers that aren't very interesting.
1178 If given a negative prefix, always show; if given a positive prefix,
1180 (interactive (gnus-article-hidden-arg))
1181 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1182 (not gnus-show-all-headers))
1185 (let ((buffer-read-only nil)
1186 (list gnus-boring-article-headers)
1187 (inhibit-point-motion-hooks t)
1189 (article-narrow-to-head)
1191 (setq elem (pop list))
1192 (goto-char (point-min))
1194 ;; Hide empty headers.
1196 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1198 (gnus-article-hide-text-type
1199 (progn (beginning-of-line) (point))
1202 (if (re-search-forward "^[^ \t]" nil t)
1206 ;; Hide boring Newsgroups header.
1207 ((eq elem 'newsgroups)
1208 (when (equal (gnus-fetch-field "newsgroups")
1209 (gnus-group-real-name
1210 (if (boundp 'gnus-newsgroup-name)
1213 (gnus-article-hide-header "newsgroups")))
1214 ((eq elem 'followup-to)
1215 (when (equal (message-fetch-field "followup-to")
1216 (message-fetch-field "newsgroups"))
1217 (gnus-article-hide-header "followup-to")))
1218 ((eq elem 'reply-to)
1219 (let ((from (message-fetch-field "from"))
1220 (reply-to (message-fetch-field "reply-to")))
1225 (nth 1 (funcall gnus-extract-address-components from))
1226 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1227 (gnus-article-hide-header "reply-to"))))
1229 (let ((date (message-fetch-field "date")))
1231 (< (days-between (current-time-string) date)
1233 (gnus-article-hide-header "date"))))
1235 (let ((to (message-fetch-field "to")))
1236 (when (> (length to) 1024)
1237 (gnus-article-hide-header "to"))))
1240 (goto-char (point-min))
1241 (while (re-search-forward "^to:" nil t)
1242 (setq to-count (1+ to-count)))
1243 (when (> to-count 1)
1244 (while (> to-count 0)
1245 (goto-char (point-min))
1247 (re-search-forward "^to:" nil nil to-count)
1249 (narrow-to-region (point) (point-max))
1250 (gnus-article-hide-header "to"))
1251 (setq to-count (1- to-count)))))))))))))
1253 (defun gnus-article-hide-header (header)
1255 (goto-char (point-min))
1256 (when (re-search-forward (concat "^" header ":") nil t)
1257 (gnus-article-hide-text-type
1258 (progn (beginning-of-line) (point))
1261 (if (re-search-forward "^[^ \t]" nil t)
1266 (defun article-toggle-headers (&optional arg)
1267 "Toggle hiding of headers. If given a negative prefix, always show;
1268 if given a positive prefix, always hide."
1269 (interactive (gnus-article-hidden-arg))
1270 (let ((force (when (numberp arg)
1271 (cond ((> arg 0) 'always-hide)
1272 ((< arg 0) 'always-show))))
1273 (window (get-buffer-window gnus-article-buffer))
1274 (header-end (point-min))
1275 header-start field-end field-start
1276 (inhibit-point-motion-hooks t)
1277 (inhibit-read-only t)
1281 (while (and (setq header-start
1282 (text-property-any header-end (point-max)
1283 'article-treated-header t))
1285 (text-property-not-all header-start (point-max)
1286 'article-treated-header t)))
1287 (setq field-end header-start)
1289 (;; Hide exposed invisible fields.
1290 (and (not (eq 'always-show force))
1292 (text-property-any field-end header-end
1293 'exposed-invisible-field t)))
1294 (while (and field-start
1295 (setq field-end (text-property-not-all
1296 field-start header-end
1297 'exposed-invisible-field t)))
1298 (add-text-properties field-start field-end gnus-hidden-properties)
1299 (setq field-start (text-property-any field-end header-end
1300 'exposed-invisible-field t)))
1301 (put-text-property header-start header-end
1302 'exposed-invisible-field nil))
1303 (;; Expose invisible fields.
1304 (and (not (eq 'always-hide force))
1306 (text-property-any field-end header-end 'invisible t)))
1307 (while (and field-start
1308 (setq field-end (text-property-not-all
1309 field-start header-end
1311 ;; If the invisible text is not terminated with newline, we
1312 ;; won't expose it. Because it may be created by x-face-mule.
1313 ;; BTW, XEmacs sometimes fail in putting a invisible text
1314 ;; property with `gnus-article-hide-text' (really?). In that
1315 ;; case, the invisible text might be started from the middle of
1316 ;; a line so we will expose the sort of thing.
1317 (when (or (not (or (eq header-start field-start)
1318 (eq ?\n (char-before field-start))))
1319 (eq ?\n (char-before field-end)))
1320 (remove-text-properties field-start field-end
1321 gnus-hidden-properties)
1322 (put-text-property field-start field-end
1323 'exposed-invisible-field t))
1324 (setq field-start (text-property-any field-end header-end
1327 (not (eq 'always-show force))
1328 (narrow-to-region header-start header-end)
1329 (article-hide-headers)
1330 ;; Re-display X-Face image under XEmacs.
1331 (when (and gnus-xemacs
1332 (gnus-functionp gnus-article-x-face-command))
1333 (let ((func (cadr (assq 'gnus-treat-display-xface
1334 gnus-treatment-function-alist)))
1336 (when (and (not gnus-inhibit-treatment)
1338 (gnus-treat-predicate gnus-treat-display-xface))
1340 (put-text-property header-start header-end 'read-only nil))))
1343 (goto-char (point-min))
1345 (set-window-start window (point-min))))))
1347 (defvar gnus-article-normalized-header-length 40
1348 "Length of normalized headers.")
1350 (defun article-normalize-headers ()
1351 "Make all header lines 40 characters long."
1353 (let ((buffer-read-only nil)
1357 (article-narrow-to-head)
1360 ((< (setq column (- (gnus-point-at-eol) (point)))
1361 gnus-article-normalized-header-length)
1363 (insert (make-string
1364 (- gnus-article-normalized-header-length column)
1366 ((> column gnus-article-normalized-header-length)
1367 (gnus-put-text-property
1369 (forward-char gnus-article-normalized-header-length)
1376 (forward-line 1))))))
1378 (defun article-treat-dumbquotes ()
1379 "Translate M******** sm*rtq**t*s into proper text.
1380 Note that this function guesses whether a character is a sm*rtq**t* or
1381 not, so it should only be used interactively."
1383 (article-translate-strings gnus-article-dumbquotes-map))
1385 (defun article-translate-characters (from to)
1386 "Translate all characters in the body of the article according to FROM and TO.
1387 FROM is a string of characters to translate from; to is a string of
1388 characters to translate to."
1390 (when (article-goto-body)
1391 (let ((buffer-read-only nil)
1392 (x (make-string 225 ?x))
1394 (while (< (incf i) (length x))
1397 (while (< i (length from))
1398 (aset x (aref from i) (aref to i))
1400 (translate-region (point) (point-max) x)))))
1402 (defun article-translate-strings (map)
1403 "Translate all string in the body of the article according to MAP.
1404 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1406 (when (article-goto-body)
1407 (let ((buffer-read-only nil)
1409 (while (setq elem (pop map))
1411 (while (search-forward (car elem) nil t)
1412 (replace-match (cadr elem)))))))))
1414 (defun article-treat-overstrike ()
1415 "Translate overstrikes into bold text."
1418 (when (article-goto-body)
1419 (let ((buffer-read-only nil))
1420 (while (search-forward "\b" nil t)
1421 (let ((next (char-after))
1422 (previous (char-after (- (point) 2))))
1423 ;; We do the boldification/underlining by hiding the
1424 ;; overstrikes and putting the proper text property
1428 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1429 (put-text-property (point) (1+ (point)) 'face 'bold))
1431 (gnus-article-hide-text-type
1432 (1- (point)) (1+ (point)) 'overstrike)
1434 (- (point) 2) (1- (point)) 'face 'underline))
1436 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1438 (point) (1+ (point)) 'face 'underline)))))))))
1440 (defun article-fill-long-lines ()
1441 "Fill lines that are wider than the window width."
1444 (let ((buffer-read-only nil)
1445 (width (window-width (get-buffer-window (current-buffer)))))
1448 (let ((adaptive-fill-mode nil))
1451 (when (>= (current-column) (min fill-column width))
1452 (narrow-to-region (point) (gnus-point-at-bol))
1453 (fill-paragraph nil)
1454 (goto-char (point-max))
1456 (forward-line 1)))))))
1458 (defun article-capitalize-sentences ()
1459 "Capitalize the first word in each sentence."
1462 (let ((buffer-read-only nil)
1463 (paragraph-start "^[\n\^L]"))
1467 (forward-sentence)))))
1469 (defun article-remove-cr ()
1470 "Remove trailing CRs and then translate remaining CRs into LFs."
1473 (let ((buffer-read-only nil))
1474 (goto-char (point-min))
1475 (while (re-search-forward "\r+$" nil t)
1476 (replace-match "" t t))
1477 (goto-char (point-min))
1478 (while (search-forward "\r" nil t)
1479 (replace-match "\n" t t)))))
1481 (defun article-remove-trailing-blank-lines ()
1482 "Remove all trailing blank lines from the article."
1485 (let ((buffer-read-only nil))
1486 (goto-char (point-max))
1490 (while (and (not (bobp))
1491 (looking-at "^[ \t]*$")
1492 (not (gnus-annotation-in-region-p
1493 (point) (gnus-point-at-eol))))
1498 (defun article-display-x-face (&optional force)
1499 "Look for an X-Face header and display it if present."
1500 (interactive (list 'force))
1502 ;; Delete the old process, if any.
1503 (when (process-status "article-x-face")
1504 (delete-process "article-x-face"))
1505 (let ((inhibit-point-motion-hooks t)
1506 (case-fold-search t)
1509 (article-narrow-to-head)
1510 (goto-char (point-min))
1511 (setq from (message-fetch-field "from"))
1512 (goto-char (point-min))
1513 (while (and gnus-article-x-face-command
1516 ;; Check whether this face is censored.
1517 (not gnus-article-x-face-too-ugly)
1518 (and gnus-article-x-face-too-ugly from
1519 (not (string-match gnus-article-x-face-too-ugly
1521 ;; Has to be present.
1522 (re-search-forward "^X-Face: " nil t))
1523 ;; This used to try to do multiple faces (`while' instead of
1524 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1525 ;; work (b) it can crash some versions of Emacs (c) are
1526 ;; multiple faces really something to encourage?
1527 (when (stringp gnus-article-x-face-command)
1529 ;; We now have the area of the buffer where the X-Face is stored.
1532 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1533 ;; We display the face.
1534 (if (symbolp gnus-article-x-face-command)
1535 ;; The command is a lisp function, so we call it.
1536 (if (gnus-functionp gnus-article-x-face-command)
1537 (funcall gnus-article-x-face-command beg end)
1538 (error "%s is not a function" gnus-article-x-face-command))
1539 ;; The command is a string, so we interpret the command
1540 ;; as a, well, command, and fork it off.
1541 (let ((process-connection-type nil))
1542 (process-kill-without-query
1544 "article-x-face" nil shell-file-name shell-command-switch
1545 gnus-article-x-face-command))
1546 (process-send-region "article-x-face" beg end)
1547 (process-send-eof "article-x-face"))))))))))
1549 (defun article-decode-mime-words ()
1550 "Decode all MIME-encoded words in the article."
1553 (set-buffer gnus-article-buffer)
1554 (let ((inhibit-point-motion-hooks t)
1556 (mail-parse-charset gnus-newsgroup-charset)
1557 (mail-parse-ignored-charsets
1558 (save-excursion (set-buffer gnus-summary-buffer)
1559 gnus-newsgroup-ignored-charsets)))
1560 (mail-decode-encoded-word-region (point-min) (point-max)))))
1562 (defun article-decode-charset (&optional prompt)
1563 "Decode charset-encoded text in the article.
1564 If PROMPT (the prefix), prompt for a coding system to use."
1568 (article-narrow-to-head)
1569 (let* ((inhibit-point-motion-hooks t)
1570 (case-fold-search t)
1571 (ct (message-fetch-field "Content-Type" t))
1572 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1573 (ctl (and ct (ignore-errors
1574 (mail-header-parse-content-type ct))))
1577 (mm-read-coding-system "Charset to decode: "))
1579 (mail-content-type-get ctl 'charset))))
1580 (mail-parse-charset gnus-newsgroup-charset)
1581 (mail-parse-ignored-charsets
1582 (save-excursion (condition-case nil
1583 (set-buffer gnus-summary-buffer)
1585 gnus-newsgroup-ignored-charsets))
1587 (if (and ctl (not (string-match "/" (car ctl))))
1589 (goto-char (point-max))
1592 (narrow-to-region (point) (point-max))
1593 (when (and (or (not ctl)
1594 (equal (car ctl) "text/plain"))
1597 charset (and cte (intern (downcase
1598 (gnus-strip-whitespace cte))))
1601 (defun article-decode-encoded-words ()
1602 "Remove encoded-word encoding from headers."
1603 (let (buffer-read-only)
1604 (let ((charset (save-excursion
1605 (set-buffer gnus-summary-buffer)
1606 default-mime-charset)))
1607 (mime-decode-header-in-buffer charset)
1610 (defun article-de-quoted-unreadable (&optional force)
1611 "Translate a quoted-printable-encoded article.
1612 If FORCE, decode the article whether it is marked as quoted-printable
1614 (interactive (list 'force))
1616 (let ((buffer-read-only nil)
1617 (type (gnus-fetch-field "content-transfer-encoding"))
1618 (charset gnus-newsgroup-charset))
1620 (and type (string-match "quoted-printable" (downcase type))))
1623 (narrow-to-region (point) (point-max))
1624 (quoted-printable-decode-region (point-min) (point-max))
1626 (mm-decode-body charset)))))))
1628 (defun article-hide-list-identifiers ()
1629 "Remove any list identifiers in `gnus-list-identifiers' from Subject
1630 header in the current article."
1634 (let ((inhibit-point-motion-hooks t)
1636 (article-narrow-to-head)
1637 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1638 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1640 (goto-char (point-min))
1641 (when (re-search-forward
1642 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1644 (delete-region (match-beginning 2) (match-end 0)))))))))
1646 (defun article-hide-pgp ()
1647 "Remove any PGP headers and signatures in the current article."
1651 (let ((inhibit-point-motion-hooks t)
1652 buffer-read-only beg end)
1654 ;; Hide the "header".
1655 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1656 (push 'pgp gnus-article-wash-types)
1657 (delete-region (match-beginning 0) (match-end 0))
1658 ;; Remove armor headers (rfc2440 6.2)
1659 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1662 ;; Hide the actual signature.
1663 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1664 (setq end (1+ (match-beginning 0)))
1667 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1669 ;; Perhaps we shouldn't hide to the end of the buffer
1670 ;; if there is no end to the signature?
1672 ;; Hide "- " PGP quotation markers.
1674 (narrow-to-region beg end)
1675 (goto-char (point-min))
1676 (while (re-search-forward "^- " nil t)
1678 (match-beginning 0) (match-end 0)))
1680 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1682 (defun article-hide-pem (&optional arg)
1683 "Toggle hiding of any PEM headers and signatures in the current article.
1684 If given a negative prefix, always show; if given a positive prefix,
1686 (interactive (gnus-article-hidden-arg))
1687 (unless (gnus-article-check-hidden-text 'pem arg)
1689 (let (buffer-read-only end)
1690 (goto-char (point-min))
1691 ;; Hide the horrendously ugly "header".
1692 (when (and (search-forward
1693 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1695 (setq end (1+ (match-beginning 0))))
1696 (push 'pem gnus-article-wash-types)
1697 (gnus-article-hide-text-type
1699 (if (search-forward "\n\n" nil t)
1703 ;; Hide the trailer as well
1704 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1706 (gnus-article-hide-text-type
1707 (match-beginning 0) (match-end 0) 'pem)))))))
1709 (defun article-strip-banner ()
1710 "Strip the banner specified by the `banner' group parameter."
1714 (let ((inhibit-point-motion-hooks t)
1715 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1716 (gnus-signature-limit nil)
1717 buffer-read-only beg end)
1721 ((eq banner 'signature)
1722 (when (gnus-article-narrow-to-signature)
1725 (delete-region (point) (point-max))))
1727 (while (re-search-forward banner nil t)
1728 (delete-region (match-beginning 0) (match-end 0))))))))))
1730 (defun article-babel ()
1731 "Translate article using an online translation service."
1735 (set-buffer gnus-article-buffer)
1736 (when (article-goto-body)
1737 (let* ((buffer-read-only nil)
1740 (orig (buffer-substring start end))
1741 (trans (babel-as-string orig)))
1743 (narrow-to-region start end)
1744 (delete-region start end)
1747 (defun article-hide-signature (&optional arg)
1748 "Hide the signature in the current article.
1749 If given a negative prefix, always show; if given a positive prefix,
1751 (interactive (gnus-article-hidden-arg))
1757 (article-goto-body))
1758 (goto-char (point-min)))
1759 (unless (gnus-article-check-hidden-text 'signature arg)
1760 (let ((buffer-read-only nil)
1762 (while (setq button (text-property-any button (point-max)
1764 'gnus-signature-toggle))
1765 (setq button (text-property-not-all button (point-max)
1767 'gnus-signature-toggle))
1768 (when (and button (not (eobp)))
1769 (gnus-article-hide-text-type
1771 (or (next-single-property-change (1+ button) 'mime-view-entity)
1775 (defun article-strip-headers-in-body ()
1776 "Strip offensive headers from bodies."
1780 (let ((case-fold-search t))
1781 (when (looking-at "x-no-archive:")
1782 (gnus-delete-line)))))
1784 (defun article-strip-leading-blank-lines ()
1785 "Remove all blank lines from the beginning of the article."
1788 (let ((inhibit-point-motion-hooks t)
1790 (when (article-goto-body)
1791 (while (and (not (eobp))
1792 (looking-at "[ \t]*$"))
1793 (gnus-delete-line))))))
1795 (defun article-narrow-to-head ()
1796 "Narrow the buffer to the head of the message.
1797 Point is left at the beginning of the narrowed-to region."
1799 (goto-char (point-min))
1800 (if (search-forward "\n\n" nil 1)
1803 (goto-char (point-min)))
1805 (defun article-goto-body ()
1806 "Place point at the start of the body."
1807 (goto-char (point-min))
1809 ;; This variable is only bound when dealing with separate
1811 (article-goto-body-goes-to-point-min-p
1813 ((search-forward "\n\n" nil t)
1816 (goto-char (point-max))
1819 (defun article-strip-multiple-blank-lines ()
1820 "Replace consecutive blank lines with one empty line."
1823 (let ((inhibit-point-motion-hooks t)
1825 ;; First make all blank lines empty.
1827 (while (re-search-forward "^[ \t]+$" nil t)
1828 (unless (gnus-annotation-in-region-p
1829 (match-beginning 0) (match-end 0))
1830 (replace-match "" nil t)))
1831 ;; Then replace multiple empty lines with a single empty line.
1833 (while (re-search-forward "\n\n\n+" nil t)
1834 (unless (gnus-annotation-in-region-p
1835 (match-beginning 0) (match-end 0))
1836 (replace-match "\n\n" t t))))))
1838 (defun article-strip-leading-space ()
1839 "Remove all white space from the beginning of the lines in the article."
1842 (let ((inhibit-point-motion-hooks t)
1845 (while (re-search-forward "^[ \t]+" nil t)
1846 (replace-match "" t t)))))
1848 (defun article-strip-trailing-space ()
1849 "Remove all white space from the end of the lines in the article."
1852 (let ((inhibit-point-motion-hooks t)
1855 (while (re-search-forward "[ \t]+$" nil t)
1856 (replace-match "" t t)))))
1858 (defun article-strip-blank-lines ()
1859 "Strip leading, trailing and multiple blank lines."
1861 (article-strip-leading-blank-lines)
1862 (article-remove-trailing-blank-lines)
1863 (article-strip-multiple-blank-lines))
1865 (defun article-strip-all-blank-lines ()
1866 "Strip all blank lines."
1869 (let ((inhibit-point-motion-hooks t)
1872 (while (re-search-forward "^[ \t]*\n" nil t)
1873 (replace-match "" t t)))))
1875 (defun gnus-article-narrow-to-signature ()
1876 "Narrow to the signature; return t if a signature is found, else nil."
1877 (let ((inhibit-point-motion-hooks t))
1878 (when (gnus-article-search-signature)
1880 ;; Check whether we have some limits to what we consider
1881 ;; to be a signature.
1882 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1883 (list gnus-signature-limit)))
1885 (while (setq limit (pop limits))
1886 (if (or (and (integerp limit)
1887 (< (- (point-max) (point)) limit))
1889 (< (count-lines (point) (point-max)) limit))
1890 (and (gnus-functionp limit)
1892 (and (stringp limit)
1893 (not (re-search-forward limit nil t))))
1894 () ; This limit did not succeed.
1898 (narrow-to-region (point) (point-max))
1901 (defun gnus-article-search-signature ()
1902 "Search the current buffer for the signature separator.
1903 Put point at the beginning of the signature separator."
1904 (let ((cur (point)))
1905 (goto-char (point-max))
1906 (if (if (stringp gnus-signature-separator)
1907 (re-search-backward gnus-signature-separator nil t)
1908 (let ((seps gnus-signature-separator))
1910 (not (re-search-backward (car seps) nil t)))
1917 (defun gnus-article-hidden-arg ()
1918 "Return the current prefix arg as a number, or 0 if no prefix."
1919 (list (if current-prefix-arg
1920 (prefix-numeric-value current-prefix-arg)
1923 (defun gnus-article-check-hidden-text (type arg)
1924 "Return nil if hiding is necessary.
1925 Arg can be nil or a number. Nil and positive means hide, negative
1926 means show, 0 means toggle."
1929 (let ((hide (gnus-article-hidden-text-p type)))
1935 (gnus-article-show-hidden-text type))
1937 (if (eq hide 'hidden)
1938 (gnus-article-show-hidden-text type)
1941 (defun gnus-article-hidden-text-p (type)
1942 "Say whether the current buffer contains hidden text of type TYPE."
1943 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1945 (not (get-text-property pos 'invisible))
1946 (not (get-text-property pos 'dummy-invisible)))
1948 (text-property-any (1+ pos) (point-max) 'article-type type)))
1953 (defun gnus-article-show-hidden-text (type &optional hide)
1954 "Show all hidden text of type TYPE.
1955 If HIDE, hide the text instead."
1957 (let ((buffer-read-only nil)
1958 (inhibit-point-motion-hooks t)
1961 (while (setq beg (text-property-any end (point-max) 'article-type type))
1964 (text-property-not-all beg (point-max) 'article-type type)
1967 (gnus-article-hide-text beg end gnus-hidden-properties)
1968 (gnus-article-unhide-text beg end))
1972 (defconst article-time-units
1973 `((year . ,(* 365.25 24 60 60))
1974 (week . ,(* 7 24 60 60))
1975 (day . ,(* 24 60 60))
1979 "Mapping from time units to seconds.")
1981 (defun article-date-ut (&optional type highlight header)
1982 "Convert DATE date to universal time in the current article.
1983 If TYPE is `local', convert to local time; if it is `lapsed', output
1984 how much time has lapsed since DATE. For `lapsed', the value of
1985 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1986 should replace the \"Date:\" one, or should be added below it."
1987 (interactive (list 'ut t))
1988 (let* ((header (or header
1989 (and (eq 1 (point-min))
1990 (mail-header-date (save-excursion
1991 (set-buffer gnus-summary-buffer)
1992 gnus-current-headers)))
1993 (message-fetch-field "date")
1995 (date (if (vectorp header) (mail-header-date header)
1997 (inhibit-point-motion-hooks t)
1998 bface eface date-pos)
1999 (when (and date (not (string= date "")))
2002 (article-narrow-to-head)
2003 (when (or (and (eq type 'lapsed)
2004 gnus-article-date-lapsed-new-header
2005 ;; Attempt to get the face of X-Sent first.
2006 (re-search-forward "^X-Sent:[ \t]" nil t))
2007 (re-search-forward "^Date:[ \t]" nil t)
2008 ;; If Date is missing, try again for X-Sent.
2009 (re-search-forward "^X-Sent:[ \t]" nil t))
2010 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2011 date (or (get-text-property (gnus-point-at-bol)
2014 eface (get-text-property (1- (gnus-point-at-eol))
2016 (let ((buffer-read-only nil))
2017 ;; Delete any old X-Sent headers.
2018 (when (setq date-pos
2019 (text-property-any (point-min) (point-max)
2020 'article-date-lapsed t))
2021 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2022 (delete-region (match-beginning 0)
2023 (progn (forward-line 1) (point))))
2024 (goto-char (point-min))
2025 ;; Delete any old Date headers.
2026 (while (re-search-forward "^Date:[ \t]" nil t)
2028 (setq date-pos (match-beginning 0)))
2029 (unless (and (eq type 'lapsed)
2030 gnus-article-date-lapsed-new-header)
2031 (delete-region (match-beginning 0)
2032 (progn (message-next-header) (point)))))
2035 (goto-char date-pos)
2037 ;; Possibly, Date has been deleted.
2039 (when (and (eq type 'lapsed)
2040 gnus-article-date-lapsed-new-header
2041 (looking-at "Date:"))
2043 (goto-char (point-min)))
2044 (insert (article-make-date-line date type))
2045 (when (eq type 'lapsed)
2046 (put-text-property (gnus-point-at-bol) (point)
2047 'article-date-lapsed t))
2051 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2052 (put-text-property (match-beginning 1) (1+ (match-end 1))
2053 'original-date date)
2054 (put-text-property (match-beginning 1) (1+ (match-end 1))
2056 (put-text-property (match-beginning 2) (match-end 2)
2059 (defun article-make-date-line (date type)
2060 "Return a DATE line of TYPE."
2061 (let ((time (condition-case ()
2065 ;; Convert to the local timezone. We have to slap a
2066 ;; `condition-case' round the calls to the timezone
2067 ;; functions since they aren't particularly resistant to
2070 (let ((tz (car (current-time-zone time))))
2071 (format "Date: %s %s%02d%02d" (current-time-string time)
2072 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2073 (/ (% (abs tz) 3600) 60))))
2074 ;; Convert to Universal Time.
2077 (current-time-string
2078 (let* ((e (parse-time-string date))
2079 (tm (apply 'encode-time e))
2081 (ls (- (cadr tm) (car (current-time-zone time)))))
2082 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2083 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2086 ;; Get the original date from the article.
2087 ((eq type 'original)
2088 (concat "Date: " (if (string-match "\n+$" date)
2089 (substring date 0 (match-beginning 0))
2091 ;; Let the user define the format.
2093 (if (gnus-functionp gnus-article-time-format)
2094 (funcall gnus-article-time-format time)
2097 (format-time-string gnus-article-time-format time))))
2100 (let ((tz (car (current-time-zone time))))
2103 (format-time-string "%Y%m%dT%H%M%S" time)
2104 (format "%s%02d%02d"
2105 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2106 (/ (% (abs tz) 3600) 60)))))
2107 ;; Do an X-Sent lapsed format.
2109 ;; If the date is seriously mangled, the timezone functions are
2110 ;; liable to bug out, so we ignore all errors.
2111 (let* ((now (current-time))
2112 (real-time (subtract-time now time))
2113 (real-sec (and real-time
2114 (+ (* (float (car real-time)) 65536)
2116 (sec (and real-time (abs real-sec)))
2126 ;; This is a bit convoluted, but basically we go
2127 ;; through the time units for years, weeks, etc,
2128 ;; and divide things to see whether that results
2129 ;; in positive answers.
2132 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2133 ;; The (remaining) seconds are too few to
2134 ;; be divided into this time unit.
2136 ;; It's big enough, so we output it.
2137 (setq sec (- sec (* num (cdr unit))))
2139 (concat (if prev ", " "") (int-to-string
2141 " " (symbol-name (car unit))
2142 (if (> num 1) "s" ""))
2144 article-time-units "")
2145 ;; If dates are odd, then it might appear like the
2146 ;; article was sent in the future.
2149 " in the future"))))))
2151 (error "Unknown conversion type: %s" type)))))
2153 (defun article-date-local (&optional highlight)
2154 "Convert the current article date to the local timezone."
2155 (interactive (list t))
2156 (article-date-ut 'local highlight))
2158 (defun article-date-original (&optional highlight)
2159 "Convert the current article date to what it was originally.
2160 This is only useful if you have used some other date conversion
2161 function and want to see what the date was before converting."
2162 (interactive (list t))
2163 (article-date-ut 'original highlight))
2165 (defun article-date-lapsed (&optional highlight)
2166 "Convert the current article date to time lapsed since it was sent."
2167 (interactive (list t))
2168 (article-date-ut 'lapsed highlight))
2170 (defun article-update-date-lapsed ()
2171 "Function to be run from a timer to update the lapsed time line."
2172 (let (deactivate-mark)
2177 (set-buffer (window-buffer w))
2178 (when (eq major-mode 'gnus-article-mode)
2179 (goto-char (point-min))
2180 (when (re-search-forward "^X-Sent:" nil t)
2181 (article-date-lapsed t))))
2184 (defun gnus-start-date-timer (&optional n)
2185 "Start a timer to update the X-Sent header in the article buffers.
2186 The numerical prefix says how frequently (in seconds) the function
2191 (gnus-stop-date-timer)
2192 (setq article-lapsed-timer
2193 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2195 (defun gnus-stop-date-timer ()
2196 "Stop the X-Sent timer."
2198 (when article-lapsed-timer
2199 (nnheader-cancel-timer article-lapsed-timer)
2200 (setq article-lapsed-timer nil)))
2202 (defun article-date-user (&optional highlight)
2203 "Convert the current article date to the user-defined format.
2204 This format is defined by the `gnus-article-time-format' variable."
2205 (interactive (list t))
2206 (article-date-ut 'user highlight))
2208 (defun article-date-iso8601 (&optional highlight)
2209 "Convert the current article date to ISO8601."
2210 (interactive (list t))
2211 (article-date-ut 'iso8601 highlight))
2213 (defun article-show-all ()
2214 "Show all hidden text in the article buffer."
2218 (let ((buffer-read-only nil))
2219 (gnus-article-unhide-text (point-min) (point-max))
2220 (gnus-remove-text-with-property 'gnus-prev)
2221 (gnus-remove-text-with-property 'gnus-next))))
2223 (defun article-show-all-headers ()
2224 "Show all hidden headers in the article buffer."
2229 (article-narrow-to-head)
2230 (let ((buffer-read-only nil))
2231 (gnus-article-unhide-text (point-min) (point-max))))))
2233 (defun article-emphasize (&optional arg)
2234 "Emphasize text according to `gnus-emphasis-alist'."
2235 (interactive (gnus-article-hidden-arg))
2236 (unless (gnus-article-check-hidden-text 'emphasis arg)
2238 (let ((alist (or (with-current-buffer gnus-summary-buffer
2239 gnus-article-emphasis-alist)
2240 gnus-emphasis-alist))
2241 (buffer-read-only nil)
2242 (props (append '(article-type emphasis)
2243 gnus-hidden-properties))
2244 regexp elem beg invisible visible face)
2247 (while (setq elem (pop alist))
2249 (setq regexp (car elem)
2250 invisible (nth 1 elem)
2251 visible (nth 2 elem)
2253 (while (re-search-forward regexp nil t)
2254 (when (and (match-beginning visible) (match-beginning invisible))
2255 (push 'emphasis gnus-article-wash-types)
2256 (gnus-article-hide-text
2257 (match-beginning invisible) (match-end invisible) props)
2258 (gnus-article-unhide-text-type
2259 (match-beginning visible) (match-end visible) 'emphasis)
2260 (gnus-put-text-property-excluding-newlines
2261 (match-beginning visible) (match-end visible) 'face face)
2262 (goto-char (match-end invisible)))))))))
2264 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2265 "Setup newsgroup emphasis alist."
2266 (unless gnus-article-emphasis-alist
2267 (let ((name (and gnus-newsgroup-name
2268 (gnus-group-real-name gnus-newsgroup-name))))
2269 (make-local-variable 'gnus-article-emphasis-alist)
2270 (setq gnus-article-emphasis-alist
2272 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2273 (while (setq elem (pop alist))
2274 (when (and name (string-match (car elem) name))
2276 highlight (copy-list (cdr elem)))))
2278 (copy-list highlight-words)
2279 (if gnus-newsgroup-name
2280 (copy-list (gnus-group-find-parameter
2281 gnus-newsgroup-name 'highlight-words t)))
2282 gnus-emphasis-alist)))))
2284 (defvar gnus-summary-article-menu)
2285 (defvar gnus-summary-post-menu)
2287 ;;; Saving functions.
2289 (defun gnus-article-save (save-buffer file &optional num)
2290 "Save the currently selected article."
2291 (unless gnus-save-all-headers
2292 ;; Remove headers according to `gnus-saved-headers'.
2293 (let ((gnus-visible-headers
2294 (or gnus-saved-headers gnus-visible-headers))
2295 (gnus-article-buffer save-buffer))
2297 (set-buffer save-buffer)
2298 (article-hide-headers 1 t))))
2299 (save-window-excursion
2300 (if (not gnus-default-article-saver)
2301 (error "No default saver is defined")
2302 ;; !!! Magic! The saving functions all save
2303 ;; `gnus-save-article-buffer' (or so they think), but we
2304 ;; bind that variable to our save-buffer.
2305 (set-buffer gnus-article-buffer)
2306 (let* ((gnus-save-article-buffer save-buffer)
2309 ((not gnus-prompt-before-saving) 'default)
2310 ((eq gnus-prompt-before-saving 'always) nil)
2312 (gnus-number-of-articles-to-be-saved
2313 (when (eq gnus-prompt-before-saving t)
2315 (set-buffer gnus-article-current-summary)
2316 (funcall gnus-default-article-saver filename)))))
2318 (defun gnus-read-save-file-name (prompt &optional filename
2319 function group headers variable)
2321 (funcall function group headers (symbol-value variable)))
2326 ((eq filename 'default)
2332 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2335 (if (and gnus-number-of-articles-to-be-saved
2336 (> gnus-number-of-articles-to-be-saved 1))
2337 (format "these %d articles"
2338 gnus-number-of-articles-to-be-saved)
2341 ;; Let the split methods have their say.
2343 ;; No split name was found.
2346 (concat prompt " (default "
2347 (file-name-nondirectory default-name) ") ")
2348 (file-name-directory default-name)
2350 ;; A single group name is returned.
2351 ((stringp split-name)
2353 (funcall function split-name headers
2354 (symbol-value variable)))
2356 (concat prompt " (default "
2357 (file-name-nondirectory default-name) ") ")
2358 (file-name-directory default-name)
2360 ;; A single split name was found
2361 ((= 1 (length split-name))
2362 (let* ((name (expand-file-name
2363 (car split-name) gnus-article-save-directory))
2364 (dir (cond ((file-directory-p name)
2365 (file-name-as-directory name))
2366 ((file-exists-p name) name)
2367 (t gnus-article-save-directory))))
2369 (concat prompt " (default " name ") ")
2371 ;; A list of splits was found.
2373 (setq split-name (nreverse split-name))
2375 (let ((file-name-history
2376 (nconc split-name file-name-history)))
2380 (concat prompt " (`M-p' for defaults) ")
2381 gnus-article-save-directory
2383 gnus-article-save-directory)))
2384 (car (push result file-name-history)))))))
2385 ;; Create the directory.
2386 (gnus-make-directory (file-name-directory file))
2387 ;; If we have read a directory, we append the default file name.
2388 (when (file-directory-p file)
2389 (setq file (concat (file-name-as-directory file)
2390 (file-name-nondirectory default-name))))
2391 ;; Possibly translate some characters.
2392 (nnheader-translate-file-chars file)))))
2393 (gnus-make-directory (file-name-directory result))
2394 (set variable result)))
2396 (defun gnus-article-archive-name (group)
2397 "Return the first instance of an \"Archive-name\" in the current buffer."
2398 (let ((case-fold-search t))
2399 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2400 (nnheader-concat gnus-article-save-directory
2401 (match-string 1)))))
2403 (defun gnus-article-nndoc-name (group)
2404 "If GROUP is an nndoc group, return the name of the parent group."
2405 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2406 (gnus-group-get-parameter group 'save-article-group)))
2408 (defun gnus-summary-save-in-rmail (&optional filename)
2409 "Append this article to Rmail file.
2410 Optional argument FILENAME specifies file name.
2411 Directory to save to is default to `gnus-article-save-directory'."
2412 (setq filename (gnus-read-save-file-name
2413 "Save %s in rmail file:" filename
2414 gnus-rmail-save-name gnus-newsgroup-name
2415 gnus-current-headers 'gnus-newsgroup-last-rmail))
2416 (gnus-eval-in-buffer-window gnus-save-article-buffer
2420 (gnus-output-to-rmail filename))))
2423 (defun gnus-summary-save-in-mail (&optional filename)
2424 "Append this article to Unix mail file.
2425 Optional argument FILENAME specifies file name.
2426 Directory to save to is default to `gnus-article-save-directory'."
2427 (setq filename (gnus-read-save-file-name
2428 "Save %s in Unix mail file:" filename
2429 gnus-mail-save-name gnus-newsgroup-name
2430 gnus-current-headers 'gnus-newsgroup-last-mail))
2431 (gnus-eval-in-buffer-window gnus-save-article-buffer
2435 (if (and (file-readable-p filename)
2436 (mail-file-babyl-p filename))
2437 (rmail-output-to-rmail-file filename t)
2438 (gnus-output-to-mail filename)))))
2441 (defun gnus-summary-save-in-file (&optional filename overwrite)
2442 "Append this article to 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 file:" filename
2447 gnus-file-save-name gnus-newsgroup-name
2448 gnus-current-headers 'gnus-newsgroup-last-file))
2449 (gnus-eval-in-buffer-window gnus-save-article-buffer
2453 (when (and overwrite
2454 (file-exists-p filename))
2455 (delete-file filename))
2456 (gnus-output-to-file filename))))
2459 (defun gnus-summary-write-to-file (&optional filename)
2460 "Write this article to a file.
2461 Optional argument FILENAME specifies file name.
2462 The directory to save in defaults to `gnus-article-save-directory'."
2463 (gnus-summary-save-in-file nil t))
2465 (defun gnus-summary-save-body-in-file (&optional filename)
2466 "Append this article body to a file.
2467 Optional argument FILENAME specifies file name.
2468 The directory to save in defaults to `gnus-article-save-directory'."
2469 (setq filename (gnus-read-save-file-name
2470 "Save %s body in file:" filename
2471 gnus-file-save-name gnus-newsgroup-name
2472 gnus-current-headers 'gnus-newsgroup-last-file))
2473 (gnus-eval-in-buffer-window gnus-save-article-buffer
2477 (when (article-goto-body)
2478 (narrow-to-region (point) (point-max)))
2479 (gnus-output-to-file filename))))
2482 (defun gnus-summary-save-in-pipe (&optional command)
2483 "Pipe this article to subprocess."
2485 (cond ((and (eq command 'default)
2486 gnus-last-shell-command)
2487 gnus-last-shell-command)
2491 "Shell command on %s: "
2492 (if (and gnus-number-of-articles-to-be-saved
2493 (> gnus-number-of-articles-to-be-saved 1))
2494 (format "these %d articles"
2495 gnus-number-of-articles-to-be-saved)
2497 gnus-last-shell-command))))
2498 (when (string-equal command "")
2499 (setq command gnus-last-shell-command))
2500 (gnus-eval-in-buffer-window gnus-article-buffer
2503 (shell-command-on-region (point-min) (point-max) command nil)))
2504 (setq gnus-last-shell-command command))
2506 ;;; Article file names when saving.
2508 (defun gnus-capitalize-newsgroup (newsgroup)
2509 "Capitalize NEWSGROUP name."
2510 (when (not (zerop (length newsgroup)))
2511 (concat (char-to-string (upcase (aref newsgroup 0)))
2512 (substring newsgroup 1))))
2514 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2515 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2516 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2517 Otherwise, it is like ~/News/news/group/num."
2520 (concat (if (gnus-use-long-file-name 'not-save)
2521 (gnus-capitalize-newsgroup newsgroup)
2522 (gnus-newsgroup-directory-form newsgroup))
2523 "/" (int-to-string (mail-header-number headers)))
2524 gnus-article-save-directory)))
2526 (string-equal (file-name-directory default)
2527 (file-name-directory last-file))
2528 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2530 (or last-file default))))
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
2535 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2538 (concat (if (gnus-use-long-file-name 'not-save)
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-Plain-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. Otherwise, it is like ~/News/news/group/news."
2556 (if (gnus-use-long-file-name 'not-save)
2557 (gnus-capitalize-newsgroup newsgroup)
2558 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2559 gnus-article-save-directory)))
2561 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2562 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2563 If variable `gnus-use-long-file-name' is non-nil, it is
2564 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2567 (if (gnus-use-long-file-name 'not-save)
2569 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2570 gnus-article-save-directory)))
2577 (setq afunc (car func)
2580 gfunc (intern (format "gnus-%s" func))))
2582 (if (not (fboundp afunc))
2584 `(lambda (&optional interactive &rest args)
2585 ,(documentation afunc t)
2586 (interactive (list t))
2588 (set-buffer gnus-article-buffer)
2590 (call-interactively ',afunc)
2591 (apply ',afunc args))))))))
2592 '(article-hide-headers
2593 article-hide-boring-headers
2594 article-toggle-headers
2595 article-treat-overstrike
2596 article-fill-long-lines
2597 article-capitalize-sentences
2599 article-display-x-face
2600 article-de-quoted-unreadable
2601 article-hide-list-identifiers
2603 article-strip-banner
2606 article-hide-signature
2607 article-strip-headers-in-body
2608 article-remove-trailing-blank-lines
2609 article-strip-leading-blank-lines
2610 article-strip-multiple-blank-lines
2611 article-strip-leading-space
2612 article-strip-trailing-space
2613 article-strip-blank-lines
2614 article-strip-all-blank-lines
2616 article-date-iso8601
2617 article-date-original
2619 article-decode-mime-words
2620 article-decode-charset
2621 article-decode-encoded-words
2625 article-treat-dumbquotes
2626 article-normalize-headers
2627 (article-show-all-headers . gnus-article-show-all-headers)
2628 (article-show-all . gnus-article-show-all))))
2631 ;;; Gnus article mode
2634 (put 'gnus-article-mode 'mode-class 'special)
2636 (gnus-define-keys gnus-article-mode-map
2637 " " gnus-article-goto-next-page
2638 "\177" gnus-article-goto-prev-page
2639 [delete] gnus-article-goto-prev-page
2640 [backspace] gnus-article-goto-prev-page
2641 "\C-c^" gnus-article-refer-article
2642 "h" gnus-article-show-summary
2643 "s" gnus-article-show-summary
2644 "\C-c\C-m" gnus-article-mail
2645 "?" gnus-article-describe-briefly
2646 gnus-mouse-2 gnus-article-push-button
2647 "\r" gnus-article-press-button
2648 "\t" gnus-article-next-button
2649 "\M-\t" gnus-article-prev-button
2650 "e" gnus-article-edit
2651 "<" beginning-of-buffer
2653 "\C-c\C-i" gnus-info-find-node
2656 "\C-d" gnus-article-read-summary-keys
2657 "\M-*" gnus-article-read-summary-keys
2658 "\M-#" gnus-article-read-summary-keys
2659 "\M-^" gnus-article-read-summary-keys
2660 "\M-g" gnus-article-read-summary-keys)
2662 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2665 (unless (lookup-key gnus-article-mode-map key)
2666 (define-key gnus-article-mode-map key
2667 'gnus-article-read-summary-keys)))
2672 (let ((key (car elt)))
2673 (and (> (length key) 0)
2674 (not (eq 'menu-bar (aref key 0)))
2675 (symbolp (lookup-key gnus-summary-mode-map key))
2677 (accessible-keymaps gnus-summary-mode-map))
2681 (push (char-to-string c) keys)
2685 (defun gnus-article-make-menu-bar ()
2686 (gnus-turn-off-edit-menu 'article)
2687 (unless (boundp 'gnus-article-article-menu)
2689 gnus-article-article-menu gnus-article-mode-map ""
2691 ["Scroll forwards" gnus-article-goto-next-page t]
2692 ["Scroll backwards" gnus-article-goto-prev-page t]
2693 ["Show summary" gnus-article-show-summary t]
2694 ["Fetch Message-ID at point" gnus-article-refer-article t]
2695 ["Mail to address at point" gnus-article-mail t]
2696 ["Send a bug report" gnus-bug t]))
2699 gnus-article-treatment-menu gnus-article-mode-map ""
2701 ["Hide headers" gnus-article-toggle-headers t]
2702 ["Hide signature" gnus-article-hide-signature t]
2703 ["Hide citation" gnus-article-hide-citation t]
2704 ["Treat overstrike" gnus-article-treat-overstrike t]
2705 ["Remove carriage return" gnus-article-remove-cr t]))
2707 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2709 (when (boundp 'gnus-summary-post-menu)
2710 (define-key gnus-article-mode-map [menu-bar post]
2711 (cons "Post" gnus-summary-post-menu)))
2713 (gnus-run-hooks 'gnus-article-menu-hook)))
2715 (defun gnus-article-mode ()
2716 "Major mode for displaying an article.
2718 All normal editing commands are switched off.
2720 The following commands are available in addition to all summary mode
2722 \\<gnus-article-mode-map>
2723 \\[gnus-article-next-page]\t Scroll the article one page forwards
2724 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2725 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2726 \\[gnus-article-show-summary]\t Display the summary buffer
2727 \\[gnus-article-mail]\t Send a reply to the address near point
2728 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2729 \\[gnus-info-find-node]\t Go to the Gnus info node"
2731 (when (gnus-visual-p 'article-menu 'menu)
2732 (gnus-article-make-menu-bar))
2733 (gnus-simplify-mode-line)
2734 (setq mode-name "Article")
2735 (setq major-mode 'gnus-article-mode)
2736 (make-local-variable 'minor-mode-alist)
2737 (unless (assq 'gnus-show-mime minor-mode-alist)
2738 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2739 (use-local-map gnus-article-mode-map)
2740 (gnus-update-format-specifications nil 'article-mode)
2741 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2742 (make-local-variable 'gnus-page-broken)
2743 (make-local-variable 'gnus-button-marker-list)
2744 (make-local-variable 'gnus-article-current-summary)
2745 (make-local-variable 'gnus-article-mime-handles)
2746 (make-local-variable 'gnus-article-decoded-p)
2747 (make-local-variable 'gnus-article-mime-handle-alist)
2748 (make-local-variable 'gnus-article-washed-types)
2749 (gnus-set-default-directory)
2750 (buffer-disable-undo)
2751 (setq buffer-read-only t)
2752 (set-syntax-table gnus-article-mode-syntax-table)
2753 (gnus-run-hooks 'gnus-article-mode-hook))
2755 (defun gnus-article-setup-buffer ()
2756 "Initialize the article buffer."
2757 (let* ((name (if gnus-single-article-buffer "*Article*"
2758 (concat "*Article " gnus-newsgroup-name "*")))
2760 (progn (string-match "\\*Article" name)
2761 (concat " *Original Article"
2762 (substring name (match-end 0))))))
2763 (setq gnus-article-buffer name)
2764 (setq gnus-original-article-buffer original)
2765 (setq gnus-article-mime-handle-alist nil)
2766 ;; This might be a variable local to the summary buffer.
2767 (unless gnus-single-article-buffer
2769 (set-buffer gnus-summary-buffer)
2770 (setq gnus-article-buffer name)
2771 (setq gnus-original-article-buffer original)
2772 (gnus-set-global-variables)))
2773 (gnus-article-setup-highlight-words)
2774 ;; Init original article buffer.
2776 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2777 (setq major-mode 'gnus-original-article-mode)
2778 (make-local-variable 'gnus-original-article))
2779 (if (get-buffer name)
2782 (kill-all-local-variables)
2783 (buffer-disable-undo)
2784 (setq buffer-read-only t)
2785 (unless (eq major-mode 'gnus-article-mode)
2786 (gnus-article-mode))
2789 (set-buffer (gnus-get-buffer-create name))
2791 (make-local-variable 'gnus-summary-buffer)
2792 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2793 (current-buffer)))))
2795 ;; Set article window start at LINE, where LINE is the number of lines
2796 ;; from the head of the article.
2797 (defun gnus-article-set-window-start (&optional line)
2799 (get-buffer-window gnus-article-buffer t)
2801 (set-buffer gnus-article-buffer)
2802 (goto-char (point-min))
2805 (gnus-message 6 "Moved to bookmark")
2806 (search-forward "\n\n" nil t)
2810 ;;; @@ article filters
2813 (defun gnus-article-display-mime-message ()
2814 "Article display method for MIME message."
2815 ;; called from `gnus-original-article-buffer'.
2816 (let (charset all-headers)
2817 (with-current-buffer gnus-summary-buffer
2818 (setq charset default-mime-charset
2819 all-headers gnus-have-all-headers))
2820 (make-local-variable 'default-mime-charset)
2821 (setq default-mime-charset charset)
2822 (with-current-buffer (get-buffer-create gnus-article-buffer)
2823 (make-local-variable 'default-mime-charset)
2824 (setq default-mime-charset charset))
2825 (mime-display-message mime-message-structure
2826 gnus-article-buffer nil gnus-article-mode-map)
2828 (gnus-article-hide-headers nil -1))
2830 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2831 (make-local-variable 'mime-button-mother-dispatcher)
2832 (setq mime-button-mother-dispatcher
2833 (function gnus-article-push-button))
2834 (run-hooks 'gnus-mime-article-prepare-hook))
2836 (defun gnus-article-display-traditional-message ()
2837 "Article display method for traditional message."
2838 (set-buffer gnus-article-buffer)
2839 (let (buffer-read-only)
2841 (insert-buffer-substring gnus-original-article-buffer)))
2843 (defun gnus-article-make-full-mail-header (&optional number charset)
2844 "Create a new mail header structure in a raw article buffer."
2845 (unless (and number charset)
2846 (save-current-buffer
2847 (set-buffer gnus-summary-buffer)
2849 (setq number (or (cdr gnus-article-current) 0)))
2851 (setq charset (or default-mime-charset 'x-ctext)))))
2852 (goto-char (point-min))
2853 (let ((header-end (if (search-forward "\n\n" nil t)
2855 (goto-char (point-max))))
2856 (chars (- (point-max) (point)))
2857 (lines (count-lines (point) (point-max)))
2858 (default-mime-charset charset)
2860 (narrow-to-region (point-min) header-end)
2861 (setq xref (std11-fetch-field "xref"))
2863 (make-full-mail-header
2865 (std11-fetch-field "subject")
2866 (std11-fetch-field "from")
2867 (std11-fetch-field "date")
2868 (std11-fetch-field "message-id")
2869 (std11-fetch-field "references")
2872 (when xref (concat "Xref: " xref)))
2875 (defun gnus-article-prepare (article &optional all-headers header)
2876 "Prepare ARTICLE in article mode buffer.
2877 ARTICLE should either be an article number or a Message-ID.
2878 If ARTICLE is an id, HEADER should be the article headers.
2879 If ALL-HEADERS is non-nil, no headers are hidden."
2881 ;; Make sure we start in a summary buffer.
2882 (unless (eq major-mode 'gnus-summary-mode)
2883 (set-buffer gnus-summary-buffer))
2884 (setq gnus-summary-buffer (current-buffer))
2885 (let* ((gnus-article (if header (mail-header-number header) article))
2886 (summary-buffer (current-buffer))
2887 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2888 (group gnus-newsgroup-name)
2891 (gnus-article-setup-buffer)
2892 (set-buffer gnus-original-article-buffer)
2893 ;; Deactivate active regions.
2894 (when (and (boundp 'transient-mark-mode)
2895 transient-mark-mode)
2896 (setq mark-active nil))
2897 (if (not (setq result (let ((buffer-read-only nil))
2898 (gnus-request-article-this-buffer
2900 ;; There is no such article.
2902 (when (and (numberp article)
2903 (not (memq article gnus-newsgroup-sparse)))
2904 (setq gnus-article-current
2905 (cons gnus-newsgroup-name article))
2906 (set-buffer gnus-summary-buffer)
2907 (setq gnus-current-article article)
2908 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2910 (gnus-summary-set-agent-mark article)
2911 (message "Message marked for downloading"))
2912 (gnus-summary-mark-article article gnus-canceled-mark)
2913 (unless (memq article gnus-newsgroup-sparse)
2915 "No such article (may have expired or been canceled)")))))
2916 (if (or (eq result 'pseudo)
2917 (eq result 'nneething))
2920 (set-buffer summary-buffer)
2921 (push article gnus-newsgroup-history)
2922 (setq gnus-last-article gnus-current-article
2923 gnus-current-article 0
2924 gnus-current-headers nil
2925 gnus-article-current nil)
2926 (if (eq result 'nneething)
2927 (gnus-configure-windows 'summary)
2928 (gnus-configure-windows 'article))
2929 (gnus-set-global-variables))
2930 (let ((gnus-article-mime-handle-alist-1
2931 gnus-article-mime-handle-alist))
2932 (gnus-set-mode-line 'article)))
2933 ;; The result from the `request' was an actual article -
2934 ;; or at least some text that is now displayed in the
2936 (when (and (numberp article)
2937 (not (eq article gnus-current-article)))
2938 ;; Seems like a new article has been selected.
2939 ;; `gnus-current-article' must be an article number.
2941 (set-buffer summary-buffer)
2942 (push article gnus-newsgroup-history)
2943 (setq gnus-last-article gnus-current-article
2944 gnus-current-article article
2945 gnus-current-headers
2946 (gnus-summary-article-header gnus-current-article)
2947 gnus-article-current
2948 (cons gnus-newsgroup-name gnus-current-article))
2949 (unless (vectorp gnus-current-headers)
2950 (setq gnus-current-headers nil))
2951 (gnus-summary-goto-subject gnus-current-article)
2952 (when (gnus-summary-show-thread)
2953 ;; If the summary buffer really was folded, the
2954 ;; previous goto may not actually have gone to
2955 ;; the right article, but the thread root instead.
2957 (gnus-summary-goto-subject gnus-current-article))
2958 (gnus-run-hooks 'gnus-mark-article-hook)
2959 (gnus-set-mode-line 'summary)
2960 (when (gnus-visual-p 'article-highlight 'highlight)
2961 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2962 ;; Set the global newsgroup variables here.
2963 (gnus-set-global-variables)
2964 (setq gnus-have-all-headers
2965 (or all-headers gnus-show-all-headers))))
2966 (when (or (numberp article)
2968 (gnus-article-prepare-display)
2970 (goto-char (point-min))
2971 (setq gnus-page-broken
2972 (when gnus-break-pages
2973 (gnus-narrow-to-page)
2975 (let ((gnus-article-mime-handle-alist-1
2976 gnus-article-mime-handle-alist))
2977 (gnus-set-mode-line 'article))
2979 (set-window-point (get-buffer-window (current-buffer)) (point))
2980 (gnus-configure-windows 'article)
2983 (defun gnus-article-prepare-mime-display (&optional number)
2984 (goto-char (point-min))
2985 (when (re-search-forward "^[^\t ]+:" nil t)
2986 (goto-char (match-beginning 0)))
2987 (let ((entity (if (eq 1 (point-min))
2988 (get-text-property 1 'mime-view-entity)
2989 (get-text-property (point) 'mime-view-entity)))
2990 last-entity child-entity next type)
2991 (setq child-entity (mime-entity-children entity))
2993 (setq last-entity (nth (1- (length child-entity))
2995 (setq last-entity entity))
2997 (narrow-to-region (point)
2998 (if (search-forward "\n\n" nil t)
3001 (gnus-treat-article 'head)
3002 (put-text-property (point-min) (point-max) 'article-treated-header t)
3003 (goto-char (point-max)))
3004 (while (and (not (eobp))
3009 (or (next-single-property-change (point)
3012 (let ((types (mime-entity-content-type entity)))
3013 (while (eq 'multipart (mime-content-type-primary-type types))
3014 (setq entity (car (mime-entity-children entity))
3015 types (mime-entity-content-type entity)))
3017 (setq type (format "%s/%s"
3018 (mime-content-type-primary-type types)
3019 (mime-content-type-subtype types)))))
3020 (if (string-equal type "message/rfc822")
3023 (let ((children (mime-entity-children entity))
3026 (setq last-children (nth (1- (length children)) children))
3029 (not (eq last-children
3030 (get-text-property next 'mime-view-entity)))
3032 (next-single-property-change next
3033 'mime-view-entity))))))
3034 (setq next (or (next-single-property-change next 'mime-view-entity)
3037 (narrow-to-region (point) next)
3038 (gnus-article-prepare-mime-display)
3039 (goto-char (point-max)))
3040 (setq entity (get-text-property (point) 'mime-view-entity)))
3042 (narrow-to-region (point) next)
3043 ;; Kludge. We have to count true number, but for now,
3044 ;; part number is here only to achieve `last'.
3045 (gnus-treat-article nil 1
3046 (if (eq entity last-entity)
3049 (setq entity (get-text-property next 'mime-view-entity))
3050 (goto-char (point-max)))))))
3053 (defun gnus-article-prepare-display ()
3054 "Make the current buffer look like a nice article."
3055 (setq gnus-article-wash-types nil)
3056 (gnus-run-hooks 'gnus-tmp-internal-hook)
3057 (gnus-run-hooks 'gnus-article-prepare-hook)
3059 (let (mime-display-header-hook mime-display-text/plain-hook)
3060 (funcall (if gnus-show-mime
3062 (setq mime-message-structure gnus-current-headers)
3063 (mime-buffer-entity-set-buffer-internal
3064 mime-message-structure
3065 gnus-original-article-buffer)
3066 (mime-entity-set-representation-type-internal
3067 mime-message-structure 'mime-buffer-entity)
3068 (luna-send mime-message-structure
3069 'initialize-instance
3070 mime-message-structure)
3071 gnus-article-display-method-for-mime)
3072 gnus-article-display-method-for-traditional)))
3073 ;; Associate this article with the current summary buffer.
3074 (setq gnus-article-current-summary gnus-summary-buffer)
3075 ;; Call the treatment functions.
3076 (let ((inhibit-read-only t)
3081 (gnus-article-prepare-mime-display)
3082 (narrow-to-region (goto-char (point-min))
3083 (if (search-forward "\n\n" nil t)
3086 (gnus-treat-article 'head)
3087 (put-text-property (point-min) (point-max) 'article-treated-header t)
3088 (goto-char (point-max))
3090 (narrow-to-region (point) (point-max))
3091 (gnus-treat-article nil))
3092 (put-text-property (point-min) (point-max) 'read-only nil)))
3093 ;; Perform the article display hooks. Incidentally, this hook is
3094 ;; an obsolete variable by now.
3095 (gnus-run-hooks 'gnus-article-display-hook))
3097 (defun gnus-article-decode-article-as-default-mime-charset ()
3098 "Decode an article as `default-mime-charset'. It won't work if the
3099 value of the variable `gnus-show-mime' is non-nil."
3100 (unless gnus-show-mime
3101 (decode-mime-charset-region (point-min) (point-max)
3102 (with-current-buffer gnus-summary-buffer
3103 default-mime-charset))))
3106 ;;; Gnus MIME viewing functions
3109 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3110 "The following specs can be used:
3112 %T MIME type, along with additional info
3113 %n The `name' parameter
3114 %d The description, if any
3115 %l The length of the encoded part
3116 %p The part identifier number
3117 %e Dots if the part isn't displayed")
3119 (defvar gnus-mime-button-line-format-alist
3120 '((?t gnus-tmp-type ?s)
3121 (?T gnus-tmp-type-long ?s)
3122 (?n gnus-tmp-name ?s)
3123 (?d gnus-tmp-description ?s)
3125 (?l gnus-tmp-length ?d)
3126 (?e gnus-tmp-dots ?s)))
3128 (defvar gnus-mime-button-commands
3129 '((gnus-article-press-button "\r" "Toggle Display")
3130 (gnus-mime-view-part "v" "View Interactively...")
3131 (gnus-mime-view-part-as-type "t" "View As Type...")
3132 (gnus-mime-save-part "o" "Save...")
3133 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3134 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3135 (gnus-mime-internalize-part "E" "View Internally")
3136 (gnus-mime-externalize-part "e" "View Externally")
3137 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3139 (defun gnus-article-mime-part-status ()
3140 (with-current-buffer gnus-article-buffer
3141 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3142 (if (and entity (mime-entity-children entity))
3143 (format " (%d parts)" (length (mime-entity-children entity)))
3146 (defvar gnus-mime-button-map nil)
3147 (unless gnus-mime-button-map
3148 (setq gnus-mime-button-map (make-sparse-keymap))
3149 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3150 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3151 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3153 (define-key gnus-mime-button-map (cadr c) (car c)))
3154 gnus-mime-button-commands))
3156 (defun gnus-mime-button-menu (event)
3157 "Construct a context-sensitive menu of MIME commands."
3160 (let ((pos (event-start event)))
3161 (set-buffer (window-buffer (posn-window pos)))
3162 (goto-char (posn-point pos))
3163 (gnus-article-check-buffer)
3164 (let ((response (x-popup-menu
3166 ("" ,@(mapcar (lambda (c)
3167 (cons (caddr c) (car c)))
3168 gnus-mime-button-commands))))))
3170 (funcall response))))))
3172 (defun gnus-mime-view-all-parts (&optional handles)
3173 "View all the MIME parts."
3175 (save-current-buffer
3176 (set-buffer gnus-article-buffer)
3177 (let ((handles (or handles gnus-article-mime-handles))
3178 (mail-parse-charset gnus-newsgroup-charset)
3179 (mail-parse-ignored-charsets
3180 (save-excursion (set-buffer gnus-summary-buffer)
3181 gnus-newsgroup-ignored-charsets)))
3182 (if (stringp (car handles))
3183 (gnus-mime-view-all-parts (cdr handles))
3184 (mapcar 'mm-display-part handles)))))
3186 (defun gnus-mime-save-part ()
3187 "Save the MIME part under point."
3189 (gnus-article-check-buffer)
3190 (let ((data (get-text-property (point) 'gnus-data)))
3191 (mm-save-part data)))
3193 (defun gnus-mime-pipe-part ()
3194 "Pipe the MIME part under point to a process."
3196 (gnus-article-check-buffer)
3197 (let ((data (get-text-property (point) 'gnus-data)))
3198 (mm-pipe-part data)))
3200 (defun gnus-mime-view-part ()
3201 "Interactively choose a viewing method for the MIME part under point."
3203 (gnus-article-check-buffer)
3204 (let ((data (get-text-property (point) 'gnus-data)))
3205 (mm-interactively-view-part data)))
3207 (defun gnus-mime-view-part-as-type ()
3208 "Choose a MIME media type, and view the part as such."
3210 (list (completing-read "View as MIME type: " mailcap-mime-types)))
3211 (gnus-article-check-buffer)
3212 (let ((handle (get-text-property (point) 'gnus-data)))
3213 (gnus-mm-display-part handle)))
3215 (defun gnus-mime-copy-part (&optional handle)
3216 "Put the the MIME part under point into a new buffer."
3218 (gnus-article-check-buffer)
3219 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3220 (contents (mm-get-part handle))|
3221 (base (file-name-nondirectory
3223 (mail-content-type-get (mm-handle-type handle) 'name)
3224 (mail-content-type-get (mm-handle-type handle)
3227 (buffer (generate-new-buffer base)))
3228 (switch-to-buffer buffer)
3230 ;; We do it this way to make `normal-mode' set the appropriate mode.
3233 (setq buffer-file-name (expand-file-name base))
3235 (setq buffer-file-name nil))
3236 (goto-char (point-min))))
3238 (defun gnus-mime-inline-part (&optional handle)
3239 "Insert the MIME part under point into the current buffer."
3241 (gnus-article-check-buffer)
3242 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3246 (if (mm-handle-undisplayer handle)
3247 (mm-remove-part handle)
3248 (setq contents (mm-get-part handle))
3250 (mm-insert-inline handle contents)
3253 (defun gnus-mime-externalize-part (&optional handle)
3254 "View the MIME part under point with an external viewer."
3256 (gnus-article-check-buffer)
3257 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3258 (mm-user-display-methods nil)
3259 (mm-inline-large-images nil)
3260 (mail-parse-charset gnus-newsgroup-charset)
3261 (mail-parse-ignored-charsets
3262 (save-excursion (set-buffer gnus-summary-buffer)
3263 gnus-newsgroup-ignored-charsets)))
3264 (if (mm-handle-undisplayer handle)
3265 (mm-remove-part handle)
3266 (mm-display-part handle))))
3268 (defun gnus-mime-internalize-part (&optional handle)
3269 "View the MIME part under point with an internal viewer."
3271 (gnus-article-check-buffer)
3272 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3273 (mm-user-display-methods '((".*" . inline)))
3274 (mm-inline-large-images t)
3275 (mail-parse-charset gnus-newsgroup-charset)
3276 (mail-parse-ignored-charsets
3277 (save-excursion (set-buffer gnus-summary-buffer)
3278 gnus-newsgroup-ignored-charsets)))
3279 (if (mm-handle-undisplayer handle)
3280 (mm-remove-part handle)
3281 (mm-display-part handle))))
3283 (defun gnus-article-part-wrapper (n function)
3284 (save-current-buffer
3285 (set-buffer gnus-article-buffer)
3286 (when (> n (length gnus-article-mime-handle-alist))
3287 (error "No such part"))
3288 (gnus-article-goto-part n)
3289 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3290 (funcall function handle))))
3292 (defun gnus-article-pipe-part (n)
3293 "Pipe MIME part N, which is the numerical prefix."
3295 (gnus-article-part-wrapper n 'mm-pipe-part))
3297 (defun gnus-article-save-part (n)
3298 "Save MIME part N, which is the numerical prefix."
3300 (gnus-article-part-wrapper n 'mm-save-part))
3302 (defun gnus-article-interactively-view-part (n)
3303 "View MIME part N interactively, which is the numerical prefix."
3305 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3307 (defun gnus-article-copy-part (n)
3308 "Copy MIME part N, which is the numerical prefix."
3310 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3312 (defun gnus-article-externalize-part (n)
3313 "View MIME part N externally, which is the numerical prefix."
3315 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3317 (defun gnus-article-inline-part (n)
3318 "Inline MIME part N, which is the numerical prefix."
3320 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3322 (defun gnus-article-mime-match-handle-first (condition)
3324 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3325 (while (setq ihandle (pop alist))
3327 ((functionp condition)
3328 (funcall condition (cdr ihandle)))
3329 ((eq condition 'undisplayed)
3330 (not (or (mm-handle-undisplayer (cdr ihandle))
3331 (equal (mm-handle-media-type (cdr ihandle))
3332 "multipart/alternative"))))
3333 ((eq condition 'undisplayed-alternative)
3334 (not (mm-handle-undisplayer (cdr ihandle))))
3336 (gnus-article-goto-part (car ihandle))
3337 (or (not n) (< (car ihandle) n)))
3338 (setq n (car ihandle))))
3342 (defun gnus-article-view-part (&optional n)
3343 "View MIME part N, which is the numerical prefix."
3345 (save-current-buffer
3346 (set-buffer gnus-article-buffer)
3347 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3348 gnus-article-mime-match-handle-function)))
3349 (when (> n (length gnus-article-mime-handle-alist))
3350 (error "No such part"))
3351 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3352 (when (gnus-article-goto-part n)
3353 (if (equal (car handle) "multipart/alternative")
3354 (gnus-article-press-button)
3355 (when (eq (gnus-mm-display-part handle) 'internal)
3356 (gnus-set-window-start)))))))
3358 (defun gnus-mm-display-part (handle)
3359 "Display HANDLE and fix MIME button."
3360 (let ((id (get-text-property (point) 'gnus-part))
3365 (let ((window (selected-window))
3366 (mail-parse-charset gnus-newsgroup-charset)
3367 (mail-parse-ignored-charsets
3368 (save-excursion (set-buffer gnus-summary-buffer)
3369 gnus-newsgroup-ignored-charsets)))
3372 (let ((win (get-buffer-window (current-buffer) t))
3375 (select-window win))
3378 (if (mm-handle-displayed-p handle)
3379 ;; This will remove the part.
3380 (mm-display-part handle)
3382 (narrow-to-region (point) (1+ (point)))
3383 (mm-display-part handle)
3384 ;; We narrow to the part itself and
3385 ;; then call the treatment functions.
3386 (goto-char (point-min))
3388 (narrow-to-region (point) (point-max))
3391 (1- (length gnus-article-mime-handles))
3392 (mm-handle-media-type handle)))))
3393 (select-window window))))
3395 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3396 (gnus-insert-mime-button
3397 handle id (list (mm-handle-displayed-p handle)))
3398 (goto-char point))))
3400 (defun gnus-article-goto-part (n)
3401 "Go to MIME part N."
3402 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3404 (goto-char point))))
3406 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3407 (let ((gnus-tmp-name
3408 (or (mail-content-type-get (mm-handle-type handle)
3410 (mail-content-type-get (mm-handle-disposition handle)
3413 (gnus-tmp-type (mm-handle-media-type handle))
3414 (gnus-tmp-description
3415 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3418 (if (if displayed (car displayed)
3419 (mm-handle-displayed-p handle))
3421 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3423 gnus-tmp-type-long b e)
3424 (when (string-match ".*/" gnus-tmp-name)
3425 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3426 (setq gnus-tmp-type-long (concat gnus-tmp-type
3427 (and (not (equal gnus-tmp-name ""))
3428 (concat "; " gnus-tmp-name))))
3429 (or (equal gnus-tmp-description "")
3430 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3435 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3436 `(local-map ,gnus-mime-button-map
3437 keymap ,gnus-mime-button-map
3438 gnus-callback gnus-mm-display-part
3439 gnus-part ,gnus-tmp-id
3440 article-type annotation
3443 (widget-convert-button 'link b e
3445 :action 'gnus-widget-press-button
3446 :button-keymap gnus-mime-button-map
3449 ;; Needed to properly clear the message
3450 ;; due to a bug in wid-edit
3451 (setq help-echo-owns-message t)
3453 "Click to %s the MIME part; %s for more options"
3454 (if (mm-handle-displayed-p
3455 (widget-get widget :mime-handle))
3457 (if gnus-xemacs "button3" "mouse-3"))))))
3459 (defun gnus-widget-press-button (elems el)
3460 (goto-char (widget-get elems :from))
3461 (gnus-article-press-button))
3463 (defvar gnus-displaying-mime nil)
3465 (defun gnus-display-mime (&optional ihandles)
3466 "Display the MIME parts."
3468 (save-selected-window
3469 (let ((window (get-buffer-window gnus-article-buffer))
3472 (select-window window)
3473 ;; We have to do this since selecting the window
3474 ;; may change the point. So we set the window point.
3475 (set-window-point window point)))
3476 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3477 buffer-read-only handle name type b e display)
3478 (when (and (not ihandles)
3479 (not gnus-displaying-mime))
3480 ;; Top-level call; we clean up.
3481 (when gnus-article-mime-handles
3482 (mm-destroy-parts gnus-article-mime-handles)
3483 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3484 (setq gnus-article-mime-handles handles)
3485 ;; We allow users to glean info from the handles.
3486 (when gnus-article-mime-part-function
3487 (gnus-mime-part-function handles)))
3489 (or (not (stringp (car handles)))
3492 (when (and (not ihandles)
3493 (not gnus-displaying-mime))
3494 ;; Clean up for mime parts.
3496 (delete-region (point) (point-max)))
3497 (let ((gnus-displaying-mime t))
3498 (gnus-mime-display-part handles)))
3501 (narrow-to-region (point) (point-max))
3502 (gnus-treat-article nil 1 1)
3505 ;; Highlight the headers.
3509 (narrow-to-region (point-min) (point))
3510 (gnus-treat-article 'head))))))))
3512 (defvar gnus-mime-display-multipart-as-mixed nil)
3514 (defun gnus-mime-display-part (handle)
3517 ((not (stringp (car handle)))
3518 (gnus-mime-display-single handle))
3519 ;; User-defined multipart
3520 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3521 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3523 ;; multipart/alternative
3524 ((and (equal (car handle) "multipart/alternative")
3525 (not gnus-mime-display-multipart-as-mixed))
3526 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3527 (push (cons id handle) gnus-article-mime-handle-alist)
3528 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3529 ;; multipart/related
3530 ((and (equal (car handle) "multipart/related")
3531 (not gnus-mime-display-multipart-as-mixed))
3532 ;;;!!!We should find the start part, but we just default
3533 ;;;!!!to the first part.
3534 (gnus-mime-display-part (cadr handle)))
3535 ;; Other multiparts are handled like multipart/mixed.
3537 (gnus-mime-display-mixed (cdr handle)))))
3539 (defun gnus-mime-part-function (handles)
3540 (if (stringp (car handles))
3541 (mapcar 'gnus-mime-part-function (cdr handles))
3542 (funcall gnus-article-mime-part-function handles)))
3544 (defun gnus-mime-display-mixed (handles)
3545 (mapcar 'gnus-mime-display-part handles))
3547 (defun gnus-mime-display-single (handle)
3548 (let ((type (mm-handle-media-type handle))
3549 (ignored gnus-ignored-mime-types)
3556 (when (string-match (pop ignored) type)
3557 (throw 'ignored nil)))
3558 (if (and (setq not-attachment
3559 (or (not (mm-handle-disposition handle))
3560 (equal (car (mm-handle-disposition handle))
3562 (mm-attachment-override-p handle)))
3563 (mm-automatic-display-p handle)
3564 (or (mm-inlined-p handle)
3565 (mm-automatic-external-display-p type)))
3567 (when (equal (mm-handle-media-supertype handle) "text")
3569 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3570 (push (cons id handle) gnus-article-mime-handle-alist)
3571 (when (or (not display)
3572 (not (gnus-unbuttonized-mime-type-p type)))
3573 (gnus-article-insert-newline)
3574 (gnus-insert-mime-button
3575 handle id (list (or display (and not-attachment text))))
3576 (gnus-article-insert-newline)
3577 (gnus-article-insert-newline)
3579 (let ((beg (point)))
3585 (let ((mail-parse-charset gnus-newsgroup-charset)
3586 (mail-parse-ignored-charsets
3587 (save-excursion (set-buffer gnus-summary-buffer)
3588 gnus-newsgroup-ignored-charsets)))
3589 (mm-display-part handle t))
3590 (goto-char (point-max)))
3591 ((and text not-attachment)
3595 (gnus-article-insert-newline)
3596 (mm-insert-inline handle (mm-get-part handle))
3597 (goto-char (point-max))))
3601 (narrow-to-region beg (point))
3603 nil (length gnus-article-mime-handle-alist)
3604 (1- (length gnus-article-mime-handles))
3605 (mm-handle-media-type handle)))))))))
3607 (defun gnus-unbuttonized-mime-type-p (type)
3608 "Say whether TYPE is to be unbuttonized."
3609 (unless gnus-inhibit-mime-unbuttonizing
3611 (let ((types gnus-unbuttonized-mime-types))
3613 (when (string-match (pop types) type)
3614 (throw 'found t)))))))
3616 (defun gnus-article-insert-newline ()
3617 "Insert a newline, but mark it as undeletable."
3618 (gnus-put-text-property
3619 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3621 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3622 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3625 handle buffer-read-only from props begend not-pref)
3626 (save-window-excursion
3629 (narrow-to-region (car ibegend)
3632 (goto-char (car ibegend))
3635 (delete-region (point-min) (point-max))
3636 (mm-remove-parts handles))
3637 (setq begend (list (point-marker)))
3639 (unless (setq not-pref (cadr (member preferred ihandles)))
3640 (setq not-pref (car ihandles)))
3642 (not (gnus-unbuttonized-mime-type-p
3643 "multipart/alternative")))
3644 (gnus-add-text-properties
3647 (insert (format "%d. " id))
3651 (unless ,(not ibegend)
3652 (setq gnus-article-mime-handle-alist
3653 ',gnus-article-mime-handle-alist))
3654 (gnus-mime-display-alternative
3655 ',ihandles ',not-pref ',begend ,id))
3656 local-map ,gnus-mime-button-map
3657 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3658 face ,gnus-article-button-face
3659 keymap ,gnus-mime-button-map
3662 (widget-convert-button 'link from (point)
3663 :action 'gnus-widget-press-button
3664 :button-keymap gnus-widget-button-keymap)
3666 (while (setq handle (pop handles))
3667 (gnus-add-text-properties
3670 (insert (format "(%c) %-18s"
3671 (if (equal handle preferred) ?* ? )
3672 (mm-handle-media-type handle)))
3676 (unless ,(not ibegend)
3677 (setq gnus-article-mime-handle-alist
3678 ',gnus-article-mime-handle-alist))
3679 (gnus-mime-display-alternative
3680 ',ihandles ',handle ',begend ,id))
3681 local-map ,gnus-mime-button-map
3682 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3683 face ,gnus-article-button-face
3684 keymap ,gnus-mime-button-map
3687 (widget-convert-button 'link from (point)
3688 :action 'gnus-widget-press-button
3689 :button-keymap gnus-widget-button-keymap)
3693 (if (stringp (car preferred))
3694 (gnus-display-mime preferred)
3695 (let ((mail-parse-charset gnus-newsgroup-charset)
3696 (mail-parse-ignored-charsets
3697 (save-excursion (set-buffer gnus-summary-buffer)
3698 gnus-newsgroup-ignored-charsets)))
3699 (mm-display-part preferred)
3703 (narrow-to-region (car begend) (point-max))
3705 nil (length gnus-article-mime-handle-alist)
3706 (1- (length gnus-article-mime-handles))
3707 (mm-handle-media-type handle))))))
3708 (goto-char (point-max))
3709 (setcdr begend (point-marker)))))
3711 (goto-char point))))
3713 (defun gnus-article-wash-status ()
3714 "Return a string which display status of article washing."
3716 (set-buffer gnus-article-buffer)
3717 (let ((cite (gnus-article-hidden-text-p 'cite))
3718 (headers (gnus-article-hidden-text-p 'headers))
3719 (boring (gnus-article-hidden-text-p 'boring-headers))
3720 (pgp (gnus-article-hidden-text-p 'pgp))
3721 (pem (gnus-article-hidden-text-p 'pem))
3722 (signature (gnus-article-hidden-text-p 'signature))
3723 (overstrike (gnus-article-hidden-text-p 'overstrike))
3724 (emphasis (gnus-article-hidden-text-p 'emphasis))
3725 (mime gnus-show-mime))
3726 (format "%c%c%c%c%c%c%c"
3728 (if (or headers boring) ?h ? )
3729 (if (or pgp pem) ?p ? )
3730 (if signature ?s ? )
3731 (if overstrike ?o ? )
3733 (if emphasis ?e ? )))))
3735 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3737 (defun gnus-article-maybe-hide-headers ()
3738 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3739 Provided for backwards compatibility."
3740 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3741 (not (save-excursion (set-buffer gnus-summary-buffer)
3742 gnus-have-all-headers)))
3743 (not gnus-inhibit-hiding))
3744 (gnus-article-hide-headers)))
3748 (defun gnus-output-to-file (file-name)
3749 "Append the current article to a file named FILE-NAME."
3750 (let ((artbuf (current-buffer)))
3752 (insert-buffer-substring artbuf)
3753 ;; Append newline at end of the buffer as separator, and then
3755 (goto-char (point-max))
3757 (write-region-as-binary (point-min) (point-max) file-name 'append)
3760 (defun gnus-narrow-to-page (&optional arg)
3761 "Narrow the article buffer to a page.
3762 If given a numerical ARG, move forward ARG pages."
3764 (setq arg (if arg (prefix-numeric-value arg) 0))
3766 (set-buffer gnus-article-buffer)
3767 (goto-char (point-min))
3769 ;; Remove any old next/prev buttons.
3770 (when (gnus-visual-p 'page-marker)
3771 (let ((buffer-read-only nil))
3772 (gnus-remove-text-with-property 'gnus-prev)
3773 (gnus-remove-text-with-property 'gnus-next)))
3776 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3778 (re-search-forward page-delimiter nil 'move arg)))
3779 (goto-char (match-end 0)))
3782 (if (re-search-forward page-delimiter nil 'move)
3785 (when (and (gnus-visual-p 'page-marker)
3786 (not (= (point-min) 1)))
3788 (goto-char (point-min))
3789 (gnus-insert-prev-page-button)))
3790 (when (and (gnus-visual-p 'page-marker)
3791 (< (+ (point-max) 2) (buffer-size)))
3793 (goto-char (point-max))
3794 (gnus-insert-next-page-button)))))
3796 ;; Article mode commands
3798 (defun gnus-article-goto-next-page ()
3799 "Show the next page of the article."
3801 (when (gnus-article-next-page)
3802 (goto-char (point-min))
3803 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3805 (defun gnus-article-goto-prev-page ()
3806 "Show the next page of the article."
3808 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3809 (gnus-article-prev-page nil)))
3811 (defun gnus-article-next-page (&optional lines)
3812 "Show the next page of the current article.
3813 If end of article, return non-nil. Otherwise return nil.
3814 Argument LINES specifies lines to be scrolled up."
3816 (let ((start (window-start))
3817 end-of-buffer end-of-page)
3819 (move-to-window-line -1)
3820 (if (<= (point) start)
3823 (setq start (point)))
3826 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3827 (setq end-of-buffer t))
3829 (setq end-of-page t)))
3831 (move-to-window-line lines)
3832 (unless (search-backward "\n\n" nil t)
3833 (setq start (point)))))
3834 (cond (end-of-buffer t)
3836 (gnus-narrow-to-page 1)
3840 (set-window-start (selected-window) start)
3844 (defun gnus-article-prev-page (&optional lines)
3845 "Show previous page of current article.
3846 Argument LINES specifies lines to be scrolled down."
3848 (let (beginning-of-buffer beginning-of-page)
3850 (move-to-window-line 0)
3851 (cond ((eq 1 (point))
3852 (setq beginning-of-buffer t))
3854 (setq beginning-of-page t))))
3855 (cond (beginning-of-buffer)
3857 (gnus-narrow-to-page -1))
3861 (beginning-of-buffer
3862 (goto-char (point-min))))))))
3864 (defun gnus-article-refer-article ()
3865 "Read article specified by message-id around point."
3867 (let ((point (point)))
3868 (search-forward ">" nil t) ;Move point to end of "<....>".
3869 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3870 (let ((message-id (match-string 1)))
3872 (set-buffer gnus-summary-buffer)
3873 (gnus-summary-refer-article message-id))
3875 (error "No references around point"))))
3877 (defun gnus-article-show-summary ()
3878 "Reconfigure windows to show summary buffer."
3880 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3881 (error "There is no summary buffer for this article buffer")
3882 (gnus-article-set-globals)
3883 (gnus-configure-windows 'article)
3884 (gnus-summary-goto-subject gnus-current-article)
3885 (gnus-summary-position-point)))
3887 (defun gnus-article-describe-briefly ()
3888 "Describe article mode commands briefly."
3890 (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")))
3892 (defun gnus-article-summary-command ()
3893 "Execute the last keystroke in the summary buffer."
3895 (let ((obuf (current-buffer))
3896 (owin (current-window-configuration))
3898 (switch-to-buffer gnus-article-current-summary 'norecord)
3899 (setq func (lookup-key (current-local-map) (this-command-keys)))
3900 (call-interactively func)
3902 (set-window-configuration owin)
3903 (set-window-point (get-buffer-window (current-buffer)) (point))))
3905 (defun gnus-article-summary-command-nosave ()
3906 "Execute the last keystroke in the summary buffer."
3909 (pop-to-buffer gnus-article-current-summary 'norecord)
3910 (setq func (lookup-key (current-local-map) (this-command-keys)))
3911 (call-interactively func)))
3913 (defun gnus-article-check-buffer ()
3914 "Beep if not in an article buffer."
3915 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3916 (error "Command invoked outside of a Gnus article buffer")))
3918 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3919 "Read a summary buffer key sequence and execute it from the article buffer."
3921 (gnus-article-check-buffer)
3923 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3924 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3925 "=" "^" "\M-^" "|"))
3931 '("n" "Gn" "p" "Gp"))
3934 (set-buffer gnus-article-current-summary)
3935 (let (gnus-pick-mode)
3936 (push (or key last-command-event) unread-command-events)
3937 (setq keys (static-if (featurep 'xemacs)
3938 (events-to-keys (read-key-sequence nil))
3939 (read-key-sequence nil)))))
3942 (if (or (member keys nosaves)
3943 (member keys nosave-but-article)
3944 (member keys nosave-in-article))
3946 (save-window-excursion
3947 (pop-to-buffer gnus-article-current-summary 'norecord)
3948 ;; We disable the pick minor mode commands.
3949 (let (gnus-pick-mode)
3950 (setq func (lookup-key (current-local-map) keys))))
3953 (unless (member keys nosave-in-article)
3954 (set-buffer gnus-article-current-summary))
3955 (call-interactively func)
3956 (setq new-sum-point (point)))
3957 (when (member keys nosave-but-article)
3958 (pop-to-buffer gnus-article-buffer 'norecord)))
3959 ;; These commands should restore window configuration.
3960 (let ((obuf (current-buffer))
3961 (owin (current-window-configuration))
3963 (summary gnus-article-current-summary)
3964 func in-buffer selected)
3965 (if not-restore-window
3966 (pop-to-buffer summary 'norecord)
3967 (switch-to-buffer summary 'norecord))
3968 (setq in-buffer (current-buffer))
3969 ;; We disable the pick minor mode commands.
3970 (if (setq func (let (gnus-pick-mode)
3971 (lookup-key (current-local-map) keys)))
3973 (call-interactively func)
3974 (setq new-sum-point (point)))
3976 (when (eq in-buffer (current-buffer))
3977 (setq selected (gnus-summary-select-article))
3979 (unless not-restore-window
3980 (set-window-configuration owin))
3981 (when (eq selected 'old)
3983 (set-window-start (get-buffer-window (current-buffer))
3985 (set-window-point (get-buffer-window (current-buffer))
3987 (let ((win (get-buffer-window gnus-article-current-summary)))
3989 (set-window-point win new-sum-point))))))))
3991 (defun gnus-article-hide (&optional arg force)
3992 "Hide all the gruft in the current article.
3993 This means that PGP stuff, signatures, cited text and (some)
3994 headers will be hidden.
3995 If given a prefix, show the hidden text instead."
3996 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3997 (gnus-article-hide-headers arg)
3998 (gnus-article-hide-list-identifiers arg)
3999 (gnus-article-hide-pgp arg)
4000 (gnus-article-hide-citation-maybe arg force)
4001 (gnus-article-hide-signature arg))
4003 (defun gnus-article-maybe-highlight ()
4004 "Do some article highlighting if article highlighting is requested."
4005 (when (gnus-visual-p 'article-highlight 'highlight)
4006 (gnus-article-highlight-some)))
4008 (defun gnus-check-group-server ()
4009 ;; Make sure the connection to the server is alive.
4010 (unless (gnus-server-opened
4011 (gnus-find-method-for-group gnus-newsgroup-name))
4012 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4013 (gnus-request-group gnus-newsgroup-name t)))
4015 (defun gnus-request-article-this-buffer (article group)
4016 "Get an article and insert it into this buffer."
4017 (let (do-update-line sparse-header)
4021 (gnus-kill-all-overlays)
4022 (setq group (or group gnus-newsgroup-name))
4024 ;; Using `gnus-request-article' directly will insert the article into
4025 ;; `nntp-server-buffer' - so we'll save some time by not having to
4026 ;; copy it from the server buffer into the article buffer.
4028 ;; We only request an article by message-id when we do not have the
4029 ;; headers for it, so we'll have to get those.
4030 (when (stringp article)
4031 (let ((gnus-override-method gnus-refer-article-method))
4032 (gnus-read-header article)))
4034 ;; If the article number is negative, that means that this article
4035 ;; doesn't belong in this newsgroup (possibly), so we find its
4036 ;; message-id and request it by id instead of number.
4037 (when (and (numberp article)
4039 (get-buffer gnus-summary-buffer)
4040 (gnus-buffer-exists-p gnus-summary-buffer))
4042 (set-buffer gnus-summary-buffer)
4043 (let ((header (gnus-summary-article-header article)))
4046 ((memq article gnus-newsgroup-sparse)
4047 ;; This is a sparse gap article.
4048 (setq do-update-line article)
4049 (setq article (mail-header-id header))
4050 (let ((gnus-override-method gnus-refer-article-method))
4051 (setq sparse-header (gnus-read-header article)))
4052 (setq gnus-newsgroup-sparse
4053 (delq article gnus-newsgroup-sparse)))
4055 ;; It's a real article.
4056 (setq article (mail-header-id header)))
4058 ;; It is an extracted pseudo-article.
4059 (setq article 'pseudo)
4060 (gnus-request-pseudo-article header))))
4062 (let ((method (gnus-find-method-for-group
4063 gnus-newsgroup-name)))
4064 (when (and (eq (car method) 'nneething)
4067 (file-name-as-directory
4068 (or (cadr (assq 'nneething-address method))
4070 (mail-header-subject header))))
4071 (when (file-directory-p dir)
4072 (setq article 'nneething)
4073 (gnus-group-enter-directory dir))))))))
4076 ;; Refuse to select canceled articles.
4077 ((and (numberp article)
4079 (get-buffer gnus-summary-buffer)
4080 (gnus-buffer-exists-p gnus-summary-buffer)
4081 (eq (cdr (save-excursion
4082 (set-buffer gnus-summary-buffer)
4083 (assq article gnus-newsgroup-reads)))
4084 gnus-canceled-mark))
4086 ;; Check the backlog.
4087 ((and gnus-keep-backlog
4088 (gnus-backlog-request-article group article (current-buffer)))
4090 ;; Check asynchronous pre-fetch.
4091 ((gnus-async-request-fetched-article group article (current-buffer))
4092 (gnus-async-prefetch-next group article gnus-summary-buffer)
4093 (when (and (numberp article) gnus-keep-backlog)
4094 (gnus-backlog-enter-article group article (current-buffer)))
4097 ((and gnus-use-cache
4099 (gnus-cache-request-article article group))
4101 ;; Get the article and put into the article buffer.
4102 ((or (stringp article) (numberp article))
4103 (let ((gnus-override-method
4104 (and (stringp article) gnus-refer-article-method))
4105 (buffer-read-only nil))
4107 (gnus-kill-all-overlays)
4108 (gnus-check-group-server)
4109 (when (gnus-request-article article group (current-buffer))
4110 (when (numberp article)
4111 (gnus-async-prefetch-next group article gnus-summary-buffer)
4112 (when gnus-keep-backlog
4113 (gnus-backlog-enter-article
4114 group article (current-buffer))))
4119 ;; Associate this article with the current summary buffer.
4120 (setq gnus-article-current-summary gnus-summary-buffer)
4122 ;; Take the article from the original article buffer
4123 ;; and place it in the buffer it's supposed to be in.
4124 (when (and (get-buffer gnus-article-buffer)
4125 (equal (buffer-name (current-buffer))
4126 (buffer-name (get-buffer gnus-article-buffer))))
4128 (if (get-buffer gnus-original-article-buffer)
4129 (set-buffer gnus-original-article-buffer)
4130 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4131 (buffer-disable-undo)
4132 (setq major-mode 'gnus-original-article-mode)
4133 (setq buffer-read-only t))
4134 (let (buffer-read-only)
4136 (insert-buffer-substring gnus-article-buffer))
4137 (setq gnus-original-article (cons group article)))
4140 (run-hooks 'gnus-article-decode-hook)
4141 ;; Mark article as decoded or not.
4142 (setq gnus-article-decoded-p gnus-article-decode-hook))
4144 ;; Update sparse articles.
4145 (when (and do-update-line
4146 (or (numberp article)
4148 (let ((buf (current-buffer)))
4149 (set-buffer gnus-summary-buffer)
4150 (gnus-summary-update-article do-update-line sparse-header)
4151 (gnus-summary-goto-subject do-update-line nil t)
4152 (set-window-point (get-buffer-window (current-buffer) t)
4154 (set-buffer buf))))))
4160 (defcustom gnus-article-edit-mode-hook nil
4161 "Hook run in article edit mode buffers."
4162 :group 'gnus-article-various
4165 (defcustom gnus-article-edit-article-setup-function
4166 'gnus-article-mime-edit-article-setup
4167 "Function called to setup an editing article buffer."
4168 :group 'gnus-article-various
4171 (defvar gnus-article-edit-done-function nil)
4173 (defvar gnus-article-edit-mode-map nil)
4175 ;; Should we be using derived.el for this?
4176 (unless gnus-article-edit-mode-map
4177 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4178 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4180 (gnus-define-keys gnus-article-edit-mode-map
4181 "\C-c\C-c" gnus-article-edit-done
4182 "\C-c\C-k" gnus-article-edit-exit)
4184 (gnus-define-keys (gnus-article-edit-wash-map
4185 "\C-c\C-w" gnus-article-edit-mode-map)
4186 "f" gnus-article-edit-full-stops))
4188 (defun gnus-article-edit-mode ()
4189 "Major mode for editing articles.
4190 This is an extended text-mode.
4192 \\{gnus-article-edit-mode-map}"
4194 (setq major-mode 'gnus-article-edit-mode)
4195 (setq mode-name "Article Edit")
4196 (use-local-map gnus-article-edit-mode-map)
4197 (make-local-variable 'gnus-article-edit-done-function)
4198 (make-local-variable 'gnus-prev-winconf)
4199 (setq buffer-read-only nil)
4200 (buffer-enable-undo)
4202 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4204 (defun gnus-article-edit (&optional force)
4205 "Edit the current article.
4206 This will have permanent effect only in mail groups.
4207 If FORCE is non-nil, allow editing of articles even in read-only
4210 (when (and (not force)
4211 (gnus-group-read-only-p))
4212 (error "The current newsgroup does not support article editing"))
4213 (gnus-article-date-original)
4214 (gnus-article-edit-article
4216 `(lambda (no-highlight)
4218 (gnus-summary-edit-article-done
4219 ,(or (mail-header-references gnus-current-headers) "")
4220 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4222 (defun gnus-article-edit-article (start-func exit-func)
4223 "Start editing the contents of the current article buffer."
4224 (let ((winconf (current-window-configuration)))
4225 (set-buffer gnus-article-buffer)
4226 (gnus-article-edit-mode)
4227 (funcall start-func)
4228 (gnus-configure-windows 'edit-article)
4229 (setq gnus-article-edit-done-function exit-func)
4230 (setq gnus-prev-winconf winconf)
4231 (when gnus-article-edit-article-setup-function
4232 (funcall gnus-article-edit-article-setup-function))
4233 (gnus-message 6 "C-c C-c to end edits")))
4235 (defun gnus-article-edit-done (&optional arg)
4236 "Update the article edits and exit."
4241 (when (article-goto-body)
4242 (let ((lines (count-lines (point) (point-max)))
4243 (length (- (point-max) (point)))
4244 (case-fold-search t)
4245 (body (copy-marker (point))))
4246 (goto-char (point-min))
4247 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4248 (delete-region (match-beginning 1) (match-end 1))
4249 (insert (number-to-string length)))
4250 (goto-char (point-min))
4251 (when (re-search-forward
4252 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4253 (delete-region (match-beginning 1) (match-end 1))
4254 (insert (number-to-string length)))
4255 (goto-char (point-min))
4256 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4257 (delete-region (match-beginning 1) (match-end 1))
4258 (insert (number-to-string lines)))))))
4259 (let ((func gnus-article-edit-done-function)
4260 (buf (current-buffer))
4261 (start (window-start)))
4262 (remove-hook 'gnus-article-mode-hook
4263 'gnus-article-mime-edit-article-unwind)
4264 (gnus-article-edit-exit)
4267 (let ((buffer-read-only nil))
4269 ;; The cache and backlog have to be flushed somewhat.
4270 (when gnus-keep-backlog
4271 (gnus-backlog-remove-article
4272 (car gnus-article-current) (cdr gnus-article-current)))
4273 ;; Flush original article as well.
4275 (when (get-buffer gnus-original-article-buffer)
4276 (set-buffer gnus-original-article-buffer)
4277 (setq gnus-original-article nil)))
4278 (when gnus-use-cache
4279 (gnus-cache-update-article
4280 (car gnus-article-current) (cdr gnus-article-current))))
4282 (set-window-start (get-buffer-window buf) start)
4283 (set-window-point (get-buffer-window buf) (point))))
4285 (defun gnus-article-edit-exit ()
4286 "Exit the article editing without updating."
4288 ;; We remove all text props from the article buffer.
4289 (let ((buf (format "%s" (buffer-string)))
4290 (curbuf (current-buffer))
4292 (window-start (window-start)))
4295 (let ((winconf gnus-prev-winconf))
4297 (set-window-configuration winconf)
4298 ;; Tippy-toe some to make sure that point remains where it was.
4299 (save-current-buffer
4301 (set-window-start (get-buffer-window (current-buffer)) window-start)
4304 (defun gnus-article-edit-full-stops ()
4305 "Interactively repair spacing at end of sentences."
4308 (goto-char (point-min))
4309 (search-forward-regexp "^$" nil t)
4310 (let ((case-fold-search nil))
4311 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4314 ;;; Article editing with MIME-Edit
4317 (defcustom gnus-article-mime-edit-article-setup-hook nil
4318 "Hook run after setting up a MIME editing article buffer."
4319 :group 'gnus-article-various
4322 (defun gnus-article-mime-edit-article-unwind ()
4323 "Unwind `gnus-article-buffer' if article editing was given up."
4324 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4325 (when mime-edit-mode-flag
4326 (mime-edit-exit 'nomime 'no-error)
4328 (when (featurep 'font-lock)
4329 (setq font-lock-defaults nil)
4330 (font-lock-mode 0)))
4332 (defun gnus-article-mime-edit-article-setup ()
4333 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4334 after replacing with the original article."
4335 (setq gnus-show-mime t)
4336 (setq gnus-article-edit-done-function
4337 `(lambda (&rest args)
4338 (when mime-edit-mode-flag
4341 (goto-char (point-min))
4342 (let (case-fold-search)
4343 (when (re-search-forward
4344 (format "^%s$" (regexp-quote mail-header-separator))
4346 (replace-match "")))
4347 (when (featurep 'font-lock)
4348 (setq font-lock-defaults nil)
4350 (apply ,gnus-article-edit-done-function args)
4351 (set-buffer gnus-original-article-buffer)
4353 (insert-buffer gnus-article-buffer)
4354 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4355 (gnus-article-prepare-display)))
4356 (substitute-key-definition
4357 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4358 gnus-article-edit-mode-map)
4360 (insert-buffer gnus-original-article-buffer)
4362 (when (featurep 'font-lock)
4363 (set (make-local-variable 'font-lock-defaults)
4364 '(message-font-lock-keywords t))
4365 (font-lock-set-defaults)
4366 (turn-on-font-lock))
4367 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4368 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4370 (defun gnus-article-mime-edit-exit ()
4371 "Exit the article MIME editing without updating."
4373 (let ((winconf gnus-prev-winconf)
4375 (when mime-edit-mode-flag
4378 (goto-char (point-min))
4379 (let (case-fold-search)
4380 (when (re-search-forward
4381 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4382 (replace-match "")))
4383 (when (featurep 'font-lock)
4384 (setq font-lock-defaults nil)
4386 ;; We remove all text props from the article buffer.
4387 (setq buf (format "%s" (buffer-string)))
4388 (set-buffer (get-buffer-create gnus-original-article-buffer))
4391 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4392 (gnus-article-prepare-display)
4393 (set-window-configuration winconf)))
4396 ;;; Article highlights
4399 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4401 ;;; Internal Variables:
4403 (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\\)"
4404 "Regular expression that matches URLs."
4405 :group 'gnus-article-buttons
4408 (defcustom gnus-button-alist
4409 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4410 0 t gnus-button-message-id 2)
4411 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4412 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4414 gnus-button-fetch-group 4)
4415 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4416 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4417 t gnus-button-message-id 3)
4418 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4419 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4420 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4421 ;; This is how URLs _should_ be embedded in text...
4422 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
4424 (,gnus-button-url-regexp 0 t gnus-button-url 0))
4425 "*Alist of regexps matching buttons in article bodies.
4427 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4428 REGEXP: is the string matching text around the button,
4429 BUTTON: is the number of the regexp grouping actually matching the button,
4430 FORM: is a lisp expression which must eval to true for the button to
4432 CALLBACK: is the function to call when the user push this button, and each
4433 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4435 CALLBACK can also be a variable, in that case the value of that
4436 variable it the real callback function."
4437 :group 'gnus-article-buttons
4438 :type '(repeat (list regexp
4439 (integer :tag "Button")
4441 (function :tag "Callback")
4444 (integer :tag "Regexp group")))))
4446 (defcustom gnus-header-button-alist
4447 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4448 0 t gnus-button-message-id 0)
4449 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4450 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4451 0 t gnus-button-mailto 0)
4452 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4453 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4454 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
4455 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4456 gnus-button-message-id 3))
4457 "*Alist of headers and regexps to match buttons in article heads.
4459 This alist is very similar to `gnus-button-alist', except that each
4460 alist has an additional HEADER element first in each entry:
4462 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4464 HEADER is a regexp to match a header. For a fuller explanation, see
4465 `gnus-button-alist'."
4466 :group 'gnus-article-buttons
4467 :group 'gnus-article-headers
4468 :type '(repeat (list (regexp :tag "Header")
4470 (integer :tag "Button")
4472 (function :tag "Callback")
4475 (integer :tag "Regexp group")))))
4477 (defvar gnus-button-regexp nil)
4478 (defvar gnus-button-marker-list nil)
4479 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4481 (defvar gnus-button-last nil)
4482 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4486 (defun gnus-article-push-button (event)
4487 "Check text under the mouse pointer for a callback function.
4488 If the text under the mouse pointer has a `gnus-callback' property,
4489 call it with the value of the `gnus-data' text property."
4491 (set-buffer (window-buffer (posn-window (event-start event))))
4492 (let* ((pos (posn-point (event-start event)))
4493 (data (get-text-property pos 'gnus-data))
4494 (fun (get-text-property pos 'gnus-callback)))
4497 (funcall fun data))))
4499 (defun gnus-article-press-button ()
4500 "Check text at point for a callback function.
4501 If the text at point has a `gnus-callback' property,
4502 call it with the value of the `gnus-data' text property."
4504 (let* ((data (get-text-property (point) 'gnus-data))
4505 (fun (get-text-property (point) 'gnus-callback)))
4507 (funcall fun data))))
4509 (defun gnus-article-prev-button (n)
4510 "Move point to N buttons backward.
4511 If N is negative, move forward instead."
4513 (gnus-article-next-button (- n)))
4515 (defun gnus-article-next-button (n)
4516 "Move point to N buttons forward.
4517 If N is negative, move backward instead."
4519 (let ((function (if (< n 0) 'previous-single-property-change
4520 'next-single-property-change))
4521 (inhibit-point-motion-hooks t)
4523 (limit (if (< n 0) (point-min) (point-max))))
4525 (while (and (not (= limit (point)))
4527 ;; Skip past the current button.
4528 (when (get-text-property (point) 'gnus-callback)
4529 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4530 ;; Go to the next (or previous) button.
4531 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4532 ;; Put point at the start of the button.
4533 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4534 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4535 ;; Skip past intangible buttons.
4536 (when (get-text-property (point) 'intangible)
4540 (gnus-message 5 "No more buttons"))
4543 (defun gnus-article-highlight (&optional force)
4544 "Highlight current article.
4545 This function calls `gnus-article-highlight-headers',
4546 `gnus-article-highlight-citation',
4547 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4548 do the highlighting. See the documentation for those functions."
4549 (interactive (list 'force))
4550 (gnus-article-highlight-headers)
4551 (gnus-article-highlight-citation force)
4552 (gnus-article-highlight-signature)
4553 (gnus-article-add-buttons force)
4554 (gnus-article-add-buttons-to-head))
4556 (defun gnus-article-highlight-some (&optional force)
4557 "Highlight current article.
4558 This function calls `gnus-article-highlight-headers',
4559 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4560 do the highlighting. See the documentation for those functions."
4561 (interactive (list 'force))
4562 (gnus-article-highlight-headers)
4563 (gnus-article-highlight-signature)
4564 (gnus-article-add-buttons))
4566 (defun gnus-article-highlight-headers ()
4567 "Highlight article headers as specified by `gnus-header-face-alist'."
4570 (set-buffer gnus-article-buffer)
4572 (let ((alist gnus-header-face-alist)
4573 (buffer-read-only nil)
4574 (case-fold-search t)
4575 (inhibit-point-motion-hooks t)
4576 entry regexp header-face field-face from hpoints fpoints)
4577 (article-narrow-to-head)
4578 (while (setq entry (pop alist))
4579 (goto-char (point-min))
4580 (setq regexp (concat "^\\("
4581 (if (string-equal "" (nth 0 entry))
4585 header-face (nth 1 entry)
4586 field-face (nth 2 entry))
4587 (while (and (re-search-forward regexp nil t)
4591 (unless (search-forward ":" nil t)
4593 (when (and header-face
4594 (not (memq (point) hpoints)))
4595 (push (point) hpoints)
4596 (gnus-put-text-property from (point) 'face header-face))
4597 (when (and field-face
4598 (not (memq (setq from (point)) fpoints)))
4600 (if (re-search-forward "^[^ \t]" nil t)
4602 (goto-char (point-max)))
4603 (gnus-put-text-property from (point) 'face field-face))))))))
4605 (defun gnus-article-highlight-signature ()
4606 "Highlight the signature in an article.
4607 It does this by highlighting everything after
4608 `gnus-signature-separator' using `gnus-signature-face'."
4610 (when gnus-signature-face
4612 (set-buffer gnus-article-buffer)
4613 (let ((buffer-read-only nil)
4614 (inhibit-point-motion-hooks t))
4616 (when (gnus-article-narrow-to-signature)
4617 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4618 'face gnus-signature-face)))))))
4620 (defun gnus-article-buttonize-signature ()
4621 "Add button to the signature."
4624 (set-buffer gnus-article-buffer)
4625 (let ((buffer-read-only nil)
4626 (inhibit-point-motion-hooks t))
4627 (when (gnus-article-search-signature)
4628 (gnus-article-add-button (match-beginning 0) (match-end 0)
4629 'gnus-signature-toggle
4630 (set-marker (make-marker)
4631 (1+ (match-end 0))))))))
4633 (defun gnus-button-in-region-p (b e prop)
4634 "Say whether PROP exists in the region."
4635 (text-property-not-all b e prop nil))
4637 (defun gnus-article-add-buttons (&optional force)
4638 "Find external references in the article and make buttons of them.
4639 \"External references\" are things like Message-IDs and URLs, as
4640 specified by `gnus-button-alist'."
4641 (interactive (list 'force))
4643 (set-buffer gnus-article-buffer)
4644 (let ((buffer-read-only nil)
4645 (inhibit-point-motion-hooks t)
4646 (case-fold-search t)
4647 (alist gnus-button-alist)
4649 ;; Remove all old markers.
4650 (let (marker entry new-list)
4651 (while (setq marker (pop gnus-button-marker-list))
4652 (if (or (< marker (point-min)) (>= marker (point-max)))
4653 (push marker new-list)
4655 (when (setq entry (gnus-button-entry))
4656 (put-text-property (match-beginning (nth 1 entry))
4657 (match-end (nth 1 entry))
4658 'gnus-callback nil))
4659 (set-marker marker nil)))
4660 (setq gnus-button-marker-list new-list))
4661 ;; We skip the headers.
4664 (while (setq entry (pop alist))
4665 (setq regexp (car entry))
4667 (while (re-search-forward regexp nil t)
4668 (let* ((start (and entry (match-beginning (nth 1 entry))))
4669 (end (and entry (match-end (nth 1 entry))))
4670 (from (match-beginning 0)))
4671 (when (and (or (eq t (nth 2 entry))
4672 (eval (nth 2 entry)))
4673 (not (gnus-button-in-region-p
4674 start end 'gnus-callback)))
4675 ;; That optional form returned non-nil, so we add the
4677 (gnus-article-add-button
4678 start end 'gnus-button-push
4679 (car (push (set-marker (make-marker) from)
4680 gnus-button-marker-list))))))))))
4682 ;; Add buttons to the head of an article.
4683 (defun gnus-article-add-buttons-to-head ()
4684 "Add buttons to the head of the article."
4687 (set-buffer gnus-article-buffer)
4689 (let ((buffer-read-only nil)
4690 (inhibit-point-motion-hooks t)
4691 (case-fold-search t)
4692 (alist gnus-header-button-alist)
4694 (article-narrow-to-head)
4696 ;; Each alist entry.
4697 (setq entry (car alist)
4699 (goto-char (point-min))
4700 (while (re-search-forward (car entry) nil t)
4701 ;; Each header matching the entry.
4702 (setq beg (match-beginning 0))
4703 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4704 (match-beginning 0))
4707 (while (re-search-forward (nth 1 entry) end t)
4708 ;; Each match within a header.
4709 (let* ((entry (cdr entry))
4710 (start (match-beginning (nth 1 entry)))
4711 (end (match-end (nth 1 entry)))
4712 (form (nth 2 entry)))
4713 (goto-char (match-end 0))
4715 (gnus-article-add-button
4716 start end (nth 3 entry)
4717 (buffer-substring (match-beginning (nth 4 entry))
4718 (match-end (nth 4 entry)))))))
4719 (goto-char end)))))))
4721 ;;; External functions:
4723 (defun gnus-article-add-button (from to fun &optional data)
4724 "Create a button between FROM and TO with callback FUN and data DATA."
4725 (when gnus-article-button-face
4726 (gnus-overlay-put (gnus-make-overlay from to)
4727 'face gnus-article-button-face))
4728 (gnus-add-text-properties
4730 (nconc (and gnus-article-mouse-face
4731 (list gnus-mouse-face-prop gnus-article-mouse-face))
4732 (list 'gnus-callback fun)
4733 (and data (list 'gnus-data data)))))
4735 ;;; Internal functions:
4737 (defun gnus-article-set-globals ()
4739 (set-buffer gnus-summary-buffer)
4740 (gnus-set-global-variables)))
4742 (defun gnus-signature-toggle (end)
4744 (set-buffer gnus-article-buffer)
4745 (let ((buffer-read-only nil)
4746 (inhibit-point-motion-hooks t)
4747 (limit (or (next-single-property-change end 'mime-view-entity)
4749 (if (get-text-property end 'invisible)
4750 (gnus-article-unhide-text end limit)
4751 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4753 (defun gnus-button-entry ()
4754 ;; Return the first entry in `gnus-button-alist' matching this place.
4755 (let ((alist gnus-button-alist)
4758 (setq entry (pop alist))
4759 (if (looking-at (car entry))
4764 (defun gnus-button-push (marker)
4765 ;; Push button starting at MARKER.
4768 (let* ((entry (gnus-button-entry))
4769 (inhibit-point-motion-hooks t)
4771 (args (mapcar (lambda (group)
4772 (let ((string (match-string group)))
4773 (gnus-set-text-properties
4774 0 (length string) nil string)
4781 (fboundp (symbol-value fun)))
4782 (apply (symbol-value fun) args))
4784 (gnus-message 1 "You must define `%S' to use this button"
4785 (cons fun args)))))))
4787 (defun gnus-button-message-id (message-id)
4790 (set-buffer gnus-summary-buffer)
4791 (gnus-summary-refer-article message-id)))
4793 (defun gnus-button-fetch-group (address)
4794 "Fetch GROUP specified by ADDRESS."
4795 (if (not (string-match "[:/]" address))
4796 ;; This is just a simple group url.
4797 (gnus-group-read-ephemeral-group address gnus-select-method)
4798 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4800 (error "Can't parse %s" address)
4801 (gnus-group-read-ephemeral-group
4802 (match-string 4 address)
4803 `(nntp ,(match-string 1 address)
4804 (nntp-address ,(match-string 1 address))
4805 (nntp-port-number ,(if (match-end 3)
4806 (match-string 3 address)
4809 (defun gnus-url-parse-query-string (query &optional downcase)
4810 (let (retval pairs cur key val)
4811 (setq pairs (split-string query "&"))
4813 (setq cur (car pairs)
4815 (if (not (string-match "=" cur))
4817 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4818 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4820 (setq key (downcase key)))
4821 (setq cur (assoc key retval))
4823 (setcdr cur (cons val (cdr cur)))
4824 (setq retval (cons (list key val) retval)))))
4827 (defun gnus-url-unhex (x)
4834 (defun gnus-url-unhex-string (str &optional allow-newlines)
4835 "Remove %XXX embedded spaces, etc in a url.
4836 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4837 decoding of carriage returns and line feeds in the string, which is normally
4838 forbidden in URL encoding."
4839 (setq str (or str ""))
4841 (case-fold-search t))
4842 (while (string-match "%[0-9a-f][0-9a-f]" str)
4843 (let* ((start (match-beginning 0))
4844 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4846 (gnus-url-unhex (elt str (+ start 2))))))
4848 tmp (substring str 0 start)
4851 (char-to-string code))
4852 ((or (= code ?\n) (= code ?\r))
4854 (t (char-to-string code))))
4855 str (substring str (match-end 0)))))
4856 (setq tmp (concat tmp str))
4859 (defun gnus-url-mailto (url)
4860 ;; Send mail to someone
4861 (when (string-match "mailto:/*\\(.*\\)" url)
4862 (setq url (substring url (match-beginning 1) nil)))
4863 (let (to args subject func)
4864 (if (string-match (regexp-quote "?") url)
4865 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4866 args (gnus-url-parse-query-string
4867 (substring url (match-end 0) nil) t))
4868 (setq to (gnus-url-unhex-string url)))
4869 (setq args (cons (list "to" to) args)
4870 subject (cdr-safe (assoc "subject" args)))
4871 (gnus-setup-message 'reply
4874 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4877 (message-position-on-field (caar args)))
4878 (insert (mapconcat 'identity (cdar args) ", "))
4879 (setq args (cdr args)))
4882 (message-goto-subject)))))
4884 (defun gnus-button-mailto (address)
4886 (set-buffer (gnus-copy-article-buffer))
4887 (gnus-setup-message 'reply
4888 (message-reply address)))
4890 (defun gnus-button-reply (address)
4891 ;; Reply to ADDRESS.
4892 (gnus-setup-message 'reply
4893 (message-reply address)))
4895 (defun gnus-button-url (address)
4897 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4898 (if (listp browse-url-browser-function)
4899 (browse-url address)
4900 (funcall browse-url-browser-function address)))
4902 (defun gnus-button-embedded-url (address)
4904 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4905 (if (listp browse-url-browser-function)
4906 (browse-url (gnus-strip-whitespace address))
4907 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4909 ;;; Next/prev buttons in the article buffer.
4911 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4912 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4914 (defvar gnus-prev-page-map nil)
4915 (unless gnus-prev-page-map
4916 (setq gnus-prev-page-map (make-sparse-keymap))
4917 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4918 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4920 (static-if (featurep 'xemacs)
4921 (defun gnus-insert-prev-page-button ()
4922 (let ((buffer-read-only nil))
4924 gnus-prev-page-line-format nil
4925 `(gnus-prev t local-map ,gnus-prev-page-map
4926 gnus-callback gnus-article-button-prev-page
4927 article-type annotation))))
4928 (defun gnus-insert-prev-page-button ()
4929 (let ((buffer-read-only nil)
4930 (situation (get-text-property (point-min) 'mime-view-situation)))
4931 (set-keymap-parent gnus-prev-page-map (current-local-map))
4933 gnus-prev-page-line-format nil
4934 `(gnus-prev t local-map ,gnus-prev-page-map
4935 gnus-callback gnus-article-button-prev-page
4936 article-type annotation
4937 mime-view-situation ,situation))))
4940 (defvar gnus-next-page-map nil)
4941 (unless gnus-next-page-map
4942 (setq gnus-next-page-map (make-sparse-keymap))
4943 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4944 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4946 (defun gnus-button-next-page ()
4947 "Go to the next page."
4949 (let ((win (selected-window)))
4950 (select-window (get-buffer-window gnus-article-buffer t))
4951 (gnus-article-next-page)
4952 (select-window win)))
4954 (defun gnus-button-prev-page ()
4955 "Go to the prev page."
4957 (let ((win (selected-window)))
4958 (select-window (get-buffer-window gnus-article-buffer t))
4959 (gnus-article-prev-page)
4960 (select-window win)))
4962 (static-if (featurep 'xemacs)
4963 (defun gnus-insert-next-page-button ()
4964 (let ((buffer-read-only nil))
4965 (gnus-eval-format gnus-next-page-line-format nil
4967 t local-map ,gnus-next-page-map
4968 gnus-callback gnus-article-button-next-page
4969 article-type annotation))))
4970 (defun gnus-insert-next-page-button ()
4971 (let ((buffer-read-only nil)
4972 (situation (get-text-property (point-min) 'mime-view-situation)))
4973 (set-keymap-parent gnus-next-page-map (current-local-map))
4974 (gnus-eval-format gnus-next-page-line-format nil
4976 t local-map ,gnus-next-page-map
4977 gnus-callback gnus-article-button-next-page
4978 article-type annotation
4979 mime-view-situation ,situation))))
4982 (defun gnus-article-button-next-page (arg)
4983 "Go to the next page."
4985 (let ((win (selected-window)))
4986 (select-window (get-buffer-window gnus-article-buffer t))
4987 (gnus-article-next-page)
4988 (select-window win)))
4990 (defun gnus-article-button-prev-page (arg)
4991 "Go to the prev page."
4993 (let ((win (selected-window)))
4994 (select-window (get-buffer-window gnus-article-buffer t))
4995 (gnus-article-prev-page)
4996 (select-window win)))
4998 (defvar gnus-decode-header-methods
4999 '(mail-decode-encoded-word-region)
5000 "List of methods used to decode headers.
5002 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
5003 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5004 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5005 whose names match REGEXP.
5008 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5009 mail-decode-encoded-word-region
5010 (\"chinese\" . rfc1843-decode-region))
5013 (defvar gnus-decode-header-methods-cache nil)
5015 (defun gnus-multi-decode-header (start end)
5016 "Apply the functions from `gnus-encoded-word-methods' that match."
5017 (unless (and gnus-decode-header-methods-cache
5018 (eq gnus-newsgroup-name
5019 (car gnus-decode-header-methods-cache)))
5020 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5023 (nconc gnus-decode-header-methods-cache (list x))
5024 (if (and gnus-newsgroup-name
5025 (string-match (car x) gnus-newsgroup-name))
5026 (nconc gnus-decode-header-methods-cache
5028 gnus-decode-header-methods))
5029 (let ((xlist gnus-decode-header-methods-cache))
5032 (narrow-to-region start end)
5034 (funcall (pop xlist) (point-min) (point-max))))))
5037 ;;; Treatment top-level handling.
5040 (defun gnus-treat-article (condition &optional part-number total-parts type)
5041 (let ((length (- (point-max) (point-min)))
5042 (alist gnus-treatment-function-alist)
5043 (article-goto-body-goes-to-point-min-p t)
5047 (let ((list gnus-article-treat-types))
5049 (when (string-match (pop list) type)
5050 (throw 'found t)))))))
5051 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5052 (entity (static-unless (featurep 'xemacs)
5053 (when (eq 'head condition)
5054 (get-text-property (point-min) 'mime-view-entity))))
5055 val elem buttonized)
5056 (gnus-run-hooks 'gnus-part-display-hook)
5057 (unless gnus-inhibit-treatment
5058 (while (setq elem (pop alist))
5059 (setq val (symbol-value (car elem)))
5060 (when (and (or (consp val)
5062 (gnus-treat-predicate val)
5063 (or (not (get (car elem) 'highlight))
5065 (when (and (not buttonized)
5067 '(gnus-treat-hide-signature
5068 gnus-treat-highlight-signature)))
5069 (gnus-article-buttonize-signature)
5070 (setq buttonized t))
5072 (funcall (cadr elem)))))
5073 ;; FSF Emacsen does not inherit the existing text properties
5074 ;; in the new text, so we should do it for `mime-view-entity'.
5075 (static-unless (featurep 'xemacs)
5077 (put-text-property (point-min) (point-max)
5078 'mime-view-entity entity))))))
5080 ;; Dynamic variables.
5081 (defvar part-number)
5082 (defvar total-parts)
5086 (defun gnus-treat-predicate (val)
5091 (stringp (car val)))
5092 (apply 'gnus-or (mapcar `(lambda (s)
5093 (string-match s ,(or gnus-newsgroup-name "")))
5096 (let ((pred (pop val)))
5099 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5101 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5103 (not (gnus-treat-predicate (car val))))
5105 (equal (car val) type))
5107 (error "%S is not a valid predicate" pred)))))
5117 (eq part-number total-parts))
5121 (error "%S is not a valid value" val))))
5127 (defun gnus-article-header-presentation-method (entity situation)
5128 (mime-insert-header entity)
5131 (set-alist 'mime-header-presentation-method-alist
5132 'gnus-original-article-mode
5133 #'gnus-article-header-presentation-method)
5135 (defun gnus-mime-preview-quitting-method ()
5136 (mime-preview-kill-buffer)
5137 (delete-other-windows)
5138 (gnus-article-show-summary)
5139 (gnus-summary-select-article gnus-show-all-headers t))
5141 (set-alist 'mime-preview-quitting-method-alist
5142 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5144 (set-alist 'mime-preview-following-method-alist
5145 'gnus-original-article-mode #'gnus-following-method)
5147 (set-alist 'mime-preview-over-to-previous-method-alist
5148 'gnus-original-article-mode
5150 (if (> (point-min) 1)
5151 (gnus-article-prev-page)
5152 (gnus-article-read-summary-keys
5153 nil (gnus-character-to-event ?P)))))
5155 (set-alist 'mime-preview-over-to-next-method-alist
5156 'gnus-original-article-mode'
5158 (if (< (point-max) (buffer-size))
5159 (gnus-article-next-page)
5160 (gnus-article-read-summary-keys
5161 nil (gnus-character-to-event ?N)))))
5171 (run-hooks 'gnus-art-load-hook)
5173 ;;; gnus-art.el ends here