1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
41 ;; Avoid byte-compile warnings.
43 (defvar gnus-article-decoded-p)
44 (defvar gnus-article-mime-handles)
53 (defgroup gnus-article nil
55 :link '(custom-manual "(gnus)The Article Buffer")
58 (defgroup gnus-article-treat nil
59 "Treating article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
63 (defgroup gnus-article-hiding nil
64 "Hiding article parts."
65 :link '(custom-manual "(gnus)Article Hiding")
68 (defgroup gnus-article-highlight nil
69 "Article highlighting."
70 :link '(custom-manual "(gnus)Article Highlighting")
74 (defgroup gnus-article-signature nil
76 :link '(custom-manual "(gnus)Article Signature")
79 (defgroup gnus-article-headers nil
81 :link '(custom-manual "(gnus)Hiding Headers")
84 (defgroup gnus-article-washing nil
85 "Special commands on articles."
86 :link '(custom-manual "(gnus)Article Washing")
89 (defgroup gnus-article-emphasis nil
90 "Fontisizing articles."
91 :link '(custom-manual "(gnus)Article Fontisizing")
94 (defgroup gnus-article-saving nil
96 :link '(custom-manual "(gnus)Saving Articles")
99 (defgroup gnus-article-mime nil
100 "Worshiping the MIME wonder."
101 :link '(custom-manual "(gnus)Using MIME")
102 :group 'gnus-article)
104 (defgroup gnus-article-buttons nil
105 "Pushable buttons in the article buffer."
106 :link '(custom-manual "(gnus)Article Buttons")
107 :group 'gnus-article)
109 (defgroup gnus-article-various nil
110 "Other article options."
111 :link '(custom-manual "(gnus)Misc Article")
112 :group 'gnus-article)
114 (defcustom gnus-ignored-headers
115 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
116 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
117 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
118 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
119 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
120 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
121 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
122 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
123 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
124 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
125 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
126 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
127 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
128 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
129 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
130 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
131 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
132 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
133 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:")
134 "*All headers that start with this regexp will be hidden.
135 This variable can also be a list of regexps of headers to be ignored.
136 If `gnus-visible-headers' is non-nil, this variable will be ignored."
137 :type '(choice :custom-show nil
140 :group 'gnus-article-hiding)
142 (defcustom gnus-visible-headers
143 "^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:"
144 "*All headers that do not match this regexp will be hidden.
145 This variable can also be a list of regexp of headers to remain visible.
146 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
147 :type '(repeat :value-to-internal (lambda (widget value)
148 (custom-split-regexp-maybe value))
149 :match (lambda (widget value)
151 (widget-editable-list-match widget value)))
153 :group 'gnus-article-hiding)
155 (defcustom gnus-sorted-header-list
156 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
157 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
158 "*This variable is a list of regular expressions.
159 If it is non-nil, headers that match the regular expressions will
160 be placed first in the article buffer in the sequence specified by
162 :type '(repeat regexp)
163 :group 'gnus-article-hiding)
165 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
166 "Headers that are only to be displayed if they have interesting data.
167 Possible values in this list are `empty', `newsgroups', `followup-to',
168 `reply-to', `date', `long-to', and `many-to'."
169 :type '(set (const :tag "Headers with no content." empty)
170 (const :tag "Newsgroups with only one group." newsgroups)
171 (const :tag "Followup-to identical to newsgroups." followup-to)
172 (const :tag "Reply-to identical to from." reply-to)
173 (const :tag "Date less than four days old." date)
174 (const :tag "Very long To header." long-to)
175 (const :tag "Multiple To headers." many-to))
176 :group 'gnus-article-hiding)
178 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
179 "Regexp matching signature separator.
180 This can also be a list of regexps. In that case, it will be checked
181 from head to tail looking for a separator. Searches will be done from
182 the end of the buffer."
183 :type '(repeat string)
184 :group 'gnus-article-signature)
186 (defcustom gnus-signature-limit nil
187 "Provide a limit to what is considered a signature.
188 If it is a number, no signature may not be longer (in characters) than
189 that number. If it is a floating point number, no signature may be
190 longer (in lines) than that number. If it is a function, the function
191 will be called without any parameters, and if it returns nil, there is
192 no signature in the buffer. If it is a string, it will be used as a
193 regexp. If it matches, the text in question is not a signature."
194 :type '(choice (integer :value 200)
196 (function :value fun)
197 (regexp :value ".*"))
198 :group 'gnus-article-signature)
200 (defcustom gnus-hidden-properties '(invisible t intangible t)
201 "Property list to use for hiding text."
203 :group 'gnus-article-hiding)
205 (defcustom gnus-article-x-face-command
206 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
207 "*String or function to be executed to display an X-Face header.
208 If it is a string, the command will be executed in a sub-shell
209 asynchronously. The compressed face will be piped to this command."
210 :type 'string ;Leave function case to Lisp.
211 :group 'gnus-article-washing)
213 (defcustom gnus-article-x-face-too-ugly nil
214 "Regexp matching posters whose face shouldn't be shown automatically."
215 :type '(choice regexp (const nil))
216 :group 'gnus-article-washing)
218 (defcustom gnus-emphasis-alist
220 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
222 '(("_" "_" underline)
225 ("_/" "/_" underline-italic)
226 ("_\\*" "\\*_" underline-bold)
227 ("\\*/" "/\\*" bold-italic)
228 ("_\\*/" "/\\*_" underline-bold-italic))))
229 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
230 2 3 gnus-emphasis-underline)
234 (format format (car spec) (cadr spec))
235 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
237 "*Alist that says how to fontify certain phrases.
238 Each item looks like this:
240 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
242 The first element is a regular expression to be matched. The second
243 is a number that says what regular expression grouping used to find
244 the entire emphasized word. The third is a number that says what
245 regexp grouping should be displayed and highlighted. The fourth
246 is the face used for highlighting."
247 :type '(repeat (list :value ("" 0 0 default)
249 (integer :tag "Match group")
250 (integer :tag "Emphasize group")
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-bold '((t (:bold t)))
255 "Face used for displaying strong emphasized text (*word*)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-italic '((t (:italic t)))
259 "Face used for displaying italic emphasized text (/word/)."
260 :group 'gnus-article-emphasis)
262 (defface gnus-emphasis-underline '((t (:underline t)))
263 "Face used for displaying underlined emphasized text (_word_)."
264 :group 'gnus-article-emphasis)
266 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
267 "Face used for displaying underlined bold emphasized text (_*word*_)."
268 :group 'gnus-article-emphasis)
270 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
271 "Face used for displaying underlined italic emphasized text (_*word*_)."
272 :group 'gnus-article-emphasis)
274 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
275 "Face used for displaying bold italic emphasized text (/*word*/)."
276 :group 'gnus-article-emphasis)
278 (defface gnus-emphasis-underline-bold-italic
279 '((t (:bold t :italic t :underline t)))
280 "Face used for displaying underlined bold italic emphasized text.
281 Esample: (_/*word*/_)."
282 :group 'gnus-article-emphasis)
284 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
285 "Format for display of Date headers in article bodies.
286 See `format-time-string' for the possible values.
288 The variable can also be function, which should return a complete Date
289 header. The function is called with one argument, the time, which can
290 be fed to `format-time-string'."
291 :type '(choice string symbol)
292 :link '(custom-manual "(gnus)Article Date")
293 :group 'gnus-article-washing)
296 (autoload 'mail-extract-address-components "mail-extr"))
298 (defcustom gnus-save-all-headers t
299 "*If non-nil, don't remove any headers before saving."
300 :group 'gnus-article-saving
303 (defcustom gnus-prompt-before-saving 'always
304 "*This variable says how much prompting is to be done when saving articles.
305 If it is nil, no prompting will be done, and the articles will be
306 saved to the default files. If this variable is `always', each and
307 every article that is saved will be preceded by a prompt, even when
308 saving large batches of articles. If this variable is neither nil not
309 `always', there the user will be prompted once for a file name for
310 each invocation of the saving commands."
311 :group 'gnus-article-saving
312 :type '(choice (item always)
313 (item :tag "never" nil)
314 (sexp :tag "once" :format "%t\n" :value t)))
316 (defcustom gnus-saved-headers gnus-visible-headers
317 "Headers to keep if `gnus-save-all-headers' is nil.
318 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
319 If that variable is nil, however, all headers that match this regexp
320 will be kept while the rest will be deleted before saving."
321 :group 'gnus-article-saving
324 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
325 "A function to save articles in your favourite format.
326 The function must be interactively callable (in other words, it must
327 be an Emacs command).
329 Gnus provides the following functions:
331 * gnus-summary-save-in-rmail (Rmail format)
332 * gnus-summary-save-in-mail (Unix mail format)
333 * gnus-summary-save-in-folder (MH folder)
334 * gnus-summary-save-in-file (article format)
335 * gnus-summary-save-in-vm (use VM's folder format)
336 * gnus-summary-write-to-file (article format -- overwrite)."
337 :group 'gnus-article-saving
338 :type '(radio (function-item gnus-summary-save-in-rmail)
339 (function-item gnus-summary-save-in-mail)
340 (function-item gnus-summary-save-in-folder)
341 (function-item gnus-summary-save-in-file)
342 (function-item gnus-summary-save-in-vm)
343 (function-item gnus-summary-write-to-file)))
345 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
346 "A function generating a file name to save articles in Rmail format.
347 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
348 :group 'gnus-article-saving
351 (defcustom gnus-mail-save-name 'gnus-plain-save-name
352 "A function generating a file name to save articles in Unix mail format.
353 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
354 :group 'gnus-article-saving
357 (defcustom gnus-folder-save-name 'gnus-folder-save-name
358 "A function generating a file name to save articles in MH folder.
359 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
360 :group 'gnus-article-saving
363 (defcustom gnus-file-save-name 'gnus-numeric-save-name
364 "A function generating a file name to save articles in article format.
365 The function is called with NEWSGROUP, HEADERS, and optional
367 :group 'gnus-article-saving
370 (defcustom gnus-split-methods
371 '((gnus-article-archive-name)
372 (gnus-article-nndoc-name))
373 "*Variable used to suggest where articles are to be saved.
374 For instance, if you would like to save articles related to Gnus in
375 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
376 you could set this variable to something like:
378 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
379 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
381 This variable is an alist where the where the key is the match and the
382 value is a list of possible files to save in if the match is non-nil.
384 If the match is a string, it is used as a regexp match on the
385 article. If the match is a symbol, that symbol will be funcalled
386 from the buffer of the article to be saved with the newsgroup as the
387 parameter. If it is a list, it will be evaled in the same buffer.
389 If this form or function returns a string, this string will be used as
390 a possible file name; and if it returns a non-nil list, that list will
391 be used as possible file names."
392 :group 'gnus-article-saving
393 :type '(repeat (choice (list :value (fun) function)
394 (cons :value ("" "") regexp (repeat string))
397 (defcustom gnus-article-display-method-for-mime
398 'gnus-article-display-mime-message
399 "Function to display a MIME message.
400 The function is called from the article buffer."
401 :group 'gnus-article-mime
404 (defcustom gnus-article-display-method-for-traditional
405 'gnus-article-display-traditional-message
406 "*Function to display a traditional message.
407 The function is called from the article buffer."
408 :group 'gnus-article-mime
411 (defcustom gnus-page-delimiter "^\^L"
412 "*Regexp describing what to use as article page delimiters.
413 The default value is \"^\^L\", which is a form linefeed at the
414 beginning of a line."
416 :group 'gnus-article-various)
418 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
419 "*The format specification for the article mode line.
420 See `gnus-summary-mode-line-format' for a closer description.
422 The following additional specs are available:
424 %w The article washing status.
425 %m The number of MIME parts in the article."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-mode-hook nil
430 "*A hook for Gnus article mode."
432 :group 'gnus-article-various)
434 (defcustom gnus-article-menu-hook nil
435 "*Hook run after the creation of the article mode menu."
437 :group 'gnus-article-various)
439 (defcustom gnus-article-prepare-hook nil
440 "*A hook called after an article has been prepared in the article buffer."
442 :group 'gnus-article-various)
444 (defcustom gnus-article-hide-pgp-hook nil
445 "*A hook called after successfully hiding a PGP signature."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-button-face 'bold
450 "Face used for highlighting buttons in the article buffer.
452 An article button is a piece of text that you can activate by pressing
453 `RET' or `mouse-2' above it."
455 :group 'gnus-article-buttons)
457 (defcustom gnus-article-mouse-face 'highlight
458 "Face used for mouse highlighting in the article buffer.
460 Article buttons will be displayed in this face when the cursor is
463 :group 'gnus-article-buttons)
465 (defcustom gnus-signature-face 'gnus-signature-face
466 "Face used for highlighting a signature in the article buffer.
467 Obsolete; use the face `gnus-signature-face' for customizations instead."
469 :group 'gnus-article-highlight
470 :group 'gnus-article-signature)
472 (defface gnus-signature-face
475 "Face used for highlighting a signature in the article buffer."
476 :group 'gnus-article-highlight
477 :group 'gnus-article-signature)
479 (defface gnus-header-from-face
482 (:foreground "spring green"))
485 (:foreground "red3"))
488 "Face used for displaying from headers."
489 :group 'gnus-article-headers
490 :group 'gnus-article-highlight)
492 (defface gnus-header-subject-face
495 (:foreground "SeaGreen3"))
498 (:foreground "red4"))
500 (:bold t :italic t)))
501 "Face used for displaying subject headers."
502 :group 'gnus-article-headers
503 :group 'gnus-article-highlight)
505 (defface gnus-header-newsgroups-face
508 (:foreground "yellow" :italic t))
511 (:foreground "MidnightBlue" :italic t))
514 "Face used for displaying newsgroups headers."
515 :group 'gnus-article-headers
516 :group 'gnus-article-highlight)
518 (defface gnus-header-name-face
521 (:foreground "SeaGreen"))
524 (:foreground "maroon"))
527 "Face used for displaying header names."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defface gnus-header-content-face
534 (:foreground "forest green" :italic t))
537 (:foreground "indianred4" :italic t))
539 (:italic t))) "Face used for displaying header content."
540 :group 'gnus-article-headers
541 :group 'gnus-article-highlight)
543 (defcustom gnus-header-face-alist
544 '(("From" nil gnus-header-from-face)
545 ("Subject" nil gnus-header-subject-face)
546 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
547 ("" gnus-header-name-face gnus-header-content-face))
548 "*Controls highlighting of article header.
550 An alist of the form (HEADER NAME CONTENT).
552 HEADER is a regular expression which should match the name of an
553 header header and NAME and CONTENT are either face names or nil.
555 The name of each header field will be displayed using the face
556 specified by the first element in the list where HEADER match the
557 header name and NAME is non-nil. Similarly, the content will be
558 displayed by the first non-nil matching CONTENT face."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight
561 :type '(repeat (list (regexp :tag "Header")
563 (item :tag "skip" nil)
564 (face :value default))
565 (choice :tag "Content"
566 (item :tag "skip" nil)
567 (face :value default)))))
569 (defcustom gnus-article-decode-hook nil
570 "*Hook run to decode charsets in articles."
571 :group 'gnus-article-headers
574 (defcustom gnus-display-mime-function 'gnus-display-mime
575 "Function to display MIME articles."
576 :group 'gnus-article-mime
579 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
580 "Function used to decode headers.")
582 (defvar gnus-article-dumbquotes-map
600 "Table for MS-to-Latin1 translation.")
602 (defcustom gnus-ignored-mime-types nil
603 "List of MIME types that should be ignored by Gnus."
604 :group 'gnus-article-mime
605 :type '(repeat regexp))
607 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
608 "List of MIME types that should not be given buttons when rendered."
609 :group 'gnus-article-mime
610 :type '(repeat regexp))
612 (defcustom gnus-article-mime-part-function nil
613 "Function called with a MIME handle as the argument.
614 This is meant for people who want to do something automatic based
615 on parts -- for instance, adding Vcard info to a database."
616 :group 'gnus-article-mime
619 (defcustom gnus-mime-multipart-functions nil
620 "An alist of MIME types to functions to display them.")
623 ;;; The treatment variables
626 (defvar gnus-part-display-hook nil
627 "Hook called on parts that are to receive treatment.")
629 (defvar gnus-article-treat-custom
630 '(choice (const :tag "Off" nil)
632 (const :tag "Header" head)
633 (const :tag "Last" last)
634 (integer :tag "Less")
635 (sexp :tag "Predicate")))
637 (defvar gnus-article-treat-head-custom
638 '(choice (const :tag "Off" nil)
639 (const :tag "Header" head)))
641 (defvar gnus-article-treat-types '("text/plain")
644 (defvar gnus-inhibit-treatment nil
645 "Whether to inhibit treatment.")
647 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
648 "Highlight the signature.
649 Valid values are nil, t, `head', `last', an integer or a predicate.
650 See the manual for details."
651 :group 'gnus-article-treat
652 :type gnus-article-treat-custom)
653 (put 'gnus-treat-highlight-signature 'highlight t)
655 (defcustom gnus-treat-buttonize t
657 Valid values are nil, t, `head', `last', an integer or a predicate.
658 See the manual for details."
659 :group 'gnus-article-treat
660 :type gnus-article-treat-custom)
661 (put 'gnus-treat-buttonize 'highlight t)
663 (defcustom gnus-treat-buttonize-head 'head
664 "Add buttons to the head.
665 Valid values are nil, t, `head', `last', an integer or a predicate.
666 See the manual for details."
667 :group 'gnus-article-treat
668 :type gnus-article-treat-head-custom)
669 (put 'gnus-treat-buttonize-head 'highlight t)
671 (defcustom gnus-treat-emphasize t
673 Valid values are nil, t, `head', `last', an integer or a predicate.
674 See the manual for details."
675 :group 'gnus-article-treat
676 :type gnus-article-treat-custom)
677 (put 'gnus-treat-emphasize 'highlight t)
679 (defcustom gnus-treat-strip-cr nil
680 "Remove carriage returns.
681 Valid values are nil, t, `head', `last', an integer or a predicate.
682 See the manual for details."
683 :group 'gnus-article-treat
684 :type gnus-article-treat-custom)
686 (defcustom gnus-treat-hide-headers 'head
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-head-custom)
693 (defcustom gnus-treat-hide-boring-headers nil
694 "Hide boring headers.
695 Valid values are nil, t, `head', `last', an integer or a predicate.
696 See the manual for details."
697 :group 'gnus-article-treat
698 :type gnus-article-treat-head-custom)
700 (defcustom gnus-treat-hide-signature nil
702 Valid values are nil, t, `head', `last', an integer or a predicate.
703 See the manual for details."
704 :group 'gnus-article-treat
705 :type gnus-article-treat-custom)
707 (defcustom gnus-treat-fill-article nil
709 Valid values are nil, t, `head', `last', an integer or a predicate.
710 See the manual for details."
711 :group 'gnus-article-treat
712 :type gnus-article-treat-custom)
714 (defcustom gnus-treat-hide-citation nil
716 Valid values are nil, t, `head', `last', an integer or a predicate.
717 See the manual for details."
718 :group 'gnus-article-treat
719 :type gnus-article-treat-custom)
721 (defcustom gnus-treat-strip-pgp t
722 "Strip PGP signatures.
723 Valid values are nil, t, `head', `last', an integer or a predicate.
724 See the manual for details."
725 :group 'gnus-article-treat
726 :type gnus-article-treat-custom)
728 (defcustom gnus-treat-strip-pem nil
729 "Strip PEM signatures.
730 Valid values are nil, t, `head', `last', an integer or a predicate.
731 See the manual for details."
732 :group 'gnus-article-treat
733 :type gnus-article-treat-custom)
735 (defcustom gnus-treat-strip-banner t
736 "Strip banners from articles.
737 The banner to be stripped is specified in the `banner' group parameter.
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-highlight-headers 'head
744 "Highlight the headers.
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-head-custom)
749 (put 'gnus-treat-highlight-headers 'highlight t)
751 (defcustom gnus-treat-highlight-citation t
752 "Highlight cited text.
753 Valid values are nil, t, `head', `last', an integer or a predicate.
754 See the manual for details."
755 :group 'gnus-article-treat
756 :type gnus-article-treat-custom)
757 (put 'gnus-treat-highlight-citation 'highlight t)
759 (defcustom gnus-treat-date-ut nil
760 "Display the Date in UT (GMT).
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-head-custom)
766 (defcustom gnus-treat-date-local nil
767 "Display the Date in the local timezone.
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-head-custom)
773 (defcustom gnus-treat-date-lapsed nil
774 "Display the Date header in a way that says how much time has elapsed.
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-head-custom)
780 (defcustom gnus-treat-date-original nil
781 "Display the date in the original timezone.
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-head-custom)
787 (defcustom gnus-treat-date-iso8601 nil
788 "Display the date in the ISO8601 format.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-head-custom)
794 (defcustom gnus-treat-date-user-defined nil
795 "Display the date in a user-defined format.
796 The format is defined by the `gnus-article-time-format' variable.
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-strip-headers-in-body t
803 "Strip the X-No-Archive header line from the beginning of the body.
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-custom)
809 (defcustom gnus-treat-strip-trailing-blank-lines nil
810 "Strip trailing blank lines.
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-custom)
816 (defcustom gnus-treat-strip-leading-blank-lines nil
817 "Strip leading blank lines.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-custom)
823 (defcustom gnus-treat-strip-multiple-blank-lines nil
824 "Strip multiple blank lines.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-custom)
830 (defcustom gnus-treat-strip-blank-lines nil
831 "Strip all blank lines.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-custom)
837 (defcustom gnus-treat-overstrike t
838 "Treat overstrike highlighting.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-custom)
843 (put 'gnus-treat-overstrike 'highlight t)
845 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
847 "Display X-Face headers.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See the manual for details."
850 :group 'gnus-article-treat
851 :type gnus-article-treat-head-custom)
852 (put 'gnus-treat-display-xface 'highlight t)
854 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
858 Valid values are nil, t, `head', `last', an integer or a predicate.
859 See the manual for details."
860 :group 'gnus-article-treat
861 :type gnus-article-treat-custom)
862 (put 'gnus-treat-display-smileys 'highlight t)
864 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
866 Valid values are nil, t, `head', `last', an integer or a predicate.
867 See the manual for details."
868 :group 'gnus-article-treat
869 :type gnus-article-treat-head-custom)
870 (put 'gnus-treat-display-picons 'highlight t)
872 (defcustom gnus-treat-capitalize-sentences nil
873 "Capitalize sentence-starting words.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876 :group 'gnus-article-treat
877 :type gnus-article-treat-custom)
879 (defcustom gnus-treat-fill-long-lines 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-custom)
886 (defcustom gnus-treat-play-sounds nil
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-custom)
893 ;;; Internal variables
895 (defvar article-goto-body-goes-to-point-min-p nil)
896 (defvar gnus-article-wash-types nil)
898 (defvar gnus-article-mime-handle-alist-1 nil)
899 (defvar gnus-treatment-function-alist
900 '((gnus-treat-strip-banner gnus-article-strip-banner)
901 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
902 (gnus-treat-highlight-signature gnus-article-highlight-signature)
903 (gnus-treat-buttonize gnus-article-add-buttons)
904 (gnus-treat-fill-article gnus-article-fill-cited-article)
905 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
906 (gnus-treat-strip-cr gnus-article-remove-cr)
907 (gnus-treat-emphasize gnus-article-emphasize)
908 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
909 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
910 (gnus-treat-hide-signature gnus-article-hide-signature)
911 (gnus-treat-hide-citation gnus-article-hide-citation)
912 (gnus-treat-strip-pgp gnus-article-hide-pgp)
913 (gnus-treat-strip-pem gnus-article-hide-pem)
914 (gnus-treat-highlight-headers gnus-article-highlight-headers)
915 (gnus-treat-highlight-citation gnus-article-highlight-citation)
916 (gnus-treat-highlight-signature gnus-article-highlight-signature)
917 (gnus-treat-date-ut gnus-article-date-ut)
918 (gnus-treat-date-local gnus-article-date-local)
919 (gnus-treat-date-lapsed gnus-article-date-lapsed)
920 (gnus-treat-date-original gnus-article-date-original)
921 (gnus-treat-date-user-defined gnus-article-date-user)
922 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
923 (gnus-treat-strip-trailing-blank-lines
924 gnus-article-remove-trailing-blank-lines)
925 (gnus-treat-strip-leading-blank-lines
926 gnus-article-strip-leading-blank-lines)
927 (gnus-treat-strip-multiple-blank-lines
928 gnus-article-strip-multiple-blank-lines)
929 (gnus-treat-strip-blank-lines gnus-article-strip-blank-lines)
930 (gnus-treat-overstrike gnus-article-treat-overstrike)
931 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
932 (gnus-treat-display-xface gnus-article-display-x-face)
933 (gnus-treat-display-smileys gnus-smiley-display)
934 (gnus-treat-display-picons gnus-article-display-picons)
935 (gnus-treat-play-sounds gnus-earcon-display)))
937 (defvar gnus-article-mime-handle-alist nil)
938 (defvar article-lapsed-timer nil)
939 (defvar gnus-article-current-summary nil)
941 (defvar gnus-article-mode-syntax-table
942 (let ((table (copy-syntax-table text-mode-syntax-table)))
943 (modify-syntax-entry ?- "w" table)
944 (modify-syntax-entry ?> ")" table)
945 (modify-syntax-entry ?< "(" table)
947 "Syntax table used in article mode buffers.
948 Initialized from `text-mode-syntax-table.")
950 (defvar gnus-save-article-buffer nil)
952 (defvar gnus-article-mode-line-format-alist
953 (nconc '((?w (gnus-article-wash-status) ?s)
954 (?m (gnus-article-mime-part-status) ?s))
955 gnus-summary-mode-line-format-alist))
957 (defvar gnus-number-of-articles-to-be-saved nil)
959 (defvar gnus-inhibit-hiding nil)
961 (defsubst gnus-article-hide-text (b e props)
962 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
963 (add-text-properties b e props)
964 (when (memq 'intangible props)
966 (max (1- b) (point-min))
967 b 'intangible (cddr (memq 'intangible props)))))
968 (defsubst gnus-article-unhide-text (b e)
969 "Remove hidden text properties from region between B and E."
970 (remove-text-properties b e gnus-hidden-properties)
971 (when (memq 'intangible gnus-hidden-properties)
972 (put-text-property (max (1- b) (point-min))
975 (defun gnus-article-hide-text-type (b e type)
976 "Hide text of TYPE between B and E."
977 (push type gnus-article-wash-types)
978 (gnus-article-hide-text
979 b e (cons 'article-type (cons type gnus-hidden-properties))))
981 (defun gnus-article-unhide-text-type (b e type)
982 "Unhide text of TYPE between B and E."
983 (setq gnus-article-wash-types
984 (delq type gnus-article-wash-types))
985 (remove-text-properties
986 b e (cons 'article-type (cons type gnus-hidden-properties)))
987 (when (memq 'intangible gnus-hidden-properties)
988 (put-text-property (max (1- b) (point-min))
991 (defun gnus-article-hide-text-of-type (type)
992 "Hide text of TYPE in the current buffer."
994 (let ((b (point-min))
996 (while (setq b (text-property-any b e 'article-type type))
997 (add-text-properties b (incf b) gnus-hidden-properties)))))
999 (defun gnus-article-delete-text-of-type (type)
1000 "Delete text of TYPE in the current buffer."
1002 (let ((b (point-min)))
1003 (while (setq b (text-property-any b (point-max) 'article-type type))
1005 b (or (text-property-not-all b (point-max) 'article-type type)
1008 (defun gnus-article-delete-invisible-text ()
1009 "Delete all invisible text in the current buffer."
1011 (let ((b (point-min)))
1012 (while (setq b (text-property-any b (point-max) 'invisible t))
1014 b (or (text-property-not-all b (point-max) 'invisible t)
1017 (defun gnus-article-text-type-exists-p (type)
1018 "Say whether any text of type TYPE exists in the buffer."
1019 (text-property-any (point-min) (point-max) 'article-type type))
1021 (defsubst gnus-article-header-rank ()
1022 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1023 (let ((list gnus-sorted-header-list)
1026 (when (looking-at (car list))
1028 (setq list (cdr list))
1032 (defun article-hide-headers (&optional arg delete)
1033 "Toggle whether to hide unwanted headers and possibly sort them as well.
1034 If given a negative prefix, always show; if given a positive prefix,
1036 (interactive (gnus-article-hidden-arg))
1038 (if (gnus-article-check-hidden-text 'headers arg)
1039 ;; Show boring headers as well.
1041 (gnus-article-show-hidden-text 'boring-headers)
1042 (when (eq 1 (point-min))
1043 (set-window-start (get-buffer-window (current-buffer)) 1)))
1044 ;; This function might be inhibited.
1045 (unless gnus-inhibit-hiding
1048 (let ((buffer-read-only nil)
1049 (case-fold-search t)
1050 (props (nconc (list 'article-type 'headers)
1051 gnus-hidden-properties))
1052 (max (1+ (length gnus-sorted-header-list)))
1053 (ignored (when (not gnus-visible-headers)
1054 (cond ((stringp gnus-ignored-headers)
1055 gnus-ignored-headers)
1056 ((listp gnus-ignored-headers)
1057 (mapconcat 'identity gnus-ignored-headers
1060 (cond ((stringp gnus-visible-headers)
1061 gnus-visible-headers)
1062 ((and gnus-visible-headers
1063 (listp gnus-visible-headers))
1064 (mapconcat 'identity gnus-visible-headers "\\|"))))
1065 (inhibit-point-motion-hooks t)
1067 ;; First we narrow to just the headers.
1068 (goto-char (point-min))
1069 ;; Hide any "From " lines at the beginning of (mail) articles.
1070 (while (looking-at "From ")
1074 (delete-region (point-min) (point))
1075 (gnus-article-hide-text (point-min) (point) props)))
1076 ;; Then treat the rest of the header lines.
1079 (if (search-forward "\n\n" nil t) ; if there's a body
1080 (progn (forward-line -1) (point))
1082 ;; Then we use the two regular expressions
1083 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1084 ;; select which header lines is to remain visible in the
1086 (goto-char (point-min))
1087 (while (re-search-forward "^[^ \t]*:" nil t)
1089 ;; Mark the rank of the header.
1091 (point) (1+ (point)) 'message-rank
1092 (if (or (and visible (looking-at visible))
1094 (not (looking-at ignored))))
1095 (gnus-article-header-rank)
1098 (message-sort-headers-1)
1099 (when (setq beg (text-property-any
1100 (point-min) (point-max) 'message-rank (+ 2 max)))
1101 ;; We make the unwanted headers invisible.
1103 (delete-region beg (point-max))
1104 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1105 (gnus-article-hide-text-type beg (point-max) 'headers))
1106 ;; Work around XEmacs lossage.
1107 (put-text-property (point-min) beg 'invisible nil))))))))
1109 (defun article-hide-boring-headers (&optional arg)
1110 "Toggle hiding of headers that aren't very interesting.
1111 If given a negative prefix, always show; if given a positive prefix,
1113 (interactive (gnus-article-hidden-arg))
1114 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1115 (not gnus-show-all-headers))
1118 (let ((buffer-read-only nil)
1119 (list gnus-boring-article-headers)
1120 (inhibit-point-motion-hooks t)
1122 (article-narrow-to-head)
1124 (setq elem (pop list))
1125 (goto-char (point-min))
1127 ;; Hide empty headers.
1129 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1131 (gnus-article-hide-text-type
1132 (progn (beginning-of-line) (point))
1135 (if (re-search-forward "^[^ \t]" nil t)
1139 ;; Hide boring Newsgroups header.
1140 ((eq elem 'newsgroups)
1141 (when (equal (gnus-fetch-field "newsgroups")
1142 (gnus-group-real-name
1143 (if (boundp 'gnus-newsgroup-name)
1146 (gnus-article-hide-header "newsgroups")))
1147 ((eq elem 'followup-to)
1148 (when (equal (message-fetch-field "followup-to")
1149 (message-fetch-field "newsgroups"))
1150 (gnus-article-hide-header "followup-to")))
1151 ((eq elem 'reply-to)
1152 (let ((from (message-fetch-field "from"))
1153 (reply-to (message-fetch-field "reply-to")))
1158 (nth 1 (funcall gnus-extract-address-components from))
1159 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1160 (gnus-article-hide-header "reply-to"))))
1162 (let ((date (message-fetch-field "date")))
1164 (< (days-between (current-time-string) date)
1166 (gnus-article-hide-header "date"))))
1168 (let ((to (message-fetch-field "to")))
1169 (when (> (length to) 1024)
1170 (gnus-article-hide-header "to"))))
1173 (goto-char (point-min))
1174 (while (re-search-forward "^to:" nil t)
1175 (setq to-count (1+ to-count)))
1176 (when (> to-count 1)
1177 (while (> to-count 0)
1178 (goto-char (point-min))
1180 (re-search-forward "^to:" nil nil to-count)
1182 (narrow-to-region (point) (point-max))
1183 (gnus-article-hide-header "to"))
1184 (setq to-count (1- to-count)))))))))))))
1186 (defun gnus-article-hide-header (header)
1188 (goto-char (point-min))
1189 (when (re-search-forward (concat "^" header ":") nil t)
1190 (gnus-article-hide-text-type
1191 (progn (beginning-of-line) (point))
1194 (if (re-search-forward "^[^ \t]" nil t)
1199 (defvar gnus-article-normalized-header-length 40
1200 "Length of normalized headers.")
1202 (defun article-normalize-headers ()
1203 "Make all header lines 40 characters long."
1205 (let ((buffer-read-only nil)
1209 (article-narrow-to-head)
1212 ((< (setq column (- (gnus-point-at-eol) (point)))
1213 gnus-article-normalized-header-length)
1215 (insert (make-string
1216 (- gnus-article-normalized-header-length column)
1218 ((> column gnus-article-normalized-header-length)
1219 (gnus-put-text-property
1221 (forward-char gnus-article-normalized-header-length)
1228 (forward-line 1))))))
1230 (defun article-treat-dumbquotes ()
1231 "Translate M******** sm*rtq**t*s into proper text.
1232 Note that this function guesses whether a character is a sm*rtq**t* or
1233 not, so it should only be used interactively."
1235 (article-translate-strings gnus-article-dumbquotes-map))
1237 (defun article-translate-characters (from to)
1238 "Translate all characters in the body of the article according to FROM and TO.
1239 FROM is a string of characters to translate from; to is a string of
1240 characters to translate to."
1242 (when (article-goto-body)
1243 (let ((buffer-read-only nil)
1244 (x (make-string 225 ?x))
1246 (while (< (incf i) (length x))
1249 (while (< i (length from))
1250 (aset x (aref from i) (aref to i))
1252 (translate-region (point) (point-max) x)))))
1254 (defun article-translate-strings (map)
1255 "Translate all string in the body of the article according to MAP.
1256 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1258 (when (article-goto-body)
1259 (let ((buffer-read-only nil)
1261 (while (setq elem (pop map))
1263 (while (search-forward (car elem) nil t)
1264 (replace-match (cadr elem)))))))))
1266 (defun article-treat-overstrike ()
1267 "Translate overstrikes into bold text."
1270 (when (article-goto-body)
1271 (let ((buffer-read-only nil))
1272 (while (search-forward "\b" nil t)
1273 (let ((next (char-after))
1274 (previous (char-after (- (point) 2))))
1275 ;; We do the boldification/underlining by hiding the
1276 ;; overstrikes and putting the proper text property
1280 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1281 (put-text-property (point) (1+ (point)) 'face 'bold))
1283 (gnus-article-hide-text-type
1284 (1- (point)) (1+ (point)) 'overstrike)
1286 (- (point) 2) (1- (point)) 'face 'underline))
1288 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1290 (point) (1+ (point)) 'face 'underline)))))))))
1292 (defun article-fill-long-lines ()
1293 "Fill lines that are wider than the window width."
1296 (let ((buffer-read-only nil)
1297 (width (window-width (get-buffer-window (current-buffer)))))
1300 (let ((adaptive-fill-mode nil))
1303 (when (>= (current-column) (min fill-column width))
1304 (narrow-to-region (point) (gnus-point-at-bol))
1305 (fill-paragraph nil)
1306 (goto-char (point-max))
1308 (forward-line 1)))))))
1310 (defun article-capitalize-sentences ()
1311 "Capitalize the first word in each sentence."
1314 (let ((buffer-read-only nil)
1315 (paragraph-start "^[\n\^L]"))
1319 (forward-sentence)))))
1321 (defun article-remove-cr ()
1322 "Remove trailing CRs and then translate remaining CRs into LFs."
1325 (let ((buffer-read-only nil))
1326 (goto-char (point-min))
1327 (while (re-search-forward "\r+$" nil t)
1328 (replace-match "" t t))
1329 (goto-char (point-min))
1330 (while (search-forward "\r" nil t)
1331 (replace-match "\n" t t)))))
1333 (defun article-remove-trailing-blank-lines ()
1334 "Remove all trailing blank lines from the article."
1337 (let ((buffer-read-only nil))
1338 (goto-char (point-max))
1342 (while (and (not (bobp))
1343 (looking-at "^[ \t]*$")
1344 (not (gnus-annotation-in-region-p
1345 (point) (gnus-point-at-eol))))
1350 (defun article-display-x-face (&optional force)
1351 "Look for an X-Face header and display it if present."
1352 (interactive (list 'force))
1354 ;; Delete the old process, if any.
1355 (when (process-status "article-x-face")
1356 (delete-process "article-x-face"))
1357 (let ((inhibit-point-motion-hooks t)
1358 (case-fold-search t)
1361 (article-narrow-to-head)
1362 (goto-char (point-min))
1363 (setq from (message-fetch-field "from"))
1364 (goto-char (point-min))
1365 (while (and gnus-article-x-face-command
1368 ;; Check whether this face is censored.
1369 (not gnus-article-x-face-too-ugly)
1370 (and gnus-article-x-face-too-ugly from
1371 (not (string-match gnus-article-x-face-too-ugly
1373 ;; Has to be present.
1374 (re-search-forward "^X-Face: " nil t))
1375 ;; This used to try to do multiple faces (`while' instead of
1376 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1377 ;; work (b) it can crash some versions of Emacs (c) are
1378 ;; multiple faces really something to encourage?
1379 (when (stringp gnus-article-x-face-command)
1381 ;; We now have the area of the buffer where the X-Face is stored.
1384 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1385 ;; We display the face.
1386 (if (symbolp gnus-article-x-face-command)
1387 ;; The command is a lisp function, so we call it.
1388 (if (gnus-functionp gnus-article-x-face-command)
1389 (funcall gnus-article-x-face-command beg end)
1390 (error "%s is not a function" gnus-article-x-face-command))
1391 ;; The command is a string, so we interpret the command
1392 ;; as a, well, command, and fork it off.
1393 (let ((process-connection-type nil))
1394 (process-kill-without-query
1396 "article-x-face" nil shell-file-name shell-command-switch
1397 gnus-article-x-face-command))
1398 (process-send-region "article-x-face" beg end)
1399 (process-send-eof "article-x-face"))))))))))
1401 (defun article-decode-mime-words ()
1402 "Decode all MIME-encoded words in the article."
1405 (set-buffer gnus-article-buffer)
1406 (let ((inhibit-point-motion-hooks t)
1408 (mail-parse-charset gnus-newsgroup-charset))
1409 (mail-decode-encoded-word-region (point-min) (point-max)))))
1411 (defun article-decode-charset (&optional prompt)
1412 "Decode charset-encoded text in the article.
1413 If PROMPT (the prefix), prompt for a coding system to use."
1417 (article-narrow-to-head)
1418 (let* ((inhibit-point-motion-hooks t)
1419 (case-fold-search t)
1420 (ct (message-fetch-field "Content-Type" t))
1421 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1422 (ctl (and ct (ignore-errors
1423 (mail-header-parse-content-type ct))))
1426 (mm-read-coding-system "Charset to decode: "))
1428 (mail-content-type-get ctl 'charset))))
1429 (mail-parse-charset gnus-newsgroup-charset)
1431 (when (memq charset gnus-newsgroup-ignored-charsets)
1433 (goto-char (point-max))
1436 (narrow-to-region (point) (point-max))
1437 (when (and (or (not ctl)
1438 (equal (car ctl) "text/plain"))
1441 charset (and cte (intern (downcase
1442 (gnus-strip-whitespace cte))))
1445 (defun article-decode-encoded-words ()
1446 "Remove encoded-word encoding from headers."
1447 (let (buffer-read-only)
1448 (let ((charset (save-excursion
1449 (set-buffer gnus-summary-buffer)
1450 default-mime-charset)))
1451 (mime-decode-header-in-buffer charset)
1454 (defun article-de-quoted-unreadable (&optional force)
1455 "Translate a quoted-printable-encoded article.
1456 If FORCE, decode the article whether it is marked as quoted-printable
1458 (interactive (list 'force))
1460 (let ((buffer-read-only nil)
1461 (type (gnus-fetch-field "content-transfer-encoding"))
1462 (charset gnus-newsgroup-charset))
1464 (and type (string-match "quoted-printable" (downcase type))))
1467 (narrow-to-region (point) (point-max))
1468 (quoted-printable-decode-region (point-min) (point-max))
1470 (mm-decode-body charset)))))))
1472 (defun article-hide-pgp ()
1473 "Remove any PGP headers and signatures in the current article."
1477 (let ((inhibit-point-motion-hooks t)
1478 buffer-read-only beg end)
1480 ;; Hide the "header".
1481 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1482 (push 'pgp gnus-article-wash-types)
1483 (delete-region (match-beginning 0) (match-end 0))
1484 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1485 (when (looking-at "Hash:.*$")
1486 (delete-region (point) (1+ (gnus-point-at-eol))))
1488 ;; Hide the actual signature.
1489 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1490 (setq end (1+ (match-beginning 0)))
1493 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1495 ;; Perhaps we shouldn't hide to the end of the buffer
1496 ;; if there is no end to the signature?
1498 ;; Hide "- " PGP quotation markers.
1500 (narrow-to-region beg end)
1501 (goto-char (point-min))
1502 (while (re-search-forward "^- " nil t)
1504 (match-beginning 0) (match-end 0)))
1506 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1508 (defun article-hide-pem (&optional arg)
1509 "Toggle hiding of any PEM headers and signatures in the current article.
1510 If given a negative prefix, always show; if given a positive prefix,
1512 (interactive (gnus-article-hidden-arg))
1513 (unless (gnus-article-check-hidden-text 'pem arg)
1515 (let (buffer-read-only end)
1516 (goto-char (point-min))
1517 ;; Hide the horrendously ugly "header".
1518 (when (and (search-forward
1519 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1521 (setq end (1+ (match-beginning 0))))
1522 (push 'pem gnus-article-wash-types)
1523 (gnus-article-hide-text-type
1525 (if (search-forward "\n\n" nil t)
1529 ;; Hide the trailer as well
1530 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1532 (gnus-article-hide-text-type
1533 (match-beginning 0) (match-end 0) 'pem)))))))
1535 (defun article-strip-banner ()
1536 "Strip the banner specified by the `banner' group parameter."
1540 (let ((inhibit-point-motion-hooks t)
1541 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1542 (gnus-signature-limit nil)
1543 buffer-read-only beg end)
1547 ((eq banner 'signature)
1548 (when (gnus-article-narrow-to-signature)
1551 (delete-region (point) (point-max))))
1553 (while (re-search-forward banner nil t)
1554 (delete-region (match-beginning 0) (match-end 0))))))))))
1556 (defun article-hide-signature (&optional arg)
1557 "Hide the signature in the current article.
1558 If given a negative prefix, always show; if given a positive prefix,
1560 (interactive (gnus-article-hidden-arg))
1561 (unless (gnus-article-check-hidden-text 'signature arg)
1564 (let ((buffer-read-only nil))
1565 (when (gnus-article-narrow-to-signature)
1566 (gnus-article-hide-text-type
1567 (point-min) (point-max) 'signature)))))))
1569 (defun article-strip-headers-in-body ()
1570 "Strip offensive headers from bodies."
1574 (let ((case-fold-search t))
1575 (when (looking-at "x-no-archive:")
1576 (gnus-delete-line)))))
1578 (defun article-strip-leading-blank-lines ()
1579 "Remove all blank lines from the beginning of the article."
1582 (let ((inhibit-point-motion-hooks t)
1584 (when (article-goto-body)
1585 (while (and (not (eobp))
1586 (looking-at "[ \t]*$"))
1587 (gnus-delete-line))))))
1589 (defun article-narrow-to-head ()
1590 "Narrow the buffer to the head of the message.
1591 Point is left at the beginning of the narrowed-to region."
1593 (goto-char (point-min))
1594 (if (search-forward "\n\n" nil 1)
1597 (goto-char (point-min)))
1599 (defun article-goto-body ()
1600 "Place point at the start of the body."
1601 (goto-char (point-min))
1603 ;; This variable is only bound when dealing with separate
1605 (article-goto-body-goes-to-point-min-p
1607 ((search-forward "\n\n" nil t)
1610 (goto-char (point-max))
1613 (defun article-strip-multiple-blank-lines ()
1614 "Replace consecutive blank lines with one empty line."
1617 (let ((inhibit-point-motion-hooks t)
1619 ;; First make all blank lines empty.
1621 (while (re-search-forward "^[ \t]+$" nil t)
1622 (unless (gnus-annotation-in-region-p
1623 (match-beginning 0) (match-end 0))
1624 (replace-match "" nil t)))
1625 ;; Then replace multiple empty lines with a single empty line.
1627 (while (re-search-forward "\n\n\n+" nil t)
1628 (unless (gnus-annotation-in-region-p
1629 (match-beginning 0) (match-end 0))
1630 (replace-match "\n\n" t t))))))
1632 (defun article-strip-leading-space ()
1633 "Remove all white space from the beginning of the lines in the article."
1636 (let ((inhibit-point-motion-hooks t)
1639 (while (re-search-forward "^[ \t]+" nil t)
1640 (replace-match "" t t)))))
1642 (defun article-strip-trailing-space ()
1643 "Remove all white space from the end of the lines in the article."
1646 (let ((inhibit-point-motion-hooks t)
1649 (while (re-search-forward "[ \t]+$" nil t)
1650 (replace-match "" t t)))))
1652 (defun article-strip-blank-lines ()
1653 "Strip leading, trailing and multiple blank lines."
1655 (article-strip-leading-blank-lines)
1656 (article-remove-trailing-blank-lines)
1657 (article-strip-multiple-blank-lines))
1659 (defun article-strip-all-blank-lines ()
1660 "Strip all blank lines."
1663 (let ((inhibit-point-motion-hooks t)
1666 (while (re-search-forward "^[ \t]*\n" nil t)
1667 (replace-match "" t t)))))
1669 (defun gnus-article-narrow-to-signature ()
1670 "Narrow to the signature; return t if a signature is found, else nil."
1671 (let ((inhibit-point-motion-hooks t))
1672 (when (gnus-article-search-signature)
1674 ;; Check whether we have some limits to what we consider
1675 ;; to be a signature.
1676 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1677 (list gnus-signature-limit)))
1679 (while (setq limit (pop limits))
1680 (if (or (and (integerp limit)
1681 (< (- (point-max) (point)) limit))
1683 (< (count-lines (point) (point-max)) limit))
1684 (and (gnus-functionp limit)
1686 (and (stringp limit)
1687 (not (re-search-forward limit nil t))))
1688 () ; This limit did not succeed.
1692 (narrow-to-region (point) (point-max))
1695 (defun gnus-article-search-signature ()
1696 "Search the current buffer for the signature separator.
1697 Put point at the beginning of the signature separator."
1698 (let ((cur (point)))
1699 (goto-char (point-max))
1700 (if (if (stringp gnus-signature-separator)
1701 (re-search-backward gnus-signature-separator nil t)
1702 (let ((seps gnus-signature-separator))
1704 (not (re-search-backward (car seps) nil t)))
1711 (defun gnus-article-hidden-arg ()
1712 "Return the current prefix arg as a number, or 0 if no prefix."
1713 (list (if current-prefix-arg
1714 (prefix-numeric-value current-prefix-arg)
1717 (defun gnus-article-check-hidden-text (type arg)
1718 "Return nil if hiding is necessary.
1719 Arg can be nil or a number. Nil and positive means hide, negative
1720 means show, 0 means toggle."
1723 (let ((hide (gnus-article-hidden-text-p type)))
1729 (gnus-article-show-hidden-text type))
1731 (if (eq hide 'hidden)
1732 (gnus-article-show-hidden-text type)
1735 (defun gnus-article-hidden-text-p (type)
1736 "Say whether the current buffer contains hidden text of type TYPE."
1737 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1739 (not (get-text-property pos 'invisible)))
1741 (text-property-any (1+ pos) (point-max) 'article-type type)))
1746 (defun gnus-article-show-hidden-text (type &optional hide)
1747 "Show all hidden text of type TYPE.
1748 If HIDE, hide the text instead."
1750 (let ((buffer-read-only nil)
1751 (inhibit-point-motion-hooks t)
1754 (while (setq beg (text-property-any end (point-max) 'article-type type))
1757 (text-property-not-all beg (point-max) 'article-type type)
1760 (gnus-article-hide-text beg end gnus-hidden-properties)
1761 (gnus-article-unhide-text beg end))
1765 (defconst article-time-units
1766 `((year . ,(* 365.25 24 60 60))
1767 (week . ,(* 7 24 60 60))
1768 (day . ,(* 24 60 60))
1772 "Mapping from time units to seconds.")
1774 (defun article-date-ut (&optional type highlight header)
1775 "Convert DATE date to universal time in the current article.
1776 If TYPE is `local', convert to local time; if it is `lapsed', output
1777 how much time has lapsed since DATE."
1778 (interactive (list 'ut t))
1779 (let* ((header (or header
1780 (mail-header-date (save-excursion
1781 (set-buffer gnus-summary-buffer)
1782 gnus-current-headers))
1783 (message-fetch-field "date")
1785 (date (if (vectorp header) (mail-header-date header)
1787 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1788 (inhibit-point-motion-hooks t)
1789 bface eface newline)
1790 (when (and date (not (string= date "")))
1793 (article-narrow-to-head)
1794 (let ((buffer-read-only nil))
1795 ;; Delete any old Date headers.
1796 (if (re-search-forward date-regexp nil t)
1798 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1799 eface (get-text-property (1- (gnus-point-at-eol))
1801 (delete-region (progn (beginning-of-line) (point))
1802 (progn (end-of-line) (point)))
1803 (beginning-of-line))
1804 (goto-char (point-max))
1806 (insert (article-make-date-line date type))
1809 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1810 (put-text-property (match-beginning 1) (1+ (match-end 1))
1812 (put-text-property (match-beginning 2) (match-end 2)
1816 (insert "\n"))))))))
1818 (defun article-make-date-line (date type)
1819 "Return a DATE line of TYPE."
1820 (let ((time (condition-case ()
1824 ;; Convert to the local timezone. We have to slap a
1825 ;; `condition-case' round the calls to the timezone
1826 ;; functions since they aren't particularly resistant to
1829 (let ((tz (car (current-time-zone))))
1830 (format "Date: %s %s%04d" (current-time-string time)
1831 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1832 ;; Convert to Universal Time.
1835 (current-time-string
1836 (let* ((e (parse-time-string date))
1837 (tm (apply 'encode-time e))
1839 (ls (- (cadr tm) (car (current-time-zone)))))
1840 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1841 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1844 ;; Get the original date from the article.
1845 ((eq type 'original)
1846 (concat "Date: " (if (string-match "\n+$" date)
1847 (substring date 0 (match-beginning 0))
1849 ;; Let the user define the format.
1851 (if (gnus-functionp gnus-article-time-format)
1852 (funcall gnus-article-time-format time)
1855 (format-time-string gnus-article-time-format time))))
1860 (format-time-string "%Y%m%dT%H%M%S" time)))
1861 ;; Do an X-Sent lapsed format.
1863 ;; If the date is seriously mangled, the timezone functions are
1864 ;; liable to bug out, so we ignore all errors.
1865 (let* ((now (current-time))
1866 (real-time (subtract-time now time))
1867 (real-sec (and real-time
1868 (+ (* (float (car real-time)) 65536)
1870 (sec (and real-time (abs real-sec)))
1880 ;; This is a bit convoluted, but basically we go
1881 ;; through the time units for years, weeks, etc,
1882 ;; and divide things to see whether that results
1883 ;; in positive answers.
1886 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1887 ;; The (remaining) seconds are too few to
1888 ;; be divided into this time unit.
1890 ;; It's big enough, so we output it.
1891 (setq sec (- sec (* num (cdr unit))))
1893 (concat (if prev ", " "") (int-to-string
1895 " " (symbol-name (car unit))
1896 (if (> num 1) "s" ""))
1898 article-time-units "")
1899 ;; If dates are odd, then it might appear like the
1900 ;; article was sent in the future.
1903 " in the future"))))))
1905 (error "Unknown conversion type: %s" type)))))
1907 (defun article-date-local (&optional highlight)
1908 "Convert the current article date to the local timezone."
1909 (interactive (list t))
1910 (article-date-ut 'local highlight))
1912 (defun article-date-original (&optional highlight)
1913 "Convert the current article date to what it was originally.
1914 This is only useful if you have used some other date conversion
1915 function and want to see what the date was before converting."
1916 (interactive (list t))
1917 (article-date-ut 'original highlight))
1919 (defun article-date-lapsed (&optional highlight)
1920 "Convert the current article date to time lapsed since it was sent."
1921 (interactive (list t))
1922 (article-date-ut 'lapsed highlight))
1924 (defun article-update-date-lapsed ()
1925 "Function to be run from a timer to update the lapsed time line."
1926 (let (deactivate-mark)
1931 (set-buffer (window-buffer w))
1932 (when (eq major-mode 'gnus-article-mode)
1933 (goto-char (point-min))
1934 (when (re-search-forward "^X-Sent:" nil t)
1935 (article-date-lapsed t))))
1938 (defun gnus-start-date-timer (&optional n)
1939 "Start a timer to update the X-Sent header in the article buffers.
1940 The numerical prefix says how frequently (in seconds) the function
1945 (gnus-stop-date-timer)
1946 (setq article-lapsed-timer
1947 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1949 (defun gnus-stop-date-timer ()
1950 "Stop the X-Sent timer."
1952 (when article-lapsed-timer
1953 (nnheader-cancel-timer article-lapsed-timer)
1954 (setq article-lapsed-timer nil)))
1956 (defun article-date-user (&optional highlight)
1957 "Convert the current article date to the user-defined format.
1958 This format is defined by the `gnus-article-time-format' variable."
1959 (interactive (list t))
1960 (article-date-ut 'user highlight))
1962 (defun article-date-iso8601 (&optional highlight)
1963 "Convert the current article date to ISO8601."
1964 (interactive (list t))
1965 (article-date-ut 'iso8601 highlight))
1967 (defun article-show-all ()
1968 "Show all hidden text in the article buffer."
1971 (let ((buffer-read-only nil))
1972 (gnus-article-unhide-text (point-min) (point-max)))))
1974 (defun article-emphasize (&optional arg)
1975 "Emphasize text according to `gnus-emphasis-alist'."
1976 (interactive (gnus-article-hidden-arg))
1977 (unless (gnus-article-check-hidden-text 'emphasis arg)
1979 (let ((alist gnus-emphasis-alist)
1980 (buffer-read-only nil)
1981 (props (append '(article-type emphasis)
1982 gnus-hidden-properties))
1983 regexp elem beg invisible visible face)
1986 (while (setq elem (pop alist))
1988 (setq regexp (car elem)
1989 invisible (nth 1 elem)
1990 visible (nth 2 elem)
1992 (while (re-search-forward regexp nil t)
1993 (when (and (match-beginning visible) (match-beginning invisible))
1994 (gnus-article-hide-text
1995 (match-beginning invisible) (match-end invisible) props)
1996 (gnus-article-unhide-text-type
1997 (match-beginning visible) (match-end visible) 'emphasis)
1998 (gnus-put-text-property-excluding-newlines
1999 (match-beginning visible) (match-end visible) 'face face)
2000 (goto-char (match-end invisible)))))))))
2002 (defvar gnus-summary-article-menu)
2003 (defvar gnus-summary-post-menu)
2005 ;;; Saving functions.
2007 (defun gnus-article-save (save-buffer file &optional num)
2008 "Save the currently selected article."
2009 (unless gnus-save-all-headers
2010 ;; Remove headers according to `gnus-saved-headers'.
2011 (let ((gnus-visible-headers
2012 (or gnus-saved-headers gnus-visible-headers))
2013 (gnus-article-buffer save-buffer))
2015 (set-buffer save-buffer)
2016 (article-hide-headers 1 t))))
2017 (save-window-excursion
2018 (if (not gnus-default-article-saver)
2019 (error "No default saver is defined")
2020 ;; !!! Magic! The saving functions all save
2021 ;; `gnus-save-article-buffer' (or so they think), but we
2022 ;; bind that variable to our save-buffer.
2023 (set-buffer gnus-article-buffer)
2024 (let* ((gnus-save-article-buffer save-buffer)
2027 ((not gnus-prompt-before-saving) 'default)
2028 ((eq gnus-prompt-before-saving 'always) nil)
2030 (gnus-number-of-articles-to-be-saved
2031 (when (eq gnus-prompt-before-saving t)
2033 (set-buffer gnus-article-current-summary)
2034 (funcall gnus-default-article-saver filename)))))
2036 (defun gnus-read-save-file-name (prompt &optional filename
2037 function group headers variable)
2039 (funcall function group headers (symbol-value variable)))
2044 ((eq filename 'default)
2050 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2053 (if (and gnus-number-of-articles-to-be-saved
2054 (> gnus-number-of-articles-to-be-saved 1))
2055 (format "these %d articles"
2056 gnus-number-of-articles-to-be-saved)
2059 ;; Let the split methods have their say.
2061 ;; No split name was found.
2064 (concat prompt " (default "
2065 (file-name-nondirectory default-name) ") ")
2066 (file-name-directory default-name)
2068 ;; A single group name is returned.
2069 ((stringp split-name)
2071 (funcall function split-name headers
2072 (symbol-value variable)))
2074 (concat prompt " (default "
2075 (file-name-nondirectory default-name) ") ")
2076 (file-name-directory default-name)
2078 ;; A single split name was found
2079 ((= 1 (length split-name))
2080 (let* ((name (expand-file-name
2081 (car split-name) gnus-article-save-directory))
2082 (dir (cond ((file-directory-p name)
2083 (file-name-as-directory name))
2084 ((file-exists-p name) name)
2085 (t gnus-article-save-directory))))
2087 (concat prompt " (default " name ") ")
2089 ;; A list of splits was found.
2091 (setq split-name (nreverse split-name))
2093 (let ((file-name-history
2094 (nconc split-name file-name-history)))
2098 (concat prompt " (`M-p' for defaults) ")
2099 gnus-article-save-directory
2101 gnus-article-save-directory)))
2102 (car (push result file-name-history)))))))
2103 ;; Create the directory.
2104 (gnus-make-directory (file-name-directory file))
2105 ;; If we have read a directory, we append the default file name.
2106 (when (file-directory-p file)
2107 (setq file (concat (file-name-as-directory file)
2108 (file-name-nondirectory default-name))))
2109 ;; Possibly translate some characters.
2110 (nnheader-translate-file-chars file)))))
2111 (gnus-make-directory (file-name-directory result))
2112 (set variable result)))
2114 (defun gnus-article-archive-name (group)
2115 "Return the first instance of an \"Archive-name\" in the current buffer."
2116 (let ((case-fold-search t))
2117 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2118 (nnheader-concat gnus-article-save-directory
2119 (match-string 1)))))
2121 (defun gnus-article-nndoc-name (group)
2122 "If GROUP is an nndoc group, return the name of the parent group."
2123 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2124 (gnus-group-get-parameter group 'save-article-group)))
2126 (defun gnus-summary-save-in-rmail (&optional filename)
2127 "Append this article to Rmail file.
2128 Optional argument FILENAME specifies file name.
2129 Directory to save to is default to `gnus-article-save-directory'."
2130 (setq filename (gnus-read-save-file-name
2131 "Save %s in rmail file:" filename
2132 gnus-rmail-save-name gnus-newsgroup-name
2133 gnus-current-headers 'gnus-newsgroup-last-rmail))
2134 (gnus-eval-in-buffer-window gnus-save-article-buffer
2138 (gnus-output-to-rmail filename))))
2141 (defun gnus-summary-save-in-mail (&optional filename)
2142 "Append this article to Unix mail file.
2143 Optional argument FILENAME specifies file name.
2144 Directory to save to is default to `gnus-article-save-directory'."
2145 (setq filename (gnus-read-save-file-name
2146 "Save %s in Unix mail file:" filename
2147 gnus-mail-save-name gnus-newsgroup-name
2148 gnus-current-headers 'gnus-newsgroup-last-mail))
2149 (gnus-eval-in-buffer-window gnus-save-article-buffer
2153 (if (and (file-readable-p filename)
2154 (mail-file-babyl-p filename))
2155 (rmail-output-to-rmail-file filename t)
2156 (gnus-output-to-mail filename)))))
2159 (defun gnus-summary-save-in-file (&optional filename overwrite)
2160 "Append this article to file.
2161 Optional argument FILENAME specifies file name.
2162 Directory to save to is default to `gnus-article-save-directory'."
2163 (setq filename (gnus-read-save-file-name
2164 "Save %s in file:" filename
2165 gnus-file-save-name gnus-newsgroup-name
2166 gnus-current-headers 'gnus-newsgroup-last-file))
2167 (gnus-eval-in-buffer-window gnus-save-article-buffer
2171 (when (and overwrite
2172 (file-exists-p filename))
2173 (delete-file filename))
2174 (gnus-output-to-file filename))))
2177 (defun gnus-summary-write-to-file (&optional filename)
2178 "Write this article to a file.
2179 Optional argument FILENAME specifies file name.
2180 The directory to save in defaults to `gnus-article-save-directory'."
2181 (gnus-summary-save-in-file nil t))
2183 (defun gnus-summary-save-body-in-file (&optional filename)
2184 "Append this article body to a file.
2185 Optional argument FILENAME specifies file name.
2186 The directory to save in defaults to `gnus-article-save-directory'."
2187 (setq filename (gnus-read-save-file-name
2188 "Save %s body in file:" filename
2189 gnus-file-save-name gnus-newsgroup-name
2190 gnus-current-headers 'gnus-newsgroup-last-file))
2191 (gnus-eval-in-buffer-window gnus-save-article-buffer
2195 (when (article-goto-body)
2196 (narrow-to-region (point) (point-max)))
2197 (gnus-output-to-file filename))))
2200 (defun gnus-summary-save-in-pipe (&optional command)
2201 "Pipe this article to subprocess."
2203 (cond ((and (eq command 'default)
2204 gnus-last-shell-command)
2205 gnus-last-shell-command)
2209 "Shell command on %s: "
2210 (if (and gnus-number-of-articles-to-be-saved
2211 (> gnus-number-of-articles-to-be-saved 1))
2212 (format "these %d articles"
2213 gnus-number-of-articles-to-be-saved)
2215 gnus-last-shell-command))))
2216 (when (string-equal command "")
2217 (setq command gnus-last-shell-command))
2218 (gnus-eval-in-buffer-window gnus-article-buffer
2221 (shell-command-on-region (point-min) (point-max) command nil)))
2222 (setq gnus-last-shell-command command))
2224 ;;; Article file names when saving.
2226 (defun gnus-capitalize-newsgroup (newsgroup)
2227 "Capitalize NEWSGROUP name."
2228 (when (not (zerop (length newsgroup)))
2229 (concat (char-to-string (upcase (aref newsgroup 0)))
2230 (substring newsgroup 1))))
2232 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2233 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2234 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2235 Otherwise, it is like ~/News/news/group/num."
2238 (concat (if (gnus-use-long-file-name 'not-save)
2239 (gnus-capitalize-newsgroup newsgroup)
2240 (gnus-newsgroup-directory-form newsgroup))
2241 "/" (int-to-string (mail-header-number headers)))
2242 gnus-article-save-directory)))
2244 (string-equal (file-name-directory default)
2245 (file-name-directory last-file))
2246 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2248 (or last-file default))))
2250 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2251 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2252 If variable `gnus-use-long-file-name' is non-nil, it is
2253 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2256 (concat (if (gnus-use-long-file-name 'not-save)
2258 (gnus-newsgroup-directory-form newsgroup))
2259 "/" (int-to-string (mail-header-number headers)))
2260 gnus-article-save-directory)))
2262 (string-equal (file-name-directory default)
2263 (file-name-directory last-file))
2264 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2266 (or last-file default))))
2268 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2269 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2270 If variable `gnus-use-long-file-name' is non-nil, it is
2271 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2274 (if (gnus-use-long-file-name 'not-save)
2275 (gnus-capitalize-newsgroup newsgroup)
2276 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2277 gnus-article-save-directory)))
2279 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2280 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2281 If variable `gnus-use-long-file-name' is non-nil, it is
2282 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2285 (if (gnus-use-long-file-name 'not-save)
2287 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2288 gnus-article-save-directory)))
2295 (setq afunc (car func)
2298 gfunc (intern (format "gnus-%s" func))))
2300 (if (not (fboundp afunc))
2302 `(lambda (&optional interactive &rest args)
2303 ,(documentation afunc t)
2304 (interactive (list t))
2306 (set-buffer gnus-article-buffer)
2308 (call-interactively ',afunc)
2309 (apply ',afunc args))))))))
2310 '(article-hide-headers
2311 article-hide-boring-headers
2312 article-treat-overstrike
2313 article-fill-long-lines
2314 article-capitalize-sentences
2316 article-display-x-face
2317 article-de-quoted-unreadable
2319 article-strip-banner
2321 article-hide-signature
2322 article-strip-headers-in-body
2323 article-remove-trailing-blank-lines
2324 article-strip-leading-blank-lines
2325 article-strip-multiple-blank-lines
2326 article-strip-leading-space
2327 article-strip-trailing-space
2328 article-strip-blank-lines
2329 article-strip-all-blank-lines
2331 article-date-iso8601
2332 article-date-original
2334 article-decode-mime-words
2335 article-decode-charset
2336 article-decode-encoded-words
2340 article-treat-dumbquotes
2341 article-normalize-headers
2342 (article-show-all . gnus-article-show-all-headers))))
2345 ;;; Gnus article mode
2348 (put 'gnus-article-mode 'mode-class 'special)
2350 (gnus-define-keys gnus-article-mode-map
2351 " " gnus-article-goto-next-page
2352 "\177" gnus-article-goto-prev-page
2353 [delete] gnus-article-goto-prev-page
2354 [backspace] gnus-article-goto-prev-page
2355 "\C-c^" gnus-article-refer-article
2356 "h" gnus-article-show-summary
2357 "s" gnus-article-show-summary
2358 "\C-c\C-m" gnus-article-mail
2359 "?" gnus-article-describe-briefly
2360 gnus-mouse-2 gnus-article-push-button
2361 "\r" gnus-article-press-button
2362 "\t" gnus-article-next-button
2363 "\M-\t" gnus-article-prev-button
2364 "e" gnus-article-edit
2365 "<" beginning-of-buffer
2367 "\C-c\C-i" gnus-info-find-node
2370 "\C-d" gnus-article-read-summary-keys
2371 "\M-*" gnus-article-read-summary-keys
2372 "\M-#" gnus-article-read-summary-keys
2373 "\M-^" gnus-article-read-summary-keys
2374 "\M-g" gnus-article-read-summary-keys)
2376 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2379 (unless (lookup-key gnus-article-mode-map key)
2380 (define-key gnus-article-mode-map key
2381 'gnus-article-read-summary-keys)))
2386 (let ((key (car elt)))
2387 (and (> (length key) 0)
2388 (not (eq 'menu-bar (aref key 0)))
2389 (symbolp (lookup-key gnus-summary-mode-map key))
2391 (accessible-keymaps gnus-summary-mode-map))
2395 (push (char-to-string c) keys)
2399 (defun gnus-article-make-menu-bar ()
2400 (gnus-turn-off-edit-menu 'article)
2401 (unless (boundp 'gnus-article-article-menu)
2403 gnus-article-article-menu gnus-article-mode-map ""
2405 ["Scroll forwards" gnus-article-goto-next-page t]
2406 ["Scroll backwards" gnus-article-goto-prev-page t]
2407 ["Show summary" gnus-article-show-summary t]
2408 ["Fetch Message-ID at point" gnus-article-refer-article t]
2409 ["Mail to address at point" gnus-article-mail t]
2410 ["Send a bug report" gnus-bug t]))
2413 gnus-article-treatment-menu gnus-article-mode-map ""
2415 ["Hide headers" gnus-article-hide-headers t]
2416 ["Hide signature" gnus-article-hide-signature t]
2417 ["Hide citation" gnus-article-hide-citation t]
2418 ["Treat overstrike" gnus-article-treat-overstrike t]
2419 ["Remove carriage return" gnus-article-remove-cr t]))
2421 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2423 (when (boundp 'gnus-summary-post-menu)
2424 (define-key gnus-article-mode-map [menu-bar post]
2425 (cons "Post" gnus-summary-post-menu)))
2427 (gnus-run-hooks 'gnus-article-menu-hook)))
2429 (defun gnus-article-mode ()
2430 "Major mode for displaying an article.
2432 All normal editing commands are switched off.
2434 The following commands are available in addition to all summary mode
2436 \\<gnus-article-mode-map>
2437 \\[gnus-article-next-page]\t Scroll the article one page forwards
2438 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2439 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2440 \\[gnus-article-show-summary]\t Display the summary buffer
2441 \\[gnus-article-mail]\t Send a reply to the address near point
2442 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2443 \\[gnus-info-find-node]\t Go to the Gnus info node"
2445 (when (gnus-visual-p 'article-menu 'menu)
2446 (gnus-article-make-menu-bar))
2447 (gnus-simplify-mode-line)
2448 (setq mode-name "Article")
2449 (setq major-mode 'gnus-article-mode)
2450 (make-local-variable 'minor-mode-alist)
2451 (unless (assq 'gnus-show-mime minor-mode-alist)
2452 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2453 (use-local-map gnus-article-mode-map)
2454 (gnus-update-format-specifications nil 'article-mode)
2455 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2456 (make-local-variable 'gnus-page-broken)
2457 (make-local-variable 'gnus-button-marker-list)
2458 (make-local-variable 'gnus-article-current-summary)
2459 (make-local-variable 'gnus-article-mime-handles)
2460 (make-local-variable 'gnus-article-decoded-p)
2461 (make-local-variable 'gnus-article-mime-handle-alist)
2462 (make-local-variable 'gnus-article-washed-types)
2463 (gnus-set-default-directory)
2464 (buffer-disable-undo)
2465 (setq buffer-read-only t)
2466 (set-syntax-table gnus-article-mode-syntax-table)
2467 (gnus-run-hooks 'gnus-article-mode-hook))
2469 (defun gnus-article-setup-buffer ()
2470 "Initialize the article buffer."
2471 (let* ((name (if gnus-single-article-buffer "*Article*"
2472 (concat "*Article " gnus-newsgroup-name "*")))
2474 (progn (string-match "\\*Article" name)
2475 (concat " *Original Article"
2476 (substring name (match-end 0))))))
2477 (setq gnus-article-buffer name)
2478 (setq gnus-original-article-buffer original)
2479 (setq gnus-article-mime-handle-alist nil)
2480 ;; This might be a variable local to the summary buffer.
2481 (unless gnus-single-article-buffer
2483 (set-buffer gnus-summary-buffer)
2484 (setq gnus-article-buffer name)
2485 (setq gnus-original-article-buffer original)
2486 (gnus-set-global-variables)))
2487 ;; Init original article buffer.
2489 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2490 (setq major-mode 'gnus-original-article-mode)
2491 (make-local-variable 'gnus-original-article))
2492 (if (get-buffer name)
2495 (buffer-disable-undo)
2496 (setq buffer-read-only t)
2497 (unless (eq major-mode 'gnus-article-mode)
2498 (gnus-article-mode))
2501 (set-buffer (gnus-get-buffer-create name))
2503 (make-local-variable 'gnus-summary-buffer)
2504 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2505 (current-buffer)))))
2507 ;; Set article window start at LINE, where LINE is the number of lines
2508 ;; from the head of the article.
2509 (defun gnus-article-set-window-start (&optional line)
2511 (get-buffer-window gnus-article-buffer t)
2513 (set-buffer gnus-article-buffer)
2514 (goto-char (point-min))
2517 (gnus-message 6 "Moved to bookmark")
2518 (search-forward "\n\n" nil t)
2522 ;;; @@ article filters
2525 (defun gnus-article-display-mime-message ()
2526 "Article display method for MIME message."
2527 ;; called from `gnus-original-article-buffer'.
2528 (let (charset all-headers)
2529 (with-current-buffer gnus-summary-buffer
2530 (setq charset default-mime-charset
2531 all-headers gnus-have-all-headers))
2532 (make-local-variable 'default-mime-charset)
2533 (setq default-mime-charset charset)
2534 (with-current-buffer (get-buffer-create gnus-article-buffer)
2535 (make-local-variable 'default-mime-charset)
2536 (setq default-mime-charset charset))
2537 (mime-display-message mime-message-structure
2538 gnus-article-buffer nil gnus-article-mode-map)
2540 (gnus-article-hide-headers nil -1))
2542 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2543 (make-local-variable 'mime-button-mother-dispatcher)
2544 (setq mime-button-mother-dispatcher
2545 (function gnus-article-push-button))
2546 (run-hooks 'gnus-mime-article-prepare-hook))
2548 (defun gnus-article-display-traditional-message ()
2549 "Article display method for traditional message."
2550 (set-buffer gnus-article-buffer)
2551 (let (buffer-read-only)
2553 (insert-buffer-substring gnus-original-article-buffer)))
2555 (defun gnus-article-make-full-mail-header (&optional number charset)
2556 "Create a new mail header structure in a raw article buffer."
2557 (unless (and number charset)
2558 (save-current-buffer
2559 (set-buffer gnus-summary-buffer)
2561 (setq number (or (cdr gnus-article-current) 0)))
2563 (setq charset (or default-mime-charset 'x-ctext)))))
2564 (goto-char (point-min))
2565 (let ((header-end (if (search-forward "\n\n" nil t)
2567 (goto-char (point-max))))
2568 (chars (- (point-max) (point)))
2569 (lines (count-lines (point) (point-max)))
2570 (default-mime-charset charset)
2572 (narrow-to-region (point-min) header-end)
2573 (setq xref (std11-fetch-field "xref"))
2575 (make-full-mail-header
2577 (std11-fetch-field "subject")
2578 (std11-fetch-field "from")
2579 (std11-fetch-field "date")
2580 (std11-fetch-field "message-id")
2581 (std11-fetch-field "references")
2584 (when xref (concat "Xref: " xref)))
2587 (defun gnus-article-prepare (article &optional all-headers header)
2588 "Prepare ARTICLE in article mode buffer.
2589 ARTICLE should either be an article number or a Message-ID.
2590 If ARTICLE is an id, HEADER should be the article headers.
2591 If ALL-HEADERS is non-nil, no headers are hidden."
2593 ;; Make sure we start in a summary buffer.
2594 (unless (eq major-mode 'gnus-summary-mode)
2595 (set-buffer gnus-summary-buffer))
2596 (setq gnus-summary-buffer (current-buffer))
2597 (let* ((gnus-article (if header (mail-header-number header) article))
2598 (summary-buffer (current-buffer))
2599 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2600 (group gnus-newsgroup-name)
2603 (gnus-article-setup-buffer)
2604 (set-buffer gnus-original-article-buffer)
2605 ;; Deactivate active regions.
2606 (when (and (boundp 'transient-mark-mode)
2607 transient-mark-mode)
2608 (setq mark-active nil))
2609 (if (not (setq result (let ((buffer-read-only nil))
2610 (gnus-request-article-this-buffer
2612 ;; There is no such article.
2614 (when (and (numberp article)
2615 (not (memq article gnus-newsgroup-sparse)))
2616 (setq gnus-article-current
2617 (cons gnus-newsgroup-name article))
2618 (set-buffer gnus-summary-buffer)
2619 (setq gnus-current-article article)
2620 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2622 (gnus-summary-set-agent-mark article)
2623 (message "Message marked for downloading"))
2624 (gnus-summary-mark-article article gnus-canceled-mark)
2625 (unless (memq article gnus-newsgroup-sparse)
2627 "No such article (may have expired or been canceled)")))))
2628 (if (or (eq result 'pseudo)
2629 (eq result 'nneething))
2632 (set-buffer summary-buffer)
2633 (push article gnus-newsgroup-history)
2634 (setq gnus-last-article gnus-current-article
2635 gnus-current-article 0
2636 gnus-current-headers nil
2637 gnus-article-current nil)
2638 (if (eq result 'nneething)
2639 (gnus-configure-windows 'summary)
2640 (gnus-configure-windows 'article))
2641 (gnus-set-global-variables))
2642 (let ((gnus-article-mime-handle-alist-1
2643 gnus-article-mime-handle-alist))
2644 (gnus-set-mode-line 'article)))
2645 ;; The result from the `request' was an actual article -
2646 ;; or at least some text that is now displayed in the
2648 (when (and (numberp article)
2649 (not (eq article gnus-current-article)))
2650 ;; Seems like a new article has been selected.
2651 ;; `gnus-current-article' must be an article number.
2653 (set-buffer summary-buffer)
2654 (push article gnus-newsgroup-history)
2655 (setq gnus-last-article gnus-current-article
2656 gnus-current-article article
2657 gnus-current-headers
2658 (gnus-summary-article-header gnus-current-article)
2659 gnus-article-current
2660 (cons gnus-newsgroup-name gnus-current-article))
2661 (unless (vectorp gnus-current-headers)
2662 (setq gnus-current-headers nil))
2663 (gnus-summary-goto-subject gnus-current-article)
2664 (when (gnus-summary-show-thread)
2665 ;; If the summary buffer really was folded, the
2666 ;; previous goto may not actually have gone to
2667 ;; the right article, but the thread root instead.
2669 (gnus-summary-goto-subject gnus-current-article))
2670 (gnus-run-hooks 'gnus-mark-article-hook)
2671 (gnus-set-mode-line 'summary)
2672 (when (gnus-visual-p 'article-highlight 'highlight)
2673 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2674 ;; Set the global newsgroup variables here.
2675 (gnus-set-global-variables)
2676 (setq gnus-have-all-headers
2677 (or all-headers gnus-show-all-headers))))
2678 (when (or (numberp article)
2680 (gnus-article-prepare-display)
2682 (goto-char (point-min))
2683 (setq gnus-page-broken
2684 (when gnus-break-pages
2685 (gnus-narrow-to-page)
2687 (let ((gnus-article-mime-handle-alist-1
2688 gnus-article-mime-handle-alist))
2689 (gnus-set-mode-line 'article))
2691 (set-window-point (get-buffer-window (current-buffer)) (point))
2692 (gnus-configure-windows 'article)
2696 (defun gnus-article-prepare-display ()
2697 "Make the current buffer look like a nice article."
2701 (setq mime-message-structure gnus-current-headers)
2702 gnus-article-display-method-for-mime)
2703 gnus-article-display-method-for-traditional)))
2704 (gnus-run-hooks 'gnus-tmp-internal-hook)
2705 (gnus-run-hooks 'gnus-article-prepare-hook)
2708 ;; Associate this article with the current summary buffer.
2709 (setq gnus-article-current-summary gnus-summary-buffer)
2710 ;; Perform the article display hooks.
2711 (gnus-run-hooks 'gnus-article-display-hook)))
2714 ;;; Gnus MIME viewing functions
2717 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2718 "The following specs can be used:
2720 %T MIME type, along with additional info
2721 %n The `name' parameter
2722 %d The description, if any
2723 %l The length of the encoded part
2724 %p The part identifier number
2725 %e Dots if the part isn't displayed")
2727 (defvar gnus-mime-button-line-format-alist
2728 '((?t gnus-tmp-type ?s)
2729 (?T gnus-tmp-type-long ?s)
2730 (?n gnus-tmp-name ?s)
2731 (?d gnus-tmp-description ?s)
2733 (?l gnus-tmp-length ?d)
2734 (?e gnus-tmp-dots ?s)))
2736 (defvar gnus-mime-button-commands
2737 '((gnus-article-press-button "\r" "Toggle Display")
2738 (gnus-mime-view-part "v" "View Interactively...")
2739 (gnus-mime-save-part "o" "Save...")
2740 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2741 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2742 (gnus-mime-internalize-part "E" "View Internally")
2743 (gnus-mime-externalize-part "e" "View Externally")
2744 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2746 (defun gnus-article-mime-part-status ()
2747 (if gnus-article-mime-handle-alist-1
2748 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2751 (defvar gnus-mime-button-map nil)
2752 (unless gnus-mime-button-map
2753 (setq gnus-mime-button-map (make-sparse-keymap))
2754 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2755 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2756 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2758 (define-key gnus-mime-button-map (cadr c) (car c)))
2759 gnus-mime-button-commands))
2761 (defun gnus-mime-button-menu (event)
2762 "Construct a context-sensitive menu of MIME commands."
2765 (let ((pos (event-start event)))
2766 (set-buffer (window-buffer (posn-window pos)))
2767 (goto-char (posn-point pos))
2768 (gnus-article-check-buffer)
2769 (let ((response (x-popup-menu
2771 ("" ,@(mapcar (lambda (c)
2772 (cons (caddr c) (car c)))
2773 gnus-mime-button-commands))))))
2775 (funcall response))))))
2777 (defun gnus-mime-view-all-parts (&optional handles)
2778 "View all the MIME parts."
2780 (save-current-buffer
2781 (set-buffer gnus-article-buffer)
2782 (let ((handles (or handles gnus-article-mime-handles))
2783 (mail-parse-charset gnus-newsgroup-charset))
2784 (if (stringp (car handles))
2785 (gnus-mime-view-all-parts (cdr handles))
2786 (mapcar 'mm-display-part handles)))))
2788 (defun gnus-mime-save-part ()
2789 "Save the MIME part under point."
2791 (gnus-article-check-buffer)
2792 (let ((data (get-text-property (point) 'gnus-data)))
2793 (mm-save-part data)))
2795 (defun gnus-mime-pipe-part ()
2796 "Pipe the MIME part under point to a process."
2798 (gnus-article-check-buffer)
2799 (let ((data (get-text-property (point) 'gnus-data)))
2800 (mm-pipe-part data)))
2802 (defun gnus-mime-view-part ()
2803 "Interactively choose a view method for the MIME part under point."
2805 (gnus-article-check-buffer)
2806 (let ((data (get-text-property (point) 'gnus-data)))
2807 (mm-interactively-view-part data)))
2809 (defun gnus-mime-copy-part (&optional handle)
2810 "Put the the MIME part under point into a new buffer."
2812 (gnus-article-check-buffer)
2813 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2814 (contents (mm-get-part handle))|
2815 (base (file-name-nondirectory
2817 (mail-content-type-get (mm-handle-type handle) 'name)
2818 (mail-content-type-get (mm-handle-type handle)
2821 (buffer (generate-new-buffer base)))
2822 (switch-to-buffer buffer)
2824 ;; We do it this way to make `normal-mode' set the appropriate mode.
2827 (setq buffer-file-name (expand-file-name base))
2829 (setq buffer-file-name nil))
2830 (goto-char (point-min))))
2832 (defun gnus-mime-inline-part (&optional handle)
2833 "Insert the MIME part under point into the current buffer."
2835 (gnus-article-check-buffer)
2836 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2840 (if (mm-handle-undisplayer handle)
2841 (mm-remove-part handle)
2842 (setq contents (mm-get-part handle))
2844 (mm-insert-inline handle contents)
2847 (defun gnus-mime-externalize-part (&optional handle)
2848 "View the MIME part under point with an external viewer."
2850 (gnus-article-check-buffer)
2851 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2852 (mm-user-display-methods nil)
2853 (mm-all-images-fit t)
2854 (mail-parse-charset gnus-newsgroup-charset))
2855 (if (mm-handle-undisplayer handle)
2856 (mm-remove-part handle)
2857 (mm-display-part handle))))
2859 (defun gnus-mime-internalize-part (&optional handle)
2860 "View the MIME part under point with an internal viewer."
2862 (gnus-article-check-buffer)
2863 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2864 (mm-user-display-methods '((".*" . inline)))
2865 (mm-all-images-fit t)
2866 (mail-parse-charset gnus-newsgroup-charset))
2867 (if (mm-handle-undisplayer handle)
2868 (mm-remove-part handle)
2869 (mm-display-part handle))))
2871 (defun gnus-article-part-wrapper (n function)
2872 (save-current-buffer
2873 (set-buffer gnus-article-buffer)
2874 (when (> n (length gnus-article-mime-handle-alist))
2875 (error "No such part"))
2876 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2877 (funcall function handle))))
2879 (defun gnus-article-pipe-part (n)
2880 "Pipe MIME part N, which is the numerical prefix."
2882 (gnus-article-part-wrapper n 'mm-pipe-part))
2884 (defun gnus-article-save-part (n)
2885 "Save MIME part N, which is the numerical prefix."
2887 (gnus-article-part-wrapper n 'mm-save-part))
2889 (defun gnus-article-interactively-view-part (n)
2890 "View MIME part N interactively, which is the numerical prefix."
2892 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2894 (defun gnus-article-copy-part (n)
2895 "Copy MIME part N, which is the numerical prefix."
2897 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2899 (defun gnus-article-externalize-part (n)
2900 "View MIME part N externally, which is the numerical prefix."
2902 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2904 (defun gnus-article-inline-part (n)
2905 "Inline MIME part N, which is the numerical prefix."
2907 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2909 (defun gnus-article-view-part (n)
2910 "View MIME part N, which is the numerical prefix."
2912 (save-current-buffer
2913 (set-buffer gnus-article-buffer)
2914 (when (> n (length gnus-article-mime-handle-alist))
2915 (error "No such part"))
2916 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2917 (when (gnus-article-goto-part n)
2918 (if (equal (car handle) "multipart/alternative")
2919 (gnus-article-press-button)
2920 (when (eq (gnus-mm-display-part handle) 'internal)
2921 (gnus-set-window-start)))))))
2923 (defun gnus-mm-display-part (handle)
2924 "Display HANDLE and fix MIME button."
2925 (let ((id (get-text-property (point) 'gnus-part))
2930 (let ((window (selected-window))
2931 (mail-parse-charset gnus-newsgroup-charset))
2934 (let ((win (get-buffer-window (current-buffer) t))
2937 (select-window win))
2940 (if (mm-handle-displayed-p handle)
2941 ;; This will remove the part.
2942 (mm-display-part handle)
2944 (narrow-to-region (point) (1+ (point)))
2945 (mm-display-part handle)
2946 ;; We narrow to the part itself and
2947 ;; then call the treatment functions.
2948 (goto-char (point-min))
2950 (narrow-to-region (point) (point-max))
2953 (1- (length gnus-article-mime-handles))
2954 (car (mm-handle-type handle))))))
2955 (select-window window))))
2957 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2958 (gnus-insert-mime-button
2959 handle id (list (mm-handle-displayed-p handle)))
2960 (goto-char point))))
2962 (defun gnus-article-goto-part (n)
2963 "Go to MIME part N."
2964 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2966 (goto-char point))))
2968 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2969 (let ((gnus-tmp-name
2970 (or (mail-content-type-get (mm-handle-type handle)
2972 (mail-content-type-get (mm-handle-disposition handle)
2975 (gnus-tmp-type (car (mm-handle-type handle)))
2976 (gnus-tmp-description
2977 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2980 (if (if displayed (car displayed)
2981 (mm-handle-displayed-p handle))
2983 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2985 gnus-tmp-type-long b e)
2986 (when (string-match ".*/" gnus-tmp-name)
2987 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2988 (setq gnus-tmp-type-long (concat gnus-tmp-type
2989 (and (not (equal gnus-tmp-name ""))
2990 (concat "; " gnus-tmp-name))))
2991 (or (equal gnus-tmp-description "")
2992 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2997 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2998 `(local-map ,gnus-mime-button-map
2999 keymap ,gnus-mime-button-map
3000 gnus-callback gnus-mm-display-part
3001 gnus-part ,gnus-tmp-id
3002 article-type annotation
3005 (widget-convert-button 'link b e
3007 :action 'gnus-widget-press-button
3008 :button-keymap gnus-mime-button-map
3011 ;; Needed to properly clear the message
3012 ;; due to a bug in wid-edit
3013 (setq help-echo-owns-message t)
3015 "Click to %s the MIME part; %s for more options"
3016 (if (mm-handle-displayed-p
3017 (widget-get widget :mime-handle))
3019 (if gnus-xemacs "button3" "mouse-3"))))))
3021 (defun gnus-widget-press-button (elems el)
3022 (goto-char (widget-get elems :from))
3023 (gnus-article-press-button))
3025 (defvar gnus-displaying-mime nil)
3027 (defun gnus-display-mime (&optional ihandles)
3028 "Display the MIME parts."
3030 (save-selected-window
3031 (let ((window (get-buffer-window gnus-article-buffer))
3034 (select-window window)
3035 ;; We have to do this since selecting the window
3036 ;; may change the point. So we set the window point.
3037 (set-window-point window point)))
3038 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3039 buffer-read-only handle name type b e display)
3040 (when (and (not ihandles)
3041 (not gnus-displaying-mime))
3042 ;; Top-level call; we clean up.
3043 (mm-destroy-parts gnus-article-mime-handles)
3044 (setq gnus-article-mime-handles handles
3045 gnus-article-mime-handle-alist nil)
3046 ;; We allow users to glean info from the handles.
3047 (when gnus-article-mime-part-function
3048 (gnus-mime-part-function handles)))
3050 (or (not (stringp (car handles)))
3053 (when (and (not ihandles)
3054 (not gnus-displaying-mime))
3055 ;; Clean up for mime parts.
3057 (delete-region (point) (point-max)))
3058 (let ((gnus-displaying-mime t))
3059 (gnus-mime-display-part handles)))
3062 (narrow-to-region (point) (point-max))
3063 (gnus-treat-article nil 1 1)
3065 ;; Highlight the headers.
3069 (narrow-to-region (point-min) (point))
3070 (gnus-treat-article 'head)))))))
3072 (defvar gnus-mime-display-multipart-as-mixed nil)
3074 (defun gnus-mime-display-part (handle)
3077 ((not (stringp (car handle)))
3078 (gnus-mime-display-single handle))
3079 ;; User-defined multipart
3080 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3081 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3083 ;; multipart/alternative
3084 ((and (equal (car handle) "multipart/alternative")
3085 (not gnus-mime-display-multipart-as-mixed))
3086 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3087 (push (cons id handle) gnus-article-mime-handle-alist)
3088 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3089 ;; multipart/related
3090 ((and (equal (car handle) "multipart/related")
3091 (not gnus-mime-display-multipart-as-mixed))
3092 ;;;!!!We should find the start part, but we just default
3093 ;;;!!!to the first part.
3094 (gnus-mime-display-part (cadr handle)))
3095 ;; Other multiparts are handled like multipart/mixed.
3097 (gnus-mime-display-mixed (cdr handle)))))
3099 (defun gnus-mime-part-function (handles)
3100 (if (stringp (car handles))
3101 (mapcar 'gnus-mime-part-function (cdr handles))
3102 (funcall gnus-article-mime-part-function handles)))
3104 (defun gnus-mime-display-mixed (handles)
3105 (mapcar 'gnus-mime-display-part handles))
3107 (defun gnus-mime-display-single (handle)
3108 (let ((type (car (mm-handle-type handle)))
3109 (ignored gnus-ignored-mime-types)
3116 (when (string-match (pop ignored) type)
3117 (throw 'ignored nil)))
3118 (if (and (setq not-attachment
3119 (or (not (mm-handle-disposition handle))
3120 (equal (car (mm-handle-disposition handle))
3122 (mm-attachment-override-p type)))
3123 (mm-automatic-display-p type)
3124 (or (mm-inlinable-part-p type)
3125 (mm-automatic-external-display-p type)))
3127 (when (equal (car (split-string type "/"))
3130 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3131 (push (cons id handle) gnus-article-mime-handle-alist)
3132 (when (or (not display)
3133 (not (gnus-unbuttonized-mime-type-p type)))
3134 (gnus-article-insert-newline)
3135 (gnus-insert-mime-button
3136 handle id (list (or display (and not-attachment text))))
3137 (gnus-article-insert-newline)
3138 (gnus-article-insert-newline)
3140 (let ((beg (point)))
3145 (let ((mail-parse-charset gnus-newsgroup-charset))
3146 (mm-display-part handle t))
3147 (goto-char (point-max)))
3148 ((and text not-attachment)
3151 (gnus-article-insert-newline)
3152 (mm-insert-inline handle (mm-get-part handle))
3153 (goto-char (point-max))))
3157 (narrow-to-region beg (point))
3159 nil (length gnus-article-mime-handle-alist)
3160 (1- (length gnus-article-mime-handles))
3161 (car (mm-handle-type handle))))))))))
3163 (defun gnus-unbuttonized-mime-type-p (type)
3164 "Say whether TYPE is to be unbuttonized."
3165 (unless gnus-inhibit-mime-unbuttonizing
3167 (let ((types gnus-unbuttonized-mime-types))
3169 (when (string-match (pop types) type)
3170 (throw 'found t)))))))
3172 (defun gnus-article-insert-newline ()
3173 "Insert a newline, but mark it as undeletable."
3174 (gnus-put-text-property
3175 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3177 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3178 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3181 handle buffer-read-only from props begend not-pref)
3182 (save-window-excursion
3185 (narrow-to-region (car ibegend)
3188 (goto-char (car ibegend))
3191 (delete-region (point-min) (point-max))
3192 (mm-remove-parts handles))
3193 (setq begend (list (point-marker)))
3195 (unless (setq not-pref (cadr (member preferred ihandles)))
3196 (setq not-pref (car ihandles)))
3198 (not (gnus-unbuttonized-mime-type-p
3199 "multipart/alternative")))
3200 (gnus-add-text-properties
3203 (insert (format "%d. " id))
3207 (unless ,(not ibegend)
3208 (setq gnus-article-mime-handle-alist
3209 ',gnus-article-mime-handle-alist))
3210 (gnus-mime-display-alternative
3211 ',ihandles ',not-pref ',begend ,id))
3212 local-map ,gnus-mime-button-map
3213 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3214 face ,gnus-article-button-face
3215 keymap ,gnus-mime-button-map
3218 (widget-convert-button 'link from (point)
3219 :action 'gnus-widget-press-button
3220 :button-keymap gnus-widget-button-keymap)
3222 (while (setq handle (pop handles))
3223 (gnus-add-text-properties
3226 (insert (format "(%c) %-18s"
3227 (if (equal handle preferred) ?* ? )
3228 (if (stringp (car handle))
3230 (car (mm-handle-type handle)))))
3234 (unless ,(not ibegend)
3235 (setq gnus-article-mime-handle-alist
3236 ',gnus-article-mime-handle-alist))
3237 (gnus-mime-display-alternative
3238 ',ihandles ',handle ',begend ,id))
3239 local-map ,gnus-mime-button-map
3240 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3241 face ,gnus-article-button-face
3242 keymap ,gnus-mime-button-map
3245 (widget-convert-button 'link from (point)
3246 :action 'gnus-widget-press-button
3247 :button-keymap gnus-widget-button-keymap)
3251 (if (stringp (car preferred))
3252 (gnus-display-mime preferred)
3253 (let ((mail-parse-charset gnus-newsgroup-charset))
3254 (mm-display-part preferred)))
3255 (goto-char (point-max))
3256 (setcdr begend (point-marker)))))
3258 (goto-char point))))
3260 (defun gnus-article-wash-status ()
3261 "Return a string which display status of article washing."
3263 (set-buffer gnus-article-buffer)
3264 (let ((cite (gnus-article-hidden-text-p 'cite))
3265 (headers (gnus-article-hidden-text-p 'headers))
3266 (boring (gnus-article-hidden-text-p 'boring-headers))
3267 (pgp (gnus-article-hidden-text-p 'pgp))
3268 (pem (gnus-article-hidden-text-p 'pem))
3269 (signature (gnus-article-hidden-text-p 'signature))
3270 (overstrike (gnus-article-hidden-text-p 'overstrike))
3271 (emphasis (gnus-article-hidden-text-p 'emphasis))
3272 (mime gnus-show-mime))
3273 (format "%c%c%c%c%c%c%c"
3275 (if (or headers boring) ?h ? )
3276 (if (or pgp pem) ?p ? )
3277 (if signature ?s ? )
3278 (if overstrike ?o ? )
3280 (if emphasis ?e ? )))))
3282 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3284 (defun gnus-article-maybe-hide-headers ()
3285 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3286 Provided for backwards compatibility."
3287 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3288 (not (save-excursion (set-buffer gnus-summary-buffer)
3289 gnus-have-all-headers)))
3290 (not gnus-inhibit-hiding))
3291 (gnus-article-hide-headers)))
3295 (defun gnus-output-to-file (file-name)
3296 "Append the current article to a file named FILE-NAME."
3297 (let ((artbuf (current-buffer)))
3299 (insert-buffer-substring artbuf)
3300 ;; Append newline at end of the buffer as separator, and then
3302 (goto-char (point-max))
3304 (append-to-file (point-min) (point-max) file-name)
3307 (defun gnus-narrow-to-page (&optional arg)
3308 "Narrow the article buffer to a page.
3309 If given a numerical ARG, move forward ARG pages."
3311 (setq arg (if arg (prefix-numeric-value arg) 0))
3313 (set-buffer gnus-article-buffer)
3314 (goto-char (point-min))
3316 ;; Remove any old next/prev buttons.
3317 (when (gnus-visual-p 'page-marker)
3318 (let ((buffer-read-only nil))
3319 (gnus-remove-text-with-property 'gnus-prev)
3320 (gnus-remove-text-with-property 'gnus-next)))
3323 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3325 (re-search-forward page-delimiter nil 'move arg)))
3326 (goto-char (match-end 0)))
3329 (if (re-search-forward page-delimiter nil 'move)
3332 (when (and (gnus-visual-p 'page-marker)
3333 (not (= (point-min) 1)))
3335 (goto-char (point-min))
3336 (gnus-insert-prev-page-button)))
3337 (when (and (gnus-visual-p 'page-marker)
3338 (< (+ (point-max) 2) (buffer-size)))
3340 (goto-char (point-max))
3341 (gnus-insert-next-page-button)))))
3343 ;; Article mode commands
3345 (defun gnus-article-goto-next-page ()
3346 "Show the next page of the article."
3348 (when (gnus-article-next-page)
3349 (goto-char (point-min))
3350 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3352 (defun gnus-article-goto-prev-page ()
3353 "Show the next page of the article."
3355 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3356 (gnus-article-prev-page nil)))
3358 (defun gnus-article-next-page (&optional lines)
3359 "Show the next page of the current article.
3360 If end of article, return non-nil. Otherwise return nil.
3361 Argument LINES specifies lines to be scrolled up."
3363 (move-to-window-line -1)
3366 (and (pos-visible-in-window-p) ;Not continuation line.
3368 ;; Nothing in this page.
3369 (if (or (not gnus-page-broken)
3372 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3374 (gnus-narrow-to-page 1) ;Go to next page.
3376 ;; More in this page.
3377 (let ((scroll-in-place nil))
3381 ;; Long lines may cause an end-of-buffer error.
3382 (goto-char (point-max)))))
3383 (move-to-window-line 0)
3386 (defun gnus-article-prev-page (&optional lines)
3387 "Show previous page of current article.
3388 Argument LINES specifies lines to be scrolled down."
3390 (move-to-window-line 0)
3391 (if (and gnus-page-broken
3393 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3395 (gnus-narrow-to-page -1) ;Go to previous page.
3396 (goto-char (point-max))
3398 (let ((scroll-in-place nil))
3402 (beginning-of-buffer
3403 (goto-char (point-min))))
3404 (move-to-window-line 0)))))
3406 (defun gnus-article-refer-article ()
3407 "Read article specified by message-id around point."
3409 (let ((point (point)))
3410 (search-forward ">" nil t) ;Move point to end of "<....>".
3411 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3412 (let ((message-id (match-string 1)))
3414 (set-buffer gnus-summary-buffer)
3415 (gnus-summary-refer-article message-id))
3417 (error "No references around point"))))
3419 (defun gnus-article-show-summary ()
3420 "Reconfigure windows to show summary buffer."
3422 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3423 (error "There is no summary buffer for this article buffer")
3424 (gnus-article-set-globals)
3425 (gnus-configure-windows 'article)
3426 (gnus-summary-goto-subject gnus-current-article)
3427 (gnus-summary-position-point)))
3429 (defun gnus-article-describe-briefly ()
3430 "Describe article mode commands briefly."
3432 (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")))
3434 (defun gnus-article-summary-command ()
3435 "Execute the last keystroke in the summary buffer."
3437 (let ((obuf (current-buffer))
3438 (owin (current-window-configuration))
3440 (switch-to-buffer gnus-article-current-summary 'norecord)
3441 (setq func (lookup-key (current-local-map) (this-command-keys)))
3442 (call-interactively func)
3444 (set-window-configuration owin)
3445 (set-window-point (get-buffer-window (current-buffer)) (point))))
3447 (defun gnus-article-summary-command-nosave ()
3448 "Execute the last keystroke in the summary buffer."
3451 (pop-to-buffer gnus-article-current-summary 'norecord)
3452 (setq func (lookup-key (current-local-map) (this-command-keys)))
3453 (call-interactively func)))
3455 (defun gnus-article-check-buffer ()
3456 "Beep if not in an article buffer."
3457 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3458 (error "Command invoked outside of a Gnus article buffer")))
3460 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3461 "Read a summary buffer key sequence and execute it from the article buffer."
3463 (gnus-article-check-buffer)
3465 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3466 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3467 "=" "^" "\M-^" "|"))
3473 '("n" "Gn" "p" "Gp"))
3476 (set-buffer gnus-article-current-summary)
3477 (let (gnus-pick-mode)
3478 (push (or key last-command-event) unread-command-events)
3479 (setq keys (read-key-sequence nil))))
3482 (if (or (member keys nosaves)
3483 (member keys nosave-but-article)
3484 (member keys nosave-in-article))
3486 (save-window-excursion
3487 (pop-to-buffer gnus-article-current-summary 'norecord)
3488 ;; We disable the pick minor mode commands.
3489 (let (gnus-pick-mode)
3490 (setq func (lookup-key (current-local-map) keys))))
3493 (unless (member keys nosave-in-article)
3494 (set-buffer gnus-article-current-summary))
3495 (call-interactively func)
3496 (setq new-sum-point (point)))
3497 (when (member keys nosave-but-article)
3498 (pop-to-buffer gnus-article-buffer 'norecord)))
3499 ;; These commands should restore window configuration.
3500 (let ((obuf (current-buffer))
3501 (owin (current-window-configuration))
3503 (summary gnus-article-current-summary)
3504 func in-buffer selected)
3505 (if not-restore-window
3506 (pop-to-buffer summary 'norecord)
3507 (switch-to-buffer summary 'norecord))
3508 (setq in-buffer (current-buffer))
3509 ;; We disable the pick minor mode commands.
3510 (if (setq func (let (gnus-pick-mode)
3511 (lookup-key (current-local-map) keys)))
3513 (call-interactively func)
3514 (setq new-sum-point (point)))
3516 (when (eq in-buffer (current-buffer))
3517 (setq selected (gnus-summary-select-article))
3519 (unless not-restore-window
3520 (set-window-configuration owin))
3521 (when (eq selected 'old)
3523 (set-window-start (get-buffer-window (current-buffer))
3525 (set-window-point (get-buffer-window (current-buffer))
3527 (let ((win (get-buffer-window gnus-article-current-summary)))
3529 (set-window-point win new-sum-point))))))))
3531 (defun gnus-article-hide (&optional arg force)
3532 "Hide all the gruft in the current article.
3533 This means that PGP stuff, signatures, cited text and (some)
3534 headers will be hidden.
3535 If given a prefix, show the hidden text instead."
3536 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3537 (gnus-article-hide-headers arg)
3538 (gnus-article-hide-pgp arg)
3539 (gnus-article-hide-citation-maybe arg force)
3540 (gnus-article-hide-signature arg))
3542 (defun gnus-article-maybe-highlight ()
3543 "Do some article highlighting if article highlighting is requested."
3544 (when (gnus-visual-p 'article-highlight 'highlight)
3545 (gnus-article-highlight-some)))
3547 (defun gnus-check-group-server ()
3548 ;; Make sure the connection to the server is alive.
3549 (unless (gnus-server-opened
3550 (gnus-find-method-for-group gnus-newsgroup-name))
3551 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3552 (gnus-request-group gnus-newsgroup-name t)))
3554 (defun gnus-request-article-this-buffer (article group)
3555 "Get an article and insert it into this buffer."
3556 (let (do-update-line sparse-header)
3560 (gnus-kill-all-overlays)
3561 (setq group (or group gnus-newsgroup-name))
3563 ;; Using `gnus-request-article' directly will insert the article into
3564 ;; `nntp-server-buffer' - so we'll save some time by not having to
3565 ;; copy it from the server buffer into the article buffer.
3567 ;; We only request an article by message-id when we do not have the
3568 ;; headers for it, so we'll have to get those.
3569 (when (stringp article)
3570 (let ((gnus-override-method gnus-refer-article-method))
3571 (gnus-read-header article)))
3573 ;; If the article number is negative, that means that this article
3574 ;; doesn't belong in this newsgroup (possibly), so we find its
3575 ;; message-id and request it by id instead of number.
3576 (when (and (numberp article)
3578 (get-buffer gnus-summary-buffer)
3579 (gnus-buffer-exists-p gnus-summary-buffer))
3581 (set-buffer gnus-summary-buffer)
3582 (let ((header (gnus-summary-article-header article)))
3585 ((memq article gnus-newsgroup-sparse)
3586 ;; This is a sparse gap article.
3587 (setq do-update-line article)
3588 (setq article (mail-header-id header))
3589 (let ((gnus-override-method gnus-refer-article-method))
3590 (setq sparse-header (gnus-read-header article)))
3591 (setq gnus-newsgroup-sparse
3592 (delq article gnus-newsgroup-sparse)))
3594 ;; It's a real article.
3595 (setq article (mail-header-id header)))
3597 ;; It is an extracted pseudo-article.
3598 (setq article 'pseudo)
3599 (gnus-request-pseudo-article header))))
3601 (let ((method (gnus-find-method-for-group
3602 gnus-newsgroup-name)))
3603 (when (and (eq (car method) 'nneething)
3606 (file-name-as-directory
3607 (or (cadr (assq 'nneething-address method))
3609 (mail-header-subject header))))
3610 (when (file-directory-p dir)
3611 (setq article 'nneething)
3612 (gnus-group-enter-directory dir))))))))
3615 ;; Refuse to select canceled articles.
3616 ((and (numberp article)
3618 (get-buffer gnus-summary-buffer)
3619 (gnus-buffer-exists-p gnus-summary-buffer)
3620 (eq (cdr (save-excursion
3621 (set-buffer gnus-summary-buffer)
3622 (assq article gnus-newsgroup-reads)))
3623 gnus-canceled-mark))
3625 ;; Check the backlog.
3626 ((and gnus-keep-backlog
3627 (gnus-backlog-request-article group article (current-buffer)))
3629 ;; Check asynchronous pre-fetch.
3630 ((gnus-async-request-fetched-article group article (current-buffer))
3631 (gnus-async-prefetch-next group article gnus-summary-buffer)
3632 (when (and (numberp article) gnus-keep-backlog)
3633 (gnus-backlog-enter-article group article (current-buffer)))
3636 ((and gnus-use-cache
3638 (gnus-cache-request-article article group))
3640 ;; Get the article and put into the article buffer.
3641 ((or (stringp article) (numberp article))
3642 (let ((gnus-override-method
3643 (and (stringp article) gnus-refer-article-method))
3644 (buffer-read-only nil))
3646 (gnus-kill-all-overlays)
3647 (gnus-check-group-server)
3648 (when (gnus-request-article article group (current-buffer))
3649 (when (numberp article)
3650 (gnus-async-prefetch-next group article gnus-summary-buffer)
3651 (when gnus-keep-backlog
3652 (gnus-backlog-enter-article
3653 group article (current-buffer))))
3658 ;; Associate this article with the current summary buffer.
3659 (setq gnus-article-current-summary gnus-summary-buffer)
3661 ;; Take the article from the original article buffer
3662 ;; and place it in the buffer it's supposed to be in.
3663 (when (and (get-buffer gnus-article-buffer)
3664 (equal (buffer-name (current-buffer))
3665 (buffer-name (get-buffer gnus-article-buffer))))
3667 (if (get-buffer gnus-original-article-buffer)
3668 (set-buffer gnus-original-article-buffer)
3669 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3670 (buffer-disable-undo)
3671 (setq major-mode 'gnus-original-article-mode)
3672 (setq buffer-read-only t))
3673 (let (buffer-read-only)
3675 (insert-buffer-substring gnus-article-buffer))
3676 (setq gnus-original-article (cons group article)))
3679 (run-hooks 'gnus-article-decode-hook)
3680 ;; Mark article as decoded or not.
3681 (setq gnus-article-decoded-p gnus-article-decode-hook))
3683 ;; Update sparse articles.
3684 (when (and do-update-line
3685 (or (numberp article)
3687 (let ((buf (current-buffer)))
3688 (set-buffer gnus-summary-buffer)
3689 (gnus-summary-update-article do-update-line sparse-header)
3690 (gnus-summary-goto-subject do-update-line nil t)
3691 (set-window-point (get-buffer-window (current-buffer) t)
3693 (set-buffer buf))))))
3699 (defcustom gnus-article-edit-mode-hook nil
3700 "Hook run in article edit mode buffers."
3701 :group 'gnus-article-various
3704 (defcustom gnus-article-edit-article-setup-function
3705 'gnus-article-mime-edit-article-setup
3706 "Function called to setup an editing article buffer."
3707 :group 'gnus-article-various
3710 (defvar gnus-article-edit-done-function nil)
3712 (defvar gnus-article-edit-mode-map nil)
3714 ;; Should we be using derived.el for this?
3715 (unless gnus-article-edit-mode-map
3716 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3717 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3719 (gnus-define-keys gnus-article-edit-mode-map
3720 "\C-c\C-c" gnus-article-edit-done
3721 "\C-c\C-k" gnus-article-edit-exit)
3723 (gnus-define-keys (gnus-article-edit-wash-map
3724 "\C-c\C-w" gnus-article-edit-mode-map)
3725 "f" gnus-article-edit-full-stops))
3727 (defun gnus-article-edit-mode ()
3728 "Major mode for editing articles.
3729 This is an extended text-mode.
3731 \\{gnus-article-edit-mode-map}"
3733 (setq major-mode 'gnus-article-edit-mode)
3734 (setq mode-name "Article Edit")
3735 (use-local-map gnus-article-edit-mode-map)
3736 (make-local-variable 'gnus-article-edit-done-function)
3737 (make-local-variable 'gnus-prev-winconf)
3738 (setq buffer-read-only nil)
3739 (buffer-enable-undo)
3741 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3743 (defun gnus-article-edit (&optional force)
3744 "Edit the current article.
3745 This will have permanent effect only in mail groups.
3746 If FORCE is non-nil, allow editing of articles even in read-only
3749 (when (and (not force)
3750 (gnus-group-read-only-p))
3751 (error "The current newsgroup does not support article editing"))
3752 (gnus-article-date-original)
3753 (gnus-article-edit-article
3755 `(lambda (no-highlight)
3757 (gnus-summary-edit-article-done
3758 ,(or (mail-header-references gnus-current-headers) "")
3759 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3761 (defun gnus-article-edit-article (start-func exit-func)
3762 "Start editing the contents of the current article buffer."
3763 (let ((winconf (current-window-configuration)))
3764 (set-buffer gnus-article-buffer)
3765 (gnus-article-edit-mode)
3766 (funcall start-func)
3767 ;;(gnus-article-delete-text-of-type 'annotation)
3768 ;;(gnus-set-text-properties (point-min) (point-max) nil)
3769 (gnus-configure-windows 'edit-article)
3770 (setq gnus-article-edit-done-function exit-func)
3771 (setq gnus-prev-winconf winconf)
3772 (when gnus-article-edit-article-setup-function
3773 (funcall gnus-article-edit-article-setup-function))
3774 (gnus-message 6 "C-c C-c to end edits")))
3776 (defun gnus-article-edit-done (&optional arg)
3777 "Update the article edits and exit."
3782 (when (article-goto-body)
3783 (let ((lines (count-lines (point) (point-max)))
3784 (length (- (point-max) (point)))
3785 (case-fold-search t)
3786 (body (copy-marker (point))))
3787 (goto-char (point-min))
3788 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3789 (delete-region (match-beginning 1) (match-end 1))
3790 (insert (number-to-string length)))
3791 (goto-char (point-min))
3792 (when (re-search-forward
3793 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3794 (delete-region (match-beginning 1) (match-end 1))
3795 (insert (number-to-string length)))
3796 (goto-char (point-min))
3797 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3798 (delete-region (match-beginning 1) (match-end 1))
3799 (insert (number-to-string lines)))))))
3800 (let ((func gnus-article-edit-done-function)
3801 (buf (current-buffer))
3802 (start (window-start)))
3803 (remove-hook 'gnus-article-mode-hook
3804 'gnus-article-mime-edit-article-unwind)
3805 (gnus-article-edit-exit)
3808 (let ((buffer-read-only nil))
3810 ;; The cache and backlog have to be flushed somewhat.
3811 (when gnus-keep-backlog
3812 (gnus-backlog-remove-article
3813 (car gnus-article-current) (cdr gnus-article-current)))
3814 ;; Flush original article as well.
3816 (when (get-buffer gnus-original-article-buffer)
3817 (set-buffer gnus-original-article-buffer)
3818 (setq gnus-original-article nil)))
3819 (when gnus-use-cache
3820 (gnus-cache-update-article
3821 (car gnus-article-current) (cdr gnus-article-current))))
3823 (set-window-start (get-buffer-window buf) start)
3824 (set-window-point (get-buffer-window buf) (point))))
3826 (defun gnus-article-edit-exit ()
3827 "Exit the article editing without updating."
3829 ;; We remove all text props from the article buffer.
3830 (let ((buf (format "%s" (buffer-string)))
3831 (curbuf (current-buffer))
3833 (window-start (window-start)))
3836 (let ((winconf gnus-prev-winconf))
3838 (set-window-configuration winconf)
3839 ;; Tippy-toe some to make sure that point remains where it was.
3840 (save-current-buffer
3842 (set-window-start (get-buffer-window (current-buffer)) window-start)
3845 (defun gnus-article-edit-full-stops ()
3846 "Interactively repair spacing at end of sentences."
3849 (goto-char (point-min))
3850 (search-forward-regexp "^$" nil t)
3851 (let ((case-fold-search nil))
3852 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3855 ;;; Article editing with MIME-Edit
3858 (defcustom gnus-article-mime-edit-article-setup-hook nil
3859 "Hook run after setting up a MIME editing article buffer."
3860 :group 'gnus-article-various
3863 (defun gnus-article-mime-edit-article-unwind ()
3864 "Unwind `gnus-article-buffer' if article editing was given up."
3865 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3866 (when mime-edit-mode-flag
3867 (mime-edit-exit 'nomime 'no-error)
3869 (when (featurep 'font-lock)
3870 (setq font-lock-defaults nil)
3871 (font-lock-mode 0)))
3873 (defun gnus-article-mime-edit-article-setup ()
3874 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3875 after replacing with the original article."
3876 (setq gnus-show-mime t)
3877 (setq gnus-article-edit-done-function
3878 `(lambda (&rest args)
3879 (when mime-edit-mode-flag
3882 (goto-char (point-min))
3883 (let (case-fold-search)
3884 (when (re-search-forward
3885 (format "^%s$" (regexp-quote mail-header-separator))
3887 (replace-match "")))
3888 (when (featurep 'font-lock)
3889 (setq font-lock-defaults nil)
3891 (apply ,gnus-article-edit-done-function args)
3892 (set-buffer gnus-original-article-buffer)
3894 (insert-buffer gnus-article-buffer)
3895 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3896 (gnus-article-prepare-display)))
3897 (substitute-key-definition
3898 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3899 gnus-article-edit-mode-map)
3901 (insert-buffer gnus-original-article-buffer)
3903 (when (featurep 'font-lock)
3904 (set (make-local-variable 'font-lock-defaults)
3905 '(message-font-lock-keywords t))
3906 (font-lock-set-defaults)
3907 (turn-on-font-lock))
3908 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3909 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3911 (defun gnus-article-mime-edit-exit ()
3912 "Exit the article MIME editing without updating."
3914 (let ((winconf gnus-prev-winconf)
3916 (when mime-edit-mode-flag
3919 (goto-char (point-min))
3920 (let (case-fold-search)
3921 (when (re-search-forward
3922 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3923 (replace-match "")))
3924 (when (featurep 'font-lock)
3925 (setq font-lock-defaults nil)
3927 ;; We remove all text props from the article buffer.
3928 (setq buf (format "%s" (buffer-string)))
3929 (set-buffer (get-buffer-create gnus-original-article-buffer))
3932 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3933 (gnus-article-prepare-display)
3934 (set-window-configuration winconf)))
3937 ;;; Article highlights
3940 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3942 ;;; Internal Variables:
3944 (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\\)"
3945 "Regular expression that matches URLs."
3946 :group 'gnus-article-buttons
3949 (defcustom gnus-button-alist
3950 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3951 0 t gnus-button-message-id 2)
3952 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3953 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3955 gnus-button-fetch-group 4)
3956 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3957 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3958 t gnus-button-message-id 3)
3959 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3960 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3961 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3962 ;; This is how URLs _should_ be embedded in text...
3963 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3965 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3966 "*Alist of regexps matching buttons in article bodies.
3968 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3969 REGEXP: is the string matching text around the button,
3970 BUTTON: is the number of the regexp grouping actually matching the button,
3971 FORM: is a lisp expression which must eval to true for the button to
3973 CALLBACK: is the function to call when the user push this button, and each
3974 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3976 CALLBACK can also be a variable, in that case the value of that
3977 variable it the real callback function."
3978 :group 'gnus-article-buttons
3979 :type '(repeat (list regexp
3980 (integer :tag "Button")
3982 (function :tag "Callback")
3985 (integer :tag "Regexp group")))))
3987 (defcustom gnus-header-button-alist
3988 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3989 0 t gnus-button-message-id 0)
3990 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3991 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3992 0 t gnus-button-mailto 0)
3993 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3994 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3995 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3996 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3997 gnus-button-message-id 3))
3998 "*Alist of headers and regexps to match buttons in article heads.
4000 This alist is very similar to `gnus-button-alist', except that each
4001 alist has an additional HEADER element first in each entry:
4003 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4005 HEADER is a regexp to match a header. For a fuller explanation, see
4006 `gnus-button-alist'."
4007 :group 'gnus-article-buttons
4008 :group 'gnus-article-headers
4009 :type '(repeat (list (regexp :tag "Header")
4011 (integer :tag "Button")
4013 (function :tag "Callback")
4016 (integer :tag "Regexp group")))))
4018 (defvar gnus-button-regexp nil)
4019 (defvar gnus-button-marker-list nil)
4020 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4022 (defvar gnus-button-last nil)
4023 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4027 (defun gnus-article-push-button (event)
4028 "Check text under the mouse pointer for a callback function.
4029 If the text under the mouse pointer has a `gnus-callback' property,
4030 call it with the value of the `gnus-data' text property."
4032 (set-buffer (window-buffer (posn-window (event-start event))))
4033 (let* ((pos (posn-point (event-start event)))
4034 (data (get-text-property pos 'gnus-data))
4035 (fun (get-text-property pos 'gnus-callback)))
4038 (funcall fun data))))
4040 (defun gnus-article-press-button ()
4041 "Check text at point for a callback function.
4042 If the text at point has a `gnus-callback' property,
4043 call it with the value of the `gnus-data' text property."
4045 (let* ((data (get-text-property (point) 'gnus-data))
4046 (fun (get-text-property (point) 'gnus-callback)))
4048 (funcall fun data))))
4050 (defun gnus-article-prev-button (n)
4051 "Move point to N buttons backward.
4052 If N is negative, move forward instead."
4054 (gnus-article-next-button (- n)))
4056 (defun gnus-article-next-button (n)
4057 "Move point to N buttons forward.
4058 If N is negative, move backward instead."
4060 (let ((function (if (< n 0) 'previous-single-property-change
4061 'next-single-property-change))
4062 (inhibit-point-motion-hooks t)
4064 (limit (if (< n 0) (point-min) (point-max))))
4066 (while (and (not (= limit (point)))
4068 ;; Skip past the current button.
4069 (when (get-text-property (point) 'gnus-callback)
4070 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4071 ;; Go to the next (or previous) button.
4072 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4073 ;; Put point at the start of the button.
4074 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4075 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4076 ;; Skip past intangible buttons.
4077 (when (get-text-property (point) 'intangible)
4081 (gnus-message 5 "No more buttons"))
4084 (defun gnus-article-highlight (&optional force)
4085 "Highlight current article.
4086 This function calls `gnus-article-highlight-headers',
4087 `gnus-article-highlight-citation',
4088 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4089 do the highlighting. See the documentation for those functions."
4090 (interactive (list 'force))
4091 (gnus-article-highlight-headers)
4092 (gnus-article-highlight-citation force)
4093 (gnus-article-highlight-signature)
4094 (gnus-article-add-buttons force)
4095 (gnus-article-add-buttons-to-head))
4097 (defun gnus-article-highlight-some (&optional force)
4098 "Highlight current article.
4099 This function calls `gnus-article-highlight-headers',
4100 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4101 do the highlighting. See the documentation for those functions."
4102 (interactive (list 'force))
4103 (gnus-article-highlight-headers)
4104 (gnus-article-highlight-signature)
4105 (gnus-article-add-buttons))
4107 (defun gnus-article-highlight-headers ()
4108 "Highlight article headers as specified by `gnus-header-face-alist'."
4111 (set-buffer gnus-article-buffer)
4113 (let ((alist gnus-header-face-alist)
4114 (buffer-read-only nil)
4115 (case-fold-search t)
4116 (inhibit-point-motion-hooks t)
4117 entry regexp header-face field-face from hpoints fpoints)
4118 (article-narrow-to-head)
4119 (while (setq entry (pop alist))
4120 (goto-char (point-min))
4121 (setq regexp (concat "^\\("
4122 (if (string-equal "" (nth 0 entry))
4126 header-face (nth 1 entry)
4127 field-face (nth 2 entry))
4128 (while (and (re-search-forward regexp nil t)
4132 (unless (search-forward ":" nil t)
4134 (when (and header-face
4135 (not (memq (point) hpoints)))
4136 (push (point) hpoints)
4137 (gnus-put-text-property from (point) 'face header-face))
4138 (when (and field-face
4139 (not (memq (setq from (point)) fpoints)))
4141 (if (re-search-forward "^[^ \t]" nil t)
4143 (goto-char (point-max)))
4144 (gnus-put-text-property from (point) 'face field-face))))))))
4146 (defun gnus-article-highlight-signature ()
4147 "Highlight the signature in an article.
4148 It does this by highlighting everything after
4149 `gnus-signature-separator' using `gnus-signature-face'."
4152 (set-buffer gnus-article-buffer)
4153 (let ((buffer-read-only nil)
4154 (inhibit-point-motion-hooks t))
4156 (when (and gnus-signature-face
4157 (gnus-article-narrow-to-signature))
4158 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4159 'face gnus-signature-face)
4161 (gnus-article-search-signature)
4162 (let ((start (match-beginning 0))
4163 (end (set-marker (make-marker) (1+ (match-end 0)))))
4164 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4167 (defun gnus-button-in-region-p (b e prop)
4168 "Say whether PROP exists in the region."
4169 (text-property-not-all b e prop nil))
4171 (defun gnus-article-add-buttons (&optional force)
4172 "Find external references in the article and make buttons of them.
4173 \"External references\" are things like Message-IDs and URLs, as
4174 specified by `gnus-button-alist'."
4175 (interactive (list 'force))
4177 (set-buffer gnus-article-buffer)
4178 (let ((buffer-read-only nil)
4179 (inhibit-point-motion-hooks t)
4180 (case-fold-search t)
4181 (alist gnus-button-alist)
4183 ;; Remove all old markers.
4185 (while (setq marker (pop gnus-button-marker-list))
4187 (when (setq entry (gnus-button-entry))
4188 (put-text-property (match-beginning (nth 1 entry))
4189 (match-end (nth 1 entry))
4190 'gnus-callback nil))
4191 (set-marker marker nil)))
4192 ;; We skip the headers.
4195 (while (setq entry (pop alist))
4196 (setq regexp (car entry))
4198 (while (re-search-forward regexp nil t)
4199 (let* ((start (and entry (match-beginning (nth 1 entry))))
4200 (end (and entry (match-end (nth 1 entry))))
4201 (from (match-beginning 0)))
4202 (when (and (or (eq t (nth 2 entry))
4203 (eval (nth 2 entry)))
4204 (not (gnus-button-in-region-p
4205 start end 'gnus-callback)))
4206 ;; That optional form returned non-nil, so we add the
4208 (gnus-article-add-button
4209 start end 'gnus-button-push
4210 (car (push (set-marker (make-marker) from)
4211 gnus-button-marker-list))))))))))
4213 ;; Add buttons to the head of an article.
4214 (defun gnus-article-add-buttons-to-head ()
4215 "Add buttons to the head of the article."
4218 (set-buffer gnus-article-buffer)
4220 (let ((buffer-read-only nil)
4221 (inhibit-point-motion-hooks t)
4222 (case-fold-search t)
4223 (alist gnus-header-button-alist)
4225 (article-narrow-to-head)
4227 ;; Each alist entry.
4228 (setq entry (car alist)
4230 (goto-char (point-min))
4231 (while (re-search-forward (car entry) nil t)
4232 ;; Each header matching the entry.
4233 (setq beg (match-beginning 0))
4234 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4235 (match-beginning 0))
4238 (while (re-search-forward (nth 1 entry) end t)
4239 ;; Each match within a header.
4240 (let* ((entry (cdr entry))
4241 (start (match-beginning (nth 1 entry)))
4242 (end (match-end (nth 1 entry)))
4243 (form (nth 2 entry)))
4244 (goto-char (match-end 0))
4246 (gnus-article-add-button
4247 start end (nth 3 entry)
4248 (buffer-substring (match-beginning (nth 4 entry))
4249 (match-end (nth 4 entry)))))))
4250 (goto-char end)))))))
4252 ;;; External functions:
4254 (defun gnus-article-add-button (from to fun &optional data)
4255 "Create a button between FROM and TO with callback FUN and data DATA."
4256 (when gnus-article-button-face
4257 (gnus-overlay-put (gnus-make-overlay from to)
4258 'face gnus-article-button-face))
4259 (gnus-add-text-properties
4261 (nconc (and gnus-article-mouse-face
4262 (list gnus-mouse-face-prop gnus-article-mouse-face))
4263 (list 'gnus-callback fun)
4264 (and data (list 'gnus-data data)))))
4266 ;;; Internal functions:
4268 (defun gnus-article-set-globals ()
4270 (set-buffer gnus-summary-buffer)
4271 (gnus-set-global-variables)))
4273 (defun gnus-signature-toggle (end)
4275 (set-buffer gnus-article-buffer)
4276 (let ((buffer-read-only nil)
4277 (inhibit-point-motion-hooks t))
4278 (if (get-text-property end 'invisible)
4279 (gnus-article-unhide-text end (point-max))
4280 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4282 (defun gnus-button-entry ()
4283 ;; Return the first entry in `gnus-button-alist' matching this place.
4284 (let ((alist gnus-button-alist)
4287 (setq entry (pop alist))
4288 (if (looking-at (car entry))
4293 (defun gnus-button-push (marker)
4294 ;; Push button starting at MARKER.
4297 (let* ((entry (gnus-button-entry))
4298 (inhibit-point-motion-hooks t)
4300 (args (mapcar (lambda (group)
4301 (let ((string (match-string group)))
4302 (gnus-set-text-properties
4303 0 (length string) nil string)
4310 (fboundp (symbol-value fun)))
4311 (apply (symbol-value fun) args))
4313 (gnus-message 1 "You must define `%S' to use this button"
4314 (cons fun args)))))))
4316 (defun gnus-button-message-id (message-id)
4319 (set-buffer gnus-summary-buffer)
4320 (gnus-summary-refer-article message-id)))
4322 (defun gnus-button-fetch-group (address)
4323 "Fetch GROUP specified by ADDRESS."
4324 (if (not (string-match "[:/]" address))
4325 ;; This is just a simple group url.
4326 (gnus-group-read-ephemeral-group address gnus-select-method)
4327 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4329 (error "Can't parse %s" address)
4330 (gnus-group-read-ephemeral-group
4331 (match-string 4 address)
4332 `(nntp ,(match-string 1 address)
4333 (nntp-address ,(match-string 1 address))
4334 (nntp-port-number ,(if (match-end 3)
4335 (match-string 3 address)
4338 (defun gnus-url-parse-query-string (query &optional downcase)
4339 (let (retval pairs cur key val)
4340 (setq pairs (split-string query "&"))
4342 (setq cur (car pairs)
4344 (if (not (string-match "=" cur))
4346 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4347 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4349 (setq key (downcase key)))
4350 (setq cur (assoc key retval))
4352 (setcdr cur (cons val (cdr cur)))
4353 (setq retval (cons (list key val) retval)))))
4356 (defun gnus-url-unhex (x)
4363 (defun gnus-url-unhex-string (str &optional allow-newlines)
4364 "Remove %XXX embedded spaces, etc in a url.
4365 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4366 decoding of carriage returns and line feeds in the string, which is normally
4367 forbidden in URL encoding."
4368 (setq str (or str ""))
4370 (case-fold-search t))
4371 (while (string-match "%[0-9a-f][0-9a-f]" str)
4372 (let* ((start (match-beginning 0))
4373 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4375 (gnus-url-unhex (elt str (+ start 2))))))
4377 tmp (substring str 0 start)
4380 (char-to-string code))
4381 ((or (= code ?\n) (= code ?\r))
4383 (t (char-to-string code))))
4384 str (substring str (match-end 0)))))
4385 (setq tmp (concat tmp str))
4388 (defun gnus-url-mailto (url)
4389 ;; Send mail to someone
4390 (when (string-match "mailto:/*\\(.*\\)" url)
4391 (setq url (substring url (match-beginning 1) nil)))
4392 (let (to args subject func)
4393 (if (string-match (regexp-quote "?") url)
4394 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4395 args (gnus-url-parse-query-string
4396 (substring url (match-end 0) nil) t))
4397 (setq to (gnus-url-unhex-string url)))
4398 (setq args (cons (list "to" to) args)
4399 subject (cdr-safe (assoc "subject" args)))
4400 (gnus-setup-message 'reply
4403 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4406 (message-position-on-field (caar args)))
4407 (insert (mapconcat 'identity (cdar args) ", "))
4408 (setq args (cdr args)))
4411 (message-goto-subject)))))
4413 (defun gnus-button-mailto (address)
4415 (set-buffer (gnus-copy-article-buffer))
4416 (gnus-setup-message 'reply
4417 (message-reply address)))
4419 (defun gnus-button-reply (address)
4420 ;; Reply to ADDRESS.
4421 (gnus-setup-message 'reply
4422 (message-reply address)))
4424 (defun gnus-button-url (address)
4426 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4427 (if (listp browse-url-browser-function)
4428 (browse-url address)
4429 (funcall browse-url-browser-function address)))
4431 (defun gnus-button-embedded-url (address)
4433 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4434 (if (listp browse-url-browser-function)
4435 (browse-url (gnus-strip-whitespace address))
4436 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4438 ;;; Next/prev buttons in the article buffer.
4440 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4441 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4443 (defvar gnus-prev-page-map nil)
4444 (unless gnus-prev-page-map
4445 (setq gnus-prev-page-map (make-sparse-keymap))
4446 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4447 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4449 (defun gnus-insert-prev-page-button ()
4450 (let ((buffer-read-only nil))
4452 gnus-prev-page-line-format nil
4453 `(gnus-prev t local-map ,gnus-prev-page-map
4454 gnus-callback gnus-article-button-prev-page
4455 article-type annotation))))
4457 (defvar gnus-next-page-map nil)
4458 (unless gnus-next-page-map
4459 (setq gnus-next-page-map (make-keymap))
4460 (suppress-keymap gnus-prev-page-map)
4461 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4462 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4464 (defun gnus-button-next-page ()
4465 "Go to the next page."
4467 (let ((win (selected-window)))
4468 (select-window (get-buffer-window gnus-article-buffer t))
4469 (gnus-article-next-page)
4470 (select-window win)))
4472 (defun gnus-button-prev-page ()
4473 "Go to the prev page."
4475 (let ((win (selected-window)))
4476 (select-window (get-buffer-window gnus-article-buffer t))
4477 (gnus-article-prev-page)
4478 (select-window win)))
4480 (defun gnus-insert-next-page-button ()
4481 (let ((buffer-read-only nil))
4482 (gnus-eval-format gnus-next-page-line-format nil
4484 t local-map ,gnus-next-page-map
4485 gnus-callback gnus-article-button-next-page
4486 article-type annotation))))
4488 (defun gnus-article-button-next-page (arg)
4489 "Go to the next page."
4491 (let ((win (selected-window)))
4492 (select-window (get-buffer-window gnus-article-buffer t))
4493 (gnus-article-next-page)
4494 (select-window win)))
4496 (defun gnus-article-button-prev-page (arg)
4497 "Go to the prev page."
4499 (let ((win (selected-window)))
4500 (select-window (get-buffer-window gnus-article-buffer t))
4501 (gnus-article-prev-page)
4502 (select-window win)))
4504 (defvar gnus-decode-header-methods
4505 '(mail-decode-encoded-word-region)
4506 "List of methods used to decode headers.
4508 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4509 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4510 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4511 whose names match REGEXP.
4514 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4515 mail-decode-encoded-word-region
4516 (\"chinese\" . rfc1843-decode-region))
4519 (defvar gnus-decode-header-methods-cache nil)
4521 (defun gnus-multi-decode-header (start end)
4522 "Apply the functions from `gnus-encoded-word-methods' that match."
4523 (unless (and gnus-decode-header-methods-cache
4524 (eq gnus-newsgroup-name
4525 (car gnus-decode-header-methods-cache)))
4526 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4529 (nconc gnus-decode-header-methods-cache (list x))
4530 (if (and gnus-newsgroup-name
4531 (string-match (car x) gnus-newsgroup-name))
4532 (nconc gnus-decode-header-methods-cache
4534 gnus-decode-header-methods))
4535 (let ((xlist gnus-decode-header-methods-cache))
4538 (narrow-to-region start end)
4540 (funcall (pop xlist) (point-min) (point-max))))))
4543 ;;; Treatment top-level handling.
4546 (defun gnus-treat-article (condition &optional part-number total-parts type)
4547 (let ((length (- (point-max) (point-min)))
4548 (alist gnus-treatment-function-alist)
4549 (article-goto-body-goes-to-point-min-p t)
4553 (let ((list gnus-article-treat-types))
4555 (when (string-match (pop list) type)
4556 (throw 'found t)))))))
4557 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4559 (gnus-run-hooks 'gnus-part-display-hook)
4560 (while (setq elem (pop alist))
4561 (setq val (symbol-value (car elem)))
4562 (when (and (or (consp val)
4564 (gnus-treat-predicate val)
4565 (or (not (get (car elem) 'highlight))
4568 (funcall (cadr elem)))))))
4570 ;; Dynamic variables.
4571 (defvar part-number)
4572 (defvar total-parts)
4576 (defun gnus-treat-predicate (val)
4587 (eq part-number total-parts))
4591 (let ((pred (pop val)))
4594 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4596 (apply 'gnus-and (mapcar 'gnus-tread-predicate val)))
4598 (not (gnus-treat-predicate val)))
4600 (equal (cadr val) type))
4602 (error "%S is not a valid predicate" pred)))))
4604 (error "%S is not a valid value" val))))
4610 (defun gnus-article-header-presentation-method (entity situation)
4611 (mime-insert-header entity)
4614 (set-alist 'mime-header-presentation-method-alist
4615 'gnus-original-article-mode
4616 #'gnus-article-header-presentation-method)
4618 (defun gnus-mime-preview-quitting-method ()
4619 (mime-preview-kill-buffer)
4620 (delete-other-windows)
4621 (gnus-article-show-summary)
4622 (gnus-summary-select-article gnus-show-all-headers t))
4624 (set-alist 'mime-preview-quitting-method-alist
4625 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
4627 (defun gnus-following-method (buf)
4630 (message-yank-original)
4632 (goto-char (point-min))
4635 (set-alist 'mime-preview-following-method-alist
4636 'gnus-original-article-mode #'gnus-following-method)
4638 (set-alist 'mime-preview-over-to-previous-method-alist
4639 'gnus-original-article-mode
4641 (gnus-article-read-summary-keys
4642 nil (gnus-character-to-event ?P))))
4644 (set-alist 'mime-preview-over-to-next-method-alist
4645 'gnus-original-article-mode'
4647 (gnus-article-read-summary-keys
4648 nil (gnus-character-to-event ?N))))
4658 (run-hooks 'gnus-art-load-hook)
4660 ;;; gnus-art.el ends here