1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
62 (defgroup gnus-article-signature nil
64 :link '(custom-manual "(gnus)Article Signature")
67 (defgroup gnus-article-headers nil
69 :link '(custom-manual "(gnus)Hiding Headers")
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
82 (defgroup gnus-article-saving nil
84 :link '(custom-manual "(gnus)Saving Articles")
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
102 (defcustom gnus-ignored-headers
103 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
104 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
105 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
106 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
107 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
108 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
109 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
110 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
111 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
112 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
113 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
114 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
115 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
116 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
117 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
120 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
121 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
122 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
123 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
124 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
125 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
126 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
127 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
128 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
129 "^X-Received:" "^Content-length:" "X-precedence:")
130 "*All headers that start with this regexp will be hidden.
131 This variable can also be a list of regexps of headers to be ignored.
132 If `gnus-visible-headers' is non-nil, this variable will be ignored."
133 :type '(choice :custom-show nil
136 :group 'gnus-article-hiding)
138 (defcustom gnus-visible-headers
139 "^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:"
140 "*All headers that do not match this regexp will be hidden.
141 This variable can also be a list of regexp of headers to remain visible.
142 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
143 :type '(repeat :value-to-internal (lambda (widget value)
144 (custom-split-regexp-maybe value))
145 :match (lambda (widget value)
147 (widget-editable-list-match widget value)))
149 :group 'gnus-article-hiding)
151 (defcustom gnus-sorted-header-list
152 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
153 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
154 "*This variable is a list of regular expressions.
155 If it is non-nil, headers that match the regular expressions will
156 be placed first in the article buffer in the sequence specified by
158 :type '(repeat regexp)
159 :group 'gnus-article-hiding)
161 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
162 "Headers that are only to be displayed if they have interesting data.
163 Possible values in this list are `empty', `newsgroups', `followup-to',
164 `reply-to', `date', `long-to', and `many-to'."
165 :type '(set (const :tag "Headers with no content." empty)
166 (const :tag "Newsgroups with only one group." newsgroups)
167 (const :tag "Followup-to identical to newsgroups." followup-to)
168 (const :tag "Reply-to identical to from." reply-to)
169 (const :tag "Date less than four days old." date)
170 (const :tag "Very long To and/or Cc header." long-to)
171 (const :tag "Multiple To and/or Cc headers." many-to))
172 :group 'gnus-article-hiding)
174 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
175 "Regexp matching signature separator.
176 This can also be a list of regexps. In that case, it will be checked
177 from head to tail looking for a separator. Searches will be done from
178 the end of the buffer."
179 :type '(repeat string)
180 :group 'gnus-article-signature)
182 (defcustom gnus-signature-limit nil
183 "Provide a limit to what is considered a signature.
184 If it is a number, no signature may not be longer (in characters) than
185 that number. If it is a floating point number, no signature may be
186 longer (in lines) than that number. If it is a function, the function
187 will be called without any parameters, and if it returns nil, there is
188 no signature in the buffer. If it is a string, it will be used as a
189 regexp. If it matches, the text in question is not a signature."
190 :type '(choice (integer :value 200)
192 (function :value fun)
193 (regexp :value ".*"))
194 :group 'gnus-article-signature)
196 (defcustom gnus-hidden-properties '(invisible t intangible t)
197 "Property list to use for hiding text."
199 :group 'gnus-article-hiding)
201 (defcustom gnus-article-x-face-command
202 (if (and (fboundp 'image-type-available-p)
203 (image-type-available-p 'xbm))
204 'gnus-article-display-xface
205 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -")
206 "*String or function to be executed to display an X-Face header.
207 If it is a string, the command will be executed in a sub-shell
208 asynchronously. The compressed face will be piped to this command."
209 :type '(choice string
210 (function-item gnus-article-display-xface)
212 :group 'gnus-article-washing)
214 (defcustom gnus-article-x-face-too-ugly nil
215 "Regexp matching posters whose face shouldn't be shown automatically."
216 :type '(choice regexp (const nil))
217 :group 'gnus-article-washing)
219 (defcustom gnus-emphasis-alist
221 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
223 '(("_" "_" underline)
226 ("_/" "/_" underline-italic)
227 ("_\\*" "\\*_" underline-bold)
228 ("\\*/" "/\\*" bold-italic)
229 ("_\\*/" "/\\*_" underline-bold-italic))))
230 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
231 2 3 gnus-emphasis-underline)
235 (format format (car spec) (cadr spec))
236 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
238 "*Alist that says how to fontify certain phrases.
239 Each item looks like this:
241 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
243 The first element is a regular expression to be matched. The second
244 is a number that says what regular expression grouping used to find
245 the entire emphasized word. The third is a number that says what
246 regexp grouping should be displayed and highlighted. The fourth
247 is the face used for highlighting."
248 :type '(repeat (list :value ("" 0 0 default)
250 (integer :tag "Match group")
251 (integer :tag "Emphasize group")
253 :group 'gnus-article-emphasis)
255 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
256 "A regexp to describe whitespace which should not be emphasized.
257 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
258 The former avoids underlining of leading and trailing whitespace,
259 and the latter avoids underlining any whitespace at all."
260 :group 'gnus-article-emphasis
263 (defface gnus-emphasis-bold '((t (:bold t)))
264 "Face used for displaying strong emphasized text (*word*)."
265 :group 'gnus-article-emphasis)
267 (defface gnus-emphasis-italic '((t (:italic t)))
268 "Face used for displaying italic emphasized text (/word/)."
269 :group 'gnus-article-emphasis)
271 (defface gnus-emphasis-underline '((t (:underline t)))
272 "Face used for displaying underlined emphasized text (_word_)."
273 :group 'gnus-article-emphasis)
275 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
276 "Face used for displaying underlined bold emphasized text (_*word*_)."
277 :group 'gnus-article-emphasis)
279 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
280 "Face used for displaying underlined italic emphasized text (_/word/_)."
281 :group 'gnus-article-emphasis)
283 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
284 "Face used for displaying bold italic emphasized text (/*word*/)."
285 :group 'gnus-article-emphasis)
287 (defface gnus-emphasis-underline-bold-italic
288 '((t (:bold t :italic t :underline t)))
289 "Face used for displaying underlined bold italic emphasized text.
290 Esample: (_/*word*/_)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-highlight-words
294 '((t (:background "black" :foreground "yellow")))
295 "Face used for displaying highlighted words."
296 :group 'gnus-article-emphasis)
298 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
299 "Format for display of Date headers in article bodies.
300 See `format-time-string' for the possible values.
302 The variable can also be function, which should return a complete Date
303 header. The function is called with one argument, the time, which can
304 be fed to `format-time-string'."
305 :type '(choice string symbol)
306 :link '(custom-manual "(gnus)Article Date")
307 :group 'gnus-article-washing)
310 (autoload 'mail-extract-address-components "mail-extr"))
312 (defcustom gnus-save-all-headers t
313 "*If non-nil, don't remove any headers before saving."
314 :group 'gnus-article-saving
317 (defcustom gnus-prompt-before-saving 'always
318 "*This variable says how much prompting is to be done when saving articles.
319 If it is nil, no prompting will be done, and the articles will be
320 saved to the default files. If this variable is `always', each and
321 every article that is saved will be preceded by a prompt, even when
322 saving large batches of articles. If this variable is neither nil not
323 `always', there the user will be prompted once for a file name for
324 each invocation of the saving commands."
325 :group 'gnus-article-saving
326 :type '(choice (item always)
327 (item :tag "never" nil)
328 (sexp :tag "once" :format "%t\n" :value t)))
330 (defcustom gnus-saved-headers gnus-visible-headers
331 "Headers to keep if `gnus-save-all-headers' is nil.
332 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
333 If that variable is nil, however, all headers that match this regexp
334 will be kept while the rest will be deleted before saving."
335 :group 'gnus-article-saving
338 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
339 "A function to save articles in your favourite format.
340 The function must be interactively callable (in other words, it must
341 be an Emacs command).
343 Gnus provides the following functions:
345 * gnus-summary-save-in-rmail (Rmail format)
346 * gnus-summary-save-in-mail (Unix mail format)
347 * gnus-summary-save-in-folder (MH folder)
348 * gnus-summary-save-in-file (article format)
349 * gnus-summary-save-in-vm (use VM's folder format)
350 * gnus-summary-write-to-file (article format -- overwrite)."
351 :group 'gnus-article-saving
352 :type '(radio (function-item gnus-summary-save-in-rmail)
353 (function-item gnus-summary-save-in-mail)
354 (function-item gnus-summary-save-in-folder)
355 (function-item gnus-summary-save-in-file)
356 (function-item gnus-summary-save-in-vm)
357 (function-item gnus-summary-write-to-file)))
359 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
360 "A function generating a file name to save articles in Rmail format.
361 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
362 :group 'gnus-article-saving
365 (defcustom gnus-mail-save-name 'gnus-plain-save-name
366 "A function generating a file name to save articles in Unix mail format.
367 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
368 :group 'gnus-article-saving
371 (defcustom gnus-folder-save-name 'gnus-folder-save-name
372 "A function generating a file name to save articles in MH folder.
373 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
374 :group 'gnus-article-saving
377 (defcustom gnus-file-save-name 'gnus-numeric-save-name
378 "A function generating a file name to save articles in article format.
379 The function is called with NEWSGROUP, HEADERS, and optional
381 :group 'gnus-article-saving
384 (defcustom gnus-split-methods
385 '((gnus-article-archive-name)
386 (gnus-article-nndoc-name))
387 "*Variable used to suggest where articles are to be saved.
388 For instance, if you would like to save articles related to Gnus in
389 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
390 you could set this variable to something like:
392 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
393 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
395 This variable is an alist where the where the key is the match and the
396 value is a list of possible files to save in if the match is non-nil.
398 If the match is a string, it is used as a regexp match on the
399 article. If the match is a symbol, that symbol will be funcalled
400 from the buffer of the article to be saved with the newsgroup as the
401 parameter. If it is a list, it will be evaled in the same buffer.
403 If this form or function returns a string, this string will be used as
404 a possible file name; and if it returns a non-nil list, that list will
405 be used as possible file names."
406 :group 'gnus-article-saving
407 :type '(repeat (choice (list :value (fun) function)
408 (cons :value ("" "") regexp (repeat string))
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 [%w] %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
570 '(article-decode-charset article-decode-encoded-words)
571 "*Hook run to decode charsets in articles."
572 :group 'gnus-article-headers
575 (defcustom gnus-display-mime-function 'gnus-display-mime
576 "Function to display MIME articles."
577 :group 'gnus-article-mime
580 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
581 "Function used to decode headers.")
583 (defvar gnus-article-dumbquotes-map
601 "Table for MS-to-Latin1 translation.")
603 (defcustom gnus-ignored-mime-types nil
604 "List of MIME types that should be ignored by Gnus."
605 :group 'gnus-article-mime
606 :type '(repeat regexp))
608 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
609 "List of MIME types that should not be given buttons when rendered inline."
610 :group 'gnus-article-mime
611 :type '(repeat regexp))
613 (defcustom gnus-article-mime-part-function nil
614 "Function called with a MIME handle as the argument.
615 This is meant for people who want to do something automatic based
616 on parts -- for instance, adding Vcard info to a database."
617 :group 'gnus-article-mime
620 (defcustom gnus-mime-multipart-functions nil
621 "An alist of MIME types to functions to display them.")
623 (defcustom gnus-article-date-lapsed-new-header nil
624 "Whether the X-Sent and Date headers can coexist.
625 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
626 either replace the old \"Date:\" header (if this variable is nil), or
627 be added below it (otherwise)."
628 :group 'gnus-article-headers
631 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
632 "Function called with a MIME handle as the argument.
633 This is meant for people who want to view first matched part.
634 For `undisplayed-alternative' (default), the first undisplayed
635 part or alternative part is used. For `undisplayed', the first
636 undisplayed part is used. For a function, the first part which
637 the function return `t' is used. For `nil', the first part is
639 :group 'gnus-article-mime
641 (item :tag "first" :value nil)
642 (item :tag "undisplayed" :value undisplayed)
643 (item :tag "undisplayed or alternative"
644 :value undisplayed-alternative)
648 ;;; The treatment variables
651 (defvar gnus-part-display-hook nil
652 "Hook called on parts that are to receive treatment.")
654 (defvar gnus-article-treat-custom
655 '(choice (const :tag "Off" nil)
657 (const :tag "Header" head)
658 (const :tag "Last" last)
659 (integer :tag "Less")
660 (repeat :tag "Groups" regexp)
661 (sexp :tag "Predicate")))
663 (defvar gnus-article-treat-head-custom
664 '(choice (const :tag "Off" nil)
665 (const :tag "Header" head)))
667 (defvar gnus-article-treat-types '("text/plain")
670 (defvar gnus-inhibit-treatment nil
671 "Whether to inhibit treatment.")
673 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
674 "Highlight the signature.
675 Valid values are nil, t, `head', `last', an integer or a predicate.
676 See the manual for details."
677 :group 'gnus-article-treat
678 :type gnus-article-treat-custom)
679 (put 'gnus-treat-highlight-signature 'highlight t)
681 (defcustom gnus-treat-buttonize 100000
683 Valid values are nil, t, `head', `last', an integer or a predicate.
684 See the manual for details."
685 :group 'gnus-article-treat
686 :type gnus-article-treat-custom)
687 (put 'gnus-treat-buttonize 'highlight t)
689 (defcustom gnus-treat-buttonize-head 'head
690 "Add buttons to the head.
691 Valid values are nil, t, `head', `last', an integer or a predicate.
692 See the manual for details."
693 :group 'gnus-article-treat
694 :type gnus-article-treat-head-custom)
695 (put 'gnus-treat-buttonize-head 'highlight t)
697 (defcustom gnus-treat-emphasize 50000
699 Valid values are nil, t, `head', `last', an integer or a predicate.
700 See the manual for details."
701 :group 'gnus-article-treat
702 :type gnus-article-treat-custom)
703 (put 'gnus-treat-emphasize 'highlight t)
705 (defcustom gnus-treat-strip-cr nil
706 "Remove carriage returns.
707 Valid values are nil, t, `head', `last', an integer or a predicate.
708 See the manual for details."
709 :group 'gnus-article-treat
710 :type gnus-article-treat-custom)
712 (defcustom gnus-treat-hide-headers 'head
714 Valid values are nil, t, `head', `last', an integer or a predicate.
715 See the manual for details."
716 :group 'gnus-article-treat
717 :type gnus-article-treat-head-custom)
719 (defcustom gnus-treat-hide-boring-headers nil
720 "Hide boring headers.
721 Valid values are nil, t, `head', `last', an integer or a predicate.
722 See the manual for details."
723 :group 'gnus-article-treat
724 :type gnus-article-treat-head-custom)
726 (defcustom gnus-treat-hide-signature nil
728 Valid values are nil, t, `head', `last', an integer or a predicate.
729 See the manual for details."
730 :group 'gnus-article-treat
731 :type gnus-article-treat-custom)
733 (defcustom gnus-treat-fill-article nil
735 Valid values are nil, t, `head', `last', an integer or a predicate.
736 See the manual for details."
737 :group 'gnus-article-treat
738 :type gnus-article-treat-custom)
740 (defcustom gnus-treat-hide-citation nil
742 Valid values are nil, t, `head', `last', an integer or a predicate.
743 See the manual for details."
744 :group 'gnus-article-treat
745 :type gnus-article-treat-custom)
747 (defcustom gnus-treat-strip-list-identifiers 'head
748 "Strip list identifiers from `gnus-list-identifiers`.
749 Valid values are nil, t, `head', `last', an integer or a predicate.
750 See the manual for details."
751 :group 'gnus-article-treat
752 :type gnus-article-treat-custom)
754 (defcustom gnus-treat-strip-pgp t
755 "Strip PGP signatures.
756 Valid values are nil, t, `head', `last', an integer or a predicate.
757 See the manual for details."
758 :group 'gnus-article-treat
759 :type gnus-article-treat-custom)
761 (defcustom gnus-treat-strip-pem nil
762 "Strip PEM signatures.
763 Valid values are nil, t, `head', `last', an integer or a predicate.
764 See the manual for details."
765 :group 'gnus-article-treat
766 :type gnus-article-treat-custom)
768 (defcustom gnus-treat-strip-banner t
769 "Strip banners from articles.
770 The banner to be stripped is specified in the `banner' group parameter.
771 Valid values are nil, t, `head', `last', an integer or a predicate.
772 See the manual for details."
773 :group 'gnus-article-treat
774 :type gnus-article-treat-custom)
776 (defcustom gnus-treat-highlight-headers 'head
777 "Highlight the headers.
778 Valid values are nil, t, `head', `last', an integer or a predicate.
779 See the manual for details."
780 :group 'gnus-article-treat
781 :type gnus-article-treat-head-custom)
782 (put 'gnus-treat-highlight-headers 'highlight t)
784 (defcustom gnus-treat-highlight-citation t
785 "Highlight cited text.
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
790 (put 'gnus-treat-highlight-citation 'highlight t)
792 (defcustom gnus-treat-date-ut nil
793 "Display the Date in UT (GMT).
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-head-custom)
799 (defcustom gnus-treat-date-local nil
800 "Display the Date in the local timezone.
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See the manual for details."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-head-custom)
806 (defcustom gnus-treat-date-lapsed nil
807 "Display the Date header in a way that says how much time has elapsed.
808 Valid values are nil, t, `head', `last', an integer or a predicate.
809 See the manual for details."
810 :group 'gnus-article-treat
811 :type gnus-article-treat-head-custom)
813 (defcustom gnus-treat-date-original nil
814 "Display the date in the original timezone.
815 Valid values are nil, t, `head', `last', an integer or a predicate.
816 See the manual for details."
817 :group 'gnus-article-treat
818 :type gnus-article-treat-head-custom)
820 (defcustom gnus-treat-date-iso8601 nil
821 "Display the date in the ISO8601 format.
822 Valid values are nil, t, `head', `last', an integer or a predicate.
823 See the manual for details."
824 :group 'gnus-article-treat
825 :type gnus-article-treat-head-custom)
827 (defcustom gnus-treat-date-user-defined nil
828 "Display the date in a user-defined format.
829 The format is defined by the `gnus-article-time-format' variable.
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-head-custom)
835 (defcustom gnus-treat-strip-headers-in-body t
836 "Strip the X-No-Archive header line from the beginning of the body.
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-custom)
842 (defcustom gnus-treat-strip-trailing-blank-lines nil
843 "Strip trailing blank lines.
844 Valid values are nil, t, `head', `last', an integer or a predicate.
845 See the manual for details."
846 :group 'gnus-article-treat
847 :type gnus-article-treat-custom)
849 (defcustom gnus-treat-strip-leading-blank-lines nil
850 "Strip leading blank lines.
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-custom)
856 (defcustom gnus-treat-strip-multiple-blank-lines nil
857 "Strip multiple blank lines.
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)
863 (defcustom gnus-treat-overstrike t
864 "Treat overstrike highlighting.
865 Valid values are nil, t, `head', `last', an integer or a predicate.
866 See the manual for details."
867 :group 'gnus-article-treat
868 :type gnus-article-treat-custom)
869 (put 'gnus-treat-overstrike 'highlight t)
871 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
873 "Display X-Face headers.
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-head-custom)
878 (put 'gnus-treat-display-xface 'highlight t)
880 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-custom)
888 (put 'gnus-treat-display-smileys 'highlight t)
890 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
892 Valid values are nil, t, `head', `last', an integer or a predicate.
893 See the manual for details."
894 :group 'gnus-article-treat
895 :type gnus-article-treat-head-custom)
896 (put 'gnus-treat-display-picons 'highlight t)
898 (defcustom gnus-treat-capitalize-sentences nil
899 "Capitalize sentence-starting words.
900 Valid values are nil, t, `head', `last', an integer or a predicate.
901 See the manual for details."
902 :group 'gnus-article-treat
903 :type gnus-article-treat-custom)
905 (defcustom gnus-treat-fill-long-lines nil
907 Valid values are nil, t, `head', `last', an integer or a predicate.
908 See the manual for details."
909 :group 'gnus-article-treat
910 :type gnus-article-treat-custom)
912 (defcustom gnus-treat-play-sounds nil
914 Valid values are nil, t, `head', `last', an integer or a predicate.
915 See the manual for details."
916 :group 'gnus-article-treat
917 :type gnus-article-treat-custom)
919 (defcustom gnus-treat-translate nil
920 "Translate articles from one language to another.
921 Valid values are nil, t, `head', `last', an integer or a predicate.
922 See the manual for details."
923 :group 'gnus-article-treat
924 :type gnus-article-treat-custom)
926 ;;; Internal variables
928 (defvar article-goto-body-goes-to-point-min-p nil)
929 (defvar gnus-article-wash-types nil)
930 (defvar gnus-article-emphasis-alist nil)
932 (defvar gnus-article-mime-handle-alist-1 nil)
933 (defvar gnus-treatment-function-alist
934 '((gnus-treat-strip-banner gnus-article-strip-banner)
935 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
936 (gnus-treat-highlight-signature gnus-article-highlight-signature)
937 (gnus-treat-buttonize gnus-article-add-buttons)
938 (gnus-treat-fill-article gnus-article-fill-cited-article)
939 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
940 (gnus-treat-strip-cr gnus-article-remove-cr)
941 (gnus-treat-emphasize gnus-article-emphasize)
942 (gnus-treat-display-xface gnus-article-display-x-face)
943 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
944 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
945 (gnus-treat-hide-signature gnus-article-hide-signature)
946 (gnus-treat-hide-citation gnus-article-hide-citation)
947 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
948 (gnus-treat-strip-pgp gnus-article-hide-pgp)
949 (gnus-treat-strip-pem gnus-article-hide-pem)
950 (gnus-treat-highlight-headers gnus-article-highlight-headers)
951 (gnus-treat-highlight-citation gnus-article-highlight-citation)
952 (gnus-treat-highlight-signature gnus-article-highlight-signature)
953 (gnus-treat-date-ut gnus-article-date-ut)
954 (gnus-treat-date-local gnus-article-date-local)
955 (gnus-treat-date-lapsed gnus-article-date-lapsed)
956 (gnus-treat-date-original gnus-article-date-original)
957 (gnus-treat-date-user-defined gnus-article-date-user)
958 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
959 (gnus-treat-strip-trailing-blank-lines
960 gnus-article-remove-trailing-blank-lines)
961 (gnus-treat-strip-leading-blank-lines
962 gnus-article-strip-leading-blank-lines)
963 (gnus-treat-strip-multiple-blank-lines
964 gnus-article-strip-multiple-blank-lines)
965 (gnus-treat-overstrike gnus-article-treat-overstrike)
966 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
967 (gnus-treat-display-smileys gnus-smiley-display)
968 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
969 (gnus-treat-display-picons gnus-article-display-picons)
970 (gnus-treat-play-sounds gnus-earcon-display)))
972 (defvar gnus-article-mime-handle-alist nil)
973 (defvar article-lapsed-timer nil)
974 (defvar gnus-article-current-summary nil)
976 (defvar gnus-article-mode-syntax-table
977 (let ((table (copy-syntax-table text-mode-syntax-table)))
978 (modify-syntax-entry ?- "w" table)
979 (modify-syntax-entry ?> ")" table)
980 (modify-syntax-entry ?< "(" table)
982 "Syntax table used in article mode buffers.
983 Initialized from `text-mode-syntax-table.")
985 (defvar gnus-save-article-buffer nil)
987 (defvar gnus-article-mode-line-format-alist
988 (nconc '((?w (gnus-article-wash-status) ?s)
989 (?m (gnus-article-mime-part-status) ?s))
990 gnus-summary-mode-line-format-alist))
992 (defvar gnus-number-of-articles-to-be-saved nil)
994 (defvar gnus-inhibit-hiding nil)
996 (defsubst gnus-article-hide-text (b e props)
997 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
998 (add-text-properties b e props)
999 (when (memq 'intangible props)
1001 (max (1- b) (point-min))
1002 b 'intangible (cddr (memq 'intangible props)))))
1003 (defsubst gnus-article-unhide-text (b e)
1004 "Remove hidden text properties from region between B and E."
1005 (remove-text-properties b e gnus-hidden-properties)
1006 (when (memq 'intangible gnus-hidden-properties)
1007 (put-text-property (max (1- b) (point-min))
1008 b 'intangible nil)))
1010 (defun gnus-article-hide-text-type (b e type)
1011 "Hide text of TYPE between B and E."
1012 (push type gnus-article-wash-types)
1013 (gnus-article-hide-text
1014 b e (cons 'article-type (cons type gnus-hidden-properties))))
1016 (defun gnus-article-unhide-text-type (b e type)
1017 "Unhide text of TYPE between B and E."
1018 (setq gnus-article-wash-types
1019 (delq type gnus-article-wash-types))
1020 (remove-text-properties
1021 b e (cons 'article-type (cons type gnus-hidden-properties)))
1022 (when (memq 'intangible gnus-hidden-properties)
1023 (put-text-property (max (1- b) (point-min))
1024 b 'intangible nil)))
1026 (defun gnus-article-hide-text-of-type (type)
1027 "Hide text of TYPE in the current buffer."
1029 (let ((b (point-min))
1031 (while (setq b (text-property-any b e 'article-type type))
1032 (add-text-properties b (incf b) gnus-hidden-properties)))))
1034 (defun gnus-article-delete-text-of-type (type)
1035 "Delete text of TYPE in the current buffer."
1037 (let ((b (point-min)))
1038 (while (setq b (text-property-any b (point-max) 'article-type type))
1040 b (or (text-property-not-all b (point-max) 'article-type type)
1043 (defun gnus-article-delete-invisible-text ()
1044 "Delete all invisible text in the current buffer."
1046 (let ((b (point-min)))
1047 (while (setq b (text-property-any b (point-max) 'invisible t))
1049 b (or (text-property-not-all b (point-max) 'invisible t)
1052 (defun gnus-article-text-type-exists-p (type)
1053 "Say whether any text of type TYPE exists in the buffer."
1054 (text-property-any (point-min) (point-max) 'article-type type))
1056 (defsubst gnus-article-header-rank ()
1057 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1058 (let ((list gnus-sorted-header-list)
1061 (when (looking-at (car list))
1063 (setq list (cdr list))
1067 (defun article-hide-headers (&optional arg delete)
1068 "Hide unwanted headers and possibly sort them as well."
1070 ;; This function might be inhibited.
1071 (unless gnus-inhibit-hiding
1074 (let ((buffer-read-only nil)
1075 (case-fold-search t)
1076 (max (1+ (length gnus-sorted-header-list)))
1077 (ignored (when (not gnus-visible-headers)
1078 (cond ((stringp gnus-ignored-headers)
1079 gnus-ignored-headers)
1080 ((listp gnus-ignored-headers)
1081 (mapconcat 'identity gnus-ignored-headers
1084 (cond ((stringp gnus-visible-headers)
1085 gnus-visible-headers)
1086 ((and gnus-visible-headers
1087 (listp gnus-visible-headers))
1088 (mapconcat 'identity gnus-visible-headers "\\|"))))
1089 (inhibit-point-motion-hooks t)
1091 ;; First we narrow to just the headers.
1092 (article-narrow-to-head)
1093 ;; Hide any "From " lines at the beginning of (mail) articles.
1094 (while (looking-at "From ")
1097 (delete-region (point-min) (point)))
1098 ;; Then treat the rest of the header lines.
1099 ;; Then we use the two regular expressions
1100 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1101 ;; select which header lines is to remain visible in the
1103 (while (re-search-forward "^[^ \t]*:" nil t)
1105 ;; Mark the rank of the header.
1107 (point) (1+ (point)) 'message-rank
1108 (if (or (and visible (looking-at visible))
1110 (not (looking-at ignored))))
1111 (gnus-article-header-rank)
1114 (message-sort-headers-1)
1115 (when (setq beg (text-property-any
1116 (point-min) (point-max) 'message-rank (+ 2 max)))
1117 ;; We delete the unwanted headers.
1118 (push 'headers gnus-article-wash-types)
1119 (add-text-properties (point-min) (+ 5 (point-min))
1120 '(article-type headers dummy-invisible t))
1121 (delete-region beg (point-max))))))))
1123 (defun article-hide-boring-headers (&optional arg)
1124 "Toggle hiding of headers that aren't very interesting.
1125 If given a negative prefix, always show; if given a positive prefix,
1127 (interactive (gnus-article-hidden-arg))
1128 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1129 (not gnus-show-all-headers))
1132 (let ((buffer-read-only nil)
1133 (list gnus-boring-article-headers)
1134 (inhibit-point-motion-hooks t)
1136 (article-narrow-to-head)
1138 (setq elem (pop list))
1139 (goto-char (point-min))
1141 ;; Hide empty headers.
1143 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1145 (gnus-article-hide-text-type
1146 (progn (beginning-of-line) (point))
1149 (if (re-search-forward "^[^ \t]" nil t)
1153 ;; Hide boring Newsgroups header.
1154 ((eq elem 'newsgroups)
1155 (when (equal (gnus-fetch-field "newsgroups")
1156 (gnus-group-real-name
1157 (if (boundp 'gnus-newsgroup-name)
1160 (gnus-article-hide-header "newsgroups")))
1161 ((eq elem 'followup-to)
1162 (when (equal (message-fetch-field "followup-to")
1163 (message-fetch-field "newsgroups"))
1164 (gnus-article-hide-header "followup-to")))
1165 ((eq elem 'reply-to)
1166 (let ((from (message-fetch-field "from"))
1167 (reply-to (message-fetch-field "reply-to")))
1172 (nth 1 (mail-extract-address-components from))
1173 (nth 1 (mail-extract-address-components reply-to)))))
1174 (gnus-article-hide-header "reply-to"))))
1176 (let ((date (message-fetch-field "date")))
1178 (< (days-between (current-time-string) date)
1180 (gnus-article-hide-header "date"))))
1182 (let ((to (message-fetch-field "to"))
1183 (cc (message-fetch-field "cc")))
1184 (when (> (length to) 1024)
1185 (gnus-article-hide-header "to"))
1186 (when (> (length cc) 1024)
1187 (gnus-article-hide-header "cc"))))
1191 (goto-char (point-min))
1192 (while (re-search-forward "^to:" nil t)
1193 (setq to-count (1+ to-count)))
1194 (when (> to-count 1)
1195 (while (> to-count 0)
1196 (goto-char (point-min))
1198 (re-search-forward "^to:" nil nil to-count)
1200 (narrow-to-region (point) (point-max))
1201 (gnus-article-hide-header "to"))
1202 (setq to-count (1- to-count))))
1203 (goto-char (point-min))
1204 (while (re-search-forward "^cc:" nil t)
1205 (setq cc-count (1+ cc-count)))
1206 (when (> cc-count 1)
1207 (while (> cc-count 0)
1208 (goto-char (point-min))
1210 (re-search-forward "^cc:" nil nil cc-count)
1212 (narrow-to-region (point) (point-max))
1213 (gnus-article-hide-header "cc"))
1214 (setq cc-count (1- cc-count)))))))))))))
1216 (defun gnus-article-hide-header (header)
1218 (goto-char (point-min))
1219 (when (re-search-forward (concat "^" header ":") nil t)
1220 (gnus-article-hide-text-type
1221 (progn (beginning-of-line) (point))
1224 (if (re-search-forward "^[^ \t]" nil t)
1229 (defvar gnus-article-normalized-header-length 40
1230 "Length of normalized headers.")
1232 (defun article-normalize-headers ()
1233 "Make all header lines 40 characters long."
1235 (let ((buffer-read-only nil)
1239 (article-narrow-to-head)
1242 ((< (setq column (- (gnus-point-at-eol) (point)))
1243 gnus-article-normalized-header-length)
1245 (insert (make-string
1246 (- gnus-article-normalized-header-length column)
1248 ((> column gnus-article-normalized-header-length)
1249 (gnus-put-text-property
1251 (forward-char gnus-article-normalized-header-length)
1258 (forward-line 1))))))
1260 (defun article-treat-dumbquotes ()
1261 "Translate M******** sm*rtq**t*s into proper text.
1262 Note that this function guesses whether a character is a sm*rtq**t* or
1263 not, so it should only be used interactively."
1265 (article-translate-strings gnus-article-dumbquotes-map))
1267 (defun article-translate-characters (from to)
1268 "Translate all characters in the body of the article according to FROM and TO.
1269 FROM is a string of characters to translate from; to is a string of
1270 characters to translate to."
1272 (when (article-goto-body)
1273 (let ((buffer-read-only nil)
1274 (x (make-string 225 ?x))
1276 (while (< (incf i) (length x))
1279 (while (< i (length from))
1280 (aset x (aref from i) (aref to i))
1282 (translate-region (point) (point-max) x)))))
1284 (defun article-translate-strings (map)
1285 "Translate all string in the body of the article according to MAP.
1286 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1288 (when (article-goto-body)
1289 (let ((buffer-read-only nil)
1291 (while (setq elem (pop map))
1293 (while (search-forward (car elem) nil t)
1294 (replace-match (cadr elem)))))))))
1296 (defun article-treat-overstrike ()
1297 "Translate overstrikes into bold text."
1300 (when (article-goto-body)
1301 (let ((buffer-read-only nil))
1302 (while (search-forward "\b" nil t)
1303 (let ((next (char-after))
1304 (previous (char-after (- (point) 2))))
1305 ;; We do the boldification/underlining by hiding the
1306 ;; overstrikes and putting the proper text property
1310 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1311 (put-text-property (point) (1+ (point)) 'face 'bold))
1313 (gnus-article-hide-text-type
1314 (1- (point)) (1+ (point)) 'overstrike)
1316 (- (point) 2) (1- (point)) 'face 'underline))
1318 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1320 (point) (1+ (point)) 'face 'underline)))))))))
1322 (defun article-fill-long-lines ()
1323 "Fill lines that are wider than the window width."
1326 (let ((buffer-read-only nil)
1327 (width (window-width (get-buffer-window (current-buffer)))))
1330 (let ((adaptive-fill-mode nil))
1333 (when (>= (current-column) (min fill-column width))
1334 (narrow-to-region (point) (gnus-point-at-bol))
1335 (fill-paragraph nil)
1336 (goto-char (point-max))
1338 (forward-line 1)))))))
1340 (defun article-capitalize-sentences ()
1341 "Capitalize the first word in each sentence."
1344 (let ((buffer-read-only nil)
1345 (paragraph-start "^[\n\^L]"))
1349 (forward-sentence)))))
1351 (defun article-remove-cr ()
1352 "Remove trailing CRs and then translate remaining CRs into LFs."
1355 (let ((buffer-read-only nil))
1356 (goto-char (point-min))
1357 (while (re-search-forward "\r+$" nil t)
1358 (replace-match "" t t))
1359 (goto-char (point-min))
1360 (while (search-forward "\r" nil t)
1361 (replace-match "\n" t t)))))
1363 (defun article-remove-trailing-blank-lines ()
1364 "Remove all trailing blank lines from the article."
1367 (let ((buffer-read-only nil))
1368 (goto-char (point-max))
1372 (while (and (not (bobp))
1373 (looking-at "^[ \t]*$")
1374 (not (gnus-annotation-in-region-p
1375 (point) (gnus-point-at-eol))))
1380 (defun article-display-x-face (&optional force)
1381 "Look for an X-Face header and display it if present."
1382 (interactive (list 'force))
1384 ;; Delete the old process, if any.
1385 (when (process-status "article-x-face")
1386 (delete-process "article-x-face"))
1387 (let ((inhibit-point-motion-hooks t)
1388 (case-fold-search t)
1391 (article-narrow-to-head)
1392 (goto-char (point-min))
1393 (setq from (message-fetch-field "from"))
1394 (goto-char (point-min))
1395 (while (and gnus-article-x-face-command
1398 ;; Check whether this face is censored.
1399 (not gnus-article-x-face-too-ugly)
1400 (and gnus-article-x-face-too-ugly from
1401 (not (string-match gnus-article-x-face-too-ugly
1403 ;; Has to be present.
1404 (re-search-forward "^X-Face: " nil t))
1405 ;; This used to try to do multiple faces (`while' instead of
1406 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1407 ;; work (b) it can crash some versions of Emacs (c) are
1408 ;; multiple faces really something to encourage?
1409 (when (stringp gnus-article-x-face-command)
1411 ;; We now have the area of the buffer where the X-Face is stored.
1414 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1415 ;; We display the face.
1416 (if (symbolp gnus-article-x-face-command)
1417 ;; The command is a lisp function, so we call it.
1418 (if (gnus-functionp gnus-article-x-face-command)
1419 (funcall gnus-article-x-face-command beg end)
1420 (error "%s is not a function" gnus-article-x-face-command))
1421 ;; The command is a string, so we interpret the command
1422 ;; as a, well, command, and fork it off.
1423 (let ((process-connection-type nil))
1424 (process-kill-without-query
1426 "article-x-face" nil shell-file-name shell-command-switch
1427 gnus-article-x-face-command))
1428 (process-send-region "article-x-face" beg end)
1429 (process-send-eof "article-x-face"))))))))))
1431 (defun article-decode-mime-words ()
1432 "Decode all MIME-encoded words in the article."
1435 (set-buffer gnus-article-buffer)
1436 (let ((inhibit-point-motion-hooks t)
1438 (mail-parse-charset gnus-newsgroup-charset)
1439 (mail-parse-ignored-charsets
1440 (save-excursion (set-buffer gnus-summary-buffer)
1441 gnus-newsgroup-ignored-charsets)))
1442 (mail-decode-encoded-word-region (point-min) (point-max)))))
1444 (defun article-decode-charset (&optional prompt)
1445 "Decode charset-encoded text in the article.
1446 If PROMPT (the prefix), prompt for a coding system to use."
1448 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1450 (mail-parse-charset gnus-newsgroup-charset)
1451 (mail-parse-ignored-charsets
1452 (save-excursion (condition-case nil
1453 (set-buffer gnus-summary-buffer)
1455 gnus-newsgroup-ignored-charsets))
1456 ct cte ctl charset format)
1459 (article-narrow-to-head)
1460 (setq ct (message-fetch-field "Content-Type" t)
1461 cte (message-fetch-field "Content-Transfer-Encoding" t)
1462 ctl (and ct (ignore-errors
1463 (mail-header-parse-content-type ct)))
1466 (mm-read-coding-system "Charset to decode: "))
1468 (mail-content-type-get ctl 'charset)))
1469 format (and ctl (mail-content-type-get ctl 'format)))
1471 (setq cte (mail-header-strip cte)))
1472 (if (and ctl (not (string-match "/" (car ctl))))
1474 (goto-char (point-max)))
1477 (narrow-to-region (point) (point-max))
1478 (when (and (or (not ctl)
1479 (equal (car ctl) "text/plain"))
1480 (not format)) ;; article with format will decode later.
1482 charset (and cte (intern (downcase
1483 (gnus-strip-whitespace cte))))
1486 (defun article-decode-encoded-words ()
1487 "Remove encoded-word encoding from headers."
1488 (let ((inhibit-point-motion-hooks t)
1489 (mail-parse-charset gnus-newsgroup-charset)
1490 (mail-parse-ignored-charsets
1491 (save-excursion (condition-case nil
1492 (set-buffer gnus-summary-buffer)
1494 gnus-newsgroup-ignored-charsets))
1497 (article-narrow-to-head)
1498 (funcall gnus-decode-header-function (point-min) (point-max)))))
1500 (defun article-de-quoted-unreadable (&optional force)
1501 "Translate a quoted-printable-encoded article.
1502 If FORCE, decode the article whether it is marked as quoted-printable
1504 (interactive (list 'force))
1506 (let ((buffer-read-only nil)
1507 (type (gnus-fetch-field "content-transfer-encoding"))
1508 (charset gnus-newsgroup-charset))
1510 (and type (string-match "quoted-printable" (downcase type))))
1512 (quoted-printable-decode-region (point) (point-max) charset)))))
1514 (defun article-de-base64-unreadable (&optional force)
1515 "Translate a base64 article.
1516 If FORCE, decode the article whether it is marked as base64 not."
1517 (interactive (list 'force))
1519 (let ((buffer-read-only nil)
1520 (type (gnus-fetch-field "content-transfer-encoding"))
1521 (charset gnus-newsgroup-charset))
1523 (and type (string-match "quoted-printable" (downcase type))))
1526 (narrow-to-region (point) (point-max))
1527 (base64-decode-region (point-min) (point-max))
1528 (if (mm-coding-system-p charset)
1529 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1534 (defun article-decode-HZ ()
1535 "Translate a HZ-encoded article."
1539 (let ((buffer-read-only nil))
1540 (rfc1843-decode-region (point-min) (point-max)))))
1542 (defun article-wash-html ()
1543 "Format an html article."
1546 (let ((buffer-read-only nil)
1547 (charset gnus-newsgroup-charset))
1549 (save-window-excursion
1551 (narrow-to-region (point) (point-max))
1553 (let ((w3-strict-width (window-width))
1554 (url-standalone-mode t))
1556 (w3-region (point-min) (point-max))
1559 (defun article-hide-list-identifiers ()
1560 "Remove list identifies from the Subject header.
1561 The `gnus-list-identifiers' variable specifies what to do."
1565 (let ((inhibit-point-motion-hooks t)
1567 (article-narrow-to-head)
1568 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1569 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1571 (goto-char (point-min))
1572 (when (re-search-forward
1573 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1574 " *\\)\\)+\\(Re: +\\)?\\)")
1576 (let ((s (or (match-string 3) (match-string 5))))
1577 (delete-region (match-beginning 1) (match-end 1))
1579 (goto-char (match-beginning 1))
1582 (defun article-hide-pgp ()
1583 "Remove any PGP headers and signatures in the current article."
1587 (let ((inhibit-point-motion-hooks t)
1588 buffer-read-only beg end)
1590 ;; Hide the "header".
1591 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1592 (push 'pgp gnus-article-wash-types)
1593 (delete-region (match-beginning 0) (match-end 0))
1594 ;; Remove armor headers (rfc2440 6.2)
1595 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1598 ;; Hide the actual signature.
1599 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1600 (setq end (1+ (match-beginning 0)))
1603 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1605 ;; Perhaps we shouldn't hide to the end of the buffer
1606 ;; if there is no end to the signature?
1608 ;; Hide "- " PGP quotation markers.
1610 (narrow-to-region beg end)
1611 (goto-char (point-min))
1612 (while (re-search-forward "^- " nil t)
1614 (match-beginning 0) (match-end 0)))
1616 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1618 (defun article-hide-pem (&optional arg)
1619 "Toggle hiding of any PEM headers and signatures in the current article.
1620 If given a negative prefix, always show; if given a positive prefix,
1622 (interactive (gnus-article-hidden-arg))
1623 (unless (gnus-article-check-hidden-text 'pem arg)
1625 (let (buffer-read-only end)
1626 (goto-char (point-min))
1627 ;; Hide the horrendously ugly "header".
1628 (when (and (search-forward
1629 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1631 (setq end (1+ (match-beginning 0))))
1632 (push 'pem gnus-article-wash-types)
1633 (gnus-article-hide-text-type
1635 (if (search-forward "\n\n" nil t)
1639 ;; Hide the trailer as well
1640 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1642 (gnus-article-hide-text-type
1643 (match-beginning 0) (match-end 0) 'pem)))))))
1645 (defun article-strip-banner ()
1646 "Strip the banner specified by the `banner' group parameter."
1650 (let ((inhibit-point-motion-hooks t)
1651 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1652 (gnus-signature-limit nil)
1653 buffer-read-only beg end)
1657 ((eq banner 'signature)
1658 (when (gnus-article-narrow-to-signature)
1661 (delete-region (point) (point-max))))
1663 (while (re-search-forward banner nil t)
1664 (delete-region (match-beginning 0) (match-end 0))))))))))
1666 (defun article-babel ()
1667 "Translate article using an online translation service."
1671 (set-buffer gnus-article-buffer)
1672 (when (article-goto-body)
1673 (let* ((buffer-read-only nil)
1676 (orig (buffer-substring start end))
1677 (trans (babel-as-string orig)))
1679 (narrow-to-region start end)
1680 (delete-region start end)
1683 (defun article-hide-signature (&optional arg)
1684 "Hide the signature in the current article.
1685 If given a negative prefix, always show; if given a positive prefix,
1687 (interactive (gnus-article-hidden-arg))
1688 (unless (gnus-article-check-hidden-text 'signature arg)
1691 (let ((buffer-read-only nil))
1692 (when (gnus-article-narrow-to-signature)
1693 (gnus-article-hide-text-type
1694 (point-min) (point-max) 'signature)))))))
1696 (defun article-strip-headers-in-body ()
1697 "Strip offensive headers from bodies."
1701 (let ((case-fold-search t))
1702 (when (looking-at "x-no-archive:")
1703 (gnus-delete-line)))))
1705 (defun article-strip-leading-blank-lines ()
1706 "Remove all blank lines from the beginning of the article."
1709 (let ((inhibit-point-motion-hooks t)
1711 (when (article-goto-body)
1712 (while (and (not (eobp))
1713 (looking-at "[ \t]*$"))
1714 (gnus-delete-line))))))
1716 (defun article-narrow-to-head ()
1717 "Narrow the buffer to the head of the message.
1718 Point is left at the beginning of the narrowed-to region."
1720 (goto-char (point-min))
1721 (if (search-forward "\n\n" nil 1)
1724 (goto-char (point-min)))
1726 (defun article-goto-body ()
1727 "Place point at the start of the body."
1728 (goto-char (point-min))
1730 ;; This variable is only bound when dealing with separate
1732 (article-goto-body-goes-to-point-min-p
1734 ((search-forward "\n\n" nil t)
1737 (goto-char (point-max))
1740 (defun article-strip-multiple-blank-lines ()
1741 "Replace consecutive blank lines with one empty line."
1744 (let ((inhibit-point-motion-hooks t)
1746 ;; First make all blank lines empty.
1748 (while (re-search-forward "^[ \t]+$" nil t)
1749 (unless (gnus-annotation-in-region-p
1750 (match-beginning 0) (match-end 0))
1751 (replace-match "" nil t)))
1752 ;; Then replace multiple empty lines with a single empty line.
1754 (while (re-search-forward "\n\n\n+" nil t)
1755 (unless (gnus-annotation-in-region-p
1756 (match-beginning 0) (match-end 0))
1757 (replace-match "\n\n" t t))))))
1759 (defun article-strip-leading-space ()
1760 "Remove all white space from the beginning of the lines in the article."
1763 (let ((inhibit-point-motion-hooks t)
1766 (while (re-search-forward "^[ \t]+" nil t)
1767 (replace-match "" t t)))))
1769 (defun article-strip-trailing-space ()
1770 "Remove all white space from the end of the lines in the article."
1773 (let ((inhibit-point-motion-hooks t)
1776 (while (re-search-forward "[ \t]+$" nil t)
1777 (replace-match "" t t)))))
1779 (defun article-strip-blank-lines ()
1780 "Strip leading, trailing and multiple blank lines."
1782 (article-strip-leading-blank-lines)
1783 (article-remove-trailing-blank-lines)
1784 (article-strip-multiple-blank-lines))
1786 (defun article-strip-all-blank-lines ()
1787 "Strip all blank lines."
1790 (let ((inhibit-point-motion-hooks t)
1793 (while (re-search-forward "^[ \t]*\n" nil t)
1794 (replace-match "" t t)))))
1796 (defun gnus-article-narrow-to-signature ()
1797 "Narrow to the signature; return t if a signature is found, else nil."
1798 (let ((inhibit-point-motion-hooks t))
1799 (when (gnus-article-search-signature)
1801 ;; Check whether we have some limits to what we consider
1802 ;; to be a signature.
1803 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1804 (list gnus-signature-limit)))
1806 (while (setq limit (pop limits))
1807 (if (or (and (integerp limit)
1808 (< (- (point-max) (point)) limit))
1810 (< (count-lines (point) (point-max)) limit))
1811 (and (gnus-functionp limit)
1813 (and (stringp limit)
1814 (not (re-search-forward limit nil t))))
1815 () ; This limit did not succeed.
1819 (narrow-to-region (point) (point-max))
1822 (defun gnus-article-search-signature ()
1823 "Search the current buffer for the signature separator.
1824 Put point at the beginning of the signature separator."
1825 (let ((cur (point)))
1826 (goto-char (point-max))
1827 (if (if (stringp gnus-signature-separator)
1828 (re-search-backward gnus-signature-separator nil t)
1829 (let ((seps gnus-signature-separator))
1831 (not (re-search-backward (car seps) nil t)))
1838 (defun gnus-article-hidden-arg ()
1839 "Return the current prefix arg as a number, or 0 if no prefix."
1840 (list (if current-prefix-arg
1841 (prefix-numeric-value current-prefix-arg)
1844 (defun gnus-article-check-hidden-text (type arg)
1845 "Return nil if hiding is necessary.
1846 Arg can be nil or a number. Nil and positive means hide, negative
1847 means show, 0 means toggle."
1850 (let ((hide (gnus-article-hidden-text-p type)))
1856 (gnus-article-show-hidden-text type))
1858 (if (eq hide 'hidden)
1859 (gnus-article-show-hidden-text type)
1862 (defun gnus-article-hidden-text-p (type)
1863 "Say whether the current buffer contains hidden text of type TYPE."
1864 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1866 (not (get-text-property pos 'invisible))
1867 (not (get-text-property pos 'dummy-invisible)))
1869 (text-property-any (1+ pos) (point-max) 'article-type type)))
1874 (defun gnus-article-show-hidden-text (type &optional hide)
1875 "Show all hidden text of type TYPE.
1876 If HIDE, hide the text instead."
1878 (let ((buffer-read-only nil)
1879 (inhibit-point-motion-hooks t)
1882 (while (setq beg (text-property-any end (point-max) 'article-type type))
1885 (text-property-not-all beg (point-max) 'article-type type)
1888 (gnus-article-hide-text beg end gnus-hidden-properties)
1889 (gnus-article-unhide-text beg end))
1893 (defconst article-time-units
1894 `((year . ,(* 365.25 24 60 60))
1895 (week . ,(* 7 24 60 60))
1896 (day . ,(* 24 60 60))
1900 "Mapping from time units to seconds.")
1902 (defun article-date-ut (&optional type highlight header)
1903 "Convert DATE date to universal time in the current article.
1904 If TYPE is `local', convert to local time; if it is `lapsed', output
1905 how much time has lapsed since DATE. For `lapsed', the value of
1906 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1907 should replace the \"Date:\" one, or should be added below it."
1908 (interactive (list 'ut t))
1909 (let* ((header (or header
1910 (message-fetch-field "date")
1912 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1915 ((not gnus-article-date-lapsed-new-header)
1921 (date (if (vectorp header) (mail-header-date header)
1923 (inhibit-point-motion-hooks t)
1928 (article-narrow-to-head)
1929 (when (re-search-forward tdate-regexp nil t)
1930 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1931 date (or (get-text-property (gnus-point-at-bol)
1934 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1936 (when (and date (not (string= date "")))
1937 (goto-char (point-min))
1938 (let ((buffer-read-only nil))
1939 ;; Delete any old Date headers.
1940 (while (re-search-forward date-regexp nil t)
1942 (delete-region (progn (beginning-of-line) (point))
1943 (progn (forward-line 1) (point)))
1944 (delete-region (progn (beginning-of-line) (point))
1945 (progn (end-of-line) (point)))
1946 (setq pos (point))))
1947 (when (and (not pos) (re-search-forward tdate-regexp nil t))
1949 (if pos (goto-char pos))
1950 (insert (article-make-date-line date (or type 'ut)))
1956 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1957 (put-text-property (match-beginning 1) (1+ (match-end 1))
1958 'original-date date)
1959 (put-text-property (match-beginning 1) (1+ (match-end 1))
1961 (put-text-property (match-beginning 2) (match-end 2)
1964 (defun article-make-date-line (date type)
1965 "Return a DATE line of TYPE."
1966 (let ((time (condition-case ()
1970 ;; Convert to the local timezone. We have to slap a
1971 ;; `condition-case' round the calls to the timezone
1972 ;; functions since they aren't particularly resistant to
1975 (let ((tz (car (current-time-zone time))))
1976 (format "Date: %s %s%02d%02d" (current-time-string time)
1977 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1978 (/ (% (abs tz) 3600) 60))))
1979 ;; Convert to Universal Time.
1982 (current-time-string
1983 (let* ((e (parse-time-string date))
1984 (tm (apply 'encode-time e))
1986 (ls (- (cadr tm) (car (current-time-zone time)))))
1987 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1988 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1991 ;; Get the original date from the article.
1992 ((eq type 'original)
1993 (concat "Date: " (if (string-match "\n+$" date)
1994 (substring date 0 (match-beginning 0))
1996 ;; Let the user define the format.
1998 (if (gnus-functionp gnus-article-time-format)
1999 (funcall gnus-article-time-format time)
2002 (format-time-string gnus-article-time-format time))))
2005 (let ((tz (car (current-time-zone time))))
2008 (format-time-string "%Y%m%dT%H%M%S" time)
2009 (format "%s%02d%02d"
2010 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2011 (/ (% (abs tz) 3600) 60)))))
2012 ;; Do an X-Sent lapsed format.
2014 ;; If the date is seriously mangled, the timezone functions are
2015 ;; liable to bug out, so we ignore all errors.
2016 (let* ((now (current-time))
2017 (real-time (subtract-time now time))
2018 (real-sec (and real-time
2019 (+ (* (float (car real-time)) 65536)
2021 (sec (and real-time (abs real-sec)))
2031 ;; This is a bit convoluted, but basically we go
2032 ;; through the time units for years, weeks, etc,
2033 ;; and divide things to see whether that results
2034 ;; in positive answers.
2037 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2038 ;; The (remaining) seconds are too few to
2039 ;; be divided into this time unit.
2041 ;; It's big enough, so we output it.
2042 (setq sec (- sec (* num (cdr unit))))
2044 (concat (if prev ", " "") (int-to-string
2046 " " (symbol-name (car unit))
2047 (if (> num 1) "s" ""))
2049 article-time-units "")
2050 ;; If dates are odd, then it might appear like the
2051 ;; article was sent in the future.
2054 " in the future"))))))
2056 (error "Unknown conversion type: %s" type)))))
2058 (defun article-date-local (&optional highlight)
2059 "Convert the current article date to the local timezone."
2060 (interactive (list t))
2061 (article-date-ut 'local highlight))
2063 (defun article-date-original (&optional highlight)
2064 "Convert the current article date to what it was originally.
2065 This is only useful if you have used some other date conversion
2066 function and want to see what the date was before converting."
2067 (interactive (list t))
2068 (article-date-ut 'original highlight))
2070 (defun article-date-lapsed (&optional highlight)
2071 "Convert the current article date to time lapsed since it was sent."
2072 (interactive (list t))
2073 (article-date-ut 'lapsed highlight))
2075 (defun article-update-date-lapsed ()
2076 "Function to be run from a timer to update the lapsed time line."
2077 (let (deactivate-mark)
2082 (set-buffer (window-buffer w))
2083 (when (eq major-mode 'gnus-article-mode)
2084 (goto-char (point-min))
2085 (when (re-search-forward "^X-Sent:" nil t)
2086 (article-date-lapsed t))))
2089 (defun gnus-start-date-timer (&optional n)
2090 "Start a timer to update the X-Sent header in the article buffers.
2091 The numerical prefix says how frequently (in seconds) the function
2096 (gnus-stop-date-timer)
2097 (setq article-lapsed-timer
2098 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2100 (defun gnus-stop-date-timer ()
2101 "Stop the X-Sent timer."
2103 (when article-lapsed-timer
2104 (nnheader-cancel-timer article-lapsed-timer)
2105 (setq article-lapsed-timer nil)))
2107 (defun article-date-user (&optional highlight)
2108 "Convert the current article date to the user-defined format.
2109 This format is defined by the `gnus-article-time-format' variable."
2110 (interactive (list t))
2111 (article-date-ut 'user highlight))
2113 (defun article-date-iso8601 (&optional highlight)
2114 "Convert the current article date to ISO8601."
2115 (interactive (list t))
2116 (article-date-ut 'iso8601 highlight))
2118 (defun article-show-all ()
2119 "Show all hidden text in the article buffer."
2122 (let ((buffer-read-only nil))
2123 (gnus-article-unhide-text (point-min) (point-max)))))
2125 (defun article-emphasize (&optional arg)
2126 "Emphasize text according to `gnus-emphasis-alist'."
2127 (interactive (gnus-article-hidden-arg))
2128 (unless (gnus-article-check-hidden-text 'emphasis arg)
2132 (with-current-buffer gnus-summary-buffer
2133 gnus-article-emphasis-alist)
2135 gnus-emphasis-alist))
2136 (buffer-read-only nil)
2137 (props (append '(article-type emphasis)
2138 gnus-hidden-properties))
2139 regexp elem beg invisible visible face)
2142 (while (setq elem (pop alist))
2144 (setq regexp (car elem)
2145 invisible (nth 1 elem)
2146 visible (nth 2 elem)
2148 (while (re-search-forward regexp nil t)
2149 (when (and (match-beginning visible) (match-beginning invisible))
2150 (push 'emphasis gnus-article-wash-types)
2151 (gnus-article-hide-text
2152 (match-beginning invisible) (match-end invisible) props)
2153 (gnus-article-unhide-text-type
2154 (match-beginning visible) (match-end visible) 'emphasis)
2155 (gnus-put-text-property-excluding-newlines
2156 (match-beginning visible) (match-end visible) 'face face)
2157 (goto-char (match-end invisible)))))))))
2159 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2160 "Setup newsgroup emphasis alist."
2161 (unless gnus-article-emphasis-alist
2162 (let ((name (and gnus-newsgroup-name
2163 (gnus-group-real-name gnus-newsgroup-name))))
2164 (make-local-variable 'gnus-article-emphasis-alist)
2165 (setq gnus-article-emphasis-alist
2167 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2168 (while (setq elem (pop alist))
2169 (when (and name (string-match (car elem) name))
2171 highlight (copy-sequence (cdr elem)))))
2173 (copy-sequence highlight-words)
2174 (if gnus-newsgroup-name
2175 (copy-sequence (gnus-group-find-parameter
2176 gnus-newsgroup-name 'highlight-words t)))
2177 gnus-emphasis-alist)))))
2179 (defvar gnus-summary-article-menu)
2180 (defvar gnus-summary-post-menu)
2182 ;;; Saving functions.
2184 (defun gnus-article-save (save-buffer file &optional num)
2185 "Save the currently selected article."
2186 (unless gnus-save-all-headers
2187 ;; Remove headers according to `gnus-saved-headers'.
2188 (let ((gnus-visible-headers
2189 (or gnus-saved-headers gnus-visible-headers))
2190 (gnus-article-buffer save-buffer))
2192 (set-buffer save-buffer)
2193 (article-hide-headers 1 t))))
2194 (save-window-excursion
2195 (if (not gnus-default-article-saver)
2196 (error "No default saver is defined")
2197 ;; !!! Magic! The saving functions all save
2198 ;; `gnus-save-article-buffer' (or so they think), but we
2199 ;; bind that variable to our save-buffer.
2200 (set-buffer gnus-article-buffer)
2201 (let* ((gnus-save-article-buffer save-buffer)
2204 ((not gnus-prompt-before-saving) 'default)
2205 ((eq gnus-prompt-before-saving 'always) nil)
2207 (gnus-number-of-articles-to-be-saved
2208 (when (eq gnus-prompt-before-saving t)
2210 (set-buffer gnus-article-current-summary)
2211 (funcall gnus-default-article-saver filename)))))
2213 (defun gnus-read-save-file-name (prompt &optional filename
2214 function group headers variable)
2216 (funcall function group headers (symbol-value variable)))
2221 ((eq filename 'default)
2227 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2230 (if (and gnus-number-of-articles-to-be-saved
2231 (> gnus-number-of-articles-to-be-saved 1))
2232 (format "these %d articles"
2233 gnus-number-of-articles-to-be-saved)
2236 ;; Let the split methods have their say.
2238 ;; No split name was found.
2241 (concat prompt " (default "
2242 (file-name-nondirectory default-name) ") ")
2243 (file-name-directory default-name)
2245 ;; A single group name is returned.
2246 ((stringp split-name)
2248 (funcall function split-name headers
2249 (symbol-value variable)))
2251 (concat prompt " (default "
2252 (file-name-nondirectory default-name) ") ")
2253 (file-name-directory default-name)
2255 ;; A single split name was found
2256 ((= 1 (length split-name))
2257 (let* ((name (expand-file-name
2258 (car split-name) gnus-article-save-directory))
2259 (dir (cond ((file-directory-p name)
2260 (file-name-as-directory name))
2261 ((file-exists-p name) name)
2262 (t gnus-article-save-directory))))
2264 (concat prompt " (default " name ") ")
2266 ;; A list of splits was found.
2268 (setq split-name (nreverse split-name))
2270 (let ((file-name-history
2271 (nconc split-name file-name-history)))
2275 (concat prompt " (`M-p' for defaults) ")
2276 gnus-article-save-directory
2278 gnus-article-save-directory)))
2279 (car (push result file-name-history)))))))
2280 ;; Create the directory.
2281 (gnus-make-directory (file-name-directory file))
2282 ;; If we have read a directory, we append the default file name.
2283 (when (file-directory-p file)
2284 (setq file (concat (file-name-as-directory file)
2285 (file-name-nondirectory default-name))))
2286 ;; Possibly translate some characters.
2287 (nnheader-translate-file-chars file)))))
2288 (gnus-make-directory (file-name-directory result))
2289 (set variable result)))
2291 (defun gnus-article-archive-name (group)
2292 "Return the first instance of an \"Archive-name\" in the current buffer."
2293 (let ((case-fold-search t))
2294 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2295 (nnheader-concat gnus-article-save-directory
2296 (match-string 1)))))
2298 (defun gnus-article-nndoc-name (group)
2299 "If GROUP is an nndoc group, return the name of the parent group."
2300 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2301 (gnus-group-get-parameter group 'save-article-group)))
2303 (defun gnus-summary-save-in-rmail (&optional filename)
2304 "Append this article to Rmail file.
2305 Optional argument FILENAME specifies file name.
2306 Directory to save to is default to `gnus-article-save-directory'."
2307 (setq filename (gnus-read-save-file-name
2308 "Save %s in rmail file:" filename
2309 gnus-rmail-save-name gnus-newsgroup-name
2310 gnus-current-headers 'gnus-newsgroup-last-rmail))
2311 (gnus-eval-in-buffer-window gnus-save-article-buffer
2315 (gnus-output-to-rmail filename))))
2318 (defun gnus-summary-save-in-mail (&optional filename)
2319 "Append this article to Unix mail file.
2320 Optional argument FILENAME specifies file name.
2321 Directory to save to is default to `gnus-article-save-directory'."
2322 (setq filename (gnus-read-save-file-name
2323 "Save %s in Unix mail file:" filename
2324 gnus-mail-save-name gnus-newsgroup-name
2325 gnus-current-headers 'gnus-newsgroup-last-mail))
2326 (gnus-eval-in-buffer-window gnus-save-article-buffer
2330 (if (and (file-readable-p filename)
2331 (mail-file-babyl-p filename))
2332 (rmail-output-to-rmail-file filename t)
2333 (gnus-output-to-mail filename)))))
2336 (defun gnus-summary-save-in-file (&optional filename overwrite)
2337 "Append this article to file.
2338 Optional argument FILENAME specifies file name.
2339 Directory to save to is default to `gnus-article-save-directory'."
2340 (setq filename (gnus-read-save-file-name
2341 "Save %s in file:" filename
2342 gnus-file-save-name gnus-newsgroup-name
2343 gnus-current-headers 'gnus-newsgroup-last-file))
2344 (gnus-eval-in-buffer-window gnus-save-article-buffer
2348 (when (and overwrite
2349 (file-exists-p filename))
2350 (delete-file filename))
2351 (gnus-output-to-file filename))))
2354 (defun gnus-summary-write-to-file (&optional filename)
2355 "Write this article to a file.
2356 Optional argument FILENAME specifies file name.
2357 The directory to save in defaults to `gnus-article-save-directory'."
2358 (gnus-summary-save-in-file nil t))
2360 (defun gnus-summary-save-body-in-file (&optional filename)
2361 "Append this article body to a file.
2362 Optional argument FILENAME specifies file name.
2363 The directory to save in defaults to `gnus-article-save-directory'."
2364 (setq filename (gnus-read-save-file-name
2365 "Save %s body in file:" filename
2366 gnus-file-save-name gnus-newsgroup-name
2367 gnus-current-headers 'gnus-newsgroup-last-file))
2368 (gnus-eval-in-buffer-window gnus-save-article-buffer
2372 (when (article-goto-body)
2373 (narrow-to-region (point) (point-max)))
2374 (gnus-output-to-file filename))))
2377 (defun gnus-summary-save-in-pipe (&optional command)
2378 "Pipe this article to subprocess."
2380 (cond ((and (eq command 'default)
2381 gnus-last-shell-command)
2382 gnus-last-shell-command)
2386 "Shell command on %s: "
2387 (if (and gnus-number-of-articles-to-be-saved
2388 (> gnus-number-of-articles-to-be-saved 1))
2389 (format "these %d articles"
2390 gnus-number-of-articles-to-be-saved)
2392 gnus-last-shell-command))))
2393 (when (string-equal command "")
2394 (setq command gnus-last-shell-command))
2395 (gnus-eval-in-buffer-window gnus-article-buffer
2398 (shell-command-on-region (point-min) (point-max) command nil)))
2399 (setq gnus-last-shell-command command))
2401 ;;; Article file names when saving.
2403 (defun gnus-capitalize-newsgroup (newsgroup)
2404 "Capitalize NEWSGROUP name."
2405 (when (not (zerop (length newsgroup)))
2406 (concat (char-to-string (upcase (aref newsgroup 0)))
2407 (substring newsgroup 1))))
2409 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2410 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2411 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2412 Otherwise, it is like ~/News/news/group/num."
2415 (concat (if (gnus-use-long-file-name 'not-save)
2416 (gnus-capitalize-newsgroup newsgroup)
2417 (gnus-newsgroup-directory-form newsgroup))
2418 "/" (int-to-string (mail-header-number headers)))
2419 gnus-article-save-directory)))
2421 (string-equal (file-name-directory default)
2422 (file-name-directory last-file))
2423 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2425 (or last-file default))))
2427 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2428 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2429 If variable `gnus-use-long-file-name' is non-nil, it is
2430 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2433 (concat (if (gnus-use-long-file-name 'not-save)
2435 (gnus-newsgroup-directory-form newsgroup))
2436 "/" (int-to-string (mail-header-number headers)))
2437 gnus-article-save-directory)))
2439 (string-equal (file-name-directory default)
2440 (file-name-directory last-file))
2441 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2443 (or last-file default))))
2445 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2446 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2447 If variable `gnus-use-long-file-name' is non-nil, it is
2448 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2451 (if (gnus-use-long-file-name 'not-save)
2452 (gnus-capitalize-newsgroup newsgroup)
2453 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2454 gnus-article-save-directory)))
2456 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2457 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2458 If variable `gnus-use-long-file-name' is non-nil, it is
2459 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2462 (if (gnus-use-long-file-name 'not-save)
2464 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2465 gnus-article-save-directory)))
2472 (setq afunc (car func)
2475 gfunc (intern (format "gnus-%s" func))))
2478 `(lambda (&optional interactive &rest args)
2479 ,(documentation afunc t)
2480 (interactive (list t))
2482 (set-buffer gnus-article-buffer)
2484 (call-interactively ',afunc)
2485 (apply ',afunc args))))))))
2486 '(article-hide-headers
2487 article-hide-boring-headers
2488 article-treat-overstrike
2489 article-fill-long-lines
2490 article-capitalize-sentences
2492 article-display-x-face
2493 article-de-quoted-unreadable
2494 article-de-base64-unreadable
2497 article-mime-decode-quoted-printable
2498 article-hide-list-identifiers
2500 article-strip-banner
2503 article-hide-signature
2504 article-strip-headers-in-body
2505 article-remove-trailing-blank-lines
2506 article-strip-leading-blank-lines
2507 article-strip-multiple-blank-lines
2508 article-strip-leading-space
2509 article-strip-trailing-space
2510 article-strip-blank-lines
2511 article-strip-all-blank-lines
2513 article-date-iso8601
2514 article-date-original
2516 article-decode-mime-words
2517 article-decode-charset
2518 article-decode-encoded-words
2522 article-treat-dumbquotes
2523 article-normalize-headers
2524 (article-show-all . gnus-article-show-all-headers))))
2527 ;;; Gnus article mode
2530 (put 'gnus-article-mode 'mode-class 'special)
2532 (set-keymap-parent gnus-article-mode-map widget-keymap)
2534 (gnus-define-keys gnus-article-mode-map
2535 " " gnus-article-goto-next-page
2536 "\177" gnus-article-goto-prev-page
2537 [delete] gnus-article-goto-prev-page
2538 [backspace] gnus-article-goto-prev-page
2539 "\C-c^" gnus-article-refer-article
2540 "h" gnus-article-show-summary
2541 "s" gnus-article-show-summary
2542 "\C-c\C-m" gnus-article-mail
2543 "?" gnus-article-describe-briefly
2544 "e" gnus-summary-edit-article
2545 "<" beginning-of-buffer
2547 "\C-c\C-i" gnus-info-find-node
2550 "\C-d" gnus-article-read-summary-keys
2551 "\M-*" gnus-article-read-summary-keys
2552 "\M-#" gnus-article-read-summary-keys
2553 "\M-^" gnus-article-read-summary-keys
2554 "\M-g" gnus-article-read-summary-keys)
2556 (substitute-key-definition
2557 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2559 (defun gnus-article-make-menu-bar ()
2560 (gnus-turn-off-edit-menu 'article)
2561 (unless (boundp 'gnus-article-article-menu)
2563 gnus-article-article-menu gnus-article-mode-map ""
2565 ["Scroll forwards" gnus-article-goto-next-page t]
2566 ["Scroll backwards" gnus-article-goto-prev-page t]
2567 ["Show summary" gnus-article-show-summary t]
2568 ["Fetch Message-ID at point" gnus-article-refer-article t]
2569 ["Mail to address at point" gnus-article-mail t]
2570 ["Send a bug report" gnus-bug t]))
2573 gnus-article-treatment-menu gnus-article-mode-map ""
2575 ["Hide headers" gnus-article-hide-headers t]
2576 ["Hide signature" gnus-article-hide-signature t]
2577 ["Hide citation" gnus-article-hide-citation t]
2578 ["Treat overstrike" gnus-article-treat-overstrike t]
2579 ["Remove carriage return" gnus-article-remove-cr t]
2580 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2581 ["Remove base64" gnus-article-de-base64-unreadable t]
2582 ["Treat html" gnus-article-wash-html t]
2583 ["Decode HZ" gnus-article-decode-HZ t]))
2585 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2587 (when (boundp 'gnus-summary-post-menu)
2588 (define-key gnus-article-mode-map [menu-bar post]
2589 (cons "Post" gnus-summary-post-menu)))
2591 (gnus-run-hooks 'gnus-article-menu-hook)))
2593 (defun gnus-article-mode ()
2594 "Major mode for displaying an article.
2596 All normal editing commands are switched off.
2598 The following commands are available in addition to all summary mode
2600 \\<gnus-article-mode-map>
2601 \\[gnus-article-next-page]\t Scroll the article one page forwards
2602 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2603 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2604 \\[gnus-article-show-summary]\t Display the summary buffer
2605 \\[gnus-article-mail]\t Send a reply to the address near point
2606 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2607 \\[gnus-info-find-node]\t Go to the Gnus info node"
2609 (when (gnus-visual-p 'article-menu 'menu)
2610 (gnus-article-make-menu-bar))
2611 (gnus-simplify-mode-line)
2612 (setq mode-name "Article")
2613 (setq major-mode 'gnus-article-mode)
2614 (make-local-variable 'minor-mode-alist)
2615 (use-local-map gnus-article-mode-map)
2616 (gnus-update-format-specifications nil 'article-mode)
2617 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2618 (make-local-variable 'gnus-page-broken)
2619 (make-local-variable 'gnus-button-marker-list)
2620 (make-local-variable 'gnus-article-current-summary)
2621 (make-local-variable 'gnus-article-mime-handles)
2622 (make-local-variable 'gnus-article-decoded-p)
2623 (make-local-variable 'gnus-article-mime-handle-alist)
2624 (make-local-variable 'gnus-article-wash-types)
2625 (gnus-set-default-directory)
2626 (buffer-disable-undo)
2627 (setq buffer-read-only t)
2628 (set-syntax-table gnus-article-mode-syntax-table)
2629 (mm-enable-multibyte)
2630 (gnus-run-hooks 'gnus-article-mode-hook))
2632 (defun gnus-article-setup-buffer ()
2633 "Initialize the article buffer."
2634 (let* ((name (if gnus-single-article-buffer "*Article*"
2635 (concat "*Article " gnus-newsgroup-name "*")))
2637 (progn (string-match "\\*Article" name)
2638 (concat " *Original Article"
2639 (substring name (match-end 0))))))
2640 (setq gnus-article-buffer name)
2641 (setq gnus-original-article-buffer original)
2642 (setq gnus-article-mime-handle-alist nil)
2643 ;; This might be a variable local to the summary buffer.
2644 (unless gnus-single-article-buffer
2646 (set-buffer gnus-summary-buffer)
2647 (setq gnus-article-buffer name)
2648 (setq gnus-original-article-buffer original)
2649 (gnus-set-global-variables)))
2650 (gnus-article-setup-highlight-words)
2651 ;; Init original article buffer.
2653 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2654 (mm-enable-multibyte)
2655 (setq major-mode 'gnus-original-article-mode)
2656 (make-local-variable 'gnus-original-article))
2657 (if (get-buffer name)
2660 (when gnus-article-mime-handles
2661 (mm-destroy-parts gnus-article-mime-handles))
2662 (buffer-disable-undo)
2663 (setq buffer-read-only t)
2664 (unless (eq major-mode 'gnus-article-mode)
2665 (gnus-article-mode))
2668 (set-buffer (gnus-get-buffer-create name))
2670 (make-local-variable 'gnus-summary-buffer)
2671 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2672 (current-buffer)))))
2674 ;; Set article window start at LINE, where LINE is the number of lines
2675 ;; from the head of the article.
2676 (defun gnus-article-set-window-start (&optional line)
2678 (get-buffer-window gnus-article-buffer t)
2680 (set-buffer gnus-article-buffer)
2681 (goto-char (point-min))
2684 (gnus-message 6 "Moved to bookmark")
2685 (search-forward "\n\n" nil t)
2689 (defun gnus-article-prepare (article &optional all-headers header)
2690 "Prepare ARTICLE in article mode buffer.
2691 ARTICLE should either be an article number or a Message-ID.
2692 If ARTICLE is an id, HEADER should be the article headers.
2693 If ALL-HEADERS is non-nil, no headers are hidden."
2695 ;; Make sure we start in a summary buffer.
2696 (unless (eq major-mode 'gnus-summary-mode)
2697 (set-buffer gnus-summary-buffer))
2698 (setq gnus-summary-buffer (current-buffer))
2699 (let* ((gnus-article (if header (mail-header-number header) article))
2700 (summary-buffer (current-buffer))
2701 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2702 (group gnus-newsgroup-name)
2705 (gnus-article-setup-buffer)
2706 (set-buffer gnus-article-buffer)
2707 ;; Deactivate active regions.
2708 (when (and (boundp 'transient-mark-mode)
2709 transient-mark-mode)
2710 (setq mark-active nil))
2711 (if (not (setq result (let ((buffer-read-only nil))
2712 (gnus-request-article-this-buffer
2714 ;; There is no such article.
2716 (when (and (numberp article)
2717 (not (memq article gnus-newsgroup-sparse)))
2718 (setq gnus-article-current
2719 (cons gnus-newsgroup-name article))
2720 (set-buffer gnus-summary-buffer)
2721 (setq gnus-current-article article)
2722 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2724 (gnus-summary-set-agent-mark article)
2725 (message "Message marked for downloading"))
2726 (gnus-summary-mark-article article gnus-canceled-mark)
2727 (unless (memq article gnus-newsgroup-sparse)
2728 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2729 (if (or (eq result 'pseudo)
2730 (eq result 'nneething))
2733 (set-buffer summary-buffer)
2734 (push article gnus-newsgroup-history)
2735 (setq gnus-last-article gnus-current-article
2736 gnus-current-article 0
2737 gnus-current-headers nil
2738 gnus-article-current nil)
2739 (if (eq result 'nneething)
2740 (gnus-configure-windows 'summary)
2741 (gnus-configure-windows 'article))
2742 (gnus-set-global-variables))
2743 (let ((gnus-article-mime-handle-alist-1
2744 gnus-article-mime-handle-alist))
2745 (gnus-set-mode-line 'article)))
2746 ;; The result from the `request' was an actual article -
2747 ;; or at least some text that is now displayed in the
2749 (when (and (numberp article)
2750 (not (eq article gnus-current-article)))
2751 ;; Seems like a new article has been selected.
2752 ;; `gnus-current-article' must be an article number.
2754 (set-buffer summary-buffer)
2755 (push article gnus-newsgroup-history)
2756 (setq gnus-last-article gnus-current-article
2757 gnus-current-article article
2758 gnus-current-headers
2759 (gnus-summary-article-header gnus-current-article)
2760 gnus-article-current
2761 (cons gnus-newsgroup-name gnus-current-article))
2762 (unless (vectorp gnus-current-headers)
2763 (setq gnus-current-headers nil))
2764 (gnus-summary-goto-subject gnus-current-article)
2765 (when (gnus-summary-show-thread)
2766 ;; If the summary buffer really was folded, the
2767 ;; previous goto may not actually have gone to
2768 ;; the right article, but the thread root instead.
2770 (gnus-summary-goto-subject gnus-current-article))
2771 (gnus-run-hooks 'gnus-mark-article-hook)
2772 (gnus-set-mode-line 'summary)
2773 (when (gnus-visual-p 'article-highlight 'highlight)
2774 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2775 ;; Set the global newsgroup variables here.
2776 (gnus-set-global-variables)
2777 (setq gnus-have-all-headers
2778 (or all-headers gnus-show-all-headers))))
2779 (when (or (numberp article)
2781 (gnus-article-prepare-display)
2783 (goto-char (point-min))
2784 (setq gnus-page-broken
2785 (when gnus-break-pages
2786 (gnus-narrow-to-page)
2788 (let ((gnus-article-mime-handle-alist-1
2789 gnus-article-mime-handle-alist))
2790 (gnus-set-mode-line 'article))
2792 (set-window-point (get-buffer-window (current-buffer)) (point))
2793 (gnus-configure-windows 'article)
2797 (defun gnus-article-prepare-display ()
2798 "Make the current buffer look like a nice article."
2799 ;; Hooks for getting information from the article.
2800 ;; This hook must be called before being narrowed.
2801 (let ((gnus-article-buffer (current-buffer))
2803 (unless (eq major-mode 'gnus-article-mode)
2804 (gnus-article-mode))
2805 (setq buffer-read-only nil
2806 gnus-article-wash-types nil)
2807 (gnus-run-hooks 'gnus-tmp-internal-hook)
2808 (when gnus-display-mime-function
2809 (funcall gnus-display-mime-function))
2810 (gnus-run-hooks 'gnus-article-prepare-hook)))
2813 ;;; Gnus MIME viewing functions
2816 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2817 "The following specs can be used:
2819 %T MIME type, along with additional info
2820 %n The `name' parameter
2821 %d The description, if any
2822 %l The length of the encoded part
2823 %p The part identifier number
2824 %e Dots if the part isn't displayed")
2826 (defvar gnus-mime-button-line-format-alist
2827 '((?t gnus-tmp-type ?s)
2828 (?T gnus-tmp-type-long ?s)
2829 (?n gnus-tmp-name ?s)
2830 (?d gnus-tmp-description ?s)
2832 (?l gnus-tmp-length ?d)
2833 (?e gnus-tmp-dots ?s)))
2835 (defvar gnus-mime-button-commands
2836 '((gnus-article-press-button "\r" "Toggle Display")
2837 (gnus-mime-view-part "v" "View Interactively...")
2838 (gnus-mime-view-part-as-type "t" "View As Type...")
2839 (gnus-mime-save-part "o" "Save...")
2840 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2841 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2842 (gnus-mime-internalize-part "E" "View Internally")
2843 (gnus-mime-externalize-part "e" "View Externally")
2844 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2846 (defun gnus-article-mime-part-status ()
2847 (if gnus-article-mime-handle-alist-1
2848 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2851 (defvar gnus-mime-button-map nil)
2852 (unless gnus-mime-button-map
2853 (setq gnus-mime-button-map (make-sparse-keymap))
2854 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2855 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2856 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2858 (define-key gnus-mime-button-map (cadr c) (car c)))
2859 gnus-mime-button-commands))
2861 (defun gnus-mime-button-menu (event)
2862 "Construct a context-sensitive menu of MIME commands."
2865 (let ((pos (event-start event)))
2866 (set-buffer (window-buffer (posn-window pos)))
2867 (goto-char (posn-point pos))
2868 (gnus-article-check-buffer)
2869 (let ((response (x-popup-menu
2871 ("" ,@(mapcar (lambda (c)
2872 (cons (caddr c) (car c)))
2873 gnus-mime-button-commands))))))
2875 (call-interactively response))))))
2877 (defun gnus-mime-view-all-parts (&optional handles)
2878 "View all the MIME parts."
2880 (save-current-buffer
2881 (set-buffer gnus-article-buffer)
2882 (let ((handles (or handles gnus-article-mime-handles))
2883 (mail-parse-charset gnus-newsgroup-charset)
2884 (mail-parse-ignored-charsets
2885 (save-excursion (set-buffer gnus-summary-buffer)
2886 gnus-newsgroup-ignored-charsets)))
2887 (if (stringp (car handles))
2888 (gnus-mime-view-all-parts (cdr handles))
2889 (mapcar 'mm-display-part handles)))))
2891 (defun gnus-mime-save-part ()
2892 "Save the MIME part under point."
2894 (gnus-article-check-buffer)
2895 (let ((data (get-text-property (point) 'gnus-data)))
2896 (mm-save-part data)))
2898 (defun gnus-mime-pipe-part ()
2899 "Pipe the MIME part under point to a process."
2901 (gnus-article-check-buffer)
2902 (let ((data (get-text-property (point) 'gnus-data)))
2903 (mm-pipe-part data)))
2905 (defun gnus-mime-view-part ()
2906 "Interactively choose a viewing method for the MIME part under point."
2908 (gnus-article-check-buffer)
2909 (let ((data (get-text-property (point) 'gnus-data)))
2910 (mm-interactively-view-part data)))
2912 (defun gnus-mime-view-part-as-type-internal ()
2913 (gnus-article-check-buffer)
2914 (let* ((name (mail-content-type-get
2915 (mm-handle-type (get-text-property (point) 'gnus-data))
2917 (def-type (and name (mm-default-file-encoding name))))
2918 (and def-type (cons def-type 0))))
2920 (defun gnus-mime-view-part-as-type (mime-type)
2921 "Choose a MIME media type, and view the part as such."
2923 (list (completing-read
2924 "View as MIME type: "
2925 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
2927 (gnus-mime-view-part-as-type-internal))))
2928 (gnus-article-check-buffer)
2929 (let ((handle (get-text-property (point) 'gnus-data)))
2930 (gnus-mm-display-part
2931 (mm-make-handle (mm-handle-buffer handle)
2932 (cons mime-type (cdr (mm-handle-type handle)))
2933 (mm-handle-encoding handle)
2934 (mm-handle-undisplayer handle)
2935 (mm-handle-disposition handle)
2936 (mm-handle-description handle)
2937 (mm-handle-cache handle)
2938 (mm-handle-id handle)))))
2940 (defun gnus-mime-copy-part (&optional handle)
2941 "Put the the MIME part under point into a new buffer."
2943 (gnus-article-check-buffer)
2944 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2945 (contents (mm-get-part handle))|
2946 (base (file-name-nondirectory
2948 (mail-content-type-get (mm-handle-type handle) 'name)
2949 (mail-content-type-get (mm-handle-type handle)
2952 (buffer (generate-new-buffer base)))
2953 (switch-to-buffer buffer)
2955 ;; We do it this way to make `normal-mode' set the appropriate mode.
2958 (setq buffer-file-name (expand-file-name base))
2960 (setq buffer-file-name nil))
2961 (goto-char (point-min))))
2963 (defun gnus-mime-inline-part (&optional handle)
2964 "Insert the MIME part under point into the current buffer."
2966 (gnus-article-check-buffer)
2967 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2971 (if (mm-handle-undisplayer handle)
2972 (mm-remove-part handle)
2973 (setq contents (mm-get-part handle))
2975 (mm-insert-inline handle contents)
2978 (defun gnus-mime-externalize-part (&optional handle)
2979 "View the MIME part under point with an external viewer."
2981 (gnus-article-check-buffer)
2982 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2983 (mm-user-display-methods nil)
2984 (mm-inlined-types nil)
2985 (mail-parse-charset gnus-newsgroup-charset)
2986 (mail-parse-ignored-charsets
2987 (save-excursion (set-buffer gnus-summary-buffer)
2988 gnus-newsgroup-ignored-charsets)))
2989 (if (mm-handle-undisplayer handle)
2990 (mm-remove-part handle)
2991 (mm-display-part handle))))
2993 (defun gnus-mime-internalize-part (&optional handle)
2994 "View the MIME part under point with an internal viewer.
2995 In no internal viewer is available, use an external viewer."
2997 (gnus-article-check-buffer)
2998 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2999 (mm-inlined-types '(".*"))
3000 (mm-inline-large-images t)
3001 (mail-parse-charset gnus-newsgroup-charset)
3002 (mail-parse-ignored-charsets
3003 (save-excursion (set-buffer gnus-summary-buffer)
3004 gnus-newsgroup-ignored-charsets)))
3005 (if (mm-handle-undisplayer handle)
3006 (mm-remove-part handle)
3007 (mm-display-part handle))))
3009 (defun gnus-article-part-wrapper (n function)
3010 (save-current-buffer
3011 (set-buffer gnus-article-buffer)
3012 (when (> n (length gnus-article-mime-handle-alist))
3013 (error "No such part"))
3014 (gnus-article-goto-part n)
3015 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3016 (funcall function handle))))
3018 (defun gnus-article-pipe-part (n)
3019 "Pipe MIME part N, which is the numerical prefix."
3021 (gnus-article-part-wrapper n 'mm-pipe-part))
3023 (defun gnus-article-save-part (n)
3024 "Save MIME part N, which is the numerical prefix."
3026 (gnus-article-part-wrapper n 'mm-save-part))
3028 (defun gnus-article-interactively-view-part (n)
3029 "View MIME part N interactively, which is the numerical prefix."
3031 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3033 (defun gnus-article-copy-part (n)
3034 "Copy MIME part N, which is the numerical prefix."
3036 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3038 (defun gnus-article-externalize-part (n)
3039 "View MIME part N externally, which is the numerical prefix."
3041 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3043 (defun gnus-article-inline-part (n)
3044 "Inline MIME part N, which is the numerical prefix."
3046 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3048 (defun gnus-article-mime-match-handle-first (condition)
3050 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3051 (while (setq ihandle (pop alist))
3053 ((functionp condition)
3054 (funcall condition (cdr ihandle)))
3055 ((eq condition 'undisplayed)
3056 (not (or (mm-handle-undisplayer (cdr ihandle))
3057 (equal (mm-handle-media-type (cdr ihandle))
3058 "multipart/alternative"))))
3059 ((eq condition 'undisplayed-alternative)
3060 (not (mm-handle-undisplayer (cdr ihandle))))
3062 (gnus-article-goto-part (car ihandle))
3063 (or (not n) (< (car ihandle) n)))
3064 (setq n (car ihandle))))
3068 (defun gnus-article-view-part (&optional n)
3069 "View MIME part N, which is the numerical prefix."
3071 (save-current-buffer
3072 (set-buffer gnus-article-buffer)
3073 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3074 gnus-article-mime-match-handle-function)))
3075 (when (> n (length gnus-article-mime-handle-alist))
3076 (error "No such part"))
3077 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3078 (when (gnus-article-goto-part n)
3079 (if (equal (car handle) "multipart/alternative")
3080 (gnus-article-press-button)
3081 (when (eq (gnus-mm-display-part handle) 'internal)
3082 (gnus-set-window-start)))))))
3084 (defun gnus-mm-display-part (handle)
3085 "Display HANDLE and fix MIME button."
3086 (let ((id (get-text-property (point) 'gnus-part))
3091 (let ((window (selected-window))
3092 (mail-parse-charset gnus-newsgroup-charset)
3093 (mail-parse-ignored-charsets
3094 (save-excursion (set-buffer gnus-summary-buffer)
3095 gnus-newsgroup-ignored-charsets)))
3098 (let ((win (get-buffer-window (current-buffer) t))
3101 (select-window win))
3104 (if (mm-handle-displayed-p handle)
3105 ;; This will remove the part.
3106 (mm-display-part handle)
3108 (narrow-to-region (point) (1+ (point)))
3109 (mm-display-part handle)
3110 ;; We narrow to the part itself and
3111 ;; then call the treatment functions.
3112 (goto-char (point-min))
3114 (narrow-to-region (point) (point-max))
3117 (1- (length gnus-article-mime-handles))
3118 (mm-handle-media-type handle)))))
3119 (select-window window))))
3121 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3122 (gnus-insert-mime-button
3123 handle id (list (mm-handle-displayed-p handle)))
3124 (goto-char point))))
3126 (defun gnus-article-goto-part (n)
3127 "Go to MIME part N."
3128 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3130 (goto-char point))))
3132 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3133 (let ((gnus-tmp-name
3134 (or (mail-content-type-get (mm-handle-type handle)
3136 (mail-content-type-get (mm-handle-disposition handle)
3139 (gnus-tmp-type (mm-handle-media-type handle))
3140 (gnus-tmp-description
3141 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3144 (if (if displayed (car displayed)
3145 (mm-handle-displayed-p handle))
3147 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3149 gnus-tmp-type-long b e)
3150 (when (string-match ".*/" gnus-tmp-name)
3151 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3152 (setq gnus-tmp-type-long (concat gnus-tmp-type
3153 (and (not (equal gnus-tmp-name ""))
3154 (concat "; " gnus-tmp-name))))
3155 (or (equal gnus-tmp-description "")
3156 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3161 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3162 `(local-map ,gnus-mime-button-map
3163 keymap ,gnus-mime-button-map
3164 gnus-callback gnus-mm-display-part
3165 gnus-part ,gnus-tmp-id
3166 article-type annotation
3169 (widget-convert-button 'link b e
3171 :action 'gnus-widget-press-button
3172 :button-keymap gnus-mime-button-map
3175 ;; Needed to properly clear the message
3176 ;; due to a bug in wid-edit
3177 (setq help-echo-owns-message t)
3179 "Click to %s the MIME part; %s for more options"
3180 (if (mm-handle-displayed-p
3181 (widget-get widget :mime-handle))
3183 (if gnus-xemacs "button3" "mouse-3"))))))
3185 (defun gnus-widget-press-button (elems el)
3186 (goto-char (widget-get elems :from))
3187 (gnus-article-press-button))
3189 (defvar gnus-displaying-mime nil)
3191 (defun gnus-display-mime (&optional ihandles)
3192 "Display the MIME parts."
3194 (save-selected-window
3195 (let ((window (get-buffer-window gnus-article-buffer))
3198 (select-window window)
3199 ;; We have to do this since selecting the window
3200 ;; may change the point. So we set the window point.
3201 (set-window-point window point)))
3202 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3203 buffer-read-only handle name type b e display)
3204 (when (and (not ihandles)
3205 (not gnus-displaying-mime))
3206 ;; Top-level call; we clean up.
3207 (when gnus-article-mime-handles
3208 (mm-destroy-parts gnus-article-mime-handles)
3209 (setq gnus-article-mime-handle-alist nil));; A trick.
3210 (setq gnus-article-mime-handles handles)
3211 ;; We allow users to glean info from the handles.
3212 (when gnus-article-mime-part-function
3213 (gnus-mime-part-function handles)))
3215 (or (not (stringp (car handles)))
3218 (when (and (not ihandles)
3219 (not gnus-displaying-mime))
3220 ;; Clean up for mime parts.
3222 (delete-region (point) (point-max)))
3223 (let ((gnus-displaying-mime t))
3224 (gnus-mime-display-part handles)))
3227 (narrow-to-region (point) (point-max))
3228 (gnus-treat-article nil 1 1)
3231 ;; Highlight the headers.
3235 (narrow-to-region (point-min) (point))
3236 (gnus-treat-article 'head))))))))
3238 (defvar gnus-mime-display-multipart-as-mixed nil)
3240 (defun gnus-mime-display-part (handle)
3243 ((not (stringp (car handle)))
3244 (gnus-mime-display-single handle))
3245 ;; User-defined multipart
3246 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3247 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3249 ;; multipart/alternative
3250 ((and (equal (car handle) "multipart/alternative")
3251 (not gnus-mime-display-multipart-as-mixed))
3252 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3253 (push (cons id handle) gnus-article-mime-handle-alist)
3254 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3255 ;; multipart/related
3256 ((and (equal (car handle) "multipart/related")
3257 (not gnus-mime-display-multipart-as-mixed))
3258 ;;;!!!We should find the start part, but we just default
3259 ;;;!!!to the first part.
3260 (gnus-mime-display-part (cadr handle)))
3261 ;; Other multiparts are handled like multipart/mixed.
3263 (gnus-mime-display-mixed (cdr handle)))))
3265 (defun gnus-mime-part-function (handles)
3266 (if (stringp (car handles))
3267 (mapcar 'gnus-mime-part-function (cdr handles))
3268 (funcall gnus-article-mime-part-function handles)))
3270 (defun gnus-mime-display-mixed (handles)
3271 (mapcar 'gnus-mime-display-part handles))
3273 (defun gnus-mime-display-single (handle)
3274 (let ((type (mm-handle-media-type handle))
3275 (ignored gnus-ignored-mime-types)
3282 (when (string-match (pop ignored) type)
3283 (throw 'ignored nil)))
3284 (if (and (setq not-attachment
3285 (and (not (mm-inline-override-p handle))
3286 (or (not (mm-handle-disposition handle))
3287 (equal (car (mm-handle-disposition handle))
3289 (mm-attachment-override-p handle))))
3290 (mm-automatic-display-p handle)
3291 (or (mm-inlined-p handle)
3292 (mm-automatic-external-display-p type)))
3294 (when (equal (mm-handle-media-supertype handle) "text")
3296 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3297 (push (cons id handle) gnus-article-mime-handle-alist)
3298 (when (or (not display)
3299 (not (gnus-unbuttonized-mime-type-p type)))
3300 ;(gnus-article-insert-newline)
3301 (gnus-insert-mime-button
3302 handle id (list (or display (and not-attachment text))))
3303 (gnus-article-insert-newline)
3304 ;(gnus-article-insert-newline)
3306 (let ((beg (point)))
3312 (let ((mail-parse-charset gnus-newsgroup-charset)
3313 (mail-parse-ignored-charsets
3314 (save-excursion (condition-case ()
3315 (set-buffer gnus-summary-buffer)
3317 gnus-newsgroup-ignored-charsets)))
3318 (mm-display-part handle t))
3319 (goto-char (point-max)))
3320 ((and text not-attachment)
3324 (gnus-article-insert-newline)
3325 (mm-insert-inline handle (mm-get-part handle))
3326 (goto-char (point-max))))
3330 (narrow-to-region beg (point))
3332 nil (length gnus-article-mime-handle-alist)
3333 (1- (length gnus-article-mime-handles))
3334 (mm-handle-media-type handle)))))))))
3336 (defun gnus-unbuttonized-mime-type-p (type)
3337 "Say whether TYPE is to be unbuttonized."
3338 (unless gnus-inhibit-mime-unbuttonizing
3340 (let ((types gnus-unbuttonized-mime-types))
3342 (when (string-match (pop types) type)
3343 (throw 'found t)))))))
3345 (defun gnus-article-insert-newline ()
3346 "Insert a newline, but mark it as undeletable."
3347 (gnus-put-text-property
3348 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3350 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3351 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3354 handle buffer-read-only from props begend not-pref)
3355 (save-window-excursion
3358 (narrow-to-region (car ibegend)
3361 (goto-char (car ibegend))
3364 (delete-region (point-min) (point-max))
3365 (mm-remove-parts handles))
3366 (setq begend (list (point-marker)))
3368 (unless (setq not-pref (cadr (member preferred ihandles)))
3369 (setq not-pref (car ihandles)))
3371 (not (gnus-unbuttonized-mime-type-p
3372 "multipart/alternative")))
3373 (gnus-add-text-properties
3376 (insert (format "%d. " id))
3380 (unless ,(not ibegend)
3381 (setq gnus-article-mime-handle-alist
3382 ',gnus-article-mime-handle-alist))
3383 (gnus-mime-display-alternative
3384 ',ihandles ',not-pref ',begend ,id))
3385 local-map ,gnus-mime-button-map
3386 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3387 face ,gnus-article-button-face
3388 keymap ,gnus-mime-button-map
3391 (widget-convert-button 'link from (point)
3392 :action 'gnus-widget-press-button
3393 :button-keymap gnus-widget-button-keymap)
3395 (while (setq handle (pop handles))
3396 (gnus-add-text-properties
3399 (insert (format "(%c) %-18s"
3400 (if (equal handle preferred) ?* ? )
3401 (mm-handle-media-type handle)))
3405 (unless ,(not ibegend)
3406 (setq gnus-article-mime-handle-alist
3407 ',gnus-article-mime-handle-alist))
3408 (gnus-mime-display-alternative
3409 ',ihandles ',handle ',begend ,id))
3410 local-map ,gnus-mime-button-map
3411 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3412 face ,gnus-article-button-face
3413 keymap ,gnus-mime-button-map
3416 (widget-convert-button 'link from (point)
3417 :action 'gnus-widget-press-button
3418 :button-keymap gnus-widget-button-keymap)
3422 (if (stringp (car preferred))
3423 (gnus-display-mime preferred)
3424 (let ((mail-parse-charset gnus-newsgroup-charset)
3425 (mail-parse-ignored-charsets
3426 (save-excursion (set-buffer gnus-summary-buffer)
3427 gnus-newsgroup-ignored-charsets)))
3428 (mm-display-part preferred)
3432 (narrow-to-region (car begend) (point-max))
3434 nil (length gnus-article-mime-handle-alist)
3435 (1- (length gnus-article-mime-handles))
3436 (mm-handle-media-type handle))))))
3437 (goto-char (point-max))
3438 (setcdr begend (point-marker)))))
3440 (goto-char point))))
3442 (defun gnus-article-wash-status ()
3443 "Return a string which display status of article washing."
3445 (set-buffer gnus-article-buffer)
3446 (let ((cite (memq 'cite gnus-article-wash-types))
3447 (headers (memq 'headers gnus-article-wash-types))
3448 (boring (memq 'boring-headers gnus-article-wash-types))
3449 (pgp (memq 'pgp gnus-article-wash-types))
3450 (pem (memq 'pem gnus-article-wash-types))
3451 (signature (memq 'signature gnus-article-wash-types))
3452 (overstrike (memq 'overstrike gnus-article-wash-types))
3453 (emphasis (memq 'emphasis gnus-article-wash-types)))
3454 (format "%c%c%c%c%c%c"
3456 (if (or headers boring) ?h ? )
3457 (if (or pgp pem) ?p ? )
3458 (if signature ?s ? )
3459 (if overstrike ?o ? )
3460 (if emphasis ?e ? )))))
3462 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3464 (defun gnus-article-maybe-hide-headers ()
3465 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3466 Provided for backwards compatibility."
3467 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3468 (not (save-excursion (set-buffer gnus-summary-buffer)
3469 gnus-have-all-headers)))
3470 (not gnus-inhibit-hiding))
3471 (gnus-article-hide-headers)))
3475 (defun gnus-output-to-file (file-name)
3476 "Append the current article to a file named FILE-NAME."
3477 (let ((artbuf (current-buffer)))
3479 (insert-buffer-substring artbuf)
3480 ;; Append newline at end of the buffer as separator, and then
3482 (goto-char (point-max))
3484 (mm-append-to-file (point-min) (point-max) file-name)
3487 (defun gnus-narrow-to-page (&optional arg)
3488 "Narrow the article buffer to a page.
3489 If given a numerical ARG, move forward ARG pages."
3491 (setq arg (if arg (prefix-numeric-value arg) 0))
3493 (set-buffer gnus-article-buffer)
3494 (goto-char (point-min))
3496 ;; Remove any old next/prev buttons.
3497 (when (gnus-visual-p 'page-marker)
3498 (let ((buffer-read-only nil))
3499 (gnus-remove-text-with-property 'gnus-prev)
3500 (gnus-remove-text-with-property 'gnus-next)))
3503 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3505 (re-search-forward page-delimiter nil 'move arg)))
3506 (goto-char (match-end 0)))
3509 (if (re-search-forward page-delimiter nil 'move)
3512 (when (and (gnus-visual-p 'page-marker)
3513 (not (= (point-min) 1)))
3515 (goto-char (point-min))
3516 (gnus-insert-prev-page-button)))
3517 (when (and (gnus-visual-p 'page-marker)
3518 (< (+ (point-max) 2) (buffer-size)))
3520 (goto-char (point-max))
3521 (gnus-insert-next-page-button)))))
3523 ;; Article mode commands
3525 (defun gnus-article-goto-next-page ()
3526 "Show the next page of the article."
3528 (when (gnus-article-next-page)
3529 (goto-char (point-min))
3530 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3532 (defun gnus-article-goto-prev-page ()
3533 "Show the next page of the article."
3535 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3536 (gnus-article-prev-page nil)))
3538 (defun gnus-article-next-page (&optional lines)
3539 "Show the next page of the current article.
3540 If end of article, return non-nil. Otherwise return nil.
3541 Argument LINES specifies lines to be scrolled up."
3543 (move-to-window-line -1)
3546 ;; Redisplay before the visibility test; else we don't DTRT
3547 ;; with Emacs 21 images, for instance.
3548 ;; Actually, the redisplay is annoying. Fixme some other way.
3550 (and (pos-visible-in-window-p) ;Not continuation line.
3552 ;; Nothing in this page.
3553 (if (or (not gnus-page-broken)
3556 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3558 (gnus-narrow-to-page 1) ;Go to next page.
3560 ;; More in this page.
3561 (let ((scroll-in-place nil))
3565 ;; Long lines may cause an end-of-buffer error.
3566 (goto-char (point-max)))))
3567 (move-to-window-line 0)
3570 (defun gnus-article-prev-page (&optional lines)
3571 "Show previous page of current article.
3572 Argument LINES specifies lines to be scrolled down."
3574 (move-to-window-line 0)
3575 (if (and gnus-page-broken
3577 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3579 (gnus-narrow-to-page -1) ;Go to previous page.
3580 (goto-char (point-max))
3582 (let ((scroll-in-place nil))
3586 (beginning-of-buffer
3587 (goto-char (point-min))))
3588 (move-to-window-line 0)))))
3590 (defun gnus-article-refer-article ()
3591 "Read article specified by message-id around point."
3593 (let ((point (point)))
3594 (search-forward ">" nil t) ;Move point to end of "<....>".
3595 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3596 (let ((message-id (match-string 1)))
3598 (set-buffer gnus-summary-buffer)
3599 (gnus-summary-refer-article message-id))
3601 (error "No references around point"))))
3603 (defun gnus-article-show-summary ()
3604 "Reconfigure windows to show summary buffer."
3606 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3607 (error "There is no summary buffer for this article buffer")
3608 (gnus-article-set-globals)
3609 (gnus-configure-windows 'article)
3610 (gnus-summary-goto-subject gnus-current-article)
3611 (gnus-summary-position-point)))
3613 (defun gnus-article-describe-briefly ()
3614 "Describe article mode commands briefly."
3616 (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")))
3618 (defun gnus-article-summary-command ()
3619 "Execute the last keystroke in the summary buffer."
3621 (let ((obuf (current-buffer))
3622 (owin (current-window-configuration))
3624 (switch-to-buffer gnus-article-current-summary 'norecord)
3625 (setq func (lookup-key (current-local-map) (this-command-keys)))
3626 (call-interactively func)
3628 (set-window-configuration owin)
3629 (set-window-point (get-buffer-window (current-buffer)) (point))))
3631 (defun gnus-article-summary-command-nosave ()
3632 "Execute the last keystroke in the summary buffer."
3635 (pop-to-buffer gnus-article-current-summary 'norecord)
3636 (setq func (lookup-key (current-local-map) (this-command-keys)))
3637 (call-interactively func)))
3639 (defun gnus-article-check-buffer ()
3640 "Beep if not in an article buffer."
3641 (unless (equal major-mode 'gnus-article-mode)
3642 (error "Command invoked outside of a Gnus article buffer")))
3644 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3645 "Read a summary buffer key sequence and execute it from the article buffer."
3647 (gnus-article-check-buffer)
3649 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3650 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3651 "=" "^" "\M-^" "|"))
3657 '("n" "Gn" "p" "Gp"))
3660 (set-buffer gnus-article-current-summary)
3661 (let (gnus-pick-mode)
3662 (push (or key last-command-event) unread-command-events)
3663 (setq keys (if gnus-xemacs
3664 (events-to-keys (read-key-sequence nil))
3665 (read-key-sequence nil)))))
3669 (if (or (member keys nosaves)
3670 (member keys nosave-but-article)
3671 (member keys nosave-in-article))
3673 (save-window-excursion
3674 (pop-to-buffer gnus-article-current-summary 'norecord)
3675 ;; We disable the pick minor mode commands.
3676 (let (gnus-pick-mode)
3677 (setq func (lookup-key (current-local-map) keys))))
3681 (unless (member keys nosave-in-article)
3682 (set-buffer gnus-article-current-summary))
3683 (call-interactively func)
3684 (setq new-sum-point (point)))
3685 (when (member keys nosave-but-article)
3686 (pop-to-buffer gnus-article-buffer 'norecord)))
3687 ;; These commands should restore window configuration.
3688 (let ((obuf (current-buffer))
3689 (owin (current-window-configuration))
3691 (summary gnus-article-current-summary)
3692 func in-buffer selected)
3693 (if not-restore-window
3694 (pop-to-buffer summary 'norecord)
3695 (switch-to-buffer summary 'norecord))
3696 (setq in-buffer (current-buffer))
3697 ;; We disable the pick minor mode commands.
3698 (if (setq func (let (gnus-pick-mode)
3699 (lookup-key (current-local-map) keys)))
3701 (call-interactively func)
3702 (setq new-sum-point (point)))
3704 (when (eq in-buffer (current-buffer))
3705 (setq selected (gnus-summary-select-article))
3707 (unless not-restore-window
3708 (set-window-configuration owin))
3709 (when (eq selected 'old)
3711 (set-window-start (get-buffer-window (current-buffer))
3713 (set-window-point (get-buffer-window (current-buffer))
3715 (let ((win (get-buffer-window gnus-article-current-summary)))
3717 (set-window-point win new-sum-point))))))))
3719 (defun gnus-article-hide (&optional arg force)
3720 "Hide all the gruft in the current article.
3721 This means that PGP stuff, signatures, cited text and (some)
3722 headers will be hidden.
3723 If given a prefix, show the hidden text instead."
3724 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3725 (gnus-article-hide-headers arg)
3726 (gnus-article-hide-list-identifiers arg)
3727 (gnus-article-hide-pgp arg)
3728 (gnus-article-hide-citation-maybe arg force)
3729 (gnus-article-hide-signature arg))
3731 (defun gnus-article-maybe-highlight ()
3732 "Do some article highlighting if article highlighting is requested."
3733 (when (gnus-visual-p 'article-highlight 'highlight)
3734 (gnus-article-highlight-some)))
3736 (defun gnus-check-group-server ()
3737 ;; Make sure the connection to the server is alive.
3738 (unless (gnus-server-opened
3739 (gnus-find-method-for-group gnus-newsgroup-name))
3740 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3741 (gnus-request-group gnus-newsgroup-name t)))
3743 (defun gnus-request-article-this-buffer (article group)
3744 "Get an article and insert it into this buffer."
3745 (let (do-update-line sparse-header)
3749 (gnus-kill-all-overlays)
3750 (setq group (or group gnus-newsgroup-name))
3752 ;; Using `gnus-request-article' directly will insert the article into
3753 ;; `nntp-server-buffer' - so we'll save some time by not having to
3754 ;; copy it from the server buffer into the article buffer.
3756 ;; We only request an article by message-id when we do not have the
3757 ;; headers for it, so we'll have to get those.
3758 (when (stringp article)
3759 (gnus-read-header article))
3761 ;; If the article number is negative, that means that this article
3762 ;; doesn't belong in this newsgroup (possibly), so we find its
3763 ;; message-id and request it by id instead of number.
3764 (when (and (numberp article)
3766 (get-buffer gnus-summary-buffer)
3767 (gnus-buffer-exists-p gnus-summary-buffer))
3769 (set-buffer gnus-summary-buffer)
3770 (let ((header (gnus-summary-article-header article)))
3773 ((memq article gnus-newsgroup-sparse)
3774 ;; This is a sparse gap article.
3775 (setq do-update-line article)
3776 (setq article (mail-header-id header))
3777 (setq sparse-header (gnus-read-header article))
3778 (setq gnus-newsgroup-sparse
3779 (delq article gnus-newsgroup-sparse)))
3781 ;; It's a real article.
3782 (setq article (mail-header-id header)))
3784 ;; It is an extracted pseudo-article.
3785 (setq article 'pseudo)
3786 (gnus-request-pseudo-article header))))
3788 (let ((method (gnus-find-method-for-group
3789 gnus-newsgroup-name)))
3790 (when (and (eq (car method) 'nneething)
3793 (file-name-as-directory
3794 (or (cadr (assq 'nneething-address method))
3796 (mail-header-subject header))))
3797 (when (file-directory-p dir)
3798 (setq article 'nneething)
3799 (gnus-group-enter-directory dir))))))))
3802 ;; Refuse to select canceled articles.
3803 ((and (numberp article)
3805 (get-buffer gnus-summary-buffer)
3806 (gnus-buffer-exists-p gnus-summary-buffer)
3807 (eq (cdr (save-excursion
3808 (set-buffer gnus-summary-buffer)
3809 (assq article gnus-newsgroup-reads)))
3810 gnus-canceled-mark))
3812 ;; We first check `gnus-original-article-buffer'.
3813 ((and (get-buffer gnus-original-article-buffer)
3816 (set-buffer gnus-original-article-buffer)
3817 (and (equal (car gnus-original-article) group)
3818 (eq (cdr gnus-original-article) article))))
3819 (insert-buffer-substring gnus-original-article-buffer)
3821 ;; Check the backlog.
3822 ((and gnus-keep-backlog
3823 (gnus-backlog-request-article group article (current-buffer)))
3825 ;; Check asynchronous pre-fetch.
3826 ((gnus-async-request-fetched-article group article (current-buffer))
3827 (gnus-async-prefetch-next group article gnus-summary-buffer)
3828 (when (and (numberp article) gnus-keep-backlog)
3829 (gnus-backlog-enter-article group article (current-buffer)))
3832 ((and gnus-use-cache
3834 (gnus-cache-request-article article group))
3836 ;; Get the article and put into the article buffer.
3837 ((or (stringp article)
3839 (let ((gnus-override-method gnus-override-method)
3840 (methods (and (stringp article)
3841 gnus-refer-article-method))
3843 (buffer-read-only nil))
3848 (when (and (null gnus-override-method)
3850 (setq gnus-override-method (pop methods)))
3852 (when (eq gnus-override-method 'current)
3853 (setq gnus-override-method gnus-current-select-method))
3855 (gnus-kill-all-overlays)
3856 (let ((gnus-newsgroup-name group))
3857 (gnus-check-group-server))
3858 (when (gnus-request-article article group (current-buffer))
3859 (when (numberp article)
3860 (gnus-async-prefetch-next group article
3861 gnus-summary-buffer)
3862 (when gnus-keep-backlog
3863 (gnus-backlog-enter-article
3864 group article (current-buffer))))
3865 (setq result 'article))
3868 (setq gnus-override-method (pop methods))
3869 (setq result 'done))))
3870 (and (eq result 'article) 'article)))
3874 ;; Associate this article with the current summary buffer.
3875 (setq gnus-article-current-summary gnus-summary-buffer)
3877 ;; Take the article from the original article buffer
3878 ;; and place it in the buffer it's supposed to be in.
3879 (when (and (get-buffer gnus-article-buffer)
3880 (equal (buffer-name (current-buffer))
3881 (buffer-name (get-buffer gnus-article-buffer))))
3883 (if (get-buffer gnus-original-article-buffer)
3884 (set-buffer gnus-original-article-buffer)
3885 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3886 (buffer-disable-undo)
3887 (setq major-mode 'gnus-original-article-mode)
3888 (setq buffer-read-only t))
3889 (let (buffer-read-only)
3891 (insert-buffer-substring gnus-article-buffer))
3892 (setq gnus-original-article (cons group article)))
3895 (run-hooks 'gnus-article-decode-hook)
3896 ;; Mark article as decoded or not.
3897 (setq gnus-article-decoded-p gnus-article-decode-hook))
3899 ;; Update sparse articles.
3900 (when (and do-update-line
3901 (or (numberp article)
3903 (let ((buf (current-buffer)))
3904 (set-buffer gnus-summary-buffer)
3905 (gnus-summary-update-article do-update-line sparse-header)
3906 (gnus-summary-goto-subject do-update-line nil t)
3907 (set-window-point (get-buffer-window (current-buffer) t)
3909 (set-buffer buf))))))
3915 (defcustom gnus-article-edit-mode-hook nil
3916 "Hook run in article edit mode buffers."
3917 :group 'gnus-article-various
3920 (defvar gnus-article-edit-done-function nil)
3922 (defvar gnus-article-edit-mode-map nil)
3924 ;; Should we be using derived.el for this?
3925 (unless gnus-article-edit-mode-map
3926 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3927 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3929 (gnus-define-keys gnus-article-edit-mode-map
3930 "\C-c\C-c" gnus-article-edit-done
3931 "\C-c\C-k" gnus-article-edit-exit)
3933 (gnus-define-keys (gnus-article-edit-wash-map
3934 "\C-c\C-w" gnus-article-edit-mode-map)
3935 "f" gnus-article-edit-full-stops))
3937 (defun gnus-article-edit-mode ()
3938 "Major mode for editing articles.
3939 This is an extended text-mode.
3941 \\{gnus-article-edit-mode-map}"
3943 (setq major-mode 'gnus-article-edit-mode)
3944 (setq mode-name "Article Edit")
3945 (use-local-map gnus-article-edit-mode-map)
3946 (make-local-variable 'gnus-article-edit-done-function)
3947 (make-local-variable 'gnus-prev-winconf)
3948 (setq buffer-read-only nil)
3949 (buffer-enable-undo)
3951 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3953 (defun gnus-article-edit (&optional force)
3954 "Edit the current article.
3955 This will have permanent effect only in mail groups.
3956 If FORCE is non-nil, allow editing of articles even in read-only
3959 (when (and (not force)
3960 (gnus-group-read-only-p))
3961 (error "The current newsgroup does not support article editing"))
3962 (gnus-article-date-original)
3963 (gnus-article-edit-article
3965 `(lambda (no-highlight)
3967 (gnus-summary-edit-article-done
3968 ,(or (mail-header-references gnus-current-headers) "")
3969 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3971 (defun gnus-article-edit-article (start-func exit-func)
3972 "Start editing the contents of the current article buffer."
3973 (let ((winconf (current-window-configuration)))
3974 (set-buffer gnus-article-buffer)
3975 (gnus-article-edit-mode)
3976 (funcall start-func)
3977 (gnus-configure-windows 'edit-article)
3978 (setq gnus-article-edit-done-function exit-func)
3979 (setq gnus-prev-winconf winconf)
3980 (gnus-message 6 "C-c C-c to end edits")))
3982 (defun gnus-article-edit-done (&optional arg)
3983 "Update the article edits and exit."
3988 (when (article-goto-body)
3989 (let ((lines (count-lines (point) (point-max)))
3990 (length (- (point-max) (point)))
3991 (case-fold-search t)
3992 (body (copy-marker (point))))
3993 (goto-char (point-min))
3994 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3995 (delete-region (match-beginning 1) (match-end 1))
3996 (insert (number-to-string length)))
3997 (goto-char (point-min))
3998 (when (re-search-forward
3999 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4000 (delete-region (match-beginning 1) (match-end 1))
4001 (insert (number-to-string length)))
4002 (goto-char (point-min))
4003 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4004 (delete-region (match-beginning 1) (match-end 1))
4005 (insert (number-to-string lines)))))))
4006 (let ((func gnus-article-edit-done-function)
4007 (buf (current-buffer))
4008 (start (window-start)))
4009 (gnus-article-edit-exit)
4012 (let ((buffer-read-only nil))
4014 ;; The cache and backlog have to be flushed somewhat.
4015 (when gnus-keep-backlog
4016 (gnus-backlog-remove-article
4017 (car gnus-article-current) (cdr gnus-article-current)))
4018 ;; Flush original article as well.
4020 (when (get-buffer gnus-original-article-buffer)
4021 (set-buffer gnus-original-article-buffer)
4022 (setq gnus-original-article nil)))
4023 (when gnus-use-cache
4024 (gnus-cache-update-article
4025 (car gnus-article-current) (cdr gnus-article-current))))
4027 (set-window-start (get-buffer-window buf) start)
4028 (set-window-point (get-buffer-window buf) (point))))
4030 (defun gnus-article-edit-exit ()
4031 "Exit the article editing without updating."
4033 ;; We remove all text props from the article buffer.
4034 (let ((buf (format "%s" (buffer-string)))
4035 (curbuf (current-buffer))
4037 (window-start (window-start)))
4040 (let ((winconf gnus-prev-winconf))
4042 (set-window-configuration winconf)
4043 ;; Tippy-toe some to make sure that point remains where it was.
4044 (save-current-buffer
4046 (set-window-start (get-buffer-window (current-buffer)) window-start)
4049 (defun gnus-article-edit-full-stops ()
4050 "Interactively repair spacing at end of sentences."
4053 (goto-char (point-min))
4054 (search-forward-regexp "^$" nil t)
4055 (let ((case-fold-search nil))
4056 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4059 ;;; Article highlights
4062 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4064 ;;; Internal Variables:
4066 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)"
4067 "Regular expression that matches URLs."
4068 :group 'gnus-article-buttons
4071 (defcustom gnus-button-alist
4072 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4073 0 t gnus-button-message-id 2)
4074 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4075 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4077 gnus-button-fetch-group 4)
4078 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4079 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4080 t gnus-button-message-id 3)
4081 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4082 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4083 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4084 ;; This is how URLs _should_ be embedded in text...
4085 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4087 (,gnus-button-url-regexp 0 t browse-url 0))
4088 "*Alist of regexps matching buttons in article bodies.
4090 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4091 REGEXP: is the string matching text around the button,
4092 BUTTON: is the number of the regexp grouping actually matching the button,
4093 FORM: is a lisp expression which must eval to true for the button to
4095 CALLBACK: is the function to call when the user push this button, and each
4096 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4098 CALLBACK can also be a variable, in that case the value of that
4099 variable it the real callback function."
4100 :group 'gnus-article-buttons
4101 :type '(repeat (list regexp
4102 (integer :tag "Button")
4104 (function :tag "Callback")
4107 (integer :tag "Regexp group")))))
4109 (defcustom gnus-header-button-alist
4110 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4111 0 t gnus-button-message-id 0)
4112 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4113 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4114 0 t gnus-button-mailto 0)
4115 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4116 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4117 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4118 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4119 gnus-button-message-id 3))
4120 "*Alist of headers and regexps to match buttons in article heads.
4122 This alist is very similar to `gnus-button-alist', except that each
4123 alist has an additional HEADER element first in each entry:
4125 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4127 HEADER is a regexp to match a header. For a fuller explanation, see
4128 `gnus-button-alist'."
4129 :group 'gnus-article-buttons
4130 :group 'gnus-article-headers
4131 :type '(repeat (list (regexp :tag "Header")
4133 (integer :tag "Button")
4135 (function :tag "Callback")
4138 (integer :tag "Regexp group")))))
4140 (defvar gnus-button-regexp nil)
4141 (defvar gnus-button-marker-list nil)
4142 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4144 (defvar gnus-button-last nil)
4145 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4149 (defun gnus-article-push-button (event)
4150 "Check text under the mouse pointer for a callback function.
4151 If the text under the mouse pointer has a `gnus-callback' property,
4152 call it with the value of the `gnus-data' text property."
4154 (set-buffer (window-buffer (posn-window (event-start event))))
4155 (let* ((pos (posn-point (event-start event)))
4156 (data (get-text-property pos 'gnus-data))
4157 (fun (get-text-property pos 'gnus-callback)))
4160 (funcall fun data))))
4162 (defun gnus-article-press-button ()
4163 "Check text at point for a callback function.
4164 If the text at point has a `gnus-callback' property,
4165 call it with the value of the `gnus-data' text property."
4167 (let* ((data (get-text-property (point) 'gnus-data))
4168 (fun (get-text-property (point) 'gnus-callback)))
4170 (funcall fun data))))
4172 (defun gnus-article-highlight (&optional force)
4173 "Highlight current article.
4174 This function calls `gnus-article-highlight-headers',
4175 `gnus-article-highlight-citation',
4176 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4177 do the highlighting. See the documentation for those functions."
4178 (interactive (list 'force))
4179 (gnus-article-highlight-headers)
4180 (gnus-article-highlight-citation force)
4181 (gnus-article-highlight-signature)
4182 (gnus-article-add-buttons force)
4183 (gnus-article-add-buttons-to-head))
4185 (defun gnus-article-highlight-some (&optional force)
4186 "Highlight current article.
4187 This function calls `gnus-article-highlight-headers',
4188 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4189 do the highlighting. See the documentation for those functions."
4190 (interactive (list 'force))
4191 (gnus-article-highlight-headers)
4192 (gnus-article-highlight-signature)
4193 (gnus-article-add-buttons))
4195 (defun gnus-article-highlight-headers ()
4196 "Highlight article headers as specified by `gnus-header-face-alist'."
4199 (set-buffer gnus-article-buffer)
4201 (let ((alist gnus-header-face-alist)
4202 (buffer-read-only nil)
4203 (case-fold-search t)
4204 (inhibit-point-motion-hooks t)
4205 entry regexp header-face field-face from hpoints fpoints)
4206 (article-narrow-to-head)
4207 (while (setq entry (pop alist))
4208 (goto-char (point-min))
4209 (setq regexp (concat "^\\("
4210 (if (string-equal "" (nth 0 entry))
4214 header-face (nth 1 entry)
4215 field-face (nth 2 entry))
4216 (while (and (re-search-forward regexp nil t)
4220 (unless (search-forward ":" nil t)
4222 (when (and header-face
4223 (not (memq (point) hpoints)))
4224 (push (point) hpoints)
4225 (gnus-put-text-property from (point) 'face header-face))
4226 (when (and field-face
4227 (not (memq (setq from (point)) fpoints)))
4229 (if (re-search-forward "^[^ \t]" nil t)
4231 (goto-char (point-max)))
4232 (gnus-put-text-property from (point) 'face field-face))))))))
4234 (defun gnus-article-highlight-signature ()
4235 "Highlight the signature in an article.
4236 It does this by highlighting everything after
4237 `gnus-signature-separator' using `gnus-signature-face'."
4240 (set-buffer gnus-article-buffer)
4241 (let ((buffer-read-only nil)
4242 (inhibit-point-motion-hooks t))
4244 (when (and gnus-signature-face
4245 (gnus-article-narrow-to-signature))
4246 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4247 'face gnus-signature-face)
4249 (gnus-article-search-signature)
4250 (let ((start (match-beginning 0))
4251 (end (set-marker (make-marker) (1+ (match-end 0)))))
4252 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4255 (defun gnus-button-in-region-p (b e prop)
4256 "Say whether PROP exists in the region."
4257 (text-property-not-all b e prop nil))
4259 (defun gnus-article-add-buttons (&optional force)
4260 "Find external references in the article and make buttons of them.
4261 \"External references\" are things like Message-IDs and URLs, as
4262 specified by `gnus-button-alist'."
4263 (interactive (list 'force))
4265 (set-buffer gnus-article-buffer)
4266 (let ((buffer-read-only nil)
4267 (inhibit-point-motion-hooks t)
4268 (case-fold-search t)
4269 (alist gnus-button-alist)
4271 ;; Remove all old markers.
4272 (let (marker entry new-list)
4273 (while (setq marker (pop gnus-button-marker-list))
4274 (if (or (< marker (point-min)) (>= marker (point-max)))
4275 (push marker new-list)
4277 (when (setq entry (gnus-button-entry))
4278 (put-text-property (match-beginning (nth 1 entry))
4279 (match-end (nth 1 entry))
4280 'gnus-callback nil))
4281 (set-marker marker nil)))
4282 (setq gnus-button-marker-list new-list))
4283 ;; We skip the headers.
4286 (while (setq entry (pop alist))
4287 (setq regexp (car entry))
4289 (while (re-search-forward regexp nil t)
4290 (let* ((start (and entry (match-beginning (nth 1 entry))))
4291 (end (and entry (match-end (nth 1 entry))))
4292 (from (match-beginning 0)))
4293 (when (and (or (eq t (nth 2 entry))
4294 (eval (nth 2 entry)))
4295 (not (gnus-button-in-region-p
4296 start end 'gnus-callback)))
4297 ;; That optional form returned non-nil, so we add the
4299 (gnus-article-add-button
4300 start end 'gnus-button-push
4301 (car (push (set-marker (make-marker) from)
4302 gnus-button-marker-list))))))))))
4304 ;; Add buttons to the head of an article.
4305 (defun gnus-article-add-buttons-to-head ()
4306 "Add buttons to the head of the article."
4309 (set-buffer gnus-article-buffer)
4311 (let ((buffer-read-only nil)
4312 (inhibit-point-motion-hooks t)
4313 (case-fold-search t)
4314 (alist gnus-header-button-alist)
4316 (article-narrow-to-head)
4318 ;; Each alist entry.
4319 (setq entry (car alist)
4321 (goto-char (point-min))
4322 (while (re-search-forward (car entry) nil t)
4323 ;; Each header matching the entry.
4324 (setq beg (match-beginning 0))
4325 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4326 (match-beginning 0))
4329 (while (re-search-forward (nth 1 entry) end t)
4330 ;; Each match within a header.
4331 (let* ((entry (cdr entry))
4332 (start (match-beginning (nth 1 entry)))
4333 (end (match-end (nth 1 entry)))
4334 (form (nth 2 entry)))
4335 (goto-char (match-end 0))
4337 (gnus-article-add-button
4338 start end (nth 3 entry)
4339 (buffer-substring (match-beginning (nth 4 entry))
4340 (match-end (nth 4 entry)))))))
4341 (goto-char end)))))))
4343 ;;; External functions:
4345 (defun gnus-article-add-button (from to fun &optional data)
4346 "Create a button between FROM and TO with callback FUN and data DATA."
4347 (when gnus-article-button-face
4348 (gnus-overlay-put (gnus-make-overlay from to)
4349 'face gnus-article-button-face))
4350 (gnus-add-text-properties
4352 (nconc (and gnus-article-mouse-face
4353 (list gnus-mouse-face-prop gnus-article-mouse-face))
4354 (list 'gnus-callback fun)
4355 (and data (list 'gnus-data data))))
4356 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4357 :button-keymap gnus-widget-button-keymap))
4359 ;;; Internal functions:
4361 (defun gnus-article-set-globals ()
4363 (set-buffer gnus-summary-buffer)
4364 (gnus-set-global-variables)))
4366 (defun gnus-signature-toggle (end)
4368 (set-buffer gnus-article-buffer)
4369 (let ((buffer-read-only nil)
4370 (inhibit-point-motion-hooks t))
4371 (if (get-text-property end 'invisible)
4372 (gnus-article-unhide-text end (point-max))
4373 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4375 (defun gnus-button-entry ()
4376 ;; Return the first entry in `gnus-button-alist' matching this place.
4377 (let ((alist gnus-button-alist)
4380 (setq entry (pop alist))
4381 (if (looking-at (car entry))
4386 (defun gnus-button-push (marker)
4387 ;; Push button starting at MARKER.
4390 (let* ((entry (gnus-button-entry))
4391 (inhibit-point-motion-hooks t)
4393 (args (mapcar (lambda (group)
4394 (let ((string (match-string group)))
4395 (gnus-set-text-properties
4396 0 (length string) nil string)
4403 (fboundp (symbol-value fun)))
4404 (apply (symbol-value fun) args))
4406 (gnus-message 1 "You must define `%S' to use this button"
4407 (cons fun args)))))))
4409 (defun gnus-button-message-id (message-id)
4412 (set-buffer gnus-summary-buffer)
4413 (gnus-summary-refer-article message-id)))
4415 (defun gnus-button-fetch-group (address)
4416 "Fetch GROUP specified by ADDRESS."
4417 (if (not (string-match "[:/]" address))
4418 ;; This is just a simple group url.
4419 (gnus-group-read-ephemeral-group address gnus-select-method)
4420 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4422 (error "Can't parse %s" address)
4423 (gnus-group-read-ephemeral-group
4424 (match-string 4 address)
4425 `(nntp ,(match-string 1 address)
4426 (nntp-address ,(match-string 1 address))
4427 (nntp-port-number ,(if (match-end 3)
4428 (match-string 3 address)
4431 (defun gnus-url-parse-query-string (query &optional downcase)
4432 (let (retval pairs cur key val)
4433 (setq pairs (split-string query "&"))
4435 (setq cur (car pairs)
4437 (if (not (string-match "=" cur))
4439 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4440 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4442 (setq key (downcase key)))
4443 (setq cur (assoc key retval))
4445 (setcdr cur (cons val (cdr cur)))
4446 (setq retval (cons (list key val) retval)))))
4449 (defun gnus-url-unhex (x)
4456 (defun gnus-url-unhex-string (str &optional allow-newlines)
4457 "Remove %XXX embedded spaces, etc in a url.
4458 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4459 decoding of carriage returns and line feeds in the string, which is normally
4460 forbidden in URL encoding."
4461 (setq str (or str ""))
4463 (case-fold-search t))
4464 (while (string-match "%[0-9a-f][0-9a-f]" str)
4465 (let* ((start (match-beginning 0))
4466 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4468 (gnus-url-unhex (elt str (+ start 2))))))
4470 tmp (substring str 0 start)
4473 (char-to-string code))
4474 ((or (= code ?\n) (= code ?\r))
4476 (t (char-to-string code))))
4477 str (substring str (match-end 0)))))
4478 (setq tmp (concat tmp str))
4481 (defun gnus-url-mailto (url)
4482 ;; Send mail to someone
4483 (when (string-match "mailto:/*\\(.*\\)" url)
4484 (setq url (substring url (match-beginning 1) nil)))
4485 (let (to args subject func)
4486 (if (string-match (regexp-quote "?") url)
4487 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4488 args (gnus-url-parse-query-string
4489 (substring url (match-end 0) nil) t))
4490 (setq to (gnus-url-unhex-string url)))
4491 (setq args (cons (list "to" to) args)
4492 subject (cdr-safe (assoc "subject" args)))
4495 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4498 (message-position-on-field (caar args)))
4499 (insert (mapconcat 'identity (cdar args) ", "))
4500 (setq args (cdr args)))
4503 (message-goto-subject))))
4505 (defun gnus-button-mailto (address)
4507 (set-buffer (gnus-copy-article-buffer))
4508 (message-reply address))
4510 (defun gnus-button-reply (address)
4511 ;; Reply to ADDRESS.
4512 (message-reply address))
4514 (defun gnus-button-embedded-url (address)
4516 (browse-url (gnus-strip-whitespace address)))
4518 ;;; Next/prev buttons in the article buffer.
4520 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4521 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4523 (defvar gnus-prev-page-map nil)
4524 (unless gnus-prev-page-map
4525 (setq gnus-prev-page-map (make-sparse-keymap))
4526 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4527 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4529 (defun gnus-insert-prev-page-button ()
4530 (let ((buffer-read-only nil))
4532 gnus-prev-page-line-format nil
4533 `(gnus-prev t local-map ,gnus-prev-page-map
4534 gnus-callback gnus-article-button-prev-page
4535 article-type annotation))))
4537 (defvar gnus-next-page-map nil)
4538 (unless gnus-next-page-map
4539 (setq gnus-next-page-map (make-keymap))
4540 (suppress-keymap gnus-prev-page-map)
4541 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4542 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4544 (defun gnus-button-next-page ()
4545 "Go to the next page."
4547 (let ((win (selected-window)))
4548 (select-window (get-buffer-window gnus-article-buffer t))
4549 (gnus-article-next-page)
4550 (select-window win)))
4552 (defun gnus-button-prev-page ()
4553 "Go to the prev page."
4555 (let ((win (selected-window)))
4556 (select-window (get-buffer-window gnus-article-buffer t))
4557 (gnus-article-prev-page)
4558 (select-window win)))
4560 (defun gnus-insert-next-page-button ()
4561 (let ((buffer-read-only nil))
4562 (gnus-eval-format gnus-next-page-line-format nil
4564 t local-map ,gnus-next-page-map
4565 gnus-callback gnus-article-button-next-page
4566 article-type annotation))))
4568 (defun gnus-article-button-next-page (arg)
4569 "Go to the next page."
4571 (let ((win (selected-window)))
4572 (select-window (get-buffer-window gnus-article-buffer t))
4573 (gnus-article-next-page)
4574 (select-window win)))
4576 (defun gnus-article-button-prev-page (arg)
4577 "Go to the prev page."
4579 (let ((win (selected-window)))
4580 (select-window (get-buffer-window gnus-article-buffer t))
4581 (gnus-article-prev-page)
4582 (select-window win)))
4584 (defvar gnus-decode-header-methods
4585 '(mail-decode-encoded-word-region)
4586 "List of methods used to decode headers.
4588 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4589 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4590 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4591 whose names match REGEXP.
4594 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4595 mail-decode-encoded-word-region
4596 (\"chinese\" . rfc1843-decode-region))
4599 (defvar gnus-decode-header-methods-cache nil)
4601 (defun gnus-multi-decode-header (start end)
4602 "Apply the functions from `gnus-encoded-word-methods' that match."
4603 (unless (and gnus-decode-header-methods-cache
4604 (eq gnus-newsgroup-name
4605 (car gnus-decode-header-methods-cache)))
4606 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4609 (nconc gnus-decode-header-methods-cache (list x))
4610 (if (and gnus-newsgroup-name
4611 (string-match (car x) gnus-newsgroup-name))
4612 (nconc gnus-decode-header-methods-cache
4614 gnus-decode-header-methods))
4615 (let ((xlist gnus-decode-header-methods-cache))
4618 (narrow-to-region start end)
4620 (funcall (pop xlist) (point-min) (point-max))))))
4623 ;;; Treatment top-level handling.
4626 (defun gnus-treat-article (condition &optional part-number total-parts type)
4627 (let ((length (- (point-max) (point-min)))
4628 (alist gnus-treatment-function-alist)
4629 (article-goto-body-goes-to-point-min-p t)
4633 (let ((list gnus-article-treat-types))
4635 (when (string-match (pop list) type)
4636 (throw 'found t)))))))
4637 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4639 (gnus-run-hooks 'gnus-part-display-hook)
4640 (while (setq elem (pop alist))
4643 (if (gnus-buffer-live-p gnus-summary-buffer)
4644 (set-buffer gnus-summary-buffer))
4645 (symbol-value (car elem))))
4646 (when (and (or (consp val)
4648 (gnus-treat-predicate val)
4649 (or (not (get (car elem) 'highlight))
4652 (funcall (cadr elem)))))))
4654 ;; Dynamic variables.
4655 (defvar part-number)
4656 (defvar total-parts)
4660 (defun gnus-treat-predicate (val)
4665 (stringp (car val)))
4666 (apply 'gnus-or (mapcar `(lambda (s)
4667 (string-match s ,(or gnus-newsgroup-name "")))
4670 (let ((pred (pop val)))
4673 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4675 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4677 (not (gnus-treat-predicate (car val))))
4679 (equal (car val) type))
4681 (error "%S is not a valid predicate" pred)))))
4689 (eq part-number total-parts))
4693 (error "%S is not a valid value" val))))
4699 (run-hooks 'gnus-art-load-hook)
4701 ;;; gnus-art.el ends here