1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
43 (defgroup gnus-article nil
45 :link '(custom-manual "(gnus)The Article Buffer")
48 (defgroup gnus-article-treat nil
49 "Treating article parts."
50 :link '(custom-manual "(gnus)Article Hiding")
53 (defgroup gnus-article-hiding nil
54 "Hiding article parts."
55 :link '(custom-manual "(gnus)Article Hiding")
58 (defgroup gnus-article-highlight nil
59 "Article highlighting."
60 :link '(custom-manual "(gnus)Article Highlighting")
64 (defgroup gnus-article-signature nil
66 :link '(custom-manual "(gnus)Article Signature")
69 (defgroup gnus-article-headers nil
71 :link '(custom-manual "(gnus)Hiding Headers")
74 (defgroup gnus-article-washing nil
75 "Special commands on articles."
76 :link '(custom-manual "(gnus)Article Washing")
79 (defgroup gnus-article-emphasis nil
80 "Fontisizing articles."
81 :link '(custom-manual "(gnus)Article Fontisizing")
84 (defgroup gnus-article-saving nil
86 :link '(custom-manual "(gnus)Saving Articles")
89 (defgroup gnus-article-mime nil
90 "Worshiping the MIME wonder."
91 :link '(custom-manual "(gnus)Using MIME")
94 (defgroup gnus-article-buttons nil
95 "Pushable buttons in the article buffer."
96 :link '(custom-manual "(gnus)Article Buttons")
99 (defgroup gnus-article-various nil
100 "Other article options."
101 :link '(custom-manual "(gnus)Misc Article")
102 :group 'gnus-article)
104 (defcustom gnus-ignored-headers
105 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
106 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
107 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
108 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
109 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
110 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
111 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
112 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
113 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
114 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
115 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
116 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
117 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
118 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
119 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
120 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
121 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
122 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
123 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
124 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
125 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
126 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
127 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
128 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
129 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
130 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
131 "^X-Received:" "^Content-length:" "X-precedence:")
132 "*All headers that start with this regexp will be hidden.
133 This variable can also be a list of regexps of headers to be ignored.
134 If `gnus-visible-headers' is non-nil, this variable will be ignored."
135 :type '(choice :custom-show nil
138 :group 'gnus-article-hiding)
140 (defcustom gnus-visible-headers
141 "^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:"
142 "*All headers that do not match this regexp will be hidden.
143 This variable can also be a list of regexp of headers to remain visible.
144 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
145 :type '(repeat :value-to-internal (lambda (widget value)
146 (custom-split-regexp-maybe value))
147 :match (lambda (widget value)
149 (widget-editable-list-match widget value)))
151 :group 'gnus-article-hiding)
153 (defcustom gnus-sorted-header-list
154 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
155 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
156 "*This variable is a list of regular expressions.
157 If it is non-nil, headers that match the regular expressions will
158 be placed first in the article buffer in the sequence specified by
160 :type '(repeat regexp)
161 :group 'gnus-article-hiding)
163 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
164 "Headers that are only to be displayed if they have interesting data.
165 Possible values in this list are `empty', `newsgroups', `followup-to',
166 `reply-to', `date', `long-to', and `many-to'."
167 :type '(set (const :tag "Headers with no content." empty)
168 (const :tag "Newsgroups with only one group." newsgroups)
169 (const :tag "Followup-to identical to newsgroups." followup-to)
170 (const :tag "Reply-to identical to from." reply-to)
171 (const :tag "Date less than four days old." date)
172 (const :tag "Very long To header." long-to)
173 (const :tag "Multiple To headers." many-to))
174 :group 'gnus-article-hiding)
176 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
177 "Regexp matching signature separator.
178 This can also be a list of regexps. In that case, it will be checked
179 from head to tail looking for a separator. Searches will be done from
180 the end of the buffer."
181 :type '(repeat string)
182 :group 'gnus-article-signature)
184 (defcustom gnus-signature-limit nil
185 "Provide a limit to what is considered a signature.
186 If it is a number, no signature may not be longer (in characters) than
187 that number. If it is a floating point number, no signature may be
188 longer (in lines) than that number. If it is a function, the function
189 will be called without any parameters, and if it returns nil, there is
190 no signature in the buffer. If it is a string, it will be used as a
191 regexp. If it matches, the text in question is not a signature."
192 :type '(choice (integer :value 200)
194 (function :value fun)
195 (regexp :value ".*"))
196 :group 'gnus-article-signature)
198 (defcustom gnus-hidden-properties '(invisible t intangible t)
199 "Property list to use for hiding text."
201 :group 'gnus-article-hiding)
203 (defcustom gnus-article-x-face-command
204 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
205 "*String or function to be executed to display an X-Face header.
206 If it is a string, the command will be executed in a sub-shell
207 asynchronously. The compressed face will be piped to this command."
208 :type 'string ;Leave function case to Lisp.
209 :group 'gnus-article-washing)
211 (defcustom gnus-article-x-face-too-ugly nil
212 "Regexp matching posters whose face shouldn't be shown automatically."
213 :type '(choice regexp (const nil))
214 :group 'gnus-article-washing)
216 (defcustom gnus-emphasis-alist
218 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
220 '(("_" "_" underline)
223 ("_/" "/_" underline-italic)
224 ("_\\*" "\\*_" underline-bold)
225 ("\\*/" "/\\*" bold-italic)
226 ("_\\*/" "/\\*_" underline-bold-italic))))
227 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
228 2 3 gnus-emphasis-underline)
232 (format format (car spec) (cadr spec))
233 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
235 "*Alist that says how to fontify certain phrases.
236 Each item looks like this:
238 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
240 The first element is a regular expression to be matched. The second
241 is a number that says what regular expression grouping used to find
242 the entire emphasized word. The third is a number that says what
243 regexp grouping should be displayed and highlighted. The fourth
244 is the face used for highlighting."
245 :type '(repeat (list :value ("" 0 0 default)
247 (integer :tag "Match group")
248 (integer :tag "Emphasize group")
250 :group 'gnus-article-emphasis)
252 (defface gnus-emphasis-bold '((t (:bold t)))
253 "Face used for displaying strong emphasized text (*word*)."
254 :group 'gnus-article-emphasis)
256 (defface gnus-emphasis-italic '((t (:italic t)))
257 "Face used for displaying italic emphasized text (/word/)."
258 :group 'gnus-article-emphasis)
260 (defface gnus-emphasis-underline '((t (:underline t)))
261 "Face used for displaying underlined emphasized text (_word_)."
262 :group 'gnus-article-emphasis)
264 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
265 "Face used for displaying underlined bold emphasized text (_*word*_)."
266 :group 'gnus-article-emphasis)
268 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
269 "Face used for displaying underlined italic emphasized text (_/word/_)."
270 :group 'gnus-article-emphasis)
272 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
273 "Face used for displaying bold italic emphasized text (/*word*/)."
274 :group 'gnus-article-emphasis)
276 (defface gnus-emphasis-underline-bold-italic
277 '((t (:bold t :italic t :underline t)))
278 "Face used for displaying underlined bold italic emphasized text.
279 Esample: (_/*word*/_)."
280 :group 'gnus-article-emphasis)
282 (defface gnus-emphasis-highlight-words
283 '((t (:background "black" :foreground "yellow")))
284 "Face used for displaying highlighted words."
285 :group 'gnus-article-emphasis)
287 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
288 "Format for display of Date headers in article bodies.
289 See `format-time-string' for the possible values.
291 The variable can also be function, which should return a complete Date
292 header. The function is called with one argument, the time, which can
293 be fed to `format-time-string'."
294 :type '(choice string symbol)
295 :link '(custom-manual "(gnus)Article Date")
296 :group 'gnus-article-washing)
299 (autoload 'mail-extract-address-components "mail-extr"))
301 (defcustom gnus-save-all-headers t
302 "*If non-nil, don't remove any headers before saving."
303 :group 'gnus-article-saving
306 (defcustom gnus-prompt-before-saving 'always
307 "*This variable says how much prompting is to be done when saving articles.
308 If it is nil, no prompting will be done, and the articles will be
309 saved to the default files. If this variable is `always', each and
310 every article that is saved will be preceded by a prompt, even when
311 saving large batches of articles. If this variable is neither nil not
312 `always', there the user will be prompted once for a file name for
313 each invocation of the saving commands."
314 :group 'gnus-article-saving
315 :type '(choice (item always)
316 (item :tag "never" nil)
317 (sexp :tag "once" :format "%t\n" :value t)))
319 (defcustom gnus-saved-headers gnus-visible-headers
320 "Headers to keep if `gnus-save-all-headers' is nil.
321 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
322 If that variable is nil, however, all headers that match this regexp
323 will be kept while the rest will be deleted before saving."
324 :group 'gnus-article-saving
327 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
328 "A function to save articles in your favourite format.
329 The function must be interactively callable (in other words, it must
330 be an Emacs command).
332 Gnus provides the following functions:
334 * gnus-summary-save-in-rmail (Rmail format)
335 * gnus-summary-save-in-mail (Unix mail format)
336 * gnus-summary-save-in-folder (MH folder)
337 * gnus-summary-save-in-file (article format)
338 * gnus-summary-save-in-vm (use VM's folder format)
339 * gnus-summary-write-to-file (article format -- overwrite)."
340 :group 'gnus-article-saving
341 :type '(radio (function-item gnus-summary-save-in-rmail)
342 (function-item gnus-summary-save-in-mail)
343 (function-item gnus-summary-save-in-folder)
344 (function-item gnus-summary-save-in-file)
345 (function-item gnus-summary-save-in-vm)
346 (function-item gnus-summary-write-to-file)))
348 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
349 "A function generating a file name to save articles in Rmail format.
350 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
351 :group 'gnus-article-saving
354 (defcustom gnus-mail-save-name 'gnus-plain-save-name
355 "A function generating a file name to save articles in Unix mail format.
356 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
357 :group 'gnus-article-saving
360 (defcustom gnus-folder-save-name 'gnus-folder-save-name
361 "A function generating a file name to save articles in MH folder.
362 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
363 :group 'gnus-article-saving
366 (defcustom gnus-file-save-name 'gnus-numeric-save-name
367 "A function generating a file name to save articles in article format.
368 The function is called with NEWSGROUP, HEADERS, and optional
370 :group 'gnus-article-saving
373 (defcustom gnus-split-methods
374 '((gnus-article-archive-name)
375 (gnus-article-nndoc-name))
376 "*Variable used to suggest where articles are to be saved.
377 For instance, if you would like to save articles related to Gnus in
378 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
379 you could set this variable to something like:
381 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
382 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
384 This variable is an alist where the where the key is the match and the
385 value is a list of possible files to save in if the match is non-nil.
387 If the match is a string, it is used as a regexp match on the
388 article. If the match is a symbol, that symbol will be funcalled
389 from the buffer of the article to be saved with the newsgroup as the
390 parameter. If it is a list, it will be evaled in the same buffer.
392 If this form or function returns a string, this string will be used as
393 a possible file name; and if it returns a non-nil list, that list will
394 be used as possible file names."
395 :group 'gnus-article-saving
396 :type '(repeat (choice (list :value (fun) function)
397 (cons :value ("" "") regexp (repeat string))
400 (defcustom gnus-page-delimiter "^\^L"
401 "*Regexp describing what to use as article page delimiters.
402 The default value is \"^\^L\", which is a form linefeed at the
403 beginning of a line."
405 :group 'gnus-article-various)
407 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
408 "*The format specification for the article mode line.
409 See `gnus-summary-mode-line-format' for a closer description.
411 The following additional specs are available:
413 %w The article washing status.
414 %m The number of MIME parts in the article."
416 :group 'gnus-article-various)
418 (defcustom gnus-article-mode-hook nil
419 "*A hook for Gnus article mode."
421 :group 'gnus-article-various)
423 (defcustom gnus-article-menu-hook nil
424 "*Hook run after the creation of the article mode menu."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-prepare-hook nil
429 "*A hook called after an article has been prepared in the article buffer."
431 :group 'gnus-article-various)
433 (defcustom gnus-article-hide-pgp-hook nil
434 "*A hook called after successfully hiding a PGP signature."
436 :group 'gnus-article-various)
438 (defcustom gnus-article-button-face 'bold
439 "Face used for highlighting buttons in the article buffer.
441 An article button is a piece of text that you can activate by pressing
442 `RET' or `mouse-2' above it."
444 :group 'gnus-article-buttons)
446 (defcustom gnus-article-mouse-face 'highlight
447 "Face used for mouse highlighting in the article buffer.
449 Article buttons will be displayed in this face when the cursor is
452 :group 'gnus-article-buttons)
454 (defcustom gnus-signature-face 'gnus-signature-face
455 "Face used for highlighting a signature in the article buffer.
456 Obsolete; use the face `gnus-signature-face' for customizations instead."
458 :group 'gnus-article-highlight
459 :group 'gnus-article-signature)
461 (defface gnus-signature-face
464 "Face used for highlighting a signature in the article buffer."
465 :group 'gnus-article-highlight
466 :group 'gnus-article-signature)
468 (defface gnus-header-from-face
471 (:foreground "spring green"))
474 (:foreground "red3"))
477 "Face used for displaying from headers."
478 :group 'gnus-article-headers
479 :group 'gnus-article-highlight)
481 (defface gnus-header-subject-face
484 (:foreground "SeaGreen3"))
487 (:foreground "red4"))
489 (:bold t :italic t)))
490 "Face used for displaying subject headers."
491 :group 'gnus-article-headers
492 :group 'gnus-article-highlight)
494 (defface gnus-header-newsgroups-face
497 (:foreground "yellow" :italic t))
500 (:foreground "MidnightBlue" :italic t))
503 "Face used for displaying newsgroups headers."
504 :group 'gnus-article-headers
505 :group 'gnus-article-highlight)
507 (defface gnus-header-name-face
510 (:foreground "SeaGreen"))
513 (:foreground "maroon"))
516 "Face used for displaying header names."
517 :group 'gnus-article-headers
518 :group 'gnus-article-highlight)
520 (defface gnus-header-content-face
523 (:foreground "forest green" :italic t))
526 (:foreground "indianred4" :italic t))
528 (:italic t))) "Face used for displaying header content."
529 :group 'gnus-article-headers
530 :group 'gnus-article-highlight)
532 (defcustom gnus-header-face-alist
533 '(("From" nil gnus-header-from-face)
534 ("Subject" nil gnus-header-subject-face)
535 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
536 ("" gnus-header-name-face gnus-header-content-face))
537 "*Controls highlighting of article header.
539 An alist of the form (HEADER NAME CONTENT).
541 HEADER is a regular expression which should match the name of an
542 header header and NAME and CONTENT are either face names or nil.
544 The name of each header field will be displayed using the face
545 specified by the first element in the list where HEADER match the
546 header name and NAME is non-nil. Similarly, the content will be
547 displayed by the first non-nil matching CONTENT face."
548 :group 'gnus-article-headers
549 :group 'gnus-article-highlight
550 :type '(repeat (list (regexp :tag "Header")
552 (item :tag "skip" nil)
553 (face :value default))
554 (choice :tag "Content"
555 (item :tag "skip" nil)
556 (face :value default)))))
558 (defcustom gnus-article-decode-hook
559 '(article-decode-charset article-decode-encoded-words)
560 "*Hook run to decode charsets in articles."
561 :group 'gnus-article-headers
564 (defcustom gnus-display-mime-function 'gnus-display-mime
565 "Function to display MIME articles."
566 :group 'gnus-article-mime
569 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
570 "Function used to decode headers.")
572 (defvar gnus-article-dumbquotes-map
590 "Table for MS-to-Latin1 translation.")
592 (defcustom gnus-ignored-mime-types nil
593 "List of MIME types that should be ignored by Gnus."
594 :group 'gnus-article-mime
595 :type '(repeat regexp))
597 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
598 "List of MIME types that should not be given buttons when rendered inline."
599 :group 'gnus-article-mime
600 :type '(repeat regexp))
602 (defcustom gnus-article-mime-part-function nil
603 "Function called with a MIME handle as the argument.
604 This is meant for people who want to do something automatic based
605 on parts -- for instance, adding Vcard info to a database."
606 :group 'gnus-article-mime
609 (defcustom gnus-mime-multipart-functions nil
610 "An alist of MIME types to functions to display them.")
612 (defcustom gnus-article-date-lapsed-new-header nil
613 "Whether the X-Sent and Date headers can coexist.
614 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
615 either replace the old \"Date:\" header (if this variable is nil), or
616 be added below it (otherwise)."
617 :group 'gnus-article-headers
620 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
621 "Function called with a MIME handle as the argument.
622 This is meant for people who want to view first matched part.
623 For `undisplayed-alternative' (default), the first undisplayed
624 part or alternative part is used. For `undisplayed', the first
625 undisplayed part is used. For a function, the first part which
626 the function return `t' is used. For `nil', the first part is
628 :group 'gnus-article-mime
630 (item :tag "first" :value nil)
631 (item :tag "undisplayed" :value undisplayed)
632 (item :tag "undisplayed or alternative"
633 :value undisplayed-alternative)
637 ;;; The treatment variables
640 (defvar gnus-part-display-hook nil
641 "Hook called on parts that are to receive treatment.")
643 (defvar gnus-article-treat-custom
644 '(choice (const :tag "Off" nil)
646 (const :tag "Header" head)
647 (const :tag "Last" last)
648 (integer :tag "Less")
649 (repeat :tag "Groups" regexp)
650 (sexp :tag "Predicate")))
652 (defvar gnus-article-treat-head-custom
653 '(choice (const :tag "Off" nil)
654 (const :tag "Header" head)))
656 (defvar gnus-article-treat-types '("text/plain")
659 (defvar gnus-inhibit-treatment nil
660 "Whether to inhibit treatment.")
662 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
663 "Highlight the signature.
664 Valid values are nil, t, `head', `last', an integer or a predicate.
665 See the manual for details."
666 :group 'gnus-article-treat
667 :type gnus-article-treat-custom)
668 (put 'gnus-treat-highlight-signature 'highlight t)
670 (defcustom gnus-treat-buttonize 100000
672 Valid values are nil, t, `head', `last', an integer or a predicate.
673 See the manual for details."
674 :group 'gnus-article-treat
675 :type gnus-article-treat-custom)
676 (put 'gnus-treat-buttonize 'highlight t)
678 (defcustom gnus-treat-buttonize-head 'head
679 "Add buttons to the head.
680 Valid values are nil, t, `head', `last', an integer or a predicate.
681 See the manual for details."
682 :group 'gnus-article-treat
683 :type gnus-article-treat-head-custom)
684 (put 'gnus-treat-buttonize-head 'highlight t)
686 (defcustom gnus-treat-emphasize 50000
688 Valid values are nil, t, `head', `last', an integer or a predicate.
689 See the manual for details."
690 :group 'gnus-article-treat
691 :type gnus-article-treat-custom)
692 (put 'gnus-treat-emphasize 'highlight t)
694 (defcustom gnus-treat-strip-cr nil
695 "Remove carriage returns.
696 Valid values are nil, t, `head', `last', an integer or a predicate.
697 See the manual for details."
698 :group 'gnus-article-treat
699 :type gnus-article-treat-custom)
701 (defcustom gnus-treat-hide-headers 'head
703 Valid values are nil, t, `head', `last', an integer or a predicate.
704 See the manual for details."
705 :group 'gnus-article-treat
706 :type gnus-article-treat-head-custom)
708 (defcustom gnus-treat-hide-boring-headers nil
709 "Hide boring headers.
710 Valid values are nil, t, `head', `last', an integer or a predicate.
711 See the manual for details."
712 :group 'gnus-article-treat
713 :type gnus-article-treat-head-custom)
715 (defcustom gnus-treat-hide-signature nil
717 Valid values are nil, t, `head', `last', an integer or a predicate.
718 See the manual for details."
719 :group 'gnus-article-treat
720 :type gnus-article-treat-custom)
722 (defcustom gnus-treat-fill-article nil
724 Valid values are nil, t, `head', `last', an integer or a predicate.
725 See the manual for details."
726 :group 'gnus-article-treat
727 :type gnus-article-treat-custom)
729 (defcustom gnus-treat-hide-citation nil
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733 :group 'gnus-article-treat
734 :type gnus-article-treat-custom)
736 (defcustom gnus-treat-strip-list-identifiers 'head
737 "Strip list identifiers from `gnus-list-identifiers`.
738 Valid values are nil, t, `head', `last', an integer or a predicate.
739 See the manual for details."
740 :group 'gnus-article-treat
741 :type gnus-article-treat-custom)
743 (defcustom gnus-treat-strip-pgp t
744 "Strip PGP signatures.
745 Valid values are nil, t, `head', `last', an integer or a predicate.
746 See the manual for details."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-custom)
750 (defcustom gnus-treat-strip-pem nil
751 "Strip PEM signatures.
752 Valid values are nil, t, `head', `last', an integer or a predicate.
753 See the manual for details."
754 :group 'gnus-article-treat
755 :type gnus-article-treat-custom)
757 (defcustom gnus-treat-strip-banner t
758 "Strip banners from articles.
759 The banner to be stripped is specified in the `banner' group parameter.
760 Valid values are nil, t, `head', `last', an integer or a predicate.
761 See the manual for details."
762 :group 'gnus-article-treat
763 :type gnus-article-treat-custom)
765 (defcustom gnus-treat-highlight-headers 'head
766 "Highlight the headers.
767 Valid values are nil, t, `head', `last', an integer or a predicate.
768 See the manual for details."
769 :group 'gnus-article-treat
770 :type gnus-article-treat-head-custom)
771 (put 'gnus-treat-highlight-headers 'highlight t)
773 (defcustom gnus-treat-highlight-citation t
774 "Highlight cited text.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-custom)
779 (put 'gnus-treat-highlight-citation 'highlight t)
781 (defcustom gnus-treat-date-ut nil
782 "Display the Date in UT (GMT).
783 Valid values are nil, t, `head', `last', an integer or a predicate.
784 See the manual for details."
785 :group 'gnus-article-treat
786 :type gnus-article-treat-head-custom)
788 (defcustom gnus-treat-date-local nil
789 "Display the Date in the local timezone.
790 Valid values are nil, t, `head', `last', an integer or a predicate.
791 See the manual for details."
792 :group 'gnus-article-treat
793 :type gnus-article-treat-head-custom)
795 (defcustom gnus-treat-date-lapsed nil
796 "Display the Date header in a way that says how much time has elapsed.
797 Valid values are nil, t, `head', `last', an integer or a predicate.
798 See the manual for details."
799 :group 'gnus-article-treat
800 :type gnus-article-treat-head-custom)
802 (defcustom gnus-treat-date-original nil
803 "Display the date in the original timezone.
804 Valid values are nil, t, `head', `last', an integer or a predicate.
805 See the manual for details."
806 :group 'gnus-article-treat
807 :type gnus-article-treat-head-custom)
809 (defcustom gnus-treat-date-iso8601 nil
810 "Display the date in the ISO8601 format.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-head-custom)
816 (defcustom gnus-treat-date-user-defined nil
817 "Display the date in a user-defined format.
818 The format is defined by the `gnus-article-time-format' variable.
819 Valid values are nil, t, `head', `last', an integer or a predicate.
820 See the manual for details."
821 :group 'gnus-article-treat
822 :type gnus-article-treat-head-custom)
824 (defcustom gnus-treat-strip-headers-in-body t
825 "Strip the X-No-Archive header line from the beginning of the body.
826 Valid values are nil, t, `head', `last', an integer or a predicate.
827 See the manual for details."
828 :group 'gnus-article-treat
829 :type gnus-article-treat-custom)
831 (defcustom gnus-treat-strip-trailing-blank-lines nil
832 "Strip trailing blank lines.
833 Valid values are nil, t, `head', `last', an integer or a predicate.
834 See the manual for details."
835 :group 'gnus-article-treat
836 :type gnus-article-treat-custom)
838 (defcustom gnus-treat-strip-leading-blank-lines nil
839 "Strip leading blank lines.
840 Valid values are nil, t, `head', `last', an integer or a predicate.
841 See the manual for details."
842 :group 'gnus-article-treat
843 :type gnus-article-treat-custom)
845 (defcustom gnus-treat-strip-multiple-blank-lines nil
846 "Strip multiple blank lines.
847 Valid values are nil, t, `head', `last', an integer or a predicate.
848 See the manual for details."
849 :group 'gnus-article-treat
850 :type gnus-article-treat-custom)
852 (defcustom gnus-treat-overstrike t
853 "Treat overstrike highlighting.
854 Valid values are nil, t, `head', `last', an integer or a predicate.
855 See the manual for details."
856 :group 'gnus-article-treat
857 :type gnus-article-treat-custom)
858 (put 'gnus-treat-overstrike 'highlight t)
860 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
862 "Display X-Face headers.
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See the manual for details."
865 :group 'gnus-article-treat
866 :type gnus-article-treat-head-custom)
867 (put 'gnus-treat-display-xface 'highlight t)
869 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
873 Valid values are nil, t, `head', `last', an integer or a predicate.
874 See the manual for details."
875 :group 'gnus-article-treat
876 :type gnus-article-treat-custom)
877 (put 'gnus-treat-display-smileys 'highlight t)
879 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
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-head-custom)
885 (put 'gnus-treat-display-picons 'highlight t)
887 (defcustom gnus-treat-capitalize-sentences nil
888 "Capitalize sentence-starting words.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-custom)
894 (defcustom gnus-treat-fill-long-lines nil
896 Valid values are nil, t, `head', `last', an integer or a predicate.
897 See the manual for details."
898 :group 'gnus-article-treat
899 :type gnus-article-treat-custom)
901 (defcustom gnus-treat-play-sounds nil
903 Valid values are nil, t, `head', `last', an integer or a predicate.
904 See the manual for details."
905 :group 'gnus-article-treat
906 :type gnus-article-treat-custom)
908 (defcustom gnus-treat-translate nil
909 "Translate articles from one language to another.
910 Valid values are nil, t, `head', `last', an integer or a predicate.
911 See the manual for details."
912 :group 'gnus-article-treat
913 :type gnus-article-treat-custom)
915 ;;; Internal variables
917 (defvar article-goto-body-goes-to-point-min-p nil)
918 (defvar gnus-article-wash-types nil)
919 (defvar gnus-article-emphasis-alist nil)
921 (defvar gnus-article-mime-handle-alist-1 nil)
922 (defvar gnus-treatment-function-alist
923 '((gnus-treat-strip-banner gnus-article-strip-banner)
924 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
925 (gnus-treat-highlight-signature gnus-article-highlight-signature)
926 (gnus-treat-buttonize gnus-article-add-buttons)
927 (gnus-treat-fill-article gnus-article-fill-cited-article)
928 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
929 (gnus-treat-strip-cr gnus-article-remove-cr)
930 (gnus-treat-emphasize gnus-article-emphasize)
931 (gnus-treat-display-xface gnus-article-display-x-face)
932 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
933 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
934 (gnus-treat-hide-signature gnus-article-hide-signature)
935 (gnus-treat-hide-citation gnus-article-hide-citation)
936 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
937 (gnus-treat-strip-pgp gnus-article-hide-pgp)
938 (gnus-treat-strip-pem gnus-article-hide-pem)
939 (gnus-treat-highlight-headers gnus-article-highlight-headers)
940 (gnus-treat-highlight-citation gnus-article-highlight-citation)
941 (gnus-treat-highlight-signature gnus-article-highlight-signature)
942 (gnus-treat-date-ut gnus-article-date-ut)
943 (gnus-treat-date-local gnus-article-date-local)
944 (gnus-treat-date-lapsed gnus-article-date-lapsed)
945 (gnus-treat-date-original gnus-article-date-original)
946 (gnus-treat-date-user-defined gnus-article-date-user)
947 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
948 (gnus-treat-strip-trailing-blank-lines
949 gnus-article-remove-trailing-blank-lines)
950 (gnus-treat-strip-leading-blank-lines
951 gnus-article-strip-leading-blank-lines)
952 (gnus-treat-strip-multiple-blank-lines
953 gnus-article-strip-multiple-blank-lines)
954 (gnus-treat-overstrike gnus-article-treat-overstrike)
955 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
956 (gnus-treat-display-smileys gnus-smiley-display)
957 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
958 (gnus-treat-display-picons gnus-article-display-picons)
959 (gnus-treat-play-sounds gnus-earcon-display)))
961 (defvar gnus-article-mime-handle-alist nil)
962 (defvar article-lapsed-timer nil)
963 (defvar gnus-article-current-summary nil)
965 (defvar gnus-article-mode-syntax-table
966 (let ((table (copy-syntax-table text-mode-syntax-table)))
967 (modify-syntax-entry ?- "w" table)
968 (modify-syntax-entry ?> ")" table)
969 (modify-syntax-entry ?< "(" table)
971 "Syntax table used in article mode buffers.
972 Initialized from `text-mode-syntax-table.")
974 (defvar gnus-save-article-buffer nil)
976 (defvar gnus-article-mode-line-format-alist
977 (nconc '((?w (gnus-article-wash-status) ?s)
978 (?m (gnus-article-mime-part-status) ?s))
979 gnus-summary-mode-line-format-alist))
981 (defvar gnus-number-of-articles-to-be-saved nil)
983 (defvar gnus-inhibit-hiding nil)
985 (defsubst gnus-article-hide-text (b e props)
986 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
987 (add-text-properties b e props)
988 (when (memq 'intangible props)
990 (max (1- b) (point-min))
991 b 'intangible (cddr (memq 'intangible props)))))
992 (defsubst gnus-article-unhide-text (b e)
993 "Remove hidden text properties from region between B and E."
994 (remove-text-properties b e gnus-hidden-properties)
995 (when (memq 'intangible gnus-hidden-properties)
996 (put-text-property (max (1- b) (point-min))
999 (defun gnus-article-hide-text-type (b e type)
1000 "Hide text of TYPE between B and E."
1001 (push type gnus-article-wash-types)
1002 (gnus-article-hide-text
1003 b e (cons 'article-type (cons type gnus-hidden-properties))))
1005 (defun gnus-article-unhide-text-type (b e type)
1006 "Unhide text of TYPE between B and E."
1007 (setq gnus-article-wash-types
1008 (delq type gnus-article-wash-types))
1009 (remove-text-properties
1010 b e (cons 'article-type (cons type gnus-hidden-properties)))
1011 (when (memq 'intangible gnus-hidden-properties)
1012 (put-text-property (max (1- b) (point-min))
1013 b 'intangible nil)))
1015 (defun gnus-article-hide-text-of-type (type)
1016 "Hide text of TYPE in the current buffer."
1018 (let ((b (point-min))
1020 (while (setq b (text-property-any b e 'article-type type))
1021 (add-text-properties b (incf b) gnus-hidden-properties)))))
1023 (defun gnus-article-delete-text-of-type (type)
1024 "Delete text of TYPE in the current buffer."
1026 (let ((b (point-min)))
1027 (while (setq b (text-property-any b (point-max) 'article-type type))
1029 b (or (text-property-not-all b (point-max) 'article-type type)
1032 (defun gnus-article-delete-invisible-text ()
1033 "Delete all invisible text in the current buffer."
1035 (let ((b (point-min)))
1036 (while (setq b (text-property-any b (point-max) 'invisible t))
1038 b (or (text-property-not-all b (point-max) 'invisible t)
1041 (defun gnus-article-text-type-exists-p (type)
1042 "Say whether any text of type TYPE exists in the buffer."
1043 (text-property-any (point-min) (point-max) 'article-type type))
1045 (defsubst gnus-article-header-rank ()
1046 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1047 (let ((list gnus-sorted-header-list)
1050 (when (looking-at (car list))
1052 (setq list (cdr list))
1056 (defun article-hide-headers (&optional arg delete)
1057 "Hide unwanted headers and possibly sort them as well."
1059 ;; This function might be inhibited.
1060 (unless gnus-inhibit-hiding
1063 (let ((buffer-read-only nil)
1064 (case-fold-search t)
1065 (max (1+ (length gnus-sorted-header-list)))
1066 (ignored (when (not gnus-visible-headers)
1067 (cond ((stringp gnus-ignored-headers)
1068 gnus-ignored-headers)
1069 ((listp gnus-ignored-headers)
1070 (mapconcat 'identity gnus-ignored-headers
1073 (cond ((stringp gnus-visible-headers)
1074 gnus-visible-headers)
1075 ((and gnus-visible-headers
1076 (listp gnus-visible-headers))
1077 (mapconcat 'identity gnus-visible-headers "\\|"))))
1078 (inhibit-point-motion-hooks t)
1080 ;; First we narrow to just the headers.
1081 (article-narrow-to-head)
1082 ;; Hide any "From " lines at the beginning of (mail) articles.
1083 (while (looking-at "From ")
1086 (delete-region (point-min) (point)))
1087 ;; Then treat the rest of the header lines.
1088 ;; Then we use the two regular expressions
1089 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1090 ;; select which header lines is to remain visible in the
1092 (while (re-search-forward "^[^ \t]*:" nil t)
1094 ;; Mark the rank of the header.
1096 (point) (1+ (point)) 'message-rank
1097 (if (or (and visible (looking-at visible))
1099 (not (looking-at ignored))))
1100 (gnus-article-header-rank)
1103 (message-sort-headers-1)
1104 (when (setq beg (text-property-any
1105 (point-min) (point-max) 'message-rank (+ 2 max)))
1106 ;; We delete the unwanted headers.
1107 (push 'headers gnus-article-wash-types)
1108 (add-text-properties (point-min) (+ 5 (point-min))
1109 '(article-type headers dummy-invisible t))
1110 (delete-region beg (point-max))))))))
1112 (defun article-hide-boring-headers (&optional arg)
1113 "Toggle hiding of headers that aren't very interesting.
1114 If given a negative prefix, always show; if given a positive prefix,
1116 (interactive (gnus-article-hidden-arg))
1117 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1118 (not gnus-show-all-headers))
1121 (let ((buffer-read-only nil)
1122 (list gnus-boring-article-headers)
1123 (inhibit-point-motion-hooks t)
1125 (article-narrow-to-head)
1127 (setq elem (pop list))
1128 (goto-char (point-min))
1130 ;; Hide empty headers.
1132 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1134 (gnus-article-hide-text-type
1135 (progn (beginning-of-line) (point))
1138 (if (re-search-forward "^[^ \t]" nil t)
1142 ;; Hide boring Newsgroups header.
1143 ((eq elem 'newsgroups)
1144 (when (equal (gnus-fetch-field "newsgroups")
1145 (gnus-group-real-name
1146 (if (boundp 'gnus-newsgroup-name)
1149 (gnus-article-hide-header "newsgroups")))
1150 ((eq elem 'followup-to)
1151 (when (equal (message-fetch-field "followup-to")
1152 (message-fetch-field "newsgroups"))
1153 (gnus-article-hide-header "followup-to")))
1154 ((eq elem 'reply-to)
1155 (let ((from (message-fetch-field "from"))
1156 (reply-to (message-fetch-field "reply-to")))
1161 (nth 1 (mail-extract-address-components from))
1162 (nth 1 (mail-extract-address-components reply-to)))))
1163 (gnus-article-hide-header "reply-to"))))
1165 (let ((date (message-fetch-field "date")))
1167 (< (days-between (current-time-string) date)
1169 (gnus-article-hide-header "date"))))
1171 (let ((to (message-fetch-field "to")))
1172 (when (> (length to) 1024)
1173 (gnus-article-hide-header "to"))))
1176 (goto-char (point-min))
1177 (while (re-search-forward "^to:" nil t)
1178 (setq to-count (1+ to-count)))
1179 (when (> to-count 1)
1180 (while (> to-count 0)
1181 (goto-char (point-min))
1183 (re-search-forward "^to:" nil nil to-count)
1185 (narrow-to-region (point) (point-max))
1186 (gnus-article-hide-header "to"))
1187 (setq to-count (1- to-count)))))))))))))
1189 (defun gnus-article-hide-header (header)
1191 (goto-char (point-min))
1192 (when (re-search-forward (concat "^" header ":") nil t)
1193 (gnus-article-hide-text-type
1194 (progn (beginning-of-line) (point))
1197 (if (re-search-forward "^[^ \t]" nil t)
1202 (defvar gnus-article-normalized-header-length 40
1203 "Length of normalized headers.")
1205 (defun article-normalize-headers ()
1206 "Make all header lines 40 characters long."
1208 (let ((buffer-read-only nil)
1212 (article-narrow-to-head)
1215 ((< (setq column (- (gnus-point-at-eol) (point)))
1216 gnus-article-normalized-header-length)
1218 (insert (make-string
1219 (- gnus-article-normalized-header-length column)
1221 ((> column gnus-article-normalized-header-length)
1222 (gnus-put-text-property
1224 (forward-char gnus-article-normalized-header-length)
1231 (forward-line 1))))))
1233 (defun article-treat-dumbquotes ()
1234 "Translate M******** sm*rtq**t*s into proper text.
1235 Note that this function guesses whether a character is a sm*rtq**t* or
1236 not, so it should only be used interactively."
1238 (article-translate-strings gnus-article-dumbquotes-map))
1240 (defun article-translate-characters (from to)
1241 "Translate all characters in the body of the article according to FROM and TO.
1242 FROM is a string of characters to translate from; to is a string of
1243 characters to translate to."
1245 (when (article-goto-body)
1246 (let ((buffer-read-only nil)
1247 (x (make-string 225 ?x))
1249 (while (< (incf i) (length x))
1252 (while (< i (length from))
1253 (aset x (aref from i) (aref to i))
1255 (translate-region (point) (point-max) x)))))
1257 (defun article-translate-strings (map)
1258 "Translate all string in the body of the article according to MAP.
1259 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1261 (when (article-goto-body)
1262 (let ((buffer-read-only nil)
1264 (while (setq elem (pop map))
1266 (while (search-forward (car elem) nil t)
1267 (replace-match (cadr elem)))))))))
1269 (defun article-treat-overstrike ()
1270 "Translate overstrikes into bold text."
1273 (when (article-goto-body)
1274 (let ((buffer-read-only nil))
1275 (while (search-forward "\b" nil t)
1276 (let ((next (char-after))
1277 (previous (char-after (- (point) 2))))
1278 ;; We do the boldification/underlining by hiding the
1279 ;; overstrikes and putting the proper text property
1283 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1284 (put-text-property (point) (1+ (point)) 'face 'bold))
1286 (gnus-article-hide-text-type
1287 (1- (point)) (1+ (point)) 'overstrike)
1289 (- (point) 2) (1- (point)) 'face 'underline))
1291 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1293 (point) (1+ (point)) 'face 'underline)))))))))
1295 (defun article-fill-long-lines ()
1296 "Fill lines that are wider than the window width."
1299 (let ((buffer-read-only nil)
1300 (width (window-width (get-buffer-window (current-buffer)))))
1303 (let ((adaptive-fill-mode nil))
1306 (when (>= (current-column) (min fill-column width))
1307 (narrow-to-region (point) (gnus-point-at-bol))
1308 (fill-paragraph nil)
1309 (goto-char (point-max))
1311 (forward-line 1)))))))
1313 (defun article-capitalize-sentences ()
1314 "Capitalize the first word in each sentence."
1317 (let ((buffer-read-only nil)
1318 (paragraph-start "^[\n\^L]"))
1322 (forward-sentence)))))
1324 (defun article-remove-cr ()
1325 "Remove trailing CRs and then translate remaining CRs into LFs."
1328 (let ((buffer-read-only nil))
1329 (goto-char (point-min))
1330 (while (re-search-forward "\r+$" nil t)
1331 (replace-match "" t t))
1332 (goto-char (point-min))
1333 (while (search-forward "\r" nil t)
1334 (replace-match "\n" t t)))))
1336 (defun article-remove-trailing-blank-lines ()
1337 "Remove all trailing blank lines from the article."
1340 (let ((buffer-read-only nil))
1341 (goto-char (point-max))
1345 (while (and (not (bobp))
1346 (looking-at "^[ \t]*$")
1347 (not (gnus-annotation-in-region-p
1348 (point) (gnus-point-at-eol))))
1353 (defun article-display-x-face (&optional force)
1354 "Look for an X-Face header and display it if present."
1355 (interactive (list 'force))
1357 ;; Delete the old process, if any.
1358 (when (process-status "article-x-face")
1359 (delete-process "article-x-face"))
1360 (let ((inhibit-point-motion-hooks t)
1361 (case-fold-search t)
1364 (article-narrow-to-head)
1365 (goto-char (point-min))
1366 (setq from (message-fetch-field "from"))
1367 (goto-char (point-min))
1368 (while (and gnus-article-x-face-command
1371 ;; Check whether this face is censored.
1372 (not gnus-article-x-face-too-ugly)
1373 (and gnus-article-x-face-too-ugly from
1374 (not (string-match gnus-article-x-face-too-ugly
1376 ;; Has to be present.
1377 (re-search-forward "^X-Face: " nil t))
1378 ;; This used to try to do multiple faces (`while' instead of
1379 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1380 ;; work (b) it can crash some versions of Emacs (c) are
1381 ;; multiple faces really something to encourage?
1382 (when (stringp gnus-article-x-face-command)
1384 ;; We now have the area of the buffer where the X-Face is stored.
1387 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1388 ;; We display the face.
1389 (if (symbolp gnus-article-x-face-command)
1390 ;; The command is a lisp function, so we call it.
1391 (if (gnus-functionp gnus-article-x-face-command)
1392 (funcall gnus-article-x-face-command beg end)
1393 (error "%s is not a function" gnus-article-x-face-command))
1394 ;; The command is a string, so we interpret the command
1395 ;; as a, well, command, and fork it off.
1396 (let ((process-connection-type nil))
1397 (process-kill-without-query
1399 "article-x-face" nil shell-file-name shell-command-switch
1400 gnus-article-x-face-command))
1401 (process-send-region "article-x-face" beg end)
1402 (process-send-eof "article-x-face"))))))))))
1404 (defun article-decode-mime-words ()
1405 "Decode all MIME-encoded words in the article."
1408 (set-buffer gnus-article-buffer)
1409 (let ((inhibit-point-motion-hooks t)
1411 (mail-parse-charset gnus-newsgroup-charset)
1412 (mail-parse-ignored-charsets
1413 (save-excursion (set-buffer gnus-summary-buffer)
1414 gnus-newsgroup-ignored-charsets)))
1415 (mail-decode-encoded-word-region (point-min) (point-max)))))
1417 (defun article-decode-charset (&optional prompt)
1418 "Decode charset-encoded text in the article.
1419 If PROMPT (the prefix), prompt for a coding system to use."
1421 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1423 (mail-parse-charset gnus-newsgroup-charset)
1424 (mail-parse-ignored-charsets
1425 (save-excursion (condition-case nil
1426 (set-buffer gnus-summary-buffer)
1428 gnus-newsgroup-ignored-charsets))
1432 (article-narrow-to-head)
1433 (setq ct (message-fetch-field "Content-Type" t)
1434 cte (message-fetch-field "Content-Transfer-Encoding" t)
1435 ctl (and ct (ignore-errors
1436 (mail-header-parse-content-type ct)))
1439 (mm-read-coding-system "Charset to decode: "))
1441 (mail-content-type-get ctl 'charset))))
1443 (setq cte (mail-header-strip cte)))
1444 (if (and ctl (not (string-match "/" (car ctl))))
1446 (goto-char (point-max)))
1449 (narrow-to-region (point) (point-max))
1450 (when (and (or (not ctl)
1451 (equal (car ctl) "text/plain")))
1453 charset (and cte (intern (downcase
1454 (gnus-strip-whitespace cte))))
1457 (defun article-decode-encoded-words ()
1458 "Remove encoded-word encoding from headers."
1459 (let ((inhibit-point-motion-hooks t)
1460 (mail-parse-charset gnus-newsgroup-charset)
1461 (mail-parse-ignored-charsets
1462 (save-excursion (condition-case nil
1463 (set-buffer gnus-summary-buffer)
1465 gnus-newsgroup-ignored-charsets))
1468 (article-narrow-to-head)
1469 (funcall gnus-decode-header-function (point-min) (point-max)))))
1471 (defun article-de-quoted-unreadable (&optional force)
1472 "Translate a quoted-printable-encoded article.
1473 If FORCE, decode the article whether it is marked as quoted-printable
1475 (interactive (list 'force))
1477 (let ((buffer-read-only nil)
1478 (type (gnus-fetch-field "content-transfer-encoding"))
1479 (charset gnus-newsgroup-charset))
1481 (and type (string-match "quoted-printable" (downcase type))))
1483 (quoted-printable-decode-region (point) (point-max) charset)))))
1488 (defun article-decode-HZ ()
1489 "Translate a HZ-encoded article."
1493 (let ((buffer-read-only nil))
1494 (rfc1843-decode-region (point-min) (point-max)))))
1496 (defun article-hide-list-identifiers ()
1497 "Remove list identifies from the Subject header.
1498 The `gnus-list-identifiers' variable specifies what to do."
1502 (let ((inhibit-point-motion-hooks t)
1504 (article-narrow-to-head)
1505 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1506 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1508 (goto-char (point-min))
1509 (when (re-search-forward
1510 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1512 (delete-region (match-beginning 2) (match-end 0)))))))))
1514 (defun article-hide-pgp ()
1515 "Remove any PGP headers and signatures in the current article."
1519 (let ((inhibit-point-motion-hooks t)
1520 buffer-read-only beg end)
1522 ;; Hide the "header".
1523 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1524 (push 'pgp gnus-article-wash-types)
1525 (delete-region (match-beginning 0) (match-end 0))
1526 ;; Remove armor headers (rfc2440 6.2)
1527 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1530 ;; Hide the actual signature.
1531 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1532 (setq end (1+ (match-beginning 0)))
1535 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1537 ;; Perhaps we shouldn't hide to the end of the buffer
1538 ;; if there is no end to the signature?
1540 ;; Hide "- " PGP quotation markers.
1542 (narrow-to-region beg end)
1543 (goto-char (point-min))
1544 (while (re-search-forward "^- " nil t)
1546 (match-beginning 0) (match-end 0)))
1548 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1550 (defun article-hide-pem (&optional arg)
1551 "Toggle hiding of any PEM headers and signatures in the current article.
1552 If given a negative prefix, always show; if given a positive prefix,
1554 (interactive (gnus-article-hidden-arg))
1555 (unless (gnus-article-check-hidden-text 'pem arg)
1557 (let (buffer-read-only end)
1558 (goto-char (point-min))
1559 ;; Hide the horrendously ugly "header".
1560 (when (and (search-forward
1561 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1563 (setq end (1+ (match-beginning 0))))
1564 (push 'pem gnus-article-wash-types)
1565 (gnus-article-hide-text-type
1567 (if (search-forward "\n\n" nil t)
1571 ;; Hide the trailer as well
1572 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1574 (gnus-article-hide-text-type
1575 (match-beginning 0) (match-end 0) 'pem)))))))
1577 (defun article-strip-banner ()
1578 "Strip the banner specified by the `banner' group parameter."
1582 (let ((inhibit-point-motion-hooks t)
1583 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1584 (gnus-signature-limit nil)
1585 buffer-read-only beg end)
1589 ((eq banner 'signature)
1590 (when (gnus-article-narrow-to-signature)
1593 (delete-region (point) (point-max))))
1595 (while (re-search-forward banner nil t)
1596 (delete-region (match-beginning 0) (match-end 0))))))))))
1598 (defun article-babel ()
1599 "Translate article using an online translation service."
1603 (set-buffer gnus-article-buffer)
1604 (when (article-goto-body)
1605 (let* ((buffer-read-only nil)
1608 (orig (buffer-substring start end))
1609 (trans (babel-as-string orig)))
1611 (narrow-to-region start end)
1612 (delete-region start end)
1615 (defun article-hide-signature (&optional arg)
1616 "Hide the signature in the current article.
1617 If given a negative prefix, always show; if given a positive prefix,
1619 (interactive (gnus-article-hidden-arg))
1620 (unless (gnus-article-check-hidden-text 'signature arg)
1623 (let ((buffer-read-only nil))
1624 (when (gnus-article-narrow-to-signature)
1625 (gnus-article-hide-text-type
1626 (point-min) (point-max) 'signature)))))))
1628 (defun article-strip-headers-in-body ()
1629 "Strip offensive headers from bodies."
1633 (let ((case-fold-search t))
1634 (when (looking-at "x-no-archive:")
1635 (gnus-delete-line)))))
1637 (defun article-strip-leading-blank-lines ()
1638 "Remove all blank lines from the beginning of the article."
1641 (let ((inhibit-point-motion-hooks t)
1643 (when (article-goto-body)
1644 (while (and (not (eobp))
1645 (looking-at "[ \t]*$"))
1646 (gnus-delete-line))))))
1648 (defun article-narrow-to-head ()
1649 "Narrow the buffer to the head of the message.
1650 Point is left at the beginning of the narrowed-to region."
1652 (goto-char (point-min))
1653 (if (search-forward "\n\n" nil 1)
1656 (goto-char (point-min)))
1658 (defun article-goto-body ()
1659 "Place point at the start of the body."
1660 (goto-char (point-min))
1662 ;; This variable is only bound when dealing with separate
1664 (article-goto-body-goes-to-point-min-p
1666 ((search-forward "\n\n" nil t)
1669 (goto-char (point-max))
1672 (defun article-strip-multiple-blank-lines ()
1673 "Replace consecutive blank lines with one empty line."
1676 (let ((inhibit-point-motion-hooks t)
1678 ;; First make all blank lines empty.
1680 (while (re-search-forward "^[ \t]+$" nil t)
1681 (unless (gnus-annotation-in-region-p
1682 (match-beginning 0) (match-end 0))
1683 (replace-match "" nil t)))
1684 ;; Then replace multiple empty lines with a single empty line.
1686 (while (re-search-forward "\n\n\n+" nil t)
1687 (unless (gnus-annotation-in-region-p
1688 (match-beginning 0) (match-end 0))
1689 (replace-match "\n\n" t t))))))
1691 (defun article-strip-leading-space ()
1692 "Remove all white space from the beginning of the lines in the article."
1695 (let ((inhibit-point-motion-hooks t)
1698 (while (re-search-forward "^[ \t]+" nil t)
1699 (replace-match "" t t)))))
1701 (defun article-strip-trailing-space ()
1702 "Remove all white space from the end of the lines in the article."
1705 (let ((inhibit-point-motion-hooks t)
1708 (while (re-search-forward "[ \t]+$" nil t)
1709 (replace-match "" t t)))))
1711 (defun article-strip-blank-lines ()
1712 "Strip leading, trailing and multiple blank lines."
1714 (article-strip-leading-blank-lines)
1715 (article-remove-trailing-blank-lines)
1716 (article-strip-multiple-blank-lines))
1718 (defun article-strip-all-blank-lines ()
1719 "Strip all blank lines."
1722 (let ((inhibit-point-motion-hooks t)
1725 (while (re-search-forward "^[ \t]*\n" nil t)
1726 (replace-match "" t t)))))
1728 (defun gnus-article-narrow-to-signature ()
1729 "Narrow to the signature; return t if a signature is found, else nil."
1730 (let ((inhibit-point-motion-hooks t))
1731 (when (gnus-article-search-signature)
1733 ;; Check whether we have some limits to what we consider
1734 ;; to be a signature.
1735 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1736 (list gnus-signature-limit)))
1738 (while (setq limit (pop limits))
1739 (if (or (and (integerp limit)
1740 (< (- (point-max) (point)) limit))
1742 (< (count-lines (point) (point-max)) limit))
1743 (and (gnus-functionp limit)
1745 (and (stringp limit)
1746 (not (re-search-forward limit nil t))))
1747 () ; This limit did not succeed.
1751 (narrow-to-region (point) (point-max))
1754 (defun gnus-article-search-signature ()
1755 "Search the current buffer for the signature separator.
1756 Put point at the beginning of the signature separator."
1757 (let ((cur (point)))
1758 (goto-char (point-max))
1759 (if (if (stringp gnus-signature-separator)
1760 (re-search-backward gnus-signature-separator nil t)
1761 (let ((seps gnus-signature-separator))
1763 (not (re-search-backward (car seps) nil t)))
1770 (defun gnus-article-hidden-arg ()
1771 "Return the current prefix arg as a number, or 0 if no prefix."
1772 (list (if current-prefix-arg
1773 (prefix-numeric-value current-prefix-arg)
1776 (defun gnus-article-check-hidden-text (type arg)
1777 "Return nil if hiding is necessary.
1778 Arg can be nil or a number. Nil and positive means hide, negative
1779 means show, 0 means toggle."
1782 (let ((hide (gnus-article-hidden-text-p type)))
1788 (gnus-article-show-hidden-text type))
1790 (if (eq hide 'hidden)
1791 (gnus-article-show-hidden-text type)
1794 (defun gnus-article-hidden-text-p (type)
1795 "Say whether the current buffer contains hidden text of type TYPE."
1796 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1798 (not (get-text-property pos 'invisible))
1799 (not (get-text-property pos 'dummy-invisible)))
1801 (text-property-any (1+ pos) (point-max) 'article-type type)))
1806 (defun gnus-article-show-hidden-text (type &optional hide)
1807 "Show all hidden text of type TYPE.
1808 If HIDE, hide the text instead."
1810 (let ((buffer-read-only nil)
1811 (inhibit-point-motion-hooks t)
1814 (while (setq beg (text-property-any end (point-max) 'article-type type))
1817 (text-property-not-all beg (point-max) 'article-type type)
1820 (gnus-article-hide-text beg end gnus-hidden-properties)
1821 (gnus-article-unhide-text beg end))
1825 (defconst article-time-units
1826 `((year . ,(* 365.25 24 60 60))
1827 (week . ,(* 7 24 60 60))
1828 (day . ,(* 24 60 60))
1832 "Mapping from time units to seconds.")
1834 (defun article-date-ut (&optional type highlight header)
1835 "Convert DATE date to universal time in the current article.
1836 If TYPE is `local', convert to local time; if it is `lapsed', output
1837 how much time has lapsed since DATE. For `lapsed', the value of
1838 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1839 should replace the \"Date:\" one, or should be added below it."
1840 (interactive (list 'ut t))
1841 (let* ((header (or header
1842 (message-fetch-field "date")
1844 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1847 ((not gnus-article-date-lapsed-new-header)
1853 (date (if (vectorp header) (mail-header-date header)
1855 (inhibit-point-motion-hooks t)
1860 (article-narrow-to-head)
1861 (when (re-search-forward tdate-regexp nil t)
1862 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1863 date (or (get-text-property (gnus-point-at-bol)
1866 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1868 (when (and date (not (string= date "")))
1869 (goto-char (point-min))
1870 (let ((buffer-read-only nil))
1871 ;; Delete any old Date headers.
1872 (while (re-search-forward date-regexp nil t)
1874 (delete-region (progn (beginning-of-line) (point))
1875 (progn (forward-line 1) (point)))
1876 (delete-region (progn (beginning-of-line) (point))
1877 (progn (end-of-line) (point)))
1878 (setq pos (point))))
1879 (when (and (not pos) (re-search-forward tdate-regexp nil t))
1881 (if pos (goto-char pos))
1882 (insert (article-make-date-line date (or type 'ut)))
1888 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1889 (put-text-property (match-beginning 1) (1+ (match-end 1))
1890 'original-date date)
1891 (put-text-property (match-beginning 1) (1+ (match-end 1))
1893 (put-text-property (match-beginning 2) (match-end 2)
1896 (defun article-make-date-line (date type)
1897 "Return a DATE line of TYPE."
1898 (let ((time (condition-case ()
1902 ;; Convert to the local timezone. We have to slap a
1903 ;; `condition-case' round the calls to the timezone
1904 ;; functions since they aren't particularly resistant to
1907 (let ((tz (car (current-time-zone time))))
1908 (format "Date: %s %s%02d%02d" (current-time-string time)
1909 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1910 (/ (% (abs tz) 3600) 60))))
1911 ;; Convert to Universal Time.
1914 (current-time-string
1915 (let* ((e (parse-time-string date))
1916 (tm (apply 'encode-time e))
1918 (ls (- (cadr tm) (car (current-time-zone time)))))
1919 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1920 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1923 ;; Get the original date from the article.
1924 ((eq type 'original)
1925 (concat "Date: " (if (string-match "\n+$" date)
1926 (substring date 0 (match-beginning 0))
1928 ;; Let the user define the format.
1930 (if (gnus-functionp gnus-article-time-format)
1931 (funcall gnus-article-time-format time)
1934 (format-time-string gnus-article-time-format time))))
1937 (let ((tz (car (current-time-zone time))))
1940 (format-time-string "%Y%m%dT%H%M%S" time)
1941 (format "%s%02d%02d"
1942 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1943 (/ (% (abs tz) 3600) 60)))))
1944 ;; Do an X-Sent lapsed format.
1946 ;; If the date is seriously mangled, the timezone functions are
1947 ;; liable to bug out, so we ignore all errors.
1948 (let* ((now (current-time))
1949 (real-time (subtract-time now time))
1950 (real-sec (and real-time
1951 (+ (* (float (car real-time)) 65536)
1953 (sec (and real-time (abs real-sec)))
1963 ;; This is a bit convoluted, but basically we go
1964 ;; through the time units for years, weeks, etc,
1965 ;; and divide things to see whether that results
1966 ;; in positive answers.
1969 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1970 ;; The (remaining) seconds are too few to
1971 ;; be divided into this time unit.
1973 ;; It's big enough, so we output it.
1974 (setq sec (- sec (* num (cdr unit))))
1976 (concat (if prev ", " "") (int-to-string
1978 " " (symbol-name (car unit))
1979 (if (> num 1) "s" ""))
1981 article-time-units "")
1982 ;; If dates are odd, then it might appear like the
1983 ;; article was sent in the future.
1986 " in the future"))))))
1988 (error "Unknown conversion type: %s" type)))))
1990 (defun article-date-local (&optional highlight)
1991 "Convert the current article date to the local timezone."
1992 (interactive (list t))
1993 (article-date-ut 'local highlight))
1995 (defun article-date-original (&optional highlight)
1996 "Convert the current article date to what it was originally.
1997 This is only useful if you have used some other date conversion
1998 function and want to see what the date was before converting."
1999 (interactive (list t))
2000 (article-date-ut 'original highlight))
2002 (defun article-date-lapsed (&optional highlight)
2003 "Convert the current article date to time lapsed since it was sent."
2004 (interactive (list t))
2005 (article-date-ut 'lapsed highlight))
2007 (defun article-update-date-lapsed ()
2008 "Function to be run from a timer to update the lapsed time line."
2009 (let (deactivate-mark)
2014 (set-buffer (window-buffer w))
2015 (when (eq major-mode 'gnus-article-mode)
2016 (goto-char (point-min))
2017 (when (re-search-forward "^X-Sent:" nil t)
2018 (article-date-lapsed t))))
2021 (defun gnus-start-date-timer (&optional n)
2022 "Start a timer to update the X-Sent header in the article buffers.
2023 The numerical prefix says how frequently (in seconds) the function
2028 (gnus-stop-date-timer)
2029 (setq article-lapsed-timer
2030 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2032 (defun gnus-stop-date-timer ()
2033 "Stop the X-Sent timer."
2035 (when article-lapsed-timer
2036 (nnheader-cancel-timer article-lapsed-timer)
2037 (setq article-lapsed-timer nil)))
2039 (defun article-date-user (&optional highlight)
2040 "Convert the current article date to the user-defined format.
2041 This format is defined by the `gnus-article-time-format' variable."
2042 (interactive (list t))
2043 (article-date-ut 'user highlight))
2045 (defun article-date-iso8601 (&optional highlight)
2046 "Convert the current article date to ISO8601."
2047 (interactive (list t))
2048 (article-date-ut 'iso8601 highlight))
2050 (defun article-show-all ()
2051 "Show all hidden text in the article buffer."
2054 (let ((buffer-read-only nil))
2055 (gnus-article-unhide-text (point-min) (point-max)))))
2057 (defun article-emphasize (&optional arg)
2058 "Emphasize text according to `gnus-emphasis-alist'."
2059 (interactive (gnus-article-hidden-arg))
2060 (unless (gnus-article-check-hidden-text 'emphasis arg)
2064 (with-current-buffer gnus-summary-buffer
2065 gnus-article-emphasis-alist)
2067 gnus-emphasis-alist))
2068 (buffer-read-only nil)
2069 (props (append '(article-type emphasis)
2070 gnus-hidden-properties))
2071 regexp elem beg invisible visible face)
2074 (while (setq elem (pop alist))
2076 (setq regexp (car elem)
2077 invisible (nth 1 elem)
2078 visible (nth 2 elem)
2080 (while (re-search-forward regexp nil t)
2081 (when (and (match-beginning visible) (match-beginning invisible))
2082 (push 'emphasis gnus-article-wash-types)
2083 (gnus-article-hide-text
2084 (match-beginning invisible) (match-end invisible) props)
2085 (gnus-article-unhide-text-type
2086 (match-beginning visible) (match-end visible) 'emphasis)
2087 (gnus-put-text-property-excluding-newlines
2088 (match-beginning visible) (match-end visible) 'face face)
2089 (goto-char (match-end invisible)))))))))
2091 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2092 "Setup newsgroup emphasis alist."
2093 (unless gnus-article-emphasis-alist
2094 (let ((name (and gnus-newsgroup-name
2095 (gnus-group-real-name gnus-newsgroup-name))))
2096 (make-local-variable 'gnus-article-emphasis-alist)
2097 (setq gnus-article-emphasis-alist
2099 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2100 (while (setq elem (pop alist))
2101 (when (and name (string-match (car elem) name))
2103 highlight (copy-sequence (cdr elem)))))
2105 (copy-sequence highlight-words)
2106 (if gnus-newsgroup-name
2107 (copy-sequence (gnus-group-find-parameter
2108 gnus-newsgroup-name 'highlight-words t)))
2109 gnus-emphasis-alist)))))
2111 (defvar gnus-summary-article-menu)
2112 (defvar gnus-summary-post-menu)
2114 ;;; Saving functions.
2116 (defun gnus-article-save (save-buffer file &optional num)
2117 "Save the currently selected article."
2118 (unless gnus-save-all-headers
2119 ;; Remove headers according to `gnus-saved-headers'.
2120 (let ((gnus-visible-headers
2121 (or gnus-saved-headers gnus-visible-headers))
2122 (gnus-article-buffer save-buffer))
2124 (set-buffer save-buffer)
2125 (article-hide-headers 1 t))))
2126 (save-window-excursion
2127 (if (not gnus-default-article-saver)
2128 (error "No default saver is defined")
2129 ;; !!! Magic! The saving functions all save
2130 ;; `gnus-save-article-buffer' (or so they think), but we
2131 ;; bind that variable to our save-buffer.
2132 (set-buffer gnus-article-buffer)
2133 (let* ((gnus-save-article-buffer save-buffer)
2136 ((not gnus-prompt-before-saving) 'default)
2137 ((eq gnus-prompt-before-saving 'always) nil)
2139 (gnus-number-of-articles-to-be-saved
2140 (when (eq gnus-prompt-before-saving t)
2142 (set-buffer gnus-article-current-summary)
2143 (funcall gnus-default-article-saver filename)))))
2145 (defun gnus-read-save-file-name (prompt &optional filename
2146 function group headers variable)
2148 (funcall function group headers (symbol-value variable)))
2153 ((eq filename 'default)
2159 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2162 (if (and gnus-number-of-articles-to-be-saved
2163 (> gnus-number-of-articles-to-be-saved 1))
2164 (format "these %d articles"
2165 gnus-number-of-articles-to-be-saved)
2168 ;; Let the split methods have their say.
2170 ;; No split name was found.
2173 (concat prompt " (default "
2174 (file-name-nondirectory default-name) ") ")
2175 (file-name-directory default-name)
2177 ;; A single group name is returned.
2178 ((stringp split-name)
2180 (funcall function split-name headers
2181 (symbol-value variable)))
2183 (concat prompt " (default "
2184 (file-name-nondirectory default-name) ") ")
2185 (file-name-directory default-name)
2187 ;; A single split name was found
2188 ((= 1 (length split-name))
2189 (let* ((name (expand-file-name
2190 (car split-name) gnus-article-save-directory))
2191 (dir (cond ((file-directory-p name)
2192 (file-name-as-directory name))
2193 ((file-exists-p name) name)
2194 (t gnus-article-save-directory))))
2196 (concat prompt " (default " name ") ")
2198 ;; A list of splits was found.
2200 (setq split-name (nreverse split-name))
2202 (let ((file-name-history
2203 (nconc split-name file-name-history)))
2207 (concat prompt " (`M-p' for defaults) ")
2208 gnus-article-save-directory
2210 gnus-article-save-directory)))
2211 (car (push result file-name-history)))))))
2212 ;; Create the directory.
2213 (gnus-make-directory (file-name-directory file))
2214 ;; If we have read a directory, we append the default file name.
2215 (when (file-directory-p file)
2216 (setq file (concat (file-name-as-directory file)
2217 (file-name-nondirectory default-name))))
2218 ;; Possibly translate some characters.
2219 (nnheader-translate-file-chars file)))))
2220 (gnus-make-directory (file-name-directory result))
2221 (set variable result)))
2223 (defun gnus-article-archive-name (group)
2224 "Return the first instance of an \"Archive-name\" in the current buffer."
2225 (let ((case-fold-search t))
2226 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2227 (nnheader-concat gnus-article-save-directory
2228 (match-string 1)))))
2230 (defun gnus-article-nndoc-name (group)
2231 "If GROUP is an nndoc group, return the name of the parent group."
2232 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2233 (gnus-group-get-parameter group 'save-article-group)))
2235 (defun gnus-summary-save-in-rmail (&optional filename)
2236 "Append this article to Rmail file.
2237 Optional argument FILENAME specifies file name.
2238 Directory to save to is default to `gnus-article-save-directory'."
2239 (setq filename (gnus-read-save-file-name
2240 "Save %s in rmail file:" filename
2241 gnus-rmail-save-name gnus-newsgroup-name
2242 gnus-current-headers 'gnus-newsgroup-last-rmail))
2243 (gnus-eval-in-buffer-window gnus-save-article-buffer
2247 (gnus-output-to-rmail filename))))
2250 (defun gnus-summary-save-in-mail (&optional filename)
2251 "Append this article to Unix mail file.
2252 Optional argument FILENAME specifies file name.
2253 Directory to save to is default to `gnus-article-save-directory'."
2254 (setq filename (gnus-read-save-file-name
2255 "Save %s in Unix mail file:" filename
2256 gnus-mail-save-name gnus-newsgroup-name
2257 gnus-current-headers 'gnus-newsgroup-last-mail))
2258 (gnus-eval-in-buffer-window gnus-save-article-buffer
2262 (if (and (file-readable-p filename)
2263 (mail-file-babyl-p filename))
2264 (rmail-output-to-rmail-file filename t)
2265 (gnus-output-to-mail filename)))))
2268 (defun gnus-summary-save-in-file (&optional filename overwrite)
2269 "Append this article to file.
2270 Optional argument FILENAME specifies file name.
2271 Directory to save to is default to `gnus-article-save-directory'."
2272 (setq filename (gnus-read-save-file-name
2273 "Save %s in file:" filename
2274 gnus-file-save-name gnus-newsgroup-name
2275 gnus-current-headers 'gnus-newsgroup-last-file))
2276 (gnus-eval-in-buffer-window gnus-save-article-buffer
2280 (when (and overwrite
2281 (file-exists-p filename))
2282 (delete-file filename))
2283 (gnus-output-to-file filename))))
2286 (defun gnus-summary-write-to-file (&optional filename)
2287 "Write this article to a file.
2288 Optional argument FILENAME specifies file name.
2289 The directory to save in defaults to `gnus-article-save-directory'."
2290 (gnus-summary-save-in-file nil t))
2292 (defun gnus-summary-save-body-in-file (&optional filename)
2293 "Append this article body to a file.
2294 Optional argument FILENAME specifies file name.
2295 The directory to save in defaults to `gnus-article-save-directory'."
2296 (setq filename (gnus-read-save-file-name
2297 "Save %s body in file:" filename
2298 gnus-file-save-name gnus-newsgroup-name
2299 gnus-current-headers 'gnus-newsgroup-last-file))
2300 (gnus-eval-in-buffer-window gnus-save-article-buffer
2304 (when (article-goto-body)
2305 (narrow-to-region (point) (point-max)))
2306 (gnus-output-to-file filename))))
2309 (defun gnus-summary-save-in-pipe (&optional command)
2310 "Pipe this article to subprocess."
2312 (cond ((and (eq command 'default)
2313 gnus-last-shell-command)
2314 gnus-last-shell-command)
2318 "Shell command on %s: "
2319 (if (and gnus-number-of-articles-to-be-saved
2320 (> gnus-number-of-articles-to-be-saved 1))
2321 (format "these %d articles"
2322 gnus-number-of-articles-to-be-saved)
2324 gnus-last-shell-command))))
2325 (when (string-equal command "")
2326 (setq command gnus-last-shell-command))
2327 (gnus-eval-in-buffer-window gnus-article-buffer
2330 (shell-command-on-region (point-min) (point-max) command nil)))
2331 (setq gnus-last-shell-command command))
2333 ;;; Article file names when saving.
2335 (defun gnus-capitalize-newsgroup (newsgroup)
2336 "Capitalize NEWSGROUP name."
2337 (when (not (zerop (length newsgroup)))
2338 (concat (char-to-string (upcase (aref newsgroup 0)))
2339 (substring newsgroup 1))))
2341 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2342 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2343 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2344 Otherwise, it is like ~/News/news/group/num."
2347 (concat (if (gnus-use-long-file-name 'not-save)
2348 (gnus-capitalize-newsgroup newsgroup)
2349 (gnus-newsgroup-directory-form newsgroup))
2350 "/" (int-to-string (mail-header-number headers)))
2351 gnus-article-save-directory)))
2353 (string-equal (file-name-directory default)
2354 (file-name-directory last-file))
2355 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2357 (or last-file default))))
2359 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2360 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2361 If variable `gnus-use-long-file-name' is non-nil, it is
2362 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2365 (concat (if (gnus-use-long-file-name 'not-save)
2367 (gnus-newsgroup-directory-form newsgroup))
2368 "/" (int-to-string (mail-header-number headers)))
2369 gnus-article-save-directory)))
2371 (string-equal (file-name-directory default)
2372 (file-name-directory last-file))
2373 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2375 (or last-file default))))
2377 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2378 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2379 If variable `gnus-use-long-file-name' is non-nil, it is
2380 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2383 (if (gnus-use-long-file-name 'not-save)
2384 (gnus-capitalize-newsgroup newsgroup)
2385 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2386 gnus-article-save-directory)))
2388 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2389 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2390 If variable `gnus-use-long-file-name' is non-nil, it is
2391 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2394 (if (gnus-use-long-file-name 'not-save)
2396 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2397 gnus-article-save-directory)))
2404 (setq afunc (car func)
2407 gfunc (intern (format "gnus-%s" func))))
2409 (if (not (fboundp afunc))
2411 `(lambda (&optional interactive &rest args)
2412 ,(documentation afunc t)
2413 (interactive (list t))
2415 (set-buffer gnus-article-buffer)
2417 (call-interactively ',afunc)
2418 (apply ',afunc args))))))))
2419 '(article-hide-headers
2420 article-hide-boring-headers
2421 article-treat-overstrike
2422 article-fill-long-lines
2423 article-capitalize-sentences
2425 article-display-x-face
2426 article-de-quoted-unreadable
2428 article-mime-decode-quoted-printable
2429 article-hide-list-identifiers
2431 article-strip-banner
2434 article-hide-signature
2435 article-strip-headers-in-body
2436 article-remove-trailing-blank-lines
2437 article-strip-leading-blank-lines
2438 article-strip-multiple-blank-lines
2439 article-strip-leading-space
2440 article-strip-trailing-space
2441 article-strip-blank-lines
2442 article-strip-all-blank-lines
2444 article-date-iso8601
2445 article-date-original
2447 article-decode-mime-words
2448 article-decode-charset
2449 article-decode-encoded-words
2453 article-treat-dumbquotes
2454 article-normalize-headers
2455 (article-show-all . gnus-article-show-all-headers))))
2458 ;;; Gnus article mode
2461 (put 'gnus-article-mode 'mode-class 'special)
2463 (set-keymap-parent gnus-article-mode-map widget-keymap)
2465 (gnus-define-keys gnus-article-mode-map
2466 " " gnus-article-goto-next-page
2467 "\177" gnus-article-goto-prev-page
2468 [delete] gnus-article-goto-prev-page
2469 [backspace] gnus-article-goto-prev-page
2470 "\C-c^" gnus-article-refer-article
2471 "h" gnus-article-show-summary
2472 "s" gnus-article-show-summary
2473 "\C-c\C-m" gnus-article-mail
2474 "?" gnus-article-describe-briefly
2475 "e" gnus-summary-edit-article
2476 "<" beginning-of-buffer
2478 "\C-c\C-i" gnus-info-find-node
2481 "\C-d" gnus-article-read-summary-keys
2482 "\M-*" gnus-article-read-summary-keys
2483 "\M-#" gnus-article-read-summary-keys
2484 "\M-^" gnus-article-read-summary-keys
2485 "\M-g" gnus-article-read-summary-keys)
2487 (substitute-key-definition
2488 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2490 (defun gnus-article-make-menu-bar ()
2491 (gnus-turn-off-edit-menu 'article)
2492 (unless (boundp 'gnus-article-article-menu)
2494 gnus-article-article-menu gnus-article-mode-map ""
2496 ["Scroll forwards" gnus-article-goto-next-page t]
2497 ["Scroll backwards" gnus-article-goto-prev-page t]
2498 ["Show summary" gnus-article-show-summary t]
2499 ["Fetch Message-ID at point" gnus-article-refer-article t]
2500 ["Mail to address at point" gnus-article-mail t]
2501 ["Send a bug report" gnus-bug t]))
2504 gnus-article-treatment-menu gnus-article-mode-map ""
2506 ["Hide headers" gnus-article-hide-headers t]
2507 ["Hide signature" gnus-article-hide-signature t]
2508 ["Hide citation" gnus-article-hide-citation t]
2509 ["Treat overstrike" gnus-article-treat-overstrike t]
2510 ["Remove carriage return" gnus-article-remove-cr t]
2511 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2512 ["Decode HZ" gnus-article-decode-HZ t]))
2514 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2516 (when (boundp 'gnus-summary-post-menu)
2517 (define-key gnus-article-mode-map [menu-bar post]
2518 (cons "Post" gnus-summary-post-menu)))
2520 (gnus-run-hooks 'gnus-article-menu-hook)))
2522 (defun gnus-article-mode ()
2523 "Major mode for displaying an article.
2525 All normal editing commands are switched off.
2527 The following commands are available in addition to all summary mode
2529 \\<gnus-article-mode-map>
2530 \\[gnus-article-next-page]\t Scroll the article one page forwards
2531 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2532 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2533 \\[gnus-article-show-summary]\t Display the summary buffer
2534 \\[gnus-article-mail]\t Send a reply to the address near point
2535 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2536 \\[gnus-info-find-node]\t Go to the Gnus info node"
2538 (when (gnus-visual-p 'article-menu 'menu)
2539 (gnus-article-make-menu-bar))
2540 (gnus-simplify-mode-line)
2541 (setq mode-name "Article")
2542 (setq major-mode 'gnus-article-mode)
2543 (make-local-variable 'minor-mode-alist)
2544 (use-local-map gnus-article-mode-map)
2545 (gnus-update-format-specifications nil 'article-mode)
2546 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2547 (make-local-variable 'gnus-page-broken)
2548 (make-local-variable 'gnus-button-marker-list)
2549 (make-local-variable 'gnus-article-current-summary)
2550 (make-local-variable 'gnus-article-mime-handles)
2551 (make-local-variable 'gnus-article-decoded-p)
2552 (make-local-variable 'gnus-article-mime-handle-alist)
2553 (make-local-variable 'gnus-article-washed-types)
2554 (gnus-set-default-directory)
2555 (buffer-disable-undo)
2556 (setq buffer-read-only t)
2557 (set-syntax-table gnus-article-mode-syntax-table)
2558 (mm-enable-multibyte)
2559 (gnus-run-hooks 'gnus-article-mode-hook))
2561 (defun gnus-article-setup-buffer ()
2562 "Initialize the article buffer."
2563 (let* ((name (if gnus-single-article-buffer "*Article*"
2564 (concat "*Article " gnus-newsgroup-name "*")))
2566 (progn (string-match "\\*Article" name)
2567 (concat " *Original Article"
2568 (substring name (match-end 0))))))
2569 (setq gnus-article-buffer name)
2570 (setq gnus-original-article-buffer original)
2571 (setq gnus-article-mime-handle-alist nil)
2572 ;; This might be a variable local to the summary buffer.
2573 (unless gnus-single-article-buffer
2575 (set-buffer gnus-summary-buffer)
2576 (setq gnus-article-buffer name)
2577 (setq gnus-original-article-buffer original)
2578 (gnus-set-global-variables)))
2579 (gnus-article-setup-highlight-words)
2580 ;; Init original article buffer.
2582 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2583 (mm-enable-multibyte)
2584 (setq major-mode 'gnus-original-article-mode)
2585 (make-local-variable 'gnus-original-article))
2586 (if (get-buffer name)
2589 (if gnus-article-mime-handles
2590 (mm-destroy-parts gnus-article-mime-handles))
2591 (kill-all-local-variables)
2592 (buffer-disable-undo)
2593 (setq buffer-read-only t)
2594 (unless (eq major-mode 'gnus-article-mode)
2595 (gnus-article-mode))
2598 (set-buffer (gnus-get-buffer-create name))
2600 (make-local-variable 'gnus-summary-buffer)
2601 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2602 (current-buffer)))))
2604 ;; Set article window start at LINE, where LINE is the number of lines
2605 ;; from the head of the article.
2606 (defun gnus-article-set-window-start (&optional line)
2608 (get-buffer-window gnus-article-buffer t)
2610 (set-buffer gnus-article-buffer)
2611 (goto-char (point-min))
2614 (gnus-message 6 "Moved to bookmark")
2615 (search-forward "\n\n" nil t)
2619 (defun gnus-article-prepare (article &optional all-headers header)
2620 "Prepare ARTICLE in article mode buffer.
2621 ARTICLE should either be an article number or a Message-ID.
2622 If ARTICLE is an id, HEADER should be the article headers.
2623 If ALL-HEADERS is non-nil, no headers are hidden."
2625 ;; Make sure we start in a summary buffer.
2626 (unless (eq major-mode 'gnus-summary-mode)
2627 (set-buffer gnus-summary-buffer))
2628 (setq gnus-summary-buffer (current-buffer))
2629 (let* ((gnus-article (if header (mail-header-number header) article))
2630 (summary-buffer (current-buffer))
2631 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2632 (group gnus-newsgroup-name)
2635 (gnus-article-setup-buffer)
2636 (set-buffer gnus-article-buffer)
2637 ;; Deactivate active regions.
2638 (when (and (boundp 'transient-mark-mode)
2639 transient-mark-mode)
2640 (setq mark-active nil))
2641 (if (not (setq result (let ((buffer-read-only nil))
2642 (gnus-request-article-this-buffer
2644 ;; There is no such article.
2646 (when (and (numberp article)
2647 (not (memq article gnus-newsgroup-sparse)))
2648 (setq gnus-article-current
2649 (cons gnus-newsgroup-name article))
2650 (set-buffer gnus-summary-buffer)
2651 (setq gnus-current-article article)
2652 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2654 (gnus-summary-set-agent-mark article)
2655 (message "Message marked for downloading"))
2656 (gnus-summary-mark-article article gnus-canceled-mark)
2657 (unless (memq article gnus-newsgroup-sparse)
2659 "No such article (may have expired or been canceled)")))))
2660 (if (or (eq result 'pseudo)
2661 (eq result 'nneething))
2664 (set-buffer summary-buffer)
2665 (push article gnus-newsgroup-history)
2666 (setq gnus-last-article gnus-current-article
2667 gnus-current-article 0
2668 gnus-current-headers nil
2669 gnus-article-current nil)
2670 (if (eq result 'nneething)
2671 (gnus-configure-windows 'summary)
2672 (gnus-configure-windows 'article))
2673 (gnus-set-global-variables))
2674 (let ((gnus-article-mime-handle-alist-1
2675 gnus-article-mime-handle-alist))
2676 (gnus-set-mode-line 'article)))
2677 ;; The result from the `request' was an actual article -
2678 ;; or at least some text that is now displayed in the
2680 (when (and (numberp article)
2681 (not (eq article gnus-current-article)))
2682 ;; Seems like a new article has been selected.
2683 ;; `gnus-current-article' must be an article number.
2685 (set-buffer summary-buffer)
2686 (push article gnus-newsgroup-history)
2687 (setq gnus-last-article gnus-current-article
2688 gnus-current-article article
2689 gnus-current-headers
2690 (gnus-summary-article-header gnus-current-article)
2691 gnus-article-current
2692 (cons gnus-newsgroup-name gnus-current-article))
2693 (unless (vectorp gnus-current-headers)
2694 (setq gnus-current-headers nil))
2695 (gnus-summary-goto-subject gnus-current-article)
2696 (when (gnus-summary-show-thread)
2697 ;; If the summary buffer really was folded, the
2698 ;; previous goto may not actually have gone to
2699 ;; the right article, but the thread root instead.
2701 (gnus-summary-goto-subject gnus-current-article))
2702 (gnus-run-hooks 'gnus-mark-article-hook)
2703 (gnus-set-mode-line 'summary)
2704 (when (gnus-visual-p 'article-highlight 'highlight)
2705 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2706 ;; Set the global newsgroup variables here.
2707 (gnus-set-global-variables)
2708 (setq gnus-have-all-headers
2709 (or all-headers gnus-show-all-headers))))
2710 (when (or (numberp article)
2712 (gnus-article-prepare-display)
2714 (goto-char (point-min))
2715 (setq gnus-page-broken
2716 (when gnus-break-pages
2717 (gnus-narrow-to-page)
2719 (let ((gnus-article-mime-handle-alist-1
2720 gnus-article-mime-handle-alist))
2721 (gnus-set-mode-line 'article))
2723 (set-window-point (get-buffer-window (current-buffer)) (point))
2724 (gnus-configure-windows 'article)
2728 (defun gnus-article-prepare-display ()
2729 "Make the current buffer look like a nice article."
2730 ;; Hooks for getting information from the article.
2731 ;; This hook must be called before being narrowed.
2732 (let ((gnus-article-buffer (current-buffer))
2734 (unless (eq major-mode 'gnus-article-mode)
2735 (gnus-article-mode))
2736 (setq buffer-read-only nil
2737 gnus-article-wash-types nil)
2738 (gnus-run-hooks 'gnus-tmp-internal-hook)
2739 (when gnus-display-mime-function
2740 (funcall gnus-display-mime-function))
2741 (gnus-run-hooks 'gnus-article-prepare-hook)))
2744 ;;; Gnus MIME viewing functions
2747 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2748 "The following specs can be used:
2750 %T MIME type, along with additional info
2751 %n The `name' parameter
2752 %d The description, if any
2753 %l The length of the encoded part
2754 %p The part identifier number
2755 %e Dots if the part isn't displayed")
2757 (defvar gnus-mime-button-line-format-alist
2758 '((?t gnus-tmp-type ?s)
2759 (?T gnus-tmp-type-long ?s)
2760 (?n gnus-tmp-name ?s)
2761 (?d gnus-tmp-description ?s)
2763 (?l gnus-tmp-length ?d)
2764 (?e gnus-tmp-dots ?s)))
2766 (defvar gnus-mime-button-commands
2767 '((gnus-article-press-button "\r" "Toggle Display")
2768 (gnus-mime-view-part "v" "View Interactively...")
2769 (gnus-mime-view-part-as-type "t" "View As Type...")
2770 (gnus-mime-save-part "o" "Save...")
2771 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2772 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2773 (gnus-mime-internalize-part "E" "View Internally")
2774 (gnus-mime-externalize-part "e" "View Externally")
2775 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2777 (defun gnus-article-mime-part-status ()
2778 (if gnus-article-mime-handle-alist-1
2779 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2782 (defvar gnus-mime-button-map nil)
2783 (unless gnus-mime-button-map
2784 (setq gnus-mime-button-map (make-sparse-keymap))
2785 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2786 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2787 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2789 (define-key gnus-mime-button-map (cadr c) (car c)))
2790 gnus-mime-button-commands))
2792 (defun gnus-mime-button-menu (event)
2793 "Construct a context-sensitive menu of MIME commands."
2796 (let ((pos (event-start event)))
2797 (set-buffer (window-buffer (posn-window pos)))
2798 (goto-char (posn-point pos))
2799 (gnus-article-check-buffer)
2800 (let ((response (x-popup-menu
2802 ("" ,@(mapcar (lambda (c)
2803 (cons (caddr c) (car c)))
2804 gnus-mime-button-commands))))))
2806 (funcall response))))))
2808 (defun gnus-mime-view-all-parts (&optional handles)
2809 "View all the MIME parts."
2811 (save-current-buffer
2812 (set-buffer gnus-article-buffer)
2813 (let ((handles (or handles gnus-article-mime-handles))
2814 (mail-parse-charset gnus-newsgroup-charset)
2815 (mail-parse-ignored-charsets
2816 (save-excursion (set-buffer gnus-summary-buffer)
2817 gnus-newsgroup-ignored-charsets)))
2818 (if (stringp (car handles))
2819 (gnus-mime-view-all-parts (cdr handles))
2820 (mapcar 'mm-display-part handles)))))
2822 (defun gnus-mime-save-part ()
2823 "Save the MIME part under point."
2825 (gnus-article-check-buffer)
2826 (let ((data (get-text-property (point) 'gnus-data)))
2827 (mm-save-part data)))
2829 (defun gnus-mime-pipe-part ()
2830 "Pipe the MIME part under point to a process."
2832 (gnus-article-check-buffer)
2833 (let ((data (get-text-property (point) 'gnus-data)))
2834 (mm-pipe-part data)))
2836 (defun gnus-mime-view-part ()
2837 "Interactively choose a viewing method for the MIME part under point."
2839 (gnus-article-check-buffer)
2840 (let ((data (get-text-property (point) 'gnus-data)))
2841 (mm-interactively-view-part data)))
2843 (defun gnus-mime-view-part-as-type-internal ()
2844 (gnus-article-check-buffer)
2845 (let* ((name (mail-content-type-get
2846 (mm-handle-type (get-text-property (point) 'gnus-data))
2848 (def-type (and name (mm-default-file-encoding name))))
2849 (and def-type (cons def-type 0))))
2851 (defun gnus-mime-view-part-as-type (mime-type)
2852 "Choose a MIME media type, and view the part as such."
2854 (list (completing-read
2855 "View as MIME type: "
2856 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
2858 (gnus-mime-view-part-as-type-internal))))
2859 (gnus-article-check-buffer)
2860 (let ((handle (get-text-property (point) 'gnus-data)))
2861 (gnus-mm-display-part
2862 (mm-make-handle (mm-handle-buffer handle)
2863 (cons mime-type (cdr (mm-handle-type handle)))
2864 (mm-handle-encoding handle)
2865 (mm-handle-undisplayer handle)
2866 (mm-handle-disposition handle)
2867 (mm-handle-description handle)
2868 (mm-handle-cache handle)
2869 (mm-handle-id handle)))))
2871 (defun gnus-mime-copy-part (&optional handle)
2872 "Put the the MIME part under point into a new buffer."
2874 (gnus-article-check-buffer)
2875 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2876 (contents (mm-get-part handle))|
2877 (base (file-name-nondirectory
2879 (mail-content-type-get (mm-handle-type handle) 'name)
2880 (mail-content-type-get (mm-handle-type handle)
2883 (buffer (generate-new-buffer base)))
2884 (switch-to-buffer buffer)
2886 ;; We do it this way to make `normal-mode' set the appropriate mode.
2889 (setq buffer-file-name (expand-file-name base))
2891 (setq buffer-file-name nil))
2892 (goto-char (point-min))))
2894 (defun gnus-mime-inline-part (&optional handle)
2895 "Insert the MIME part under point into the current buffer."
2897 (gnus-article-check-buffer)
2898 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2902 (if (mm-handle-undisplayer handle)
2903 (mm-remove-part handle)
2904 (setq contents (mm-get-part handle))
2906 (mm-insert-inline handle contents)
2909 (defun gnus-mime-externalize-part (&optional handle)
2910 "View the MIME part under point with an external viewer."
2912 (gnus-article-check-buffer)
2913 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2914 (mm-user-display-methods nil)
2915 (mm-inline-large-images nil)
2916 (mail-parse-charset gnus-newsgroup-charset)
2917 (mail-parse-ignored-charsets
2918 (save-excursion (set-buffer gnus-summary-buffer)
2919 gnus-newsgroup-ignored-charsets)))
2920 (if (mm-handle-undisplayer handle)
2921 (mm-remove-part handle)
2922 (mm-display-part handle))))
2924 (defun gnus-mime-internalize-part (&optional handle)
2925 "View the MIME part under point with an internal viewer.
2926 In no internal viewer is available, use an external viewer."
2928 (gnus-article-check-buffer)
2929 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2930 (mm-inlined-types '(".*"))
2931 (mm-inline-large-images t)
2932 (mail-parse-charset gnus-newsgroup-charset)
2933 (mail-parse-ignored-charsets
2934 (save-excursion (set-buffer gnus-summary-buffer)
2935 gnus-newsgroup-ignored-charsets)))
2936 (if (mm-handle-undisplayer handle)
2937 (mm-remove-part handle)
2938 (mm-display-part handle))))
2940 (defun gnus-article-part-wrapper (n function)
2941 (save-current-buffer
2942 (set-buffer gnus-article-buffer)
2943 (when (> n (length gnus-article-mime-handle-alist))
2944 (error "No such part"))
2945 (gnus-article-goto-part n)
2946 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2947 (funcall function handle))))
2949 (defun gnus-article-pipe-part (n)
2950 "Pipe MIME part N, which is the numerical prefix."
2952 (gnus-article-part-wrapper n 'mm-pipe-part))
2954 (defun gnus-article-save-part (n)
2955 "Save MIME part N, which is the numerical prefix."
2957 (gnus-article-part-wrapper n 'mm-save-part))
2959 (defun gnus-article-interactively-view-part (n)
2960 "View MIME part N interactively, which is the numerical prefix."
2962 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2964 (defun gnus-article-copy-part (n)
2965 "Copy MIME part N, which is the numerical prefix."
2967 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2969 (defun gnus-article-externalize-part (n)
2970 "View MIME part N externally, which is the numerical prefix."
2972 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2974 (defun gnus-article-inline-part (n)
2975 "Inline MIME part N, which is the numerical prefix."
2977 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2979 (defun gnus-article-mime-match-handle-first (condition)
2981 (let ((alist gnus-article-mime-handle-alist) ihandle n)
2982 (while (setq ihandle (pop alist))
2984 ((functionp condition)
2985 (funcall condition (cdr ihandle)))
2986 ((eq condition 'undisplayed)
2987 (not (or (mm-handle-undisplayer (cdr ihandle))
2988 (equal (mm-handle-media-type (cdr ihandle))
2989 "multipart/alternative"))))
2990 ((eq condition 'undisplayed-alternative)
2991 (not (mm-handle-undisplayer (cdr ihandle))))
2993 (gnus-article-goto-part (car ihandle))
2994 (or (not n) (< (car ihandle) n)))
2995 (setq n (car ihandle))))
2999 (defun gnus-article-view-part (&optional n)
3000 "View MIME part N, which is the numerical prefix."
3002 (save-current-buffer
3003 (set-buffer gnus-article-buffer)
3004 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3005 gnus-article-mime-match-handle-function)))
3006 (when (> n (length gnus-article-mime-handle-alist))
3007 (error "No such part"))
3008 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3009 (when (gnus-article-goto-part n)
3010 (if (equal (car handle) "multipart/alternative")
3011 (gnus-article-press-button)
3012 (when (eq (gnus-mm-display-part handle) 'internal)
3013 (gnus-set-window-start)))))))
3015 (defun gnus-mm-display-part (handle)
3016 "Display HANDLE and fix MIME button."
3017 (let ((id (get-text-property (point) 'gnus-part))
3022 (let ((window (selected-window))
3023 (mail-parse-charset gnus-newsgroup-charset)
3024 (mail-parse-ignored-charsets
3025 (save-excursion (set-buffer gnus-summary-buffer)
3026 gnus-newsgroup-ignored-charsets)))
3029 (let ((win (get-buffer-window (current-buffer) t))
3032 (select-window win))
3035 (if (mm-handle-displayed-p handle)
3036 ;; This will remove the part.
3037 (mm-display-part handle)
3039 (narrow-to-region (point) (1+ (point)))
3040 (mm-display-part handle)
3041 ;; We narrow to the part itself and
3042 ;; then call the treatment functions.
3043 (goto-char (point-min))
3045 (narrow-to-region (point) (point-max))
3048 (1- (length gnus-article-mime-handles))
3049 (mm-handle-media-type handle)))))
3050 (select-window window))))
3052 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3053 (gnus-insert-mime-button
3054 handle id (list (mm-handle-displayed-p handle)))
3055 (goto-char point))))
3057 (defun gnus-article-goto-part (n)
3058 "Go to MIME part N."
3059 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3061 (goto-char point))))
3063 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3064 (let ((gnus-tmp-name
3065 (or (mail-content-type-get (mm-handle-type handle)
3067 (mail-content-type-get (mm-handle-disposition handle)
3070 (gnus-tmp-type (mm-handle-media-type handle))
3071 (gnus-tmp-description
3072 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3075 (if (if displayed (car displayed)
3076 (mm-handle-displayed-p handle))
3078 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3080 gnus-tmp-type-long b e)
3081 (when (string-match ".*/" gnus-tmp-name)
3082 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3083 (setq gnus-tmp-type-long (concat gnus-tmp-type
3084 (and (not (equal gnus-tmp-name ""))
3085 (concat "; " gnus-tmp-name))))
3086 (or (equal gnus-tmp-description "")
3087 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3092 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3093 `(local-map ,gnus-mime-button-map
3094 keymap ,gnus-mime-button-map
3095 gnus-callback gnus-mm-display-part
3096 gnus-part ,gnus-tmp-id
3097 article-type annotation
3100 (widget-convert-button 'link b e
3102 :action 'gnus-widget-press-button
3103 :button-keymap gnus-mime-button-map
3106 ;; Needed to properly clear the message
3107 ;; due to a bug in wid-edit
3108 (setq help-echo-owns-message t)
3110 "Click to %s the MIME part; %s for more options"
3111 (if (mm-handle-displayed-p
3112 (widget-get widget :mime-handle))
3114 (if gnus-xemacs "button3" "mouse-3"))))))
3116 (defun gnus-widget-press-button (elems el)
3117 (goto-char (widget-get elems :from))
3118 (gnus-article-press-button))
3120 (defvar gnus-displaying-mime nil)
3122 (defun gnus-display-mime (&optional ihandles)
3123 "Display the MIME parts."
3125 (save-selected-window
3126 (let ((window (get-buffer-window gnus-article-buffer))
3129 (select-window window)
3130 ;; We have to do this since selecting the window
3131 ;; may change the point. So we set the window point.
3132 (set-window-point window point)))
3133 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3134 buffer-read-only handle name type b e display)
3135 (when (and (not ihandles)
3136 (not gnus-displaying-mime))
3137 ;; Top-level call; we clean up.
3138 (when gnus-article-mime-handles
3139 (mm-destroy-parts gnus-article-mime-handles)
3140 (setq gnus-article-mime-handle-alist nil));; A trick.
3141 (setq gnus-article-mime-handles handles)
3142 ;; We allow users to glean info from the handles.
3143 (when gnus-article-mime-part-function
3144 (gnus-mime-part-function handles)))
3146 (or (not (stringp (car handles)))
3149 (when (and (not ihandles)
3150 (not gnus-displaying-mime))
3151 ;; Clean up for mime parts.
3153 (delete-region (point) (point-max)))
3154 (let ((gnus-displaying-mime t))
3155 (gnus-mime-display-part handles)))
3158 (narrow-to-region (point) (point-max))
3159 (gnus-treat-article nil 1 1)
3162 ;; Highlight the headers.
3166 (narrow-to-region (point-min) (point))
3167 (gnus-treat-article 'head))))))))
3169 (defvar gnus-mime-display-multipart-as-mixed nil)
3171 (defun gnus-mime-display-part (handle)
3174 ((not (stringp (car handle)))
3175 (gnus-mime-display-single handle))
3176 ;; User-defined multipart
3177 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3178 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3180 ;; multipart/alternative
3181 ((and (equal (car handle) "multipart/alternative")
3182 (not gnus-mime-display-multipart-as-mixed))
3183 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3184 (push (cons id handle) gnus-article-mime-handle-alist)
3185 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3186 ;; multipart/related
3187 ((and (equal (car handle) "multipart/related")
3188 (not gnus-mime-display-multipart-as-mixed))
3189 ;;;!!!We should find the start part, but we just default
3190 ;;;!!!to the first part.
3191 (gnus-mime-display-part (cadr handle)))
3192 ;; Other multiparts are handled like multipart/mixed.
3194 (gnus-mime-display-mixed (cdr handle)))))
3196 (defun gnus-mime-part-function (handles)
3197 (if (stringp (car handles))
3198 (mapcar 'gnus-mime-part-function (cdr handles))
3199 (funcall gnus-article-mime-part-function handles)))
3201 (defun gnus-mime-display-mixed (handles)
3202 (mapcar 'gnus-mime-display-part handles))
3204 (defun gnus-mime-display-single (handle)
3205 (let ((type (mm-handle-media-type handle))
3206 (ignored gnus-ignored-mime-types)
3213 (when (string-match (pop ignored) type)
3214 (throw 'ignored nil)))
3215 (if (and (setq not-attachment
3216 (and (not (mm-inline-override-p handle))
3217 (or (not (mm-handle-disposition handle))
3218 (equal (car (mm-handle-disposition handle))
3220 (mm-attachment-override-p handle))))
3221 (mm-automatic-display-p handle)
3222 (or (mm-inlined-p handle)
3223 (mm-automatic-external-display-p type)))
3225 (when (equal (mm-handle-media-supertype handle) "text")
3227 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3228 (push (cons id handle) gnus-article-mime-handle-alist)
3229 (when (or (not display)
3230 (not (gnus-unbuttonized-mime-type-p type)))
3231 ;(gnus-article-insert-newline)
3232 (gnus-insert-mime-button
3233 handle id (list (or display (and not-attachment text))))
3234 (gnus-article-insert-newline)
3235 ;(gnus-article-insert-newline)
3237 (let ((beg (point)))
3243 (let ((mail-parse-charset gnus-newsgroup-charset)
3244 (mail-parse-ignored-charsets
3245 (save-excursion (condition-case ()
3246 (set-buffer gnus-summary-buffer)
3248 gnus-newsgroup-ignored-charsets)))
3249 (mm-display-part handle t))
3250 (goto-char (point-max)))
3251 ((and text not-attachment)
3255 (gnus-article-insert-newline)
3256 (mm-insert-inline handle (mm-get-part handle))
3257 (goto-char (point-max))))
3261 (narrow-to-region beg (point))
3263 nil (length gnus-article-mime-handle-alist)
3264 (1- (length gnus-article-mime-handles))
3265 (mm-handle-media-type handle)))))))))
3267 (defun gnus-unbuttonized-mime-type-p (type)
3268 "Say whether TYPE is to be unbuttonized."
3269 (unless gnus-inhibit-mime-unbuttonizing
3271 (let ((types gnus-unbuttonized-mime-types))
3273 (when (string-match (pop types) type)
3274 (throw 'found t)))))))
3276 (defun gnus-article-insert-newline ()
3277 "Insert a newline, but mark it as undeletable."
3278 (gnus-put-text-property
3279 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3281 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3282 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3285 handle buffer-read-only from props begend not-pref)
3286 (save-window-excursion
3289 (narrow-to-region (car ibegend)
3292 (goto-char (car ibegend))
3295 (delete-region (point-min) (point-max))
3296 (mm-remove-parts handles))
3297 (setq begend (list (point-marker)))
3299 (unless (setq not-pref (cadr (member preferred ihandles)))
3300 (setq not-pref (car ihandles)))
3302 (not (gnus-unbuttonized-mime-type-p
3303 "multipart/alternative")))
3304 (gnus-add-text-properties
3307 (insert (format "%d. " id))
3311 (unless ,(not ibegend)
3312 (setq gnus-article-mime-handle-alist
3313 ',gnus-article-mime-handle-alist))
3314 (gnus-mime-display-alternative
3315 ',ihandles ',not-pref ',begend ,id))
3316 local-map ,gnus-mime-button-map
3317 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3318 face ,gnus-article-button-face
3319 keymap ,gnus-mime-button-map
3322 (widget-convert-button 'link from (point)
3323 :action 'gnus-widget-press-button
3324 :button-keymap gnus-widget-button-keymap)
3326 (while (setq handle (pop handles))
3327 (gnus-add-text-properties
3330 (insert (format "(%c) %-18s"
3331 (if (equal handle preferred) ?* ? )
3332 (mm-handle-media-type handle)))
3336 (unless ,(not ibegend)
3337 (setq gnus-article-mime-handle-alist
3338 ',gnus-article-mime-handle-alist))
3339 (gnus-mime-display-alternative
3340 ',ihandles ',handle ',begend ,id))
3341 local-map ,gnus-mime-button-map
3342 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3343 face ,gnus-article-button-face
3344 keymap ,gnus-mime-button-map
3347 (widget-convert-button 'link from (point)
3348 :action 'gnus-widget-press-button
3349 :button-keymap gnus-widget-button-keymap)
3353 (if (stringp (car preferred))
3354 (gnus-display-mime preferred)
3355 (let ((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 (mm-display-part preferred)
3363 (narrow-to-region (car begend) (point-max))
3365 nil (length gnus-article-mime-handle-alist)
3366 (1- (length gnus-article-mime-handles))
3367 (mm-handle-media-type handle))))))
3368 (goto-char (point-max))
3369 (setcdr begend (point-marker)))))
3371 (goto-char point))))
3373 (defun gnus-article-wash-status ()
3374 "Return a string which display status of article washing."
3376 (set-buffer gnus-article-buffer)
3377 (let ((cite (memq 'cite gnus-article-wash-types))
3378 (headers (memq 'headers gnus-article-wash-types))
3379 (boring (memq 'boring-headers gnus-article-wash-types))
3380 (pgp (memq 'pgp gnus-article-wash-types))
3381 (pem (memq 'pem gnus-article-wash-types))
3382 (signature (memq 'signature gnus-article-wash-types))
3383 (overstrike (memq 'overstrike gnus-article-wash-types))
3384 (emphasis (memq 'emphasis gnus-article-wash-types)))
3385 (format "%c%c%c%c%c%c"
3387 (if (or headers boring) ?h ? )
3388 (if (or pgp pem) ?p ? )
3389 (if signature ?s ? )
3390 (if overstrike ?o ? )
3391 (if emphasis ?e ? )))))
3393 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3395 (defun gnus-article-maybe-hide-headers ()
3396 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3397 Provided for backwards compatibility."
3398 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3399 (not (save-excursion (set-buffer gnus-summary-buffer)
3400 gnus-have-all-headers)))
3401 (not gnus-inhibit-hiding))
3402 (gnus-article-hide-headers)))
3406 (defun gnus-output-to-file (file-name)
3407 "Append the current article to a file named FILE-NAME."
3408 (let ((artbuf (current-buffer)))
3410 (insert-buffer-substring artbuf)
3411 ;; Append newline at end of the buffer as separator, and then
3413 (goto-char (point-max))
3415 (mm-append-to-file (point-min) (point-max) file-name)
3418 (defun gnus-narrow-to-page (&optional arg)
3419 "Narrow the article buffer to a page.
3420 If given a numerical ARG, move forward ARG pages."
3422 (setq arg (if arg (prefix-numeric-value arg) 0))
3424 (set-buffer gnus-article-buffer)
3425 (goto-char (point-min))
3427 ;; Remove any old next/prev buttons.
3428 (when (gnus-visual-p 'page-marker)
3429 (let ((buffer-read-only nil))
3430 (gnus-remove-text-with-property 'gnus-prev)
3431 (gnus-remove-text-with-property 'gnus-next)))
3434 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3436 (re-search-forward page-delimiter nil 'move arg)))
3437 (goto-char (match-end 0)))
3440 (if (re-search-forward page-delimiter nil 'move)
3443 (when (and (gnus-visual-p 'page-marker)
3444 (not (= (point-min) 1)))
3446 (goto-char (point-min))
3447 (gnus-insert-prev-page-button)))
3448 (when (and (gnus-visual-p 'page-marker)
3449 (< (+ (point-max) 2) (buffer-size)))
3451 (goto-char (point-max))
3452 (gnus-insert-next-page-button)))))
3454 ;; Article mode commands
3456 (defun gnus-article-goto-next-page ()
3457 "Show the next page of the article."
3459 (when (gnus-article-next-page)
3460 (goto-char (point-min))
3461 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3463 (defun gnus-article-goto-prev-page ()
3464 "Show the next page of the article."
3466 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3467 (gnus-article-prev-page nil)))
3469 (defun gnus-article-next-page (&optional lines)
3470 "Show the next page of the current article.
3471 If end of article, return non-nil. Otherwise return nil.
3472 Argument LINES specifies lines to be scrolled up."
3474 (move-to-window-line -1)
3477 (and (pos-visible-in-window-p) ;Not continuation line.
3479 ;; Nothing in this page.
3480 (if (or (not gnus-page-broken)
3483 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3485 (gnus-narrow-to-page 1) ;Go to next page.
3487 ;; More in this page.
3488 (let ((scroll-in-place nil))
3492 ;; Long lines may cause an end-of-buffer error.
3493 (goto-char (point-max)))))
3494 (move-to-window-line 0)
3497 (defun gnus-article-prev-page (&optional lines)
3498 "Show previous page of current article.
3499 Argument LINES specifies lines to be scrolled down."
3501 (move-to-window-line 0)
3502 (if (and gnus-page-broken
3504 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3506 (gnus-narrow-to-page -1) ;Go to previous page.
3507 (goto-char (point-max))
3509 (let ((scroll-in-place nil))
3513 (beginning-of-buffer
3514 (goto-char (point-min))))
3515 (move-to-window-line 0)))))
3517 (defun gnus-article-refer-article ()
3518 "Read article specified by message-id around point."
3520 (let ((point (point)))
3521 (search-forward ">" nil t) ;Move point to end of "<....>".
3522 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3523 (let ((message-id (match-string 1)))
3525 (set-buffer gnus-summary-buffer)
3526 (gnus-summary-refer-article message-id))
3528 (error "No references around point"))))
3530 (defun gnus-article-show-summary ()
3531 "Reconfigure windows to show summary buffer."
3533 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3534 (error "There is no summary buffer for this article buffer")
3535 (gnus-article-set-globals)
3536 (gnus-configure-windows 'article)
3537 (gnus-summary-goto-subject gnus-current-article)
3538 (gnus-summary-position-point)))
3540 (defun gnus-article-describe-briefly ()
3541 "Describe article mode commands briefly."
3543 (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")))
3545 (defun gnus-article-summary-command ()
3546 "Execute the last keystroke in the summary buffer."
3548 (let ((obuf (current-buffer))
3549 (owin (current-window-configuration))
3551 (switch-to-buffer gnus-article-current-summary 'norecord)
3552 (setq func (lookup-key (current-local-map) (this-command-keys)))
3553 (call-interactively func)
3555 (set-window-configuration owin)
3556 (set-window-point (get-buffer-window (current-buffer)) (point))))
3558 (defun gnus-article-summary-command-nosave ()
3559 "Execute the last keystroke in the summary buffer."
3562 (pop-to-buffer gnus-article-current-summary 'norecord)
3563 (setq func (lookup-key (current-local-map) (this-command-keys)))
3564 (call-interactively func)))
3566 (defun gnus-article-check-buffer ()
3567 "Beep if not in an article buffer."
3568 (unless (equal major-mode 'gnus-article-mode)
3569 (error "Command invoked outside of a Gnus article buffer")))
3571 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3572 "Read a summary buffer key sequence and execute it from the article buffer."
3574 (gnus-article-check-buffer)
3576 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3577 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3578 "=" "^" "\M-^" "|"))
3584 '("n" "Gn" "p" "Gp"))
3587 (set-buffer gnus-article-current-summary)
3588 (let (gnus-pick-mode)
3589 (push (or key last-command-event) unread-command-events)
3590 (setq keys (if gnus-xemacs
3591 (events-to-keys (read-key-sequence nil))
3592 (read-key-sequence nil)))))
3596 (if (or (member keys nosaves)
3597 (member keys nosave-but-article)
3598 (member keys nosave-in-article))
3600 (save-window-excursion
3601 (pop-to-buffer gnus-article-current-summary 'norecord)
3602 ;; We disable the pick minor mode commands.
3603 (let (gnus-pick-mode)
3604 (setq func (lookup-key (current-local-map) keys))))
3607 (unless (member keys nosave-in-article)
3608 (set-buffer gnus-article-current-summary))
3609 (call-interactively func)
3610 (setq new-sum-point (point)))
3611 (when (member keys nosave-but-article)
3612 (pop-to-buffer gnus-article-buffer 'norecord)))
3613 ;; These commands should restore window configuration.
3614 (let ((obuf (current-buffer))
3615 (owin (current-window-configuration))
3617 (summary gnus-article-current-summary)
3618 func in-buffer selected)
3619 (if not-restore-window
3620 (pop-to-buffer summary 'norecord)
3621 (switch-to-buffer summary 'norecord))
3622 (setq in-buffer (current-buffer))
3623 ;; We disable the pick minor mode commands.
3624 (if (setq func (let (gnus-pick-mode)
3625 (lookup-key (current-local-map) keys)))
3627 (call-interactively func)
3628 (setq new-sum-point (point)))
3630 (when (eq in-buffer (current-buffer))
3631 (setq selected (gnus-summary-select-article))
3633 (unless not-restore-window
3634 (set-window-configuration owin))
3635 (when (eq selected 'old)
3637 (set-window-start (get-buffer-window (current-buffer))
3639 (set-window-point (get-buffer-window (current-buffer))
3641 (let ((win (get-buffer-window gnus-article-current-summary)))
3643 (set-window-point win new-sum-point))))))))
3645 (defun gnus-article-hide (&optional arg force)
3646 "Hide all the gruft in the current article.
3647 This means that PGP stuff, signatures, cited text and (some)
3648 headers will be hidden.
3649 If given a prefix, show the hidden text instead."
3650 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3651 (gnus-article-hide-headers arg)
3652 (gnus-article-hide-list-identifiers arg)
3653 (gnus-article-hide-pgp arg)
3654 (gnus-article-hide-citation-maybe arg force)
3655 (gnus-article-hide-signature arg))
3657 (defun gnus-article-maybe-highlight ()
3658 "Do some article highlighting if article highlighting is requested."
3659 (when (gnus-visual-p 'article-highlight 'highlight)
3660 (gnus-article-highlight-some)))
3662 (defun gnus-check-group-server ()
3663 ;; Make sure the connection to the server is alive.
3664 (unless (gnus-server-opened
3665 (gnus-find-method-for-group gnus-newsgroup-name))
3666 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3667 (gnus-request-group gnus-newsgroup-name t)))
3669 (defun gnus-request-article-this-buffer (article group)
3670 "Get an article and insert it into this buffer."
3671 (let (do-update-line sparse-header)
3675 (gnus-kill-all-overlays)
3676 (setq group (or group gnus-newsgroup-name))
3678 ;; Using `gnus-request-article' directly will insert the article into
3679 ;; `nntp-server-buffer' - so we'll save some time by not having to
3680 ;; copy it from the server buffer into the article buffer.
3682 ;; We only request an article by message-id when we do not have the
3683 ;; headers for it, so we'll have to get those.
3684 (when (stringp article)
3685 (gnus-read-header article))
3687 ;; If the article number is negative, that means that this article
3688 ;; doesn't belong in this newsgroup (possibly), so we find its
3689 ;; message-id and request it by id instead of number.
3690 (when (and (numberp article)
3692 (get-buffer gnus-summary-buffer)
3693 (gnus-buffer-exists-p gnus-summary-buffer))
3695 (set-buffer gnus-summary-buffer)
3696 (let ((header (gnus-summary-article-header article)))
3699 ((memq article gnus-newsgroup-sparse)
3700 ;; This is a sparse gap article.
3701 (setq do-update-line article)
3702 (setq article (mail-header-id header))
3703 (setq sparse-header (gnus-read-header article))
3704 (setq gnus-newsgroup-sparse
3705 (delq article gnus-newsgroup-sparse)))
3707 ;; It's a real article.
3708 (setq article (mail-header-id header)))
3710 ;; It is an extracted pseudo-article.
3711 (setq article 'pseudo)
3712 (gnus-request-pseudo-article header))))
3714 (let ((method (gnus-find-method-for-group
3715 gnus-newsgroup-name)))
3716 (when (and (eq (car method) 'nneething)
3719 (file-name-as-directory
3720 (or (cadr (assq 'nneething-address method))
3722 (mail-header-subject header))))
3723 (when (file-directory-p dir)
3724 (setq article 'nneething)
3725 (gnus-group-enter-directory dir))))))))
3728 ;; Refuse to select canceled articles.
3729 ((and (numberp article)
3731 (get-buffer gnus-summary-buffer)
3732 (gnus-buffer-exists-p gnus-summary-buffer)
3733 (eq (cdr (save-excursion
3734 (set-buffer gnus-summary-buffer)
3735 (assq article gnus-newsgroup-reads)))
3736 gnus-canceled-mark))
3738 ;; We first check `gnus-original-article-buffer'.
3739 ((and (get-buffer gnus-original-article-buffer)
3742 (set-buffer gnus-original-article-buffer)
3743 (and (equal (car gnus-original-article) group)
3744 (eq (cdr gnus-original-article) article))))
3745 (insert-buffer-substring gnus-original-article-buffer)
3747 ;; Check the backlog.
3748 ((and gnus-keep-backlog
3749 (gnus-backlog-request-article group article (current-buffer)))
3751 ;; Check asynchronous pre-fetch.
3752 ((gnus-async-request-fetched-article group article (current-buffer))
3753 (gnus-async-prefetch-next group article gnus-summary-buffer)
3754 (when (and (numberp article) gnus-keep-backlog)
3755 (gnus-backlog-enter-article group article (current-buffer)))
3758 ((and gnus-use-cache
3760 (gnus-cache-request-article article group))
3762 ;; Get the article and put into the article buffer.
3763 ((or (stringp article)
3765 (let ((gnus-override-method gnus-override-method)
3766 (methods (and (stringp article)
3767 gnus-refer-article-method))
3769 (buffer-read-only nil))
3774 (when (and (null gnus-override-method)
3776 (setq gnus-override-method (pop methods)))
3778 (when (eq gnus-override-method 'current)
3779 (setq gnus-override-method gnus-current-select-method))
3781 (gnus-kill-all-overlays)
3782 (let ((gnus-newsgroup-name group))
3783 (gnus-check-group-server))
3784 (when (gnus-request-article article group (current-buffer))
3785 (when (numberp article)
3786 (gnus-async-prefetch-next group article
3787 gnus-summary-buffer)
3788 (when gnus-keep-backlog
3789 (gnus-backlog-enter-article
3790 group article (current-buffer))))
3791 (setq result 'article))
3794 (setq gnus-override-method (pop methods))
3795 (setq result 'done))))
3796 (and (eq result 'article) 'article)))
3800 ;; Associate this article with the current summary buffer.
3801 (setq gnus-article-current-summary gnus-summary-buffer)
3803 ;; Take the article from the original article buffer
3804 ;; and place it in the buffer it's supposed to be in.
3805 (when (and (get-buffer gnus-article-buffer)
3806 (equal (buffer-name (current-buffer))
3807 (buffer-name (get-buffer gnus-article-buffer))))
3809 (if (get-buffer gnus-original-article-buffer)
3810 (set-buffer gnus-original-article-buffer)
3811 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3812 (buffer-disable-undo)
3813 (setq major-mode 'gnus-original-article-mode)
3814 (setq buffer-read-only t))
3815 (let (buffer-read-only)
3817 (insert-buffer-substring gnus-article-buffer))
3818 (setq gnus-original-article (cons group article)))
3821 (run-hooks 'gnus-article-decode-hook)
3822 ;; Mark article as decoded or not.
3823 (setq gnus-article-decoded-p gnus-article-decode-hook))
3825 ;; Update sparse articles.
3826 (when (and do-update-line
3827 (or (numberp article)
3829 (let ((buf (current-buffer)))
3830 (set-buffer gnus-summary-buffer)
3831 (gnus-summary-update-article do-update-line sparse-header)
3832 (gnus-summary-goto-subject do-update-line nil t)
3833 (set-window-point (get-buffer-window (current-buffer) t)
3835 (set-buffer buf))))))
3841 (defcustom gnus-article-edit-mode-hook nil
3842 "Hook run in article edit mode buffers."
3843 :group 'gnus-article-various
3846 (defvar gnus-article-edit-done-function nil)
3848 (defvar gnus-article-edit-mode-map nil)
3850 ;; Should we be using derived.el for this?
3851 (unless gnus-article-edit-mode-map
3852 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3853 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3855 (gnus-define-keys gnus-article-edit-mode-map
3856 "\C-c\C-c" gnus-article-edit-done
3857 "\C-c\C-k" gnus-article-edit-exit)
3859 (gnus-define-keys (gnus-article-edit-wash-map
3860 "\C-c\C-w" gnus-article-edit-mode-map)
3861 "f" gnus-article-edit-full-stops))
3863 (defun gnus-article-edit-mode ()
3864 "Major mode for editing articles.
3865 This is an extended text-mode.
3867 \\{gnus-article-edit-mode-map}"
3869 (setq major-mode 'gnus-article-edit-mode)
3870 (setq mode-name "Article Edit")
3871 (use-local-map gnus-article-edit-mode-map)
3872 (make-local-variable 'gnus-article-edit-done-function)
3873 (make-local-variable 'gnus-prev-winconf)
3874 (setq buffer-read-only nil)
3875 (buffer-enable-undo)
3877 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3879 (defun gnus-article-edit (&optional force)
3880 "Edit the current article.
3881 This will have permanent effect only in mail groups.
3882 If FORCE is non-nil, allow editing of articles even in read-only
3885 (when (and (not force)
3886 (gnus-group-read-only-p))
3887 (error "The current newsgroup does not support article editing"))
3888 (gnus-article-date-original)
3889 (gnus-article-edit-article
3891 `(lambda (no-highlight)
3893 (gnus-summary-edit-article-done
3894 ,(or (mail-header-references gnus-current-headers) "")
3895 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3897 (defun gnus-article-edit-article (start-func exit-func)
3898 "Start editing the contents of the current article buffer."
3899 (let ((winconf (current-window-configuration)))
3900 (set-buffer gnus-article-buffer)
3901 (gnus-article-edit-mode)
3902 (funcall start-func)
3903 (gnus-configure-windows 'edit-article)
3904 (setq gnus-article-edit-done-function exit-func)
3905 (setq gnus-prev-winconf winconf)
3906 (gnus-message 6 "C-c C-c to end edits")))
3908 (defun gnus-article-edit-done (&optional arg)
3909 "Update the article edits and exit."
3914 (when (article-goto-body)
3915 (let ((lines (count-lines (point) (point-max)))
3916 (length (- (point-max) (point)))
3917 (case-fold-search t)
3918 (body (copy-marker (point))))
3919 (goto-char (point-min))
3920 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3921 (delete-region (match-beginning 1) (match-end 1))
3922 (insert (number-to-string length)))
3923 (goto-char (point-min))
3924 (when (re-search-forward
3925 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3926 (delete-region (match-beginning 1) (match-end 1))
3927 (insert (number-to-string length)))
3928 (goto-char (point-min))
3929 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3930 (delete-region (match-beginning 1) (match-end 1))
3931 (insert (number-to-string lines)))))))
3932 (let ((func gnus-article-edit-done-function)
3933 (buf (current-buffer))
3934 (start (window-start)))
3935 (gnus-article-edit-exit)
3938 (let ((buffer-read-only nil))
3940 ;; The cache and backlog have to be flushed somewhat.
3941 (when gnus-keep-backlog
3942 (gnus-backlog-remove-article
3943 (car gnus-article-current) (cdr gnus-article-current)))
3944 ;; Flush original article as well.
3946 (when (get-buffer gnus-original-article-buffer)
3947 (set-buffer gnus-original-article-buffer)
3948 (setq gnus-original-article nil)))
3949 (when gnus-use-cache
3950 (gnus-cache-update-article
3951 (car gnus-article-current) (cdr gnus-article-current))))
3953 (set-window-start (get-buffer-window buf) start)
3954 (set-window-point (get-buffer-window buf) (point))))
3956 (defun gnus-article-edit-exit ()
3957 "Exit the article editing without updating."
3959 ;; We remove all text props from the article buffer.
3960 (let ((buf (format "%s" (buffer-string)))
3961 (curbuf (current-buffer))
3963 (window-start (window-start)))
3966 (let ((winconf gnus-prev-winconf))
3968 (set-window-configuration winconf)
3969 ;; Tippy-toe some to make sure that point remains where it was.
3970 (save-current-buffer
3972 (set-window-start (get-buffer-window (current-buffer)) window-start)
3975 (defun gnus-article-edit-full-stops ()
3976 "Interactively repair spacing at end of sentences."
3979 (goto-char (point-min))
3980 (search-forward-regexp "^$" nil t)
3981 (let ((case-fold-search nil))
3982 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3985 ;;; Article highlights
3988 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3990 ;;; Internal Variables:
3992 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)"
3993 "Regular expression that matches URLs."
3994 :group 'gnus-article-buttons
3997 (defcustom gnus-button-alist
3998 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3999 0 t gnus-button-message-id 2)
4000 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4001 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4003 gnus-button-fetch-group 4)
4004 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4005 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4006 t gnus-button-message-id 3)
4007 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4008 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4009 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4010 ;; This is how URLs _should_ be embedded in text...
4011 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4013 (,gnus-button-url-regexp 0 t browse-url 0))
4014 "*Alist of regexps matching buttons in article bodies.
4016 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4017 REGEXP: is the string matching text around the button,
4018 BUTTON: is the number of the regexp grouping actually matching the button,
4019 FORM: is a lisp expression which must eval to true for the button to
4021 CALLBACK: is the function to call when the user push this button, and each
4022 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4024 CALLBACK can also be a variable, in that case the value of that
4025 variable it the real callback function."
4026 :group 'gnus-article-buttons
4027 :type '(repeat (list regexp
4028 (integer :tag "Button")
4030 (function :tag "Callback")
4033 (integer :tag "Regexp group")))))
4035 (defcustom gnus-header-button-alist
4036 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4037 0 t gnus-button-message-id 0)
4038 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4039 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4040 0 t gnus-button-mailto 0)
4041 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4042 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4043 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4044 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4045 gnus-button-message-id 3))
4046 "*Alist of headers and regexps to match buttons in article heads.
4048 This alist is very similar to `gnus-button-alist', except that each
4049 alist has an additional HEADER element first in each entry:
4051 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4053 HEADER is a regexp to match a header. For a fuller explanation, see
4054 `gnus-button-alist'."
4055 :group 'gnus-article-buttons
4056 :group 'gnus-article-headers
4057 :type '(repeat (list (regexp :tag "Header")
4059 (integer :tag "Button")
4061 (function :tag "Callback")
4064 (integer :tag "Regexp group")))))
4066 (defvar gnus-button-regexp nil)
4067 (defvar gnus-button-marker-list nil)
4068 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4070 (defvar gnus-button-last nil)
4071 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4075 (defun gnus-article-push-button (event)
4076 "Check text under the mouse pointer for a callback function.
4077 If the text under the mouse pointer has a `gnus-callback' property,
4078 call it with the value of the `gnus-data' text property."
4080 (set-buffer (window-buffer (posn-window (event-start event))))
4081 (let* ((pos (posn-point (event-start event)))
4082 (data (get-text-property pos 'gnus-data))
4083 (fun (get-text-property pos 'gnus-callback)))
4086 (funcall fun data))))
4088 (defun gnus-article-press-button ()
4089 "Check text at point for a callback function.
4090 If the text at point has a `gnus-callback' property,
4091 call it with the value of the `gnus-data' text property."
4093 (let* ((data (get-text-property (point) 'gnus-data))
4094 (fun (get-text-property (point) 'gnus-callback)))
4096 (funcall fun data))))
4098 (defun gnus-article-highlight (&optional force)
4099 "Highlight current article.
4100 This function calls `gnus-article-highlight-headers',
4101 `gnus-article-highlight-citation',
4102 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4103 do the highlighting. See the documentation for those functions."
4104 (interactive (list 'force))
4105 (gnus-article-highlight-headers)
4106 (gnus-article-highlight-citation force)
4107 (gnus-article-highlight-signature)
4108 (gnus-article-add-buttons force)
4109 (gnus-article-add-buttons-to-head))
4111 (defun gnus-article-highlight-some (&optional force)
4112 "Highlight current article.
4113 This function calls `gnus-article-highlight-headers',
4114 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4115 do the highlighting. See the documentation for those functions."
4116 (interactive (list 'force))
4117 (gnus-article-highlight-headers)
4118 (gnus-article-highlight-signature)
4119 (gnus-article-add-buttons))
4121 (defun gnus-article-highlight-headers ()
4122 "Highlight article headers as specified by `gnus-header-face-alist'."
4125 (set-buffer gnus-article-buffer)
4127 (let ((alist gnus-header-face-alist)
4128 (buffer-read-only nil)
4129 (case-fold-search t)
4130 (inhibit-point-motion-hooks t)
4131 entry regexp header-face field-face from hpoints fpoints)
4132 (article-narrow-to-head)
4133 (while (setq entry (pop alist))
4134 (goto-char (point-min))
4135 (setq regexp (concat "^\\("
4136 (if (string-equal "" (nth 0 entry))
4140 header-face (nth 1 entry)
4141 field-face (nth 2 entry))
4142 (while (and (re-search-forward regexp nil t)
4146 (unless (search-forward ":" nil t)
4148 (when (and header-face
4149 (not (memq (point) hpoints)))
4150 (push (point) hpoints)
4151 (gnus-put-text-property from (point) 'face header-face))
4152 (when (and field-face
4153 (not (memq (setq from (point)) fpoints)))
4155 (if (re-search-forward "^[^ \t]" nil t)
4157 (goto-char (point-max)))
4158 (gnus-put-text-property from (point) 'face field-face))))))))
4160 (defun gnus-article-highlight-signature ()
4161 "Highlight the signature in an article.
4162 It does this by highlighting everything after
4163 `gnus-signature-separator' using `gnus-signature-face'."
4166 (set-buffer gnus-article-buffer)
4167 (let ((buffer-read-only nil)
4168 (inhibit-point-motion-hooks t))
4170 (when (and gnus-signature-face
4171 (gnus-article-narrow-to-signature))
4172 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4173 'face gnus-signature-face)
4175 (gnus-article-search-signature)
4176 (let ((start (match-beginning 0))
4177 (end (set-marker (make-marker) (1+ (match-end 0)))))
4178 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4181 (defun gnus-button-in-region-p (b e prop)
4182 "Say whether PROP exists in the region."
4183 (text-property-not-all b e prop nil))
4185 (defun gnus-article-add-buttons (&optional force)
4186 "Find external references in the article and make buttons of them.
4187 \"External references\" are things like Message-IDs and URLs, as
4188 specified by `gnus-button-alist'."
4189 (interactive (list 'force))
4191 (set-buffer gnus-article-buffer)
4192 (let ((buffer-read-only nil)
4193 (inhibit-point-motion-hooks t)
4194 (case-fold-search t)
4195 (alist gnus-button-alist)
4197 ;; Remove all old markers.
4198 (let (marker entry new-list)
4199 (while (setq marker (pop gnus-button-marker-list))
4200 (if (or (< marker (point-min)) (>= marker (point-max)))
4201 (push marker new-list)
4203 (when (setq entry (gnus-button-entry))
4204 (put-text-property (match-beginning (nth 1 entry))
4205 (match-end (nth 1 entry))
4206 'gnus-callback nil))
4207 (set-marker marker nil)))
4208 (setq gnus-button-marker-list new-list))
4209 ;; We skip the headers.
4212 (while (setq entry (pop alist))
4213 (setq regexp (car entry))
4215 (while (re-search-forward regexp nil t)
4216 (let* ((start (and entry (match-beginning (nth 1 entry))))
4217 (end (and entry (match-end (nth 1 entry))))
4218 (from (match-beginning 0)))
4219 (when (and (or (eq t (nth 2 entry))
4220 (eval (nth 2 entry)))
4221 (not (gnus-button-in-region-p
4222 start end 'gnus-callback)))
4223 ;; That optional form returned non-nil, so we add the
4225 (gnus-article-add-button
4226 start end 'gnus-button-push
4227 (car (push (set-marker (make-marker) from)
4228 gnus-button-marker-list))))))))))
4230 ;; Add buttons to the head of an article.
4231 (defun gnus-article-add-buttons-to-head ()
4232 "Add buttons to the head of the article."
4235 (set-buffer gnus-article-buffer)
4237 (let ((buffer-read-only nil)
4238 (inhibit-point-motion-hooks t)
4239 (case-fold-search t)
4240 (alist gnus-header-button-alist)
4242 (article-narrow-to-head)
4244 ;; Each alist entry.
4245 (setq entry (car alist)
4247 (goto-char (point-min))
4248 (while (re-search-forward (car entry) nil t)
4249 ;; Each header matching the entry.
4250 (setq beg (match-beginning 0))
4251 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4252 (match-beginning 0))
4255 (while (re-search-forward (nth 1 entry) end t)
4256 ;; Each match within a header.
4257 (let* ((entry (cdr entry))
4258 (start (match-beginning (nth 1 entry)))
4259 (end (match-end (nth 1 entry)))
4260 (form (nth 2 entry)))
4261 (goto-char (match-end 0))
4263 (gnus-article-add-button
4264 start end (nth 3 entry)
4265 (buffer-substring (match-beginning (nth 4 entry))
4266 (match-end (nth 4 entry)))))))
4267 (goto-char end)))))))
4269 ;;; External functions:
4271 (defun gnus-article-add-button (from to fun &optional data)
4272 "Create a button between FROM and TO with callback FUN and data DATA."
4273 (when gnus-article-button-face
4274 (gnus-overlay-put (gnus-make-overlay from to)
4275 'face gnus-article-button-face))
4276 (gnus-add-text-properties
4278 (nconc (and gnus-article-mouse-face
4279 (list gnus-mouse-face-prop gnus-article-mouse-face))
4280 (list 'gnus-callback fun)
4281 (and data (list 'gnus-data data))))
4282 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4283 :button-keymap gnus-widget-button-keymap))
4285 ;;; Internal functions:
4287 (defun gnus-article-set-globals ()
4289 (set-buffer gnus-summary-buffer)
4290 (gnus-set-global-variables)))
4292 (defun gnus-signature-toggle (end)
4294 (set-buffer gnus-article-buffer)
4295 (let ((buffer-read-only nil)
4296 (inhibit-point-motion-hooks t))
4297 (if (get-text-property end 'invisible)
4298 (gnus-article-unhide-text end (point-max))
4299 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4301 (defun gnus-button-entry ()
4302 ;; Return the first entry in `gnus-button-alist' matching this place.
4303 (let ((alist gnus-button-alist)
4306 (setq entry (pop alist))
4307 (if (looking-at (car entry))
4312 (defun gnus-button-push (marker)
4313 ;; Push button starting at MARKER.
4316 (let* ((entry (gnus-button-entry))
4317 (inhibit-point-motion-hooks t)
4319 (args (mapcar (lambda (group)
4320 (let ((string (match-string group)))
4321 (gnus-set-text-properties
4322 0 (length string) nil string)
4329 (fboundp (symbol-value fun)))
4330 (apply (symbol-value fun) args))
4332 (gnus-message 1 "You must define `%S' to use this button"
4333 (cons fun args)))))))
4335 (defun gnus-button-message-id (message-id)
4338 (set-buffer gnus-summary-buffer)
4339 (gnus-summary-refer-article message-id)))
4341 (defun gnus-button-fetch-group (address)
4342 "Fetch GROUP specified by ADDRESS."
4343 (if (not (string-match "[:/]" address))
4344 ;; This is just a simple group url.
4345 (gnus-group-read-ephemeral-group address gnus-select-method)
4346 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4348 (error "Can't parse %s" address)
4349 (gnus-group-read-ephemeral-group
4350 (match-string 4 address)
4351 `(nntp ,(match-string 1 address)
4352 (nntp-address ,(match-string 1 address))
4353 (nntp-port-number ,(if (match-end 3)
4354 (match-string 3 address)
4357 (defun gnus-url-parse-query-string (query &optional downcase)
4358 (let (retval pairs cur key val)
4359 (setq pairs (split-string query "&"))
4361 (setq cur (car pairs)
4363 (if (not (string-match "=" cur))
4365 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4366 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4368 (setq key (downcase key)))
4369 (setq cur (assoc key retval))
4371 (setcdr cur (cons val (cdr cur)))
4372 (setq retval (cons (list key val) retval)))))
4375 (defun gnus-url-unhex (x)
4382 (defun gnus-url-unhex-string (str &optional allow-newlines)
4383 "Remove %XXX embedded spaces, etc in a url.
4384 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4385 decoding of carriage returns and line feeds in the string, which is normally
4386 forbidden in URL encoding."
4387 (setq str (or str ""))
4389 (case-fold-search t))
4390 (while (string-match "%[0-9a-f][0-9a-f]" str)
4391 (let* ((start (match-beginning 0))
4392 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4394 (gnus-url-unhex (elt str (+ start 2))))))
4396 tmp (substring str 0 start)
4399 (char-to-string code))
4400 ((or (= code ?\n) (= code ?\r))
4402 (t (char-to-string code))))
4403 str (substring str (match-end 0)))))
4404 (setq tmp (concat tmp str))
4407 (defun gnus-url-mailto (url)
4408 ;; Send mail to someone
4409 (when (string-match "mailto:/*\\(.*\\)" url)
4410 (setq url (substring url (match-beginning 1) nil)))
4411 (let (to args subject func)
4412 (if (string-match (regexp-quote "?") url)
4413 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4414 args (gnus-url-parse-query-string
4415 (substring url (match-end 0) nil) t))
4416 (setq to (gnus-url-unhex-string url)))
4417 (setq args (cons (list "to" to) args)
4418 subject (cdr-safe (assoc "subject" args)))
4421 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4424 (message-position-on-field (caar args)))
4425 (insert (mapconcat 'identity (cdar args) ", "))
4426 (setq args (cdr args)))
4429 (message-goto-subject))))
4431 (defun gnus-button-mailto (address)
4433 (set-buffer (gnus-copy-article-buffer))
4434 (message-reply address))
4436 (defun gnus-button-reply (address)
4437 ;; Reply to ADDRESS.
4438 (message-reply address))
4440 (defun gnus-button-embedded-url (address)
4442 (browse-url (gnus-strip-whitespace address)))
4444 ;;; Next/prev buttons in the article buffer.
4446 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4447 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4449 (defvar gnus-prev-page-map nil)
4450 (unless gnus-prev-page-map
4451 (setq gnus-prev-page-map (make-sparse-keymap))
4452 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4453 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4455 (defun gnus-insert-prev-page-button ()
4456 (let ((buffer-read-only nil))
4458 gnus-prev-page-line-format nil
4459 `(gnus-prev t local-map ,gnus-prev-page-map
4460 gnus-callback gnus-article-button-prev-page
4461 article-type annotation))))
4463 (defvar gnus-next-page-map nil)
4464 (unless gnus-next-page-map
4465 (setq gnus-next-page-map (make-keymap))
4466 (suppress-keymap gnus-prev-page-map)
4467 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4468 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4470 (defun gnus-button-next-page ()
4471 "Go to the next page."
4473 (let ((win (selected-window)))
4474 (select-window (get-buffer-window gnus-article-buffer t))
4475 (gnus-article-next-page)
4476 (select-window win)))
4478 (defun gnus-button-prev-page ()
4479 "Go to the prev page."
4481 (let ((win (selected-window)))
4482 (select-window (get-buffer-window gnus-article-buffer t))
4483 (gnus-article-prev-page)
4484 (select-window win)))
4486 (defun gnus-insert-next-page-button ()
4487 (let ((buffer-read-only nil))
4488 (gnus-eval-format gnus-next-page-line-format nil
4490 t local-map ,gnus-next-page-map
4491 gnus-callback gnus-article-button-next-page
4492 article-type annotation))))
4494 (defun gnus-article-button-next-page (arg)
4495 "Go to the next page."
4497 (let ((win (selected-window)))
4498 (select-window (get-buffer-window gnus-article-buffer t))
4499 (gnus-article-next-page)
4500 (select-window win)))
4502 (defun gnus-article-button-prev-page (arg)
4503 "Go to the prev page."
4505 (let ((win (selected-window)))
4506 (select-window (get-buffer-window gnus-article-buffer t))
4507 (gnus-article-prev-page)
4508 (select-window win)))
4510 (defvar gnus-decode-header-methods
4511 '(mail-decode-encoded-word-region)
4512 "List of methods used to decode headers.
4514 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4515 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4516 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4517 whose names match REGEXP.
4520 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4521 mail-decode-encoded-word-region
4522 (\"chinese\" . rfc1843-decode-region))
4525 (defvar gnus-decode-header-methods-cache nil)
4527 (defun gnus-multi-decode-header (start end)
4528 "Apply the functions from `gnus-encoded-word-methods' that match."
4529 (unless (and gnus-decode-header-methods-cache
4530 (eq gnus-newsgroup-name
4531 (car gnus-decode-header-methods-cache)))
4532 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4535 (nconc gnus-decode-header-methods-cache (list x))
4536 (if (and gnus-newsgroup-name
4537 (string-match (car x) gnus-newsgroup-name))
4538 (nconc gnus-decode-header-methods-cache
4540 gnus-decode-header-methods))
4541 (let ((xlist gnus-decode-header-methods-cache))
4544 (narrow-to-region start end)
4546 (funcall (pop xlist) (point-min) (point-max))))))
4549 ;;; Treatment top-level handling.
4552 (defun gnus-treat-article (condition &optional part-number total-parts type)
4553 (let ((length (- (point-max) (point-min)))
4554 (alist gnus-treatment-function-alist)
4555 (article-goto-body-goes-to-point-min-p t)
4559 (let ((list gnus-article-treat-types))
4561 (when (string-match (pop list) type)
4562 (throw 'found t)))))))
4563 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4565 (gnus-run-hooks 'gnus-part-display-hook)
4566 (while (setq elem (pop alist))
4567 (setq val (symbol-value (car elem)))
4568 (when (and (or (consp val)
4570 (gnus-treat-predicate val)
4571 (or (not (get (car elem) 'highlight))
4574 (funcall (cadr elem)))))))
4576 ;; Dynamic variables.
4577 (defvar part-number)
4578 (defvar total-parts)
4582 (defun gnus-treat-predicate (val)
4587 (stringp (car val)))
4588 (apply 'gnus-or (mapcar `(lambda (s)
4589 (string-match s ,(or gnus-newsgroup-name "")))
4592 (let ((pred (pop val)))
4595 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4597 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4599 (not (gnus-treat-predicate (car val))))
4601 (equal (car val) type))
4603 (error "%S is not a valid predicate" pred)))))
4611 (eq part-number total-parts))
4615 (error "%S is not a valid value" val))))
4621 (run-hooks 'gnus-art-load-hook)
4623 ;;; gnus-art.el ends here