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))
41 ;; Avoid byte-compile warnings.
51 (defgroup gnus-article nil
53 :link '(custom-manual "(gnus)The Article Buffer")
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
72 (defgroup gnus-article-signature nil
74 :link '(custom-manual "(gnus)Article Signature")
77 (defgroup gnus-article-headers nil
79 :link '(custom-manual "(gnus)Hiding Headers")
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
92 (defgroup gnus-article-saving nil
94 :link '(custom-manual "(gnus)Saving Articles")
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
113 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
114 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
115 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
116 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
117 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
118 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
119 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
120 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
121 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
122 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
123 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
124 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
125 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
126 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
127 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
128 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
129 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
130 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
131 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
132 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
133 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
134 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
135 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
136 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
137 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
138 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
139 "^X-Received:" "^Content-length:" "X-precedence:")
140 "*All headers that start with this regexp will be hidden.
141 This variable can also be a list of regexps of headers to be ignored.
142 If `gnus-visible-headers' is non-nil, this variable will be ignored."
143 :type '(choice :custom-show nil
146 :group 'gnus-article-hiding)
148 (defcustom gnus-visible-headers
149 "^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:"
150 "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153 :type '(repeat :value-to-internal (lambda (widget value)
154 (custom-split-regexp-maybe value))
155 :match (lambda (widget value)
157 (widget-editable-list-match widget value)))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-sorted-header-list
162 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164 "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
168 :type '(repeat regexp)
169 :group 'gnus-article-hiding)
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172 "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175 :type '(set (const :tag "Headers with no content." empty)
176 (const :tag "Newsgroups with only one group." newsgroups)
177 (const :tag "Followup-to identical to newsgroups." followup-to)
178 (const :tag "Reply-to identical to from." reply-to)
179 (const :tag "Date less than four days old." date)
180 (const :tag "Very long To and/or Cc header." long-to)
181 (const :tag "Multiple To and/or Cc headers." many-to))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185 "Regexp matching signature separator.
186 This can also be a list of regexps. In that case, it will be checked
187 from head to tail looking for a separator. Searches will be done from
188 the end of the buffer."
189 :type '(repeat string)
190 :group 'gnus-article-signature)
192 (defcustom gnus-signature-limit nil
193 "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number. If it is a floating point number, no signature may be
196 longer (in lines) than that number. If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer. If it is a string, it will be used as a
199 regexp. If it matches, the text in question is not a signature."
200 :type '(choice (integer :value 200)
202 (function :value fun)
203 (regexp :value ".*"))
204 :group 'gnus-article-signature)
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207 "Property list to use for hiding text."
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-x-face-command
213 ((and (fboundp 'image-type-available-p)
214 (or (image-type-available-p 'xpm)
215 (image-type-available-p 'xbm)))
216 'gnus-article-display-xface)
217 ((and (not gnus-xemacs)
219 (module-installed-p 'x-face-mule))
220 'x-face-mule-gnus-article-display-x-face)
222 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
223 "*String or function to be executed to display an X-Face header.
224 If it is a string, the command will be executed in a sub-shell
225 asynchronously. The compressed face will be piped to this command."
226 :type '(choice string
227 (function-item gnus-article-display-xface)
228 (function-item x-face-mule-gnus-article-display-x-face)
230 :group 'gnus-article-washing)
232 (defcustom gnus-article-x-face-too-ugly nil
233 "Regexp matching posters whose face shouldn't be shown automatically."
234 :type '(choice regexp (const nil))
235 :group 'gnus-article-washing)
237 (defcustom gnus-emphasis-alist
239 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
241 '(("_" "_" underline)
244 ("_/" "/_" underline-italic)
245 ("_\\*" "\\*_" underline-bold)
246 ("\\*/" "/\\*" bold-italic)
247 ("_\\*/" "/\\*_" underline-bold-italic))))
248 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
249 2 3 gnus-emphasis-underline)
253 (format format (car spec) (car (cdr spec)))
254 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
256 "*Alist that says how to fontify certain phrases.
257 Each item looks like this:
259 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
261 The first element is a regular expression to be matched. The second
262 is a number that says what regular expression grouping used to find
263 the entire emphasized word. The third is a number that says what
264 regexp grouping should be displayed and highlighted. The fourth
265 is the face used for highlighting."
266 :type '(repeat (list :value ("" 0 0 default)
268 (integer :tag "Match group")
269 (integer :tag "Emphasize group")
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-bold '((t (:bold t)))
274 "Face used for displaying strong emphasized text (*word*)."
275 :group 'gnus-article-emphasis)
277 (defface gnus-emphasis-italic '((t (:italic t)))
278 "Face used for displaying italic emphasized text (/word/)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-underline '((t (:underline t)))
282 "Face used for displaying underlined emphasized text (_word_)."
283 :group 'gnus-article-emphasis)
285 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
286 "Face used for displaying underlined bold emphasized text (_*word*_)."
287 :group 'gnus-article-emphasis)
289 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
290 "Face used for displaying underlined italic emphasized text (_/word/_)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
294 "Face used for displaying bold italic emphasized text (/*word*/)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-underline-bold-italic
298 '((t (:bold t :italic t :underline t)))
299 "Face used for displaying underlined bold italic emphasized text.
300 Esample: (_/*word*/_)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-highlight-words
304 '((t (:background "black" :foreground "yellow")))
305 "Face used for displaying highlighted words."
306 :group 'gnus-article-emphasis)
308 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
309 "Format for display of Date headers in article bodies.
310 See `format-time-string' for the possible values.
312 The variable can also be function, which should return a complete Date
313 header. The function is called with one argument, the time, which can
314 be fed to `format-time-string'."
315 :type '(choice string symbol)
316 :link '(custom-manual "(gnus)Article Date")
317 :group 'gnus-article-washing)
320 (autoload 'mail-extract-address-components "mail-extr"))
322 (defcustom gnus-save-all-headers t
323 "*If non-nil, don't remove any headers before saving."
324 :group 'gnus-article-saving
327 (defcustom gnus-prompt-before-saving 'always
328 "*This variable says how much prompting is to be done when saving articles.
329 If it is nil, no prompting will be done, and the articles will be
330 saved to the default files. If this variable is `always', each and
331 every article that is saved will be preceded by a prompt, even when
332 saving large batches of articles. If this variable is neither nil not
333 `always', there the user will be prompted once for a file name for
334 each invocation of the saving commands."
335 :group 'gnus-article-saving
336 :type '(choice (item always)
337 (item :tag "never" nil)
338 (sexp :tag "once" :format "%t\n" :value t)))
340 (defcustom gnus-saved-headers gnus-visible-headers
341 "Headers to keep if `gnus-save-all-headers' is nil.
342 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
343 If that variable is nil, however, all headers that match this regexp
344 will be kept while the rest will be deleted before saving."
345 :group 'gnus-article-saving
348 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
349 "A function to save articles in your favourite format.
350 The function must be interactively callable (in other words, it must
351 be an Emacs command).
353 Gnus provides the following functions:
355 * gnus-summary-save-in-rmail (Rmail format)
356 * gnus-summary-save-in-mail (Unix mail format)
357 * gnus-summary-save-in-folder (MH folder)
358 * gnus-summary-save-in-file (article format)
359 * gnus-summary-save-in-vm (use VM's folder format)
360 * gnus-summary-write-to-file (article format -- overwrite)."
361 :group 'gnus-article-saving
362 :type '(radio (function-item gnus-summary-save-in-rmail)
363 (function-item gnus-summary-save-in-mail)
364 (function-item gnus-summary-save-in-folder)
365 (function-item gnus-summary-save-in-file)
366 (function-item gnus-summary-save-in-vm)
367 (function-item gnus-summary-write-to-file)))
369 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
370 "A function generating a file name to save articles in Rmail format.
371 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
372 :group 'gnus-article-saving
375 (defcustom gnus-mail-save-name 'gnus-plain-save-name
376 "A function generating a file name to save articles in Unix mail format.
377 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
378 :group 'gnus-article-saving
381 (defcustom gnus-folder-save-name 'gnus-folder-save-name
382 "A function generating a file name to save articles in MH folder.
383 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
384 :group 'gnus-article-saving
387 (defcustom gnus-file-save-name 'gnus-numeric-save-name
388 "A function generating a file name to save articles in article format.
389 The function is called with NEWSGROUP, HEADERS, and optional
391 :group 'gnus-article-saving
394 (defcustom gnus-split-methods
395 '((gnus-article-archive-name)
396 (gnus-article-nndoc-name))
397 "*Variable used to suggest where articles are to be saved.
398 For instance, if you would like to save articles related to Gnus in
399 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
400 you could set this variable to something like:
402 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
403 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
405 This variable is an alist where the where the key is the match and the
406 value is a list of possible files to save in if the match is non-nil.
408 If the match is a string, it is used as a regexp match on the
409 article. If the match is a symbol, that symbol will be funcalled
410 from the buffer of the article to be saved with the newsgroup as the
411 parameter. If it is a list, it will be evaled in the same buffer.
413 If this form or function returns a string, this string will be used as
414 a possible file name; and if it returns a non-nil list, that list will
415 be used as possible file names."
416 :group 'gnus-article-saving
417 :type '(repeat (choice (list :value (fun) function)
418 (cons :value ("" "") regexp (repeat string))
421 (defcustom gnus-article-display-method-for-mime
422 'gnus-article-display-mime-message
423 "Function to display a MIME message.
424 The function is called from the article buffer."
425 :group 'gnus-article-mime
428 (defcustom gnus-article-display-method-for-traditional
429 'gnus-article-display-traditional-message
430 "*Function to display a traditional message.
431 The function is called from the article buffer."
432 :group 'gnus-article-mime
435 (defcustom gnus-page-delimiter "^\^L"
436 "*Regexp describing what to use as article page delimiters.
437 The default value is \"^\^L\", which is a form linefeed at the
438 beginning of a line."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
443 "*The format specification for the article mode line.
444 See `gnus-summary-mode-line-format' for a closer description.
446 The following additional specs are available:
448 %w The article washing status.
449 %m The number of MIME parts in the article."
451 :group 'gnus-article-various)
453 (defcustom gnus-article-mode-hook nil
454 "*A hook for Gnus article mode."
456 :group 'gnus-article-various)
458 (defcustom gnus-article-menu-hook nil
459 "*Hook run after the creation of the article mode menu."
461 :group 'gnus-article-various)
463 (defcustom gnus-article-prepare-hook nil
464 "*A hook called after an article has been prepared in the article buffer."
466 :group 'gnus-article-various)
468 (defcustom gnus-article-hide-pgp-hook nil
469 "*A hook called after successfully hiding a PGP signature."
471 :group 'gnus-article-various)
473 (defcustom gnus-article-button-face 'bold
474 "Face used for highlighting buttons in the article buffer.
476 An article button is a piece of text that you can activate by pressing
477 `RET' or `mouse-2' above it."
479 :group 'gnus-article-buttons)
481 (defcustom gnus-article-mouse-face 'highlight
482 "Face used for mouse highlighting in the article buffer.
484 Article buttons will be displayed in this face when the cursor is
487 :group 'gnus-article-buttons)
489 (defcustom gnus-signature-face 'gnus-signature-face
490 "Face used for highlighting a signature in the article buffer.
491 Obsolete; use the face `gnus-signature-face' for customizations instead."
493 :group 'gnus-article-highlight
494 :group 'gnus-article-signature)
496 (defface gnus-signature-face
498 "Face used for highlighting a signature in the article buffer."
499 :group 'gnus-article-highlight
500 :group 'gnus-article-signature)
502 (defface gnus-header-from-face
505 (:foreground "spring green"))
508 (:foreground "red3"))
511 "Face used for displaying from headers."
512 :group 'gnus-article-headers
513 :group 'gnus-article-highlight)
515 (defface gnus-header-subject-face
518 (:foreground "SeaGreen3"))
521 (:foreground "red4"))
523 (:bold t :italic t)))
524 "Face used for displaying subject headers."
525 :group 'gnus-article-headers
526 :group 'gnus-article-highlight)
528 (defface gnus-header-newsgroups-face
531 (:foreground "yellow" :italic t))
534 (:foreground "MidnightBlue" :italic t))
537 "Face used for displaying newsgroups headers."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight)
541 (defface gnus-header-name-face
544 (:foreground "SeaGreen"))
547 (:foreground "maroon"))
550 "Face used for displaying header names."
551 :group 'gnus-article-headers
552 :group 'gnus-article-highlight)
554 (defface gnus-header-content-face
557 (:foreground "forest green" :italic t))
560 (:foreground "indianred4" :italic t))
562 (:italic t))) "Face used for displaying header content."
563 :group 'gnus-article-headers
564 :group 'gnus-article-highlight)
566 (defcustom gnus-header-face-alist
567 '(("From" nil gnus-header-from-face)
568 ("Subject" nil gnus-header-subject-face)
569 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
570 ("" gnus-header-name-face gnus-header-content-face))
571 "*Controls highlighting of article header.
573 An alist of the form (HEADER NAME CONTENT).
575 HEADER is a regular expression which should match the name of an
576 header header and NAME and CONTENT are either face names or nil.
578 The name of each header field will be displayed using the face
579 specified by the first element in the list where HEADER match the
580 header name and NAME is non-nil. Similarly, the content will be
581 displayed by the first non-nil matching CONTENT face."
582 :group 'gnus-article-headers
583 :group 'gnus-article-highlight
584 :type '(repeat (list (regexp :tag "Header")
586 (item :tag "skip" nil)
587 (face :value default))
588 (choice :tag "Content"
589 (item :tag "skip" nil)
590 (face :value default)))))
592 (defcustom gnus-article-decode-hook nil
593 "*Hook run to decode charsets in articles."
594 :group 'gnus-article-headers
597 (defcustom gnus-display-mime-function 'gnus-display-mime
598 "Function to display MIME articles."
599 :group 'gnus-article-mime
602 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
603 "Function used to decode headers.")
605 (defvar gnus-article-dumbquotes-map
623 "Table for MS-to-Latin1 translation.")
625 (defcustom gnus-ignored-mime-types nil
626 "List of MIME types that should be ignored by Gnus."
627 :group 'gnus-article-mime
628 :type '(repeat regexp))
630 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
631 "List of MIME types that should not be given buttons when rendered inline."
632 :group 'gnus-article-mime
633 :type '(repeat regexp))
635 (defcustom gnus-article-mime-part-function nil
636 "Function called with a MIME handle as the argument.
637 This is meant for people who want to do something automatic based
638 on parts -- for instance, adding Vcard info to a database."
639 :group 'gnus-article-mime
642 (defcustom gnus-mime-multipart-functions nil
643 "An alist of MIME types to functions to display them.")
645 (defcustom gnus-article-date-lapsed-new-header nil
646 "Whether the X-Sent and Date headers can coexist.
647 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
648 either replace the old \"Date:\" header (if this variable is nil), or
649 be added below it (otherwise)."
650 :group 'gnus-article-headers
653 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
654 "Function called with a MIME handle as the argument.
655 This is meant for people who want to view first matched part.
656 For `undisplayed-alternative' (default), the first undisplayed
657 part or alternative part is used. For `undisplayed', the first
658 undisplayed part is used. For a function, the first part which
659 the function return `t' is used. For `nil', the first part is
661 :group 'gnus-article-mime
663 (item :tag "first" :value nil)
664 (item :tag "undisplayed" :value undisplayed)
665 (item :tag "undisplayed or alternative"
666 :value undisplayed-alternative)
670 ;;; The treatment variables
673 (defvar gnus-part-display-hook nil
674 "Hook called on parts that are to receive treatment.")
676 (defvar gnus-article-treat-custom
677 '(choice (const :tag "Off" nil)
679 (const :tag "Header" head)
680 (const :tag "Last" last)
681 (const :tag "Mime" mime)
682 (integer :tag "Less")
683 (repeat :tag "Groups" regexp)
684 (sexp :tag "Predicate")))
686 (defvar gnus-article-treat-head-custom
687 '(choice (const :tag "Off" nil)
688 (const :tag "Header" head)))
690 (defvar gnus-article-treat-types '("text/plain")
693 (defvar gnus-inhibit-treatment nil
694 "Whether to inhibit treatment.")
696 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
697 "Highlight the signature.
698 Valid values are nil, t, `head', `last', an integer or a predicate.
699 See the manual for details."
700 :group 'gnus-article-treat
701 :type gnus-article-treat-custom)
702 (put 'gnus-treat-highlight-signature 'highlight t)
704 (defcustom gnus-treat-buttonize 100000
706 Valid values are nil, t, `head', `last', an integer or a predicate.
707 See the manual for details."
708 :group 'gnus-article-treat
709 :type gnus-article-treat-custom)
710 (put 'gnus-treat-buttonize 'highlight t)
712 (defcustom gnus-treat-buttonize-head 'head
713 "Add buttons to the head.
714 Valid values are nil, t, `head', `last', an integer or a predicate.
715 See the manual for details."
716 :group 'gnus-article-treat
717 :type gnus-article-treat-head-custom)
718 (put 'gnus-treat-buttonize-head 'highlight t)
720 (defcustom gnus-treat-emphasize nil
722 Valid values are nil, t, `head', `last', an integer or a predicate.
723 See the manual for details."
724 :group 'gnus-article-treat
725 :type gnus-article-treat-custom)
726 (put 'gnus-treat-emphasize 'highlight t)
728 (defcustom gnus-treat-strip-cr nil
729 "Remove carriage returns.
730 Valid values are nil, t, `head', `last', an integer or a predicate.
731 See the manual for details."
732 :group 'gnus-article-treat
733 :type gnus-article-treat-custom)
735 (defcustom gnus-treat-hide-headers 'head
737 Valid values are nil, t, `head', `last', an integer or a predicate.
738 See the manual for details."
739 :group 'gnus-article-treat
740 :type gnus-article-treat-head-custom)
742 (defcustom gnus-treat-hide-boring-headers nil
743 "Hide boring headers.
744 Valid values are nil, t, `head', `last', an integer or a predicate.
745 See the manual for details."
746 :group 'gnus-article-treat
747 :type gnus-article-treat-head-custom)
749 (defcustom gnus-treat-hide-signature nil
751 Valid values are nil, t, `head', `last', an integer or a predicate.
752 See the manual for details."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-custom)
756 (defcustom gnus-treat-fill-article nil
758 Valid values are nil, t, `head', `last', an integer or a predicate.
759 See the manual for details."
760 :group 'gnus-article-treat
761 :type gnus-article-treat-custom)
763 (defcustom gnus-treat-hide-citation nil
765 Valid values are nil, t, `head', `last', an integer or a predicate.
766 See the manual for details."
767 :group 'gnus-article-treat
768 :type gnus-article-treat-custom)
770 (defcustom gnus-treat-strip-list-identifiers 'head
771 "Strip list identifiers from `gnus-list-identifiers`.
772 Valid values are nil, t, `head', `last', an integer or a predicate.
773 See the manual for details."
774 :group 'gnus-article-treat
775 :type gnus-article-treat-custom)
777 (defcustom gnus-treat-strip-pgp t
778 "Strip PGP signatures.
779 Valid values are nil, t, `head', `last', an integer or a predicate.
780 See the manual for details."
781 :group 'gnus-article-treat
782 :type gnus-article-treat-custom)
784 (defcustom gnus-treat-strip-pem nil
785 "Strip PEM signatures.
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
791 (defcustom gnus-treat-strip-banner t
792 "Strip banners from articles.
793 The banner to be stripped is specified in the `banner' group parameter.
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
799 (defcustom gnus-treat-highlight-headers 'head
800 "Highlight the headers.
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See the manual for details."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-head-custom)
805 (put 'gnus-treat-highlight-headers 'highlight t)
807 (defcustom gnus-treat-highlight-citation t
808 "Highlight cited text.
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-custom)
813 (put 'gnus-treat-highlight-citation 'highlight t)
815 (defcustom gnus-treat-date-ut nil
816 "Display the Date in UT (GMT).
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-head-custom)
822 (defcustom gnus-treat-date-local nil
823 "Display the Date in the local timezone.
824 Valid values are nil, t, `head', `last', an integer or a predicate.
825 See the manual for details."
826 :group 'gnus-article-treat
827 :type gnus-article-treat-head-custom)
829 (defcustom gnus-treat-date-lapsed nil
830 "Display the Date header in a way that says how much time has elapsed.
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833 :group 'gnus-article-treat
834 :type gnus-article-treat-head-custom)
836 (defcustom gnus-treat-date-original nil
837 "Display the date in the original timezone.
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840 :group 'gnus-article-treat
841 :type gnus-article-treat-head-custom)
843 (defcustom gnus-treat-date-iso8601 nil
844 "Display the date in the ISO8601 format.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-head-custom)
850 (defcustom gnus-treat-date-user-defined nil
851 "Display the date in a user-defined format.
852 The format is defined by the `gnus-article-time-format' variable.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-head-custom)
858 (defcustom gnus-treat-strip-headers-in-body t
859 "Strip the X-No-Archive header line from the beginning of the body.
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862 :group 'gnus-article-treat
863 :type gnus-article-treat-custom)
865 (defcustom gnus-treat-strip-trailing-blank-lines nil
866 "Strip trailing blank lines.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
872 (defcustom gnus-treat-strip-leading-blank-lines nil
873 "Strip leading blank lines.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876 :group 'gnus-article-treat
877 :type gnus-article-treat-custom)
879 (defcustom gnus-treat-strip-multiple-blank-lines nil
880 "Strip multiple blank lines.
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-custom)
886 (defcustom gnus-treat-overstrike t
887 "Treat overstrike highlighting.
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-custom)
892 (put 'gnus-treat-overstrike 'highlight t)
894 (defcustom gnus-treat-display-xface
895 (if (or (and gnus-xemacs (featurep 'xface))
896 (eq 'x-face-mule-gnus-article-display-x-face
897 gnus-article-x-face-command))
900 "Display X-Face headers.
901 Valid values are nil, t, `head', `last', an integer or a predicate.
902 See the manual for details."
903 :group 'gnus-article-treat
904 :type gnus-article-treat-head-custom)
905 (put 'gnus-treat-display-xface 'highlight t)
907 (defcustom gnus-treat-display-smileys
908 (if (or (and gnus-xemacs (featurep 'xpm))
909 (and (not gnus-xemacs)
911 (module-installed-p 'gnus-bitmap)))
915 Valid values are nil, t, `head', `last', an integer or a predicate.
916 See the manual for details."
917 :group 'gnus-article-treat
918 :type gnus-article-treat-custom)
919 (put 'gnus-treat-display-smileys 'highlight t)
921 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
923 Valid values are nil, t, `head', `last', an integer or a predicate.
924 See the manual for details."
925 :group 'gnus-article-treat
926 :type gnus-article-treat-head-custom)
927 (put 'gnus-treat-display-picons 'highlight t)
929 (defcustom gnus-treat-capitalize-sentences nil
930 "Capitalize sentence-starting words.
931 Valid values are nil, t, `head', `last', an integer or a predicate.
932 See the manual for details."
933 :group 'gnus-article-treat
934 :type gnus-article-treat-custom)
936 (defcustom gnus-treat-fill-long-lines nil
938 Valid values are nil, t, `head', `last', an integer or a predicate.
939 See the manual for details."
940 :group 'gnus-article-treat
941 :type gnus-article-treat-custom)
943 (defcustom gnus-treat-play-sounds nil
945 Valid values are nil, t, `head', `last', an integer or a predicate.
946 See the manual for details."
947 :group 'gnus-article-treat
948 :type gnus-article-treat-custom)
950 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
951 "Decode an article as `default-mime-charset'. For instance, if you want to
952 attempt to decode an article even if the value of `gnus-show-mime' is nil,
953 you could set this variable to something like: nil for don't decode, t for
954 decode the body, '(or header t) for the whole article, etc."
955 :group 'gnus-article-treat
956 :type '(radio (const :tag "Off" nil)
957 (const :tag "Decode body" t)
958 (const :tag "Decode all" (or head t))))
960 (defcustom gnus-treat-translate nil
961 "Translate articles from one language to another.
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
967 ;;; Internal variables
969 (defvar article-goto-body-goes-to-point-min-p nil)
970 (defvar gnus-article-wash-types nil)
971 (defvar gnus-article-emphasis-alist nil)
973 (defvar gnus-article-mime-handle-alist-1 nil)
974 (defvar gnus-treatment-function-alist
975 '((gnus-treat-decode-article-as-default-mime-charset
976 gnus-article-decode-article-as-default-mime-charset)
977 (gnus-treat-strip-banner gnus-article-strip-banner)
978 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
979 (gnus-treat-buttonize gnus-article-add-buttons)
980 (gnus-treat-fill-article gnus-article-fill-cited-article)
981 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
982 (gnus-treat-strip-cr gnus-article-remove-cr)
983 (gnus-treat-display-xface gnus-article-display-x-face)
984 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
985 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
986 (gnus-treat-hide-signature gnus-article-hide-signature)
987 (gnus-treat-hide-citation gnus-article-hide-citation)
988 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
989 (gnus-treat-strip-pgp gnus-article-hide-pgp)
990 (gnus-treat-strip-pem gnus-article-hide-pem)
991 (gnus-treat-highlight-headers gnus-article-highlight-headers)
992 (gnus-treat-emphasize gnus-article-emphasize)
993 (gnus-treat-highlight-citation gnus-article-highlight-citation)
994 (gnus-treat-highlight-signature gnus-article-highlight-signature)
995 (gnus-treat-date-ut gnus-article-date-ut)
996 (gnus-treat-date-local gnus-article-date-local)
997 (gnus-treat-date-lapsed gnus-article-date-lapsed)
998 (gnus-treat-date-original gnus-article-date-original)
999 (gnus-treat-date-user-defined gnus-article-date-user)
1000 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1001 (gnus-treat-strip-trailing-blank-lines
1002 gnus-article-remove-trailing-blank-lines)
1003 (gnus-treat-strip-leading-blank-lines
1004 gnus-article-strip-leading-blank-lines)
1005 (gnus-treat-strip-multiple-blank-lines
1006 gnus-article-strip-multiple-blank-lines)
1007 (gnus-treat-overstrike gnus-article-treat-overstrike)
1008 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1009 (gnus-treat-display-smileys gnus-article-smiley-display)
1010 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1011 (gnus-treat-display-picons gnus-article-display-picons)
1012 (gnus-treat-play-sounds gnus-earcon-display)))
1014 (defvar gnus-article-mime-handle-alist nil)
1015 (defvar article-lapsed-timer nil)
1016 (defvar gnus-article-current-summary nil)
1018 (defvar gnus-article-mode-syntax-table
1019 (let ((table (copy-syntax-table text-mode-syntax-table)))
1020 (modify-syntax-entry ?- "w" table)
1021 (modify-syntax-entry ?> ")" table)
1022 (modify-syntax-entry ?< "(" table)
1024 "Syntax table used in article mode buffers.
1025 Initialized from `text-mode-syntax-table.")
1027 (defvar gnus-save-article-buffer nil)
1029 (defvar gnus-article-mode-line-format-alist
1030 (nconc '((?w (gnus-article-wash-status) ?s)
1031 (?m (gnus-article-mime-part-status) ?s))
1032 gnus-summary-mode-line-format-alist))
1034 (defvar gnus-number-of-articles-to-be-saved nil)
1036 (defvar gnus-inhibit-hiding nil)
1038 (defsubst gnus-article-hide-text (b e props)
1039 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1040 (add-text-properties b e props)
1041 (when (memq 'intangible props)
1043 (max (1- b) (point-min))
1044 b 'intangible (cddr (memq 'intangible props)))))
1045 (defsubst gnus-article-unhide-text (b e)
1046 "Remove hidden text properties from region between B and E."
1047 (remove-text-properties b e gnus-hidden-properties)
1048 (when (memq 'intangible gnus-hidden-properties)
1049 (put-text-property (max (1- b) (point-min))
1050 b 'intangible nil)))
1052 (defun gnus-article-hide-text-type (b e type)
1053 "Hide text of TYPE between B and E."
1054 (push type gnus-article-wash-types)
1055 (gnus-article-hide-text
1056 b e (cons 'article-type (cons type gnus-hidden-properties))))
1058 (defun gnus-article-unhide-text-type (b e type)
1059 "Unhide text of TYPE between B and E."
1060 (setq gnus-article-wash-types
1061 (delq type gnus-article-wash-types))
1062 (remove-text-properties
1063 b e (cons 'article-type (cons type gnus-hidden-properties)))
1064 (when (memq 'intangible gnus-hidden-properties)
1065 (put-text-property (max (1- b) (point-min))
1066 b 'intangible nil)))
1068 (defun gnus-article-hide-text-of-type (type)
1069 "Hide text of TYPE in the current buffer."
1071 (let ((b (point-min))
1073 (while (setq b (text-property-any b e 'article-type type))
1074 (add-text-properties b (incf b) gnus-hidden-properties)))))
1076 (defun gnus-article-delete-text-of-type (type)
1077 "Delete text of TYPE in the current buffer."
1079 (let ((b (point-min)))
1080 (while (setq b (text-property-any b (point-max) 'article-type type))
1082 b (or (text-property-not-all b (point-max) 'article-type type)
1085 (defun gnus-article-delete-invisible-text ()
1086 "Delete all invisible text in the current buffer."
1088 (let ((b (point-min)))
1089 (while (setq b (text-property-any b (point-max) 'invisible t))
1091 b (or (text-property-not-all b (point-max) 'invisible t)
1094 (defun gnus-article-text-type-exists-p (type)
1095 "Say whether any text of type TYPE exists in the buffer."
1096 (text-property-any (point-min) (point-max) 'article-type type))
1098 (defsubst gnus-article-header-rank ()
1099 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1100 (let ((list gnus-sorted-header-list)
1103 (when (looking-at (car list))
1105 (setq list (cdr list))
1109 (defun article-hide-headers (&optional arg delete)
1110 "Hide unwanted headers and possibly sort them as well."
1111 (interactive (gnus-article-hidden-arg))
1112 ;; Lars said that this function might be inhibited.
1113 (if (gnus-article-check-hidden-text 'headers arg)
1115 ;; Show boring headers as well.
1116 (gnus-article-show-hidden-text 'boring-headers)
1117 (when (eq 1 (point-min))
1118 (set-window-start (get-buffer-window (current-buffer)) 1)))
1119 (unless gnus-inhibit-hiding
1122 (let ((buffer-read-only nil)
1123 (inhibit-read-only t)
1124 (case-fold-search t)
1125 (max (1+ (length gnus-sorted-header-list)))
1126 (ignored (when (not gnus-visible-headers)
1127 (cond ((stringp gnus-ignored-headers)
1128 gnus-ignored-headers)
1129 ((listp gnus-ignored-headers)
1130 (mapconcat 'identity gnus-ignored-headers
1133 (cond ((stringp gnus-visible-headers)
1134 gnus-visible-headers)
1135 ((and gnus-visible-headers
1136 (listp gnus-visible-headers))
1137 (mapconcat 'identity gnus-visible-headers "\\|"))))
1138 (inhibit-point-motion-hooks t)
1140 ;; First we narrow to just the headers.
1141 (article-narrow-to-head)
1142 ;; Hide any "From " lines at the beginning of (mail) articles.
1143 (while (looking-at "From ")
1147 (delete-region (point-min) (point))
1148 (gnus-article-hide-text (point-min) (point)
1149 (nconc (list 'article-type 'headers)
1150 gnus-hidden-properties))))
1151 ;; Then treat the rest of the header lines.
1152 ;; Then we use the two regular expressions
1153 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1154 ;; select which header lines is to remain visible in the
1156 (while (re-search-forward "^[^ \t]*:" nil t)
1158 ;; Mark the rank of the header.
1160 (point) (1+ (point)) 'message-rank
1161 (if (or (and visible (looking-at visible))
1163 (not (looking-at ignored))))
1164 (gnus-article-header-rank)
1167 (message-sort-headers-1)
1168 (when (setq beg (text-property-any
1169 (point-min) (point-max) 'message-rank (+ 2 max)))
1170 ;; We delete or make invisible the unwanted headers.
1171 (push 'headers gnus-article-wash-types)
1174 (add-text-properties
1175 (point-min) (+ 5 (point-min))
1176 '(article-type headers dummy-invisible t))
1177 (delete-region beg (point-max)))
1178 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1181 (defun article-hide-boring-headers (&optional arg)
1182 "Toggle hiding of headers that aren't very interesting.
1183 If given a negative prefix, always show; if given a positive prefix,
1185 (interactive (gnus-article-hidden-arg))
1186 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1187 (not gnus-show-all-headers))
1190 (let ((buffer-read-only nil)
1191 (list gnus-boring-article-headers)
1192 (inhibit-point-motion-hooks t)
1194 (article-narrow-to-head)
1196 (setq elem (pop list))
1197 (goto-char (point-min))
1199 ;; Hide empty headers.
1201 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1203 (gnus-article-hide-text-type
1204 (progn (beginning-of-line) (point))
1207 (if (re-search-forward "^[^ \t]" nil t)
1211 ;; Hide boring Newsgroups header.
1212 ((eq elem 'newsgroups)
1213 (when (equal (gnus-fetch-field "newsgroups")
1214 (gnus-group-real-name
1215 (if (boundp 'gnus-newsgroup-name)
1218 (gnus-article-hide-header "newsgroups")))
1219 ((eq elem 'followup-to)
1220 (when (equal (message-fetch-field "followup-to")
1221 (message-fetch-field "newsgroups"))
1222 (gnus-article-hide-header "followup-to")))
1223 ((eq elem 'reply-to)
1224 (let ((from (message-fetch-field "from"))
1225 (reply-to (message-fetch-field "reply-to")))
1230 (nth 1 (funcall gnus-extract-address-components from))
1231 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1232 (gnus-article-hide-header "reply-to"))))
1234 (let ((date (message-fetch-field "date")))
1236 (< (days-between (current-time-string) date)
1238 (gnus-article-hide-header "date"))))
1240 (let ((to (message-fetch-field "to"))
1241 (cc (message-fetch-field "cc")))
1242 (when (> (length to) 1024)
1243 (gnus-article-hide-header "to"))
1244 (when (> (length cc) 1024)
1245 (gnus-article-hide-header "cc"))))
1249 (goto-char (point-min))
1250 (while (re-search-forward "^to:" nil t)
1251 (setq to-count (1+ to-count)))
1252 (when (> to-count 1)
1253 (while (> to-count 0)
1254 (goto-char (point-min))
1256 (re-search-forward "^to:" nil nil to-count)
1258 (narrow-to-region (point) (point-max))
1259 (gnus-article-hide-header "to"))
1260 (setq to-count (1- to-count))))
1261 (goto-char (point-min))
1262 (while (re-search-forward "^cc:" nil t)
1263 (setq cc-count (1+ cc-count)))
1264 (when (> cc-count 1)
1265 (while (> cc-count 0)
1266 (goto-char (point-min))
1268 (re-search-forward "^cc:" nil nil cc-count)
1270 (narrow-to-region (point) (point-max))
1271 (gnus-article-hide-header "cc"))
1272 (setq cc-count (1- cc-count)))))))))))))
1274 (defun gnus-article-hide-header (header)
1276 (goto-char (point-min))
1277 (when (re-search-forward (concat "^" header ":") nil t)
1278 (gnus-article-hide-text-type
1279 (progn (beginning-of-line) (point))
1282 (if (re-search-forward "^[^ \t]" nil t)
1287 (defun article-toggle-headers (&optional arg)
1288 "Toggle hiding of headers. If given a negative prefix, always show;
1289 if given a positive prefix, always hide."
1290 (interactive (gnus-article-hidden-arg))
1291 (let ((force (when (numberp arg)
1292 (cond ((> arg 0) 'always-hide)
1293 ((< arg 0) 'always-show))))
1294 (window (get-buffer-window gnus-article-buffer))
1295 (header-end (point-min))
1296 header-start field-end field-start
1297 (inhibit-point-motion-hooks t)
1298 (inhibit-read-only t)
1302 (while (and (setq header-start
1303 (text-property-any header-end (point-max)
1304 'article-treated-header t))
1306 (text-property-not-all header-start (point-max)
1307 'article-treated-header t)))
1308 (setq field-end header-start)
1310 (;; Hide exposed invisible fields.
1311 (and (not (eq 'always-show force))
1313 (text-property-any field-end header-end
1314 'exposed-invisible-field t)))
1315 (while (and field-start
1316 (setq field-end (text-property-not-all
1317 field-start header-end
1318 'exposed-invisible-field t)))
1319 (add-text-properties field-start field-end gnus-hidden-properties)
1320 (setq field-start (text-property-any field-end header-end
1321 'exposed-invisible-field t)))
1322 (put-text-property header-start header-end
1323 'exposed-invisible-field nil))
1324 (;; Expose invisible fields.
1325 (and (not (eq 'always-hide force))
1327 (text-property-any field-end header-end 'invisible t)))
1328 (while (and field-start
1329 (setq field-end (text-property-not-all
1330 field-start header-end
1332 ;; If the invisible text is not terminated with newline, we
1333 ;; won't expose it. Because it may be created by x-face-mule.
1334 ;; BTW, XEmacs sometimes fail in putting a invisible text
1335 ;; property with `gnus-article-hide-text' (really?). In that
1336 ;; case, the invisible text might be started from the middle of
1337 ;; a line so we will expose the sort of thing.
1338 (when (or (not (or (eq header-start field-start)
1339 (eq ?\n (char-before field-start))))
1340 (eq ?\n (char-before field-end)))
1341 (remove-text-properties field-start field-end
1342 gnus-hidden-properties)
1343 (put-text-property field-start field-end
1344 'exposed-invisible-field t))
1345 (setq field-start (text-property-any field-end header-end
1348 (not (eq 'always-show force))
1349 (narrow-to-region header-start header-end)
1350 (article-hide-headers)
1351 ;; Re-display X-Face image under XEmacs.
1352 (when (and gnus-xemacs
1353 (gnus-functionp gnus-article-x-face-command))
1354 (let ((func (cadr (assq 'gnus-treat-display-xface
1355 gnus-treatment-function-alist)))
1357 (when (and (not gnus-inhibit-treatment)
1359 (gnus-treat-predicate gnus-treat-display-xface))
1361 (put-text-property header-start header-end 'read-only nil))))
1364 (goto-char (point-min))
1366 (set-window-start window (point-min))))))
1368 (defvar gnus-article-normalized-header-length 40
1369 "Length of normalized headers.")
1371 (defun article-normalize-headers ()
1372 "Make all header lines 40 characters long."
1374 (let ((buffer-read-only nil)
1378 (article-narrow-to-head)
1381 ((< (setq column (- (gnus-point-at-eol) (point)))
1382 gnus-article-normalized-header-length)
1384 (insert (make-string
1385 (- gnus-article-normalized-header-length column)
1387 ((> column gnus-article-normalized-header-length)
1388 (gnus-put-text-property
1390 (forward-char gnus-article-normalized-header-length)
1397 (forward-line 1))))))
1399 (defun article-treat-dumbquotes ()
1400 "Translate M******** sm*rtq**t*s into proper text.
1401 Note that this function guesses whether a character is a sm*rtq**t* or
1402 not, so it should only be used interactively."
1404 (article-translate-strings gnus-article-dumbquotes-map))
1406 (defun article-translate-characters (from to)
1407 "Translate all characters in the body of the article according to FROM and TO.
1408 FROM is a string of characters to translate from; to is a string of
1409 characters to translate to."
1411 (when (article-goto-body)
1412 (let ((buffer-read-only nil)
1413 (x (make-string 225 ?x))
1415 (while (< (incf i) (length x))
1418 (while (< i (length from))
1419 (aset x (aref from i) (aref to i))
1421 (translate-region (point) (point-max) x)))))
1423 (defun article-translate-strings (map)
1424 "Translate all string in the body of the article according to MAP.
1425 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1427 (when (article-goto-body)
1428 (let ((buffer-read-only nil)
1430 (while (setq elem (pop map))
1432 (while (search-forward (car elem) nil t)
1433 (replace-match (cadr elem)))))))))
1435 (defun article-treat-overstrike ()
1436 "Translate overstrikes into bold text."
1439 (when (article-goto-body)
1440 (let ((buffer-read-only nil))
1441 (while (search-forward "\b" nil t)
1442 (let ((next (char-after))
1446 previous (char-after))
1450 ;; We do the boldification/underlining by hiding the
1451 ;; overstrikes and putting the proper text property
1455 (gnus-article-hide-text-type start (point) 'overstrike)
1456 (put-text-property (point) end 'face 'bold))
1458 (gnus-article-hide-text-type
1459 (1- (point)) (1+ (point)) 'overstrike)
1461 start (1- (point)) 'face 'underline))
1463 (gnus-article-hide-text-type start (point) 'overstrike)
1465 (point) end 'face 'underline)))))))))
1467 (defun article-fill-long-lines ()
1468 "Fill lines that are wider than the window width."
1471 (let ((buffer-read-only nil)
1472 (width (window-width (get-buffer-window (current-buffer)))))
1475 (let ((adaptive-fill-mode nil))
1478 (when (>= (current-column) (min fill-column width))
1479 (narrow-to-region (point) (gnus-point-at-bol))
1480 (fill-paragraph nil)
1481 (goto-char (point-max))
1483 (forward-line 1)))))))
1485 (defun article-capitalize-sentences ()
1486 "Capitalize the first word in each sentence."
1489 (let ((buffer-read-only nil)
1490 (paragraph-start "^[\n\^L]"))
1494 (forward-sentence)))))
1496 (defun article-remove-cr ()
1497 "Remove trailing CRs and then translate remaining CRs into LFs."
1500 (let ((buffer-read-only nil))
1501 (goto-char (point-min))
1502 (while (re-search-forward "\r+$" nil t)
1503 (replace-match "" t t))
1504 (goto-char (point-min))
1505 (while (search-forward "\r" nil t)
1506 (replace-match "\n" t t)))))
1508 (defun article-remove-trailing-blank-lines ()
1509 "Remove all trailing blank lines from the article."
1512 (let ((buffer-read-only nil))
1513 (goto-char (point-max))
1517 (while (and (not (bobp))
1518 (looking-at "^[ \t]*$")
1519 (not (gnus-annotation-in-region-p
1520 (point) (gnus-point-at-eol))))
1525 (defun article-display-x-face (&optional force)
1526 "Look for an X-Face header and display it if present."
1527 (interactive (list 'force))
1529 ;; Delete the old process, if any.
1530 (when (process-status "article-x-face")
1531 (delete-process "article-x-face"))
1532 (let ((inhibit-point-motion-hooks t)
1533 (case-fold-search t)
1536 (article-narrow-to-head)
1537 (goto-char (point-min))
1538 (setq from (message-fetch-field "from"))
1539 (goto-char (point-min))
1540 (while (and gnus-article-x-face-command
1543 ;; Check whether this face is censored.
1544 (not gnus-article-x-face-too-ugly)
1545 (and gnus-article-x-face-too-ugly from
1546 (not (string-match gnus-article-x-face-too-ugly
1548 ;; Has to be present.
1549 (re-search-forward "^X-Face:[ \t]*" nil t))
1550 ;; This used to try to do multiple faces (`while' instead of
1551 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1552 ;; work (b) it can crash some versions of Emacs (c) are
1553 ;; multiple faces really something to encourage?
1554 (when (stringp gnus-article-x-face-command)
1556 ;; We now have the area of the buffer where the X-Face is stored.
1559 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1560 ;; We display the face.
1561 (if (symbolp gnus-article-x-face-command)
1562 ;; The command is a lisp function, so we call it.
1563 (if (gnus-functionp gnus-article-x-face-command)
1564 (funcall gnus-article-x-face-command beg end)
1565 (error "%s is not a function" gnus-article-x-face-command))
1566 ;; The command is a string, so we interpret the command
1567 ;; as a, well, command, and fork it off.
1568 (let ((process-connection-type nil))
1569 (process-kill-without-query
1571 "article-x-face" nil shell-file-name shell-command-switch
1572 gnus-article-x-face-command))
1573 (process-send-region "article-x-face" beg end)
1574 (process-send-eof "article-x-face"))))))))))
1576 (defun article-decode-mime-words ()
1577 "Decode all MIME-encoded words in the article."
1580 (set-buffer gnus-article-buffer)
1581 (let ((inhibit-point-motion-hooks t)
1583 (mail-parse-charset gnus-newsgroup-charset)
1584 (mail-parse-ignored-charsets
1585 (save-excursion (set-buffer gnus-summary-buffer)
1586 gnus-newsgroup-ignored-charsets)))
1587 (mail-decode-encoded-word-region (point-min) (point-max)))))
1589 (defun article-decode-charset (&optional prompt)
1590 "Decode charset-encoded text in the article.
1591 If PROMPT (the prefix), prompt for a coding system to use."
1593 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1595 (mail-parse-charset gnus-newsgroup-charset)
1596 (mail-parse-ignored-charsets
1597 (save-excursion (condition-case nil
1598 (set-buffer gnus-summary-buffer)
1600 gnus-newsgroup-ignored-charsets))
1601 ct cte ctl charset format)
1604 (article-narrow-to-head)
1605 (setq ct (message-fetch-field "Content-Type" t)
1606 cte (message-fetch-field "Content-Transfer-Encoding" t)
1607 ctl (and ct (ignore-errors
1608 (mail-header-parse-content-type ct)))
1611 (mm-read-coding-system "Charset to decode: "))
1613 (mail-content-type-get ctl 'charset)))
1614 format (and ctl (mail-content-type-get ctl 'format)))
1616 (setq cte (mail-header-strip cte)))
1617 (if (and ctl (not (string-match "/" (car ctl))))
1619 (goto-char (point-max)))
1622 (narrow-to-region (point) (point-max))
1623 (when (and (or (not ctl)
1624 (equal (car ctl) "text/plain"))
1625 (not format)) ;; article with format will decode later.
1627 charset (and cte (intern (downcase
1628 (gnus-strip-whitespace cte))))
1631 (defun article-decode-encoded-words ()
1632 "Remove encoded-word encoding from headers."
1633 (let (buffer-read-only)
1634 (let ((charset (save-excursion
1635 (set-buffer gnus-summary-buffer)
1636 default-mime-charset)))
1637 (mime-decode-header-in-buffer charset)
1640 (defun article-de-quoted-unreadable (&optional force)
1641 "Translate a quoted-printable-encoded article.
1642 If FORCE, decode the article whether it is marked as quoted-printable
1644 (interactive (list 'force))
1646 (let ((buffer-read-only nil)
1647 (type (gnus-fetch-field "content-transfer-encoding"))
1648 (charset gnus-newsgroup-charset))
1650 (and type (string-match "quoted-printable" (downcase type))))
1652 (quoted-printable-decode-region (point) (point-max) charset)))))
1654 (defun article-de-base64-unreadable (&optional force)
1655 "Translate a base64 article.
1656 If FORCE, decode the article whether it is marked as base64 not."
1657 (interactive (list 'force))
1659 (let ((buffer-read-only nil)
1660 (type (gnus-fetch-field "content-transfer-encoding"))
1661 (charset gnus-newsgroup-charset))
1663 (and type (string-match "quoted-printable" (downcase type))))
1666 (narrow-to-region (point) (point-max))
1667 (base64-decode-region (point-min) (point-max))
1668 (if (mm-coding-system-p charset)
1669 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1674 (defun article-decode-HZ ()
1675 "Translate a HZ-encoded article."
1679 (let ((buffer-read-only nil))
1680 (rfc1843-decode-region (point-min) (point-max)))))
1682 (defun article-wash-html ()
1683 "Format an html article."
1686 (let ((buffer-read-only nil)
1687 (charset gnus-newsgroup-charset))
1689 (save-window-excursion
1691 (narrow-to-region (point) (point-max))
1693 (let ((w3-strict-width (window-width))
1694 (url-standalone-mode t))
1696 (w3-region (point-min) (point-max))
1699 (defun article-hide-list-identifiers ()
1700 "Remove list identifies from the Subject header.
1701 The `gnus-list-identifiers' variable specifies what to do."
1705 (let ((inhibit-point-motion-hooks t)
1707 (article-narrow-to-head)
1708 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1709 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1711 (goto-char (point-min))
1712 (when (re-search-forward
1713 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1714 " *\\)\\)+\\(Re: +\\)?\\)")
1716 (let ((s (or (match-string 3) (match-string 5))))
1717 (delete-region (match-beginning 1) (match-end 1))
1719 (goto-char (match-beginning 1))
1722 (defun article-hide-pgp ()
1723 "Remove any PGP headers and signatures in the current article."
1727 (let ((inhibit-point-motion-hooks t)
1728 buffer-read-only beg end)
1730 ;; Hide the "header".
1731 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1732 (push 'pgp gnus-article-wash-types)
1733 (delete-region (match-beginning 0) (match-end 0))
1734 ;; Remove armor headers (rfc2440 6.2)
1735 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1738 ;; Hide the actual signature.
1739 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1740 (setq end (1+ (match-beginning 0)))
1743 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1745 ;; Perhaps we shouldn't hide to the end of the buffer
1746 ;; if there is no end to the signature?
1748 ;; Hide "- " PGP quotation markers.
1750 (narrow-to-region beg end)
1751 (goto-char (point-min))
1752 (while (re-search-forward "^- " nil t)
1754 (match-beginning 0) (match-end 0)))
1756 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1758 (defun article-hide-pem (&optional arg)
1759 "Toggle hiding of any PEM headers and signatures in the current article.
1760 If given a negative prefix, always show; if given a positive prefix,
1762 (interactive (gnus-article-hidden-arg))
1763 (unless (gnus-article-check-hidden-text 'pem arg)
1765 (let (buffer-read-only end)
1766 (goto-char (point-min))
1767 ;; Hide the horrendously ugly "header".
1768 (when (and (search-forward
1769 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1771 (setq end (1+ (match-beginning 0))))
1772 (push 'pem gnus-article-wash-types)
1773 (gnus-article-hide-text-type
1775 (if (search-forward "\n\n" nil t)
1779 ;; Hide the trailer as well
1780 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1782 (gnus-article-hide-text-type
1783 (match-beginning 0) (match-end 0) 'pem)))))))
1785 (defun article-strip-banner ()
1786 "Strip the banner specified by the `banner' group parameter."
1790 (let ((inhibit-point-motion-hooks t)
1791 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1792 (gnus-signature-limit nil)
1793 buffer-read-only beg end)
1797 ((eq banner 'signature)
1798 (when (gnus-article-narrow-to-signature)
1801 (delete-region (point) (point-max))))
1803 (while (re-search-forward banner nil t)
1804 (delete-region (match-beginning 0) (match-end 0))))))))))
1806 (defun article-babel ()
1807 "Translate article using an online translation service."
1811 (set-buffer gnus-article-buffer)
1812 (when (article-goto-body)
1813 (let* ((buffer-read-only nil)
1816 (orig (buffer-substring start end))
1817 (trans (babel-as-string orig)))
1819 (narrow-to-region start end)
1820 (delete-region start end)
1823 (defun article-hide-signature (&optional arg)
1824 "Hide the signature in the current article.
1825 If given a negative prefix, always show; if given a positive prefix,
1827 (interactive (gnus-article-hidden-arg))
1833 (article-goto-body))
1834 (goto-char (point-min)))
1835 (unless (gnus-article-check-hidden-text 'signature arg)
1836 (let ((buffer-read-only nil)
1838 (while (setq button (text-property-any button (point-max)
1840 'gnus-signature-toggle))
1841 (setq button (text-property-not-all button (point-max)
1843 'gnus-signature-toggle))
1844 (when (and button (not (eobp)))
1845 (gnus-article-hide-text-type
1847 (next-single-property-change (1+ button) 'mime-view-entity
1851 (defun article-strip-headers-in-body ()
1852 "Strip offensive headers from bodies."
1856 (let ((case-fold-search t))
1857 (when (looking-at "x-no-archive:")
1858 (gnus-delete-line)))))
1860 (defun article-strip-leading-blank-lines ()
1861 "Remove all blank lines from the beginning of the article."
1864 (let ((inhibit-point-motion-hooks t)
1866 (when (article-goto-body)
1867 (while (and (not (eobp))
1868 (looking-at "[ \t]*$"))
1869 (gnus-delete-line))))))
1871 (defun article-narrow-to-head ()
1872 "Narrow the buffer to the head of the message.
1873 Point is left at the beginning of the narrowed-to region."
1875 (goto-char (point-min))
1876 (if (search-forward "\n\n" nil 1)
1879 (goto-char (point-min)))
1881 (defun article-goto-body ()
1882 "Place point at the start of the body."
1883 (goto-char (point-min))
1885 ;; This variable is only bound when dealing with separate
1887 (article-goto-body-goes-to-point-min-p
1889 ((search-forward "\n\n" nil t)
1892 (goto-char (point-max))
1895 (defun article-strip-multiple-blank-lines ()
1896 "Replace consecutive blank lines with one empty line."
1899 (let ((inhibit-point-motion-hooks t)
1901 ;; First make all blank lines empty.
1903 (while (re-search-forward "^[ \t]+$" nil t)
1904 (unless (gnus-annotation-in-region-p
1905 (match-beginning 0) (match-end 0))
1906 (replace-match "" nil t)))
1907 ;; Then replace multiple empty lines with a single empty line.
1909 (while (re-search-forward "\n\n\n+" nil t)
1910 (unless (gnus-annotation-in-region-p
1911 (match-beginning 0) (match-end 0))
1912 (replace-match "\n\n" t t))))))
1914 (defun article-strip-leading-space ()
1915 "Remove all white space from the beginning of the lines in the article."
1918 (let ((inhibit-point-motion-hooks t)
1921 (while (re-search-forward "^[ \t]+" nil t)
1922 (replace-match "" t t)))))
1924 (defun article-strip-trailing-space ()
1925 "Remove all white space from the end of the lines in the article."
1928 (let ((inhibit-point-motion-hooks t)
1931 (while (re-search-forward "[ \t]+$" nil t)
1932 (replace-match "" t t)))))
1934 (defun article-strip-blank-lines ()
1935 "Strip leading, trailing and multiple blank lines."
1937 (article-strip-leading-blank-lines)
1938 (article-remove-trailing-blank-lines)
1939 (article-strip-multiple-blank-lines))
1941 (defun article-strip-all-blank-lines ()
1942 "Strip all blank lines."
1945 (let ((inhibit-point-motion-hooks t)
1948 (while (re-search-forward "^[ \t]*\n" nil t)
1949 (replace-match "" t t)))))
1951 (defun gnus-article-narrow-to-signature ()
1952 "Narrow to the signature; return t if a signature is found, else nil."
1953 (let ((inhibit-point-motion-hooks t))
1954 (when (gnus-article-search-signature)
1956 ;; Check whether we have some limits to what we consider
1957 ;; to be a signature.
1958 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1959 (list gnus-signature-limit)))
1961 (while (setq limit (pop limits))
1962 (if (or (and (integerp limit)
1963 (< (- (point-max) (point)) limit))
1965 (< (count-lines (point) (point-max)) limit))
1966 (and (gnus-functionp limit)
1968 (and (stringp limit)
1969 (not (re-search-forward limit nil t))))
1970 () ; This limit did not succeed.
1974 (narrow-to-region (point) (point-max))
1977 (defun gnus-article-search-signature ()
1978 "Search the current buffer for the signature separator.
1979 Put point at the beginning of the signature separator."
1980 (let ((cur (point)))
1981 (goto-char (point-max))
1982 (if (if (stringp gnus-signature-separator)
1983 (re-search-backward gnus-signature-separator nil t)
1984 (let ((seps gnus-signature-separator))
1986 (not (re-search-backward (car seps) nil t)))
1993 (defun gnus-article-hidden-arg ()
1994 "Return the current prefix arg as a number, or 0 if no prefix."
1995 (list (if current-prefix-arg
1996 (prefix-numeric-value current-prefix-arg)
1999 (defun gnus-article-check-hidden-text (type arg)
2000 "Return nil if hiding is necessary.
2001 Arg can be nil or a number. Nil and positive means hide, negative
2002 means show, 0 means toggle."
2005 (let ((hide (gnus-article-hidden-text-p type)))
2011 (gnus-article-show-hidden-text type))
2013 (if (eq hide 'hidden)
2014 (gnus-article-show-hidden-text type)
2017 (defun gnus-article-hidden-text-p (type)
2018 "Say whether the current buffer contains hidden text of type TYPE."
2019 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2021 (not (get-text-property pos 'invisible))
2022 (not (get-text-property pos 'dummy-invisible)))
2024 (text-property-any (1+ pos) (point-max) 'article-type type)))
2029 (defun gnus-article-show-hidden-text (type &optional hide)
2030 "Show all hidden text of type TYPE.
2031 If HIDE, hide the text instead."
2033 (let ((buffer-read-only nil)
2034 (inhibit-point-motion-hooks t)
2037 (while (setq beg (text-property-any end (point-max) 'article-type type))
2040 (text-property-not-all beg (point-max) 'article-type type)
2043 (gnus-article-hide-text beg end gnus-hidden-properties)
2044 (gnus-article-unhide-text beg end))
2048 (defconst article-time-units
2049 `((year . ,(* 365.25 24 60 60))
2050 (week . ,(* 7 24 60 60))
2051 (day . ,(* 24 60 60))
2055 "Mapping from time units to seconds.")
2057 (defun article-date-ut (&optional type highlight header)
2058 "Convert DATE date to universal time in the current article.
2059 If TYPE is `local', convert to local time; if it is `lapsed', output
2060 how much time has lapsed since DATE. For `lapsed', the value of
2061 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2062 should replace the \"Date:\" one, or should be added below it."
2063 (interactive (list 'ut t))
2064 (let* ((header (or header
2065 (and (eq 1 (point-min))
2066 (mail-header-date (save-excursion
2067 (set-buffer gnus-summary-buffer)
2068 gnus-current-headers)))
2069 (message-fetch-field "date")
2071 (date (if (vectorp header) (mail-header-date header)
2073 (inhibit-point-motion-hooks t)
2074 bface eface date-pos)
2075 (when (and date (not (string= date "")))
2078 (article-narrow-to-head)
2079 (when (or (and (eq type 'lapsed)
2080 gnus-article-date-lapsed-new-header
2081 ;; Attempt to get the face of X-Sent first.
2082 (re-search-forward "^X-Sent:[ \t]" nil t))
2083 (re-search-forward "^Date:[ \t]" nil t)
2084 ;; If Date is missing, try again for X-Sent.
2085 (re-search-forward "^X-Sent:[ \t]" nil t))
2086 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2087 date (or (get-text-property (gnus-point-at-bol)
2090 eface (get-text-property (1- (gnus-point-at-eol))
2092 (let ((buffer-read-only nil))
2093 ;; Delete any old X-Sent headers.
2094 (when (setq date-pos
2095 (text-property-any (point-min) (point-max)
2096 'article-date-lapsed t))
2097 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2098 (delete-region (match-beginning 0)
2099 (progn (forward-line 1) (point))))
2100 (goto-char (point-min))
2101 ;; Delete any old Date headers.
2102 (while (re-search-forward "^Date:[ \t]" nil t)
2104 (setq date-pos (match-beginning 0)))
2105 (unless (and (eq type 'lapsed)
2106 gnus-article-date-lapsed-new-header)
2107 (delete-region (match-beginning 0)
2108 (progn (message-next-header) (point)))))
2111 (goto-char date-pos)
2113 ;; Possibly, Date has been deleted.
2115 (when (and (eq type 'lapsed)
2116 gnus-article-date-lapsed-new-header
2117 (looking-at "Date:"))
2119 (goto-char (point-min)))
2120 (insert (article-make-date-line date type))
2121 (when (eq type 'lapsed)
2122 (put-text-property (gnus-point-at-bol) (point)
2123 'article-date-lapsed t))
2127 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2128 (put-text-property (match-beginning 1) (1+ (match-end 1))
2129 'original-date date)
2130 (put-text-property (match-beginning 1) (1+ (match-end 1))
2132 (put-text-property (match-beginning 2) (match-end 2)
2135 (defun article-make-date-line (date type)
2136 "Return a DATE line of TYPE."
2137 (let ((time (condition-case ()
2141 ;; Convert to the local timezone. We have to slap a
2142 ;; `condition-case' round the calls to the timezone
2143 ;; functions since they aren't particularly resistant to
2146 (let ((tz (car (current-time-zone time))))
2147 (format "Date: %s %s%02d%02d" (current-time-string time)
2148 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2149 (/ (% (abs tz) 3600) 60))))
2150 ;; Convert to Universal Time.
2153 (current-time-string
2154 (let* ((e (parse-time-string date))
2155 (tm (apply 'encode-time e))
2157 (ls (- (cadr tm) (car (current-time-zone time)))))
2158 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2159 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2162 ;; Get the original date from the article.
2163 ((eq type 'original)
2164 (concat "Date: " (if (string-match "\n+$" date)
2165 (substring date 0 (match-beginning 0))
2167 ;; Let the user define the format.
2169 (if (gnus-functionp gnus-article-time-format)
2170 (funcall gnus-article-time-format time)
2173 (format-time-string gnus-article-time-format time))))
2176 (let ((tz (car (current-time-zone time))))
2179 (format-time-string "%Y%m%dT%H%M%S" time)
2180 (format "%s%02d%02d"
2181 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2182 (/ (% (abs tz) 3600) 60)))))
2183 ;; Do an X-Sent lapsed format.
2185 ;; If the date is seriously mangled, the timezone functions are
2186 ;; liable to bug out, so we ignore all errors.
2187 (let* ((now (current-time))
2188 (real-time (subtract-time now time))
2189 (real-sec (and real-time
2190 (+ (* (float (car real-time)) 65536)
2192 (sec (and real-time (abs real-sec)))
2202 ;; This is a bit convoluted, but basically we go
2203 ;; through the time units for years, weeks, etc,
2204 ;; and divide things to see whether that results
2205 ;; in positive answers.
2208 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2209 ;; The (remaining) seconds are too few to
2210 ;; be divided into this time unit.
2212 ;; It's big enough, so we output it.
2213 (setq sec (- sec (* num (cdr unit))))
2215 (concat (if prev ", " "") (int-to-string
2217 " " (symbol-name (car unit))
2218 (if (> num 1) "s" ""))
2220 article-time-units "")
2221 ;; If dates are odd, then it might appear like the
2222 ;; article was sent in the future.
2225 " in the future"))))))
2227 (error "Unknown conversion type: %s" type)))))
2229 (defun article-date-local (&optional highlight)
2230 "Convert the current article date to the local timezone."
2231 (interactive (list t))
2232 (article-date-ut 'local highlight))
2234 (defun article-date-original (&optional highlight)
2235 "Convert the current article date to what it was originally.
2236 This is only useful if you have used some other date conversion
2237 function and want to see what the date was before converting."
2238 (interactive (list t))
2239 (article-date-ut 'original highlight))
2241 (defun article-date-lapsed (&optional highlight)
2242 "Convert the current article date to time lapsed since it was sent."
2243 (interactive (list t))
2244 (article-date-ut 'lapsed highlight))
2246 (defun article-update-date-lapsed ()
2247 "Function to be run from a timer to update the lapsed time line."
2248 (let (deactivate-mark)
2253 (set-buffer (window-buffer w))
2254 (when (eq major-mode 'gnus-article-mode)
2255 (goto-char (point-min))
2256 (when (re-search-forward "^X-Sent:" nil t)
2257 (article-date-lapsed t))))
2260 (defun gnus-start-date-timer (&optional n)
2261 "Start a timer to update the X-Sent header in the article buffers.
2262 The numerical prefix says how frequently (in seconds) the function
2267 (gnus-stop-date-timer)
2268 (setq article-lapsed-timer
2269 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2271 (defun gnus-stop-date-timer ()
2272 "Stop the X-Sent timer."
2274 (when article-lapsed-timer
2275 (nnheader-cancel-timer article-lapsed-timer)
2276 (setq article-lapsed-timer nil)))
2278 (defun article-date-user (&optional highlight)
2279 "Convert the current article date to the user-defined format.
2280 This format is defined by the `gnus-article-time-format' variable."
2281 (interactive (list t))
2282 (article-date-ut 'user highlight))
2284 (defun article-date-iso8601 (&optional highlight)
2285 "Convert the current article date to ISO8601."
2286 (interactive (list t))
2287 (article-date-ut 'iso8601 highlight))
2289 (defun article-show-all ()
2290 "Show all hidden text in the article buffer."
2294 (let ((buffer-read-only nil))
2295 (gnus-article-unhide-text (point-min) (point-max))
2296 (gnus-remove-text-with-property 'gnus-prev)
2297 (gnus-remove-text-with-property 'gnus-next))))
2299 (defun article-show-all-headers ()
2300 "Show all hidden headers in the article buffer."
2305 (article-narrow-to-head)
2306 (let ((buffer-read-only nil))
2307 (gnus-article-unhide-text (point-min) (point-max))))))
2309 (defun article-emphasize (&optional arg)
2310 "Emphasize text according to `gnus-emphasis-alist'."
2311 (interactive (gnus-article-hidden-arg))
2312 (unless (gnus-article-check-hidden-text 'emphasis arg)
2316 (with-current-buffer gnus-summary-buffer
2317 gnus-article-emphasis-alist)
2319 gnus-emphasis-alist))
2320 (buffer-read-only nil)
2321 (props (append '(article-type emphasis)
2322 gnus-hidden-properties))
2323 regexp elem beg invisible visible face)
2326 (while (setq elem (pop alist))
2328 (setq regexp (car elem)
2329 invisible (nth 1 elem)
2330 visible (nth 2 elem)
2332 (while (re-search-forward regexp nil t)
2333 (when (and (match-beginning visible) (match-beginning invisible))
2334 (push 'emphasis gnus-article-wash-types)
2335 (gnus-article-hide-text
2336 (match-beginning invisible) (match-end invisible) props)
2337 (gnus-article-unhide-text-type
2338 (match-beginning visible) (match-end visible) 'emphasis)
2339 (gnus-put-text-property-excluding-newlines
2340 (match-beginning visible) (match-end visible) 'face face)
2341 (goto-char (match-end invisible)))))))))
2343 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2344 "Setup newsgroup emphasis alist."
2345 (unless gnus-article-emphasis-alist
2346 (let ((name (and gnus-newsgroup-name
2347 (gnus-group-real-name gnus-newsgroup-name))))
2348 (make-local-variable 'gnus-article-emphasis-alist)
2349 (setq gnus-article-emphasis-alist
2351 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2352 (while (setq elem (pop alist))
2353 (when (and name (string-match (car elem) name))
2355 highlight (copy-sequence (cdr elem)))))
2357 (copy-sequence highlight-words)
2358 (if gnus-newsgroup-name
2359 (copy-sequence (gnus-group-find-parameter
2360 gnus-newsgroup-name 'highlight-words t)))
2361 gnus-emphasis-alist)))))
2363 (defvar gnus-summary-article-menu)
2364 (defvar gnus-summary-post-menu)
2366 ;;; Saving functions.
2368 (defun gnus-article-save (save-buffer file &optional num)
2369 "Save the currently selected article."
2370 (unless gnus-save-all-headers
2371 ;; Remove headers according to `gnus-saved-headers'.
2372 (let ((gnus-visible-headers
2373 (or gnus-saved-headers gnus-visible-headers))
2374 (gnus-article-buffer save-buffer))
2376 (set-buffer save-buffer)
2377 (article-hide-headers 1 t))))
2378 (save-window-excursion
2379 (if (not gnus-default-article-saver)
2380 (error "No default saver is defined")
2381 ;; !!! Magic! The saving functions all save
2382 ;; `gnus-save-article-buffer' (or so they think), but we
2383 ;; bind that variable to our save-buffer.
2384 (set-buffer gnus-article-buffer)
2385 (let* ((gnus-save-article-buffer save-buffer)
2388 ((not gnus-prompt-before-saving) 'default)
2389 ((eq gnus-prompt-before-saving 'always) nil)
2391 (gnus-number-of-articles-to-be-saved
2392 (when (eq gnus-prompt-before-saving t)
2394 (set-buffer gnus-article-current-summary)
2395 (funcall gnus-default-article-saver filename)))))
2397 (defun gnus-read-save-file-name (prompt &optional filename
2398 function group headers variable)
2400 (funcall function group headers (symbol-value variable)))
2405 ((eq filename 'default)
2411 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2414 (if (and gnus-number-of-articles-to-be-saved
2415 (> gnus-number-of-articles-to-be-saved 1))
2416 (format "these %d articles"
2417 gnus-number-of-articles-to-be-saved)
2420 ;; Let the split methods have their say.
2422 ;; No split name was found.
2425 (concat prompt " (default "
2426 (file-name-nondirectory default-name) ") ")
2427 (file-name-directory default-name)
2429 ;; A single group name is returned.
2430 ((stringp split-name)
2432 (funcall function split-name headers
2433 (symbol-value variable)))
2435 (concat prompt " (default "
2436 (file-name-nondirectory default-name) ") ")
2437 (file-name-directory default-name)
2439 ;; A single split name was found
2440 ((= 1 (length split-name))
2441 (let* ((name (expand-file-name
2442 (car split-name) gnus-article-save-directory))
2443 (dir (cond ((file-directory-p name)
2444 (file-name-as-directory name))
2445 ((file-exists-p name) name)
2446 (t gnus-article-save-directory))))
2448 (concat prompt " (default " name ") ")
2450 ;; A list of splits was found.
2452 (setq split-name (nreverse split-name))
2454 (let ((file-name-history
2455 (nconc split-name file-name-history)))
2459 (concat prompt " (`M-p' for defaults) ")
2460 gnus-article-save-directory
2462 gnus-article-save-directory)))
2463 (car (push result file-name-history)))))))
2464 ;; Create the directory.
2465 (gnus-make-directory (file-name-directory file))
2466 ;; If we have read a directory, we append the default file name.
2467 (when (file-directory-p file)
2468 (setq file (concat (file-name-as-directory file)
2469 (file-name-nondirectory default-name))))
2470 ;; Possibly translate some characters.
2471 (nnheader-translate-file-chars file)))))
2472 (gnus-make-directory (file-name-directory result))
2473 (set variable result)))
2475 (defun gnus-article-archive-name (group)
2476 "Return the first instance of an \"Archive-name\" in the current buffer."
2477 (let ((case-fold-search t))
2478 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2479 (nnheader-concat gnus-article-save-directory
2480 (match-string 1)))))
2482 (defun gnus-article-nndoc-name (group)
2483 "If GROUP is an nndoc group, return the name of the parent group."
2484 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2485 (gnus-group-get-parameter group 'save-article-group)))
2487 (defun gnus-summary-save-in-rmail (&optional filename)
2488 "Append this article to Rmail file.
2489 Optional argument FILENAME specifies file name.
2490 Directory to save to is default to `gnus-article-save-directory'."
2491 (setq filename (gnus-read-save-file-name
2492 "Save %s in rmail file:" filename
2493 gnus-rmail-save-name gnus-newsgroup-name
2494 gnus-current-headers 'gnus-newsgroup-last-rmail))
2495 (gnus-eval-in-buffer-window gnus-save-article-buffer
2499 (gnus-output-to-rmail filename))))
2502 (defun gnus-summary-save-in-mail (&optional filename)
2503 "Append this article to Unix mail file.
2504 Optional argument FILENAME specifies file name.
2505 Directory to save to is default to `gnus-article-save-directory'."
2506 (setq filename (gnus-read-save-file-name
2507 "Save %s in Unix mail file:" filename
2508 gnus-mail-save-name gnus-newsgroup-name
2509 gnus-current-headers 'gnus-newsgroup-last-mail))
2510 (gnus-eval-in-buffer-window gnus-save-article-buffer
2514 (if (and (file-readable-p filename)
2515 (mail-file-babyl-p filename))
2516 (rmail-output-to-rmail-file filename t)
2517 (gnus-output-to-mail filename)))))
2520 (defun gnus-summary-save-in-file (&optional filename overwrite)
2521 "Append this article to file.
2522 Optional argument FILENAME specifies file name.
2523 Directory to save to is default to `gnus-article-save-directory'."
2524 (setq filename (gnus-read-save-file-name
2525 "Save %s in file:" filename
2526 gnus-file-save-name gnus-newsgroup-name
2527 gnus-current-headers 'gnus-newsgroup-last-file))
2528 (gnus-eval-in-buffer-window gnus-save-article-buffer
2532 (when (and overwrite
2533 (file-exists-p filename))
2534 (delete-file filename))
2535 (gnus-output-to-file filename))))
2538 (defun gnus-summary-write-to-file (&optional filename)
2539 "Write this article to a file.
2540 Optional argument FILENAME specifies file name.
2541 The directory to save in defaults to `gnus-article-save-directory'."
2542 (gnus-summary-save-in-file nil t))
2544 (defun gnus-summary-save-body-in-file (&optional filename)
2545 "Append this article body to a file.
2546 Optional argument FILENAME specifies file name.
2547 The directory to save in defaults to `gnus-article-save-directory'."
2548 (setq filename (gnus-read-save-file-name
2549 "Save %s body in file:" filename
2550 gnus-file-save-name gnus-newsgroup-name
2551 gnus-current-headers 'gnus-newsgroup-last-file))
2552 (gnus-eval-in-buffer-window gnus-save-article-buffer
2556 (when (article-goto-body)
2557 (narrow-to-region (point) (point-max)))
2558 (gnus-output-to-file filename))))
2561 (defun gnus-summary-save-in-pipe (&optional command)
2562 "Pipe this article to subprocess."
2564 (cond ((and (eq command 'default)
2565 gnus-last-shell-command)
2566 gnus-last-shell-command)
2570 "Shell command on %s: "
2571 (if (and gnus-number-of-articles-to-be-saved
2572 (> gnus-number-of-articles-to-be-saved 1))
2573 (format "these %d articles"
2574 gnus-number-of-articles-to-be-saved)
2576 gnus-last-shell-command))))
2577 (when (string-equal command "")
2578 (setq command gnus-last-shell-command))
2579 (gnus-eval-in-buffer-window gnus-article-buffer
2582 (shell-command-on-region (point-min) (point-max) command nil)))
2583 (setq gnus-last-shell-command command))
2585 ;;; Article file names when saving.
2587 (defun gnus-capitalize-newsgroup (newsgroup)
2588 "Capitalize NEWSGROUP name."
2589 (when (not (zerop (length newsgroup)))
2590 (concat (char-to-string (upcase (aref newsgroup 0)))
2591 (substring newsgroup 1))))
2593 (defun gnus-Numeric-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 ~/News/News.group/num.
2596 Otherwise, it is like ~/News/news/group/num."
2599 (concat (if (gnus-use-long-file-name 'not-save)
2600 (gnus-capitalize-newsgroup newsgroup)
2601 (gnus-newsgroup-directory-form newsgroup))
2602 "/" (int-to-string (mail-header-number headers)))
2603 gnus-article-save-directory)))
2605 (string-equal (file-name-directory default)
2606 (file-name-directory last-file))
2607 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2609 (or last-file default))))
2611 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2612 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2613 If variable `gnus-use-long-file-name' is non-nil, it is
2614 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2617 (concat (if (gnus-use-long-file-name 'not-save)
2619 (gnus-newsgroup-directory-form newsgroup))
2620 "/" (int-to-string (mail-header-number headers)))
2621 gnus-article-save-directory)))
2623 (string-equal (file-name-directory default)
2624 (file-name-directory last-file))
2625 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2627 (or last-file default))))
2629 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2630 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2631 If variable `gnus-use-long-file-name' is non-nil, it is
2632 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2635 (if (gnus-use-long-file-name 'not-save)
2636 (gnus-capitalize-newsgroup newsgroup)
2637 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2638 gnus-article-save-directory)))
2640 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2641 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2642 If variable `gnus-use-long-file-name' is non-nil, it is
2643 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2646 (if (gnus-use-long-file-name 'not-save)
2648 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2649 gnus-article-save-directory)))
2656 (setq afunc (car func)
2659 gfunc (intern (format "gnus-%s" func))))
2661 (if (not (fboundp afunc))
2663 `(lambda (&optional interactive &rest args)
2664 ,(documentation afunc t)
2665 (interactive (list t))
2667 (set-buffer gnus-article-buffer)
2669 (call-interactively ',afunc)
2670 (apply ',afunc args))))))))
2671 '(article-hide-headers
2672 article-hide-boring-headers
2673 article-toggle-headers
2674 article-treat-overstrike
2675 article-fill-long-lines
2676 article-capitalize-sentences
2678 article-display-x-face
2679 article-de-quoted-unreadable
2680 article-de-base64-unreadable
2683 article-hide-list-identifiers
2685 article-strip-banner
2688 article-hide-signature
2689 article-strip-headers-in-body
2690 article-remove-trailing-blank-lines
2691 article-strip-leading-blank-lines
2692 article-strip-multiple-blank-lines
2693 article-strip-leading-space
2694 article-strip-trailing-space
2695 article-strip-blank-lines
2696 article-strip-all-blank-lines
2698 article-date-iso8601
2699 article-date-original
2701 article-decode-mime-words
2702 article-decode-charset
2703 article-decode-encoded-words
2707 article-treat-dumbquotes
2708 article-normalize-headers
2709 (article-show-all-headers . gnus-article-show-all-headers)
2710 (article-show-all . gnus-article-show-all))))
2713 ;;; Gnus article mode
2716 (put 'gnus-article-mode 'mode-class 'special)
2718 (gnus-define-keys gnus-article-mode-map
2719 " " gnus-article-goto-next-page
2720 "\177" gnus-article-goto-prev-page
2721 [delete] gnus-article-goto-prev-page
2722 [backspace] gnus-article-goto-prev-page
2723 "\C-c^" gnus-article-refer-article
2724 "h" gnus-article-show-summary
2725 "s" gnus-article-show-summary
2726 "\C-c\C-m" gnus-article-mail
2727 "?" gnus-article-describe-briefly
2728 "e" gnus-summary-edit-article
2729 "<" beginning-of-buffer
2731 "\C-c\C-i" gnus-info-find-node
2734 "\C-d" gnus-article-read-summary-keys
2735 "\M-*" gnus-article-read-summary-keys
2736 "\M-#" gnus-article-read-summary-keys
2737 "\M-^" gnus-article-read-summary-keys
2738 "\M-g" gnus-article-read-summary-keys)
2740 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2743 (unless (lookup-key gnus-article-mode-map key)
2744 (define-key gnus-article-mode-map key
2745 'gnus-article-read-summary-keys)))
2750 (let ((key (car elt)))
2751 (and (> (length key) 0)
2752 (not (eq 'menu-bar (aref key 0)))
2753 (symbolp (lookup-key gnus-summary-mode-map key))
2755 (accessible-keymaps gnus-summary-mode-map))
2759 (push (char-to-string c) keys)
2763 (defun gnus-article-make-menu-bar ()
2764 (gnus-turn-off-edit-menu 'article)
2765 (unless (boundp 'gnus-article-article-menu)
2767 gnus-article-article-menu gnus-article-mode-map ""
2769 ["Scroll forwards" gnus-article-goto-next-page t]
2770 ["Scroll backwards" gnus-article-goto-prev-page t]
2771 ["Show summary" gnus-article-show-summary t]
2772 ["Fetch Message-ID at point" gnus-article-refer-article t]
2773 ["Mail to address at point" gnus-article-mail t]
2774 ["Send a bug report" gnus-bug t]))
2777 gnus-article-treatment-menu gnus-article-mode-map ""
2779 ["Hide headers" gnus-article-toggle-headers t]
2780 ["Hide signature" gnus-article-hide-signature t]
2781 ["Hide citation" gnus-article-hide-citation t]
2782 ["Treat overstrike" gnus-article-treat-overstrike t]
2783 ["Remove carriage return" gnus-article-remove-cr t]
2784 ["Decode HZ" gnus-article-decode-HZ t]))
2786 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2788 (when (boundp 'gnus-summary-post-menu)
2789 (define-key gnus-article-mode-map [menu-bar post]
2790 (cons "Post" gnus-summary-post-menu)))
2792 (gnus-run-hooks 'gnus-article-menu-hook)))
2794 (defun gnus-article-mode ()
2795 "Major mode for displaying an article.
2797 All normal editing commands are switched off.
2799 The following commands are available in addition to all summary mode
2801 \\<gnus-article-mode-map>
2802 \\[gnus-article-next-page]\t Scroll the article one page forwards
2803 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2804 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2805 \\[gnus-article-show-summary]\t Display the summary buffer
2806 \\[gnus-article-mail]\t Send a reply to the address near point
2807 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2808 \\[gnus-info-find-node]\t Go to the Gnus info node"
2810 (when (gnus-visual-p 'article-menu 'menu)
2811 (gnus-article-make-menu-bar))
2812 (gnus-simplify-mode-line)
2813 (setq mode-name "Article")
2814 (setq major-mode 'gnus-article-mode)
2815 (make-local-variable 'minor-mode-alist)
2816 (unless (assq 'gnus-show-mime minor-mode-alist)
2817 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2818 (use-local-map gnus-article-mode-map)
2819 (gnus-update-format-specifications nil 'article-mode)
2820 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2821 (make-local-variable 'gnus-page-broken)
2822 (make-local-variable 'gnus-button-marker-list)
2823 (make-local-variable 'gnus-article-current-summary)
2824 (make-local-variable 'gnus-article-mime-handles)
2825 (make-local-variable 'gnus-article-decoded-p)
2826 (make-local-variable 'gnus-article-mime-handle-alist)
2827 (make-local-variable 'gnus-article-wash-types)
2828 (gnus-set-default-directory)
2829 (buffer-disable-undo)
2830 (setq buffer-read-only t)
2831 (set-syntax-table gnus-article-mode-syntax-table)
2832 (gnus-run-hooks 'gnus-article-mode-hook))
2834 (defun gnus-article-setup-buffer ()
2835 "Initialize the article buffer."
2836 (let* ((name (if gnus-single-article-buffer "*Article*"
2837 (concat "*Article " gnus-newsgroup-name "*")))
2839 (progn (string-match "\\*Article" name)
2840 (concat " *Original Article"
2841 (substring name (match-end 0))))))
2842 (setq gnus-article-buffer name)
2843 (setq gnus-original-article-buffer original)
2844 (setq gnus-article-mime-handle-alist nil)
2845 ;; This might be a variable local to the summary buffer.
2846 (unless gnus-single-article-buffer
2848 (set-buffer gnus-summary-buffer)
2849 (setq gnus-article-buffer name)
2850 (setq gnus-original-article-buffer original)
2851 (gnus-set-global-variables)))
2852 (gnus-article-setup-highlight-words)
2853 ;; Init original article buffer.
2855 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2856 (setq major-mode 'gnus-original-article-mode)
2857 (make-local-variable 'gnus-original-article))
2858 (if (get-buffer name)
2861 (buffer-disable-undo)
2862 (setq buffer-read-only t)
2863 (unless (eq major-mode 'gnus-article-mode)
2864 (gnus-article-mode))
2867 (set-buffer (gnus-get-buffer-create name))
2869 (make-local-variable 'gnus-summary-buffer)
2870 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2871 (current-buffer)))))
2873 ;; Set article window start at LINE, where LINE is the number of lines
2874 ;; from the head of the article.
2875 (defun gnus-article-set-window-start (&optional line)
2877 (get-buffer-window gnus-article-buffer t)
2879 (set-buffer gnus-article-buffer)
2880 (goto-char (point-min))
2883 (gnus-message 6 "Moved to bookmark")
2884 (search-forward "\n\n" nil t)
2888 ;;; @@ article filters
2891 (defun gnus-article-display-mime-message ()
2892 "Article display method for MIME message."
2893 ;; called from `gnus-original-article-buffer'.
2894 (let (charset all-headers)
2895 (with-current-buffer gnus-summary-buffer
2896 (setq charset default-mime-charset
2897 all-headers gnus-have-all-headers))
2898 (make-local-variable 'default-mime-charset)
2899 (setq default-mime-charset charset)
2900 (with-current-buffer (get-buffer-create gnus-article-buffer)
2901 (make-local-variable 'default-mime-charset)
2902 (setq default-mime-charset charset))
2903 (mime-display-message mime-message-structure
2904 gnus-article-buffer nil gnus-article-mode-map)
2906 (gnus-article-hide-headers nil -1))
2908 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2909 (make-local-variable 'mime-button-mother-dispatcher)
2910 (setq mime-button-mother-dispatcher
2911 (function gnus-article-push-button))
2912 (run-hooks 'gnus-mime-article-prepare-hook))
2914 (defun gnus-article-display-traditional-message ()
2915 "Article display method for traditional message."
2916 (set-buffer gnus-article-buffer)
2917 (let (buffer-read-only)
2919 (insert-buffer-substring gnus-original-article-buffer)))
2921 (defun gnus-article-make-full-mail-header (&optional number charset)
2922 "Create a new mail header structure in a raw article buffer."
2923 (unless (and number charset)
2924 (save-current-buffer
2925 (set-buffer gnus-summary-buffer)
2927 (setq number (or (cdr gnus-article-current) 0)))
2929 (setq charset (or default-mime-charset 'x-ctext)))))
2930 (goto-char (point-min))
2931 (let ((header-end (if (search-forward "\n\n" nil t)
2933 (goto-char (point-max))))
2934 (chars (- (point-max) (point)))
2935 (lines (count-lines (point) (point-max)))
2936 (default-mime-charset charset)
2938 (narrow-to-region (point-min) header-end)
2939 (setq xref (std11-fetch-field "xref"))
2941 (make-full-mail-header
2943 (std11-fetch-field "subject")
2944 (std11-fetch-field "from")
2945 (std11-fetch-field "date")
2946 (std11-fetch-field "message-id")
2947 (std11-fetch-field "references")
2950 (when xref (concat "Xref: " xref)))
2953 (defun gnus-article-prepare (article &optional all-headers header)
2954 "Prepare ARTICLE in article mode buffer.
2955 ARTICLE should either be an article number or a Message-ID.
2956 If ARTICLE is an id, HEADER should be the article headers.
2957 If ALL-HEADERS is non-nil, no headers are hidden."
2959 ;; Make sure we start in a summary buffer.
2960 (unless (eq major-mode 'gnus-summary-mode)
2961 (set-buffer gnus-summary-buffer))
2962 (setq gnus-summary-buffer (current-buffer))
2963 (let* ((gnus-article (if header (mail-header-number header) article))
2964 (summary-buffer (current-buffer))
2965 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2966 (group gnus-newsgroup-name)
2969 (gnus-article-setup-buffer)
2970 (set-buffer gnus-original-article-buffer)
2971 ;; Deactivate active regions.
2972 (when (and (boundp 'transient-mark-mode)
2973 transient-mark-mode)
2974 (setq mark-active nil))
2975 (if (not (setq result (let ((buffer-read-only nil))
2976 (gnus-request-article-this-buffer
2978 ;; There is no such article.
2980 (when (and (numberp article)
2981 (not (memq article gnus-newsgroup-sparse)))
2982 (setq gnus-article-current
2983 (cons gnus-newsgroup-name article))
2984 (set-buffer gnus-summary-buffer)
2985 (setq gnus-current-article article)
2986 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2988 (gnus-summary-set-agent-mark article)
2989 (message "Message marked for downloading"))
2990 (gnus-summary-mark-article article gnus-canceled-mark)
2991 (unless (memq article gnus-newsgroup-sparse)
2992 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2993 (if (or (eq result 'pseudo)
2994 (eq result 'nneething))
2997 (set-buffer summary-buffer)
2998 (push article gnus-newsgroup-history)
2999 (setq gnus-last-article gnus-current-article
3000 gnus-current-article 0
3001 gnus-current-headers nil
3002 gnus-article-current nil)
3003 (if (eq result 'nneething)
3004 (gnus-configure-windows 'summary)
3005 (gnus-configure-windows 'article))
3006 (gnus-set-global-variables))
3007 (let ((gnus-article-mime-handle-alist-1
3008 gnus-article-mime-handle-alist))
3009 (gnus-set-mode-line 'article)))
3010 ;; The result from the `request' was an actual article -
3011 ;; or at least some text that is now displayed in the
3013 (when (and (numberp article)
3014 (not (eq article gnus-current-article)))
3015 ;; Seems like a new article has been selected.
3016 ;; `gnus-current-article' must be an article number.
3018 (set-buffer summary-buffer)
3019 (push article gnus-newsgroup-history)
3020 (setq gnus-last-article gnus-current-article
3021 gnus-current-article article
3022 gnus-current-headers
3023 (gnus-summary-article-header gnus-current-article)
3024 gnus-article-current
3025 (cons gnus-newsgroup-name gnus-current-article))
3026 (unless (vectorp gnus-current-headers)
3027 (setq gnus-current-headers nil))
3028 (gnus-summary-goto-subject gnus-current-article)
3029 (when (gnus-summary-show-thread)
3030 ;; If the summary buffer really was folded, the
3031 ;; previous goto may not actually have gone to
3032 ;; the right article, but the thread root instead.
3034 (gnus-summary-goto-subject gnus-current-article))
3035 (gnus-run-hooks 'gnus-mark-article-hook)
3036 (gnus-set-mode-line 'summary)
3037 (when (gnus-visual-p 'article-highlight 'highlight)
3038 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3039 ;; Set the global newsgroup variables here.
3040 (gnus-set-global-variables)
3041 (setq gnus-have-all-headers
3042 (or all-headers gnus-show-all-headers))))
3043 (when (or (numberp article)
3045 (gnus-article-prepare-display)
3047 (goto-char (point-min))
3048 (setq gnus-page-broken
3049 (when gnus-break-pages
3050 (gnus-narrow-to-page)
3052 (let ((gnus-article-mime-handle-alist-1
3053 gnus-article-mime-handle-alist))
3054 (gnus-set-mode-line 'article))
3056 (set-window-point (get-buffer-window (current-buffer)) (point))
3057 (gnus-configure-windows 'article)
3060 (defun gnus-article-prepare-mime-display (&optional number)
3061 (goto-char (point-min))
3062 (when (re-search-forward "^[^\t ]+:" nil t)
3063 (goto-char (match-beginning 0)))
3064 (let ((entity (if (eq 1 (point-min))
3065 (get-text-property 1 'mime-view-entity)
3066 (get-text-property (point) 'mime-view-entity)))
3067 last-entity child-entity next type)
3068 (setq child-entity (mime-entity-children entity))
3070 (setq last-entity (nth (1- (length child-entity))
3072 (setq last-entity entity))
3074 (narrow-to-region (point)
3075 (if (search-forward "\n\n" nil t)
3078 (gnus-treat-article 'head)
3079 (put-text-property (point-min) (point-max) 'article-treated-header t)
3080 (goto-char (point-max)))
3081 (while (and (not (eobp)) entity)
3082 (setq next (set-marker
3084 (next-single-property-change (point) 'mime-view-entity
3086 (let ((types (mime-entity-content-type entity)))
3087 (while (eq 'multipart (mime-content-type-primary-type types))
3088 (setq entity (car (mime-entity-children entity))
3089 types (mime-entity-content-type entity)))
3091 (setq type (format "%s/%s"
3092 (mime-content-type-primary-type types)
3093 (mime-content-type-subtype types)))))
3094 (if (string-equal type "message/rfc822")
3097 (let ((children (mime-entity-children entity))
3100 (setq last-children (nth (1- (length children)) children))
3103 (not (eq last-children
3104 (get-text-property next 'mime-view-entity)))
3106 (next-single-property-change next
3108 nil (point-max)))))))
3109 (setq next (next-single-property-change next 'mime-view-entity
3112 (narrow-to-region (point) next)
3113 (gnus-article-prepare-mime-display)
3114 (goto-char (point-max)))
3115 (setq entity (get-text-property (point) 'mime-view-entity)))
3117 (narrow-to-region (point) next)
3118 ;; Kludge. We have to count true number, but for now,
3119 ;; part number is here only to achieve `last'.
3120 (gnus-treat-article nil 1
3121 (if (eq entity last-entity)
3124 (goto-char (point-max)))
3125 (setq entity (get-text-property next 'mime-view-entity))))))
3128 (defun gnus-article-prepare-display ()
3129 "Make the current buffer look like a nice article."
3130 (setq gnus-article-wash-types nil)
3131 (gnus-run-hooks 'gnus-tmp-internal-hook)
3132 (gnus-run-hooks 'gnus-article-prepare-hook)
3134 (let (mime-display-header-hook mime-display-text/plain-hook)
3135 (funcall (if gnus-show-mime
3137 (setq mime-message-structure gnus-current-headers)
3138 (mime-buffer-entity-set-buffer-internal
3139 mime-message-structure
3140 gnus-original-article-buffer)
3141 (mime-entity-set-representation-type-internal
3142 mime-message-structure 'mime-buffer-entity)
3143 (luna-send mime-message-structure
3144 'initialize-instance
3145 mime-message-structure)
3146 gnus-article-display-method-for-mime)
3147 gnus-article-display-method-for-traditional)))
3148 ;; Associate this article with the current summary buffer.
3149 (setq gnus-article-current-summary gnus-summary-buffer)
3150 ;; Call the treatment functions.
3151 (let ((inhibit-read-only t)
3156 (gnus-article-prepare-mime-display)
3157 (narrow-to-region (goto-char (point-min))
3158 (if (search-forward "\n\n" nil t)
3161 (gnus-treat-article 'head)
3162 (put-text-property (point-min) (point-max) 'article-treated-header t)
3163 (goto-char (point-max))
3165 (narrow-to-region (point) (point-max))
3166 (gnus-treat-article nil))
3167 (put-text-property (point-min) (point-max) 'read-only nil)))
3168 ;; Perform the article display hooks. Incidentally, this hook is
3169 ;; an obsolete variable by now.
3170 (gnus-run-hooks 'gnus-article-display-hook))
3172 (defun gnus-article-decode-article-as-default-mime-charset ()
3173 "Decode an article as `default-mime-charset'. It won't work if the
3174 value of the variable `gnus-show-mime' is non-nil."
3175 (unless gnus-show-mime
3176 (decode-mime-charset-region (point-min) (point-max)
3177 (with-current-buffer gnus-summary-buffer
3178 default-mime-charset))))
3181 ;;; Gnus MIME viewing functions
3184 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3185 "The following specs can be used:
3187 %T MIME type, along with additional info
3188 %n The `name' parameter
3189 %d The description, if any
3190 %l The length of the encoded part
3191 %p The part identifier number
3192 %e Dots if the part isn't displayed")
3194 (defvar gnus-mime-button-line-format-alist
3195 '((?t gnus-tmp-type ?s)
3196 (?T gnus-tmp-type-long ?s)
3197 (?n gnus-tmp-name ?s)
3198 (?d gnus-tmp-description ?s)
3200 (?l gnus-tmp-length ?d)
3201 (?e gnus-tmp-dots ?s)))
3203 (defvar gnus-mime-button-commands
3204 '((gnus-article-press-button "\r" "Toggle Display")
3205 (gnus-mime-view-part "v" "View Interactively...")
3206 (gnus-mime-view-part-as-type "t" "View As Type...")
3207 (gnus-mime-save-part "o" "Save...")
3208 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3209 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3210 (gnus-mime-internalize-part "E" "View Internally")
3211 (gnus-mime-externalize-part "e" "View Externally")
3212 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3214 (defun gnus-article-mime-part-status ()
3215 (with-current-buffer gnus-article-buffer
3216 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3217 (if (and entity (mime-entity-children entity))
3218 (format " (%d parts)" (length (mime-entity-children entity)))
3221 (defvar gnus-mime-button-map nil)
3222 (unless gnus-mime-button-map
3223 (setq gnus-mime-button-map (make-sparse-keymap))
3224 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3225 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3226 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3228 (define-key gnus-mime-button-map (cadr c) (car c)))
3229 gnus-mime-button-commands))
3231 (defun gnus-mime-button-menu (event)
3232 "Construct a context-sensitive menu of MIME commands."
3235 (let ((pos (event-start event)))
3236 (set-buffer (window-buffer (posn-window pos)))
3237 (goto-char (posn-point pos))
3238 (gnus-article-check-buffer)
3239 (let ((response (x-popup-menu
3241 ("" ,@(mapcar (lambda (c)
3242 (cons (caddr c) (car c)))
3243 gnus-mime-button-commands))))))
3245 (call-interactively response))))))
3247 (defun gnus-mime-view-all-parts (&optional handles)
3248 "View all the MIME parts."
3250 (save-current-buffer
3251 (set-buffer gnus-article-buffer)
3252 (let ((handles (or handles gnus-article-mime-handles))
3253 (mail-parse-charset gnus-newsgroup-charset)
3254 (mail-parse-ignored-charsets
3255 (save-excursion (set-buffer gnus-summary-buffer)
3256 gnus-newsgroup-ignored-charsets)))
3257 (if (stringp (car handles))
3258 (gnus-mime-view-all-parts (cdr handles))
3259 (mapcar 'mm-display-part handles)))))
3261 (defun gnus-mime-save-part ()
3262 "Save the MIME part under point."
3264 (gnus-article-check-buffer)
3265 (let ((data (get-text-property (point) 'gnus-data)))
3266 (mm-save-part data)))
3268 (defun gnus-mime-pipe-part ()
3269 "Pipe the MIME part under point to a process."
3271 (gnus-article-check-buffer)
3272 (let ((data (get-text-property (point) 'gnus-data)))
3273 (mm-pipe-part data)))
3275 (defun gnus-mime-view-part ()
3276 "Interactively choose a viewing method for the MIME part under point."
3278 (gnus-article-check-buffer)
3279 (let ((data (get-text-property (point) 'gnus-data)))
3280 (mm-interactively-view-part data)))
3282 (defun gnus-mime-view-part-as-type-internal ()
3283 (gnus-article-check-buffer)
3284 (let* ((name (mail-content-type-get
3285 (mm-handle-type (get-text-property (point) 'gnus-data))
3287 (def-type (and name (mm-default-file-encoding name))))
3288 (and def-type (cons def-type 0))))
3290 (defun gnus-mime-view-part-as-type (mime-type)
3291 "Choose a MIME media type, and view the part as such."
3293 (list (completing-read
3294 "View as MIME type: "
3295 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
3297 (gnus-mime-view-part-as-type-internal))))
3298 (gnus-article-check-buffer)
3299 (let ((handle (get-text-property (point) 'gnus-data)))
3300 (gnus-mm-display-part
3301 (mm-make-handle (mm-handle-buffer handle)
3302 (cons mime-type (cdr (mm-handle-type handle)))
3303 (mm-handle-encoding handle)
3304 (mm-handle-undisplayer handle)
3305 (mm-handle-disposition handle)
3306 (mm-handle-description handle)
3307 (mm-handle-cache handle)
3308 (mm-handle-id handle)))))
3310 (defun gnus-mime-copy-part (&optional handle)
3311 "Put the the MIME part under point into a new buffer."
3313 (gnus-article-check-buffer)
3314 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3315 (contents (mm-get-part handle))|
3316 (base (file-name-nondirectory
3318 (mail-content-type-get (mm-handle-type handle) 'name)
3319 (mail-content-type-get (mm-handle-type handle)
3322 (buffer (generate-new-buffer base)))
3323 (switch-to-buffer buffer)
3325 ;; We do it this way to make `normal-mode' set the appropriate mode.
3328 (setq buffer-file-name (expand-file-name base))
3330 (setq buffer-file-name nil))
3331 (goto-char (point-min))))
3333 (defun gnus-mime-inline-part (&optional handle)
3334 "Insert the MIME part under point into the current buffer."
3336 (gnus-article-check-buffer)
3337 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3341 (if (mm-handle-undisplayer handle)
3342 (mm-remove-part handle)
3343 (setq contents (mm-get-part handle))
3345 (mm-insert-inline handle contents)
3348 (defun gnus-mime-externalize-part (&optional handle)
3349 "View the MIME part under point with an external viewer."
3351 (gnus-article-check-buffer)
3352 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3353 (mm-user-display-methods nil)
3354 (mm-inline-large-images nil)
3355 (mail-parse-charset gnus-newsgroup-charset)
3356 (mail-parse-ignored-charsets
3357 (save-excursion (set-buffer gnus-summary-buffer)
3358 gnus-newsgroup-ignored-charsets)))
3359 (if (mm-handle-undisplayer handle)
3360 (mm-remove-part handle)
3361 (mm-display-part handle))))
3363 (defun gnus-mime-internalize-part (&optional handle)
3364 "View the MIME part under point with an internal viewer.
3365 In no internal viewer is available, use an external viewer."
3367 (gnus-article-check-buffer)
3368 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3369 (mm-inlined-types '(".*"))
3370 (mm-inline-large-images t)
3371 (mail-parse-charset gnus-newsgroup-charset)
3372 (mail-parse-ignored-charsets
3373 (save-excursion (set-buffer gnus-summary-buffer)
3374 gnus-newsgroup-ignored-charsets)))
3375 (if (mm-handle-undisplayer handle)
3376 (mm-remove-part handle)
3377 (mm-display-part handle))))
3379 (defun gnus-article-part-wrapper (n function)
3380 (save-current-buffer
3381 (set-buffer gnus-article-buffer)
3382 (when (> n (length gnus-article-mime-handle-alist))
3383 (error "No such part"))
3384 (gnus-article-goto-part n)
3385 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3386 (funcall function handle))))
3388 (defun gnus-article-pipe-part (n)
3389 "Pipe MIME part N, which is the numerical prefix."
3391 (gnus-article-part-wrapper n 'mm-pipe-part))
3393 (defun gnus-article-save-part (n)
3394 "Save MIME part N, which is the numerical prefix."
3396 (gnus-article-part-wrapper n 'mm-save-part))
3398 (defun gnus-article-interactively-view-part (n)
3399 "View MIME part N interactively, which is the numerical prefix."
3401 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3403 (defun gnus-article-copy-part (n)
3404 "Copy MIME part N, which is the numerical prefix."
3406 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3408 (defun gnus-article-externalize-part (n)
3409 "View MIME part N externally, which is the numerical prefix."
3411 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3413 (defun gnus-article-inline-part (n)
3414 "Inline MIME part N, which is the numerical prefix."
3416 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3418 (defun gnus-article-mime-match-handle-first (condition)
3420 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3421 (while (setq ihandle (pop alist))
3423 ((functionp condition)
3424 (funcall condition (cdr ihandle)))
3425 ((eq condition 'undisplayed)
3426 (not (or (mm-handle-undisplayer (cdr ihandle))
3427 (equal (mm-handle-media-type (cdr ihandle))
3428 "multipart/alternative"))))
3429 ((eq condition 'undisplayed-alternative)
3430 (not (mm-handle-undisplayer (cdr ihandle))))
3432 (gnus-article-goto-part (car ihandle))
3433 (or (not n) (< (car ihandle) n)))
3434 (setq n (car ihandle))))
3438 (defun gnus-article-view-part (&optional n)
3439 "View MIME part N, which is the numerical prefix."
3441 (save-current-buffer
3442 (set-buffer gnus-article-buffer)
3443 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3444 gnus-article-mime-match-handle-function)))
3445 (when (> n (length gnus-article-mime-handle-alist))
3446 (error "No such part"))
3447 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3448 (when (gnus-article-goto-part n)
3449 (if (equal (car handle) "multipart/alternative")
3450 (gnus-article-press-button)
3451 (when (eq (gnus-mm-display-part handle) 'internal)
3452 (gnus-set-window-start)))))))
3454 (defun gnus-mm-display-part (handle)
3455 "Display HANDLE and fix MIME button."
3456 (let ((id (get-text-property (point) 'gnus-part))
3461 (let ((window (selected-window))
3462 (mail-parse-charset gnus-newsgroup-charset)
3463 (mail-parse-ignored-charsets
3464 (save-excursion (set-buffer gnus-summary-buffer)
3465 gnus-newsgroup-ignored-charsets)))
3468 (let ((win (get-buffer-window (current-buffer) t))
3471 (select-window win))
3474 (if (mm-handle-displayed-p handle)
3475 ;; This will remove the part.
3476 (mm-display-part handle)
3478 (narrow-to-region (point) (1+ (point)))
3479 (mm-display-part handle)
3480 ;; We narrow to the part itself and
3481 ;; then call the treatment functions.
3482 (goto-char (point-min))
3484 (narrow-to-region (point) (point-max))
3487 (1- (length gnus-article-mime-handles))
3488 (mm-handle-media-type handle)))))
3489 (select-window window))))
3491 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3492 (gnus-insert-mime-button
3493 handle id (list (mm-handle-displayed-p handle)))
3494 (goto-char point))))
3496 (defun gnus-article-goto-part (n)
3497 "Go to MIME part N."
3498 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3500 (goto-char point))))
3502 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3503 (let ((gnus-tmp-name
3504 (or (mail-content-type-get (mm-handle-type handle)
3506 (mail-content-type-get (mm-handle-disposition handle)
3509 (gnus-tmp-type (mm-handle-media-type handle))
3510 (gnus-tmp-description
3511 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3514 (if (if displayed (car displayed)
3515 (mm-handle-displayed-p handle))
3517 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3519 gnus-tmp-type-long b e)
3520 (when (string-match ".*/" gnus-tmp-name)
3521 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3522 (setq gnus-tmp-type-long (concat gnus-tmp-type
3523 (and (not (equal gnus-tmp-name ""))
3524 (concat "; " gnus-tmp-name))))
3525 (or (equal gnus-tmp-description "")
3526 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3531 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3532 `(local-map ,gnus-mime-button-map
3533 keymap ,gnus-mime-button-map
3534 gnus-callback gnus-mm-display-part
3535 gnus-part ,gnus-tmp-id
3536 article-type annotation
3539 (widget-convert-button 'link b e
3541 :action 'gnus-widget-press-button
3542 :button-keymap gnus-mime-button-map
3545 ;; Needed to properly clear the message
3546 ;; due to a bug in wid-edit
3547 (setq help-echo-owns-message t)
3549 "Click to %s the MIME part; %s for more options"
3550 (if (mm-handle-displayed-p
3551 (widget-get widget :mime-handle))
3553 (if gnus-xemacs "button3" "mouse-3"))))))
3555 (defun gnus-widget-press-button (elems el)
3556 (goto-char (widget-get elems :from))
3557 (gnus-article-press-button))
3559 (defvar gnus-displaying-mime nil)
3561 (defun gnus-display-mime (&optional ihandles)
3562 "Display the MIME parts."
3564 (save-selected-window
3565 (let ((window (get-buffer-window gnus-article-buffer))
3568 (select-window window)
3569 ;; We have to do this since selecting the window
3570 ;; may change the point. So we set the window point.
3571 (set-window-point window point)))
3572 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3573 buffer-read-only handle name type b e display)
3574 (when (and (not ihandles)
3575 (not gnus-displaying-mime))
3576 ;; Top-level call; we clean up.
3577 (when gnus-article-mime-handles
3578 (mm-destroy-parts gnus-article-mime-handles)
3579 (setq gnus-article-mime-handle-alist nil));; A trick.
3580 (setq gnus-article-mime-handles handles)
3581 ;; We allow users to glean info from the handles.
3582 (when gnus-article-mime-part-function
3583 (gnus-mime-part-function handles)))
3585 (or (not (stringp (car handles)))
3588 (when (and (not ihandles)
3589 (not gnus-displaying-mime))
3590 ;; Clean up for mime parts.
3592 (delete-region (point) (point-max)))
3593 (let ((gnus-displaying-mime t))
3594 (gnus-mime-display-part handles)))
3597 (narrow-to-region (point) (point-max))
3598 (gnus-treat-article nil 1 1)
3601 ;; Highlight the headers.
3605 (narrow-to-region (point-min) (point))
3606 (gnus-treat-article 'head))))))))
3608 (defvar gnus-mime-display-multipart-as-mixed nil)
3610 (defun gnus-mime-display-part (handle)
3613 ((not (stringp (car handle)))
3614 (gnus-mime-display-single handle))
3615 ;; User-defined multipart
3616 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3617 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3619 ;; multipart/alternative
3620 ((and (equal (car handle) "multipart/alternative")
3621 (not gnus-mime-display-multipart-as-mixed))
3622 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3623 (push (cons id handle) gnus-article-mime-handle-alist)
3624 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3625 ;; multipart/related
3626 ((and (equal (car handle) "multipart/related")
3627 (not gnus-mime-display-multipart-as-mixed))
3628 ;;;!!!We should find the start part, but we just default
3629 ;;;!!!to the first part.
3630 (gnus-mime-display-part (cadr handle)))
3631 ;; Other multiparts are handled like multipart/mixed.
3633 (gnus-mime-display-mixed (cdr handle)))))
3635 (defun gnus-mime-part-function (handles)
3636 (if (stringp (car handles))
3637 (mapcar 'gnus-mime-part-function (cdr handles))
3638 (funcall gnus-article-mime-part-function handles)))
3640 (defun gnus-mime-display-mixed (handles)
3641 (mapcar 'gnus-mime-display-part handles))
3643 (defun gnus-mime-display-single (handle)
3644 (let ((type (mm-handle-media-type handle))
3645 (ignored gnus-ignored-mime-types)
3652 (when (string-match (pop ignored) type)
3653 (throw 'ignored nil)))
3654 (if (and (setq not-attachment
3655 (and (not (mm-inline-override-p handle))
3656 (or (not (mm-handle-disposition handle))
3657 (equal (car (mm-handle-disposition handle))
3659 (mm-attachment-override-p handle))))
3660 (mm-automatic-display-p handle)
3661 (or (mm-inlined-p handle)
3662 (mm-automatic-external-display-p type)))
3664 (when (equal (mm-handle-media-supertype handle) "text")
3666 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3667 (push (cons id handle) gnus-article-mime-handle-alist)
3668 (when (or (not display)
3669 (not (gnus-unbuttonized-mime-type-p type)))
3670 ;(gnus-article-insert-newline)
3671 (gnus-insert-mime-button
3672 handle id (list (or display (and not-attachment text))))
3673 (gnus-article-insert-newline)
3674 ;(gnus-article-insert-newline)
3676 (let ((beg (point)))
3682 (let ((mail-parse-charset gnus-newsgroup-charset)
3683 (mail-parse-ignored-charsets
3684 (save-excursion (condition-case ()
3685 (set-buffer gnus-summary-buffer)
3687 gnus-newsgroup-ignored-charsets)))
3688 (mm-display-part handle t))
3689 (goto-char (point-max)))
3690 ((and text not-attachment)
3694 (gnus-article-insert-newline)
3695 (mm-insert-inline handle (mm-get-part handle))
3696 (goto-char (point-max))))
3700 (narrow-to-region beg (point))
3702 nil (length gnus-article-mime-handle-alist)
3703 (1- (length gnus-article-mime-handles))
3704 (mm-handle-media-type handle)))))))))
3706 (defun gnus-unbuttonized-mime-type-p (type)
3707 "Say whether TYPE is to be unbuttonized."
3708 (unless gnus-inhibit-mime-unbuttonizing
3710 (let ((types gnus-unbuttonized-mime-types))
3712 (when (string-match (pop types) type)
3713 (throw 'found t)))))))
3715 (defun gnus-article-insert-newline ()
3716 "Insert a newline, but mark it as undeletable."
3717 (gnus-put-text-property
3718 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3720 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3721 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3724 handle buffer-read-only from props begend not-pref)
3725 (save-window-excursion
3728 (narrow-to-region (car ibegend)
3731 (goto-char (car ibegend))
3734 (delete-region (point-min) (point-max))
3735 (mm-remove-parts handles))
3736 (setq begend (list (point-marker)))
3738 (unless (setq not-pref (cadr (member preferred ihandles)))
3739 (setq not-pref (car ihandles)))
3741 (not (gnus-unbuttonized-mime-type-p
3742 "multipart/alternative")))
3743 (gnus-add-text-properties
3746 (insert (format "%d. " id))
3750 (unless ,(not ibegend)
3751 (setq gnus-article-mime-handle-alist
3752 ',gnus-article-mime-handle-alist))
3753 (gnus-mime-display-alternative
3754 ',ihandles ',not-pref ',begend ,id))
3755 local-map ,gnus-mime-button-map
3756 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3757 face ,gnus-article-button-face
3758 keymap ,gnus-mime-button-map
3761 (widget-convert-button 'link from (point)
3762 :action 'gnus-widget-press-button
3763 :button-keymap gnus-widget-button-keymap)
3765 (while (setq handle (pop handles))
3766 (gnus-add-text-properties
3769 (insert (format "(%c) %-18s"
3770 (if (equal handle preferred) ?* ? )
3771 (mm-handle-media-type handle)))
3775 (unless ,(not ibegend)
3776 (setq gnus-article-mime-handle-alist
3777 ',gnus-article-mime-handle-alist))
3778 (gnus-mime-display-alternative
3779 ',ihandles ',handle ',begend ,id))
3780 local-map ,gnus-mime-button-map
3781 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3782 face ,gnus-article-button-face
3783 keymap ,gnus-mime-button-map
3786 (widget-convert-button 'link from (point)
3787 :action 'gnus-widget-press-button
3788 :button-keymap gnus-widget-button-keymap)
3792 (if (stringp (car preferred))
3793 (gnus-display-mime preferred)
3794 (let ((mail-parse-charset gnus-newsgroup-charset)
3795 (mail-parse-ignored-charsets
3796 (save-excursion (set-buffer gnus-summary-buffer)
3797 gnus-newsgroup-ignored-charsets)))
3798 (mm-display-part preferred)
3802 (narrow-to-region (car begend) (point-max))
3804 nil (length gnus-article-mime-handle-alist)
3805 (1- (length gnus-article-mime-handles))
3806 (mm-handle-media-type handle))))))
3807 (goto-char (point-max))
3808 (setcdr begend (point-marker)))))
3810 (goto-char point))))
3812 (defun gnus-article-wash-status ()
3813 "Return a string which display status of article washing."
3815 (set-buffer gnus-article-buffer)
3816 (let ((cite (memq 'cite gnus-article-wash-types))
3817 (headers (memq 'headers gnus-article-wash-types))
3818 (boring (memq 'boring-headers gnus-article-wash-types))
3819 (pgp (memq 'pgp gnus-article-wash-types))
3820 (pem (memq 'pem gnus-article-wash-types))
3821 (signature (memq 'signature gnus-article-wash-types))
3822 (overstrike (memq 'overstrike gnus-article-wash-types))
3823 (emphasis (memq 'emphasis gnus-article-wash-types)))
3824 (format "%c%c%c%c%c%c%c"
3826 (if (or headers boring) ?h ? )
3827 (if (or pgp pem) ?p ? )
3828 (if signature ?s ? )
3829 (if overstrike ?o ? )
3830 (if gnus-show-mime ?m ? )
3831 (if emphasis ?e ? )))))
3833 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3835 (defun gnus-article-maybe-hide-headers ()
3836 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3837 Provided for backwards compatibility."
3838 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3839 (not (save-excursion (set-buffer gnus-summary-buffer)
3840 gnus-have-all-headers)))
3841 (not gnus-inhibit-hiding))
3842 (gnus-article-hide-headers)))
3846 (defun gnus-output-to-file (file-name)
3847 "Append the current article to a file named FILE-NAME."
3848 (let ((artbuf (current-buffer)))
3850 (insert-buffer-substring artbuf)
3851 ;; Append newline at end of the buffer as separator, and then
3853 (goto-char (point-max))
3855 (write-region-as-binary (point-min) (point-max) file-name 'append)
3858 (defun gnus-narrow-to-page (&optional arg)
3859 "Narrow the article buffer to a page.
3860 If given a numerical ARG, move forward ARG pages."
3862 (setq arg (if arg (prefix-numeric-value arg) 0))
3864 (set-buffer gnus-article-buffer)
3865 (goto-char (point-min))
3867 ;; Remove any old next/prev buttons.
3868 (when (gnus-visual-p 'page-marker)
3869 (let ((buffer-read-only nil))
3870 (gnus-remove-text-with-property 'gnus-prev)
3871 (gnus-remove-text-with-property 'gnus-next)))
3874 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3876 (re-search-forward page-delimiter nil 'move arg)))
3877 (goto-char (match-end 0)))
3880 (if (re-search-forward page-delimiter nil 'move)
3883 (when (and (gnus-visual-p 'page-marker)
3884 (not (= (point-min) 1)))
3886 (goto-char (point-min))
3887 (gnus-insert-prev-page-button)))
3888 (when (and (gnus-visual-p 'page-marker)
3889 (< (+ (point-max) 2) (buffer-size)))
3891 (goto-char (point-max))
3892 (gnus-insert-next-page-button)))))
3894 ;; Article mode commands
3896 (defun gnus-article-goto-next-page ()
3897 "Show the next page of the article."
3899 (when (gnus-article-next-page)
3900 (goto-char (point-min))
3901 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3903 (defun gnus-article-goto-prev-page ()
3904 "Show the next page of the article."
3906 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3907 (gnus-article-prev-page nil)))
3909 (defun gnus-article-next-page (&optional lines)
3910 "Show the next page of the current article.
3911 If end of article, return non-nil. Otherwise return nil.
3912 Argument LINES specifies lines to be scrolled up."
3914 (let ((start (window-start))
3915 end-of-buffer end-of-page)
3917 (move-to-window-line -1)
3918 (if (<= (point) start)
3921 (setq start (point)))
3924 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3925 (and (pos-visible-in-window-p)
3926 (setq end-of-buffer t)))
3928 (setq end-of-page t)))
3930 (move-to-window-line lines)
3931 (unless (search-backward "\n\n" nil t)
3932 (setq start (point)))))
3933 (cond (end-of-buffer t)
3935 (gnus-narrow-to-page 1)
3939 (set-window-start (selected-window) start)
3940 (let (window-pixel-scroll-increment)
3944 (defun gnus-article-prev-page (&optional lines)
3945 "Show previous page of current article.
3946 Argument LINES specifies lines to be scrolled down."
3948 (let (beginning-of-buffer beginning-of-page)
3950 (move-to-window-line 0)
3951 (cond ((eq 1 (point))
3952 (setq beginning-of-buffer t))
3954 (setq beginning-of-page t))))
3955 (cond (beginning-of-buffer)
3957 (gnus-narrow-to-page -1))
3960 (let (window-pixel-scroll-increment)
3961 (scroll-down lines))
3962 (beginning-of-buffer
3963 (goto-char (point-min))))))))
3965 (defun gnus-article-refer-article ()
3966 "Read article specified by message-id around point."
3968 (let ((point (point)))
3969 (search-forward ">" nil t) ;Move point to end of "<....>".
3970 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3971 (let ((message-id (match-string 1)))
3973 (set-buffer gnus-summary-buffer)
3974 (gnus-summary-refer-article message-id))
3976 (error "No references around point"))))
3978 (defun gnus-article-show-summary ()
3979 "Reconfigure windows to show summary buffer."
3981 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3982 (error "There is no summary buffer for this article buffer")
3983 (gnus-article-set-globals)
3984 (gnus-configure-windows 'article)
3985 (gnus-summary-goto-subject gnus-current-article)
3986 (gnus-summary-position-point)))
3988 (defun gnus-article-describe-briefly ()
3989 "Describe article mode commands briefly."
3991 (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")))
3993 (defun gnus-article-summary-command ()
3994 "Execute the last keystroke in the summary buffer."
3996 (let ((obuf (current-buffer))
3997 (owin (current-window-configuration))
3999 (switch-to-buffer gnus-article-current-summary 'norecord)
4000 (setq func (lookup-key (current-local-map) (this-command-keys)))
4001 (call-interactively func)
4003 (set-window-configuration owin)
4004 (set-window-point (get-buffer-window (current-buffer)) (point))))
4006 (defun gnus-article-summary-command-nosave ()
4007 "Execute the last keystroke in the summary buffer."
4010 (pop-to-buffer gnus-article-current-summary 'norecord)
4011 (setq func (lookup-key (current-local-map) (this-command-keys)))
4012 (call-interactively func)))
4014 (defun gnus-article-check-buffer ()
4015 "Beep if not in an article buffer."
4016 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4017 (error "Command invoked outside of a Gnus article buffer")))
4019 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4020 "Read a summary buffer key sequence and execute it from the article buffer."
4022 (gnus-article-check-buffer)
4024 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4025 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4026 "=" "^" "\M-^" "|"))
4032 '("n" "Gn" "p" "Gp"))
4035 (set-buffer gnus-article-current-summary)
4036 (let (gnus-pick-mode)
4037 (push (or key last-command-event) unread-command-events)
4038 (setq keys (static-if (featurep 'xemacs)
4039 (events-to-keys (read-key-sequence nil))
4040 (read-key-sequence nil)))))
4043 (if (or (member keys nosaves)
4044 (member keys nosave-but-article)
4045 (member keys nosave-in-article))
4047 (save-window-excursion
4048 (pop-to-buffer gnus-article-current-summary 'norecord)
4049 ;; We disable the pick minor mode commands.
4050 (let (gnus-pick-mode)
4051 (setq func (lookup-key (current-local-map) keys))))
4055 (unless (member keys nosave-in-article)
4056 (set-buffer gnus-article-current-summary))
4057 (call-interactively func)
4058 (setq new-sum-point (point)))
4059 (when (member keys nosave-but-article)
4060 (pop-to-buffer gnus-article-buffer 'norecord)))
4061 ;; These commands should restore window configuration.
4062 (let ((obuf (current-buffer))
4063 (owin (current-window-configuration))
4065 (summary gnus-article-current-summary)
4066 func in-buffer selected)
4067 (if not-restore-window
4068 (pop-to-buffer summary 'norecord)
4069 (switch-to-buffer summary 'norecord))
4070 (setq in-buffer (current-buffer))
4071 ;; We disable the pick minor mode commands.
4072 (if (setq func (let (gnus-pick-mode)
4073 (lookup-key (current-local-map) keys)))
4075 (call-interactively func)
4076 (setq new-sum-point (point)))
4078 (when (eq in-buffer (current-buffer))
4079 (setq selected (gnus-summary-select-article))
4081 (unless not-restore-window
4082 (set-window-configuration owin))
4083 (when (eq selected 'old)
4085 (set-window-start (get-buffer-window (current-buffer))
4087 (set-window-point (get-buffer-window (current-buffer))
4089 (let ((win (get-buffer-window gnus-article-current-summary)))
4091 (set-window-point win new-sum-point))))))))
4093 (defun gnus-article-hide (&optional arg force)
4094 "Hide all the gruft in the current article.
4095 This means that PGP stuff, signatures, cited text and (some)
4096 headers will be hidden.
4097 If given a prefix, show the hidden text instead."
4098 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4099 (gnus-article-hide-headers arg)
4100 (gnus-article-hide-list-identifiers arg)
4101 (gnus-article-hide-pgp arg)
4102 (gnus-article-hide-citation-maybe arg force)
4103 (gnus-article-hide-signature arg))
4105 (defun gnus-article-maybe-highlight ()
4106 "Do some article highlighting if article highlighting is requested."
4107 (when (gnus-visual-p 'article-highlight 'highlight)
4108 (gnus-article-highlight-some)))
4110 (defun gnus-check-group-server ()
4111 ;; Make sure the connection to the server is alive.
4112 (unless (gnus-server-opened
4113 (gnus-find-method-for-group gnus-newsgroup-name))
4114 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4115 (gnus-request-group gnus-newsgroup-name t)))
4117 (defun gnus-request-article-this-buffer (article group)
4118 "Get an article and insert it into this buffer."
4119 (let (do-update-line sparse-header)
4123 (gnus-kill-all-overlays)
4124 (setq group (or group gnus-newsgroup-name))
4126 ;; Using `gnus-request-article' directly will insert the article into
4127 ;; `nntp-server-buffer' - so we'll save some time by not having to
4128 ;; copy it from the server buffer into the article buffer.
4130 ;; We only request an article by message-id when we do not have the
4131 ;; headers for it, so we'll have to get those.
4132 (when (stringp article)
4133 (gnus-read-header article))
4135 ;; If the article number is negative, that means that this article
4136 ;; doesn't belong in this newsgroup (possibly), so we find its
4137 ;; message-id and request it by id instead of number.
4138 (when (and (numberp article)
4140 (get-buffer gnus-summary-buffer)
4141 (gnus-buffer-exists-p gnus-summary-buffer))
4143 (set-buffer gnus-summary-buffer)
4144 (let ((header (gnus-summary-article-header article)))
4147 ((memq article gnus-newsgroup-sparse)
4148 ;; This is a sparse gap article.
4149 (setq do-update-line article)
4150 (setq article (mail-header-id header))
4151 (setq sparse-header (gnus-read-header article))
4152 (setq gnus-newsgroup-sparse
4153 (delq article gnus-newsgroup-sparse)))
4155 ;; It's a real article.
4156 (setq article (mail-header-id header)))
4158 ;; It is an extracted pseudo-article.
4159 (setq article 'pseudo)
4160 (gnus-request-pseudo-article header))))
4162 (let ((method (gnus-find-method-for-group
4163 gnus-newsgroup-name)))
4164 (when (and (eq (car method) 'nneething)
4167 (file-name-as-directory
4168 (or (cadr (assq 'nneething-address method))
4170 (mail-header-subject header))))
4171 (when (file-directory-p dir)
4172 (setq article 'nneething)
4173 (gnus-group-enter-directory dir))))))))
4176 ;; Refuse to select canceled articles.
4177 ((and (numberp article)
4179 (get-buffer gnus-summary-buffer)
4180 (gnus-buffer-exists-p gnus-summary-buffer)
4181 (eq (cdr (save-excursion
4182 (set-buffer gnus-summary-buffer)
4183 (assq article gnus-newsgroup-reads)))
4184 gnus-canceled-mark))
4186 ;; Check the backlog.
4187 ((and gnus-keep-backlog
4188 (gnus-backlog-request-article group article (current-buffer)))
4190 ;; Check asynchronous pre-fetch.
4191 ((gnus-async-request-fetched-article group article (current-buffer))
4192 (gnus-async-prefetch-next group article gnus-summary-buffer)
4193 (when (and (numberp article) gnus-keep-backlog)
4194 (gnus-backlog-enter-article group article (current-buffer)))
4197 ((and gnus-use-cache
4199 (gnus-cache-request-article article group))
4201 ;; Get the article and put into the article buffer.
4202 ((or (stringp article)
4204 (let ((gnus-override-method gnus-override-method)
4205 (methods (and (stringp article)
4206 gnus-refer-article-method))
4208 (buffer-read-only nil))
4213 (when (and (null gnus-override-method)
4215 (setq gnus-override-method (pop methods)))
4217 (when (eq gnus-override-method 'current)
4218 (setq gnus-override-method gnus-current-select-method))
4220 (gnus-kill-all-overlays)
4221 (let ((gnus-newsgroup-name group))
4222 (gnus-check-group-server))
4223 (when (gnus-request-article article group (current-buffer))
4224 (when (numberp article)
4225 (gnus-async-prefetch-next group article
4226 gnus-summary-buffer)
4227 (when gnus-keep-backlog
4228 (gnus-backlog-enter-article
4229 group article (current-buffer))))
4230 (setq result 'article))
4233 (setq gnus-override-method (pop methods))
4234 (setq result 'done))))
4235 (and (eq result 'article) 'article)))
4239 ;; Associate this article with the current summary buffer.
4240 (setq gnus-article-current-summary gnus-summary-buffer)
4242 ;; Take the article from the original article buffer
4243 ;; and place it in the buffer it's supposed to be in.
4244 (when (and (get-buffer gnus-article-buffer)
4245 (equal (buffer-name (current-buffer))
4246 (buffer-name (get-buffer gnus-article-buffer))))
4248 (if (get-buffer gnus-original-article-buffer)
4249 (set-buffer gnus-original-article-buffer)
4250 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4251 (buffer-disable-undo)
4252 (setq major-mode 'gnus-original-article-mode)
4253 (setq buffer-read-only t))
4254 (let (buffer-read-only)
4256 (insert-buffer-substring gnus-article-buffer))
4257 (setq gnus-original-article (cons group article)))
4260 (run-hooks 'gnus-article-decode-hook)
4261 ;; Mark article as decoded or not.
4262 (setq gnus-article-decoded-p gnus-article-decode-hook))
4264 ;; Update sparse articles.
4265 (when (and do-update-line
4266 (or (numberp article)
4268 (let ((buf (current-buffer)))
4269 (set-buffer gnus-summary-buffer)
4270 (gnus-summary-update-article do-update-line sparse-header)
4271 (gnus-summary-goto-subject do-update-line nil t)
4272 (set-window-point (get-buffer-window (current-buffer) t)
4274 (set-buffer buf))))))
4280 (defcustom gnus-article-edit-mode-hook nil
4281 "Hook run in article edit mode buffers."
4282 :group 'gnus-article-various
4285 (defcustom gnus-article-edit-article-setup-function
4286 'gnus-article-mime-edit-article-setup
4287 "Function called to setup an editing article buffer."
4288 :group 'gnus-article-various
4291 (defvar gnus-article-edit-done-function nil)
4293 (defvar gnus-article-edit-mode-map nil)
4295 ;; Should we be using derived.el for this?
4296 (unless gnus-article-edit-mode-map
4297 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4298 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4300 (gnus-define-keys gnus-article-edit-mode-map
4301 "\C-c\C-c" gnus-article-edit-done
4302 "\C-c\C-k" gnus-article-edit-exit)
4304 (gnus-define-keys (gnus-article-edit-wash-map
4305 "\C-c\C-w" gnus-article-edit-mode-map)
4306 "f" gnus-article-edit-full-stops))
4308 (defun gnus-article-edit-mode ()
4309 "Major mode for editing articles.
4310 This is an extended text-mode.
4312 \\{gnus-article-edit-mode-map}"
4314 (setq major-mode 'gnus-article-edit-mode)
4315 (setq mode-name "Article Edit")
4316 (use-local-map gnus-article-edit-mode-map)
4317 (make-local-variable 'gnus-article-edit-done-function)
4318 (make-local-variable 'gnus-prev-winconf)
4319 (setq buffer-read-only nil)
4320 (buffer-enable-undo)
4322 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4324 (defun gnus-article-edit (&optional force)
4325 "Edit the current article.
4326 This will have permanent effect only in mail groups.
4327 If FORCE is non-nil, allow editing of articles even in read-only
4330 (when (and (not force)
4331 (gnus-group-read-only-p))
4332 (error "The current newsgroup does not support article editing"))
4333 (gnus-article-date-original)
4334 (gnus-article-edit-article
4336 `(lambda (no-highlight)
4338 (gnus-summary-edit-article-done
4339 ,(or (mail-header-references gnus-current-headers) "")
4340 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4342 (defun gnus-article-edit-article (start-func exit-func)
4343 "Start editing the contents of the current article buffer."
4344 (let ((winconf (current-window-configuration)))
4345 (set-buffer gnus-article-buffer)
4346 (gnus-article-edit-mode)
4347 (funcall start-func)
4348 (gnus-configure-windows 'edit-article)
4349 (setq gnus-article-edit-done-function exit-func)
4350 (setq gnus-prev-winconf winconf)
4351 (when gnus-article-edit-article-setup-function
4352 (funcall gnus-article-edit-article-setup-function))
4353 (gnus-message 6 "C-c C-c to end edits")))
4355 (defun gnus-article-edit-done (&optional arg)
4356 "Update the article edits and exit."
4361 (when (article-goto-body)
4362 (let ((lines (count-lines (point) (point-max)))
4363 (length (- (point-max) (point)))
4364 (case-fold-search t)
4365 (body (copy-marker (point))))
4366 (goto-char (point-min))
4367 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4368 (delete-region (match-beginning 1) (match-end 1))
4369 (insert (number-to-string length)))
4370 (goto-char (point-min))
4371 (when (re-search-forward
4372 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4373 (delete-region (match-beginning 1) (match-end 1))
4374 (insert (number-to-string length)))
4375 (goto-char (point-min))
4376 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4377 (delete-region (match-beginning 1) (match-end 1))
4378 (insert (number-to-string lines)))))))
4379 (let ((func gnus-article-edit-done-function)
4380 (buf (current-buffer))
4381 (start (window-start)))
4382 (remove-hook 'gnus-article-mode-hook
4383 'gnus-article-mime-edit-article-unwind)
4384 (gnus-article-edit-exit)
4387 (let ((buffer-read-only nil))
4389 ;; The cache and backlog have to be flushed somewhat.
4390 (when gnus-keep-backlog
4391 (gnus-backlog-remove-article
4392 (car gnus-article-current) (cdr gnus-article-current)))
4393 ;; Flush original article as well.
4395 (when (get-buffer gnus-original-article-buffer)
4396 (set-buffer gnus-original-article-buffer)
4397 (setq gnus-original-article nil)))
4398 (when gnus-use-cache
4399 (gnus-cache-update-article
4400 (car gnus-article-current) (cdr gnus-article-current))))
4402 (set-window-start (get-buffer-window buf) start)
4403 (set-window-point (get-buffer-window buf) (point))))
4405 (defun gnus-article-edit-exit ()
4406 "Exit the article editing without updating."
4408 ;; We remove all text props from the article buffer.
4409 (let ((buf (format "%s" (buffer-string)))
4410 (curbuf (current-buffer))
4412 (window-start (window-start)))
4415 (let ((winconf gnus-prev-winconf))
4417 (set-window-configuration winconf)
4418 ;; Tippy-toe some to make sure that point remains where it was.
4419 (save-current-buffer
4421 (set-window-start (get-buffer-window (current-buffer)) window-start)
4424 (defun gnus-article-edit-full-stops ()
4425 "Interactively repair spacing at end of sentences."
4428 (goto-char (point-min))
4429 (search-forward-regexp "^$" nil t)
4430 (let ((case-fold-search nil))
4431 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4434 ;;; Article editing with MIME-Edit
4437 (defcustom gnus-article-mime-edit-article-setup-hook nil
4438 "Hook run after setting up a MIME editing article buffer."
4439 :group 'gnus-article-various
4442 (defun gnus-article-mime-edit-article-unwind ()
4443 "Unwind `gnus-article-buffer' if article editing was given up."
4444 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4445 (when mime-edit-mode-flag
4446 (mime-edit-exit 'nomime 'no-error)
4448 (when (featurep 'font-lock)
4449 (setq font-lock-defaults nil)
4450 (font-lock-mode 0)))
4452 (defun gnus-article-mime-edit-article-setup ()
4453 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4454 after replacing with the original article."
4455 (setq gnus-show-mime t)
4456 (setq gnus-article-edit-done-function
4457 `(lambda (&rest args)
4458 (when mime-edit-mode-flag
4461 (goto-char (point-min))
4462 (let (case-fold-search)
4463 (when (re-search-forward
4464 (format "^%s$" (regexp-quote mail-header-separator))
4466 (replace-match "")))
4467 (when (featurep 'font-lock)
4468 (setq font-lock-defaults nil)
4470 (apply ,gnus-article-edit-done-function args)
4471 (set-buffer gnus-original-article-buffer)
4473 (insert-buffer gnus-article-buffer)
4474 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4475 (gnus-article-prepare-display)))
4476 (substitute-key-definition
4477 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4478 gnus-article-edit-mode-map)
4480 (insert-buffer gnus-original-article-buffer)
4482 (when (featurep 'font-lock)
4483 (set (make-local-variable 'font-lock-defaults)
4484 '(message-font-lock-keywords t))
4485 (font-lock-set-defaults)
4486 (turn-on-font-lock))
4487 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4488 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4490 (defun gnus-article-mime-edit-exit ()
4491 "Exit the article MIME editing without updating."
4493 (let ((winconf gnus-prev-winconf)
4495 (when mime-edit-mode-flag
4498 (goto-char (point-min))
4499 (let (case-fold-search)
4500 (when (re-search-forward
4501 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4502 (replace-match "")))
4503 (when (featurep 'font-lock)
4504 (setq font-lock-defaults nil)
4506 ;; We remove all text props from the article buffer.
4507 (setq buf (format "%s" (buffer-string)))
4508 (set-buffer (get-buffer-create gnus-original-article-buffer))
4511 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4512 (gnus-article-prepare-display)
4513 (set-window-configuration winconf)))
4516 ;;; Article highlights
4519 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4521 ;;; Internal Variables:
4523 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(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\\)\\)"
4524 "Regular expression that matches URLs."
4525 :group 'gnus-article-buttons
4528 (defcustom gnus-button-alist
4529 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4530 0 t gnus-button-message-id 2)
4531 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4532 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4534 gnus-button-fetch-group 4)
4535 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4536 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4537 t gnus-button-message-id 3)
4538 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4539 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4540 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4541 ;; This is how URLs _should_ be embedded in text...
4542 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4544 (,gnus-button-url-regexp 0 t browse-url 0))
4545 "*Alist of regexps matching buttons in article bodies.
4547 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4548 REGEXP: is the string matching text around the button,
4549 BUTTON: is the number of the regexp grouping actually matching the button,
4550 FORM: is a lisp expression which must eval to true for the button to
4552 CALLBACK: is the function to call when the user push this button, and each
4553 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4555 CALLBACK can also be a variable, in that case the value of that
4556 variable it the real callback function."
4557 :group 'gnus-article-buttons
4558 :type '(repeat (list regexp
4559 (integer :tag "Button")
4561 (function :tag "Callback")
4564 (integer :tag "Regexp group")))))
4566 (defcustom gnus-header-button-alist
4567 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4568 0 t gnus-button-message-id 0)
4569 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4570 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4571 0 t gnus-button-mailto 0)
4572 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4573 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4574 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4575 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4576 gnus-button-message-id 3))
4577 "*Alist of headers and regexps to match buttons in article heads.
4579 This alist is very similar to `gnus-button-alist', except that each
4580 alist has an additional HEADER element first in each entry:
4582 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4584 HEADER is a regexp to match a header. For a fuller explanation, see
4585 `gnus-button-alist'."
4586 :group 'gnus-article-buttons
4587 :group 'gnus-article-headers
4588 :type '(repeat (list (regexp :tag "Header")
4590 (integer :tag "Button")
4592 (function :tag "Callback")
4595 (integer :tag "Regexp group")))))
4597 (defvar gnus-button-regexp nil)
4598 (defvar gnus-button-marker-list nil)
4599 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4601 (defvar gnus-button-last nil)
4602 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4606 (defun gnus-article-push-button (event)
4607 "Check text under the mouse pointer for a callback function.
4608 If the text under the mouse pointer has a `gnus-callback' property,
4609 call it with the value of the `gnus-data' text property."
4611 (set-buffer (window-buffer (posn-window (event-start event))))
4612 (let* ((pos (posn-point (event-start event)))
4613 (data (get-text-property pos 'gnus-data))
4614 (fun (get-text-property pos 'gnus-callback)))
4617 (funcall fun data))))
4619 (defun gnus-article-press-button ()
4620 "Check text at point for a callback function.
4621 If the text at point has a `gnus-callback' property,
4622 call it with the value of the `gnus-data' text property."
4624 (let* ((data (get-text-property (point) 'gnus-data))
4625 (fun (get-text-property (point) 'gnus-callback)))
4627 (funcall fun data))))
4629 (defun gnus-article-prev-button (n)
4630 "Move point to N buttons backward.
4631 If N is negative, move forward instead."
4633 (gnus-article-next-button (- n)))
4635 (defun gnus-article-next-button (n)
4636 "Move point to N buttons forward.
4637 If N is negative, move backward instead."
4639 (let ((function (if (< n 0) 'previous-single-property-change
4640 'next-single-property-change))
4641 (inhibit-point-motion-hooks t)
4643 (limit (if (< n 0) (point-min) (point-max))))
4645 (while (and (not (= limit (point)))
4647 ;; Skip past the current button.
4648 (when (get-text-property (point) 'gnus-callback)
4649 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4650 ;; Go to the next (or previous) button.
4651 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4652 ;; Put point at the start of the button.
4653 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4654 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4655 ;; Skip past intangible buttons.
4656 (when (get-text-property (point) 'intangible)
4660 (gnus-message 5 "No more buttons"))
4663 (defun gnus-article-highlight (&optional force)
4664 "Highlight current article.
4665 This function calls `gnus-article-highlight-headers',
4666 `gnus-article-highlight-citation',
4667 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4668 do the highlighting. See the documentation for those functions."
4669 (interactive (list 'force))
4670 (gnus-article-highlight-headers)
4671 (gnus-article-highlight-citation force)
4672 (gnus-article-highlight-signature)
4673 (gnus-article-add-buttons force)
4674 (gnus-article-add-buttons-to-head))
4676 (defun gnus-article-highlight-some (&optional force)
4677 "Highlight current article.
4678 This function calls `gnus-article-highlight-headers',
4679 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4680 do the highlighting. See the documentation for those functions."
4681 (interactive (list 'force))
4682 (gnus-article-highlight-headers)
4683 (gnus-article-highlight-signature)
4684 (gnus-article-add-buttons))
4686 (defun gnus-article-highlight-headers ()
4687 "Highlight article headers as specified by `gnus-header-face-alist'."
4690 (set-buffer gnus-article-buffer)
4692 (let ((alist gnus-header-face-alist)
4693 (buffer-read-only nil)
4694 (case-fold-search t)
4695 (inhibit-point-motion-hooks t)
4696 entry regexp header-face field-face from hpoints fpoints)
4697 (article-narrow-to-head)
4698 (while (setq entry (pop alist))
4699 (goto-char (point-min))
4700 (setq regexp (concat "^\\("
4701 (if (string-equal "" (nth 0 entry))
4705 header-face (nth 1 entry)
4706 field-face (nth 2 entry))
4707 (while (and (re-search-forward regexp nil t)
4711 (unless (search-forward ":" nil t)
4713 (when (and header-face
4714 (not (memq (point) hpoints)))
4715 (push (point) hpoints)
4716 (gnus-put-text-property from (point) 'face header-face))
4717 (when (and field-face
4718 (not (memq (setq from (point)) fpoints)))
4720 (if (re-search-forward "^[^ \t]" nil t)
4722 (goto-char (point-max)))
4723 (gnus-put-text-property from (point) 'face field-face))))))))
4725 (defun gnus-article-highlight-signature ()
4726 "Highlight the signature in an article.
4727 It does this by highlighting everything after
4728 `gnus-signature-separator' using `gnus-signature-face'."
4730 (when gnus-signature-face
4732 (set-buffer gnus-article-buffer)
4733 (let ((buffer-read-only nil)
4734 (inhibit-point-motion-hooks t))
4736 (when (gnus-article-narrow-to-signature)
4737 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4738 'face gnus-signature-face)))))))
4740 (defun gnus-article-buttonize-signature ()
4741 "Add button to the signature."
4744 (set-buffer gnus-article-buffer)
4745 (let ((buffer-read-only nil)
4746 (inhibit-point-motion-hooks t))
4747 (when (gnus-article-search-signature)
4748 (gnus-article-add-button (match-beginning 0) (match-end 0)
4749 'gnus-signature-toggle
4750 (set-marker (make-marker)
4751 (1+ (match-end 0))))))))
4753 (defun gnus-button-in-region-p (b e prop)
4754 "Say whether PROP exists in the region."
4755 (text-property-not-all b e prop nil))
4757 (defun gnus-article-add-buttons (&optional force)
4758 "Find external references in the article and make buttons of them.
4759 \"External references\" are things like Message-IDs and URLs, as
4760 specified by `gnus-button-alist'."
4761 (interactive (list 'force))
4763 (set-buffer gnus-article-buffer)
4764 (let ((buffer-read-only nil)
4765 (inhibit-point-motion-hooks t)
4766 (case-fold-search t)
4767 (alist gnus-button-alist)
4769 ;; Remove all old markers.
4770 (let (marker entry new-list)
4771 (while (setq marker (pop gnus-button-marker-list))
4772 (if (or (< marker (point-min)) (>= marker (point-max)))
4773 (push marker new-list)
4775 (when (setq entry (gnus-button-entry))
4776 (put-text-property (match-beginning (nth 1 entry))
4777 (match-end (nth 1 entry))
4778 'gnus-callback nil))
4779 (set-marker marker nil)))
4780 (setq gnus-button-marker-list new-list))
4781 ;; We skip the headers.
4784 (while (setq entry (pop alist))
4785 (setq regexp (car entry))
4787 (while (re-search-forward regexp nil t)
4788 (let* ((start (and entry (match-beginning (nth 1 entry))))
4789 (end (and entry (match-end (nth 1 entry))))
4790 (from (match-beginning 0)))
4791 (when (and (or (eq t (nth 2 entry))
4792 (eval (nth 2 entry)))
4793 (not (gnus-button-in-region-p
4794 start end 'gnus-callback)))
4795 ;; That optional form returned non-nil, so we add the
4797 (gnus-article-add-button
4798 start end 'gnus-button-push
4799 (car (push (set-marker (make-marker) from)
4800 gnus-button-marker-list))))))))))
4802 ;; Add buttons to the head of an article.
4803 (defun gnus-article-add-buttons-to-head ()
4804 "Add buttons to the head of the article."
4807 (set-buffer gnus-article-buffer)
4809 (let ((buffer-read-only nil)
4810 (inhibit-point-motion-hooks t)
4811 (case-fold-search t)
4812 (alist gnus-header-button-alist)
4814 (article-narrow-to-head)
4816 ;; Each alist entry.
4817 (setq entry (car alist)
4819 (goto-char (point-min))
4820 (while (re-search-forward (car entry) nil t)
4821 ;; Each header matching the entry.
4822 (setq beg (match-beginning 0))
4823 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4824 (match-beginning 0))
4827 (while (re-search-forward (nth 1 entry) end t)
4828 ;; Each match within a header.
4829 (let* ((entry (cdr entry))
4830 (start (match-beginning (nth 1 entry)))
4831 (end (match-end (nth 1 entry)))
4832 (form (nth 2 entry)))
4833 (goto-char (match-end 0))
4835 (gnus-article-add-button
4836 start end (nth 3 entry)
4837 (buffer-substring (match-beginning (nth 4 entry))
4838 (match-end (nth 4 entry)))))))
4839 (goto-char end)))))))
4841 ;;; External functions:
4843 (defun gnus-article-add-button (from to fun &optional data)
4844 "Create a button between FROM and TO with callback FUN and data DATA."
4845 (when gnus-article-button-face
4846 (gnus-overlay-put (gnus-make-overlay from to)
4847 'face gnus-article-button-face))
4848 (gnus-add-text-properties
4850 (nconc (and gnus-article-mouse-face
4851 (list gnus-mouse-face-prop gnus-article-mouse-face))
4852 (list 'gnus-callback fun)
4853 (and data (list 'gnus-data data)))))
4855 ;;; Internal functions:
4857 (defun gnus-article-set-globals ()
4859 (set-buffer gnus-summary-buffer)
4860 (gnus-set-global-variables)))
4862 (defun gnus-signature-toggle (end)
4864 (set-buffer gnus-article-buffer)
4865 (let ((buffer-read-only nil)
4866 (inhibit-point-motion-hooks t)
4867 (limit (next-single-property-change end 'mime-view-entity
4869 (if (get-text-property end 'invisible)
4870 (gnus-article-unhide-text end limit)
4871 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4873 (defun gnus-button-entry ()
4874 ;; Return the first entry in `gnus-button-alist' matching this place.
4875 (let ((alist gnus-button-alist)
4878 (setq entry (pop alist))
4879 (if (looking-at (car entry))
4884 (defun gnus-button-push (marker)
4885 ;; Push button starting at MARKER.
4888 (let* ((entry (gnus-button-entry))
4889 (inhibit-point-motion-hooks t)
4891 (args (mapcar (lambda (group)
4892 (let ((string (match-string group)))
4893 (gnus-set-text-properties
4894 0 (length string) nil string)
4901 (fboundp (symbol-value fun)))
4902 (apply (symbol-value fun) args))
4904 (gnus-message 1 "You must define `%S' to use this button"
4905 (cons fun args)))))))
4907 (defun gnus-button-message-id (message-id)
4910 (set-buffer gnus-summary-buffer)
4911 (gnus-summary-refer-article message-id)))
4913 (defun gnus-button-fetch-group (address)
4914 "Fetch GROUP specified by ADDRESS."
4915 (if (not (string-match "[:/]" address))
4916 ;; This is just a simple group url.
4917 (gnus-group-read-ephemeral-group address gnus-select-method)
4918 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4920 (error "Can't parse %s" address)
4921 (gnus-group-read-ephemeral-group
4922 (match-string 4 address)
4923 `(nntp ,(match-string 1 address)
4924 (nntp-address ,(match-string 1 address))
4925 (nntp-port-number ,(if (match-end 3)
4926 (match-string 3 address)
4929 (defun gnus-url-parse-query-string (query &optional downcase)
4930 (let (retval pairs cur key val)
4931 (setq pairs (split-string query "&"))
4933 (setq cur (car pairs)
4935 (if (not (string-match "=" cur))
4937 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4938 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4940 (setq key (downcase key)))
4941 (setq cur (assoc key retval))
4943 (setcdr cur (cons val (cdr cur)))
4944 (setq retval (cons (list key val) retval)))))
4947 (defun gnus-url-unhex (x)
4954 (defun gnus-url-unhex-string (str &optional allow-newlines)
4955 "Remove %XXX embedded spaces, etc in a url.
4956 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4957 decoding of carriage returns and line feeds in the string, which is normally
4958 forbidden in URL encoding."
4959 (setq str (or str ""))
4961 (case-fold-search t))
4962 (while (string-match "%[0-9a-f][0-9a-f]" str)
4963 (let* ((start (match-beginning 0))
4964 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4966 (gnus-url-unhex (elt str (+ start 2))))))
4968 tmp (substring str 0 start)
4971 (char-to-string code))
4972 ((or (= code ?\n) (= code ?\r))
4974 (t (char-to-string code))))
4975 str (substring str (match-end 0)))))
4976 (setq tmp (concat tmp str))
4979 (defun gnus-url-mailto (url)
4980 ;; Send mail to someone
4981 (when (string-match "mailto:/*\\(.*\\)" url)
4982 (setq url (substring url (match-beginning 1) nil)))
4983 (let (to args subject func)
4984 (if (string-match (regexp-quote "?") url)
4985 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4986 args (gnus-url-parse-query-string
4987 (substring url (match-end 0) nil) t))
4988 (setq to (gnus-url-unhex-string url)))
4989 (setq args (cons (list "to" to) args)
4990 subject (cdr-safe (assoc "subject" args)))
4991 (gnus-setup-message 'reply
4994 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4997 (message-position-on-field (caar args)))
4998 (insert (mapconcat 'identity (cdar args) ", "))
4999 (setq args (cdr args)))
5002 (message-goto-subject)))))
5004 (defun gnus-button-mailto (address)
5006 (set-buffer (gnus-copy-article-buffer))
5007 (gnus-setup-message 'reply
5008 (message-reply address)))
5010 (defun gnus-button-reply (address)
5011 ;; Reply to ADDRESS.
5012 (gnus-setup-message 'reply
5013 (message-reply address)))
5015 (defun gnus-button-embedded-url (address)
5017 (browse-url (gnus-strip-whitespace address)))
5019 (defun gnus-article-smiley-display ()
5020 "Display \"smileys\" as small graphical icons."
5021 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5023 ;;; Next/prev buttons in the article buffer.
5025 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5026 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5028 (defvar gnus-prev-page-map nil)
5029 (unless gnus-prev-page-map
5030 (setq gnus-prev-page-map (make-sparse-keymap))
5031 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5032 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5034 (static-if (featurep 'xemacs)
5035 (defun gnus-insert-prev-page-button ()
5036 (let ((buffer-read-only nil))
5038 gnus-prev-page-line-format nil
5039 `(gnus-prev t local-map ,gnus-prev-page-map
5040 gnus-callback gnus-article-button-prev-page
5041 article-type annotation))))
5042 (defun gnus-insert-prev-page-button ()
5043 (let ((buffer-read-only nil)
5044 (situation (get-text-property (point-min) 'mime-view-situation)))
5045 (set-keymap-parent gnus-prev-page-map (current-local-map))
5047 gnus-prev-page-line-format nil
5048 `(gnus-prev t local-map ,gnus-prev-page-map
5049 gnus-callback gnus-article-button-prev-page
5050 article-type annotation
5051 mime-view-situation ,situation))))
5054 (defvar gnus-next-page-map nil)
5055 (unless gnus-next-page-map
5056 (setq gnus-next-page-map (make-sparse-keymap))
5057 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5058 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5060 (defun gnus-button-next-page ()
5061 "Go to the next page."
5063 (let ((win (selected-window)))
5064 (select-window (get-buffer-window gnus-article-buffer t))
5065 (gnus-article-next-page)
5066 (select-window win)))
5068 (defun gnus-button-prev-page ()
5069 "Go to the prev page."
5071 (let ((win (selected-window)))
5072 (select-window (get-buffer-window gnus-article-buffer t))
5073 (gnus-article-prev-page)
5074 (select-window win)))
5076 (static-if (featurep 'xemacs)
5077 (defun gnus-insert-next-page-button ()
5078 (let ((buffer-read-only nil))
5079 (gnus-eval-format gnus-next-page-line-format nil
5081 t local-map ,gnus-next-page-map
5082 gnus-callback gnus-article-button-next-page
5083 article-type annotation))))
5084 (defun gnus-insert-next-page-button ()
5085 (let ((buffer-read-only nil)
5086 (situation (get-text-property (point-min) 'mime-view-situation)))
5087 (set-keymap-parent gnus-next-page-map (current-local-map))
5088 (gnus-eval-format gnus-next-page-line-format nil
5090 t local-map ,gnus-next-page-map
5091 gnus-callback gnus-article-button-next-page
5092 article-type annotation
5093 mime-view-situation ,situation))))
5096 (defun gnus-article-button-next-page (arg)
5097 "Go to the next page."
5099 (let ((win (selected-window)))
5100 (select-window (get-buffer-window gnus-article-buffer t))
5101 (gnus-article-next-page)
5102 (select-window win)))
5104 (defun gnus-article-button-prev-page (arg)
5105 "Go to the prev page."
5107 (let ((win (selected-window)))
5108 (select-window (get-buffer-window gnus-article-buffer t))
5109 (gnus-article-prev-page)
5110 (select-window win)))
5112 (defvar gnus-decode-header-methods
5113 '(mail-decode-encoded-word-region)
5114 "List of methods used to decode headers.
5116 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5117 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5118 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5119 whose names match REGEXP.
5122 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5123 mail-decode-encoded-word-region
5124 (\"chinese\" . rfc1843-decode-region))
5127 (defvar gnus-decode-header-methods-cache nil)
5129 (defun gnus-multi-decode-header (start end)
5130 "Apply the functions from `gnus-encoded-word-methods' that match."
5131 (unless (and gnus-decode-header-methods-cache
5132 (eq gnus-newsgroup-name
5133 (car gnus-decode-header-methods-cache)))
5134 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5137 (nconc gnus-decode-header-methods-cache (list x))
5138 (if (and gnus-newsgroup-name
5139 (string-match (car x) gnus-newsgroup-name))
5140 (nconc gnus-decode-header-methods-cache
5142 gnus-decode-header-methods))
5143 (let ((xlist gnus-decode-header-methods-cache))
5146 (narrow-to-region start end)
5148 (funcall (pop xlist) (point-min) (point-max))))))
5151 ;;; Treatment top-level handling.
5154 (defun gnus-treat-article (condition &optional part-number total-parts type)
5155 (let ((length (- (point-max) (point-min)))
5156 (alist gnus-treatment-function-alist)
5157 (article-goto-body-goes-to-point-min-p t)
5161 (let ((list gnus-article-treat-types))
5163 (when (string-match (pop list) type)
5164 (throw 'found t)))))))
5165 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5166 (entity (static-unless (featurep 'xemacs)
5167 (when (eq 'head condition)
5168 (get-text-property (point-min) 'mime-view-entity))))
5169 val elem buttonized)
5170 (gnus-run-hooks 'gnus-part-display-hook)
5171 (unless gnus-inhibit-treatment
5172 (while (setq elem (pop alist))
5175 (if (gnus-buffer-live-p gnus-summary-buffer)
5176 (set-buffer gnus-summary-buffer))
5177 (symbol-value (car elem))))
5178 (when (and (or (consp val)
5180 (gnus-treat-predicate val)
5181 (or (not (get (car elem) 'highlight))
5183 (when (and (not buttonized)
5185 '(gnus-treat-hide-signature
5186 gnus-treat-highlight-signature)))
5187 (gnus-article-buttonize-signature)
5188 (setq buttonized t))
5190 (funcall (cadr elem)))))
5191 ;; FSF Emacsen does not inherit the existing text properties
5192 ;; in the new text, so we should do it for `mime-view-entity'.
5193 (static-unless (featurep 'xemacs)
5195 (put-text-property (point-min) (point-max)
5196 'mime-view-entity entity))))))
5198 ;; Dynamic variables.
5199 (defvar part-number)
5200 (defvar total-parts)
5204 (defun gnus-treat-predicate (val)
5209 (stringp (car val)))
5210 (apply 'gnus-or (mapcar `(lambda (s)
5211 (string-match s ,(or gnus-newsgroup-name "")))
5214 (let ((pred (pop val)))
5217 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5219 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5221 (not (gnus-treat-predicate (car val))))
5223 (equal (car val) type))
5225 (error "%S is not a valid predicate" pred)))))
5235 (eq part-number total-parts))
5239 (error "%S is not a valid value" val))))
5245 (defun gnus-article-header-presentation-method (entity situation)
5246 (mime-insert-header entity)
5249 (set-alist 'mime-header-presentation-method-alist
5250 'gnus-original-article-mode
5251 #'gnus-article-header-presentation-method)
5253 (defun gnus-mime-preview-quitting-method ()
5254 (mime-preview-kill-buffer)
5255 (delete-other-windows)
5256 (gnus-article-show-summary)
5257 (gnus-summary-select-article gnus-show-all-headers t))
5259 (set-alist 'mime-preview-quitting-method-alist
5260 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5262 (set-alist 'mime-preview-following-method-alist
5263 'gnus-original-article-mode #'gnus-following-method)
5265 (set-alist 'mime-preview-over-to-previous-method-alist
5266 'gnus-original-article-mode
5268 (if (> (point-min) 1)
5269 (gnus-article-prev-page)
5270 (gnus-article-read-summary-keys
5271 nil (gnus-character-to-event ?P)))))
5273 (set-alist 'mime-preview-over-to-next-method-alist
5274 'gnus-original-article-mode'
5276 (if (< (point-max) (buffer-size))
5277 (gnus-article-next-page)
5278 (gnus-article-read-summary-keys
5279 nil (gnus-character-to-event ?N)))))
5289 (run-hooks 'gnus-art-load-hook)
5291 ;;; gnus-art.el ends here