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-hide-citation-maybe nil
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-list-identifiers 'head
779 "Strip list identifiers from `gnus-list-identifiers`.
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-pgp t
786 "Strip PGP 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-pem nil
793 "Strip PEM signatures.
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
799 (defcustom gnus-treat-strip-banner t
800 "Strip banners from articles.
801 The banner to be stripped is specified in the `banner' group parameter.
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-custom)
807 (defcustom gnus-treat-highlight-headers 'head
808 "Highlight the headers.
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-head-custom)
813 (put 'gnus-treat-highlight-headers 'highlight t)
815 (defcustom gnus-treat-highlight-citation t
816 "Highlight cited text.
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-custom)
821 (put 'gnus-treat-highlight-citation 'highlight t)
823 (defcustom gnus-treat-date-ut nil
824 "Display the Date in UT (GMT).
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-local nil
831 "Display the Date in the local timezone.
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-lapsed nil
838 "Display the Date header in a way that says how much time has elapsed.
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-original nil
845 "Display the date in the original timezone.
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-iso8601 nil
852 "Display the date in the ISO8601 format.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-head-custom)
858 (defcustom gnus-treat-date-user-defined nil
859 "Display the date in a user-defined format.
860 The format is defined by the `gnus-article-time-format' variable.
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-head-custom)
866 (defcustom gnus-treat-strip-headers-in-body t
867 "Strip the X-No-Archive header line from the beginning of the body.
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-trailing-blank-lines nil
874 "Strip trailing 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-leading-blank-lines nil
881 "Strip leading 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-strip-multiple-blank-lines nil
888 "Strip multiple blank lines.
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)
894 (defcustom gnus-treat-overstrike t
895 "Treat overstrike highlighting.
896 Valid values are nil, t, `head', `last', an integer or a predicate.
897 See the manual for details."
898 :group 'gnus-article-treat
899 :type gnus-article-treat-custom)
900 (put 'gnus-treat-overstrike 'highlight t)
902 (defcustom gnus-treat-display-xface
903 (and (or (and (fboundp 'image-type-available-p)
904 (image-type-available-p 'xbm))
905 (and (featurep 'xemacs) (featurep 'xface)))
907 "Display X-Face headers.
908 Valid values are nil, t, `head', `last', an integer or a predicate.
909 See the manual for details."
910 :group 'gnus-article-treat
911 :type gnus-article-treat-head-custom)
912 (put 'gnus-treat-display-xface 'highlight t)
914 (defcustom gnus-treat-display-smileys
915 (if (or (and (featurep 'xemacs)
917 (and (fboundp 'image-type-available-p)
918 (image-type-available-p 'pbm)))
921 Valid values are nil, t, `head', `last', an integer or a predicate.
922 See the manual for details."
923 :group 'gnus-article-treat
924 :type gnus-article-treat-custom)
925 (put 'gnus-treat-display-smileys 'highlight t)
927 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
929 Valid values are nil, t, `head', `last', an integer or a predicate.
930 See the manual for details."
931 :group 'gnus-article-treat
932 :type gnus-article-treat-head-custom)
933 (put 'gnus-treat-display-picons 'highlight t)
935 (defcustom gnus-treat-capitalize-sentences nil
936 "Capitalize sentence-starting words.
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-fill-long-lines 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-play-sounds nil
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 (defcustom gnus-treat-translate nil
957 "Translate articles from one language to another.
958 Valid values are nil, t, `head', `last', an integer or a predicate.
959 See the manual for details."
960 :group 'gnus-article-treat
961 :type gnus-article-treat-custom)
963 ;;; Internal variables
965 (defvar article-goto-body-goes-to-point-min-p nil)
966 (defvar gnus-article-wash-types nil)
967 (defvar gnus-article-emphasis-alist nil)
969 (defvar gnus-article-mime-handle-alist-1 nil)
970 (defvar gnus-treatment-function-alist
971 '((gnus-treat-strip-banner gnus-article-strip-banner)
972 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
973 (gnus-treat-highlight-signature gnus-article-highlight-signature)
974 (gnus-treat-buttonize gnus-article-add-buttons)
975 (gnus-treat-fill-article gnus-article-fill-cited-article)
976 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
977 (gnus-treat-strip-cr gnus-article-remove-cr)
978 (gnus-treat-emphasize gnus-article-emphasize)
979 (gnus-treat-display-xface gnus-article-display-x-face)
980 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
981 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
982 (gnus-treat-hide-signature gnus-article-hide-signature)
983 (gnus-treat-hide-citation gnus-article-hide-citation)
984 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
985 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
986 (gnus-treat-strip-pgp gnus-article-hide-pgp)
987 (gnus-treat-strip-pem gnus-article-hide-pem)
988 (gnus-treat-highlight-headers gnus-article-highlight-headers)
989 (gnus-treat-highlight-citation gnus-article-highlight-citation)
990 (gnus-treat-highlight-signature gnus-article-highlight-signature)
991 (gnus-treat-date-ut gnus-article-date-ut)
992 (gnus-treat-date-local gnus-article-date-local)
993 (gnus-treat-date-lapsed gnus-article-date-lapsed)
994 (gnus-treat-date-original gnus-article-date-original)
995 (gnus-treat-date-user-defined gnus-article-date-user)
996 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
997 (gnus-treat-strip-trailing-blank-lines
998 gnus-article-remove-trailing-blank-lines)
999 (gnus-treat-strip-leading-blank-lines
1000 gnus-article-strip-leading-blank-lines)
1001 (gnus-treat-strip-multiple-blank-lines
1002 gnus-article-strip-multiple-blank-lines)
1003 (gnus-treat-overstrike gnus-article-treat-overstrike)
1004 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1005 (gnus-treat-display-smileys gnus-smiley-display)
1006 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1007 (gnus-treat-display-picons gnus-article-display-picons)
1008 (gnus-treat-play-sounds gnus-earcon-display)))
1010 (defvar gnus-article-mime-handle-alist nil)
1011 (defvar article-lapsed-timer nil)
1012 (defvar gnus-article-current-summary nil)
1014 (defvar gnus-article-mode-syntax-table
1015 (let ((table (copy-syntax-table text-mode-syntax-table)))
1016 (modify-syntax-entry ?- "w" table)
1017 (modify-syntax-entry ?> ")" table)
1018 (modify-syntax-entry ?< "(" table)
1020 "Syntax table used in article mode buffers.
1021 Initialized from `text-mode-syntax-table.")
1023 (defvar gnus-save-article-buffer nil)
1025 (defvar gnus-article-mode-line-format-alist
1026 (nconc '((?w (gnus-article-wash-status) ?s)
1027 (?m (gnus-article-mime-part-status) ?s))
1028 gnus-summary-mode-line-format-alist))
1030 (defvar gnus-number-of-articles-to-be-saved nil)
1032 (defvar gnus-inhibit-hiding nil)
1034 (defsubst gnus-article-hide-text (b e props)
1035 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1036 (add-text-properties b e props)
1037 (when (memq 'intangible props)
1039 (max (1- b) (point-min))
1040 b 'intangible (cddr (memq 'intangible props)))))
1041 (defsubst gnus-article-unhide-text (b e)
1042 "Remove hidden text properties from region between B and E."
1043 (remove-text-properties b e gnus-hidden-properties)
1044 (when (memq 'intangible gnus-hidden-properties)
1045 (put-text-property (max (1- b) (point-min))
1046 b 'intangible nil)))
1048 (defun gnus-article-hide-text-type (b e type)
1049 "Hide text of TYPE between B and E."
1050 (push type gnus-article-wash-types)
1051 (gnus-article-hide-text
1052 b e (cons 'article-type (cons type gnus-hidden-properties))))
1054 (defun gnus-article-unhide-text-type (b e type)
1055 "Unhide text of TYPE between B and E."
1056 (setq gnus-article-wash-types
1057 (delq type gnus-article-wash-types))
1058 (remove-text-properties
1059 b e (cons 'article-type (cons type gnus-hidden-properties)))
1060 (when (memq 'intangible gnus-hidden-properties)
1061 (put-text-property (max (1- b) (point-min))
1062 b 'intangible nil)))
1064 (defun gnus-article-hide-text-of-type (type)
1065 "Hide text of TYPE in the current buffer."
1067 (let ((b (point-min))
1069 (while (setq b (text-property-any b e 'article-type type))
1070 (add-text-properties b (incf b) gnus-hidden-properties)))))
1072 (defun gnus-article-delete-text-of-type (type)
1073 "Delete text of TYPE in the current buffer."
1075 (let ((b (point-min)))
1076 (while (setq b (text-property-any b (point-max) 'article-type type))
1078 b (or (text-property-not-all b (point-max) 'article-type type)
1081 (defun gnus-article-delete-invisible-text ()
1082 "Delete all invisible text in the current buffer."
1084 (let ((b (point-min)))
1085 (while (setq b (text-property-any b (point-max) 'invisible t))
1087 b (or (text-property-not-all b (point-max) 'invisible t)
1090 (defun gnus-article-text-type-exists-p (type)
1091 "Say whether any text of type TYPE exists in the buffer."
1092 (text-property-any (point-min) (point-max) 'article-type type))
1094 (defsubst gnus-article-header-rank ()
1095 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1096 (let ((list gnus-sorted-header-list)
1099 (when (looking-at (car list))
1101 (setq list (cdr list))
1105 (defun article-hide-headers (&optional arg delete)
1106 "Hide unwanted headers and possibly sort them as well."
1108 ;; This function might be inhibited.
1109 (unless gnus-inhibit-hiding
1112 (let ((buffer-read-only nil)
1113 (case-fold-search t)
1114 (max (1+ (length gnus-sorted-header-list)))
1115 (ignored (when (not gnus-visible-headers)
1116 (cond ((stringp gnus-ignored-headers)
1117 gnus-ignored-headers)
1118 ((listp gnus-ignored-headers)
1119 (mapconcat 'identity gnus-ignored-headers
1122 (cond ((stringp gnus-visible-headers)
1123 gnus-visible-headers)
1124 ((and gnus-visible-headers
1125 (listp gnus-visible-headers))
1126 (mapconcat 'identity gnus-visible-headers "\\|"))))
1127 (inhibit-point-motion-hooks t)
1129 ;; First we narrow to just the headers.
1130 (article-narrow-to-head)
1131 ;; Hide any "From " lines at the beginning of (mail) articles.
1132 (while (looking-at "From ")
1135 (delete-region (point-min) (point)))
1136 ;; Then treat the rest of the header lines.
1137 ;; Then we use the two regular expressions
1138 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1139 ;; select which header lines is to remain visible in the
1141 (while (re-search-forward "^[^ \t]*:" nil t)
1143 ;; Mark the rank of the header.
1145 (point) (1+ (point)) 'message-rank
1146 (if (or (and visible (looking-at visible))
1148 (not (looking-at ignored))))
1149 (gnus-article-header-rank)
1152 (message-sort-headers-1)
1153 (when (setq beg (text-property-any
1154 (point-min) (point-max) 'message-rank (+ 2 max)))
1155 ;; We delete the unwanted headers.
1156 (push 'headers gnus-article-wash-types)
1157 (add-text-properties (point-min) (+ 5 (point-min))
1158 '(article-type headers dummy-invisible t))
1159 (delete-region beg (point-max))))))))
1161 (defun article-hide-boring-headers (&optional arg)
1162 "Toggle hiding of headers that aren't very interesting.
1163 If given a negative prefix, always show; if given a positive prefix,
1165 (interactive (gnus-article-hidden-arg))
1166 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1167 (not gnus-show-all-headers))
1170 (let ((buffer-read-only nil)
1171 (list gnus-boring-article-headers)
1172 (inhibit-point-motion-hooks t)
1174 (article-narrow-to-head)
1176 (setq elem (pop list))
1177 (goto-char (point-min))
1179 ;; Hide empty headers.
1181 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1183 (gnus-article-hide-text-type
1184 (progn (beginning-of-line) (point))
1187 (if (re-search-forward "^[^ \t]" nil t)
1191 ;; Hide boring Newsgroups header.
1192 ((eq elem 'newsgroups)
1193 (when (equal (gnus-fetch-field "newsgroups")
1194 (gnus-group-real-name
1195 (if (boundp 'gnus-newsgroup-name)
1198 (gnus-article-hide-header "newsgroups")))
1199 ((eq elem 'followup-to)
1200 (when (equal (message-fetch-field "followup-to")
1201 (message-fetch-field "newsgroups"))
1202 (gnus-article-hide-header "followup-to")))
1203 ((eq elem 'reply-to)
1204 (let ((from (message-fetch-field "from"))
1205 (reply-to (message-fetch-field "reply-to")))
1210 (nth 1 (mail-extract-address-components from))
1211 (nth 1 (mail-extract-address-components reply-to)))))
1212 (gnus-article-hide-header "reply-to"))))
1214 (let ((date (message-fetch-field "date")))
1216 (< (days-between (current-time-string) date)
1218 (gnus-article-hide-header "date"))))
1220 (let ((to (message-fetch-field "to"))
1221 (cc (message-fetch-field "cc")))
1222 (when (> (length to) 1024)
1223 (gnus-article-hide-header "to"))
1224 (when (> (length cc) 1024)
1225 (gnus-article-hide-header "cc"))))
1229 (goto-char (point-min))
1230 (while (re-search-forward "^to:" nil t)
1231 (setq to-count (1+ to-count)))
1232 (when (> to-count 1)
1233 (while (> to-count 0)
1234 (goto-char (point-min))
1236 (re-search-forward "^to:" nil nil to-count)
1238 (narrow-to-region (point) (point-max))
1239 (gnus-article-hide-header "to"))
1240 (setq to-count (1- to-count))))
1241 (goto-char (point-min))
1242 (while (re-search-forward "^cc:" nil t)
1243 (setq cc-count (1+ cc-count)))
1244 (when (> cc-count 1)
1245 (while (> cc-count 0)
1246 (goto-char (point-min))
1248 (re-search-forward "^cc:" nil nil cc-count)
1250 (narrow-to-region (point) (point-max))
1251 (gnus-article-hide-header "cc"))
1252 (setq cc-count (1- cc-count)))))))))))))
1254 (defun gnus-article-hide-header (header)
1256 (goto-char (point-min))
1257 (when (re-search-forward (concat "^" header ":") nil t)
1258 (gnus-article-hide-text-type
1259 (progn (beginning-of-line) (point))
1262 (if (re-search-forward "^[^ \t]" nil t)
1267 (defvar gnus-article-normalized-header-length 40
1268 "Length of normalized headers.")
1270 (defun article-normalize-headers ()
1271 "Make all header lines 40 characters long."
1273 (let ((buffer-read-only nil)
1277 (article-narrow-to-head)
1280 ((< (setq column (- (gnus-point-at-eol) (point)))
1281 gnus-article-normalized-header-length)
1283 (insert (make-string
1284 (- gnus-article-normalized-header-length column)
1286 ((> column gnus-article-normalized-header-length)
1287 (gnus-put-text-property
1289 (forward-char gnus-article-normalized-header-length)
1296 (forward-line 1))))))
1298 (defun article-treat-dumbquotes ()
1299 "Translate M******** sm*rtq**t*s into proper text.
1300 Note that this function guesses whether a character is a sm*rtq**t* or
1301 not, so it should only be used interactively."
1303 (article-translate-strings gnus-article-dumbquotes-map))
1305 (defun article-translate-characters (from to)
1306 "Translate all characters in the body of the article according to FROM and TO.
1307 FROM is a string of characters to translate from; to is a string of
1308 characters to translate to."
1310 (when (article-goto-body)
1311 (let ((buffer-read-only nil)
1312 (x (make-string 225 ?x))
1314 (while (< (incf i) (length x))
1317 (while (< i (length from))
1318 (aset x (aref from i) (aref to i))
1320 (translate-region (point) (point-max) x)))))
1322 (defun article-translate-strings (map)
1323 "Translate all string in the body of the article according to MAP.
1324 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1326 (when (article-goto-body)
1327 (let ((buffer-read-only nil)
1329 (while (setq elem (pop map))
1331 (while (search-forward (car elem) nil t)
1332 (replace-match (cadr elem)))))))))
1334 (defun article-treat-overstrike ()
1335 "Translate overstrikes into bold text."
1338 (when (article-goto-body)
1339 (let ((buffer-read-only nil))
1340 (while (search-forward "\b" nil t)
1341 (let ((next (char-after))
1342 (previous (char-after (- (point) 2))))
1343 ;; We do the boldification/underlining by hiding the
1344 ;; overstrikes and putting the proper text property
1348 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1349 (put-text-property (point) (1+ (point)) 'face 'bold))
1351 (gnus-article-hide-text-type
1352 (1- (point)) (1+ (point)) 'overstrike)
1354 (- (point) 2) (1- (point)) 'face 'underline))
1356 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1358 (point) (1+ (point)) 'face 'underline)))))))))
1360 (defun article-fill-long-lines ()
1361 "Fill lines that are wider than the window width."
1364 (let ((buffer-read-only nil)
1365 (width (window-width (get-buffer-window (current-buffer)))))
1368 (let ((adaptive-fill-mode nil))
1371 (when (>= (current-column) (min fill-column width))
1372 (narrow-to-region (point) (gnus-point-at-bol))
1373 (fill-paragraph nil)
1374 (goto-char (point-max))
1376 (forward-line 1)))))))
1378 (defun article-capitalize-sentences ()
1379 "Capitalize the first word in each sentence."
1382 (let ((buffer-read-only nil)
1383 (paragraph-start "^[\n\^L]"))
1387 (forward-sentence)))))
1389 (defun article-remove-cr ()
1390 "Remove trailing CRs and then translate remaining CRs into LFs."
1393 (let ((buffer-read-only nil))
1394 (goto-char (point-min))
1395 (while (re-search-forward "\r+$" nil t)
1396 (replace-match "" t t))
1397 (goto-char (point-min))
1398 (while (search-forward "\r" nil t)
1399 (replace-match "\n" t t)))))
1401 (defun article-remove-trailing-blank-lines ()
1402 "Remove all trailing blank lines from the article."
1405 (let ((buffer-read-only nil))
1406 (goto-char (point-max))
1410 (while (and (not (bobp))
1411 (looking-at "^[ \t]*$")
1412 (not (gnus-annotation-in-region-p
1413 (point) (gnus-point-at-eol))))
1418 (defun article-display-x-face (&optional force)
1419 "Look for an X-Face header and display it if present."
1420 (interactive (list 'force))
1422 ;; Delete the old process, if any.
1423 (when (process-status "article-x-face")
1424 (delete-process "article-x-face"))
1425 (let ((inhibit-point-motion-hooks t)
1426 (case-fold-search t)
1429 (article-narrow-to-head)
1430 (goto-char (point-min))
1431 (setq from (message-fetch-field "from"))
1432 (goto-char (point-min))
1433 (while (and gnus-article-x-face-command
1436 ;; Check whether this face is censored.
1437 (not gnus-article-x-face-too-ugly)
1438 (and gnus-article-x-face-too-ugly from
1439 (not (string-match gnus-article-x-face-too-ugly
1441 ;; Has to be present.
1442 (re-search-forward "^X-Face: " nil t))
1443 ;; This used to try to do multiple faces (`while' instead of
1444 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1445 ;; work (b) it can crash some versions of Emacs (c) are
1446 ;; multiple faces really something to encourage?
1447 (when (stringp gnus-article-x-face-command)
1449 ;; We now have the area of the buffer where the X-Face is stored.
1452 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1453 ;; We display the face.
1454 (if (symbolp gnus-article-x-face-command)
1455 ;; The command is a lisp function, so we call it.
1456 (if (gnus-functionp gnus-article-x-face-command)
1457 (funcall gnus-article-x-face-command beg end)
1458 (error "%s is not a function" gnus-article-x-face-command))
1459 ;; The command is a string, so we interpret the command
1460 ;; as a, well, command, and fork it off.
1461 (let ((process-connection-type nil))
1462 (process-kill-without-query
1464 "article-x-face" nil shell-file-name shell-command-switch
1465 gnus-article-x-face-command))
1466 (process-send-region "article-x-face" beg end)
1467 (process-send-eof "article-x-face"))))))))))
1469 (defun article-decode-mime-words ()
1470 "Decode all MIME-encoded words in the article."
1473 (set-buffer gnus-article-buffer)
1474 (let ((inhibit-point-motion-hooks t)
1476 (mail-parse-charset gnus-newsgroup-charset)
1477 (mail-parse-ignored-charsets
1478 (save-excursion (set-buffer gnus-summary-buffer)
1479 gnus-newsgroup-ignored-charsets)))
1480 (mail-decode-encoded-word-region (point-min) (point-max)))))
1482 (defun article-decode-charset (&optional prompt)
1483 "Decode charset-encoded text in the article.
1484 If PROMPT (the prefix), prompt for a coding system to use."
1486 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1488 (mail-parse-charset gnus-newsgroup-charset)
1489 (mail-parse-ignored-charsets
1490 (save-excursion (condition-case nil
1491 (set-buffer gnus-summary-buffer)
1493 gnus-newsgroup-ignored-charsets))
1494 ct cte ctl charset format)
1497 (article-narrow-to-head)
1498 (setq ct (message-fetch-field "Content-Type" t)
1499 cte (message-fetch-field "Content-Transfer-Encoding" t)
1500 ctl (and ct (ignore-errors
1501 (mail-header-parse-content-type ct)))
1504 (mm-read-coding-system "Charset to decode: "))
1506 (mail-content-type-get ctl 'charset)))
1507 format (and ctl (mail-content-type-get ctl 'format)))
1509 (setq cte (mail-header-strip cte)))
1510 (if (and ctl (not (string-match "/" (car ctl))))
1512 (goto-char (point-max)))
1515 (narrow-to-region (point) (point-max))
1516 (when (and (eq mail-parse-charset 'gnus-decoded)
1517 (eq (mm-body-7-or-8) '8bit))
1518 ;; The text code could have been decoded.
1519 (setq charset mail-parse-charset))
1520 (when (and (or (not ctl)
1521 (equal (car ctl) "text/plain"))
1522 (not format)) ;; article with format will decode later.
1524 charset (and cte (intern (downcase
1525 (gnus-strip-whitespace cte))))
1528 (defun article-decode-encoded-words ()
1529 "Remove encoded-word encoding from headers."
1530 (let ((inhibit-point-motion-hooks t)
1531 (mail-parse-charset gnus-newsgroup-charset)
1532 (mail-parse-ignored-charsets
1533 (save-excursion (condition-case nil
1534 (set-buffer gnus-summary-buffer)
1536 gnus-newsgroup-ignored-charsets))
1539 (article-narrow-to-head)
1540 (funcall gnus-decode-header-function (point-min) (point-max)))))
1542 (defun article-de-quoted-unreadable (&optional force)
1543 "Translate a quoted-printable-encoded article.
1544 If FORCE, decode the article whether it is marked as quoted-printable
1546 (interactive (list 'force))
1548 (let ((buffer-read-only nil) type charset)
1549 (if (gnus-buffer-live-p gnus-original-article-buffer)
1550 (with-current-buffer gnus-original-article-buffer
1552 (gnus-fetch-field "content-transfer-encoding"))
1553 (let* ((ct (gnus-fetch-field "content-type"))
1556 (mail-header-parse-content-type ct)))))
1557 (setq charset (and ctl
1558 (mail-content-type-get ctl 'charset)))
1559 (if (stringp charset)
1560 (setq charset (intern (downcase charset)))))))
1562 (setq charset gnus-newsgroup-charset))
1564 (and type (let ((case-fold-search t))
1565 (string-match "quoted-printable" type))))
1567 (quoted-printable-decode-region
1568 (point) (point-max) (mm-charset-to-coding-system charset))))))
1570 (defun article-de-base64-unreadable (&optional force)
1571 "Translate a base64 article.
1572 If FORCE, decode the article whether it is marked as base64 not."
1573 (interactive (list 'force))
1575 (let ((buffer-read-only nil) type charset)
1576 (if (gnus-buffer-live-p gnus-original-article-buffer)
1577 (with-current-buffer gnus-original-article-buffer
1579 (gnus-fetch-field "content-transfer-encoding"))
1580 (let* ((ct (gnus-fetch-field "content-type"))
1583 (mail-header-parse-content-type ct)))))
1584 (setq charset (and ctl
1585 (mail-content-type-get ctl 'charset)))
1586 (if (stringp charset)
1587 (setq charset (intern (downcase charset)))))))
1589 (setq charset gnus-newsgroup-charset))
1591 (and type (let ((case-fold-search t))
1592 (string-match "base64" type))))
1595 (narrow-to-region (point) (point-max))
1596 (base64-decode-region (point-min) (point-max))
1597 (mm-decode-coding-region
1598 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1603 (defun article-decode-HZ ()
1604 "Translate a HZ-encoded article."
1608 (let ((buffer-read-only nil))
1609 (rfc1843-decode-region (point-min) (point-max)))))
1611 (defun article-wash-html ()
1612 "Format an html article."
1615 (let ((buffer-read-only nil)
1617 (if (gnus-buffer-live-p gnus-original-article-buffer)
1618 (with-current-buffer gnus-original-article-buffer
1619 (let* ((ct (gnus-fetch-field "content-type"))
1622 (mail-header-parse-content-type ct)))))
1623 (setq charset (and ctl
1624 (mail-content-type-get ctl 'charset)))
1625 (if (stringp charset)
1626 (setq charset (intern (downcase charset)))))))
1628 (setq charset gnus-newsgroup-charset))
1630 (save-window-excursion
1632 (narrow-to-region (point) (point-max))
1634 (let ((w3-strict-width (window-width))
1635 (url-standalone-mode t))
1637 (w3-region (point-min) (point-max))
1640 (defun article-hide-list-identifiers ()
1641 "Remove list identifies from the Subject header.
1642 The `gnus-list-identifiers' variable specifies what to do."
1646 (let ((inhibit-point-motion-hooks t)
1648 (article-narrow-to-head)
1649 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1650 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1652 (goto-char (point-min))
1653 (when (re-search-forward
1654 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1655 " *\\)\\)+\\(Re: +\\)?\\)")
1657 (let ((s (or (match-string 3) (match-string 5))))
1658 (delete-region (match-beginning 1) (match-end 1))
1660 (goto-char (match-beginning 1))
1663 (defun article-hide-pgp ()
1664 "Remove any PGP headers and signatures in the current article."
1668 (let ((inhibit-point-motion-hooks t)
1669 buffer-read-only beg end)
1671 ;; Hide the "header".
1672 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1673 (push 'pgp gnus-article-wash-types)
1674 (delete-region (match-beginning 0) (match-end 0))
1675 ;; Remove armor headers (rfc2440 6.2)
1676 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1679 ;; Hide the actual signature.
1680 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1681 (setq end (1+ (match-beginning 0)))
1684 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1686 ;; Perhaps we shouldn't hide to the end of the buffer
1687 ;; if there is no end to the signature?
1689 ;; Hide "- " PGP quotation markers.
1691 (narrow-to-region beg end)
1692 (goto-char (point-min))
1693 (while (re-search-forward "^- " nil t)
1695 (match-beginning 0) (match-end 0)))
1697 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1699 (defun article-hide-pem (&optional arg)
1700 "Toggle hiding of any PEM headers and signatures in the current article.
1701 If given a negative prefix, always show; if given a positive prefix,
1703 (interactive (gnus-article-hidden-arg))
1704 (unless (gnus-article-check-hidden-text 'pem arg)
1706 (let (buffer-read-only end)
1707 (goto-char (point-min))
1708 ;; Hide the horrendously ugly "header".
1709 (when (and (search-forward
1710 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1712 (setq end (1+ (match-beginning 0))))
1713 (push 'pem gnus-article-wash-types)
1714 (gnus-article-hide-text-type
1716 (if (search-forward "\n\n" nil t)
1720 ;; Hide the trailer as well
1721 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1723 (gnus-article-hide-text-type
1724 (match-beginning 0) (match-end 0) 'pem)))))))
1726 (defun article-strip-banner ()
1727 "Strip the banner specified by the `banner' group parameter."
1731 (let ((inhibit-point-motion-hooks t)
1732 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1733 (gnus-signature-limit nil)
1734 buffer-read-only beg end)
1738 ((eq banner 'signature)
1739 (when (gnus-article-narrow-to-signature)
1742 (delete-region (point) (point-max))))
1744 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1745 (while (re-search-forward banner nil t)
1746 (delete-region (match-beginning 0) (match-end 0)))))
1748 (while (re-search-forward banner nil t)
1749 (delete-region (match-beginning 0) (match-end 0))))))))))
1751 (defun article-babel ()
1752 "Translate article using an online translation service."
1756 (set-buffer gnus-article-buffer)
1757 (when (article-goto-body)
1758 (let* ((buffer-read-only nil)
1761 (orig (buffer-substring start end))
1762 (trans (babel-as-string orig)))
1764 (narrow-to-region start end)
1765 (delete-region start end)
1768 (defun article-hide-signature (&optional arg)
1769 "Hide the signature in the current article.
1770 If given a negative prefix, always show; if given a positive prefix,
1772 (interactive (gnus-article-hidden-arg))
1773 (unless (gnus-article-check-hidden-text 'signature arg)
1776 (let ((buffer-read-only nil))
1777 (when (gnus-article-narrow-to-signature)
1778 (gnus-article-hide-text-type
1779 (point-min) (point-max) 'signature)))))))
1781 (defun article-strip-headers-in-body ()
1782 "Strip offensive headers from bodies."
1786 (let ((case-fold-search t))
1787 (when (looking-at "x-no-archive:")
1788 (gnus-delete-line)))))
1790 (defun article-strip-leading-blank-lines ()
1791 "Remove all blank lines from the beginning of the article."
1794 (let ((inhibit-point-motion-hooks t)
1796 (when (article-goto-body)
1797 (while (and (not (eobp))
1798 (looking-at "[ \t]*$"))
1799 (gnus-delete-line))))))
1801 (defun article-narrow-to-head ()
1802 "Narrow the buffer to the head of the message.
1803 Point is left at the beginning of the narrowed-to region."
1805 (goto-char (point-min))
1806 (if (search-forward "\n\n" nil 1)
1809 (goto-char (point-min)))
1811 (defun article-goto-body ()
1812 "Place point at the start of the body."
1813 (goto-char (point-min))
1815 ;; This variable is only bound when dealing with separate
1817 (article-goto-body-goes-to-point-min-p
1819 ((search-forward "\n\n" nil t)
1822 (goto-char (point-max))
1825 (defun article-strip-multiple-blank-lines ()
1826 "Replace consecutive blank lines with one empty line."
1829 (let ((inhibit-point-motion-hooks t)
1831 ;; First make all blank lines empty.
1833 (while (re-search-forward "^[ \t]+$" nil t)
1834 (unless (gnus-annotation-in-region-p
1835 (match-beginning 0) (match-end 0))
1836 (replace-match "" nil t)))
1837 ;; Then replace multiple empty lines with a single empty line.
1839 (while (re-search-forward "\n\n\n+" nil t)
1840 (unless (gnus-annotation-in-region-p
1841 (match-beginning 0) (match-end 0))
1842 (replace-match "\n\n" t t))))))
1844 (defun article-strip-leading-space ()
1845 "Remove all white space from the beginning of the lines in the article."
1848 (let ((inhibit-point-motion-hooks t)
1851 (while (re-search-forward "^[ \t]+" nil t)
1852 (replace-match "" t t)))))
1854 (defun article-strip-trailing-space ()
1855 "Remove all white space from the end of the lines in the article."
1858 (let ((inhibit-point-motion-hooks t)
1861 (while (re-search-forward "[ \t]+$" nil t)
1862 (replace-match "" t t)))))
1864 (defun article-strip-blank-lines ()
1865 "Strip leading, trailing and multiple blank lines."
1867 (article-strip-leading-blank-lines)
1868 (article-remove-trailing-blank-lines)
1869 (article-strip-multiple-blank-lines))
1871 (defun article-strip-all-blank-lines ()
1872 "Strip all blank lines."
1875 (let ((inhibit-point-motion-hooks t)
1878 (while (re-search-forward "^[ \t]*\n" nil t)
1879 (replace-match "" t t)))))
1881 (defun gnus-article-narrow-to-signature ()
1882 "Narrow to the signature; return t if a signature is found, else nil."
1883 (let ((inhibit-point-motion-hooks t))
1884 (when (gnus-article-search-signature)
1886 ;; Check whether we have some limits to what we consider
1887 ;; to be a signature.
1888 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1889 (list gnus-signature-limit)))
1891 (while (setq limit (pop limits))
1892 (if (or (and (integerp limit)
1893 (< (- (point-max) (point)) limit))
1895 (< (count-lines (point) (point-max)) limit))
1896 (and (gnus-functionp limit)
1898 (and (stringp limit)
1899 (not (re-search-forward limit nil t))))
1900 () ; This limit did not succeed.
1904 (narrow-to-region (point) (point-max))
1907 (defun gnus-article-search-signature ()
1908 "Search the current buffer for the signature separator.
1909 Put point at the beginning of the signature separator."
1910 (let ((cur (point)))
1911 (goto-char (point-max))
1912 (if (if (stringp gnus-signature-separator)
1913 (re-search-backward gnus-signature-separator nil t)
1914 (let ((seps gnus-signature-separator))
1916 (not (re-search-backward (car seps) nil t)))
1923 (defun gnus-article-hidden-arg ()
1924 "Return the current prefix arg as a number, or 0 if no prefix."
1925 (list (if current-prefix-arg
1926 (prefix-numeric-value current-prefix-arg)
1929 (defun gnus-article-check-hidden-text (type arg)
1930 "Return nil if hiding is necessary.
1931 Arg can be nil or a number. Nil and positive means hide, negative
1932 means show, 0 means toggle."
1935 (let ((hide (gnus-article-hidden-text-p type)))
1941 (gnus-article-show-hidden-text type))
1943 (if (eq hide 'hidden)
1944 (gnus-article-show-hidden-text type)
1947 (defun gnus-article-hidden-text-p (type)
1948 "Say whether the current buffer contains hidden text of type TYPE."
1949 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1951 (not (get-text-property pos 'invisible))
1952 (not (get-text-property pos 'dummy-invisible)))
1954 (text-property-any (1+ pos) (point-max) 'article-type type)))
1959 (defun gnus-article-show-hidden-text (type &optional hide)
1960 "Show all hidden text of type TYPE.
1961 If HIDE, hide the text instead."
1963 (let ((buffer-read-only nil)
1964 (inhibit-point-motion-hooks t)
1967 (while (setq beg (text-property-any end (point-max) 'article-type type))
1970 (text-property-not-all beg (point-max) 'article-type type)
1973 (gnus-article-hide-text beg end gnus-hidden-properties)
1974 (gnus-article-unhide-text beg end))
1978 (defconst article-time-units
1979 `((year . ,(* 365.25 24 60 60))
1980 (week . ,(* 7 24 60 60))
1981 (day . ,(* 24 60 60))
1985 "Mapping from time units to seconds.")
1987 (defun article-date-ut (&optional type highlight header)
1988 "Convert DATE date to universal time in the current article.
1989 If TYPE is `local', convert to local time; if it is `lapsed', output
1990 how much time has lapsed since DATE. For `lapsed', the value of
1991 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1992 should replace the \"Date:\" one, or should be added below it."
1993 (interactive (list 'ut t))
1994 (let* ((header (or header
1995 (message-fetch-field "date")
1997 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2000 ((not gnus-article-date-lapsed-new-header)
2006 (date (if (vectorp header) (mail-header-date header)
2008 (inhibit-point-motion-hooks t)
2013 (article-narrow-to-head)
2014 (when (re-search-forward tdate-regexp nil t)
2015 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2016 date (or (get-text-property (gnus-point-at-bol)
2019 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2021 (when (and date (not (string= date "")))
2022 (goto-char (point-min))
2023 (let ((buffer-read-only nil))
2024 ;; Delete any old Date headers.
2025 (while (re-search-forward date-regexp nil t)
2027 (delete-region (progn (beginning-of-line) (point))
2028 (progn (forward-line 1) (point)))
2029 (delete-region (progn (beginning-of-line) (point))
2030 (progn (end-of-line) (point)))
2031 (setq pos (point))))
2032 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2034 (if pos (goto-char pos))
2035 (insert (article-make-date-line date (or type 'ut)))
2041 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2042 (put-text-property (match-beginning 1) (1+ (match-end 1))
2043 'original-date date)
2044 (put-text-property (match-beginning 1) (1+ (match-end 1))
2046 (put-text-property (match-beginning 2) (match-end 2)
2049 (defun article-make-date-line (date type)
2050 "Return a DATE line of TYPE."
2051 (let ((time (condition-case ()
2055 ;; Convert to the local timezone. We have to slap a
2056 ;; `condition-case' round the calls to the timezone
2057 ;; functions since they aren't particularly resistant to
2060 (let ((tz (car (current-time-zone time))))
2061 (format "Date: %s %s%02d%02d" (current-time-string time)
2062 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2063 (/ (% (abs tz) 3600) 60))))
2064 ;; Convert to Universal Time.
2067 (current-time-string
2068 (let* ((e (parse-time-string date))
2069 (tm (apply 'encode-time e))
2071 (ls (- (cadr tm) (car (current-time-zone time)))))
2072 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2073 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2076 ;; Get the original date from the article.
2077 ((eq type 'original)
2078 (concat "Date: " (if (string-match "\n+$" date)
2079 (substring date 0 (match-beginning 0))
2081 ;; Let the user define the format.
2083 (if (gnus-functionp gnus-article-time-format)
2084 (funcall gnus-article-time-format time)
2087 (format-time-string gnus-article-time-format time))))
2090 (let ((tz (car (current-time-zone time))))
2093 (format-time-string "%Y%m%dT%H%M%S" time)
2094 (format "%s%02d%02d"
2095 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2096 (/ (% (abs tz) 3600) 60)))))
2097 ;; Do an X-Sent lapsed format.
2099 ;; If the date is seriously mangled, the timezone functions are
2100 ;; liable to bug out, so we ignore all errors.
2101 (let* ((now (current-time))
2102 (real-time (subtract-time now time))
2103 (real-sec (and real-time
2104 (+ (* (float (car real-time)) 65536)
2106 (sec (and real-time (abs real-sec)))
2116 ;; This is a bit convoluted, but basically we go
2117 ;; through the time units for years, weeks, etc,
2118 ;; and divide things to see whether that results
2119 ;; in positive answers.
2122 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2123 ;; The (remaining) seconds are too few to
2124 ;; be divided into this time unit.
2126 ;; It's big enough, so we output it.
2127 (setq sec (- sec (* num (cdr unit))))
2129 (concat (if prev ", " "") (int-to-string
2131 " " (symbol-name (car unit))
2132 (if (> num 1) "s" ""))
2134 article-time-units "")
2135 ;; If dates are odd, then it might appear like the
2136 ;; article was sent in the future.
2139 " in the future"))))))
2141 (error "Unknown conversion type: %s" type)))))
2143 (defun article-date-local (&optional highlight)
2144 "Convert the current article date to the local timezone."
2145 (interactive (list t))
2146 (article-date-ut 'local highlight))
2148 (defun article-date-original (&optional highlight)
2149 "Convert the current article date to what it was originally.
2150 This is only useful if you have used some other date conversion
2151 function and want to see what the date was before converting."
2152 (interactive (list t))
2153 (article-date-ut 'original highlight))
2155 (defun article-date-lapsed (&optional highlight)
2156 "Convert the current article date to time lapsed since it was sent."
2157 (interactive (list t))
2158 (article-date-ut 'lapsed highlight))
2160 (defun article-update-date-lapsed ()
2161 "Function to be run from a timer to update the lapsed time line."
2162 (let (deactivate-mark)
2167 (set-buffer (window-buffer w))
2168 (when (eq major-mode 'gnus-article-mode)
2169 (goto-char (point-min))
2170 (when (re-search-forward "^X-Sent:" nil t)
2171 (article-date-lapsed t))))
2174 (defun gnus-start-date-timer (&optional n)
2175 "Start a timer to update the X-Sent header in the article buffers.
2176 The numerical prefix says how frequently (in seconds) the function
2181 (gnus-stop-date-timer)
2182 (setq article-lapsed-timer
2183 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2185 (defun gnus-stop-date-timer ()
2186 "Stop the X-Sent timer."
2188 (when article-lapsed-timer
2189 (nnheader-cancel-timer article-lapsed-timer)
2190 (setq article-lapsed-timer nil)))
2192 (defun article-date-user (&optional highlight)
2193 "Convert the current article date to the user-defined format.
2194 This format is defined by the `gnus-article-time-format' variable."
2195 (interactive (list t))
2196 (article-date-ut 'user highlight))
2198 (defun article-date-iso8601 (&optional highlight)
2199 "Convert the current article date to ISO8601."
2200 (interactive (list t))
2201 (article-date-ut 'iso8601 highlight))
2203 (defun article-show-all ()
2204 "Show all hidden text in the article buffer."
2207 (let ((buffer-read-only nil))
2208 (gnus-article-unhide-text (point-min) (point-max)))))
2210 (defun article-emphasize (&optional arg)
2211 "Emphasize text according to `gnus-emphasis-alist'."
2212 (interactive (gnus-article-hidden-arg))
2213 (unless (gnus-article-check-hidden-text 'emphasis arg)
2217 (with-current-buffer gnus-summary-buffer
2218 gnus-article-emphasis-alist)
2220 gnus-emphasis-alist))
2221 (buffer-read-only nil)
2222 (props (append '(article-type emphasis)
2223 gnus-hidden-properties))
2224 regexp elem beg invisible visible face)
2227 (while (setq elem (pop alist))
2229 (setq regexp (car elem)
2230 invisible (nth 1 elem)
2231 visible (nth 2 elem)
2233 (while (re-search-forward regexp nil t)
2234 (when (and (match-beginning visible) (match-beginning invisible))
2235 (push 'emphasis gnus-article-wash-types)
2236 (gnus-article-hide-text
2237 (match-beginning invisible) (match-end invisible) props)
2238 (gnus-article-unhide-text-type
2239 (match-beginning visible) (match-end visible) 'emphasis)
2240 (gnus-put-text-property-excluding-newlines
2241 (match-beginning visible) (match-end visible) 'face face)
2242 (goto-char (match-end invisible)))))))))
2244 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2245 "Setup newsgroup emphasis alist."
2246 (unless gnus-article-emphasis-alist
2247 (let ((name (and gnus-newsgroup-name
2248 (gnus-group-real-name gnus-newsgroup-name))))
2249 (make-local-variable 'gnus-article-emphasis-alist)
2250 (setq gnus-article-emphasis-alist
2252 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2253 (while (setq elem (pop alist))
2254 (when (and name (string-match (car elem) name))
2256 highlight (copy-sequence (cdr elem)))))
2258 (copy-sequence highlight-words)
2259 (if gnus-newsgroup-name
2260 (copy-sequence (gnus-group-find-parameter
2261 gnus-newsgroup-name 'highlight-words t)))
2262 gnus-emphasis-alist)))))
2264 (defvar gnus-summary-article-menu)
2265 (defvar gnus-summary-post-menu)
2267 ;;; Saving functions.
2269 (defun gnus-article-save (save-buffer file &optional num)
2270 "Save the currently selected article."
2271 (unless gnus-save-all-headers
2272 ;; Remove headers according to `gnus-saved-headers'.
2273 (let ((gnus-visible-headers
2274 (or gnus-saved-headers gnus-visible-headers))
2275 (gnus-article-buffer save-buffer))
2277 (set-buffer save-buffer)
2278 (article-hide-headers 1 t))))
2279 (save-window-excursion
2280 (if (not gnus-default-article-saver)
2281 (error "No default saver is defined")
2282 ;; !!! Magic! The saving functions all save
2283 ;; `gnus-save-article-buffer' (or so they think), but we
2284 ;; bind that variable to our save-buffer.
2285 (set-buffer gnus-article-buffer)
2286 (let* ((gnus-save-article-buffer save-buffer)
2289 ((not gnus-prompt-before-saving) 'default)
2290 ((eq gnus-prompt-before-saving 'always) nil)
2292 (gnus-number-of-articles-to-be-saved
2293 (when (eq gnus-prompt-before-saving t)
2295 (set-buffer gnus-article-current-summary)
2296 (funcall gnus-default-article-saver filename)))))
2298 (defun gnus-read-save-file-name (prompt &optional filename
2299 function group headers variable)
2301 (funcall function group headers (symbol-value variable)))
2306 ((eq filename 'default)
2312 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2315 (if (and gnus-number-of-articles-to-be-saved
2316 (> gnus-number-of-articles-to-be-saved 1))
2317 (format "these %d articles"
2318 gnus-number-of-articles-to-be-saved)
2321 ;; Let the split methods have their say.
2323 ;; No split name was found.
2326 (concat prompt " (default "
2327 (file-name-nondirectory default-name) ") ")
2328 (file-name-directory default-name)
2330 ;; A single group name is returned.
2331 ((stringp split-name)
2333 (funcall function split-name headers
2334 (symbol-value variable)))
2336 (concat prompt " (default "
2337 (file-name-nondirectory default-name) ") ")
2338 (file-name-directory default-name)
2340 ;; A single split name was found
2341 ((= 1 (length split-name))
2342 (let* ((name (expand-file-name
2343 (car split-name) gnus-article-save-directory))
2344 (dir (cond ((file-directory-p name)
2345 (file-name-as-directory name))
2346 ((file-exists-p name) name)
2347 (t gnus-article-save-directory))))
2349 (concat prompt " (default " name ") ")
2351 ;; A list of splits was found.
2353 (setq split-name (nreverse split-name))
2355 (let ((file-name-history
2356 (nconc split-name file-name-history)))
2360 (concat prompt " (`M-p' for defaults) ")
2361 gnus-article-save-directory
2363 gnus-article-save-directory)))
2364 (car (push result file-name-history)))))))
2365 ;; Create the directory.
2366 (gnus-make-directory (file-name-directory file))
2367 ;; If we have read a directory, we append the default file name.
2368 (when (file-directory-p file)
2369 (setq file (expand-file-name (file-name-nondirectory default-name)
2370 (file-name-as-directory file))))
2371 ;; Possibly translate some characters.
2372 (nnheader-translate-file-chars file))))))
2373 (gnus-make-directory (file-name-directory result))
2374 (set variable result)))
2376 (defun gnus-article-archive-name (group)
2377 "Return the first instance of an \"Archive-name\" in the current buffer."
2378 (let ((case-fold-search t))
2379 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2380 (nnheader-concat gnus-article-save-directory
2381 (match-string 1)))))
2383 (defun gnus-article-nndoc-name (group)
2384 "If GROUP is an nndoc group, return the name of the parent group."
2385 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2386 (gnus-group-get-parameter group 'save-article-group)))
2388 (defun gnus-summary-save-in-rmail (&optional filename)
2389 "Append this article to Rmail file.
2390 Optional argument FILENAME specifies file name.
2391 Directory to save to is default to `gnus-article-save-directory'."
2392 (setq filename (gnus-read-save-file-name
2393 "Save %s in rmail file:" filename
2394 gnus-rmail-save-name gnus-newsgroup-name
2395 gnus-current-headers 'gnus-newsgroup-last-rmail))
2396 (gnus-eval-in-buffer-window gnus-save-article-buffer
2400 (gnus-output-to-rmail filename))))
2403 (defun gnus-summary-save-in-mail (&optional filename)
2404 "Append this article to Unix mail file.
2405 Optional argument FILENAME specifies file name.
2406 Directory to save to is default to `gnus-article-save-directory'."
2407 (setq filename (gnus-read-save-file-name
2408 "Save %s in Unix mail file:" filename
2409 gnus-mail-save-name gnus-newsgroup-name
2410 gnus-current-headers 'gnus-newsgroup-last-mail))
2411 (gnus-eval-in-buffer-window gnus-save-article-buffer
2415 (if (and (file-readable-p filename)
2416 (mail-file-babyl-p filename))
2417 (rmail-output-to-rmail-file filename t)
2418 (gnus-output-to-mail filename)))))
2421 (defun gnus-summary-save-in-file (&optional filename overwrite)
2422 "Append this article to file.
2423 Optional argument FILENAME specifies file name.
2424 Directory to save to is default to `gnus-article-save-directory'."
2425 (setq filename (gnus-read-save-file-name
2426 "Save %s in file:" filename
2427 gnus-file-save-name gnus-newsgroup-name
2428 gnus-current-headers 'gnus-newsgroup-last-file))
2429 (gnus-eval-in-buffer-window gnus-save-article-buffer
2433 (when (and overwrite
2434 (file-exists-p filename))
2435 (delete-file filename))
2436 (gnus-output-to-file filename))))
2439 (defun gnus-summary-write-to-file (&optional filename)
2440 "Write this article to a file.
2441 Optional argument FILENAME specifies file name.
2442 The directory to save in defaults to `gnus-article-save-directory'."
2443 (gnus-summary-save-in-file nil t))
2445 (defun gnus-summary-save-body-in-file (&optional filename)
2446 "Append this article body to a file.
2447 Optional argument FILENAME specifies file name.
2448 The directory to save in defaults to `gnus-article-save-directory'."
2449 (setq filename (gnus-read-save-file-name
2450 "Save %s body in file:" filename
2451 gnus-file-save-name gnus-newsgroup-name
2452 gnus-current-headers 'gnus-newsgroup-last-file))
2453 (gnus-eval-in-buffer-window gnus-save-article-buffer
2457 (when (article-goto-body)
2458 (narrow-to-region (point) (point-max)))
2459 (gnus-output-to-file filename))))
2462 (defun gnus-summary-save-in-pipe (&optional command)
2463 "Pipe this article to subprocess."
2465 (cond ((and (eq command 'default)
2466 gnus-last-shell-command)
2467 gnus-last-shell-command)
2471 "Shell command on %s: "
2472 (if (and gnus-number-of-articles-to-be-saved
2473 (> gnus-number-of-articles-to-be-saved 1))
2474 (format "these %d articles"
2475 gnus-number-of-articles-to-be-saved)
2477 gnus-last-shell-command))))
2478 (when (string-equal command "")
2479 (setq command gnus-last-shell-command))
2480 (gnus-eval-in-buffer-window gnus-article-buffer
2483 (shell-command-on-region (point-min) (point-max) command nil)))
2484 (setq gnus-last-shell-command command))
2486 ;;; Article file names when saving.
2488 (defun gnus-capitalize-newsgroup (newsgroup)
2489 "Capitalize NEWSGROUP name."
2490 (when (not (zerop (length newsgroup)))
2491 (concat (char-to-string (upcase (aref newsgroup 0)))
2492 (substring newsgroup 1))))
2494 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2495 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2496 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2497 Otherwise, it is like ~/News/news/group/num."
2500 (concat (if (gnus-use-long-file-name 'not-save)
2501 (gnus-capitalize-newsgroup newsgroup)
2502 (gnus-newsgroup-directory-form newsgroup))
2503 "/" (int-to-string (mail-header-number headers)))
2504 gnus-article-save-directory)))
2506 (string-equal (file-name-directory default)
2507 (file-name-directory last-file))
2508 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2510 (or last-file default))))
2512 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2513 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2514 If variable `gnus-use-long-file-name' is non-nil, it is
2515 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2518 (concat (if (gnus-use-long-file-name 'not-save)
2520 (gnus-newsgroup-directory-form newsgroup))
2521 "/" (int-to-string (mail-header-number headers)))
2522 gnus-article-save-directory)))
2524 (string-equal (file-name-directory default)
2525 (file-name-directory last-file))
2526 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2528 (or last-file default))))
2530 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2531 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2532 If variable `gnus-use-long-file-name' is non-nil, it is
2533 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2536 (if (gnus-use-long-file-name 'not-save)
2538 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2539 gnus-article-save-directory)))
2546 (setq afunc (car func)
2549 gfunc (intern (format "gnus-%s" func))))
2552 `(lambda (&optional interactive &rest args)
2553 ,(documentation afunc t)
2554 (interactive (list t))
2556 (set-buffer gnus-article-buffer)
2558 (call-interactively ',afunc)
2559 (apply ',afunc args))))))))
2560 '(article-hide-headers
2561 article-hide-boring-headers
2562 article-treat-overstrike
2563 article-fill-long-lines
2564 article-capitalize-sentences
2566 article-display-x-face
2567 article-de-quoted-unreadable
2568 article-de-base64-unreadable
2571 article-hide-list-identifiers
2573 article-strip-banner
2576 article-hide-signature
2577 article-strip-headers-in-body
2578 article-remove-trailing-blank-lines
2579 article-strip-leading-blank-lines
2580 article-strip-multiple-blank-lines
2581 article-strip-leading-space
2582 article-strip-trailing-space
2583 article-strip-blank-lines
2584 article-strip-all-blank-lines
2586 article-date-iso8601
2587 article-date-original
2589 article-decode-mime-words
2590 article-decode-charset
2591 article-decode-encoded-words
2595 article-treat-dumbquotes
2596 article-normalize-headers
2597 (article-show-all . gnus-article-show-all-headers))))
2600 ;;; Gnus article mode
2603 (put 'gnus-article-mode 'mode-class 'special)
2605 (set-keymap-parent gnus-article-mode-map widget-keymap)
2607 (gnus-define-keys gnus-article-mode-map
2608 " " gnus-article-goto-next-page
2609 "\177" gnus-article-goto-prev-page
2610 [delete] gnus-article-goto-prev-page
2611 [backspace] gnus-article-goto-prev-page
2612 "\C-c^" gnus-article-refer-article
2613 "h" gnus-article-show-summary
2614 "s" gnus-article-show-summary
2615 "\C-c\C-m" gnus-article-mail
2616 "?" gnus-article-describe-briefly
2617 "e" gnus-summary-edit-article
2618 "<" beginning-of-buffer
2620 "\C-c\C-i" gnus-info-find-node
2623 "\C-d" gnus-article-read-summary-keys
2624 "\M-*" gnus-article-read-summary-keys
2625 "\M-#" gnus-article-read-summary-keys
2626 "\M-^" gnus-article-read-summary-keys
2627 "\M-g" gnus-article-read-summary-keys)
2629 (substitute-key-definition
2630 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2632 (defun gnus-article-make-menu-bar ()
2633 (gnus-turn-off-edit-menu 'article)
2634 (unless (boundp 'gnus-article-article-menu)
2636 gnus-article-article-menu gnus-article-mode-map ""
2638 ["Scroll forwards" gnus-article-goto-next-page t]
2639 ["Scroll backwards" gnus-article-goto-prev-page t]
2640 ["Show summary" gnus-article-show-summary t]
2641 ["Fetch Message-ID at point" gnus-article-refer-article t]
2642 ["Mail to address at point" gnus-article-mail t]
2643 ["Send a bug report" gnus-bug t]))
2646 gnus-article-treatment-menu gnus-article-mode-map ""
2648 ["Hide headers" gnus-article-hide-headers t]
2649 ["Hide signature" gnus-article-hide-signature t]
2650 ["Hide citation" gnus-article-hide-citation t]
2651 ["Treat overstrike" gnus-article-treat-overstrike t]
2652 ["Remove carriage return" gnus-article-remove-cr t]
2653 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2654 ["Remove base64" gnus-article-de-base64-unreadable t]
2655 ["Treat html" gnus-article-wash-html t]
2656 ["Decode HZ" gnus-article-decode-HZ t]))
2658 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2660 (when (boundp 'gnus-summary-post-menu)
2661 (define-key gnus-article-mode-map [menu-bar post]
2662 (cons "Post" gnus-summary-post-menu)))
2664 (gnus-run-hooks 'gnus-article-menu-hook)))
2666 (defun gnus-article-mode ()
2667 "Major mode for displaying an article.
2669 All normal editing commands are switched off.
2671 The following commands are available in addition to all summary mode
2673 \\<gnus-article-mode-map>
2674 \\[gnus-article-next-page]\t Scroll the article one page forwards
2675 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2676 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2677 \\[gnus-article-show-summary]\t Display the summary buffer
2678 \\[gnus-article-mail]\t Send a reply to the address near point
2679 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2680 \\[gnus-info-find-node]\t Go to the Gnus info node"
2682 (when (gnus-visual-p 'article-menu 'menu)
2683 (gnus-article-make-menu-bar))
2684 (gnus-simplify-mode-line)
2685 (setq mode-name "Article")
2686 (setq major-mode 'gnus-article-mode)
2687 (make-local-variable 'minor-mode-alist)
2688 (use-local-map gnus-article-mode-map)
2689 (gnus-update-format-specifications nil 'article-mode)
2690 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2691 (make-local-variable 'gnus-page-broken)
2692 (make-local-variable 'gnus-button-marker-list)
2693 (make-local-variable 'gnus-article-current-summary)
2694 (make-local-variable 'gnus-article-mime-handles)
2695 (make-local-variable 'gnus-article-decoded-p)
2696 (make-local-variable 'gnus-article-mime-handle-alist)
2697 (make-local-variable 'gnus-article-wash-types)
2698 (gnus-set-default-directory)
2699 (buffer-disable-undo)
2700 (setq buffer-read-only t)
2701 (set-syntax-table gnus-article-mode-syntax-table)
2702 (mm-enable-multibyte)
2703 (gnus-run-hooks 'gnus-article-mode-hook))
2705 (defun gnus-article-setup-buffer ()
2706 "Initialize the article buffer."
2707 (let* ((name (if gnus-single-article-buffer "*Article*"
2708 (concat "*Article " gnus-newsgroup-name "*")))
2710 (progn (string-match "\\*Article" name)
2711 (concat " *Original Article"
2712 (substring name (match-end 0))))))
2713 (setq gnus-article-buffer name)
2714 (setq gnus-original-article-buffer original)
2715 (setq gnus-article-mime-handle-alist nil)
2716 ;; This might be a variable local to the summary buffer.
2717 (unless gnus-single-article-buffer
2719 (set-buffer gnus-summary-buffer)
2720 (setq gnus-article-buffer name)
2721 (setq gnus-original-article-buffer original)
2722 (gnus-set-global-variables)))
2723 (gnus-article-setup-highlight-words)
2724 ;; Init original article buffer.
2726 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2727 (mm-enable-multibyte)
2728 (setq major-mode 'gnus-original-article-mode)
2729 (make-local-variable 'gnus-original-article))
2730 (if (get-buffer name)
2733 (when gnus-article-mime-handles
2734 (mm-destroy-parts gnus-article-mime-handles)
2735 (setq gnus-article-mime-handles nil))
2736 ;; Set it to nil in article-buffer!
2737 (setq gnus-article-mime-handle-alist nil)
2738 (buffer-disable-undo)
2739 (setq buffer-read-only t)
2740 (unless (eq major-mode 'gnus-article-mode)
2741 (gnus-article-mode))
2744 (set-buffer (gnus-get-buffer-create name))
2746 (make-local-variable 'gnus-summary-buffer)
2747 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2748 (current-buffer)))))
2750 ;; Set article window start at LINE, where LINE is the number of lines
2751 ;; from the head of the article.
2752 (defun gnus-article-set-window-start (&optional line)
2754 (get-buffer-window gnus-article-buffer t)
2756 (set-buffer gnus-article-buffer)
2757 (goto-char (point-min))
2760 (gnus-message 6 "Moved to bookmark")
2761 (search-forward "\n\n" nil t)
2765 (defun gnus-article-prepare (article &optional all-headers header)
2766 "Prepare ARTICLE in article mode buffer.
2767 ARTICLE should either be an article number or a Message-ID.
2768 If ARTICLE is an id, HEADER should be the article headers.
2769 If ALL-HEADERS is non-nil, no headers are hidden."
2771 ;; Make sure we start in a summary buffer.
2772 (unless (eq major-mode 'gnus-summary-mode)
2773 (set-buffer gnus-summary-buffer))
2774 (setq gnus-summary-buffer (current-buffer))
2775 (let* ((gnus-article (if header (mail-header-number header) article))
2776 (summary-buffer (current-buffer))
2777 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2778 (group gnus-newsgroup-name)
2781 (gnus-article-setup-buffer)
2782 (set-buffer gnus-article-buffer)
2783 ;; Deactivate active regions.
2784 (when (and (boundp 'transient-mark-mode)
2785 transient-mark-mode)
2786 (setq mark-active nil))
2787 (if (not (setq result (let ((buffer-read-only nil))
2788 (gnus-request-article-this-buffer
2790 ;; There is no such article.
2792 (when (and (numberp article)
2793 (not (memq article gnus-newsgroup-sparse)))
2794 (setq gnus-article-current
2795 (cons gnus-newsgroup-name article))
2796 (set-buffer gnus-summary-buffer)
2797 (setq gnus-current-article article)
2798 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2800 (gnus-summary-set-agent-mark article)
2801 (message "Message marked for downloading"))
2802 (gnus-summary-mark-article article gnus-canceled-mark)
2803 (unless (memq article gnus-newsgroup-sparse)
2804 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2805 (if (or (eq result 'pseudo)
2806 (eq result 'nneething))
2809 (set-buffer summary-buffer)
2810 (push article gnus-newsgroup-history)
2811 (setq gnus-last-article gnus-current-article
2812 gnus-current-article 0
2813 gnus-current-headers nil
2814 gnus-article-current nil)
2815 (if (eq result 'nneething)
2816 (gnus-configure-windows 'summary)
2817 (gnus-configure-windows 'article))
2818 (gnus-set-global-variables))
2819 (let ((gnus-article-mime-handle-alist-1
2820 gnus-article-mime-handle-alist))
2821 (gnus-set-mode-line 'article)))
2822 ;; The result from the `request' was an actual article -
2823 ;; or at least some text that is now displayed in the
2825 (when (and (numberp article)
2826 (not (eq article gnus-current-article)))
2827 ;; Seems like a new article has been selected.
2828 ;; `gnus-current-article' must be an article number.
2830 (set-buffer summary-buffer)
2831 (push article gnus-newsgroup-history)
2832 (setq gnus-last-article gnus-current-article
2833 gnus-current-article article
2834 gnus-current-headers
2835 (gnus-summary-article-header gnus-current-article)
2836 gnus-article-current
2837 (cons gnus-newsgroup-name gnus-current-article))
2838 (unless (vectorp gnus-current-headers)
2839 (setq gnus-current-headers nil))
2840 (gnus-summary-goto-subject gnus-current-article)
2841 (when (gnus-summary-show-thread)
2842 ;; If the summary buffer really was folded, the
2843 ;; previous goto may not actually have gone to
2844 ;; the right article, but the thread root instead.
2846 (gnus-summary-goto-subject gnus-current-article))
2847 (gnus-run-hooks 'gnus-mark-article-hook)
2848 (gnus-set-mode-line 'summary)
2849 (when (gnus-visual-p 'article-highlight 'highlight)
2850 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2851 ;; Set the global newsgroup variables here.
2852 (gnus-set-global-variables)
2853 (setq gnus-have-all-headers
2854 (or all-headers gnus-show-all-headers))))
2856 (gnus-configure-windows 'article))
2857 (when (or (numberp article)
2859 (gnus-article-prepare-display)
2861 (goto-char (point-min))
2862 (setq gnus-page-broken
2863 (when gnus-break-pages
2864 (gnus-narrow-to-page)
2866 (let ((gnus-article-mime-handle-alist-1
2867 gnus-article-mime-handle-alist))
2868 (gnus-set-mode-line 'article))
2870 (set-window-point (get-buffer-window (current-buffer)) (point))
2871 (gnus-configure-windows 'article)
2875 (defun gnus-article-prepare-display ()
2876 "Make the current buffer look like a nice article."
2877 ;; Hooks for getting information from the article.
2878 ;; This hook must be called before being narrowed.
2879 (let ((gnus-article-buffer (current-buffer))
2881 (unless (eq major-mode 'gnus-article-mode)
2882 (gnus-article-mode))
2883 (setq buffer-read-only nil
2884 gnus-article-wash-types nil)
2885 (gnus-run-hooks 'gnus-tmp-internal-hook)
2886 (when gnus-display-mime-function
2887 (funcall gnus-display-mime-function))
2888 (gnus-run-hooks 'gnus-article-prepare-hook)))
2891 ;;; Gnus MIME viewing functions
2894 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2895 "The following specs can be used:
2897 %T MIME type, along with additional info
2898 %n The `name' parameter
2899 %d The description, if any
2900 %l The length of the encoded part
2901 %p The part identifier number
2902 %e Dots if the part isn't displayed")
2904 (defvar gnus-mime-button-line-format-alist
2905 '((?t gnus-tmp-type ?s)
2906 (?T gnus-tmp-type-long ?s)
2907 (?n gnus-tmp-name ?s)
2908 (?d gnus-tmp-description ?s)
2910 (?l gnus-tmp-length ?d)
2911 (?e gnus-tmp-dots ?s)))
2913 (defvar gnus-mime-button-commands
2914 '((gnus-article-press-button "\r" "Toggle Display")
2915 (gnus-mime-view-part "v" "View Interactively...")
2916 (gnus-mime-view-part-as-type "t" "View As Type...")
2917 (gnus-mime-save-part "o" "Save...")
2918 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2919 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2920 (gnus-mime-internalize-part "E" "View Internally")
2921 (gnus-mime-externalize-part "e" "View Externally")
2922 (gnus-mime-pipe-part "|" "Pipe To Command...")
2923 (gnus-mime-action-on-part "." "Take action on the part")))
2925 (defun gnus-article-mime-part-status ()
2926 (if gnus-article-mime-handle-alist-1
2927 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2930 (defvar gnus-mime-button-map
2931 (let ((map (make-sparse-keymap)))
2932 (set-keymap-parent map gnus-article-mode-map)
2933 (define-key map gnus-mouse-2 'gnus-article-push-button)
2934 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2935 (dolist (c gnus-mime-button-commands)
2936 (define-key map (cadr c) (car c)))
2939 (defun gnus-mime-button-menu (event)
2940 "Construct a context-sensitive menu of MIME commands."
2943 (let ((pos (event-start event)))
2944 (set-buffer (window-buffer (posn-window pos)))
2945 (goto-char (posn-point pos))
2946 (gnus-article-check-buffer)
2947 (let ((response (x-popup-menu
2949 ("" ,@(mapcar (lambda (c)
2950 (cons (caddr c) (car c)))
2951 gnus-mime-button-commands))))))
2953 (call-interactively response))))))
2955 (defun gnus-mime-view-all-parts (&optional handles)
2956 "View all the MIME parts."
2958 (save-current-buffer
2959 (set-buffer gnus-article-buffer)
2960 (let ((handles (or handles gnus-article-mime-handles))
2961 (mail-parse-charset gnus-newsgroup-charset)
2962 (mail-parse-ignored-charsets
2963 (save-excursion (set-buffer gnus-summary-buffer)
2964 gnus-newsgroup-ignored-charsets)))
2965 (if (stringp (car handles))
2966 (gnus-mime-view-all-parts (cdr handles))
2967 (mapcar 'mm-display-part handles)))))
2969 (defun gnus-mime-save-part ()
2970 "Save the MIME part under point."
2972 (gnus-article-check-buffer)
2973 (let ((data (get-text-property (point) 'gnus-data)))
2974 (mm-save-part data)))
2976 (defun gnus-mime-pipe-part ()
2977 "Pipe the MIME part under point to a process."
2979 (gnus-article-check-buffer)
2980 (let ((data (get-text-property (point) 'gnus-data)))
2981 (mm-pipe-part data)))
2983 (defun gnus-mime-view-part ()
2984 "Interactively choose a viewing method for the MIME part under point."
2986 (gnus-article-check-buffer)
2987 (let ((data (get-text-property (point) 'gnus-data)))
2988 (mm-interactively-view-part data)))
2990 (defun gnus-mime-view-part-as-type-internal ()
2991 (gnus-article-check-buffer)
2992 (let* ((name (mail-content-type-get
2993 (mm-handle-type (get-text-property (point) 'gnus-data))
2995 (def-type (and name (mm-default-file-encoding name))))
2996 (and def-type (cons def-type 0))))
2998 (defun gnus-mime-view-part-as-type (mime-type)
2999 "Choose a MIME media type, and view the part as such."
3001 (list (completing-read
3002 "View as MIME type: "
3003 (mapcar #'list (mailcap-mime-types))
3005 (gnus-mime-view-part-as-type-internal))))
3006 (gnus-article-check-buffer)
3007 (let ((handle (get-text-property (point) 'gnus-data)))
3008 (gnus-mm-display-part
3009 (mm-make-handle (mm-handle-buffer handle)
3010 (cons mime-type (cdr (mm-handle-type handle)))
3011 (mm-handle-encoding handle)
3012 (mm-handle-undisplayer handle)
3013 (mm-handle-disposition handle)
3014 (mm-handle-description handle)
3015 (mm-handle-cache handle)
3016 (mm-handle-id handle)))))
3018 (defun gnus-mime-copy-part (&optional handle)
3019 "Put the the MIME part under point into a new buffer."
3021 (gnus-article-check-buffer)
3022 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3023 (contents (mm-get-part handle))|
3024 (base (file-name-nondirectory
3026 (mail-content-type-get (mm-handle-type handle) 'name)
3027 (mail-content-type-get (mm-handle-type handle)
3030 (buffer (generate-new-buffer base)))
3031 (switch-to-buffer buffer)
3033 ;; We do it this way to make `normal-mode' set the appropriate mode.
3036 (setq buffer-file-name (expand-file-name base))
3038 (setq buffer-file-name nil))
3039 (goto-char (point-min))))
3041 (defun gnus-mime-inline-part (&optional handle arg)
3042 "Insert the MIME part under point into the current buffer."
3043 (interactive (list nil current-prefix-arg))
3044 (gnus-article-check-buffer)
3045 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3049 (if (mm-handle-undisplayer handle)
3050 (mm-remove-part handle)
3051 (setq contents (mm-get-part handle))
3054 (setq charset (or (mail-content-type-get
3055 (mm-handle-type handle) 'charset)
3056 gnus-newsgroup-charset)))
3060 gnus-summary-show-article-charset-alist))
3061 (read-coding-system "Charset: ")))))
3063 (mm-insert-inline handle
3065 (setq charset (mm-charset-to-coding-system
3067 (not (eq charset 'ascii)))
3068 (mm-decode-coding-string contents charset)
3072 (defun gnus-mime-externalize-part (&optional handle)
3073 "View the MIME part under point with an external viewer."
3075 (gnus-article-check-buffer)
3076 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3077 (mm-user-display-methods nil)
3078 (mm-inlined-types nil)
3079 (mail-parse-charset gnus-newsgroup-charset)
3080 (mail-parse-ignored-charsets
3081 (save-excursion (set-buffer gnus-summary-buffer)
3082 gnus-newsgroup-ignored-charsets)))
3083 (if (mm-handle-undisplayer handle)
3084 (mm-remove-part handle)
3085 (mm-display-part handle))))
3087 (defun gnus-mime-internalize-part (&optional handle)
3088 "View the MIME part under point with an internal viewer.
3089 In no internal viewer is available, use an external viewer."
3091 (gnus-article-check-buffer)
3092 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3093 (mm-inlined-types '(".*"))
3094 (mm-inline-large-images t)
3095 (mail-parse-charset gnus-newsgroup-charset)
3096 (mail-parse-ignored-charsets
3097 (save-excursion (set-buffer gnus-summary-buffer)
3098 gnus-newsgroup-ignored-charsets)))
3099 (if (mm-handle-undisplayer handle)
3100 (mm-remove-part handle)
3101 (mm-display-part handle))))
3103 (defun gnus-mime-action-on-part (&optional action)
3104 "Do something with the MIME attachment at \(point\)."
3106 (list (completing-read "Action: " gnus-mime-action-alist)))
3107 (gnus-article-check-buffer)
3108 (let ((action-pair (assoc action gnus-mime-action-alist)))
3110 (funcall (cdr action-pair)))))
3113 (defun gnus-article-part-wrapper (n function)
3114 (save-current-buffer
3115 (set-buffer gnus-article-buffer)
3116 (when (> n (length gnus-article-mime-handle-alist))
3117 (error "No such part"))
3118 (gnus-article-goto-part n)
3119 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3120 (funcall function handle))))
3122 (defun gnus-article-pipe-part (n)
3123 "Pipe MIME part N, which is the numerical prefix."
3125 (gnus-article-part-wrapper n 'mm-pipe-part))
3127 (defun gnus-article-save-part (n)
3128 "Save MIME part N, which is the numerical prefix."
3130 (gnus-article-part-wrapper n 'mm-save-part))
3132 (defun gnus-article-interactively-view-part (n)
3133 "View MIME part N interactively, which is the numerical prefix."
3135 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3137 (defun gnus-article-copy-part (n)
3138 "Copy MIME part N, which is the numerical prefix."
3140 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3142 (defun gnus-article-externalize-part (n)
3143 "View MIME part N externally, which is the numerical prefix."
3145 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3147 (defun gnus-article-inline-part (n)
3148 "Inline MIME part N, which is the numerical prefix."
3150 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3152 (defun gnus-article-mime-match-handle-first (condition)
3154 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3155 (while (setq ihandle (pop alist))
3157 ((functionp condition)
3158 (funcall condition (cdr ihandle)))
3159 ((eq condition 'undisplayed)
3160 (not (or (mm-handle-undisplayer (cdr ihandle))
3161 (equal (mm-handle-media-type (cdr ihandle))
3162 "multipart/alternative"))))
3163 ((eq condition 'undisplayed-alternative)
3164 (not (mm-handle-undisplayer (cdr ihandle))))
3166 (gnus-article-goto-part (car ihandle))
3167 (or (not n) (< (car ihandle) n)))
3168 (setq n (car ihandle))))
3172 (defun gnus-article-view-part (&optional n)
3173 "View MIME part N, which is the numerical prefix."
3175 (save-current-buffer
3176 (set-buffer gnus-article-buffer)
3177 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3178 gnus-article-mime-match-handle-function)))
3179 (when (> n (length gnus-article-mime-handle-alist))
3180 (error "No such part"))
3181 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3182 (when (gnus-article-goto-part n)
3183 (if (equal (car handle) "multipart/alternative")
3184 (gnus-article-press-button)
3185 (when (eq (gnus-mm-display-part handle) 'internal)
3186 (gnus-set-window-start)))))))
3188 (defsubst gnus-article-mime-total-parts ()
3189 (if (bufferp (car gnus-article-mime-handles))
3191 (1- (length gnus-article-mime-handles))))
3193 (defun gnus-mm-display-part (handle)
3194 "Display HANDLE and fix MIME button."
3195 (let ((id (get-text-property (point) 'gnus-part))
3200 (let ((window (selected-window))
3201 (mail-parse-charset gnus-newsgroup-charset)
3202 (mail-parse-ignored-charsets
3203 (save-excursion (set-buffer gnus-summary-buffer)
3204 gnus-newsgroup-ignored-charsets)))
3207 (let ((win (get-buffer-window (current-buffer) t))
3210 (select-window win))
3213 (if (mm-handle-displayed-p handle)
3214 ;; This will remove the part.
3215 (mm-display-part handle)
3217 (narrow-to-region (point) (1+ (point)))
3218 (mm-display-part handle)
3219 ;; We narrow to the part itself and
3220 ;; then call the treatment functions.
3221 (goto-char (point-min))
3223 (narrow-to-region (point) (point-max))
3226 (gnus-article-mime-total-parts)
3227 (mm-handle-media-type handle)))))
3228 (select-window window))))
3230 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3231 (gnus-insert-mime-button
3232 handle id (list (mm-handle-displayed-p handle)))
3233 (goto-char point))))
3235 (defun gnus-article-goto-part (n)
3236 "Go to MIME part N."
3237 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3239 (goto-char point))))
3241 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3242 (let ((gnus-tmp-name
3243 (or (mail-content-type-get (mm-handle-type handle)
3245 (mail-content-type-get (mm-handle-disposition handle)
3248 (gnus-tmp-type (mm-handle-media-type handle))
3249 (gnus-tmp-description
3250 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3253 (if (if displayed (car displayed)
3254 (mm-handle-displayed-p handle))
3256 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3258 gnus-tmp-type-long b e)
3259 (when (string-match ".*/" gnus-tmp-name)
3260 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3261 (setq gnus-tmp-type-long (concat gnus-tmp-type
3262 (and (not (equal gnus-tmp-name ""))
3263 (concat "; " gnus-tmp-name))))
3264 (or (equal gnus-tmp-description "")
3265 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3270 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3271 `(local-map ,gnus-mime-button-map
3272 keymap ,gnus-mime-button-map
3273 gnus-callback gnus-mm-display-part
3274 gnus-part ,gnus-tmp-id
3275 article-type annotation
3278 (widget-convert-button
3281 :action 'gnus-widget-press-button
3282 :button-keymap gnus-mime-button-map
3284 (lambda (widget/window &optional overlay pos)
3285 ;; Needed to properly clear the message due to a bug in
3286 ;; wid-edit (XEmacs only).
3287 (if (boundp 'help-echo-owns-message)
3288 (setq help-echo-owns-message t))
3290 "%S: %s the MIME part; %S: more options"
3291 (aref gnus-mouse-2 0)
3292 ;; XEmacs will get a single widget arg; Emacs 21 will get
3293 ;; window, overlay, position.
3294 (if (mm-handle-displayed-p
3296 (with-current-buffer (gnus-overlay-buffer overlay)
3297 (widget-get (widget-at (gnus-overlay-start overlay))
3299 (widget-get widget/window :mime-handle)))
3301 (aref gnus-down-mouse-3 0))))))
3303 (defun gnus-widget-press-button (elems el)
3304 (goto-char (widget-get elems :from))
3305 (gnus-article-press-button))
3307 (defvar gnus-displaying-mime nil)
3309 (defun gnus-display-mime (&optional ihandles)
3310 "Display the MIME parts."
3312 (save-selected-window
3313 (let ((window (get-buffer-window gnus-article-buffer))
3316 (select-window window)
3317 ;; We have to do this since selecting the window
3318 ;; may change the point. So we set the window point.
3319 (set-window-point window point)))
3320 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3321 buffer-read-only handle name type b e display)
3322 (when (and (not ihandles)
3323 (not gnus-displaying-mime))
3324 ;; Top-level call; we clean up.
3325 (when gnus-article-mime-handles
3326 (mm-destroy-parts gnus-article-mime-handles)
3327 (setq gnus-article-mime-handle-alist nil));; A trick.
3328 (setq gnus-article-mime-handles handles)
3329 ;; We allow users to glean info from the handles.
3330 (when gnus-article-mime-part-function
3331 (gnus-mime-part-function handles)))
3333 (or (not (stringp (car handles)))
3336 (when (and (not ihandles)
3337 (not gnus-displaying-mime))
3338 ;; Clean up for mime parts.
3340 (delete-region (point) (point-max)))
3341 (let ((gnus-displaying-mime t))
3342 (gnus-mime-display-part handles)))
3345 (narrow-to-region (point) (point-max))
3346 (gnus-treat-article nil 1 1)
3349 ;; Highlight the headers.
3353 (narrow-to-region (point-min) (point))
3354 (gnus-treat-article 'head))))))))
3356 (defvar gnus-mime-display-multipart-as-mixed nil)
3358 (defun gnus-mime-display-part (handle)
3361 ((not (stringp (car handle)))
3362 (gnus-mime-display-single handle))
3363 ;; User-defined multipart
3364 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3365 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3367 ;; multipart/alternative
3368 ((and (equal (car handle) "multipart/alternative")
3369 (not gnus-mime-display-multipart-as-mixed))
3370 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3371 (push (cons id handle) gnus-article-mime-handle-alist)
3372 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3373 ;; multipart/related
3374 ((and (equal (car handle) "multipart/related")
3375 (not gnus-mime-display-multipart-as-mixed))
3376 ;;;!!!We should find the start part, but we just default
3377 ;;;!!!to the first part.
3378 (gnus-mime-display-part (cadr handle)))
3379 ;; Other multiparts are handled like multipart/mixed.
3381 (gnus-mime-display-mixed (cdr handle)))))
3383 (defun gnus-mime-part-function (handles)
3384 (if (stringp (car handles))
3385 (mapcar 'gnus-mime-part-function (cdr handles))
3386 (funcall gnus-article-mime-part-function handles)))
3388 (defun gnus-mime-display-mixed (handles)
3389 (mapcar 'gnus-mime-display-part handles))
3391 (defun gnus-mime-display-single (handle)
3392 (let ((type (mm-handle-media-type handle))
3393 (ignored gnus-ignored-mime-types)
3400 (when (string-match (pop ignored) type)
3401 (throw 'ignored nil)))
3402 (if (and (setq not-attachment
3403 (and (not (mm-inline-override-p handle))
3404 (or (not (mm-handle-disposition handle))
3405 (equal (car (mm-handle-disposition handle))
3407 (mm-attachment-override-p handle))))
3408 (mm-automatic-display-p handle)
3409 (or (mm-inlined-p handle)
3410 (mm-automatic-external-display-p type)))
3412 (when (equal (mm-handle-media-supertype handle) "text")
3414 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3416 (push (cons id handle) gnus-article-mime-handle-alist)
3417 (when (or (not display)
3418 (not (gnus-unbuttonized-mime-type-p type)))
3419 ;(gnus-article-insert-newline)
3420 (gnus-insert-mime-button
3421 handle id (list (or display (and not-attachment text))))
3422 (gnus-article-insert-newline)
3423 ;(gnus-article-insert-newline)
3431 (let ((mail-parse-charset gnus-newsgroup-charset)
3432 (mail-parse-ignored-charsets
3433 (save-excursion (condition-case ()
3434 (set-buffer gnus-summary-buffer)
3436 gnus-newsgroup-ignored-charsets)))
3437 (mm-display-part handle t))
3438 (goto-char (point-max)))
3439 ((and text not-attachment)
3443 (gnus-article-insert-newline)
3444 (mm-insert-inline handle (mm-get-part handle))
3445 (goto-char (point-max))))
3449 (narrow-to-region beg (point))
3452 (gnus-article-mime-total-parts)
3453 (mm-handle-media-type handle)))))))))
3455 (defun gnus-unbuttonized-mime-type-p (type)
3456 "Say whether TYPE is to be unbuttonized."
3457 (unless gnus-inhibit-mime-unbuttonizing
3459 (let ((types gnus-unbuttonized-mime-types))
3461 (when (string-match (pop types) type)
3462 (throw 'found t)))))))
3464 (defun gnus-article-insert-newline ()
3465 "Insert a newline, but mark it as undeletable."
3466 (gnus-put-text-property
3467 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3469 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3470 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3473 handle buffer-read-only from props begend not-pref)
3474 (save-window-excursion
3477 (narrow-to-region (car ibegend)
3480 (goto-char (car ibegend))
3483 (delete-region (point-min) (point-max))
3484 (mm-remove-parts handles))
3485 (setq begend (list (point-marker)))
3487 (unless (setq not-pref (cadr (member preferred ihandles)))
3488 (setq not-pref (car ihandles)))
3490 (not (gnus-unbuttonized-mime-type-p
3491 "multipart/alternative")))
3492 (gnus-add-text-properties
3495 (insert (format "%d. " id))
3499 (unless ,(not ibegend)
3500 (setq gnus-article-mime-handle-alist
3501 ',gnus-article-mime-handle-alist))
3502 (gnus-mime-display-alternative
3503 ',ihandles ',not-pref ',begend ,id))
3504 local-map ,gnus-mime-button-map
3505 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3506 face ,gnus-article-button-face
3507 keymap ,gnus-mime-button-map
3510 (widget-convert-button 'link from (point)
3511 :action 'gnus-widget-press-button
3512 :button-keymap gnus-widget-button-keymap)
3514 (while (setq handle (pop handles))
3515 (gnus-add-text-properties
3518 (insert (format "(%c) %-18s"
3519 (if (equal handle preferred) ?* ? )
3520 (mm-handle-media-type handle)))
3524 (unless ,(not ibegend)
3525 (setq gnus-article-mime-handle-alist
3526 ',gnus-article-mime-handle-alist))
3527 (gnus-mime-display-alternative
3528 ',ihandles ',handle ',begend ,id))
3529 local-map ,gnus-mime-button-map
3530 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3531 face ,gnus-article-button-face
3532 keymap ,gnus-mime-button-map
3535 (widget-convert-button 'link from (point)
3536 :action 'gnus-widget-press-button
3537 :button-keymap gnus-widget-button-keymap)
3541 (if (stringp (car preferred))
3542 (gnus-display-mime preferred)
3543 (let ((mail-parse-charset gnus-newsgroup-charset)
3544 (mail-parse-ignored-charsets
3545 (save-excursion (set-buffer gnus-summary-buffer)
3546 gnus-newsgroup-ignored-charsets)))
3547 (mm-display-part preferred)
3551 (narrow-to-region (car begend) (point-max))
3553 nil (length gnus-article-mime-handle-alist)
3554 (gnus-article-mime-total-parts)
3555 (mm-handle-media-type handle))))))
3556 (goto-char (point-max))
3557 (setcdr begend (point-marker)))))
3559 (goto-char point))))
3561 (defun gnus-article-wash-status ()
3562 "Return a string which display status of article washing."
3564 (set-buffer gnus-article-buffer)
3565 (let ((cite (memq 'cite gnus-article-wash-types))
3566 (headers (memq 'headers gnus-article-wash-types))
3567 (boring (memq 'boring-headers gnus-article-wash-types))
3568 (pgp (memq 'pgp gnus-article-wash-types))
3569 (pem (memq 'pem gnus-article-wash-types))
3570 (signature (memq 'signature gnus-article-wash-types))
3571 (overstrike (memq 'overstrike gnus-article-wash-types))
3572 (emphasis (memq 'emphasis gnus-article-wash-types)))
3573 (format "%c%c%c%c%c%c"
3575 (if (or headers boring) ?h ? )
3576 (if (or pgp pem) ?p ? )
3577 (if signature ?s ? )
3578 (if overstrike ?o ? )
3579 (if emphasis ?e ? )))))
3581 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3583 (defun gnus-article-maybe-hide-headers ()
3584 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3585 Provided for backwards compatibility."
3586 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3587 (not (save-excursion (set-buffer gnus-summary-buffer)
3588 gnus-have-all-headers)))
3589 (not gnus-inhibit-hiding))
3590 (gnus-article-hide-headers)))
3594 (defun gnus-output-to-file (file-name)
3595 "Append the current article to a file named FILE-NAME."
3596 (let ((artbuf (current-buffer)))
3598 (insert-buffer-substring artbuf)
3599 ;; Append newline at end of the buffer as separator, and then
3601 (goto-char (point-max))
3603 (mm-append-to-file (point-min) (point-max) file-name)
3606 (defun gnus-narrow-to-page (&optional arg)
3607 "Narrow the article buffer to a page.
3608 If given a numerical ARG, move forward ARG pages."
3610 (setq arg (if arg (prefix-numeric-value arg) 0))
3612 (set-buffer gnus-article-buffer)
3613 (goto-char (point-min))
3615 ;; Remove any old next/prev buttons.
3616 (when (gnus-visual-p 'page-marker)
3617 (let ((buffer-read-only nil))
3618 (gnus-remove-text-with-property 'gnus-prev)
3619 (gnus-remove-text-with-property 'gnus-next)))
3622 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3624 (re-search-forward page-delimiter nil 'move arg)))
3625 (goto-char (match-end 0)))
3628 (if (re-search-forward page-delimiter nil 'move)
3631 (when (and (gnus-visual-p 'page-marker)
3632 (not (= (point-min) 1)))
3634 (goto-char (point-min))
3635 (gnus-insert-prev-page-button)))
3636 (when (and (gnus-visual-p 'page-marker)
3637 (< (+ (point-max) 2) (buffer-size)))
3639 (goto-char (point-max))
3640 (gnus-insert-next-page-button)))))
3642 ;; Article mode commands
3644 (defun gnus-article-goto-next-page ()
3645 "Show the next page of the article."
3647 (when (gnus-article-next-page)
3648 (goto-char (point-min))
3649 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3651 (defun gnus-article-goto-prev-page ()
3652 "Show the next page of the article."
3654 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3655 (gnus-article-prev-page nil)))
3657 (defun gnus-article-next-page (&optional lines)
3658 "Show the next page of the current article.
3659 If end of article, return non-nil. Otherwise return nil.
3660 Argument LINES specifies lines to be scrolled up."
3662 (move-to-window-line -1)
3665 (and (pos-visible-in-window-p) ;Not continuation line.
3667 ;; Nothing in this page.
3668 (if (or (not gnus-page-broken)
3671 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3673 (gnus-narrow-to-page 1) ;Go to next page.
3675 ;; More in this page.
3676 (let ((scroll-in-place nil))
3680 ;; Long lines may cause an end-of-buffer error.
3681 (goto-char (point-max)))))
3682 (move-to-window-line 0)
3685 (defun gnus-article-prev-page (&optional lines)
3686 "Show previous page of current article.
3687 Argument LINES specifies lines to be scrolled down."
3689 (move-to-window-line 0)
3690 (if (and gnus-page-broken
3692 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3694 (gnus-narrow-to-page -1) ;Go to previous page.
3695 (goto-char (point-max))
3697 (let ((scroll-in-place nil))
3701 (beginning-of-buffer
3702 (goto-char (point-min))))
3703 (move-to-window-line 0)))))
3705 (defun gnus-article-refer-article ()
3706 "Read article specified by message-id around point."
3708 (let ((point (point)))
3709 (search-forward ">" nil t) ;Move point to end of "<....>".
3710 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3711 (let ((message-id (match-string 1)))
3713 (set-buffer gnus-summary-buffer)
3714 (gnus-summary-refer-article message-id))
3716 (error "No references around point"))))
3718 (defun gnus-article-show-summary ()
3719 "Reconfigure windows to show summary buffer."
3721 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3722 (error "There is no summary buffer for this article buffer")
3723 (gnus-article-set-globals)
3724 (gnus-configure-windows 'article)
3725 (gnus-summary-goto-subject gnus-current-article)
3726 (gnus-summary-position-point)))
3728 (defun gnus-article-describe-briefly ()
3729 "Describe article mode commands briefly."
3731 (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")))
3733 (defun gnus-article-summary-command ()
3734 "Execute the last keystroke in the summary buffer."
3736 (let ((obuf (current-buffer))
3737 (owin (current-window-configuration))
3739 (switch-to-buffer gnus-article-current-summary 'norecord)
3740 (setq func (lookup-key (current-local-map) (this-command-keys)))
3741 (call-interactively func)
3743 (set-window-configuration owin)
3744 (set-window-point (get-buffer-window (current-buffer)) (point))))
3746 (defun gnus-article-summary-command-nosave ()
3747 "Execute the last keystroke in the summary buffer."
3750 (pop-to-buffer gnus-article-current-summary 'norecord)
3751 (setq func (lookup-key (current-local-map) (this-command-keys)))
3752 (call-interactively func)))
3754 (defun gnus-article-check-buffer ()
3755 "Beep if not in an article buffer."
3756 (unless (equal major-mode 'gnus-article-mode)
3757 (error "Command invoked outside of a Gnus article buffer")))
3759 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3760 "Read a summary buffer key sequence and execute it from the article buffer."
3762 (gnus-article-check-buffer)
3764 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3765 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3766 "=" "^" "\M-^" "|"))
3772 '("n" "Gn" "p" "Gp"))
3775 (set-buffer gnus-article-current-summary)
3776 (let (gnus-pick-mode)
3777 (push (or key last-command-event) unread-command-events)
3778 (setq keys (if (featurep 'xemacs)
3779 (events-to-keys (read-key-sequence nil))
3780 (read-key-sequence nil)))))
3784 (if (or (member keys nosaves)
3785 (member keys nosave-but-article)
3786 (member keys nosave-in-article))
3788 (save-window-excursion
3789 (pop-to-buffer gnus-article-current-summary 'norecord)
3790 ;; We disable the pick minor mode commands.
3791 (let (gnus-pick-mode)
3792 (setq func (lookup-key (current-local-map) keys))))
3796 (unless (member keys nosave-in-article)
3797 (set-buffer gnus-article-current-summary))
3798 (call-interactively func)
3799 (setq new-sum-point (point)))
3800 (when (member keys nosave-but-article)
3801 (pop-to-buffer gnus-article-buffer 'norecord)))
3802 ;; These commands should restore window configuration.
3803 (let ((obuf (current-buffer))
3804 (owin (current-window-configuration))
3806 (summary gnus-article-current-summary)
3807 func in-buffer selected)
3808 (if not-restore-window
3809 (pop-to-buffer summary 'norecord)
3810 (switch-to-buffer summary 'norecord))
3811 (setq in-buffer (current-buffer))
3812 ;; We disable the pick minor mode commands.
3813 (if (setq func (let (gnus-pick-mode)
3814 (lookup-key (current-local-map) keys)))
3816 (call-interactively func)
3817 (setq new-sum-point (point)))
3819 (when (eq in-buffer (current-buffer))
3820 (setq selected (gnus-summary-select-article))
3822 (unless not-restore-window
3823 (set-window-configuration owin))
3824 (when (eq selected 'old)
3826 (set-window-start (get-buffer-window (current-buffer))
3828 (set-window-point (get-buffer-window (current-buffer))
3830 (let ((win (get-buffer-window gnus-article-current-summary)))
3832 (set-window-point win new-sum-point))))))))
3834 (defun gnus-article-hide (&optional arg force)
3835 "Hide all the gruft in the current article.
3836 This means that PGP stuff, signatures, cited text and (some)
3837 headers will be hidden.
3838 If given a prefix, show the hidden text instead."
3839 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3840 (gnus-article-hide-headers arg)
3841 (gnus-article-hide-list-identifiers arg)
3842 (gnus-article-hide-pgp arg)
3843 (gnus-article-hide-citation-maybe arg force)
3844 (gnus-article-hide-signature arg))
3846 (defun gnus-article-maybe-highlight ()
3847 "Do some article highlighting if article highlighting is requested."
3848 (when (gnus-visual-p 'article-highlight 'highlight)
3849 (gnus-article-highlight-some)))
3851 (defun gnus-check-group-server ()
3852 ;; Make sure the connection to the server is alive.
3853 (unless (gnus-server-opened
3854 (gnus-find-method-for-group gnus-newsgroup-name))
3855 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3856 (gnus-request-group gnus-newsgroup-name t)))
3858 (defun gnus-request-article-this-buffer (article group)
3859 "Get an article and insert it into this buffer."
3860 (let (do-update-line sparse-header)
3864 (gnus-kill-all-overlays)
3865 (setq group (or group gnus-newsgroup-name))
3867 ;; Using `gnus-request-article' directly will insert the article into
3868 ;; `nntp-server-buffer' - so we'll save some time by not having to
3869 ;; copy it from the server buffer into the article buffer.
3871 ;; We only request an article by message-id when we do not have the
3872 ;; headers for it, so we'll have to get those.
3873 (when (stringp article)
3874 (gnus-read-header article))
3876 ;; If the article number is negative, that means that this article
3877 ;; doesn't belong in this newsgroup (possibly), so we find its
3878 ;; message-id and request it by id instead of number.
3879 (when (and (numberp article)
3881 (get-buffer gnus-summary-buffer)
3882 (gnus-buffer-exists-p gnus-summary-buffer))
3884 (set-buffer gnus-summary-buffer)
3885 (let ((header (gnus-summary-article-header article)))
3888 ((memq article gnus-newsgroup-sparse)
3889 ;; This is a sparse gap article.
3890 (setq do-update-line article)
3891 (setq article (mail-header-id header))
3892 (setq sparse-header (gnus-read-header article))
3893 (setq gnus-newsgroup-sparse
3894 (delq article gnus-newsgroup-sparse)))
3896 ;; It's a real article.
3897 (setq article (mail-header-id header)))
3899 ;; It is an extracted pseudo-article.
3900 (setq article 'pseudo)
3901 (gnus-request-pseudo-article header))))
3903 (let ((method (gnus-find-method-for-group
3904 gnus-newsgroup-name)))
3905 (when (and (eq (car method) 'nneething)
3907 (let ((dir (expand-file-name
3908 (mail-header-subject header)
3909 (file-name-as-directory
3910 (or (cadr (assq 'nneething-address method))
3912 (when (file-directory-p dir)
3913 (setq article 'nneething)
3914 (gnus-group-enter-directory dir))))))))
3917 ;; Refuse to select canceled articles.
3918 ((and (numberp article)
3920 (get-buffer gnus-summary-buffer)
3921 (gnus-buffer-exists-p gnus-summary-buffer)
3922 (eq (cdr (save-excursion
3923 (set-buffer gnus-summary-buffer)
3924 (assq article gnus-newsgroup-reads)))
3925 gnus-canceled-mark))
3927 ;; We first check `gnus-original-article-buffer'.
3928 ((and (get-buffer gnus-original-article-buffer)
3931 (set-buffer gnus-original-article-buffer)
3932 (and (equal (car gnus-original-article) group)
3933 (eq (cdr gnus-original-article) article))))
3934 (insert-buffer-substring gnus-original-article-buffer)
3936 ;; Check the backlog.
3937 ((and gnus-keep-backlog
3938 (gnus-backlog-request-article group article (current-buffer)))
3940 ;; Check asynchronous pre-fetch.
3941 ((gnus-async-request-fetched-article group article (current-buffer))
3942 (gnus-async-prefetch-next group article gnus-summary-buffer)
3943 (when (and (numberp article) gnus-keep-backlog)
3944 (gnus-backlog-enter-article group article (current-buffer)))
3947 ((and gnus-use-cache
3949 (gnus-cache-request-article article group))
3951 ;; Get the article and put into the article buffer.
3952 ((or (stringp article)
3954 (let ((gnus-override-method gnus-override-method)
3955 (methods (and (stringp article)
3956 gnus-refer-article-method))
3958 (buffer-read-only nil))
3959 (if (or (not (listp methods))
3960 (and (symbolp (car methods))
3961 (assq (car methods) nnoo-definition-alist)))
3962 (setq methods (list methods)))
3963 (when (and (null gnus-override-method)
3965 (setq gnus-override-method (pop methods)))
3967 (when (eq gnus-override-method 'current)
3968 (setq gnus-override-method gnus-current-select-method))
3970 (gnus-kill-all-overlays)
3971 (let ((gnus-newsgroup-name group))
3972 (gnus-check-group-server))
3973 (when (gnus-request-article article group (current-buffer))
3974 (when (numberp article)
3975 (gnus-async-prefetch-next group article
3976 gnus-summary-buffer)
3977 (when gnus-keep-backlog
3978 (gnus-backlog-enter-article
3979 group article (current-buffer))))
3980 (setq result 'article))
3983 (setq gnus-override-method (pop methods))
3984 (setq result 'done))))
3985 (and (eq result 'article) 'article)))
3989 ;; Associate this article with the current summary buffer.
3990 (setq gnus-article-current-summary gnus-summary-buffer)
3992 ;; Take the article from the original article buffer
3993 ;; and place it in the buffer it's supposed to be in.
3994 (when (and (get-buffer gnus-article-buffer)
3995 (equal (buffer-name (current-buffer))
3996 (buffer-name (get-buffer gnus-article-buffer))))
3998 (if (get-buffer gnus-original-article-buffer)
3999 (set-buffer gnus-original-article-buffer)
4000 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4001 (buffer-disable-undo)
4002 (setq major-mode 'gnus-original-article-mode)
4003 (setq buffer-read-only t))
4004 (let (buffer-read-only)
4006 (insert-buffer-substring gnus-article-buffer))
4007 (setq gnus-original-article (cons group article)))
4010 (run-hooks 'gnus-article-decode-hook)
4011 ;; Mark article as decoded or not.
4012 (setq gnus-article-decoded-p gnus-article-decode-hook))
4014 ;; Update sparse articles.
4015 (when (and do-update-line
4016 (or (numberp article)
4018 (let ((buf (current-buffer)))
4019 (set-buffer gnus-summary-buffer)
4020 (gnus-summary-update-article do-update-line sparse-header)
4021 (gnus-summary-goto-subject do-update-line nil t)
4022 (set-window-point (get-buffer-window (current-buffer) t)
4024 (set-buffer buf))))))
4030 (defcustom gnus-article-edit-mode-hook nil
4031 "Hook run in article edit mode buffers."
4032 :group 'gnus-article-various
4035 (defvar gnus-article-edit-done-function nil)
4037 (defvar gnus-article-edit-mode-map nil)
4039 ;; Should we be using derived.el for this?
4040 (unless gnus-article-edit-mode-map
4041 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4042 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4044 (gnus-define-keys gnus-article-edit-mode-map
4045 "\C-c\C-c" gnus-article-edit-done
4046 "\C-c\C-k" gnus-article-edit-exit)
4048 (gnus-define-keys (gnus-article-edit-wash-map
4049 "\C-c\C-w" gnus-article-edit-mode-map)
4050 "f" gnus-article-edit-full-stops))
4052 (defun gnus-article-edit-mode ()
4053 "Major mode for editing articles.
4054 This is an extended text-mode.
4056 \\{gnus-article-edit-mode-map}"
4058 (setq major-mode 'gnus-article-edit-mode)
4059 (setq mode-name "Article Edit")
4060 (use-local-map gnus-article-edit-mode-map)
4061 (make-local-variable 'gnus-article-edit-done-function)
4062 (make-local-variable 'gnus-prev-winconf)
4063 (setq buffer-read-only nil)
4064 (buffer-enable-undo)
4066 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4068 (defun gnus-article-edit (&optional force)
4069 "Edit the current article.
4070 This will have permanent effect only in mail groups.
4071 If FORCE is non-nil, allow editing of articles even in read-only
4074 (when (and (not force)
4075 (gnus-group-read-only-p))
4076 (error "The current newsgroup does not support article editing"))
4077 (gnus-article-date-original)
4078 (gnus-article-edit-article
4080 `(lambda (no-highlight)
4082 (gnus-summary-edit-article-done
4083 ,(or (mail-header-references gnus-current-headers) "")
4084 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4086 (defun gnus-article-edit-article (start-func exit-func)
4087 "Start editing the contents of the current article buffer."
4088 (let ((winconf (current-window-configuration)))
4089 (set-buffer gnus-article-buffer)
4090 (gnus-article-edit-mode)
4091 (funcall start-func)
4092 (gnus-configure-windows 'edit-article)
4093 (setq gnus-article-edit-done-function exit-func)
4094 (setq gnus-prev-winconf winconf)
4095 (gnus-message 6 "C-c C-c to end edits")))
4097 (defun gnus-article-edit-done (&optional arg)
4098 "Update the article edits and exit."
4103 (when (article-goto-body)
4104 (let ((lines (count-lines (point) (point-max)))
4105 (length (- (point-max) (point)))
4106 (case-fold-search t)
4107 (body (copy-marker (point))))
4108 (goto-char (point-min))
4109 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4110 (delete-region (match-beginning 1) (match-end 1))
4111 (insert (number-to-string length)))
4112 (goto-char (point-min))
4113 (when (re-search-forward
4114 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4115 (delete-region (match-beginning 1) (match-end 1))
4116 (insert (number-to-string length)))
4117 (goto-char (point-min))
4118 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4119 (delete-region (match-beginning 1) (match-end 1))
4120 (insert (number-to-string lines)))))))
4121 (let ((func gnus-article-edit-done-function)
4122 (buf (current-buffer))
4123 (start (window-start)))
4124 (gnus-article-edit-exit)
4127 (let ((buffer-read-only nil))
4129 ;; The cache and backlog have to be flushed somewhat.
4130 (when gnus-keep-backlog
4131 (gnus-backlog-remove-article
4132 (car gnus-article-current) (cdr gnus-article-current)))
4133 ;; Flush original article as well.
4135 (when (get-buffer gnus-original-article-buffer)
4136 (set-buffer gnus-original-article-buffer)
4137 (setq gnus-original-article nil)))
4138 (when gnus-use-cache
4139 (gnus-cache-update-article
4140 (car gnus-article-current) (cdr gnus-article-current))))
4142 (set-window-start (get-buffer-window buf) start)
4143 (set-window-point (get-buffer-window buf) (point))))
4145 (defun gnus-article-edit-exit ()
4146 "Exit the article editing without updating."
4148 ;; We remove all text props from the article buffer.
4149 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4150 (curbuf (current-buffer))
4152 (window-start (window-start)))
4155 (let ((winconf gnus-prev-winconf))
4157 (set-window-configuration winconf)
4158 ;; Tippy-toe some to make sure that point remains where it was.
4159 (save-current-buffer
4161 (set-window-start (get-buffer-window (current-buffer)) window-start)
4164 (defun gnus-article-edit-full-stops ()
4165 "Interactively repair spacing at end of sentences."
4168 (goto-char (point-min))
4169 (search-forward-regexp "^$" nil t)
4170 (let ((case-fold-search nil))
4171 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4174 ;;; Article highlights
4177 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4179 ;;; Internal Variables:
4181 (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\\)\\)"
4182 "Regular expression that matches URLs."
4183 :group 'gnus-article-buttons
4186 (defcustom gnus-button-alist
4187 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4188 0 t gnus-button-message-id 2)
4189 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4190 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4192 gnus-button-fetch-group 4)
4193 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4194 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4195 t gnus-button-message-id 3)
4196 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4197 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4198 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4199 ;; This is how URLs _should_ be embedded in text...
4200 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4202 (,gnus-button-url-regexp 0 t browse-url 0))
4203 "*Alist of regexps matching buttons in article bodies.
4205 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4206 REGEXP: is the string matching text around the button,
4207 BUTTON: is the number of the regexp grouping actually matching the button,
4208 FORM: is a lisp expression which must eval to true for the button to
4210 CALLBACK: is the function to call when the user push this button, and each
4211 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4213 CALLBACK can also be a variable, in that case the value of that
4214 variable it the real callback function."
4215 :group 'gnus-article-buttons
4216 :type '(repeat (list regexp
4217 (integer :tag "Button")
4219 (function :tag "Callback")
4222 (integer :tag "Regexp group")))))
4224 (defcustom gnus-header-button-alist
4225 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4226 0 t gnus-button-message-id 0)
4227 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4228 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4229 0 t gnus-button-mailto 0)
4230 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4231 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4232 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4233 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4234 gnus-button-message-id 3))
4235 "*Alist of headers and regexps to match buttons in article heads.
4237 This alist is very similar to `gnus-button-alist', except that each
4238 alist has an additional HEADER element first in each entry:
4240 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4242 HEADER is a regexp to match a header. For a fuller explanation, see
4243 `gnus-button-alist'."
4244 :group 'gnus-article-buttons
4245 :group 'gnus-article-headers
4246 :type '(repeat (list (regexp :tag "Header")
4248 (integer :tag "Button")
4250 (function :tag "Callback")
4253 (integer :tag "Regexp group")))))
4255 (defvar gnus-button-regexp nil)
4256 (defvar gnus-button-marker-list nil)
4257 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4259 (defvar gnus-button-last nil)
4260 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4264 (defun gnus-article-push-button (event)
4265 "Check text under the mouse pointer for a callback function.
4266 If the text under the mouse pointer has a `gnus-callback' property,
4267 call it with the value of the `gnus-data' text property."
4269 (set-buffer (window-buffer (posn-window (event-start event))))
4270 (let* ((pos (posn-point (event-start event)))
4271 (data (get-text-property pos 'gnus-data))
4272 (fun (get-text-property pos 'gnus-callback)))
4275 (funcall fun data))))
4277 (defun gnus-article-press-button ()
4278 "Check text at point for a callback function.
4279 If the text at point has a `gnus-callback' property,
4280 call it with the value of the `gnus-data' text property."
4282 (let* ((data (get-text-property (point) 'gnus-data))
4283 (fun (get-text-property (point) 'gnus-callback)))
4285 (funcall fun data))))
4287 (defun gnus-article-highlight (&optional force)
4288 "Highlight current article.
4289 This function calls `gnus-article-highlight-headers',
4290 `gnus-article-highlight-citation',
4291 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4292 do the highlighting. See the documentation for those functions."
4293 (interactive (list 'force))
4294 (gnus-article-highlight-headers)
4295 (gnus-article-highlight-citation force)
4296 (gnus-article-highlight-signature)
4297 (gnus-article-add-buttons force)
4298 (gnus-article-add-buttons-to-head))
4300 (defun gnus-article-highlight-some (&optional force)
4301 "Highlight current article.
4302 This function calls `gnus-article-highlight-headers',
4303 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4304 do the highlighting. See the documentation for those functions."
4305 (interactive (list 'force))
4306 (gnus-article-highlight-headers)
4307 (gnus-article-highlight-signature)
4308 (gnus-article-add-buttons))
4310 (defun gnus-article-highlight-headers ()
4311 "Highlight article headers as specified by `gnus-header-face-alist'."
4314 (set-buffer gnus-article-buffer)
4316 (let ((alist gnus-header-face-alist)
4317 (buffer-read-only nil)
4318 (case-fold-search t)
4319 (inhibit-point-motion-hooks t)
4320 entry regexp header-face field-face from hpoints fpoints)
4321 (article-narrow-to-head)
4322 (while (setq entry (pop alist))
4323 (goto-char (point-min))
4324 (setq regexp (concat "^\\("
4325 (if (string-equal "" (nth 0 entry))
4329 header-face (nth 1 entry)
4330 field-face (nth 2 entry))
4331 (while (and (re-search-forward regexp nil t)
4335 (unless (search-forward ":" nil t)
4337 (when (and header-face
4338 (not (memq (point) hpoints)))
4339 (push (point) hpoints)
4340 (gnus-put-text-property from (point) 'face header-face))
4341 (when (and field-face
4342 (not (memq (setq from (point)) fpoints)))
4344 (if (re-search-forward "^[^ \t]" nil t)
4346 (goto-char (point-max)))
4347 (gnus-put-text-property from (point) 'face field-face))))))))
4349 (defun gnus-article-highlight-signature ()
4350 "Highlight the signature in an article.
4351 It does this by highlighting everything after
4352 `gnus-signature-separator' using `gnus-signature-face'."
4355 (set-buffer gnus-article-buffer)
4356 (let ((buffer-read-only nil)
4357 (inhibit-point-motion-hooks t))
4359 (when (and gnus-signature-face
4360 (gnus-article-narrow-to-signature))
4361 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4362 'face gnus-signature-face)
4364 (gnus-article-search-signature)
4365 (let ((start (match-beginning 0))
4366 (end (set-marker (make-marker) (1+ (match-end 0)))))
4367 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4370 (defun gnus-button-in-region-p (b e prop)
4371 "Say whether PROP exists in the region."
4372 (text-property-not-all b e prop nil))
4374 (defun gnus-article-add-buttons (&optional force)
4375 "Find external references in the article and make buttons of them.
4376 \"External references\" are things like Message-IDs and URLs, as
4377 specified by `gnus-button-alist'."
4378 (interactive (list 'force))
4380 (set-buffer gnus-article-buffer)
4381 (let ((buffer-read-only nil)
4382 (inhibit-point-motion-hooks t)
4383 (case-fold-search t)
4384 (alist gnus-button-alist)
4386 ;; Remove all old markers.
4387 (let (marker entry new-list)
4388 (while (setq marker (pop gnus-button-marker-list))
4389 (if (or (< marker (point-min)) (>= marker (point-max)))
4390 (push marker new-list)
4392 (when (setq entry (gnus-button-entry))
4393 (put-text-property (match-beginning (nth 1 entry))
4394 (match-end (nth 1 entry))
4395 'gnus-callback nil))
4396 (set-marker marker nil)))
4397 (setq gnus-button-marker-list new-list))
4398 ;; We skip the headers.
4401 (while (setq entry (pop alist))
4402 (setq regexp (car entry))
4404 (while (re-search-forward regexp nil t)
4405 (let* ((start (and entry (match-beginning (nth 1 entry))))
4406 (end (and entry (match-end (nth 1 entry))))
4407 (from (match-beginning 0)))
4408 (when (and (or (eq t (nth 2 entry))
4409 (eval (nth 2 entry)))
4410 (not (gnus-button-in-region-p
4411 start end 'gnus-callback)))
4412 ;; That optional form returned non-nil, so we add the
4414 (gnus-article-add-button
4415 start end 'gnus-button-push
4416 (car (push (set-marker (make-marker) from)
4417 gnus-button-marker-list))))))))))
4419 ;; Add buttons to the head of an article.
4420 (defun gnus-article-add-buttons-to-head ()
4421 "Add buttons to the head of the article."
4424 (set-buffer gnus-article-buffer)
4426 (let ((buffer-read-only nil)
4427 (inhibit-point-motion-hooks t)
4428 (case-fold-search t)
4429 (alist gnus-header-button-alist)
4431 (article-narrow-to-head)
4433 ;; Each alist entry.
4434 (setq entry (car alist)
4436 (goto-char (point-min))
4437 (while (re-search-forward (car entry) nil t)
4438 ;; Each header matching the entry.
4439 (setq beg (match-beginning 0))
4440 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4441 (match-beginning 0))
4444 (while (re-search-forward (nth 1 entry) end t)
4445 ;; Each match within a header.
4446 (let* ((entry (cdr entry))
4447 (start (match-beginning (nth 1 entry)))
4448 (end (match-end (nth 1 entry)))
4449 (form (nth 2 entry)))
4450 (goto-char (match-end 0))
4452 (gnus-article-add-button
4453 start end (nth 3 entry)
4454 (buffer-substring (match-beginning (nth 4 entry))
4455 (match-end (nth 4 entry)))))))
4456 (goto-char end)))))))
4458 ;;; External functions:
4460 (defun gnus-article-add-button (from to fun &optional data)
4461 "Create a button between FROM and TO with callback FUN and data DATA."
4462 (when gnus-article-button-face
4463 (gnus-overlay-put (gnus-make-overlay from to)
4464 'face gnus-article-button-face))
4465 (gnus-add-text-properties
4467 (nconc (and gnus-article-mouse-face
4468 (list gnus-mouse-face-prop gnus-article-mouse-face))
4469 (list 'gnus-callback fun)
4470 (and data (list 'gnus-data data))))
4471 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4472 :button-keymap gnus-widget-button-keymap))
4474 ;;; Internal functions:
4476 (defun gnus-article-set-globals ()
4478 (set-buffer gnus-summary-buffer)
4479 (gnus-set-global-variables)))
4481 (defun gnus-signature-toggle (end)
4483 (set-buffer gnus-article-buffer)
4484 (let ((buffer-read-only nil)
4485 (inhibit-point-motion-hooks t))
4486 (if (get-text-property end 'invisible)
4487 (gnus-article-unhide-text end (point-max))
4488 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4490 (defun gnus-button-entry ()
4491 ;; Return the first entry in `gnus-button-alist' matching this place.
4492 (let ((alist gnus-button-alist)
4495 (setq entry (pop alist))
4496 (if (looking-at (car entry))
4501 (defun gnus-button-push (marker)
4502 ;; Push button starting at MARKER.
4505 (let* ((entry (gnus-button-entry))
4506 (inhibit-point-motion-hooks t)
4508 (args (mapcar (lambda (group)
4509 (let ((string (match-string group)))
4510 (gnus-set-text-properties
4511 0 (length string) nil string)
4518 (fboundp (symbol-value fun)))
4519 (apply (symbol-value fun) args))
4521 (gnus-message 1 "You must define `%S' to use this button"
4522 (cons fun args)))))))
4524 (defun gnus-button-message-id (message-id)
4527 (set-buffer gnus-summary-buffer)
4528 (gnus-summary-refer-article message-id)))
4530 (defun gnus-button-fetch-group (address)
4531 "Fetch GROUP specified by ADDRESS."
4532 (if (not (string-match "[:/]" address))
4533 ;; This is just a simple group url.
4534 (gnus-group-read-ephemeral-group address gnus-select-method)
4535 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4537 (error "Can't parse %s" address)
4538 (gnus-group-read-ephemeral-group
4539 (match-string 4 address)
4540 `(nntp ,(match-string 1 address)
4541 (nntp-address ,(match-string 1 address))
4542 (nntp-port-number ,(if (match-end 3)
4543 (match-string 3 address)
4546 (defun gnus-url-parse-query-string (query &optional downcase)
4547 (let (retval pairs cur key val)
4548 (setq pairs (split-string query "&"))
4550 (setq cur (car pairs)
4552 (if (not (string-match "=" cur))
4554 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4555 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4557 (setq key (downcase key)))
4558 (setq cur (assoc key retval))
4560 (setcdr cur (cons val (cdr cur)))
4561 (setq retval (cons (list key val) retval)))))
4564 (defun gnus-url-unhex (x)
4571 (defun gnus-url-unhex-string (str &optional allow-newlines)
4572 "Remove %XXX embedded spaces, etc in a url.
4573 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4574 decoding of carriage returns and line feeds in the string, which is normally
4575 forbidden in URL encoding."
4576 (setq str (or str ""))
4578 (case-fold-search t))
4579 (while (string-match "%[0-9a-f][0-9a-f]" str)
4580 (let* ((start (match-beginning 0))
4581 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4583 (gnus-url-unhex (elt str (+ start 2))))))
4585 tmp (substring str 0 start)
4588 (char-to-string code))
4589 ((or (= code ?\n) (= code ?\r))
4591 (t (char-to-string code))))
4592 str (substring str (match-end 0)))))
4593 (setq tmp (concat tmp str))
4596 (defun gnus-url-mailto (url)
4597 ;; Send mail to someone
4598 (when (string-match "mailto:/*\\(.*\\)" url)
4599 (setq url (substring url (match-beginning 1) nil)))
4600 (let (to args subject func)
4601 (if (string-match (regexp-quote "?") url)
4602 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4603 args (gnus-url-parse-query-string
4604 (substring url (match-end 0) nil) t))
4605 (setq to (gnus-url-unhex-string url)))
4606 (setq args (cons (list "to" to) args)
4607 subject (cdr-safe (assoc "subject" args)))
4610 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4613 (message-position-on-field (caar args)))
4614 (insert (mapconcat 'identity (cdar args) ", "))
4615 (setq args (cdr args)))
4618 (message-goto-subject))))
4620 (defun gnus-button-mailto (address)
4622 (set-buffer (gnus-copy-article-buffer))
4623 (message-reply address))
4625 (defalias 'gnus-button-reply 'message-reply)
4627 (defun gnus-button-embedded-url (address)
4628 "Activate ADDRESS with `browse-url'."
4629 (browse-url (gnus-strip-whitespace address)))
4631 ;;; Next/prev buttons in the article buffer.
4633 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4634 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4636 (defvar gnus-prev-page-map nil)
4637 (unless gnus-prev-page-map
4638 (setq gnus-prev-page-map (make-sparse-keymap))
4639 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4640 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4642 (defun gnus-insert-prev-page-button ()
4643 (let ((buffer-read-only nil))
4645 gnus-prev-page-line-format nil
4646 `(gnus-prev t local-map ,gnus-prev-page-map
4647 gnus-callback gnus-article-button-prev-page
4648 article-type annotation))))
4650 (defvar gnus-next-page-map nil)
4651 (unless gnus-next-page-map
4652 (setq gnus-next-page-map (make-keymap))
4653 (suppress-keymap gnus-prev-page-map)
4654 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4655 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4657 (defun gnus-button-next-page ()
4658 "Go to the next page."
4660 (let ((win (selected-window)))
4661 (select-window (get-buffer-window gnus-article-buffer t))
4662 (gnus-article-next-page)
4663 (select-window win)))
4665 (defun gnus-button-prev-page ()
4666 "Go to the prev page."
4668 (let ((win (selected-window)))
4669 (select-window (get-buffer-window gnus-article-buffer t))
4670 (gnus-article-prev-page)
4671 (select-window win)))
4673 (defun gnus-insert-next-page-button ()
4674 (let ((buffer-read-only nil))
4675 (gnus-eval-format gnus-next-page-line-format nil
4677 t local-map ,gnus-next-page-map
4678 gnus-callback gnus-article-button-next-page
4679 article-type annotation))))
4681 (defun gnus-article-button-next-page (arg)
4682 "Go to the next page."
4684 (let ((win (selected-window)))
4685 (select-window (get-buffer-window gnus-article-buffer t))
4686 (gnus-article-next-page)
4687 (select-window win)))
4689 (defun gnus-article-button-prev-page (arg)
4690 "Go to the prev page."
4692 (let ((win (selected-window)))
4693 (select-window (get-buffer-window gnus-article-buffer t))
4694 (gnus-article-prev-page)
4695 (select-window win)))
4697 (defvar gnus-decode-header-methods
4698 '(mail-decode-encoded-word-region)
4699 "List of methods used to decode headers.
4701 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4702 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4703 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4704 whose names match REGEXP.
4707 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4708 mail-decode-encoded-word-region
4709 (\"chinese\" . rfc1843-decode-region))
4712 (defvar gnus-decode-header-methods-cache nil)
4714 (defun gnus-multi-decode-header (start end)
4715 "Apply the functions from `gnus-encoded-word-methods' that match."
4716 (unless (and gnus-decode-header-methods-cache
4717 (eq gnus-newsgroup-name
4718 (car gnus-decode-header-methods-cache)))
4719 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4722 (nconc gnus-decode-header-methods-cache (list x))
4723 (if (and gnus-newsgroup-name
4724 (string-match (car x) gnus-newsgroup-name))
4725 (nconc gnus-decode-header-methods-cache
4727 gnus-decode-header-methods))
4728 (let ((xlist gnus-decode-header-methods-cache))
4731 (narrow-to-region start end)
4733 (funcall (pop xlist) (point-min) (point-max))))))
4736 ;;; Treatment top-level handling.
4739 (defun gnus-treat-article (condition &optional part-number total-parts type)
4740 (let ((length (- (point-max) (point-min)))
4741 (alist gnus-treatment-function-alist)
4742 (article-goto-body-goes-to-point-min-p t)
4746 (let ((list gnus-article-treat-types))
4748 (when (string-match (pop list) type)
4749 (throw 'found t)))))))
4750 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4752 (gnus-run-hooks 'gnus-part-display-hook)
4753 (while (setq elem (pop alist))
4756 (if (gnus-buffer-live-p gnus-summary-buffer)
4757 (set-buffer gnus-summary-buffer))
4758 (symbol-value (car elem))))
4759 (when (and (or (consp val)
4761 (gnus-treat-predicate val)
4762 (or (not (get (car elem) 'highlight))
4765 (funcall (cadr elem)))))))
4767 ;; Dynamic variables.
4769 (defvar part-number)
4770 (defvar total-parts)
4775 (defun gnus-treat-predicate (val)
4780 (stringp (car val)))
4781 (apply 'gnus-or (mapcar `(lambda (s)
4782 (string-match s ,(or gnus-newsgroup-name "")))
4785 (let ((pred (pop val)))
4788 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4790 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4792 (not (gnus-treat-predicate (car val))))
4794 (equal (car val) type))
4796 (error "%S is not a valid predicate" pred)))))
4804 (eq part-number total-parts))
4808 (error "%S is not a valid value" val))))
4814 (run-hooks 'gnus-art-load-hook)
4816 ;;; gnus-art.el ends here