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 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -")
209 "*String or function to be executed to display an X-Face header.
210 If it is a string, the command will be executed in a sub-shell
211 asynchronously. The compressed face will be piped to this command."
212 :type '(choice string
213 (function-item gnus-article-display-xface)
215 :group 'gnus-article-washing)
217 (defcustom gnus-article-x-face-too-ugly nil
218 "Regexp matching posters whose face shouldn't be shown automatically."
219 :type '(choice regexp (const nil))
220 :group 'gnus-article-washing)
222 (defcustom gnus-article-banner-alist nil
223 "Banner alist for stripping.
225 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
226 :type '(repeat (cons symbol regexp))
227 :group 'gnus-article-washing)
229 (defcustom gnus-emphasis-alist
231 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
233 '(("_" "_" underline)
236 ("_/" "/_" underline-italic)
237 ("_\\*" "\\*_" underline-bold)
238 ("\\*/" "/\\*" bold-italic)
239 ("_\\*/" "/\\*_" underline-bold-italic))))
240 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
241 2 3 gnus-emphasis-underline)
245 (format format (car spec) (cadr spec))
246 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
248 "*Alist that says how to fontify certain phrases.
249 Each item looks like this:
251 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
253 The first element is a regular expression to be matched. The second
254 is a number that says what regular expression grouping used to find
255 the entire emphasized word. The third is a number that says what
256 regexp grouping should be displayed and highlighted. The fourth
257 is the face used for highlighting."
258 :type '(repeat (list :value ("" 0 0 default)
260 (integer :tag "Match group")
261 (integer :tag "Emphasize group")
263 :group 'gnus-article-emphasis)
265 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
266 "A regexp to describe whitespace which should not be emphasized.
267 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
268 The former avoids underlining of leading and trailing whitespace,
269 and the latter avoids underlining any whitespace at all."
270 :group 'gnus-article-emphasis
273 (defface gnus-emphasis-bold '((t (:bold t)))
274 "Face used for displaying strong emphasized text (*word*)."
275 :group 'gnus-article-emphasis)
277 (defface gnus-emphasis-italic '((t (:italic t)))
278 "Face used for displaying italic emphasized text (/word/)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-underline '((t (:underline t)))
282 "Face used for displaying underlined emphasized text (_word_)."
283 :group 'gnus-article-emphasis)
285 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
286 "Face used for displaying underlined bold emphasized text (_*word*_)."
287 :group 'gnus-article-emphasis)
289 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
290 "Face used for displaying underlined italic emphasized text (_/word/_)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
294 "Face used for displaying bold italic emphasized text (/*word*/)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-underline-bold-italic
298 '((t (:bold t :italic t :underline t)))
299 "Face used for displaying underlined bold italic emphasized text.
300 Esample: (_/*word*/_)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-highlight-words
304 '((t (:background "black" :foreground "yellow")))
305 "Face used for displaying highlighted words."
306 :group 'gnus-article-emphasis)
308 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
309 "Format for display of Date headers in article bodies.
310 See `format-time-string' for the possible values.
312 The variable can also be function, which should return a complete Date
313 header. The function is called with one argument, the time, which can
314 be fed to `format-time-string'."
315 :type '(choice string symbol)
316 :link '(custom-manual "(gnus)Article Date")
317 :group 'gnus-article-washing)
320 (autoload 'mail-extract-address-components "mail-extr"))
322 (defcustom gnus-save-all-headers t
323 "*If non-nil, don't remove any headers before saving."
324 :group 'gnus-article-saving
327 (defcustom gnus-prompt-before-saving 'always
328 "*This variable says how much prompting is to be done when saving articles.
329 If it is nil, no prompting will be done, and the articles will be
330 saved to the default files. If this variable is `always', each and
331 every article that is saved will be preceded by a prompt, even when
332 saving large batches of articles. If this variable is neither nil not
333 `always', there the user will be prompted once for a file name for
334 each invocation of the saving commands."
335 :group 'gnus-article-saving
336 :type '(choice (item always)
337 (item :tag "never" nil)
338 (sexp :tag "once" :format "%t\n" :value t)))
340 (defcustom gnus-saved-headers gnus-visible-headers
341 "Headers to keep if `gnus-save-all-headers' is nil.
342 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
343 If that variable is nil, however, all headers that match this regexp
344 will be kept while the rest will be deleted before saving."
345 :group 'gnus-article-saving
348 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
349 "A function to save articles in your favourite format.
350 The function must be interactively callable (in other words, it must
351 be an Emacs command).
353 Gnus provides the following functions:
355 * gnus-summary-save-in-rmail (Rmail format)
356 * gnus-summary-save-in-mail (Unix mail format)
357 * gnus-summary-save-in-folder (MH folder)
358 * gnus-summary-save-in-file (article format)
359 * gnus-summary-save-in-vm (use VM's folder format)
360 * gnus-summary-write-to-file (article format -- overwrite)."
361 :group 'gnus-article-saving
362 :type '(radio (function-item gnus-summary-save-in-rmail)
363 (function-item gnus-summary-save-in-mail)
364 (function-item gnus-summary-save-in-folder)
365 (function-item gnus-summary-save-in-file)
366 (function-item gnus-summary-save-in-vm)
367 (function-item gnus-summary-write-to-file)))
369 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
370 "A function generating a file name to save articles in Rmail format.
371 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
372 :group 'gnus-article-saving
375 (defcustom gnus-mail-save-name 'gnus-plain-save-name
376 "A function generating a file name to save articles in Unix mail format.
377 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
378 :group 'gnus-article-saving
381 (defcustom gnus-folder-save-name 'gnus-folder-save-name
382 "A function generating a file name to save articles in MH folder.
383 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
384 :group 'gnus-article-saving
387 (defcustom gnus-file-save-name 'gnus-numeric-save-name
388 "A function generating a file name to save articles in article format.
389 The function is called with NEWSGROUP, HEADERS, and optional
391 :group 'gnus-article-saving
394 (defcustom gnus-split-methods
395 '((gnus-article-archive-name)
396 (gnus-article-nndoc-name))
397 "*Variable used to suggest where articles are to be saved.
398 For instance, if you would like to save articles related to Gnus in
399 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
400 you could set this variable to something like:
402 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
403 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
405 This variable is an alist where the where the key is the match and the
406 value is a list of possible files to save in if the match is non-nil.
408 If the match is a string, it is used as a regexp match on the
409 article. If the match is a symbol, that symbol will be funcalled
410 from the buffer of the article to be saved with the newsgroup as the
411 parameter. If it is a list, it will be evaled in the same buffer.
413 If this form or function returns a string, this string will be used as
414 a possible file name; and if it returns a non-nil list, that list will
415 be used as possible file names."
416 :group 'gnus-article-saving
417 :type '(repeat (choice (list :value (fun) function)
418 (cons :value ("" "") regexp (repeat string))
421 (defcustom gnus-page-delimiter "^\^L"
422 "*Regexp describing what to use as article page delimiters.
423 The default value is \"^\^L\", which is a form linefeed at the
424 beginning of a line."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
429 "*The format specification for the article mode line.
430 See `gnus-summary-mode-line-format' for a closer description.
432 The following additional specs are available:
434 %w The article washing status.
435 %m The number of MIME parts in the article."
437 :group 'gnus-article-various)
439 (defcustom gnus-article-mode-hook nil
440 "*A hook for Gnus article mode."
442 :group 'gnus-article-various)
444 (defcustom gnus-article-menu-hook nil
445 "*Hook run after the creation of the article mode menu."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-prepare-hook nil
450 "*A hook called after an article has been prepared in the article buffer."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-hide-pgp-hook nil
455 "*A hook called after successfully hiding a PGP signature."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-button-face 'bold
460 "Face used for highlighting buttons in the article buffer.
462 An article button is a piece of text that you can activate by pressing
463 `RET' or `mouse-2' above it."
465 :group 'gnus-article-buttons)
467 (defcustom gnus-article-mouse-face 'highlight
468 "Face used for mouse highlighting in the article buffer.
470 Article buttons will be displayed in this face when the cursor is
473 :group 'gnus-article-buttons)
475 (defcustom gnus-signature-face 'gnus-signature-face
476 "Face used for highlighting a signature in the article buffer.
477 Obsolete; use the face `gnus-signature-face' for customizations instead."
479 :group 'gnus-article-highlight
480 :group 'gnus-article-signature)
482 (defface gnus-signature-face
485 "Face used for highlighting a signature in the article buffer."
486 :group 'gnus-article-highlight
487 :group 'gnus-article-signature)
489 (defface gnus-header-from-face
492 (:foreground "spring green"))
495 (:foreground "red3"))
498 "Face used for displaying from headers."
499 :group 'gnus-article-headers
500 :group 'gnus-article-highlight)
502 (defface gnus-header-subject-face
505 (:foreground "SeaGreen3"))
508 (:foreground "red4"))
510 (:bold t :italic t)))
511 "Face used for displaying subject headers."
512 :group 'gnus-article-headers
513 :group 'gnus-article-highlight)
515 (defface gnus-header-newsgroups-face
518 (:foreground "yellow" :italic t))
521 (:foreground "MidnightBlue" :italic t))
524 "Face used for displaying newsgroups headers."
525 :group 'gnus-article-headers
526 :group 'gnus-article-highlight)
528 (defface gnus-header-name-face
531 (:foreground "SeaGreen"))
534 (:foreground "maroon"))
537 "Face used for displaying header names."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight)
541 (defface gnus-header-content-face
544 (:foreground "forest green" :italic t))
547 (:foreground "indianred4" :italic t))
549 (:italic t))) "Face used for displaying header content."
550 :group 'gnus-article-headers
551 :group 'gnus-article-highlight)
553 (defcustom gnus-header-face-alist
554 '(("From" nil gnus-header-from-face)
555 ("Subject" nil gnus-header-subject-face)
556 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
557 ("" gnus-header-name-face gnus-header-content-face))
558 "*Controls highlighting of article header.
560 An alist of the form (HEADER NAME CONTENT).
562 HEADER is a regular expression which should match the name of an
563 header header and NAME and CONTENT are either face names or nil.
565 The name of each header field will be displayed using the face
566 specified by the first element in the list where HEADER match the
567 header name and NAME is non-nil. Similarly, the content will be
568 displayed by the first non-nil matching CONTENT face."
569 :group 'gnus-article-headers
570 :group 'gnus-article-highlight
571 :type '(repeat (list (regexp :tag "Header")
573 (item :tag "skip" nil)
574 (face :value default))
575 (choice :tag "Content"
576 (item :tag "skip" nil)
577 (face :value default)))))
579 (defcustom gnus-article-decode-hook
580 '(article-decode-charset article-decode-encoded-words)
581 "*Hook run to decode charsets in articles."
582 :group 'gnus-article-headers
585 (defcustom gnus-display-mime-function 'gnus-display-mime
586 "Function to display MIME articles."
587 :group 'gnus-article-mime
590 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
591 "Function used to decode headers.")
593 (defvar gnus-article-dumbquotes-map
611 "Table for MS-to-Latin1 translation.")
613 (defcustom gnus-ignored-mime-types nil
614 "List of MIME types that should be ignored by Gnus."
615 :group 'gnus-article-mime
616 :type '(repeat regexp))
618 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
619 "List of MIME types that should not be given buttons when rendered inline."
620 :group 'gnus-article-mime
621 :type '(repeat regexp))
623 (defcustom gnus-article-mime-part-function nil
624 "Function called with a MIME handle as the argument.
625 This is meant for people who want to do something automatic based
626 on parts -- for instance, adding Vcard info to a database."
627 :group 'gnus-article-mime
630 (defcustom gnus-mime-multipart-functions nil
631 "An alist of MIME types to functions to display them.")
633 (defcustom gnus-article-date-lapsed-new-header nil
634 "Whether the X-Sent and Date headers can coexist.
635 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
636 either replace the old \"Date:\" header (if this variable is nil), or
637 be added below it (otherwise)."
638 :group 'gnus-article-headers
641 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
642 "Function called with a MIME handle as the argument.
643 This is meant for people who want to view first matched part.
644 For `undisplayed-alternative' (default), the first undisplayed
645 part or alternative part is used. For `undisplayed', the first
646 undisplayed part is used. For a function, the first part which
647 the function return `t' is used. For `nil', the first part is
649 :group 'gnus-article-mime
651 (item :tag "first" :value nil)
652 (item :tag "undisplayed" :value undisplayed)
653 (item :tag "undisplayed or alternative"
654 :value undisplayed-alternative)
657 (defcustom gnus-mime-action-alist
658 '(("save to file" . gnus-mime-save-part)
659 ("display as text" . gnus-mime-inline-part)
660 ("view the part" . gnus-mime-view-part)
661 ("pipe to command" . gnus-mime-pipe-part)
662 ("toggle display" . gnus-article-press-button)
663 ("view as type" . gnus-mime-view-part-as-type)
664 ("internalize type" . gnus-mime-internalize-part)
665 ("externalize type" . gnus-mime-externalize-part))
666 "An alist of actions that run on the MIME attachment."
667 :group 'gnus-article-mime
668 :type '(repeat (cons (string :tag "name")
672 ;;; The treatment variables
675 (defvar gnus-part-display-hook nil
676 "Hook called on parts that are to receive treatment.")
678 (defvar gnus-article-treat-custom
679 '(choice (const :tag "Off" nil)
681 (const :tag "Header" head)
682 (const :tag "Last" last)
683 (integer :tag "Less")
684 (repeat :tag "Groups" regexp)
685 (sexp :tag "Predicate")))
687 (defvar gnus-article-treat-head-custom
688 '(choice (const :tag "Off" nil)
689 (const :tag "Header" head)))
691 (defvar gnus-article-treat-types '("text/plain")
694 (defvar gnus-inhibit-treatment nil
695 "Whether to inhibit treatment.")
697 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
698 "Highlight the signature.
699 Valid values are nil, t, `head', `last', an integer or a predicate.
700 See the manual for details."
701 :group 'gnus-article-treat
702 :type gnus-article-treat-custom)
703 (put 'gnus-treat-highlight-signature 'highlight t)
705 (defcustom gnus-treat-buttonize 100000
707 Valid values are nil, t, `head', `last', an integer or a predicate.
708 See the manual for details."
709 :group 'gnus-article-treat
710 :type gnus-article-treat-custom)
711 (put 'gnus-treat-buttonize 'highlight t)
713 (defcustom gnus-treat-buttonize-head 'head
714 "Add buttons to the head.
715 Valid values are nil, t, `head', `last', an integer or a predicate.
716 See the manual for details."
717 :group 'gnus-article-treat
718 :type gnus-article-treat-head-custom)
719 (put 'gnus-treat-buttonize-head 'highlight t)
721 (defcustom gnus-treat-emphasize 50000
723 Valid values are nil, t, `head', `last', an integer or a predicate.
724 See the manual for details."
725 :group 'gnus-article-treat
726 :type gnus-article-treat-custom)
727 (put 'gnus-treat-emphasize 'highlight t)
729 (defcustom gnus-treat-strip-cr nil
730 "Remove carriage returns.
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733 :group 'gnus-article-treat
734 :type gnus-article-treat-custom)
736 (defcustom gnus-treat-hide-headers 'head
738 Valid values are nil, t, `head', `last', an integer or a predicate.
739 See the manual for details."
740 :group 'gnus-article-treat
741 :type gnus-article-treat-head-custom)
743 (defcustom gnus-treat-hide-boring-headers nil
744 "Hide boring headers.
745 Valid values are nil, t, `head', `last', an integer or a predicate.
746 See the manual for details."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-head-custom)
750 (defcustom gnus-treat-hide-signature nil
752 Valid values are nil, t, `head', `last', an integer or a predicate.
753 See the manual for details."
754 :group 'gnus-article-treat
755 :type gnus-article-treat-custom)
757 (defcustom gnus-treat-fill-article nil
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-custom)
764 (defcustom gnus-treat-hide-citation nil
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-custom)
771 (defcustom gnus-treat-strip-list-identifiers 'head
772 "Strip list identifiers from `gnus-list-identifiers`.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-custom)
778 (defcustom gnus-treat-strip-pgp t
779 "Strip PGP signatures.
780 Valid values are nil, t, `head', `last', an integer or a predicate.
781 See the manual for details."
782 :group 'gnus-article-treat
783 :type gnus-article-treat-custom)
785 (defcustom gnus-treat-strip-pem nil
786 "Strip PEM signatures.
787 Valid values are nil, t, `head', `last', an integer or a predicate.
788 See the manual for details."
789 :group 'gnus-article-treat
790 :type gnus-article-treat-custom)
792 (defcustom gnus-treat-strip-banner t
793 "Strip banners from articles.
794 The banner to be stripped is specified in the `banner' group parameter.
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-custom)
800 (defcustom gnus-treat-highlight-headers 'head
801 "Highlight the headers.
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-head-custom)
806 (put 'gnus-treat-highlight-headers 'highlight t)
808 (defcustom gnus-treat-highlight-citation t
809 "Highlight cited text.
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-custom)
814 (put 'gnus-treat-highlight-citation 'highlight t)
816 (defcustom gnus-treat-date-ut nil
817 "Display the Date in UT (GMT).
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-head-custom)
823 (defcustom gnus-treat-date-local nil
824 "Display the Date in the local timezone.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-head-custom)
830 (defcustom gnus-treat-date-lapsed nil
831 "Display the Date header in a way that says how much time has elapsed.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-head-custom)
837 (defcustom gnus-treat-date-original nil
838 "Display the date in the original timezone.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-head-custom)
844 (defcustom gnus-treat-date-iso8601 nil
845 "Display the date in the ISO8601 format.
846 Valid values are nil, t, `head', `last', an integer or a predicate.
847 See the manual for details."
848 :group 'gnus-article-treat
849 :type gnus-article-treat-head-custom)
851 (defcustom gnus-treat-date-user-defined nil
852 "Display the date in a user-defined format.
853 The format is defined by the `gnus-article-time-format' variable.
854 Valid values are nil, t, `head', `last', an integer or a predicate.
855 See the manual for details."
856 :group 'gnus-article-treat
857 :type gnus-article-treat-head-custom)
859 (defcustom gnus-treat-strip-headers-in-body t
860 "Strip the X-No-Archive header line from the beginning of the body.
861 Valid values are nil, t, `head', `last', an integer or a predicate.
862 See the manual for details."
863 :group 'gnus-article-treat
864 :type gnus-article-treat-custom)
866 (defcustom gnus-treat-strip-trailing-blank-lines nil
867 "Strip trailing blank lines.
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-custom)
873 (defcustom gnus-treat-strip-leading-blank-lines nil
874 "Strip leading blank lines.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-custom)
880 (defcustom gnus-treat-strip-multiple-blank-lines nil
881 "Strip multiple blank lines.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884 :group 'gnus-article-treat
885 :type gnus-article-treat-custom)
887 (defcustom gnus-treat-overstrike t
888 "Treat overstrike highlighting.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-custom)
893 (put 'gnus-treat-overstrike 'highlight t)
895 (defcustom gnus-treat-display-xface
896 (and (or (and (fboundp 'image-type-available-p)
897 (image-type-available-p 'xbm))
898 (and (featurep 'xemacs) (featurep 'xface)))
900 "Display X-Face headers.
901 Valid values are nil, t, `head', `last', an integer or a predicate.
902 See the manual for details."
903 :group 'gnus-article-treat
904 :type gnus-article-treat-head-custom)
905 (put 'gnus-treat-display-xface 'highlight t)
907 (defcustom gnus-treat-display-smileys
908 (if (or (and (featurep 'xemacs)
910 (and (fboundp 'image-type-available-p)
911 (image-type-available-p 'pbm)))
914 Valid values are nil, t, `head', `last', an integer or a predicate.
915 See the manual for details."
916 :group 'gnus-article-treat
917 :type gnus-article-treat-custom)
918 (put 'gnus-treat-display-smileys 'highlight t)
920 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
922 Valid values are nil, t, `head', `last', an integer or a predicate.
923 See the manual for details."
924 :group 'gnus-article-treat
925 :type gnus-article-treat-head-custom)
926 (put 'gnus-treat-display-picons 'highlight t)
928 (defcustom gnus-treat-capitalize-sentences nil
929 "Capitalize sentence-starting words.
930 Valid values are nil, t, `head', `last', an integer or a predicate.
931 See the manual for details."
932 :group 'gnus-article-treat
933 :type gnus-article-treat-custom)
935 (defcustom gnus-treat-fill-long-lines nil
937 Valid values are nil, t, `head', `last', an integer or a predicate.
938 See the manual for details."
939 :group 'gnus-article-treat
940 :type gnus-article-treat-custom)
942 (defcustom gnus-treat-play-sounds nil
944 Valid values are nil, t, `head', `last', an integer or a predicate.
945 See the manual for details."
946 :group 'gnus-article-treat
947 :type gnus-article-treat-custom)
949 (defcustom gnus-treat-translate nil
950 "Translate articles from one language to another.
951 Valid values are nil, t, `head', `last', an integer or a predicate.
952 See the manual for details."
953 :group 'gnus-article-treat
954 :type gnus-article-treat-custom)
956 ;;; Internal variables
958 (defvar article-goto-body-goes-to-point-min-p nil)
959 (defvar gnus-article-wash-types nil)
960 (defvar gnus-article-emphasis-alist nil)
962 (defvar gnus-article-mime-handle-alist-1 nil)
963 (defvar gnus-treatment-function-alist
964 '((gnus-treat-strip-banner gnus-article-strip-banner)
965 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
966 (gnus-treat-highlight-signature gnus-article-highlight-signature)
967 (gnus-treat-buttonize gnus-article-add-buttons)
968 (gnus-treat-fill-article gnus-article-fill-cited-article)
969 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
970 (gnus-treat-strip-cr gnus-article-remove-cr)
971 (gnus-treat-emphasize gnus-article-emphasize)
972 (gnus-treat-display-xface gnus-article-display-x-face)
973 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
974 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
975 (gnus-treat-hide-signature gnus-article-hide-signature)
976 (gnus-treat-hide-citation gnus-article-hide-citation)
977 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
978 (gnus-treat-strip-pgp gnus-article-hide-pgp)
979 (gnus-treat-strip-pem gnus-article-hide-pem)
980 (gnus-treat-highlight-headers gnus-article-highlight-headers)
981 (gnus-treat-highlight-citation gnus-article-highlight-citation)
982 (gnus-treat-highlight-signature gnus-article-highlight-signature)
983 (gnus-treat-date-ut gnus-article-date-ut)
984 (gnus-treat-date-local gnus-article-date-local)
985 (gnus-treat-date-lapsed gnus-article-date-lapsed)
986 (gnus-treat-date-original gnus-article-date-original)
987 (gnus-treat-date-user-defined gnus-article-date-user)
988 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
989 (gnus-treat-strip-trailing-blank-lines
990 gnus-article-remove-trailing-blank-lines)
991 (gnus-treat-strip-leading-blank-lines
992 gnus-article-strip-leading-blank-lines)
993 (gnus-treat-strip-multiple-blank-lines
994 gnus-article-strip-multiple-blank-lines)
995 (gnus-treat-overstrike gnus-article-treat-overstrike)
996 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
997 (gnus-treat-display-smileys gnus-smiley-display)
998 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
999 (gnus-treat-display-picons gnus-article-display-picons)
1000 (gnus-treat-play-sounds gnus-earcon-display)))
1002 (defvar gnus-article-mime-handle-alist nil)
1003 (defvar article-lapsed-timer nil)
1004 (defvar gnus-article-current-summary nil)
1006 (defvar gnus-article-mode-syntax-table
1007 (let ((table (copy-syntax-table text-mode-syntax-table)))
1008 (modify-syntax-entry ?- "w" table)
1009 (modify-syntax-entry ?> ")" table)
1010 (modify-syntax-entry ?< "(" table)
1012 "Syntax table used in article mode buffers.
1013 Initialized from `text-mode-syntax-table.")
1015 (defvar gnus-save-article-buffer nil)
1017 (defvar gnus-article-mode-line-format-alist
1018 (nconc '((?w (gnus-article-wash-status) ?s)
1019 (?m (gnus-article-mime-part-status) ?s))
1020 gnus-summary-mode-line-format-alist))
1022 (defvar gnus-number-of-articles-to-be-saved nil)
1024 (defvar gnus-inhibit-hiding nil)
1026 (defsubst gnus-article-hide-text (b e props)
1027 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1028 (add-text-properties b e props)
1029 (when (memq 'intangible props)
1031 (max (1- b) (point-min))
1032 b 'intangible (cddr (memq 'intangible props)))))
1033 (defsubst gnus-article-unhide-text (b e)
1034 "Remove hidden text properties from region between B and E."
1035 (remove-text-properties b e gnus-hidden-properties)
1036 (when (memq 'intangible gnus-hidden-properties)
1037 (put-text-property (max (1- b) (point-min))
1038 b 'intangible nil)))
1040 (defun gnus-article-hide-text-type (b e type)
1041 "Hide text of TYPE between B and E."
1042 (push type gnus-article-wash-types)
1043 (gnus-article-hide-text
1044 b e (cons 'article-type (cons type gnus-hidden-properties))))
1046 (defun gnus-article-unhide-text-type (b e type)
1047 "Unhide text of TYPE between B and E."
1048 (setq gnus-article-wash-types
1049 (delq type gnus-article-wash-types))
1050 (remove-text-properties
1051 b e (cons 'article-type (cons type gnus-hidden-properties)))
1052 (when (memq 'intangible gnus-hidden-properties)
1053 (put-text-property (max (1- b) (point-min))
1054 b 'intangible nil)))
1056 (defun gnus-article-hide-text-of-type (type)
1057 "Hide text of TYPE in the current buffer."
1059 (let ((b (point-min))
1061 (while (setq b (text-property-any b e 'article-type type))
1062 (add-text-properties b (incf b) gnus-hidden-properties)))))
1064 (defun gnus-article-delete-text-of-type (type)
1065 "Delete text of TYPE in the current buffer."
1067 (let ((b (point-min)))
1068 (while (setq b (text-property-any b (point-max) 'article-type type))
1070 b (or (text-property-not-all b (point-max) 'article-type type)
1073 (defun gnus-article-delete-invisible-text ()
1074 "Delete all invisible text in the current buffer."
1076 (let ((b (point-min)))
1077 (while (setq b (text-property-any b (point-max) 'invisible t))
1079 b (or (text-property-not-all b (point-max) 'invisible t)
1082 (defun gnus-article-text-type-exists-p (type)
1083 "Say whether any text of type TYPE exists in the buffer."
1084 (text-property-any (point-min) (point-max) 'article-type type))
1086 (defsubst gnus-article-header-rank ()
1087 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1088 (let ((list gnus-sorted-header-list)
1091 (when (looking-at (car list))
1093 (setq list (cdr list))
1097 (defun article-hide-headers (&optional arg delete)
1098 "Hide unwanted headers and possibly sort them as well."
1100 ;; This function might be inhibited.
1101 (unless gnus-inhibit-hiding
1104 (let ((buffer-read-only nil)
1105 (case-fold-search t)
1106 (max (1+ (length gnus-sorted-header-list)))
1107 (ignored (when (not gnus-visible-headers)
1108 (cond ((stringp gnus-ignored-headers)
1109 gnus-ignored-headers)
1110 ((listp gnus-ignored-headers)
1111 (mapconcat 'identity gnus-ignored-headers
1114 (cond ((stringp gnus-visible-headers)
1115 gnus-visible-headers)
1116 ((and gnus-visible-headers
1117 (listp gnus-visible-headers))
1118 (mapconcat 'identity gnus-visible-headers "\\|"))))
1119 (inhibit-point-motion-hooks t)
1121 ;; First we narrow to just the headers.
1122 (article-narrow-to-head)
1123 ;; Hide any "From " lines at the beginning of (mail) articles.
1124 (while (looking-at "From ")
1127 (delete-region (point-min) (point)))
1128 ;; Then treat the rest of the header lines.
1129 ;; Then we use the two regular expressions
1130 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1131 ;; select which header lines is to remain visible in the
1133 (while (re-search-forward "^[^ \t]*:" nil t)
1135 ;; Mark the rank of the header.
1137 (point) (1+ (point)) 'message-rank
1138 (if (or (and visible (looking-at visible))
1140 (not (looking-at ignored))))
1141 (gnus-article-header-rank)
1144 (message-sort-headers-1)
1145 (when (setq beg (text-property-any
1146 (point-min) (point-max) 'message-rank (+ 2 max)))
1147 ;; We delete the unwanted headers.
1148 (push 'headers gnus-article-wash-types)
1149 (add-text-properties (point-min) (+ 5 (point-min))
1150 '(article-type headers dummy-invisible t))
1151 (delete-region beg (point-max))))))))
1153 (defun article-hide-boring-headers (&optional arg)
1154 "Toggle hiding of headers that aren't very interesting.
1155 If given a negative prefix, always show; if given a positive prefix,
1157 (interactive (gnus-article-hidden-arg))
1158 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1159 (not gnus-show-all-headers))
1162 (let ((buffer-read-only nil)
1163 (list gnus-boring-article-headers)
1164 (inhibit-point-motion-hooks t)
1166 (article-narrow-to-head)
1168 (setq elem (pop list))
1169 (goto-char (point-min))
1171 ;; Hide empty headers.
1173 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1175 (gnus-article-hide-text-type
1176 (progn (beginning-of-line) (point))
1179 (if (re-search-forward "^[^ \t]" nil t)
1183 ;; Hide boring Newsgroups header.
1184 ((eq elem 'newsgroups)
1185 (when (equal (gnus-fetch-field "newsgroups")
1186 (gnus-group-real-name
1187 (if (boundp 'gnus-newsgroup-name)
1190 (gnus-article-hide-header "newsgroups")))
1191 ((eq elem 'followup-to)
1192 (when (equal (message-fetch-field "followup-to")
1193 (message-fetch-field "newsgroups"))
1194 (gnus-article-hide-header "followup-to")))
1195 ((eq elem 'reply-to)
1196 (let ((from (message-fetch-field "from"))
1197 (reply-to (message-fetch-field "reply-to")))
1202 (nth 1 (mail-extract-address-components from))
1203 (nth 1 (mail-extract-address-components reply-to)))))
1204 (gnus-article-hide-header "reply-to"))))
1206 (let ((date (message-fetch-field "date")))
1208 (< (days-between (current-time-string) date)
1210 (gnus-article-hide-header "date"))))
1212 (let ((to (message-fetch-field "to"))
1213 (cc (message-fetch-field "cc")))
1214 (when (> (length to) 1024)
1215 (gnus-article-hide-header "to"))
1216 (when (> (length cc) 1024)
1217 (gnus-article-hide-header "cc"))))
1221 (goto-char (point-min))
1222 (while (re-search-forward "^to:" nil t)
1223 (setq to-count (1+ to-count)))
1224 (when (> to-count 1)
1225 (while (> to-count 0)
1226 (goto-char (point-min))
1228 (re-search-forward "^to:" nil nil to-count)
1230 (narrow-to-region (point) (point-max))
1231 (gnus-article-hide-header "to"))
1232 (setq to-count (1- to-count))))
1233 (goto-char (point-min))
1234 (while (re-search-forward "^cc:" nil t)
1235 (setq cc-count (1+ cc-count)))
1236 (when (> cc-count 1)
1237 (while (> cc-count 0)
1238 (goto-char (point-min))
1240 (re-search-forward "^cc:" nil nil cc-count)
1242 (narrow-to-region (point) (point-max))
1243 (gnus-article-hide-header "cc"))
1244 (setq cc-count (1- cc-count)))))))))))))
1246 (defun gnus-article-hide-header (header)
1248 (goto-char (point-min))
1249 (when (re-search-forward (concat "^" header ":") nil t)
1250 (gnus-article-hide-text-type
1251 (progn (beginning-of-line) (point))
1254 (if (re-search-forward "^[^ \t]" nil t)
1259 (defvar gnus-article-normalized-header-length 40
1260 "Length of normalized headers.")
1262 (defun article-normalize-headers ()
1263 "Make all header lines 40 characters long."
1265 (let ((buffer-read-only nil)
1269 (article-narrow-to-head)
1272 ((< (setq column (- (gnus-point-at-eol) (point)))
1273 gnus-article-normalized-header-length)
1275 (insert (make-string
1276 (- gnus-article-normalized-header-length column)
1278 ((> column gnus-article-normalized-header-length)
1279 (gnus-put-text-property
1281 (forward-char gnus-article-normalized-header-length)
1288 (forward-line 1))))))
1290 (defun article-treat-dumbquotes ()
1291 "Translate M******** sm*rtq**t*s into proper text.
1292 Note that this function guesses whether a character is a sm*rtq**t* or
1293 not, so it should only be used interactively."
1295 (article-translate-strings gnus-article-dumbquotes-map))
1297 (defun article-translate-characters (from to)
1298 "Translate all characters in the body of the article according to FROM and TO.
1299 FROM is a string of characters to translate from; to is a string of
1300 characters to translate to."
1302 (when (article-goto-body)
1303 (let ((buffer-read-only nil)
1304 (x (make-string 225 ?x))
1306 (while (< (incf i) (length x))
1309 (while (< i (length from))
1310 (aset x (aref from i) (aref to i))
1312 (translate-region (point) (point-max) x)))))
1314 (defun article-translate-strings (map)
1315 "Translate all string in the body of the article according to MAP.
1316 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1318 (when (article-goto-body)
1319 (let ((buffer-read-only nil)
1321 (while (setq elem (pop map))
1323 (while (search-forward (car elem) nil t)
1324 (replace-match (cadr elem)))))))))
1326 (defun article-treat-overstrike ()
1327 "Translate overstrikes into bold text."
1330 (when (article-goto-body)
1331 (let ((buffer-read-only nil))
1332 (while (search-forward "\b" nil t)
1333 (let ((next (char-after))
1334 (previous (char-after (- (point) 2))))
1335 ;; We do the boldification/underlining by hiding the
1336 ;; overstrikes and putting the proper text property
1340 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1341 (put-text-property (point) (1+ (point)) 'face 'bold))
1343 (gnus-article-hide-text-type
1344 (1- (point)) (1+ (point)) 'overstrike)
1346 (- (point) 2) (1- (point)) 'face 'underline))
1348 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1350 (point) (1+ (point)) 'face 'underline)))))))))
1352 (defun article-fill-long-lines ()
1353 "Fill lines that are wider than the window width."
1356 (let ((buffer-read-only nil)
1357 (width (window-width (get-buffer-window (current-buffer)))))
1360 (let ((adaptive-fill-mode nil))
1363 (when (>= (current-column) (min fill-column width))
1364 (narrow-to-region (point) (gnus-point-at-bol))
1365 (fill-paragraph nil)
1366 (goto-char (point-max))
1368 (forward-line 1)))))))
1370 (defun article-capitalize-sentences ()
1371 "Capitalize the first word in each sentence."
1374 (let ((buffer-read-only nil)
1375 (paragraph-start "^[\n\^L]"))
1379 (forward-sentence)))))
1381 (defun article-remove-cr ()
1382 "Remove trailing CRs and then translate remaining CRs into LFs."
1385 (let ((buffer-read-only nil))
1386 (goto-char (point-min))
1387 (while (re-search-forward "\r+$" nil t)
1388 (replace-match "" t t))
1389 (goto-char (point-min))
1390 (while (search-forward "\r" nil t)
1391 (replace-match "\n" t t)))))
1393 (defun article-remove-trailing-blank-lines ()
1394 "Remove all trailing blank lines from the article."
1397 (let ((buffer-read-only nil))
1398 (goto-char (point-max))
1402 (while (and (not (bobp))
1403 (looking-at "^[ \t]*$")
1404 (not (gnus-annotation-in-region-p
1405 (point) (gnus-point-at-eol))))
1410 (defun article-display-x-face (&optional force)
1411 "Look for an X-Face header and display it if present."
1412 (interactive (list 'force))
1414 ;; Delete the old process, if any.
1415 (when (process-status "article-x-face")
1416 (delete-process "article-x-face"))
1417 (let ((inhibit-point-motion-hooks t)
1418 (case-fold-search t)
1421 (article-narrow-to-head)
1422 (goto-char (point-min))
1423 (setq from (message-fetch-field "from"))
1424 (goto-char (point-min))
1425 (while (and gnus-article-x-face-command
1428 ;; Check whether this face is censored.
1429 (not gnus-article-x-face-too-ugly)
1430 (and gnus-article-x-face-too-ugly from
1431 (not (string-match gnus-article-x-face-too-ugly
1433 ;; Has to be present.
1434 (re-search-forward "^X-Face: " nil t))
1435 ;; This used to try to do multiple faces (`while' instead of
1436 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1437 ;; work (b) it can crash some versions of Emacs (c) are
1438 ;; multiple faces really something to encourage?
1439 (when (stringp gnus-article-x-face-command)
1441 ;; We now have the area of the buffer where the X-Face is stored.
1444 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1445 ;; We display the face.
1446 (if (symbolp gnus-article-x-face-command)
1447 ;; The command is a lisp function, so we call it.
1448 (if (gnus-functionp gnus-article-x-face-command)
1449 (funcall gnus-article-x-face-command beg end)
1450 (error "%s is not a function" gnus-article-x-face-command))
1451 ;; The command is a string, so we interpret the command
1452 ;; as a, well, command, and fork it off.
1453 (let ((process-connection-type nil))
1454 (process-kill-without-query
1456 "article-x-face" nil shell-file-name shell-command-switch
1457 gnus-article-x-face-command))
1458 (process-send-region "article-x-face" beg end)
1459 (process-send-eof "article-x-face"))))))))))
1461 (defun article-decode-mime-words ()
1462 "Decode all MIME-encoded words in the article."
1465 (set-buffer gnus-article-buffer)
1466 (let ((inhibit-point-motion-hooks t)
1468 (mail-parse-charset gnus-newsgroup-charset)
1469 (mail-parse-ignored-charsets
1470 (save-excursion (set-buffer gnus-summary-buffer)
1471 gnus-newsgroup-ignored-charsets)))
1472 (mail-decode-encoded-word-region (point-min) (point-max)))))
1474 (defun article-decode-charset (&optional prompt)
1475 "Decode charset-encoded text in the article.
1476 If PROMPT (the prefix), prompt for a coding system to use."
1478 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1480 (mail-parse-charset gnus-newsgroup-charset)
1481 (mail-parse-ignored-charsets
1482 (save-excursion (condition-case nil
1483 (set-buffer gnus-summary-buffer)
1485 gnus-newsgroup-ignored-charsets))
1486 ct cte ctl charset format)
1489 (article-narrow-to-head)
1490 (setq ct (message-fetch-field "Content-Type" t)
1491 cte (message-fetch-field "Content-Transfer-Encoding" t)
1492 ctl (and ct (ignore-errors
1493 (mail-header-parse-content-type ct)))
1496 (mm-read-coding-system "Charset to decode: "))
1498 (mail-content-type-get ctl 'charset)))
1499 format (and ctl (mail-content-type-get ctl 'format)))
1501 (setq cte (mail-header-strip cte)))
1502 (if (and ctl (not (string-match "/" (car ctl))))
1504 (goto-char (point-max)))
1507 (narrow-to-region (point) (point-max))
1508 (when (and (eq mail-parse-charset 'gnus-decoded)
1509 (eq (mm-body-7-or-8) '8bit))
1510 ;; The text code could have been decoded.
1511 (setq charset mail-parse-charset))
1512 (when (and (or (not ctl)
1513 (equal (car ctl) "text/plain"))
1514 (not format)) ;; article with format will decode later.
1516 charset (and cte (intern (downcase
1517 (gnus-strip-whitespace cte))))
1520 (defun article-decode-encoded-words ()
1521 "Remove encoded-word encoding from headers."
1522 (let ((inhibit-point-motion-hooks t)
1523 (mail-parse-charset gnus-newsgroup-charset)
1524 (mail-parse-ignored-charsets
1525 (save-excursion (condition-case nil
1526 (set-buffer gnus-summary-buffer)
1528 gnus-newsgroup-ignored-charsets))
1531 (article-narrow-to-head)
1532 (funcall gnus-decode-header-function (point-min) (point-max)))))
1534 (defun article-de-quoted-unreadable (&optional force)
1535 "Translate a quoted-printable-encoded article.
1536 If FORCE, decode the article whether it is marked as quoted-printable
1538 (interactive (list 'force))
1540 (let ((buffer-read-only nil) type charset)
1541 (if (gnus-buffer-live-p gnus-original-article-buffer)
1542 (with-current-buffer gnus-original-article-buffer
1544 (gnus-fetch-field "content-transfer-encoding"))
1545 (let* ((ct (gnus-fetch-field "content-type"))
1548 (mail-header-parse-content-type ct)))))
1549 (setq charset (and ctl
1550 (mail-content-type-get ctl 'charset)))
1551 (if (stringp charset)
1552 (setq charset (intern (downcase charset)))))))
1554 (setq charset gnus-newsgroup-charset))
1556 (and type (let ((case-fold-search t))
1557 (string-match "quoted-printable" type))))
1559 (quoted-printable-decode-region
1560 (point) (point-max) (mm-charset-to-coding-system charset))))))
1562 (defun article-de-base64-unreadable (&optional force)
1563 "Translate a base64 article.
1564 If FORCE, decode the article whether it is marked as base64 not."
1565 (interactive (list 'force))
1567 (let ((buffer-read-only nil) type charset)
1568 (if (gnus-buffer-live-p gnus-original-article-buffer)
1569 (with-current-buffer gnus-original-article-buffer
1571 (gnus-fetch-field "content-transfer-encoding"))
1572 (let* ((ct (gnus-fetch-field "content-type"))
1575 (mail-header-parse-content-type ct)))))
1576 (setq charset (and ctl
1577 (mail-content-type-get ctl 'charset)))
1578 (if (stringp charset)
1579 (setq charset (intern (downcase charset)))))))
1581 (setq charset gnus-newsgroup-charset))
1583 (and type (let ((case-fold-search t))
1584 (string-match "base64" type))))
1587 (narrow-to-region (point) (point-max))
1588 (base64-decode-region (point-min) (point-max))
1589 (mm-decode-coding-region
1590 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1595 (defun article-decode-HZ ()
1596 "Translate a HZ-encoded article."
1600 (let ((buffer-read-only nil))
1601 (rfc1843-decode-region (point-min) (point-max)))))
1603 (defun article-wash-html ()
1604 "Format an html article."
1607 (let ((buffer-read-only nil)
1609 (if (gnus-buffer-live-p gnus-original-article-buffer)
1610 (with-current-buffer gnus-original-article-buffer
1611 (let* ((ct (gnus-fetch-field "content-type"))
1614 (mail-header-parse-content-type ct)))))
1615 (setq charset (and ctl
1616 (mail-content-type-get ctl 'charset)))
1617 (if (stringp charset)
1618 (setq charset (intern (downcase charset)))))))
1620 (setq charset gnus-newsgroup-charset))
1622 (save-window-excursion
1624 (narrow-to-region (point) (point-max))
1626 (let ((w3-strict-width (window-width))
1627 (url-standalone-mode t))
1629 (w3-region (point-min) (point-max))
1632 (defun article-hide-list-identifiers ()
1633 "Remove list identifies from the Subject header.
1634 The `gnus-list-identifiers' variable specifies what to do."
1638 (let ((inhibit-point-motion-hooks t)
1640 (article-narrow-to-head)
1641 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1642 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1644 (goto-char (point-min))
1645 (when (re-search-forward
1646 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1647 " *\\)\\)+\\(Re: +\\)?\\)")
1649 (let ((s (or (match-string 3) (match-string 5))))
1650 (delete-region (match-beginning 1) (match-end 1))
1652 (goto-char (match-beginning 1))
1655 (defun article-hide-pgp ()
1656 "Remove any PGP headers and signatures in the current article."
1660 (let ((inhibit-point-motion-hooks t)
1661 buffer-read-only beg end)
1663 ;; Hide the "header".
1664 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1665 (push 'pgp gnus-article-wash-types)
1666 (delete-region (match-beginning 0) (match-end 0))
1667 ;; Remove armor headers (rfc2440 6.2)
1668 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1671 ;; Hide the actual signature.
1672 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1673 (setq end (1+ (match-beginning 0)))
1676 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1678 ;; Perhaps we shouldn't hide to the end of the buffer
1679 ;; if there is no end to the signature?
1681 ;; Hide "- " PGP quotation markers.
1683 (narrow-to-region beg end)
1684 (goto-char (point-min))
1685 (while (re-search-forward "^- " nil t)
1687 (match-beginning 0) (match-end 0)))
1689 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1691 (defun article-hide-pem (&optional arg)
1692 "Toggle hiding of any PEM headers and signatures in the current article.
1693 If given a negative prefix, always show; if given a positive prefix,
1695 (interactive (gnus-article-hidden-arg))
1696 (unless (gnus-article-check-hidden-text 'pem arg)
1698 (let (buffer-read-only end)
1699 (goto-char (point-min))
1700 ;; Hide the horrendously ugly "header".
1701 (when (and (search-forward
1702 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1704 (setq end (1+ (match-beginning 0))))
1705 (push 'pem gnus-article-wash-types)
1706 (gnus-article-hide-text-type
1708 (if (search-forward "\n\n" nil t)
1712 ;; Hide the trailer as well
1713 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1715 (gnus-article-hide-text-type
1716 (match-beginning 0) (match-end 0) 'pem)))))))
1718 (defun article-strip-banner ()
1719 "Strip the banner specified by the `banner' group parameter."
1723 (let ((inhibit-point-motion-hooks t)
1724 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1725 (gnus-signature-limit nil)
1726 buffer-read-only beg end)
1730 ((eq banner 'signature)
1731 (when (gnus-article-narrow-to-signature)
1734 (delete-region (point) (point-max))))
1736 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1737 (while (re-search-forward banner nil t)
1738 (delete-region (match-beginning 0) (match-end 0)))))
1740 (while (re-search-forward banner nil t)
1741 (delete-region (match-beginning 0) (match-end 0))))))))))
1743 (defun article-babel ()
1744 "Translate article using an online translation service."
1748 (set-buffer gnus-article-buffer)
1749 (when (article-goto-body)
1750 (let* ((buffer-read-only nil)
1753 (orig (buffer-substring start end))
1754 (trans (babel-as-string orig)))
1756 (narrow-to-region start end)
1757 (delete-region start end)
1760 (defun article-hide-signature (&optional arg)
1761 "Hide the signature in the current article.
1762 If given a negative prefix, always show; if given a positive prefix,
1764 (interactive (gnus-article-hidden-arg))
1765 (unless (gnus-article-check-hidden-text 'signature arg)
1768 (let ((buffer-read-only nil))
1769 (when (gnus-article-narrow-to-signature)
1770 (gnus-article-hide-text-type
1771 (point-min) (point-max) 'signature)))))))
1773 (defun article-strip-headers-in-body ()
1774 "Strip offensive headers from bodies."
1778 (let ((case-fold-search t))
1779 (when (looking-at "x-no-archive:")
1780 (gnus-delete-line)))))
1782 (defun article-strip-leading-blank-lines ()
1783 "Remove all blank lines from the beginning of the article."
1786 (let ((inhibit-point-motion-hooks t)
1788 (when (article-goto-body)
1789 (while (and (not (eobp))
1790 (looking-at "[ \t]*$"))
1791 (gnus-delete-line))))))
1793 (defun article-narrow-to-head ()
1794 "Narrow the buffer to the head of the message.
1795 Point is left at the beginning of the narrowed-to region."
1797 (goto-char (point-min))
1798 (if (search-forward "\n\n" nil 1)
1801 (goto-char (point-min)))
1803 (defun article-goto-body ()
1804 "Place point at the start of the body."
1805 (goto-char (point-min))
1807 ;; This variable is only bound when dealing with separate
1809 (article-goto-body-goes-to-point-min-p
1811 ((search-forward "\n\n" nil t)
1814 (goto-char (point-max))
1817 (defun article-strip-multiple-blank-lines ()
1818 "Replace consecutive blank lines with one empty line."
1821 (let ((inhibit-point-motion-hooks t)
1823 ;; First make all blank lines empty.
1825 (while (re-search-forward "^[ \t]+$" nil t)
1826 (unless (gnus-annotation-in-region-p
1827 (match-beginning 0) (match-end 0))
1828 (replace-match "" nil t)))
1829 ;; Then replace multiple empty lines with a single empty line.
1831 (while (re-search-forward "\n\n\n+" nil t)
1832 (unless (gnus-annotation-in-region-p
1833 (match-beginning 0) (match-end 0))
1834 (replace-match "\n\n" t t))))))
1836 (defun article-strip-leading-space ()
1837 "Remove all white space from the beginning of the lines in the article."
1840 (let ((inhibit-point-motion-hooks t)
1843 (while (re-search-forward "^[ \t]+" nil t)
1844 (replace-match "" t t)))))
1846 (defun article-strip-trailing-space ()
1847 "Remove all white space from the end of the lines in the article."
1850 (let ((inhibit-point-motion-hooks t)
1853 (while (re-search-forward "[ \t]+$" nil t)
1854 (replace-match "" t t)))))
1856 (defun article-strip-blank-lines ()
1857 "Strip leading, trailing and multiple blank lines."
1859 (article-strip-leading-blank-lines)
1860 (article-remove-trailing-blank-lines)
1861 (article-strip-multiple-blank-lines))
1863 (defun article-strip-all-blank-lines ()
1864 "Strip all blank lines."
1867 (let ((inhibit-point-motion-hooks t)
1870 (while (re-search-forward "^[ \t]*\n" nil t)
1871 (replace-match "" t t)))))
1873 (defun gnus-article-narrow-to-signature ()
1874 "Narrow to the signature; return t if a signature is found, else nil."
1875 (let ((inhibit-point-motion-hooks t))
1876 (when (gnus-article-search-signature)
1878 ;; Check whether we have some limits to what we consider
1879 ;; to be a signature.
1880 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1881 (list gnus-signature-limit)))
1883 (while (setq limit (pop limits))
1884 (if (or (and (integerp limit)
1885 (< (- (point-max) (point)) limit))
1887 (< (count-lines (point) (point-max)) limit))
1888 (and (gnus-functionp limit)
1890 (and (stringp limit)
1891 (not (re-search-forward limit nil t))))
1892 () ; This limit did not succeed.
1896 (narrow-to-region (point) (point-max))
1899 (defun gnus-article-search-signature ()
1900 "Search the current buffer for the signature separator.
1901 Put point at the beginning of the signature separator."
1902 (let ((cur (point)))
1903 (goto-char (point-max))
1904 (if (if (stringp gnus-signature-separator)
1905 (re-search-backward gnus-signature-separator nil t)
1906 (let ((seps gnus-signature-separator))
1908 (not (re-search-backward (car seps) nil t)))
1915 (defun gnus-article-hidden-arg ()
1916 "Return the current prefix arg as a number, or 0 if no prefix."
1917 (list (if current-prefix-arg
1918 (prefix-numeric-value current-prefix-arg)
1921 (defun gnus-article-check-hidden-text (type arg)
1922 "Return nil if hiding is necessary.
1923 Arg can be nil or a number. Nil and positive means hide, negative
1924 means show, 0 means toggle."
1927 (let ((hide (gnus-article-hidden-text-p type)))
1933 (gnus-article-show-hidden-text type))
1935 (if (eq hide 'hidden)
1936 (gnus-article-show-hidden-text type)
1939 (defun gnus-article-hidden-text-p (type)
1940 "Say whether the current buffer contains hidden text of type TYPE."
1941 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1943 (not (get-text-property pos 'invisible))
1944 (not (get-text-property pos 'dummy-invisible)))
1946 (text-property-any (1+ pos) (point-max) 'article-type type)))
1951 (defun gnus-article-show-hidden-text (type &optional hide)
1952 "Show all hidden text of type TYPE.
1953 If HIDE, hide the text instead."
1955 (let ((buffer-read-only nil)
1956 (inhibit-point-motion-hooks t)
1959 (while (setq beg (text-property-any end (point-max) 'article-type type))
1962 (text-property-not-all beg (point-max) 'article-type type)
1965 (gnus-article-hide-text beg end gnus-hidden-properties)
1966 (gnus-article-unhide-text beg end))
1970 (defconst article-time-units
1971 `((year . ,(* 365.25 24 60 60))
1972 (week . ,(* 7 24 60 60))
1973 (day . ,(* 24 60 60))
1977 "Mapping from time units to seconds.")
1979 (defun article-date-ut (&optional type highlight header)
1980 "Convert DATE date to universal time in the current article.
1981 If TYPE is `local', convert to local time; if it is `lapsed', output
1982 how much time has lapsed since DATE. For `lapsed', the value of
1983 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1984 should replace the \"Date:\" one, or should be added below it."
1985 (interactive (list 'ut t))
1986 (let* ((header (or header
1987 (message-fetch-field "date")
1989 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1992 ((not gnus-article-date-lapsed-new-header)
1998 (date (if (vectorp header) (mail-header-date header)
2000 (inhibit-point-motion-hooks t)
2005 (article-narrow-to-head)
2006 (when (re-search-forward tdate-regexp nil t)
2007 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2008 date (or (get-text-property (gnus-point-at-bol)
2011 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2013 (when (and date (not (string= date "")))
2014 (goto-char (point-min))
2015 (let ((buffer-read-only nil))
2016 ;; Delete any old Date headers.
2017 (while (re-search-forward date-regexp nil t)
2019 (delete-region (progn (beginning-of-line) (point))
2020 (progn (forward-line 1) (point)))
2021 (delete-region (progn (beginning-of-line) (point))
2022 (progn (end-of-line) (point)))
2023 (setq pos (point))))
2024 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2026 (if pos (goto-char pos))
2027 (insert (article-make-date-line date (or type 'ut)))
2033 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2034 (put-text-property (match-beginning 1) (1+ (match-end 1))
2035 'original-date date)
2036 (put-text-property (match-beginning 1) (1+ (match-end 1))
2038 (put-text-property (match-beginning 2) (match-end 2)
2041 (defun article-make-date-line (date type)
2042 "Return a DATE line of TYPE."
2043 (let ((time (condition-case ()
2047 ;; Convert to the local timezone. We have to slap a
2048 ;; `condition-case' round the calls to the timezone
2049 ;; functions since they aren't particularly resistant to
2052 (let ((tz (car (current-time-zone time))))
2053 (format "Date: %s %s%02d%02d" (current-time-string time)
2054 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2055 (/ (% (abs tz) 3600) 60))))
2056 ;; Convert to Universal Time.
2059 (current-time-string
2060 (let* ((e (parse-time-string date))
2061 (tm (apply 'encode-time e))
2063 (ls (- (cadr tm) (car (current-time-zone time)))))
2064 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2065 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2068 ;; Get the original date from the article.
2069 ((eq type 'original)
2070 (concat "Date: " (if (string-match "\n+$" date)
2071 (substring date 0 (match-beginning 0))
2073 ;; Let the user define the format.
2075 (if (gnus-functionp gnus-article-time-format)
2076 (funcall gnus-article-time-format time)
2079 (format-time-string gnus-article-time-format time))))
2082 (let ((tz (car (current-time-zone time))))
2085 (format-time-string "%Y%m%dT%H%M%S" time)
2086 (format "%s%02d%02d"
2087 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2088 (/ (% (abs tz) 3600) 60)))))
2089 ;; Do an X-Sent lapsed format.
2091 ;; If the date is seriously mangled, the timezone functions are
2092 ;; liable to bug out, so we ignore all errors.
2093 (let* ((now (current-time))
2094 (real-time (subtract-time now time))
2095 (real-sec (and real-time
2096 (+ (* (float (car real-time)) 65536)
2098 (sec (and real-time (abs real-sec)))
2108 ;; This is a bit convoluted, but basically we go
2109 ;; through the time units for years, weeks, etc,
2110 ;; and divide things to see whether that results
2111 ;; in positive answers.
2114 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2115 ;; The (remaining) seconds are too few to
2116 ;; be divided into this time unit.
2118 ;; It's big enough, so we output it.
2119 (setq sec (- sec (* num (cdr unit))))
2121 (concat (if prev ", " "") (int-to-string
2123 " " (symbol-name (car unit))
2124 (if (> num 1) "s" ""))
2126 article-time-units "")
2127 ;; If dates are odd, then it might appear like the
2128 ;; article was sent in the future.
2131 " in the future"))))))
2133 (error "Unknown conversion type: %s" type)))))
2135 (defun article-date-local (&optional highlight)
2136 "Convert the current article date to the local timezone."
2137 (interactive (list t))
2138 (article-date-ut 'local highlight))
2140 (defun article-date-original (&optional highlight)
2141 "Convert the current article date to what it was originally.
2142 This is only useful if you have used some other date conversion
2143 function and want to see what the date was before converting."
2144 (interactive (list t))
2145 (article-date-ut 'original highlight))
2147 (defun article-date-lapsed (&optional highlight)
2148 "Convert the current article date to time lapsed since it was sent."
2149 (interactive (list t))
2150 (article-date-ut 'lapsed highlight))
2152 (defun article-update-date-lapsed ()
2153 "Function to be run from a timer to update the lapsed time line."
2154 (let (deactivate-mark)
2159 (set-buffer (window-buffer w))
2160 (when (eq major-mode 'gnus-article-mode)
2161 (goto-char (point-min))
2162 (when (re-search-forward "^X-Sent:" nil t)
2163 (article-date-lapsed t))))
2166 (defun gnus-start-date-timer (&optional n)
2167 "Start a timer to update the X-Sent header in the article buffers.
2168 The numerical prefix says how frequently (in seconds) the function
2173 (gnus-stop-date-timer)
2174 (setq article-lapsed-timer
2175 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2177 (defun gnus-stop-date-timer ()
2178 "Stop the X-Sent timer."
2180 (when article-lapsed-timer
2181 (nnheader-cancel-timer article-lapsed-timer)
2182 (setq article-lapsed-timer nil)))
2184 (defun article-date-user (&optional highlight)
2185 "Convert the current article date to the user-defined format.
2186 This format is defined by the `gnus-article-time-format' variable."
2187 (interactive (list t))
2188 (article-date-ut 'user highlight))
2190 (defun article-date-iso8601 (&optional highlight)
2191 "Convert the current article date to ISO8601."
2192 (interactive (list t))
2193 (article-date-ut 'iso8601 highlight))
2195 (defun article-show-all ()
2196 "Show all hidden text in the article buffer."
2199 (let ((buffer-read-only nil))
2200 (gnus-article-unhide-text (point-min) (point-max)))))
2202 (defun article-emphasize (&optional arg)
2203 "Emphasize text according to `gnus-emphasis-alist'."
2204 (interactive (gnus-article-hidden-arg))
2205 (unless (gnus-article-check-hidden-text 'emphasis arg)
2209 (with-current-buffer gnus-summary-buffer
2210 gnus-article-emphasis-alist)
2212 gnus-emphasis-alist))
2213 (buffer-read-only nil)
2214 (props (append '(article-type emphasis)
2215 gnus-hidden-properties))
2216 regexp elem beg invisible visible face)
2219 (while (setq elem (pop alist))
2221 (setq regexp (car elem)
2222 invisible (nth 1 elem)
2223 visible (nth 2 elem)
2225 (while (re-search-forward regexp nil t)
2226 (when (and (match-beginning visible) (match-beginning invisible))
2227 (push 'emphasis gnus-article-wash-types)
2228 (gnus-article-hide-text
2229 (match-beginning invisible) (match-end invisible) props)
2230 (gnus-article-unhide-text-type
2231 (match-beginning visible) (match-end visible) 'emphasis)
2232 (gnus-put-text-property-excluding-newlines
2233 (match-beginning visible) (match-end visible) 'face face)
2234 (goto-char (match-end invisible)))))))))
2236 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2237 "Setup newsgroup emphasis alist."
2238 (unless gnus-article-emphasis-alist
2239 (let ((name (and gnus-newsgroup-name
2240 (gnus-group-real-name gnus-newsgroup-name))))
2241 (make-local-variable 'gnus-article-emphasis-alist)
2242 (setq gnus-article-emphasis-alist
2244 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2245 (while (setq elem (pop alist))
2246 (when (and name (string-match (car elem) name))
2248 highlight (copy-sequence (cdr elem)))))
2250 (copy-sequence highlight-words)
2251 (if gnus-newsgroup-name
2252 (copy-sequence (gnus-group-find-parameter
2253 gnus-newsgroup-name 'highlight-words t)))
2254 gnus-emphasis-alist)))))
2256 (defvar gnus-summary-article-menu)
2257 (defvar gnus-summary-post-menu)
2259 ;;; Saving functions.
2261 (defun gnus-article-save (save-buffer file &optional num)
2262 "Save the currently selected article."
2263 (unless gnus-save-all-headers
2264 ;; Remove headers according to `gnus-saved-headers'.
2265 (let ((gnus-visible-headers
2266 (or gnus-saved-headers gnus-visible-headers))
2267 (gnus-article-buffer save-buffer))
2269 (set-buffer save-buffer)
2270 (article-hide-headers 1 t))))
2271 (save-window-excursion
2272 (if (not gnus-default-article-saver)
2273 (error "No default saver is defined")
2274 ;; !!! Magic! The saving functions all save
2275 ;; `gnus-save-article-buffer' (or so they think), but we
2276 ;; bind that variable to our save-buffer.
2277 (set-buffer gnus-article-buffer)
2278 (let* ((gnus-save-article-buffer save-buffer)
2281 ((not gnus-prompt-before-saving) 'default)
2282 ((eq gnus-prompt-before-saving 'always) nil)
2284 (gnus-number-of-articles-to-be-saved
2285 (when (eq gnus-prompt-before-saving t)
2287 (set-buffer gnus-article-current-summary)
2288 (funcall gnus-default-article-saver filename)))))
2290 (defun gnus-read-save-file-name (prompt &optional filename
2291 function group headers variable)
2293 (funcall function group headers (symbol-value variable)))
2298 ((eq filename 'default)
2304 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2307 (if (and gnus-number-of-articles-to-be-saved
2308 (> gnus-number-of-articles-to-be-saved 1))
2309 (format "these %d articles"
2310 gnus-number-of-articles-to-be-saved)
2313 ;; Let the split methods have their say.
2315 ;; No split name was found.
2318 (concat prompt " (default "
2319 (file-name-nondirectory default-name) ") ")
2320 (file-name-directory default-name)
2322 ;; A single group name is returned.
2323 ((stringp split-name)
2325 (funcall function split-name headers
2326 (symbol-value variable)))
2328 (concat prompt " (default "
2329 (file-name-nondirectory default-name) ") ")
2330 (file-name-directory default-name)
2332 ;; A single split name was found
2333 ((= 1 (length split-name))
2334 (let* ((name (expand-file-name
2335 (car split-name) gnus-article-save-directory))
2336 (dir (cond ((file-directory-p name)
2337 (file-name-as-directory name))
2338 ((file-exists-p name) name)
2339 (t gnus-article-save-directory))))
2341 (concat prompt " (default " name ") ")
2343 ;; A list of splits was found.
2345 (setq split-name (nreverse split-name))
2347 (let ((file-name-history
2348 (nconc split-name file-name-history)))
2352 (concat prompt " (`M-p' for defaults) ")
2353 gnus-article-save-directory
2355 gnus-article-save-directory)))
2356 (car (push result file-name-history)))))))
2357 ;; Create the directory.
2358 (gnus-make-directory (file-name-directory file))
2359 ;; If we have read a directory, we append the default file name.
2360 (when (file-directory-p file)
2361 (setq file (expand-file-name (file-name-nondirectory default-name)
2362 (file-name-as-directory file))))
2363 ;; Possibly translate some characters.
2364 (nnheader-translate-file-chars file))))))
2365 (gnus-make-directory (file-name-directory result))
2366 (set variable result)))
2368 (defun gnus-article-archive-name (group)
2369 "Return the first instance of an \"Archive-name\" in the current buffer."
2370 (let ((case-fold-search t))
2371 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2372 (nnheader-concat gnus-article-save-directory
2373 (match-string 1)))))
2375 (defun gnus-article-nndoc-name (group)
2376 "If GROUP is an nndoc group, return the name of the parent group."
2377 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2378 (gnus-group-get-parameter group 'save-article-group)))
2380 (defun gnus-summary-save-in-rmail (&optional filename)
2381 "Append this article to Rmail file.
2382 Optional argument FILENAME specifies file name.
2383 Directory to save to is default to `gnus-article-save-directory'."
2384 (setq filename (gnus-read-save-file-name
2385 "Save %s in rmail file:" filename
2386 gnus-rmail-save-name gnus-newsgroup-name
2387 gnus-current-headers 'gnus-newsgroup-last-rmail))
2388 (gnus-eval-in-buffer-window gnus-save-article-buffer
2392 (gnus-output-to-rmail filename))))
2395 (defun gnus-summary-save-in-mail (&optional filename)
2396 "Append this article to Unix mail file.
2397 Optional argument FILENAME specifies file name.
2398 Directory to save to is default to `gnus-article-save-directory'."
2399 (setq filename (gnus-read-save-file-name
2400 "Save %s in Unix mail file:" filename
2401 gnus-mail-save-name gnus-newsgroup-name
2402 gnus-current-headers 'gnus-newsgroup-last-mail))
2403 (gnus-eval-in-buffer-window gnus-save-article-buffer
2407 (if (and (file-readable-p filename)
2408 (mail-file-babyl-p filename))
2409 (rmail-output-to-rmail-file filename t)
2410 (gnus-output-to-mail filename)))))
2413 (defun gnus-summary-save-in-file (&optional filename overwrite)
2414 "Append this article to file.
2415 Optional argument FILENAME specifies file name.
2416 Directory to save to is default to `gnus-article-save-directory'."
2417 (setq filename (gnus-read-save-file-name
2418 "Save %s in file:" filename
2419 gnus-file-save-name gnus-newsgroup-name
2420 gnus-current-headers 'gnus-newsgroup-last-file))
2421 (gnus-eval-in-buffer-window gnus-save-article-buffer
2425 (when (and overwrite
2426 (file-exists-p filename))
2427 (delete-file filename))
2428 (gnus-output-to-file filename))))
2431 (defun gnus-summary-write-to-file (&optional filename)
2432 "Write this article to a file.
2433 Optional argument FILENAME specifies file name.
2434 The directory to save in defaults to `gnus-article-save-directory'."
2435 (gnus-summary-save-in-file nil t))
2437 (defun gnus-summary-save-body-in-file (&optional filename)
2438 "Append this article body to a file.
2439 Optional argument FILENAME specifies file name.
2440 The directory to save in defaults to `gnus-article-save-directory'."
2441 (setq filename (gnus-read-save-file-name
2442 "Save %s body in file:" filename
2443 gnus-file-save-name gnus-newsgroup-name
2444 gnus-current-headers 'gnus-newsgroup-last-file))
2445 (gnus-eval-in-buffer-window gnus-save-article-buffer
2449 (when (article-goto-body)
2450 (narrow-to-region (point) (point-max)))
2451 (gnus-output-to-file filename))))
2454 (defun gnus-summary-save-in-pipe (&optional command)
2455 "Pipe this article to subprocess."
2457 (cond ((and (eq command 'default)
2458 gnus-last-shell-command)
2459 gnus-last-shell-command)
2463 "Shell command on %s: "
2464 (if (and gnus-number-of-articles-to-be-saved
2465 (> gnus-number-of-articles-to-be-saved 1))
2466 (format "these %d articles"
2467 gnus-number-of-articles-to-be-saved)
2469 gnus-last-shell-command))))
2470 (when (string-equal command "")
2471 (setq command gnus-last-shell-command))
2472 (gnus-eval-in-buffer-window gnus-article-buffer
2475 (shell-command-on-region (point-min) (point-max) command nil)))
2476 (setq gnus-last-shell-command command))
2478 ;;; Article file names when saving.
2480 (defun gnus-capitalize-newsgroup (newsgroup)
2481 "Capitalize NEWSGROUP name."
2482 (when (not (zerop (length newsgroup)))
2483 (concat (char-to-string (upcase (aref newsgroup 0)))
2484 (substring newsgroup 1))))
2486 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2487 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2488 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2489 Otherwise, it is like ~/News/news/group/num."
2492 (concat (if (gnus-use-long-file-name 'not-save)
2493 (gnus-capitalize-newsgroup newsgroup)
2494 (gnus-newsgroup-directory-form newsgroup))
2495 "/" (int-to-string (mail-header-number headers)))
2496 gnus-article-save-directory)))
2498 (string-equal (file-name-directory default)
2499 (file-name-directory last-file))
2500 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2502 (or last-file default))))
2504 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2505 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2506 If variable `gnus-use-long-file-name' is non-nil, it is
2507 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2510 (concat (if (gnus-use-long-file-name 'not-save)
2512 (gnus-newsgroup-directory-form newsgroup))
2513 "/" (int-to-string (mail-header-number headers)))
2514 gnus-article-save-directory)))
2516 (string-equal (file-name-directory default)
2517 (file-name-directory last-file))
2518 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2520 (or last-file default))))
2522 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2523 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2524 If variable `gnus-use-long-file-name' is non-nil, it is
2525 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2528 (if (gnus-use-long-file-name 'not-save)
2530 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2531 gnus-article-save-directory)))
2538 (setq afunc (car func)
2541 gfunc (intern (format "gnus-%s" func))))
2544 `(lambda (&optional interactive &rest args)
2545 ,(documentation afunc t)
2546 (interactive (list t))
2548 (set-buffer gnus-article-buffer)
2550 (call-interactively ',afunc)
2551 (apply ',afunc args))))))))
2552 '(article-hide-headers
2553 article-hide-boring-headers
2554 article-treat-overstrike
2555 article-fill-long-lines
2556 article-capitalize-sentences
2558 article-display-x-face
2559 article-de-quoted-unreadable
2560 article-de-base64-unreadable
2563 article-hide-list-identifiers
2565 article-strip-banner
2568 article-hide-signature
2569 article-strip-headers-in-body
2570 article-remove-trailing-blank-lines
2571 article-strip-leading-blank-lines
2572 article-strip-multiple-blank-lines
2573 article-strip-leading-space
2574 article-strip-trailing-space
2575 article-strip-blank-lines
2576 article-strip-all-blank-lines
2578 article-date-iso8601
2579 article-date-original
2581 article-decode-mime-words
2582 article-decode-charset
2583 article-decode-encoded-words
2587 article-treat-dumbquotes
2588 article-normalize-headers
2589 (article-show-all . gnus-article-show-all-headers))))
2592 ;;; Gnus article mode
2595 (put 'gnus-article-mode 'mode-class 'special)
2597 (set-keymap-parent gnus-article-mode-map widget-keymap)
2599 (gnus-define-keys gnus-article-mode-map
2600 " " gnus-article-goto-next-page
2601 "\177" gnus-article-goto-prev-page
2602 [delete] gnus-article-goto-prev-page
2603 [backspace] gnus-article-goto-prev-page
2604 "\C-c^" gnus-article-refer-article
2605 "h" gnus-article-show-summary
2606 "s" gnus-article-show-summary
2607 "\C-c\C-m" gnus-article-mail
2608 "?" gnus-article-describe-briefly
2609 "e" gnus-summary-edit-article
2610 "<" beginning-of-buffer
2612 "\C-c\C-i" gnus-info-find-node
2615 "\C-d" gnus-article-read-summary-keys
2616 "\M-*" gnus-article-read-summary-keys
2617 "\M-#" gnus-article-read-summary-keys
2618 "\M-^" gnus-article-read-summary-keys
2619 "\M-g" gnus-article-read-summary-keys)
2621 (substitute-key-definition
2622 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2624 (defun gnus-article-make-menu-bar ()
2625 (gnus-turn-off-edit-menu 'article)
2626 (unless (boundp 'gnus-article-article-menu)
2628 gnus-article-article-menu gnus-article-mode-map ""
2630 ["Scroll forwards" gnus-article-goto-next-page t]
2631 ["Scroll backwards" gnus-article-goto-prev-page t]
2632 ["Show summary" gnus-article-show-summary t]
2633 ["Fetch Message-ID at point" gnus-article-refer-article t]
2634 ["Mail to address at point" gnus-article-mail t]
2635 ["Send a bug report" gnus-bug t]))
2638 gnus-article-treatment-menu gnus-article-mode-map ""
2640 ["Hide headers" gnus-article-hide-headers t]
2641 ["Hide signature" gnus-article-hide-signature t]
2642 ["Hide citation" gnus-article-hide-citation t]
2643 ["Treat overstrike" gnus-article-treat-overstrike t]
2644 ["Remove carriage return" gnus-article-remove-cr t]
2645 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2646 ["Remove base64" gnus-article-de-base64-unreadable t]
2647 ["Treat html" gnus-article-wash-html t]
2648 ["Decode HZ" gnus-article-decode-HZ t]))
2650 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2652 (when (boundp 'gnus-summary-post-menu)
2653 (define-key gnus-article-mode-map [menu-bar post]
2654 (cons "Post" gnus-summary-post-menu)))
2656 (gnus-run-hooks 'gnus-article-menu-hook)))
2658 (defun gnus-article-mode ()
2659 "Major mode for displaying an article.
2661 All normal editing commands are switched off.
2663 The following commands are available in addition to all summary mode
2665 \\<gnus-article-mode-map>
2666 \\[gnus-article-next-page]\t Scroll the article one page forwards
2667 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2668 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2669 \\[gnus-article-show-summary]\t Display the summary buffer
2670 \\[gnus-article-mail]\t Send a reply to the address near point
2671 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2672 \\[gnus-info-find-node]\t Go to the Gnus info node"
2674 (when (gnus-visual-p 'article-menu 'menu)
2675 (gnus-article-make-menu-bar))
2676 (gnus-simplify-mode-line)
2677 (setq mode-name "Article")
2678 (setq major-mode 'gnus-article-mode)
2679 (make-local-variable 'minor-mode-alist)
2680 (use-local-map gnus-article-mode-map)
2681 (gnus-update-format-specifications nil 'article-mode)
2682 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2683 (make-local-variable 'gnus-page-broken)
2684 (make-local-variable 'gnus-button-marker-list)
2685 (make-local-variable 'gnus-article-current-summary)
2686 (make-local-variable 'gnus-article-mime-handles)
2687 (make-local-variable 'gnus-article-decoded-p)
2688 (make-local-variable 'gnus-article-mime-handle-alist)
2689 (make-local-variable 'gnus-article-wash-types)
2690 (gnus-set-default-directory)
2691 (buffer-disable-undo)
2692 (setq buffer-read-only t)
2693 (set-syntax-table gnus-article-mode-syntax-table)
2694 (mm-enable-multibyte)
2695 (gnus-run-hooks 'gnus-article-mode-hook))
2697 (defun gnus-article-setup-buffer ()
2698 "Initialize the article buffer."
2699 (let* ((name (if gnus-single-article-buffer "*Article*"
2700 (concat "*Article " gnus-newsgroup-name "*")))
2702 (progn (string-match "\\*Article" name)
2703 (concat " *Original Article"
2704 (substring name (match-end 0))))))
2705 (setq gnus-article-buffer name)
2706 (setq gnus-original-article-buffer original)
2707 (setq gnus-article-mime-handle-alist nil)
2708 ;; This might be a variable local to the summary buffer.
2709 (unless gnus-single-article-buffer
2711 (set-buffer gnus-summary-buffer)
2712 (setq gnus-article-buffer name)
2713 (setq gnus-original-article-buffer original)
2714 (gnus-set-global-variables)))
2715 (gnus-article-setup-highlight-words)
2716 ;; Init original article buffer.
2718 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2719 (mm-enable-multibyte)
2720 (setq major-mode 'gnus-original-article-mode)
2721 (make-local-variable 'gnus-original-article))
2722 (if (get-buffer name)
2725 (when gnus-article-mime-handles
2726 (mm-destroy-parts gnus-article-mime-handles)
2727 (setq gnus-article-mime-handles nil))
2728 ;; Set it to nil in article-buffer!
2729 (setq gnus-article-mime-handle-alist nil)
2730 (buffer-disable-undo)
2731 (setq buffer-read-only t)
2732 (unless (eq major-mode 'gnus-article-mode)
2733 (gnus-article-mode))
2736 (set-buffer (gnus-get-buffer-create name))
2738 (make-local-variable 'gnus-summary-buffer)
2739 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2740 (current-buffer)))))
2742 ;; Set article window start at LINE, where LINE is the number of lines
2743 ;; from the head of the article.
2744 (defun gnus-article-set-window-start (&optional line)
2746 (get-buffer-window gnus-article-buffer t)
2748 (set-buffer gnus-article-buffer)
2749 (goto-char (point-min))
2752 (gnus-message 6 "Moved to bookmark")
2753 (search-forward "\n\n" nil t)
2757 (defun gnus-article-prepare (article &optional all-headers header)
2758 "Prepare ARTICLE in article mode buffer.
2759 ARTICLE should either be an article number or a Message-ID.
2760 If ARTICLE is an id, HEADER should be the article headers.
2761 If ALL-HEADERS is non-nil, no headers are hidden."
2763 ;; Make sure we start in a summary buffer.
2764 (unless (eq major-mode 'gnus-summary-mode)
2765 (set-buffer gnus-summary-buffer))
2766 (setq gnus-summary-buffer (current-buffer))
2767 (let* ((gnus-article (if header (mail-header-number header) article))
2768 (summary-buffer (current-buffer))
2769 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2770 (group gnus-newsgroup-name)
2773 (gnus-article-setup-buffer)
2774 (set-buffer gnus-article-buffer)
2775 ;; Deactivate active regions.
2776 (when (and (boundp 'transient-mark-mode)
2777 transient-mark-mode)
2778 (setq mark-active nil))
2779 (if (not (setq result (let ((buffer-read-only nil))
2780 (gnus-request-article-this-buffer
2782 ;; There is no such article.
2784 (when (and (numberp article)
2785 (not (memq article gnus-newsgroup-sparse)))
2786 (setq gnus-article-current
2787 (cons gnus-newsgroup-name article))
2788 (set-buffer gnus-summary-buffer)
2789 (setq gnus-current-article article)
2790 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2792 (gnus-summary-set-agent-mark article)
2793 (message "Message marked for downloading"))
2794 (gnus-summary-mark-article article gnus-canceled-mark)
2795 (unless (memq article gnus-newsgroup-sparse)
2796 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2797 (if (or (eq result 'pseudo)
2798 (eq result 'nneething))
2801 (set-buffer summary-buffer)
2802 (push article gnus-newsgroup-history)
2803 (setq gnus-last-article gnus-current-article
2804 gnus-current-article 0
2805 gnus-current-headers nil
2806 gnus-article-current nil)
2807 (if (eq result 'nneething)
2808 (gnus-configure-windows 'summary)
2809 (gnus-configure-windows 'article))
2810 (gnus-set-global-variables))
2811 (let ((gnus-article-mime-handle-alist-1
2812 gnus-article-mime-handle-alist))
2813 (gnus-set-mode-line 'article)))
2814 ;; The result from the `request' was an actual article -
2815 ;; or at least some text that is now displayed in the
2817 (when (and (numberp article)
2818 (not (eq article gnus-current-article)))
2819 ;; Seems like a new article has been selected.
2820 ;; `gnus-current-article' must be an article number.
2822 (set-buffer summary-buffer)
2823 (push article gnus-newsgroup-history)
2824 (setq gnus-last-article gnus-current-article
2825 gnus-current-article article
2826 gnus-current-headers
2827 (gnus-summary-article-header gnus-current-article)
2828 gnus-article-current
2829 (cons gnus-newsgroup-name gnus-current-article))
2830 (unless (vectorp gnus-current-headers)
2831 (setq gnus-current-headers nil))
2832 (gnus-summary-goto-subject gnus-current-article)
2833 (when (gnus-summary-show-thread)
2834 ;; If the summary buffer really was folded, the
2835 ;; previous goto may not actually have gone to
2836 ;; the right article, but the thread root instead.
2838 (gnus-summary-goto-subject gnus-current-article))
2839 (gnus-run-hooks 'gnus-mark-article-hook)
2840 (gnus-set-mode-line 'summary)
2841 (when (gnus-visual-p 'article-highlight 'highlight)
2842 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2843 ;; Set the global newsgroup variables here.
2844 (gnus-set-global-variables)
2845 (setq gnus-have-all-headers
2846 (or all-headers gnus-show-all-headers))))
2848 (gnus-configure-windows 'article))
2849 (when (or (numberp article)
2851 (gnus-article-prepare-display)
2853 (goto-char (point-min))
2854 (setq gnus-page-broken
2855 (when gnus-break-pages
2856 (gnus-narrow-to-page)
2858 (let ((gnus-article-mime-handle-alist-1
2859 gnus-article-mime-handle-alist))
2860 (gnus-set-mode-line 'article))
2862 (set-window-point (get-buffer-window (current-buffer)) (point))
2863 (gnus-configure-windows 'article)
2867 (defun gnus-article-prepare-display ()
2868 "Make the current buffer look like a nice article."
2869 ;; Hooks for getting information from the article.
2870 ;; This hook must be called before being narrowed.
2871 (let ((gnus-article-buffer (current-buffer))
2873 (unless (eq major-mode 'gnus-article-mode)
2874 (gnus-article-mode))
2875 (setq buffer-read-only nil
2876 gnus-article-wash-types nil)
2877 (gnus-run-hooks 'gnus-tmp-internal-hook)
2878 (when gnus-display-mime-function
2879 (funcall gnus-display-mime-function))
2880 (gnus-run-hooks 'gnus-article-prepare-hook)))
2883 ;;; Gnus MIME viewing functions
2886 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2887 "The following specs can be used:
2889 %T MIME type, along with additional info
2890 %n The `name' parameter
2891 %d The description, if any
2892 %l The length of the encoded part
2893 %p The part identifier number
2894 %e Dots if the part isn't displayed")
2896 (defvar gnus-mime-button-line-format-alist
2897 '((?t gnus-tmp-type ?s)
2898 (?T gnus-tmp-type-long ?s)
2899 (?n gnus-tmp-name ?s)
2900 (?d gnus-tmp-description ?s)
2902 (?l gnus-tmp-length ?d)
2903 (?e gnus-tmp-dots ?s)))
2905 (defvar gnus-mime-button-commands
2906 '((gnus-article-press-button "\r" "Toggle Display")
2907 (gnus-mime-view-part "v" "View Interactively...")
2908 (gnus-mime-view-part-as-type "t" "View As Type...")
2909 (gnus-mime-save-part "o" "Save...")
2910 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2911 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2912 (gnus-mime-internalize-part "E" "View Internally")
2913 (gnus-mime-externalize-part "e" "View Externally")
2914 (gnus-mime-pipe-part "|" "Pipe To Command...")
2915 (gnus-mime-action-on-part "." "Take action on the part")))
2917 (defun gnus-article-mime-part-status ()
2918 (if gnus-article-mime-handle-alist-1
2919 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2922 (defvar gnus-mime-button-map
2923 (let ((map (make-sparse-keymap)))
2924 (set-keymap-parent map gnus-article-mode-map)
2925 (define-key map gnus-mouse-2 'gnus-article-push-button)
2926 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2927 (dolist (c gnus-mime-button-commands)
2928 (define-key map (cadr c) (car c)))
2931 (defun gnus-mime-button-menu (event)
2932 "Construct a context-sensitive menu of MIME commands."
2935 (let ((pos (event-start event)))
2936 (set-buffer (window-buffer (posn-window pos)))
2937 (goto-char (posn-point pos))
2938 (gnus-article-check-buffer)
2939 (let ((response (x-popup-menu
2941 ("" ,@(mapcar (lambda (c)
2942 (cons (caddr c) (car c)))
2943 gnus-mime-button-commands))))))
2945 (call-interactively response))))))
2947 (defun gnus-mime-view-all-parts (&optional handles)
2948 "View all the MIME parts."
2950 (save-current-buffer
2951 (set-buffer gnus-article-buffer)
2952 (let ((handles (or handles gnus-article-mime-handles))
2953 (mail-parse-charset gnus-newsgroup-charset)
2954 (mail-parse-ignored-charsets
2955 (save-excursion (set-buffer gnus-summary-buffer)
2956 gnus-newsgroup-ignored-charsets)))
2957 (if (stringp (car handles))
2958 (gnus-mime-view-all-parts (cdr handles))
2959 (mapcar 'mm-display-part handles)))))
2961 (defun gnus-mime-save-part ()
2962 "Save the MIME part under point."
2964 (gnus-article-check-buffer)
2965 (let ((data (get-text-property (point) 'gnus-data)))
2966 (mm-save-part data)))
2968 (defun gnus-mime-pipe-part ()
2969 "Pipe the MIME part under point to a process."
2971 (gnus-article-check-buffer)
2972 (let ((data (get-text-property (point) 'gnus-data)))
2973 (mm-pipe-part data)))
2975 (defun gnus-mime-view-part ()
2976 "Interactively choose a viewing method for the MIME part under point."
2978 (gnus-article-check-buffer)
2979 (let ((data (get-text-property (point) 'gnus-data)))
2980 (mm-interactively-view-part data)))
2982 (defun gnus-mime-view-part-as-type-internal ()
2983 (gnus-article-check-buffer)
2984 (let* ((name (mail-content-type-get
2985 (mm-handle-type (get-text-property (point) 'gnus-data))
2987 (def-type (and name (mm-default-file-encoding name))))
2988 (and def-type (cons def-type 0))))
2990 (defun gnus-mime-view-part-as-type (mime-type)
2991 "Choose a MIME media type, and view the part as such."
2993 (list (completing-read
2994 "View as MIME type: "
2995 (mapcar #'list (mailcap-mime-types))
2997 (gnus-mime-view-part-as-type-internal))))
2998 (gnus-article-check-buffer)
2999 (let ((handle (get-text-property (point) 'gnus-data)))
3000 (gnus-mm-display-part
3001 (mm-make-handle (mm-handle-buffer handle)
3002 (cons mime-type (cdr (mm-handle-type handle)))
3003 (mm-handle-encoding handle)
3004 (mm-handle-undisplayer handle)
3005 (mm-handle-disposition handle)
3006 (mm-handle-description handle)
3007 (mm-handle-cache handle)
3008 (mm-handle-id handle)))))
3010 (defun gnus-mime-copy-part (&optional handle)
3011 "Put the the MIME part under point into a new buffer."
3013 (gnus-article-check-buffer)
3014 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3015 (contents (mm-get-part handle))|
3016 (base (file-name-nondirectory
3018 (mail-content-type-get (mm-handle-type handle) 'name)
3019 (mail-content-type-get (mm-handle-type handle)
3022 (buffer (generate-new-buffer base)))
3023 (switch-to-buffer buffer)
3025 ;; We do it this way to make `normal-mode' set the appropriate mode.
3028 (setq buffer-file-name (expand-file-name base))
3030 (setq buffer-file-name nil))
3031 (goto-char (point-min))))
3033 (defun gnus-mime-inline-part (&optional handle arg)
3034 "Insert the MIME part under point into the current buffer."
3035 (interactive (list nil current-prefix-arg))
3036 (gnus-article-check-buffer)
3037 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3041 (if (mm-handle-undisplayer handle)
3042 (mm-remove-part handle)
3043 (setq contents (mm-get-part handle))
3046 (setq charset (or (mail-content-type-get
3047 (mm-handle-type handle) 'charset)
3048 gnus-newsgroup-charset)))
3052 gnus-summary-show-article-charset-alist))
3053 (read-coding-system "Charset: ")))))
3055 (mm-insert-inline handle
3057 (mm-decode-coding-string
3058 contents (mm-charset-to-coding-system charset))
3062 (defun gnus-mime-externalize-part (&optional handle)
3063 "View the MIME part under point with an external viewer."
3065 (gnus-article-check-buffer)
3066 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3067 (mm-user-display-methods nil)
3068 (mm-inlined-types nil)
3069 (mail-parse-charset gnus-newsgroup-charset)
3070 (mail-parse-ignored-charsets
3071 (save-excursion (set-buffer gnus-summary-buffer)
3072 gnus-newsgroup-ignored-charsets)))
3073 (if (mm-handle-undisplayer handle)
3074 (mm-remove-part handle)
3075 (mm-display-part handle))))
3077 (defun gnus-mime-internalize-part (&optional handle)
3078 "View the MIME part under point with an internal viewer.
3079 In no internal viewer is available, use an external viewer."
3081 (gnus-article-check-buffer)
3082 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3083 (mm-inlined-types '(".*"))
3084 (mm-inline-large-images t)
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-action-on-part (&optional action)
3094 "Do something with the MIME attachment at \(point\)."
3096 (list (completing-read "Action: " gnus-mime-action-alist)))
3097 (gnus-article-check-buffer)
3098 (let ((action-pair (assoc action gnus-mime-action-alist)))
3100 (funcall (cdr action-pair)))))
3103 (defun gnus-article-part-wrapper (n function)
3104 (save-current-buffer
3105 (set-buffer gnus-article-buffer)
3106 (when (> n (length gnus-article-mime-handle-alist))
3107 (error "No such part"))
3108 (gnus-article-goto-part n)
3109 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3110 (funcall function handle))))
3112 (defun gnus-article-pipe-part (n)
3113 "Pipe MIME part N, which is the numerical prefix."
3115 (gnus-article-part-wrapper n 'mm-pipe-part))
3117 (defun gnus-article-save-part (n)
3118 "Save MIME part N, which is the numerical prefix."
3120 (gnus-article-part-wrapper n 'mm-save-part))
3122 (defun gnus-article-interactively-view-part (n)
3123 "View MIME part N interactively, which is the numerical prefix."
3125 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3127 (defun gnus-article-copy-part (n)
3128 "Copy MIME part N, which is the numerical prefix."
3130 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3132 (defun gnus-article-externalize-part (n)
3133 "View MIME part N externally, which is the numerical prefix."
3135 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3137 (defun gnus-article-inline-part (n)
3138 "Inline MIME part N, which is the numerical prefix."
3140 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3142 (defun gnus-article-mime-match-handle-first (condition)
3144 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3145 (while (setq ihandle (pop alist))
3147 ((functionp condition)
3148 (funcall condition (cdr ihandle)))
3149 ((eq condition 'undisplayed)
3150 (not (or (mm-handle-undisplayer (cdr ihandle))
3151 (equal (mm-handle-media-type (cdr ihandle))
3152 "multipart/alternative"))))
3153 ((eq condition 'undisplayed-alternative)
3154 (not (mm-handle-undisplayer (cdr ihandle))))
3156 (gnus-article-goto-part (car ihandle))
3157 (or (not n) (< (car ihandle) n)))
3158 (setq n (car ihandle))))
3162 (defun gnus-article-view-part (&optional n)
3163 "View MIME part N, which is the numerical prefix."
3165 (save-current-buffer
3166 (set-buffer gnus-article-buffer)
3167 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3168 gnus-article-mime-match-handle-function)))
3169 (when (> n (length gnus-article-mime-handle-alist))
3170 (error "No such part"))
3171 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3172 (when (gnus-article-goto-part n)
3173 (if (equal (car handle) "multipart/alternative")
3174 (gnus-article-press-button)
3175 (when (eq (gnus-mm-display-part handle) 'internal)
3176 (gnus-set-window-start)))))))
3178 (defun gnus-mm-display-part (handle)
3179 "Display HANDLE and fix MIME button."
3180 (let ((id (get-text-property (point) 'gnus-part))
3185 (let ((window (selected-window))
3186 (mail-parse-charset gnus-newsgroup-charset)
3187 (mail-parse-ignored-charsets
3188 (save-excursion (set-buffer gnus-summary-buffer)
3189 gnus-newsgroup-ignored-charsets)))
3192 (let ((win (get-buffer-window (current-buffer) t))
3195 (select-window win))
3198 (if (mm-handle-displayed-p handle)
3199 ;; This will remove the part.
3200 (mm-display-part handle)
3202 (narrow-to-region (point) (1+ (point)))
3203 (mm-display-part handle)
3204 ;; We narrow to the part itself and
3205 ;; then call the treatment functions.
3206 (goto-char (point-min))
3208 (narrow-to-region (point) (point-max))
3211 (1- (length gnus-article-mime-handles))
3212 (mm-handle-media-type handle)))))
3213 (select-window window))))
3215 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3216 (gnus-insert-mime-button
3217 handle id (list (mm-handle-displayed-p handle)))
3218 (goto-char point))))
3220 (defun gnus-article-goto-part (n)
3221 "Go to MIME part N."
3222 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3224 (goto-char point))))
3226 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3227 (let ((gnus-tmp-name
3228 (or (mail-content-type-get (mm-handle-type handle)
3230 (mail-content-type-get (mm-handle-disposition handle)
3233 (gnus-tmp-type (mm-handle-media-type handle))
3234 (gnus-tmp-description
3235 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3238 (if (if displayed (car displayed)
3239 (mm-handle-displayed-p handle))
3241 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3243 gnus-tmp-type-long b e)
3244 (when (string-match ".*/" gnus-tmp-name)
3245 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3246 (setq gnus-tmp-type-long (concat gnus-tmp-type
3247 (and (not (equal gnus-tmp-name ""))
3248 (concat "; " gnus-tmp-name))))
3249 (or (equal gnus-tmp-description "")
3250 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3255 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3256 `(local-map ,gnus-mime-button-map
3257 keymap ,gnus-mime-button-map
3258 gnus-callback gnus-mm-display-part
3259 gnus-part ,gnus-tmp-id
3260 article-type annotation
3263 (widget-convert-button
3266 :action 'gnus-widget-press-button
3267 :button-keymap gnus-mime-button-map
3269 (lambda (widget/window &optional overlay pos)
3270 ;; Needed to properly clear the message due to a bug in
3271 ;; wid-edit (XEmacs only).
3272 (if (boundp 'help-echo-owns-message)
3273 (setq help-echo-owns-message t))
3275 "%S: %s the MIME part; %S: more options"
3276 (aref gnus-mouse-2 0)
3277 ;; XEmacs will get a single widget arg; Emacs 21 will get
3278 ;; window, overlay, position.
3279 (if (mm-handle-displayed-p
3281 (with-current-buffer (gnus-overlay-buffer overlay)
3282 (widget-get (widget-at (gnus-overlay-start overlay))
3284 (widget-get widget/window :mime-handle)))
3286 (aref gnus-down-mouse-3 0))))))
3288 (defun gnus-widget-press-button (elems el)
3289 (goto-char (widget-get elems :from))
3290 (gnus-article-press-button))
3292 (defvar gnus-displaying-mime nil)
3294 (defun gnus-display-mime (&optional ihandles)
3295 "Display the MIME parts."
3297 (save-selected-window
3298 (let ((window (get-buffer-window gnus-article-buffer))
3301 (select-window window)
3302 ;; We have to do this since selecting the window
3303 ;; may change the point. So we set the window point.
3304 (set-window-point window point)))
3305 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3306 buffer-read-only handle name type b e display)
3307 (when (and (not ihandles)
3308 (not gnus-displaying-mime))
3309 ;; Top-level call; we clean up.
3310 (when gnus-article-mime-handles
3311 (mm-destroy-parts gnus-article-mime-handles)
3312 (setq gnus-article-mime-handle-alist nil));; A trick.
3313 (setq gnus-article-mime-handles handles)
3314 ;; We allow users to glean info from the handles.
3315 (when gnus-article-mime-part-function
3316 (gnus-mime-part-function handles)))
3318 (or (not (stringp (car handles)))
3321 (when (and (not ihandles)
3322 (not gnus-displaying-mime))
3323 ;; Clean up for mime parts.
3325 (delete-region (point) (point-max)))
3326 (let ((gnus-displaying-mime t))
3327 (gnus-mime-display-part handles)))
3330 (narrow-to-region (point) (point-max))
3331 (gnus-treat-article nil 1 1)
3334 ;; Highlight the headers.
3338 (narrow-to-region (point-min) (point))
3339 (gnus-treat-article 'head))))))))
3341 (defvar gnus-mime-display-multipart-as-mixed nil)
3343 (defun gnus-mime-display-part (handle)
3346 ((not (stringp (car handle)))
3347 (gnus-mime-display-single handle))
3348 ;; User-defined multipart
3349 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3350 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3352 ;; multipart/alternative
3353 ((and (equal (car handle) "multipart/alternative")
3354 (not gnus-mime-display-multipart-as-mixed))
3355 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3356 (push (cons id handle) gnus-article-mime-handle-alist)
3357 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3358 ;; multipart/related
3359 ((and (equal (car handle) "multipart/related")
3360 (not gnus-mime-display-multipart-as-mixed))
3361 ;;;!!!We should find the start part, but we just default
3362 ;;;!!!to the first part.
3363 (gnus-mime-display-part (cadr handle)))
3364 ;; Other multiparts are handled like multipart/mixed.
3366 (gnus-mime-display-mixed (cdr handle)))))
3368 (defun gnus-mime-part-function (handles)
3369 (if (stringp (car handles))
3370 (mapcar 'gnus-mime-part-function (cdr handles))
3371 (funcall gnus-article-mime-part-function handles)))
3373 (defun gnus-mime-display-mixed (handles)
3374 (mapcar 'gnus-mime-display-part handles))
3376 (defun gnus-mime-display-single (handle)
3377 (let ((type (mm-handle-media-type handle))
3378 (ignored gnus-ignored-mime-types)
3385 (when (string-match (pop ignored) type)
3386 (throw 'ignored nil)))
3387 (if (and (setq not-attachment
3388 (and (not (mm-inline-override-p handle))
3389 (or (not (mm-handle-disposition handle))
3390 (equal (car (mm-handle-disposition handle))
3392 (mm-attachment-override-p handle))))
3393 (mm-automatic-display-p handle)
3394 (or (mm-inlined-p handle)
3395 (mm-automatic-external-display-p type)))
3397 (when (equal (mm-handle-media-supertype handle) "text")
3399 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3400 (push (cons id handle) gnus-article-mime-handle-alist)
3401 (when (or (not display)
3402 (not (gnus-unbuttonized-mime-type-p type)))
3403 ;(gnus-article-insert-newline)
3404 (gnus-insert-mime-button
3405 handle id (list (or display (and not-attachment text))))
3406 (gnus-article-insert-newline)
3407 ;(gnus-article-insert-newline)
3409 (let ((beg (point)))
3415 (let ((mail-parse-charset gnus-newsgroup-charset)
3416 (mail-parse-ignored-charsets
3417 (save-excursion (condition-case ()
3418 (set-buffer gnus-summary-buffer)
3420 gnus-newsgroup-ignored-charsets)))
3421 (mm-display-part handle t))
3422 (goto-char (point-max)))
3423 ((and text not-attachment)
3427 (gnus-article-insert-newline)
3428 (mm-insert-inline handle (mm-get-part handle))
3429 (goto-char (point-max))))
3433 (narrow-to-region beg (point))
3435 nil (length gnus-article-mime-handle-alist)
3436 (1- (length gnus-article-mime-handles))
3437 (mm-handle-media-type handle)))))))))
3439 (defun gnus-unbuttonized-mime-type-p (type)
3440 "Say whether TYPE is to be unbuttonized."
3441 (unless gnus-inhibit-mime-unbuttonizing
3443 (let ((types gnus-unbuttonized-mime-types))
3445 (when (string-match (pop types) type)
3446 (throw 'found t)))))))
3448 (defun gnus-article-insert-newline ()
3449 "Insert a newline, but mark it as undeletable."
3450 (gnus-put-text-property
3451 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3453 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3454 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3457 handle buffer-read-only from props begend not-pref)
3458 (save-window-excursion
3461 (narrow-to-region (car ibegend)
3464 (goto-char (car ibegend))
3467 (delete-region (point-min) (point-max))
3468 (mm-remove-parts handles))
3469 (setq begend (list (point-marker)))
3471 (unless (setq not-pref (cadr (member preferred ihandles)))
3472 (setq not-pref (car ihandles)))
3474 (not (gnus-unbuttonized-mime-type-p
3475 "multipart/alternative")))
3476 (gnus-add-text-properties
3479 (insert (format "%d. " id))
3483 (unless ,(not ibegend)
3484 (setq gnus-article-mime-handle-alist
3485 ',gnus-article-mime-handle-alist))
3486 (gnus-mime-display-alternative
3487 ',ihandles ',not-pref ',begend ,id))
3488 local-map ,gnus-mime-button-map
3489 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3490 face ,gnus-article-button-face
3491 keymap ,gnus-mime-button-map
3494 (widget-convert-button 'link from (point)
3495 :action 'gnus-widget-press-button
3496 :button-keymap gnus-widget-button-keymap)
3498 (while (setq handle (pop handles))
3499 (gnus-add-text-properties
3502 (insert (format "(%c) %-18s"
3503 (if (equal handle preferred) ?* ? )
3504 (mm-handle-media-type handle)))
3508 (unless ,(not ibegend)
3509 (setq gnus-article-mime-handle-alist
3510 ',gnus-article-mime-handle-alist))
3511 (gnus-mime-display-alternative
3512 ',ihandles ',handle ',begend ,id))
3513 local-map ,gnus-mime-button-map
3514 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3515 face ,gnus-article-button-face
3516 keymap ,gnus-mime-button-map
3519 (widget-convert-button 'link from (point)
3520 :action 'gnus-widget-press-button
3521 :button-keymap gnus-widget-button-keymap)
3525 (if (stringp (car preferred))
3526 (gnus-display-mime preferred)
3527 (let ((mail-parse-charset gnus-newsgroup-charset)
3528 (mail-parse-ignored-charsets
3529 (save-excursion (set-buffer gnus-summary-buffer)
3530 gnus-newsgroup-ignored-charsets)))
3531 (mm-display-part preferred)
3535 (narrow-to-region (car begend) (point-max))
3537 nil (length gnus-article-mime-handle-alist)
3538 (1- (length gnus-article-mime-handles))
3539 (mm-handle-media-type handle))))))
3540 (goto-char (point-max))
3541 (setcdr begend (point-marker)))))
3543 (goto-char point))))
3545 (defun gnus-article-wash-status ()
3546 "Return a string which display status of article washing."
3548 (set-buffer gnus-article-buffer)
3549 (let ((cite (memq 'cite gnus-article-wash-types))
3550 (headers (memq 'headers gnus-article-wash-types))
3551 (boring (memq 'boring-headers gnus-article-wash-types))
3552 (pgp (memq 'pgp gnus-article-wash-types))
3553 (pem (memq 'pem gnus-article-wash-types))
3554 (signature (memq 'signature gnus-article-wash-types))
3555 (overstrike (memq 'overstrike gnus-article-wash-types))
3556 (emphasis (memq 'emphasis gnus-article-wash-types)))
3557 (format "%c%c%c%c%c%c"
3559 (if (or headers boring) ?h ? )
3560 (if (or pgp pem) ?p ? )
3561 (if signature ?s ? )
3562 (if overstrike ?o ? )
3563 (if emphasis ?e ? )))))
3565 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3567 (defun gnus-article-maybe-hide-headers ()
3568 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3569 Provided for backwards compatibility."
3570 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3571 (not (save-excursion (set-buffer gnus-summary-buffer)
3572 gnus-have-all-headers)))
3573 (not gnus-inhibit-hiding))
3574 (gnus-article-hide-headers)))
3578 (defun gnus-output-to-file (file-name)
3579 "Append the current article to a file named FILE-NAME."
3580 (let ((artbuf (current-buffer)))
3582 (insert-buffer-substring artbuf)
3583 ;; Append newline at end of the buffer as separator, and then
3585 (goto-char (point-max))
3587 (mm-append-to-file (point-min) (point-max) file-name)
3590 (defun gnus-narrow-to-page (&optional arg)
3591 "Narrow the article buffer to a page.
3592 If given a numerical ARG, move forward ARG pages."
3594 (setq arg (if arg (prefix-numeric-value arg) 0))
3596 (set-buffer gnus-article-buffer)
3597 (goto-char (point-min))
3599 ;; Remove any old next/prev buttons.
3600 (when (gnus-visual-p 'page-marker)
3601 (let ((buffer-read-only nil))
3602 (gnus-remove-text-with-property 'gnus-prev)
3603 (gnus-remove-text-with-property 'gnus-next)))
3606 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3608 (re-search-forward page-delimiter nil 'move arg)))
3609 (goto-char (match-end 0)))
3612 (if (re-search-forward page-delimiter nil 'move)
3615 (when (and (gnus-visual-p 'page-marker)
3616 (not (= (point-min) 1)))
3618 (goto-char (point-min))
3619 (gnus-insert-prev-page-button)))
3620 (when (and (gnus-visual-p 'page-marker)
3621 (< (+ (point-max) 2) (buffer-size)))
3623 (goto-char (point-max))
3624 (gnus-insert-next-page-button)))))
3626 ;; Article mode commands
3628 (defun gnus-article-goto-next-page ()
3629 "Show the next page of the article."
3631 (when (gnus-article-next-page)
3632 (goto-char (point-min))
3633 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3635 (defun gnus-article-goto-prev-page ()
3636 "Show the next page of the article."
3638 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3639 (gnus-article-prev-page nil)))
3641 (defun gnus-article-next-page (&optional lines)
3642 "Show the next page of the current article.
3643 If end of article, return non-nil. Otherwise return nil.
3644 Argument LINES specifies lines to be scrolled up."
3646 (move-to-window-line -1)
3649 (and (pos-visible-in-window-p) ;Not continuation line.
3651 ;; Nothing in this page.
3652 (if (or (not gnus-page-broken)
3655 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3657 (gnus-narrow-to-page 1) ;Go to next page.
3659 ;; More in this page.
3660 (let ((scroll-in-place nil))
3664 ;; Long lines may cause an end-of-buffer error.
3665 (goto-char (point-max)))))
3666 (move-to-window-line 0)
3669 (defun gnus-article-prev-page (&optional lines)
3670 "Show previous page of current article.
3671 Argument LINES specifies lines to be scrolled down."
3673 (move-to-window-line 0)
3674 (if (and gnus-page-broken
3676 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3678 (gnus-narrow-to-page -1) ;Go to previous page.
3679 (goto-char (point-max))
3681 (let ((scroll-in-place nil))
3685 (beginning-of-buffer
3686 (goto-char (point-min))))
3687 (move-to-window-line 0)))))
3689 (defun gnus-article-refer-article ()
3690 "Read article specified by message-id around point."
3692 (let ((point (point)))
3693 (search-forward ">" nil t) ;Move point to end of "<....>".
3694 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3695 (let ((message-id (match-string 1)))
3697 (set-buffer gnus-summary-buffer)
3698 (gnus-summary-refer-article message-id))
3700 (error "No references around point"))))
3702 (defun gnus-article-show-summary ()
3703 "Reconfigure windows to show summary buffer."
3705 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3706 (error "There is no summary buffer for this article buffer")
3707 (gnus-article-set-globals)
3708 (gnus-configure-windows 'article)
3709 (gnus-summary-goto-subject gnus-current-article)
3710 (gnus-summary-position-point)))
3712 (defun gnus-article-describe-briefly ()
3713 "Describe article mode commands briefly."
3715 (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")))
3717 (defun gnus-article-summary-command ()
3718 "Execute the last keystroke in the summary buffer."
3720 (let ((obuf (current-buffer))
3721 (owin (current-window-configuration))
3723 (switch-to-buffer gnus-article-current-summary 'norecord)
3724 (setq func (lookup-key (current-local-map) (this-command-keys)))
3725 (call-interactively func)
3727 (set-window-configuration owin)
3728 (set-window-point (get-buffer-window (current-buffer)) (point))))
3730 (defun gnus-article-summary-command-nosave ()
3731 "Execute the last keystroke in the summary buffer."
3734 (pop-to-buffer gnus-article-current-summary 'norecord)
3735 (setq func (lookup-key (current-local-map) (this-command-keys)))
3736 (call-interactively func)))
3738 (defun gnus-article-check-buffer ()
3739 "Beep if not in an article buffer."
3740 (unless (equal major-mode 'gnus-article-mode)
3741 (error "Command invoked outside of a Gnus article buffer")))
3743 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3744 "Read a summary buffer key sequence and execute it from the article buffer."
3746 (gnus-article-check-buffer)
3748 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3749 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3750 "=" "^" "\M-^" "|"))
3756 '("n" "Gn" "p" "Gp"))
3759 (set-buffer gnus-article-current-summary)
3760 (let (gnus-pick-mode)
3761 (push (or key last-command-event) unread-command-events)
3762 (setq keys (if (featurep 'xemacs)
3763 (events-to-keys (read-key-sequence nil))
3764 (read-key-sequence nil)))))
3768 (if (or (member keys nosaves)
3769 (member keys nosave-but-article)
3770 (member keys nosave-in-article))
3772 (save-window-excursion
3773 (pop-to-buffer gnus-article-current-summary 'norecord)
3774 ;; We disable the pick minor mode commands.
3775 (let (gnus-pick-mode)
3776 (setq func (lookup-key (current-local-map) keys))))
3780 (unless (member keys nosave-in-article)
3781 (set-buffer gnus-article-current-summary))
3782 (call-interactively func)
3783 (setq new-sum-point (point)))
3784 (when (member keys nosave-but-article)
3785 (pop-to-buffer gnus-article-buffer 'norecord)))
3786 ;; These commands should restore window configuration.
3787 (let ((obuf (current-buffer))
3788 (owin (current-window-configuration))
3790 (summary gnus-article-current-summary)
3791 func in-buffer selected)
3792 (if not-restore-window
3793 (pop-to-buffer summary 'norecord)
3794 (switch-to-buffer summary 'norecord))
3795 (setq in-buffer (current-buffer))
3796 ;; We disable the pick minor mode commands.
3797 (if (setq func (let (gnus-pick-mode)
3798 (lookup-key (current-local-map) keys)))
3800 (call-interactively func)
3801 (setq new-sum-point (point)))
3803 (when (eq in-buffer (current-buffer))
3804 (setq selected (gnus-summary-select-article))
3806 (unless not-restore-window
3807 (set-window-configuration owin))
3808 (when (eq selected 'old)
3810 (set-window-start (get-buffer-window (current-buffer))
3812 (set-window-point (get-buffer-window (current-buffer))
3814 (let ((win (get-buffer-window gnus-article-current-summary)))
3816 (set-window-point win new-sum-point))))))))
3818 (defun gnus-article-hide (&optional arg force)
3819 "Hide all the gruft in the current article.
3820 This means that PGP stuff, signatures, cited text and (some)
3821 headers will be hidden.
3822 If given a prefix, show the hidden text instead."
3823 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3824 (gnus-article-hide-headers arg)
3825 (gnus-article-hide-list-identifiers arg)
3826 (gnus-article-hide-pgp arg)
3827 (gnus-article-hide-citation-maybe arg force)
3828 (gnus-article-hide-signature arg))
3830 (defun gnus-article-maybe-highlight ()
3831 "Do some article highlighting if article highlighting is requested."
3832 (when (gnus-visual-p 'article-highlight 'highlight)
3833 (gnus-article-highlight-some)))
3835 (defun gnus-check-group-server ()
3836 ;; Make sure the connection to the server is alive.
3837 (unless (gnus-server-opened
3838 (gnus-find-method-for-group gnus-newsgroup-name))
3839 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3840 (gnus-request-group gnus-newsgroup-name t)))
3842 (defun gnus-request-article-this-buffer (article group)
3843 "Get an article and insert it into this buffer."
3844 (let (do-update-line sparse-header)
3848 (gnus-kill-all-overlays)
3849 (setq group (or group gnus-newsgroup-name))
3851 ;; Using `gnus-request-article' directly will insert the article into
3852 ;; `nntp-server-buffer' - so we'll save some time by not having to
3853 ;; copy it from the server buffer into the article buffer.
3855 ;; We only request an article by message-id when we do not have the
3856 ;; headers for it, so we'll have to get those.
3857 (when (stringp article)
3858 (gnus-read-header article))
3860 ;; If the article number is negative, that means that this article
3861 ;; doesn't belong in this newsgroup (possibly), so we find its
3862 ;; message-id and request it by id instead of number.
3863 (when (and (numberp article)
3865 (get-buffer gnus-summary-buffer)
3866 (gnus-buffer-exists-p gnus-summary-buffer))
3868 (set-buffer gnus-summary-buffer)
3869 (let ((header (gnus-summary-article-header article)))
3872 ((memq article gnus-newsgroup-sparse)
3873 ;; This is a sparse gap article.
3874 (setq do-update-line article)
3875 (setq article (mail-header-id header))
3876 (setq sparse-header (gnus-read-header article))
3877 (setq gnus-newsgroup-sparse
3878 (delq article gnus-newsgroup-sparse)))
3880 ;; It's a real article.
3881 (setq article (mail-header-id header)))
3883 ;; It is an extracted pseudo-article.
3884 (setq article 'pseudo)
3885 (gnus-request-pseudo-article header))))
3887 (let ((method (gnus-find-method-for-group
3888 gnus-newsgroup-name)))
3889 (when (and (eq (car method) 'nneething)
3891 (let ((dir (expand-file-name
3892 (mail-header-subject header)
3893 (file-name-as-directory
3894 (or (cadr (assq 'nneething-address method))
3896 (when (file-directory-p dir)
3897 (setq article 'nneething)
3898 (gnus-group-enter-directory dir))))))))
3901 ;; Refuse to select canceled articles.
3902 ((and (numberp article)
3904 (get-buffer gnus-summary-buffer)
3905 (gnus-buffer-exists-p gnus-summary-buffer)
3906 (eq (cdr (save-excursion
3907 (set-buffer gnus-summary-buffer)
3908 (assq article gnus-newsgroup-reads)))
3909 gnus-canceled-mark))
3911 ;; We first check `gnus-original-article-buffer'.
3912 ((and (get-buffer gnus-original-article-buffer)
3915 (set-buffer gnus-original-article-buffer)
3916 (and (equal (car gnus-original-article) group)
3917 (eq (cdr gnus-original-article) article))))
3918 (insert-buffer-substring gnus-original-article-buffer)
3920 ;; Check the backlog.
3921 ((and gnus-keep-backlog
3922 (gnus-backlog-request-article group article (current-buffer)))
3924 ;; Check asynchronous pre-fetch.
3925 ((gnus-async-request-fetched-article group article (current-buffer))
3926 (gnus-async-prefetch-next group article gnus-summary-buffer)
3927 (when (and (numberp article) gnus-keep-backlog)
3928 (gnus-backlog-enter-article group article (current-buffer)))
3931 ((and gnus-use-cache
3933 (gnus-cache-request-article article group))
3935 ;; Get the article and put into the article buffer.
3936 ((or (stringp article)
3938 (let ((gnus-override-method gnus-override-method)
3939 (methods (and (stringp article)
3940 gnus-refer-article-method))
3942 (buffer-read-only nil))
3947 (when (and (null gnus-override-method)
3949 (setq gnus-override-method (pop methods)))
3951 (when (eq gnus-override-method 'current)
3952 (setq gnus-override-method gnus-current-select-method))
3954 (gnus-kill-all-overlays)
3955 (let ((gnus-newsgroup-name group))
3956 (gnus-check-group-server))
3957 (when (gnus-request-article article group (current-buffer))
3958 (when (numberp article)
3959 (gnus-async-prefetch-next group article
3960 gnus-summary-buffer)
3961 (when gnus-keep-backlog
3962 (gnus-backlog-enter-article
3963 group article (current-buffer))))
3964 (setq result 'article))
3967 (setq gnus-override-method (pop methods))
3968 (setq result 'done))))
3969 (and (eq result 'article) 'article)))
3973 ;; Associate this article with the current summary buffer.
3974 (setq gnus-article-current-summary gnus-summary-buffer)
3976 ;; Take the article from the original article buffer
3977 ;; and place it in the buffer it's supposed to be in.
3978 (when (and (get-buffer gnus-article-buffer)
3979 (equal (buffer-name (current-buffer))
3980 (buffer-name (get-buffer gnus-article-buffer))))
3982 (if (get-buffer gnus-original-article-buffer)
3983 (set-buffer gnus-original-article-buffer)
3984 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3985 (buffer-disable-undo)
3986 (setq major-mode 'gnus-original-article-mode)
3987 (setq buffer-read-only t))
3988 (let (buffer-read-only)
3990 (insert-buffer-substring gnus-article-buffer))
3991 (setq gnus-original-article (cons group article)))
3994 (run-hooks 'gnus-article-decode-hook)
3995 ;; Mark article as decoded or not.
3996 (setq gnus-article-decoded-p gnus-article-decode-hook))
3998 ;; Update sparse articles.
3999 (when (and do-update-line
4000 (or (numberp article)
4002 (let ((buf (current-buffer)))
4003 (set-buffer gnus-summary-buffer)
4004 (gnus-summary-update-article do-update-line sparse-header)
4005 (gnus-summary-goto-subject do-update-line nil t)
4006 (set-window-point (get-buffer-window (current-buffer) t)
4008 (set-buffer buf))))))
4014 (defcustom gnus-article-edit-mode-hook nil
4015 "Hook run in article edit mode buffers."
4016 :group 'gnus-article-various
4019 (defvar gnus-article-edit-done-function nil)
4021 (defvar gnus-article-edit-mode-map nil)
4023 ;; Should we be using derived.el for this?
4024 (unless gnus-article-edit-mode-map
4025 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4026 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4028 (gnus-define-keys gnus-article-edit-mode-map
4029 "\C-c\C-c" gnus-article-edit-done
4030 "\C-c\C-k" gnus-article-edit-exit)
4032 (gnus-define-keys (gnus-article-edit-wash-map
4033 "\C-c\C-w" gnus-article-edit-mode-map)
4034 "f" gnus-article-edit-full-stops))
4036 (defun gnus-article-edit-mode ()
4037 "Major mode for editing articles.
4038 This is an extended text-mode.
4040 \\{gnus-article-edit-mode-map}"
4042 (setq major-mode 'gnus-article-edit-mode)
4043 (setq mode-name "Article Edit")
4044 (use-local-map gnus-article-edit-mode-map)
4045 (make-local-variable 'gnus-article-edit-done-function)
4046 (make-local-variable 'gnus-prev-winconf)
4047 (setq buffer-read-only nil)
4048 (buffer-enable-undo)
4050 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4052 (defun gnus-article-edit (&optional force)
4053 "Edit the current article.
4054 This will have permanent effect only in mail groups.
4055 If FORCE is non-nil, allow editing of articles even in read-only
4058 (when (and (not force)
4059 (gnus-group-read-only-p))
4060 (error "The current newsgroup does not support article editing"))
4061 (gnus-article-date-original)
4062 (gnus-article-edit-article
4064 `(lambda (no-highlight)
4066 (gnus-summary-edit-article-done
4067 ,(or (mail-header-references gnus-current-headers) "")
4068 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4070 (defun gnus-article-edit-article (start-func exit-func)
4071 "Start editing the contents of the current article buffer."
4072 (let ((winconf (current-window-configuration)))
4073 (set-buffer gnus-article-buffer)
4074 (gnus-article-edit-mode)
4075 (funcall start-func)
4076 (gnus-configure-windows 'edit-article)
4077 (setq gnus-article-edit-done-function exit-func)
4078 (setq gnus-prev-winconf winconf)
4079 (gnus-message 6 "C-c C-c to end edits")))
4081 (defun gnus-article-edit-done (&optional arg)
4082 "Update the article edits and exit."
4087 (when (article-goto-body)
4088 (let ((lines (count-lines (point) (point-max)))
4089 (length (- (point-max) (point)))
4090 (case-fold-search t)
4091 (body (copy-marker (point))))
4092 (goto-char (point-min))
4093 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4094 (delete-region (match-beginning 1) (match-end 1))
4095 (insert (number-to-string length)))
4096 (goto-char (point-min))
4097 (when (re-search-forward
4098 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4099 (delete-region (match-beginning 1) (match-end 1))
4100 (insert (number-to-string length)))
4101 (goto-char (point-min))
4102 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4103 (delete-region (match-beginning 1) (match-end 1))
4104 (insert (number-to-string lines)))))))
4105 (let ((func gnus-article-edit-done-function)
4106 (buf (current-buffer))
4107 (start (window-start)))
4108 (gnus-article-edit-exit)
4111 (let ((buffer-read-only nil))
4113 ;; The cache and backlog have to be flushed somewhat.
4114 (when gnus-keep-backlog
4115 (gnus-backlog-remove-article
4116 (car gnus-article-current) (cdr gnus-article-current)))
4117 ;; Flush original article as well.
4119 (when (get-buffer gnus-original-article-buffer)
4120 (set-buffer gnus-original-article-buffer)
4121 (setq gnus-original-article nil)))
4122 (when gnus-use-cache
4123 (gnus-cache-update-article
4124 (car gnus-article-current) (cdr gnus-article-current))))
4126 (set-window-start (get-buffer-window buf) start)
4127 (set-window-point (get-buffer-window buf) (point))))
4129 (defun gnus-article-edit-exit ()
4130 "Exit the article editing without updating."
4132 ;; We remove all text props from the article buffer.
4133 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4134 (curbuf (current-buffer))
4136 (window-start (window-start)))
4139 (let ((winconf gnus-prev-winconf))
4141 (set-window-configuration winconf)
4142 ;; Tippy-toe some to make sure that point remains where it was.
4143 (save-current-buffer
4145 (set-window-start (get-buffer-window (current-buffer)) window-start)
4148 (defun gnus-article-edit-full-stops ()
4149 "Interactively repair spacing at end of sentences."
4152 (goto-char (point-min))
4153 (search-forward-regexp "^$" nil t)
4154 (let ((case-fold-search nil))
4155 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4158 ;;; Article highlights
4161 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4163 ;;; Internal Variables:
4165 (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\\)\\)"
4166 "Regular expression that matches URLs."
4167 :group 'gnus-article-buttons
4170 (defcustom gnus-button-alist
4171 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4172 0 t gnus-button-message-id 2)
4173 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4174 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4176 gnus-button-fetch-group 4)
4177 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4178 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4179 t gnus-button-message-id 3)
4180 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4181 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4182 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4183 ;; This is how URLs _should_ be embedded in text...
4184 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4186 (,gnus-button-url-regexp 0 t browse-url 0))
4187 "*Alist of regexps matching buttons in article bodies.
4189 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4190 REGEXP: is the string matching text around the button,
4191 BUTTON: is the number of the regexp grouping actually matching the button,
4192 FORM: is a lisp expression which must eval to true for the button to
4194 CALLBACK: is the function to call when the user push this button, and each
4195 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4197 CALLBACK can also be a variable, in that case the value of that
4198 variable it the real callback function."
4199 :group 'gnus-article-buttons
4200 :type '(repeat (list regexp
4201 (integer :tag "Button")
4203 (function :tag "Callback")
4206 (integer :tag "Regexp group")))))
4208 (defcustom gnus-header-button-alist
4209 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4210 0 t gnus-button-message-id 0)
4211 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4212 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4213 0 t gnus-button-mailto 0)
4214 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4215 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4216 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4217 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4218 gnus-button-message-id 3))
4219 "*Alist of headers and regexps to match buttons in article heads.
4221 This alist is very similar to `gnus-button-alist', except that each
4222 alist has an additional HEADER element first in each entry:
4224 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4226 HEADER is a regexp to match a header. For a fuller explanation, see
4227 `gnus-button-alist'."
4228 :group 'gnus-article-buttons
4229 :group 'gnus-article-headers
4230 :type '(repeat (list (regexp :tag "Header")
4232 (integer :tag "Button")
4234 (function :tag "Callback")
4237 (integer :tag "Regexp group")))))
4239 (defvar gnus-button-regexp nil)
4240 (defvar gnus-button-marker-list nil)
4241 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4243 (defvar gnus-button-last nil)
4244 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4248 (defun gnus-article-push-button (event)
4249 "Check text under the mouse pointer for a callback function.
4250 If the text under the mouse pointer has a `gnus-callback' property,
4251 call it with the value of the `gnus-data' text property."
4253 (set-buffer (window-buffer (posn-window (event-start event))))
4254 (let* ((pos (posn-point (event-start event)))
4255 (data (get-text-property pos 'gnus-data))
4256 (fun (get-text-property pos 'gnus-callback)))
4259 (funcall fun data))))
4261 (defun gnus-article-press-button ()
4262 "Check text at point for a callback function.
4263 If the text at point has a `gnus-callback' property,
4264 call it with the value of the `gnus-data' text property."
4266 (let* ((data (get-text-property (point) 'gnus-data))
4267 (fun (get-text-property (point) 'gnus-callback)))
4269 (funcall fun data))))
4271 (defun gnus-article-highlight (&optional force)
4272 "Highlight current article.
4273 This function calls `gnus-article-highlight-headers',
4274 `gnus-article-highlight-citation',
4275 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4276 do the highlighting. See the documentation for those functions."
4277 (interactive (list 'force))
4278 (gnus-article-highlight-headers)
4279 (gnus-article-highlight-citation force)
4280 (gnus-article-highlight-signature)
4281 (gnus-article-add-buttons force)
4282 (gnus-article-add-buttons-to-head))
4284 (defun gnus-article-highlight-some (&optional force)
4285 "Highlight current article.
4286 This function calls `gnus-article-highlight-headers',
4287 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4288 do the highlighting. See the documentation for those functions."
4289 (interactive (list 'force))
4290 (gnus-article-highlight-headers)
4291 (gnus-article-highlight-signature)
4292 (gnus-article-add-buttons))
4294 (defun gnus-article-highlight-headers ()
4295 "Highlight article headers as specified by `gnus-header-face-alist'."
4298 (set-buffer gnus-article-buffer)
4300 (let ((alist gnus-header-face-alist)
4301 (buffer-read-only nil)
4302 (case-fold-search t)
4303 (inhibit-point-motion-hooks t)
4304 entry regexp header-face field-face from hpoints fpoints)
4305 (article-narrow-to-head)
4306 (while (setq entry (pop alist))
4307 (goto-char (point-min))
4308 (setq regexp (concat "^\\("
4309 (if (string-equal "" (nth 0 entry))
4313 header-face (nth 1 entry)
4314 field-face (nth 2 entry))
4315 (while (and (re-search-forward regexp nil t)
4319 (unless (search-forward ":" nil t)
4321 (when (and header-face
4322 (not (memq (point) hpoints)))
4323 (push (point) hpoints)
4324 (gnus-put-text-property from (point) 'face header-face))
4325 (when (and field-face
4326 (not (memq (setq from (point)) fpoints)))
4328 (if (re-search-forward "^[^ \t]" nil t)
4330 (goto-char (point-max)))
4331 (gnus-put-text-property from (point) 'face field-face))))))))
4333 (defun gnus-article-highlight-signature ()
4334 "Highlight the signature in an article.
4335 It does this by highlighting everything after
4336 `gnus-signature-separator' using `gnus-signature-face'."
4339 (set-buffer gnus-article-buffer)
4340 (let ((buffer-read-only nil)
4341 (inhibit-point-motion-hooks t))
4343 (when (and gnus-signature-face
4344 (gnus-article-narrow-to-signature))
4345 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4346 'face gnus-signature-face)
4348 (gnus-article-search-signature)
4349 (let ((start (match-beginning 0))
4350 (end (set-marker (make-marker) (1+ (match-end 0)))))
4351 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4354 (defun gnus-button-in-region-p (b e prop)
4355 "Say whether PROP exists in the region."
4356 (text-property-not-all b e prop nil))
4358 (defun gnus-article-add-buttons (&optional force)
4359 "Find external references in the article and make buttons of them.
4360 \"External references\" are things like Message-IDs and URLs, as
4361 specified by `gnus-button-alist'."
4362 (interactive (list 'force))
4364 (set-buffer gnus-article-buffer)
4365 (let ((buffer-read-only nil)
4366 (inhibit-point-motion-hooks t)
4367 (case-fold-search t)
4368 (alist gnus-button-alist)
4370 ;; Remove all old markers.
4371 (let (marker entry new-list)
4372 (while (setq marker (pop gnus-button-marker-list))
4373 (if (or (< marker (point-min)) (>= marker (point-max)))
4374 (push marker new-list)
4376 (when (setq entry (gnus-button-entry))
4377 (put-text-property (match-beginning (nth 1 entry))
4378 (match-end (nth 1 entry))
4379 'gnus-callback nil))
4380 (set-marker marker nil)))
4381 (setq gnus-button-marker-list new-list))
4382 ;; We skip the headers.
4385 (while (setq entry (pop alist))
4386 (setq regexp (car entry))
4388 (while (re-search-forward regexp nil t)
4389 (let* ((start (and entry (match-beginning (nth 1 entry))))
4390 (end (and entry (match-end (nth 1 entry))))
4391 (from (match-beginning 0)))
4392 (when (and (or (eq t (nth 2 entry))
4393 (eval (nth 2 entry)))
4394 (not (gnus-button-in-region-p
4395 start end 'gnus-callback)))
4396 ;; That optional form returned non-nil, so we add the
4398 (gnus-article-add-button
4399 start end 'gnus-button-push
4400 (car (push (set-marker (make-marker) from)
4401 gnus-button-marker-list))))))))))
4403 ;; Add buttons to the head of an article.
4404 (defun gnus-article-add-buttons-to-head ()
4405 "Add buttons to the head of the article."
4408 (set-buffer gnus-article-buffer)
4410 (let ((buffer-read-only nil)
4411 (inhibit-point-motion-hooks t)
4412 (case-fold-search t)
4413 (alist gnus-header-button-alist)
4415 (article-narrow-to-head)
4417 ;; Each alist entry.
4418 (setq entry (car alist)
4420 (goto-char (point-min))
4421 (while (re-search-forward (car entry) nil t)
4422 ;; Each header matching the entry.
4423 (setq beg (match-beginning 0))
4424 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4425 (match-beginning 0))
4428 (while (re-search-forward (nth 1 entry) end t)
4429 ;; Each match within a header.
4430 (let* ((entry (cdr entry))
4431 (start (match-beginning (nth 1 entry)))
4432 (end (match-end (nth 1 entry)))
4433 (form (nth 2 entry)))
4434 (goto-char (match-end 0))
4436 (gnus-article-add-button
4437 start end (nth 3 entry)
4438 (buffer-substring (match-beginning (nth 4 entry))
4439 (match-end (nth 4 entry)))))))
4440 (goto-char end)))))))
4442 ;;; External functions:
4444 (defun gnus-article-add-button (from to fun &optional data)
4445 "Create a button between FROM and TO with callback FUN and data DATA."
4446 (when gnus-article-button-face
4447 (gnus-overlay-put (gnus-make-overlay from to)
4448 'face gnus-article-button-face))
4449 (gnus-add-text-properties
4451 (nconc (and gnus-article-mouse-face
4452 (list gnus-mouse-face-prop gnus-article-mouse-face))
4453 (list 'gnus-callback fun)
4454 (and data (list 'gnus-data data))))
4455 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4456 :button-keymap gnus-widget-button-keymap))
4458 ;;; Internal functions:
4460 (defun gnus-article-set-globals ()
4462 (set-buffer gnus-summary-buffer)
4463 (gnus-set-global-variables)))
4465 (defun gnus-signature-toggle (end)
4467 (set-buffer gnus-article-buffer)
4468 (let ((buffer-read-only nil)
4469 (inhibit-point-motion-hooks t))
4470 (if (get-text-property end 'invisible)
4471 (gnus-article-unhide-text end (point-max))
4472 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4474 (defun gnus-button-entry ()
4475 ;; Return the first entry in `gnus-button-alist' matching this place.
4476 (let ((alist gnus-button-alist)
4479 (setq entry (pop alist))
4480 (if (looking-at (car entry))
4485 (defun gnus-button-push (marker)
4486 ;; Push button starting at MARKER.
4489 (let* ((entry (gnus-button-entry))
4490 (inhibit-point-motion-hooks t)
4492 (args (mapcar (lambda (group)
4493 (let ((string (match-string group)))
4494 (gnus-set-text-properties
4495 0 (length string) nil string)
4502 (fboundp (symbol-value fun)))
4503 (apply (symbol-value fun) args))
4505 (gnus-message 1 "You must define `%S' to use this button"
4506 (cons fun args)))))))
4508 (defun gnus-button-message-id (message-id)
4511 (set-buffer gnus-summary-buffer)
4512 (gnus-summary-refer-article message-id)))
4514 (defun gnus-button-fetch-group (address)
4515 "Fetch GROUP specified by ADDRESS."
4516 (if (not (string-match "[:/]" address))
4517 ;; This is just a simple group url.
4518 (gnus-group-read-ephemeral-group address gnus-select-method)
4519 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4521 (error "Can't parse %s" address)
4522 (gnus-group-read-ephemeral-group
4523 (match-string 4 address)
4524 `(nntp ,(match-string 1 address)
4525 (nntp-address ,(match-string 1 address))
4526 (nntp-port-number ,(if (match-end 3)
4527 (match-string 3 address)
4530 (defun gnus-url-parse-query-string (query &optional downcase)
4531 (let (retval pairs cur key val)
4532 (setq pairs (split-string query "&"))
4534 (setq cur (car pairs)
4536 (if (not (string-match "=" cur))
4538 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4539 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4541 (setq key (downcase key)))
4542 (setq cur (assoc key retval))
4544 (setcdr cur (cons val (cdr cur)))
4545 (setq retval (cons (list key val) retval)))))
4548 (defun gnus-url-unhex (x)
4555 (defun gnus-url-unhex-string (str &optional allow-newlines)
4556 "Remove %XXX embedded spaces, etc in a url.
4557 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4558 decoding of carriage returns and line feeds in the string, which is normally
4559 forbidden in URL encoding."
4560 (setq str (or str ""))
4562 (case-fold-search t))
4563 (while (string-match "%[0-9a-f][0-9a-f]" str)
4564 (let* ((start (match-beginning 0))
4565 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4567 (gnus-url-unhex (elt str (+ start 2))))))
4569 tmp (substring str 0 start)
4572 (char-to-string code))
4573 ((or (= code ?\n) (= code ?\r))
4575 (t (char-to-string code))))
4576 str (substring str (match-end 0)))))
4577 (setq tmp (concat tmp str))
4580 (defun gnus-url-mailto (url)
4581 ;; Send mail to someone
4582 (when (string-match "mailto:/*\\(.*\\)" url)
4583 (setq url (substring url (match-beginning 1) nil)))
4584 (let (to args subject func)
4585 (if (string-match (regexp-quote "?") url)
4586 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4587 args (gnus-url-parse-query-string
4588 (substring url (match-end 0) nil) t))
4589 (setq to (gnus-url-unhex-string url)))
4590 (setq args (cons (list "to" to) args)
4591 subject (cdr-safe (assoc "subject" args)))
4594 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4597 (message-position-on-field (caar args)))
4598 (insert (mapconcat 'identity (cdar args) ", "))
4599 (setq args (cdr args)))
4602 (message-goto-subject))))
4604 (defun gnus-button-mailto (address)
4606 (set-buffer (gnus-copy-article-buffer))
4607 (message-reply address))
4609 (defalias 'gnus-button-reply 'message-reply)
4611 (defun gnus-button-embedded-url (address)
4612 "Activate ADDRESS with `browse-url'."
4613 (browse-url (gnus-strip-whitespace address)))
4615 ;;; Next/prev buttons in the article buffer.
4617 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4618 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4620 (defvar gnus-prev-page-map nil)
4621 (unless gnus-prev-page-map
4622 (setq gnus-prev-page-map (make-sparse-keymap))
4623 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4624 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4626 (defun gnus-insert-prev-page-button ()
4627 (let ((buffer-read-only nil))
4629 gnus-prev-page-line-format nil
4630 `(gnus-prev t local-map ,gnus-prev-page-map
4631 gnus-callback gnus-article-button-prev-page
4632 article-type annotation))))
4634 (defvar gnus-next-page-map nil)
4635 (unless gnus-next-page-map
4636 (setq gnus-next-page-map (make-keymap))
4637 (suppress-keymap gnus-prev-page-map)
4638 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4639 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4641 (defun gnus-button-next-page ()
4642 "Go to the next page."
4644 (let ((win (selected-window)))
4645 (select-window (get-buffer-window gnus-article-buffer t))
4646 (gnus-article-next-page)
4647 (select-window win)))
4649 (defun gnus-button-prev-page ()
4650 "Go to the prev page."
4652 (let ((win (selected-window)))
4653 (select-window (get-buffer-window gnus-article-buffer t))
4654 (gnus-article-prev-page)
4655 (select-window win)))
4657 (defun gnus-insert-next-page-button ()
4658 (let ((buffer-read-only nil))
4659 (gnus-eval-format gnus-next-page-line-format nil
4661 t local-map ,gnus-next-page-map
4662 gnus-callback gnus-article-button-next-page
4663 article-type annotation))))
4665 (defun gnus-article-button-next-page (arg)
4666 "Go to the next page."
4668 (let ((win (selected-window)))
4669 (select-window (get-buffer-window gnus-article-buffer t))
4670 (gnus-article-next-page)
4671 (select-window win)))
4673 (defun gnus-article-button-prev-page (arg)
4674 "Go to the prev page."
4676 (let ((win (selected-window)))
4677 (select-window (get-buffer-window gnus-article-buffer t))
4678 (gnus-article-prev-page)
4679 (select-window win)))
4681 (defvar gnus-decode-header-methods
4682 '(mail-decode-encoded-word-region)
4683 "List of methods used to decode headers.
4685 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4686 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4687 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4688 whose names match REGEXP.
4691 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4692 mail-decode-encoded-word-region
4693 (\"chinese\" . rfc1843-decode-region))
4696 (defvar gnus-decode-header-methods-cache nil)
4698 (defun gnus-multi-decode-header (start end)
4699 "Apply the functions from `gnus-encoded-word-methods' that match."
4700 (unless (and gnus-decode-header-methods-cache
4701 (eq gnus-newsgroup-name
4702 (car gnus-decode-header-methods-cache)))
4703 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4706 (nconc gnus-decode-header-methods-cache (list x))
4707 (if (and gnus-newsgroup-name
4708 (string-match (car x) gnus-newsgroup-name))
4709 (nconc gnus-decode-header-methods-cache
4711 gnus-decode-header-methods))
4712 (let ((xlist gnus-decode-header-methods-cache))
4715 (narrow-to-region start end)
4717 (funcall (pop xlist) (point-min) (point-max))))))
4720 ;;; Treatment top-level handling.
4723 (defun gnus-treat-article (condition &optional part-number total-parts type)
4724 (let ((length (- (point-max) (point-min)))
4725 (alist gnus-treatment-function-alist)
4726 (article-goto-body-goes-to-point-min-p t)
4730 (let ((list gnus-article-treat-types))
4732 (when (string-match (pop list) type)
4733 (throw 'found t)))))))
4734 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4736 (gnus-run-hooks 'gnus-part-display-hook)
4737 (while (setq elem (pop alist))
4740 (if (gnus-buffer-live-p gnus-summary-buffer)
4741 (set-buffer gnus-summary-buffer))
4742 (symbol-value (car elem))))
4743 (when (and (or (consp val)
4745 (gnus-treat-predicate val)
4746 (or (not (get (car elem) 'highlight))
4749 (funcall (cadr elem)))))))
4751 ;; Dynamic variables.
4753 (defvar part-number)
4754 (defvar total-parts)
4759 (defun gnus-treat-predicate (val)
4764 (stringp (car val)))
4765 (apply 'gnus-or (mapcar `(lambda (s)
4766 (string-match s ,(or gnus-newsgroup-name "")))
4769 (let ((pred (pop val)))
4772 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4774 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4776 (not (gnus-treat-predicate (car val))))
4778 (equal (car val) type))
4780 (error "%S is not a valid predicate" pred)))))
4788 (eq part-number total-parts))
4792 (error "%S is not a valid value" val))))
4798 (run-hooks 'gnus-art-load-hook)
4800 ;;; gnus-art.el ends here