1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
62 (defgroup gnus-article-signature nil
64 :link '(custom-manual "(gnus)Article Signature")
67 (defgroup gnus-article-headers nil
69 :link '(custom-manual "(gnus)Hiding Headers")
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
82 (defgroup gnus-article-saving nil
84 :link '(custom-manual "(gnus)Saving Articles")
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
102 (defcustom gnus-ignored-headers
103 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
104 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
105 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
106 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
107 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
108 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
109 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
110 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
111 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
112 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
113 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
114 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
115 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
116 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
117 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
120 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
121 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
122 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
123 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
124 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
125 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
126 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
127 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
128 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
129 "^X-Received:" "^Content-length:" "X-precedence:")
130 "*All headers that start with this regexp will be hidden.
131 This variable can also be a list of regexps of headers to be ignored.
132 If `gnus-visible-headers' is non-nil, this variable will be ignored."
133 :type '(choice :custom-show nil
136 :group 'gnus-article-hiding)
138 (defcustom gnus-visible-headers
139 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
140 "*All headers that do not match this regexp will be hidden.
141 This variable can also be a list of regexp of headers to remain visible.
142 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
143 :type '(repeat :value-to-internal (lambda (widget value)
144 (custom-split-regexp-maybe value))
145 :match (lambda (widget value)
147 (widget-editable-list-match widget value)))
149 :group 'gnus-article-hiding)
151 (defcustom gnus-sorted-header-list
152 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
153 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
154 "*This variable is a list of regular expressions.
155 If it is non-nil, headers that match the regular expressions will
156 be placed first in the article buffer in the sequence specified by
158 :type '(repeat regexp)
159 :group 'gnus-article-hiding)
161 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
162 "Headers that are only to be displayed if they have interesting data.
163 Possible values in this list are `empty', `newsgroups', `followup-to',
164 `reply-to', `date', `long-to', and `many-to'."
165 :type '(set (const :tag "Headers with no content." empty)
166 (const :tag "Newsgroups with only one group." newsgroups)
167 (const :tag "Followup-to identical to newsgroups." followup-to)
168 (const :tag "Reply-to identical to from." reply-to)
169 (const :tag "Date less than four days old." date)
170 (const :tag "Very long To and/or Cc header." long-to)
171 (const :tag "Multiple To and/or Cc headers." many-to))
172 :group 'gnus-article-hiding)
174 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
175 "Regexp matching signature separator.
176 This can also be a list of regexps. In that case, it will be checked
177 from head to tail looking for a separator. Searches will be done from
178 the end of the buffer."
179 :type '(repeat string)
180 :group 'gnus-article-signature)
182 (defcustom gnus-signature-limit nil
183 "Provide a limit to what is considered a signature.
184 If it is a number, no signature may not be longer (in characters) than
185 that number. If it is a floating point number, no signature may be
186 longer (in lines) than that number. If it is a function, the function
187 will be called without any parameters, and if it returns nil, there is
188 no signature in the buffer. If it is a string, it will be used as a
189 regexp. If it matches, the text in question is not a signature."
190 :type '(choice (integer :value 200)
192 (function :value fun)
193 (regexp :value ".*"))
194 :group 'gnus-article-signature)
196 (defcustom gnus-hidden-properties '(invisible t intangible t)
197 "Property list to use for hiding text."
199 :group 'gnus-article-hiding)
201 ;; Fixme: This isn't the right thing for mixed graphical and and
202 ;; non-graphical frames in a session.
203 ;; gnus-xmas.el overrides this for XEmacs.
204 (defcustom gnus-article-x-face-command
205 (if (and (fboundp 'image-type-available-p)
206 (image-type-available-p 'xbm))
207 'gnus-article-display-xface
208 (if gnus-article-compface-xbm
209 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
210 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
212 "*String or function to be executed to display an X-Face header.
213 If it is a string, the command will be executed in a sub-shell
214 asynchronously. The compressed face will be piped to this command."
215 :type '(choice string
216 (function-item gnus-article-display-xface)
218 :group 'gnus-article-washing)
220 (defcustom gnus-article-x-face-too-ugly nil
221 "Regexp matching posters whose face shouldn't be shown automatically."
222 :type '(choice regexp (const nil))
223 :group 'gnus-article-washing)
225 (defcustom gnus-article-banner-alist nil
226 "Banner alist for stripping.
228 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
230 :type '(repeat (cons symbol regexp))
231 :group 'gnus-article-washing)
233 (defcustom gnus-emphasis-alist
235 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
237 '(("_" "_" underline)
240 ("_/" "/_" underline-italic)
241 ("_\\*" "\\*_" underline-bold)
242 ("\\*/" "/\\*" bold-italic)
243 ("_\\*/" "/\\*_" underline-bold-italic))))
244 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
245 2 3 gnus-emphasis-underline)
249 (format format (car spec) (cadr spec))
250 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
252 "*Alist that says how to fontify certain phrases.
253 Each item looks like this:
255 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
257 The first element is a regular expression to be matched. The second
258 is a number that says what regular expression grouping used to find
259 the entire emphasized word. The third is a number that says what
260 regexp grouping should be displayed and highlighted. The fourth
261 is the face used for highlighting."
262 :type '(repeat (list :value ("" 0 0 default)
264 (integer :tag "Match group")
265 (integer :tag "Emphasize group")
267 :group 'gnus-article-emphasis)
269 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
270 "A regexp to describe whitespace which should not be emphasized.
271 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
272 The former avoids underlining of leading and trailing whitespace,
273 and the latter avoids underlining any whitespace at all."
275 :group 'gnus-article-emphasis
278 (defface gnus-emphasis-bold '((t (:bold t)))
279 "Face used for displaying strong emphasized text (*word*)."
280 :group 'gnus-article-emphasis)
282 (defface gnus-emphasis-italic '((t (:italic t)))
283 "Face used for displaying italic emphasized text (/word/)."
284 :group 'gnus-article-emphasis)
286 (defface gnus-emphasis-underline '((t (:underline t)))
287 "Face used for displaying underlined emphasized text (_word_)."
288 :group 'gnus-article-emphasis)
290 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
291 "Face used for displaying underlined bold emphasized text (_*word*_)."
292 :group 'gnus-article-emphasis)
294 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
295 "Face used for displaying underlined italic emphasized text (_/word/_)."
296 :group 'gnus-article-emphasis)
298 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
299 "Face used for displaying bold italic emphasized text (/*word*/)."
300 :group 'gnus-article-emphasis)
302 (defface gnus-emphasis-underline-bold-italic
303 '((t (:bold t :italic t :underline t)))
304 "Face used for displaying underlined bold italic emphasized text.
305 Esample: (_/*word*/_)."
306 :group 'gnus-article-emphasis)
308 (defface gnus-emphasis-highlight-words
309 '((t (:background "black" :foreground "yellow")))
310 "Face used for displaying highlighted words."
311 :group 'gnus-article-emphasis)
313 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
314 "Format for display of Date headers in article bodies.
315 See `format-time-string' for the possible values.
317 The variable can also be function, which should return a complete Date
318 header. The function is called with one argument, the time, which can
319 be fed to `format-time-string'."
320 :type '(choice string symbol)
321 :link '(custom-manual "(gnus)Article Date")
322 :group 'gnus-article-washing)
325 (autoload 'mail-extract-address-components "mail-extr"))
327 (defcustom gnus-save-all-headers t
328 "*If non-nil, don't remove any headers before saving."
329 :group 'gnus-article-saving
332 (defcustom gnus-prompt-before-saving 'always
333 "*This variable says how much prompting is to be done when saving articles.
334 If it is nil, no prompting will be done, and the articles will be
335 saved to the default files. If this variable is `always', each and
336 every article that is saved will be preceded by a prompt, even when
337 saving large batches of articles. If this variable is neither nil not
338 `always', there the user will be prompted once for a file name for
339 each invocation of the saving commands."
340 :group 'gnus-article-saving
341 :type '(choice (item always)
342 (item :tag "never" nil)
343 (sexp :tag "once" :format "%t\n" :value t)))
345 (defcustom gnus-saved-headers gnus-visible-headers
346 "Headers to keep if `gnus-save-all-headers' is nil.
347 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
348 If that variable is nil, however, all headers that match this regexp
349 will be kept while the rest will be deleted before saving."
350 :group 'gnus-article-saving
353 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
354 "A function to save articles in your favourite format.
355 The function must be interactively callable (in other words, it must
356 be an Emacs command).
358 Gnus provides the following functions:
360 * gnus-summary-save-in-rmail (Rmail format)
361 * gnus-summary-save-in-mail (Unix mail format)
362 * gnus-summary-save-in-folder (MH folder)
363 * gnus-summary-save-in-file (article format)
364 * gnus-summary-save-in-vm (use VM's folder format)
365 * gnus-summary-write-to-file (article format -- overwrite)."
366 :group 'gnus-article-saving
367 :type '(radio (function-item gnus-summary-save-in-rmail)
368 (function-item gnus-summary-save-in-mail)
369 (function-item gnus-summary-save-in-folder)
370 (function-item gnus-summary-save-in-file)
371 (function-item gnus-summary-save-in-vm)
372 (function-item gnus-summary-write-to-file)))
374 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
375 "A function generating a file name to save articles in Rmail format.
376 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
377 :group 'gnus-article-saving
380 (defcustom gnus-mail-save-name 'gnus-plain-save-name
381 "A function generating a file name to save articles in Unix mail format.
382 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
383 :group 'gnus-article-saving
386 (defcustom gnus-folder-save-name 'gnus-folder-save-name
387 "A function generating a file name to save articles in MH folder.
388 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
389 :group 'gnus-article-saving
392 (defcustom gnus-file-save-name 'gnus-numeric-save-name
393 "A function generating a file name to save articles in article format.
394 The function is called with NEWSGROUP, HEADERS, and optional
396 :group 'gnus-article-saving
399 (defcustom gnus-split-methods
400 '((gnus-article-archive-name)
401 (gnus-article-nndoc-name))
402 "*Variable used to suggest where articles are to be saved.
403 For instance, if you would like to save articles related to Gnus in
404 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
405 you could set this variable to something like:
407 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
408 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
410 This variable is an alist where the where the key is the match and the
411 value is a list of possible files to save in if the match is non-nil.
413 If the match is a string, it is used as a regexp match on the
414 article. If the match is a symbol, that symbol will be funcalled
415 from the buffer of the article to be saved with the newsgroup as the
416 parameter. If it is a list, it will be evaled in the same buffer.
418 If this form or function returns a string, this string will be used as
419 a possible file name; and if it returns a non-nil list, that list will
420 be used as possible file names."
421 :group 'gnus-article-saving
422 :type '(repeat (choice (list :value (fun) function)
423 (cons :value ("" "") regexp (repeat string))
426 (defcustom gnus-page-delimiter "^\^L"
427 "*Regexp describing what to use as article page delimiters.
428 The default value is \"^\^L\", which is a form linefeed at the
429 beginning of a line."
431 :group 'gnus-article-various)
433 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
434 "*The format specification for the article mode line.
435 See `gnus-summary-mode-line-format' for a closer description.
437 The following additional specs are available:
439 %w The article washing status.
440 %m The number of MIME parts in the article."
442 :group 'gnus-article-various)
444 (defcustom gnus-article-mode-hook nil
445 "*A hook for Gnus article mode."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-menu-hook nil
450 "*Hook run after the creation of the article mode menu."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-prepare-hook nil
455 "*A hook called after an article has been prepared in the article buffer."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-hide-pgp-hook nil
460 "*A hook called after successfully hiding a PGP signature."
462 :group 'gnus-article-various)
464 (defcustom gnus-article-button-face 'bold
465 "Face used for highlighting buttons in the article buffer.
467 An article button is a piece of text that you can activate by pressing
468 `RET' or `mouse-2' above it."
470 :group 'gnus-article-buttons)
472 (defcustom gnus-article-mouse-face 'highlight
473 "Face used for mouse highlighting in the article buffer.
475 Article buttons will be displayed in this face when the cursor is
478 :group 'gnus-article-buttons)
480 (defcustom gnus-signature-face 'gnus-signature-face
481 "Face used for highlighting a signature in the article buffer.
482 Obsolete; use the face `gnus-signature-face' for customizations instead."
484 :group 'gnus-article-highlight
485 :group 'gnus-article-signature)
487 (defface gnus-signature-face
490 "Face used for highlighting a signature in the article buffer."
491 :group 'gnus-article-highlight
492 :group 'gnus-article-signature)
494 (defface gnus-header-from-face
497 (:foreground "spring green"))
500 (:foreground "red3"))
503 "Face used for displaying from headers."
504 :group 'gnus-article-headers
505 :group 'gnus-article-highlight)
507 (defface gnus-header-subject-face
510 (:foreground "SeaGreen3"))
513 (:foreground "red4"))
515 (:bold t :italic t)))
516 "Face used for displaying subject headers."
517 :group 'gnus-article-headers
518 :group 'gnus-article-highlight)
520 (defface gnus-header-newsgroups-face
523 (:foreground "yellow" :italic t))
526 (:foreground "MidnightBlue" :italic t))
529 "Face used for displaying newsgroups headers."
530 :group 'gnus-article-headers
531 :group 'gnus-article-highlight)
533 (defface gnus-header-name-face
536 (:foreground "SeaGreen"))
539 (:foreground "maroon"))
542 "Face used for displaying header names."
543 :group 'gnus-article-headers
544 :group 'gnus-article-highlight)
546 (defface gnus-header-content-face
549 (:foreground "forest green" :italic t))
552 (:foreground "indianred4" :italic t))
554 (:italic t))) "Face used for displaying header content."
555 :group 'gnus-article-headers
556 :group 'gnus-article-highlight)
558 (defcustom gnus-header-face-alist
559 '(("From" nil gnus-header-from-face)
560 ("Subject" nil gnus-header-subject-face)
561 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
562 ("" gnus-header-name-face gnus-header-content-face))
563 "*Controls highlighting of article header.
565 An alist of the form (HEADER NAME CONTENT).
567 HEADER is a regular expression which should match the name of an
568 header header and NAME and CONTENT are either face names or nil.
570 The name of each header field will be displayed using the face
571 specified by the first element in the list where HEADER match the
572 header name and NAME is non-nil. Similarly, the content will be
573 displayed by the first non-nil matching CONTENT face."
574 :group 'gnus-article-headers
575 :group 'gnus-article-highlight
576 :type '(repeat (list (regexp :tag "Header")
578 (item :tag "skip" nil)
579 (face :value default))
580 (choice :tag "Content"
581 (item :tag "skip" nil)
582 (face :value default)))))
584 (defcustom gnus-article-decode-hook
585 '(article-decode-charset article-decode-encoded-words)
586 "*Hook run to decode charsets in articles."
587 :group 'gnus-article-headers
590 (defcustom gnus-display-mime-function 'gnus-display-mime
591 "Function to display MIME articles."
592 :group 'gnus-article-mime
595 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
596 "Function used to decode headers.")
598 (defvar gnus-article-dumbquotes-map
616 "Table for MS-to-Latin1 translation.")
618 (defcustom gnus-ignored-mime-types nil
619 "List of MIME types that should be ignored by Gnus."
621 :group 'gnus-article-mime
622 :type '(repeat regexp))
624 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
625 "List of MIME types that should not be given buttons when rendered inline."
627 :group 'gnus-article-mime
628 :type '(repeat regexp))
630 (defcustom gnus-article-mime-part-function nil
631 "Function called with a MIME handle as the argument.
632 This is meant for people who want to do something automatic based
633 on parts -- for instance, adding Vcard info to a database."
634 :group 'gnus-article-mime
637 (defcustom gnus-mime-multipart-functions nil
638 "An alist of MIME types to functions to display them."
640 :group 'gnus-article-mime
643 (defcustom gnus-article-date-lapsed-new-header nil
644 "Whether the X-Sent and Date headers can coexist.
645 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
646 either replace the old \"Date:\" header (if this variable is nil), or
647 be added below it (otherwise)."
649 :group 'gnus-article-headers
652 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
653 "Function called with a MIME handle as the argument.
654 This is meant for people who want to view first matched part.
655 For `undisplayed-alternative' (default), the first undisplayed
656 part or alternative part is used. For `undisplayed', the first
657 undisplayed part is used. For a function, the first part which
658 the function return `t' is used. For `nil', the first part is
661 :group 'gnus-article-mime
663 (item :tag "first" :value nil)
664 (item :tag "undisplayed" :value undisplayed)
665 (item :tag "undisplayed or alternative"
666 :value undisplayed-alternative)
669 (defcustom gnus-mime-action-alist
670 '(("save to file" . gnus-mime-save-part)
671 ("display as text" . gnus-mime-inline-part)
672 ("view the part" . gnus-mime-view-part)
673 ("pipe to command" . gnus-mime-pipe-part)
674 ("toggle display" . gnus-article-press-button)
675 ("view as type" . gnus-mime-view-part-as-type)
676 ("internalize type" . gnus-mime-internalize-part)
677 ("externalize type" . gnus-mime-externalize-part))
678 "An alist of actions that run on the MIME attachment."
680 :group 'gnus-article-mime
681 :type '(repeat (cons (string :tag "name")
685 ;;; The treatment variables
688 (defvar gnus-part-display-hook nil
689 "Hook called on parts that are to receive treatment.")
691 (defvar gnus-article-treat-custom
692 '(choice (const :tag "Off" nil)
694 (const :tag "Header" head)
695 (const :tag "Last" last)
696 (integer :tag "Less")
697 (repeat :tag "Groups" regexp)
698 (sexp :tag "Predicate")))
700 (defvar gnus-article-treat-head-custom
701 '(choice (const :tag "Off" nil)
702 (const :tag "Header" head)))
704 (defvar gnus-article-treat-types '("text/plain")
707 (defvar gnus-inhibit-treatment nil
708 "Whether to inhibit treatment.")
710 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
711 "Highlight the signature.
712 Valid values are nil, t, `head', `last', an integer or a predicate.
713 See the manual for details."
714 :group 'gnus-article-treat
715 :type gnus-article-treat-custom)
716 (put 'gnus-treat-highlight-signature 'highlight t)
718 (defcustom gnus-treat-buttonize 100000
720 Valid values are nil, t, `head', `last', an integer or a predicate.
721 See the manual for details."
722 :group 'gnus-article-treat
723 :type gnus-article-treat-custom)
724 (put 'gnus-treat-buttonize 'highlight t)
726 (defcustom gnus-treat-buttonize-head 'head
727 "Add buttons to the head.
728 Valid values are nil, t, `head', `last', an integer or a predicate.
729 See the manual for details."
730 :group 'gnus-article-treat
731 :type gnus-article-treat-head-custom)
732 (put 'gnus-treat-buttonize-head 'highlight t)
734 (defcustom gnus-treat-emphasize 50000
736 Valid values are nil, t, `head', `last', an integer or a predicate.
737 See the manual for details."
738 :group 'gnus-article-treat
739 :type gnus-article-treat-custom)
740 (put 'gnus-treat-emphasize 'highlight t)
742 (defcustom gnus-treat-strip-cr nil
743 "Remove carriage returns.
744 Valid values are nil, t, `head', `last', an integer or a predicate.
745 See the manual for details."
746 :group 'gnus-article-treat
747 :type gnus-article-treat-custom)
749 (defcustom gnus-treat-hide-headers 'head
751 Valid values are nil, t, `head', `last', an integer or a predicate.
752 See the manual for details."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-head-custom)
756 (defcustom gnus-treat-hide-boring-headers nil
757 "Hide boring headers.
758 Valid values are nil, t, `head', `last', an integer or a predicate.
759 See the manual for details."
760 :group 'gnus-article-treat
761 :type gnus-article-treat-head-custom)
763 (defcustom gnus-treat-hide-signature nil
765 Valid values are nil, t, `head', `last', an integer or a predicate.
766 See the manual for details."
767 :group 'gnus-article-treat
768 :type gnus-article-treat-custom)
770 (defcustom gnus-treat-fill-article nil
772 Valid values are nil, t, `head', `last', an integer or a predicate.
773 See the manual for details."
774 :group 'gnus-article-treat
775 :type gnus-article-treat-custom)
777 (defcustom gnus-treat-hide-citation nil
779 Valid values are nil, t, `head', `last', an integer or a predicate.
780 See the manual for details."
781 :group 'gnus-article-treat
782 :type gnus-article-treat-custom)
784 (defcustom gnus-treat-hide-citation-maybe nil
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
791 (defcustom gnus-treat-strip-list-identifiers 'head
792 "Strip list identifiers from `gnus-list-identifiers`.
793 Valid values are nil, t, `head', `last', an integer or a predicate.
794 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
799 (defcustom gnus-treat-strip-pgp t
800 "Strip PGP signatures.
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See the manual for details."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-custom)
806 (defcustom gnus-treat-strip-pem nil
807 "Strip PEM signatures.
808 Valid values are nil, t, `head', `last', an integer or a predicate.
809 See the manual for details."
810 :group 'gnus-article-treat
811 :type gnus-article-treat-custom)
813 (defcustom gnus-treat-strip-banner t
814 "Strip banners from articles.
815 The banner to be stripped is specified in the `banner' group parameter.
816 Valid values are nil, t, `head', `last', an integer or a predicate.
817 See the manual for details."
818 :group 'gnus-article-treat
819 :type gnus-article-treat-custom)
821 (defcustom gnus-treat-highlight-headers 'head
822 "Highlight the headers.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-head-custom)
827 (put 'gnus-treat-highlight-headers 'highlight t)
829 (defcustom gnus-treat-highlight-citation t
830 "Highlight cited text.
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833 :group 'gnus-article-treat
834 :type gnus-article-treat-custom)
835 (put 'gnus-treat-highlight-citation 'highlight t)
837 (defcustom gnus-treat-date-ut nil
838 "Display the Date in UT (GMT).
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-local nil
845 "Display the Date in the local 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-lapsed nil
852 "Display the Date header in a way that says how much time has elapsed.
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-original nil
859 "Display the date in the original timezone.
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862 :group 'gnus-article-treat
863 :type gnus-article-treat-head-custom)
865 (defcustom gnus-treat-date-iso8601 nil
866 "Display the date in the ISO8601 format.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-head-custom)
873 (defcustom gnus-treat-date-user-defined nil
874 "Display the date in a user-defined format.
875 The format is defined by the `gnus-article-time-format' variable.
876 Valid values are nil, t, `head', `last', an integer or a predicate.
877 See the manual for details."
878 :group 'gnus-article-treat
879 :type gnus-article-treat-head-custom)
881 (defcustom gnus-treat-strip-headers-in-body t
882 "Strip the X-No-Archive header line from the beginning of the body.
883 Valid values are nil, t, `head', `last', an integer or a predicate.
884 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-custom)
889 (defcustom gnus-treat-strip-trailing-blank-lines nil
890 "Strip trailing blank lines.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893 :group 'gnus-article-treat
894 :type gnus-article-treat-custom)
896 (defcustom gnus-treat-strip-leading-blank-lines nil
897 "Strip leading blank lines.
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-custom)
903 (defcustom gnus-treat-strip-multiple-blank-lines nil
904 "Strip multiple blank lines.
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See the manual for details."
907 :group 'gnus-article-treat
908 :type gnus-article-treat-custom)
910 (defcustom gnus-treat-overstrike t
911 "Treat overstrike highlighting.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914 :group 'gnus-article-treat
915 :type gnus-article-treat-custom)
916 (put 'gnus-treat-overstrike 'highlight t)
918 (defcustom gnus-treat-display-xface
919 (and (or (and (fboundp 'image-type-available-p)
920 (image-type-available-p 'xbm)
921 (string-match "^0x" (shell-command-to-string "uncompface")))
922 (and (featurep 'xemacs) (featurep 'xface)))
924 "Display X-Face headers.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-head-custom)
929 (put 'gnus-treat-display-xface 'highlight t)
931 (defcustom gnus-treat-display-smileys
932 (if (or (and (featurep 'xemacs)
934 (and (fboundp 'image-type-available-p)
935 (image-type-available-p 'pbm)))
938 Valid values are nil, t, `head', `last', an integer or a predicate.
939 See the manual for details."
940 :group 'gnus-article-treat
941 :type gnus-article-treat-custom)
942 (put 'gnus-treat-display-smileys 'highlight t)
944 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
946 Valid values are nil, t, `head', `last', an integer or a predicate.
947 See the manual for details."
948 :group 'gnus-article-treat
949 :type gnus-article-treat-head-custom)
950 (put 'gnus-treat-display-picons 'highlight t)
952 (defcustom gnus-treat-capitalize-sentences nil
953 "Capitalize sentence-starting words.
954 Valid values are nil, t, `head', `last', an integer or a predicate.
955 See the manual for details."
957 :group 'gnus-article-treat
958 :type gnus-article-treat-custom)
960 (defcustom gnus-treat-fill-long-lines nil
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
967 (defcustom gnus-treat-play-sounds nil
969 Valid values are nil, t, `head', `last', an integer or a predicate.
970 See the manual for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-custom)
975 (defcustom gnus-treat-translate nil
976 "Translate articles from one language to another.
977 Valid values are nil, t, `head', `last', an integer or a predicate.
978 See the manual for details."
980 :group 'gnus-article-treat
981 :type gnus-article-treat-custom)
983 ;;; Internal variables
985 (defvar article-goto-body-goes-to-point-min-p nil)
986 (defvar gnus-article-wash-types nil)
987 (defvar gnus-article-emphasis-alist nil)
989 (defvar gnus-article-mime-handle-alist-1 nil)
990 (defvar gnus-treatment-function-alist
991 '((gnus-treat-strip-banner gnus-article-strip-banner)
992 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
993 (gnus-treat-highlight-signature gnus-article-highlight-signature)
994 (gnus-treat-buttonize gnus-article-add-buttons)
995 (gnus-treat-fill-article gnus-article-fill-cited-article)
996 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
997 (gnus-treat-strip-cr gnus-article-remove-cr)
998 (gnus-treat-emphasize gnus-article-emphasize)
999 (gnus-treat-display-xface gnus-article-display-x-face)
1000 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1001 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1002 (gnus-treat-hide-signature gnus-article-hide-signature)
1003 (gnus-treat-hide-citation gnus-article-hide-citation)
1004 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1005 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1006 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1007 (gnus-treat-strip-pem gnus-article-hide-pem)
1008 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1009 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1010 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1011 (gnus-treat-date-ut gnus-article-date-ut)
1012 (gnus-treat-date-local gnus-article-date-local)
1013 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1014 (gnus-treat-date-original gnus-article-date-original)
1015 (gnus-treat-date-user-defined gnus-article-date-user)
1016 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1017 (gnus-treat-strip-trailing-blank-lines
1018 gnus-article-remove-trailing-blank-lines)
1019 (gnus-treat-strip-leading-blank-lines
1020 gnus-article-strip-leading-blank-lines)
1021 (gnus-treat-strip-multiple-blank-lines
1022 gnus-article-strip-multiple-blank-lines)
1023 (gnus-treat-overstrike gnus-article-treat-overstrike)
1024 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1025 (gnus-treat-display-smileys gnus-smiley-display)
1026 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1027 (gnus-treat-display-picons gnus-article-display-picons)
1028 (gnus-treat-play-sounds gnus-earcon-display)))
1030 (defvar gnus-article-mime-handle-alist nil)
1031 (defvar article-lapsed-timer nil)
1032 (defvar gnus-article-current-summary nil)
1034 (defvar gnus-article-mode-syntax-table
1035 (let ((table (copy-syntax-table text-mode-syntax-table)))
1036 (modify-syntax-entry ?- "w" table)
1037 (modify-syntax-entry ?> ")" table)
1038 (modify-syntax-entry ?< "(" table)
1040 "Syntax table used in article mode buffers.
1041 Initialized from `text-mode-syntax-table.")
1043 (defvar gnus-save-article-buffer nil)
1045 (defvar gnus-article-mode-line-format-alist
1046 (nconc '((?w (gnus-article-wash-status) ?s)
1047 (?m (gnus-article-mime-part-status) ?s))
1048 gnus-summary-mode-line-format-alist))
1050 (defvar gnus-number-of-articles-to-be-saved nil)
1052 (defvar gnus-inhibit-hiding nil)
1054 (defsubst gnus-article-hide-text (b e props)
1055 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1056 (add-text-properties b e props)
1057 (when (memq 'intangible props)
1059 (max (1- b) (point-min))
1060 b 'intangible (cddr (memq 'intangible props)))))
1061 (defsubst gnus-article-unhide-text (b e)
1062 "Remove hidden text properties from region between B and E."
1063 (remove-text-properties b e gnus-hidden-properties)
1064 (when (memq 'intangible gnus-hidden-properties)
1065 (put-text-property (max (1- b) (point-min))
1066 b 'intangible nil)))
1068 (defun gnus-article-hide-text-type (b e type)
1069 "Hide text of TYPE between B and E."
1070 (push type gnus-article-wash-types)
1071 (gnus-article-hide-text
1072 b e (cons 'article-type (cons type gnus-hidden-properties))))
1074 (defun gnus-article-unhide-text-type (b e type)
1075 "Unhide text of TYPE between B and E."
1076 (setq gnus-article-wash-types
1077 (delq type gnus-article-wash-types))
1078 (remove-text-properties
1079 b e (cons 'article-type (cons type gnus-hidden-properties)))
1080 (when (memq 'intangible gnus-hidden-properties)
1081 (put-text-property (max (1- b) (point-min))
1082 b 'intangible nil)))
1084 (defun gnus-article-hide-text-of-type (type)
1085 "Hide text of TYPE in the current buffer."
1087 (let ((b (point-min))
1089 (while (setq b (text-property-any b e 'article-type type))
1090 (add-text-properties b (incf b) gnus-hidden-properties)))))
1092 (defun gnus-article-delete-text-of-type (type)
1093 "Delete text of TYPE in the current buffer."
1095 (let ((b (point-min)))
1096 (while (setq b (text-property-any b (point-max) 'article-type type))
1098 b (or (text-property-not-all b (point-max) 'article-type type)
1101 (defun gnus-article-delete-invisible-text ()
1102 "Delete all invisible text in the current buffer."
1104 (let ((b (point-min)))
1105 (while (setq b (text-property-any b (point-max) 'invisible t))
1107 b (or (text-property-not-all b (point-max) 'invisible t)
1110 (defun gnus-article-text-type-exists-p (type)
1111 "Say whether any text of type TYPE exists in the buffer."
1112 (text-property-any (point-min) (point-max) 'article-type type))
1114 (defsubst gnus-article-header-rank ()
1115 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1116 (let ((list gnus-sorted-header-list)
1119 (when (looking-at (car list))
1121 (setq list (cdr list))
1125 (defun article-hide-headers (&optional arg delete)
1126 "Hide unwanted headers and possibly sort them as well."
1128 ;; This function might be inhibited.
1129 (unless gnus-inhibit-hiding
1132 (let ((buffer-read-only nil)
1133 (case-fold-search t)
1134 (max (1+ (length gnus-sorted-header-list)))
1135 (ignored (when (not gnus-visible-headers)
1136 (cond ((stringp gnus-ignored-headers)
1137 gnus-ignored-headers)
1138 ((listp gnus-ignored-headers)
1139 (mapconcat 'identity gnus-ignored-headers
1142 (cond ((stringp gnus-visible-headers)
1143 gnus-visible-headers)
1144 ((and gnus-visible-headers
1145 (listp gnus-visible-headers))
1146 (mapconcat 'identity gnus-visible-headers "\\|"))))
1147 (inhibit-point-motion-hooks t)
1149 ;; First we narrow to just the headers.
1150 (article-narrow-to-head)
1151 ;; Hide any "From " lines at the beginning of (mail) articles.
1152 (while (looking-at "From ")
1155 (delete-region (point-min) (point)))
1156 ;; Then treat the rest of the header lines.
1157 ;; Then we use the two regular expressions
1158 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1159 ;; select which header lines is to remain visible in the
1161 (while (re-search-forward "^[^ \t]*:" nil t)
1163 ;; Mark the rank of the header.
1165 (point) (1+ (point)) 'message-rank
1166 (if (or (and visible (looking-at visible))
1168 (not (looking-at ignored))))
1169 (gnus-article-header-rank)
1172 (message-sort-headers-1)
1173 (when (setq beg (text-property-any
1174 (point-min) (point-max) 'message-rank (+ 2 max)))
1175 ;; We delete the unwanted headers.
1176 (push 'headers gnus-article-wash-types)
1177 (add-text-properties (point-min) (+ 5 (point-min))
1178 '(article-type headers dummy-invisible t))
1179 (delete-region beg (point-max))))))))
1181 (defun article-hide-boring-headers (&optional arg)
1182 "Toggle hiding of headers that aren't very interesting.
1183 If given a negative prefix, always show; if given a positive prefix,
1185 (interactive (gnus-article-hidden-arg))
1186 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1187 (not gnus-show-all-headers))
1190 (let ((buffer-read-only nil)
1191 (list gnus-boring-article-headers)
1192 (inhibit-point-motion-hooks t)
1194 (article-narrow-to-head)
1196 (setq elem (pop list))
1197 (goto-char (point-min))
1199 ;; Hide empty headers.
1201 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1203 (gnus-article-hide-text-type
1204 (progn (beginning-of-line) (point))
1207 (if (re-search-forward "^[^ \t]" nil t)
1211 ;; Hide boring Newsgroups header.
1212 ((eq elem 'newsgroups)
1213 (when (equal (gnus-fetch-field "newsgroups")
1214 (gnus-group-real-name
1215 (if (boundp 'gnus-newsgroup-name)
1218 (gnus-article-hide-header "newsgroups")))
1219 ((eq elem 'followup-to)
1220 (when (equal (message-fetch-field "followup-to")
1221 (message-fetch-field "newsgroups"))
1222 (gnus-article-hide-header "followup-to")))
1223 ((eq elem 'reply-to)
1224 (let ((from (message-fetch-field "from"))
1225 (reply-to (message-fetch-field "reply-to")))
1230 (nth 1 (mail-extract-address-components from))
1231 (nth 1 (mail-extract-address-components reply-to)))))
1232 (gnus-article-hide-header "reply-to"))))
1234 (let ((date (message-fetch-field "date")))
1236 (< (days-between (current-time-string) date)
1238 (gnus-article-hide-header "date"))))
1240 (let ((to (message-fetch-field "to"))
1241 (cc (message-fetch-field "cc")))
1242 (when (> (length to) 1024)
1243 (gnus-article-hide-header "to"))
1244 (when (> (length cc) 1024)
1245 (gnus-article-hide-header "cc"))))
1249 (goto-char (point-min))
1250 (while (re-search-forward "^to:" nil t)
1251 (setq to-count (1+ to-count)))
1252 (when (> to-count 1)
1253 (while (> to-count 0)
1254 (goto-char (point-min))
1256 (re-search-forward "^to:" nil nil to-count)
1258 (narrow-to-region (point) (point-max))
1259 (gnus-article-hide-header "to"))
1260 (setq to-count (1- to-count))))
1261 (goto-char (point-min))
1262 (while (re-search-forward "^cc:" nil t)
1263 (setq cc-count (1+ cc-count)))
1264 (when (> cc-count 1)
1265 (while (> cc-count 0)
1266 (goto-char (point-min))
1268 (re-search-forward "^cc:" nil nil cc-count)
1270 (narrow-to-region (point) (point-max))
1271 (gnus-article-hide-header "cc"))
1272 (setq cc-count (1- cc-count)))))))))))))
1274 (defun gnus-article-hide-header (header)
1276 (goto-char (point-min))
1277 (when (re-search-forward (concat "^" header ":") nil t)
1278 (gnus-article-hide-text-type
1279 (progn (beginning-of-line) (point))
1282 (if (re-search-forward "^[^ \t]" nil t)
1287 (defvar gnus-article-normalized-header-length 40
1288 "Length of normalized headers.")
1290 (defun article-normalize-headers ()
1291 "Make all header lines 40 characters long."
1293 (let ((buffer-read-only nil)
1297 (article-narrow-to-head)
1300 ((< (setq column (- (gnus-point-at-eol) (point)))
1301 gnus-article-normalized-header-length)
1303 (insert (make-string
1304 (- gnus-article-normalized-header-length column)
1306 ((> column gnus-article-normalized-header-length)
1307 (gnus-put-text-property
1309 (forward-char gnus-article-normalized-header-length)
1316 (forward-line 1))))))
1318 (defun article-treat-dumbquotes ()
1319 "Translate M******** sm*rtq**t*s into proper text.
1320 Note that this function guesses whether a character is a sm*rtq**t* or
1321 not, so it should only be used interactively."
1323 (article-translate-strings gnus-article-dumbquotes-map))
1325 (defun article-translate-characters (from to)
1326 "Translate all characters in the body of the article according to FROM and TO.
1327 FROM is a string of characters to translate from; to is a string of
1328 characters to translate to."
1330 (when (article-goto-body)
1331 (let ((buffer-read-only nil)
1332 (x (make-string 225 ?x))
1334 (while (< (incf i) (length x))
1337 (while (< i (length from))
1338 (aset x (aref from i) (aref to i))
1340 (translate-region (point) (point-max) x)))))
1342 (defun article-translate-strings (map)
1343 "Translate all string in the body of the article according to MAP.
1344 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1346 (when (article-goto-body)
1347 (let ((buffer-read-only nil)
1349 (while (setq elem (pop map))
1351 (while (search-forward (car elem) nil t)
1352 (replace-match (cadr elem)))))))))
1354 (defun article-treat-overstrike ()
1355 "Translate overstrikes into bold text."
1358 (when (article-goto-body)
1359 (let ((buffer-read-only nil))
1360 (while (search-forward "\b" nil t)
1361 (let ((next (char-after))
1362 (previous (char-after (- (point) 2))))
1363 ;; We do the boldification/underlining by hiding the
1364 ;; overstrikes and putting the proper text property
1368 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1369 (put-text-property (point) (1+ (point)) 'face 'bold))
1371 (gnus-article-hide-text-type
1372 (1- (point)) (1+ (point)) 'overstrike)
1374 (- (point) 2) (1- (point)) 'face 'underline))
1376 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1378 (point) (1+ (point)) 'face 'underline)))))))))
1380 (defun article-fill-long-lines ()
1381 "Fill lines that are wider than the window width."
1384 (let ((buffer-read-only nil)
1385 (width (window-width (get-buffer-window (current-buffer)))))
1388 (let ((adaptive-fill-mode nil))
1391 (when (>= (current-column) (min fill-column width))
1392 (narrow-to-region (point) (gnus-point-at-bol))
1393 (fill-paragraph nil)
1394 (goto-char (point-max))
1396 (forward-line 1)))))))
1398 (defun article-capitalize-sentences ()
1399 "Capitalize the first word in each sentence."
1402 (let ((buffer-read-only nil)
1403 (paragraph-start "^[\n\^L]"))
1407 (forward-sentence)))))
1409 (defun article-remove-cr ()
1410 "Remove trailing CRs and then translate remaining CRs into LFs."
1413 (let ((buffer-read-only nil))
1414 (goto-char (point-min))
1415 (while (re-search-forward "\r+$" nil t)
1416 (replace-match "" t t))
1417 (goto-char (point-min))
1418 (while (search-forward "\r" nil t)
1419 (replace-match "\n" t t)))))
1421 (defun article-remove-trailing-blank-lines ()
1422 "Remove all trailing blank lines from the article."
1425 (let ((buffer-read-only nil))
1426 (goto-char (point-max))
1430 (while (and (not (bobp))
1431 (looking-at "^[ \t]*$")
1432 (not (gnus-annotation-in-region-p
1433 (point) (gnus-point-at-eol))))
1438 (defun article-display-x-face (&optional force)
1439 "Look for an X-Face header and display it if present."
1440 (interactive (list 'force))
1442 ;; Delete the old process, if any.
1443 (when (process-status "article-x-face")
1444 (delete-process "article-x-face"))
1445 (let ((inhibit-point-motion-hooks t)
1446 (case-fold-search t)
1449 (article-narrow-to-head)
1450 (goto-char (point-min))
1451 (setq from (message-fetch-field "from"))
1452 (goto-char (point-min))
1453 (while (and gnus-article-x-face-command
1456 ;; Check whether this face is censored.
1457 (not gnus-article-x-face-too-ugly)
1458 (and gnus-article-x-face-too-ugly from
1459 (not (string-match gnus-article-x-face-too-ugly
1461 ;; Has to be present.
1462 (re-search-forward "^X-Face: " nil t))
1463 ;; This used to try to do multiple faces (`while' instead of
1464 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1465 ;; work (b) it can crash some versions of Emacs (c) are
1466 ;; multiple faces really something to encourage?
1467 (when (stringp gnus-article-x-face-command)
1469 ;; We now have the area of the buffer where the X-Face is stored.
1472 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1473 ;; We display the face.
1474 (if (symbolp gnus-article-x-face-command)
1475 ;; The command is a lisp function, so we call it.
1476 (if (gnus-functionp gnus-article-x-face-command)
1477 (funcall gnus-article-x-face-command beg end)
1478 (error "%s is not a function" gnus-article-x-face-command))
1479 ;; The command is a string, so we interpret the command
1480 ;; as a, well, command, and fork it off.
1481 (let ((process-connection-type nil))
1482 (process-kill-without-query
1484 "article-x-face" nil shell-file-name shell-command-switch
1485 gnus-article-x-face-command))
1486 (process-send-region "article-x-face" beg end)
1487 (process-send-eof "article-x-face"))))))))))
1489 (defun article-decode-mime-words ()
1490 "Decode all MIME-encoded words in the article."
1493 (set-buffer gnus-article-buffer)
1494 (let ((inhibit-point-motion-hooks t)
1496 (mail-parse-charset gnus-newsgroup-charset)
1497 (mail-parse-ignored-charsets
1498 (save-excursion (set-buffer gnus-summary-buffer)
1499 gnus-newsgroup-ignored-charsets)))
1500 (mail-decode-encoded-word-region (point-min) (point-max)))))
1502 (defun article-decode-charset (&optional prompt)
1503 "Decode charset-encoded text in the article.
1504 If PROMPT (the prefix), prompt for a coding system to use."
1506 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1508 (mail-parse-charset gnus-newsgroup-charset)
1509 (mail-parse-ignored-charsets
1510 (save-excursion (condition-case nil
1511 (set-buffer gnus-summary-buffer)
1513 gnus-newsgroup-ignored-charsets))
1514 ct cte ctl charset format)
1517 (article-narrow-to-head)
1518 (setq ct (message-fetch-field "Content-Type" t)
1519 cte (message-fetch-field "Content-Transfer-Encoding" t)
1520 ctl (and ct (ignore-errors
1521 (mail-header-parse-content-type ct)))
1524 (mm-read-coding-system "Charset to decode: "))
1526 (mail-content-type-get ctl 'charset)))
1527 format (and ctl (mail-content-type-get ctl 'format)))
1529 (setq cte (mail-header-strip cte)))
1530 (if (and ctl (not (string-match "/" (car ctl))))
1532 (goto-char (point-max)))
1535 (narrow-to-region (point) (point-max))
1536 (when (and (eq mail-parse-charset 'gnus-decoded)
1537 (eq (mm-body-7-or-8) '8bit))
1538 ;; The text code could have been decoded.
1539 (setq charset mail-parse-charset))
1540 (when (and (or (not ctl)
1541 (equal (car ctl) "text/plain"))
1542 (not format)) ;; article with format will decode later.
1544 charset (and cte (intern (downcase
1545 (gnus-strip-whitespace cte))))
1548 (defun article-decode-encoded-words ()
1549 "Remove encoded-word encoding from headers."
1550 (let ((inhibit-point-motion-hooks t)
1551 (mail-parse-charset gnus-newsgroup-charset)
1552 (mail-parse-ignored-charsets
1553 (save-excursion (condition-case nil
1554 (set-buffer gnus-summary-buffer)
1556 gnus-newsgroup-ignored-charsets))
1559 (article-narrow-to-head)
1560 (funcall gnus-decode-header-function (point-min) (point-max)))))
1562 (defun article-de-quoted-unreadable (&optional force)
1563 "Translate a quoted-printable-encoded article.
1564 If FORCE, decode the article whether it is marked as quoted-printable
1566 (interactive (list 'force))
1568 (let ((buffer-read-only nil) type charset)
1569 (if (gnus-buffer-live-p gnus-original-article-buffer)
1570 (with-current-buffer gnus-original-article-buffer
1572 (gnus-fetch-field "content-transfer-encoding"))
1573 (let* ((ct (gnus-fetch-field "content-type"))
1576 (mail-header-parse-content-type ct)))))
1577 (setq charset (and ctl
1578 (mail-content-type-get ctl 'charset)))
1579 (if (stringp charset)
1580 (setq charset (intern (downcase charset)))))))
1582 (setq charset gnus-newsgroup-charset))
1584 (and type (let ((case-fold-search t))
1585 (string-match "quoted-printable" type))))
1587 (quoted-printable-decode-region
1588 (point) (point-max) (mm-charset-to-coding-system charset))))))
1590 (defun article-de-base64-unreadable (&optional force)
1591 "Translate a base64 article.
1592 If FORCE, decode the article whether it is marked as base64 not."
1593 (interactive (list 'force))
1595 (let ((buffer-read-only nil) type charset)
1596 (if (gnus-buffer-live-p gnus-original-article-buffer)
1597 (with-current-buffer gnus-original-article-buffer
1599 (gnus-fetch-field "content-transfer-encoding"))
1600 (let* ((ct (gnus-fetch-field "content-type"))
1603 (mail-header-parse-content-type ct)))))
1604 (setq charset (and ctl
1605 (mail-content-type-get ctl 'charset)))
1606 (if (stringp charset)
1607 (setq charset (intern (downcase charset)))))))
1609 (setq charset gnus-newsgroup-charset))
1611 (and type (let ((case-fold-search t))
1612 (string-match "base64" type))))
1615 (narrow-to-region (point) (point-max))
1616 (base64-decode-region (point-min) (point-max))
1617 (mm-decode-coding-region
1618 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1623 (defun article-decode-HZ ()
1624 "Translate a HZ-encoded article."
1628 (let ((buffer-read-only nil))
1629 (rfc1843-decode-region (point-min) (point-max)))))
1631 (defun article-wash-html ()
1632 "Format an html article."
1635 (let ((buffer-read-only nil)
1637 (if (gnus-buffer-live-p gnus-original-article-buffer)
1638 (with-current-buffer gnus-original-article-buffer
1639 (let* ((ct (gnus-fetch-field "content-type"))
1642 (mail-header-parse-content-type ct)))))
1643 (setq charset (and ctl
1644 (mail-content-type-get ctl 'charset)))
1645 (if (stringp charset)
1646 (setq charset (intern (downcase charset)))))))
1648 (setq charset gnus-newsgroup-charset))
1650 (save-window-excursion
1652 (narrow-to-region (point) (point-max))
1654 (let ((w3-strict-width (window-width))
1655 (url-standalone-mode t))
1657 (w3-region (point-min) (point-max))
1660 (defun article-hide-list-identifiers ()
1661 "Remove list identifies from the Subject header.
1662 The `gnus-list-identifiers' variable specifies what to do."
1666 (let ((inhibit-point-motion-hooks t)
1668 (article-narrow-to-head)
1669 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1670 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1672 (goto-char (point-min))
1673 (when (re-search-forward
1674 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1675 " *\\)\\)+\\(Re: +\\)?\\)")
1677 (let ((s (or (match-string 3) (match-string 5))))
1678 (delete-region (match-beginning 1) (match-end 1))
1680 (goto-char (match-beginning 1))
1683 (defun article-hide-pgp ()
1684 "Remove any PGP headers and signatures in the current article."
1688 (let ((inhibit-point-motion-hooks t)
1689 buffer-read-only beg end)
1691 ;; Hide the "header".
1692 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1693 (push 'pgp gnus-article-wash-types)
1694 (delete-region (match-beginning 0) (match-end 0))
1695 ;; Remove armor headers (rfc2440 6.2)
1696 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1699 ;; Hide the actual signature.
1700 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1701 (setq end (1+ (match-beginning 0)))
1704 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1706 ;; Perhaps we shouldn't hide to the end of the buffer
1707 ;; if there is no end to the signature?
1709 ;; Hide "- " PGP quotation markers.
1711 (narrow-to-region beg end)
1712 (goto-char (point-min))
1713 (while (re-search-forward "^- " nil t)
1715 (match-beginning 0) (match-end 0)))
1717 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1719 (defun article-hide-pem (&optional arg)
1720 "Toggle hiding of any PEM headers and signatures in the current article.
1721 If given a negative prefix, always show; if given a positive prefix,
1723 (interactive (gnus-article-hidden-arg))
1724 (unless (gnus-article-check-hidden-text 'pem arg)
1726 (let (buffer-read-only end)
1727 (goto-char (point-min))
1728 ;; Hide the horrendously ugly "header".
1729 (when (and (search-forward
1730 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1732 (setq end (1+ (match-beginning 0))))
1733 (push 'pem gnus-article-wash-types)
1734 (gnus-article-hide-text-type
1736 (if (search-forward "\n\n" nil t)
1740 ;; Hide the trailer as well
1741 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1743 (gnus-article-hide-text-type
1744 (match-beginning 0) (match-end 0) 'pem)))))))
1746 (defun article-strip-banner ()
1747 "Strip the banner specified by the `banner' group parameter."
1751 (let ((inhibit-point-motion-hooks t)
1752 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1753 (gnus-signature-limit nil)
1754 buffer-read-only beg end)
1758 ((eq banner 'signature)
1759 (when (gnus-article-narrow-to-signature)
1762 (delete-region (point) (point-max))))
1764 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1765 (while (re-search-forward banner nil t)
1766 (delete-region (match-beginning 0) (match-end 0)))))
1768 (while (re-search-forward banner nil t)
1769 (delete-region (match-beginning 0) (match-end 0))))))))))
1771 (defun article-babel ()
1772 "Translate article using an online translation service."
1776 (set-buffer gnus-article-buffer)
1777 (when (article-goto-body)
1778 (let* ((buffer-read-only nil)
1781 (orig (buffer-substring start end))
1782 (trans (babel-as-string orig)))
1784 (narrow-to-region start end)
1785 (delete-region start end)
1788 (defun article-hide-signature (&optional arg)
1789 "Hide the signature in the current article.
1790 If given a negative prefix, always show; if given a positive prefix,
1792 (interactive (gnus-article-hidden-arg))
1793 (unless (gnus-article-check-hidden-text 'signature arg)
1796 (let ((buffer-read-only nil))
1797 (when (gnus-article-narrow-to-signature)
1798 (gnus-article-hide-text-type
1799 (point-min) (point-max) 'signature)))))))
1801 (defun article-strip-headers-in-body ()
1802 "Strip offensive headers from bodies."
1806 (let ((case-fold-search t))
1807 (when (looking-at "x-no-archive:")
1808 (gnus-delete-line)))))
1810 (defun article-strip-leading-blank-lines ()
1811 "Remove all blank lines from the beginning of the article."
1814 (let ((inhibit-point-motion-hooks t)
1816 (when (article-goto-body)
1817 (while (and (not (eobp))
1818 (looking-at "[ \t]*$"))
1819 (gnus-delete-line))))))
1821 (defun article-narrow-to-head ()
1822 "Narrow the buffer to the head of the message.
1823 Point is left at the beginning of the narrowed-to region."
1825 (goto-char (point-min))
1826 (if (search-forward "\n\n" nil 1)
1829 (goto-char (point-min)))
1831 (defun article-goto-body ()
1832 "Place point at the start of the body."
1833 (goto-char (point-min))
1835 ;; This variable is only bound when dealing with separate
1837 (article-goto-body-goes-to-point-min-p
1839 ((search-forward "\n\n" nil t)
1842 (goto-char (point-max))
1845 (defun article-strip-multiple-blank-lines ()
1846 "Replace consecutive blank lines with one empty line."
1849 (let ((inhibit-point-motion-hooks t)
1851 ;; First make all blank lines empty.
1853 (while (re-search-forward "^[ \t]+$" nil t)
1854 (unless (gnus-annotation-in-region-p
1855 (match-beginning 0) (match-end 0))
1856 (replace-match "" nil t)))
1857 ;; Then replace multiple empty lines with a single empty line.
1859 (while (re-search-forward "\n\n\n+" nil t)
1860 (unless (gnus-annotation-in-region-p
1861 (match-beginning 0) (match-end 0))
1862 (replace-match "\n\n" t t))))))
1864 (defun article-strip-leading-space ()
1865 "Remove all white space from the beginning of the lines in the article."
1868 (let ((inhibit-point-motion-hooks t)
1871 (while (re-search-forward "^[ \t]+" nil t)
1872 (replace-match "" t t)))))
1874 (defun article-strip-trailing-space ()
1875 "Remove all white space from the end of the lines in the article."
1878 (let ((inhibit-point-motion-hooks t)
1881 (while (re-search-forward "[ \t]+$" nil t)
1882 (replace-match "" t t)))))
1884 (defun article-strip-blank-lines ()
1885 "Strip leading, trailing and multiple blank lines."
1887 (article-strip-leading-blank-lines)
1888 (article-remove-trailing-blank-lines)
1889 (article-strip-multiple-blank-lines))
1891 (defun article-strip-all-blank-lines ()
1892 "Strip all blank lines."
1895 (let ((inhibit-point-motion-hooks t)
1898 (while (re-search-forward "^[ \t]*\n" nil t)
1899 (replace-match "" t t)))))
1901 (defun gnus-article-narrow-to-signature ()
1902 "Narrow to the signature; return t if a signature is found, else nil."
1903 (let ((inhibit-point-motion-hooks t))
1904 (when (gnus-article-search-signature)
1906 ;; Check whether we have some limits to what we consider
1907 ;; to be a signature.
1908 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1909 (list gnus-signature-limit)))
1911 (while (setq limit (pop limits))
1912 (if (or (and (integerp limit)
1913 (< (- (point-max) (point)) limit))
1915 (< (count-lines (point) (point-max)) limit))
1916 (and (gnus-functionp limit)
1918 (and (stringp limit)
1919 (not (re-search-forward limit nil t))))
1920 () ; This limit did not succeed.
1924 (narrow-to-region (point) (point-max))
1927 (defun gnus-article-search-signature ()
1928 "Search the current buffer for the signature separator.
1929 Put point at the beginning of the signature separator."
1930 (let ((cur (point)))
1931 (goto-char (point-max))
1932 (if (if (stringp gnus-signature-separator)
1933 (re-search-backward gnus-signature-separator nil t)
1934 (let ((seps gnus-signature-separator))
1936 (not (re-search-backward (car seps) nil t)))
1943 (defun gnus-article-hidden-arg ()
1944 "Return the current prefix arg as a number, or 0 if no prefix."
1945 (list (if current-prefix-arg
1946 (prefix-numeric-value current-prefix-arg)
1949 (defun gnus-article-check-hidden-text (type arg)
1950 "Return nil if hiding is necessary.
1951 Arg can be nil or a number. Nil and positive means hide, negative
1952 means show, 0 means toggle."
1955 (let ((hide (gnus-article-hidden-text-p type)))
1961 (gnus-article-show-hidden-text type))
1963 (if (eq hide 'hidden)
1964 (gnus-article-show-hidden-text type)
1967 (defun gnus-article-hidden-text-p (type)
1968 "Say whether the current buffer contains hidden text of type TYPE."
1969 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1971 (not (get-text-property pos 'invisible))
1972 (not (get-text-property pos 'dummy-invisible)))
1974 (text-property-any (1+ pos) (point-max) 'article-type type)))
1979 (defun gnus-article-show-hidden-text (type &optional hide)
1980 "Show all hidden text of type TYPE.
1981 If HIDE, hide the text instead."
1983 (let ((buffer-read-only nil)
1984 (inhibit-point-motion-hooks t)
1987 (while (setq beg (text-property-any end (point-max) 'article-type type))
1990 (text-property-not-all beg (point-max) 'article-type type)
1993 (gnus-article-hide-text beg end gnus-hidden-properties)
1994 (gnus-article-unhide-text beg end))
1998 (defconst article-time-units
1999 `((year . ,(* 365.25 24 60 60))
2000 (week . ,(* 7 24 60 60))
2001 (day . ,(* 24 60 60))
2005 "Mapping from time units to seconds.")
2007 (defun article-date-ut (&optional type highlight header)
2008 "Convert DATE date to universal time in the current article.
2009 If TYPE is `local', convert to local time; if it is `lapsed', output
2010 how much time has lapsed since DATE. For `lapsed', the value of
2011 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2012 should replace the \"Date:\" one, or should be added below it."
2013 (interactive (list 'ut t))
2014 (let* ((header (or header
2015 (message-fetch-field "date")
2017 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2020 ((not gnus-article-date-lapsed-new-header)
2026 (date (if (vectorp header) (mail-header-date header)
2028 (inhibit-point-motion-hooks t)
2033 (article-narrow-to-head)
2034 (when (re-search-forward tdate-regexp nil t)
2035 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2036 date (or (get-text-property (gnus-point-at-bol)
2039 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2041 (when (and date (not (string= date "")))
2042 (goto-char (point-min))
2043 (let ((buffer-read-only nil))
2044 ;; Delete any old Date headers.
2045 (while (re-search-forward date-regexp nil t)
2047 (delete-region (progn (beginning-of-line) (point))
2048 (progn (forward-line 1) (point)))
2049 (delete-region (progn (beginning-of-line) (point))
2050 (progn (end-of-line) (point)))
2051 (setq pos (point))))
2052 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2054 (if pos (goto-char pos))
2055 (insert (article-make-date-line date (or type 'ut)))
2061 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2062 (put-text-property (match-beginning 1) (1+ (match-end 1))
2063 'original-date date)
2064 (put-text-property (match-beginning 1) (1+ (match-end 1))
2066 (put-text-property (match-beginning 2) (match-end 2)
2069 (defun article-make-date-line (date type)
2070 "Return a DATE line of TYPE."
2071 (let ((time (condition-case ()
2075 ;; Convert to the local timezone. We have to slap a
2076 ;; `condition-case' round the calls to the timezone
2077 ;; functions since they aren't particularly resistant to
2080 (let ((tz (car (current-time-zone time))))
2081 (format "Date: %s %s%02d%02d" (current-time-string time)
2082 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2083 (/ (% (abs tz) 3600) 60))))
2084 ;; Convert to Universal Time.
2087 (current-time-string
2088 (let* ((e (parse-time-string date))
2089 (tm (apply 'encode-time e))
2091 (ls (- (cadr tm) (car (current-time-zone time)))))
2092 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2093 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2096 ;; Get the original date from the article.
2097 ((eq type 'original)
2098 (concat "Date: " (if (string-match "\n+$" date)
2099 (substring date 0 (match-beginning 0))
2101 ;; Let the user define the format.
2103 (if (gnus-functionp gnus-article-time-format)
2104 (funcall gnus-article-time-format time)
2107 (format-time-string gnus-article-time-format time))))
2110 (let ((tz (car (current-time-zone time))))
2113 (format-time-string "%Y%m%dT%H%M%S" time)
2114 (format "%s%02d%02d"
2115 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2116 (/ (% (abs tz) 3600) 60)))))
2117 ;; Do an X-Sent lapsed format.
2119 ;; If the date is seriously mangled, the timezone functions are
2120 ;; liable to bug out, so we ignore all errors.
2121 (let* ((now (current-time))
2122 (real-time (subtract-time now time))
2123 (real-sec (and real-time
2124 (+ (* (float (car real-time)) 65536)
2126 (sec (and real-time (abs real-sec)))
2136 ;; This is a bit convoluted, but basically we go
2137 ;; through the time units for years, weeks, etc,
2138 ;; and divide things to see whether that results
2139 ;; in positive answers.
2142 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2143 ;; The (remaining) seconds are too few to
2144 ;; be divided into this time unit.
2146 ;; It's big enough, so we output it.
2147 (setq sec (- sec (* num (cdr unit))))
2149 (concat (if prev ", " "") (int-to-string
2151 " " (symbol-name (car unit))
2152 (if (> num 1) "s" ""))
2154 article-time-units "")
2155 ;; If dates are odd, then it might appear like the
2156 ;; article was sent in the future.
2159 " in the future"))))))
2161 (error "Unknown conversion type: %s" type)))))
2163 (defun article-date-local (&optional highlight)
2164 "Convert the current article date to the local timezone."
2165 (interactive (list t))
2166 (article-date-ut 'local highlight))
2168 (defun article-date-original (&optional highlight)
2169 "Convert the current article date to what it was originally.
2170 This is only useful if you have used some other date conversion
2171 function and want to see what the date was before converting."
2172 (interactive (list t))
2173 (article-date-ut 'original highlight))
2175 (defun article-date-lapsed (&optional highlight)
2176 "Convert the current article date to time lapsed since it was sent."
2177 (interactive (list t))
2178 (article-date-ut 'lapsed highlight))
2180 (defun article-update-date-lapsed ()
2181 "Function to be run from a timer to update the lapsed time line."
2182 (let (deactivate-mark)
2187 (set-buffer (window-buffer w))
2188 (when (eq major-mode 'gnus-article-mode)
2189 (goto-char (point-min))
2190 (when (re-search-forward "^X-Sent:" nil t)
2191 (article-date-lapsed t))))
2194 (defun gnus-start-date-timer (&optional n)
2195 "Start a timer to update the X-Sent header in the article buffers.
2196 The numerical prefix says how frequently (in seconds) the function
2201 (gnus-stop-date-timer)
2202 (setq article-lapsed-timer
2203 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2205 (defun gnus-stop-date-timer ()
2206 "Stop the X-Sent timer."
2208 (when article-lapsed-timer
2209 (nnheader-cancel-timer article-lapsed-timer)
2210 (setq article-lapsed-timer nil)))
2212 (defun article-date-user (&optional highlight)
2213 "Convert the current article date to the user-defined format.
2214 This format is defined by the `gnus-article-time-format' variable."
2215 (interactive (list t))
2216 (article-date-ut 'user highlight))
2218 (defun article-date-iso8601 (&optional highlight)
2219 "Convert the current article date to ISO8601."
2220 (interactive (list t))
2221 (article-date-ut 'iso8601 highlight))
2223 (defun article-show-all ()
2224 "Show all hidden text in the article buffer."
2227 (let ((buffer-read-only nil))
2228 (gnus-article-unhide-text (point-min) (point-max)))))
2230 (defun article-emphasize (&optional arg)
2231 "Emphasize text according to `gnus-emphasis-alist'."
2232 (interactive (gnus-article-hidden-arg))
2233 (unless (gnus-article-check-hidden-text 'emphasis arg)
2237 (with-current-buffer gnus-summary-buffer
2238 gnus-article-emphasis-alist)
2240 gnus-emphasis-alist))
2241 (buffer-read-only nil)
2242 (props (append '(article-type emphasis)
2243 gnus-hidden-properties))
2244 regexp elem beg invisible visible face)
2247 (while (setq elem (pop alist))
2249 (setq regexp (car elem)
2250 invisible (nth 1 elem)
2251 visible (nth 2 elem)
2253 (while (re-search-forward regexp nil t)
2254 (when (and (match-beginning visible) (match-beginning invisible))
2255 (push 'emphasis gnus-article-wash-types)
2256 (gnus-article-hide-text
2257 (match-beginning invisible) (match-end invisible) props)
2258 (gnus-article-unhide-text-type
2259 (match-beginning visible) (match-end visible) 'emphasis)
2260 (gnus-put-text-property-excluding-newlines
2261 (match-beginning visible) (match-end visible) 'face face)
2262 (goto-char (match-end invisible)))))))))
2264 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2265 "Setup newsgroup emphasis alist."
2266 (unless gnus-article-emphasis-alist
2267 (let ((name (and gnus-newsgroup-name
2268 (gnus-group-real-name gnus-newsgroup-name))))
2269 (make-local-variable 'gnus-article-emphasis-alist)
2270 (setq gnus-article-emphasis-alist
2272 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2273 (while (setq elem (pop alist))
2274 (when (and name (string-match (car elem) name))
2276 highlight (copy-sequence (cdr elem)))))
2278 (copy-sequence highlight-words)
2279 (if gnus-newsgroup-name
2280 (copy-sequence (gnus-group-find-parameter
2281 gnus-newsgroup-name 'highlight-words t)))
2282 gnus-emphasis-alist)))))
2284 (defvar gnus-summary-article-menu)
2285 (defvar gnus-summary-post-menu)
2287 ;;; Saving functions.
2289 (defun gnus-article-save (save-buffer file &optional num)
2290 "Save the currently selected article."
2291 (unless gnus-save-all-headers
2292 ;; Remove headers according to `gnus-saved-headers'.
2293 (let ((gnus-visible-headers
2294 (or gnus-saved-headers gnus-visible-headers))
2295 (gnus-article-buffer save-buffer))
2297 (set-buffer save-buffer)
2298 (article-hide-headers 1 t))))
2299 (save-window-excursion
2300 (if (not gnus-default-article-saver)
2301 (error "No default saver is defined")
2302 ;; !!! Magic! The saving functions all save
2303 ;; `gnus-save-article-buffer' (or so they think), but we
2304 ;; bind that variable to our save-buffer.
2305 (set-buffer gnus-article-buffer)
2306 (let* ((gnus-save-article-buffer save-buffer)
2309 ((not gnus-prompt-before-saving) 'default)
2310 ((eq gnus-prompt-before-saving 'always) nil)
2312 (gnus-number-of-articles-to-be-saved
2313 (when (eq gnus-prompt-before-saving t)
2315 (set-buffer gnus-article-current-summary)
2316 (funcall gnus-default-article-saver filename)))))
2318 (defun gnus-read-save-file-name (prompt &optional filename
2319 function group headers variable)
2321 (funcall function group headers (symbol-value variable)))
2326 ((eq filename 'default)
2332 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2335 (if (and gnus-number-of-articles-to-be-saved
2336 (> gnus-number-of-articles-to-be-saved 1))
2337 (format "these %d articles"
2338 gnus-number-of-articles-to-be-saved)
2341 ;; Let the split methods have their say.
2343 ;; No split name was found.
2346 (concat prompt " (default "
2347 (file-name-nondirectory default-name) ") ")
2348 (file-name-directory default-name)
2350 ;; A single group name is returned.
2351 ((stringp split-name)
2353 (funcall function split-name headers
2354 (symbol-value variable)))
2356 (concat prompt " (default "
2357 (file-name-nondirectory default-name) ") ")
2358 (file-name-directory default-name)
2360 ;; A single split name was found
2361 ((= 1 (length split-name))
2362 (let* ((name (expand-file-name
2363 (car split-name) gnus-article-save-directory))
2364 (dir (cond ((file-directory-p name)
2365 (file-name-as-directory name))
2366 ((file-exists-p name) name)
2367 (t gnus-article-save-directory))))
2369 (concat prompt " (default " name ") ")
2371 ;; A list of splits was found.
2373 (setq split-name (nreverse split-name))
2375 (let ((file-name-history
2376 (nconc split-name file-name-history)))
2380 (concat prompt " (`M-p' for defaults) ")
2381 gnus-article-save-directory
2383 gnus-article-save-directory)))
2384 (car (push result file-name-history)))))))
2385 ;; Create the directory.
2386 (gnus-make-directory (file-name-directory file))
2387 ;; If we have read a directory, we append the default file name.
2388 (when (file-directory-p file)
2389 (setq file (expand-file-name (file-name-nondirectory default-name)
2390 (file-name-as-directory file))))
2391 ;; Possibly translate some characters.
2392 (nnheader-translate-file-chars file))))))
2393 (gnus-make-directory (file-name-directory result))
2394 (set variable result)))
2396 (defun gnus-article-archive-name (group)
2397 "Return the first instance of an \"Archive-name\" in the current buffer."
2398 (let ((case-fold-search t))
2399 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2400 (nnheader-concat gnus-article-save-directory
2401 (match-string 1)))))
2403 (defun gnus-article-nndoc-name (group)
2404 "If GROUP is an nndoc group, return the name of the parent group."
2405 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2406 (gnus-group-get-parameter group 'save-article-group)))
2408 (defun gnus-summary-save-in-rmail (&optional filename)
2409 "Append this article to Rmail file.
2410 Optional argument FILENAME specifies file name.
2411 Directory to save to is default to `gnus-article-save-directory'."
2412 (setq filename (gnus-read-save-file-name
2413 "Save %s in rmail file:" filename
2414 gnus-rmail-save-name gnus-newsgroup-name
2415 gnus-current-headers 'gnus-newsgroup-last-rmail))
2416 (gnus-eval-in-buffer-window gnus-save-article-buffer
2420 (gnus-output-to-rmail filename))))
2423 (defun gnus-summary-save-in-mail (&optional filename)
2424 "Append this article to Unix mail file.
2425 Optional argument FILENAME specifies file name.
2426 Directory to save to is default to `gnus-article-save-directory'."
2427 (setq filename (gnus-read-save-file-name
2428 "Save %s in Unix mail file:" filename
2429 gnus-mail-save-name gnus-newsgroup-name
2430 gnus-current-headers 'gnus-newsgroup-last-mail))
2431 (gnus-eval-in-buffer-window gnus-save-article-buffer
2435 (if (and (file-readable-p filename)
2436 (mail-file-babyl-p filename))
2437 (rmail-output-to-rmail-file filename t)
2438 (gnus-output-to-mail filename)))))
2441 (defun gnus-summary-save-in-file (&optional filename overwrite)
2442 "Append this article to file.
2443 Optional argument FILENAME specifies file name.
2444 Directory to save to is default to `gnus-article-save-directory'."
2445 (setq filename (gnus-read-save-file-name
2446 "Save %s in file:" filename
2447 gnus-file-save-name gnus-newsgroup-name
2448 gnus-current-headers 'gnus-newsgroup-last-file))
2449 (gnus-eval-in-buffer-window gnus-save-article-buffer
2453 (when (and overwrite
2454 (file-exists-p filename))
2455 (delete-file filename))
2456 (gnus-output-to-file filename))))
2459 (defun gnus-summary-write-to-file (&optional filename)
2460 "Write this article to a file.
2461 Optional argument FILENAME specifies file name.
2462 The directory to save in defaults to `gnus-article-save-directory'."
2463 (gnus-summary-save-in-file nil t))
2465 (defun gnus-summary-save-body-in-file (&optional filename)
2466 "Append this article body to a file.
2467 Optional argument FILENAME specifies file name.
2468 The directory to save in defaults to `gnus-article-save-directory'."
2469 (setq filename (gnus-read-save-file-name
2470 "Save %s body in file:" filename
2471 gnus-file-save-name gnus-newsgroup-name
2472 gnus-current-headers 'gnus-newsgroup-last-file))
2473 (gnus-eval-in-buffer-window gnus-save-article-buffer
2477 (when (article-goto-body)
2478 (narrow-to-region (point) (point-max)))
2479 (gnus-output-to-file filename))))
2482 (defun gnus-summary-save-in-pipe (&optional command)
2483 "Pipe this article to subprocess."
2485 (cond ((and (eq command 'default)
2486 gnus-last-shell-command)
2487 gnus-last-shell-command)
2491 "Shell command on %s: "
2492 (if (and gnus-number-of-articles-to-be-saved
2493 (> gnus-number-of-articles-to-be-saved 1))
2494 (format "these %d articles"
2495 gnus-number-of-articles-to-be-saved)
2497 gnus-last-shell-command))))
2498 (when (string-equal command "")
2499 (setq command gnus-last-shell-command))
2500 (gnus-eval-in-buffer-window gnus-article-buffer
2503 (shell-command-on-region (point-min) (point-max) command nil)))
2504 (setq gnus-last-shell-command command))
2506 ;;; Article file names when saving.
2508 (defun gnus-capitalize-newsgroup (newsgroup)
2509 "Capitalize NEWSGROUP name."
2510 (when (not (zerop (length newsgroup)))
2511 (concat (char-to-string (upcase (aref newsgroup 0)))
2512 (substring newsgroup 1))))
2514 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2515 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2516 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2517 Otherwise, it is like ~/News/news/group/num."
2520 (concat (if (gnus-use-long-file-name 'not-save)
2521 (gnus-capitalize-newsgroup newsgroup)
2522 (gnus-newsgroup-directory-form newsgroup))
2523 "/" (int-to-string (mail-header-number headers)))
2524 gnus-article-save-directory)))
2526 (string-equal (file-name-directory default)
2527 (file-name-directory last-file))
2528 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2530 (or last-file default))))
2532 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2533 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2534 If variable `gnus-use-long-file-name' is non-nil, it is
2535 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2538 (concat (if (gnus-use-long-file-name 'not-save)
2540 (gnus-newsgroup-directory-form newsgroup))
2541 "/" (int-to-string (mail-header-number headers)))
2542 gnus-article-save-directory)))
2544 (string-equal (file-name-directory default)
2545 (file-name-directory last-file))
2546 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2548 (or last-file default))))
2550 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2551 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2552 If variable `gnus-use-long-file-name' is non-nil, it is
2553 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2556 (if (gnus-use-long-file-name 'not-save)
2558 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2559 gnus-article-save-directory)))
2566 (setq afunc (car func)
2569 gfunc (intern (format "gnus-%s" func))))
2572 `(lambda (&optional interactive &rest args)
2573 ,(documentation afunc t)
2574 (interactive (list t))
2576 (set-buffer gnus-article-buffer)
2578 (call-interactively ',afunc)
2579 (apply ',afunc args))))))))
2580 '(article-hide-headers
2581 article-hide-boring-headers
2582 article-treat-overstrike
2583 article-fill-long-lines
2584 article-capitalize-sentences
2586 article-display-x-face
2587 article-de-quoted-unreadable
2588 article-de-base64-unreadable
2591 article-hide-list-identifiers
2593 article-strip-banner
2596 article-hide-signature
2597 article-strip-headers-in-body
2598 article-remove-trailing-blank-lines
2599 article-strip-leading-blank-lines
2600 article-strip-multiple-blank-lines
2601 article-strip-leading-space
2602 article-strip-trailing-space
2603 article-strip-blank-lines
2604 article-strip-all-blank-lines
2606 article-date-iso8601
2607 article-date-original
2609 article-decode-mime-words
2610 article-decode-charset
2611 article-decode-encoded-words
2615 article-treat-dumbquotes
2616 article-normalize-headers
2617 (article-show-all . gnus-article-show-all-headers))))
2620 ;;; Gnus article mode
2623 (put 'gnus-article-mode 'mode-class 'special)
2625 (set-keymap-parent gnus-article-mode-map widget-keymap)
2627 (gnus-define-keys gnus-article-mode-map
2628 " " gnus-article-goto-next-page
2629 "\177" gnus-article-goto-prev-page
2630 [delete] gnus-article-goto-prev-page
2631 [backspace] gnus-article-goto-prev-page
2632 "\C-c^" gnus-article-refer-article
2633 "h" gnus-article-show-summary
2634 "s" gnus-article-show-summary
2635 "\C-c\C-m" gnus-article-mail
2636 "?" gnus-article-describe-briefly
2637 "e" gnus-summary-edit-article
2638 "<" beginning-of-buffer
2640 "\C-c\C-i" gnus-info-find-node
2643 "\C-d" gnus-article-read-summary-keys
2644 "\M-*" gnus-article-read-summary-keys
2645 "\M-#" gnus-article-read-summary-keys
2646 "\M-^" gnus-article-read-summary-keys
2647 "\M-g" gnus-article-read-summary-keys)
2649 (substitute-key-definition
2650 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2652 (defun gnus-article-make-menu-bar ()
2653 (gnus-turn-off-edit-menu 'article)
2654 (unless (boundp 'gnus-article-article-menu)
2656 gnus-article-article-menu gnus-article-mode-map ""
2658 ["Scroll forwards" gnus-article-goto-next-page t]
2659 ["Scroll backwards" gnus-article-goto-prev-page t]
2660 ["Show summary" gnus-article-show-summary t]
2661 ["Fetch Message-ID at point" gnus-article-refer-article t]
2662 ["Mail to address at point" gnus-article-mail t]
2663 ["Send a bug report" gnus-bug t]))
2666 gnus-article-treatment-menu gnus-article-mode-map ""
2667 ;; Fixme: this should use :active (and maybe :visible).
2669 ["Hide headers" gnus-article-hide-headers t]
2670 ["Hide signature" gnus-article-hide-signature t]
2671 ["Hide citation" gnus-article-hide-citation t]
2672 ["Treat overstrike" gnus-article-treat-overstrike t]
2673 ["Remove carriage return" gnus-article-remove-cr t]
2674 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2675 ["Remove base64" gnus-article-de-base64-unreadable t]
2676 ["Treat html" gnus-article-wash-html t]
2677 ["Decode HZ" gnus-article-decode-HZ t]))
2679 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2681 (when (boundp 'gnus-summary-post-menu)
2682 (define-key gnus-article-mode-map [menu-bar post]
2683 (cons "Post" gnus-summary-post-menu)))
2685 (gnus-run-hooks 'gnus-article-menu-hook)))
2687 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2690 (defun gnus-article-mode ()
2691 "Major mode for displaying an article.
2693 All normal editing commands are switched off.
2695 The following commands are available in addition to all summary mode
2697 \\<gnus-article-mode-map>
2698 \\[gnus-article-next-page]\t Scroll the article one page forwards
2699 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2700 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2701 \\[gnus-article-show-summary]\t Display the summary buffer
2702 \\[gnus-article-mail]\t Send a reply to the address near point
2703 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2704 \\[gnus-info-find-node]\t Go to the Gnus info node"
2706 (when (gnus-visual-p 'article-menu 'menu)
2707 (gnus-article-make-menu-bar))
2708 (gnus-simplify-mode-line)
2709 (setq mode-name "Article")
2710 (setq major-mode 'gnus-article-mode)
2711 (make-local-variable 'minor-mode-alist)
2712 (use-local-map gnus-article-mode-map)
2713 (gnus-update-format-specifications nil 'article-mode)
2714 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2715 (make-local-variable 'gnus-page-broken)
2716 (make-local-variable 'gnus-button-marker-list)
2717 (make-local-variable 'gnus-article-current-summary)
2718 (make-local-variable 'gnus-article-mime-handles)
2719 (make-local-variable 'gnus-article-decoded-p)
2720 (make-local-variable 'gnus-article-mime-handle-alist)
2721 (make-local-variable 'gnus-article-wash-types)
2722 (gnus-set-default-directory)
2723 (buffer-disable-undo)
2724 (setq buffer-read-only t)
2725 (set-syntax-table gnus-article-mode-syntax-table)
2726 (mm-enable-multibyte)
2727 (gnus-run-hooks 'gnus-article-mode-hook))
2729 (defun gnus-article-setup-buffer ()
2730 "Initialize the article buffer."
2731 (let* ((name (if gnus-single-article-buffer "*Article*"
2732 (concat "*Article " gnus-newsgroup-name "*")))
2734 (progn (string-match "\\*Article" name)
2735 (concat " *Original Article"
2736 (substring name (match-end 0))))))
2737 (setq gnus-article-buffer name)
2738 (setq gnus-original-article-buffer original)
2739 (setq gnus-article-mime-handle-alist nil)
2740 ;; This might be a variable local to the summary buffer.
2741 (unless gnus-single-article-buffer
2743 (set-buffer gnus-summary-buffer)
2744 (setq gnus-article-buffer name)
2745 (setq gnus-original-article-buffer original)
2746 (gnus-set-global-variables)))
2747 (gnus-article-setup-highlight-words)
2748 ;; Init original article buffer.
2750 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2751 (mm-enable-multibyte)
2752 (setq major-mode 'gnus-original-article-mode)
2753 (make-local-variable 'gnus-original-article))
2754 (if (get-buffer name)
2757 (when gnus-article-mime-handles
2758 (mm-destroy-parts gnus-article-mime-handles)
2759 (setq gnus-article-mime-handles nil))
2760 ;; Set it to nil in article-buffer!
2761 (setq gnus-article-mime-handle-alist nil)
2762 (buffer-disable-undo)
2763 (setq buffer-read-only t)
2764 (unless (eq major-mode 'gnus-article-mode)
2765 (gnus-article-mode))
2768 (set-buffer (gnus-get-buffer-create name))
2770 (make-local-variable 'gnus-summary-buffer)
2771 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2772 (current-buffer)))))
2774 ;; Set article window start at LINE, where LINE is the number of lines
2775 ;; from the head of the article.
2776 (defun gnus-article-set-window-start (&optional line)
2778 (get-buffer-window gnus-article-buffer t)
2780 (set-buffer gnus-article-buffer)
2781 (goto-char (point-min))
2784 (gnus-message 6 "Moved to bookmark")
2785 (search-forward "\n\n" nil t)
2789 (defun gnus-article-prepare (article &optional all-headers header)
2790 "Prepare ARTICLE in article mode buffer.
2791 ARTICLE should either be an article number or a Message-ID.
2792 If ARTICLE is an id, HEADER should be the article headers.
2793 If ALL-HEADERS is non-nil, no headers are hidden."
2795 ;; Make sure we start in a summary buffer.
2796 (unless (eq major-mode 'gnus-summary-mode)
2797 (set-buffer gnus-summary-buffer))
2798 (setq gnus-summary-buffer (current-buffer))
2799 (let* ((gnus-article (if header (mail-header-number header) article))
2800 (summary-buffer (current-buffer))
2801 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2802 (group gnus-newsgroup-name)
2805 (gnus-article-setup-buffer)
2806 (set-buffer gnus-article-buffer)
2807 ;; Deactivate active regions.
2808 (when (and (boundp 'transient-mark-mode)
2809 transient-mark-mode)
2810 (setq mark-active nil))
2811 (if (not (setq result (let ((buffer-read-only nil))
2812 (gnus-request-article-this-buffer
2814 ;; There is no such article.
2816 (when (and (numberp article)
2817 (not (memq article gnus-newsgroup-sparse)))
2818 (setq gnus-article-current
2819 (cons gnus-newsgroup-name article))
2820 (set-buffer gnus-summary-buffer)
2821 (setq gnus-current-article article)
2822 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2824 (gnus-summary-set-agent-mark article)
2825 (message "Message marked for downloading"))
2826 (gnus-summary-mark-article article gnus-canceled-mark)
2827 (unless (memq article gnus-newsgroup-sparse)
2828 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2829 (if (or (eq result 'pseudo)
2830 (eq result 'nneething))
2833 (set-buffer summary-buffer)
2834 (push article gnus-newsgroup-history)
2835 (setq gnus-last-article gnus-current-article
2836 gnus-current-article 0
2837 gnus-current-headers nil
2838 gnus-article-current nil)
2839 (if (eq result 'nneething)
2840 (gnus-configure-windows 'summary)
2841 (gnus-configure-windows 'article))
2842 (gnus-set-global-variables))
2843 (let ((gnus-article-mime-handle-alist-1
2844 gnus-article-mime-handle-alist))
2845 (gnus-set-mode-line 'article)))
2846 ;; The result from the `request' was an actual article -
2847 ;; or at least some text that is now displayed in the
2849 (when (and (numberp article)
2850 (not (eq article gnus-current-article)))
2851 ;; Seems like a new article has been selected.
2852 ;; `gnus-current-article' must be an article number.
2854 (set-buffer summary-buffer)
2855 (push article gnus-newsgroup-history)
2856 (setq gnus-last-article gnus-current-article
2857 gnus-current-article article
2858 gnus-current-headers
2859 (gnus-summary-article-header gnus-current-article)
2860 gnus-article-current
2861 (cons gnus-newsgroup-name gnus-current-article))
2862 (unless (vectorp gnus-current-headers)
2863 (setq gnus-current-headers nil))
2864 (gnus-summary-goto-subject gnus-current-article)
2865 (when (gnus-summary-show-thread)
2866 ;; If the summary buffer really was folded, the
2867 ;; previous goto may not actually have gone to
2868 ;; the right article, but the thread root instead.
2870 (gnus-summary-goto-subject gnus-current-article))
2871 (gnus-run-hooks 'gnus-mark-article-hook)
2872 (gnus-set-mode-line 'summary)
2873 (when (gnus-visual-p 'article-highlight 'highlight)
2874 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2875 ;; Set the global newsgroup variables here.
2876 (gnus-set-global-variables)
2877 (setq gnus-have-all-headers
2878 (or all-headers gnus-show-all-headers))))
2880 (gnus-configure-windows 'article))
2881 (when (or (numberp article)
2883 (gnus-article-prepare-display)
2885 (goto-char (point-min))
2886 (setq gnus-page-broken
2887 (when gnus-break-pages
2888 (gnus-narrow-to-page)
2890 (let ((gnus-article-mime-handle-alist-1
2891 gnus-article-mime-handle-alist))
2892 (gnus-set-mode-line 'article))
2894 (set-window-point (get-buffer-window (current-buffer)) (point))
2895 (gnus-configure-windows 'article)
2899 (defun gnus-article-prepare-display ()
2900 "Make the current buffer look like a nice article."
2901 ;; Hooks for getting information from the article.
2902 ;; This hook must be called before being narrowed.
2903 (let ((gnus-article-buffer (current-buffer))
2905 (unless (eq major-mode 'gnus-article-mode)
2906 (gnus-article-mode))
2907 (setq buffer-read-only nil
2908 gnus-article-wash-types nil)
2909 (gnus-run-hooks 'gnus-tmp-internal-hook)
2910 (when gnus-display-mime-function
2911 (funcall gnus-display-mime-function))
2912 (gnus-run-hooks 'gnus-article-prepare-hook)))
2915 ;;; Gnus MIME viewing functions
2918 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2919 "The following specs can be used:
2921 %T MIME type, along with additional info
2922 %n The `name' parameter
2923 %d The description, if any
2924 %l The length of the encoded part
2925 %p The part identifier number
2926 %e Dots if the part isn't displayed")
2928 (defvar gnus-mime-button-line-format-alist
2929 '((?t gnus-tmp-type ?s)
2930 (?T gnus-tmp-type-long ?s)
2931 (?n gnus-tmp-name ?s)
2932 (?d gnus-tmp-description ?s)
2934 (?l gnus-tmp-length ?d)
2935 (?e gnus-tmp-dots ?s)))
2937 (defvar gnus-mime-button-commands
2938 '((gnus-article-press-button "\r" "Toggle Display")
2939 (gnus-mime-view-part "v" "View Interactively...")
2940 (gnus-mime-view-part-as-type "t" "View As Type...")
2941 (gnus-mime-save-part "o" "Save...")
2942 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2943 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2944 (gnus-mime-internalize-part "E" "View Internally")
2945 (gnus-mime-externalize-part "e" "View Externally")
2946 (gnus-mime-pipe-part "|" "Pipe To Command...")
2947 (gnus-mime-action-on-part "." "Take action on the part")))
2949 (defun gnus-article-mime-part-status ()
2950 (if gnus-article-mime-handle-alist-1
2951 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2954 (defvar gnus-mime-button-map
2955 (let ((map (make-sparse-keymap)))
2956 ;; Not for Emacs 21: fixme better.
2957 ;; (set-keymap-parent map gnus-article-mode-map)
2958 (define-key map gnus-mouse-2 'gnus-article-push-button)
2959 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2960 (dolist (c gnus-mime-button-commands)
2961 (define-key map (cadr c) (car c)))
2964 (defun gnus-mime-button-menu (event)
2965 "Construct a context-sensitive menu of MIME commands."
2968 (mouse-set-point event)
2969 (gnus-article-check-buffer)
2970 (let ((response (x-popup-menu
2972 ("" ,@(mapcar (lambda (c)
2973 (cons (caddr c) (car c)))
2974 gnus-mime-button-commands))))))
2976 (call-interactively response)))))
2978 (defun gnus-mime-view-all-parts (&optional handles)
2979 "View all the MIME parts."
2981 (save-current-buffer
2982 (set-buffer gnus-article-buffer)
2983 (let ((handles (or handles gnus-article-mime-handles))
2984 (mail-parse-charset gnus-newsgroup-charset)
2985 (mail-parse-ignored-charsets
2986 (save-excursion (set-buffer gnus-summary-buffer)
2987 gnus-newsgroup-ignored-charsets)))
2988 (if (stringp (car handles))
2989 (gnus-mime-view-all-parts (cdr handles))
2990 (mapcar 'mm-display-part handles)))))
2992 (defun gnus-mime-save-part ()
2993 "Save the MIME part under point."
2995 (gnus-article-check-buffer)
2996 (let ((data (get-text-property (point) 'gnus-data)))
2997 (mm-save-part data)))
2999 (defun gnus-mime-pipe-part ()
3000 "Pipe the MIME part under point to a process."
3002 (gnus-article-check-buffer)
3003 (let ((data (get-text-property (point) 'gnus-data)))
3004 (mm-pipe-part data)))
3006 (defun gnus-mime-view-part ()
3007 "Interactively choose a viewing method for the MIME part under point."
3009 (gnus-article-check-buffer)
3010 (let ((data (get-text-property (point) 'gnus-data)))
3011 (mm-interactively-view-part data)))
3013 (defun gnus-mime-view-part-as-type-internal ()
3014 (gnus-article-check-buffer)
3015 (let* ((name (mail-content-type-get
3016 (mm-handle-type (get-text-property (point) 'gnus-data))
3018 (def-type (and name (mm-default-file-encoding name))))
3019 (and def-type (cons def-type 0))))
3021 (defun gnus-mime-view-part-as-type (mime-type)
3022 "Choose a MIME media type, and view the part as such."
3024 (list (completing-read
3025 "View as MIME type: "
3026 (mapcar #'list (mailcap-mime-types))
3028 (gnus-mime-view-part-as-type-internal))))
3029 (gnus-article-check-buffer)
3030 (let ((handle (get-text-property (point) 'gnus-data)))
3031 (gnus-mm-display-part
3032 (mm-make-handle (mm-handle-buffer handle)
3033 (cons mime-type (cdr (mm-handle-type handle)))
3034 (mm-handle-encoding handle)
3035 (mm-handle-undisplayer handle)
3036 (mm-handle-disposition handle)
3037 (mm-handle-description handle)
3038 (mm-handle-cache handle)
3039 (mm-handle-id handle)))))
3041 (defun gnus-mime-copy-part (&optional handle)
3042 "Put the the MIME part under point into a new buffer."
3044 (gnus-article-check-buffer)
3045 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3046 (contents (mm-get-part handle))|
3047 (base (file-name-nondirectory
3049 (mail-content-type-get (mm-handle-type handle) 'name)
3050 (mail-content-type-get (mm-handle-type handle)
3053 (buffer (generate-new-buffer base)))
3054 (switch-to-buffer buffer)
3056 ;; We do it this way to make `normal-mode' set the appropriate mode.
3059 (setq buffer-file-name (expand-file-name base))
3061 (setq buffer-file-name nil))
3062 (goto-char (point-min))))
3064 (defun gnus-mime-inline-part (&optional handle arg)
3065 "Insert the MIME part under point into the current buffer."
3066 (interactive (list nil current-prefix-arg))
3067 (gnus-article-check-buffer)
3068 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3072 (if (mm-handle-undisplayer handle)
3073 (mm-remove-part handle)
3074 (setq contents (mm-get-part handle))
3077 (setq charset (or (mail-content-type-get
3078 (mm-handle-type handle) 'charset)
3079 gnus-newsgroup-charset)))
3083 gnus-summary-show-article-charset-alist))
3084 (read-coding-system "Charset: ")))))
3086 (mm-insert-inline handle
3088 (setq charset (mm-charset-to-coding-system
3090 (not (eq charset 'ascii)))
3091 (mm-decode-coding-string contents charset)
3095 (defun gnus-mime-externalize-part (&optional handle)
3096 "View the MIME part under point with an external viewer."
3098 (gnus-article-check-buffer)
3099 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3100 (mm-user-display-methods nil)
3101 (mm-inlined-types nil)
3102 (mail-parse-charset gnus-newsgroup-charset)
3103 (mail-parse-ignored-charsets
3104 (save-excursion (set-buffer gnus-summary-buffer)
3105 gnus-newsgroup-ignored-charsets)))
3106 (if (mm-handle-undisplayer handle)
3107 (mm-remove-part handle)
3108 (mm-display-part handle))))
3110 (defun gnus-mime-internalize-part (&optional handle)
3111 "View the MIME part under point with an internal viewer.
3112 In no internal viewer is available, use an external viewer."
3114 (gnus-article-check-buffer)
3115 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3116 (mm-inlined-types '(".*"))
3117 (mm-inline-large-images t)
3118 (mail-parse-charset gnus-newsgroup-charset)
3119 (mail-parse-ignored-charsets
3120 (save-excursion (set-buffer gnus-summary-buffer)
3121 gnus-newsgroup-ignored-charsets)))
3122 (if (mm-handle-undisplayer handle)
3123 (mm-remove-part handle)
3124 (mm-display-part handle))))
3126 (defun gnus-mime-action-on-part (&optional action)
3127 "Do something with the MIME attachment at \(point\)."
3129 (list (completing-read "Action: " gnus-mime-action-alist)))
3130 (gnus-article-check-buffer)
3131 (let ((action-pair (assoc action gnus-mime-action-alist)))
3133 (funcall (cdr action-pair)))))
3136 (defun gnus-article-part-wrapper (n function)
3137 (save-current-buffer
3138 (set-buffer gnus-article-buffer)
3139 (when (> n (length gnus-article-mime-handle-alist))
3140 (error "No such part"))
3141 (gnus-article-goto-part n)
3142 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3143 (funcall function handle))))
3145 (defun gnus-article-pipe-part (n)
3146 "Pipe MIME part N, which is the numerical prefix."
3148 (gnus-article-part-wrapper n 'mm-pipe-part))
3150 (defun gnus-article-save-part (n)
3151 "Save MIME part N, which is the numerical prefix."
3153 (gnus-article-part-wrapper n 'mm-save-part))
3155 (defun gnus-article-interactively-view-part (n)
3156 "View MIME part N interactively, which is the numerical prefix."
3158 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3160 (defun gnus-article-copy-part (n)
3161 "Copy MIME part N, which is the numerical prefix."
3163 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3165 (defun gnus-article-externalize-part (n)
3166 "View MIME part N externally, which is the numerical prefix."
3168 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3170 (defun gnus-article-inline-part (n)
3171 "Inline MIME part N, which is the numerical prefix."
3173 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3175 (defun gnus-article-mime-match-handle-first (condition)
3177 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3178 (while (setq ihandle (pop alist))
3180 ((functionp condition)
3181 (funcall condition (cdr ihandle)))
3182 ((eq condition 'undisplayed)
3183 (not (or (mm-handle-undisplayer (cdr ihandle))
3184 (equal (mm-handle-media-type (cdr ihandle))
3185 "multipart/alternative"))))
3186 ((eq condition 'undisplayed-alternative)
3187 (not (mm-handle-undisplayer (cdr ihandle))))
3189 (gnus-article-goto-part (car ihandle))
3190 (or (not n) (< (car ihandle) n)))
3191 (setq n (car ihandle))))
3195 (defun gnus-article-view-part (&optional n)
3196 "View MIME part N, which is the numerical prefix."
3198 (save-current-buffer
3199 (set-buffer gnus-article-buffer)
3200 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3201 gnus-article-mime-match-handle-function)))
3202 (when (> n (length gnus-article-mime-handle-alist))
3203 (error "No such part"))
3204 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3205 (when (gnus-article-goto-part n)
3206 (if (equal (car handle) "multipart/alternative")
3207 (gnus-article-press-button)
3208 (when (eq (gnus-mm-display-part handle) 'internal)
3209 (gnus-set-window-start)))))))
3211 (defsubst gnus-article-mime-total-parts ()
3212 (if (bufferp (car gnus-article-mime-handles))
3214 (1- (length gnus-article-mime-handles))))
3216 (defun gnus-mm-display-part (handle)
3217 "Display HANDLE and fix MIME button."
3218 (let ((id (get-text-property (point) 'gnus-part))
3223 (let ((window (selected-window))
3224 (mail-parse-charset gnus-newsgroup-charset)
3225 (mail-parse-ignored-charsets
3226 (save-excursion (set-buffer gnus-summary-buffer)
3227 gnus-newsgroup-ignored-charsets)))
3230 (let ((win (get-buffer-window (current-buffer) t))
3233 (select-window win))
3236 (if (mm-handle-displayed-p handle)
3237 ;; This will remove the part.
3238 (mm-display-part handle)
3240 (narrow-to-region (point) (1+ (point)))
3241 (mm-display-part handle)
3242 ;; We narrow to the part itself and
3243 ;; then call the treatment functions.
3244 (goto-char (point-min))
3246 (narrow-to-region (point) (point-max))
3249 (gnus-article-mime-total-parts)
3250 (mm-handle-media-type handle)))))
3251 (select-window window))))
3253 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3254 (gnus-insert-mime-button
3255 handle id (list (mm-handle-displayed-p handle)))
3256 (goto-char point))))
3258 (defun gnus-article-goto-part (n)
3259 "Go to MIME part N."
3260 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3262 (goto-char point))))
3264 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3265 (let ((gnus-tmp-name
3266 (or (mail-content-type-get (mm-handle-type handle)
3268 (mail-content-type-get (mm-handle-disposition handle)
3271 (gnus-tmp-type (mm-handle-media-type handle))
3272 (gnus-tmp-description
3273 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3276 (if (if displayed (car displayed)
3277 (mm-handle-displayed-p handle))
3279 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3281 gnus-tmp-type-long b e)
3282 (when (string-match ".*/" gnus-tmp-name)
3283 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3284 (setq gnus-tmp-type-long (concat gnus-tmp-type
3285 (and (not (equal gnus-tmp-name ""))
3286 (concat "; " gnus-tmp-name))))
3287 (or (equal gnus-tmp-description "")
3288 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3293 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3294 `(keymap ,gnus-mime-button-map
3295 ;; Not for Emacs 21: fixme better.
3296 ;; local-map ,gnus-mime-button-map
3297 gnus-callback gnus-mm-display-part
3298 gnus-part ,gnus-tmp-id
3299 article-type annotation
3302 (widget-convert-button
3305 :action 'gnus-widget-press-button
3306 :button-keymap gnus-mime-button-map
3308 (lambda (widget/window &optional overlay pos)
3309 ;; Needed to properly clear the message due to a bug in
3310 ;; wid-edit (XEmacs only).
3311 (if (boundp 'help-echo-owns-message)
3312 (setq help-echo-owns-message t))
3314 "%S: %s the MIME part; %S: more options"
3315 (aref gnus-mouse-2 0)
3316 ;; XEmacs will get a single widget arg; Emacs 21 will get
3317 ;; window, overlay, position.
3318 (if (mm-handle-displayed-p
3320 (with-current-buffer (gnus-overlay-buffer overlay)
3321 (widget-get (widget-at (gnus-overlay-start overlay))
3323 (widget-get widget/window :mime-handle)))
3325 (aref gnus-down-mouse-3 0))))))
3327 (defun gnus-widget-press-button (elems el)
3328 (goto-char (widget-get elems :from))
3329 (gnus-article-press-button))
3331 (defvar gnus-displaying-mime nil)
3333 (defun gnus-display-mime (&optional ihandles)
3334 "Display the MIME parts."
3336 (save-selected-window
3337 (let ((window (get-buffer-window gnus-article-buffer))
3340 (select-window window)
3341 ;; We have to do this since selecting the window
3342 ;; may change the point. So we set the window point.
3343 (set-window-point window point)))
3344 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3345 buffer-read-only handle name type b e display)
3346 (when (and (not ihandles)
3347 (not gnus-displaying-mime))
3348 ;; Top-level call; we clean up.
3349 (when gnus-article-mime-handles
3350 (mm-destroy-parts gnus-article-mime-handles)
3351 (setq gnus-article-mime-handle-alist nil));; A trick.
3352 (setq gnus-article-mime-handles handles)
3353 ;; We allow users to glean info from the handles.
3354 (when gnus-article-mime-part-function
3355 (gnus-mime-part-function handles)))
3357 (or (not (stringp (car handles)))
3360 (when (and (not ihandles)
3361 (not gnus-displaying-mime))
3362 ;; Clean up for mime parts.
3364 (delete-region (point) (point-max)))
3365 (let ((gnus-displaying-mime t))
3366 (gnus-mime-display-part handles)))
3369 (narrow-to-region (point) (point-max))
3370 (gnus-treat-article nil 1 1)
3373 ;; Highlight the headers.
3377 (narrow-to-region (point-min) (point))
3378 (gnus-treat-article 'head))))))))
3380 (defvar gnus-mime-display-multipart-as-mixed nil)
3382 (defun gnus-mime-display-part (handle)
3385 ((not (stringp (car handle)))
3386 (gnus-mime-display-single handle))
3387 ;; User-defined multipart
3388 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3389 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3391 ;; multipart/alternative
3392 ((and (equal (car handle) "multipart/alternative")
3393 (not gnus-mime-display-multipart-as-mixed))
3394 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3395 (push (cons id handle) gnus-article-mime-handle-alist)
3396 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3397 ;; multipart/related
3398 ((and (equal (car handle) "multipart/related")
3399 (not gnus-mime-display-multipart-as-mixed))
3400 ;;;!!!We should find the start part, but we just default
3401 ;;;!!!to the first part.
3402 (gnus-mime-display-part (cadr handle)))
3403 ;; Other multiparts are handled like multipart/mixed.
3405 (gnus-mime-display-mixed (cdr handle)))))
3407 (defun gnus-mime-part-function (handles)
3408 (if (stringp (car handles))
3409 (mapcar 'gnus-mime-part-function (cdr handles))
3410 (funcall gnus-article-mime-part-function handles)))
3412 (defun gnus-mime-display-mixed (handles)
3413 (mapcar 'gnus-mime-display-part handles))
3415 (defun gnus-mime-display-single (handle)
3416 (let ((type (mm-handle-media-type handle))
3417 (ignored gnus-ignored-mime-types)
3424 (when (string-match (pop ignored) type)
3425 (throw 'ignored nil)))
3426 (if (and (setq not-attachment
3427 (and (not (mm-inline-override-p handle))
3428 (or (not (mm-handle-disposition handle))
3429 (equal (car (mm-handle-disposition handle))
3431 (mm-attachment-override-p handle))))
3432 (mm-automatic-display-p handle)
3433 (or (mm-inlined-p handle)
3434 (mm-automatic-external-display-p type)))
3436 (when (equal (mm-handle-media-supertype handle) "text")
3438 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3440 (push (cons id handle) gnus-article-mime-handle-alist)
3441 (when (or (not display)
3442 (not (gnus-unbuttonized-mime-type-p type)))
3443 ;(gnus-article-insert-newline)
3444 (gnus-insert-mime-button
3445 handle id (list (or display (and not-attachment text))))
3446 (gnus-article-insert-newline)
3447 ;(gnus-article-insert-newline)
3455 (let ((mail-parse-charset gnus-newsgroup-charset)
3456 (mail-parse-ignored-charsets
3457 (save-excursion (condition-case ()
3458 (set-buffer gnus-summary-buffer)
3460 gnus-newsgroup-ignored-charsets)))
3461 (mm-display-part handle t))
3462 (goto-char (point-max)))
3463 ((and text not-attachment)
3467 (gnus-article-insert-newline)
3468 (mm-insert-inline handle (mm-get-part handle))
3469 (goto-char (point-max))))
3473 (narrow-to-region beg (point))
3476 (gnus-article-mime-total-parts)
3477 (mm-handle-media-type handle)))))))))
3479 (defun gnus-unbuttonized-mime-type-p (type)
3480 "Say whether TYPE is to be unbuttonized."
3481 (unless gnus-inhibit-mime-unbuttonizing
3483 (let ((types gnus-unbuttonized-mime-types))
3485 (when (string-match (pop types) type)
3486 (throw 'found t)))))))
3488 (defun gnus-article-insert-newline ()
3489 "Insert a newline, but mark it as undeletable."
3490 (gnus-put-text-property
3491 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3493 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3494 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3497 handle buffer-read-only from props begend not-pref)
3498 (save-window-excursion
3501 (narrow-to-region (car ibegend)
3504 (goto-char (car ibegend))
3507 (delete-region (point-min) (point-max))
3508 (mm-remove-parts handles))
3509 (setq begend (list (point-marker)))
3511 (unless (setq not-pref (cadr (member preferred ihandles)))
3512 (setq not-pref (car ihandles)))
3514 (not (gnus-unbuttonized-mime-type-p
3515 "multipart/alternative")))
3516 (gnus-add-text-properties
3519 (insert (format "%d. " id))
3523 (unless ,(not ibegend)
3524 (setq gnus-article-mime-handle-alist
3525 ',gnus-article-mime-handle-alist))
3526 (gnus-mime-display-alternative
3527 ',ihandles ',not-pref ',begend ,id))
3528 ;; Not for Emacs 21: fixme better.
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)
3539 (while (setq handle (pop handles))
3540 (gnus-add-text-properties
3543 (insert (format "(%c) %-18s"
3544 (if (equal handle preferred) ?* ? )
3545 (mm-handle-media-type handle)))
3549 (unless ,(not ibegend)
3550 (setq gnus-article-mime-handle-alist
3551 ',gnus-article-mime-handle-alist))
3552 (gnus-mime-display-alternative
3553 ',ihandles ',handle ',begend ,id))
3554 ;; Not for Emacs 21: fixme better.
3555 ;; local-map ,gnus-mime-button-map
3556 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3557 face ,gnus-article-button-face
3558 keymap ,gnus-mime-button-map
3561 (widget-convert-button 'link from (point)
3562 :action 'gnus-widget-press-button
3563 :button-keymap gnus-widget-button-keymap)
3567 (if (stringp (car preferred))
3568 (gnus-display-mime preferred)
3569 (let ((mail-parse-charset gnus-newsgroup-charset)
3570 (mail-parse-ignored-charsets
3571 (save-excursion (set-buffer gnus-summary-buffer)
3572 gnus-newsgroup-ignored-charsets)))
3573 (mm-display-part preferred)
3577 (narrow-to-region (car begend) (point-max))
3579 nil (length gnus-article-mime-handle-alist)
3580 (gnus-article-mime-total-parts)
3581 (mm-handle-media-type handle))))))
3582 (goto-char (point-max))
3583 (setcdr begend (point-marker)))))
3585 (goto-char point))))
3587 (defun gnus-article-wash-status ()
3588 "Return a string which display status of article washing."
3590 (set-buffer gnus-article-buffer)
3591 (let ((cite (memq 'cite gnus-article-wash-types))
3592 (headers (memq 'headers gnus-article-wash-types))
3593 (boring (memq 'boring-headers gnus-article-wash-types))
3594 (pgp (memq 'pgp gnus-article-wash-types))
3595 (pem (memq 'pem gnus-article-wash-types))
3596 (signature (memq 'signature gnus-article-wash-types))
3597 (overstrike (memq 'overstrike gnus-article-wash-types))
3598 (emphasis (memq 'emphasis gnus-article-wash-types)))
3599 (format "%c%c%c%c%c%c"
3601 (if (or headers boring) ?h ? )
3602 (if (or pgp pem) ?p ? )
3603 (if signature ?s ? )
3604 (if overstrike ?o ? )
3605 (if emphasis ?e ? )))))
3607 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3609 (defun gnus-article-maybe-hide-headers ()
3610 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3611 Provided for backwards compatibility."
3612 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3613 (not (save-excursion (set-buffer gnus-summary-buffer)
3614 gnus-have-all-headers)))
3615 (not gnus-inhibit-hiding))
3616 (gnus-article-hide-headers)))
3620 (defun gnus-output-to-file (file-name)
3621 "Append the current article to a file named FILE-NAME."
3622 (let ((artbuf (current-buffer)))
3624 (insert-buffer-substring artbuf)
3625 ;; Append newline at end of the buffer as separator, and then
3627 (goto-char (point-max))
3629 (mm-append-to-file (point-min) (point-max) file-name)
3632 (defun gnus-narrow-to-page (&optional arg)
3633 "Narrow the article buffer to a page.
3634 If given a numerical ARG, move forward ARG pages."
3636 (setq arg (if arg (prefix-numeric-value arg) 0))
3638 (set-buffer gnus-article-buffer)
3639 (goto-char (point-min))
3641 ;; Remove any old next/prev buttons.
3642 (when (gnus-visual-p 'page-marker)
3643 (let ((buffer-read-only nil))
3644 (gnus-remove-text-with-property 'gnus-prev)
3645 (gnus-remove-text-with-property 'gnus-next)))
3648 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3650 (re-search-forward page-delimiter nil 'move arg)))
3651 (goto-char (match-end 0)))
3654 (if (re-search-forward page-delimiter nil 'move)
3657 (when (and (gnus-visual-p 'page-marker)
3658 (not (= (point-min) 1)))
3660 (goto-char (point-min))
3661 (gnus-insert-prev-page-button)))
3662 (when (and (gnus-visual-p 'page-marker)
3663 (< (+ (point-max) 2) (buffer-size)))
3665 (goto-char (point-max))
3666 (gnus-insert-next-page-button)))))
3668 ;; Article mode commands
3670 (defun gnus-article-goto-next-page ()
3671 "Show the next page of the article."
3673 (when (gnus-article-next-page)
3674 (goto-char (point-min))
3675 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3677 (defun gnus-article-goto-prev-page ()
3678 "Show the next page of the article."
3680 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3681 (gnus-article-prev-page nil)))
3683 (defun gnus-article-next-page (&optional lines)
3684 "Show the next page of the current article.
3685 If end of article, return non-nil. Otherwise return nil.
3686 Argument LINES specifies lines to be scrolled up."
3688 (move-to-window-line -1)
3691 (and (pos-visible-in-window-p) ;Not continuation line.
3693 ;; Nothing in this page.
3694 (if (or (not gnus-page-broken)
3697 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3699 (gnus-narrow-to-page 1) ;Go to next page.
3701 ;; More in this page.
3702 (let ((scroll-in-place nil))
3706 ;; Long lines may cause an end-of-buffer error.
3707 (goto-char (point-max)))))
3708 (move-to-window-line 0)
3711 (defun gnus-article-prev-page (&optional lines)
3712 "Show previous page of current article.
3713 Argument LINES specifies lines to be scrolled down."
3715 (move-to-window-line 0)
3716 (if (and gnus-page-broken
3718 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3720 (gnus-narrow-to-page -1) ;Go to previous page.
3721 (goto-char (point-max))
3723 (let ((scroll-in-place nil))
3727 (beginning-of-buffer
3728 (goto-char (point-min))))
3729 (move-to-window-line 0)))))
3731 (defun gnus-article-refer-article ()
3732 "Read article specified by message-id around point."
3734 (let ((point (point)))
3735 (search-forward ">" nil t) ;Move point to end of "<....>".
3736 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3737 (let ((message-id (match-string 1)))
3739 (set-buffer gnus-summary-buffer)
3740 (gnus-summary-refer-article message-id))
3742 (error "No references around point"))))
3744 (defun gnus-article-show-summary ()
3745 "Reconfigure windows to show summary buffer."
3747 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3748 (error "There is no summary buffer for this article buffer")
3749 (gnus-article-set-globals)
3750 (gnus-configure-windows 'article)
3751 (gnus-summary-goto-subject gnus-current-article)
3752 (gnus-summary-position-point)))
3754 (defun gnus-article-describe-briefly ()
3755 "Describe article mode commands briefly."
3757 (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")))
3759 (defun gnus-article-summary-command ()
3760 "Execute the last keystroke in the summary buffer."
3762 (let ((obuf (current-buffer))
3763 (owin (current-window-configuration))
3765 (switch-to-buffer gnus-article-current-summary 'norecord)
3766 (setq func (lookup-key (current-local-map) (this-command-keys)))
3767 (call-interactively func)
3769 (set-window-configuration owin)
3770 (set-window-point (get-buffer-window (current-buffer)) (point))))
3772 (defun gnus-article-summary-command-nosave ()
3773 "Execute the last keystroke in the summary buffer."
3776 (pop-to-buffer gnus-article-current-summary 'norecord)
3777 (setq func (lookup-key (current-local-map) (this-command-keys)))
3778 (call-interactively func)))
3780 (defun gnus-article-check-buffer ()
3781 "Beep if not in an article buffer."
3782 (unless (equal major-mode 'gnus-article-mode)
3783 (error "Command invoked outside of a Gnus article buffer")))
3785 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3786 "Read a summary buffer key sequence and execute it from the article buffer."
3788 (gnus-article-check-buffer)
3790 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3791 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3792 "=" "^" "\M-^" "|"))
3798 '("n" "Gn" "p" "Gp"))
3801 (set-buffer gnus-article-current-summary)
3802 (let (gnus-pick-mode)
3803 (push (or key last-command-event) unread-command-events)
3804 (setq keys (if (featurep 'xemacs)
3805 (events-to-keys (read-key-sequence nil))
3806 (read-key-sequence nil)))))
3810 (if (or (member keys nosaves)
3811 (member keys nosave-but-article)
3812 (member keys nosave-in-article))
3814 (save-window-excursion
3815 (pop-to-buffer gnus-article-current-summary 'norecord)
3816 ;; We disable the pick minor mode commands.
3817 (let (gnus-pick-mode)
3818 (setq func (lookup-key (current-local-map) keys))))
3822 (unless (member keys nosave-in-article)
3823 (set-buffer gnus-article-current-summary))
3824 (call-interactively func)
3825 (setq new-sum-point (point)))
3826 (when (member keys nosave-but-article)
3827 (pop-to-buffer gnus-article-buffer 'norecord)))
3828 ;; These commands should restore window configuration.
3829 (let ((obuf (current-buffer))
3830 (owin (current-window-configuration))
3832 (summary gnus-article-current-summary)
3833 func in-buffer selected)
3834 (if not-restore-window
3835 (pop-to-buffer summary 'norecord)
3836 (switch-to-buffer summary 'norecord))
3837 (setq in-buffer (current-buffer))
3838 ;; We disable the pick minor mode commands.
3839 (if (setq func (let (gnus-pick-mode)
3840 (lookup-key (current-local-map) keys)))
3842 (call-interactively func)
3843 (setq new-sum-point (point)))
3845 (when (eq in-buffer (current-buffer))
3846 (setq selected (gnus-summary-select-article))
3848 (unless not-restore-window
3849 (set-window-configuration owin))
3850 (when (eq selected 'old)
3852 (set-window-start (get-buffer-window (current-buffer))
3854 (set-window-point (get-buffer-window (current-buffer))
3856 (let ((win (get-buffer-window gnus-article-current-summary)))
3858 (set-window-point win new-sum-point))))))))
3860 (defun gnus-article-hide (&optional arg force)
3861 "Hide all the gruft in the current article.
3862 This means that PGP stuff, signatures, cited text and (some)
3863 headers will be hidden.
3864 If given a prefix, show the hidden text instead."
3865 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3866 (gnus-article-hide-headers arg)
3867 (gnus-article-hide-list-identifiers arg)
3868 (gnus-article-hide-pgp arg)
3869 (gnus-article-hide-citation-maybe arg force)
3870 (gnus-article-hide-signature arg))
3872 (defun gnus-article-maybe-highlight ()
3873 "Do some article highlighting if article highlighting is requested."
3874 (when (gnus-visual-p 'article-highlight 'highlight)
3875 (gnus-article-highlight-some)))
3877 (defun gnus-check-group-server ()
3878 ;; Make sure the connection to the server is alive.
3879 (unless (gnus-server-opened
3880 (gnus-find-method-for-group gnus-newsgroup-name))
3881 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3882 (gnus-request-group gnus-newsgroup-name t)))
3884 (defun gnus-request-article-this-buffer (article group)
3885 "Get an article and insert it into this buffer."
3886 (let (do-update-line sparse-header)
3890 (gnus-kill-all-overlays)
3891 (setq group (or group gnus-newsgroup-name))
3893 ;; Using `gnus-request-article' directly will insert the article into
3894 ;; `nntp-server-buffer' - so we'll save some time by not having to
3895 ;; copy it from the server buffer into the article buffer.
3897 ;; We only request an article by message-id when we do not have the
3898 ;; headers for it, so we'll have to get those.
3899 (when (stringp article)
3900 (gnus-read-header article))
3902 ;; If the article number is negative, that means that this article
3903 ;; doesn't belong in this newsgroup (possibly), so we find its
3904 ;; message-id and request it by id instead of number.
3905 (when (and (numberp article)
3907 (get-buffer gnus-summary-buffer)
3908 (gnus-buffer-exists-p gnus-summary-buffer))
3910 (set-buffer gnus-summary-buffer)
3911 (let ((header (gnus-summary-article-header article)))
3914 ((memq article gnus-newsgroup-sparse)
3915 ;; This is a sparse gap article.
3916 (setq do-update-line article)
3917 (setq article (mail-header-id header))
3918 (setq sparse-header (gnus-read-header article))
3919 (setq gnus-newsgroup-sparse
3920 (delq article gnus-newsgroup-sparse)))
3922 ;; It's a real article.
3923 (setq article (mail-header-id header)))
3925 ;; It is an extracted pseudo-article.
3926 (setq article 'pseudo)
3927 (gnus-request-pseudo-article header))))
3929 (let ((method (gnus-find-method-for-group
3930 gnus-newsgroup-name)))
3931 (when (and (eq (car method) 'nneething)
3933 (let ((dir (expand-file-name
3934 (mail-header-subject header)
3935 (file-name-as-directory
3936 (or (cadr (assq 'nneething-address method))
3938 (when (file-directory-p dir)
3939 (setq article 'nneething)
3940 (gnus-group-enter-directory dir))))))))
3943 ;; Refuse to select canceled articles.
3944 ((and (numberp article)
3946 (get-buffer gnus-summary-buffer)
3947 (gnus-buffer-exists-p gnus-summary-buffer)
3948 (eq (cdr (save-excursion
3949 (set-buffer gnus-summary-buffer)
3950 (assq article gnus-newsgroup-reads)))
3951 gnus-canceled-mark))
3953 ;; We first check `gnus-original-article-buffer'.
3954 ((and (get-buffer gnus-original-article-buffer)
3957 (set-buffer gnus-original-article-buffer)
3958 (and (equal (car gnus-original-article) group)
3959 (eq (cdr gnus-original-article) article))))
3960 (insert-buffer-substring gnus-original-article-buffer)
3962 ;; Check the backlog.
3963 ((and gnus-keep-backlog
3964 (gnus-backlog-request-article group article (current-buffer)))
3966 ;; Check asynchronous pre-fetch.
3967 ((gnus-async-request-fetched-article group article (current-buffer))
3968 (gnus-async-prefetch-next group article gnus-summary-buffer)
3969 (when (and (numberp article) gnus-keep-backlog)
3970 (gnus-backlog-enter-article group article (current-buffer)))
3973 ((and gnus-use-cache
3975 (gnus-cache-request-article article group))
3977 ;; Get the article and put into the article buffer.
3978 ((or (stringp article)
3980 (let ((gnus-override-method gnus-override-method)
3981 (methods (and (stringp article)
3982 gnus-refer-article-method))
3984 (buffer-read-only nil))
3985 (if (or (not (listp methods))
3986 (and (symbolp (car methods))
3987 (assq (car methods) nnoo-definition-alist)))
3988 (setq methods (list methods)))
3989 (when (and (null gnus-override-method)
3991 (setq gnus-override-method (pop methods)))
3993 (when (eq gnus-override-method 'current)
3994 (setq gnus-override-method gnus-current-select-method))
3996 (gnus-kill-all-overlays)
3997 (let ((gnus-newsgroup-name group))
3998 (gnus-check-group-server))
3999 (when (gnus-request-article article group (current-buffer))
4000 (when (numberp article)
4001 (gnus-async-prefetch-next group article
4002 gnus-summary-buffer)
4003 (when gnus-keep-backlog
4004 (gnus-backlog-enter-article
4005 group article (current-buffer))))
4006 (setq result 'article))
4009 (setq gnus-override-method (pop methods))
4010 (setq result 'done))))
4011 (and (eq result 'article) 'article)))
4015 ;; Associate this article with the current summary buffer.
4016 (setq gnus-article-current-summary gnus-summary-buffer)
4018 ;; Take the article from the original article buffer
4019 ;; and place it in the buffer it's supposed to be in.
4020 (when (and (get-buffer gnus-article-buffer)
4021 (equal (buffer-name (current-buffer))
4022 (buffer-name (get-buffer gnus-article-buffer))))
4024 (if (get-buffer gnus-original-article-buffer)
4025 (set-buffer gnus-original-article-buffer)
4026 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4027 (buffer-disable-undo)
4028 (setq major-mode 'gnus-original-article-mode)
4029 (setq buffer-read-only t))
4030 (let (buffer-read-only)
4032 (insert-buffer-substring gnus-article-buffer))
4033 (setq gnus-original-article (cons group article)))
4036 (run-hooks 'gnus-article-decode-hook)
4037 ;; Mark article as decoded or not.
4038 (setq gnus-article-decoded-p gnus-article-decode-hook))
4040 ;; Update sparse articles.
4041 (when (and do-update-line
4042 (or (numberp article)
4044 (let ((buf (current-buffer)))
4045 (set-buffer gnus-summary-buffer)
4046 (gnus-summary-update-article do-update-line sparse-header)
4047 (gnus-summary-goto-subject do-update-line nil t)
4048 (set-window-point (get-buffer-window (current-buffer) t)
4050 (set-buffer buf))))))
4056 (defcustom gnus-article-edit-mode-hook nil
4057 "Hook run in article edit mode buffers."
4058 :group 'gnus-article-various
4061 (defvar gnus-article-edit-done-function nil)
4063 (defvar gnus-article-edit-mode-map nil)
4065 ;; Should we be using derived.el for this?
4066 (unless gnus-article-edit-mode-map
4067 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4068 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4070 (gnus-define-keys gnus-article-edit-mode-map
4071 "\C-c\C-c" gnus-article-edit-done
4072 "\C-c\C-k" gnus-article-edit-exit)
4074 (gnus-define-keys (gnus-article-edit-wash-map
4075 "\C-c\C-w" gnus-article-edit-mode-map)
4076 "f" gnus-article-edit-full-stops))
4078 (defun gnus-article-edit-mode ()
4079 "Major mode for editing articles.
4080 This is an extended text-mode.
4082 \\{gnus-article-edit-mode-map}"
4084 (setq major-mode 'gnus-article-edit-mode)
4085 (setq mode-name "Article Edit")
4086 (use-local-map gnus-article-edit-mode-map)
4087 (make-local-variable 'gnus-article-edit-done-function)
4088 (make-local-variable 'gnus-prev-winconf)
4089 (setq buffer-read-only nil)
4090 (buffer-enable-undo)
4092 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4094 (defun gnus-article-edit (&optional force)
4095 "Edit the current article.
4096 This will have permanent effect only in mail groups.
4097 If FORCE is non-nil, allow editing of articles even in read-only
4100 (when (and (not force)
4101 (gnus-group-read-only-p))
4102 (error "The current newsgroup does not support article editing"))
4103 (gnus-article-date-original)
4104 (gnus-article-edit-article
4106 `(lambda (no-highlight)
4108 (gnus-summary-edit-article-done
4109 ,(or (mail-header-references gnus-current-headers) "")
4110 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4112 (defun gnus-article-edit-article (start-func exit-func)
4113 "Start editing the contents of the current article buffer."
4114 (let ((winconf (current-window-configuration)))
4115 (set-buffer gnus-article-buffer)
4116 (gnus-article-edit-mode)
4117 (funcall start-func)
4118 (gnus-configure-windows 'edit-article)
4119 (setq gnus-article-edit-done-function exit-func)
4120 (setq gnus-prev-winconf winconf)
4121 (gnus-message 6 "C-c C-c to end edits")))
4123 (defun gnus-article-edit-done (&optional arg)
4124 "Update the article edits and exit."
4129 (when (article-goto-body)
4130 (let ((lines (count-lines (point) (point-max)))
4131 (length (- (point-max) (point)))
4132 (case-fold-search t)
4133 (body (copy-marker (point))))
4134 (goto-char (point-min))
4135 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4136 (delete-region (match-beginning 1) (match-end 1))
4137 (insert (number-to-string length)))
4138 (goto-char (point-min))
4139 (when (re-search-forward
4140 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4141 (delete-region (match-beginning 1) (match-end 1))
4142 (insert (number-to-string length)))
4143 (goto-char (point-min))
4144 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4145 (delete-region (match-beginning 1) (match-end 1))
4146 (insert (number-to-string lines)))))))
4147 (let ((func gnus-article-edit-done-function)
4148 (buf (current-buffer))
4149 (start (window-start)))
4150 (gnus-article-edit-exit)
4153 (let ((buffer-read-only nil))
4155 ;; The cache and backlog have to be flushed somewhat.
4156 (when gnus-keep-backlog
4157 (gnus-backlog-remove-article
4158 (car gnus-article-current) (cdr gnus-article-current)))
4159 ;; Flush original article as well.
4161 (when (get-buffer gnus-original-article-buffer)
4162 (set-buffer gnus-original-article-buffer)
4163 (setq gnus-original-article nil)))
4164 (when gnus-use-cache
4165 (gnus-cache-update-article
4166 (car gnus-article-current) (cdr gnus-article-current))))
4168 (set-window-start (get-buffer-window buf) start)
4169 (set-window-point (get-buffer-window buf) (point))))
4171 (defun gnus-article-edit-exit ()
4172 "Exit the article editing without updating."
4174 ;; We remove all text props from the article buffer.
4175 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4176 (curbuf (current-buffer))
4178 (window-start (window-start)))
4181 (let ((winconf gnus-prev-winconf))
4183 (set-window-configuration winconf)
4184 ;; Tippy-toe some to make sure that point remains where it was.
4185 (save-current-buffer
4187 (set-window-start (get-buffer-window (current-buffer)) window-start)
4190 (defun gnus-article-edit-full-stops ()
4191 "Interactively repair spacing at end of sentences."
4194 (goto-char (point-min))
4195 (search-forward-regexp "^$" nil t)
4196 (let ((case-fold-search nil))
4197 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4200 ;;; Article highlights
4203 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4205 ;;; Internal Variables:
4207 (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\\)\\)"
4208 "Regular expression that matches URLs."
4209 :group 'gnus-article-buttons
4212 (defcustom gnus-button-alist
4213 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4214 0 t gnus-button-message-id 2)
4215 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4216 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4218 gnus-button-fetch-group 4)
4219 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4220 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4221 t gnus-button-message-id 3)
4222 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4223 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4224 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4225 ;; This is how URLs _should_ be embedded in text...
4226 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4228 (,gnus-button-url-regexp 0 t browse-url 0))
4229 "*Alist of regexps matching buttons in article bodies.
4231 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4232 REGEXP: is the string matching text around the button,
4233 BUTTON: is the number of the regexp grouping actually matching the button,
4234 FORM: is a lisp expression which must eval to true for the button to
4236 CALLBACK: is the function to call when the user push this button, and each
4237 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4239 CALLBACK can also be a variable, in that case the value of that
4240 variable it the real callback function."
4241 :group 'gnus-article-buttons
4242 :type '(repeat (list regexp
4243 (integer :tag "Button")
4245 (function :tag "Callback")
4248 (integer :tag "Regexp group")))))
4250 (defcustom gnus-header-button-alist
4251 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4252 0 t gnus-button-message-id 0)
4253 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4254 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4255 0 t gnus-button-mailto 0)
4256 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4257 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4258 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4259 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4260 gnus-button-message-id 3))
4261 "*Alist of headers and regexps to match buttons in article heads.
4263 This alist is very similar to `gnus-button-alist', except that each
4264 alist has an additional HEADER element first in each entry:
4266 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4268 HEADER is a regexp to match a header. For a fuller explanation, see
4269 `gnus-button-alist'."
4270 :group 'gnus-article-buttons
4271 :group 'gnus-article-headers
4272 :type '(repeat (list (regexp :tag "Header")
4274 (integer :tag "Button")
4276 (function :tag "Callback")
4279 (integer :tag "Regexp group")))))
4281 (defvar gnus-button-regexp nil)
4282 (defvar gnus-button-marker-list nil)
4283 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4285 (defvar gnus-button-last nil)
4286 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4290 (defun gnus-article-push-button (event)
4291 "Check text under the mouse pointer for a callback function.
4292 If the text under the mouse pointer has a `gnus-callback' property,
4293 call it with the value of the `gnus-data' text property."
4295 (set-buffer (window-buffer (posn-window (event-start event))))
4296 (let* ((pos (posn-point (event-start event)))
4297 (data (get-text-property pos 'gnus-data))
4298 (fun (get-text-property pos 'gnus-callback)))
4301 (funcall fun data))))
4303 (defun gnus-article-press-button ()
4304 "Check text at point for a callback function.
4305 If the text at point has a `gnus-callback' property,
4306 call it with the value of the `gnus-data' text property."
4308 (let* ((data (get-text-property (point) 'gnus-data))
4309 (fun (get-text-property (point) 'gnus-callback)))
4311 (funcall fun data))))
4313 (defun gnus-article-highlight (&optional force)
4314 "Highlight current article.
4315 This function calls `gnus-article-highlight-headers',
4316 `gnus-article-highlight-citation',
4317 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4318 do the highlighting. See the documentation for those functions."
4319 (interactive (list 'force))
4320 (gnus-article-highlight-headers)
4321 (gnus-article-highlight-citation force)
4322 (gnus-article-highlight-signature)
4323 (gnus-article-add-buttons force)
4324 (gnus-article-add-buttons-to-head))
4326 (defun gnus-article-highlight-some (&optional force)
4327 "Highlight current article.
4328 This function calls `gnus-article-highlight-headers',
4329 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4330 do the highlighting. See the documentation for those functions."
4331 (interactive (list 'force))
4332 (gnus-article-highlight-headers)
4333 (gnus-article-highlight-signature)
4334 (gnus-article-add-buttons))
4336 (defun gnus-article-highlight-headers ()
4337 "Highlight article headers as specified by `gnus-header-face-alist'."
4340 (set-buffer gnus-article-buffer)
4342 (let ((alist gnus-header-face-alist)
4343 (buffer-read-only nil)
4344 (case-fold-search t)
4345 (inhibit-point-motion-hooks t)
4346 entry regexp header-face field-face from hpoints fpoints)
4347 (article-narrow-to-head)
4348 (while (setq entry (pop alist))
4349 (goto-char (point-min))
4350 (setq regexp (concat "^\\("
4351 (if (string-equal "" (nth 0 entry))
4355 header-face (nth 1 entry)
4356 field-face (nth 2 entry))
4357 (while (and (re-search-forward regexp nil t)
4361 (unless (search-forward ":" nil t)
4363 (when (and header-face
4364 (not (memq (point) hpoints)))
4365 (push (point) hpoints)
4366 (gnus-put-text-property from (point) 'face header-face))
4367 (when (and field-face
4368 (not (memq (setq from (point)) fpoints)))
4370 (if (re-search-forward "^[^ \t]" nil t)
4372 (goto-char (point-max)))
4373 (gnus-put-text-property from (point) 'face field-face))))))))
4375 (defun gnus-article-highlight-signature ()
4376 "Highlight the signature in an article.
4377 It does this by highlighting everything after
4378 `gnus-signature-separator' using `gnus-signature-face'."
4381 (set-buffer gnus-article-buffer)
4382 (let ((buffer-read-only nil)
4383 (inhibit-point-motion-hooks t))
4385 (when (and gnus-signature-face
4386 (gnus-article-narrow-to-signature))
4387 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4388 'face gnus-signature-face)
4390 (gnus-article-search-signature)
4391 (let ((start (match-beginning 0))
4392 (end (set-marker (make-marker) (1+ (match-end 0)))))
4393 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4396 (defun gnus-button-in-region-p (b e prop)
4397 "Say whether PROP exists in the region."
4398 (text-property-not-all b e prop nil))
4400 (defun gnus-article-add-buttons (&optional force)
4401 "Find external references in the article and make buttons of them.
4402 \"External references\" are things like Message-IDs and URLs, as
4403 specified by `gnus-button-alist'."
4404 (interactive (list 'force))
4406 (set-buffer gnus-article-buffer)
4407 (let ((buffer-read-only nil)
4408 (inhibit-point-motion-hooks t)
4409 (case-fold-search t)
4410 (alist gnus-button-alist)
4412 ;; Remove all old markers.
4413 (let (marker entry new-list)
4414 (while (setq marker (pop gnus-button-marker-list))
4415 (if (or (< marker (point-min)) (>= marker (point-max)))
4416 (push marker new-list)
4418 (when (setq entry (gnus-button-entry))
4419 (put-text-property (match-beginning (nth 1 entry))
4420 (match-end (nth 1 entry))
4421 'gnus-callback nil))
4422 (set-marker marker nil)))
4423 (setq gnus-button-marker-list new-list))
4424 ;; We skip the headers.
4427 (while (setq entry (pop alist))
4428 (setq regexp (car entry))
4430 (while (re-search-forward regexp nil t)
4431 (let* ((start (and entry (match-beginning (nth 1 entry))))
4432 (end (and entry (match-end (nth 1 entry))))
4433 (from (match-beginning 0)))
4434 (when (and (or (eq t (nth 2 entry))
4435 (eval (nth 2 entry)))
4436 (not (gnus-button-in-region-p
4437 start end 'gnus-callback)))
4438 ;; That optional form returned non-nil, so we add the
4440 (gnus-article-add-button
4441 start end 'gnus-button-push
4442 (car (push (set-marker (make-marker) from)
4443 gnus-button-marker-list))))))))))
4445 ;; Add buttons to the head of an article.
4446 (defun gnus-article-add-buttons-to-head ()
4447 "Add buttons to the head of the article."
4450 (set-buffer gnus-article-buffer)
4452 (let ((buffer-read-only nil)
4453 (inhibit-point-motion-hooks t)
4454 (case-fold-search t)
4455 (alist gnus-header-button-alist)
4457 (article-narrow-to-head)
4459 ;; Each alist entry.
4460 (setq entry (car alist)
4462 (goto-char (point-min))
4463 (while (re-search-forward (car entry) nil t)
4464 ;; Each header matching the entry.
4465 (setq beg (match-beginning 0))
4466 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4467 (match-beginning 0))
4470 (while (re-search-forward (nth 1 entry) end t)
4471 ;; Each match within a header.
4472 (let* ((entry (cdr entry))
4473 (start (match-beginning (nth 1 entry)))
4474 (end (match-end (nth 1 entry)))
4475 (form (nth 2 entry)))
4476 (goto-char (match-end 0))
4478 (gnus-article-add-button
4479 start end (nth 3 entry)
4480 (buffer-substring (match-beginning (nth 4 entry))
4481 (match-end (nth 4 entry)))))))
4482 (goto-char end)))))))
4484 ;;; External functions:
4486 (defun gnus-article-add-button (from to fun &optional data)
4487 "Create a button between FROM and TO with callback FUN and data DATA."
4488 (when gnus-article-button-face
4489 (gnus-overlay-put (gnus-make-overlay from to)
4490 'face gnus-article-button-face))
4491 (gnus-add-text-properties
4493 (nconc (and gnus-article-mouse-face
4494 (list gnus-mouse-face-prop gnus-article-mouse-face))
4495 (list 'gnus-callback fun)
4496 (and data (list 'gnus-data data))))
4497 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4498 :button-keymap gnus-widget-button-keymap))
4500 ;;; Internal functions:
4502 (defun gnus-article-set-globals ()
4504 (set-buffer gnus-summary-buffer)
4505 (gnus-set-global-variables)))
4507 (defun gnus-signature-toggle (end)
4509 (set-buffer gnus-article-buffer)
4510 (let ((buffer-read-only nil)
4511 (inhibit-point-motion-hooks t))
4512 (if (get-text-property end 'invisible)
4513 (gnus-article-unhide-text end (point-max))
4514 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4516 (defun gnus-button-entry ()
4517 ;; Return the first entry in `gnus-button-alist' matching this place.
4518 (let ((alist gnus-button-alist)
4521 (setq entry (pop alist))
4522 (if (looking-at (car entry))
4527 (defun gnus-button-push (marker)
4528 ;; Push button starting at MARKER.
4531 (let* ((entry (gnus-button-entry))
4532 (inhibit-point-motion-hooks t)
4534 (args (mapcar (lambda (group)
4535 (let ((string (match-string group)))
4536 (gnus-set-text-properties
4537 0 (length string) nil string)
4544 (fboundp (symbol-value fun)))
4545 (apply (symbol-value fun) args))
4547 (gnus-message 1 "You must define `%S' to use this button"
4548 (cons fun args)))))))
4550 (defun gnus-button-message-id (message-id)
4553 (set-buffer gnus-summary-buffer)
4554 (gnus-summary-refer-article message-id)))
4556 (defun gnus-button-fetch-group (address)
4557 "Fetch GROUP specified by ADDRESS."
4558 (if (not (string-match "[:/]" address))
4559 ;; This is just a simple group url.
4560 (gnus-group-read-ephemeral-group address gnus-select-method)
4561 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4563 (error "Can't parse %s" address)
4564 (gnus-group-read-ephemeral-group
4565 (match-string 4 address)
4566 `(nntp ,(match-string 1 address)
4567 (nntp-address ,(match-string 1 address))
4568 (nntp-port-number ,(if (match-end 3)
4569 (match-string 3 address)
4572 (defun gnus-url-parse-query-string (query &optional downcase)
4573 (let (retval pairs cur key val)
4574 (setq pairs (split-string query "&"))
4576 (setq cur (car pairs)
4578 (if (not (string-match "=" cur))
4580 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4581 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4583 (setq key (downcase key)))
4584 (setq cur (assoc key retval))
4586 (setcdr cur (cons val (cdr cur)))
4587 (setq retval (cons (list key val) retval)))))
4590 (defun gnus-url-unhex (x)
4597 (defun gnus-url-unhex-string (str &optional allow-newlines)
4598 "Remove %XXX embedded spaces, etc in a url.
4599 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4600 decoding of carriage returns and line feeds in the string, which is normally
4601 forbidden in URL encoding."
4602 (setq str (or str ""))
4604 (case-fold-search t))
4605 (while (string-match "%[0-9a-f][0-9a-f]" str)
4606 (let* ((start (match-beginning 0))
4607 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4609 (gnus-url-unhex (elt str (+ start 2))))))
4611 tmp (substring str 0 start)
4614 (char-to-string code))
4615 ((or (= code ?\n) (= code ?\r))
4617 (t (char-to-string code))))
4618 str (substring str (match-end 0)))))
4619 (setq tmp (concat tmp str))
4622 (defun gnus-url-mailto (url)
4623 ;; Send mail to someone
4624 (when (string-match "mailto:/*\\(.*\\)" url)
4625 (setq url (substring url (match-beginning 1) nil)))
4626 (let (to args subject func)
4627 (if (string-match (regexp-quote "?") url)
4628 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4629 args (gnus-url-parse-query-string
4630 (substring url (match-end 0) nil) t))
4631 (setq to (gnus-url-unhex-string url)))
4632 (setq args (cons (list "to" to) args)
4633 subject (cdr-safe (assoc "subject" args)))
4636 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4639 (message-position-on-field (caar args)))
4640 (insert (mapconcat 'identity (cdar args) ", "))
4641 (setq args (cdr args)))
4644 (message-goto-subject))))
4646 (defun gnus-button-mailto (address)
4648 (set-buffer (gnus-copy-article-buffer))
4649 (message-reply address))
4651 (defalias 'gnus-button-reply 'message-reply)
4653 (defun gnus-button-embedded-url (address)
4654 "Activate ADDRESS with `browse-url'."
4655 (browse-url (gnus-strip-whitespace address)))
4657 ;;; Next/prev buttons in the article buffer.
4659 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4660 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4662 (defvar gnus-prev-page-map nil)
4663 (unless gnus-prev-page-map
4664 (setq gnus-prev-page-map (make-sparse-keymap))
4665 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4666 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4668 (defun gnus-insert-prev-page-button ()
4669 (let ((buffer-read-only nil))
4671 gnus-prev-page-line-format nil
4672 `(gnus-prev t local-map ,gnus-prev-page-map
4673 gnus-callback gnus-article-button-prev-page
4674 article-type annotation))))
4676 (defvar gnus-next-page-map nil)
4677 (unless gnus-next-page-map
4678 (setq gnus-next-page-map (make-keymap))
4679 (suppress-keymap gnus-prev-page-map)
4680 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4681 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4683 (defun gnus-button-next-page ()
4684 "Go to the next page."
4686 (let ((win (selected-window)))
4687 (select-window (get-buffer-window gnus-article-buffer t))
4688 (gnus-article-next-page)
4689 (select-window win)))
4691 (defun gnus-button-prev-page ()
4692 "Go to the prev page."
4694 (let ((win (selected-window)))
4695 (select-window (get-buffer-window gnus-article-buffer t))
4696 (gnus-article-prev-page)
4697 (select-window win)))
4699 (defun gnus-insert-next-page-button ()
4700 (let ((buffer-read-only nil))
4701 (gnus-eval-format gnus-next-page-line-format nil
4703 t local-map ,gnus-next-page-map
4704 gnus-callback gnus-article-button-next-page
4705 article-type annotation))))
4707 (defun gnus-article-button-next-page (arg)
4708 "Go to the next page."
4710 (let ((win (selected-window)))
4711 (select-window (get-buffer-window gnus-article-buffer t))
4712 (gnus-article-next-page)
4713 (select-window win)))
4715 (defun gnus-article-button-prev-page (arg)
4716 "Go to the prev page."
4718 (let ((win (selected-window)))
4719 (select-window (get-buffer-window gnus-article-buffer t))
4720 (gnus-article-prev-page)
4721 (select-window win)))
4723 (defvar gnus-decode-header-methods
4724 '(mail-decode-encoded-word-region)
4725 "List of methods used to decode headers.
4727 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4728 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4729 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4730 whose names match REGEXP.
4733 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4734 mail-decode-encoded-word-region
4735 (\"chinese\" . rfc1843-decode-region))
4738 (defvar gnus-decode-header-methods-cache nil)
4740 (defun gnus-multi-decode-header (start end)
4741 "Apply the functions from `gnus-encoded-word-methods' that match."
4742 (unless (and gnus-decode-header-methods-cache
4743 (eq gnus-newsgroup-name
4744 (car gnus-decode-header-methods-cache)))
4745 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4748 (nconc gnus-decode-header-methods-cache (list x))
4749 (if (and gnus-newsgroup-name
4750 (string-match (car x) gnus-newsgroup-name))
4751 (nconc gnus-decode-header-methods-cache
4753 gnus-decode-header-methods))
4754 (let ((xlist gnus-decode-header-methods-cache))
4757 (narrow-to-region start end)
4759 (funcall (pop xlist) (point-min) (point-max))))))
4762 ;;; Treatment top-level handling.
4765 (defun gnus-treat-article (condition &optional part-number total-parts type)
4766 (let ((length (- (point-max) (point-min)))
4767 (alist gnus-treatment-function-alist)
4768 (article-goto-body-goes-to-point-min-p t)
4772 (let ((list gnus-article-treat-types))
4774 (when (string-match (pop list) type)
4775 (throw 'found t)))))))
4776 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4778 (gnus-run-hooks 'gnus-part-display-hook)
4779 (while (setq elem (pop alist))
4782 (if (gnus-buffer-live-p gnus-summary-buffer)
4783 (set-buffer gnus-summary-buffer))
4784 (symbol-value (car elem))))
4785 (when (and (or (consp val)
4787 (gnus-treat-predicate val)
4788 (or (not (get (car elem) 'highlight))
4791 (funcall (cadr elem)))))))
4793 ;; Dynamic variables.
4795 (defvar part-number)
4796 (defvar total-parts)
4801 (defun gnus-treat-predicate (val)
4806 (stringp (car val)))
4807 (apply 'gnus-or (mapcar `(lambda (s)
4808 (string-match s ,(or gnus-newsgroup-name "")))
4811 (let ((pred (pop val)))
4814 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4816 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4818 (not (gnus-treat-predicate (car val))))
4820 (equal (car val) type))
4822 (error "%S is not a valid predicate" pred)))))
4830 (eq part-number total-parts))
4834 (error "%S is not a valid value" val))))
4840 (run-hooks 'gnus-art-load-hook)
4842 ;;; gnus-art.el ends here