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
614 "Table for MS-to-Latin1 translation.")
616 (defcustom gnus-ignored-mime-types nil
617 "List of MIME types that should be ignored by Gnus."
618 :group 'gnus-article-mime
619 :type '(repeat regexp))
621 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
622 "List of MIME types that should not be given buttons when rendered inline."
623 :group 'gnus-article-mime
624 :type '(repeat regexp))
626 (defcustom gnus-article-mime-part-function nil
627 "Function called with a MIME handle as the argument.
628 This is meant for people who want to do something automatic based
629 on parts -- for instance, adding Vcard info to a database."
630 :group 'gnus-article-mime
633 (defcustom gnus-mime-multipart-functions nil
634 "An alist of MIME types to functions to display them.")
636 (defcustom gnus-article-date-lapsed-new-header nil
637 "Whether the X-Sent and Date headers can coexist.
638 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
639 either replace the old \"Date:\" header (if this variable is nil), or
640 be added below it (otherwise)."
641 :group 'gnus-article-headers
644 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
645 "Function called with a MIME handle as the argument.
646 This is meant for people who want to view first matched part.
647 For `undisplayed-alternative' (default), the first undisplayed
648 part or alternative part is used. For `undisplayed', the first
649 undisplayed part is used. For a function, the first part which
650 the function return `t' is used. For `nil', the first part is
652 :group 'gnus-article-mime
654 (item :tag "first" :value nil)
655 (item :tag "undisplayed" :value undisplayed)
656 (item :tag "undisplayed or alternative"
657 :value undisplayed-alternative)
660 (defcustom gnus-mime-action-alist
661 '(("save to file" . gnus-mime-save-part)
662 ("display as text" . gnus-mime-inline-part)
663 ("view the part" . gnus-mime-view-part)
664 ("pipe to command" . gnus-mime-pipe-part)
665 ("toggle display" . gnus-article-press-button)
666 ("view as type" . gnus-mime-view-part-as-type)
667 ("internalize type" . gnus-mime-internalize-part)
668 ("externalize type" . gnus-mime-externalize-part))
669 "An alist of actions that run on the MIME attachment."
670 :group 'gnus-article-mime
671 :type '(repeat (cons (string :tag "name")
675 ;;; The treatment variables
678 (defvar gnus-part-display-hook nil
679 "Hook called on parts that are to receive treatment.")
681 (defvar gnus-article-treat-custom
682 '(choice (const :tag "Off" nil)
684 (const :tag "Header" head)
685 (const :tag "Last" last)
686 (integer :tag "Less")
687 (repeat :tag "Groups" regexp)
688 (sexp :tag "Predicate")))
690 (defvar gnus-article-treat-head-custom
691 '(choice (const :tag "Off" nil)
692 (const :tag "Header" head)))
694 (defvar gnus-article-treat-types '("text/plain")
697 (defvar gnus-inhibit-treatment nil
698 "Whether to inhibit treatment.")
700 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
701 "Highlight the signature.
702 Valid values are nil, t, `head', `last', an integer or a predicate.
703 See the manual for details."
704 :group 'gnus-article-treat
705 :type gnus-article-treat-custom)
706 (put 'gnus-treat-highlight-signature 'highlight t)
708 (defcustom gnus-treat-buttonize 100000
710 Valid values are nil, t, `head', `last', an integer or a predicate.
711 See the manual for details."
712 :group 'gnus-article-treat
713 :type gnus-article-treat-custom)
714 (put 'gnus-treat-buttonize 'highlight t)
716 (defcustom gnus-treat-buttonize-head 'head
717 "Add buttons to the head.
718 Valid values are nil, t, `head', `last', an integer or a predicate.
719 See the manual for details."
720 :group 'gnus-article-treat
721 :type gnus-article-treat-head-custom)
722 (put 'gnus-treat-buttonize-head 'highlight t)
724 (defcustom gnus-treat-emphasize 50000
726 Valid values are nil, t, `head', `last', an integer or a predicate.
727 See the manual for details."
728 :group 'gnus-article-treat
729 :type gnus-article-treat-custom)
730 (put 'gnus-treat-emphasize 'highlight t)
732 (defcustom gnus-treat-strip-cr nil
733 "Remove carriage returns.
734 Valid values are nil, t, `head', `last', an integer or a predicate.
735 See the manual for details."
736 :group 'gnus-article-treat
737 :type gnus-article-treat-custom)
739 (defcustom gnus-treat-hide-headers 'head
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-head-custom)
746 (defcustom gnus-treat-hide-boring-headers nil
747 "Hide boring headers.
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-signature nil
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-custom)
760 (defcustom gnus-treat-fill-article 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-hide-citation 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-maybe 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-strip-list-identifiers 'head
782 "Strip list identifiers from `gnus-list-identifiers`.
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-pgp t
789 "Strip PGP signatures.
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-pem nil
796 "Strip PEM 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-banner t
803 "Strip banners from articles.
804 The banner to be stripped is specified in the `banner' group parameter.
805 Valid values are nil, t, `head', `last', an integer or a predicate.
806 See the manual for details."
807 :group 'gnus-article-treat
808 :type gnus-article-treat-custom)
810 (defcustom gnus-treat-highlight-headers 'head
811 "Highlight the headers.
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-head-custom)
816 (put 'gnus-treat-highlight-headers 'highlight t)
818 (defcustom gnus-treat-highlight-citation t
819 "Highlight cited text.
820 Valid values are nil, t, `head', `last', an integer or a predicate.
821 See the manual for details."
822 :group 'gnus-article-treat
823 :type gnus-article-treat-custom)
824 (put 'gnus-treat-highlight-citation 'highlight t)
826 (defcustom gnus-treat-date-ut nil
827 "Display the Date in UT (GMT).
828 Valid values are nil, t, `head', `last', an integer or a predicate.
829 See the manual for details."
830 :group 'gnus-article-treat
831 :type gnus-article-treat-head-custom)
833 (defcustom gnus-treat-date-local nil
834 "Display the Date in the local timezone.
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-lapsed nil
841 "Display the Date header in a way that says how much time has elapsed.
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-original nil
848 "Display the date in the original timezone.
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-iso8601 nil
855 "Display the date in the ISO8601 format.
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-user-defined nil
862 "Display the date in a user-defined format.
863 The format is defined by the `gnus-article-time-format' variable.
864 Valid values are nil, t, `head', `last', an integer or a predicate.
865 See the manual for details."
866 :group 'gnus-article-treat
867 :type gnus-article-treat-head-custom)
869 (defcustom gnus-treat-strip-headers-in-body t
870 "Strip the X-No-Archive header line from the beginning of the body.
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-custom)
876 (defcustom gnus-treat-strip-trailing-blank-lines nil
877 "Strip trailing blank lines.
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-leading-blank-lines nil
884 "Strip leading 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-multiple-blank-lines nil
891 "Strip multiple 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-overstrike t
898 "Treat overstrike highlighting.
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)
903 (put 'gnus-treat-overstrike 'highlight t)
905 (defcustom gnus-treat-display-xface
906 (and (or (and (fboundp 'image-type-available-p)
907 (image-type-available-p 'xbm)
908 (string-match "^0x" (shell-command-to-string "uncompface")))
909 (and (featurep 'xemacs) (featurep 'xface)))
911 "Display X-Face headers.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914 :group 'gnus-article-treat
915 :type gnus-article-treat-head-custom)
916 (put 'gnus-treat-display-xface 'highlight t)
918 (defcustom gnus-treat-display-smileys
919 (if (or (and (featurep 'xemacs)
921 (and (fboundp 'image-type-available-p)
922 (image-type-available-p 'pbm)))
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-custom)
929 (put 'gnus-treat-display-smileys 'highlight t)
931 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
935 :group 'gnus-article-treat
936 :type gnus-article-treat-head-custom)
937 (put 'gnus-treat-display-picons 'highlight t)
939 (defcustom gnus-treat-capitalize-sentences nil
940 "Capitalize sentence-starting words.
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943 :group 'gnus-article-treat
944 :type gnus-article-treat-custom)
946 (defcustom gnus-treat-fill-long-lines nil
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-play-sounds 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-translate nil
961 "Translate articles from one language to another.
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
967 ;;; Internal variables
969 (defvar article-goto-body-goes-to-point-min-p nil)
970 (defvar gnus-article-wash-types nil)
971 (defvar gnus-article-emphasis-alist nil)
973 (defvar gnus-article-mime-handle-alist-1 nil)
974 (defvar gnus-treatment-function-alist
975 '((gnus-treat-strip-banner gnus-article-strip-banner)
976 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
977 (gnus-treat-highlight-signature gnus-article-highlight-signature)
978 (gnus-treat-buttonize gnus-article-add-buttons)
979 (gnus-treat-fill-article gnus-article-fill-cited-article)
980 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
981 (gnus-treat-strip-cr gnus-article-remove-cr)
982 (gnus-treat-emphasize gnus-article-emphasize)
983 (gnus-treat-display-xface gnus-article-display-x-face)
984 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
985 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
986 (gnus-treat-hide-signature gnus-article-hide-signature)
987 (gnus-treat-hide-citation gnus-article-hide-citation)
988 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
989 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
990 (gnus-treat-strip-pgp gnus-article-hide-pgp)
991 (gnus-treat-strip-pem gnus-article-hide-pem)
992 (gnus-treat-highlight-headers gnus-article-highlight-headers)
993 (gnus-treat-highlight-citation gnus-article-highlight-citation)
994 (gnus-treat-highlight-signature gnus-article-highlight-signature)
995 (gnus-treat-date-ut gnus-article-date-ut)
996 (gnus-treat-date-local gnus-article-date-local)
997 (gnus-treat-date-lapsed gnus-article-date-lapsed)
998 (gnus-treat-date-original gnus-article-date-original)
999 (gnus-treat-date-user-defined gnus-article-date-user)
1000 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1001 (gnus-treat-strip-trailing-blank-lines
1002 gnus-article-remove-trailing-blank-lines)
1003 (gnus-treat-strip-leading-blank-lines
1004 gnus-article-strip-leading-blank-lines)
1005 (gnus-treat-strip-multiple-blank-lines
1006 gnus-article-strip-multiple-blank-lines)
1007 (gnus-treat-overstrike gnus-article-treat-overstrike)
1008 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1009 (gnus-treat-display-smileys gnus-smiley-display)
1010 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1011 (gnus-treat-display-picons gnus-article-display-picons)
1012 (gnus-treat-play-sounds gnus-earcon-display)))
1014 (defvar gnus-article-mime-handle-alist nil)
1015 (defvar article-lapsed-timer nil)
1016 (defvar gnus-article-current-summary nil)
1018 (defvar gnus-article-mode-syntax-table
1019 (let ((table (copy-syntax-table text-mode-syntax-table)))
1020 (modify-syntax-entry ?- "w" table)
1021 (modify-syntax-entry ?> ")" table)
1022 (modify-syntax-entry ?< "(" table)
1024 "Syntax table used in article mode buffers.
1025 Initialized from `text-mode-syntax-table.")
1027 (defvar gnus-save-article-buffer nil)
1029 (defvar gnus-article-mode-line-format-alist
1030 (nconc '((?w (gnus-article-wash-status) ?s)
1031 (?m (gnus-article-mime-part-status) ?s))
1032 gnus-summary-mode-line-format-alist))
1034 (defvar gnus-number-of-articles-to-be-saved nil)
1036 (defvar gnus-inhibit-hiding nil)
1038 (defsubst gnus-article-hide-text (b e props)
1039 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1040 (add-text-properties b e props)
1041 (when (memq 'intangible props)
1043 (max (1- b) (point-min))
1044 b 'intangible (cddr (memq 'intangible props)))))
1045 (defsubst gnus-article-unhide-text (b e)
1046 "Remove hidden text properties from region between B and E."
1047 (remove-text-properties b e gnus-hidden-properties)
1048 (when (memq 'intangible gnus-hidden-properties)
1049 (put-text-property (max (1- b) (point-min))
1050 b 'intangible nil)))
1052 (defun gnus-article-hide-text-type (b e type)
1053 "Hide text of TYPE between B and E."
1054 (push type gnus-article-wash-types)
1055 (gnus-article-hide-text
1056 b e (cons 'article-type (cons type gnus-hidden-properties))))
1058 (defun gnus-article-unhide-text-type (b e type)
1059 "Unhide text of TYPE between B and E."
1060 (setq gnus-article-wash-types
1061 (delq type gnus-article-wash-types))
1062 (remove-text-properties
1063 b e (cons 'article-type (cons type gnus-hidden-properties)))
1064 (when (memq 'intangible gnus-hidden-properties)
1065 (put-text-property (max (1- b) (point-min))
1066 b 'intangible nil)))
1068 (defun gnus-article-hide-text-of-type (type)
1069 "Hide text of TYPE in the current buffer."
1071 (let ((b (point-min))
1073 (while (setq b (text-property-any b e 'article-type type))
1074 (add-text-properties b (incf b) gnus-hidden-properties)))))
1076 (defun gnus-article-delete-text-of-type (type)
1077 "Delete text of TYPE in the current buffer."
1079 (let ((b (point-min)))
1080 (while (setq b (text-property-any b (point-max) 'article-type type))
1082 b (or (text-property-not-all b (point-max) 'article-type type)
1085 (defun gnus-article-delete-invisible-text ()
1086 "Delete all invisible text in the current buffer."
1088 (let ((b (point-min)))
1089 (while (setq b (text-property-any b (point-max) 'invisible t))
1091 b (or (text-property-not-all b (point-max) 'invisible t)
1094 (defun gnus-article-text-type-exists-p (type)
1095 "Say whether any text of type TYPE exists in the buffer."
1096 (text-property-any (point-min) (point-max) 'article-type type))
1098 (defsubst gnus-article-header-rank ()
1099 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1100 (let ((list gnus-sorted-header-list)
1103 (when (looking-at (car list))
1105 (setq list (cdr list))
1109 (defun article-hide-headers (&optional arg delete)
1110 "Hide unwanted headers and possibly sort them as well."
1112 ;; This function might be inhibited.
1113 (unless gnus-inhibit-hiding
1116 (let ((buffer-read-only nil)
1117 (case-fold-search t)
1118 (max (1+ (length gnus-sorted-header-list)))
1119 (ignored (when (not gnus-visible-headers)
1120 (cond ((stringp gnus-ignored-headers)
1121 gnus-ignored-headers)
1122 ((listp gnus-ignored-headers)
1123 (mapconcat 'identity gnus-ignored-headers
1126 (cond ((stringp gnus-visible-headers)
1127 gnus-visible-headers)
1128 ((and gnus-visible-headers
1129 (listp gnus-visible-headers))
1130 (mapconcat 'identity gnus-visible-headers "\\|"))))
1131 (inhibit-point-motion-hooks t)
1133 ;; First we narrow to just the headers.
1134 (article-narrow-to-head)
1135 ;; Hide any "From " lines at the beginning of (mail) articles.
1136 (while (looking-at "From ")
1139 (delete-region (point-min) (point)))
1140 ;; Then treat the rest of the header lines.
1141 ;; Then we use the two regular expressions
1142 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1143 ;; select which header lines is to remain visible in the
1145 (while (re-search-forward "^[^ \t]*:" nil t)
1147 ;; Mark the rank of the header.
1149 (point) (1+ (point)) 'message-rank
1150 (if (or (and visible (looking-at visible))
1152 (not (looking-at ignored))))
1153 (gnus-article-header-rank)
1156 (message-sort-headers-1)
1157 (when (setq beg (text-property-any
1158 (point-min) (point-max) 'message-rank (+ 2 max)))
1159 ;; We delete the unwanted headers.
1160 (push 'headers gnus-article-wash-types)
1161 (add-text-properties (point-min) (+ 5 (point-min))
1162 '(article-type headers dummy-invisible t))
1163 (delete-region beg (point-max))))))))
1165 (defun article-hide-boring-headers (&optional arg)
1166 "Toggle hiding of headers that aren't very interesting.
1167 If given a negative prefix, always show; if given a positive prefix,
1169 (interactive (gnus-article-hidden-arg))
1170 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1171 (not gnus-show-all-headers))
1174 (let ((buffer-read-only nil)
1175 (list gnus-boring-article-headers)
1176 (inhibit-point-motion-hooks t)
1178 (article-narrow-to-head)
1180 (setq elem (pop list))
1181 (goto-char (point-min))
1183 ;; Hide empty headers.
1185 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1187 (gnus-article-hide-text-type
1188 (progn (beginning-of-line) (point))
1191 (if (re-search-forward "^[^ \t]" nil t)
1195 ;; Hide boring Newsgroups header.
1196 ((eq elem 'newsgroups)
1197 (when (equal (gnus-fetch-field "newsgroups")
1198 (gnus-group-real-name
1199 (if (boundp 'gnus-newsgroup-name)
1202 (gnus-article-hide-header "newsgroups")))
1203 ((eq elem 'followup-to)
1204 (when (equal (message-fetch-field "followup-to")
1205 (message-fetch-field "newsgroups"))
1206 (gnus-article-hide-header "followup-to")))
1207 ((eq elem 'reply-to)
1208 (let ((from (message-fetch-field "from"))
1209 (reply-to (message-fetch-field "reply-to")))
1214 (nth 1 (mail-extract-address-components from))
1215 (nth 1 (mail-extract-address-components reply-to)))))
1216 (gnus-article-hide-header "reply-to"))))
1218 (let ((date (message-fetch-field "date")))
1220 (< (days-between (current-time-string) date)
1222 (gnus-article-hide-header "date"))))
1224 (let ((to (message-fetch-field "to"))
1225 (cc (message-fetch-field "cc")))
1226 (when (> (length to) 1024)
1227 (gnus-article-hide-header "to"))
1228 (when (> (length cc) 1024)
1229 (gnus-article-hide-header "cc"))))
1233 (goto-char (point-min))
1234 (while (re-search-forward "^to:" nil t)
1235 (setq to-count (1+ to-count)))
1236 (when (> to-count 1)
1237 (while (> to-count 0)
1238 (goto-char (point-min))
1240 (re-search-forward "^to:" nil nil to-count)
1242 (narrow-to-region (point) (point-max))
1243 (gnus-article-hide-header "to"))
1244 (setq to-count (1- to-count))))
1245 (goto-char (point-min))
1246 (while (re-search-forward "^cc:" nil t)
1247 (setq cc-count (1+ cc-count)))
1248 (when (> cc-count 1)
1249 (while (> cc-count 0)
1250 (goto-char (point-min))
1252 (re-search-forward "^cc:" nil nil cc-count)
1254 (narrow-to-region (point) (point-max))
1255 (gnus-article-hide-header "cc"))
1256 (setq cc-count (1- cc-count)))))))))))))
1258 (defun gnus-article-hide-header (header)
1260 (goto-char (point-min))
1261 (when (re-search-forward (concat "^" header ":") nil t)
1262 (gnus-article-hide-text-type
1263 (progn (beginning-of-line) (point))
1266 (if (re-search-forward "^[^ \t]" nil t)
1271 (defvar gnus-article-normalized-header-length 40
1272 "Length of normalized headers.")
1274 (defun article-normalize-headers ()
1275 "Make all header lines 40 characters long."
1277 (let ((buffer-read-only nil)
1281 (article-narrow-to-head)
1284 ((< (setq column (- (gnus-point-at-eol) (point)))
1285 gnus-article-normalized-header-length)
1287 (insert (make-string
1288 (- gnus-article-normalized-header-length column)
1290 ((> column gnus-article-normalized-header-length)
1291 (gnus-put-text-property
1293 (forward-char gnus-article-normalized-header-length)
1300 (forward-line 1))))))
1302 (defun article-treat-dumbquotes ()
1303 "Translate M******** sm*rtq**t*s into proper text.
1304 Note that this function guesses whether a character is a sm*rtq**t* or
1305 not, so it should only be used interactively."
1307 (article-translate-strings gnus-article-dumbquotes-map))
1309 (defun article-translate-characters (from to)
1310 "Translate all characters in the body of the article according to FROM and TO.
1311 FROM is a string of characters to translate from; to is a string of
1312 characters to translate to."
1314 (when (article-goto-body)
1315 (let ((buffer-read-only nil)
1316 (x (make-string 225 ?x))
1318 (while (< (incf i) (length x))
1321 (while (< i (length from))
1322 (aset x (aref from i) (aref to i))
1324 (translate-region (point) (point-max) x)))))
1326 (defun article-translate-strings (map)
1327 "Translate all string in the body of the article according to MAP.
1328 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1330 (when (article-goto-body)
1331 (let ((buffer-read-only nil)
1333 (while (setq elem (pop map))
1335 (while (search-forward (car elem) nil t)
1336 (replace-match (cadr elem)))))))))
1338 (defun article-treat-overstrike ()
1339 "Translate overstrikes into bold text."
1342 (when (article-goto-body)
1343 (let ((buffer-read-only nil))
1344 (while (search-forward "\b" nil t)
1345 (let ((next (char-after))
1346 (previous (char-after (- (point) 2))))
1347 ;; We do the boldification/underlining by hiding the
1348 ;; overstrikes and putting the proper text property
1352 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1353 (put-text-property (point) (1+ (point)) 'face 'bold))
1355 (gnus-article-hide-text-type
1356 (1- (point)) (1+ (point)) 'overstrike)
1358 (- (point) 2) (1- (point)) 'face 'underline))
1360 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1362 (point) (1+ (point)) 'face 'underline)))))))))
1364 (defun article-fill-long-lines ()
1365 "Fill lines that are wider than the window width."
1368 (let ((buffer-read-only nil)
1369 (width (window-width (get-buffer-window (current-buffer)))))
1372 (let ((adaptive-fill-mode nil))
1375 (when (>= (current-column) (min fill-column width))
1376 (narrow-to-region (point) (gnus-point-at-bol))
1377 (fill-paragraph nil)
1378 (goto-char (point-max))
1380 (forward-line 1)))))))
1382 (defun article-capitalize-sentences ()
1383 "Capitalize the first word in each sentence."
1386 (let ((buffer-read-only nil)
1387 (paragraph-start "^[\n\^L]"))
1391 (forward-sentence)))))
1393 (defun article-remove-cr ()
1394 "Remove trailing CRs and then translate remaining CRs into LFs."
1397 (let ((buffer-read-only nil))
1398 (goto-char (point-min))
1399 (while (re-search-forward "\r+$" nil t)
1400 (replace-match "" t t))
1401 (goto-char (point-min))
1402 (while (search-forward "\r" nil t)
1403 (replace-match "\n" t t)))))
1405 (defun article-remove-trailing-blank-lines ()
1406 "Remove all trailing blank lines from the article."
1409 (let ((buffer-read-only nil))
1410 (goto-char (point-max))
1414 (while (and (not (bobp))
1415 (looking-at "^[ \t]*$")
1416 (not (gnus-annotation-in-region-p
1417 (point) (gnus-point-at-eol))))
1422 (defun article-display-x-face (&optional force)
1423 "Look for an X-Face header and display it if present."
1424 (interactive (list 'force))
1426 ;; Delete the old process, if any.
1427 (when (process-status "article-x-face")
1428 (delete-process "article-x-face"))
1429 (let ((inhibit-point-motion-hooks t)
1430 (case-fold-search t)
1433 (article-narrow-to-head)
1434 (goto-char (point-min))
1435 (setq from (message-fetch-field "from"))
1436 (goto-char (point-min))
1437 (while (and gnus-article-x-face-command
1440 ;; Check whether this face is censored.
1441 (not gnus-article-x-face-too-ugly)
1442 (and gnus-article-x-face-too-ugly from
1443 (not (string-match gnus-article-x-face-too-ugly
1445 ;; Has to be present.
1446 (re-search-forward "^X-Face: " nil t))
1447 ;; This used to try to do multiple faces (`while' instead of
1448 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1449 ;; work (b) it can crash some versions of Emacs (c) are
1450 ;; multiple faces really something to encourage?
1451 (when (stringp gnus-article-x-face-command)
1453 ;; We now have the area of the buffer where the X-Face is stored.
1456 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1457 ;; We display the face.
1458 (if (symbolp gnus-article-x-face-command)
1459 ;; The command is a lisp function, so we call it.
1460 (if (gnus-functionp gnus-article-x-face-command)
1461 (funcall gnus-article-x-face-command beg end)
1462 (error "%s is not a function" gnus-article-x-face-command))
1463 ;; The command is a string, so we interpret the command
1464 ;; as a, well, command, and fork it off.
1465 (let ((process-connection-type nil))
1466 (process-kill-without-query
1468 "article-x-face" nil shell-file-name shell-command-switch
1469 gnus-article-x-face-command))
1470 (process-send-region "article-x-face" beg end)
1471 (process-send-eof "article-x-face"))))))))))
1473 (defun article-decode-mime-words ()
1474 "Decode all MIME-encoded words in the article."
1477 (set-buffer gnus-article-buffer)
1478 (let ((inhibit-point-motion-hooks t)
1480 (mail-parse-charset gnus-newsgroup-charset)
1481 (mail-parse-ignored-charsets
1482 (save-excursion (set-buffer gnus-summary-buffer)
1483 gnus-newsgroup-ignored-charsets)))
1484 (mail-decode-encoded-word-region (point-min) (point-max)))))
1486 (defun article-decode-charset (&optional prompt)
1487 "Decode charset-encoded text in the article.
1488 If PROMPT (the prefix), prompt for a coding system to use."
1490 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1492 (mail-parse-charset gnus-newsgroup-charset)
1493 (mail-parse-ignored-charsets
1494 (save-excursion (condition-case nil
1495 (set-buffer gnus-summary-buffer)
1497 gnus-newsgroup-ignored-charsets))
1498 ct cte ctl charset format)
1501 (article-narrow-to-head)
1502 (setq ct (message-fetch-field "Content-Type" t)
1503 cte (message-fetch-field "Content-Transfer-Encoding" t)
1504 ctl (and ct (ignore-errors
1505 (mail-header-parse-content-type ct)))
1508 (mm-read-coding-system "Charset to decode: "))
1510 (mail-content-type-get ctl 'charset)))
1511 format (and ctl (mail-content-type-get ctl 'format)))
1513 (setq cte (mail-header-strip cte)))
1514 (if (and ctl (not (string-match "/" (car ctl))))
1516 (goto-char (point-max)))
1519 (narrow-to-region (point) (point-max))
1520 (when (and (eq mail-parse-charset 'gnus-decoded)
1521 (eq (mm-body-7-or-8) '8bit))
1522 ;; The text code could have been decoded.
1523 (setq charset mail-parse-charset))
1524 (when (and (or (not ctl)
1525 (equal (car ctl) "text/plain"))
1526 (not format)) ;; article with format will decode later.
1528 charset (and cte (intern (downcase
1529 (gnus-strip-whitespace cte))))
1532 (defun article-decode-encoded-words ()
1533 "Remove encoded-word encoding from headers."
1534 (let ((inhibit-point-motion-hooks t)
1535 (mail-parse-charset gnus-newsgroup-charset)
1536 (mail-parse-ignored-charsets
1537 (save-excursion (condition-case nil
1538 (set-buffer gnus-summary-buffer)
1540 gnus-newsgroup-ignored-charsets))
1543 (article-narrow-to-head)
1544 (funcall gnus-decode-header-function (point-min) (point-max)))))
1546 (defun article-de-quoted-unreadable (&optional force)
1547 "Translate a quoted-printable-encoded article.
1548 If FORCE, decode the article whether it is marked as quoted-printable
1550 (interactive (list 'force))
1552 (let ((buffer-read-only nil) type charset)
1553 (if (gnus-buffer-live-p gnus-original-article-buffer)
1554 (with-current-buffer gnus-original-article-buffer
1556 (gnus-fetch-field "content-transfer-encoding"))
1557 (let* ((ct (gnus-fetch-field "content-type"))
1560 (mail-header-parse-content-type ct)))))
1561 (setq charset (and ctl
1562 (mail-content-type-get ctl 'charset)))
1563 (if (stringp charset)
1564 (setq charset (intern (downcase charset)))))))
1566 (setq charset gnus-newsgroup-charset))
1568 (and type (let ((case-fold-search t))
1569 (string-match "quoted-printable" type))))
1571 (quoted-printable-decode-region
1572 (point) (point-max) (mm-charset-to-coding-system charset))))))
1574 (defun article-de-base64-unreadable (&optional force)
1575 "Translate a base64 article.
1576 If FORCE, decode the article whether it is marked as base64 not."
1577 (interactive (list 'force))
1579 (let ((buffer-read-only nil) type charset)
1580 (if (gnus-buffer-live-p gnus-original-article-buffer)
1581 (with-current-buffer gnus-original-article-buffer
1583 (gnus-fetch-field "content-transfer-encoding"))
1584 (let* ((ct (gnus-fetch-field "content-type"))
1587 (mail-header-parse-content-type ct)))))
1588 (setq charset (and ctl
1589 (mail-content-type-get ctl 'charset)))
1590 (if (stringp charset)
1591 (setq charset (intern (downcase charset)))))))
1593 (setq charset gnus-newsgroup-charset))
1595 (and type (let ((case-fold-search t))
1596 (string-match "base64" type))))
1599 (narrow-to-region (point) (point-max))
1600 (base64-decode-region (point-min) (point-max))
1601 (mm-decode-coding-region
1602 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1607 (defun article-decode-HZ ()
1608 "Translate a HZ-encoded article."
1612 (let ((buffer-read-only nil))
1613 (rfc1843-decode-region (point-min) (point-max)))))
1615 (defun article-wash-html ()
1616 "Format an html article."
1619 (let ((buffer-read-only nil)
1621 (if (gnus-buffer-live-p gnus-original-article-buffer)
1622 (with-current-buffer gnus-original-article-buffer
1623 (let* ((ct (gnus-fetch-field "content-type"))
1626 (mail-header-parse-content-type ct)))))
1627 (setq charset (and ctl
1628 (mail-content-type-get ctl 'charset)))
1629 (if (stringp charset)
1630 (setq charset (intern (downcase charset)))))))
1632 (setq charset gnus-newsgroup-charset))
1634 (save-window-excursion
1636 (narrow-to-region (point) (point-max))
1638 (let ((w3-strict-width (window-width))
1639 (url-standalone-mode t))
1641 (w3-region (point-min) (point-max))
1644 (defun article-hide-list-identifiers ()
1645 "Remove list identifies from the Subject header.
1646 The `gnus-list-identifiers' variable specifies what to do."
1650 (let ((inhibit-point-motion-hooks t)
1652 (article-narrow-to-head)
1653 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1654 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1656 (goto-char (point-min))
1657 (when (re-search-forward
1658 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1659 " *\\)\\)+\\(Re: +\\)?\\)")
1661 (let ((s (or (match-string 3) (match-string 5))))
1662 (delete-region (match-beginning 1) (match-end 1))
1664 (goto-char (match-beginning 1))
1667 (defun article-hide-pgp ()
1668 "Remove any PGP headers and signatures in the current article."
1672 (let ((inhibit-point-motion-hooks t)
1673 buffer-read-only beg end)
1675 ;; Hide the "header".
1676 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1677 (push 'pgp gnus-article-wash-types)
1678 (delete-region (match-beginning 0) (match-end 0))
1679 ;; Remove armor headers (rfc2440 6.2)
1680 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1683 ;; Hide the actual signature.
1684 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1685 (setq end (1+ (match-beginning 0)))
1688 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1690 ;; Perhaps we shouldn't hide to the end of the buffer
1691 ;; if there is no end to the signature?
1693 ;; Hide "- " PGP quotation markers.
1695 (narrow-to-region beg end)
1696 (goto-char (point-min))
1697 (while (re-search-forward "^- " nil t)
1699 (match-beginning 0) (match-end 0)))
1701 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1703 (defun article-hide-pem (&optional arg)
1704 "Toggle hiding of any PEM headers and signatures in the current article.
1705 If given a negative prefix, always show; if given a positive prefix,
1707 (interactive (gnus-article-hidden-arg))
1708 (unless (gnus-article-check-hidden-text 'pem arg)
1710 (let (buffer-read-only end)
1711 (goto-char (point-min))
1712 ;; Hide the horrendously ugly "header".
1713 (when (and (search-forward
1714 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1716 (setq end (1+ (match-beginning 0))))
1717 (push 'pem gnus-article-wash-types)
1718 (gnus-article-hide-text-type
1720 (if (search-forward "\n\n" nil t)
1724 ;; Hide the trailer as well
1725 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1727 (gnus-article-hide-text-type
1728 (match-beginning 0) (match-end 0) 'pem)))))))
1730 (defun article-strip-banner ()
1731 "Strip the banner specified by the `banner' group parameter."
1735 (let ((inhibit-point-motion-hooks t)
1736 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1737 (gnus-signature-limit nil)
1738 buffer-read-only beg end)
1742 ((eq banner 'signature)
1743 (when (gnus-article-narrow-to-signature)
1746 (delete-region (point) (point-max))))
1748 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1749 (while (re-search-forward banner nil t)
1750 (delete-region (match-beginning 0) (match-end 0)))))
1752 (while (re-search-forward banner nil t)
1753 (delete-region (match-beginning 0) (match-end 0))))))))))
1755 (defun article-babel ()
1756 "Translate article using an online translation service."
1760 (set-buffer gnus-article-buffer)
1761 (when (article-goto-body)
1762 (let* ((buffer-read-only nil)
1765 (orig (buffer-substring start end))
1766 (trans (babel-as-string orig)))
1768 (narrow-to-region start end)
1769 (delete-region start end)
1772 (defun article-hide-signature (&optional arg)
1773 "Hide the signature in the current article.
1774 If given a negative prefix, always show; if given a positive prefix,
1776 (interactive (gnus-article-hidden-arg))
1777 (unless (gnus-article-check-hidden-text 'signature arg)
1780 (let ((buffer-read-only nil))
1781 (when (gnus-article-narrow-to-signature)
1782 (gnus-article-hide-text-type
1783 (point-min) (point-max) 'signature)))))))
1785 (defun article-strip-headers-in-body ()
1786 "Strip offensive headers from bodies."
1790 (let ((case-fold-search t))
1791 (when (looking-at "x-no-archive:")
1792 (gnus-delete-line)))))
1794 (defun article-strip-leading-blank-lines ()
1795 "Remove all blank lines from the beginning of the article."
1798 (let ((inhibit-point-motion-hooks t)
1800 (when (article-goto-body)
1801 (while (and (not (eobp))
1802 (looking-at "[ \t]*$"))
1803 (gnus-delete-line))))))
1805 (defun article-narrow-to-head ()
1806 "Narrow the buffer to the head of the message.
1807 Point is left at the beginning of the narrowed-to region."
1809 (goto-char (point-min))
1810 (if (search-forward "\n\n" nil 1)
1813 (goto-char (point-min)))
1815 (defun article-goto-body ()
1816 "Place point at the start of the body."
1817 (goto-char (point-min))
1819 ;; This variable is only bound when dealing with separate
1821 (article-goto-body-goes-to-point-min-p
1823 ((search-forward "\n\n" nil t)
1826 (goto-char (point-max))
1829 (defun article-strip-multiple-blank-lines ()
1830 "Replace consecutive blank lines with one empty line."
1833 (let ((inhibit-point-motion-hooks t)
1835 ;; First make all blank lines empty.
1837 (while (re-search-forward "^[ \t]+$" nil t)
1838 (unless (gnus-annotation-in-region-p
1839 (match-beginning 0) (match-end 0))
1840 (replace-match "" nil t)))
1841 ;; Then replace multiple empty lines with a single empty line.
1843 (while (re-search-forward "\n\n\n+" nil t)
1844 (unless (gnus-annotation-in-region-p
1845 (match-beginning 0) (match-end 0))
1846 (replace-match "\n\n" t t))))))
1848 (defun article-strip-leading-space ()
1849 "Remove all white space from the beginning of the lines in the article."
1852 (let ((inhibit-point-motion-hooks t)
1855 (while (re-search-forward "^[ \t]+" nil t)
1856 (replace-match "" t t)))))
1858 (defun article-strip-trailing-space ()
1859 "Remove all white space from the end of the lines in the article."
1862 (let ((inhibit-point-motion-hooks t)
1865 (while (re-search-forward "[ \t]+$" nil t)
1866 (replace-match "" t t)))))
1868 (defun article-strip-blank-lines ()
1869 "Strip leading, trailing and multiple blank lines."
1871 (article-strip-leading-blank-lines)
1872 (article-remove-trailing-blank-lines)
1873 (article-strip-multiple-blank-lines))
1875 (defun article-strip-all-blank-lines ()
1876 "Strip all blank lines."
1879 (let ((inhibit-point-motion-hooks t)
1882 (while (re-search-forward "^[ \t]*\n" nil t)
1883 (replace-match "" t t)))))
1885 (defun gnus-article-narrow-to-signature ()
1886 "Narrow to the signature; return t if a signature is found, else nil."
1887 (let ((inhibit-point-motion-hooks t))
1888 (when (gnus-article-search-signature)
1890 ;; Check whether we have some limits to what we consider
1891 ;; to be a signature.
1892 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1893 (list gnus-signature-limit)))
1895 (while (setq limit (pop limits))
1896 (if (or (and (integerp limit)
1897 (< (- (point-max) (point)) limit))
1899 (< (count-lines (point) (point-max)) limit))
1900 (and (gnus-functionp limit)
1902 (and (stringp limit)
1903 (not (re-search-forward limit nil t))))
1904 () ; This limit did not succeed.
1908 (narrow-to-region (point) (point-max))
1911 (defun gnus-article-search-signature ()
1912 "Search the current buffer for the signature separator.
1913 Put point at the beginning of the signature separator."
1914 (let ((cur (point)))
1915 (goto-char (point-max))
1916 (if (if (stringp gnus-signature-separator)
1917 (re-search-backward gnus-signature-separator nil t)
1918 (let ((seps gnus-signature-separator))
1920 (not (re-search-backward (car seps) nil t)))
1927 (defun gnus-article-hidden-arg ()
1928 "Return the current prefix arg as a number, or 0 if no prefix."
1929 (list (if current-prefix-arg
1930 (prefix-numeric-value current-prefix-arg)
1933 (defun gnus-article-check-hidden-text (type arg)
1934 "Return nil if hiding is necessary.
1935 Arg can be nil or a number. Nil and positive means hide, negative
1936 means show, 0 means toggle."
1939 (let ((hide (gnus-article-hidden-text-p type)))
1945 (gnus-article-show-hidden-text type))
1947 (if (eq hide 'hidden)
1948 (gnus-article-show-hidden-text type)
1951 (defun gnus-article-hidden-text-p (type)
1952 "Say whether the current buffer contains hidden text of type TYPE."
1953 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1955 (not (get-text-property pos 'invisible))
1956 (not (get-text-property pos 'dummy-invisible)))
1958 (text-property-any (1+ pos) (point-max) 'article-type type)))
1963 (defun gnus-article-show-hidden-text (type &optional hide)
1964 "Show all hidden text of type TYPE.
1965 If HIDE, hide the text instead."
1967 (let ((buffer-read-only nil)
1968 (inhibit-point-motion-hooks t)
1971 (while (setq beg (text-property-any end (point-max) 'article-type type))
1974 (text-property-not-all beg (point-max) 'article-type type)
1977 (gnus-article-hide-text beg end gnus-hidden-properties)
1978 (gnus-article-unhide-text beg end))
1982 (defconst article-time-units
1983 `((year . ,(* 365.25 24 60 60))
1984 (week . ,(* 7 24 60 60))
1985 (day . ,(* 24 60 60))
1989 "Mapping from time units to seconds.")
1991 (defun article-date-ut (&optional type highlight header)
1992 "Convert DATE date to universal time in the current article.
1993 If TYPE is `local', convert to local time; if it is `lapsed', output
1994 how much time has lapsed since DATE. For `lapsed', the value of
1995 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1996 should replace the \"Date:\" one, or should be added below it."
1997 (interactive (list 'ut t))
1998 (let* ((header (or header
1999 (message-fetch-field "date")
2001 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2004 ((not gnus-article-date-lapsed-new-header)
2010 (date (if (vectorp header) (mail-header-date header)
2012 (inhibit-point-motion-hooks t)
2017 (article-narrow-to-head)
2018 (when (re-search-forward tdate-regexp nil t)
2019 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2020 date (or (get-text-property (gnus-point-at-bol)
2023 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2025 (when (and date (not (string= date "")))
2026 (goto-char (point-min))
2027 (let ((buffer-read-only nil))
2028 ;; Delete any old Date headers.
2029 (while (re-search-forward date-regexp nil t)
2031 (delete-region (progn (beginning-of-line) (point))
2032 (progn (forward-line 1) (point)))
2033 (delete-region (progn (beginning-of-line) (point))
2034 (progn (end-of-line) (point)))
2035 (setq pos (point))))
2036 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2038 (if pos (goto-char pos))
2039 (insert (article-make-date-line date (or type 'ut)))
2045 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2046 (put-text-property (match-beginning 1) (1+ (match-end 1))
2047 'original-date date)
2048 (put-text-property (match-beginning 1) (1+ (match-end 1))
2050 (put-text-property (match-beginning 2) (match-end 2)
2053 (defun article-make-date-line (date type)
2054 "Return a DATE line of TYPE."
2055 (let ((time (condition-case ()
2059 ;; Convert to the local timezone. We have to slap a
2060 ;; `condition-case' round the calls to the timezone
2061 ;; functions since they aren't particularly resistant to
2064 (let ((tz (car (current-time-zone time))))
2065 (format "Date: %s %s%02d%02d" (current-time-string time)
2066 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2067 (/ (% (abs tz) 3600) 60))))
2068 ;; Convert to Universal Time.
2071 (current-time-string
2072 (let* ((e (parse-time-string date))
2073 (tm (apply 'encode-time e))
2075 (ls (- (cadr tm) (car (current-time-zone time)))))
2076 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2077 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2080 ;; Get the original date from the article.
2081 ((eq type 'original)
2082 (concat "Date: " (if (string-match "\n+$" date)
2083 (substring date 0 (match-beginning 0))
2085 ;; Let the user define the format.
2087 (if (gnus-functionp gnus-article-time-format)
2088 (funcall gnus-article-time-format time)
2091 (format-time-string gnus-article-time-format time))))
2094 (let ((tz (car (current-time-zone time))))
2097 (format-time-string "%Y%m%dT%H%M%S" time)
2098 (format "%s%02d%02d"
2099 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2100 (/ (% (abs tz) 3600) 60)))))
2101 ;; Do an X-Sent lapsed format.
2103 ;; If the date is seriously mangled, the timezone functions are
2104 ;; liable to bug out, so we ignore all errors.
2105 (let* ((now (current-time))
2106 (real-time (subtract-time now time))
2107 (real-sec (and real-time
2108 (+ (* (float (car real-time)) 65536)
2110 (sec (and real-time (abs real-sec)))
2120 ;; This is a bit convoluted, but basically we go
2121 ;; through the time units for years, weeks, etc,
2122 ;; and divide things to see whether that results
2123 ;; in positive answers.
2126 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2127 ;; The (remaining) seconds are too few to
2128 ;; be divided into this time unit.
2130 ;; It's big enough, so we output it.
2131 (setq sec (- sec (* num (cdr unit))))
2133 (concat (if prev ", " "") (int-to-string
2135 " " (symbol-name (car unit))
2136 (if (> num 1) "s" ""))
2138 article-time-units "")
2139 ;; If dates are odd, then it might appear like the
2140 ;; article was sent in the future.
2143 " in the future"))))))
2145 (error "Unknown conversion type: %s" type)))))
2147 (defun article-date-local (&optional highlight)
2148 "Convert the current article date to the local timezone."
2149 (interactive (list t))
2150 (article-date-ut 'local highlight))
2152 (defun article-date-original (&optional highlight)
2153 "Convert the current article date to what it was originally.
2154 This is only useful if you have used some other date conversion
2155 function and want to see what the date was before converting."
2156 (interactive (list t))
2157 (article-date-ut 'original highlight))
2159 (defun article-date-lapsed (&optional highlight)
2160 "Convert the current article date to time lapsed since it was sent."
2161 (interactive (list t))
2162 (article-date-ut 'lapsed highlight))
2164 (defun article-update-date-lapsed ()
2165 "Function to be run from a timer to update the lapsed time line."
2166 (let (deactivate-mark)
2171 (set-buffer (window-buffer w))
2172 (when (eq major-mode 'gnus-article-mode)
2173 (goto-char (point-min))
2174 (when (re-search-forward "^X-Sent:" nil t)
2175 (article-date-lapsed t))))
2178 (defun gnus-start-date-timer (&optional n)
2179 "Start a timer to update the X-Sent header in the article buffers.
2180 The numerical prefix says how frequently (in seconds) the function
2185 (gnus-stop-date-timer)
2186 (setq article-lapsed-timer
2187 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2189 (defun gnus-stop-date-timer ()
2190 "Stop the X-Sent timer."
2192 (when article-lapsed-timer
2193 (nnheader-cancel-timer article-lapsed-timer)
2194 (setq article-lapsed-timer nil)))
2196 (defun article-date-user (&optional highlight)
2197 "Convert the current article date to the user-defined format.
2198 This format is defined by the `gnus-article-time-format' variable."
2199 (interactive (list t))
2200 (article-date-ut 'user highlight))
2202 (defun article-date-iso8601 (&optional highlight)
2203 "Convert the current article date to ISO8601."
2204 (interactive (list t))
2205 (article-date-ut 'iso8601 highlight))
2207 (defun article-show-all ()
2208 "Show all hidden text in the article buffer."
2211 (let ((buffer-read-only nil))
2212 (gnus-article-unhide-text (point-min) (point-max)))))
2214 (defun article-emphasize (&optional arg)
2215 "Emphasize text according to `gnus-emphasis-alist'."
2216 (interactive (gnus-article-hidden-arg))
2217 (unless (gnus-article-check-hidden-text 'emphasis arg)
2221 (with-current-buffer gnus-summary-buffer
2222 gnus-article-emphasis-alist)
2224 gnus-emphasis-alist))
2225 (buffer-read-only nil)
2226 (props (append '(article-type emphasis)
2227 gnus-hidden-properties))
2228 regexp elem beg invisible visible face)
2231 (while (setq elem (pop alist))
2233 (setq regexp (car elem)
2234 invisible (nth 1 elem)
2235 visible (nth 2 elem)
2237 (while (re-search-forward regexp nil t)
2238 (when (and (match-beginning visible) (match-beginning invisible))
2239 (push 'emphasis gnus-article-wash-types)
2240 (gnus-article-hide-text
2241 (match-beginning invisible) (match-end invisible) props)
2242 (gnus-article-unhide-text-type
2243 (match-beginning visible) (match-end visible) 'emphasis)
2244 (gnus-put-text-property-excluding-newlines
2245 (match-beginning visible) (match-end visible) 'face face)
2246 (goto-char (match-end invisible)))))))))
2248 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2249 "Setup newsgroup emphasis alist."
2250 (unless gnus-article-emphasis-alist
2251 (let ((name (and gnus-newsgroup-name
2252 (gnus-group-real-name gnus-newsgroup-name))))
2253 (make-local-variable 'gnus-article-emphasis-alist)
2254 (setq gnus-article-emphasis-alist
2256 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2257 (while (setq elem (pop alist))
2258 (when (and name (string-match (car elem) name))
2260 highlight (copy-sequence (cdr elem)))))
2262 (copy-sequence highlight-words)
2263 (if gnus-newsgroup-name
2264 (copy-sequence (gnus-group-find-parameter
2265 gnus-newsgroup-name 'highlight-words t)))
2266 gnus-emphasis-alist)))))
2268 (defvar gnus-summary-article-menu)
2269 (defvar gnus-summary-post-menu)
2271 ;;; Saving functions.
2273 (defun gnus-article-save (save-buffer file &optional num)
2274 "Save the currently selected article."
2275 (unless gnus-save-all-headers
2276 ;; Remove headers according to `gnus-saved-headers'.
2277 (let ((gnus-visible-headers
2278 (or gnus-saved-headers gnus-visible-headers))
2279 (gnus-article-buffer save-buffer))
2281 (set-buffer save-buffer)
2282 (article-hide-headers 1 t))))
2283 (save-window-excursion
2284 (if (not gnus-default-article-saver)
2285 (error "No default saver is defined")
2286 ;; !!! Magic! The saving functions all save
2287 ;; `gnus-save-article-buffer' (or so they think), but we
2288 ;; bind that variable to our save-buffer.
2289 (set-buffer gnus-article-buffer)
2290 (let* ((gnus-save-article-buffer save-buffer)
2293 ((not gnus-prompt-before-saving) 'default)
2294 ((eq gnus-prompt-before-saving 'always) nil)
2296 (gnus-number-of-articles-to-be-saved
2297 (when (eq gnus-prompt-before-saving t)
2299 (set-buffer gnus-article-current-summary)
2300 (funcall gnus-default-article-saver filename)))))
2302 (defun gnus-read-save-file-name (prompt &optional filename
2303 function group headers variable)
2305 (funcall function group headers (symbol-value variable)))
2310 ((eq filename 'default)
2316 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2319 (if (and gnus-number-of-articles-to-be-saved
2320 (> gnus-number-of-articles-to-be-saved 1))
2321 (format "these %d articles"
2322 gnus-number-of-articles-to-be-saved)
2325 ;; Let the split methods have their say.
2327 ;; No split name was found.
2330 (concat prompt " (default "
2331 (file-name-nondirectory default-name) ") ")
2332 (file-name-directory default-name)
2334 ;; A single group name is returned.
2335 ((stringp split-name)
2337 (funcall function split-name headers
2338 (symbol-value variable)))
2340 (concat prompt " (default "
2341 (file-name-nondirectory default-name) ") ")
2342 (file-name-directory default-name)
2344 ;; A single split name was found
2345 ((= 1 (length split-name))
2346 (let* ((name (expand-file-name
2348 gnus-article-save-directory))
2349 (dir (cond ((file-directory-p name)
2350 (file-name-as-directory name))
2351 ((file-exists-p name) name)
2352 (t gnus-article-save-directory))))
2354 (concat prompt " (default " name ") ")
2356 ;; A list of splits was found.
2358 (setq split-name (nreverse split-name))
2360 (let ((file-name-history
2361 (nconc split-name file-name-history)))
2365 (concat prompt " (`M-p' for defaults) ")
2366 gnus-article-save-directory
2368 gnus-article-save-directory)))
2369 (car (push result file-name-history)))))))
2370 ;; Create the directory.
2371 (gnus-make-directory (file-name-directory file))
2372 ;; If we have read a directory, we append the default file name.
2373 (when (file-directory-p file)
2374 (setq file (expand-file-name (file-name-nondirectory
2376 (file-name-as-directory file))))
2377 ;; Possibly translate some characters.
2378 (nnheader-translate-file-chars file))))))
2379 (gnus-make-directory (file-name-directory result))
2380 (set variable result)))
2382 (defun gnus-article-archive-name (group)
2383 "Return the first instance of an \"Archive-name\" in the current buffer."
2384 (let ((case-fold-search t))
2385 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2386 (nnheader-concat gnus-article-save-directory
2387 (match-string 1)))))
2389 (defun gnus-article-nndoc-name (group)
2390 "If GROUP is an nndoc group, return the name of the parent group."
2391 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2392 (gnus-group-get-parameter group 'save-article-group)))
2394 (defun gnus-summary-save-in-rmail (&optional filename)
2395 "Append this article to Rmail file.
2396 Optional argument FILENAME specifies file name.
2397 Directory to save to is default to `gnus-article-save-directory'."
2398 (setq filename (gnus-read-save-file-name
2399 "Save %s in rmail file:" filename
2400 gnus-rmail-save-name gnus-newsgroup-name
2401 gnus-current-headers 'gnus-newsgroup-last-rmail))
2402 (gnus-eval-in-buffer-window gnus-save-article-buffer
2406 (gnus-output-to-rmail filename))))
2409 (defun gnus-summary-save-in-mail (&optional filename)
2410 "Append this article to Unix mail file.
2411 Optional argument FILENAME specifies file name.
2412 Directory to save to is default to `gnus-article-save-directory'."
2413 (setq filename (gnus-read-save-file-name
2414 "Save %s in Unix mail file:" filename
2415 gnus-mail-save-name gnus-newsgroup-name
2416 gnus-current-headers 'gnus-newsgroup-last-mail))
2417 (gnus-eval-in-buffer-window gnus-save-article-buffer
2421 (if (and (file-readable-p filename)
2422 (mail-file-babyl-p filename))
2423 (rmail-output-to-rmail-file filename t)
2424 (gnus-output-to-mail filename)))))
2427 (defun gnus-summary-save-in-file (&optional filename overwrite)
2428 "Append this article to file.
2429 Optional argument FILENAME specifies file name.
2430 Directory to save to is default to `gnus-article-save-directory'."
2431 (setq filename (gnus-read-save-file-name
2432 "Save %s in file:" filename
2433 gnus-file-save-name gnus-newsgroup-name
2434 gnus-current-headers 'gnus-newsgroup-last-file))
2435 (gnus-eval-in-buffer-window gnus-save-article-buffer
2439 (when (and overwrite
2440 (file-exists-p filename))
2441 (delete-file filename))
2442 (gnus-output-to-file filename))))
2445 (defun gnus-summary-write-to-file (&optional filename)
2446 "Write this article to a file.
2447 Optional argument FILENAME specifies file name.
2448 The directory to save in defaults to `gnus-article-save-directory'."
2449 (gnus-summary-save-in-file nil t))
2451 (defun gnus-summary-save-body-in-file (&optional filename)
2452 "Append this article body to a file.
2453 Optional argument FILENAME specifies file name.
2454 The directory to save in defaults to `gnus-article-save-directory'."
2455 (setq filename (gnus-read-save-file-name
2456 "Save %s body in file:" filename
2457 gnus-file-save-name gnus-newsgroup-name
2458 gnus-current-headers 'gnus-newsgroup-last-file))
2459 (gnus-eval-in-buffer-window gnus-save-article-buffer
2463 (when (article-goto-body)
2464 (narrow-to-region (point) (point-max)))
2465 (gnus-output-to-file filename))))
2468 (defun gnus-summary-save-in-pipe (&optional command)
2469 "Pipe this article to subprocess."
2471 (cond ((and (eq command 'default)
2472 gnus-last-shell-command)
2473 gnus-last-shell-command)
2477 "Shell command on %s: "
2478 (if (and gnus-number-of-articles-to-be-saved
2479 (> gnus-number-of-articles-to-be-saved 1))
2480 (format "these %d articles"
2481 gnus-number-of-articles-to-be-saved)
2483 gnus-last-shell-command))))
2484 (when (string-equal command "")
2485 (setq command gnus-last-shell-command))
2486 (gnus-eval-in-buffer-window gnus-article-buffer
2489 (shell-command-on-region (point-min) (point-max) command nil)))
2490 (setq gnus-last-shell-command command))
2492 ;;; Article file names when saving.
2494 (defun gnus-capitalize-newsgroup (newsgroup)
2495 "Capitalize NEWSGROUP name."
2496 (when (not (zerop (length newsgroup)))
2497 (concat (char-to-string (upcase (aref newsgroup 0)))
2498 (substring newsgroup 1))))
2500 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2501 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2502 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2503 Otherwise, it is like ~/News/news/group/num."
2506 (concat (if (gnus-use-long-file-name 'not-save)
2507 (gnus-capitalize-newsgroup newsgroup)
2508 (gnus-newsgroup-directory-form newsgroup))
2509 "/" (int-to-string (mail-header-number headers)))
2510 gnus-article-save-directory)))
2512 (string-equal (file-name-directory default)
2513 (file-name-directory last-file))
2514 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2516 (or last-file default))))
2518 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2519 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2520 If variable `gnus-use-long-file-name' is non-nil, it is
2521 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2524 (concat (if (gnus-use-long-file-name 'not-save)
2526 (gnus-newsgroup-directory-form newsgroup))
2527 "/" (int-to-string (mail-header-number headers)))
2528 gnus-article-save-directory)))
2530 (string-equal (file-name-directory default)
2531 (file-name-directory last-file))
2532 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2534 (or last-file default))))
2536 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2537 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2538 If variable `gnus-use-long-file-name' is non-nil, it is
2539 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2542 (if (gnus-use-long-file-name 'not-save)
2544 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2545 gnus-article-save-directory)))
2552 (setq afunc (car func)
2555 gfunc (intern (format "gnus-%s" func))))
2558 `(lambda (&optional interactive &rest args)
2559 ,(documentation afunc t)
2560 (interactive (list t))
2562 (set-buffer gnus-article-buffer)
2564 (call-interactively ',afunc)
2565 (apply ',afunc args))))))))
2566 '(article-hide-headers
2567 article-hide-boring-headers
2568 article-treat-overstrike
2569 article-fill-long-lines
2570 article-capitalize-sentences
2572 article-display-x-face
2573 article-de-quoted-unreadable
2574 article-de-base64-unreadable
2577 article-hide-list-identifiers
2579 article-strip-banner
2582 article-hide-signature
2583 article-strip-headers-in-body
2584 article-remove-trailing-blank-lines
2585 article-strip-leading-blank-lines
2586 article-strip-multiple-blank-lines
2587 article-strip-leading-space
2588 article-strip-trailing-space
2589 article-strip-blank-lines
2590 article-strip-all-blank-lines
2592 article-date-iso8601
2593 article-date-original
2595 article-decode-mime-words
2596 article-decode-charset
2597 article-decode-encoded-words
2601 article-treat-dumbquotes
2602 article-normalize-headers
2603 (article-show-all . gnus-article-show-all-headers))))
2606 ;;; Gnus article mode
2609 (put 'gnus-article-mode 'mode-class 'special)
2611 (set-keymap-parent gnus-article-mode-map widget-keymap)
2613 (gnus-define-keys gnus-article-mode-map
2614 " " gnus-article-goto-next-page
2615 "\177" gnus-article-goto-prev-page
2616 [delete] gnus-article-goto-prev-page
2617 [backspace] gnus-article-goto-prev-page
2618 "\C-c^" gnus-article-refer-article
2619 "h" gnus-article-show-summary
2620 "s" gnus-article-show-summary
2621 "\C-c\C-m" gnus-article-mail
2622 "?" gnus-article-describe-briefly
2623 "e" gnus-summary-edit-article
2624 "<" beginning-of-buffer
2626 "\C-c\C-i" gnus-info-find-node
2629 "\C-d" gnus-article-read-summary-keys
2630 "\M-*" gnus-article-read-summary-keys
2631 "\M-#" gnus-article-read-summary-keys
2632 "\M-^" gnus-article-read-summary-keys
2633 "\M-g" gnus-article-read-summary-keys)
2635 (substitute-key-definition
2636 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2638 (defun gnus-article-make-menu-bar ()
2639 (gnus-turn-off-edit-menu 'article)
2640 (unless (boundp 'gnus-article-article-menu)
2642 gnus-article-article-menu gnus-article-mode-map ""
2644 ["Scroll forwards" gnus-article-goto-next-page t]
2645 ["Scroll backwards" gnus-article-goto-prev-page t]
2646 ["Show summary" gnus-article-show-summary t]
2647 ["Fetch Message-ID at point" gnus-article-refer-article t]
2648 ["Mail to address at point" gnus-article-mail t]
2649 ["Send a bug report" gnus-bug t]))
2652 gnus-article-treatment-menu gnus-article-mode-map ""
2654 ["Hide headers" gnus-article-hide-headers t]
2655 ["Hide signature" gnus-article-hide-signature t]
2656 ["Hide citation" gnus-article-hide-citation t]
2657 ["Treat overstrike" gnus-article-treat-overstrike t]
2658 ["Remove carriage return" gnus-article-remove-cr t]
2659 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2660 ["Remove base64" gnus-article-de-base64-unreadable t]
2661 ["Treat html" gnus-article-wash-html t]
2662 ["Decode HZ" gnus-article-decode-HZ t]))
2664 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2666 (when (boundp 'gnus-summary-post-menu)
2667 (define-key gnus-article-mode-map [menu-bar post]
2668 (cons "Post" gnus-summary-post-menu)))
2670 (gnus-run-hooks 'gnus-article-menu-hook)))
2672 (defun gnus-article-mode ()
2673 "Major mode for displaying an article.
2675 All normal editing commands are switched off.
2677 The following commands are available in addition to all summary mode
2679 \\<gnus-article-mode-map>
2680 \\[gnus-article-next-page]\t Scroll the article one page forwards
2681 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2682 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2683 \\[gnus-article-show-summary]\t Display the summary buffer
2684 \\[gnus-article-mail]\t Send a reply to the address near point
2685 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2686 \\[gnus-info-find-node]\t Go to the Gnus info node"
2688 (when (gnus-visual-p 'article-menu 'menu)
2689 (gnus-article-make-menu-bar))
2690 (gnus-simplify-mode-line)
2691 (setq mode-name "Article")
2692 (setq major-mode 'gnus-article-mode)
2693 (make-local-variable 'minor-mode-alist)
2694 (use-local-map gnus-article-mode-map)
2695 (gnus-update-format-specifications nil 'article-mode)
2696 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2697 (make-local-variable 'gnus-page-broken)
2698 (make-local-variable 'gnus-button-marker-list)
2699 (make-local-variable 'gnus-article-current-summary)
2700 (make-local-variable 'gnus-article-mime-handles)
2701 (make-local-variable 'gnus-article-decoded-p)
2702 (make-local-variable 'gnus-article-mime-handle-alist)
2703 (make-local-variable 'gnus-article-wash-types)
2704 (gnus-set-default-directory)
2705 (buffer-disable-undo)
2706 (setq buffer-read-only t)
2707 (set-syntax-table gnus-article-mode-syntax-table)
2708 (mm-enable-multibyte)
2709 (gnus-run-hooks 'gnus-article-mode-hook))
2711 (defun gnus-article-setup-buffer ()
2712 "Initialize the article buffer."
2713 (let* ((name (if gnus-single-article-buffer "*Article*"
2714 (concat "*Article " gnus-newsgroup-name "*")))
2716 (progn (string-match "\\*Article" name)
2717 (concat " *Original Article"
2718 (substring name (match-end 0))))))
2719 (setq gnus-article-buffer name)
2720 (setq gnus-original-article-buffer original)
2721 (setq gnus-article-mime-handle-alist nil)
2722 ;; This might be a variable local to the summary buffer.
2723 (unless gnus-single-article-buffer
2725 (set-buffer gnus-summary-buffer)
2726 (setq gnus-article-buffer name)
2727 (setq gnus-original-article-buffer original)
2728 (gnus-set-global-variables)))
2729 (gnus-article-setup-highlight-words)
2730 ;; Init original article buffer.
2732 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2733 (mm-enable-multibyte)
2734 (setq major-mode 'gnus-original-article-mode)
2735 (make-local-variable 'gnus-original-article))
2736 (if (get-buffer name)
2739 (when gnus-article-mime-handles
2740 (mm-destroy-parts gnus-article-mime-handles)
2741 (setq gnus-article-mime-handles nil))
2742 ;; Set it to nil in article-buffer!
2743 (setq gnus-article-mime-handle-alist nil)
2744 (buffer-disable-undo)
2745 (setq buffer-read-only t)
2746 (unless (eq major-mode 'gnus-article-mode)
2747 (gnus-article-mode))
2750 (set-buffer (gnus-get-buffer-create name))
2752 (make-local-variable 'gnus-summary-buffer)
2753 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2754 (current-buffer)))))
2756 ;; Set article window start at LINE, where LINE is the number of lines
2757 ;; from the head of the article.
2758 (defun gnus-article-set-window-start (&optional line)
2760 (get-buffer-window gnus-article-buffer t)
2762 (set-buffer gnus-article-buffer)
2763 (goto-char (point-min))
2766 (gnus-message 6 "Moved to bookmark")
2767 (search-forward "\n\n" nil t)
2771 (defun gnus-article-prepare (article &optional all-headers header)
2772 "Prepare ARTICLE in article mode buffer.
2773 ARTICLE should either be an article number or a Message-ID.
2774 If ARTICLE is an id, HEADER should be the article headers.
2775 If ALL-HEADERS is non-nil, no headers are hidden."
2777 ;; Make sure we start in a summary buffer.
2778 (unless (eq major-mode 'gnus-summary-mode)
2779 (set-buffer gnus-summary-buffer))
2780 (setq gnus-summary-buffer (current-buffer))
2781 (let* ((gnus-article (if header (mail-header-number header) article))
2782 (summary-buffer (current-buffer))
2783 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2784 (group gnus-newsgroup-name)
2787 (gnus-article-setup-buffer)
2788 (set-buffer gnus-article-buffer)
2789 ;; Deactivate active regions.
2790 (when (and (boundp 'transient-mark-mode)
2791 transient-mark-mode)
2792 (setq mark-active nil))
2793 (if (not (setq result (let ((buffer-read-only nil))
2794 (gnus-request-article-this-buffer
2796 ;; There is no such article.
2798 (when (and (numberp article)
2799 (not (memq article gnus-newsgroup-sparse)))
2800 (setq gnus-article-current
2801 (cons gnus-newsgroup-name article))
2802 (set-buffer gnus-summary-buffer)
2803 (setq gnus-current-article article)
2804 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2806 (gnus-summary-set-agent-mark article)
2807 (message "Message marked for downloading"))
2808 (gnus-summary-mark-article article gnus-canceled-mark)
2809 (unless (memq article gnus-newsgroup-sparse)
2810 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2811 (if (or (eq result 'pseudo)
2812 (eq result 'nneething))
2815 (set-buffer summary-buffer)
2816 (push article gnus-newsgroup-history)
2817 (setq gnus-last-article gnus-current-article
2818 gnus-current-article 0
2819 gnus-current-headers nil
2820 gnus-article-current nil)
2821 (if (eq result 'nneething)
2822 (gnus-configure-windows 'summary)
2823 (gnus-configure-windows 'article))
2824 (gnus-set-global-variables))
2825 (let ((gnus-article-mime-handle-alist-1
2826 gnus-article-mime-handle-alist))
2827 (gnus-set-mode-line 'article)))
2828 ;; The result from the `request' was an actual article -
2829 ;; or at least some text that is now displayed in the
2831 (when (and (numberp article)
2832 (not (eq article gnus-current-article)))
2833 ;; Seems like a new article has been selected.
2834 ;; `gnus-current-article' must be an article number.
2836 (set-buffer summary-buffer)
2837 (push article gnus-newsgroup-history)
2838 (setq gnus-last-article gnus-current-article
2839 gnus-current-article article
2840 gnus-current-headers
2841 (gnus-summary-article-header gnus-current-article)
2842 gnus-article-current
2843 (cons gnus-newsgroup-name gnus-current-article))
2844 (unless (vectorp gnus-current-headers)
2845 (setq gnus-current-headers nil))
2846 (gnus-summary-goto-subject gnus-current-article)
2847 (when (gnus-summary-show-thread)
2848 ;; If the summary buffer really was folded, the
2849 ;; previous goto may not actually have gone to
2850 ;; the right article, but the thread root instead.
2852 (gnus-summary-goto-subject gnus-current-article))
2853 (gnus-run-hooks 'gnus-mark-article-hook)
2854 (gnus-set-mode-line 'summary)
2855 (when (gnus-visual-p 'article-highlight 'highlight)
2856 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2857 ;; Set the global newsgroup variables here.
2858 (gnus-set-global-variables)
2859 (setq gnus-have-all-headers
2860 (or all-headers gnus-show-all-headers))))
2862 (gnus-configure-windows 'article))
2863 (when (or (numberp article)
2865 (gnus-article-prepare-display)
2867 (goto-char (point-min))
2868 (setq gnus-page-broken
2869 (when gnus-break-pages
2870 (gnus-narrow-to-page)
2872 (let ((gnus-article-mime-handle-alist-1
2873 gnus-article-mime-handle-alist))
2874 (gnus-set-mode-line 'article))
2876 (set-window-point (get-buffer-window (current-buffer)) (point))
2877 (gnus-configure-windows 'article)
2881 (defun gnus-article-prepare-display ()
2882 "Make the current buffer look like a nice article."
2883 ;; Hooks for getting information from the article.
2884 ;; This hook must be called before being narrowed.
2885 (let ((gnus-article-buffer (current-buffer))
2887 (unless (eq major-mode 'gnus-article-mode)
2888 (gnus-article-mode))
2889 (setq buffer-read-only nil
2890 gnus-article-wash-types nil)
2891 (gnus-run-hooks 'gnus-tmp-internal-hook)
2892 (when gnus-display-mime-function
2893 (funcall gnus-display-mime-function))
2894 (gnus-run-hooks 'gnus-article-prepare-hook)))
2897 ;;; Gnus MIME viewing functions
2900 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2901 "The following specs can be used:
2903 %T MIME type, along with additional info
2904 %n The `name' parameter
2905 %d The description, if any
2906 %l The length of the encoded part
2907 %p The part identifier number
2908 %e Dots if the part isn't displayed")
2910 (defvar gnus-mime-button-line-format-alist
2911 '((?t gnus-tmp-type ?s)
2912 (?T gnus-tmp-type-long ?s)
2913 (?n gnus-tmp-name ?s)
2914 (?d gnus-tmp-description ?s)
2916 (?l gnus-tmp-length ?d)
2917 (?e gnus-tmp-dots ?s)))
2919 (defvar gnus-mime-button-commands
2920 '((gnus-article-press-button "\r" "Toggle Display")
2921 (gnus-mime-view-part "v" "View Interactively...")
2922 (gnus-mime-view-part-as-type "t" "View As Type...")
2923 (gnus-mime-save-part "o" "Save...")
2924 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2925 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2926 (gnus-mime-internalize-part "E" "View Internally")
2927 (gnus-mime-externalize-part "e" "View Externally")
2928 (gnus-mime-pipe-part "|" "Pipe To Command...")
2929 (gnus-mime-action-on-part "." "Take action on the part")))
2931 (defun gnus-article-mime-part-status ()
2932 (if gnus-article-mime-handle-alist-1
2933 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2936 (defvar gnus-mime-button-map
2937 (let ((map (make-sparse-keymap)))
2938 (set-keymap-parent map gnus-article-mode-map)
2939 (define-key map gnus-mouse-2 'gnus-article-push-button)
2940 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2941 (dolist (c gnus-mime-button-commands)
2942 (define-key map (cadr c) (car c)))
2945 (defun gnus-mime-button-menu (event)
2946 "Construct a context-sensitive menu of MIME commands."
2949 (let ((pos (event-start event)))
2950 (set-buffer (window-buffer (posn-window pos)))
2951 (goto-char (posn-point pos))
2952 (gnus-article-check-buffer)
2953 (let ((response (x-popup-menu
2955 ("" ,@(mapcar (lambda (c)
2956 (cons (caddr c) (car c)))
2957 gnus-mime-button-commands))))))
2959 (call-interactively response))))))
2961 (defun gnus-mime-view-all-parts (&optional handles)
2962 "View all the MIME parts."
2964 (save-current-buffer
2965 (set-buffer gnus-article-buffer)
2966 (let ((handles (or handles gnus-article-mime-handles))
2967 (mail-parse-charset gnus-newsgroup-charset)
2968 (mail-parse-ignored-charsets
2969 (save-excursion (set-buffer gnus-summary-buffer)
2970 gnus-newsgroup-ignored-charsets)))
2971 (if (stringp (car handles))
2972 (gnus-mime-view-all-parts (cdr handles))
2973 (mapcar 'mm-display-part handles)))))
2975 (defun gnus-mime-save-part ()
2976 "Save the MIME part under point."
2978 (gnus-article-check-buffer)
2979 (let ((data (get-text-property (point) 'gnus-data)))
2980 (mm-save-part data)))
2982 (defun gnus-mime-pipe-part ()
2983 "Pipe the MIME part under point to a process."
2985 (gnus-article-check-buffer)
2986 (let ((data (get-text-property (point) 'gnus-data)))
2987 (mm-pipe-part data)))
2989 (defun gnus-mime-view-part ()
2990 "Interactively choose a viewing method for the MIME part under point."
2992 (gnus-article-check-buffer)
2993 (let ((data (get-text-property (point) 'gnus-data)))
2994 (mm-interactively-view-part data)))
2996 (defun gnus-mime-view-part-as-type-internal ()
2997 (gnus-article-check-buffer)
2998 (let* ((name (mail-content-type-get
2999 (mm-handle-type (get-text-property (point) 'gnus-data))
3001 (def-type (and name (mm-default-file-encoding name))))
3002 (and def-type (cons def-type 0))))
3004 (defun gnus-mime-view-part-as-type (mime-type)
3005 "Choose a MIME media type, and view the part as such."
3007 (list (completing-read
3008 "View as MIME type: "
3009 (mapcar #'list (mailcap-mime-types))
3011 (gnus-mime-view-part-as-type-internal))))
3012 (gnus-article-check-buffer)
3013 (let ((handle (get-text-property (point) 'gnus-data)))
3014 (gnus-mm-display-part
3015 (mm-make-handle (mm-handle-buffer handle)
3016 (cons mime-type (cdr (mm-handle-type handle)))
3017 (mm-handle-encoding handle)
3018 (mm-handle-undisplayer handle)
3019 (mm-handle-disposition handle)
3020 (mm-handle-description handle)
3021 (mm-handle-cache handle)
3022 (mm-handle-id handle)))))
3024 (defun gnus-mime-copy-part (&optional handle)
3025 "Put the the MIME part under point into a new buffer."
3027 (gnus-article-check-buffer)
3028 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3029 (contents (mm-get-part handle))|
3030 (base (file-name-nondirectory
3032 (mail-content-type-get (mm-handle-type handle) 'name)
3033 (mail-content-type-get (mm-handle-type handle)
3036 (buffer (generate-new-buffer base)))
3037 (switch-to-buffer buffer)
3039 ;; We do it this way to make `normal-mode' set the appropriate mode.
3042 (setq buffer-file-name (expand-file-name base))
3044 (setq buffer-file-name nil))
3045 (goto-char (point-min))))
3047 (defun gnus-mime-inline-part (&optional handle arg)
3048 "Insert the MIME part under point into the current buffer."
3049 (interactive (list nil current-prefix-arg))
3050 (gnus-article-check-buffer)
3051 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3055 (if (mm-handle-undisplayer handle)
3056 (mm-remove-part handle)
3057 (setq contents (mm-get-part handle))
3060 (setq charset (or (mail-content-type-get
3061 (mm-handle-type handle) 'charset)
3062 gnus-newsgroup-charset)))
3066 gnus-summary-show-article-charset-alist))
3067 (read-coding-system "Charset: ")))))
3069 (mm-insert-inline handle
3071 (setq charset (mm-charset-to-coding-system
3073 (not (eq charset 'ascii)))
3074 (mm-decode-coding-string contents charset)
3078 (defun gnus-mime-externalize-part (&optional handle)
3079 "View the MIME part under point with an external viewer."
3081 (gnus-article-check-buffer)
3082 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3083 (mm-user-display-methods nil)
3084 (mm-inlined-types nil)
3085 (mail-parse-charset gnus-newsgroup-charset)
3086 (mail-parse-ignored-charsets
3087 (save-excursion (set-buffer gnus-summary-buffer)
3088 gnus-newsgroup-ignored-charsets)))
3089 (if (mm-handle-undisplayer handle)
3090 (mm-remove-part handle)
3091 (mm-display-part handle))))
3093 (defun gnus-mime-internalize-part (&optional handle)
3094 "View the MIME part under point with an internal viewer.
3095 In no internal viewer is available, use an external viewer."
3097 (gnus-article-check-buffer)
3098 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3099 (mm-inlined-types '(".*"))
3100 (mm-inline-large-images t)
3101 (mail-parse-charset gnus-newsgroup-charset)
3102 (mail-parse-ignored-charsets
3103 (save-excursion (set-buffer gnus-summary-buffer)
3104 gnus-newsgroup-ignored-charsets)))
3105 (if (mm-handle-undisplayer handle)
3106 (mm-remove-part handle)
3107 (mm-display-part handle))))
3109 (defun gnus-mime-action-on-part (&optional action)
3110 "Do something with the MIME attachment at \(point\)."
3112 (list (completing-read "Action: " gnus-mime-action-alist)))
3113 (gnus-article-check-buffer)
3114 (let ((action-pair (assoc action gnus-mime-action-alist)))
3116 (funcall (cdr action-pair)))))
3119 (defun gnus-article-part-wrapper (n function)
3120 (save-current-buffer
3121 (set-buffer gnus-article-buffer)
3122 (when (> n (length gnus-article-mime-handle-alist))
3123 (error "No such part"))
3124 (gnus-article-goto-part n)
3125 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3126 (funcall function handle))))
3128 (defun gnus-article-pipe-part (n)
3129 "Pipe MIME part N, which is the numerical prefix."
3131 (gnus-article-part-wrapper n 'mm-pipe-part))
3133 (defun gnus-article-save-part (n)
3134 "Save MIME part N, which is the numerical prefix."
3136 (gnus-article-part-wrapper n 'mm-save-part))
3138 (defun gnus-article-interactively-view-part (n)
3139 "View MIME part N interactively, which is the numerical prefix."
3141 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3143 (defun gnus-article-copy-part (n)
3144 "Copy MIME part N, which is the numerical prefix."
3146 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3148 (defun gnus-article-externalize-part (n)
3149 "View MIME part N externally, which is the numerical prefix."
3151 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3153 (defun gnus-article-inline-part (n)
3154 "Inline MIME part N, which is the numerical prefix."
3156 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3158 (defun gnus-article-mime-match-handle-first (condition)
3160 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3161 (while (setq ihandle (pop alist))
3163 ((functionp condition)
3164 (funcall condition (cdr ihandle)))
3165 ((eq condition 'undisplayed)
3166 (not (or (mm-handle-undisplayer (cdr ihandle))
3167 (equal (mm-handle-media-type (cdr ihandle))
3168 "multipart/alternative"))))
3169 ((eq condition 'undisplayed-alternative)
3170 (not (mm-handle-undisplayer (cdr ihandle))))
3172 (gnus-article-goto-part (car ihandle))
3173 (or (not n) (< (car ihandle) n)))
3174 (setq n (car ihandle))))
3178 (defun gnus-article-view-part (&optional n)
3179 "View MIME part N, which is the numerical prefix."
3181 (save-current-buffer
3182 (set-buffer gnus-article-buffer)
3183 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3184 gnus-article-mime-match-handle-function)))
3185 (when (> n (length gnus-article-mime-handle-alist))
3186 (error "No such part"))
3187 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3188 (when (gnus-article-goto-part n)
3189 (if (equal (car handle) "multipart/alternative")
3190 (gnus-article-press-button)
3191 (when (eq (gnus-mm-display-part handle) 'internal)
3192 (gnus-set-window-start)))))))
3194 (defsubst gnus-article-mime-total-parts ()
3195 (if (bufferp (car gnus-article-mime-handles))
3197 (1- (length gnus-article-mime-handles))))
3199 (defun gnus-mm-display-part (handle)
3200 "Display HANDLE and fix MIME button."
3201 (let ((id (get-text-property (point) 'gnus-part))
3206 (let ((window (selected-window))
3207 (mail-parse-charset gnus-newsgroup-charset)
3208 (mail-parse-ignored-charsets
3209 (save-excursion (set-buffer gnus-summary-buffer)
3210 gnus-newsgroup-ignored-charsets)))
3213 (let ((win (get-buffer-window (current-buffer) t))
3216 (select-window win))
3219 (if (mm-handle-displayed-p handle)
3220 ;; This will remove the part.
3221 (mm-display-part handle)
3223 (narrow-to-region (point) (1+ (point)))
3224 (mm-display-part handle)
3225 ;; We narrow to the part itself and
3226 ;; then call the treatment functions.
3227 (goto-char (point-min))
3229 (narrow-to-region (point) (point-max))
3232 (gnus-article-mime-total-parts)
3233 (mm-handle-media-type handle)))))
3234 (select-window window))))
3236 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3237 (gnus-insert-mime-button
3238 handle id (list (mm-handle-displayed-p handle)))
3239 (goto-char point))))
3241 (defun gnus-article-goto-part (n)
3242 "Go to MIME part N."
3243 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3245 (goto-char point))))
3247 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3248 (let ((gnus-tmp-name
3249 (or (mail-content-type-get (mm-handle-type handle)
3251 (mail-content-type-get (mm-handle-disposition handle)
3254 (gnus-tmp-type (mm-handle-media-type handle))
3255 (gnus-tmp-description
3256 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3259 (if (if displayed (car displayed)
3260 (mm-handle-displayed-p handle))
3262 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3264 gnus-tmp-type-long b e)
3265 (when (string-match ".*/" gnus-tmp-name)
3266 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3267 (setq gnus-tmp-type-long (concat gnus-tmp-type
3268 (and (not (equal gnus-tmp-name ""))
3269 (concat "; " gnus-tmp-name))))
3270 (or (equal gnus-tmp-description "")
3271 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3276 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3277 `(local-map ,gnus-mime-button-map
3278 keymap ,gnus-mime-button-map
3279 gnus-callback gnus-mm-display-part
3280 gnus-part ,gnus-tmp-id
3281 article-type annotation
3284 (widget-convert-button
3287 :action 'gnus-widget-press-button
3288 :button-keymap gnus-mime-button-map
3290 (lambda (widget/window &optional overlay pos)
3291 ;; Needed to properly clear the message due to a bug in
3292 ;; wid-edit (XEmacs only).
3293 (if (boundp 'help-echo-owns-message)
3294 (setq help-echo-owns-message t))
3296 "%S: %s the MIME part; %S: more options"
3297 (aref gnus-mouse-2 0)
3298 ;; XEmacs will get a single widget arg; Emacs 21 will get
3299 ;; window, overlay, position.
3300 (if (mm-handle-displayed-p
3302 (with-current-buffer (gnus-overlay-buffer overlay)
3303 (widget-get (widget-at (gnus-overlay-start overlay))
3305 (widget-get widget/window :mime-handle)))
3307 (aref gnus-down-mouse-3 0))))))
3309 (defun gnus-widget-press-button (elems el)
3310 (goto-char (widget-get elems :from))
3311 (gnus-article-press-button))
3313 (defvar gnus-displaying-mime nil)
3315 (defun gnus-display-mime (&optional ihandles)
3316 "Display the MIME parts."
3318 (save-selected-window
3319 (let ((window (get-buffer-window gnus-article-buffer))
3322 (select-window window)
3323 ;; We have to do this since selecting the window
3324 ;; may change the point. So we set the window point.
3325 (set-window-point window point)))
3326 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3327 buffer-read-only handle name type b e display)
3328 (when (and (not ihandles)
3329 (not gnus-displaying-mime))
3330 ;; Top-level call; we clean up.
3331 (when gnus-article-mime-handles
3332 (mm-destroy-parts gnus-article-mime-handles)
3333 (setq gnus-article-mime-handle-alist nil));; A trick.
3334 (setq gnus-article-mime-handles handles)
3335 ;; We allow users to glean info from the handles.
3336 (when gnus-article-mime-part-function
3337 (gnus-mime-part-function handles)))
3339 (or (not (stringp (car handles)))
3342 (when (and (not ihandles)
3343 (not gnus-displaying-mime))
3344 ;; Clean up for mime parts.
3346 (delete-region (point) (point-max)))
3347 (let ((gnus-displaying-mime t))
3348 (gnus-mime-display-part handles)))
3351 (narrow-to-region (point) (point-max))
3352 (gnus-treat-article nil 1 1)
3355 ;; Highlight the headers.
3359 (narrow-to-region (point-min) (point))
3360 (gnus-treat-article 'head))))))))
3362 (defvar gnus-mime-display-multipart-as-mixed nil)
3364 (defun gnus-mime-display-part (handle)
3367 ((not (stringp (car handle)))
3368 (gnus-mime-display-single handle))
3369 ;; User-defined multipart
3370 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3371 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3373 ;; multipart/alternative
3374 ((and (equal (car handle) "multipart/alternative")
3375 (not gnus-mime-display-multipart-as-mixed))
3376 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3377 (push (cons id handle) gnus-article-mime-handle-alist)
3378 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3379 ;; multipart/related
3380 ((and (equal (car handle) "multipart/related")
3381 (not gnus-mime-display-multipart-as-mixed))
3382 ;;;!!!We should find the start part, but we just default
3383 ;;;!!!to the first part.
3384 (gnus-mime-display-part (cadr handle)))
3385 ;; Other multiparts are handled like multipart/mixed.
3387 (gnus-mime-display-mixed (cdr handle)))))
3389 (defun gnus-mime-part-function (handles)
3390 (if (stringp (car handles))
3391 (mapcar 'gnus-mime-part-function (cdr handles))
3392 (funcall gnus-article-mime-part-function handles)))
3394 (defun gnus-mime-display-mixed (handles)
3395 (mapcar 'gnus-mime-display-part handles))
3397 (defun gnus-mime-display-single (handle)
3398 (let ((type (mm-handle-media-type handle))
3399 (ignored gnus-ignored-mime-types)
3406 (when (string-match (pop ignored) type)
3407 (throw 'ignored nil)))
3408 (if (and (setq not-attachment
3409 (and (not (mm-inline-override-p handle))
3410 (or (not (mm-handle-disposition handle))
3411 (equal (car (mm-handle-disposition handle))
3413 (mm-attachment-override-p handle))))
3414 (mm-automatic-display-p handle)
3415 (or (mm-inlined-p handle)
3416 (mm-automatic-external-display-p type)))
3418 (when (equal (mm-handle-media-supertype handle) "text")
3420 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3422 (push (cons id handle) gnus-article-mime-handle-alist)
3423 (when (or (not display)
3424 (not (gnus-unbuttonized-mime-type-p type)))
3425 ;(gnus-article-insert-newline)
3426 (gnus-insert-mime-button
3427 handle id (list (or display (and not-attachment text))))
3428 (gnus-article-insert-newline)
3429 ;(gnus-article-insert-newline)
3437 (let ((mail-parse-charset gnus-newsgroup-charset)
3438 (mail-parse-ignored-charsets
3439 (save-excursion (condition-case ()
3440 (set-buffer gnus-summary-buffer)
3442 gnus-newsgroup-ignored-charsets)))
3443 (mm-display-part handle t))
3444 (goto-char (point-max)))
3445 ((and text not-attachment)
3449 (gnus-article-insert-newline)
3450 (mm-insert-inline handle (mm-get-part handle))
3451 (goto-char (point-max))))
3455 (narrow-to-region beg (point))
3458 (gnus-article-mime-total-parts)
3459 (mm-handle-media-type handle)))))))))
3461 (defun gnus-unbuttonized-mime-type-p (type)
3462 "Say whether TYPE is to be unbuttonized."
3463 (unless gnus-inhibit-mime-unbuttonizing
3465 (let ((types gnus-unbuttonized-mime-types))
3467 (when (string-match (pop types) type)
3468 (throw 'found t)))))))
3470 (defun gnus-article-insert-newline ()
3471 "Insert a newline, but mark it as undeletable."
3472 (gnus-put-text-property
3473 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3475 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3476 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3479 handle buffer-read-only from props begend not-pref)
3480 (save-window-excursion
3483 (narrow-to-region (car ibegend)
3486 (goto-char (car ibegend))
3489 (delete-region (point-min) (point-max))
3490 (mm-remove-parts handles))
3491 (setq begend (list (point-marker)))
3493 (unless (setq not-pref (cadr (member preferred ihandles)))
3494 (setq not-pref (car ihandles)))
3496 (not (gnus-unbuttonized-mime-type-p
3497 "multipart/alternative")))
3498 (gnus-add-text-properties
3501 (insert (format "%d. " id))
3505 (unless ,(not ibegend)
3506 (setq gnus-article-mime-handle-alist
3507 ',gnus-article-mime-handle-alist))
3508 (gnus-mime-display-alternative
3509 ',ihandles ',not-pref ',begend ,id))
3510 local-map ,gnus-mime-button-map
3511 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3512 face ,gnus-article-button-face
3513 keymap ,gnus-mime-button-map
3516 (widget-convert-button 'link from (point)
3517 :action 'gnus-widget-press-button
3518 :button-keymap gnus-widget-button-keymap)
3520 (while (setq handle (pop handles))
3521 (gnus-add-text-properties
3524 (insert (format "(%c) %-18s"
3525 (if (equal handle preferred) ?* ? )
3526 (mm-handle-media-type handle)))
3530 (unless ,(not ibegend)
3531 (setq gnus-article-mime-handle-alist
3532 ',gnus-article-mime-handle-alist))
3533 (gnus-mime-display-alternative
3534 ',ihandles ',handle ',begend ,id))
3535 local-map ,gnus-mime-button-map
3536 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3537 face ,gnus-article-button-face
3538 keymap ,gnus-mime-button-map
3541 (widget-convert-button 'link from (point)
3542 :action 'gnus-widget-press-button
3543 :button-keymap gnus-widget-button-keymap)
3547 (if (stringp (car preferred))
3548 (gnus-display-mime preferred)
3549 (let ((mail-parse-charset gnus-newsgroup-charset)
3550 (mail-parse-ignored-charsets
3551 (save-excursion (set-buffer gnus-summary-buffer)
3552 gnus-newsgroup-ignored-charsets)))
3553 (mm-display-part preferred)
3557 (narrow-to-region (car begend) (point-max))
3559 nil (length gnus-article-mime-handle-alist)
3560 (gnus-article-mime-total-parts)
3561 (mm-handle-media-type handle))))))
3562 (goto-char (point-max))
3563 (setcdr begend (point-marker)))))
3565 (goto-char point))))
3567 (defun gnus-article-wash-status ()
3568 "Return a string which display status of article washing."
3570 (set-buffer gnus-article-buffer)
3571 (let ((cite (memq 'cite gnus-article-wash-types))
3572 (headers (memq 'headers gnus-article-wash-types))
3573 (boring (memq 'boring-headers gnus-article-wash-types))
3574 (pgp (memq 'pgp gnus-article-wash-types))
3575 (pem (memq 'pem gnus-article-wash-types))
3576 (signature (memq 'signature gnus-article-wash-types))
3577 (overstrike (memq 'overstrike gnus-article-wash-types))
3578 (emphasis (memq 'emphasis gnus-article-wash-types)))
3579 (format "%c%c%c%c%c%c"
3581 (if (or headers boring) ?h ? )
3582 (if (or pgp pem) ?p ? )
3583 (if signature ?s ? )
3584 (if overstrike ?o ? )
3585 (if emphasis ?e ? )))))
3587 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3589 (defun gnus-article-maybe-hide-headers ()
3590 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3591 Provided for backwards compatibility."
3592 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3593 (not (save-excursion (set-buffer gnus-summary-buffer)
3594 gnus-have-all-headers)))
3595 (not gnus-inhibit-hiding))
3596 (gnus-article-hide-headers)))
3600 (defun gnus-output-to-file (file-name)
3601 "Append the current article to a file named FILE-NAME."
3602 (let ((artbuf (current-buffer)))
3604 (insert-buffer-substring artbuf)
3605 ;; Append newline at end of the buffer as separator, and then
3607 (goto-char (point-max))
3609 (mm-append-to-file (point-min) (point-max) file-name)
3612 (defun gnus-narrow-to-page (&optional arg)
3613 "Narrow the article buffer to a page.
3614 If given a numerical ARG, move forward ARG pages."
3616 (setq arg (if arg (prefix-numeric-value arg) 0))
3618 (set-buffer gnus-article-buffer)
3619 (goto-char (point-min))
3621 ;; Remove any old next/prev buttons.
3622 (when (gnus-visual-p 'page-marker)
3623 (let ((buffer-read-only nil))
3624 (gnus-remove-text-with-property 'gnus-prev)
3625 (gnus-remove-text-with-property 'gnus-next)))
3628 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3630 (re-search-forward page-delimiter nil 'move arg)))
3631 (goto-char (match-end 0)))
3634 (if (re-search-forward page-delimiter nil 'move)
3637 (when (and (gnus-visual-p 'page-marker)
3638 (not (= (point-min) 1)))
3640 (goto-char (point-min))
3641 (gnus-insert-prev-page-button)))
3642 (when (and (gnus-visual-p 'page-marker)
3643 (< (+ (point-max) 2) (buffer-size)))
3645 (goto-char (point-max))
3646 (gnus-insert-next-page-button)))))
3648 ;; Article mode commands
3650 (defun gnus-article-goto-next-page ()
3651 "Show the next page of the article."
3653 (when (gnus-article-next-page)
3654 (goto-char (point-min))
3655 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3657 (defun gnus-article-goto-prev-page ()
3658 "Show the next page of the article."
3660 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3661 (gnus-article-prev-page nil)))
3663 (defun gnus-article-next-page (&optional lines)
3664 "Show the next page of the current article.
3665 If end of article, return non-nil. Otherwise return nil.
3666 Argument LINES specifies lines to be scrolled up."
3668 (move-to-window-line -1)
3671 (and (pos-visible-in-window-p) ;Not continuation line.
3673 ;; Nothing in this page.
3674 (if (or (not gnus-page-broken)
3677 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3679 (gnus-narrow-to-page 1) ;Go to next page.
3681 ;; More in this page.
3682 (let ((scroll-in-place nil))
3686 ;; Long lines may cause an end-of-buffer error.
3687 (goto-char (point-max)))))
3688 (move-to-window-line 0)
3691 (defun gnus-article-prev-page (&optional lines)
3692 "Show previous page of current article.
3693 Argument LINES specifies lines to be scrolled down."
3695 (move-to-window-line 0)
3696 (if (and gnus-page-broken
3698 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3700 (gnus-narrow-to-page -1) ;Go to previous page.
3701 (goto-char (point-max))
3703 (let ((scroll-in-place nil))
3707 (beginning-of-buffer
3708 (goto-char (point-min))))
3709 (move-to-window-line 0)))))
3711 (defun gnus-article-refer-article ()
3712 "Read article specified by message-id around point."
3714 (let ((point (point)))
3715 (search-forward ">" nil t) ;Move point to end of "<....>".
3716 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3717 (let ((message-id (match-string 1)))
3719 (set-buffer gnus-summary-buffer)
3720 (gnus-summary-refer-article message-id))
3722 (error "No references around point"))))
3724 (defun gnus-article-show-summary ()
3725 "Reconfigure windows to show summary buffer."
3727 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3728 (error "There is no summary buffer for this article buffer")
3729 (gnus-article-set-globals)
3730 (gnus-configure-windows 'article)
3731 (gnus-summary-goto-subject gnus-current-article)
3732 (gnus-summary-position-point)))
3734 (defun gnus-article-describe-briefly ()
3735 "Describe article mode commands briefly."
3737 (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")))
3739 (defun gnus-article-summary-command ()
3740 "Execute the last keystroke in the summary buffer."
3742 (let ((obuf (current-buffer))
3743 (owin (current-window-configuration))
3745 (switch-to-buffer gnus-article-current-summary 'norecord)
3746 (setq func (lookup-key (current-local-map) (this-command-keys)))
3747 (call-interactively func)
3749 (set-window-configuration owin)
3750 (set-window-point (get-buffer-window (current-buffer)) (point))))
3752 (defun gnus-article-summary-command-nosave ()
3753 "Execute the last keystroke in the summary buffer."
3756 (pop-to-buffer gnus-article-current-summary 'norecord)
3757 (setq func (lookup-key (current-local-map) (this-command-keys)))
3758 (call-interactively func)))
3760 (defun gnus-article-check-buffer ()
3761 "Beep if not in an article buffer."
3762 (unless (equal major-mode 'gnus-article-mode)
3763 (error "Command invoked outside of a Gnus article buffer")))
3765 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3766 "Read a summary buffer key sequence and execute it from the article buffer."
3768 (gnus-article-check-buffer)
3770 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3771 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3772 "=" "^" "\M-^" "|"))
3778 '("n" "Gn" "p" "Gp"))
3781 (set-buffer gnus-article-current-summary)
3782 (let (gnus-pick-mode)
3783 (push (or key last-command-event) unread-command-events)
3784 (setq keys (if (featurep 'xemacs)
3785 (events-to-keys (read-key-sequence nil))
3786 (read-key-sequence nil)))))
3790 (if (or (member keys nosaves)
3791 (member keys nosave-but-article)
3792 (member keys nosave-in-article))
3794 (save-window-excursion
3795 (pop-to-buffer gnus-article-current-summary 'norecord)
3796 ;; We disable the pick minor mode commands.
3797 (let (gnus-pick-mode)
3798 (setq func (lookup-key (current-local-map) keys))))
3802 (unless (member keys nosave-in-article)
3803 (set-buffer gnus-article-current-summary))
3804 (call-interactively func)
3805 (setq new-sum-point (point)))
3806 (when (member keys nosave-but-article)
3807 (pop-to-buffer gnus-article-buffer 'norecord)))
3808 ;; These commands should restore window configuration.
3809 (let ((obuf (current-buffer))
3810 (owin (current-window-configuration))
3812 (summary gnus-article-current-summary)
3813 func in-buffer selected)
3814 (if not-restore-window
3815 (pop-to-buffer summary 'norecord)
3816 (switch-to-buffer summary 'norecord))
3817 (setq in-buffer (current-buffer))
3818 ;; We disable the pick minor mode commands.
3819 (if (setq func (let (gnus-pick-mode)
3820 (lookup-key (current-local-map) keys)))
3822 (call-interactively func)
3823 (setq new-sum-point (point)))
3825 (when (eq in-buffer (current-buffer))
3826 (setq selected (gnus-summary-select-article))
3828 (unless not-restore-window
3829 (set-window-configuration owin))
3830 (when (eq selected 'old)
3832 (set-window-start (get-buffer-window (current-buffer))
3834 (set-window-point (get-buffer-window (current-buffer))
3836 (let ((win (get-buffer-window gnus-article-current-summary)))
3838 (set-window-point win new-sum-point))))))))
3840 (defun gnus-article-hide (&optional arg force)
3841 "Hide all the gruft in the current article.
3842 This means that PGP stuff, signatures, cited text and (some)
3843 headers will be hidden.
3844 If given a prefix, show the hidden text instead."
3845 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3846 (gnus-article-hide-headers arg)
3847 (gnus-article-hide-list-identifiers arg)
3848 (gnus-article-hide-pgp arg)
3849 (gnus-article-hide-citation-maybe arg force)
3850 (gnus-article-hide-signature arg))
3852 (defun gnus-article-maybe-highlight ()
3853 "Do some article highlighting if article highlighting is requested."
3854 (when (gnus-visual-p 'article-highlight 'highlight)
3855 (gnus-article-highlight-some)))
3857 (defun gnus-check-group-server ()
3858 ;; Make sure the connection to the server is alive.
3859 (unless (gnus-server-opened
3860 (gnus-find-method-for-group gnus-newsgroup-name))
3861 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3862 (gnus-request-group gnus-newsgroup-name t)))
3864 (defun gnus-request-article-this-buffer (article group)
3865 "Get an article and insert it into this buffer."
3866 (let (do-update-line sparse-header)
3870 (gnus-kill-all-overlays)
3871 (setq group (or group gnus-newsgroup-name))
3873 ;; Using `gnus-request-article' directly will insert the article into
3874 ;; `nntp-server-buffer' - so we'll save some time by not having to
3875 ;; copy it from the server buffer into the article buffer.
3877 ;; We only request an article by message-id when we do not have the
3878 ;; headers for it, so we'll have to get those.
3879 (when (stringp article)
3880 (gnus-read-header article))
3882 ;; If the article number is negative, that means that this article
3883 ;; doesn't belong in this newsgroup (possibly), so we find its
3884 ;; message-id and request it by id instead of number.
3885 (when (and (numberp article)
3887 (get-buffer gnus-summary-buffer)
3888 (gnus-buffer-exists-p gnus-summary-buffer))
3890 (set-buffer gnus-summary-buffer)
3891 (let ((header (gnus-summary-article-header article)))
3894 ((memq article gnus-newsgroup-sparse)
3895 ;; This is a sparse gap article.
3896 (setq do-update-line article)
3897 (setq article (mail-header-id header))
3898 (setq sparse-header (gnus-read-header article))
3899 (setq gnus-newsgroup-sparse
3900 (delq article gnus-newsgroup-sparse)))
3902 ;; It's a real article.
3903 (setq article (mail-header-id header)))
3905 ;; It is an extracted pseudo-article.
3906 (setq article 'pseudo)
3907 (gnus-request-pseudo-article header))))
3909 (let ((method (gnus-find-method-for-group
3910 gnus-newsgroup-name)))
3911 (when (and (eq (car method) 'nneething)
3913 (let ((dir (expand-file-name
3914 (mail-header-subject header)
3915 (file-name-as-directory
3916 (or (cadr (assq 'nneething-address method))
3918 (when (file-directory-p dir)
3919 (setq article 'nneething)
3920 (gnus-group-enter-directory dir))))))))
3923 ;; Refuse to select canceled articles.
3924 ((and (numberp article)
3926 (get-buffer gnus-summary-buffer)
3927 (gnus-buffer-exists-p gnus-summary-buffer)
3928 (eq (cdr (save-excursion
3929 (set-buffer gnus-summary-buffer)
3930 (assq article gnus-newsgroup-reads)))
3931 gnus-canceled-mark))
3933 ;; We first check `gnus-original-article-buffer'.
3934 ((and (get-buffer gnus-original-article-buffer)
3937 (set-buffer gnus-original-article-buffer)
3938 (and (equal (car gnus-original-article) group)
3939 (eq (cdr gnus-original-article) article))))
3940 (insert-buffer-substring gnus-original-article-buffer)
3942 ;; Check the backlog.
3943 ((and gnus-keep-backlog
3944 (gnus-backlog-request-article group article (current-buffer)))
3946 ;; Check asynchronous pre-fetch.
3947 ((gnus-async-request-fetched-article group article (current-buffer))
3948 (gnus-async-prefetch-next group article gnus-summary-buffer)
3949 (when (and (numberp article) gnus-keep-backlog)
3950 (gnus-backlog-enter-article group article (current-buffer)))
3953 ((and gnus-use-cache
3955 (gnus-cache-request-article article group))
3957 ;; Get the article and put into the article buffer.
3958 ((or (stringp article)
3960 (let ((gnus-override-method gnus-override-method)
3961 (methods (and (stringp article)
3962 gnus-refer-article-method))
3964 (buffer-read-only nil))
3965 (if (or (not (listp methods))
3966 (and (symbolp (car methods))
3967 (assq (car methods) nnoo-definition-alist)))
3968 (setq methods (list methods)))
3969 (when (and (null gnus-override-method)
3971 (setq gnus-override-method (pop methods)))
3973 (when (eq gnus-override-method 'current)
3974 (setq gnus-override-method gnus-current-select-method))
3976 (gnus-kill-all-overlays)
3977 (let ((gnus-newsgroup-name group))
3978 (gnus-check-group-server))
3979 (when (gnus-request-article article group (current-buffer))
3980 (when (numberp article)
3981 (gnus-async-prefetch-next group article
3982 gnus-summary-buffer)
3983 (when gnus-keep-backlog
3984 (gnus-backlog-enter-article
3985 group article (current-buffer))))
3986 (setq result 'article))
3989 (setq gnus-override-method (pop methods))
3990 (setq result 'done))))
3991 (and (eq result 'article) 'article)))
3995 ;; Associate this article with the current summary buffer.
3996 (setq gnus-article-current-summary gnus-summary-buffer)
3998 ;; Take the article from the original article buffer
3999 ;; and place it in the buffer it's supposed to be in.
4000 (when (and (get-buffer gnus-article-buffer)
4001 (equal (buffer-name (current-buffer))
4002 (buffer-name (get-buffer gnus-article-buffer))))
4004 (if (get-buffer gnus-original-article-buffer)
4005 (set-buffer gnus-original-article-buffer)
4006 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4007 (buffer-disable-undo)
4008 (setq major-mode 'gnus-original-article-mode)
4009 (setq buffer-read-only t))
4010 (let (buffer-read-only)
4012 (insert-buffer-substring gnus-article-buffer))
4013 (setq gnus-original-article (cons group article)))
4016 (run-hooks 'gnus-article-decode-hook)
4017 ;; Mark article as decoded or not.
4018 (setq gnus-article-decoded-p gnus-article-decode-hook))
4020 ;; Update sparse articles.
4021 (when (and do-update-line
4022 (or (numberp article)
4024 (let ((buf (current-buffer)))
4025 (set-buffer gnus-summary-buffer)
4026 (gnus-summary-update-article do-update-line sparse-header)
4027 (gnus-summary-goto-subject do-update-line nil t)
4028 (set-window-point (get-buffer-window (current-buffer) t)
4030 (set-buffer buf))))))
4036 (defcustom gnus-article-edit-mode-hook nil
4037 "Hook run in article edit mode buffers."
4038 :group 'gnus-article-various
4041 (defvar gnus-article-edit-done-function nil)
4043 (defvar gnus-article-edit-mode-map nil)
4045 ;; Should we be using derived.el for this?
4046 (unless gnus-article-edit-mode-map
4047 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4048 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4050 (gnus-define-keys gnus-article-edit-mode-map
4051 "\C-c\C-c" gnus-article-edit-done
4052 "\C-c\C-k" gnus-article-edit-exit)
4054 (gnus-define-keys (gnus-article-edit-wash-map
4055 "\C-c\C-w" gnus-article-edit-mode-map)
4056 "f" gnus-article-edit-full-stops))
4058 (defun gnus-article-edit-mode ()
4059 "Major mode for editing articles.
4060 This is an extended text-mode.
4062 \\{gnus-article-edit-mode-map}"
4064 (setq major-mode 'gnus-article-edit-mode)
4065 (setq mode-name "Article Edit")
4066 (use-local-map gnus-article-edit-mode-map)
4067 (make-local-variable 'gnus-article-edit-done-function)
4068 (make-local-variable 'gnus-prev-winconf)
4069 (setq buffer-read-only nil)
4070 (buffer-enable-undo)
4072 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4074 (defun gnus-article-edit (&optional force)
4075 "Edit the current article.
4076 This will have permanent effect only in mail groups.
4077 If FORCE is non-nil, allow editing of articles even in read-only
4080 (when (and (not force)
4081 (gnus-group-read-only-p))
4082 (error "The current newsgroup does not support article editing"))
4083 (gnus-article-date-original)
4084 (gnus-article-edit-article
4086 `(lambda (no-highlight)
4088 (gnus-summary-edit-article-done
4089 ,(or (mail-header-references gnus-current-headers) "")
4090 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4092 (defun gnus-article-edit-article (start-func exit-func)
4093 "Start editing the contents of the current article buffer."
4094 (let ((winconf (current-window-configuration)))
4095 (set-buffer gnus-article-buffer)
4096 (gnus-article-edit-mode)
4097 (funcall start-func)
4098 (gnus-configure-windows 'edit-article)
4099 (setq gnus-article-edit-done-function exit-func)
4100 (setq gnus-prev-winconf winconf)
4101 (gnus-message 6 "C-c C-c to end edits")))
4103 (defun gnus-article-edit-done (&optional arg)
4104 "Update the article edits and exit."
4109 (when (article-goto-body)
4110 (let ((lines (count-lines (point) (point-max)))
4111 (length (- (point-max) (point)))
4112 (case-fold-search t)
4113 (body (copy-marker (point))))
4114 (goto-char (point-min))
4115 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4116 (delete-region (match-beginning 1) (match-end 1))
4117 (insert (number-to-string length)))
4118 (goto-char (point-min))
4119 (when (re-search-forward
4120 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4121 (delete-region (match-beginning 1) (match-end 1))
4122 (insert (number-to-string length)))
4123 (goto-char (point-min))
4124 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4125 (delete-region (match-beginning 1) (match-end 1))
4126 (insert (number-to-string lines)))))))
4127 (let ((func gnus-article-edit-done-function)
4128 (buf (current-buffer))
4129 (start (window-start)))
4130 (gnus-article-edit-exit)
4133 (let ((buffer-read-only nil))
4135 ;; The cache and backlog have to be flushed somewhat.
4136 (when gnus-keep-backlog
4137 (gnus-backlog-remove-article
4138 (car gnus-article-current) (cdr gnus-article-current)))
4139 ;; Flush original article as well.
4141 (when (get-buffer gnus-original-article-buffer)
4142 (set-buffer gnus-original-article-buffer)
4143 (setq gnus-original-article nil)))
4144 (when gnus-use-cache
4145 (gnus-cache-update-article
4146 (car gnus-article-current) (cdr gnus-article-current))))
4148 (set-window-start (get-buffer-window buf) start)
4149 (set-window-point (get-buffer-window buf) (point))))
4151 (defun gnus-article-edit-exit ()
4152 "Exit the article editing without updating."
4154 ;; We remove all text props from the article buffer.
4155 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4156 (curbuf (current-buffer))
4158 (window-start (window-start)))
4161 (let ((winconf gnus-prev-winconf))
4163 (set-window-configuration winconf)
4164 ;; Tippy-toe some to make sure that point remains where it was.
4165 (save-current-buffer
4167 (set-window-start (get-buffer-window (current-buffer)) window-start)
4170 (defun gnus-article-edit-full-stops ()
4171 "Interactively repair spacing at end of sentences."
4174 (goto-char (point-min))
4175 (search-forward-regexp "^$" nil t)
4176 (let ((case-fold-search nil))
4177 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4180 ;;; Article highlights
4183 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4185 ;;; Internal Variables:
4187 (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\\)\\)"
4188 "Regular expression that matches URLs."
4189 :group 'gnus-article-buttons
4192 (defcustom gnus-button-alist
4193 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4194 0 t gnus-button-message-id 2)
4195 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4196 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4198 gnus-button-fetch-group 4)
4199 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4200 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4201 t gnus-button-message-id 3)
4202 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4203 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4204 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4205 ;; This is how URLs _should_ be embedded in text...
4206 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4208 (,gnus-button-url-regexp 0 t browse-url 0))
4209 "*Alist of regexps matching buttons in article bodies.
4211 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4212 REGEXP: is the string matching text around the button,
4213 BUTTON: is the number of the regexp grouping actually matching the button,
4214 FORM: is a lisp expression which must eval to true for the button to
4216 CALLBACK: is the function to call when the user push this button, and each
4217 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4219 CALLBACK can also be a variable, in that case the value of that
4220 variable it the real callback function."
4221 :group 'gnus-article-buttons
4222 :type '(repeat (list regexp
4223 (integer :tag "Button")
4225 (function :tag "Callback")
4228 (integer :tag "Regexp group")))))
4230 (defcustom gnus-header-button-alist
4231 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4232 0 t gnus-button-message-id 0)
4233 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4234 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4235 0 t gnus-button-mailto 0)
4236 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4237 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4238 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4239 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4240 gnus-button-message-id 3))
4241 "*Alist of headers and regexps to match buttons in article heads.
4243 This alist is very similar to `gnus-button-alist', except that each
4244 alist has an additional HEADER element first in each entry:
4246 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4248 HEADER is a regexp to match a header. For a fuller explanation, see
4249 `gnus-button-alist'."
4250 :group 'gnus-article-buttons
4251 :group 'gnus-article-headers
4252 :type '(repeat (list (regexp :tag "Header")
4254 (integer :tag "Button")
4256 (function :tag "Callback")
4259 (integer :tag "Regexp group")))))
4261 (defvar gnus-button-regexp nil)
4262 (defvar gnus-button-marker-list nil)
4263 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4265 (defvar gnus-button-last nil)
4266 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4270 (defun gnus-article-push-button (event)
4271 "Check text under the mouse pointer for a callback function.
4272 If the text under the mouse pointer has a `gnus-callback' property,
4273 call it with the value of the `gnus-data' text property."
4275 (set-buffer (window-buffer (posn-window (event-start event))))
4276 (let* ((pos (posn-point (event-start event)))
4277 (data (get-text-property pos 'gnus-data))
4278 (fun (get-text-property pos 'gnus-callback)))
4281 (funcall fun data))))
4283 (defun gnus-article-press-button ()
4284 "Check text at point for a callback function.
4285 If the text at point has a `gnus-callback' property,
4286 call it with the value of the `gnus-data' text property."
4288 (let* ((data (get-text-property (point) 'gnus-data))
4289 (fun (get-text-property (point) 'gnus-callback)))
4291 (funcall fun data))))
4293 (defun gnus-article-highlight (&optional force)
4294 "Highlight current article.
4295 This function calls `gnus-article-highlight-headers',
4296 `gnus-article-highlight-citation',
4297 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4298 do the highlighting. See the documentation for those functions."
4299 (interactive (list 'force))
4300 (gnus-article-highlight-headers)
4301 (gnus-article-highlight-citation force)
4302 (gnus-article-highlight-signature)
4303 (gnus-article-add-buttons force)
4304 (gnus-article-add-buttons-to-head))
4306 (defun gnus-article-highlight-some (&optional force)
4307 "Highlight current article.
4308 This function calls `gnus-article-highlight-headers',
4309 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4310 do the highlighting. See the documentation for those functions."
4311 (interactive (list 'force))
4312 (gnus-article-highlight-headers)
4313 (gnus-article-highlight-signature)
4314 (gnus-article-add-buttons))
4316 (defun gnus-article-highlight-headers ()
4317 "Highlight article headers as specified by `gnus-header-face-alist'."
4320 (set-buffer gnus-article-buffer)
4322 (let ((alist gnus-header-face-alist)
4323 (buffer-read-only nil)
4324 (case-fold-search t)
4325 (inhibit-point-motion-hooks t)
4326 entry regexp header-face field-face from hpoints fpoints)
4327 (article-narrow-to-head)
4328 (while (setq entry (pop alist))
4329 (goto-char (point-min))
4330 (setq regexp (concat "^\\("
4331 (if (string-equal "" (nth 0 entry))
4335 header-face (nth 1 entry)
4336 field-face (nth 2 entry))
4337 (while (and (re-search-forward regexp nil t)
4341 (unless (search-forward ":" nil t)
4343 (when (and header-face
4344 (not (memq (point) hpoints)))
4345 (push (point) hpoints)
4346 (gnus-put-text-property from (point) 'face header-face))
4347 (when (and field-face
4348 (not (memq (setq from (point)) fpoints)))
4350 (if (re-search-forward "^[^ \t]" nil t)
4352 (goto-char (point-max)))
4353 (gnus-put-text-property from (point) 'face field-face))))))))
4355 (defun gnus-article-highlight-signature ()
4356 "Highlight the signature in an article.
4357 It does this by highlighting everything after
4358 `gnus-signature-separator' using `gnus-signature-face'."
4361 (set-buffer gnus-article-buffer)
4362 (let ((buffer-read-only nil)
4363 (inhibit-point-motion-hooks t))
4365 (when (and gnus-signature-face
4366 (gnus-article-narrow-to-signature))
4367 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4368 'face gnus-signature-face)
4370 (gnus-article-search-signature)
4371 (let ((start (match-beginning 0))
4372 (end (set-marker (make-marker) (1+ (match-end 0)))))
4373 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4376 (defun gnus-button-in-region-p (b e prop)
4377 "Say whether PROP exists in the region."
4378 (text-property-not-all b e prop nil))
4380 (defun gnus-article-add-buttons (&optional force)
4381 "Find external references in the article and make buttons of them.
4382 \"External references\" are things like Message-IDs and URLs, as
4383 specified by `gnus-button-alist'."
4384 (interactive (list 'force))
4386 (set-buffer gnus-article-buffer)
4387 (let ((buffer-read-only nil)
4388 (inhibit-point-motion-hooks t)
4389 (case-fold-search t)
4390 (alist gnus-button-alist)
4392 ;; Remove all old markers.
4393 (let (marker entry new-list)
4394 (while (setq marker (pop gnus-button-marker-list))
4395 (if (or (< marker (point-min)) (>= marker (point-max)))
4396 (push marker new-list)
4398 (when (setq entry (gnus-button-entry))
4399 (put-text-property (match-beginning (nth 1 entry))
4400 (match-end (nth 1 entry))
4401 'gnus-callback nil))
4402 (set-marker marker nil)))
4403 (setq gnus-button-marker-list new-list))
4404 ;; We skip the headers.
4407 (while (setq entry (pop alist))
4408 (setq regexp (car entry))
4410 (while (re-search-forward regexp nil t)
4411 (let* ((start (and entry (match-beginning (nth 1 entry))))
4412 (end (and entry (match-end (nth 1 entry))))
4413 (from (match-beginning 0)))
4414 (when (and (or (eq t (nth 2 entry))
4415 (eval (nth 2 entry)))
4416 (not (gnus-button-in-region-p
4417 start end 'gnus-callback)))
4418 ;; That optional form returned non-nil, so we add the
4420 (gnus-article-add-button
4421 start end 'gnus-button-push
4422 (car (push (set-marker (make-marker) from)
4423 gnus-button-marker-list))))))))))
4425 ;; Add buttons to the head of an article.
4426 (defun gnus-article-add-buttons-to-head ()
4427 "Add buttons to the head of the article."
4430 (set-buffer gnus-article-buffer)
4432 (let ((buffer-read-only nil)
4433 (inhibit-point-motion-hooks t)
4434 (case-fold-search t)
4435 (alist gnus-header-button-alist)
4437 (article-narrow-to-head)
4439 ;; Each alist entry.
4440 (setq entry (car alist)
4442 (goto-char (point-min))
4443 (while (re-search-forward (car entry) nil t)
4444 ;; Each header matching the entry.
4445 (setq beg (match-beginning 0))
4446 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4447 (match-beginning 0))
4450 (while (re-search-forward (nth 1 entry) end t)
4451 ;; Each match within a header.
4452 (let* ((entry (cdr entry))
4453 (start (match-beginning (nth 1 entry)))
4454 (end (match-end (nth 1 entry)))
4455 (form (nth 2 entry)))
4456 (goto-char (match-end 0))
4458 (gnus-article-add-button
4459 start end (nth 3 entry)
4460 (buffer-substring (match-beginning (nth 4 entry))
4461 (match-end (nth 4 entry)))))))
4462 (goto-char end)))))))
4464 ;;; External functions:
4466 (defun gnus-article-add-button (from to fun &optional data)
4467 "Create a button between FROM and TO with callback FUN and data DATA."
4468 (when gnus-article-button-face
4469 (gnus-overlay-put (gnus-make-overlay from to)
4470 'face gnus-article-button-face))
4471 (gnus-add-text-properties
4473 (nconc (and gnus-article-mouse-face
4474 (list gnus-mouse-face-prop gnus-article-mouse-face))
4475 (list 'gnus-callback fun)
4476 (and data (list 'gnus-data data))))
4477 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4478 :button-keymap gnus-widget-button-keymap))
4480 ;;; Internal functions:
4482 (defun gnus-article-set-globals ()
4484 (set-buffer gnus-summary-buffer)
4485 (gnus-set-global-variables)))
4487 (defun gnus-signature-toggle (end)
4489 (set-buffer gnus-article-buffer)
4490 (let ((buffer-read-only nil)
4491 (inhibit-point-motion-hooks t))
4492 (if (get-text-property end 'invisible)
4493 (gnus-article-unhide-text end (point-max))
4494 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4496 (defun gnus-button-entry ()
4497 ;; Return the first entry in `gnus-button-alist' matching this place.
4498 (let ((alist gnus-button-alist)
4501 (setq entry (pop alist))
4502 (if (looking-at (car entry))
4507 (defun gnus-button-push (marker)
4508 ;; Push button starting at MARKER.
4511 (let* ((entry (gnus-button-entry))
4512 (inhibit-point-motion-hooks t)
4514 (args (mapcar (lambda (group)
4515 (let ((string (match-string group)))
4516 (gnus-set-text-properties
4517 0 (length string) nil string)
4524 (fboundp (symbol-value fun)))
4525 (apply (symbol-value fun) args))
4527 (gnus-message 1 "You must define `%S' to use this button"
4528 (cons fun args)))))))
4530 (defun gnus-button-message-id (message-id)
4533 (set-buffer gnus-summary-buffer)
4534 (gnus-summary-refer-article message-id)))
4536 (defun gnus-button-fetch-group (address)
4537 "Fetch GROUP specified by ADDRESS."
4538 (if (not (string-match "[:/]" address))
4539 ;; This is just a simple group url.
4540 (gnus-group-read-ephemeral-group address gnus-select-method)
4541 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4543 (error "Can't parse %s" address)
4544 (gnus-group-read-ephemeral-group
4545 (match-string 4 address)
4546 `(nntp ,(match-string 1 address)
4547 (nntp-address ,(match-string 1 address))
4548 (nntp-port-number ,(if (match-end 3)
4549 (match-string 3 address)
4552 (defun gnus-url-parse-query-string (query &optional downcase)
4553 (let (retval pairs cur key val)
4554 (setq pairs (split-string query "&"))
4556 (setq cur (car pairs)
4558 (if (not (string-match "=" cur))
4560 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4561 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4563 (setq key (downcase key)))
4564 (setq cur (assoc key retval))
4566 (setcdr cur (cons val (cdr cur)))
4567 (setq retval (cons (list key val) retval)))))
4570 (defun gnus-url-unhex (x)
4577 (defun gnus-url-unhex-string (str &optional allow-newlines)
4578 "Remove %XXX embedded spaces, etc in a url.
4579 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4580 decoding of carriage returns and line feeds in the string, which is normally
4581 forbidden in URL encoding."
4582 (setq str (or str ""))
4584 (case-fold-search t))
4585 (while (string-match "%[0-9a-f][0-9a-f]" str)
4586 (let* ((start (match-beginning 0))
4587 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4589 (gnus-url-unhex (elt str (+ start 2))))))
4591 tmp (substring str 0 start)
4594 (char-to-string code))
4595 ((or (= code ?\n) (= code ?\r))
4597 (t (char-to-string code))))
4598 str (substring str (match-end 0)))))
4599 (setq tmp (concat tmp str))
4602 (defun gnus-url-mailto (url)
4603 ;; Send mail to someone
4604 (when (string-match "mailto:/*\\(.*\\)" url)
4605 (setq url (substring url (match-beginning 1) nil)))
4606 (let (to args subject func)
4607 (if (string-match (regexp-quote "?") url)
4608 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4609 args (gnus-url-parse-query-string
4610 (substring url (match-end 0) nil) t))
4611 (setq to (gnus-url-unhex-string url)))
4612 (setq args (cons (list "to" to) args)
4613 subject (cdr-safe (assoc "subject" args)))
4616 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4619 (message-position-on-field (caar args)))
4620 (insert (mapconcat 'identity (cdar args) ", "))
4621 (setq args (cdr args)))
4624 (message-goto-subject))))
4626 (defun gnus-button-mailto (address)
4628 (set-buffer (gnus-copy-article-buffer))
4629 (message-reply address))
4631 (defalias 'gnus-button-reply 'message-reply)
4633 (defun gnus-button-embedded-url (address)
4634 "Activate ADDRESS with `browse-url'."
4635 (browse-url (gnus-strip-whitespace address)))
4637 ;;; Next/prev buttons in the article buffer.
4639 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4640 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4642 (defvar gnus-prev-page-map nil)
4643 (unless gnus-prev-page-map
4644 (setq gnus-prev-page-map (make-sparse-keymap))
4645 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4646 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4648 (defun gnus-insert-prev-page-button ()
4649 (let ((buffer-read-only nil))
4651 gnus-prev-page-line-format nil
4652 `(gnus-prev t local-map ,gnus-prev-page-map
4653 gnus-callback gnus-article-button-prev-page
4654 article-type annotation))))
4656 (defvar gnus-next-page-map nil)
4657 (unless gnus-next-page-map
4658 (setq gnus-next-page-map (make-keymap))
4659 (suppress-keymap gnus-prev-page-map)
4660 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4661 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4663 (defun gnus-button-next-page ()
4664 "Go to the next page."
4666 (let ((win (selected-window)))
4667 (select-window (get-buffer-window gnus-article-buffer t))
4668 (gnus-article-next-page)
4669 (select-window win)))
4671 (defun gnus-button-prev-page ()
4672 "Go to the prev page."
4674 (let ((win (selected-window)))
4675 (select-window (get-buffer-window gnus-article-buffer t))
4676 (gnus-article-prev-page)
4677 (select-window win)))
4679 (defun gnus-insert-next-page-button ()
4680 (let ((buffer-read-only nil))
4681 (gnus-eval-format gnus-next-page-line-format nil
4683 t local-map ,gnus-next-page-map
4684 gnus-callback gnus-article-button-next-page
4685 article-type annotation))))
4687 (defun gnus-article-button-next-page (arg)
4688 "Go to the next page."
4690 (let ((win (selected-window)))
4691 (select-window (get-buffer-window gnus-article-buffer t))
4692 (gnus-article-next-page)
4693 (select-window win)))
4695 (defun gnus-article-button-prev-page (arg)
4696 "Go to the prev page."
4698 (let ((win (selected-window)))
4699 (select-window (get-buffer-window gnus-article-buffer t))
4700 (gnus-article-prev-page)
4701 (select-window win)))
4703 (defvar gnus-decode-header-methods
4704 '(mail-decode-encoded-word-region)
4705 "List of methods used to decode headers.
4707 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4708 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4709 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4710 whose names match REGEXP.
4713 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4714 mail-decode-encoded-word-region
4715 (\"chinese\" . rfc1843-decode-region))
4718 (defvar gnus-decode-header-methods-cache nil)
4720 (defun gnus-multi-decode-header (start end)
4721 "Apply the functions from `gnus-encoded-word-methods' that match."
4722 (unless (and gnus-decode-header-methods-cache
4723 (eq gnus-newsgroup-name
4724 (car gnus-decode-header-methods-cache)))
4725 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4728 (nconc gnus-decode-header-methods-cache (list x))
4729 (if (and gnus-newsgroup-name
4730 (string-match (car x) gnus-newsgroup-name))
4731 (nconc gnus-decode-header-methods-cache
4733 gnus-decode-header-methods))
4734 (let ((xlist gnus-decode-header-methods-cache))
4737 (narrow-to-region start end)
4739 (funcall (pop xlist) (point-min) (point-max))))))
4742 ;;; Treatment top-level handling.
4745 (defun gnus-treat-article (condition &optional part-number total-parts type)
4746 (let ((length (- (point-max) (point-min)))
4747 (alist gnus-treatment-function-alist)
4748 (article-goto-body-goes-to-point-min-p t)
4752 (let ((list gnus-article-treat-types))
4754 (when (string-match (pop list) type)
4755 (throw 'found t)))))))
4756 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4758 (gnus-run-hooks 'gnus-part-display-hook)
4759 (while (setq elem (pop alist))
4762 (if (gnus-buffer-live-p gnus-summary-buffer)
4763 (set-buffer gnus-summary-buffer))
4764 (symbol-value (car elem))))
4765 (when (and (or (consp val)
4767 (gnus-treat-predicate val)
4768 (or (not (get (car elem) 'highlight))
4771 (funcall (cadr elem)))))))
4773 ;; Dynamic variables.
4775 (defvar part-number)
4776 (defvar total-parts)
4781 (defun gnus-treat-predicate (val)
4786 (stringp (car val)))
4787 (apply 'gnus-or (mapcar `(lambda (s)
4788 (string-match s ,(or gnus-newsgroup-name "")))
4791 (let ((pred (pop val)))
4794 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4796 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4798 (not (gnus-treat-predicate (car val))))
4800 (equal (car val) type))
4802 (error "%S is not a valid predicate" pred)))))
4810 (eq part-number total-parts))
4814 (error "%S is not a valid value" val))))
4820 (run-hooks 'gnus-art-load-hook)
4822 ;;; gnus-art.el ends here