1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'static))
43 ;; Avoid byte-compile warnings.
53 (defgroup gnus-article nil
55 :link '(custom-manual "(gnus)The Article Buffer")
58 (defgroup gnus-article-treat nil
59 "Treating article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
63 (defgroup gnus-article-hiding nil
64 "Hiding article parts."
65 :link '(custom-manual "(gnus)Article Hiding")
68 (defgroup gnus-article-highlight nil
69 "Article highlighting."
70 :link '(custom-manual "(gnus)Article Highlighting")
74 (defgroup gnus-article-signature nil
76 :link '(custom-manual "(gnus)Article Signature")
79 (defgroup gnus-article-headers nil
81 :link '(custom-manual "(gnus)Hiding Headers")
84 (defgroup gnus-article-washing nil
85 "Special commands on articles."
86 :link '(custom-manual "(gnus)Article Washing")
89 (defgroup gnus-article-emphasis nil
90 "Fontisizing articles."
91 :link '(custom-manual "(gnus)Article Fontisizing")
94 (defgroup gnus-article-saving nil
96 :link '(custom-manual "(gnus)Saving Articles")
99 (defgroup gnus-article-mime nil
100 "Worshiping the MIME wonder."
101 :link '(custom-manual "(gnus)Using MIME")
102 :group 'gnus-article)
104 (defgroup gnus-article-buttons nil
105 "Pushable buttons in the article buffer."
106 :link '(custom-manual "(gnus)Article Buttons")
107 :group 'gnus-article)
109 (defgroup gnus-article-various nil
110 "Other article options."
111 :link '(custom-manual "(gnus)Misc Article")
112 :group 'gnus-article)
114 (defcustom gnus-ignored-headers
115 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
116 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
117 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
118 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
119 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
120 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
121 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
122 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
123 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
124 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
125 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
126 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
127 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
128 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
129 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
130 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
131 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
132 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
133 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
134 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
135 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
136 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
137 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
138 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
139 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
140 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
141 "^X-Received:" "^Content-length:" "X-precedence:")
142 "*All headers that start with this regexp will be hidden.
143 This variable can also be a list of regexps of headers to be ignored.
144 If `gnus-visible-headers' is non-nil, this variable will be ignored."
145 :type '(choice :custom-show nil
148 :group 'gnus-article-hiding)
150 (defcustom gnus-visible-headers
151 "^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:"
152 "*All headers that do not match this regexp will be hidden.
153 This variable can also be a list of regexp of headers to remain visible.
154 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
155 :type '(repeat :value-to-internal (lambda (widget value)
156 (custom-split-regexp-maybe value))
157 :match (lambda (widget value)
159 (widget-editable-list-match widget value)))
161 :group 'gnus-article-hiding)
163 (defcustom gnus-sorted-header-list
164 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
165 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
166 "*This variable is a list of regular expressions.
167 If it is non-nil, headers that match the regular expressions will
168 be placed first in the article buffer in the sequence specified by
170 :type '(repeat regexp)
171 :group 'gnus-article-hiding)
173 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
174 "Headers that are only to be displayed if they have interesting data.
175 Possible values in this list are `empty', `newsgroups', `followup-to',
176 `reply-to', `date', `long-to', and `many-to'."
177 :type '(set (const :tag "Headers with no content." empty)
178 (const :tag "Newsgroups with only one group." newsgroups)
179 (const :tag "Followup-to identical to newsgroups." followup-to)
180 (const :tag "Reply-to identical to from." reply-to)
181 (const :tag "Date less than four days old." date)
182 (const :tag "Very long To and/or Cc header." long-to)
183 (const :tag "Multiple To and/or Cc headers." many-to))
184 :group 'gnus-article-hiding)
186 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
187 "Regexp matching signature separator.
188 This can also be a list of regexps. In that case, it will be checked
189 from head to tail looking for a separator. Searches will be done from
190 the end of the buffer."
191 :type '(repeat string)
192 :group 'gnus-article-signature)
194 (defcustom gnus-signature-limit nil
195 "Provide a limit to what is considered a signature.
196 If it is a number, no signature may not be longer (in characters) than
197 that number. If it is a floating point number, no signature may be
198 longer (in lines) than that number. If it is a function, the function
199 will be called without any parameters, and if it returns nil, there is
200 no signature in the buffer. If it is a string, it will be used as a
201 regexp. If it matches, the text in question is not a signature."
202 :type '(choice (integer :value 200)
204 (function :value fun)
205 (regexp :value ".*"))
206 :group 'gnus-article-signature)
208 (defcustom gnus-hidden-properties '(invisible t intangible t)
209 "Property list to use for hiding text."
211 :group 'gnus-article-hiding)
213 (defcustom gnus-article-x-face-command
214 (if (and (not gnus-xemacs)
216 (module-installed-p 'x-face-mule))
217 'x-face-mule-gnus-article-display-x-face
218 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
220 "*String or function to be executed to display an X-Face header.
221 If it is a string, the command will be executed in a sub-shell
222 asynchronously. The compressed face will be piped to this command."
223 :type 'string ;Leave function case to Lisp.
224 :group 'gnus-article-washing)
226 (defcustom gnus-article-x-face-too-ugly nil
227 "Regexp matching posters whose face shouldn't be shown automatically."
228 :type '(choice regexp (const nil))
229 :group 'gnus-article-washing)
231 (defcustom gnus-emphasis-alist
233 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
235 '(("_" "_" underline)
238 ("_/" "/_" underline-italic)
239 ("_\\*" "\\*_" underline-bold)
240 ("\\*/" "/\\*" bold-italic)
241 ("_\\*/" "/\\*_" underline-bold-italic))))
242 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
243 2 3 gnus-emphasis-underline)
247 (format format (car spec) (car (cdr spec)))
248 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
250 "*Alist that says how to fontify certain phrases.
251 Each item looks like this:
253 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
255 The first element is a regular expression to be matched. The second
256 is a number that says what regular expression grouping used to find
257 the entire emphasized word. The third is a number that says what
258 regexp grouping should be displayed and highlighted. The fourth
259 is the face used for highlighting."
260 :type '(repeat (list :value ("" 0 0 default)
262 (integer :tag "Match group")
263 (integer :tag "Emphasize group")
265 :group 'gnus-article-emphasis)
267 (defface gnus-emphasis-bold '((t (:bold t)))
268 "Face used for displaying strong emphasized text (*word*)."
269 :group 'gnus-article-emphasis)
271 (defface gnus-emphasis-italic '((t (:italic t)))
272 "Face used for displaying italic emphasized text (/word/)."
273 :group 'gnus-article-emphasis)
275 (defface gnus-emphasis-underline '((t (:underline t)))
276 "Face used for displaying underlined emphasized text (_word_)."
277 :group 'gnus-article-emphasis)
279 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
280 "Face used for displaying underlined bold emphasized text (_*word*_)."
281 :group 'gnus-article-emphasis)
283 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
284 "Face used for displaying underlined italic emphasized text (_/word/_)."
285 :group 'gnus-article-emphasis)
287 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
288 "Face used for displaying bold italic emphasized text (/*word*/)."
289 :group 'gnus-article-emphasis)
291 (defface gnus-emphasis-underline-bold-italic
292 '((t (:bold t :italic t :underline t)))
293 "Face used for displaying underlined bold italic emphasized text.
294 Esample: (_/*word*/_)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-highlight-words
298 '((t (:background "black" :foreground "yellow")))
299 "Face used for displaying highlighted words."
300 :group 'gnus-article-emphasis)
302 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
303 "Format for display of Date headers in article bodies.
304 See `format-time-string' for the possible values.
306 The variable can also be function, which should return a complete Date
307 header. The function is called with one argument, the time, which can
308 be fed to `format-time-string'."
309 :type '(choice string symbol)
310 :link '(custom-manual "(gnus)Article Date")
311 :group 'gnus-article-washing)
314 (autoload 'mail-extract-address-components "mail-extr"))
316 (defcustom gnus-save-all-headers t
317 "*If non-nil, don't remove any headers before saving."
318 :group 'gnus-article-saving
321 (defcustom gnus-prompt-before-saving 'always
322 "*This variable says how much prompting is to be done when saving articles.
323 If it is nil, no prompting will be done, and the articles will be
324 saved to the default files. If this variable is `always', each and
325 every article that is saved will be preceded by a prompt, even when
326 saving large batches of articles. If this variable is neither nil not
327 `always', there the user will be prompted once for a file name for
328 each invocation of the saving commands."
329 :group 'gnus-article-saving
330 :type '(choice (item always)
331 (item :tag "never" nil)
332 (sexp :tag "once" :format "%t\n" :value t)))
334 (defcustom gnus-saved-headers gnus-visible-headers
335 "Headers to keep if `gnus-save-all-headers' is nil.
336 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
337 If that variable is nil, however, all headers that match this regexp
338 will be kept while the rest will be deleted before saving."
339 :group 'gnus-article-saving
342 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
343 "A function to save articles in your favourite format.
344 The function must be interactively callable (in other words, it must
345 be an Emacs command).
347 Gnus provides the following functions:
349 * gnus-summary-save-in-rmail (Rmail format)
350 * gnus-summary-save-in-mail (Unix mail format)
351 * gnus-summary-save-in-folder (MH folder)
352 * gnus-summary-save-in-file (article format)
353 * gnus-summary-save-in-vm (use VM's folder format)
354 * gnus-summary-write-to-file (article format -- overwrite)."
355 :group 'gnus-article-saving
356 :type '(radio (function-item gnus-summary-save-in-rmail)
357 (function-item gnus-summary-save-in-mail)
358 (function-item gnus-summary-save-in-folder)
359 (function-item gnus-summary-save-in-file)
360 (function-item gnus-summary-save-in-vm)
361 (function-item gnus-summary-write-to-file)))
363 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
364 "A function generating a file name to save articles in Rmail format.
365 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
366 :group 'gnus-article-saving
369 (defcustom gnus-mail-save-name 'gnus-plain-save-name
370 "A function generating a file name to save articles in Unix mail format.
371 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
372 :group 'gnus-article-saving
375 (defcustom gnus-folder-save-name 'gnus-folder-save-name
376 "A function generating a file name to save articles in MH folder.
377 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
378 :group 'gnus-article-saving
381 (defcustom gnus-file-save-name 'gnus-numeric-save-name
382 "A function generating a file name to save articles in article format.
383 The function is called with NEWSGROUP, HEADERS, and optional
385 :group 'gnus-article-saving
388 (defcustom gnus-split-methods
389 '((gnus-article-archive-name)
390 (gnus-article-nndoc-name))
391 "*Variable used to suggest where articles are to be saved.
392 For instance, if you would like to save articles related to Gnus in
393 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
394 you could set this variable to something like:
396 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
397 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
399 This variable is an alist where the where the key is the match and the
400 value is a list of possible files to save in if the match is non-nil.
402 If the match is a string, it is used as a regexp match on the
403 article. If the match is a symbol, that symbol will be funcalled
404 from the buffer of the article to be saved with the newsgroup as the
405 parameter. If it is a list, it will be evaled in the same buffer.
407 If this form or function returns a string, this string will be used as
408 a possible file name; and if it returns a non-nil list, that list will
409 be used as possible file names."
410 :group 'gnus-article-saving
411 :type '(repeat (choice (list :value (fun) function)
412 (cons :value ("" "") regexp (repeat string))
415 (defcustom gnus-article-display-method-for-mime
416 'gnus-article-display-mime-message
417 "Function to display a MIME message.
418 The function is called from the article buffer."
419 :group 'gnus-article-mime
422 (defcustom gnus-article-display-method-for-traditional
423 'gnus-article-display-traditional-message
424 "*Function to display a traditional message.
425 The function is called from the article buffer."
426 :group 'gnus-article-mime
429 (defcustom gnus-page-delimiter "^\^L"
430 "*Regexp describing what to use as article page delimiters.
431 The default value is \"^\^L\", which is a form linefeed at the
432 beginning of a line."
434 :group 'gnus-article-various)
436 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
437 "*The format specification for the article mode line.
438 See `gnus-summary-mode-line-format' for a closer description.
440 The following additional specs are available:
442 %w The article washing status.
443 %m The number of MIME parts in the article."
445 :group 'gnus-article-various)
447 (defcustom gnus-article-mode-hook nil
448 "*A hook for Gnus article mode."
450 :group 'gnus-article-various)
452 (defcustom gnus-article-menu-hook nil
453 "*Hook run after the creation of the article mode menu."
455 :group 'gnus-article-various)
457 (defcustom gnus-article-prepare-hook nil
458 "*A hook called after an article has been prepared in the article buffer."
460 :group 'gnus-article-various)
462 (defcustom gnus-article-hide-pgp-hook nil
463 "*A hook called after successfully hiding a PGP signature."
465 :group 'gnus-article-various)
467 (defcustom gnus-article-button-face 'bold
468 "Face used for highlighting buttons in the article buffer.
470 An article button is a piece of text that you can activate by pressing
471 `RET' or `mouse-2' above it."
473 :group 'gnus-article-buttons)
475 (defcustom gnus-article-mouse-face 'highlight
476 "Face used for mouse highlighting in the article buffer.
478 Article buttons will be displayed in this face when the cursor is
481 :group 'gnus-article-buttons)
483 (defcustom gnus-signature-face 'gnus-signature-face
484 "Face used for highlighting a signature in the article buffer.
485 Obsolete; use the face `gnus-signature-face' for customizations instead."
487 :group 'gnus-article-highlight
488 :group 'gnus-article-signature)
490 (defface gnus-signature-face
492 "Face used for highlighting a signature in the article buffer."
493 :group 'gnus-article-highlight
494 :group 'gnus-article-signature)
496 (defface gnus-header-from-face
499 (:foreground "spring green"))
502 (:foreground "red3"))
505 "Face used for displaying from headers."
506 :group 'gnus-article-headers
507 :group 'gnus-article-highlight)
509 (defface gnus-header-subject-face
512 (:foreground "SeaGreen3"))
515 (:foreground "red4"))
517 (:bold t :italic t)))
518 "Face used for displaying subject headers."
519 :group 'gnus-article-headers
520 :group 'gnus-article-highlight)
522 (defface gnus-header-newsgroups-face
525 (:foreground "yellow" :italic t))
528 (:foreground "MidnightBlue" :italic t))
531 "Face used for displaying newsgroups headers."
532 :group 'gnus-article-headers
533 :group 'gnus-article-highlight)
535 (defface gnus-header-name-face
538 (:foreground "SeaGreen"))
541 (:foreground "maroon"))
544 "Face used for displaying header names."
545 :group 'gnus-article-headers
546 :group 'gnus-article-highlight)
548 (defface gnus-header-content-face
551 (:foreground "forest green" :italic t))
554 (:foreground "indianred4" :italic t))
556 (:italic t))) "Face used for displaying header content."
557 :group 'gnus-article-headers
558 :group 'gnus-article-highlight)
560 (defcustom gnus-header-face-alist
561 '(("From" nil gnus-header-from-face)
562 ("Subject" nil gnus-header-subject-face)
563 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
564 ("" gnus-header-name-face gnus-header-content-face))
565 "*Controls highlighting of article header.
567 An alist of the form (HEADER NAME CONTENT).
569 HEADER is a regular expression which should match the name of an
570 header header and NAME and CONTENT are either face names or nil.
572 The name of each header field will be displayed using the face
573 specified by the first element in the list where HEADER match the
574 header name and NAME is non-nil. Similarly, the content will be
575 displayed by the first non-nil matching CONTENT face."
576 :group 'gnus-article-headers
577 :group 'gnus-article-highlight
578 :type '(repeat (list (regexp :tag "Header")
580 (item :tag "skip" nil)
581 (face :value default))
582 (choice :tag "Content"
583 (item :tag "skip" nil)
584 (face :value default)))))
586 (defcustom gnus-article-decode-hook nil
587 "*Hook run to decode charsets in articles."
588 :group 'gnus-article-headers
591 (defcustom gnus-display-mime-function 'gnus-display-mime
592 "Function to display MIME articles."
593 :group 'gnus-article-mime
596 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
597 "Function used to decode headers.")
599 (defvar gnus-article-dumbquotes-map
617 "Table for MS-to-Latin1 translation.")
619 (defcustom gnus-ignored-mime-types nil
620 "List of MIME types that should be ignored by Gnus."
621 :group 'gnus-article-mime
622 :type '(repeat regexp))
624 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
625 "List of MIME types that should not be given buttons when rendered inline."
626 :group 'gnus-article-mime
627 :type '(repeat regexp))
629 (defcustom gnus-article-mime-part-function nil
630 "Function called with a MIME handle as the argument.
631 This is meant for people who want to do something automatic based
632 on parts -- for instance, adding Vcard info to a database."
633 :group 'gnus-article-mime
636 (defcustom gnus-mime-multipart-functions nil
637 "An alist of MIME types to functions to display them.")
639 (defcustom gnus-article-date-lapsed-new-header nil
640 "Whether the X-Sent and Date headers can coexist.
641 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
642 either replace the old \"Date:\" header (if this variable is nil), or
643 be added below it (otherwise)."
644 :group 'gnus-article-headers
647 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
648 "Function called with a MIME handle as the argument.
649 This is meant for people who want to view first matched part.
650 For `undisplayed-alternative' (default), the first undisplayed
651 part or alternative part is used. For `undisplayed', the first
652 undisplayed part is used. For a function, the first part which
653 the function return `t' is used. For `nil', the first part is
655 :group 'gnus-article-mime
657 (item :tag "first" :value nil)
658 (item :tag "undisplayed" :value undisplayed)
659 (item :tag "undisplayed or alternative"
660 :value undisplayed-alternative)
664 ;;; The treatment variables
667 (defvar gnus-part-display-hook nil
668 "Hook called on parts that are to receive treatment.")
670 (defvar gnus-article-treat-custom
671 '(choice (const :tag "Off" nil)
673 (const :tag "Header" head)
674 (const :tag "Last" last)
675 (const :tag "Mime" mime)
676 (integer :tag "Less")
677 (repeat :tag "Groups" regexp)
678 (sexp :tag "Predicate")))
680 (defvar gnus-article-treat-head-custom
681 '(choice (const :tag "Off" nil)
682 (const :tag "Header" head)))
684 (defvar gnus-article-treat-types '("text/plain")
687 (defvar gnus-inhibit-treatment nil
688 "Whether to inhibit treatment.")
690 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
691 "Highlight the signature.
692 Valid values are nil, t, `head', `last', an integer or a predicate.
693 See the manual for details."
694 :group 'gnus-article-treat
695 :type gnus-article-treat-custom)
696 (put 'gnus-treat-highlight-signature 'highlight t)
698 (defcustom gnus-treat-buttonize 100000
700 Valid values are nil, t, `head', `last', an integer or a predicate.
701 See the manual for details."
702 :group 'gnus-article-treat
703 :type gnus-article-treat-custom)
704 (put 'gnus-treat-buttonize 'highlight t)
706 (defcustom gnus-treat-buttonize-head 'head
707 "Add buttons to the head.
708 Valid values are nil, t, `head', `last', an integer or a predicate.
709 See the manual for details."
710 :group 'gnus-article-treat
711 :type gnus-article-treat-head-custom)
712 (put 'gnus-treat-buttonize-head 'highlight t)
714 (defcustom gnus-treat-emphasize nil
716 Valid values are nil, t, `head', `last', an integer or a predicate.
717 See the manual for details."
718 :group 'gnus-article-treat
719 :type gnus-article-treat-custom)
720 (put 'gnus-treat-emphasize 'highlight t)
722 (defcustom gnus-treat-strip-cr nil
723 "Remove carriage returns.
724 Valid values are nil, t, `head', `last', an integer or a predicate.
725 See the manual for details."
726 :group 'gnus-article-treat
727 :type gnus-article-treat-custom)
729 (defcustom gnus-treat-hide-headers 'head
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733 :group 'gnus-article-treat
734 :type gnus-article-treat-head-custom)
736 (defcustom gnus-treat-hide-boring-headers nil
737 "Hide boring headers.
738 Valid values are nil, t, `head', `last', an integer or a predicate.
739 See the manual for details."
740 :group 'gnus-article-treat
741 :type gnus-article-treat-head-custom)
743 (defcustom gnus-treat-hide-signature nil
745 Valid values are nil, t, `head', `last', an integer or a predicate.
746 See the manual for details."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-custom)
750 (defcustom gnus-treat-fill-article nil
752 Valid values are nil, t, `head', `last', an integer or a predicate.
753 See the manual for details."
754 :group 'gnus-article-treat
755 :type gnus-article-treat-custom)
757 (defcustom gnus-treat-hide-citation nil
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-custom)
764 (defcustom gnus-treat-strip-list-identifiers 'head
765 "Strip list identifiers from `gnus-list-identifiers`.
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-custom)
771 (defcustom gnus-treat-strip-pgp t
772 "Strip PGP signatures.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-custom)
778 (defcustom gnus-treat-strip-pem nil
779 "Strip PEM signatures.
780 Valid values are nil, t, `head', `last', an integer or a predicate.
781 See the manual for details."
782 :group 'gnus-article-treat
783 :type gnus-article-treat-custom)
785 (defcustom gnus-treat-strip-banner t
786 "Strip banners from articles.
787 The banner to be stripped is specified in the `banner' group parameter.
788 Valid values are nil, t, `head', `last', an integer or a predicate.
789 See the manual for details."
790 :group 'gnus-article-treat
791 :type gnus-article-treat-custom)
793 (defcustom gnus-treat-highlight-headers 'head
794 "Highlight the headers.
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-head-custom)
799 (put 'gnus-treat-highlight-headers 'highlight t)
801 (defcustom gnus-treat-highlight-citation t
802 "Highlight cited text.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-custom)
807 (put 'gnus-treat-highlight-citation 'highlight t)
809 (defcustom gnus-treat-date-ut nil
810 "Display the Date in UT (GMT).
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-head-custom)
816 (defcustom gnus-treat-date-local nil
817 "Display the Date in the local timezone.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-head-custom)
823 (defcustom gnus-treat-date-lapsed nil
824 "Display the Date header in a way that says how much time has elapsed.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-head-custom)
830 (defcustom gnus-treat-date-original nil
831 "Display the date in the original timezone.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-head-custom)
837 (defcustom gnus-treat-date-iso8601 nil
838 "Display the date in the ISO8601 format.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-head-custom)
844 (defcustom gnus-treat-date-user-defined nil
845 "Display the date in a user-defined format.
846 The format is defined by the `gnus-article-time-format' variable.
847 Valid values are nil, t, `head', `last', an integer or a predicate.
848 See the manual for details."
849 :group 'gnus-article-treat
850 :type gnus-article-treat-head-custom)
852 (defcustom gnus-treat-strip-headers-in-body t
853 "Strip the X-No-Archive header line from the beginning of the body.
854 Valid values are nil, t, `head', `last', an integer or a predicate.
855 See the manual for details."
856 :group 'gnus-article-treat
857 :type gnus-article-treat-custom)
859 (defcustom gnus-treat-strip-trailing-blank-lines nil
860 "Strip trailing blank lines.
861 Valid values are nil, t, `head', `last', an integer or a predicate.
862 See the manual for details."
863 :group 'gnus-article-treat
864 :type gnus-article-treat-custom)
866 (defcustom gnus-treat-strip-leading-blank-lines nil
867 "Strip leading blank lines.
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-custom)
873 (defcustom gnus-treat-strip-multiple-blank-lines nil
874 "Strip multiple blank lines.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-custom)
880 (defcustom gnus-treat-overstrike t
881 "Treat overstrike highlighting.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884 :group 'gnus-article-treat
885 :type gnus-article-treat-custom)
886 (put 'gnus-treat-overstrike 'highlight t)
888 (defcustom gnus-treat-display-xface
889 (if (or (and gnus-xemacs (featurep 'xface))
890 (eq 'x-face-mule-gnus-article-display-x-face
891 gnus-article-x-face-command))
894 "Display X-Face headers.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-head-custom)
899 (put 'gnus-treat-display-xface 'highlight t)
901 (defcustom gnus-treat-display-smileys
902 (if (or (and gnus-xemacs (featurep 'xpm))
903 (and (not gnus-xemacs)
905 (module-installed-p 'gnus-bitmap)))
909 Valid values are nil, t, `head', `last', an integer or a predicate.
910 See the manual for details."
911 :group 'gnus-article-treat
912 :type gnus-article-treat-custom)
913 (put 'gnus-treat-display-smileys 'highlight t)
915 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
917 Valid values are nil, t, `head', `last', an integer or a predicate.
918 See the manual for details."
919 :group 'gnus-article-treat
920 :type gnus-article-treat-head-custom)
921 (put 'gnus-treat-display-picons 'highlight t)
923 (defcustom gnus-treat-capitalize-sentences nil
924 "Capitalize sentence-starting words.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-custom)
930 (defcustom gnus-treat-fill-long-lines nil
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934 :group 'gnus-article-treat
935 :type gnus-article-treat-custom)
937 (defcustom gnus-treat-play-sounds nil
939 Valid values are nil, t, `head', `last', an integer or a predicate.
940 See the manual for details."
941 :group 'gnus-article-treat
942 :type gnus-article-treat-custom)
944 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
945 "Decode an article as `default-mime-charset'. For instance, if you want to
946 attempt to decode an article even if the value of `gnus-show-mime' is nil,
947 you could set this variable to something like: nil for don't decode, t for
948 decode the body, '(or header t) for the whole article, etc."
949 :group 'gnus-article-treat
950 :type '(radio (const :tag "Off" nil)
951 (const :tag "Decode body" t)
952 (const :tag "Decode all" (or head t))))
954 (defcustom gnus-treat-translate nil
955 "Translate articles from one language to another.
956 Valid values are nil, t, `head', `last', an integer or a predicate.
957 See the manual for details."
958 :group 'gnus-article-treat
959 :type gnus-article-treat-custom)
961 ;;; Internal variables
963 (defvar article-goto-body-goes-to-point-min-p nil)
964 (defvar gnus-article-wash-types nil)
965 (defvar gnus-article-emphasis-alist nil)
967 (defvar gnus-article-mime-handle-alist-1 nil)
968 (defvar gnus-treatment-function-alist
969 '((gnus-treat-decode-article-as-default-mime-charset
970 gnus-article-decode-article-as-default-mime-charset)
971 (gnus-treat-strip-banner gnus-article-strip-banner)
972 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
973 (gnus-treat-buttonize gnus-article-add-buttons)
974 (gnus-treat-fill-article gnus-article-fill-cited-article)
975 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
976 (gnus-treat-strip-cr gnus-article-remove-cr)
977 (gnus-treat-display-xface gnus-article-display-x-face)
978 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
979 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
980 (gnus-treat-hide-signature gnus-article-hide-signature)
981 (gnus-treat-hide-citation gnus-article-hide-citation)
982 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
983 (gnus-treat-strip-pgp gnus-article-hide-pgp)
984 (gnus-treat-strip-pem gnus-article-hide-pem)
985 (gnus-treat-highlight-headers gnus-article-highlight-headers)
986 (gnus-treat-emphasize gnus-article-emphasize)
987 (gnus-treat-highlight-citation gnus-article-highlight-citation)
988 (gnus-treat-highlight-signature gnus-article-highlight-signature)
989 (gnus-treat-date-ut gnus-article-date-ut)
990 (gnus-treat-date-local gnus-article-date-local)
991 (gnus-treat-date-lapsed gnus-article-date-lapsed)
992 (gnus-treat-date-original gnus-article-date-original)
993 (gnus-treat-date-user-defined gnus-article-date-user)
994 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
995 (gnus-treat-strip-trailing-blank-lines
996 gnus-article-remove-trailing-blank-lines)
997 (gnus-treat-strip-leading-blank-lines
998 gnus-article-strip-leading-blank-lines)
999 (gnus-treat-strip-multiple-blank-lines
1000 gnus-article-strip-multiple-blank-lines)
1001 (gnus-treat-overstrike gnus-article-treat-overstrike)
1002 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1003 (gnus-treat-display-smileys gnus-article-smiley-display)
1004 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1005 (gnus-treat-display-picons gnus-article-display-picons)
1006 (gnus-treat-play-sounds gnus-earcon-display)))
1008 (defvar gnus-article-mime-handle-alist nil)
1009 (defvar article-lapsed-timer nil)
1010 (defvar gnus-article-current-summary nil)
1012 (defvar gnus-article-mode-syntax-table
1013 (let ((table (copy-syntax-table text-mode-syntax-table)))
1014 (modify-syntax-entry ?- "w" table)
1015 (modify-syntax-entry ?> ")" table)
1016 (modify-syntax-entry ?< "(" table)
1018 "Syntax table used in article mode buffers.
1019 Initialized from `text-mode-syntax-table.")
1021 (defvar gnus-save-article-buffer nil)
1023 (defvar gnus-article-mode-line-format-alist
1024 (nconc '((?w (gnus-article-wash-status) ?s)
1025 (?m (gnus-article-mime-part-status) ?s))
1026 gnus-summary-mode-line-format-alist))
1028 (defvar gnus-number-of-articles-to-be-saved nil)
1030 (defvar gnus-inhibit-hiding nil)
1032 (defsubst gnus-article-hide-text (b e props)
1033 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1034 (add-text-properties b e props)
1035 (when (memq 'intangible props)
1037 (max (1- b) (point-min))
1038 b 'intangible (cddr (memq 'intangible props)))))
1039 (defsubst gnus-article-unhide-text (b e)
1040 "Remove hidden text properties from region between B and E."
1041 (remove-text-properties b e gnus-hidden-properties)
1042 (when (memq 'intangible gnus-hidden-properties)
1043 (put-text-property (max (1- b) (point-min))
1044 b 'intangible nil)))
1046 (defun gnus-article-hide-text-type (b e type)
1047 "Hide text of TYPE between B and E."
1048 (push type gnus-article-wash-types)
1049 (gnus-article-hide-text
1050 b e (cons 'article-type (cons type gnus-hidden-properties))))
1052 (defun gnus-article-unhide-text-type (b e type)
1053 "Unhide text of TYPE between B and E."
1054 (setq gnus-article-wash-types
1055 (delq type gnus-article-wash-types))
1056 (remove-text-properties
1057 b e (cons 'article-type (cons type gnus-hidden-properties)))
1058 (when (memq 'intangible gnus-hidden-properties)
1059 (put-text-property (max (1- b) (point-min))
1060 b 'intangible nil)))
1062 (defun gnus-article-hide-text-of-type (type)
1063 "Hide text of TYPE in the current buffer."
1065 (let ((b (point-min))
1067 (while (setq b (text-property-any b e 'article-type type))
1068 (add-text-properties b (incf b) gnus-hidden-properties)))))
1070 (defun gnus-article-delete-text-of-type (type)
1071 "Delete text of TYPE in the current buffer."
1073 (let ((b (point-min)))
1074 (while (setq b (text-property-any b (point-max) 'article-type type))
1076 b (or (text-property-not-all b (point-max) 'article-type type)
1079 (defun gnus-article-delete-invisible-text ()
1080 "Delete all invisible text in the current buffer."
1082 (let ((b (point-min)))
1083 (while (setq b (text-property-any b (point-max) 'invisible t))
1085 b (or (text-property-not-all b (point-max) 'invisible t)
1088 (defun gnus-article-text-type-exists-p (type)
1089 "Say whether any text of type TYPE exists in the buffer."
1090 (text-property-any (point-min) (point-max) 'article-type type))
1092 (defsubst gnus-article-header-rank ()
1093 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1094 (let ((list gnus-sorted-header-list)
1097 (when (looking-at (car list))
1099 (setq list (cdr list))
1103 (defun article-hide-headers (&optional arg delete)
1104 "Hide unwanted headers and possibly sort them as well."
1105 (interactive (gnus-article-hidden-arg))
1106 ;; Lars said that this function might be inhibited.
1107 (if (gnus-article-check-hidden-text 'headers arg)
1109 ;; Show boring headers as well.
1110 (gnus-article-show-hidden-text 'boring-headers)
1111 (when (eq 1 (point-min))
1112 (set-window-start (get-buffer-window (current-buffer)) 1)))
1113 (unless gnus-inhibit-hiding
1116 (let ((buffer-read-only nil)
1117 (inhibit-read-only t)
1118 (case-fold-search t)
1119 (max (1+ (length gnus-sorted-header-list)))
1120 (ignored (when (not gnus-visible-headers)
1121 (cond ((stringp gnus-ignored-headers)
1122 gnus-ignored-headers)
1123 ((listp gnus-ignored-headers)
1124 (mapconcat 'identity gnus-ignored-headers
1127 (cond ((stringp gnus-visible-headers)
1128 gnus-visible-headers)
1129 ((and gnus-visible-headers
1130 (listp gnus-visible-headers))
1131 (mapconcat 'identity gnus-visible-headers "\\|"))))
1132 (inhibit-point-motion-hooks t)
1134 ;; First we narrow to just the headers.
1135 (article-narrow-to-head)
1136 ;; Hide any "From " lines at the beginning of (mail) articles.
1137 (while (looking-at "From ")
1141 (delete-region (point-min) (point))
1142 (gnus-article-hide-text (point-min) (point)
1143 (nconc (list 'article-type 'headers)
1144 gnus-hidden-properties))))
1145 ;; Then treat the rest of the header lines.
1146 ;; Then we use the two regular expressions
1147 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1148 ;; select which header lines is to remain visible in the
1150 (while (re-search-forward "^[^ \t]*:" nil t)
1152 ;; Mark the rank of the header.
1154 (point) (1+ (point)) 'message-rank
1155 (if (or (and visible (looking-at visible))
1157 (not (looking-at ignored))))
1158 (gnus-article-header-rank)
1161 (message-sort-headers-1)
1162 (when (setq beg (text-property-any
1163 (point-min) (point-max) 'message-rank (+ 2 max)))
1164 ;; We delete or make invisible the unwanted headers.
1165 (push 'headers gnus-article-wash-types)
1168 (add-text-properties
1169 (point-min) (+ 5 (point-min))
1170 '(article-type headers dummy-invisible t))
1171 (delete-region beg (point-max)))
1172 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1175 (defun article-hide-boring-headers (&optional arg)
1176 "Toggle hiding of headers that aren't very interesting.
1177 If given a negative prefix, always show; if given a positive prefix,
1179 (interactive (gnus-article-hidden-arg))
1180 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1181 (not gnus-show-all-headers))
1184 (let ((buffer-read-only nil)
1185 (list gnus-boring-article-headers)
1186 (inhibit-point-motion-hooks t)
1188 (article-narrow-to-head)
1190 (setq elem (pop list))
1191 (goto-char (point-min))
1193 ;; Hide empty headers.
1195 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1197 (gnus-article-hide-text-type
1198 (progn (beginning-of-line) (point))
1201 (if (re-search-forward "^[^ \t]" nil t)
1205 ;; Hide boring Newsgroups header.
1206 ((eq elem 'newsgroups)
1207 (when (equal (gnus-fetch-field "newsgroups")
1208 (gnus-group-real-name
1209 (if (boundp 'gnus-newsgroup-name)
1212 (gnus-article-hide-header "newsgroups")))
1213 ((eq elem 'followup-to)
1214 (when (equal (message-fetch-field "followup-to")
1215 (message-fetch-field "newsgroups"))
1216 (gnus-article-hide-header "followup-to")))
1217 ((eq elem 'reply-to)
1218 (let ((from (message-fetch-field "from"))
1219 (reply-to (message-fetch-field "reply-to")))
1224 (nth 1 (funcall gnus-extract-address-components from))
1225 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1226 (gnus-article-hide-header "reply-to"))))
1228 (let ((date (message-fetch-field "date")))
1230 (< (days-between (current-time-string) date)
1232 (gnus-article-hide-header "date"))))
1234 (let ((to (message-fetch-field "to"))
1235 (cc (message-fetch-field "cc")))
1236 (when (> (length to) 1024)
1237 (gnus-article-hide-header "to"))
1238 (when (> (length cc) 1024)
1239 (gnus-article-hide-header "cc"))))
1243 (goto-char (point-min))
1244 (while (re-search-forward "^to:" nil t)
1245 (setq to-count (1+ to-count)))
1246 (when (> to-count 1)
1247 (while (> to-count 0)
1248 (goto-char (point-min))
1250 (re-search-forward "^to:" nil nil to-count)
1252 (narrow-to-region (point) (point-max))
1253 (gnus-article-hide-header "to"))
1254 (setq to-count (1- to-count))))
1255 (goto-char (point-min))
1256 (while (re-search-forward "^cc:" nil t)
1257 (setq cc-count (1+ cc-count)))
1258 (when (> cc-count 1)
1259 (while (> cc-count 0)
1260 (goto-char (point-min))
1262 (re-search-forward "^cc:" nil nil cc-count)
1264 (narrow-to-region (point) (point-max))
1265 (gnus-article-hide-header "cc"))
1266 (setq cc-count (1- cc-count)))))))))))))
1268 (defun gnus-article-hide-header (header)
1270 (goto-char (point-min))
1271 (when (re-search-forward (concat "^" header ":") nil t)
1272 (gnus-article-hide-text-type
1273 (progn (beginning-of-line) (point))
1276 (if (re-search-forward "^[^ \t]" nil t)
1281 (defun article-toggle-headers (&optional arg)
1282 "Toggle hiding of headers. If given a negative prefix, always show;
1283 if given a positive prefix, always hide."
1284 (interactive (gnus-article-hidden-arg))
1285 (let ((force (when (numberp arg)
1286 (cond ((> arg 0) 'always-hide)
1287 ((< arg 0) 'always-show))))
1288 (window (get-buffer-window gnus-article-buffer))
1289 (header-end (point-min))
1290 header-start field-end field-start
1291 (inhibit-point-motion-hooks t)
1292 (inhibit-read-only t)
1296 (while (and (setq header-start
1297 (text-property-any header-end (point-max)
1298 'article-treated-header t))
1300 (text-property-not-all header-start (point-max)
1301 'article-treated-header t)))
1302 (setq field-end header-start)
1304 (;; Hide exposed invisible fields.
1305 (and (not (eq 'always-show force))
1307 (text-property-any field-end header-end
1308 'exposed-invisible-field t)))
1309 (while (and field-start
1310 (setq field-end (text-property-not-all
1311 field-start header-end
1312 'exposed-invisible-field t)))
1313 (add-text-properties field-start field-end gnus-hidden-properties)
1314 (setq field-start (text-property-any field-end header-end
1315 'exposed-invisible-field t)))
1316 (put-text-property header-start header-end
1317 'exposed-invisible-field nil))
1318 (;; Expose invisible fields.
1319 (and (not (eq 'always-hide force))
1321 (text-property-any field-end header-end 'invisible t)))
1322 (while (and field-start
1323 (setq field-end (text-property-not-all
1324 field-start header-end
1326 ;; If the invisible text is not terminated with newline, we
1327 ;; won't expose it. Because it may be created by x-face-mule.
1328 ;; BTW, XEmacs sometimes fail in putting a invisible text
1329 ;; property with `gnus-article-hide-text' (really?). In that
1330 ;; case, the invisible text might be started from the middle of
1331 ;; a line so we will expose the sort of thing.
1332 (when (or (not (or (eq header-start field-start)
1333 (eq ?\n (char-before field-start))))
1334 (eq ?\n (char-before field-end)))
1335 (remove-text-properties field-start field-end
1336 gnus-hidden-properties)
1337 (put-text-property field-start field-end
1338 'exposed-invisible-field t))
1339 (setq field-start (text-property-any field-end header-end
1342 (not (eq 'always-show force))
1343 (narrow-to-region header-start header-end)
1344 (article-hide-headers)
1345 ;; Re-display X-Face image under XEmacs.
1346 (when (and gnus-xemacs
1347 (gnus-functionp gnus-article-x-face-command))
1348 (let ((func (cadr (assq 'gnus-treat-display-xface
1349 gnus-treatment-function-alist)))
1351 (when (and (not gnus-inhibit-treatment)
1353 (gnus-treat-predicate gnus-treat-display-xface))
1355 (put-text-property header-start header-end 'read-only nil))))
1358 (goto-char (point-min))
1360 (set-window-start window (point-min))))))
1362 (defvar gnus-article-normalized-header-length 40
1363 "Length of normalized headers.")
1365 (defun article-normalize-headers ()
1366 "Make all header lines 40 characters long."
1368 (let ((buffer-read-only nil)
1372 (article-narrow-to-head)
1375 ((< (setq column (- (gnus-point-at-eol) (point)))
1376 gnus-article-normalized-header-length)
1378 (insert (make-string
1379 (- gnus-article-normalized-header-length column)
1381 ((> column gnus-article-normalized-header-length)
1382 (gnus-put-text-property
1384 (forward-char gnus-article-normalized-header-length)
1391 (forward-line 1))))))
1393 (defun article-treat-dumbquotes ()
1394 "Translate M******** sm*rtq**t*s into proper text.
1395 Note that this function guesses whether a character is a sm*rtq**t* or
1396 not, so it should only be used interactively."
1398 (article-translate-strings gnus-article-dumbquotes-map))
1400 (defun article-translate-characters (from to)
1401 "Translate all characters in the body of the article according to FROM and TO.
1402 FROM is a string of characters to translate from; to is a string of
1403 characters to translate to."
1405 (when (article-goto-body)
1406 (let ((buffer-read-only nil)
1407 (x (make-string 225 ?x))
1409 (while (< (incf i) (length x))
1412 (while (< i (length from))
1413 (aset x (aref from i) (aref to i))
1415 (translate-region (point) (point-max) x)))))
1417 (defun article-translate-strings (map)
1418 "Translate all string in the body of the article according to MAP.
1419 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1421 (when (article-goto-body)
1422 (let ((buffer-read-only nil)
1424 (while (setq elem (pop map))
1426 (while (search-forward (car elem) nil t)
1427 (replace-match (cadr elem)))))))))
1429 (defun article-treat-overstrike ()
1430 "Translate overstrikes into bold text."
1433 (when (article-goto-body)
1434 (let ((buffer-read-only nil))
1435 (while (search-forward "\b" nil t)
1436 (let ((next (char-after))
1440 previous (char-after))
1444 ;; We do the boldification/underlining by hiding the
1445 ;; overstrikes and putting the proper text property
1449 (gnus-article-hide-text-type start (point) 'overstrike)
1450 (put-text-property (point) end 'face 'bold))
1452 (gnus-article-hide-text-type
1453 (1- (point)) (1+ (point)) 'overstrike)
1455 start (1- (point)) 'face 'underline))
1457 (gnus-article-hide-text-type start (point) 'overstrike)
1459 (point) end 'face 'underline)))))))))
1461 (defun article-fill-long-lines ()
1462 "Fill lines that are wider than the window width."
1465 (let ((buffer-read-only nil)
1466 (width (window-width (get-buffer-window (current-buffer)))))
1469 (let ((adaptive-fill-mode nil))
1472 (when (>= (current-column) (min fill-column width))
1473 (narrow-to-region (point) (gnus-point-at-bol))
1474 (fill-paragraph nil)
1475 (goto-char (point-max))
1477 (forward-line 1)))))))
1479 (defun article-capitalize-sentences ()
1480 "Capitalize the first word in each sentence."
1483 (let ((buffer-read-only nil)
1484 (paragraph-start "^[\n\^L]"))
1488 (forward-sentence)))))
1490 (defun article-remove-cr ()
1491 "Remove trailing CRs and then translate remaining CRs into LFs."
1494 (let ((buffer-read-only nil))
1495 (goto-char (point-min))
1496 (while (re-search-forward "\r+$" nil t)
1497 (replace-match "" t t))
1498 (goto-char (point-min))
1499 (while (search-forward "\r" nil t)
1500 (replace-match "\n" t t)))))
1502 (defun article-remove-trailing-blank-lines ()
1503 "Remove all trailing blank lines from the article."
1506 (let ((buffer-read-only nil))
1507 (goto-char (point-max))
1511 (while (and (not (bobp))
1512 (looking-at "^[ \t]*$")
1513 (not (gnus-annotation-in-region-p
1514 (point) (gnus-point-at-eol))))
1519 (defun article-display-x-face (&optional force)
1520 "Look for an X-Face header and display it if present."
1521 (interactive (list 'force))
1523 ;; Delete the old process, if any.
1524 (when (process-status "article-x-face")
1525 (delete-process "article-x-face"))
1526 (let ((inhibit-point-motion-hooks t)
1527 (case-fold-search t)
1530 (article-narrow-to-head)
1531 (goto-char (point-min))
1532 (setq from (message-fetch-field "from"))
1533 (goto-char (point-min))
1534 (while (and gnus-article-x-face-command
1537 ;; Check whether this face is censored.
1538 (not gnus-article-x-face-too-ugly)
1539 (and gnus-article-x-face-too-ugly from
1540 (not (string-match gnus-article-x-face-too-ugly
1542 ;; Has to be present.
1543 (re-search-forward "^X-Face:[ \t]*" nil t))
1544 ;; This used to try to do multiple faces (`while' instead of
1545 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1546 ;; work (b) it can crash some versions of Emacs (c) are
1547 ;; multiple faces really something to encourage?
1548 (when (stringp gnus-article-x-face-command)
1550 ;; We now have the area of the buffer where the X-Face is stored.
1553 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1554 ;; We display the face.
1555 (if (symbolp gnus-article-x-face-command)
1556 ;; The command is a lisp function, so we call it.
1557 (if (gnus-functionp gnus-article-x-face-command)
1558 (funcall gnus-article-x-face-command beg end)
1559 (error "%s is not a function" gnus-article-x-face-command))
1560 ;; The command is a string, so we interpret the command
1561 ;; as a, well, command, and fork it off.
1562 (let ((process-connection-type nil))
1563 (process-kill-without-query
1565 "article-x-face" nil shell-file-name shell-command-switch
1566 gnus-article-x-face-command))
1567 (process-send-region "article-x-face" beg end)
1568 (process-send-eof "article-x-face"))))))))))
1570 (defun article-decode-mime-words ()
1571 "Decode all MIME-encoded words in the article."
1574 (set-buffer gnus-article-buffer)
1575 (let ((inhibit-point-motion-hooks t)
1577 (mail-parse-charset gnus-newsgroup-charset)
1578 (mail-parse-ignored-charsets
1579 (save-excursion (set-buffer gnus-summary-buffer)
1580 gnus-newsgroup-ignored-charsets)))
1581 (mail-decode-encoded-word-region (point-min) (point-max)))))
1583 (defun article-decode-charset (&optional prompt)
1584 "Decode charset-encoded text in the article.
1585 If PROMPT (the prefix), prompt for a coding system to use."
1587 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1589 (mail-parse-charset gnus-newsgroup-charset)
1590 (mail-parse-ignored-charsets
1591 (save-excursion (condition-case nil
1592 (set-buffer gnus-summary-buffer)
1594 gnus-newsgroup-ignored-charsets))
1598 (article-narrow-to-head)
1599 (setq ct (message-fetch-field "Content-Type" t)
1600 cte (message-fetch-field "Content-Transfer-Encoding" t)
1601 ctl (and ct (ignore-errors
1602 (mail-header-parse-content-type ct)))
1605 (mm-read-coding-system "Charset to decode: "))
1607 (mail-content-type-get ctl 'charset))))
1609 (setq cte (mail-header-strip cte)))
1610 (if (and ctl (not (string-match "/" (car ctl))))
1612 (goto-char (point-max)))
1615 (narrow-to-region (point) (point-max))
1616 (when (and (or (not ctl)
1617 (equal (car ctl) "text/plain")))
1619 charset (and cte (intern (downcase
1620 (gnus-strip-whitespace cte))))
1623 (defun article-decode-encoded-words ()
1624 "Remove encoded-word encoding from headers."
1625 (let (buffer-read-only)
1626 (let ((charset (save-excursion
1627 (set-buffer gnus-summary-buffer)
1628 default-mime-charset)))
1629 (mime-decode-header-in-buffer charset)
1632 (defun article-de-quoted-unreadable (&optional force)
1633 "Translate a quoted-printable-encoded article.
1634 If FORCE, decode the article whether it is marked as quoted-printable
1636 (interactive (list 'force))
1638 (let ((buffer-read-only nil)
1639 (type (gnus-fetch-field "content-transfer-encoding"))
1640 (charset gnus-newsgroup-charset))
1642 (and type (string-match "quoted-printable" (downcase type))))
1644 (quoted-printable-decode-region (point) (point-max) charset)))))
1649 (defun article-decode-HZ ()
1650 "Translate a HZ-encoded article."
1654 (let ((buffer-read-only nil))
1655 (rfc1843-decode-region (point-min) (point-max)))))
1657 (defun article-hide-list-identifiers ()
1658 "Remove list identifies from the Subject header.
1659 The `gnus-list-identifiers' variable specifies what to do."
1663 (let ((inhibit-point-motion-hooks t)
1665 (article-narrow-to-head)
1666 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1667 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1669 (goto-char (point-min))
1670 (when (re-search-forward
1671 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1673 (delete-region (match-beginning 2) (match-end 0)))))))))
1675 (defun article-hide-pgp ()
1676 "Remove any PGP headers and signatures in the current article."
1680 (let ((inhibit-point-motion-hooks t)
1681 buffer-read-only beg end)
1683 ;; Hide the "header".
1684 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1685 (push 'pgp gnus-article-wash-types)
1686 (delete-region (match-beginning 0) (match-end 0))
1687 ;; Remove armor headers (rfc2440 6.2)
1688 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1691 ;; Hide the actual signature.
1692 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1693 (setq end (1+ (match-beginning 0)))
1696 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1698 ;; Perhaps we shouldn't hide to the end of the buffer
1699 ;; if there is no end to the signature?
1701 ;; Hide "- " PGP quotation markers.
1703 (narrow-to-region beg end)
1704 (goto-char (point-min))
1705 (while (re-search-forward "^- " nil t)
1707 (match-beginning 0) (match-end 0)))
1709 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1711 (defun article-hide-pem (&optional arg)
1712 "Toggle hiding of any PEM headers and signatures in the current article.
1713 If given a negative prefix, always show; if given a positive prefix,
1715 (interactive (gnus-article-hidden-arg))
1716 (unless (gnus-article-check-hidden-text 'pem arg)
1718 (let (buffer-read-only end)
1719 (goto-char (point-min))
1720 ;; Hide the horrendously ugly "header".
1721 (when (and (search-forward
1722 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1724 (setq end (1+ (match-beginning 0))))
1725 (push 'pem gnus-article-wash-types)
1726 (gnus-article-hide-text-type
1728 (if (search-forward "\n\n" nil t)
1732 ;; Hide the trailer as well
1733 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1735 (gnus-article-hide-text-type
1736 (match-beginning 0) (match-end 0) 'pem)))))))
1738 (defun article-strip-banner ()
1739 "Strip the banner specified by the `banner' group parameter."
1743 (let ((inhibit-point-motion-hooks t)
1744 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1745 (gnus-signature-limit nil)
1746 buffer-read-only beg end)
1750 ((eq banner 'signature)
1751 (when (gnus-article-narrow-to-signature)
1754 (delete-region (point) (point-max))))
1756 (while (re-search-forward banner nil t)
1757 (delete-region (match-beginning 0) (match-end 0))))))))))
1759 (defun article-babel ()
1760 "Translate article using an online translation service."
1764 (set-buffer gnus-article-buffer)
1765 (when (article-goto-body)
1766 (let* ((buffer-read-only nil)
1769 (orig (buffer-substring start end))
1770 (trans (babel-as-string orig)))
1772 (narrow-to-region start end)
1773 (delete-region start end)
1776 (defun article-hide-signature (&optional arg)
1777 "Hide the signature in the current article.
1778 If given a negative prefix, always show; if given a positive prefix,
1780 (interactive (gnus-article-hidden-arg))
1786 (article-goto-body))
1787 (goto-char (point-min)))
1788 (unless (gnus-article-check-hidden-text 'signature arg)
1789 (let ((buffer-read-only nil)
1791 (while (setq button (text-property-any button (point-max)
1793 'gnus-signature-toggle))
1794 (setq button (text-property-not-all button (point-max)
1796 'gnus-signature-toggle))
1797 (when (and button (not (eobp)))
1798 (gnus-article-hide-text-type
1800 (next-single-property-change (1+ button) 'mime-view-entity
1804 (defun article-strip-headers-in-body ()
1805 "Strip offensive headers from bodies."
1809 (let ((case-fold-search t))
1810 (when (looking-at "x-no-archive:")
1811 (gnus-delete-line)))))
1813 (defun article-strip-leading-blank-lines ()
1814 "Remove all blank lines from the beginning of the article."
1817 (let ((inhibit-point-motion-hooks t)
1819 (when (article-goto-body)
1820 (while (and (not (eobp))
1821 (looking-at "[ \t]*$"))
1822 (gnus-delete-line))))))
1824 (defun article-narrow-to-head ()
1825 "Narrow the buffer to the head of the message.
1826 Point is left at the beginning of the narrowed-to region."
1828 (goto-char (point-min))
1829 (if (search-forward "\n\n" nil 1)
1832 (goto-char (point-min)))
1834 (defun article-goto-body ()
1835 "Place point at the start of the body."
1836 (goto-char (point-min))
1838 ;; This variable is only bound when dealing with separate
1840 (article-goto-body-goes-to-point-min-p
1842 ((search-forward "\n\n" nil t)
1845 (goto-char (point-max))
1848 (defun article-strip-multiple-blank-lines ()
1849 "Replace consecutive blank lines with one empty line."
1852 (let ((inhibit-point-motion-hooks t)
1854 ;; First make all blank lines empty.
1856 (while (re-search-forward "^[ \t]+$" nil t)
1857 (unless (gnus-annotation-in-region-p
1858 (match-beginning 0) (match-end 0))
1859 (replace-match "" nil t)))
1860 ;; Then replace multiple empty lines with a single empty line.
1862 (while (re-search-forward "\n\n\n+" nil t)
1863 (unless (gnus-annotation-in-region-p
1864 (match-beginning 0) (match-end 0))
1865 (replace-match "\n\n" t t))))))
1867 (defun article-strip-leading-space ()
1868 "Remove all white space from the beginning of the lines in the article."
1871 (let ((inhibit-point-motion-hooks t)
1874 (while (re-search-forward "^[ \t]+" nil t)
1875 (replace-match "" t t)))))
1877 (defun article-strip-trailing-space ()
1878 "Remove all white space from the end of the lines in the article."
1881 (let ((inhibit-point-motion-hooks t)
1884 (while (re-search-forward "[ \t]+$" nil t)
1885 (replace-match "" t t)))))
1887 (defun article-strip-blank-lines ()
1888 "Strip leading, trailing and multiple blank lines."
1890 (article-strip-leading-blank-lines)
1891 (article-remove-trailing-blank-lines)
1892 (article-strip-multiple-blank-lines))
1894 (defun article-strip-all-blank-lines ()
1895 "Strip all blank lines."
1898 (let ((inhibit-point-motion-hooks t)
1901 (while (re-search-forward "^[ \t]*\n" nil t)
1902 (replace-match "" t t)))))
1904 (defun gnus-article-narrow-to-signature ()
1905 "Narrow to the signature; return t if a signature is found, else nil."
1906 (let ((inhibit-point-motion-hooks t))
1907 (when (gnus-article-search-signature)
1909 ;; Check whether we have some limits to what we consider
1910 ;; to be a signature.
1911 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1912 (list gnus-signature-limit)))
1914 (while (setq limit (pop limits))
1915 (if (or (and (integerp limit)
1916 (< (- (point-max) (point)) limit))
1918 (< (count-lines (point) (point-max)) limit))
1919 (and (gnus-functionp limit)
1921 (and (stringp limit)
1922 (not (re-search-forward limit nil t))))
1923 () ; This limit did not succeed.
1927 (narrow-to-region (point) (point-max))
1930 (defun gnus-article-search-signature ()
1931 "Search the current buffer for the signature separator.
1932 Put point at the beginning of the signature separator."
1933 (let ((cur (point)))
1934 (goto-char (point-max))
1935 (if (if (stringp gnus-signature-separator)
1936 (re-search-backward gnus-signature-separator nil t)
1937 (let ((seps gnus-signature-separator))
1939 (not (re-search-backward (car seps) nil t)))
1946 (defun gnus-article-hidden-arg ()
1947 "Return the current prefix arg as a number, or 0 if no prefix."
1948 (list (if current-prefix-arg
1949 (prefix-numeric-value current-prefix-arg)
1952 (defun gnus-article-check-hidden-text (type arg)
1953 "Return nil if hiding is necessary.
1954 Arg can be nil or a number. Nil and positive means hide, negative
1955 means show, 0 means toggle."
1958 (let ((hide (gnus-article-hidden-text-p type)))
1964 (gnus-article-show-hidden-text type))
1966 (if (eq hide 'hidden)
1967 (gnus-article-show-hidden-text type)
1970 (defun gnus-article-hidden-text-p (type)
1971 "Say whether the current buffer contains hidden text of type TYPE."
1972 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1974 (not (get-text-property pos 'invisible))
1975 (not (get-text-property pos 'dummy-invisible)))
1977 (text-property-any (1+ pos) (point-max) 'article-type type)))
1982 (defun gnus-article-show-hidden-text (type &optional hide)
1983 "Show all hidden text of type TYPE.
1984 If HIDE, hide the text instead."
1986 (let ((buffer-read-only nil)
1987 (inhibit-point-motion-hooks t)
1990 (while (setq beg (text-property-any end (point-max) 'article-type type))
1993 (text-property-not-all beg (point-max) 'article-type type)
1996 (gnus-article-hide-text beg end gnus-hidden-properties)
1997 (gnus-article-unhide-text beg end))
2001 (defconst article-time-units
2002 `((year . ,(* 365.25 24 60 60))
2003 (week . ,(* 7 24 60 60))
2004 (day . ,(* 24 60 60))
2008 "Mapping from time units to seconds.")
2010 (defun article-date-ut (&optional type highlight header)
2011 "Convert DATE date to universal time in the current article.
2012 If TYPE is `local', convert to local time; if it is `lapsed', output
2013 how much time has lapsed since DATE. For `lapsed', the value of
2014 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2015 should replace the \"Date:\" one, or should be added below it."
2016 (interactive (list 'ut t))
2017 (let* ((header (or header
2018 (and (eq 1 (point-min))
2019 (mail-header-date (save-excursion
2020 (set-buffer gnus-summary-buffer)
2021 gnus-current-headers)))
2022 (message-fetch-field "date")
2024 (date (if (vectorp header) (mail-header-date header)
2026 (inhibit-point-motion-hooks t)
2027 bface eface date-pos)
2028 (when (and date (not (string= date "")))
2031 (article-narrow-to-head)
2032 (when (or (and (eq type 'lapsed)
2033 gnus-article-date-lapsed-new-header
2034 ;; Attempt to get the face of X-Sent first.
2035 (re-search-forward "^X-Sent:[ \t]" nil t))
2036 (re-search-forward "^Date:[ \t]" nil t)
2037 ;; If Date is missing, try again for X-Sent.
2038 (re-search-forward "^X-Sent:[ \t]" nil t))
2039 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2040 date (or (get-text-property (gnus-point-at-bol)
2043 eface (get-text-property (1- (gnus-point-at-eol))
2045 (let ((buffer-read-only nil))
2046 ;; Delete any old X-Sent headers.
2047 (when (setq date-pos
2048 (text-property-any (point-min) (point-max)
2049 'article-date-lapsed t))
2050 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2051 (delete-region (match-beginning 0)
2052 (progn (forward-line 1) (point))))
2053 (goto-char (point-min))
2054 ;; Delete any old Date headers.
2055 (while (re-search-forward "^Date:[ \t]" nil t)
2057 (setq date-pos (match-beginning 0)))
2058 (unless (and (eq type 'lapsed)
2059 gnus-article-date-lapsed-new-header)
2060 (delete-region (match-beginning 0)
2061 (progn (message-next-header) (point)))))
2064 (goto-char date-pos)
2066 ;; Possibly, Date has been deleted.
2068 (when (and (eq type 'lapsed)
2069 gnus-article-date-lapsed-new-header
2070 (looking-at "Date:"))
2072 (goto-char (point-min)))
2073 (insert (article-make-date-line date type))
2074 (when (eq type 'lapsed)
2075 (put-text-property (gnus-point-at-bol) (point)
2076 'article-date-lapsed t))
2080 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2081 (put-text-property (match-beginning 1) (1+ (match-end 1))
2082 'original-date date)
2083 (put-text-property (match-beginning 1) (1+ (match-end 1))
2085 (put-text-property (match-beginning 2) (match-end 2)
2088 (defun article-make-date-line (date type)
2089 "Return a DATE line of TYPE."
2090 (let ((time (condition-case ()
2094 ;; Convert to the local timezone. We have to slap a
2095 ;; `condition-case' round the calls to the timezone
2096 ;; functions since they aren't particularly resistant to
2099 (let ((tz (car (current-time-zone time))))
2100 (format "Date: %s %s%02d%02d" (current-time-string time)
2101 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2102 (/ (% (abs tz) 3600) 60))))
2103 ;; Convert to Universal Time.
2106 (current-time-string
2107 (let* ((e (parse-time-string date))
2108 (tm (apply 'encode-time e))
2110 (ls (- (cadr tm) (car (current-time-zone time)))))
2111 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2112 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2115 ;; Get the original date from the article.
2116 ((eq type 'original)
2117 (concat "Date: " (if (string-match "\n+$" date)
2118 (substring date 0 (match-beginning 0))
2120 ;; Let the user define the format.
2122 (if (gnus-functionp gnus-article-time-format)
2123 (funcall gnus-article-time-format time)
2126 (format-time-string gnus-article-time-format time))))
2129 (let ((tz (car (current-time-zone time))))
2132 (format-time-string "%Y%m%dT%H%M%S" time)
2133 (format "%s%02d%02d"
2134 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2135 (/ (% (abs tz) 3600) 60)))))
2136 ;; Do an X-Sent lapsed format.
2138 ;; If the date is seriously mangled, the timezone functions are
2139 ;; liable to bug out, so we ignore all errors.
2140 (let* ((now (current-time))
2141 (real-time (subtract-time now time))
2142 (real-sec (and real-time
2143 (+ (* (float (car real-time)) 65536)
2145 (sec (and real-time (abs real-sec)))
2155 ;; This is a bit convoluted, but basically we go
2156 ;; through the time units for years, weeks, etc,
2157 ;; and divide things to see whether that results
2158 ;; in positive answers.
2161 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2162 ;; The (remaining) seconds are too few to
2163 ;; be divided into this time unit.
2165 ;; It's big enough, so we output it.
2166 (setq sec (- sec (* num (cdr unit))))
2168 (concat (if prev ", " "") (int-to-string
2170 " " (symbol-name (car unit))
2171 (if (> num 1) "s" ""))
2173 article-time-units "")
2174 ;; If dates are odd, then it might appear like the
2175 ;; article was sent in the future.
2178 " in the future"))))))
2180 (error "Unknown conversion type: %s" type)))))
2182 (defun article-date-local (&optional highlight)
2183 "Convert the current article date to the local timezone."
2184 (interactive (list t))
2185 (article-date-ut 'local highlight))
2187 (defun article-date-original (&optional highlight)
2188 "Convert the current article date to what it was originally.
2189 This is only useful if you have used some other date conversion
2190 function and want to see what the date was before converting."
2191 (interactive (list t))
2192 (article-date-ut 'original highlight))
2194 (defun article-date-lapsed (&optional highlight)
2195 "Convert the current article date to time lapsed since it was sent."
2196 (interactive (list t))
2197 (article-date-ut 'lapsed highlight))
2199 (defun article-update-date-lapsed ()
2200 "Function to be run from a timer to update the lapsed time line."
2201 (let (deactivate-mark)
2206 (set-buffer (window-buffer w))
2207 (when (eq major-mode 'gnus-article-mode)
2208 (goto-char (point-min))
2209 (when (re-search-forward "^X-Sent:" nil t)
2210 (article-date-lapsed t))))
2213 (defun gnus-start-date-timer (&optional n)
2214 "Start a timer to update the X-Sent header in the article buffers.
2215 The numerical prefix says how frequently (in seconds) the function
2220 (gnus-stop-date-timer)
2221 (setq article-lapsed-timer
2222 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2224 (defun gnus-stop-date-timer ()
2225 "Stop the X-Sent timer."
2227 (when article-lapsed-timer
2228 (nnheader-cancel-timer article-lapsed-timer)
2229 (setq article-lapsed-timer nil)))
2231 (defun article-date-user (&optional highlight)
2232 "Convert the current article date to the user-defined format.
2233 This format is defined by the `gnus-article-time-format' variable."
2234 (interactive (list t))
2235 (article-date-ut 'user highlight))
2237 (defun article-date-iso8601 (&optional highlight)
2238 "Convert the current article date to ISO8601."
2239 (interactive (list t))
2240 (article-date-ut 'iso8601 highlight))
2242 (defun article-show-all ()
2243 "Show all hidden text in the article buffer."
2247 (let ((buffer-read-only nil))
2248 (gnus-article-unhide-text (point-min) (point-max))
2249 (gnus-remove-text-with-property 'gnus-prev)
2250 (gnus-remove-text-with-property 'gnus-next))))
2252 (defun article-show-all-headers ()
2253 "Show all hidden headers in the article buffer."
2258 (article-narrow-to-head)
2259 (let ((buffer-read-only nil))
2260 (gnus-article-unhide-text (point-min) (point-max))))))
2262 (defun article-emphasize (&optional arg)
2263 "Emphasize text according to `gnus-emphasis-alist'."
2264 (interactive (gnus-article-hidden-arg))
2265 (unless (gnus-article-check-hidden-text 'emphasis arg)
2269 (with-current-buffer gnus-summary-buffer
2270 gnus-article-emphasis-alist)
2272 gnus-emphasis-alist))
2273 (buffer-read-only nil)
2274 (props (append '(article-type emphasis)
2275 gnus-hidden-properties))
2276 regexp elem beg invisible visible face)
2279 (while (setq elem (pop alist))
2281 (setq regexp (car elem)
2282 invisible (nth 1 elem)
2283 visible (nth 2 elem)
2285 (while (re-search-forward regexp nil t)
2286 (when (and (match-beginning visible) (match-beginning invisible))
2287 (push 'emphasis gnus-article-wash-types)
2288 (gnus-article-hide-text
2289 (match-beginning invisible) (match-end invisible) props)
2290 (gnus-article-unhide-text-type
2291 (match-beginning visible) (match-end visible) 'emphasis)
2292 (gnus-put-text-property-excluding-newlines
2293 (match-beginning visible) (match-end visible) 'face face)
2294 (goto-char (match-end invisible)))))))))
2296 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2297 "Setup newsgroup emphasis alist."
2298 (unless gnus-article-emphasis-alist
2299 (let ((name (and gnus-newsgroup-name
2300 (gnus-group-real-name gnus-newsgroup-name))))
2301 (make-local-variable 'gnus-article-emphasis-alist)
2302 (setq gnus-article-emphasis-alist
2304 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2305 (while (setq elem (pop alist))
2306 (when (and name (string-match (car elem) name))
2308 highlight (copy-sequence (cdr elem)))))
2310 (copy-sequence highlight-words)
2311 (if gnus-newsgroup-name
2312 (copy-sequence (gnus-group-find-parameter
2313 gnus-newsgroup-name 'highlight-words t)))
2314 gnus-emphasis-alist)))))
2316 (defvar gnus-summary-article-menu)
2317 (defvar gnus-summary-post-menu)
2319 ;;; Saving functions.
2321 (defun gnus-article-save (save-buffer file &optional num)
2322 "Save the currently selected article."
2323 (unless gnus-save-all-headers
2324 ;; Remove headers according to `gnus-saved-headers'.
2325 (let ((gnus-visible-headers
2326 (or gnus-saved-headers gnus-visible-headers))
2327 (gnus-article-buffer save-buffer))
2329 (set-buffer save-buffer)
2330 (article-hide-headers 1 t))))
2331 (save-window-excursion
2332 (if (not gnus-default-article-saver)
2333 (error "No default saver is defined")
2334 ;; !!! Magic! The saving functions all save
2335 ;; `gnus-save-article-buffer' (or so they think), but we
2336 ;; bind that variable to our save-buffer.
2337 (set-buffer gnus-article-buffer)
2338 (let* ((gnus-save-article-buffer save-buffer)
2341 ((not gnus-prompt-before-saving) 'default)
2342 ((eq gnus-prompt-before-saving 'always) nil)
2344 (gnus-number-of-articles-to-be-saved
2345 (when (eq gnus-prompt-before-saving t)
2347 (set-buffer gnus-article-current-summary)
2348 (funcall gnus-default-article-saver filename)))))
2350 (defun gnus-read-save-file-name (prompt &optional filename
2351 function group headers variable)
2353 (funcall function group headers (symbol-value variable)))
2358 ((eq filename 'default)
2364 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2367 (if (and gnus-number-of-articles-to-be-saved
2368 (> gnus-number-of-articles-to-be-saved 1))
2369 (format "these %d articles"
2370 gnus-number-of-articles-to-be-saved)
2373 ;; Let the split methods have their say.
2375 ;; No split name was found.
2378 (concat prompt " (default "
2379 (file-name-nondirectory default-name) ") ")
2380 (file-name-directory default-name)
2382 ;; A single group name is returned.
2383 ((stringp split-name)
2385 (funcall function split-name headers
2386 (symbol-value variable)))
2388 (concat prompt " (default "
2389 (file-name-nondirectory default-name) ") ")
2390 (file-name-directory default-name)
2392 ;; A single split name was found
2393 ((= 1 (length split-name))
2394 (let* ((name (expand-file-name
2395 (car split-name) gnus-article-save-directory))
2396 (dir (cond ((file-directory-p name)
2397 (file-name-as-directory name))
2398 ((file-exists-p name) name)
2399 (t gnus-article-save-directory))))
2401 (concat prompt " (default " name ") ")
2403 ;; A list of splits was found.
2405 (setq split-name (nreverse split-name))
2407 (let ((file-name-history
2408 (nconc split-name file-name-history)))
2412 (concat prompt " (`M-p' for defaults) ")
2413 gnus-article-save-directory
2415 gnus-article-save-directory)))
2416 (car (push result file-name-history)))))))
2417 ;; Create the directory.
2418 (gnus-make-directory (file-name-directory file))
2419 ;; If we have read a directory, we append the default file name.
2420 (when (file-directory-p file)
2421 (setq file (concat (file-name-as-directory file)
2422 (file-name-nondirectory default-name))))
2423 ;; Possibly translate some characters.
2424 (nnheader-translate-file-chars file)))))
2425 (gnus-make-directory (file-name-directory result))
2426 (set variable result)))
2428 (defun gnus-article-archive-name (group)
2429 "Return the first instance of an \"Archive-name\" in the current buffer."
2430 (let ((case-fold-search t))
2431 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2432 (nnheader-concat gnus-article-save-directory
2433 (match-string 1)))))
2435 (defun gnus-article-nndoc-name (group)
2436 "If GROUP is an nndoc group, return the name of the parent group."
2437 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2438 (gnus-group-get-parameter group 'save-article-group)))
2440 (defun gnus-summary-save-in-rmail (&optional filename)
2441 "Append this article to Rmail file.
2442 Optional argument FILENAME specifies file name.
2443 Directory to save to is default to `gnus-article-save-directory'."
2444 (setq filename (gnus-read-save-file-name
2445 "Save %s in rmail file:" filename
2446 gnus-rmail-save-name gnus-newsgroup-name
2447 gnus-current-headers 'gnus-newsgroup-last-rmail))
2448 (gnus-eval-in-buffer-window gnus-save-article-buffer
2452 (gnus-output-to-rmail filename))))
2455 (defun gnus-summary-save-in-mail (&optional filename)
2456 "Append this article to Unix mail file.
2457 Optional argument FILENAME specifies file name.
2458 Directory to save to is default to `gnus-article-save-directory'."
2459 (setq filename (gnus-read-save-file-name
2460 "Save %s in Unix mail file:" filename
2461 gnus-mail-save-name gnus-newsgroup-name
2462 gnus-current-headers 'gnus-newsgroup-last-mail))
2463 (gnus-eval-in-buffer-window gnus-save-article-buffer
2467 (if (and (file-readable-p filename)
2468 (mail-file-babyl-p filename))
2469 (rmail-output-to-rmail-file filename t)
2470 (gnus-output-to-mail filename)))))
2473 (defun gnus-summary-save-in-file (&optional filename overwrite)
2474 "Append this article to file.
2475 Optional argument FILENAME specifies file name.
2476 Directory to save to is default to `gnus-article-save-directory'."
2477 (setq filename (gnus-read-save-file-name
2478 "Save %s in file:" filename
2479 gnus-file-save-name gnus-newsgroup-name
2480 gnus-current-headers 'gnus-newsgroup-last-file))
2481 (gnus-eval-in-buffer-window gnus-save-article-buffer
2485 (when (and overwrite
2486 (file-exists-p filename))
2487 (delete-file filename))
2488 (gnus-output-to-file filename))))
2491 (defun gnus-summary-write-to-file (&optional filename)
2492 "Write this article to a file.
2493 Optional argument FILENAME specifies file name.
2494 The directory to save in defaults to `gnus-article-save-directory'."
2495 (gnus-summary-save-in-file nil t))
2497 (defun gnus-summary-save-body-in-file (&optional filename)
2498 "Append this article body to a file.
2499 Optional argument FILENAME specifies file name.
2500 The directory to save in defaults to `gnus-article-save-directory'."
2501 (setq filename (gnus-read-save-file-name
2502 "Save %s body in file:" filename
2503 gnus-file-save-name gnus-newsgroup-name
2504 gnus-current-headers 'gnus-newsgroup-last-file))
2505 (gnus-eval-in-buffer-window gnus-save-article-buffer
2509 (when (article-goto-body)
2510 (narrow-to-region (point) (point-max)))
2511 (gnus-output-to-file filename))))
2514 (defun gnus-summary-save-in-pipe (&optional command)
2515 "Pipe this article to subprocess."
2517 (cond ((and (eq command 'default)
2518 gnus-last-shell-command)
2519 gnus-last-shell-command)
2523 "Shell command on %s: "
2524 (if (and gnus-number-of-articles-to-be-saved
2525 (> gnus-number-of-articles-to-be-saved 1))
2526 (format "these %d articles"
2527 gnus-number-of-articles-to-be-saved)
2529 gnus-last-shell-command))))
2530 (when (string-equal command "")
2531 (setq command gnus-last-shell-command))
2532 (gnus-eval-in-buffer-window gnus-article-buffer
2535 (shell-command-on-region (point-min) (point-max) command nil)))
2536 (setq gnus-last-shell-command command))
2538 ;;; Article file names when saving.
2540 (defun gnus-capitalize-newsgroup (newsgroup)
2541 "Capitalize NEWSGROUP name."
2542 (when (not (zerop (length newsgroup)))
2543 (concat (char-to-string (upcase (aref newsgroup 0)))
2544 (substring newsgroup 1))))
2546 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2547 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2548 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2549 Otherwise, it is like ~/News/news/group/num."
2552 (concat (if (gnus-use-long-file-name 'not-save)
2553 (gnus-capitalize-newsgroup newsgroup)
2554 (gnus-newsgroup-directory-form newsgroup))
2555 "/" (int-to-string (mail-header-number headers)))
2556 gnus-article-save-directory)))
2558 (string-equal (file-name-directory default)
2559 (file-name-directory last-file))
2560 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2562 (or last-file default))))
2564 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2565 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2566 If variable `gnus-use-long-file-name' is non-nil, it is
2567 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2570 (concat (if (gnus-use-long-file-name 'not-save)
2572 (gnus-newsgroup-directory-form newsgroup))
2573 "/" (int-to-string (mail-header-number headers)))
2574 gnus-article-save-directory)))
2576 (string-equal (file-name-directory default)
2577 (file-name-directory last-file))
2578 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2580 (or last-file default))))
2582 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2583 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2584 If variable `gnus-use-long-file-name' is non-nil, it is
2585 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2588 (if (gnus-use-long-file-name 'not-save)
2589 (gnus-capitalize-newsgroup newsgroup)
2590 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2591 gnus-article-save-directory)))
2593 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2594 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2595 If variable `gnus-use-long-file-name' is non-nil, it is
2596 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2599 (if (gnus-use-long-file-name 'not-save)
2601 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2602 gnus-article-save-directory)))
2609 (setq afunc (car func)
2612 gfunc (intern (format "gnus-%s" func))))
2614 (if (not (fboundp afunc))
2616 `(lambda (&optional interactive &rest args)
2617 ,(documentation afunc t)
2618 (interactive (list t))
2620 (set-buffer gnus-article-buffer)
2622 (call-interactively ',afunc)
2623 (apply ',afunc args))))))))
2624 '(article-hide-headers
2625 article-hide-boring-headers
2626 article-toggle-headers
2627 article-treat-overstrike
2628 article-fill-long-lines
2629 article-capitalize-sentences
2631 article-display-x-face
2632 article-de-quoted-unreadable
2634 article-hide-list-identifiers
2636 article-strip-banner
2639 article-hide-signature
2640 article-strip-headers-in-body
2641 article-remove-trailing-blank-lines
2642 article-strip-leading-blank-lines
2643 article-strip-multiple-blank-lines
2644 article-strip-leading-space
2645 article-strip-trailing-space
2646 article-strip-blank-lines
2647 article-strip-all-blank-lines
2649 article-date-iso8601
2650 article-date-original
2652 article-decode-mime-words
2653 article-decode-charset
2654 article-decode-encoded-words
2658 article-treat-dumbquotes
2659 article-normalize-headers
2660 (article-show-all-headers . gnus-article-show-all-headers)
2661 (article-show-all . gnus-article-show-all))))
2664 ;;; Gnus article mode
2667 (put 'gnus-article-mode 'mode-class 'special)
2669 (gnus-define-keys gnus-article-mode-map
2670 " " gnus-article-goto-next-page
2671 "\177" gnus-article-goto-prev-page
2672 [delete] gnus-article-goto-prev-page
2673 [backspace] gnus-article-goto-prev-page
2674 "\C-c^" gnus-article-refer-article
2675 "h" gnus-article-show-summary
2676 "s" gnus-article-show-summary
2677 "\C-c\C-m" gnus-article-mail
2678 "?" gnus-article-describe-briefly
2679 "e" gnus-summary-edit-article
2680 "<" beginning-of-buffer
2682 "\C-c\C-i" gnus-info-find-node
2685 "\C-d" gnus-article-read-summary-keys
2686 "\M-*" gnus-article-read-summary-keys
2687 "\M-#" gnus-article-read-summary-keys
2688 "\M-^" gnus-article-read-summary-keys
2689 "\M-g" gnus-article-read-summary-keys)
2691 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2694 (unless (lookup-key gnus-article-mode-map key)
2695 (define-key gnus-article-mode-map key
2696 'gnus-article-read-summary-keys)))
2701 (let ((key (car elt)))
2702 (and (> (length key) 0)
2703 (not (eq 'menu-bar (aref key 0)))
2704 (symbolp (lookup-key gnus-summary-mode-map key))
2706 (accessible-keymaps gnus-summary-mode-map))
2710 (push (char-to-string c) keys)
2714 (defun gnus-article-make-menu-bar ()
2715 (gnus-turn-off-edit-menu 'article)
2716 (unless (boundp 'gnus-article-article-menu)
2718 gnus-article-article-menu gnus-article-mode-map ""
2720 ["Scroll forwards" gnus-article-goto-next-page t]
2721 ["Scroll backwards" gnus-article-goto-prev-page t]
2722 ["Show summary" gnus-article-show-summary t]
2723 ["Fetch Message-ID at point" gnus-article-refer-article t]
2724 ["Mail to address at point" gnus-article-mail t]
2725 ["Send a bug report" gnus-bug t]))
2728 gnus-article-treatment-menu gnus-article-mode-map ""
2730 ["Hide headers" gnus-article-toggle-headers t]
2731 ["Hide signature" gnus-article-hide-signature t]
2732 ["Hide citation" gnus-article-hide-citation t]
2733 ["Treat overstrike" gnus-article-treat-overstrike t]
2734 ["Remove carriage return" gnus-article-remove-cr t]
2735 ["Decode HZ" gnus-article-decode-HZ t]))
2737 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2739 (when (boundp 'gnus-summary-post-menu)
2740 (define-key gnus-article-mode-map [menu-bar post]
2741 (cons "Post" gnus-summary-post-menu)))
2743 (gnus-run-hooks 'gnus-article-menu-hook)))
2745 (defun gnus-article-mode ()
2746 "Major mode for displaying an article.
2748 All normal editing commands are switched off.
2750 The following commands are available in addition to all summary mode
2752 \\<gnus-article-mode-map>
2753 \\[gnus-article-next-page]\t Scroll the article one page forwards
2754 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2755 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2756 \\[gnus-article-show-summary]\t Display the summary buffer
2757 \\[gnus-article-mail]\t Send a reply to the address near point
2758 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2759 \\[gnus-info-find-node]\t Go to the Gnus info node"
2761 (when (gnus-visual-p 'article-menu 'menu)
2762 (gnus-article-make-menu-bar))
2763 (gnus-simplify-mode-line)
2764 (setq mode-name "Article")
2765 (setq major-mode 'gnus-article-mode)
2766 (make-local-variable 'minor-mode-alist)
2767 (unless (assq 'gnus-show-mime minor-mode-alist)
2768 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2769 (use-local-map gnus-article-mode-map)
2770 (gnus-update-format-specifications nil 'article-mode)
2771 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2772 (make-local-variable 'gnus-page-broken)
2773 (make-local-variable 'gnus-button-marker-list)
2774 (make-local-variable 'gnus-article-current-summary)
2775 (make-local-variable 'gnus-article-mime-handles)
2776 (make-local-variable 'gnus-article-decoded-p)
2777 (make-local-variable 'gnus-article-mime-handle-alist)
2778 (make-local-variable 'gnus-article-wash-types)
2779 (gnus-set-default-directory)
2780 (buffer-disable-undo)
2781 (setq buffer-read-only t)
2782 (set-syntax-table gnus-article-mode-syntax-table)
2783 (gnus-run-hooks 'gnus-article-mode-hook))
2785 (defun gnus-article-setup-buffer ()
2786 "Initialize the article buffer."
2787 (let* ((name (if gnus-single-article-buffer "*Article*"
2788 (concat "*Article " gnus-newsgroup-name "*")))
2790 (progn (string-match "\\*Article" name)
2791 (concat " *Original Article"
2792 (substring name (match-end 0))))))
2793 (setq gnus-article-buffer name)
2794 (setq gnus-original-article-buffer original)
2795 (setq gnus-article-mime-handle-alist nil)
2796 ;; This might be a variable local to the summary buffer.
2797 (unless gnus-single-article-buffer
2799 (set-buffer gnus-summary-buffer)
2800 (setq gnus-article-buffer name)
2801 (setq gnus-original-article-buffer original)
2802 (gnus-set-global-variables)))
2803 (gnus-article-setup-highlight-words)
2804 ;; Init original article buffer.
2806 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2807 (setq major-mode 'gnus-original-article-mode)
2808 (make-local-variable 'gnus-original-article))
2809 (if (get-buffer name)
2812 (buffer-disable-undo)
2813 (setq buffer-read-only t)
2814 (unless (eq major-mode 'gnus-article-mode)
2815 (gnus-article-mode))
2818 (set-buffer (gnus-get-buffer-create name))
2820 (make-local-variable 'gnus-summary-buffer)
2821 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2822 (current-buffer)))))
2824 ;; Set article window start at LINE, where LINE is the number of lines
2825 ;; from the head of the article.
2826 (defun gnus-article-set-window-start (&optional line)
2828 (get-buffer-window gnus-article-buffer t)
2830 (set-buffer gnus-article-buffer)
2831 (goto-char (point-min))
2834 (gnus-message 6 "Moved to bookmark")
2835 (search-forward "\n\n" nil t)
2839 ;;; @@ article filters
2842 (defun gnus-article-display-mime-message ()
2843 "Article display method for MIME message."
2844 ;; called from `gnus-original-article-buffer'.
2845 (let (charset all-headers)
2846 (with-current-buffer gnus-summary-buffer
2847 (setq charset default-mime-charset
2848 all-headers gnus-have-all-headers))
2849 (make-local-variable 'default-mime-charset)
2850 (setq default-mime-charset charset)
2851 (with-current-buffer (get-buffer-create gnus-article-buffer)
2852 (make-local-variable 'default-mime-charset)
2853 (setq default-mime-charset charset))
2854 (mime-display-message mime-message-structure
2855 gnus-article-buffer nil gnus-article-mode-map)
2857 (gnus-article-hide-headers nil -1))
2859 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2860 (make-local-variable 'mime-button-mother-dispatcher)
2861 (setq mime-button-mother-dispatcher
2862 (function gnus-article-push-button))
2863 (run-hooks 'gnus-mime-article-prepare-hook))
2865 (defun gnus-article-display-traditional-message ()
2866 "Article display method for traditional message."
2867 (set-buffer gnus-article-buffer)
2868 (let (buffer-read-only)
2870 (insert-buffer-substring gnus-original-article-buffer)))
2872 (defun gnus-article-make-full-mail-header (&optional number charset)
2873 "Create a new mail header structure in a raw article buffer."
2874 (unless (and number charset)
2875 (save-current-buffer
2876 (set-buffer gnus-summary-buffer)
2878 (setq number (or (cdr gnus-article-current) 0)))
2880 (setq charset (or default-mime-charset 'x-ctext)))))
2881 (goto-char (point-min))
2882 (let ((header-end (if (search-forward "\n\n" nil t)
2884 (goto-char (point-max))))
2885 (chars (- (point-max) (point)))
2886 (lines (count-lines (point) (point-max)))
2887 (default-mime-charset charset)
2889 (narrow-to-region (point-min) header-end)
2890 (setq xref (std11-fetch-field "xref"))
2892 (make-full-mail-header
2894 (std11-fetch-field "subject")
2895 (std11-fetch-field "from")
2896 (std11-fetch-field "date")
2897 (std11-fetch-field "message-id")
2898 (std11-fetch-field "references")
2901 (when xref (concat "Xref: " xref)))
2904 (defun gnus-article-prepare (article &optional all-headers header)
2905 "Prepare ARTICLE in article mode buffer.
2906 ARTICLE should either be an article number or a Message-ID.
2907 If ARTICLE is an id, HEADER should be the article headers.
2908 If ALL-HEADERS is non-nil, no headers are hidden."
2910 ;; Make sure we start in a summary buffer.
2911 (unless (eq major-mode 'gnus-summary-mode)
2912 (set-buffer gnus-summary-buffer))
2913 (setq gnus-summary-buffer (current-buffer))
2914 (let* ((gnus-article (if header (mail-header-number header) article))
2915 (summary-buffer (current-buffer))
2916 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2917 (group gnus-newsgroup-name)
2920 (gnus-article-setup-buffer)
2921 (set-buffer gnus-original-article-buffer)
2922 ;; Deactivate active regions.
2923 (when (and (boundp 'transient-mark-mode)
2924 transient-mark-mode)
2925 (setq mark-active nil))
2926 (if (not (setq result (let ((buffer-read-only nil))
2927 (gnus-request-article-this-buffer
2929 ;; There is no such article.
2931 (when (and (numberp article)
2932 (not (memq article gnus-newsgroup-sparse)))
2933 (setq gnus-article-current
2934 (cons gnus-newsgroup-name article))
2935 (set-buffer gnus-summary-buffer)
2936 (setq gnus-current-article article)
2937 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2939 (gnus-summary-set-agent-mark article)
2940 (message "Message marked for downloading"))
2941 (gnus-summary-mark-article article gnus-canceled-mark)
2942 (unless (memq article gnus-newsgroup-sparse)
2943 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2944 (if (or (eq result 'pseudo)
2945 (eq result 'nneething))
2948 (set-buffer summary-buffer)
2949 (push article gnus-newsgroup-history)
2950 (setq gnus-last-article gnus-current-article
2951 gnus-current-article 0
2952 gnus-current-headers nil
2953 gnus-article-current nil)
2954 (if (eq result 'nneething)
2955 (gnus-configure-windows 'summary)
2956 (gnus-configure-windows 'article))
2957 (gnus-set-global-variables))
2958 (let ((gnus-article-mime-handle-alist-1
2959 gnus-article-mime-handle-alist))
2960 (gnus-set-mode-line 'article)))
2961 ;; The result from the `request' was an actual article -
2962 ;; or at least some text that is now displayed in the
2964 (when (and (numberp article)
2965 (not (eq article gnus-current-article)))
2966 ;; Seems like a new article has been selected.
2967 ;; `gnus-current-article' must be an article number.
2969 (set-buffer summary-buffer)
2970 (push article gnus-newsgroup-history)
2971 (setq gnus-last-article gnus-current-article
2972 gnus-current-article article
2973 gnus-current-headers
2974 (gnus-summary-article-header gnus-current-article)
2975 gnus-article-current
2976 (cons gnus-newsgroup-name gnus-current-article))
2977 (unless (vectorp gnus-current-headers)
2978 (setq gnus-current-headers nil))
2979 (gnus-summary-goto-subject gnus-current-article)
2980 (when (gnus-summary-show-thread)
2981 ;; If the summary buffer really was folded, the
2982 ;; previous goto may not actually have gone to
2983 ;; the right article, but the thread root instead.
2985 (gnus-summary-goto-subject gnus-current-article))
2986 (gnus-run-hooks 'gnus-mark-article-hook)
2987 (gnus-set-mode-line 'summary)
2988 (when (gnus-visual-p 'article-highlight 'highlight)
2989 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2990 ;; Set the global newsgroup variables here.
2991 (gnus-set-global-variables)
2992 (setq gnus-have-all-headers
2993 (or all-headers gnus-show-all-headers))))
2994 (when (or (numberp article)
2996 (gnus-article-prepare-display)
2998 (goto-char (point-min))
2999 (setq gnus-page-broken
3000 (when gnus-break-pages
3001 (gnus-narrow-to-page)
3003 (let ((gnus-article-mime-handle-alist-1
3004 gnus-article-mime-handle-alist))
3005 (gnus-set-mode-line 'article))
3007 (set-window-point (get-buffer-window (current-buffer)) (point))
3008 (gnus-configure-windows 'article)
3011 (defun gnus-article-prepare-mime-display (&optional number)
3012 (goto-char (point-min))
3013 (when (re-search-forward "^[^\t ]+:" nil t)
3014 (goto-char (match-beginning 0)))
3015 (let ((entity (if (eq 1 (point-min))
3016 (get-text-property 1 'mime-view-entity)
3017 (get-text-property (point) 'mime-view-entity)))
3018 last-entity child-entity next type)
3019 (setq child-entity (mime-entity-children entity))
3021 (setq last-entity (nth (1- (length child-entity))
3023 (setq last-entity entity))
3025 (narrow-to-region (point)
3026 (if (search-forward "\n\n" nil t)
3029 (gnus-treat-article 'head)
3030 (put-text-property (point-min) (point-max) 'article-treated-header t)
3031 (goto-char (point-max)))
3032 (while (and (not (eobp)) entity)
3033 (setq next (set-marker
3035 (next-single-property-change (point) 'mime-view-entity
3037 (let ((types (mime-entity-content-type entity)))
3038 (while (eq 'multipart (mime-content-type-primary-type types))
3039 (setq entity (car (mime-entity-children entity))
3040 types (mime-entity-content-type entity)))
3042 (setq type (format "%s/%s"
3043 (mime-content-type-primary-type types)
3044 (mime-content-type-subtype types)))))
3045 (if (string-equal type "message/rfc822")
3048 (let ((children (mime-entity-children entity))
3051 (setq last-children (nth (1- (length children)) children))
3054 (not (eq last-children
3055 (get-text-property next 'mime-view-entity)))
3057 (next-single-property-change next
3059 nil (point-max)))))))
3060 (setq next (next-single-property-change next 'mime-view-entity
3063 (narrow-to-region (point) next)
3064 (gnus-article-prepare-mime-display)
3065 (goto-char (point-max)))
3066 (setq entity (get-text-property (point) 'mime-view-entity)))
3068 (narrow-to-region (point) next)
3069 ;; Kludge. We have to count true number, but for now,
3070 ;; part number is here only to achieve `last'.
3071 (gnus-treat-article nil 1
3072 (if (eq entity last-entity)
3075 (goto-char (point-max)))
3076 (setq entity (get-text-property next 'mime-view-entity))))))
3079 (defun gnus-article-prepare-display ()
3080 "Make the current buffer look like a nice article."
3081 (setq gnus-article-wash-types nil)
3082 (gnus-run-hooks 'gnus-tmp-internal-hook)
3083 (gnus-run-hooks 'gnus-article-prepare-hook)
3085 (let (mime-display-header-hook mime-display-text/plain-hook)
3086 (funcall (if gnus-show-mime
3088 (setq mime-message-structure gnus-current-headers)
3089 (mime-buffer-entity-set-buffer-internal
3090 mime-message-structure
3091 gnus-original-article-buffer)
3092 (mime-entity-set-representation-type-internal
3093 mime-message-structure 'mime-buffer-entity)
3094 (luna-send mime-message-structure
3095 'initialize-instance
3096 mime-message-structure)
3097 gnus-article-display-method-for-mime)
3098 gnus-article-display-method-for-traditional)))
3099 ;; Associate this article with the current summary buffer.
3100 (setq gnus-article-current-summary gnus-summary-buffer)
3101 ;; Call the treatment functions.
3102 (let ((inhibit-read-only t)
3107 (gnus-article-prepare-mime-display)
3108 (narrow-to-region (goto-char (point-min))
3109 (if (search-forward "\n\n" nil t)
3112 (gnus-treat-article 'head)
3113 (put-text-property (point-min) (point-max) 'article-treated-header t)
3114 (goto-char (point-max))
3116 (narrow-to-region (point) (point-max))
3117 (gnus-treat-article nil))
3118 (put-text-property (point-min) (point-max) 'read-only nil)))
3119 ;; Perform the article display hooks. Incidentally, this hook is
3120 ;; an obsolete variable by now.
3121 (gnus-run-hooks 'gnus-article-display-hook))
3123 (defun gnus-article-decode-article-as-default-mime-charset ()
3124 "Decode an article as `default-mime-charset'. It won't work if the
3125 value of the variable `gnus-show-mime' is non-nil."
3126 (unless gnus-show-mime
3127 (decode-mime-charset-region (point-min) (point-max)
3128 (with-current-buffer gnus-summary-buffer
3129 default-mime-charset))))
3132 ;;; Gnus MIME viewing functions
3135 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3136 "The following specs can be used:
3138 %T MIME type, along with additional info
3139 %n The `name' parameter
3140 %d The description, if any
3141 %l The length of the encoded part
3142 %p The part identifier number
3143 %e Dots if the part isn't displayed")
3145 (defvar gnus-mime-button-line-format-alist
3146 '((?t gnus-tmp-type ?s)
3147 (?T gnus-tmp-type-long ?s)
3148 (?n gnus-tmp-name ?s)
3149 (?d gnus-tmp-description ?s)
3151 (?l gnus-tmp-length ?d)
3152 (?e gnus-tmp-dots ?s)))
3154 (defvar gnus-mime-button-commands
3155 '((gnus-article-press-button "\r" "Toggle Display")
3156 (gnus-mime-view-part "v" "View Interactively...")
3157 (gnus-mime-view-part-as-type "t" "View As Type...")
3158 (gnus-mime-save-part "o" "Save...")
3159 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3160 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3161 (gnus-mime-internalize-part "E" "View Internally")
3162 (gnus-mime-externalize-part "e" "View Externally")
3163 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3165 (defun gnus-article-mime-part-status ()
3166 (with-current-buffer gnus-article-buffer
3167 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3168 (if (and entity (mime-entity-children entity))
3169 (format " (%d parts)" (length (mime-entity-children entity)))
3172 (defvar gnus-mime-button-map nil)
3173 (unless gnus-mime-button-map
3174 (setq gnus-mime-button-map (make-sparse-keymap))
3175 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3176 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3177 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3179 (define-key gnus-mime-button-map (cadr c) (car c)))
3180 gnus-mime-button-commands))
3182 (defun gnus-mime-button-menu (event)
3183 "Construct a context-sensitive menu of MIME commands."
3186 (let ((pos (event-start event)))
3187 (set-buffer (window-buffer (posn-window pos)))
3188 (goto-char (posn-point pos))
3189 (gnus-article-check-buffer)
3190 (let ((response (x-popup-menu
3192 ("" ,@(mapcar (lambda (c)
3193 (cons (caddr c) (car c)))
3194 gnus-mime-button-commands))))))
3196 (funcall response))))))
3198 (defun gnus-mime-view-all-parts (&optional handles)
3199 "View all the MIME parts."
3201 (save-current-buffer
3202 (set-buffer gnus-article-buffer)
3203 (let ((handles (or handles gnus-article-mime-handles))
3204 (mail-parse-charset gnus-newsgroup-charset)
3205 (mail-parse-ignored-charsets
3206 (save-excursion (set-buffer gnus-summary-buffer)
3207 gnus-newsgroup-ignored-charsets)))
3208 (if (stringp (car handles))
3209 (gnus-mime-view-all-parts (cdr handles))
3210 (mapcar 'mm-display-part handles)))))
3212 (defun gnus-mime-save-part ()
3213 "Save the MIME part under point."
3215 (gnus-article-check-buffer)
3216 (let ((data (get-text-property (point) 'gnus-data)))
3217 (mm-save-part data)))
3219 (defun gnus-mime-pipe-part ()
3220 "Pipe the MIME part under point to a process."
3222 (gnus-article-check-buffer)
3223 (let ((data (get-text-property (point) 'gnus-data)))
3224 (mm-pipe-part data)))
3226 (defun gnus-mime-view-part ()
3227 "Interactively choose a viewing method for the MIME part under point."
3229 (gnus-article-check-buffer)
3230 (let ((data (get-text-property (point) 'gnus-data)))
3231 (mm-interactively-view-part data)))
3233 (defun gnus-mime-view-part-as-type-internal ()
3234 (gnus-article-check-buffer)
3235 (let* ((name (mail-content-type-get
3236 (mm-handle-type (get-text-property (point) 'gnus-data))
3238 (def-type (and name (mm-default-file-encoding name))))
3239 (and def-type (cons def-type 0))))
3241 (defun gnus-mime-view-part-as-type (mime-type)
3242 "Choose a MIME media type, and view the part as such."
3244 (list (completing-read
3245 "View as MIME type: "
3246 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
3248 (gnus-mime-view-part-as-type-internal))))
3249 (gnus-article-check-buffer)
3250 (let ((handle (get-text-property (point) 'gnus-data)))
3251 (gnus-mm-display-part
3252 (mm-make-handle (mm-handle-buffer handle)
3253 (cons mime-type (cdr (mm-handle-type handle)))
3254 (mm-handle-encoding handle)
3255 (mm-handle-undisplayer handle)
3256 (mm-handle-disposition handle)
3257 (mm-handle-description handle)
3258 (mm-handle-cache handle)
3259 (mm-handle-id handle)))))
3261 (defun gnus-mime-copy-part (&optional handle)
3262 "Put the the MIME part under point into a new buffer."
3264 (gnus-article-check-buffer)
3265 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3266 (contents (mm-get-part handle))|
3267 (base (file-name-nondirectory
3269 (mail-content-type-get (mm-handle-type handle) 'name)
3270 (mail-content-type-get (mm-handle-type handle)
3273 (buffer (generate-new-buffer base)))
3274 (switch-to-buffer buffer)
3276 ;; We do it this way to make `normal-mode' set the appropriate mode.
3279 (setq buffer-file-name (expand-file-name base))
3281 (setq buffer-file-name nil))
3282 (goto-char (point-min))))
3284 (defun gnus-mime-inline-part (&optional handle)
3285 "Insert the MIME part under point into the current buffer."
3287 (gnus-article-check-buffer)
3288 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3292 (if (mm-handle-undisplayer handle)
3293 (mm-remove-part handle)
3294 (setq contents (mm-get-part handle))
3296 (mm-insert-inline handle contents)
3299 (defun gnus-mime-externalize-part (&optional handle)
3300 "View the MIME part under point with an external viewer."
3302 (gnus-article-check-buffer)
3303 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3304 (mm-user-display-methods nil)
3305 (mm-inline-large-images nil)
3306 (mail-parse-charset gnus-newsgroup-charset)
3307 (mail-parse-ignored-charsets
3308 (save-excursion (set-buffer gnus-summary-buffer)
3309 gnus-newsgroup-ignored-charsets)))
3310 (if (mm-handle-undisplayer handle)
3311 (mm-remove-part handle)
3312 (mm-display-part handle))))
3314 (defun gnus-mime-internalize-part (&optional handle)
3315 "View the MIME part under point with an internal viewer.
3316 In no internal viewer is available, use an external viewer."
3318 (gnus-article-check-buffer)
3319 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3320 (mm-inlined-types '(".*"))
3321 (mm-inline-large-images t)
3322 (mail-parse-charset gnus-newsgroup-charset)
3323 (mail-parse-ignored-charsets
3324 (save-excursion (set-buffer gnus-summary-buffer)
3325 gnus-newsgroup-ignored-charsets)))
3326 (if (mm-handle-undisplayer handle)
3327 (mm-remove-part handle)
3328 (mm-display-part handle))))
3330 (defun gnus-article-part-wrapper (n function)
3331 (save-current-buffer
3332 (set-buffer gnus-article-buffer)
3333 (when (> n (length gnus-article-mime-handle-alist))
3334 (error "No such part"))
3335 (gnus-article-goto-part n)
3336 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3337 (funcall function handle))))
3339 (defun gnus-article-pipe-part (n)
3340 "Pipe MIME part N, which is the numerical prefix."
3342 (gnus-article-part-wrapper n 'mm-pipe-part))
3344 (defun gnus-article-save-part (n)
3345 "Save MIME part N, which is the numerical prefix."
3347 (gnus-article-part-wrapper n 'mm-save-part))
3349 (defun gnus-article-interactively-view-part (n)
3350 "View MIME part N interactively, which is the numerical prefix."
3352 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3354 (defun gnus-article-copy-part (n)
3355 "Copy MIME part N, which is the numerical prefix."
3357 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3359 (defun gnus-article-externalize-part (n)
3360 "View MIME part N externally, which is the numerical prefix."
3362 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3364 (defun gnus-article-inline-part (n)
3365 "Inline MIME part N, which is the numerical prefix."
3367 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3369 (defun gnus-article-mime-match-handle-first (condition)
3371 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3372 (while (setq ihandle (pop alist))
3374 ((functionp condition)
3375 (funcall condition (cdr ihandle)))
3376 ((eq condition 'undisplayed)
3377 (not (or (mm-handle-undisplayer (cdr ihandle))
3378 (equal (mm-handle-media-type (cdr ihandle))
3379 "multipart/alternative"))))
3380 ((eq condition 'undisplayed-alternative)
3381 (not (mm-handle-undisplayer (cdr ihandle))))
3383 (gnus-article-goto-part (car ihandle))
3384 (or (not n) (< (car ihandle) n)))
3385 (setq n (car ihandle))))
3389 (defun gnus-article-view-part (&optional n)
3390 "View MIME part N, which is the numerical prefix."
3392 (save-current-buffer
3393 (set-buffer gnus-article-buffer)
3394 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3395 gnus-article-mime-match-handle-function)))
3396 (when (> n (length gnus-article-mime-handle-alist))
3397 (error "No such part"))
3398 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3399 (when (gnus-article-goto-part n)
3400 (if (equal (car handle) "multipart/alternative")
3401 (gnus-article-press-button)
3402 (when (eq (gnus-mm-display-part handle) 'internal)
3403 (gnus-set-window-start)))))))
3405 (defun gnus-mm-display-part (handle)
3406 "Display HANDLE and fix MIME button."
3407 (let ((id (get-text-property (point) 'gnus-part))
3412 (let ((window (selected-window))
3413 (mail-parse-charset gnus-newsgroup-charset)
3414 (mail-parse-ignored-charsets
3415 (save-excursion (set-buffer gnus-summary-buffer)
3416 gnus-newsgroup-ignored-charsets)))
3419 (let ((win (get-buffer-window (current-buffer) t))
3422 (select-window win))
3425 (if (mm-handle-displayed-p handle)
3426 ;; This will remove the part.
3427 (mm-display-part handle)
3429 (narrow-to-region (point) (1+ (point)))
3430 (mm-display-part handle)
3431 ;; We narrow to the part itself and
3432 ;; then call the treatment functions.
3433 (goto-char (point-min))
3435 (narrow-to-region (point) (point-max))
3438 (1- (length gnus-article-mime-handles))
3439 (mm-handle-media-type handle)))))
3440 (select-window window))))
3442 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3443 (gnus-insert-mime-button
3444 handle id (list (mm-handle-displayed-p handle)))
3445 (goto-char point))))
3447 (defun gnus-article-goto-part (n)
3448 "Go to MIME part N."
3449 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3451 (goto-char point))))
3453 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3454 (let ((gnus-tmp-name
3455 (or (mail-content-type-get (mm-handle-type handle)
3457 (mail-content-type-get (mm-handle-disposition handle)
3460 (gnus-tmp-type (mm-handle-media-type handle))
3461 (gnus-tmp-description
3462 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3465 (if (if displayed (car displayed)
3466 (mm-handle-displayed-p handle))
3468 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3470 gnus-tmp-type-long b e)
3471 (when (string-match ".*/" gnus-tmp-name)
3472 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3473 (setq gnus-tmp-type-long (concat gnus-tmp-type
3474 (and (not (equal gnus-tmp-name ""))
3475 (concat "; " gnus-tmp-name))))
3476 (or (equal gnus-tmp-description "")
3477 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3482 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3483 `(local-map ,gnus-mime-button-map
3484 keymap ,gnus-mime-button-map
3485 gnus-callback gnus-mm-display-part
3486 gnus-part ,gnus-tmp-id
3487 article-type annotation
3490 (widget-convert-button 'link b e
3492 :action 'gnus-widget-press-button
3493 :button-keymap gnus-mime-button-map
3496 ;; Needed to properly clear the message
3497 ;; due to a bug in wid-edit
3498 (setq help-echo-owns-message t)
3500 "Click to %s the MIME part; %s for more options"
3501 (if (mm-handle-displayed-p
3502 (widget-get widget :mime-handle))
3504 (if gnus-xemacs "button3" "mouse-3"))))))
3506 (defun gnus-widget-press-button (elems el)
3507 (goto-char (widget-get elems :from))
3508 (gnus-article-press-button))
3510 (defvar gnus-displaying-mime nil)
3512 (defun gnus-display-mime (&optional ihandles)
3513 "Display the MIME parts."
3515 (save-selected-window
3516 (let ((window (get-buffer-window gnus-article-buffer))
3519 (select-window window)
3520 ;; We have to do this since selecting the window
3521 ;; may change the point. So we set the window point.
3522 (set-window-point window point)))
3523 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3524 buffer-read-only handle name type b e display)
3525 (when (and (not ihandles)
3526 (not gnus-displaying-mime))
3527 ;; Top-level call; we clean up.
3528 (when gnus-article-mime-handles
3529 (mm-destroy-parts gnus-article-mime-handles)
3530 (setq gnus-article-mime-handle-alist nil));; A trick.
3531 (setq gnus-article-mime-handles handles)
3532 ;; We allow users to glean info from the handles.
3533 (when gnus-article-mime-part-function
3534 (gnus-mime-part-function handles)))
3536 (or (not (stringp (car handles)))
3539 (when (and (not ihandles)
3540 (not gnus-displaying-mime))
3541 ;; Clean up for mime parts.
3543 (delete-region (point) (point-max)))
3544 (let ((gnus-displaying-mime t))
3545 (gnus-mime-display-part handles)))
3548 (narrow-to-region (point) (point-max))
3549 (gnus-treat-article nil 1 1)
3552 ;; Highlight the headers.
3556 (narrow-to-region (point-min) (point))
3557 (gnus-treat-article 'head))))))))
3559 (defvar gnus-mime-display-multipart-as-mixed nil)
3561 (defun gnus-mime-display-part (handle)
3564 ((not (stringp (car handle)))
3565 (gnus-mime-display-single handle))
3566 ;; User-defined multipart
3567 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3568 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3570 ;; multipart/alternative
3571 ((and (equal (car handle) "multipart/alternative")
3572 (not gnus-mime-display-multipart-as-mixed))
3573 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3574 (push (cons id handle) gnus-article-mime-handle-alist)
3575 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3576 ;; multipart/related
3577 ((and (equal (car handle) "multipart/related")
3578 (not gnus-mime-display-multipart-as-mixed))
3579 ;;;!!!We should find the start part, but we just default
3580 ;;;!!!to the first part.
3581 (gnus-mime-display-part (cadr handle)))
3582 ;; Other multiparts are handled like multipart/mixed.
3584 (gnus-mime-display-mixed (cdr handle)))))
3586 (defun gnus-mime-part-function (handles)
3587 (if (stringp (car handles))
3588 (mapcar 'gnus-mime-part-function (cdr handles))
3589 (funcall gnus-article-mime-part-function handles)))
3591 (defun gnus-mime-display-mixed (handles)
3592 (mapcar 'gnus-mime-display-part handles))
3594 (defun gnus-mime-display-single (handle)
3595 (let ((type (mm-handle-media-type handle))
3596 (ignored gnus-ignored-mime-types)
3603 (when (string-match (pop ignored) type)
3604 (throw 'ignored nil)))
3605 (if (and (setq not-attachment
3606 (and (not (mm-inline-override-p handle))
3607 (or (not (mm-handle-disposition handle))
3608 (equal (car (mm-handle-disposition handle))
3610 (mm-attachment-override-p handle))))
3611 (mm-automatic-display-p handle)
3612 (or (mm-inlined-p handle)
3613 (mm-automatic-external-display-p type)))
3615 (when (equal (mm-handle-media-supertype handle) "text")
3617 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3618 (push (cons id handle) gnus-article-mime-handle-alist)
3619 (when (or (not display)
3620 (not (gnus-unbuttonized-mime-type-p type)))
3621 ;(gnus-article-insert-newline)
3622 (gnus-insert-mime-button
3623 handle id (list (or display (and not-attachment text))))
3624 (gnus-article-insert-newline)
3625 ;(gnus-article-insert-newline)
3627 (let ((beg (point)))
3633 (let ((mail-parse-charset gnus-newsgroup-charset)
3634 (mail-parse-ignored-charsets
3635 (save-excursion (condition-case ()
3636 (set-buffer gnus-summary-buffer)
3638 gnus-newsgroup-ignored-charsets)))
3639 (mm-display-part handle t))
3640 (goto-char (point-max)))
3641 ((and text not-attachment)
3645 (gnus-article-insert-newline)
3646 (mm-insert-inline handle (mm-get-part handle))
3647 (goto-char (point-max))))
3651 (narrow-to-region beg (point))
3653 nil (length gnus-article-mime-handle-alist)
3654 (1- (length gnus-article-mime-handles))
3655 (mm-handle-media-type handle)))))))))
3657 (defun gnus-unbuttonized-mime-type-p (type)
3658 "Say whether TYPE is to be unbuttonized."
3659 (unless gnus-inhibit-mime-unbuttonizing
3661 (let ((types gnus-unbuttonized-mime-types))
3663 (when (string-match (pop types) type)
3664 (throw 'found t)))))))
3666 (defun gnus-article-insert-newline ()
3667 "Insert a newline, but mark it as undeletable."
3668 (gnus-put-text-property
3669 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3671 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3672 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3675 handle buffer-read-only from props begend not-pref)
3676 (save-window-excursion
3679 (narrow-to-region (car ibegend)
3682 (goto-char (car ibegend))
3685 (delete-region (point-min) (point-max))
3686 (mm-remove-parts handles))
3687 (setq begend (list (point-marker)))
3689 (unless (setq not-pref (cadr (member preferred ihandles)))
3690 (setq not-pref (car ihandles)))
3692 (not (gnus-unbuttonized-mime-type-p
3693 "multipart/alternative")))
3694 (gnus-add-text-properties
3697 (insert (format "%d. " id))
3701 (unless ,(not ibegend)
3702 (setq gnus-article-mime-handle-alist
3703 ',gnus-article-mime-handle-alist))
3704 (gnus-mime-display-alternative
3705 ',ihandles ',not-pref ',begend ,id))
3706 local-map ,gnus-mime-button-map
3707 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3708 face ,gnus-article-button-face
3709 keymap ,gnus-mime-button-map
3712 (widget-convert-button 'link from (point)
3713 :action 'gnus-widget-press-button
3714 :button-keymap gnus-widget-button-keymap)
3716 (while (setq handle (pop handles))
3717 (gnus-add-text-properties
3720 (insert (format "(%c) %-18s"
3721 (if (equal handle preferred) ?* ? )
3722 (mm-handle-media-type handle)))
3726 (unless ,(not ibegend)
3727 (setq gnus-article-mime-handle-alist
3728 ',gnus-article-mime-handle-alist))
3729 (gnus-mime-display-alternative
3730 ',ihandles ',handle ',begend ,id))
3731 local-map ,gnus-mime-button-map
3732 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3733 face ,gnus-article-button-face
3734 keymap ,gnus-mime-button-map
3737 (widget-convert-button 'link from (point)
3738 :action 'gnus-widget-press-button
3739 :button-keymap gnus-widget-button-keymap)
3743 (if (stringp (car preferred))
3744 (gnus-display-mime preferred)
3745 (let ((mail-parse-charset gnus-newsgroup-charset)
3746 (mail-parse-ignored-charsets
3747 (save-excursion (set-buffer gnus-summary-buffer)
3748 gnus-newsgroup-ignored-charsets)))
3749 (mm-display-part preferred)
3753 (narrow-to-region (car begend) (point-max))
3755 nil (length gnus-article-mime-handle-alist)
3756 (1- (length gnus-article-mime-handles))
3757 (mm-handle-media-type handle))))))
3758 (goto-char (point-max))
3759 (setcdr begend (point-marker)))))
3761 (goto-char point))))
3763 (defun gnus-article-wash-status ()
3764 "Return a string which display status of article washing."
3766 (set-buffer gnus-article-buffer)
3767 (let ((cite (memq 'cite gnus-article-wash-types))
3768 (headers (memq 'headers gnus-article-wash-types))
3769 (boring (memq 'boring-headers gnus-article-wash-types))
3770 (pgp (memq 'pgp gnus-article-wash-types))
3771 (pem (memq 'pem gnus-article-wash-types))
3772 (signature (memq 'signature gnus-article-wash-types))
3773 (overstrike (memq 'overstrike gnus-article-wash-types))
3774 (emphasis (memq 'emphasis gnus-article-wash-types)))
3775 (format "%c%c%c%c%c%c%c"
3777 (if (or headers boring) ?h ? )
3778 (if (or pgp pem) ?p ? )
3779 (if signature ?s ? )
3780 (if overstrike ?o ? )
3781 (if gnus-show-mime ?m ? )
3782 (if emphasis ?e ? )))))
3784 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3786 (defun gnus-article-maybe-hide-headers ()
3787 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3788 Provided for backwards compatibility."
3789 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3790 (not (save-excursion (set-buffer gnus-summary-buffer)
3791 gnus-have-all-headers)))
3792 (not gnus-inhibit-hiding))
3793 (gnus-article-hide-headers)))
3797 (defun gnus-output-to-file (file-name)
3798 "Append the current article to a file named FILE-NAME."
3799 (let ((artbuf (current-buffer)))
3801 (insert-buffer-substring artbuf)
3802 ;; Append newline at end of the buffer as separator, and then
3804 (goto-char (point-max))
3806 (write-region-as-binary (point-min) (point-max) file-name 'append)
3809 (defun gnus-narrow-to-page (&optional arg)
3810 "Narrow the article buffer to a page.
3811 If given a numerical ARG, move forward ARG pages."
3813 (setq arg (if arg (prefix-numeric-value arg) 0))
3815 (set-buffer gnus-article-buffer)
3816 (goto-char (point-min))
3818 ;; Remove any old next/prev buttons.
3819 (when (gnus-visual-p 'page-marker)
3820 (let ((buffer-read-only nil))
3821 (gnus-remove-text-with-property 'gnus-prev)
3822 (gnus-remove-text-with-property 'gnus-next)))
3825 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3827 (re-search-forward page-delimiter nil 'move arg)))
3828 (goto-char (match-end 0)))
3831 (if (re-search-forward page-delimiter nil 'move)
3834 (when (and (gnus-visual-p 'page-marker)
3835 (not (= (point-min) 1)))
3837 (goto-char (point-min))
3838 (gnus-insert-prev-page-button)))
3839 (when (and (gnus-visual-p 'page-marker)
3840 (< (+ (point-max) 2) (buffer-size)))
3842 (goto-char (point-max))
3843 (gnus-insert-next-page-button)))))
3845 ;; Article mode commands
3847 (defun gnus-article-goto-next-page ()
3848 "Show the next page of the article."
3850 (when (gnus-article-next-page)
3851 (goto-char (point-min))
3852 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3854 (defun gnus-article-goto-prev-page ()
3855 "Show the next page of the article."
3857 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3858 (gnus-article-prev-page nil)))
3860 (defun gnus-article-next-page (&optional lines)
3861 "Show the next page of the current article.
3862 If end of article, return non-nil. Otherwise return nil.
3863 Argument LINES specifies lines to be scrolled up."
3865 (let ((start (window-start))
3866 end-of-buffer end-of-page)
3868 (move-to-window-line -1)
3869 (if (<= (point) start)
3872 (setq start (point)))
3875 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3876 (and (pos-visible-in-window-p)
3877 (setq end-of-buffer t)))
3879 (setq end-of-page t)))
3881 (move-to-window-line lines)
3882 (unless (search-backward "\n\n" nil t)
3883 (setq start (point)))))
3884 (cond (end-of-buffer t)
3886 (gnus-narrow-to-page 1)
3890 (set-window-start (selected-window) start)
3891 (let (window-pixel-scroll-increment)
3895 (defun gnus-article-prev-page (&optional lines)
3896 "Show previous page of current article.
3897 Argument LINES specifies lines to be scrolled down."
3899 (let (beginning-of-buffer beginning-of-page)
3901 (move-to-window-line 0)
3902 (cond ((eq 1 (point))
3903 (setq beginning-of-buffer t))
3905 (setq beginning-of-page t))))
3906 (cond (beginning-of-buffer)
3908 (gnus-narrow-to-page -1))
3911 (let (window-pixel-scroll-increment)
3912 (scroll-down lines))
3913 (beginning-of-buffer
3914 (goto-char (point-min))))))))
3916 (defun gnus-article-refer-article ()
3917 "Read article specified by message-id around point."
3919 (let ((point (point)))
3920 (search-forward ">" nil t) ;Move point to end of "<....>".
3921 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3922 (let ((message-id (match-string 1)))
3924 (set-buffer gnus-summary-buffer)
3925 (gnus-summary-refer-article message-id))
3927 (error "No references around point"))))
3929 (defun gnus-article-show-summary ()
3930 "Reconfigure windows to show summary buffer."
3932 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3933 (error "There is no summary buffer for this article buffer")
3934 (gnus-article-set-globals)
3935 (gnus-configure-windows 'article)
3936 (gnus-summary-goto-subject gnus-current-article)
3937 (gnus-summary-position-point)))
3939 (defun gnus-article-describe-briefly ()
3940 "Describe article mode commands briefly."
3942 (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")))
3944 (defun gnus-article-summary-command ()
3945 "Execute the last keystroke in the summary buffer."
3947 (let ((obuf (current-buffer))
3948 (owin (current-window-configuration))
3950 (switch-to-buffer gnus-article-current-summary 'norecord)
3951 (setq func (lookup-key (current-local-map) (this-command-keys)))
3952 (call-interactively func)
3954 (set-window-configuration owin)
3955 (set-window-point (get-buffer-window (current-buffer)) (point))))
3957 (defun gnus-article-summary-command-nosave ()
3958 "Execute the last keystroke in the summary buffer."
3961 (pop-to-buffer gnus-article-current-summary 'norecord)
3962 (setq func (lookup-key (current-local-map) (this-command-keys)))
3963 (call-interactively func)))
3965 (defun gnus-article-check-buffer ()
3966 "Beep if not in an article buffer."
3967 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3968 (error "Command invoked outside of a Gnus article buffer")))
3970 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3971 "Read a summary buffer key sequence and execute it from the article buffer."
3973 (gnus-article-check-buffer)
3975 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3976 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3977 "=" "^" "\M-^" "|"))
3983 '("n" "Gn" "p" "Gp"))
3986 (set-buffer gnus-article-current-summary)
3987 (let (gnus-pick-mode)
3988 (push (or key last-command-event) unread-command-events)
3989 (setq keys (static-if (featurep 'xemacs)
3990 (events-to-keys (read-key-sequence nil))
3991 (read-key-sequence nil)))))
3994 (if (or (member keys nosaves)
3995 (member keys nosave-but-article)
3996 (member keys nosave-in-article))
3998 (save-window-excursion
3999 (pop-to-buffer gnus-article-current-summary 'norecord)
4000 ;; We disable the pick minor mode commands.
4001 (let (gnus-pick-mode)
4002 (setq func (lookup-key (current-local-map) keys))))
4006 (unless (member keys nosave-in-article)
4007 (set-buffer gnus-article-current-summary))
4008 (call-interactively func)
4009 (setq new-sum-point (point)))
4010 (when (member keys nosave-but-article)
4011 (pop-to-buffer gnus-article-buffer 'norecord)))
4012 ;; These commands should restore window configuration.
4013 (let ((obuf (current-buffer))
4014 (owin (current-window-configuration))
4016 (summary gnus-article-current-summary)
4017 func in-buffer selected)
4018 (if not-restore-window
4019 (pop-to-buffer summary 'norecord)
4020 (switch-to-buffer summary 'norecord))
4021 (setq in-buffer (current-buffer))
4022 ;; We disable the pick minor mode commands.
4023 (if (setq func (let (gnus-pick-mode)
4024 (lookup-key (current-local-map) keys)))
4026 (call-interactively func)
4027 (setq new-sum-point (point)))
4029 (when (eq in-buffer (current-buffer))
4030 (setq selected (gnus-summary-select-article))
4032 (unless not-restore-window
4033 (set-window-configuration owin))
4034 (when (eq selected 'old)
4036 (set-window-start (get-buffer-window (current-buffer))
4038 (set-window-point (get-buffer-window (current-buffer))
4040 (let ((win (get-buffer-window gnus-article-current-summary)))
4042 (set-window-point win new-sum-point))))))))
4044 (defun gnus-article-hide (&optional arg force)
4045 "Hide all the gruft in the current article.
4046 This means that PGP stuff, signatures, cited text and (some)
4047 headers will be hidden.
4048 If given a prefix, show the hidden text instead."
4049 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4050 (gnus-article-hide-headers arg)
4051 (gnus-article-hide-list-identifiers arg)
4052 (gnus-article-hide-pgp arg)
4053 (gnus-article-hide-citation-maybe arg force)
4054 (gnus-article-hide-signature arg))
4056 (defun gnus-article-maybe-highlight ()
4057 "Do some article highlighting if article highlighting is requested."
4058 (when (gnus-visual-p 'article-highlight 'highlight)
4059 (gnus-article-highlight-some)))
4061 (defun gnus-check-group-server ()
4062 ;; Make sure the connection to the server is alive.
4063 (unless (gnus-server-opened
4064 (gnus-find-method-for-group gnus-newsgroup-name))
4065 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4066 (gnus-request-group gnus-newsgroup-name t)))
4068 (defun gnus-request-article-this-buffer (article group)
4069 "Get an article and insert it into this buffer."
4070 (let (do-update-line sparse-header)
4074 (gnus-kill-all-overlays)
4075 (setq group (or group gnus-newsgroup-name))
4077 ;; Using `gnus-request-article' directly will insert the article into
4078 ;; `nntp-server-buffer' - so we'll save some time by not having to
4079 ;; copy it from the server buffer into the article buffer.
4081 ;; We only request an article by message-id when we do not have the
4082 ;; headers for it, so we'll have to get those.
4083 (when (stringp article)
4084 (gnus-read-header article))
4086 ;; If the article number is negative, that means that this article
4087 ;; doesn't belong in this newsgroup (possibly), so we find its
4088 ;; message-id and request it by id instead of number.
4089 (when (and (numberp article)
4091 (get-buffer gnus-summary-buffer)
4092 (gnus-buffer-exists-p gnus-summary-buffer))
4094 (set-buffer gnus-summary-buffer)
4095 (let ((header (gnus-summary-article-header article)))
4098 ((memq article gnus-newsgroup-sparse)
4099 ;; This is a sparse gap article.
4100 (setq do-update-line article)
4101 (setq article (mail-header-id header))
4102 (setq sparse-header (gnus-read-header article))
4103 (setq gnus-newsgroup-sparse
4104 (delq article gnus-newsgroup-sparse)))
4106 ;; It's a real article.
4107 (setq article (mail-header-id header)))
4109 ;; It is an extracted pseudo-article.
4110 (setq article 'pseudo)
4111 (gnus-request-pseudo-article header))))
4113 (let ((method (gnus-find-method-for-group
4114 gnus-newsgroup-name)))
4115 (when (and (eq (car method) 'nneething)
4118 (file-name-as-directory
4119 (or (cadr (assq 'nneething-address method))
4121 (mail-header-subject header))))
4122 (when (file-directory-p dir)
4123 (setq article 'nneething)
4124 (gnus-group-enter-directory dir))))))))
4127 ;; Refuse to select canceled articles.
4128 ((and (numberp article)
4130 (get-buffer gnus-summary-buffer)
4131 (gnus-buffer-exists-p gnus-summary-buffer)
4132 (eq (cdr (save-excursion
4133 (set-buffer gnus-summary-buffer)
4134 (assq article gnus-newsgroup-reads)))
4135 gnus-canceled-mark))
4137 ;; Check the backlog.
4138 ((and gnus-keep-backlog
4139 (gnus-backlog-request-article group article (current-buffer)))
4141 ;; Check asynchronous pre-fetch.
4142 ((gnus-async-request-fetched-article group article (current-buffer))
4143 (gnus-async-prefetch-next group article gnus-summary-buffer)
4144 (when (and (numberp article) gnus-keep-backlog)
4145 (gnus-backlog-enter-article group article (current-buffer)))
4148 ((and gnus-use-cache
4150 (gnus-cache-request-article article group))
4152 ;; Get the article and put into the article buffer.
4153 ((or (stringp article)
4155 (let ((gnus-override-method gnus-override-method)
4156 (methods (and (stringp article)
4157 gnus-refer-article-method))
4159 (buffer-read-only nil))
4164 (when (and (null gnus-override-method)
4166 (setq gnus-override-method (pop methods)))
4168 (when (eq gnus-override-method 'current)
4169 (setq gnus-override-method gnus-current-select-method))
4171 (gnus-kill-all-overlays)
4172 (let ((gnus-newsgroup-name group))
4173 (gnus-check-group-server))
4174 (when (gnus-request-article article group (current-buffer))
4175 (when (numberp article)
4176 (gnus-async-prefetch-next group article
4177 gnus-summary-buffer)
4178 (when gnus-keep-backlog
4179 (gnus-backlog-enter-article
4180 group article (current-buffer))))
4181 (setq result 'article))
4184 (setq gnus-override-method (pop methods))
4185 (setq result 'done))))
4186 (and (eq result 'article) 'article)))
4190 ;; Associate this article with the current summary buffer.
4191 (setq gnus-article-current-summary gnus-summary-buffer)
4193 ;; Take the article from the original article buffer
4194 ;; and place it in the buffer it's supposed to be in.
4195 (when (and (get-buffer gnus-article-buffer)
4196 (equal (buffer-name (current-buffer))
4197 (buffer-name (get-buffer gnus-article-buffer))))
4199 (if (get-buffer gnus-original-article-buffer)
4200 (set-buffer gnus-original-article-buffer)
4201 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4202 (buffer-disable-undo)
4203 (setq major-mode 'gnus-original-article-mode)
4204 (setq buffer-read-only t))
4205 (let (buffer-read-only)
4207 (insert-buffer-substring gnus-article-buffer))
4208 (setq gnus-original-article (cons group article)))
4211 (run-hooks 'gnus-article-decode-hook)
4212 ;; Mark article as decoded or not.
4213 (setq gnus-article-decoded-p gnus-article-decode-hook))
4215 ;; Update sparse articles.
4216 (when (and do-update-line
4217 (or (numberp article)
4219 (let ((buf (current-buffer)))
4220 (set-buffer gnus-summary-buffer)
4221 (gnus-summary-update-article do-update-line sparse-header)
4222 (gnus-summary-goto-subject do-update-line nil t)
4223 (set-window-point (get-buffer-window (current-buffer) t)
4225 (set-buffer buf))))))
4231 (defcustom gnus-article-edit-mode-hook nil
4232 "Hook run in article edit mode buffers."
4233 :group 'gnus-article-various
4236 (defcustom gnus-article-edit-article-setup-function
4237 'gnus-article-mime-edit-article-setup
4238 "Function called to setup an editing article buffer."
4239 :group 'gnus-article-various
4242 (defvar gnus-article-edit-done-function nil)
4244 (defvar gnus-article-edit-mode-map nil)
4246 ;; Should we be using derived.el for this?
4247 (unless gnus-article-edit-mode-map
4248 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4249 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4251 (gnus-define-keys gnus-article-edit-mode-map
4252 "\C-c\C-c" gnus-article-edit-done
4253 "\C-c\C-k" gnus-article-edit-exit)
4255 (gnus-define-keys (gnus-article-edit-wash-map
4256 "\C-c\C-w" gnus-article-edit-mode-map)
4257 "f" gnus-article-edit-full-stops))
4259 (defun gnus-article-edit-mode ()
4260 "Major mode for editing articles.
4261 This is an extended text-mode.
4263 \\{gnus-article-edit-mode-map}"
4265 (setq major-mode 'gnus-article-edit-mode)
4266 (setq mode-name "Article Edit")
4267 (use-local-map gnus-article-edit-mode-map)
4268 (make-local-variable 'gnus-article-edit-done-function)
4269 (make-local-variable 'gnus-prev-winconf)
4270 (setq buffer-read-only nil)
4271 (buffer-enable-undo)
4273 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4275 (defun gnus-article-edit (&optional force)
4276 "Edit the current article.
4277 This will have permanent effect only in mail groups.
4278 If FORCE is non-nil, allow editing of articles even in read-only
4281 (when (and (not force)
4282 (gnus-group-read-only-p))
4283 (error "The current newsgroup does not support article editing"))
4284 (gnus-article-date-original)
4285 (gnus-article-edit-article
4287 `(lambda (no-highlight)
4289 (gnus-summary-edit-article-done
4290 ,(or (mail-header-references gnus-current-headers) "")
4291 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4293 (defun gnus-article-edit-article (start-func exit-func)
4294 "Start editing the contents of the current article buffer."
4295 (let ((winconf (current-window-configuration)))
4296 (set-buffer gnus-article-buffer)
4297 (gnus-article-edit-mode)
4298 (funcall start-func)
4299 (gnus-configure-windows 'edit-article)
4300 (setq gnus-article-edit-done-function exit-func)
4301 (setq gnus-prev-winconf winconf)
4302 (when gnus-article-edit-article-setup-function
4303 (funcall gnus-article-edit-article-setup-function))
4304 (gnus-message 6 "C-c C-c to end edits")))
4306 (defun gnus-article-edit-done (&optional arg)
4307 "Update the article edits and exit."
4312 (when (article-goto-body)
4313 (let ((lines (count-lines (point) (point-max)))
4314 (length (- (point-max) (point)))
4315 (case-fold-search t)
4316 (body (copy-marker (point))))
4317 (goto-char (point-min))
4318 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4319 (delete-region (match-beginning 1) (match-end 1))
4320 (insert (number-to-string length)))
4321 (goto-char (point-min))
4322 (when (re-search-forward
4323 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4324 (delete-region (match-beginning 1) (match-end 1))
4325 (insert (number-to-string length)))
4326 (goto-char (point-min))
4327 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4328 (delete-region (match-beginning 1) (match-end 1))
4329 (insert (number-to-string lines)))))))
4330 (let ((func gnus-article-edit-done-function)
4331 (buf (current-buffer))
4332 (start (window-start)))
4333 (remove-hook 'gnus-article-mode-hook
4334 'gnus-article-mime-edit-article-unwind)
4335 (gnus-article-edit-exit)
4338 (let ((buffer-read-only nil))
4340 ;; The cache and backlog have to be flushed somewhat.
4341 (when gnus-keep-backlog
4342 (gnus-backlog-remove-article
4343 (car gnus-article-current) (cdr gnus-article-current)))
4344 ;; Flush original article as well.
4346 (when (get-buffer gnus-original-article-buffer)
4347 (set-buffer gnus-original-article-buffer)
4348 (setq gnus-original-article nil)))
4349 (when gnus-use-cache
4350 (gnus-cache-update-article
4351 (car gnus-article-current) (cdr gnus-article-current))))
4353 (set-window-start (get-buffer-window buf) start)
4354 (set-window-point (get-buffer-window buf) (point))))
4356 (defun gnus-article-edit-exit ()
4357 "Exit the article editing without updating."
4359 ;; We remove all text props from the article buffer.
4360 (let ((buf (format "%s" (buffer-string)))
4361 (curbuf (current-buffer))
4363 (window-start (window-start)))
4366 (let ((winconf gnus-prev-winconf))
4368 (set-window-configuration winconf)
4369 ;; Tippy-toe some to make sure that point remains where it was.
4370 (save-current-buffer
4372 (set-window-start (get-buffer-window (current-buffer)) window-start)
4375 (defun gnus-article-edit-full-stops ()
4376 "Interactively repair spacing at end of sentences."
4379 (goto-char (point-min))
4380 (search-forward-regexp "^$" nil t)
4381 (let ((case-fold-search nil))
4382 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4385 ;;; Article editing with MIME-Edit
4388 (defcustom gnus-article-mime-edit-article-setup-hook nil
4389 "Hook run after setting up a MIME editing article buffer."
4390 :group 'gnus-article-various
4393 (defun gnus-article-mime-edit-article-unwind ()
4394 "Unwind `gnus-article-buffer' if article editing was given up."
4395 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4396 (when mime-edit-mode-flag
4397 (mime-edit-exit 'nomime 'no-error)
4399 (when (featurep 'font-lock)
4400 (setq font-lock-defaults nil)
4401 (font-lock-mode 0)))
4403 (defun gnus-article-mime-edit-article-setup ()
4404 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4405 after replacing with the original article."
4406 (setq gnus-show-mime t)
4407 (setq gnus-article-edit-done-function
4408 `(lambda (&rest args)
4409 (when mime-edit-mode-flag
4412 (goto-char (point-min))
4413 (let (case-fold-search)
4414 (when (re-search-forward
4415 (format "^%s$" (regexp-quote mail-header-separator))
4417 (replace-match "")))
4418 (when (featurep 'font-lock)
4419 (setq font-lock-defaults nil)
4421 (apply ,gnus-article-edit-done-function args)
4422 (set-buffer gnus-original-article-buffer)
4424 (insert-buffer gnus-article-buffer)
4425 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4426 (gnus-article-prepare-display)))
4427 (substitute-key-definition
4428 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4429 gnus-article-edit-mode-map)
4431 (insert-buffer gnus-original-article-buffer)
4433 (when (featurep 'font-lock)
4434 (set (make-local-variable 'font-lock-defaults)
4435 '(message-font-lock-keywords t))
4436 (font-lock-set-defaults)
4437 (turn-on-font-lock))
4438 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4439 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4441 (defun gnus-article-mime-edit-exit ()
4442 "Exit the article MIME editing without updating."
4444 (let ((winconf gnus-prev-winconf)
4446 (when mime-edit-mode-flag
4449 (goto-char (point-min))
4450 (let (case-fold-search)
4451 (when (re-search-forward
4452 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4453 (replace-match "")))
4454 (when (featurep 'font-lock)
4455 (setq font-lock-defaults nil)
4457 ;; We remove all text props from the article buffer.
4458 (setq buf (format "%s" (buffer-string)))
4459 (set-buffer (get-buffer-create gnus-original-article-buffer))
4462 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4463 (gnus-article-prepare-display)
4464 (set-window-configuration winconf)))
4467 ;;; Article highlights
4470 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4472 ;;; Internal Variables:
4474 (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\\)\\)\\|[-a-zA-Z0-9_]+\\.[-a-zA-Z0-9_]+\\(\\.[-a-zA-Z0-9_]+[-a-zA-Z0-9_/]+\\)+"
4475 "Regular expression that matches URLs."
4476 :group 'gnus-article-buttons
4479 (defcustom gnus-button-alist
4480 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4481 0 t gnus-button-message-id 2)
4482 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4483 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4485 gnus-button-fetch-group 4)
4486 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4487 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4488 t gnus-button-message-id 3)
4489 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4490 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4491 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4492 ;; This is how URLs _should_ be embedded in text...
4493 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4495 (,gnus-button-url-regexp 0 t browse-url 0))
4496 "*Alist of regexps matching buttons in article bodies.
4498 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4499 REGEXP: is the string matching text around the button,
4500 BUTTON: is the number of the regexp grouping actually matching the button,
4501 FORM: is a lisp expression which must eval to true for the button to
4503 CALLBACK: is the function to call when the user push this button, and each
4504 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4506 CALLBACK can also be a variable, in that case the value of that
4507 variable it the real callback function."
4508 :group 'gnus-article-buttons
4509 :type '(repeat (list regexp
4510 (integer :tag "Button")
4512 (function :tag "Callback")
4515 (integer :tag "Regexp group")))))
4517 (defcustom gnus-header-button-alist
4518 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4519 0 t gnus-button-message-id 0)
4520 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4521 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4522 0 t gnus-button-mailto 0)
4523 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4524 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4525 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4526 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4527 gnus-button-message-id 3))
4528 "*Alist of headers and regexps to match buttons in article heads.
4530 This alist is very similar to `gnus-button-alist', except that each
4531 alist has an additional HEADER element first in each entry:
4533 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4535 HEADER is a regexp to match a header. For a fuller explanation, see
4536 `gnus-button-alist'."
4537 :group 'gnus-article-buttons
4538 :group 'gnus-article-headers
4539 :type '(repeat (list (regexp :tag "Header")
4541 (integer :tag "Button")
4543 (function :tag "Callback")
4546 (integer :tag "Regexp group")))))
4548 (defvar gnus-button-regexp nil)
4549 (defvar gnus-button-marker-list nil)
4550 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4552 (defvar gnus-button-last nil)
4553 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4557 (defun gnus-article-push-button (event)
4558 "Check text under the mouse pointer for a callback function.
4559 If the text under the mouse pointer has a `gnus-callback' property,
4560 call it with the value of the `gnus-data' text property."
4562 (set-buffer (window-buffer (posn-window (event-start event))))
4563 (let* ((pos (posn-point (event-start event)))
4564 (data (get-text-property pos 'gnus-data))
4565 (fun (get-text-property pos 'gnus-callback)))
4568 (funcall fun data))))
4570 (defun gnus-article-press-button ()
4571 "Check text at point for a callback function.
4572 If the text at point has a `gnus-callback' property,
4573 call it with the value of the `gnus-data' text property."
4575 (let* ((data (get-text-property (point) 'gnus-data))
4576 (fun (get-text-property (point) 'gnus-callback)))
4578 (funcall fun data))))
4580 (defun gnus-article-prev-button (n)
4581 "Move point to N buttons backward.
4582 If N is negative, move forward instead."
4584 (gnus-article-next-button (- n)))
4586 (defun gnus-article-next-button (n)
4587 "Move point to N buttons forward.
4588 If N is negative, move backward instead."
4590 (let ((function (if (< n 0) 'previous-single-property-change
4591 'next-single-property-change))
4592 (inhibit-point-motion-hooks t)
4594 (limit (if (< n 0) (point-min) (point-max))))
4596 (while (and (not (= limit (point)))
4598 ;; Skip past the current button.
4599 (when (get-text-property (point) 'gnus-callback)
4600 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4601 ;; Go to the next (or previous) button.
4602 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4603 ;; Put point at the start of the button.
4604 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4605 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4606 ;; Skip past intangible buttons.
4607 (when (get-text-property (point) 'intangible)
4611 (gnus-message 5 "No more buttons"))
4614 (defun gnus-article-highlight (&optional force)
4615 "Highlight current article.
4616 This function calls `gnus-article-highlight-headers',
4617 `gnus-article-highlight-citation',
4618 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4619 do the highlighting. See the documentation for those functions."
4620 (interactive (list 'force))
4621 (gnus-article-highlight-headers)
4622 (gnus-article-highlight-citation force)
4623 (gnus-article-highlight-signature)
4624 (gnus-article-add-buttons force)
4625 (gnus-article-add-buttons-to-head))
4627 (defun gnus-article-highlight-some (&optional force)
4628 "Highlight current article.
4629 This function calls `gnus-article-highlight-headers',
4630 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4631 do the highlighting. See the documentation for those functions."
4632 (interactive (list 'force))
4633 (gnus-article-highlight-headers)
4634 (gnus-article-highlight-signature)
4635 (gnus-article-add-buttons))
4637 (defun gnus-article-highlight-headers ()
4638 "Highlight article headers as specified by `gnus-header-face-alist'."
4641 (set-buffer gnus-article-buffer)
4643 (let ((alist gnus-header-face-alist)
4644 (buffer-read-only nil)
4645 (case-fold-search t)
4646 (inhibit-point-motion-hooks t)
4647 entry regexp header-face field-face from hpoints fpoints)
4648 (article-narrow-to-head)
4649 (while (setq entry (pop alist))
4650 (goto-char (point-min))
4651 (setq regexp (concat "^\\("
4652 (if (string-equal "" (nth 0 entry))
4656 header-face (nth 1 entry)
4657 field-face (nth 2 entry))
4658 (while (and (re-search-forward regexp nil t)
4662 (unless (search-forward ":" nil t)
4664 (when (and header-face
4665 (not (memq (point) hpoints)))
4666 (push (point) hpoints)
4667 (gnus-put-text-property from (point) 'face header-face))
4668 (when (and field-face
4669 (not (memq (setq from (point)) fpoints)))
4671 (if (re-search-forward "^[^ \t]" nil t)
4673 (goto-char (point-max)))
4674 (gnus-put-text-property from (point) 'face field-face))))))))
4676 (defun gnus-article-highlight-signature ()
4677 "Highlight the signature in an article.
4678 It does this by highlighting everything after
4679 `gnus-signature-separator' using `gnus-signature-face'."
4681 (when gnus-signature-face
4683 (set-buffer gnus-article-buffer)
4684 (let ((buffer-read-only nil)
4685 (inhibit-point-motion-hooks t))
4687 (when (gnus-article-narrow-to-signature)
4688 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4689 'face gnus-signature-face)))))))
4691 (defun gnus-article-buttonize-signature ()
4692 "Add button to the signature."
4695 (set-buffer gnus-article-buffer)
4696 (let ((buffer-read-only nil)
4697 (inhibit-point-motion-hooks t))
4698 (when (gnus-article-search-signature)
4699 (gnus-article-add-button (match-beginning 0) (match-end 0)
4700 'gnus-signature-toggle
4701 (set-marker (make-marker)
4702 (1+ (match-end 0))))))))
4704 (defun gnus-button-in-region-p (b e prop)
4705 "Say whether PROP exists in the region."
4706 (text-property-not-all b e prop nil))
4708 (defun gnus-article-add-buttons (&optional force)
4709 "Find external references in the article and make buttons of them.
4710 \"External references\" are things like Message-IDs and URLs, as
4711 specified by `gnus-button-alist'."
4712 (interactive (list 'force))
4714 (set-buffer gnus-article-buffer)
4715 (let ((buffer-read-only nil)
4716 (inhibit-point-motion-hooks t)
4717 (case-fold-search t)
4718 (alist gnus-button-alist)
4720 ;; Remove all old markers.
4721 (let (marker entry new-list)
4722 (while (setq marker (pop gnus-button-marker-list))
4723 (if (or (< marker (point-min)) (>= marker (point-max)))
4724 (push marker new-list)
4726 (when (setq entry (gnus-button-entry))
4727 (put-text-property (match-beginning (nth 1 entry))
4728 (match-end (nth 1 entry))
4729 'gnus-callback nil))
4730 (set-marker marker nil)))
4731 (setq gnus-button-marker-list new-list))
4732 ;; We skip the headers.
4735 (while (setq entry (pop alist))
4736 (setq regexp (car entry))
4738 (while (re-search-forward regexp nil t)
4739 (let* ((start (and entry (match-beginning (nth 1 entry))))
4740 (end (and entry (match-end (nth 1 entry))))
4741 (from (match-beginning 0)))
4742 (when (and (or (eq t (nth 2 entry))
4743 (eval (nth 2 entry)))
4744 (not (gnus-button-in-region-p
4745 start end 'gnus-callback)))
4746 ;; That optional form returned non-nil, so we add the
4748 (gnus-article-add-button
4749 start end 'gnus-button-push
4750 (car (push (set-marker (make-marker) from)
4751 gnus-button-marker-list))))))))))
4753 ;; Add buttons to the head of an article.
4754 (defun gnus-article-add-buttons-to-head ()
4755 "Add buttons to the head of the article."
4758 (set-buffer gnus-article-buffer)
4760 (let ((buffer-read-only nil)
4761 (inhibit-point-motion-hooks t)
4762 (case-fold-search t)
4763 (alist gnus-header-button-alist)
4765 (article-narrow-to-head)
4767 ;; Each alist entry.
4768 (setq entry (car alist)
4770 (goto-char (point-min))
4771 (while (re-search-forward (car entry) nil t)
4772 ;; Each header matching the entry.
4773 (setq beg (match-beginning 0))
4774 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4775 (match-beginning 0))
4778 (while (re-search-forward (nth 1 entry) end t)
4779 ;; Each match within a header.
4780 (let* ((entry (cdr entry))
4781 (start (match-beginning (nth 1 entry)))
4782 (end (match-end (nth 1 entry)))
4783 (form (nth 2 entry)))
4784 (goto-char (match-end 0))
4786 (gnus-article-add-button
4787 start end (nth 3 entry)
4788 (buffer-substring (match-beginning (nth 4 entry))
4789 (match-end (nth 4 entry)))))))
4790 (goto-char end)))))))
4792 ;;; External functions:
4794 (defun gnus-article-add-button (from to fun &optional data)
4795 "Create a button between FROM and TO with callback FUN and data DATA."
4796 (when gnus-article-button-face
4797 (gnus-overlay-put (gnus-make-overlay from to)
4798 'face gnus-article-button-face))
4799 (gnus-add-text-properties
4801 (nconc (and gnus-article-mouse-face
4802 (list gnus-mouse-face-prop gnus-article-mouse-face))
4803 (list 'gnus-callback fun)
4804 (and data (list 'gnus-data data)))))
4806 ;;; Internal functions:
4808 (defun gnus-article-set-globals ()
4810 (set-buffer gnus-summary-buffer)
4811 (gnus-set-global-variables)))
4813 (defun gnus-signature-toggle (end)
4815 (set-buffer gnus-article-buffer)
4816 (let ((buffer-read-only nil)
4817 (inhibit-point-motion-hooks t)
4818 (limit (next-single-property-change end 'mime-view-entity
4820 (if (get-text-property end 'invisible)
4821 (gnus-article-unhide-text end limit)
4822 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4824 (defun gnus-button-entry ()
4825 ;; Return the first entry in `gnus-button-alist' matching this place.
4826 (let ((alist gnus-button-alist)
4829 (setq entry (pop alist))
4830 (if (looking-at (car entry))
4835 (defun gnus-button-push (marker)
4836 ;; Push button starting at MARKER.
4839 (let* ((entry (gnus-button-entry))
4840 (inhibit-point-motion-hooks t)
4842 (args (mapcar (lambda (group)
4843 (let ((string (match-string group)))
4844 (gnus-set-text-properties
4845 0 (length string) nil string)
4852 (fboundp (symbol-value fun)))
4853 (apply (symbol-value fun) args))
4855 (gnus-message 1 "You must define `%S' to use this button"
4856 (cons fun args)))))))
4858 (defun gnus-button-message-id (message-id)
4861 (set-buffer gnus-summary-buffer)
4862 (gnus-summary-refer-article message-id)))
4864 (defun gnus-button-fetch-group (address)
4865 "Fetch GROUP specified by ADDRESS."
4866 (if (not (string-match "[:/]" address))
4867 ;; This is just a simple group url.
4868 (gnus-group-read-ephemeral-group address gnus-select-method)
4869 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4871 (error "Can't parse %s" address)
4872 (gnus-group-read-ephemeral-group
4873 (match-string 4 address)
4874 `(nntp ,(match-string 1 address)
4875 (nntp-address ,(match-string 1 address))
4876 (nntp-port-number ,(if (match-end 3)
4877 (match-string 3 address)
4880 (defun gnus-url-parse-query-string (query &optional downcase)
4881 (let (retval pairs cur key val)
4882 (setq pairs (split-string query "&"))
4884 (setq cur (car pairs)
4886 (if (not (string-match "=" cur))
4888 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4889 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4891 (setq key (downcase key)))
4892 (setq cur (assoc key retval))
4894 (setcdr cur (cons val (cdr cur)))
4895 (setq retval (cons (list key val) retval)))))
4898 (defun gnus-url-unhex (x)
4905 (defun gnus-url-unhex-string (str &optional allow-newlines)
4906 "Remove %XXX embedded spaces, etc in a url.
4907 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4908 decoding of carriage returns and line feeds in the string, which is normally
4909 forbidden in URL encoding."
4910 (setq str (or str ""))
4912 (case-fold-search t))
4913 (while (string-match "%[0-9a-f][0-9a-f]" str)
4914 (let* ((start (match-beginning 0))
4915 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4917 (gnus-url-unhex (elt str (+ start 2))))))
4919 tmp (substring str 0 start)
4922 (char-to-string code))
4923 ((or (= code ?\n) (= code ?\r))
4925 (t (char-to-string code))))
4926 str (substring str (match-end 0)))))
4927 (setq tmp (concat tmp str))
4930 (defun gnus-url-mailto (url)
4931 ;; Send mail to someone
4932 (when (string-match "mailto:/*\\(.*\\)" url)
4933 (setq url (substring url (match-beginning 1) nil)))
4934 (let (to args subject func)
4935 (if (string-match (regexp-quote "?") url)
4936 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4937 args (gnus-url-parse-query-string
4938 (substring url (match-end 0) nil) t))
4939 (setq to (gnus-url-unhex-string url)))
4940 (setq args (cons (list "to" to) args)
4941 subject (cdr-safe (assoc "subject" args)))
4942 (gnus-setup-message 'reply
4945 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4948 (message-position-on-field (caar args)))
4949 (insert (mapconcat 'identity (cdar args) ", "))
4950 (setq args (cdr args)))
4953 (message-goto-subject)))))
4955 (defun gnus-button-mailto (address)
4957 (set-buffer (gnus-copy-article-buffer))
4958 (gnus-setup-message 'reply
4959 (message-reply address)))
4961 (defun gnus-button-reply (address)
4962 ;; Reply to ADDRESS.
4963 (gnus-setup-message 'reply
4964 (message-reply address)))
4966 (defun gnus-button-embedded-url (address)
4968 (browse-url (gnus-strip-whitespace address)))
4970 (defun gnus-article-smiley-display ()
4971 "Display \"smileys\" as small graphical icons."
4972 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
4974 ;;; Next/prev buttons in the article buffer.
4976 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4977 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4979 (defvar gnus-prev-page-map nil)
4980 (unless gnus-prev-page-map
4981 (setq gnus-prev-page-map (make-sparse-keymap))
4982 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4983 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4985 (static-if (featurep 'xemacs)
4986 (defun gnus-insert-prev-page-button ()
4987 (let ((buffer-read-only nil))
4989 gnus-prev-page-line-format nil
4990 `(gnus-prev t local-map ,gnus-prev-page-map
4991 gnus-callback gnus-article-button-prev-page
4992 article-type annotation))))
4993 (defun gnus-insert-prev-page-button ()
4994 (let ((buffer-read-only nil)
4995 (situation (get-text-property (point-min) 'mime-view-situation)))
4996 (set-keymap-parent gnus-prev-page-map (current-local-map))
4998 gnus-prev-page-line-format nil
4999 `(gnus-prev t local-map ,gnus-prev-page-map
5000 gnus-callback gnus-article-button-prev-page
5001 article-type annotation
5002 mime-view-situation ,situation))))
5005 (defvar gnus-next-page-map nil)
5006 (unless gnus-next-page-map
5007 (setq gnus-next-page-map (make-sparse-keymap))
5008 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5009 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5011 (defun gnus-button-next-page ()
5012 "Go to the next page."
5014 (let ((win (selected-window)))
5015 (select-window (get-buffer-window gnus-article-buffer t))
5016 (gnus-article-next-page)
5017 (select-window win)))
5019 (defun gnus-button-prev-page ()
5020 "Go to the prev page."
5022 (let ((win (selected-window)))
5023 (select-window (get-buffer-window gnus-article-buffer t))
5024 (gnus-article-prev-page)
5025 (select-window win)))
5027 (static-if (featurep 'xemacs)
5028 (defun gnus-insert-next-page-button ()
5029 (let ((buffer-read-only nil))
5030 (gnus-eval-format gnus-next-page-line-format nil
5032 t local-map ,gnus-next-page-map
5033 gnus-callback gnus-article-button-next-page
5034 article-type annotation))))
5035 (defun gnus-insert-next-page-button ()
5036 (let ((buffer-read-only nil)
5037 (situation (get-text-property (point-min) 'mime-view-situation)))
5038 (set-keymap-parent gnus-next-page-map (current-local-map))
5039 (gnus-eval-format gnus-next-page-line-format nil
5041 t local-map ,gnus-next-page-map
5042 gnus-callback gnus-article-button-next-page
5043 article-type annotation
5044 mime-view-situation ,situation))))
5047 (defun gnus-article-button-next-page (arg)
5048 "Go to the next page."
5050 (let ((win (selected-window)))
5051 (select-window (get-buffer-window gnus-article-buffer t))
5052 (gnus-article-next-page)
5053 (select-window win)))
5055 (defun gnus-article-button-prev-page (arg)
5056 "Go to the prev page."
5058 (let ((win (selected-window)))
5059 (select-window (get-buffer-window gnus-article-buffer t))
5060 (gnus-article-prev-page)
5061 (select-window win)))
5063 (defvar gnus-decode-header-methods
5064 '(mail-decode-encoded-word-region)
5065 "List of methods used to decode headers.
5067 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5068 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5069 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5070 whose names match REGEXP.
5073 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5074 mail-decode-encoded-word-region
5075 (\"chinese\" . rfc1843-decode-region))
5078 (defvar gnus-decode-header-methods-cache nil)
5080 (defun gnus-multi-decode-header (start end)
5081 "Apply the functions from `gnus-encoded-word-methods' that match."
5082 (unless (and gnus-decode-header-methods-cache
5083 (eq gnus-newsgroup-name
5084 (car gnus-decode-header-methods-cache)))
5085 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5088 (nconc gnus-decode-header-methods-cache (list x))
5089 (if (and gnus-newsgroup-name
5090 (string-match (car x) gnus-newsgroup-name))
5091 (nconc gnus-decode-header-methods-cache
5093 gnus-decode-header-methods))
5094 (let ((xlist gnus-decode-header-methods-cache))
5097 (narrow-to-region start end)
5099 (funcall (pop xlist) (point-min) (point-max))))))
5102 ;;; Treatment top-level handling.
5105 (defun gnus-treat-article (condition &optional part-number total-parts type)
5106 (let ((length (- (point-max) (point-min)))
5107 (alist gnus-treatment-function-alist)
5108 (article-goto-body-goes-to-point-min-p t)
5112 (let ((list gnus-article-treat-types))
5114 (when (string-match (pop list) type)
5115 (throw 'found t)))))))
5116 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5117 (entity (static-unless (featurep 'xemacs)
5118 (when (eq 'head condition)
5119 (get-text-property (point-min) 'mime-view-entity))))
5120 val elem buttonized)
5121 (gnus-run-hooks 'gnus-part-display-hook)
5122 (unless gnus-inhibit-treatment
5123 (while (setq elem (pop alist))
5126 (if (gnus-buffer-live-p gnus-summary-buffer)
5127 (set-buffer gnus-summary-buffer))
5128 (symbol-value (car elem))))
5129 (when (and (or (consp val)
5131 (gnus-treat-predicate val)
5132 (or (not (get (car elem) 'highlight))
5134 (when (and (not buttonized)
5136 '(gnus-treat-hide-signature
5137 gnus-treat-highlight-signature)))
5138 (gnus-article-buttonize-signature)
5139 (setq buttonized t))
5141 (funcall (cadr elem)))))
5142 ;; FSF Emacsen does not inherit the existing text properties
5143 ;; in the new text, so we should do it for `mime-view-entity'.
5144 (static-unless (featurep 'xemacs)
5146 (put-text-property (point-min) (point-max)
5147 'mime-view-entity entity))))))
5149 ;; Dynamic variables.
5150 (defvar part-number)
5151 (defvar total-parts)
5155 (defun gnus-treat-predicate (val)
5160 (stringp (car val)))
5161 (apply 'gnus-or (mapcar `(lambda (s)
5162 (string-match s ,(or gnus-newsgroup-name "")))
5165 (let ((pred (pop val)))
5168 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5170 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5172 (not (gnus-treat-predicate (car val))))
5174 (equal (car val) type))
5176 (error "%S is not a valid predicate" pred)))))
5186 (eq part-number total-parts))
5190 (error "%S is not a valid value" val))))
5196 (defun gnus-article-header-presentation-method (entity situation)
5197 (mime-insert-header entity)
5200 (set-alist 'mime-header-presentation-method-alist
5201 'gnus-original-article-mode
5202 #'gnus-article-header-presentation-method)
5204 (defun gnus-mime-preview-quitting-method ()
5205 (mime-preview-kill-buffer)
5206 (delete-other-windows)
5207 (gnus-article-show-summary)
5208 (gnus-summary-select-article gnus-show-all-headers t))
5210 (set-alist 'mime-preview-quitting-method-alist
5211 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5213 (set-alist 'mime-preview-following-method-alist
5214 'gnus-original-article-mode #'gnus-following-method)
5216 (set-alist 'mime-preview-over-to-previous-method-alist
5217 'gnus-original-article-mode
5219 (if (> (point-min) 1)
5220 (gnus-article-prev-page)
5221 (gnus-article-read-summary-keys
5222 nil (gnus-character-to-event ?P)))))
5224 (set-alist 'mime-preview-over-to-next-method-alist
5225 'gnus-original-article-mode'
5227 (if (< (point-max) (buffer-size))
5228 (gnus-article-next-page)
5229 (gnus-article-read-summary-keys
5230 nil (gnus-character-to-event ?N)))))
5240 (run-hooks 'gnus-art-load-hook)
5242 ;;; gnus-art.el ends here