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 ;; Fixme: This isn't the right thing for mixed graphical and and
202 ;; non-graphical frames in a session.
203 ;; gnus-xmas.el overrides this for XEmacs.
204 (defcustom gnus-article-x-face-command
205 (if (and (fboundp 'image-type-available-p)
206 (image-type-available-p 'xbm))
207 'gnus-article-display-xface
208 (if gnus-article-compface-xbm
209 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
210 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
212 "*String or function to be executed to display an X-Face header.
213 If it is a string, the command will be executed in a sub-shell
214 asynchronously. The compressed face will be piped to this command."
215 :type '(choice string
216 (function-item gnus-article-display-xface)
218 :group 'gnus-article-washing)
220 (defcustom gnus-article-x-face-too-ugly nil
221 "Regexp matching posters whose face shouldn't be shown automatically."
222 :type '(choice regexp (const nil))
223 :group 'gnus-article-washing)
225 (defcustom gnus-article-banner-alist nil
226 "Banner alist for stripping.
228 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
229 :type '(repeat (cons symbol regexp))
230 :group 'gnus-article-washing)
232 (defcustom gnus-emphasis-alist
234 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
236 '(("_" "_" underline)
239 ("_/" "/_" underline-italic)
240 ("_\\*" "\\*_" underline-bold)
241 ("\\*/" "/\\*" bold-italic)
242 ("_\\*/" "/\\*_" underline-bold-italic))))
243 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
244 2 3 gnus-emphasis-underline)
248 (format format (car spec) (cadr spec))
249 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
251 "*Alist that says how to fontify certain phrases.
252 Each item looks like this:
254 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
256 The first element is a regular expression to be matched. The second
257 is a number that says what regular expression grouping used to find
258 the entire emphasized word. The third is a number that says what
259 regexp grouping should be displayed and highlighted. The fourth
260 is the face used for highlighting."
261 :type '(repeat (list :value ("" 0 0 default)
263 (integer :tag "Match group")
264 (integer :tag "Emphasize group")
266 :group 'gnus-article-emphasis)
268 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
269 "A regexp to describe whitespace which should not be emphasized.
270 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
271 The former avoids underlining of leading and trailing whitespace,
272 and the latter avoids underlining any whitespace at all."
273 :group 'gnus-article-emphasis
276 (defface gnus-emphasis-bold '((t (:bold t)))
277 "Face used for displaying strong emphasized text (*word*)."
278 :group 'gnus-article-emphasis)
280 (defface gnus-emphasis-italic '((t (:italic t)))
281 "Face used for displaying italic emphasized text (/word/)."
282 :group 'gnus-article-emphasis)
284 (defface gnus-emphasis-underline '((t (:underline t)))
285 "Face used for displaying underlined emphasized text (_word_)."
286 :group 'gnus-article-emphasis)
288 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
289 "Face used for displaying underlined bold emphasized text (_*word*_)."
290 :group 'gnus-article-emphasis)
292 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
293 "Face used for displaying underlined italic emphasized text (_/word/_)."
294 :group 'gnus-article-emphasis)
296 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
297 "Face used for displaying bold italic emphasized text (/*word*/)."
298 :group 'gnus-article-emphasis)
300 (defface gnus-emphasis-underline-bold-italic
301 '((t (:bold t :italic t :underline t)))
302 "Face used for displaying underlined bold italic emphasized text.
303 Esample: (_/*word*/_)."
304 :group 'gnus-article-emphasis)
306 (defface gnus-emphasis-highlight-words
307 '((t (:background "black" :foreground "yellow")))
308 "Face used for displaying highlighted words."
309 :group 'gnus-article-emphasis)
311 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
312 "Format for display of Date headers in article bodies.
313 See `format-time-string' for the possible values.
315 The variable can also be function, which should return a complete Date
316 header. The function is called with one argument, the time, which can
317 be fed to `format-time-string'."
318 :type '(choice string symbol)
319 :link '(custom-manual "(gnus)Article Date")
320 :group 'gnus-article-washing)
323 (autoload 'mail-extract-address-components "mail-extr"))
325 (defcustom gnus-save-all-headers t
326 "*If non-nil, don't remove any headers before saving."
327 :group 'gnus-article-saving
330 (defcustom gnus-prompt-before-saving 'always
331 "*This variable says how much prompting is to be done when saving articles.
332 If it is nil, no prompting will be done, and the articles will be
333 saved to the default files. If this variable is `always', each and
334 every article that is saved will be preceded by a prompt, even when
335 saving large batches of articles. If this variable is neither nil not
336 `always', there the user will be prompted once for a file name for
337 each invocation of the saving commands."
338 :group 'gnus-article-saving
339 :type '(choice (item always)
340 (item :tag "never" nil)
341 (sexp :tag "once" :format "%t\n" :value t)))
343 (defcustom gnus-saved-headers gnus-visible-headers
344 "Headers to keep if `gnus-save-all-headers' is nil.
345 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
346 If that variable is nil, however, all headers that match this regexp
347 will be kept while the rest will be deleted before saving."
348 :group 'gnus-article-saving
351 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
352 "A function to save articles in your favourite format.
353 The function must be interactively callable (in other words, it must
354 be an Emacs command).
356 Gnus provides the following functions:
358 * gnus-summary-save-in-rmail (Rmail format)
359 * gnus-summary-save-in-mail (Unix mail format)
360 * gnus-summary-save-in-folder (MH folder)
361 * gnus-summary-save-in-file (article format)
362 * gnus-summary-save-in-vm (use VM's folder format)
363 * gnus-summary-write-to-file (article format -- overwrite)."
364 :group 'gnus-article-saving
365 :type '(radio (function-item gnus-summary-save-in-rmail)
366 (function-item gnus-summary-save-in-mail)
367 (function-item gnus-summary-save-in-folder)
368 (function-item gnus-summary-save-in-file)
369 (function-item gnus-summary-save-in-vm)
370 (function-item gnus-summary-write-to-file)))
372 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
373 "A function generating a file name to save articles in Rmail format.
374 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
375 :group 'gnus-article-saving
378 (defcustom gnus-mail-save-name 'gnus-plain-save-name
379 "A function generating a file name to save articles in Unix mail format.
380 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
381 :group 'gnus-article-saving
384 (defcustom gnus-folder-save-name 'gnus-folder-save-name
385 "A function generating a file name to save articles in MH folder.
386 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
387 :group 'gnus-article-saving
390 (defcustom gnus-file-save-name 'gnus-numeric-save-name
391 "A function generating a file name to save articles in article format.
392 The function is called with NEWSGROUP, HEADERS, and optional
394 :group 'gnus-article-saving
397 (defcustom gnus-split-methods
398 '((gnus-article-archive-name)
399 (gnus-article-nndoc-name))
400 "*Variable used to suggest where articles are to be saved.
401 For instance, if you would like to save articles related to Gnus in
402 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
403 you could set this variable to something like:
405 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
406 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
408 This variable is an alist where the where the key is the match and the
409 value is a list of possible files to save in if the match is non-nil.
411 If the match is a string, it is used as a regexp match on the
412 article. If the match is a symbol, that symbol will be funcalled
413 from the buffer of the article to be saved with the newsgroup as the
414 parameter. If it is a list, it will be evaled in the same buffer.
416 If this form or function returns a string, this string will be used as
417 a possible file name; and if it returns a non-nil list, that list will
418 be used as possible file names."
419 :group 'gnus-article-saving
420 :type '(repeat (choice (list :value (fun) function)
421 (cons :value ("" "") regexp (repeat string))
424 (defcustom gnus-page-delimiter "^\^L"
425 "*Regexp describing what to use as article page delimiters.
426 The default value is \"^\^L\", which is a form linefeed at the
427 beginning of a line."
429 :group 'gnus-article-various)
431 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
432 "*The format specification for the article mode line.
433 See `gnus-summary-mode-line-format' for a closer description.
435 The following additional specs are available:
437 %w The article washing status.
438 %m The number of MIME parts in the article."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-mode-hook nil
443 "*A hook for Gnus article mode."
445 :group 'gnus-article-various)
447 (defcustom gnus-article-menu-hook nil
448 "*Hook run after the creation of the article mode menu."
450 :group 'gnus-article-various)
452 (defcustom gnus-article-prepare-hook nil
453 "*A hook called after an article has been prepared in the article buffer."
455 :group 'gnus-article-various)
457 (defcustom gnus-article-hide-pgp-hook nil
458 "*A hook called after successfully hiding a PGP signature."
460 :group 'gnus-article-various)
462 (defcustom gnus-article-button-face 'bold
463 "Face used for highlighting buttons in the article buffer.
465 An article button is a piece of text that you can activate by pressing
466 `RET' or `mouse-2' above it."
468 :group 'gnus-article-buttons)
470 (defcustom gnus-article-mouse-face 'highlight
471 "Face used for mouse highlighting in the article buffer.
473 Article buttons will be displayed in this face when the cursor is
476 :group 'gnus-article-buttons)
478 (defcustom gnus-signature-face 'gnus-signature-face
479 "Face used for highlighting a signature in the article buffer.
480 Obsolete; use the face `gnus-signature-face' for customizations instead."
482 :group 'gnus-article-highlight
483 :group 'gnus-article-signature)
485 (defface gnus-signature-face
488 "Face used for highlighting a signature in the article buffer."
489 :group 'gnus-article-highlight
490 :group 'gnus-article-signature)
492 (defface gnus-header-from-face
495 (:foreground "spring green"))
498 (:foreground "red3"))
501 "Face used for displaying from headers."
502 :group 'gnus-article-headers
503 :group 'gnus-article-highlight)
505 (defface gnus-header-subject-face
508 (:foreground "SeaGreen3"))
511 (:foreground "red4"))
513 (:bold t :italic t)))
514 "Face used for displaying subject headers."
515 :group 'gnus-article-headers
516 :group 'gnus-article-highlight)
518 (defface gnus-header-newsgroups-face
521 (:foreground "yellow" :italic t))
524 (:foreground "MidnightBlue" :italic t))
527 "Face used for displaying newsgroups headers."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defface gnus-header-name-face
534 (:foreground "SeaGreen"))
537 (:foreground "maroon"))
540 "Face used for displaying header names."
541 :group 'gnus-article-headers
542 :group 'gnus-article-highlight)
544 (defface gnus-header-content-face
547 (:foreground "forest green" :italic t))
550 (:foreground "indianred4" :italic t))
552 (:italic t))) "Face used for displaying header content."
553 :group 'gnus-article-headers
554 :group 'gnus-article-highlight)
556 (defcustom gnus-header-face-alist
557 '(("From" nil gnus-header-from-face)
558 ("Subject" nil gnus-header-subject-face)
559 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
560 ("" gnus-header-name-face gnus-header-content-face))
561 "*Controls highlighting of article header.
563 An alist of the form (HEADER NAME CONTENT).
565 HEADER is a regular expression which should match the name of an
566 header header and NAME and CONTENT are either face names or nil.
568 The name of each header field will be displayed using the face
569 specified by the first element in the list where HEADER match the
570 header name and NAME is non-nil. Similarly, the content will be
571 displayed by the first non-nil matching CONTENT face."
572 :group 'gnus-article-headers
573 :group 'gnus-article-highlight
574 :type '(repeat (list (regexp :tag "Header")
576 (item :tag "skip" nil)
577 (face :value default))
578 (choice :tag "Content"
579 (item :tag "skip" nil)
580 (face :value default)))))
582 (defcustom gnus-article-decode-hook
583 '(article-decode-charset article-decode-encoded-words)
584 "*Hook run to decode charsets in articles."
585 :group 'gnus-article-headers
588 (defcustom gnus-display-mime-function 'gnus-display-mime
589 "Function to display MIME articles."
590 :group 'gnus-article-mime
593 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
594 "Function used to decode headers.")
596 (defvar gnus-article-dumbquotes-map
615 "Table for MS-to-Latin1 translation.")
617 (defcustom gnus-ignored-mime-types nil
618 "List of MIME types that should be ignored by Gnus."
619 :group 'gnus-article-mime
620 :type '(repeat regexp))
622 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
623 "List of MIME types that should not be given buttons when rendered inline."
624 :group 'gnus-article-mime
625 :type '(repeat regexp))
627 (defcustom gnus-article-mime-part-function nil
628 "Function called with a MIME handle as the argument.
629 This is meant for people who want to do something automatic based
630 on parts -- for instance, adding Vcard info to a database."
631 :group 'gnus-article-mime
634 (defcustom gnus-mime-multipart-functions nil
635 "An alist of MIME types to functions to display them."
636 :group 'gnus-article-mime
639 (defcustom gnus-article-date-lapsed-new-header nil
640 "Whether the X-Sent and Date headers can coexist.
641 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
642 either replace the old \"Date:\" header (if this variable is nil), or
643 be added below it (otherwise)."
644 :group 'gnus-article-headers
647 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
648 "Function called with a MIME handle as the argument.
649 This is meant for people who want to view first matched part.
650 For `undisplayed-alternative' (default), the first undisplayed
651 part or alternative part is used. For `undisplayed', the first
652 undisplayed part is used. For a function, the first part which
653 the function return `t' is used. For `nil', the first part is
655 :group 'gnus-article-mime
657 (item :tag "first" :value nil)
658 (item :tag "undisplayed" :value undisplayed)
659 (item :tag "undisplayed or alternative"
660 :value undisplayed-alternative)
663 (defcustom gnus-mime-action-alist
664 '(("save to file" . gnus-mime-save-part)
665 ("display as text" . gnus-mime-inline-part)
666 ("view the part" . gnus-mime-view-part)
667 ("pipe to command" . gnus-mime-pipe-part)
668 ("toggle display" . gnus-article-press-button)
669 ("view as type" . gnus-mime-view-part-as-type)
670 ("internalize type" . gnus-mime-internalize-part)
671 ("externalize type" . gnus-mime-externalize-part))
672 "An alist of actions that run on the MIME attachment."
673 :group 'gnus-article-mime
674 :type '(repeat (cons (string :tag "name")
678 ;;; The treatment variables
681 (defvar gnus-part-display-hook nil
682 "Hook called on parts that are to receive treatment.")
684 (defvar gnus-article-treat-custom
685 '(choice (const :tag "Off" nil)
687 (const :tag "Header" head)
688 (const :tag "Last" last)
689 (integer :tag "Less")
690 (repeat :tag "Groups" regexp)
691 (sexp :tag "Predicate")))
693 (defvar gnus-article-treat-head-custom
694 '(choice (const :tag "Off" nil)
695 (const :tag "Header" head)))
697 (defvar gnus-article-treat-types '("text/plain")
700 (defvar gnus-inhibit-treatment nil
701 "Whether to inhibit treatment.")
703 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
704 "Highlight the signature.
705 Valid values are nil, t, `head', `last', an integer or a predicate.
706 See the manual for details."
707 :group 'gnus-article-treat
708 :type gnus-article-treat-custom)
709 (put 'gnus-treat-highlight-signature 'highlight t)
711 (defcustom gnus-treat-buttonize 100000
713 Valid values are nil, t, `head', `last', an integer or a predicate.
714 See the manual for details."
715 :group 'gnus-article-treat
716 :type gnus-article-treat-custom)
717 (put 'gnus-treat-buttonize 'highlight t)
719 (defcustom gnus-treat-buttonize-head 'head
720 "Add buttons to the head.
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)
725 (put 'gnus-treat-buttonize-head 'highlight t)
727 (defcustom gnus-treat-emphasize
728 (and (or window-system
730 (>= (string-to-number emacs-version) 21))
733 Valid values are nil, t, `head', `last', an integer or a predicate.
734 See the manual for details."
735 :group 'gnus-article-treat
736 :type gnus-article-treat-custom)
737 (put 'gnus-treat-emphasize 'highlight t)
739 (defcustom gnus-treat-strip-cr nil
740 "Remove carriage returns.
741 Valid values are nil, t, `head', `last', an integer or a predicate.
742 See the manual for details."
743 :group 'gnus-article-treat
744 :type gnus-article-treat-custom)
746 (defcustom gnus-treat-hide-headers 'head
748 Valid values are nil, t, `head', `last', an integer or a predicate.
749 See the manual for details."
750 :group 'gnus-article-treat
751 :type gnus-article-treat-head-custom)
753 (defcustom gnus-treat-hide-boring-headers nil
754 "Hide boring headers.
755 Valid values are nil, t, `head', `last', an integer or a predicate.
756 See the manual for details."
757 :group 'gnus-article-treat
758 :type gnus-article-treat-head-custom)
760 (defcustom gnus-treat-hide-signature nil
762 Valid values are nil, t, `head', `last', an integer or a predicate.
763 See the manual for details."
764 :group 'gnus-article-treat
765 :type gnus-article-treat-custom)
767 (defcustom gnus-treat-fill-article nil
769 Valid values are nil, t, `head', `last', an integer or a predicate.
770 See the manual for details."
771 :group 'gnus-article-treat
772 :type gnus-article-treat-custom)
774 (defcustom gnus-treat-hide-citation nil
776 Valid values are nil, t, `head', `last', an integer or a predicate.
777 See the manual for details."
778 :group 'gnus-article-treat
779 :type gnus-article-treat-custom)
781 (defcustom gnus-treat-hide-citation-maybe nil
783 Valid values are nil, t, `head', `last', an integer or a predicate.
784 See the manual for details."
785 :group 'gnus-article-treat
786 :type gnus-article-treat-custom)
788 (defcustom gnus-treat-strip-list-identifiers 'head
789 "Strip list identifiers from `gnus-list-identifiers`.
790 Valid values are nil, t, `head', `last', an integer or a predicate.
791 See the manual for details."
792 :group 'gnus-article-treat
793 :type gnus-article-treat-custom)
795 (defcustom gnus-treat-strip-pgp t
796 "Strip PGP signatures.
797 Valid values are nil, t, `head', `last', an integer or a predicate.
798 See the manual for details."
799 :group 'gnus-article-treat
800 :type gnus-article-treat-custom)
802 (defcustom gnus-treat-strip-pem nil
803 "Strip PEM signatures.
804 Valid values are nil, t, `head', `last', an integer or a predicate.
805 See the manual for details."
806 :group 'gnus-article-treat
807 :type gnus-article-treat-custom)
809 (defcustom gnus-treat-strip-banner t
810 "Strip banners from articles.
811 The banner to be stripped is specified in the `banner' group parameter.
812 Valid values are nil, t, `head', `last', an integer or a predicate.
813 See the manual for details."
814 :group 'gnus-article-treat
815 :type gnus-article-treat-custom)
817 (defcustom gnus-treat-highlight-headers 'head
818 "Highlight the headers.
819 Valid values are nil, t, `head', `last', an integer or a predicate.
820 See the manual for details."
821 :group 'gnus-article-treat
822 :type gnus-article-treat-head-custom)
823 (put 'gnus-treat-highlight-headers 'highlight t)
825 (defcustom gnus-treat-highlight-citation t
826 "Highlight cited text.
827 Valid values are nil, t, `head', `last', an integer or a predicate.
828 See the manual for details."
829 :group 'gnus-article-treat
830 :type gnus-article-treat-custom)
831 (put 'gnus-treat-highlight-citation 'highlight t)
833 (defcustom gnus-treat-date-ut nil
834 "Display the Date in UT (GMT).
835 Valid values are nil, t, `head', `last', an integer or a predicate.
836 See the manual for details."
837 :group 'gnus-article-treat
838 :type gnus-article-treat-head-custom)
840 (defcustom gnus-treat-date-local nil
841 "Display the Date in the local timezone.
842 Valid values are nil, t, `head', `last', an integer or a predicate.
843 See the manual for details."
844 :group 'gnus-article-treat
845 :type gnus-article-treat-head-custom)
847 (defcustom gnus-treat-date-lapsed nil
848 "Display the Date header in a way that says how much time has elapsed.
849 Valid values are nil, t, `head', `last', an integer or a predicate.
850 See the manual for details."
851 :group 'gnus-article-treat
852 :type gnus-article-treat-head-custom)
854 (defcustom gnus-treat-date-original nil
855 "Display the date in the original timezone.
856 Valid values are nil, t, `head', `last', an integer or a predicate.
857 See the manual for details."
858 :group 'gnus-article-treat
859 :type gnus-article-treat-head-custom)
861 (defcustom gnus-treat-date-iso8601 nil
862 "Display the date in the ISO8601 format.
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See the manual for details."
865 :group 'gnus-article-treat
866 :type gnus-article-treat-head-custom)
868 (defcustom gnus-treat-date-user-defined nil
869 "Display the date in a user-defined format.
870 The format is defined by the `gnus-article-time-format' variable.
871 Valid values are nil, t, `head', `last', an integer or a predicate.
872 See the manual for details."
873 :group 'gnus-article-treat
874 :type gnus-article-treat-head-custom)
876 (defcustom gnus-treat-strip-headers-in-body t
877 "Strip the X-No-Archive header line from the beginning of the body.
878 Valid values are nil, t, `head', `last', an integer or a predicate.
879 See the manual for details."
880 :group 'gnus-article-treat
881 :type gnus-article-treat-custom)
883 (defcustom gnus-treat-strip-trailing-blank-lines nil
884 "Strip trailing blank lines.
885 Valid values are nil, t, `head', `last', an integer or a predicate.
886 See the manual for details."
887 :group 'gnus-article-treat
888 :type gnus-article-treat-custom)
890 (defcustom gnus-treat-strip-leading-blank-lines nil
891 "Strip leading blank lines.
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-custom)
897 (defcustom gnus-treat-strip-multiple-blank-lines nil
898 "Strip multiple blank lines.
899 Valid values are nil, t, `head', `last', an integer or a predicate.
900 See the manual for details."
901 :group 'gnus-article-treat
902 :type gnus-article-treat-custom)
904 (defcustom gnus-treat-overstrike t
905 "Treat overstrike highlighting.
906 Valid values are nil, t, `head', `last', an integer or a predicate.
907 See the manual for details."
908 :group 'gnus-article-treat
909 :type gnus-article-treat-custom)
910 (put 'gnus-treat-overstrike 'highlight t)
912 (defcustom gnus-treat-display-xface
913 (and (or (and (fboundp 'image-type-available-p)
914 (image-type-available-p 'xbm)
915 (string-match "^0x" (shell-command-to-string "uncompface")))
916 (and (featurep 'xemacs) (featurep 'xface)))
918 "Display X-Face headers.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-head-custom)
923 (put 'gnus-treat-display-xface 'highlight t)
925 (defcustom gnus-treat-display-smileys
926 (if (or (and (featurep 'xemacs)
928 (and (fboundp 'image-type-available-p)
929 (image-type-available-p 'pbm)))
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934 :group 'gnus-article-treat
935 :type gnus-article-treat-custom)
936 (put 'gnus-treat-display-smileys 'highlight t)
938 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
940 Valid values are nil, t, `head', `last', an integer or a predicate.
941 See the manual for details."
942 :group 'gnus-article-treat
943 :type gnus-article-treat-head-custom)
944 (put 'gnus-treat-display-picons 'highlight t)
946 (defcustom gnus-treat-capitalize-sentences nil
947 "Capitalize sentence-starting words.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-custom)
953 (defcustom gnus-treat-fill-long-lines nil
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See the manual for details."
957 :group 'gnus-article-treat
958 :type gnus-article-treat-custom)
960 (defcustom gnus-treat-play-sounds nil
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
967 (defcustom gnus-treat-translate nil
968 "Translate articles from one language to another.
969 Valid values are nil, t, `head', `last', an integer or a predicate.
970 See the manual for details."
971 :group 'gnus-article-treat
972 :type gnus-article-treat-custom)
974 ;;; Internal variables
976 (defvar article-goto-body-goes-to-point-min-p nil)
977 (defvar gnus-article-wash-types nil)
978 (defvar gnus-article-emphasis-alist nil)
980 (defvar gnus-article-mime-handle-alist-1 nil)
981 (defvar gnus-treatment-function-alist
982 '((gnus-treat-strip-banner gnus-article-strip-banner)
983 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
984 (gnus-treat-highlight-signature gnus-article-highlight-signature)
985 (gnus-treat-buttonize gnus-article-add-buttons)
986 (gnus-treat-fill-article gnus-article-fill-cited-article)
987 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
988 (gnus-treat-strip-cr gnus-article-remove-cr)
989 (gnus-treat-emphasize gnus-article-emphasize)
990 (gnus-treat-display-xface gnus-article-display-x-face)
991 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
992 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
993 (gnus-treat-hide-signature gnus-article-hide-signature)
994 (gnus-treat-hide-citation gnus-article-hide-citation)
995 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
996 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
997 (gnus-treat-strip-pgp gnus-article-hide-pgp)
998 (gnus-treat-strip-pem gnus-article-hide-pem)
999 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1000 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1001 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1002 (gnus-treat-date-ut gnus-article-date-ut)
1003 (gnus-treat-date-local gnus-article-date-local)
1004 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1005 (gnus-treat-date-original gnus-article-date-original)
1006 (gnus-treat-date-user-defined gnus-article-date-user)
1007 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1008 (gnus-treat-strip-trailing-blank-lines
1009 gnus-article-remove-trailing-blank-lines)
1010 (gnus-treat-strip-leading-blank-lines
1011 gnus-article-strip-leading-blank-lines)
1012 (gnus-treat-strip-multiple-blank-lines
1013 gnus-article-strip-multiple-blank-lines)
1014 (gnus-treat-overstrike gnus-article-treat-overstrike)
1015 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1016 (gnus-treat-display-smileys gnus-smiley-display)
1017 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1018 (gnus-treat-display-picons gnus-article-display-picons)
1019 (gnus-treat-play-sounds gnus-earcon-display)))
1021 (defvar gnus-article-mime-handle-alist nil)
1022 (defvar article-lapsed-timer nil)
1023 (defvar gnus-article-current-summary nil)
1025 (defvar gnus-article-mode-syntax-table
1026 (let ((table (copy-syntax-table text-mode-syntax-table)))
1027 (modify-syntax-entry ?- "w" table)
1028 (modify-syntax-entry ?> ")" table)
1029 (modify-syntax-entry ?< "(" table)
1031 "Syntax table used in article mode buffers.
1032 Initialized from `text-mode-syntax-table.")
1034 (defvar gnus-save-article-buffer nil)
1036 (defvar gnus-article-mode-line-format-alist
1037 (nconc '((?w (gnus-article-wash-status) ?s)
1038 (?m (gnus-article-mime-part-status) ?s))
1039 gnus-summary-mode-line-format-alist))
1041 (defvar gnus-number-of-articles-to-be-saved nil)
1043 (defvar gnus-inhibit-hiding nil)
1045 (defsubst gnus-article-hide-text (b e props)
1046 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1047 (gnus-add-text-properties-when 'article-type nil b e props)
1048 (when (memq 'intangible props)
1050 (max (1- b) (point-min))
1051 b 'intangible (cddr (memq 'intangible props)))))
1053 (defsubst gnus-article-unhide-text (b e)
1054 "Remove hidden text properties from region between B and E."
1055 (remove-text-properties b e gnus-hidden-properties)
1056 (when (memq 'intangible gnus-hidden-properties)
1057 (put-text-property (max (1- b) (point-min))
1058 b 'intangible nil)))
1060 (defun gnus-article-hide-text-type (b e type)
1061 "Hide text of TYPE between B and E."
1062 (push type gnus-article-wash-types)
1063 (gnus-article-hide-text
1064 b e (cons 'article-type (cons type gnus-hidden-properties))))
1066 (defun gnus-article-unhide-text-type (b e type)
1067 "Unhide text of TYPE between B and E."
1068 (setq gnus-article-wash-types
1069 (delq type gnus-article-wash-types))
1070 (remove-text-properties
1071 b e (cons 'article-type (cons type gnus-hidden-properties)))
1072 (when (memq 'intangible gnus-hidden-properties)
1073 (put-text-property (max (1- b) (point-min))
1074 b 'intangible nil)))
1076 (defun gnus-article-hide-text-of-type (type)
1077 "Hide text of TYPE in the current buffer."
1079 (let ((b (point-min))
1081 (while (setq b (text-property-any b e 'article-type type))
1082 (add-text-properties b (incf b) gnus-hidden-properties)))))
1084 (defun gnus-article-delete-text-of-type (type)
1085 "Delete text of TYPE in the current buffer."
1087 (let ((b (point-min)))
1088 (while (setq b (text-property-any b (point-max) 'article-type type))
1090 b (or (text-property-not-all b (point-max) 'article-type type)
1093 (defun gnus-article-delete-invisible-text ()
1094 "Delete all invisible text in the current buffer."
1096 (let ((b (point-min)))
1097 (while (setq b (text-property-any b (point-max) 'invisible t))
1099 b (or (text-property-not-all b (point-max) 'invisible t)
1102 (defun gnus-article-text-type-exists-p (type)
1103 "Say whether any text of type TYPE exists in the buffer."
1104 (text-property-any (point-min) (point-max) 'article-type type))
1106 (defsubst gnus-article-header-rank ()
1107 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1108 (let ((list gnus-sorted-header-list)
1111 (when (looking-at (car list))
1113 (setq list (cdr list))
1117 (defun article-hide-headers (&optional arg delete)
1118 "Hide unwanted headers and possibly sort them as well."
1120 ;; This function might be inhibited.
1121 (unless gnus-inhibit-hiding
1124 (let ((buffer-read-only nil)
1125 (case-fold-search t)
1126 (max (1+ (length gnus-sorted-header-list)))
1127 (ignored (when (not gnus-visible-headers)
1128 (cond ((stringp gnus-ignored-headers)
1129 gnus-ignored-headers)
1130 ((listp gnus-ignored-headers)
1131 (mapconcat 'identity gnus-ignored-headers
1134 (cond ((stringp gnus-visible-headers)
1135 gnus-visible-headers)
1136 ((and gnus-visible-headers
1137 (listp gnus-visible-headers))
1138 (mapconcat 'identity gnus-visible-headers "\\|"))))
1139 (inhibit-point-motion-hooks t)
1141 ;; First we narrow to just the headers.
1142 (article-narrow-to-head)
1143 ;; Hide any "From " lines at the beginning of (mail) articles.
1144 (while (looking-at "From ")
1147 (delete-region (point-min) (point)))
1148 ;; Then treat the rest of the header lines.
1149 ;; Then we use the two regular expressions
1150 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1151 ;; select which header lines is to remain visible in the
1153 (while (re-search-forward "^[^ \t]*:" nil t)
1155 ;; Mark the rank of the header.
1157 (point) (1+ (point)) 'message-rank
1158 (if (or (and visible (looking-at visible))
1160 (not (looking-at ignored))))
1161 (gnus-article-header-rank)
1164 (message-sort-headers-1)
1165 (when (setq beg (text-property-any
1166 (point-min) (point-max) 'message-rank (+ 2 max)))
1167 ;; We delete the unwanted headers.
1168 (push 'headers gnus-article-wash-types)
1169 (add-text-properties (point-min) (+ 5 (point-min))
1170 '(article-type headers dummy-invisible t))
1171 (delete-region beg (point-max))))))))
1173 (defun article-hide-boring-headers (&optional arg)
1174 "Toggle hiding of headers that aren't very interesting.
1175 If given a negative prefix, always show; if given a positive prefix,
1177 (interactive (gnus-article-hidden-arg))
1178 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1179 (not gnus-show-all-headers))
1182 (let ((buffer-read-only nil)
1183 (list gnus-boring-article-headers)
1184 (inhibit-point-motion-hooks t)
1186 (article-narrow-to-head)
1188 (setq elem (pop list))
1189 (goto-char (point-min))
1191 ;; Hide empty headers.
1193 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1195 (gnus-article-hide-text-type
1196 (progn (beginning-of-line) (point))
1199 (if (re-search-forward "^[^ \t]" nil t)
1203 ;; Hide boring Newsgroups header.
1204 ((eq elem 'newsgroups)
1205 (when (equal (gnus-fetch-field "newsgroups")
1206 (gnus-group-real-name
1207 (if (boundp 'gnus-newsgroup-name)
1210 (gnus-article-hide-header "newsgroups")))
1211 ((eq elem 'followup-to)
1212 (when (equal (message-fetch-field "followup-to")
1213 (message-fetch-field "newsgroups"))
1214 (gnus-article-hide-header "followup-to")))
1215 ((eq elem 'reply-to)
1216 (let ((from (message-fetch-field "from"))
1217 (reply-to (message-fetch-field "reply-to")))
1222 (nth 1 (mail-extract-address-components from))
1223 (nth 1 (mail-extract-address-components reply-to)))))
1224 (gnus-article-hide-header "reply-to"))))
1226 (let ((date (message-fetch-field "date")))
1228 (< (days-between (current-time-string) date)
1230 (gnus-article-hide-header "date"))))
1232 (let ((to (message-fetch-field "to"))
1233 (cc (message-fetch-field "cc")))
1234 (when (> (length to) 1024)
1235 (gnus-article-hide-header "to"))
1236 (when (> (length cc) 1024)
1237 (gnus-article-hide-header "cc"))))
1241 (goto-char (point-min))
1242 (while (re-search-forward "^to:" nil t)
1243 (setq to-count (1+ to-count)))
1244 (when (> to-count 1)
1245 (while (> to-count 0)
1246 (goto-char (point-min))
1248 (re-search-forward "^to:" nil nil to-count)
1250 (narrow-to-region (point) (point-max))
1251 (gnus-article-hide-header "to"))
1252 (setq to-count (1- to-count))))
1253 (goto-char (point-min))
1254 (while (re-search-forward "^cc:" nil t)
1255 (setq cc-count (1+ cc-count)))
1256 (when (> cc-count 1)
1257 (while (> cc-count 0)
1258 (goto-char (point-min))
1260 (re-search-forward "^cc:" nil nil cc-count)
1262 (narrow-to-region (point) (point-max))
1263 (gnus-article-hide-header "cc"))
1264 (setq cc-count (1- cc-count)))))))))))))
1266 (defun gnus-article-hide-header (header)
1268 (goto-char (point-min))
1269 (when (re-search-forward (concat "^" header ":") nil t)
1270 (gnus-article-hide-text-type
1271 (progn (beginning-of-line) (point))
1274 (if (re-search-forward "^[^ \t]" nil t)
1279 (defvar gnus-article-normalized-header-length 40
1280 "Length of normalized headers.")
1282 (defun article-normalize-headers ()
1283 "Make all header lines 40 characters long."
1285 (let ((buffer-read-only nil)
1289 (article-narrow-to-head)
1292 ((< (setq column (- (gnus-point-at-eol) (point)))
1293 gnus-article-normalized-header-length)
1295 (insert (make-string
1296 (- gnus-article-normalized-header-length column)
1298 ((> column gnus-article-normalized-header-length)
1299 (gnus-put-text-property
1301 (forward-char gnus-article-normalized-header-length)
1308 (forward-line 1))))))
1310 (defun article-treat-dumbquotes ()
1311 "Translate M****s*** sm*rtq**t*s into proper text.
1312 Note that this function guesses whether a character is a sm*rtq**t* or
1313 not, so it should only be used interactively.
1315 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1316 in an attempt to provide more quoting characters. If you see
1317 something like \\222 or \\264 where you're expecting some kind of
1318 apostrophe or quotation mark, then try this wash."
1320 (article-translate-strings gnus-article-dumbquotes-map))
1322 (defun article-translate-characters (from to)
1323 "Translate all characters in the body of the article according to FROM and TO.
1324 FROM is a string of characters to translate from; to is a string of
1325 characters to translate to."
1327 (when (article-goto-body)
1328 (let ((buffer-read-only nil)
1329 (x (make-string 225 ?x))
1331 (while (< (incf i) (length x))
1334 (while (< i (length from))
1335 (aset x (aref from i) (aref to i))
1337 (translate-region (point) (point-max) x)))))
1339 (defun article-translate-strings (map)
1340 "Translate all string in the body of the article according to MAP.
1341 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1343 (when (article-goto-body)
1344 (let ((buffer-read-only nil)
1346 (while (setq elem (pop map))
1348 (while (search-forward (car elem) nil t)
1349 (replace-match (cadr elem)))))))))
1351 (defun article-treat-overstrike ()
1352 "Translate overstrikes into bold text."
1355 (when (article-goto-body)
1356 (let ((buffer-read-only nil))
1357 (while (search-forward "\b" nil t)
1358 (let ((next (char-after))
1359 (previous (char-after (- (point) 2))))
1360 ;; We do the boldification/underlining by hiding the
1361 ;; overstrikes and putting the proper text property
1365 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1366 (put-text-property (point) (1+ (point)) 'face 'bold))
1368 (gnus-article-hide-text-type
1369 (1- (point)) (1+ (point)) 'overstrike)
1371 (- (point) 2) (1- (point)) 'face 'underline))
1373 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1375 (point) (1+ (point)) 'face 'underline)))))))))
1377 (defun article-fill-long-lines ()
1378 "Fill lines that are wider than the window width."
1381 (let ((buffer-read-only nil)
1382 (width (window-width (get-buffer-window (current-buffer)))))
1385 (let ((adaptive-fill-mode nil))
1388 (when (>= (current-column) (min fill-column width))
1389 (narrow-to-region (point) (gnus-point-at-bol))
1390 (fill-paragraph nil)
1391 (goto-char (point-max))
1393 (forward-line 1)))))))
1395 (defun article-capitalize-sentences ()
1396 "Capitalize the first word in each sentence."
1399 (let ((buffer-read-only nil)
1400 (paragraph-start "^[\n\^L]"))
1404 (forward-sentence)))))
1406 (defun article-remove-cr ()
1407 "Remove trailing CRs and then translate remaining CRs into LFs."
1410 (let ((buffer-read-only nil))
1411 (goto-char (point-min))
1412 (while (re-search-forward "\r+$" nil t)
1413 (replace-match "" t t))
1414 (goto-char (point-min))
1415 (while (search-forward "\r" nil t)
1416 (replace-match "\n" t t)))))
1418 (defun article-remove-trailing-blank-lines ()
1419 "Remove all trailing blank lines from the article."
1422 (let ((buffer-read-only nil))
1423 (goto-char (point-max))
1427 (while (and (not (bobp))
1428 (looking-at "^[ \t]*$")
1429 (not (gnus-annotation-in-region-p
1430 (point) (gnus-point-at-eol))))
1435 (defun article-display-x-face (&optional force)
1436 "Look for an X-Face header and display it if present."
1437 (interactive (list 'force))
1439 ;; Delete the old process, if any.
1440 (when (process-status "article-x-face")
1441 (delete-process "article-x-face"))
1442 (let ((inhibit-point-motion-hooks t)
1443 (case-fold-search t)
1446 (article-narrow-to-head)
1447 (goto-char (point-min))
1448 (setq from (message-fetch-field "from"))
1449 (goto-char (point-min))
1450 (while (and gnus-article-x-face-command
1453 ;; Check whether this face is censored.
1454 (not gnus-article-x-face-too-ugly)
1455 (and gnus-article-x-face-too-ugly from
1456 (not (string-match gnus-article-x-face-too-ugly
1458 ;; Has to be present.
1459 (re-search-forward "^X-Face: " nil t))
1460 ;; This used to try to do multiple faces (`while' instead of
1461 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1462 ;; work (b) it can crash some versions of Emacs (c) are
1463 ;; multiple faces really something to encourage?
1464 (when (stringp gnus-article-x-face-command)
1466 ;; We now have the area of the buffer where the X-Face is stored.
1469 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1470 ;; We display the face.
1471 (if (symbolp gnus-article-x-face-command)
1472 ;; The command is a lisp function, so we call it.
1473 (if (gnus-functionp gnus-article-x-face-command)
1474 (funcall gnus-article-x-face-command beg end)
1475 (error "%s is not a function" gnus-article-x-face-command))
1476 ;; The command is a string, so we interpret the command
1477 ;; as a, well, command, and fork it off.
1478 (let ((process-connection-type nil))
1479 (process-kill-without-query
1481 "article-x-face" nil shell-file-name shell-command-switch
1482 gnus-article-x-face-command))
1483 (process-send-region "article-x-face" beg end)
1484 (process-send-eof "article-x-face"))))))))))
1486 (defun article-decode-mime-words ()
1487 "Decode all MIME-encoded words in the article."
1490 (set-buffer gnus-article-buffer)
1491 (let ((inhibit-point-motion-hooks t)
1493 (mail-parse-charset gnus-newsgroup-charset)
1494 (mail-parse-ignored-charsets
1495 (save-excursion (set-buffer gnus-summary-buffer)
1496 gnus-newsgroup-ignored-charsets)))
1497 (mail-decode-encoded-word-region (point-min) (point-max)))))
1499 (defun article-decode-charset (&optional prompt)
1500 "Decode charset-encoded text in the article.
1501 If PROMPT (the prefix), prompt for a coding system to use."
1503 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1505 (mail-parse-charset gnus-newsgroup-charset)
1506 (mail-parse-ignored-charsets
1507 (save-excursion (condition-case nil
1508 (set-buffer gnus-summary-buffer)
1510 gnus-newsgroup-ignored-charsets))
1511 ct cte ctl charset format)
1514 (article-narrow-to-head)
1515 (setq ct (message-fetch-field "Content-Type" t)
1516 cte (message-fetch-field "Content-Transfer-Encoding" t)
1517 ctl (and ct (ignore-errors
1518 (mail-header-parse-content-type ct)))
1521 (mm-read-coding-system "Charset to decode: "))
1523 (mail-content-type-get ctl 'charset)))
1524 format (and ctl (mail-content-type-get ctl 'format)))
1526 (setq cte (mail-header-strip cte)))
1527 (if (and ctl (not (string-match "/" (car ctl))))
1529 (goto-char (point-max)))
1532 (narrow-to-region (point) (point-max))
1533 (when (and (eq mail-parse-charset 'gnus-decoded)
1534 (eq (mm-body-7-or-8) '8bit))
1535 ;; The text code could have been decoded.
1536 (setq charset mail-parse-charset))
1537 (when (and (or (not ctl)
1538 (equal (car ctl) "text/plain"))
1539 (not format)) ;; article with format will decode later.
1541 charset (and cte (intern (downcase
1542 (gnus-strip-whitespace cte))))
1545 (defun article-decode-encoded-words ()
1546 "Remove encoded-word encoding from headers."
1547 (let ((inhibit-point-motion-hooks t)
1548 (mail-parse-charset gnus-newsgroup-charset)
1549 (mail-parse-ignored-charsets
1550 (save-excursion (condition-case nil
1551 (set-buffer gnus-summary-buffer)
1553 gnus-newsgroup-ignored-charsets))
1556 (article-narrow-to-head)
1557 (funcall gnus-decode-header-function (point-min) (point-max)))))
1559 (defun article-de-quoted-unreadable (&optional force)
1560 "Translate a quoted-printable-encoded article.
1561 If FORCE, decode the article whether it is marked as quoted-printable
1563 (interactive (list 'force))
1565 (let ((buffer-read-only nil) type charset)
1566 (if (gnus-buffer-live-p gnus-original-article-buffer)
1567 (with-current-buffer gnus-original-article-buffer
1569 (gnus-fetch-field "content-transfer-encoding"))
1570 (let* ((ct (gnus-fetch-field "content-type"))
1573 (mail-header-parse-content-type ct)))))
1574 (setq charset (and ctl
1575 (mail-content-type-get ctl 'charset)))
1576 (if (stringp charset)
1577 (setq charset (intern (downcase charset)))))))
1579 (setq charset gnus-newsgroup-charset))
1581 (and type (let ((case-fold-search t))
1582 (string-match "quoted-printable" type))))
1584 (quoted-printable-decode-region
1585 (point) (point-max) (mm-charset-to-coding-system charset))))))
1587 (defun article-de-base64-unreadable (&optional force)
1588 "Translate a base64 article.
1589 If FORCE, decode the article whether it is marked as base64 not."
1590 (interactive (list 'force))
1592 (let ((buffer-read-only nil) type charset)
1593 (if (gnus-buffer-live-p gnus-original-article-buffer)
1594 (with-current-buffer gnus-original-article-buffer
1596 (gnus-fetch-field "content-transfer-encoding"))
1597 (let* ((ct (gnus-fetch-field "content-type"))
1600 (mail-header-parse-content-type ct)))))
1601 (setq charset (and ctl
1602 (mail-content-type-get ctl 'charset)))
1603 (if (stringp charset)
1604 (setq charset (intern (downcase charset)))))))
1606 (setq charset gnus-newsgroup-charset))
1608 (and type (let ((case-fold-search t))
1609 (string-match "base64" type))))
1612 (narrow-to-region (point) (point-max))
1613 (base64-decode-region (point-min) (point-max))
1614 (mm-decode-coding-region
1615 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1620 (defun article-decode-HZ ()
1621 "Translate a HZ-encoded article."
1625 (let ((buffer-read-only nil))
1626 (rfc1843-decode-region (point-min) (point-max)))))
1628 (defun article-wash-html ()
1629 "Format an html article."
1632 (let ((buffer-read-only nil)
1634 (if (gnus-buffer-live-p gnus-original-article-buffer)
1635 (with-current-buffer gnus-original-article-buffer
1636 (let* ((ct (gnus-fetch-field "content-type"))
1639 (mail-header-parse-content-type ct)))))
1640 (setq charset (and ctl
1641 (mail-content-type-get ctl 'charset)))
1642 (if (stringp charset)
1643 (setq charset (intern (downcase charset)))))))
1645 (setq charset gnus-newsgroup-charset))
1647 (save-window-excursion
1649 (narrow-to-region (point) (point-max))
1651 (let ((w3-strict-width (window-width))
1652 (url-standalone-mode t))
1654 (w3-region (point-min) (point-max))
1657 (defun article-hide-list-identifiers ()
1658 "Remove list identifies from the Subject header.
1659 The `gnus-list-identifiers' variable specifies what to do."
1663 (let ((inhibit-point-motion-hooks t)
1665 (article-narrow-to-head)
1666 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1667 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1669 (goto-char (point-min))
1670 (when (re-search-forward
1671 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1672 " *\\)\\)+\\(Re: +\\)?\\)")
1674 (let ((s (or (match-string 3) (match-string 5))))
1675 (delete-region (match-beginning 1) (match-end 1))
1677 (goto-char (match-beginning 1))
1680 (defun article-hide-pgp ()
1681 "Remove any PGP headers and signatures in the current article."
1685 (let ((inhibit-point-motion-hooks t)
1686 buffer-read-only beg end)
1688 ;; Hide the "header".
1689 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1690 (push 'pgp gnus-article-wash-types)
1691 (delete-region (match-beginning 0) (match-end 0))
1692 ;; Remove armor headers (rfc2440 6.2)
1693 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1696 ;; Hide the actual signature.
1697 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1698 (setq end (1+ (match-beginning 0)))
1701 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1703 ;; Perhaps we shouldn't hide to the end of the buffer
1704 ;; if there is no end to the signature?
1706 ;; Hide "- " PGP quotation markers.
1708 (narrow-to-region beg end)
1709 (goto-char (point-min))
1710 (while (re-search-forward "^- " nil t)
1712 (match-beginning 0) (match-end 0)))
1714 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1716 (defun article-hide-pem (&optional arg)
1717 "Toggle hiding of any PEM headers and signatures in the current article.
1718 If given a negative prefix, always show; if given a positive prefix,
1720 (interactive (gnus-article-hidden-arg))
1721 (unless (gnus-article-check-hidden-text 'pem arg)
1723 (let (buffer-read-only end)
1724 (goto-char (point-min))
1725 ;; Hide the horrendously ugly "header".
1726 (when (and (search-forward
1727 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1729 (setq end (1+ (match-beginning 0))))
1730 (push 'pem gnus-article-wash-types)
1731 (gnus-article-hide-text-type
1733 (if (search-forward "\n\n" nil t)
1737 ;; Hide the trailer as well
1738 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1740 (gnus-article-hide-text-type
1741 (match-beginning 0) (match-end 0) 'pem)))))))
1743 (defun article-strip-banner ()
1744 "Strip the banner specified by the `banner' group parameter."
1748 (let ((inhibit-point-motion-hooks t)
1749 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1750 (gnus-signature-limit nil)
1751 buffer-read-only beg end)
1755 ((eq banner 'signature)
1756 (when (gnus-article-narrow-to-signature)
1759 (delete-region (point) (point-max))))
1761 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1762 (while (re-search-forward banner nil t)
1763 (delete-region (match-beginning 0) (match-end 0)))))
1765 (while (re-search-forward banner nil t)
1766 (delete-region (match-beginning 0) (match-end 0))))))))))
1768 (defun article-babel ()
1769 "Translate article using an online translation service."
1773 (set-buffer gnus-article-buffer)
1774 (when (article-goto-body)
1775 (let* ((buffer-read-only nil)
1778 (orig (buffer-substring start end))
1779 (trans (babel-as-string orig)))
1781 (narrow-to-region start end)
1782 (delete-region start end)
1785 (defun article-hide-signature (&optional arg)
1786 "Hide the signature in the current article.
1787 If given a negative prefix, always show; if given a positive prefix,
1789 (interactive (gnus-article-hidden-arg))
1790 (unless (gnus-article-check-hidden-text 'signature arg)
1793 (let ((buffer-read-only nil))
1794 (when (gnus-article-narrow-to-signature)
1795 (gnus-article-hide-text-type
1796 (point-min) (point-max) 'signature)))))))
1798 (defun article-strip-headers-in-body ()
1799 "Strip offensive headers from bodies."
1803 (let ((case-fold-search t))
1804 (when (looking-at "x-no-archive:")
1805 (gnus-delete-line)))))
1807 (defun article-strip-leading-blank-lines ()
1808 "Remove all blank lines from the beginning of the article."
1811 (let ((inhibit-point-motion-hooks t)
1813 (when (article-goto-body)
1814 (while (and (not (eobp))
1815 (looking-at "[ \t]*$"))
1816 (gnus-delete-line))))))
1818 (defun article-narrow-to-head ()
1819 "Narrow the buffer to the head of the message.
1820 Point is left at the beginning of the narrowed-to region."
1822 (goto-char (point-min))
1823 (if (search-forward "\n\n" nil 1)
1826 (goto-char (point-min)))
1828 (defun article-goto-body ()
1829 "Place point at the start of the body."
1830 (goto-char (point-min))
1832 ;; This variable is only bound when dealing with separate
1834 (article-goto-body-goes-to-point-min-p
1836 ((search-forward "\n\n" nil t)
1839 (goto-char (point-max))
1842 (defun article-strip-multiple-blank-lines ()
1843 "Replace consecutive blank lines with one empty line."
1846 (let ((inhibit-point-motion-hooks t)
1848 ;; First make all blank lines empty.
1850 (while (re-search-forward "^[ \t]+$" nil t)
1851 (unless (gnus-annotation-in-region-p
1852 (match-beginning 0) (match-end 0))
1853 (replace-match "" nil t)))
1854 ;; Then replace multiple empty lines with a single empty line.
1856 (while (re-search-forward "\n\n\n+" nil t)
1857 (unless (gnus-annotation-in-region-p
1858 (match-beginning 0) (match-end 0))
1859 (replace-match "\n\n" t t))))))
1861 (defun article-strip-leading-space ()
1862 "Remove all white space from the beginning of the lines in the article."
1865 (let ((inhibit-point-motion-hooks t)
1868 (while (re-search-forward "^[ \t]+" nil t)
1869 (replace-match "" t t)))))
1871 (defun article-strip-trailing-space ()
1872 "Remove all white space from the end of the lines in the article."
1875 (let ((inhibit-point-motion-hooks t)
1878 (while (re-search-forward "[ \t]+$" nil t)
1879 (replace-match "" t t)))))
1881 (defun article-strip-blank-lines ()
1882 "Strip leading, trailing and multiple blank lines."
1884 (article-strip-leading-blank-lines)
1885 (article-remove-trailing-blank-lines)
1886 (article-strip-multiple-blank-lines))
1888 (defun article-strip-all-blank-lines ()
1889 "Strip all blank lines."
1892 (let ((inhibit-point-motion-hooks t)
1895 (while (re-search-forward "^[ \t]*\n" nil t)
1896 (replace-match "" t t)))))
1898 (defun gnus-article-narrow-to-signature ()
1899 "Narrow to the signature; return t if a signature is found, else nil."
1900 (let ((inhibit-point-motion-hooks t))
1901 (when (gnus-article-search-signature)
1903 ;; Check whether we have some limits to what we consider
1904 ;; to be a signature.
1905 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1906 (list gnus-signature-limit)))
1908 (while (setq limit (pop limits))
1909 (if (or (and (integerp limit)
1910 (< (- (point-max) (point)) limit))
1912 (< (count-lines (point) (point-max)) limit))
1913 (and (gnus-functionp limit)
1915 (and (stringp limit)
1916 (not (re-search-forward limit nil t))))
1917 () ; This limit did not succeed.
1921 (narrow-to-region (point) (point-max))
1924 (defun gnus-article-search-signature ()
1925 "Search the current buffer for the signature separator.
1926 Put point at the beginning of the signature separator."
1927 (let ((cur (point)))
1928 (goto-char (point-max))
1929 (if (if (stringp gnus-signature-separator)
1930 (re-search-backward gnus-signature-separator nil t)
1931 (let ((seps gnus-signature-separator))
1933 (not (re-search-backward (car seps) nil t)))
1940 (defun gnus-article-hidden-arg ()
1941 "Return the current prefix arg as a number, or 0 if no prefix."
1942 (list (if current-prefix-arg
1943 (prefix-numeric-value current-prefix-arg)
1946 (defun gnus-article-check-hidden-text (type arg)
1947 "Return nil if hiding is necessary.
1948 Arg can be nil or a number. Nil and positive means hide, negative
1949 means show, 0 means toggle."
1952 (let ((hide (gnus-article-hidden-text-p type)))
1958 (gnus-article-show-hidden-text type)
1961 (if (eq hide 'hidden)
1963 (gnus-article-show-hidden-text type)
1967 (defun gnus-article-hidden-text-p (type)
1968 "Say whether the current buffer contains hidden text of type TYPE."
1969 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1971 (not (get-text-property pos 'invisible))
1972 (not (get-text-property pos 'dummy-invisible)))
1974 (text-property-any (1+ pos) (point-max) 'article-type type)))
1979 (defun gnus-article-show-hidden-text (type &optional dummy)
1980 "Show all hidden text of type TYPE.
1981 Originally it is hide instead of DUMMY."
1982 (let ((buffer-read-only nil)
1983 (inhibit-point-motion-hooks t))
1984 (gnus-remove-text-properties-when
1986 (point-min) (point-max)
1987 (cons 'article-type (cons type
1988 gnus-hidden-properties)))))
1990 (defconst article-time-units
1991 `((year . ,(* 365.25 24 60 60))
1992 (week . ,(* 7 24 60 60))
1993 (day . ,(* 24 60 60))
1997 "Mapping from time units to seconds.")
1999 (defun article-date-ut (&optional type highlight header)
2000 "Convert DATE date to universal time in the current article.
2001 If TYPE is `local', convert to local time; if it is `lapsed', output
2002 how much time has lapsed since DATE. For `lapsed', the value of
2003 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2004 should replace the \"Date:\" one, or should be added below it."
2005 (interactive (list 'ut t))
2006 (let* ((header (or header
2007 (message-fetch-field "date")
2009 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2012 ((not gnus-article-date-lapsed-new-header)
2018 (date (if (vectorp header) (mail-header-date header)
2020 (inhibit-point-motion-hooks t)
2025 (article-narrow-to-head)
2026 (when (re-search-forward tdate-regexp nil t)
2027 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2028 date (or (get-text-property (gnus-point-at-bol)
2031 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2033 (when (and date (not (string= date "")))
2034 (goto-char (point-min))
2035 (let ((buffer-read-only nil))
2036 ;; Delete any old Date headers.
2037 (while (re-search-forward date-regexp nil t)
2039 (delete-region (progn (beginning-of-line) (point))
2040 (progn (forward-line 1) (point)))
2041 (delete-region (progn (beginning-of-line) (point))
2042 (progn (end-of-line) (point)))
2043 (setq pos (point))))
2044 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2046 (if pos (goto-char pos))
2047 (insert (article-make-date-line date (or type 'ut)))
2053 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2054 (put-text-property (match-beginning 1) (1+ (match-end 1))
2055 'original-date date)
2056 (put-text-property (match-beginning 1) (1+ (match-end 1))
2058 (put-text-property (match-beginning 2) (match-end 2)
2061 (defun article-make-date-line (date type)
2062 "Return a DATE line of TYPE."
2063 (let ((time (condition-case ()
2067 ;; Convert to the local timezone. We have to slap a
2068 ;; `condition-case' round the calls to the timezone
2069 ;; functions since they aren't particularly resistant to
2072 (let ((tz (car (current-time-zone time))))
2073 (format "Date: %s %s%02d%02d" (current-time-string time)
2074 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2075 (/ (% (abs tz) 3600) 60))))
2076 ;; Convert to Universal Time.
2079 (current-time-string
2080 (let* ((e (parse-time-string date))
2081 (tm (apply 'encode-time e))
2083 (ls (- (cadr tm) (car (current-time-zone time)))))
2084 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2085 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2088 ;; Get the original date from the article.
2089 ((eq type 'original)
2090 (concat "Date: " (if (string-match "\n+$" date)
2091 (substring date 0 (match-beginning 0))
2093 ;; Let the user define the format.
2095 (if (gnus-functionp gnus-article-time-format)
2096 (funcall gnus-article-time-format time)
2099 (format-time-string gnus-article-time-format time))))
2102 (let ((tz (car (current-time-zone time))))
2105 (format-time-string "%Y%m%dT%H%M%S" time)
2106 (format "%s%02d%02d"
2107 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2108 (/ (% (abs tz) 3600) 60)))))
2109 ;; Do an X-Sent lapsed format.
2111 ;; If the date is seriously mangled, the timezone functions are
2112 ;; liable to bug out, so we ignore all errors.
2113 (let* ((now (current-time))
2114 (real-time (subtract-time now time))
2115 (real-sec (and real-time
2116 (+ (* (float (car real-time)) 65536)
2118 (sec (and real-time (abs real-sec)))
2128 ;; This is a bit convoluted, but basically we go
2129 ;; through the time units for years, weeks, etc,
2130 ;; and divide things to see whether that results
2131 ;; in positive answers.
2134 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2135 ;; The (remaining) seconds are too few to
2136 ;; be divided into this time unit.
2138 ;; It's big enough, so we output it.
2139 (setq sec (- sec (* num (cdr unit))))
2141 (concat (if prev ", " "") (int-to-string
2143 " " (symbol-name (car unit))
2144 (if (> num 1) "s" ""))
2146 article-time-units "")
2147 ;; If dates are odd, then it might appear like the
2148 ;; article was sent in the future.
2151 " in the future"))))))
2153 (error "Unknown conversion type: %s" type)))))
2155 (defun article-date-local (&optional highlight)
2156 "Convert the current article date to the local timezone."
2157 (interactive (list t))
2158 (article-date-ut 'local highlight))
2160 (defun article-date-original (&optional highlight)
2161 "Convert the current article date to what it was originally.
2162 This is only useful if you have used some other date conversion
2163 function and want to see what the date was before converting."
2164 (interactive (list t))
2165 (article-date-ut 'original highlight))
2167 (defun article-date-lapsed (&optional highlight)
2168 "Convert the current article date to time lapsed since it was sent."
2169 (interactive (list t))
2170 (article-date-ut 'lapsed highlight))
2172 (defun article-update-date-lapsed ()
2173 "Function to be run from a timer to update the lapsed time line."
2174 (let (deactivate-mark)
2179 (set-buffer (window-buffer w))
2180 (when (eq major-mode 'gnus-article-mode)
2181 (goto-char (point-min))
2182 (when (re-search-forward "^X-Sent:" nil t)
2183 (article-date-lapsed t))))
2186 (defun gnus-start-date-timer (&optional n)
2187 "Start a timer to update the X-Sent header in the article buffers.
2188 The numerical prefix says how frequently (in seconds) the function
2193 (gnus-stop-date-timer)
2194 (setq article-lapsed-timer
2195 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2197 (defun gnus-stop-date-timer ()
2198 "Stop the X-Sent timer."
2200 (when article-lapsed-timer
2201 (nnheader-cancel-timer article-lapsed-timer)
2202 (setq article-lapsed-timer nil)))
2204 (defun article-date-user (&optional highlight)
2205 "Convert the current article date to the user-defined format.
2206 This format is defined by the `gnus-article-time-format' variable."
2207 (interactive (list t))
2208 (article-date-ut 'user highlight))
2210 (defun article-date-iso8601 (&optional highlight)
2211 "Convert the current article date to ISO8601."
2212 (interactive (list t))
2213 (article-date-ut 'iso8601 highlight))
2215 (defun article-show-all ()
2216 "Show all hidden text in the article buffer."
2219 (let ((buffer-read-only nil))
2220 (gnus-article-unhide-text (point-min) (point-max)))))
2222 (defun article-emphasize (&optional arg)
2223 "Emphasize text according to `gnus-emphasis-alist'."
2224 (interactive (gnus-article-hidden-arg))
2225 (unless (gnus-article-check-hidden-text 'emphasis arg)
2229 (with-current-buffer gnus-summary-buffer
2230 gnus-article-emphasis-alist)
2232 gnus-emphasis-alist))
2233 (buffer-read-only nil)
2234 (props (append '(article-type emphasis)
2235 gnus-hidden-properties))
2236 regexp elem beg invisible visible face)
2239 (while (setq elem (pop alist))
2241 (setq regexp (car elem)
2242 invisible (nth 1 elem)
2243 visible (nth 2 elem)
2245 (while (re-search-forward regexp nil t)
2246 (when (and (match-beginning visible) (match-beginning invisible))
2247 (push 'emphasis gnus-article-wash-types)
2248 (gnus-article-hide-text
2249 (match-beginning invisible) (match-end invisible) props)
2250 (gnus-article-unhide-text-type
2251 (match-beginning visible) (match-end visible) 'emphasis)
2252 (gnus-put-text-property-excluding-newlines
2253 (match-beginning visible) (match-end visible) 'face face)
2254 (goto-char (match-end invisible)))))))))
2256 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2257 "Setup newsgroup emphasis alist."
2258 (unless gnus-article-emphasis-alist
2259 (let ((name (and gnus-newsgroup-name
2260 (gnus-group-real-name gnus-newsgroup-name))))
2261 (make-local-variable 'gnus-article-emphasis-alist)
2262 (setq gnus-article-emphasis-alist
2264 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2265 (while (setq elem (pop alist))
2266 (when (and name (string-match (car elem) name))
2268 highlight (copy-sequence (cdr elem)))))
2270 (copy-sequence highlight-words)
2271 (if gnus-newsgroup-name
2272 (copy-sequence (gnus-group-find-parameter
2273 gnus-newsgroup-name 'highlight-words t)))
2274 gnus-emphasis-alist)))))
2276 (defvar gnus-summary-article-menu)
2277 (defvar gnus-summary-post-menu)
2279 ;;; Saving functions.
2281 (defun gnus-article-save (save-buffer file &optional num)
2282 "Save the currently selected article."
2283 (unless gnus-save-all-headers
2284 ;; Remove headers according to `gnus-saved-headers'.
2285 (let ((gnus-visible-headers
2286 (or gnus-saved-headers gnus-visible-headers))
2287 (gnus-article-buffer save-buffer))
2289 (set-buffer save-buffer)
2290 (article-hide-headers 1 t))))
2291 (save-window-excursion
2292 (if (not gnus-default-article-saver)
2293 (error "No default saver is defined")
2294 ;; !!! Magic! The saving functions all save
2295 ;; `gnus-save-article-buffer' (or so they think), but we
2296 ;; bind that variable to our save-buffer.
2297 (set-buffer gnus-article-buffer)
2298 (let* ((gnus-save-article-buffer save-buffer)
2301 ((not gnus-prompt-before-saving) 'default)
2302 ((eq gnus-prompt-before-saving 'always) nil)
2304 (gnus-number-of-articles-to-be-saved
2305 (when (eq gnus-prompt-before-saving t)
2307 (set-buffer gnus-article-current-summary)
2308 (funcall gnus-default-article-saver filename)))))
2310 (defun gnus-read-save-file-name (prompt &optional filename
2311 function group headers variable)
2313 (funcall function group headers (symbol-value variable)))
2318 ((eq filename 'default)
2324 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2327 (if (and gnus-number-of-articles-to-be-saved
2328 (> gnus-number-of-articles-to-be-saved 1))
2329 (format "these %d articles"
2330 gnus-number-of-articles-to-be-saved)
2333 ;; Let the split methods have their say.
2335 ;; No split name was found.
2338 (concat prompt " (default "
2339 (file-name-nondirectory default-name) ") ")
2340 (file-name-directory default-name)
2342 ;; A single group name is returned.
2343 ((stringp split-name)
2345 (funcall function split-name headers
2346 (symbol-value variable)))
2348 (concat prompt " (default "
2349 (file-name-nondirectory default-name) ") ")
2350 (file-name-directory default-name)
2352 ;; A single split name was found
2353 ((= 1 (length split-name))
2354 (let* ((name (expand-file-name
2356 gnus-article-save-directory))
2357 (dir (cond ((file-directory-p name)
2358 (file-name-as-directory name))
2359 ((file-exists-p name) name)
2360 (t gnus-article-save-directory))))
2362 (concat prompt " (default " name ") ")
2364 ;; A list of splits was found.
2366 (setq split-name (nreverse split-name))
2368 (let ((file-name-history
2369 (nconc split-name file-name-history)))
2373 (concat prompt " (`M-p' for defaults) ")
2374 gnus-article-save-directory
2376 gnus-article-save-directory)))
2377 (car (push result file-name-history)))))))
2378 ;; Create the directory.
2379 (gnus-make-directory (file-name-directory file))
2380 ;; If we have read a directory, we append the default file name.
2381 (when (file-directory-p file)
2382 (setq file (expand-file-name (file-name-nondirectory
2384 (file-name-as-directory file))))
2385 ;; Possibly translate some characters.
2386 (nnheader-translate-file-chars file))))))
2387 (gnus-make-directory (file-name-directory result))
2388 (set variable result)))
2390 (defun gnus-article-archive-name (group)
2391 "Return the first instance of an \"Archive-name\" in the current buffer."
2392 (let ((case-fold-search t))
2393 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2394 (nnheader-concat gnus-article-save-directory
2395 (match-string 1)))))
2397 (defun gnus-article-nndoc-name (group)
2398 "If GROUP is an nndoc group, return the name of the parent group."
2399 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2400 (gnus-group-get-parameter group 'save-article-group)))
2402 (defun gnus-summary-save-in-rmail (&optional filename)
2403 "Append this article to Rmail file.
2404 Optional argument FILENAME specifies file name.
2405 Directory to save to is default to `gnus-article-save-directory'."
2406 (setq filename (gnus-read-save-file-name
2407 "Save %s in rmail file:" filename
2408 gnus-rmail-save-name gnus-newsgroup-name
2409 gnus-current-headers 'gnus-newsgroup-last-rmail))
2410 (gnus-eval-in-buffer-window gnus-save-article-buffer
2414 (gnus-output-to-rmail filename))))
2417 (defun gnus-summary-save-in-mail (&optional filename)
2418 "Append this article to Unix mail file.
2419 Optional argument FILENAME specifies file name.
2420 Directory to save to is default to `gnus-article-save-directory'."
2421 (setq filename (gnus-read-save-file-name
2422 "Save %s in Unix mail file:" filename
2423 gnus-mail-save-name gnus-newsgroup-name
2424 gnus-current-headers 'gnus-newsgroup-last-mail))
2425 (gnus-eval-in-buffer-window gnus-save-article-buffer
2429 (if (and (file-readable-p filename)
2430 (mail-file-babyl-p filename))
2431 (rmail-output-to-rmail-file filename t)
2432 (gnus-output-to-mail filename)))))
2435 (defun gnus-summary-save-in-file (&optional filename overwrite)
2436 "Append this article to file.
2437 Optional argument FILENAME specifies file name.
2438 Directory to save to is default to `gnus-article-save-directory'."
2439 (setq filename (gnus-read-save-file-name
2440 "Save %s in file:" filename
2441 gnus-file-save-name gnus-newsgroup-name
2442 gnus-current-headers 'gnus-newsgroup-last-file))
2443 (gnus-eval-in-buffer-window gnus-save-article-buffer
2447 (when (and overwrite
2448 (file-exists-p filename))
2449 (delete-file filename))
2450 (gnus-output-to-file filename))))
2453 (defun gnus-summary-write-to-file (&optional filename)
2454 "Write this article to a file.
2455 Optional argument FILENAME specifies file name.
2456 The directory to save in defaults to `gnus-article-save-directory'."
2457 (gnus-summary-save-in-file nil t))
2459 (defun gnus-summary-save-body-in-file (&optional filename)
2460 "Append this article body to a file.
2461 Optional argument FILENAME specifies file name.
2462 The directory to save in defaults to `gnus-article-save-directory'."
2463 (setq filename (gnus-read-save-file-name
2464 "Save %s body in file:" filename
2465 gnus-file-save-name gnus-newsgroup-name
2466 gnus-current-headers 'gnus-newsgroup-last-file))
2467 (gnus-eval-in-buffer-window gnus-save-article-buffer
2471 (when (article-goto-body)
2472 (narrow-to-region (point) (point-max)))
2473 (gnus-output-to-file filename))))
2476 (defun gnus-summary-save-in-pipe (&optional command)
2477 "Pipe this article to subprocess."
2479 (cond ((and (eq command 'default)
2480 gnus-last-shell-command)
2481 gnus-last-shell-command)
2485 "Shell command on %s: "
2486 (if (and gnus-number-of-articles-to-be-saved
2487 (> gnus-number-of-articles-to-be-saved 1))
2488 (format "these %d articles"
2489 gnus-number-of-articles-to-be-saved)
2491 gnus-last-shell-command))))
2492 (when (string-equal command "")
2493 (setq command gnus-last-shell-command))
2494 (gnus-eval-in-buffer-window gnus-article-buffer
2497 (shell-command-on-region (point-min) (point-max) command nil)))
2498 (setq gnus-last-shell-command command))
2500 ;;; Article file names when saving.
2502 (defun gnus-capitalize-newsgroup (newsgroup)
2503 "Capitalize NEWSGROUP name."
2504 (when (not (zerop (length newsgroup)))
2505 (concat (char-to-string (upcase (aref newsgroup 0)))
2506 (substring newsgroup 1))))
2508 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2509 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2510 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2511 Otherwise, it is like ~/News/news/group/num."
2514 (concat (if (gnus-use-long-file-name 'not-save)
2515 (gnus-capitalize-newsgroup newsgroup)
2516 (gnus-newsgroup-directory-form newsgroup))
2517 "/" (int-to-string (mail-header-number headers)))
2518 gnus-article-save-directory)))
2520 (string-equal (file-name-directory default)
2521 (file-name-directory last-file))
2522 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2524 (or last-file default))))
2526 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2527 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2528 If variable `gnus-use-long-file-name' is non-nil, it is
2529 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2532 (concat (if (gnus-use-long-file-name 'not-save)
2534 (gnus-newsgroup-directory-form newsgroup))
2535 "/" (int-to-string (mail-header-number headers)))
2536 gnus-article-save-directory)))
2538 (string-equal (file-name-directory default)
2539 (file-name-directory last-file))
2540 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2542 (or last-file default))))
2544 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2545 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2546 If variable `gnus-use-long-file-name' is non-nil, it is
2547 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2550 (if (gnus-use-long-file-name 'not-save)
2552 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2553 gnus-article-save-directory)))
2560 (setq afunc (car func)
2563 gfunc (intern (format "gnus-%s" func))))
2566 `(lambda (&optional interactive &rest args)
2567 ,(documentation afunc t)
2568 (interactive (list t))
2570 (set-buffer gnus-article-buffer)
2572 (call-interactively ',afunc)
2573 (apply ',afunc args))))))))
2574 '(article-hide-headers
2575 article-hide-boring-headers
2576 article-treat-overstrike
2577 article-fill-long-lines
2578 article-capitalize-sentences
2580 article-display-x-face
2581 article-de-quoted-unreadable
2582 article-de-base64-unreadable
2585 article-hide-list-identifiers
2587 article-strip-banner
2590 article-hide-signature
2591 article-strip-headers-in-body
2592 article-remove-trailing-blank-lines
2593 article-strip-leading-blank-lines
2594 article-strip-multiple-blank-lines
2595 article-strip-leading-space
2596 article-strip-trailing-space
2597 article-strip-blank-lines
2598 article-strip-all-blank-lines
2600 article-date-iso8601
2601 article-date-original
2603 article-decode-mime-words
2604 article-decode-charset
2605 article-decode-encoded-words
2609 article-treat-dumbquotes
2610 article-normalize-headers
2611 (article-show-all . gnus-article-show-all-headers))))
2614 ;;; Gnus article mode
2617 (put 'gnus-article-mode 'mode-class 'special)
2619 (set-keymap-parent gnus-article-mode-map widget-keymap)
2621 (gnus-define-keys gnus-article-mode-map
2622 " " gnus-article-goto-next-page
2623 "\177" gnus-article-goto-prev-page
2624 [delete] gnus-article-goto-prev-page
2625 [backspace] gnus-article-goto-prev-page
2626 "\C-c^" gnus-article-refer-article
2627 "h" gnus-article-show-summary
2628 "s" gnus-article-show-summary
2629 "\C-c\C-m" gnus-article-mail
2630 "?" gnus-article-describe-briefly
2631 "e" gnus-summary-edit-article
2632 "<" beginning-of-buffer
2634 "\C-c\C-i" gnus-info-find-node
2636 "\C-hk" gnus-article-describe-key
2637 "\C-hc" gnus-article-describe-key-briefly
2639 "\C-d" gnus-article-read-summary-keys
2640 "\M-*" gnus-article-read-summary-keys
2641 "\M-#" gnus-article-read-summary-keys
2642 "\M-^" gnus-article-read-summary-keys
2643 "\M-g" gnus-article-read-summary-keys)
2645 (substitute-key-definition
2646 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2648 (defun gnus-article-make-menu-bar ()
2649 (gnus-turn-off-edit-menu 'article)
2650 (unless (boundp 'gnus-article-article-menu)
2652 gnus-article-article-menu gnus-article-mode-map ""
2654 ["Scroll forwards" gnus-article-goto-next-page t]
2655 ["Scroll backwards" gnus-article-goto-prev-page t]
2656 ["Show summary" gnus-article-show-summary t]
2657 ["Fetch Message-ID at point" gnus-article-refer-article t]
2658 ["Mail to address at point" gnus-article-mail t]
2659 ["Send a bug report" gnus-bug t]))
2662 gnus-article-treatment-menu gnus-article-mode-map ""
2664 ["Hide headers" gnus-article-hide-headers t]
2665 ["Hide signature" gnus-article-hide-signature t]
2666 ["Hide citation" gnus-article-hide-citation t]
2667 ["Treat overstrike" gnus-article-treat-overstrike t]
2668 ["Remove carriage return" gnus-article-remove-cr t]
2669 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2670 ["Remove base64" gnus-article-de-base64-unreadable t]
2671 ["Treat html" gnus-article-wash-html t]
2672 ["Decode HZ" gnus-article-decode-HZ t]))
2674 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2676 (when (boundp 'gnus-summary-post-menu)
2677 (define-key gnus-article-mode-map [menu-bar post]
2678 (cons "Post" gnus-summary-post-menu)))
2680 (gnus-run-hooks 'gnus-article-menu-hook)))
2682 (defun gnus-article-mode ()
2683 "Major mode for displaying an article.
2685 All normal editing commands are switched off.
2687 The following commands are available in addition to all summary mode
2689 \\<gnus-article-mode-map>
2690 \\[gnus-article-next-page]\t Scroll the article one page forwards
2691 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2692 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2693 \\[gnus-article-show-summary]\t Display the summary buffer
2694 \\[gnus-article-mail]\t Send a reply to the address near point
2695 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2696 \\[gnus-info-find-node]\t Go to the Gnus info node"
2698 (when (gnus-visual-p 'article-menu 'menu)
2699 (gnus-article-make-menu-bar))
2700 (gnus-simplify-mode-line)
2701 (setq mode-name "Article")
2702 (setq major-mode 'gnus-article-mode)
2703 (make-local-variable 'minor-mode-alist)
2704 (use-local-map gnus-article-mode-map)
2705 (gnus-update-format-specifications nil 'article-mode)
2706 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2707 (make-local-variable 'gnus-page-broken)
2708 (make-local-variable 'gnus-button-marker-list)
2709 (make-local-variable 'gnus-article-current-summary)
2710 (make-local-variable 'gnus-article-mime-handles)
2711 (make-local-variable 'gnus-article-decoded-p)
2712 (make-local-variable 'gnus-article-mime-handle-alist)
2713 (make-local-variable 'gnus-article-wash-types)
2714 (gnus-set-default-directory)
2715 (buffer-disable-undo)
2716 (setq buffer-read-only t)
2717 (set-syntax-table gnus-article-mode-syntax-table)
2718 (mm-enable-multibyte)
2719 (gnus-run-hooks 'gnus-article-mode-hook))
2721 (defun gnus-article-setup-buffer ()
2722 "Initialize the article buffer."
2723 (let* ((name (if gnus-single-article-buffer "*Article*"
2724 (concat "*Article " gnus-newsgroup-name "*")))
2726 (progn (string-match "\\*Article" name)
2727 (concat " *Original Article"
2728 (substring name (match-end 0))))))
2729 (setq gnus-article-buffer name)
2730 (setq gnus-original-article-buffer original)
2731 (setq gnus-article-mime-handle-alist nil)
2732 ;; This might be a variable local to the summary buffer.
2733 (unless gnus-single-article-buffer
2735 (set-buffer gnus-summary-buffer)
2736 (setq gnus-article-buffer name)
2737 (setq gnus-original-article-buffer original)
2738 (gnus-set-global-variables)))
2739 (gnus-article-setup-highlight-words)
2740 ;; Init original article buffer.
2742 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2743 (mm-enable-multibyte)
2744 (setq major-mode 'gnus-original-article-mode)
2745 (make-local-variable 'gnus-original-article))
2746 (if (get-buffer name)
2749 (when gnus-article-mime-handles
2750 (mm-destroy-parts gnus-article-mime-handles)
2751 (setq gnus-article-mime-handles nil))
2752 ;; Set it to nil in article-buffer!
2753 (setq gnus-article-mime-handle-alist nil)
2754 (buffer-disable-undo)
2755 (setq buffer-read-only t)
2756 (unless (eq major-mode 'gnus-article-mode)
2757 (gnus-article-mode))
2760 (set-buffer (gnus-get-buffer-create name))
2762 (make-local-variable 'gnus-summary-buffer)
2763 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2764 (current-buffer)))))
2766 ;; Set article window start at LINE, where LINE is the number of lines
2767 ;; from the head of the article.
2768 (defun gnus-article-set-window-start (&optional line)
2770 (get-buffer-window gnus-article-buffer t)
2772 (set-buffer gnus-article-buffer)
2773 (goto-char (point-min))
2776 (gnus-message 6 "Moved to bookmark")
2777 (search-forward "\n\n" nil t)
2781 (defun gnus-article-prepare (article &optional all-headers header)
2782 "Prepare ARTICLE in article mode buffer.
2783 ARTICLE should either be an article number or a Message-ID.
2784 If ARTICLE is an id, HEADER should be the article headers.
2785 If ALL-HEADERS is non-nil, no headers are hidden."
2787 ;; Make sure we start in a summary buffer.
2788 (unless (eq major-mode 'gnus-summary-mode)
2789 (set-buffer gnus-summary-buffer))
2790 (setq gnus-summary-buffer (current-buffer))
2791 (let* ((gnus-article (if header (mail-header-number header) article))
2792 (summary-buffer (current-buffer))
2793 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2794 (group gnus-newsgroup-name)
2797 (gnus-article-setup-buffer)
2798 (set-buffer gnus-article-buffer)
2799 ;; Deactivate active regions.
2800 (when (and (boundp 'transient-mark-mode)
2801 transient-mark-mode)
2802 (setq mark-active nil))
2803 (if (not (setq result (let ((buffer-read-only nil))
2804 (gnus-request-article-this-buffer
2806 ;; There is no such article.
2808 (when (and (numberp article)
2809 (not (memq article gnus-newsgroup-sparse)))
2810 (setq gnus-article-current
2811 (cons gnus-newsgroup-name article))
2812 (set-buffer gnus-summary-buffer)
2813 (setq gnus-current-article article)
2814 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2816 (gnus-summary-set-agent-mark article)
2817 (message "Message marked for downloading"))
2818 (gnus-summary-mark-article article gnus-canceled-mark)
2819 (unless (memq article gnus-newsgroup-sparse)
2820 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2821 (if (or (eq result 'pseudo)
2822 (eq result 'nneething))
2825 (set-buffer summary-buffer)
2826 (push article gnus-newsgroup-history)
2827 (setq gnus-last-article gnus-current-article
2828 gnus-current-article 0
2829 gnus-current-headers nil
2830 gnus-article-current nil)
2831 (if (eq result 'nneething)
2832 (gnus-configure-windows 'summary)
2833 (gnus-configure-windows 'article))
2834 (gnus-set-global-variables))
2835 (let ((gnus-article-mime-handle-alist-1
2836 gnus-article-mime-handle-alist))
2837 (gnus-set-mode-line 'article)))
2838 ;; The result from the `request' was an actual article -
2839 ;; or at least some text that is now displayed in the
2841 (when (and (numberp article)
2842 (not (eq article gnus-current-article)))
2843 ;; Seems like a new article has been selected.
2844 ;; `gnus-current-article' must be an article number.
2846 (set-buffer summary-buffer)
2847 (push article gnus-newsgroup-history)
2848 (setq gnus-last-article gnus-current-article
2849 gnus-current-article article
2850 gnus-current-headers
2851 (gnus-summary-article-header gnus-current-article)
2852 gnus-article-current
2853 (cons gnus-newsgroup-name gnus-current-article))
2854 (unless (vectorp gnus-current-headers)
2855 (setq gnus-current-headers nil))
2856 (gnus-summary-goto-subject gnus-current-article)
2857 (when (gnus-summary-show-thread)
2858 ;; If the summary buffer really was folded, the
2859 ;; previous goto may not actually have gone to
2860 ;; the right article, but the thread root instead.
2862 (gnus-summary-goto-subject gnus-current-article))
2863 (gnus-run-hooks 'gnus-mark-article-hook)
2864 (gnus-set-mode-line 'summary)
2865 (when (gnus-visual-p 'article-highlight 'highlight)
2866 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2867 ;; Set the global newsgroup variables here.
2868 (gnus-set-global-variables)
2869 (setq gnus-have-all-headers
2870 (or all-headers gnus-show-all-headers))))
2872 (gnus-configure-windows 'article))
2873 (when (or (numberp article)
2875 (gnus-article-prepare-display)
2877 (goto-char (point-min))
2878 (setq gnus-page-broken
2879 (when gnus-break-pages
2880 (gnus-narrow-to-page)
2882 (let ((gnus-article-mime-handle-alist-1
2883 gnus-article-mime-handle-alist))
2884 (gnus-set-mode-line 'article))
2886 (set-window-point (get-buffer-window (current-buffer)) (point))
2887 (gnus-configure-windows 'article)
2891 (defun gnus-article-prepare-display ()
2892 "Make the current buffer look like a nice article."
2893 ;; Hooks for getting information from the article.
2894 ;; This hook must be called before being narrowed.
2895 (let ((gnus-article-buffer (current-buffer))
2897 (unless (eq major-mode 'gnus-article-mode)
2898 (gnus-article-mode))
2899 (setq buffer-read-only nil
2900 gnus-article-wash-types nil)
2901 (gnus-run-hooks 'gnus-tmp-internal-hook)
2902 (when gnus-display-mime-function
2903 (funcall gnus-display-mime-function))
2904 (gnus-run-hooks 'gnus-article-prepare-hook)))
2907 ;;; Gnus MIME viewing functions
2910 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2911 "The following specs can be used:
2913 %T MIME type, along with additional info
2914 %n The `name' parameter
2915 %d The description, if any
2916 %l The length of the encoded part
2917 %p The part identifier number
2918 %e Dots if the part isn't displayed")
2920 (defvar gnus-mime-button-line-format-alist
2921 '((?t gnus-tmp-type ?s)
2922 (?T gnus-tmp-type-long ?s)
2923 (?n gnus-tmp-name ?s)
2924 (?d gnus-tmp-description ?s)
2926 (?l gnus-tmp-length ?d)
2927 (?e gnus-tmp-dots ?s)))
2929 (defvar gnus-mime-button-commands
2930 '((gnus-article-press-button "\r" "Toggle Display")
2931 (gnus-mime-view-part "v" "View Interactively...")
2932 (gnus-mime-view-part-as-type "t" "View As Type...")
2933 (gnus-mime-save-part "o" "Save...")
2934 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2935 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2936 (gnus-mime-internalize-part "E" "View Internally")
2937 (gnus-mime-externalize-part "e" "View Externally")
2938 (gnus-mime-pipe-part "|" "Pipe To Command...")
2939 (gnus-mime-action-on-part "." "Take action on the part")))
2941 (defun gnus-article-mime-part-status ()
2942 (if gnus-article-mime-handle-alist-1
2943 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2946 (defvar gnus-mime-button-map
2947 (let ((map (make-sparse-keymap)))
2948 (set-keymap-parent map gnus-article-mode-map)
2949 (define-key map gnus-mouse-2 'gnus-article-push-button)
2950 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2951 (dolist (c gnus-mime-button-commands)
2952 (define-key map (cadr c) (car c)))
2955 (defun gnus-mime-button-menu (event)
2956 "Construct a context-sensitive menu of MIME commands."
2958 (save-window-excursion
2959 (let ((pos (event-start event)))
2960 (select-window (posn-window pos))
2961 (goto-char (posn-point pos))
2962 (gnus-article-check-buffer)
2963 (let ((response (x-popup-menu
2965 ("" ,@(mapcar (lambda (c)
2966 (cons (caddr c) (car c)))
2967 gnus-mime-button-commands))))))
2969 (call-interactively response))))))
2971 (defun gnus-mime-view-all-parts (&optional handles)
2972 "View all the MIME parts."
2974 (save-current-buffer
2975 (set-buffer gnus-article-buffer)
2976 (let ((handles (or handles gnus-article-mime-handles))
2977 (mail-parse-charset gnus-newsgroup-charset)
2978 (mail-parse-ignored-charsets
2979 (save-excursion (set-buffer gnus-summary-buffer)
2980 gnus-newsgroup-ignored-charsets)))
2981 (if (stringp (car handles))
2982 (gnus-mime-view-all-parts (cdr handles))
2983 (mapcar 'mm-display-part handles)))))
2985 (defun gnus-mime-save-part ()
2986 "Save the MIME part under point."
2988 (gnus-article-check-buffer)
2989 (let ((data (get-text-property (point) 'gnus-data)))
2991 (mm-save-part data))))
2993 (defun gnus-mime-pipe-part ()
2994 "Pipe the MIME part under point to a process."
2996 (gnus-article-check-buffer)
2997 (let ((data (get-text-property (point) 'gnus-data)))
2999 (mm-pipe-part data))))
3001 (defun gnus-mime-view-part ()
3002 "Interactively choose a viewing method for the MIME part under point."
3004 (gnus-article-check-buffer)
3005 (let ((data (get-text-property (point) 'gnus-data)))
3007 (mm-interactively-view-part data))))
3009 (defun gnus-mime-view-part-as-type-internal ()
3010 (gnus-article-check-buffer)
3011 (let* ((name (mail-content-type-get
3012 (mm-handle-type (get-text-property (point) 'gnus-data))
3014 (def-type (and name (mm-default-file-encoding name))))
3015 (and def-type (cons def-type 0))))
3017 (defun gnus-mime-view-part-as-type (mime-type)
3018 "Choose a MIME media type, and view the part as such."
3020 (list (completing-read
3021 "View as MIME type: "
3022 (mapcar #'list (mailcap-mime-types))
3024 (gnus-mime-view-part-as-type-internal))))
3025 (gnus-article-check-buffer)
3026 (let ((handle (get-text-property (point) 'gnus-data)))
3028 (gnus-mm-display-part
3029 (mm-make-handle (mm-handle-buffer handle)
3030 (cons mime-type (cdr (mm-handle-type handle)))
3031 (mm-handle-encoding handle)
3032 (mm-handle-undisplayer handle)
3033 (mm-handle-disposition handle)
3034 (mm-handle-description handle)
3035 (mm-handle-cache handle)
3036 (mm-handle-id handle))))))
3038 (defun gnus-mime-copy-part (&optional handle)
3039 "Put the the MIME part under point into a new buffer."
3041 (gnus-article-check-buffer)
3042 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3043 (contents (and handle (mm-get-part handle)))
3045 (file-name-nondirectory
3047 (mail-content-type-get (mm-handle-type handle) 'name)
3048 (mail-content-type-get (mm-handle-type handle)
3051 (buffer (and base (generate-new-buffer base))))
3053 (switch-to-buffer buffer)
3055 ;; We do it this way to make `normal-mode' set the appropriate mode.
3058 (setq buffer-file-name (expand-file-name base))
3060 (setq buffer-file-name nil))
3061 (goto-char (point-min)))))
3063 (defun gnus-mime-inline-part (&optional handle arg)
3064 "Insert the MIME part under point into the current buffer."
3065 (interactive (list nil current-prefix-arg))
3066 (gnus-article-check-buffer)
3067 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3072 (if (and (not arg) (mm-handle-undisplayer handle))
3073 (mm-remove-part handle)
3074 (setq contents (mm-get-part handle))
3077 (setq charset (or (mail-content-type-get
3078 (mm-handle-type handle) 'charset)
3079 gnus-newsgroup-charset)))
3081 (if (mm-handle-undisplayer handle)
3082 (mm-remove-part handle))
3085 gnus-summary-show-article-charset-alist))
3086 (read-coding-system "Charset: ")))))
3088 (mm-insert-inline handle
3090 (setq charset (mm-charset-to-coding-system
3092 (not (eq charset 'ascii)))
3093 (mm-decode-coding-string contents charset)
3097 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3098 "Insert the MIME part under point into the current buffer."
3099 (interactive (list nil current-prefix-arg))
3100 (gnus-article-check-buffer)
3101 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3106 (if (mm-handle-undisplayer handle)
3107 (mm-remove-part handle))
3108 (let ((gnus-newsgroup-charset
3110 gnus-summary-show-article-charset-alist))
3111 (read-coding-system "Charset: ")))
3112 (gnus-newsgroup-ignored-charsets 'gnus-all))
3113 (gnus-article-press-button)))))
3115 (defun gnus-mime-externalize-part (&optional handle)
3116 "View the MIME part under point with an external viewer."
3118 (gnus-article-check-buffer)
3119 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3120 (mm-user-display-methods nil)
3121 (mm-inlined-types nil)
3122 (mail-parse-charset gnus-newsgroup-charset)
3123 (mail-parse-ignored-charsets
3124 (save-excursion (set-buffer gnus-summary-buffer)
3125 gnus-newsgroup-ignored-charsets)))
3127 (if (mm-handle-undisplayer handle)
3128 (mm-remove-part handle)
3129 (mm-display-part handle)))))
3131 (defun gnus-mime-internalize-part (&optional handle)
3132 "View the MIME part under point with an internal viewer.
3133 In no internal viewer is available, use an external viewer."
3135 (gnus-article-check-buffer)
3136 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3137 (mm-inlined-types '(".*"))
3138 (mm-inline-large-images t)
3139 (mail-parse-charset gnus-newsgroup-charset)
3140 (mail-parse-ignored-charsets
3141 (save-excursion (set-buffer gnus-summary-buffer)
3142 gnus-newsgroup-ignored-charsets)))
3144 (if (mm-handle-undisplayer handle)
3145 (mm-remove-part handle)
3146 (mm-display-part handle)))))
3148 (defun gnus-mime-action-on-part (&optional action)
3149 "Do something with the MIME attachment at \(point\)."
3151 (list (completing-read "Action: " gnus-mime-action-alist)))
3152 (gnus-article-check-buffer)
3153 (let ((action-pair (assoc action gnus-mime-action-alist)))
3155 (funcall (cdr action-pair)))))
3157 (defun gnus-article-part-wrapper (n function)
3158 (save-current-buffer
3159 (set-buffer gnus-article-buffer)
3160 (when (> n (length gnus-article-mime-handle-alist))
3161 (error "No such part"))
3162 (gnus-article-goto-part n)
3163 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3164 (funcall function handle))))
3166 (defun gnus-article-pipe-part (n)
3167 "Pipe MIME part N, which is the numerical prefix."
3169 (gnus-article-part-wrapper n 'mm-pipe-part))
3171 (defun gnus-article-save-part (n)
3172 "Save MIME part N, which is the numerical prefix."
3174 (gnus-article-part-wrapper n 'mm-save-part))
3176 (defun gnus-article-interactively-view-part (n)
3177 "View MIME part N interactively, which is the numerical prefix."
3179 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3181 (defun gnus-article-copy-part (n)
3182 "Copy MIME part N, which is the numerical prefix."
3184 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3186 (defun gnus-article-externalize-part (n)
3187 "View MIME part N externally, which is the numerical prefix."
3189 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3191 (defun gnus-article-inline-part (n)
3192 "Inline MIME part N, which is the numerical prefix."
3194 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3196 (defun gnus-article-mime-match-handle-first (condition)
3198 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3199 (while (setq ihandle (pop alist))
3201 ((functionp condition)
3202 (funcall condition (cdr ihandle)))
3203 ((eq condition 'undisplayed)
3204 (not (or (mm-handle-undisplayer (cdr ihandle))
3205 (equal (mm-handle-media-type (cdr ihandle))
3206 "multipart/alternative"))))
3207 ((eq condition 'undisplayed-alternative)
3208 (not (mm-handle-undisplayer (cdr ihandle))))
3210 (gnus-article-goto-part (car ihandle))
3211 (or (not n) (< (car ihandle) n)))
3212 (setq n (car ihandle))))
3216 (defun gnus-article-view-part (&optional n)
3217 "View MIME part N, which is the numerical prefix."
3219 (save-current-buffer
3220 (set-buffer gnus-article-buffer)
3221 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3222 gnus-article-mime-match-handle-function)))
3223 (when (> n (length gnus-article-mime-handle-alist))
3224 (error "No such part"))
3225 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3226 (when (gnus-article-goto-part n)
3227 (if (equal (car handle) "multipart/alternative")
3228 (gnus-article-press-button)
3229 (when (eq (gnus-mm-display-part handle) 'internal)
3230 (gnus-set-window-start)))))))
3232 (defsubst gnus-article-mime-total-parts ()
3233 (if (bufferp (car gnus-article-mime-handles))
3235 (1- (length gnus-article-mime-handles))))
3237 (defun gnus-mm-display-part (handle)
3238 "Display HANDLE and fix MIME button."
3239 (let ((id (get-text-property (point) 'gnus-part))
3244 (let ((window (selected-window))
3245 (mail-parse-charset gnus-newsgroup-charset)
3246 (mail-parse-ignored-charsets
3247 (save-excursion (set-buffer gnus-summary-buffer)
3248 gnus-newsgroup-ignored-charsets)))
3251 (let ((win (get-buffer-window (current-buffer) t))
3254 (select-window win))
3257 (if (mm-handle-displayed-p handle)
3258 ;; This will remove the part.
3259 (mm-display-part handle)
3261 (narrow-to-region (point) (1+ (point)))
3262 (mm-display-part handle)
3263 ;; We narrow to the part itself and
3264 ;; then call the treatment functions.
3265 (goto-char (point-min))
3267 (narrow-to-region (point) (point-max))
3270 (gnus-article-mime-total-parts)
3271 (mm-handle-media-type handle)))))
3272 (select-window window))))
3274 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3275 (gnus-insert-mime-button
3276 handle id (list (mm-handle-displayed-p handle)))
3277 (goto-char point))))
3279 (defun gnus-article-goto-part (n)
3280 "Go to MIME part N."
3281 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3283 (goto-char point))))
3285 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3286 (let ((gnus-tmp-name
3287 (or (mail-content-type-get (mm-handle-type handle)
3289 (mail-content-type-get (mm-handle-disposition handle)
3292 (gnus-tmp-type (mm-handle-media-type handle))
3293 (gnus-tmp-description
3294 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3297 (if (if displayed (car displayed)
3298 (mm-handle-displayed-p handle))
3300 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3302 gnus-tmp-type-long b e)
3303 (when (string-match ".*/" gnus-tmp-name)
3304 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3305 (setq gnus-tmp-type-long (concat gnus-tmp-type
3306 (and (not (equal gnus-tmp-name ""))
3307 (concat "; " gnus-tmp-name))))
3308 (or (equal gnus-tmp-description "")
3309 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3314 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3315 `(local-map ,gnus-mime-button-map
3316 keymap ,gnus-mime-button-map
3317 gnus-callback gnus-mm-display-part
3318 gnus-part ,gnus-tmp-id
3319 article-type annotation
3322 (widget-convert-button
3325 :action 'gnus-widget-press-button
3326 :button-keymap gnus-mime-button-map
3328 (lambda (widget/window &optional overlay pos)
3329 ;; Needed to properly clear the message due to a bug in
3330 ;; wid-edit (XEmacs only).
3331 (if (boundp 'help-echo-owns-message)
3332 (setq help-echo-owns-message t))
3334 "%S: %s the MIME part; %S: more options"
3335 (aref gnus-mouse-2 0)
3336 ;; XEmacs will get a single widget arg; Emacs 21 will get
3337 ;; window, overlay, position.
3338 (if (mm-handle-displayed-p
3340 (with-current-buffer (gnus-overlay-buffer overlay)
3341 (widget-get (widget-at (gnus-overlay-start overlay))
3343 (widget-get widget/window :mime-handle)))
3345 (aref gnus-down-mouse-3 0))))))
3347 (defun gnus-widget-press-button (elems el)
3348 (goto-char (widget-get elems :from))
3349 (gnus-article-press-button))
3351 (defvar gnus-displaying-mime nil)
3353 (defun gnus-display-mime (&optional ihandles)
3354 "Display the MIME parts."
3356 (save-selected-window
3357 (let ((window (get-buffer-window gnus-article-buffer))
3360 (select-window window)
3361 ;; We have to do this since selecting the window
3362 ;; may change the point. So we set the window point.
3363 (set-window-point window point)))
3364 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3365 buffer-read-only handle name type b e display)
3366 (when (and (not ihandles)
3367 (not gnus-displaying-mime))
3368 ;; Top-level call; we clean up.
3369 (when gnus-article-mime-handles
3370 (mm-destroy-parts gnus-article-mime-handles)
3371 (setq gnus-article-mime-handle-alist nil));; A trick.
3372 (setq gnus-article-mime-handles handles)
3373 ;; We allow users to glean info from the handles.
3374 (when gnus-article-mime-part-function
3375 (gnus-mime-part-function handles)))
3377 (or (not (stringp (car handles)))
3380 (when (and (not ihandles)
3381 (not gnus-displaying-mime))
3382 ;; Clean up for mime parts.
3384 (delete-region (point) (point-max)))
3385 (let ((gnus-displaying-mime t))
3386 (gnus-mime-display-part handles)))
3389 (narrow-to-region (point) (point-max))
3390 (gnus-treat-article nil 1 1)
3393 ;; Highlight the headers.
3397 (narrow-to-region (point-min) (point))
3398 (gnus-treat-article 'head))))))))
3400 (defvar gnus-mime-display-multipart-as-mixed nil)
3402 (defun gnus-mime-display-part (handle)
3405 ((not (stringp (car handle)))
3406 (gnus-mime-display-single handle))
3407 ;; User-defined multipart
3408 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3409 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3411 ;; multipart/alternative
3412 ((and (equal (car handle) "multipart/alternative")
3413 (not gnus-mime-display-multipart-as-mixed))
3414 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3415 (push (cons id handle) gnus-article-mime-handle-alist)
3416 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3417 ;; multipart/related
3418 ((and (equal (car handle) "multipart/related")
3419 (not gnus-mime-display-multipart-as-mixed))
3420 ;;;!!!We should find the start part, but we just default
3421 ;;;!!!to the first part.
3422 (gnus-mime-display-part (cadr handle)))
3423 ;; Other multiparts are handled like multipart/mixed.
3425 (gnus-mime-display-mixed (cdr handle)))))
3427 (defun gnus-mime-part-function (handles)
3428 (if (stringp (car handles))
3429 (mapcar 'gnus-mime-part-function (cdr handles))
3430 (funcall gnus-article-mime-part-function handles)))
3432 (defun gnus-mime-display-mixed (handles)
3433 (mapcar 'gnus-mime-display-part handles))
3435 (defun gnus-mime-display-single (handle)
3436 (let ((type (mm-handle-media-type handle))
3437 (ignored gnus-ignored-mime-types)
3444 (when (string-match (pop ignored) type)
3445 (throw 'ignored nil)))
3446 (if (and (setq not-attachment
3447 (and (not (mm-inline-override-p handle))
3448 (or (not (mm-handle-disposition handle))
3449 (equal (car (mm-handle-disposition handle))
3451 (mm-attachment-override-p handle))))
3452 (mm-automatic-display-p handle)
3453 (or (mm-inlined-p handle)
3454 (mm-automatic-external-display-p type)))
3456 (when (equal (mm-handle-media-supertype handle) "text")
3458 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3460 (push (cons id handle) gnus-article-mime-handle-alist)
3461 (when (or (not display)
3462 (not (gnus-unbuttonized-mime-type-p type)))
3463 ;(gnus-article-insert-newline)
3464 (gnus-insert-mime-button
3465 handle id (list (or display (and not-attachment text))))
3466 (gnus-article-insert-newline)
3467 ;(gnus-article-insert-newline)
3468 ;; Remember modify the number of forward lines.
3476 (let ((mail-parse-charset gnus-newsgroup-charset)
3477 (mail-parse-ignored-charsets
3478 (save-excursion (condition-case ()
3479 (set-buffer gnus-summary-buffer)
3481 gnus-newsgroup-ignored-charsets)))
3482 (mm-display-part handle t))
3483 (goto-char (point-max)))
3484 ((and text not-attachment)
3488 (gnus-article-insert-newline)
3489 (mm-insert-inline handle (mm-get-part handle))
3490 (goto-char (point-max))))
3494 (narrow-to-region beg (point))
3497 (gnus-article-mime-total-parts)
3498 (mm-handle-media-type handle)))))))))
3500 (defun gnus-unbuttonized-mime-type-p (type)
3501 "Say whether TYPE is to be unbuttonized."
3502 (unless gnus-inhibit-mime-unbuttonizing
3504 (let ((types gnus-unbuttonized-mime-types))
3506 (when (string-match (pop types) type)
3507 (throw 'found t)))))))
3509 (defun gnus-article-insert-newline ()
3510 "Insert a newline, but mark it as undeletable."
3511 (gnus-put-text-property
3512 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3514 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3515 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3518 handle buffer-read-only from props begend not-pref)
3519 (save-window-excursion
3522 (narrow-to-region (car ibegend)
3525 (goto-char (car ibegend))
3528 (delete-region (point-min) (point-max))
3529 (mm-remove-parts handles))
3530 (setq begend (list (point-marker)))
3532 (unless (setq not-pref (cadr (member preferred ihandles)))
3533 (setq not-pref (car ihandles)))
3536 (not (gnus-unbuttonized-mime-type-p
3537 "multipart/alternative")))
3538 (gnus-add-text-properties
3541 (insert (format "%d. " id))
3545 (unless ,(not ibegend)
3546 (setq gnus-article-mime-handle-alist
3547 ',gnus-article-mime-handle-alist))
3548 (gnus-mime-display-alternative
3549 ',ihandles ',not-pref ',begend ,id))
3550 local-map ,gnus-mime-button-map
3551 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3552 face ,gnus-article-button-face
3553 keymap ,gnus-mime-button-map
3556 (widget-convert-button 'link from (point)
3557 :action 'gnus-widget-press-button
3558 :button-keymap gnus-widget-button-keymap)
3560 (while (setq handle (pop handles))
3561 (gnus-add-text-properties
3564 (insert (format "(%c) %-18s"
3565 (if (equal handle preferred) ?* ? )
3566 (mm-handle-media-type handle)))
3570 (unless ,(not ibegend)
3571 (setq gnus-article-mime-handle-alist
3572 ',gnus-article-mime-handle-alist))
3573 (gnus-mime-display-alternative
3574 ',ihandles ',handle ',begend ,id))
3575 local-map ,gnus-mime-button-map
3576 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3577 face ,gnus-article-button-face
3578 keymap ,gnus-mime-button-map
3581 (widget-convert-button 'link from (point)
3582 :action 'gnus-widget-press-button
3583 :button-keymap gnus-widget-button-keymap)
3587 (if (stringp (car preferred))
3588 (gnus-display-mime preferred)
3589 (let ((mail-parse-charset gnus-newsgroup-charset)
3590 (mail-parse-ignored-charsets
3591 (save-excursion (set-buffer gnus-summary-buffer)
3592 gnus-newsgroup-ignored-charsets)))
3593 (mm-display-part preferred)
3597 (narrow-to-region (car begend) (point-max))
3599 nil (length gnus-article-mime-handle-alist)
3600 (gnus-article-mime-total-parts)
3601 (mm-handle-media-type handle))))))
3602 (goto-char (point-max))
3603 (setcdr begend (point-marker)))))
3605 (goto-char point))))
3607 (defun gnus-article-wash-status ()
3608 "Return a string which display status of article washing."
3610 (set-buffer gnus-article-buffer)
3611 (let ((cite (memq 'cite gnus-article-wash-types))
3612 (headers (memq 'headers gnus-article-wash-types))
3613 (boring (memq 'boring-headers gnus-article-wash-types))
3614 (pgp (memq 'pgp gnus-article-wash-types))
3615 (pem (memq 'pem gnus-article-wash-types))
3616 (signature (memq 'signature gnus-article-wash-types))
3617 (overstrike (memq 'overstrike gnus-article-wash-types))
3618 (emphasis (memq 'emphasis gnus-article-wash-types)))
3619 (format "%c%c%c%c%c%c"
3621 (if (or headers boring) ?h ? )
3622 (if (or pgp pem) ?p ? )
3623 (if signature ?s ? )
3624 (if overstrike ?o ? )
3625 (if emphasis ?e ? )))))
3627 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3629 (defun gnus-article-maybe-hide-headers ()
3630 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3631 Provided for backwards compatibility."
3632 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3633 (not (save-excursion (set-buffer gnus-summary-buffer)
3634 gnus-have-all-headers)))
3635 (not gnus-inhibit-hiding))
3636 (gnus-article-hide-headers)))
3640 (defun gnus-output-to-file (file-name)
3641 "Append the current article to a file named FILE-NAME."
3642 (let ((artbuf (current-buffer)))
3644 (insert-buffer-substring artbuf)
3645 ;; Append newline at end of the buffer as separator, and then
3647 (goto-char (point-max))
3649 (mm-append-to-file (point-min) (point-max) file-name)
3652 (defun gnus-narrow-to-page (&optional arg)
3653 "Narrow the article buffer to a page.
3654 If given a numerical ARG, move forward ARG pages."
3656 (setq arg (if arg (prefix-numeric-value arg) 0))
3658 (set-buffer gnus-article-buffer)
3659 (goto-char (point-min))
3661 ;; Remove any old next/prev buttons.
3662 (when (gnus-visual-p 'page-marker)
3663 (let ((buffer-read-only nil))
3664 (gnus-remove-text-with-property 'gnus-prev)
3665 (gnus-remove-text-with-property 'gnus-next)))
3668 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3670 (re-search-forward page-delimiter nil 'move arg)))
3671 (goto-char (match-end 0)))
3674 (if (re-search-forward page-delimiter nil 'move)
3677 (when (and (gnus-visual-p 'page-marker)
3678 (not (= (point-min) 1)))
3680 (goto-char (point-min))
3681 (gnus-insert-prev-page-button)))
3682 (when (and (gnus-visual-p 'page-marker)
3683 (< (+ (point-max) 2) (buffer-size)))
3685 (goto-char (point-max))
3686 (gnus-insert-next-page-button)))))
3688 ;; Article mode commands
3690 (defun gnus-article-goto-next-page ()
3691 "Show the next page of the article."
3693 (when (gnus-article-next-page)
3694 (goto-char (point-min))
3695 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3697 (defun gnus-article-goto-prev-page ()
3698 "Show the next page of the article."
3700 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3701 (gnus-article-prev-page nil)))
3703 (defun gnus-article-next-page (&optional lines)
3704 "Show the next page of the current article.
3705 If end of article, return non-nil. Otherwise return nil.
3706 Argument LINES specifies lines to be scrolled up."
3708 (move-to-window-line -1)
3711 (and (pos-visible-in-window-p) ;Not continuation line.
3713 ;; Nothing in this page.
3714 (if (or (not gnus-page-broken)
3717 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3719 (gnus-narrow-to-page 1) ;Go to next page.
3721 ;; More in this page.
3722 (let ((scroll-in-place nil))
3726 ;; Long lines may cause an end-of-buffer error.
3727 (goto-char (point-max)))))
3728 (move-to-window-line 0)
3731 (defun gnus-article-prev-page (&optional lines)
3732 "Show previous page of current article.
3733 Argument LINES specifies lines to be scrolled down."
3735 (move-to-window-line 0)
3736 (if (and gnus-page-broken
3738 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3740 (gnus-narrow-to-page -1) ;Go to previous page.
3741 (goto-char (point-max))
3743 (let ((scroll-in-place nil))
3747 (beginning-of-buffer
3748 (goto-char (point-min))))
3749 (move-to-window-line 0)))))
3751 (defun gnus-article-refer-article ()
3752 "Read article specified by message-id around point."
3754 (let ((point (point)))
3755 (search-forward ">" nil t) ;Move point to end of "<....>".
3756 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3757 (let ((message-id (match-string 1)))
3759 (set-buffer gnus-summary-buffer)
3760 (gnus-summary-refer-article message-id))
3762 (error "No references around point"))))
3764 (defun gnus-article-show-summary ()
3765 "Reconfigure windows to show summary buffer."
3767 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3768 (error "There is no summary buffer for this article buffer")
3769 (gnus-article-set-globals)
3770 (gnus-configure-windows 'article)
3771 (gnus-summary-goto-subject gnus-current-article)
3772 (gnus-summary-position-point)))
3774 (defun gnus-article-describe-briefly ()
3775 "Describe article mode commands briefly."
3777 (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")))
3779 (defun gnus-article-summary-command ()
3780 "Execute the last keystroke in the summary buffer."
3782 (let ((obuf (current-buffer))
3783 (owin (current-window-configuration))
3785 (switch-to-buffer gnus-article-current-summary 'norecord)
3786 (setq func (lookup-key (current-local-map) (this-command-keys)))
3787 (call-interactively func)
3789 (set-window-configuration owin)
3790 (set-window-point (get-buffer-window (current-buffer)) (point))))
3792 (defun gnus-article-summary-command-nosave ()
3793 "Execute the last keystroke in the summary buffer."
3796 (pop-to-buffer gnus-article-current-summary 'norecord)
3797 (setq func (lookup-key (current-local-map) (this-command-keys)))
3798 (call-interactively func)))
3800 (defun gnus-article-check-buffer ()
3801 "Beep if not in an article buffer."
3802 (unless (equal major-mode 'gnus-article-mode)
3803 (error "Command invoked outside of a Gnus article buffer")))
3805 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3806 "Read a summary buffer key sequence and execute it from the article buffer."
3808 (gnus-article-check-buffer)
3810 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3811 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3812 "=" "^" "\M-^" "|"))
3818 '("n" "Gn" "p" "Gp"))
3821 (set-buffer gnus-article-current-summary)
3822 (let (gnus-pick-mode)
3823 (push (or key last-command-event) unread-command-events)
3824 (setq keys (if (featurep 'xemacs)
3825 (events-to-keys (read-key-sequence nil))
3826 (read-key-sequence nil)))))
3830 (if (or (member keys nosaves)
3831 (member keys nosave-but-article)
3832 (member keys nosave-in-article))
3834 (save-window-excursion
3835 (pop-to-buffer gnus-article-current-summary 'norecord)
3836 ;; We disable the pick minor mode commands.
3837 (let (gnus-pick-mode)
3838 (setq func (lookup-key (current-local-map) keys))))
3842 (unless (member keys nosave-in-article)
3843 (set-buffer gnus-article-current-summary))
3844 (call-interactively func)
3845 (setq new-sum-point (point)))
3846 (when (member keys nosave-but-article)
3847 (pop-to-buffer gnus-article-buffer 'norecord)))
3848 ;; These commands should restore window configuration.
3849 (let ((obuf (current-buffer))
3850 (owin (current-window-configuration))
3852 (summary gnus-article-current-summary)
3853 func in-buffer selected)
3854 (if not-restore-window
3855 (pop-to-buffer summary 'norecord)
3856 (switch-to-buffer summary 'norecord))
3857 (setq in-buffer (current-buffer))
3858 ;; We disable the pick minor mode commands.
3859 (if (and (setq func (let (gnus-pick-mode)
3860 (lookup-key (current-local-map) keys)))
3863 (call-interactively func)
3864 (setq new-sum-point (point))
3865 (when (eq in-buffer (current-buffer))
3866 (setq selected (gnus-summary-select-article))
3868 (unless not-restore-window
3869 (set-window-configuration owin))
3870 (when (eq selected 'old)
3872 (set-window-start (get-buffer-window (current-buffer))
3874 (set-window-point (get-buffer-window (current-buffer))
3876 (let ((win (get-buffer-window gnus-article-current-summary)))
3878 (set-window-point win new-sum-point)))) )
3879 (switch-to-buffer gnus-article-buffer)
3882 (defun gnus-article-describe-key (key)
3883 "Display documentation of the function invoked by KEY. KEY is a string."
3884 (interactive "kDescribe key: ")
3885 (gnus-article-check-buffer)
3886 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
3888 (set-buffer gnus-article-current-summary)
3889 (let (gnus-pick-mode)
3890 (push (elt key 0) unread-command-events)
3891 (setq key (if (featurep 'xemacs)
3892 (events-to-keys (read-key-sequence "Describe key: "))
3893 (read-key-sequence "Describe key: "))))
3895 (describe-key key)))
3897 (defun gnus-article-describe-key-briefly (key &optional insert)
3898 "Display documentation of the function invoked by KEY. KEY is a string."
3899 (interactive "kDescribe key: \nP")
3900 (gnus-article-check-buffer)
3901 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
3903 (set-buffer gnus-article-current-summary)
3904 (let (gnus-pick-mode)
3905 (push (elt key 0) unread-command-events)
3906 (setq key (if (featurep 'xemacs)
3907 (events-to-keys (read-key-sequence "Describe key: "))
3908 (read-key-sequence "Describe key: "))))
3909 (describe-key-briefly key insert))
3910 (describe-key-briefly key insert)))
3912 (defun gnus-article-hide (&optional arg force)
3913 "Hide all the gruft in the current article.
3914 This means that PGP stuff, signatures, cited text and (some)
3915 headers will be hidden.
3916 If given a prefix, show the hidden text instead."
3917 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3918 (gnus-article-hide-headers arg)
3919 (gnus-article-hide-list-identifiers arg)
3920 (gnus-article-hide-pgp arg)
3921 (gnus-article-hide-citation-maybe arg force)
3922 (gnus-article-hide-signature arg))
3924 (defun gnus-article-maybe-highlight ()
3925 "Do some article highlighting if article highlighting is requested."
3926 (when (gnus-visual-p 'article-highlight 'highlight)
3927 (gnus-article-highlight-some)))
3929 (defun gnus-check-group-server ()
3930 ;; Make sure the connection to the server is alive.
3931 (unless (gnus-server-opened
3932 (gnus-find-method-for-group gnus-newsgroup-name))
3933 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3934 (gnus-request-group gnus-newsgroup-name t)))
3936 (defun gnus-request-article-this-buffer (article group)
3937 "Get an article and insert it into this buffer."
3938 (let (do-update-line sparse-header)
3942 (gnus-kill-all-overlays)
3943 (setq group (or group gnus-newsgroup-name))
3945 ;; Using `gnus-request-article' directly will insert the article into
3946 ;; `nntp-server-buffer' - so we'll save some time by not having to
3947 ;; copy it from the server buffer into the article buffer.
3949 ;; We only request an article by message-id when we do not have the
3950 ;; headers for it, so we'll have to get those.
3951 (when (stringp article)
3952 (gnus-read-header article))
3954 ;; If the article number is negative, that means that this article
3955 ;; doesn't belong in this newsgroup (possibly), so we find its
3956 ;; message-id and request it by id instead of number.
3957 (when (and (numberp article)
3959 (get-buffer gnus-summary-buffer)
3960 (gnus-buffer-exists-p gnus-summary-buffer))
3962 (set-buffer gnus-summary-buffer)
3963 (let ((header (gnus-summary-article-header article)))
3966 ((memq article gnus-newsgroup-sparse)
3967 ;; This is a sparse gap article.
3968 (setq do-update-line article)
3969 (setq article (mail-header-id header))
3970 (setq sparse-header (gnus-read-header article))
3971 (setq gnus-newsgroup-sparse
3972 (delq article gnus-newsgroup-sparse)))
3974 ;; It's a real article.
3975 (setq article (mail-header-id header)))
3977 ;; It is an extracted pseudo-article.
3978 (setq article 'pseudo)
3979 (gnus-request-pseudo-article header))))
3981 (let ((method (gnus-find-method-for-group
3982 gnus-newsgroup-name)))
3983 (when (and (eq (car method) 'nneething)
3985 (let ((dir (expand-file-name
3986 (mail-header-subject header)
3987 (file-name-as-directory
3988 (or (cadr (assq 'nneething-address method))
3990 (when (file-directory-p dir)
3991 (setq article 'nneething)
3992 (gnus-group-enter-directory dir))))))))
3995 ;; Refuse to select canceled articles.
3996 ((and (numberp article)
3998 (get-buffer gnus-summary-buffer)
3999 (gnus-buffer-exists-p gnus-summary-buffer)
4000 (eq (cdr (save-excursion
4001 (set-buffer gnus-summary-buffer)
4002 (assq article gnus-newsgroup-reads)))
4003 gnus-canceled-mark))
4005 ;; We first check `gnus-original-article-buffer'.
4006 ((and (get-buffer gnus-original-article-buffer)
4009 (set-buffer gnus-original-article-buffer)
4010 (and (equal (car gnus-original-article) group)
4011 (eq (cdr gnus-original-article) article))))
4012 (insert-buffer-substring gnus-original-article-buffer)
4014 ;; Check the backlog.
4015 ((and gnus-keep-backlog
4016 (gnus-backlog-request-article group article (current-buffer)))
4018 ;; Check asynchronous pre-fetch.
4019 ((gnus-async-request-fetched-article group article (current-buffer))
4020 (gnus-async-prefetch-next group article gnus-summary-buffer)
4021 (when (and (numberp article) gnus-keep-backlog)
4022 (gnus-backlog-enter-article group article (current-buffer)))
4025 ((and gnus-use-cache
4027 (gnus-cache-request-article article group))
4029 ;; Get the article and put into the article buffer.
4030 ((or (stringp article)
4032 (let ((gnus-override-method gnus-override-method)
4033 (methods (and (stringp article)
4034 gnus-refer-article-method))
4036 (buffer-read-only nil))
4037 (if (or (not (listp methods))
4038 (and (symbolp (car methods))
4039 (assq (car methods) nnoo-definition-alist)))
4040 (setq methods (list methods)))
4041 (when (and (null gnus-override-method)
4043 (setq gnus-override-method (pop methods)))
4045 (when (eq gnus-override-method 'current)
4046 (setq gnus-override-method gnus-current-select-method))
4048 (gnus-kill-all-overlays)
4049 (let ((gnus-newsgroup-name group))
4050 (gnus-check-group-server))
4051 (when (gnus-request-article article group (current-buffer))
4052 (when (numberp article)
4053 (gnus-async-prefetch-next group article
4054 gnus-summary-buffer)
4055 (when gnus-keep-backlog
4056 (gnus-backlog-enter-article
4057 group article (current-buffer))))
4058 (setq result 'article))
4061 (setq gnus-override-method (pop methods))
4062 (setq result 'done))))
4063 (and (eq result 'article) 'article)))
4067 ;; Associate this article with the current summary buffer.
4068 (setq gnus-article-current-summary gnus-summary-buffer)
4070 ;; Take the article from the original article buffer
4071 ;; and place it in the buffer it's supposed to be in.
4072 (when (and (get-buffer gnus-article-buffer)
4073 (equal (buffer-name (current-buffer))
4074 (buffer-name (get-buffer gnus-article-buffer))))
4076 (if (get-buffer gnus-original-article-buffer)
4077 (set-buffer gnus-original-article-buffer)
4078 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4079 (buffer-disable-undo)
4080 (setq major-mode 'gnus-original-article-mode)
4081 (setq buffer-read-only t))
4082 (let (buffer-read-only)
4084 (insert-buffer-substring gnus-article-buffer))
4085 (setq gnus-original-article (cons group article)))
4088 (run-hooks 'gnus-article-decode-hook)
4089 ;; Mark article as decoded or not.
4090 (setq gnus-article-decoded-p gnus-article-decode-hook))
4092 ;; Update sparse articles.
4093 (when (and do-update-line
4094 (or (numberp article)
4096 (let ((buf (current-buffer)))
4097 (set-buffer gnus-summary-buffer)
4098 (gnus-summary-update-article do-update-line sparse-header)
4099 (gnus-summary-goto-subject do-update-line nil t)
4100 (set-window-point (get-buffer-window (current-buffer) t)
4102 (set-buffer buf))))))
4108 (defcustom gnus-article-edit-mode-hook nil
4109 "Hook run in article edit mode buffers."
4110 :group 'gnus-article-various
4113 (defvar gnus-article-edit-done-function nil)
4115 (defvar gnus-article-edit-mode-map nil)
4117 ;; Should we be using derived.el for this?
4118 (unless gnus-article-edit-mode-map
4119 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4120 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4122 (gnus-define-keys gnus-article-edit-mode-map
4123 "\C-c\C-c" gnus-article-edit-done
4124 "\C-c\C-k" gnus-article-edit-exit)
4126 (gnus-define-keys (gnus-article-edit-wash-map
4127 "\C-c\C-w" gnus-article-edit-mode-map)
4128 "f" gnus-article-edit-full-stops))
4130 (defun gnus-article-edit-mode ()
4131 "Major mode for editing articles.
4132 This is an extended text-mode.
4134 \\{gnus-article-edit-mode-map}"
4136 (setq major-mode 'gnus-article-edit-mode)
4137 (setq mode-name "Article Edit")
4138 (use-local-map gnus-article-edit-mode-map)
4139 (make-local-variable 'gnus-article-edit-done-function)
4140 (make-local-variable 'gnus-prev-winconf)
4141 (setq buffer-read-only nil)
4142 (buffer-enable-undo)
4144 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4146 (defun gnus-article-edit (&optional force)
4147 "Edit the current article.
4148 This will have permanent effect only in mail groups.
4149 If FORCE is non-nil, allow editing of articles even in read-only
4152 (when (and (not force)
4153 (gnus-group-read-only-p))
4154 (error "The current newsgroup does not support article editing"))
4155 (gnus-article-date-original)
4156 (gnus-article-edit-article
4158 `(lambda (no-highlight)
4160 (gnus-summary-edit-article-done
4161 ,(or (mail-header-references gnus-current-headers) "")
4162 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4164 (defun gnus-article-edit-article (start-func exit-func)
4165 "Start editing the contents of the current article buffer."
4166 (let ((winconf (current-window-configuration)))
4167 (set-buffer gnus-article-buffer)
4168 (gnus-article-edit-mode)
4169 (funcall start-func)
4170 (gnus-configure-windows 'edit-article)
4171 (setq gnus-article-edit-done-function exit-func)
4172 (setq gnus-prev-winconf winconf)
4173 (gnus-message 6 "C-c C-c to end edits")))
4175 (defun gnus-article-edit-done (&optional arg)
4176 "Update the article edits and exit."
4178 (let ((func gnus-article-edit-done-function)
4179 (buf (current-buffer))
4180 (start (window-start)))
4181 (gnus-article-edit-exit)
4184 (let ((buffer-read-only nil))
4186 ;; The cache and backlog have to be flushed somewhat.
4187 (when gnus-keep-backlog
4188 (gnus-backlog-remove-article
4189 (car gnus-article-current) (cdr gnus-article-current)))
4190 ;; Flush original article as well.
4192 (when (get-buffer gnus-original-article-buffer)
4193 (set-buffer gnus-original-article-buffer)
4194 (setq gnus-original-article nil)))
4195 (when gnus-use-cache
4196 (gnus-cache-update-article
4197 (car gnus-article-current) (cdr gnus-article-current))))
4199 (set-window-start (get-buffer-window buf) start)
4200 (set-window-point (get-buffer-window buf) (point))))
4202 (defun gnus-article-edit-exit ()
4203 "Exit the article editing without updating."
4205 ;; We remove all text props from the article buffer.
4206 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4207 (curbuf (current-buffer))
4209 (window-start (window-start)))
4212 (let ((winconf gnus-prev-winconf))
4214 (set-window-configuration winconf)
4215 ;; Tippy-toe some to make sure that point remains where it was.
4216 (save-current-buffer
4218 (set-window-start (get-buffer-window (current-buffer)) window-start)
4221 (defun gnus-article-edit-full-stops ()
4222 "Interactively repair spacing at end of sentences."
4225 (goto-char (point-min))
4226 (search-forward-regexp "^$" nil t)
4227 (let ((case-fold-search nil))
4228 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4231 ;;; Article highlights
4234 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4236 ;;; Internal Variables:
4238 (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\\)\\)"
4239 "Regular expression that matches URLs."
4240 :group 'gnus-article-buttons
4243 (defcustom gnus-button-alist
4244 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4245 0 t gnus-button-message-id 2)
4246 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4247 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4249 gnus-button-fetch-group 4)
4250 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4251 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4252 t gnus-button-message-id 3)
4253 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4254 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4255 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4256 ;; This is how URLs _should_ be embedded in text...
4257 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4259 (,gnus-button-url-regexp 0 t browse-url 0))
4260 "*Alist of regexps matching buttons in article bodies.
4262 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4263 REGEXP: is the string matching text around the button,
4264 BUTTON: is the number of the regexp grouping actually matching the button,
4265 FORM: is a lisp expression which must eval to true for the button to
4267 CALLBACK: is the function to call when the user push this button, and each
4268 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4270 CALLBACK can also be a variable, in that case the value of that
4271 variable it the real callback function."
4272 :group 'gnus-article-buttons
4273 :type '(repeat (list regexp
4274 (integer :tag "Button")
4276 (function :tag "Callback")
4279 (integer :tag "Regexp group")))))
4281 (defcustom gnus-header-button-alist
4282 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4283 0 t gnus-button-message-id 0)
4284 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4285 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4286 0 t gnus-button-mailto 0)
4287 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4288 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4289 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4290 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4291 gnus-button-message-id 3))
4292 "*Alist of headers and regexps to match buttons in article heads.
4294 This alist is very similar to `gnus-button-alist', except that each
4295 alist has an additional HEADER element first in each entry:
4297 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4299 HEADER is a regexp to match a header. For a fuller explanation, see
4300 `gnus-button-alist'."
4301 :group 'gnus-article-buttons
4302 :group 'gnus-article-headers
4303 :type '(repeat (list (regexp :tag "Header")
4305 (integer :tag "Button")
4307 (function :tag "Callback")
4310 (integer :tag "Regexp group")))))
4312 (defvar gnus-button-regexp nil)
4313 (defvar gnus-button-marker-list nil)
4314 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4316 (defvar gnus-button-last nil)
4317 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4321 (defun gnus-article-push-button (event)
4322 "Check text under the mouse pointer for a callback function.
4323 If the text under the mouse pointer has a `gnus-callback' property,
4324 call it with the value of the `gnus-data' text property."
4326 (set-buffer (window-buffer (posn-window (event-start event))))
4327 (let* ((pos (posn-point (event-start event)))
4328 (data (get-text-property pos 'gnus-data))
4329 (fun (get-text-property pos 'gnus-callback)))
4332 (funcall fun data))))
4334 (defun gnus-article-press-button ()
4335 "Check text at point for a callback function.
4336 If the text at point has a `gnus-callback' property,
4337 call it with the value of the `gnus-data' text property."
4339 (let* ((data (get-text-property (point) 'gnus-data))
4340 (fun (get-text-property (point) 'gnus-callback)))
4342 (funcall fun data))))
4344 (defun gnus-article-highlight (&optional force)
4345 "Highlight current article.
4346 This function calls `gnus-article-highlight-headers',
4347 `gnus-article-highlight-citation',
4348 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4349 do the highlighting. See the documentation for those functions."
4350 (interactive (list 'force))
4351 (gnus-article-highlight-headers)
4352 (gnus-article-highlight-citation force)
4353 (gnus-article-highlight-signature)
4354 (gnus-article-add-buttons force)
4355 (gnus-article-add-buttons-to-head))
4357 (defun gnus-article-highlight-some (&optional force)
4358 "Highlight current article.
4359 This function calls `gnus-article-highlight-headers',
4360 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4361 do the highlighting. See the documentation for those functions."
4362 (interactive (list 'force))
4363 (gnus-article-highlight-headers)
4364 (gnus-article-highlight-signature)
4365 (gnus-article-add-buttons))
4367 (defun gnus-article-highlight-headers ()
4368 "Highlight article headers as specified by `gnus-header-face-alist'."
4371 (set-buffer gnus-article-buffer)
4373 (let ((alist gnus-header-face-alist)
4374 (buffer-read-only nil)
4375 (case-fold-search t)
4376 (inhibit-point-motion-hooks t)
4377 entry regexp header-face field-face from hpoints fpoints)
4378 (article-narrow-to-head)
4379 (while (setq entry (pop alist))
4380 (goto-char (point-min))
4381 (setq regexp (concat "^\\("
4382 (if (string-equal "" (nth 0 entry))
4386 header-face (nth 1 entry)
4387 field-face (nth 2 entry))
4388 (while (and (re-search-forward regexp nil t)
4392 (unless (search-forward ":" nil t)
4394 (when (and header-face
4395 (not (memq (point) hpoints)))
4396 (push (point) hpoints)
4397 (gnus-put-text-property from (point) 'face header-face))
4398 (when (and field-face
4399 (not (memq (setq from (point)) fpoints)))
4401 (if (re-search-forward "^[^ \t]" nil t)
4403 (goto-char (point-max)))
4404 (gnus-put-text-property from (point) 'face field-face))))))))
4406 (defun gnus-article-highlight-signature ()
4407 "Highlight the signature in an article.
4408 It does this by highlighting everything after
4409 `gnus-signature-separator' using `gnus-signature-face'."
4412 (set-buffer gnus-article-buffer)
4413 (let ((buffer-read-only nil)
4414 (inhibit-point-motion-hooks t))
4416 (when (and gnus-signature-face
4417 (gnus-article-narrow-to-signature))
4418 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4419 'face gnus-signature-face)
4421 (gnus-article-search-signature)
4422 (let ((start (match-beginning 0))
4423 (end (set-marker (make-marker) (1+ (match-end 0)))))
4424 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4427 (defun gnus-button-in-region-p (b e prop)
4428 "Say whether PROP exists in the region."
4429 (text-property-not-all b e prop nil))
4431 (defun gnus-article-add-buttons (&optional force)
4432 "Find external references in the article and make buttons of them.
4433 \"External references\" are things like Message-IDs and URLs, as
4434 specified by `gnus-button-alist'."
4435 (interactive (list 'force))
4437 (set-buffer gnus-article-buffer)
4438 (let ((buffer-read-only nil)
4439 (inhibit-point-motion-hooks t)
4440 (case-fold-search t)
4441 (alist gnus-button-alist)
4443 ;; Remove all old markers.
4444 (let (marker entry new-list)
4445 (while (setq marker (pop gnus-button-marker-list))
4446 (if (or (< marker (point-min)) (>= marker (point-max)))
4447 (push marker new-list)
4449 (when (setq entry (gnus-button-entry))
4450 (put-text-property (match-beginning (nth 1 entry))
4451 (match-end (nth 1 entry))
4452 'gnus-callback nil))
4453 (set-marker marker nil)))
4454 (setq gnus-button-marker-list new-list))
4455 ;; We skip the headers.
4458 (while (setq entry (pop alist))
4459 (setq regexp (car entry))
4461 (while (re-search-forward regexp nil t)
4462 (let* ((start (and entry (match-beginning (nth 1 entry))))
4463 (end (and entry (match-end (nth 1 entry))))
4464 (from (match-beginning 0)))
4465 (when (and (or (eq t (nth 2 entry))
4466 (eval (nth 2 entry)))
4467 (not (gnus-button-in-region-p
4468 start end 'gnus-callback)))
4469 ;; That optional form returned non-nil, so we add the
4471 (gnus-article-add-button
4472 start end 'gnus-button-push
4473 (car (push (set-marker (make-marker) from)
4474 gnus-button-marker-list))))))))))
4476 ;; Add buttons to the head of an article.
4477 (defun gnus-article-add-buttons-to-head ()
4478 "Add buttons to the head of the article."
4481 (set-buffer gnus-article-buffer)
4483 (let ((buffer-read-only nil)
4484 (inhibit-point-motion-hooks t)
4485 (case-fold-search t)
4486 (alist gnus-header-button-alist)
4488 (article-narrow-to-head)
4490 ;; Each alist entry.
4491 (setq entry (car alist)
4493 (goto-char (point-min))
4494 (while (re-search-forward (car entry) nil t)
4495 ;; Each header matching the entry.
4496 (setq beg (match-beginning 0))
4497 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4498 (match-beginning 0))
4501 (while (re-search-forward (nth 1 entry) end t)
4502 ;; Each match within a header.
4503 (let* ((entry (cdr entry))
4504 (start (match-beginning (nth 1 entry)))
4505 (end (match-end (nth 1 entry)))
4506 (form (nth 2 entry)))
4507 (goto-char (match-end 0))
4509 (gnus-article-add-button
4510 start end (nth 3 entry)
4511 (buffer-substring (match-beginning (nth 4 entry))
4512 (match-end (nth 4 entry)))))))
4513 (goto-char end)))))))
4515 ;;; External functions:
4517 (defun gnus-article-add-button (from to fun &optional data)
4518 "Create a button between FROM and TO with callback FUN and data DATA."
4519 (when gnus-article-button-face
4520 (gnus-overlay-put (gnus-make-overlay from to)
4521 'face gnus-article-button-face))
4522 (gnus-add-text-properties
4524 (nconc (and gnus-article-mouse-face
4525 (list gnus-mouse-face-prop gnus-article-mouse-face))
4526 (list 'gnus-callback fun)
4527 (and data (list 'gnus-data data))))
4528 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4529 :button-keymap gnus-widget-button-keymap))
4531 ;;; Internal functions:
4533 (defun gnus-article-set-globals ()
4535 (set-buffer gnus-summary-buffer)
4536 (gnus-set-global-variables)))
4538 (defun gnus-signature-toggle (end)
4540 (set-buffer gnus-article-buffer)
4541 (let ((buffer-read-only nil)
4542 (inhibit-point-motion-hooks t))
4543 (if (text-property-any end (point-max) 'article-type 'signature)
4544 (gnus-remove-text-properties-when
4545 'article-type 'signature end (point-max)
4546 (cons 'article-type (cons 'signature
4547 gnus-hidden-properties)))
4548 (gnus-add-text-properties-when
4549 'article-type nil end (point-max)
4550 (cons 'article-type (cons 'signature
4551 gnus-hidden-properties)))))))
4553 (defun gnus-button-entry ()
4554 ;; Return the first entry in `gnus-button-alist' matching this place.
4555 (let ((alist gnus-button-alist)
4558 (setq entry (pop alist))
4559 (if (looking-at (car entry))
4564 (defun gnus-button-push (marker)
4565 ;; Push button starting at MARKER.
4568 (let* ((entry (gnus-button-entry))
4569 (inhibit-point-motion-hooks t)
4571 (args (mapcar (lambda (group)
4572 (let ((string (match-string group)))
4573 (gnus-set-text-properties
4574 0 (length string) nil string)
4581 (fboundp (symbol-value fun)))
4582 (apply (symbol-value fun) args))
4584 (gnus-message 1 "You must define `%S' to use this button"
4585 (cons fun args)))))))
4587 (defun gnus-button-message-id (message-id)
4590 (set-buffer gnus-summary-buffer)
4591 (gnus-summary-refer-article message-id)))
4593 (defun gnus-button-fetch-group (address)
4594 "Fetch GROUP specified by ADDRESS."
4595 (if (not (string-match "[:/]" address))
4596 ;; This is just a simple group url.
4597 (gnus-group-read-ephemeral-group address gnus-select-method)
4598 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4600 (error "Can't parse %s" address)
4601 (gnus-group-read-ephemeral-group
4602 (match-string 4 address)
4603 `(nntp ,(match-string 1 address)
4604 (nntp-address ,(match-string 1 address))
4605 (nntp-port-number ,(if (match-end 3)
4606 (match-string 3 address)
4609 (defun gnus-url-parse-query-string (query &optional downcase)
4610 (let (retval pairs cur key val)
4611 (setq pairs (split-string query "&"))
4613 (setq cur (car pairs)
4615 (if (not (string-match "=" cur))
4617 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4618 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4620 (setq key (downcase key)))
4621 (setq cur (assoc key retval))
4623 (setcdr cur (cons val (cdr cur)))
4624 (setq retval (cons (list key val) retval)))))
4627 (defun gnus-url-unhex (x)
4634 (defun gnus-url-unhex-string (str &optional allow-newlines)
4635 "Remove %XXX embedded spaces, etc in a url.
4636 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4637 decoding of carriage returns and line feeds in the string, which is normally
4638 forbidden in URL encoding."
4639 (setq str (or str ""))
4641 (case-fold-search t))
4642 (while (string-match "%[0-9a-f][0-9a-f]" str)
4643 (let* ((start (match-beginning 0))
4644 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4646 (gnus-url-unhex (elt str (+ start 2))))))
4648 tmp (substring str 0 start)
4651 (char-to-string code))
4652 ((or (= code ?\n) (= code ?\r))
4654 (t (char-to-string code))))
4655 str (substring str (match-end 0)))))
4656 (setq tmp (concat tmp str))
4659 (defun gnus-url-mailto (url)
4660 ;; Send mail to someone
4661 (when (string-match "mailto:/*\\(.*\\)" url)
4662 (setq url (substring url (match-beginning 1) nil)))
4663 (let (to args subject func)
4664 (if (string-match (regexp-quote "?") url)
4665 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4666 args (gnus-url-parse-query-string
4667 (substring url (match-end 0) nil) t))
4668 (setq to (gnus-url-unhex-string url)))
4669 (setq args (cons (list "to" to) args)
4670 subject (cdr-safe (assoc "subject" args)))
4673 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4676 (message-position-on-field (caar args)))
4677 (insert (mapconcat 'identity (cdar args) ", "))
4678 (setq args (cdr args)))
4681 (message-goto-subject))))
4683 (defun gnus-button-mailto (address)
4685 (set-buffer (gnus-copy-article-buffer))
4686 (message-reply address))
4688 (defalias 'gnus-button-reply 'message-reply)
4690 (defun gnus-button-embedded-url (address)
4691 "Activate ADDRESS with `browse-url'."
4692 (browse-url (gnus-strip-whitespace address)))
4694 ;;; Next/prev buttons in the article buffer.
4696 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4697 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4699 (defvar gnus-prev-page-map nil)
4700 (unless gnus-prev-page-map
4701 (setq gnus-prev-page-map (make-sparse-keymap))
4702 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4703 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4705 (defun gnus-insert-prev-page-button ()
4706 (let ((buffer-read-only nil))
4708 gnus-prev-page-line-format nil
4709 `(gnus-prev t local-map ,gnus-prev-page-map
4710 gnus-callback gnus-article-button-prev-page
4711 article-type annotation))))
4713 (defvar gnus-next-page-map nil)
4714 (unless gnus-next-page-map
4715 (setq gnus-next-page-map (make-keymap))
4716 (suppress-keymap gnus-prev-page-map)
4717 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4718 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4720 (defun gnus-button-next-page ()
4721 "Go to the next page."
4723 (let ((win (selected-window)))
4724 (select-window (get-buffer-window gnus-article-buffer t))
4725 (gnus-article-next-page)
4726 (select-window win)))
4728 (defun gnus-button-prev-page ()
4729 "Go to the prev page."
4731 (let ((win (selected-window)))
4732 (select-window (get-buffer-window gnus-article-buffer t))
4733 (gnus-article-prev-page)
4734 (select-window win)))
4736 (defun gnus-insert-next-page-button ()
4737 (let ((buffer-read-only nil))
4738 (gnus-eval-format gnus-next-page-line-format nil
4740 t local-map ,gnus-next-page-map
4741 gnus-callback gnus-article-button-next-page
4742 article-type annotation))))
4744 (defun gnus-article-button-next-page (arg)
4745 "Go to the next page."
4747 (let ((win (selected-window)))
4748 (select-window (get-buffer-window gnus-article-buffer t))
4749 (gnus-article-next-page)
4750 (select-window win)))
4752 (defun gnus-article-button-prev-page (arg)
4753 "Go to the prev page."
4755 (let ((win (selected-window)))
4756 (select-window (get-buffer-window gnus-article-buffer t))
4757 (gnus-article-prev-page)
4758 (select-window win)))
4760 (defvar gnus-decode-header-methods
4761 '(mail-decode-encoded-word-region)
4762 "List of methods used to decode headers.
4764 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4765 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4766 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4767 whose names match REGEXP.
4770 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4771 mail-decode-encoded-word-region
4772 (\"chinese\" . rfc1843-decode-region))
4775 (defvar gnus-decode-header-methods-cache nil)
4777 (defun gnus-multi-decode-header (start end)
4778 "Apply the functions from `gnus-encoded-word-methods' that match."
4779 (unless (and gnus-decode-header-methods-cache
4780 (eq gnus-newsgroup-name
4781 (car gnus-decode-header-methods-cache)))
4782 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4785 (nconc gnus-decode-header-methods-cache (list x))
4786 (if (and gnus-newsgroup-name
4787 (string-match (car x) gnus-newsgroup-name))
4788 (nconc gnus-decode-header-methods-cache
4790 gnus-decode-header-methods))
4791 (let ((xlist gnus-decode-header-methods-cache))
4794 (narrow-to-region start end)
4796 (funcall (pop xlist) (point-min) (point-max))))))
4799 ;;; Treatment top-level handling.
4802 (defun gnus-treat-article (condition &optional part-number total-parts type)
4803 (let ((length (- (point-max) (point-min)))
4804 (alist gnus-treatment-function-alist)
4805 (article-goto-body-goes-to-point-min-p t)
4809 (let ((list gnus-article-treat-types))
4811 (when (string-match (pop list) type)
4812 (throw 'found t)))))))
4813 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4815 (gnus-run-hooks 'gnus-part-display-hook)
4816 (while (setq elem (pop alist))
4819 (if (gnus-buffer-live-p gnus-summary-buffer)
4820 (set-buffer gnus-summary-buffer))
4821 (symbol-value (car elem))))
4822 (when (and (or (consp val)
4824 (gnus-treat-predicate val)
4825 (or (not (get (car elem) 'highlight))
4828 (funcall (cadr elem)))))))
4830 ;; Dynamic variables.
4832 (defvar part-number)
4833 (defvar total-parts)
4838 (defun gnus-treat-predicate (val)
4843 (stringp (car val)))
4844 (apply 'gnus-or (mapcar `(lambda (s)
4845 (string-match s ,(or gnus-newsgroup-name "")))
4848 (let ((pred (pop val)))
4851 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4853 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4855 (not (gnus-treat-predicate (car val))))
4857 (equal (car val) type))
4859 (error "%S is not a valid predicate" pred)))))
4867 (eq part-number total-parts))
4871 (error "%S is not a valid value" val))))
4877 (run-hooks 'gnus-art-load-hook)
4879 ;;; gnus-art.el ends here