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:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
140 "*All headers that do not match this regexp will be hidden.
141 This variable can also be a list of regexp of headers to remain visible.
142 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
143 :type '(repeat :value-to-internal (lambda (widget value)
144 (custom-split-regexp-maybe value))
145 :match (lambda (widget value)
147 (widget-editable-list-match widget value)))
149 :group 'gnus-article-hiding)
151 (defcustom gnus-sorted-header-list
152 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
153 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
154 "*This variable is a list of regular expressions.
155 If it is non-nil, headers that match the regular expressions will
156 be placed first in the article buffer in the sequence specified by
158 :type '(repeat regexp)
159 :group 'gnus-article-hiding)
161 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
162 "Headers that are only to be displayed if they have interesting data.
163 Possible values in this list are `empty', `newsgroups', `followup-to',
164 `reply-to', `date', `long-to', and `many-to'."
165 :type '(set (const :tag "Headers with no content." empty)
166 (const :tag "Newsgroups with only one group." newsgroups)
167 (const :tag "Followup-to identical to newsgroups." followup-to)
168 (const :tag "Reply-to identical to from." reply-to)
169 (const :tag "Date less than four days old." date)
170 (const :tag "Very long To and/or Cc header." long-to)
171 (const :tag "Multiple To and/or Cc headers." many-to))
172 :group 'gnus-article-hiding)
174 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
175 "Regexp matching signature separator.
176 This can also be a list of regexps. In that case, it will be checked
177 from head to tail looking for a separator. Searches will be done from
178 the end of the buffer."
179 :type '(repeat string)
180 :group 'gnus-article-signature)
182 (defcustom gnus-signature-limit nil
183 "Provide a limit to what is considered a signature.
184 If it is a number, no signature may not be longer (in characters) than
185 that number. If it is a floating point number, no signature may be
186 longer (in lines) than that number. If it is a function, the function
187 will be called without any parameters, and if it returns nil, there is
188 no signature in the buffer. If it is a string, it will be used as a
189 regexp. If it matches, the text in question is not a signature."
190 :type '(choice (integer :value 200)
192 (function :value fun)
193 (regexp :value ".*"))
194 :group 'gnus-article-signature)
196 (defcustom gnus-hidden-properties '(invisible t intangible t)
197 "Property list to use for hiding text."
199 :group 'gnus-article-hiding)
201 ;; Fixme: This isn't the right thing for mixed graphical and and
202 ;; non-graphical frames in a session.
203 ;; gnus-xmas.el overrides this for XEmacs.
204 (defcustom gnus-article-x-face-command
205 (if (and (fboundp 'image-type-available-p)
206 (image-type-available-p 'xbm))
207 'gnus-article-display-xface
208 (if gnus-article-compface-xbm
209 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
210 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
212 "*String or function to be executed to display an X-Face header.
213 If it is a string, the command will be executed in a sub-shell
214 asynchronously. The compressed face will be piped to this command."
215 :type '(choice string
216 (function-item gnus-article-display-xface)
218 :group 'gnus-article-washing)
220 (defcustom gnus-article-x-face-too-ugly nil
221 "Regexp matching posters whose face shouldn't be shown automatically."
222 :type '(choice regexp (const nil))
223 :group 'gnus-article-washing)
225 (defcustom gnus-article-banner-alist nil
226 "Banner alist for stripping.
228 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
229 :type '(repeat (cons symbol regexp))
230 :group 'gnus-article-washing)
232 (defcustom gnus-emphasis-alist
234 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
236 '(("_" "_" underline)
239 ("_/" "/_" underline-italic)
240 ("_\\*" "\\*_" underline-bold)
241 ("\\*/" "/\\*" bold-italic)
242 ("_\\*/" "/\\*_" underline-bold-italic))))
243 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
244 2 3 gnus-emphasis-underline)
248 (format format (car spec) (cadr spec))
249 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
251 "*Alist that says how to fontify certain phrases.
252 Each item looks like this:
254 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
256 The first element is a regular expression to be matched. The second
257 is a number that says what regular expression grouping used to find
258 the entire emphasized word. The third is a number that says what
259 regexp grouping should be displayed and highlighted. The fourth
260 is the face used for highlighting."
261 :type '(repeat (list :value ("" 0 0 default)
263 (integer :tag "Match group")
264 (integer :tag "Emphasize group")
266 :group 'gnus-article-emphasis)
268 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
269 "A regexp to describe whitespace which should not be emphasized.
270 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
271 The former avoids underlining of leading and trailing whitespace,
272 and the latter avoids underlining any whitespace at all."
273 :group 'gnus-article-emphasis
276 (defface gnus-emphasis-bold '((t (:bold t)))
277 "Face used for displaying strong emphasized text (*word*)."
278 :group 'gnus-article-emphasis)
280 (defface gnus-emphasis-italic '((t (:italic t)))
281 "Face used for displaying italic emphasized text (/word/)."
282 :group 'gnus-article-emphasis)
284 (defface gnus-emphasis-underline '((t (:underline t)))
285 "Face used for displaying underlined emphasized text (_word_)."
286 :group 'gnus-article-emphasis)
288 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
289 "Face used for displaying underlined bold emphasized text (_*word*_)."
290 :group 'gnus-article-emphasis)
292 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
293 "Face used for displaying underlined italic emphasized text (_/word/_)."
294 :group 'gnus-article-emphasis)
296 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
297 "Face used for displaying bold italic emphasized text (/*word*/)."
298 :group 'gnus-article-emphasis)
300 (defface gnus-emphasis-underline-bold-italic
301 '((t (:bold t :italic t :underline t)))
302 "Face used for displaying underlined bold italic emphasized text.
303 Esample: (_/*word*/_)."
304 :group 'gnus-article-emphasis)
306 (defface gnus-emphasis-highlight-words
307 '((t (:background "black" :foreground "yellow")))
308 "Face used for displaying highlighted words."
309 :group 'gnus-article-emphasis)
311 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
312 "Format for display of Date headers in article bodies.
313 See `format-time-string' for the possible values.
315 The variable can also be function, which should return a complete Date
316 header. The function is called with one argument, the time, which can
317 be fed to `format-time-string'."
318 :type '(choice string symbol)
319 :link '(custom-manual "(gnus)Article Date")
320 :group 'gnus-article-washing)
323 (autoload 'mail-extract-address-components "mail-extr"))
325 (defcustom gnus-save-all-headers t
326 "*If non-nil, don't remove any headers before saving."
327 :group 'gnus-article-saving
330 (defcustom gnus-prompt-before-saving 'always
331 "*This variable says how much prompting is to be done when saving articles.
332 If it is nil, no prompting will be done, and the articles will be
333 saved to the default files. If this variable is `always', each and
334 every article that is saved will be preceded by a prompt, even when
335 saving large batches of articles. If this variable is neither nil not
336 `always', there the user will be prompted once for a file name for
337 each invocation of the saving commands."
338 :group 'gnus-article-saving
339 :type '(choice (item always)
340 (item :tag "never" nil)
341 (sexp :tag "once" :format "%t\n" :value t)))
343 (defcustom gnus-saved-headers gnus-visible-headers
344 "Headers to keep if `gnus-save-all-headers' is nil.
345 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
346 If that variable is nil, however, all headers that match this regexp
347 will be kept while the rest will be deleted before saving."
348 :group 'gnus-article-saving
351 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
352 "A function to save articles in your favourite format.
353 The function must be interactively callable (in other words, it must
354 be an Emacs command).
356 Gnus provides the following functions:
358 * gnus-summary-save-in-rmail (Rmail format)
359 * gnus-summary-save-in-mail (Unix mail format)
360 * gnus-summary-save-in-folder (MH folder)
361 * gnus-summary-save-in-file (article format)
362 * gnus-summary-save-in-vm (use VM's folder format)
363 * gnus-summary-write-to-file (article format -- overwrite)."
364 :group 'gnus-article-saving
365 :type '(radio (function-item gnus-summary-save-in-rmail)
366 (function-item gnus-summary-save-in-mail)
367 (function-item gnus-summary-save-in-folder)
368 (function-item gnus-summary-save-in-file)
369 (function-item gnus-summary-save-in-vm)
370 (function-item gnus-summary-write-to-file)))
372 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
373 "A function generating a file name to save articles in Rmail format.
374 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
375 :group 'gnus-article-saving
378 (defcustom gnus-mail-save-name 'gnus-plain-save-name
379 "A function generating a file name to save articles in Unix mail format.
380 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
381 :group 'gnus-article-saving
384 (defcustom gnus-folder-save-name 'gnus-folder-save-name
385 "A function generating a file name to save articles in MH folder.
386 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
387 :group 'gnus-article-saving
390 (defcustom gnus-file-save-name 'gnus-numeric-save-name
391 "A function generating a file name to save articles in article format.
392 The function is called with NEWSGROUP, HEADERS, and optional
394 :group 'gnus-article-saving
397 (defcustom gnus-split-methods
398 '((gnus-article-archive-name)
399 (gnus-article-nndoc-name))
400 "*Variable used to suggest where articles are to be saved.
401 For instance, if you would like to save articles related to Gnus in
402 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
403 you could set this variable to something like:
405 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
406 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
408 This variable is an alist where the where the key is the match and the
409 value is a list of possible files to save in if the match is non-nil.
411 If the match is a string, it is used as a regexp match on the
412 article. If the match is a symbol, that symbol will be funcalled
413 from the buffer of the article to be saved with the newsgroup as the
414 parameter. If it is a list, it will be evaled in the same buffer.
416 If this form or function returns a string, this string will be used as
417 a possible file name; and if it returns a non-nil list, that list will
418 be used as possible file names."
419 :group 'gnus-article-saving
420 :type '(repeat (choice (list :value (fun) function)
421 (cons :value ("" "") regexp (repeat string))
424 (defcustom gnus-page-delimiter "^\^L"
425 "*Regexp describing what to use as article page delimiters.
426 The default value is \"^\^L\", which is a form linefeed at the
427 beginning of a line."
429 :group 'gnus-article-various)
431 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
432 "*The format specification for the article mode line.
433 See `gnus-summary-mode-line-format' for a closer description.
435 The following additional specs are available:
437 %w The article washing status.
438 %m The number of MIME parts in the article."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-mode-hook nil
443 "*A hook for Gnus article mode."
445 :group 'gnus-article-various)
447 (defcustom gnus-article-menu-hook nil
448 "*Hook run after the creation of the article mode menu."
450 :group 'gnus-article-various)
452 (defcustom gnus-article-prepare-hook nil
453 "*A hook called after an article has been prepared in the article buffer."
455 :group 'gnus-article-various)
457 (defcustom gnus-article-hide-pgp-hook nil
458 "*A hook called after successfully hiding a PGP signature."
460 :group 'gnus-article-various)
462 (defcustom gnus-article-button-face 'bold
463 "Face used for highlighting buttons in the article buffer.
465 An article button is a piece of text that you can activate by pressing
466 `RET' or `mouse-2' above it."
468 :group 'gnus-article-buttons)
470 (defcustom gnus-article-mouse-face 'highlight
471 "Face used for mouse highlighting in the article buffer.
473 Article buttons will be displayed in this face when the cursor is
476 :group 'gnus-article-buttons)
478 (defcustom gnus-signature-face 'gnus-signature-face
479 "Face used for highlighting a signature in the article buffer.
480 Obsolete; use the face `gnus-signature-face' for customizations instead."
482 :group 'gnus-article-highlight
483 :group 'gnus-article-signature)
485 (defface gnus-signature-face
488 "Face used for highlighting a signature in the article buffer."
489 :group 'gnus-article-highlight
490 :group 'gnus-article-signature)
492 (defface gnus-header-from-face
495 (:foreground "spring green"))
498 (:foreground "red3"))
501 "Face used for displaying from headers."
502 :group 'gnus-article-headers
503 :group 'gnus-article-highlight)
505 (defface gnus-header-subject-face
508 (:foreground "SeaGreen3"))
511 (:foreground "red4"))
513 (:bold t :italic t)))
514 "Face used for displaying subject headers."
515 :group 'gnus-article-headers
516 :group 'gnus-article-highlight)
518 (defface gnus-header-newsgroups-face
521 (:foreground "yellow" :italic t))
524 (:foreground "MidnightBlue" :italic t))
527 "Face used for displaying newsgroups headers."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defface gnus-header-name-face
534 (:foreground "SeaGreen"))
537 (:foreground "maroon"))
540 "Face used for displaying header names."
541 :group 'gnus-article-headers
542 :group 'gnus-article-highlight)
544 (defface gnus-header-content-face
547 (:foreground "forest green" :italic t))
550 (:foreground "indianred4" :italic t))
552 (:italic t))) "Face used for displaying header content."
553 :group 'gnus-article-headers
554 :group 'gnus-article-highlight)
556 (defcustom gnus-header-face-alist
557 '(("From" nil gnus-header-from-face)
558 ("Subject" nil gnus-header-subject-face)
559 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
560 ("" gnus-header-name-face gnus-header-content-face))
561 "*Controls highlighting of article header.
563 An alist of the form (HEADER NAME CONTENT).
565 HEADER is a regular expression which should match the name of an
566 header header and NAME and CONTENT are either face names or nil.
568 The name of each header field will be displayed using the face
569 specified by the first element in the list where HEADER match the
570 header name and NAME is non-nil. Similarly, the content will be
571 displayed by the first non-nil matching CONTENT face."
572 :group 'gnus-article-headers
573 :group 'gnus-article-highlight
574 :type '(repeat (list (regexp :tag "Header")
576 (item :tag "skip" nil)
577 (face :value default))
578 (choice :tag "Content"
579 (item :tag "skip" nil)
580 (face :value default)))))
582 (defcustom gnus-article-decode-hook
583 '(article-decode-charset article-decode-encoded-words)
584 "*Hook run to decode charsets in articles."
585 :group 'gnus-article-headers
588 (defcustom gnus-display-mime-function 'gnus-display-mime
589 "Function to display MIME articles."
590 :group 'gnus-article-mime
593 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
594 "Function used to decode headers.")
596 (defvar gnus-article-dumbquotes-map
614 "Table for MS-to-Latin1 translation.")
616 (defcustom gnus-ignored-mime-types nil
617 "List of MIME types that should be ignored by Gnus."
618 :group 'gnus-article-mime
619 :type '(repeat regexp))
621 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
622 "List of MIME types that should not be given buttons when rendered inline."
623 :group 'gnus-article-mime
624 :type '(repeat regexp))
626 (defcustom gnus-article-mime-part-function nil
627 "Function called with a MIME handle as the argument.
628 This is meant for people who want to do something automatic based
629 on parts -- for instance, adding Vcard info to a database."
630 :group 'gnus-article-mime
633 (defcustom gnus-mime-multipart-functions nil
634 "An alist of MIME types to functions to display them.")
636 (defcustom gnus-article-date-lapsed-new-header nil
637 "Whether the X-Sent and Date headers can coexist.
638 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
639 either replace the old \"Date:\" header (if this variable is nil), or
640 be added below it (otherwise)."
641 :group 'gnus-article-headers
644 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
645 "Function called with a MIME handle as the argument.
646 This is meant for people who want to view first matched part.
647 For `undisplayed-alternative' (default), the first undisplayed
648 part or alternative part is used. For `undisplayed', the first
649 undisplayed part is used. For a function, the first part which
650 the function return `t' is used. For `nil', the first part is
652 :group 'gnus-article-mime
654 (item :tag "first" :value nil)
655 (item :tag "undisplayed" :value undisplayed)
656 (item :tag "undisplayed or alternative"
657 :value undisplayed-alternative)
660 (defcustom gnus-mime-action-alist
661 '(("save to file" . gnus-mime-save-part)
662 ("save and strip" . gnus-mime-save-part-and-strip)
663 ("display as text" . gnus-mime-inline-part)
664 ("view the part" . gnus-mime-view-part)
665 ("pipe to command" . gnus-mime-pipe-part)
666 ("toggle display" . gnus-article-press-button)
667 ("toggle display" . gnus-article-view-part-as-charset)
668 ("view as type" . gnus-mime-view-part-as-type)
669 ("internalize type" . gnus-mime-internalize-part)
670 ("externalize type" . gnus-mime-externalize-part))
671 "An alist of actions that run on the MIME attachment."
672 :group 'gnus-article-mime
673 :type '(repeat (cons (string :tag "name")
677 ;;; The treatment variables
680 (defvar gnus-part-display-hook nil
681 "Hook called on parts that are to receive treatment.")
683 (defvar gnus-article-treat-custom
684 '(choice (const :tag "Off" nil)
686 (const :tag "Header" head)
687 (const :tag "Last" last)
688 (integer :tag "Less")
689 (repeat :tag "Groups" regexp)
690 (sexp :tag "Predicate")))
692 (defvar gnus-article-treat-head-custom
693 '(choice (const :tag "Off" nil)
694 (const :tag "Header" head)))
696 (defvar gnus-article-treat-types '("text/plain")
699 (defvar gnus-inhibit-treatment nil
700 "Whether to inhibit treatment.")
702 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
703 "Highlight the signature.
704 Valid values are nil, t, `head', `last', an integer or a predicate.
705 See the manual for details."
706 :group 'gnus-article-treat
707 :type gnus-article-treat-custom)
708 (put 'gnus-treat-highlight-signature 'highlight t)
710 (defcustom gnus-treat-buttonize 100000
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-buttonize 'highlight t)
718 (defcustom gnus-treat-buttonize-head 'head
719 "Add buttons to the head.
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-head-custom)
724 (put 'gnus-treat-buttonize-head 'highlight t)
726 (defcustom gnus-treat-emphasize 50000
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-custom)
732 (put 'gnus-treat-emphasize 'highlight t)
734 (defcustom gnus-treat-strip-cr nil
735 "Remove carriage returns.
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)
741 (defcustom gnus-treat-hide-headers 'head
743 Valid values are nil, t, `head', `last', an integer or a predicate.
744 See the manual for details."
745 :group 'gnus-article-treat
746 :type gnus-article-treat-head-custom)
748 (defcustom gnus-treat-hide-boring-headers nil
749 "Hide boring headers.
750 Valid values are nil, t, `head', `last', an integer or a predicate.
751 See the manual for details."
752 :group 'gnus-article-treat
753 :type gnus-article-treat-head-custom)
755 (defcustom gnus-treat-hide-signature nil
757 Valid values are nil, t, `head', `last', an integer or a predicate.
758 See the manual for details."
759 :group 'gnus-article-treat
760 :type gnus-article-treat-custom)
762 (defcustom gnus-treat-fill-article nil
764 Valid values are nil, t, `head', `last', an integer or a predicate.
765 See the manual for details."
766 :group 'gnus-article-treat
767 :type gnus-article-treat-custom)
769 (defcustom gnus-treat-hide-citation nil
771 Valid values are nil, t, `head', `last', an integer or a predicate.
772 See the manual for details."
773 :group 'gnus-article-treat
774 :type gnus-article-treat-custom)
776 (defcustom gnus-treat-hide-citation-maybe nil
778 Valid values are nil, t, `head', `last', an integer or a predicate.
779 See the manual for details."
780 :group 'gnus-article-treat
781 :type gnus-article-treat-custom)
783 (defcustom gnus-treat-strip-list-identifiers 'head
784 "Strip list identifiers from `gnus-list-identifiers`.
785 Valid values are nil, t, `head', `last', an integer or a predicate.
786 See the manual for details."
787 :group 'gnus-article-treat
788 :type gnus-article-treat-custom)
790 (defcustom gnus-treat-strip-pgp t
791 "Strip PGP signatures.
792 Valid values are nil, t, `head', `last', an integer or a predicate.
793 See the manual for details."
794 :group 'gnus-article-treat
795 :type gnus-article-treat-custom)
797 (defcustom gnus-treat-strip-pem nil
798 "Strip PEM signatures.
799 Valid values are nil, t, `head', `last', an integer or a predicate.
800 See the manual for details."
801 :group 'gnus-article-treat
802 :type gnus-article-treat-custom)
804 (defcustom gnus-treat-strip-banner t
805 "Strip banners from articles.
806 The banner to be stripped is specified in the `banner' group parameter.
807 Valid values are nil, t, `head', `last', an integer or a predicate.
808 See the manual for details."
809 :group 'gnus-article-treat
810 :type gnus-article-treat-custom)
812 (defcustom gnus-treat-highlight-headers 'head
813 "Highlight the headers.
814 Valid values are nil, t, `head', `last', an integer or a predicate.
815 See the manual for details."
816 :group 'gnus-article-treat
817 :type gnus-article-treat-head-custom)
818 (put 'gnus-treat-highlight-headers 'highlight t)
820 (defcustom gnus-treat-highlight-citation t
821 "Highlight cited text.
822 Valid values are nil, t, `head', `last', an integer or a predicate.
823 See the manual for details."
824 :group 'gnus-article-treat
825 :type gnus-article-treat-custom)
826 (put 'gnus-treat-highlight-citation 'highlight t)
828 (defcustom gnus-treat-date-ut nil
829 "Display the Date in UT (GMT).
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-head-custom)
835 (defcustom gnus-treat-date-local nil
836 "Display the Date in the local timezone.
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-head-custom)
842 (defcustom gnus-treat-date-lapsed nil
843 "Display the Date header in a way that says how much time has elapsed.
844 Valid values are nil, t, `head', `last', an integer or a predicate.
845 See the manual for details."
846 :group 'gnus-article-treat
847 :type gnus-article-treat-head-custom)
849 (defcustom gnus-treat-date-original nil
850 "Display the date in the original timezone.
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-head-custom)
856 (defcustom gnus-treat-date-iso8601 nil
857 "Display the date in the ISO8601 format.
858 Valid values are nil, t, `head', `last', an integer or a predicate.
859 See the manual for details."
860 :group 'gnus-article-treat
861 :type gnus-article-treat-head-custom)
863 (defcustom gnus-treat-date-user-defined nil
864 "Display the date in a user-defined format.
865 The format is defined by the `gnus-article-time-format' variable.
866 Valid values are nil, t, `head', `last', an integer or a predicate.
867 See the manual for details."
868 :group 'gnus-article-treat
869 :type gnus-article-treat-head-custom)
871 (defcustom gnus-treat-strip-headers-in-body t
872 "Strip the X-No-Archive header line from the beginning of the body.
873 Valid values are nil, t, `head', `last', an integer or a predicate.
874 See the manual for details."
875 :group 'gnus-article-treat
876 :type gnus-article-treat-custom)
878 (defcustom gnus-treat-strip-trailing-blank-lines nil
879 "Strip trailing blank lines.
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882 :group 'gnus-article-treat
883 :type gnus-article-treat-custom)
885 (defcustom gnus-treat-strip-leading-blank-lines nil
886 "Strip leading blank lines.
887 Valid values are nil, t, `head', `last', an integer or a predicate.
888 See the manual for details."
889 :group 'gnus-article-treat
890 :type gnus-article-treat-custom)
892 (defcustom gnus-treat-strip-multiple-blank-lines nil
893 "Strip multiple blank lines.
894 Valid values are nil, t, `head', `last', an integer or a predicate.
895 See the manual for details."
896 :group 'gnus-article-treat
897 :type gnus-article-treat-custom)
899 (defcustom gnus-treat-overstrike t
900 "Treat overstrike highlighting.
901 Valid values are nil, t, `head', `last', an integer or a predicate.
902 See the manual for details."
903 :group 'gnus-article-treat
904 :type gnus-article-treat-custom)
905 (put 'gnus-treat-overstrike 'highlight t)
907 (defcustom gnus-treat-display-xface
908 (and (or (and (fboundp 'image-type-available-p)
909 (image-type-available-p 'xbm)
910 (string-match "^0x" (shell-command-to-string "uncompface")))
911 (and (featurep 'xemacs) (featurep 'xface)))
913 "Display X-Face headers.
914 Valid values are nil, t, `head', `last', an integer or a predicate.
915 See the manual for details."
916 :group 'gnus-article-treat
917 :type gnus-article-treat-head-custom)
918 (put 'gnus-treat-display-xface 'highlight t)
920 (defcustom gnus-treat-display-smileys
921 (if (or (and (featurep 'xemacs)
923 (and (fboundp 'image-type-available-p)
924 (image-type-available-p 'pbm)))
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See the manual for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-custom)
931 (put 'gnus-treat-display-smileys 'highlight t)
933 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
935 Valid values are nil, t, `head', `last', an integer or a predicate.
936 See the manual for details."
937 :group 'gnus-article-treat
938 :type gnus-article-treat-head-custom)
939 (put 'gnus-treat-display-picons 'highlight t)
941 (defcustom gnus-treat-capitalize-sentences nil
942 "Capitalize sentence-starting words.
943 Valid values are nil, t, `head', `last', an integer or a predicate.
944 See the manual for details."
945 :group 'gnus-article-treat
946 :type gnus-article-treat-custom)
948 (defcustom gnus-treat-fill-long-lines nil
950 Valid values are nil, t, `head', `last', an integer or a predicate.
951 See the manual for details."
952 :group 'gnus-article-treat
953 :type gnus-article-treat-custom)
955 (defcustom gnus-treat-play-sounds nil
957 Valid values are nil, t, `head', `last', an integer or a predicate.
958 See the manual for details."
959 :group 'gnus-article-treat
960 :type gnus-article-treat-custom)
962 (defcustom gnus-treat-translate nil
963 "Translate articles from one language to another.
964 Valid values are nil, t, `head', `last', an integer or a predicate.
965 See the manual for details."
966 :group 'gnus-article-treat
967 :type gnus-article-treat-custom)
969 ;;; Internal variables
971 (defvar article-goto-body-goes-to-point-min-p nil)
972 (defvar gnus-article-wash-types nil)
973 (defvar gnus-article-emphasis-alist nil)
975 (defvar gnus-article-mime-handle-alist-1 nil)
976 (defvar gnus-treatment-function-alist
977 '((gnus-treat-strip-banner gnus-article-strip-banner)
978 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
979 (gnus-treat-highlight-signature gnus-article-highlight-signature)
980 (gnus-treat-buttonize gnus-article-add-buttons)
981 (gnus-treat-fill-article gnus-article-fill-cited-article)
982 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
983 (gnus-treat-strip-cr gnus-article-remove-cr)
984 (gnus-treat-emphasize gnus-article-emphasize)
985 (gnus-treat-display-xface gnus-article-display-x-face)
986 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
987 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
988 (gnus-treat-hide-signature gnus-article-hide-signature)
989 (gnus-treat-hide-citation gnus-article-hide-citation)
990 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
991 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
992 (gnus-treat-strip-pgp gnus-article-hide-pgp)
993 (gnus-treat-strip-pem gnus-article-hide-pem)
994 (gnus-treat-highlight-headers gnus-article-highlight-headers)
995 (gnus-treat-highlight-citation gnus-article-highlight-citation)
996 (gnus-treat-highlight-signature gnus-article-highlight-signature)
997 (gnus-treat-date-ut gnus-article-date-ut)
998 (gnus-treat-date-local gnus-article-date-local)
999 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1000 (gnus-treat-date-original gnus-article-date-original)
1001 (gnus-treat-date-user-defined gnus-article-date-user)
1002 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1003 (gnus-treat-strip-trailing-blank-lines
1004 gnus-article-remove-trailing-blank-lines)
1005 (gnus-treat-strip-leading-blank-lines
1006 gnus-article-strip-leading-blank-lines)
1007 (gnus-treat-strip-multiple-blank-lines
1008 gnus-article-strip-multiple-blank-lines)
1009 (gnus-treat-overstrike gnus-article-treat-overstrike)
1010 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1011 (gnus-treat-display-smileys gnus-smiley-display)
1012 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1013 (gnus-treat-display-picons gnus-article-display-picons)
1014 (gnus-treat-play-sounds gnus-earcon-display)))
1016 (defvar gnus-article-mime-handle-alist nil)
1017 (defvar article-lapsed-timer nil)
1018 (defvar gnus-article-current-summary nil)
1020 (defvar gnus-article-mode-syntax-table
1021 (let ((table (copy-syntax-table text-mode-syntax-table)))
1022 (modify-syntax-entry ?- "w" table)
1023 (modify-syntax-entry ?> ")" table)
1024 (modify-syntax-entry ?< "(" table)
1026 "Syntax table used in article mode buffers.
1027 Initialized from `text-mode-syntax-table.")
1029 (defvar gnus-save-article-buffer nil)
1031 (defvar gnus-article-mode-line-format-alist
1032 (nconc '((?w (gnus-article-wash-status) ?s)
1033 (?m (gnus-article-mime-part-status) ?s))
1034 gnus-summary-mode-line-format-alist))
1036 (defvar gnus-number-of-articles-to-be-saved nil)
1038 (defvar gnus-inhibit-hiding nil)
1040 (defsubst gnus-article-hide-text (b e props)
1041 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1042 (add-text-properties b e props)
1043 (when (memq 'intangible props)
1045 (max (1- b) (point-min))
1046 b 'intangible (cddr (memq 'intangible props)))))
1047 (defsubst gnus-article-unhide-text (b e)
1048 "Remove hidden text properties from region between B and E."
1049 (remove-text-properties b e gnus-hidden-properties)
1050 (when (memq 'intangible gnus-hidden-properties)
1051 (put-text-property (max (1- b) (point-min))
1052 b 'intangible nil)))
1054 (defun gnus-article-hide-text-type (b e type)
1055 "Hide text of TYPE between B and E."
1056 (push type gnus-article-wash-types)
1057 (gnus-article-hide-text
1058 b e (cons 'article-type (cons type gnus-hidden-properties))))
1060 (defun gnus-article-unhide-text-type (b e type)
1061 "Unhide text of TYPE between B and E."
1062 (setq gnus-article-wash-types
1063 (delq type gnus-article-wash-types))
1064 (remove-text-properties
1065 b e (cons 'article-type (cons type gnus-hidden-properties)))
1066 (when (memq 'intangible gnus-hidden-properties)
1067 (put-text-property (max (1- b) (point-min))
1068 b 'intangible nil)))
1070 (defun gnus-article-hide-text-of-type (type)
1071 "Hide text of TYPE in the current buffer."
1073 (let ((b (point-min))
1075 (while (setq b (text-property-any b e 'article-type type))
1076 (add-text-properties b (incf b) gnus-hidden-properties)))))
1078 (defun gnus-article-delete-text-of-type (type)
1079 "Delete text of TYPE in the current buffer."
1081 (let ((b (point-min)))
1082 (while (setq b (text-property-any b (point-max) 'article-type type))
1084 b (or (text-property-not-all b (point-max) 'article-type type)
1087 (defun gnus-article-delete-invisible-text ()
1088 "Delete all invisible text in the current buffer."
1090 (let ((b (point-min)))
1091 (while (setq b (text-property-any b (point-max) 'invisible t))
1093 b (or (text-property-not-all b (point-max) 'invisible t)
1096 (defun gnus-article-text-type-exists-p (type)
1097 "Say whether any text of type TYPE exists in the buffer."
1098 (text-property-any (point-min) (point-max) 'article-type type))
1100 (defsubst gnus-article-header-rank ()
1101 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1102 (let ((list gnus-sorted-header-list)
1105 (when (looking-at (car list))
1107 (setq list (cdr list))
1111 (defun article-hide-headers (&optional arg delete)
1112 "Hide unwanted headers and possibly sort them as well."
1114 ;; This function might be inhibited.
1115 (unless gnus-inhibit-hiding
1118 (let ((buffer-read-only nil)
1119 (case-fold-search t)
1120 (max (1+ (length gnus-sorted-header-list)))
1121 (ignored (when (not gnus-visible-headers)
1122 (cond ((stringp gnus-ignored-headers)
1123 gnus-ignored-headers)
1124 ((listp gnus-ignored-headers)
1125 (mapconcat 'identity gnus-ignored-headers
1128 (cond ((stringp gnus-visible-headers)
1129 gnus-visible-headers)
1130 ((and gnus-visible-headers
1131 (listp gnus-visible-headers))
1132 (mapconcat 'identity gnus-visible-headers "\\|"))))
1133 (inhibit-point-motion-hooks t)
1135 ;; First we narrow to just the headers.
1136 (article-narrow-to-head)
1137 ;; Hide any "From " lines at the beginning of (mail) articles.
1138 (while (looking-at "From ")
1141 (delete-region (point-min) (point)))
1142 ;; Then treat the rest of the header lines.
1143 ;; Then we use the two regular expressions
1144 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1145 ;; select which header lines is to remain visible in the
1147 (while (re-search-forward "^[^ \t]*:" nil t)
1149 ;; Mark the rank of the header.
1151 (point) (1+ (point)) 'message-rank
1152 (if (or (and visible (looking-at visible))
1154 (not (looking-at ignored))))
1155 (gnus-article-header-rank)
1158 (message-sort-headers-1)
1159 (when (setq beg (text-property-any
1160 (point-min) (point-max) 'message-rank (+ 2 max)))
1161 ;; We delete the unwanted headers.
1162 (push 'headers gnus-article-wash-types)
1163 (add-text-properties (point-min) (+ 5 (point-min))
1164 '(article-type headers dummy-invisible t))
1165 (delete-region beg (point-max))))))))
1167 (defun article-hide-boring-headers (&optional arg)
1168 "Toggle hiding of headers that aren't very interesting.
1169 If given a negative prefix, always show; if given a positive prefix,
1171 (interactive (gnus-article-hidden-arg))
1172 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1173 (not gnus-show-all-headers))
1176 (let ((buffer-read-only nil)
1177 (list gnus-boring-article-headers)
1178 (inhibit-point-motion-hooks t)
1180 (article-narrow-to-head)
1182 (setq elem (pop list))
1183 (goto-char (point-min))
1185 ;; Hide empty headers.
1187 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1189 (gnus-article-hide-text-type
1190 (progn (beginning-of-line) (point))
1193 (if (re-search-forward "^[^ \t]" nil t)
1197 ;; Hide boring Newsgroups header.
1198 ((eq elem 'newsgroups)
1199 (when (equal (gnus-fetch-field "newsgroups")
1200 (gnus-group-real-name
1201 (if (boundp 'gnus-newsgroup-name)
1204 (gnus-article-hide-header "newsgroups")))
1205 ((eq elem 'followup-to)
1206 (when (equal (message-fetch-field "followup-to")
1207 (message-fetch-field "newsgroups"))
1208 (gnus-article-hide-header "followup-to")))
1209 ((eq elem 'reply-to)
1210 (let ((from (message-fetch-field "from"))
1211 (reply-to (message-fetch-field "reply-to")))
1216 (nth 1 (mail-extract-address-components from))
1217 (nth 1 (mail-extract-address-components reply-to)))))
1218 (gnus-article-hide-header "reply-to"))))
1220 (let ((date (message-fetch-field "date")))
1222 (< (days-between (current-time-string) date)
1224 (gnus-article-hide-header "date"))))
1226 (let ((to (message-fetch-field "to"))
1227 (cc (message-fetch-field "cc")))
1228 (when (> (length to) 1024)
1229 (gnus-article-hide-header "to"))
1230 (when (> (length cc) 1024)
1231 (gnus-article-hide-header "cc"))))
1235 (goto-char (point-min))
1236 (while (re-search-forward "^to:" nil t)
1237 (setq to-count (1+ to-count)))
1238 (when (> to-count 1)
1239 (while (> to-count 0)
1240 (goto-char (point-min))
1242 (re-search-forward "^to:" nil nil to-count)
1244 (narrow-to-region (point) (point-max))
1245 (gnus-article-hide-header "to"))
1246 (setq to-count (1- to-count))))
1247 (goto-char (point-min))
1248 (while (re-search-forward "^cc:" nil t)
1249 (setq cc-count (1+ cc-count)))
1250 (when (> cc-count 1)
1251 (while (> cc-count 0)
1252 (goto-char (point-min))
1254 (re-search-forward "^cc:" nil nil cc-count)
1256 (narrow-to-region (point) (point-max))
1257 (gnus-article-hide-header "cc"))
1258 (setq cc-count (1- cc-count)))))))))))))
1260 (defun gnus-article-hide-header (header)
1262 (goto-char (point-min))
1263 (when (re-search-forward (concat "^" header ":") nil t)
1264 (gnus-article-hide-text-type
1265 (progn (beginning-of-line) (point))
1268 (if (re-search-forward "^[^ \t]" nil t)
1273 (defvar gnus-article-normalized-header-length 40
1274 "Length of normalized headers.")
1276 (defun article-normalize-headers ()
1277 "Make all header lines 40 characters long."
1279 (let ((buffer-read-only nil)
1283 (article-narrow-to-head)
1286 ((< (setq column (- (gnus-point-at-eol) (point)))
1287 gnus-article-normalized-header-length)
1289 (insert (make-string
1290 (- gnus-article-normalized-header-length column)
1292 ((> column gnus-article-normalized-header-length)
1293 (gnus-put-text-property
1295 (forward-char gnus-article-normalized-header-length)
1302 (forward-line 1))))))
1304 (defun article-treat-dumbquotes ()
1305 "Translate M******** sm*rtq**t*s into proper text.
1306 Note that this function guesses whether a character is a sm*rtq**t* or
1307 not, so it should only be used interactively."
1309 (article-translate-strings gnus-article-dumbquotes-map))
1311 (defun article-translate-characters (from to)
1312 "Translate all characters in the body of the article according to FROM and TO.
1313 FROM is a string of characters to translate from; to is a string of
1314 characters to translate to."
1316 (when (article-goto-body)
1317 (let ((buffer-read-only nil)
1318 (x (make-string 225 ?x))
1320 (while (< (incf i) (length x))
1323 (while (< i (length from))
1324 (aset x (aref from i) (aref to i))
1326 (translate-region (point) (point-max) x)))))
1328 (defun article-translate-strings (map)
1329 "Translate all string in the body of the article according to MAP.
1330 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1332 (when (article-goto-body)
1333 (let ((buffer-read-only nil)
1335 (while (setq elem (pop map))
1337 (while (search-forward (car elem) nil t)
1338 (replace-match (cadr elem)))))))))
1340 (defun article-treat-overstrike ()
1341 "Translate overstrikes into bold text."
1344 (when (article-goto-body)
1345 (let ((buffer-read-only nil))
1346 (while (search-forward "\b" nil t)
1347 (let ((next (char-after))
1348 (previous (char-after (- (point) 2))))
1349 ;; We do the boldification/underlining by hiding the
1350 ;; overstrikes and putting the proper text property
1354 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1355 (put-text-property (point) (1+ (point)) 'face 'bold))
1357 (gnus-article-hide-text-type
1358 (1- (point)) (1+ (point)) 'overstrike)
1360 (- (point) 2) (1- (point)) 'face 'underline))
1362 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1364 (point) (1+ (point)) 'face 'underline)))))))))
1366 (defun article-fill-long-lines ()
1367 "Fill lines that are wider than the window width."
1370 (let ((buffer-read-only nil)
1371 (width (window-width (get-buffer-window (current-buffer)))))
1374 (let ((adaptive-fill-mode nil))
1377 (when (>= (current-column) (min fill-column width))
1378 (narrow-to-region (point) (gnus-point-at-bol))
1379 (fill-paragraph nil)
1380 (goto-char (point-max))
1382 (forward-line 1)))))))
1384 (defun article-capitalize-sentences ()
1385 "Capitalize the first word in each sentence."
1388 (let ((buffer-read-only nil)
1389 (paragraph-start "^[\n\^L]"))
1393 (forward-sentence)))))
1395 (defun article-remove-cr ()
1396 "Remove trailing CRs and then translate remaining CRs into LFs."
1399 (let ((buffer-read-only nil))
1400 (goto-char (point-min))
1401 (while (re-search-forward "\r+$" nil t)
1402 (replace-match "" t t))
1403 (goto-char (point-min))
1404 (while (search-forward "\r" nil t)
1405 (replace-match "\n" t t)))))
1407 (defun article-remove-trailing-blank-lines ()
1408 "Remove all trailing blank lines from the article."
1411 (let ((buffer-read-only nil))
1412 (goto-char (point-max))
1416 (while (and (not (bobp))
1417 (looking-at "^[ \t]*$")
1418 (not (gnus-annotation-in-region-p
1419 (point) (gnus-point-at-eol))))
1424 (defun article-display-x-face (&optional force)
1425 "Look for an X-Face header and display it if present."
1426 (interactive (list 'force))
1428 ;; Delete the old process, if any.
1429 (when (process-status "article-x-face")
1430 (delete-process "article-x-face"))
1431 (let ((inhibit-point-motion-hooks t)
1432 (case-fold-search t)
1435 (article-narrow-to-head)
1436 (goto-char (point-min))
1437 (setq from (message-fetch-field "from"))
1438 (goto-char (point-min))
1439 (while (and gnus-article-x-face-command
1442 ;; Check whether this face is censored.
1443 (not gnus-article-x-face-too-ugly)
1444 (and gnus-article-x-face-too-ugly from
1445 (not (string-match gnus-article-x-face-too-ugly
1447 ;; Has to be present.
1448 (re-search-forward "^X-Face: " nil t))
1449 ;; This used to try to do multiple faces (`while' instead of
1450 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1451 ;; work (b) it can crash some versions of Emacs (c) are
1452 ;; multiple faces really something to encourage?
1453 (when (stringp gnus-article-x-face-command)
1455 ;; We now have the area of the buffer where the X-Face is stored.
1458 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1459 ;; We display the face.
1460 (if (symbolp gnus-article-x-face-command)
1461 ;; The command is a lisp function, so we call it.
1462 (if (gnus-functionp gnus-article-x-face-command)
1463 (funcall gnus-article-x-face-command beg end)
1464 (error "%s is not a function" gnus-article-x-face-command))
1465 ;; The command is a string, so we interpret the command
1466 ;; as a, well, command, and fork it off.
1467 (let ((process-connection-type nil))
1468 (process-kill-without-query
1470 "article-x-face" nil shell-file-name shell-command-switch
1471 gnus-article-x-face-command))
1472 (process-send-region "article-x-face" beg end)
1473 (process-send-eof "article-x-face"))))))))))
1475 (defun article-decode-mime-words ()
1476 "Decode all MIME-encoded words in the article."
1479 (set-buffer gnus-article-buffer)
1480 (let ((inhibit-point-motion-hooks t)
1482 (mail-parse-charset gnus-newsgroup-charset)
1483 (mail-parse-ignored-charsets
1484 (save-excursion (set-buffer gnus-summary-buffer)
1485 gnus-newsgroup-ignored-charsets)))
1486 (mail-decode-encoded-word-region (point-min) (point-max)))))
1488 (defun article-decode-charset (&optional prompt)
1489 "Decode charset-encoded text in the article.
1490 If PROMPT (the prefix), prompt for a coding system to use."
1492 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1494 (mail-parse-charset gnus-newsgroup-charset)
1495 (mail-parse-ignored-charsets
1496 (save-excursion (condition-case nil
1497 (set-buffer gnus-summary-buffer)
1499 gnus-newsgroup-ignored-charsets))
1500 ct cte ctl charset format)
1503 (article-narrow-to-head)
1504 (setq ct (message-fetch-field "Content-Type" t)
1505 cte (message-fetch-field "Content-Transfer-Encoding" t)
1506 ctl (and ct (ignore-errors
1507 (mail-header-parse-content-type ct)))
1510 (mm-read-coding-system "Charset to decode: "))
1512 (mail-content-type-get ctl 'charset)))
1513 format (and ctl (mail-content-type-get ctl 'format)))
1515 (setq cte (mail-header-strip cte)))
1516 (if (and ctl (not (string-match "/" (car ctl))))
1518 (goto-char (point-max)))
1521 (narrow-to-region (point) (point-max))
1522 (when (and (eq mail-parse-charset 'gnus-decoded)
1523 (eq (mm-body-7-or-8) '8bit))
1524 ;; The text code could have been decoded.
1525 (setq charset mail-parse-charset))
1526 (when (and (or (not ctl)
1527 (equal (car ctl) "text/plain"))
1528 (not format)) ;; article with format will decode later.
1530 charset (and cte (intern (downcase
1531 (gnus-strip-whitespace cte))))
1534 (defun article-decode-encoded-words ()
1535 "Remove encoded-word encoding from headers."
1536 (let ((inhibit-point-motion-hooks t)
1537 (mail-parse-charset gnus-newsgroup-charset)
1538 (mail-parse-ignored-charsets
1539 (save-excursion (condition-case nil
1540 (set-buffer gnus-summary-buffer)
1542 gnus-newsgroup-ignored-charsets))
1545 (article-narrow-to-head)
1546 (funcall gnus-decode-header-function (point-min) (point-max)))))
1548 (defun article-de-quoted-unreadable (&optional force)
1549 "Translate a quoted-printable-encoded article.
1550 If FORCE, decode the article whether it is marked as quoted-printable
1552 (interactive (list 'force))
1554 (let ((buffer-read-only nil) type charset)
1555 (if (gnus-buffer-live-p gnus-original-article-buffer)
1556 (with-current-buffer gnus-original-article-buffer
1558 (gnus-fetch-field "content-transfer-encoding"))
1559 (let* ((ct (gnus-fetch-field "content-type"))
1562 (mail-header-parse-content-type ct)))))
1563 (setq charset (and ctl
1564 (mail-content-type-get ctl 'charset)))
1565 (if (stringp charset)
1566 (setq charset (intern (downcase charset)))))))
1568 (setq charset gnus-newsgroup-charset))
1570 (and type (let ((case-fold-search t))
1571 (string-match "quoted-printable" type))))
1573 (quoted-printable-decode-region
1574 (point) (point-max) (mm-charset-to-coding-system charset))))))
1576 (defun article-de-base64-unreadable (&optional force)
1577 "Translate a base64 article.
1578 If FORCE, decode the article whether it is marked as base64 not."
1579 (interactive (list 'force))
1581 (let ((buffer-read-only nil) type charset)
1582 (if (gnus-buffer-live-p gnus-original-article-buffer)
1583 (with-current-buffer gnus-original-article-buffer
1585 (gnus-fetch-field "content-transfer-encoding"))
1586 (let* ((ct (gnus-fetch-field "content-type"))
1589 (mail-header-parse-content-type ct)))))
1590 (setq charset (and ctl
1591 (mail-content-type-get ctl 'charset)))
1592 (if (stringp charset)
1593 (setq charset (intern (downcase charset)))))))
1595 (setq charset gnus-newsgroup-charset))
1597 (and type (let ((case-fold-search t))
1598 (string-match "base64" type))))
1601 (narrow-to-region (point) (point-max))
1602 (base64-decode-region (point-min) (point-max))
1603 (mm-decode-coding-region
1604 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1609 (defun article-decode-HZ ()
1610 "Translate a HZ-encoded article."
1614 (let ((buffer-read-only nil))
1615 (rfc1843-decode-region (point-min) (point-max)))))
1617 (defun article-wash-html ()
1618 "Format an html article."
1621 (let ((buffer-read-only nil)
1623 (if (gnus-buffer-live-p gnus-original-article-buffer)
1624 (with-current-buffer gnus-original-article-buffer
1625 (let* ((ct (gnus-fetch-field "content-type"))
1628 (mail-header-parse-content-type ct)))))
1629 (setq charset (and ctl
1630 (mail-content-type-get ctl 'charset)))
1631 (if (stringp charset)
1632 (setq charset (intern (downcase charset)))))))
1634 (setq charset gnus-newsgroup-charset))
1636 (save-window-excursion
1638 (narrow-to-region (point) (point-max))
1640 (let ((w3-strict-width (window-width))
1641 (url-standalone-mode t))
1643 (w3-region (point-min) (point-max))
1646 (defun article-hide-list-identifiers ()
1647 "Remove list identifies from the Subject header.
1648 The `gnus-list-identifiers' variable specifies what to do."
1652 (let ((inhibit-point-motion-hooks t)
1654 (article-narrow-to-head)
1655 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1656 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1658 (goto-char (point-min))
1659 (when (re-search-forward
1660 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1661 " *\\)\\)+\\(Re: +\\)?\\)")
1663 (let ((s (or (match-string 3) (match-string 5))))
1664 (delete-region (match-beginning 1) (match-end 1))
1666 (goto-char (match-beginning 1))
1669 (defun article-hide-pgp ()
1670 "Remove any PGP headers and signatures in the current article."
1674 (let ((inhibit-point-motion-hooks t)
1675 buffer-read-only beg end)
1677 ;; Hide the "header".
1678 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1679 (push 'pgp gnus-article-wash-types)
1680 (delete-region (match-beginning 0) (match-end 0))
1681 ;; Remove armor headers (rfc2440 6.2)
1682 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1685 ;; Hide the actual signature.
1686 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1687 (setq end (1+ (match-beginning 0)))
1690 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1692 ;; Perhaps we shouldn't hide to the end of the buffer
1693 ;; if there is no end to the signature?
1695 ;; Hide "- " PGP quotation markers.
1697 (narrow-to-region beg end)
1698 (goto-char (point-min))
1699 (while (re-search-forward "^- " nil t)
1701 (match-beginning 0) (match-end 0)))
1703 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1705 (defun article-hide-pem (&optional arg)
1706 "Toggle hiding of any PEM headers and signatures in the current article.
1707 If given a negative prefix, always show; if given a positive prefix,
1709 (interactive (gnus-article-hidden-arg))
1710 (unless (gnus-article-check-hidden-text 'pem arg)
1712 (let (buffer-read-only end)
1713 (goto-char (point-min))
1714 ;; Hide the horrendously ugly "header".
1715 (when (and (search-forward
1716 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1718 (setq end (1+ (match-beginning 0))))
1719 (push 'pem gnus-article-wash-types)
1720 (gnus-article-hide-text-type
1722 (if (search-forward "\n\n" nil t)
1726 ;; Hide the trailer as well
1727 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1729 (gnus-article-hide-text-type
1730 (match-beginning 0) (match-end 0) 'pem)))))))
1732 (defun article-strip-banner ()
1733 "Strip the banner specified by the `banner' group parameter."
1737 (let ((inhibit-point-motion-hooks t)
1738 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1739 (gnus-signature-limit nil)
1740 buffer-read-only beg end)
1744 ((eq banner 'signature)
1745 (when (gnus-article-narrow-to-signature)
1748 (delete-region (point) (point-max))))
1750 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1751 (while (re-search-forward banner nil t)
1752 (delete-region (match-beginning 0) (match-end 0)))))
1754 (while (re-search-forward banner nil t)
1755 (delete-region (match-beginning 0) (match-end 0))))))))))
1757 (defun article-babel ()
1758 "Translate article using an online translation service."
1762 (set-buffer gnus-article-buffer)
1763 (when (article-goto-body)
1764 (let* ((buffer-read-only nil)
1767 (orig (buffer-substring start end))
1768 (trans (babel-as-string orig)))
1770 (narrow-to-region start end)
1771 (delete-region start end)
1774 (defun article-hide-signature (&optional arg)
1775 "Hide the signature in the current article.
1776 If given a negative prefix, always show; if given a positive prefix,
1778 (interactive (gnus-article-hidden-arg))
1779 (unless (gnus-article-check-hidden-text 'signature arg)
1782 (let ((buffer-read-only nil))
1783 (when (gnus-article-narrow-to-signature)
1784 (gnus-article-hide-text-type
1785 (point-min) (point-max) 'signature)))))))
1787 (defun article-strip-headers-in-body ()
1788 "Strip offensive headers from bodies."
1792 (let ((case-fold-search t))
1793 (when (looking-at "x-no-archive:")
1794 (gnus-delete-line)))))
1796 (defun article-strip-leading-blank-lines ()
1797 "Remove all blank lines from the beginning of the article."
1800 (let ((inhibit-point-motion-hooks t)
1802 (when (article-goto-body)
1803 (while (and (not (eobp))
1804 (looking-at "[ \t]*$"))
1805 (gnus-delete-line))))))
1807 (defun article-narrow-to-head ()
1808 "Narrow the buffer to the head of the message.
1809 Point is left at the beginning of the narrowed-to region."
1811 (goto-char (point-min))
1812 (if (search-forward "\n\n" nil 1)
1815 (goto-char (point-min)))
1817 (defun article-goto-body ()
1818 "Place point at the start of the body."
1819 (goto-char (point-min))
1821 ;; This variable is only bound when dealing with separate
1823 (article-goto-body-goes-to-point-min-p
1825 ((search-forward "\n\n" nil t)
1828 (goto-char (point-max))
1831 (defun article-strip-multiple-blank-lines ()
1832 "Replace consecutive blank lines with one empty line."
1835 (let ((inhibit-point-motion-hooks t)
1837 ;; First make all blank lines empty.
1839 (while (re-search-forward "^[ \t]+$" nil t)
1840 (unless (gnus-annotation-in-region-p
1841 (match-beginning 0) (match-end 0))
1842 (replace-match "" nil t)))
1843 ;; Then replace multiple empty lines with a single empty line.
1845 (while (re-search-forward "\n\n\n+" nil t)
1846 (unless (gnus-annotation-in-region-p
1847 (match-beginning 0) (match-end 0))
1848 (replace-match "\n\n" t t))))))
1850 (defun article-strip-leading-space ()
1851 "Remove all white space from the beginning of the lines in the article."
1854 (let ((inhibit-point-motion-hooks t)
1857 (while (re-search-forward "^[ \t]+" nil t)
1858 (replace-match "" t t)))))
1860 (defun article-strip-trailing-space ()
1861 "Remove all white space from the end of the lines in the article."
1864 (let ((inhibit-point-motion-hooks t)
1867 (while (re-search-forward "[ \t]+$" nil t)
1868 (replace-match "" t t)))))
1870 (defun article-strip-blank-lines ()
1871 "Strip leading, trailing and multiple blank lines."
1873 (article-strip-leading-blank-lines)
1874 (article-remove-trailing-blank-lines)
1875 (article-strip-multiple-blank-lines))
1877 (defun article-strip-all-blank-lines ()
1878 "Strip all blank lines."
1881 (let ((inhibit-point-motion-hooks t)
1884 (while (re-search-forward "^[ \t]*\n" nil t)
1885 (replace-match "" t t)))))
1887 (defun gnus-article-narrow-to-signature ()
1888 "Narrow to the signature; return t if a signature is found, else nil."
1889 (let ((inhibit-point-motion-hooks t))
1890 (when (gnus-article-search-signature)
1892 ;; Check whether we have some limits to what we consider
1893 ;; to be a signature.
1894 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1895 (list gnus-signature-limit)))
1897 (while (setq limit (pop limits))
1898 (if (or (and (integerp limit)
1899 (< (- (point-max) (point)) limit))
1901 (< (count-lines (point) (point-max)) limit))
1902 (and (gnus-functionp limit)
1904 (and (stringp limit)
1905 (not (re-search-forward limit nil t))))
1906 () ; This limit did not succeed.
1910 (narrow-to-region (point) (point-max))
1913 (defun gnus-article-search-signature ()
1914 "Search the current buffer for the signature separator.
1915 Put point at the beginning of the signature separator."
1916 (let ((cur (point)))
1917 (goto-char (point-max))
1918 (if (if (stringp gnus-signature-separator)
1919 (re-search-backward gnus-signature-separator nil t)
1920 (let ((seps gnus-signature-separator))
1922 (not (re-search-backward (car seps) nil t)))
1929 (defun gnus-article-hidden-arg ()
1930 "Return the current prefix arg as a number, or 0 if no prefix."
1931 (list (if current-prefix-arg
1932 (prefix-numeric-value current-prefix-arg)
1935 (defun gnus-article-check-hidden-text (type arg)
1936 "Return nil if hiding is necessary.
1937 Arg can be nil or a number. Nil and positive means hide, negative
1938 means show, 0 means toggle."
1941 (let ((hide (gnus-article-hidden-text-p type)))
1947 (gnus-article-show-hidden-text type))
1949 (if (eq hide 'hidden)
1950 (gnus-article-show-hidden-text type)
1953 (defun gnus-article-hidden-text-p (type)
1954 "Say whether the current buffer contains hidden text of type TYPE."
1955 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1957 (not (get-text-property pos 'invisible))
1958 (not (get-text-property pos 'dummy-invisible)))
1960 (text-property-any (1+ pos) (point-max) 'article-type type)))
1965 (defun gnus-article-show-hidden-text (type &optional hide)
1966 "Show all hidden text of type TYPE.
1967 If HIDE, hide the text instead."
1969 (let ((buffer-read-only nil)
1970 (inhibit-point-motion-hooks t)
1973 (while (setq beg (text-property-any end (point-max) 'article-type type))
1976 (text-property-not-all beg (point-max) 'article-type type)
1979 (gnus-article-hide-text beg end gnus-hidden-properties)
1980 (gnus-article-unhide-text beg end))
1984 (defconst article-time-units
1985 `((year . ,(* 365.25 24 60 60))
1986 (week . ,(* 7 24 60 60))
1987 (day . ,(* 24 60 60))
1991 "Mapping from time units to seconds.")
1993 (defun article-date-ut (&optional type highlight header)
1994 "Convert DATE date to universal time in the current article.
1995 If TYPE is `local', convert to local time; if it is `lapsed', output
1996 how much time has lapsed since DATE. For `lapsed', the value of
1997 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1998 should replace the \"Date:\" one, or should be added below it."
1999 (interactive (list 'ut t))
2000 (let* ((header (or header
2001 (message-fetch-field "date")
2003 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2006 ((not gnus-article-date-lapsed-new-header)
2012 (date (if (vectorp header) (mail-header-date header)
2014 (inhibit-point-motion-hooks t)
2019 (article-narrow-to-head)
2020 (when (re-search-forward tdate-regexp nil t)
2021 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2022 date (or (get-text-property (gnus-point-at-bol)
2025 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2027 (when (and date (not (string= date "")))
2028 (goto-char (point-min))
2029 (let ((buffer-read-only nil))
2030 ;; Delete any old Date headers.
2031 (while (re-search-forward date-regexp nil t)
2033 (delete-region (progn (beginning-of-line) (point))
2034 (progn (forward-line 1) (point)))
2035 (delete-region (progn (beginning-of-line) (point))
2036 (progn (end-of-line) (point)))
2037 (setq pos (point))))
2038 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2040 (if pos (goto-char pos))
2041 (insert (article-make-date-line date (or type 'ut)))
2047 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2048 (put-text-property (match-beginning 1) (1+ (match-end 1))
2049 'original-date date)
2050 (put-text-property (match-beginning 1) (1+ (match-end 1))
2052 (put-text-property (match-beginning 2) (match-end 2)
2055 (defun article-make-date-line (date type)
2056 "Return a DATE line of TYPE."
2057 (let ((time (condition-case ()
2061 ;; Convert to the local timezone. We have to slap a
2062 ;; `condition-case' round the calls to the timezone
2063 ;; functions since they aren't particularly resistant to
2066 (let ((tz (car (current-time-zone time))))
2067 (format "Date: %s %s%02d%02d" (current-time-string time)
2068 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2069 (/ (% (abs tz) 3600) 60))))
2070 ;; Convert to Universal Time.
2073 (current-time-string
2074 (let* ((e (parse-time-string date))
2075 (tm (apply 'encode-time e))
2077 (ls (- (cadr tm) (car (current-time-zone time)))))
2078 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2079 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2082 ;; Get the original date from the article.
2083 ((eq type 'original)
2084 (concat "Date: " (if (string-match "\n+$" date)
2085 (substring date 0 (match-beginning 0))
2087 ;; Let the user define the format.
2089 (if (gnus-functionp gnus-article-time-format)
2090 (funcall gnus-article-time-format time)
2093 (format-time-string gnus-article-time-format time))))
2096 (let ((tz (car (current-time-zone time))))
2099 (format-time-string "%Y%m%dT%H%M%S" time)
2100 (format "%s%02d%02d"
2101 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2102 (/ (% (abs tz) 3600) 60)))))
2103 ;; Do an X-Sent lapsed format.
2105 ;; If the date is seriously mangled, the timezone functions are
2106 ;; liable to bug out, so we ignore all errors.
2107 (let* ((now (current-time))
2108 (real-time (subtract-time now time))
2109 (real-sec (and real-time
2110 (+ (* (float (car real-time)) 65536)
2112 (sec (and real-time (abs real-sec)))
2122 ;; This is a bit convoluted, but basically we go
2123 ;; through the time units for years, weeks, etc,
2124 ;; and divide things to see whether that results
2125 ;; in positive answers.
2128 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2129 ;; The (remaining) seconds are too few to
2130 ;; be divided into this time unit.
2132 ;; It's big enough, so we output it.
2133 (setq sec (- sec (* num (cdr unit))))
2135 (concat (if prev ", " "") (int-to-string
2137 " " (symbol-name (car unit))
2138 (if (> num 1) "s" ""))
2140 article-time-units "")
2141 ;; If dates are odd, then it might appear like the
2142 ;; article was sent in the future.
2145 " in the future"))))))
2147 (error "Unknown conversion type: %s" type)))))
2149 (defun article-date-local (&optional highlight)
2150 "Convert the current article date to the local timezone."
2151 (interactive (list t))
2152 (article-date-ut 'local highlight))
2154 (defun article-date-original (&optional highlight)
2155 "Convert the current article date to what it was originally.
2156 This is only useful if you have used some other date conversion
2157 function and want to see what the date was before converting."
2158 (interactive (list t))
2159 (article-date-ut 'original highlight))
2161 (defun article-date-lapsed (&optional highlight)
2162 "Convert the current article date to time lapsed since it was sent."
2163 (interactive (list t))
2164 (article-date-ut 'lapsed highlight))
2166 (defun article-update-date-lapsed ()
2167 "Function to be run from a timer to update the lapsed time line."
2168 (let (deactivate-mark)
2173 (set-buffer (window-buffer w))
2174 (when (eq major-mode 'gnus-article-mode)
2175 (goto-char (point-min))
2176 (when (re-search-forward "^X-Sent:" nil t)
2177 (article-date-lapsed t))))
2180 (defun gnus-start-date-timer (&optional n)
2181 "Start a timer to update the X-Sent header in the article buffers.
2182 The numerical prefix says how frequently (in seconds) the function
2187 (gnus-stop-date-timer)
2188 (setq article-lapsed-timer
2189 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2191 (defun gnus-stop-date-timer ()
2192 "Stop the X-Sent timer."
2194 (when article-lapsed-timer
2195 (nnheader-cancel-timer article-lapsed-timer)
2196 (setq article-lapsed-timer nil)))
2198 (defun article-date-user (&optional highlight)
2199 "Convert the current article date to the user-defined format.
2200 This format is defined by the `gnus-article-time-format' variable."
2201 (interactive (list t))
2202 (article-date-ut 'user highlight))
2204 (defun article-date-iso8601 (&optional highlight)
2205 "Convert the current article date to ISO8601."
2206 (interactive (list t))
2207 (article-date-ut 'iso8601 highlight))
2209 (defun article-show-all ()
2210 "Show all hidden text in the article buffer."
2213 (let ((buffer-read-only nil))
2214 (gnus-article-unhide-text (point-min) (point-max)))))
2216 (defun article-emphasize (&optional arg)
2217 "Emphasize text according to `gnus-emphasis-alist'."
2218 (interactive (gnus-article-hidden-arg))
2219 (unless (gnus-article-check-hidden-text 'emphasis arg)
2223 (with-current-buffer gnus-summary-buffer
2224 gnus-article-emphasis-alist)
2226 gnus-emphasis-alist))
2227 (buffer-read-only nil)
2228 (props (append '(article-type emphasis)
2229 gnus-hidden-properties))
2230 regexp elem beg invisible visible face)
2233 (while (setq elem (pop alist))
2235 (setq regexp (car elem)
2236 invisible (nth 1 elem)
2237 visible (nth 2 elem)
2239 (while (re-search-forward regexp nil t)
2240 (when (and (match-beginning visible) (match-beginning invisible))
2241 (push 'emphasis gnus-article-wash-types)
2242 (gnus-article-hide-text
2243 (match-beginning invisible) (match-end invisible) props)
2244 (gnus-article-unhide-text-type
2245 (match-beginning visible) (match-end visible) 'emphasis)
2246 (gnus-put-text-property-excluding-newlines
2247 (match-beginning visible) (match-end visible) 'face face)
2248 (goto-char (match-end invisible)))))))))
2250 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2251 "Setup newsgroup emphasis alist."
2252 (unless gnus-article-emphasis-alist
2253 (let ((name (and gnus-newsgroup-name
2254 (gnus-group-real-name gnus-newsgroup-name))))
2255 (make-local-variable 'gnus-article-emphasis-alist)
2256 (setq gnus-article-emphasis-alist
2258 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2259 (while (setq elem (pop alist))
2260 (when (and name (string-match (car elem) name))
2262 highlight (copy-sequence (cdr elem)))))
2264 (copy-sequence highlight-words)
2265 (if gnus-newsgroup-name
2266 (copy-sequence (gnus-group-find-parameter
2267 gnus-newsgroup-name 'highlight-words t)))
2268 gnus-emphasis-alist)))))
2270 (defvar gnus-summary-article-menu)
2271 (defvar gnus-summary-post-menu)
2273 ;;; Saving functions.
2275 (defun gnus-article-save (save-buffer file &optional num)
2276 "Save the currently selected article."
2277 (unless gnus-save-all-headers
2278 ;; Remove headers according to `gnus-saved-headers'.
2279 (let ((gnus-visible-headers
2280 (or gnus-saved-headers gnus-visible-headers))
2281 (gnus-article-buffer save-buffer))
2283 (set-buffer save-buffer)
2284 (article-hide-headers 1 t))))
2285 (save-window-excursion
2286 (if (not gnus-default-article-saver)
2287 (error "No default saver is defined")
2288 ;; !!! Magic! The saving functions all save
2289 ;; `gnus-save-article-buffer' (or so they think), but we
2290 ;; bind that variable to our save-buffer.
2291 (set-buffer gnus-article-buffer)
2292 (let* ((gnus-save-article-buffer save-buffer)
2295 ((not gnus-prompt-before-saving) 'default)
2296 ((eq gnus-prompt-before-saving 'always) nil)
2298 (gnus-number-of-articles-to-be-saved
2299 (when (eq gnus-prompt-before-saving t)
2301 (set-buffer gnus-article-current-summary)
2302 (funcall gnus-default-article-saver filename)))))
2304 (defun gnus-read-save-file-name (prompt &optional filename
2305 function group headers variable)
2307 (funcall function group headers (symbol-value variable)))
2312 ((eq filename 'default)
2318 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2321 (if (and gnus-number-of-articles-to-be-saved
2322 (> gnus-number-of-articles-to-be-saved 1))
2323 (format "these %d articles"
2324 gnus-number-of-articles-to-be-saved)
2327 ;; Let the split methods have their say.
2329 ;; No split name was found.
2332 (concat prompt " (default "
2333 (file-name-nondirectory default-name) ") ")
2334 (file-name-directory default-name)
2336 ;; A single group name is returned.
2337 ((stringp split-name)
2339 (funcall function split-name headers
2340 (symbol-value variable)))
2342 (concat prompt " (default "
2343 (file-name-nondirectory default-name) ") ")
2344 (file-name-directory default-name)
2346 ;; A single split name was found
2347 ((= 1 (length split-name))
2348 (let* ((name (expand-file-name
2350 gnus-article-save-directory))
2351 (dir (cond ((file-directory-p name)
2352 (file-name-as-directory name))
2353 ((file-exists-p name) name)
2354 (t gnus-article-save-directory))))
2356 (concat prompt " (default " name ") ")
2358 ;; A list of splits was found.
2360 (setq split-name (nreverse split-name))
2362 (let ((file-name-history
2363 (nconc split-name file-name-history)))
2367 (concat prompt " (`M-p' for defaults) ")
2368 gnus-article-save-directory
2370 gnus-article-save-directory)))
2371 (car (push result file-name-history)))))))
2372 ;; Create the directory.
2373 (gnus-make-directory (file-name-directory file))
2374 ;; If we have read a directory, we append the default file name.
2375 (when (file-directory-p file)
2376 (setq file (expand-file-name (file-name-nondirectory
2378 (file-name-as-directory file))))
2379 ;; Possibly translate some characters.
2380 (nnheader-translate-file-chars file))))))
2381 (gnus-make-directory (file-name-directory result))
2382 (set variable result)))
2384 (defun gnus-article-archive-name (group)
2385 "Return the first instance of an \"Archive-name\" in the current buffer."
2386 (let ((case-fold-search t))
2387 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2388 (nnheader-concat gnus-article-save-directory
2389 (match-string 1)))))
2391 (defun gnus-article-nndoc-name (group)
2392 "If GROUP is an nndoc group, return the name of the parent group."
2393 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2394 (gnus-group-get-parameter group 'save-article-group)))
2396 (defun gnus-summary-save-in-rmail (&optional filename)
2397 "Append this article to Rmail file.
2398 Optional argument FILENAME specifies file name.
2399 Directory to save to is default to `gnus-article-save-directory'."
2400 (setq filename (gnus-read-save-file-name
2401 "Save %s in rmail file:" filename
2402 gnus-rmail-save-name gnus-newsgroup-name
2403 gnus-current-headers 'gnus-newsgroup-last-rmail))
2404 (gnus-eval-in-buffer-window gnus-save-article-buffer
2408 (gnus-output-to-rmail filename))))
2411 (defun gnus-summary-save-in-mail (&optional filename)
2412 "Append this article to Unix mail file.
2413 Optional argument FILENAME specifies file name.
2414 Directory to save to is default to `gnus-article-save-directory'."
2415 (setq filename (gnus-read-save-file-name
2416 "Save %s in Unix mail file:" filename
2417 gnus-mail-save-name gnus-newsgroup-name
2418 gnus-current-headers 'gnus-newsgroup-last-mail))
2419 (gnus-eval-in-buffer-window gnus-save-article-buffer
2423 (if (and (file-readable-p filename)
2424 (mail-file-babyl-p filename))
2425 (rmail-output-to-rmail-file filename t)
2426 (gnus-output-to-mail filename)))))
2429 (defun gnus-summary-save-in-file (&optional filename overwrite)
2430 "Append this article to file.
2431 Optional argument FILENAME specifies file name.
2432 Directory to save to is default to `gnus-article-save-directory'."
2433 (setq filename (gnus-read-save-file-name
2434 "Save %s in file:" filename
2435 gnus-file-save-name gnus-newsgroup-name
2436 gnus-current-headers 'gnus-newsgroup-last-file))
2437 (gnus-eval-in-buffer-window gnus-save-article-buffer
2441 (when (and overwrite
2442 (file-exists-p filename))
2443 (delete-file filename))
2444 (gnus-output-to-file filename))))
2447 (defun gnus-summary-write-to-file (&optional filename)
2448 "Write this article to a file.
2449 Optional argument FILENAME specifies file name.
2450 The directory to save in defaults to `gnus-article-save-directory'."
2451 (gnus-summary-save-in-file nil t))
2453 (defun gnus-summary-save-body-in-file (&optional filename)
2454 "Append this article body to a file.
2455 Optional argument FILENAME specifies file name.
2456 The directory to save in defaults to `gnus-article-save-directory'."
2457 (setq filename (gnus-read-save-file-name
2458 "Save %s body in file:" filename
2459 gnus-file-save-name gnus-newsgroup-name
2460 gnus-current-headers 'gnus-newsgroup-last-file))
2461 (gnus-eval-in-buffer-window gnus-save-article-buffer
2465 (when (article-goto-body)
2466 (narrow-to-region (point) (point-max)))
2467 (gnus-output-to-file filename))))
2470 (defun gnus-summary-save-in-pipe (&optional command)
2471 "Pipe this article to subprocess."
2473 (cond ((and (eq command 'default)
2474 gnus-last-shell-command)
2475 gnus-last-shell-command)
2479 "Shell command on %s: "
2480 (if (and gnus-number-of-articles-to-be-saved
2481 (> gnus-number-of-articles-to-be-saved 1))
2482 (format "these %d articles"
2483 gnus-number-of-articles-to-be-saved)
2485 gnus-last-shell-command))))
2486 (when (string-equal command "")
2487 (setq command gnus-last-shell-command))
2488 (gnus-eval-in-buffer-window gnus-article-buffer
2491 (shell-command-on-region (point-min) (point-max) command nil)))
2492 (setq gnus-last-shell-command command))
2494 ;;; Article file names when saving.
2496 (defun gnus-capitalize-newsgroup (newsgroup)
2497 "Capitalize NEWSGROUP name."
2498 (when (not (zerop (length newsgroup)))
2499 (concat (char-to-string (upcase (aref newsgroup 0)))
2500 (substring newsgroup 1))))
2502 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2503 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2504 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2505 Otherwise, it is like ~/News/news/group/num."
2508 (concat (if (gnus-use-long-file-name 'not-save)
2509 (gnus-capitalize-newsgroup newsgroup)
2510 (gnus-newsgroup-directory-form newsgroup))
2511 "/" (int-to-string (mail-header-number headers)))
2512 gnus-article-save-directory)))
2514 (string-equal (file-name-directory default)
2515 (file-name-directory last-file))
2516 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2518 (or last-file default))))
2520 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2521 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2522 If variable `gnus-use-long-file-name' is non-nil, it is
2523 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2526 (concat (if (gnus-use-long-file-name 'not-save)
2528 (gnus-newsgroup-directory-form newsgroup))
2529 "/" (int-to-string (mail-header-number headers)))
2530 gnus-article-save-directory)))
2532 (string-equal (file-name-directory default)
2533 (file-name-directory last-file))
2534 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2536 (or last-file default))))
2538 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2539 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2540 If variable `gnus-use-long-file-name' is non-nil, it is
2541 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2544 (if (gnus-use-long-file-name 'not-save)
2546 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2547 gnus-article-save-directory)))
2554 (setq afunc (car func)
2557 gfunc (intern (format "gnus-%s" func))))
2560 `(lambda (&optional interactive &rest args)
2561 ,(documentation afunc t)
2562 (interactive (list t))
2564 (set-buffer gnus-article-buffer)
2566 (call-interactively ',afunc)
2567 (apply ',afunc args))))))))
2568 '(article-hide-headers
2569 article-hide-boring-headers
2570 article-treat-overstrike
2571 article-fill-long-lines
2572 article-capitalize-sentences
2574 article-display-x-face
2575 article-de-quoted-unreadable
2576 article-de-base64-unreadable
2579 article-hide-list-identifiers
2581 article-strip-banner
2584 article-hide-signature
2585 article-strip-headers-in-body
2586 article-remove-trailing-blank-lines
2587 article-strip-leading-blank-lines
2588 article-strip-multiple-blank-lines
2589 article-strip-leading-space
2590 article-strip-trailing-space
2591 article-strip-blank-lines
2592 article-strip-all-blank-lines
2594 article-date-iso8601
2595 article-date-original
2597 article-decode-mime-words
2598 article-decode-charset
2599 article-decode-encoded-words
2603 article-treat-dumbquotes
2604 article-normalize-headers
2605 (article-show-all . gnus-article-show-all-headers))))
2608 ;;; Gnus article mode
2611 (put 'gnus-article-mode 'mode-class 'special)
2613 (set-keymap-parent gnus-article-mode-map widget-keymap)
2615 (gnus-define-keys gnus-article-mode-map
2616 " " gnus-article-goto-next-page
2617 "\177" gnus-article-goto-prev-page
2618 [delete] gnus-article-goto-prev-page
2619 [backspace] gnus-article-goto-prev-page
2620 "\C-c^" gnus-article-refer-article
2621 "h" gnus-article-show-summary
2622 "s" gnus-article-show-summary
2623 "\C-c\C-m" gnus-article-mail
2624 "?" gnus-article-describe-briefly
2625 "e" gnus-summary-edit-article
2626 "<" beginning-of-buffer
2628 "\C-c\C-i" gnus-info-find-node
2631 "\C-d" gnus-article-read-summary-keys
2632 "\M-*" gnus-article-read-summary-keys
2633 "\M-#" gnus-article-read-summary-keys
2634 "\M-^" gnus-article-read-summary-keys
2635 "\M-g" gnus-article-read-summary-keys)
2637 (substitute-key-definition
2638 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2640 (defun gnus-article-make-menu-bar ()
2641 (gnus-turn-off-edit-menu 'article)
2642 (unless (boundp 'gnus-article-article-menu)
2644 gnus-article-article-menu gnus-article-mode-map ""
2646 ["Scroll forwards" gnus-article-goto-next-page t]
2647 ["Scroll backwards" gnus-article-goto-prev-page t]
2648 ["Show summary" gnus-article-show-summary t]
2649 ["Fetch Message-ID at point" gnus-article-refer-article t]
2650 ["Mail to address at point" gnus-article-mail t]
2651 ["Send a bug report" gnus-bug t]))
2654 gnus-article-treatment-menu gnus-article-mode-map ""
2656 ["Hide headers" gnus-article-hide-headers t]
2657 ["Hide signature" gnus-article-hide-signature t]
2658 ["Hide citation" gnus-article-hide-citation t]
2659 ["Treat overstrike" gnus-article-treat-overstrike t]
2660 ["Remove carriage return" gnus-article-remove-cr t]
2661 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2662 ["Remove base64" gnus-article-de-base64-unreadable t]
2663 ["Treat html" gnus-article-wash-html t]
2664 ["Decode HZ" gnus-article-decode-HZ t]))
2666 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2668 (when (boundp 'gnus-summary-post-menu)
2669 (define-key gnus-article-mode-map [menu-bar post]
2670 (cons "Post" gnus-summary-post-menu)))
2672 (gnus-run-hooks 'gnus-article-menu-hook)))
2674 (defun gnus-article-mode ()
2675 "Major mode for displaying an article.
2677 All normal editing commands are switched off.
2679 The following commands are available in addition to all summary mode
2681 \\<gnus-article-mode-map>
2682 \\[gnus-article-next-page]\t Scroll the article one page forwards
2683 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2684 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2685 \\[gnus-article-show-summary]\t Display the summary buffer
2686 \\[gnus-article-mail]\t Send a reply to the address near point
2687 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2688 \\[gnus-info-find-node]\t Go to the Gnus info node"
2690 (when (gnus-visual-p 'article-menu 'menu)
2691 (gnus-article-make-menu-bar))
2692 (gnus-simplify-mode-line)
2693 (setq mode-name "Article")
2694 (setq major-mode 'gnus-article-mode)
2695 (make-local-variable 'minor-mode-alist)
2696 (use-local-map gnus-article-mode-map)
2697 (gnus-update-format-specifications nil 'article-mode)
2698 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2699 (make-local-variable 'gnus-page-broken)
2700 (make-local-variable 'gnus-button-marker-list)
2701 (make-local-variable 'gnus-article-current-summary)
2702 (make-local-variable 'gnus-article-mime-handles)
2703 (make-local-variable 'gnus-article-decoded-p)
2704 (make-local-variable 'gnus-article-mime-handle-alist)
2705 (make-local-variable 'gnus-article-wash-types)
2706 (make-local-variable 'gnus-article-charset)
2707 (make-local-variable 'gnus-article-ignored-charsets)
2708 (gnus-set-default-directory)
2709 (buffer-disable-undo)
2710 (setq buffer-read-only t)
2711 (set-syntax-table gnus-article-mode-syntax-table)
2712 (mm-enable-multibyte)
2713 (gnus-run-hooks 'gnus-article-mode-hook))
2715 (defun gnus-article-setup-buffer ()
2716 "Initialize the article buffer."
2717 (let* ((name (if gnus-single-article-buffer "*Article*"
2718 (concat "*Article " gnus-newsgroup-name "*")))
2720 (progn (string-match "\\*Article" name)
2721 (concat " *Original Article"
2722 (substring name (match-end 0))))))
2723 (setq gnus-article-buffer name)
2724 (setq gnus-original-article-buffer original)
2725 (setq gnus-article-mime-handle-alist nil)
2726 ;; This might be a variable local to the summary buffer.
2727 (unless gnus-single-article-buffer
2729 (set-buffer gnus-summary-buffer)
2730 (setq gnus-article-buffer name)
2731 (setq gnus-original-article-buffer original)
2732 (gnus-set-global-variables)))
2733 (gnus-article-setup-highlight-words)
2734 ;; Init original article buffer.
2736 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2737 (mm-enable-multibyte)
2738 (setq major-mode 'gnus-original-article-mode)
2739 (make-local-variable 'gnus-original-article))
2740 (if (get-buffer name)
2743 (when gnus-article-mime-handles
2744 (mm-destroy-parts gnus-article-mime-handles)
2745 (setq gnus-article-mime-handles nil))
2746 ;; Set it to nil in article-buffer!
2747 (setq gnus-article-mime-handle-alist nil)
2748 (buffer-disable-undo)
2749 (setq buffer-read-only t)
2750 (unless (eq major-mode 'gnus-article-mode)
2751 (gnus-article-mode))
2754 (set-buffer (gnus-get-buffer-create name))
2756 (make-local-variable 'gnus-summary-buffer)
2757 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2758 (current-buffer)))))
2760 ;; Set article window start at LINE, where LINE is the number of lines
2761 ;; from the head of the article.
2762 (defun gnus-article-set-window-start (&optional line)
2764 (get-buffer-window gnus-article-buffer t)
2766 (set-buffer gnus-article-buffer)
2767 (goto-char (point-min))
2770 (gnus-message 6 "Moved to bookmark")
2771 (search-forward "\n\n" nil t)
2775 (defun gnus-article-prepare (article &optional all-headers header)
2776 "Prepare ARTICLE in article mode buffer.
2777 ARTICLE should either be an article number or a Message-ID.
2778 If ARTICLE is an id, HEADER should be the article headers.
2779 If ALL-HEADERS is non-nil, no headers are hidden."
2781 ;; Make sure we start in a summary buffer.
2782 (unless (eq major-mode 'gnus-summary-mode)
2783 (set-buffer gnus-summary-buffer))
2784 (setq gnus-summary-buffer (current-buffer))
2785 (let* ((gnus-article (if header (mail-header-number header) article))
2786 (summary-buffer (current-buffer))
2787 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2788 (group gnus-newsgroup-name)
2791 (gnus-article-setup-buffer)
2792 (set-buffer gnus-article-buffer)
2793 ;; Deactivate active regions.
2794 (when (and (boundp 'transient-mark-mode)
2795 transient-mark-mode)
2796 (setq mark-active nil))
2797 (if (not (setq result (let ((buffer-read-only nil))
2798 (gnus-request-article-this-buffer
2800 ;; There is no such article.
2802 (when (and (numberp article)
2803 (not (memq article gnus-newsgroup-sparse)))
2804 (setq gnus-article-current
2805 (cons gnus-newsgroup-name article))
2806 (set-buffer gnus-summary-buffer)
2807 (setq gnus-current-article article)
2808 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2810 (gnus-summary-set-agent-mark article)
2811 (message "Message marked for downloading"))
2812 (gnus-summary-mark-article article gnus-canceled-mark)
2813 (unless (memq article gnus-newsgroup-sparse)
2814 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2815 (if (or (eq result 'pseudo)
2816 (eq result 'nneething))
2819 (set-buffer summary-buffer)
2820 (push article gnus-newsgroup-history)
2821 (setq gnus-last-article gnus-current-article
2822 gnus-current-article 0
2823 gnus-current-headers nil
2824 gnus-article-current nil)
2825 (if (eq result 'nneething)
2826 (gnus-configure-windows 'summary)
2827 (gnus-configure-windows 'article))
2828 (gnus-set-global-variables))
2829 (let ((gnus-article-mime-handle-alist-1
2830 gnus-article-mime-handle-alist))
2831 (gnus-set-mode-line 'article)))
2832 ;; The result from the `request' was an actual article -
2833 ;; or at least some text that is now displayed in the
2835 (when (and (numberp article)
2836 (not (eq article gnus-current-article)))
2837 ;; Seems like a new article has been selected.
2838 ;; `gnus-current-article' must be an article number.
2840 (set-buffer summary-buffer)
2841 (push article gnus-newsgroup-history)
2842 (setq gnus-last-article gnus-current-article
2843 gnus-current-article article
2844 gnus-current-headers
2845 (gnus-summary-article-header gnus-current-article)
2846 gnus-article-current
2847 (cons gnus-newsgroup-name gnus-current-article))
2848 (unless (vectorp gnus-current-headers)
2849 (setq gnus-current-headers nil))
2850 (gnus-summary-goto-subject gnus-current-article)
2851 (when (gnus-summary-show-thread)
2852 ;; If the summary buffer really was folded, the
2853 ;; previous goto may not actually have gone to
2854 ;; the right article, but the thread root instead.
2856 (gnus-summary-goto-subject gnus-current-article))
2857 (gnus-run-hooks 'gnus-mark-article-hook)
2858 (gnus-set-mode-line 'summary)
2859 (when (gnus-visual-p 'article-highlight 'highlight)
2860 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2861 ;; Set the global newsgroup variables here.
2862 (gnus-set-global-variables)
2863 (setq gnus-have-all-headers
2864 (or all-headers gnus-show-all-headers))))
2866 (gnus-configure-windows 'article))
2867 (when (or (numberp article)
2869 (gnus-article-prepare-display)
2871 (goto-char (point-min))
2872 (setq gnus-page-broken
2873 (when gnus-break-pages
2874 (gnus-narrow-to-page)
2876 (let ((gnus-article-mime-handle-alist-1
2877 gnus-article-mime-handle-alist))
2878 (gnus-set-mode-line 'article))
2880 (set-window-point (get-buffer-window (current-buffer)) (point))
2881 (gnus-configure-windows 'article)
2885 (defun gnus-article-prepare-display ()
2886 "Make the current buffer look like a nice article."
2887 ;; Hooks for getting information from the article.
2888 ;; This hook must be called before being narrowed.
2889 (let ((gnus-article-buffer (current-buffer))
2891 (unless (eq major-mode 'gnus-article-mode)
2892 (gnus-article-mode))
2893 (setq buffer-read-only nil
2894 gnus-article-wash-types nil)
2895 (gnus-run-hooks 'gnus-tmp-internal-hook)
2896 (when gnus-display-mime-function
2897 (funcall gnus-display-mime-function))
2898 (gnus-run-hooks 'gnus-article-prepare-hook)))
2901 ;;; Gnus MIME viewing functions
2904 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2905 "The following specs can be used:
2907 %T MIME type, along with additional info
2908 %n The `name' parameter
2909 %d The description, if any
2910 %l The length of the encoded part
2911 %p The part identifier number
2912 %e Dots if the part isn't displayed")
2914 (defvar gnus-mime-button-line-format-alist
2915 '((?t gnus-tmp-type ?s)
2916 (?T gnus-tmp-type-long ?s)
2917 (?n gnus-tmp-name ?s)
2918 (?d gnus-tmp-description ?s)
2920 (?l gnus-tmp-length ?d)
2921 (?e gnus-tmp-dots ?s)))
2923 (defvar gnus-mime-button-commands
2924 '((gnus-article-press-button "\r" "Toggle Display")
2925 (gnus-mime-view-part "v" "View Interactively...")
2926 (gnus-mime-view-part-as-type "t" "View As Type...")
2927 (gnus-mime-view-part-as-charset "C" "View As charset...")
2928 (gnus-mime-save-part "o" "Save...")
2929 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
2930 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2931 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2932 (gnus-mime-internalize-part "E" "View Internally")
2933 (gnus-mime-externalize-part "e" "View Externally")
2934 (gnus-mime-pipe-part "|" "Pipe To Command...")
2935 (gnus-mime-action-on-part "." "Take action on the part")))
2937 (defun gnus-article-mime-part-status ()
2938 (if gnus-article-mime-handle-alist-1
2939 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2942 (defvar gnus-mime-button-map
2943 (let ((map (make-sparse-keymap)))
2944 (set-keymap-parent map gnus-article-mode-map)
2945 (define-key map gnus-mouse-2 'gnus-article-push-button)
2946 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2947 (dolist (c gnus-mime-button-commands)
2948 (define-key map (cadr c) (car c)))
2951 (defun gnus-mime-button-menu (event)
2952 "Construct a context-sensitive menu of MIME commands."
2955 (let ((pos (event-start event)))
2956 (set-buffer (window-buffer (posn-window pos)))
2957 (goto-char (posn-point pos))
2958 (gnus-article-check-buffer)
2959 (let ((response (x-popup-menu
2961 ("" ,@(mapcar (lambda (c)
2962 (cons (caddr c) (car c)))
2963 gnus-mime-button-commands))))))
2965 (call-interactively response))))))
2967 (defun gnus-mime-view-all-parts (&optional handles)
2968 "View all the MIME parts."
2970 (save-current-buffer
2971 (set-buffer gnus-article-buffer)
2972 (let ((handles (or handles gnus-article-mime-handles))
2973 (mail-parse-charset gnus-newsgroup-charset)
2974 (mail-parse-ignored-charsets
2975 (save-excursion (set-buffer gnus-summary-buffer)
2976 gnus-newsgroup-ignored-charsets)))
2977 (if (stringp (car handles))
2978 (gnus-mime-view-all-parts (cdr handles))
2979 (mapcar 'mm-display-part handles)))))
2981 (defun gnus-mime-save-part-and-strip ()
2982 "Save the MIME part under point then replace it with an external body."
2984 (gnus-article-check-buffer)
2985 (let* ((data (get-text-property (point) 'gnus-data))
2986 (file (mm-save-part data))
2989 (with-current-buffer (mm-handle-buffer data)
2991 (insert "Content-Type: " (mm-handle-media-type data))
2992 (mml-insert-parameter-string (cdr (mm-handle-type data))
2995 (insert "Content-ID: " (message-make-message-id) "\n")
2996 (insert "Content-Transfer-Encoding: binary\n")
2999 (cdr (mm-make-handle nil
3000 `("message/external-body"
3001 (access-type . "LOCAL-FILE")
3003 (set-buffer gnus-summary-buffer)
3004 (gnus-article-edit-article
3007 (let ((mail-parse-charset (or gnus-article-charset
3008 ',gnus-newsgroup-charset))
3009 (mail-parse-ignored-charsets
3010 (or gnus-article-ignored-charsets
3011 ',gnus-newsgroup-ignored-charsets))
3012 (mbl mml-buffer-list))
3013 (insert-buffer gnus-original-article-buffer)
3015 (message-narrow-to-head)
3016 (message-remove-header "Content-Type")
3017 (message-remove-header "MIME-Version")
3018 (message-remove-header "Content-Transfer-Encoding")
3019 (mail-decode-encoded-word-region (point-min) (point-max))
3020 (goto-char (point-max)))
3022 (delete-region (point) (point-max))
3023 (setq mml-buffer-list nil)
3024 (if (stringp (car gnus-article-mime-handles))
3025 (mml-insert-mime gnus-article-mime-handles)
3026 (mml-insert-mime gnus-article-mime-handles t))
3027 (mm-destroy-parts gnus-article-mime-handles)
3028 (setq gnus-article-mime-handles nil)
3029 (make-local-hook 'kill-buffer-hook)
3030 (let ((mbl1 mml-buffer-list))
3031 (setq mml-buffer-list mbl)
3032 (set (make-local-variable 'mml-buffer-list) mbl1))
3033 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3034 `(lambda (no-highlight)
3035 (let ((mail-parse-charset (or gnus-article-charset
3036 ',gnus-newsgroup-charset))
3037 (message-options message-options)
3038 (message-options-set-recipient)
3039 (mail-parse-ignored-charsets
3040 (or gnus-article-ignored-charsets
3041 ',gnus-newsgroup-ignored-charsets)))
3043 (mml-destroy-buffers)
3044 (remove-hook 'kill-buffer-hook
3045 'mml-destroy-buffers t)
3046 (kill-local-variable 'mml-buffer-list))
3047 (gnus-summary-edit-article-done
3048 ,(or (mail-header-references gnus-current-headers) "")
3049 ,(gnus-group-read-only-p)
3050 ,gnus-summary-buffer no-highlight))))))
3052 (defun gnus-mime-save-part ()
3053 "Save the MIME part under point."
3055 (gnus-article-check-buffer)
3056 (let ((data (get-text-property (point) 'gnus-data)))
3057 (mm-save-part data)))
3059 (defun gnus-mime-pipe-part ()
3060 "Pipe the MIME part under point to a process."
3062 (gnus-article-check-buffer)
3063 (let ((data (get-text-property (point) 'gnus-data)))
3064 (mm-pipe-part data)))
3066 (defun gnus-mime-view-part ()
3067 "Interactively choose a viewing method for the MIME part under point."
3069 (gnus-article-check-buffer)
3070 (let ((data (get-text-property (point) 'gnus-data)))
3071 (mm-interactively-view-part data)))
3073 (defun gnus-mime-view-part-as-type-internal ()
3074 (gnus-article-check-buffer)
3075 (let* ((name (mail-content-type-get
3076 (mm-handle-type (get-text-property (point) 'gnus-data))
3078 (def-type (and name (mm-default-file-encoding name))))
3079 (and def-type (cons def-type 0))))
3081 (defun gnus-mime-view-part-as-type (mime-type)
3082 "Choose a MIME media type, and view the part as such."
3084 (list (completing-read
3085 "View as MIME type: "
3086 (mapcar #'list (mailcap-mime-types))
3088 (gnus-mime-view-part-as-type-internal))))
3089 (gnus-article-check-buffer)
3090 (let ((handle (get-text-property (point) 'gnus-data)))
3091 (gnus-mm-display-part
3092 (mm-make-handle (mm-handle-buffer handle)
3093 (cons mime-type (cdr (mm-handle-type handle)))
3094 (mm-handle-encoding handle)
3095 (mm-handle-undisplayer handle)
3096 (mm-handle-disposition handle)
3097 (mm-handle-description handle)
3098 (mm-handle-cache handle)
3099 (mm-handle-id handle)))))
3101 (defun gnus-mime-copy-part (&optional handle)
3102 "Put the the MIME part under point into a new buffer."
3104 (gnus-article-check-buffer)
3105 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3106 (contents (mm-get-part handle))|
3107 (base (file-name-nondirectory
3109 (mail-content-type-get (mm-handle-type handle) 'name)
3110 (mail-content-type-get (mm-handle-type handle)
3113 (buffer (generate-new-buffer base)))
3114 (switch-to-buffer buffer)
3116 ;; We do it this way to make `normal-mode' set the appropriate mode.
3119 (setq buffer-file-name (expand-file-name base))
3121 (setq buffer-file-name nil))
3122 (goto-char (point-min))))
3124 (defun gnus-mime-inline-part (&optional handle arg)
3125 "Insert the MIME part under point into the current buffer."
3126 (interactive (list nil current-prefix-arg))
3127 (gnus-article-check-buffer)
3128 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3132 (if (and (not arg) (mm-handle-undisplayer handle))
3133 (mm-remove-part handle)
3134 (setq contents (mm-get-part handle))
3137 (setq charset (or (mail-content-type-get
3138 (mm-handle-type handle) 'charset)
3139 gnus-newsgroup-charset)))
3141 (if (mm-handle-undisplayer handle)
3142 (mm-remove-part handle))
3145 gnus-summary-show-article-charset-alist))
3146 (read-coding-system "Charset: ")))))
3148 (mm-insert-inline handle
3150 (setq charset (mm-charset-to-coding-system
3152 (not (eq charset 'ascii)))
3153 (mm-decode-coding-string contents charset)
3157 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3158 "Insert the MIME part under point into the current buffer."
3159 (interactive (list nil current-prefix-arg))
3160 (gnus-article-check-buffer)
3161 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3165 (if (mm-handle-undisplayer handle)
3166 (mm-remove-part handle))
3167 (let ((gnus-newsgroup-charset
3169 gnus-summary-show-article-charset-alist))
3170 (read-coding-system "Charset: ")))
3171 (gnus-newsgroup-ignored-charsets 'gnus-all))
3172 (gnus-article-press-button))))
3174 (defun gnus-mime-externalize-part (&optional handle)
3175 "View the MIME part under point with an external viewer."
3177 (gnus-article-check-buffer)
3178 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3179 (mm-user-display-methods nil)
3180 (mm-inlined-types nil)
3181 (mail-parse-charset gnus-newsgroup-charset)
3182 (mail-parse-ignored-charsets
3183 (save-excursion (set-buffer gnus-summary-buffer)
3184 gnus-newsgroup-ignored-charsets)))
3185 (if (mm-handle-undisplayer handle)
3186 (mm-remove-part handle)
3187 (mm-display-part handle))))
3189 (defun gnus-mime-internalize-part (&optional handle)
3190 "View the MIME part under point with an internal viewer.
3191 In no internal viewer is available, use an external viewer."
3193 (gnus-article-check-buffer)
3194 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3195 (mm-inlined-types '(".*"))
3196 (mm-inline-large-images t)
3197 (mail-parse-charset gnus-newsgroup-charset)
3198 (mail-parse-ignored-charsets
3199 (save-excursion (set-buffer gnus-summary-buffer)
3200 gnus-newsgroup-ignored-charsets)))
3201 (if (mm-handle-undisplayer handle)
3202 (mm-remove-part handle)
3203 (mm-display-part handle))))
3205 (defun gnus-mime-action-on-part (&optional action)
3206 "Do something with the MIME attachment at \(point\)."
3208 (list (completing-read "Action: " gnus-mime-action-alist)))
3209 (gnus-article-check-buffer)
3210 (let ((action-pair (assoc action gnus-mime-action-alist)))
3212 (funcall (cdr action-pair)))))
3215 (defun gnus-article-part-wrapper (n function)
3216 (save-current-buffer
3217 (set-buffer gnus-article-buffer)
3218 (when (> n (length gnus-article-mime-handle-alist))
3219 (error "No such part"))
3220 (gnus-article-goto-part n)
3221 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3222 (funcall function handle))))
3224 (defun gnus-article-pipe-part (n)
3225 "Pipe MIME part N, which is the numerical prefix."
3227 (gnus-article-part-wrapper n 'mm-pipe-part))
3229 (defun gnus-article-save-part (n)
3230 "Save MIME part N, which is the numerical prefix."
3232 (gnus-article-part-wrapper n 'mm-save-part))
3234 (defun gnus-article-interactively-view-part (n)
3235 "View MIME part N interactively, which is the numerical prefix."
3237 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3239 (defun gnus-article-copy-part (n)
3240 "Copy MIME part N, which is the numerical prefix."
3242 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3244 (defun gnus-article-view-part-as-charset (n)
3245 "Copy MIME part N, which is the numerical prefix."
3247 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3249 (defun gnus-article-externalize-part (n)
3250 "View MIME part N externally, which is the numerical prefix."
3252 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3254 (defun gnus-article-inline-part (n)
3255 "Inline MIME part N, which is the numerical prefix."
3257 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3259 (defun gnus-article-mime-match-handle-first (condition)
3261 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3262 (while (setq ihandle (pop alist))
3264 ((functionp condition)
3265 (funcall condition (cdr ihandle)))
3266 ((eq condition 'undisplayed)
3267 (not (or (mm-handle-undisplayer (cdr ihandle))
3268 (equal (mm-handle-media-type (cdr ihandle))
3269 "multipart/alternative"))))
3270 ((eq condition 'undisplayed-alternative)
3271 (not (mm-handle-undisplayer (cdr ihandle))))
3273 (gnus-article-goto-part (car ihandle))
3274 (or (not n) (< (car ihandle) n)))
3275 (setq n (car ihandle))))
3279 (defun gnus-article-view-part (&optional n)
3280 "View MIME part N, which is the numerical prefix."
3282 (save-current-buffer
3283 (set-buffer gnus-article-buffer)
3284 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3285 gnus-article-mime-match-handle-function)))
3286 (when (> n (length gnus-article-mime-handle-alist))
3287 (error "No such part"))
3288 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3289 (when (gnus-article-goto-part n)
3290 (if (equal (car handle) "multipart/alternative")
3291 (gnus-article-press-button)
3292 (when (eq (gnus-mm-display-part handle) 'internal)
3293 (gnus-set-window-start)))))))
3295 (defsubst gnus-article-mime-total-parts ()
3296 (if (bufferp (car gnus-article-mime-handles))
3298 (1- (length gnus-article-mime-handles))))
3300 (defun gnus-mm-display-part (handle)
3301 "Display HANDLE and fix MIME button."
3302 (let ((id (get-text-property (point) 'gnus-part))
3307 (let ((window (selected-window))
3308 (mail-parse-charset gnus-newsgroup-charset)
3309 (mail-parse-ignored-charsets
3310 (save-excursion (set-buffer gnus-summary-buffer)
3311 gnus-newsgroup-ignored-charsets)))
3314 (let ((win (get-buffer-window (current-buffer) t))
3317 (select-window win))
3320 (if (mm-handle-displayed-p handle)
3321 ;; This will remove the part.
3322 (mm-display-part handle)
3324 (narrow-to-region (point) (1+ (point)))
3325 (mm-display-part handle)
3326 ;; We narrow to the part itself and
3327 ;; then call the treatment functions.
3328 (goto-char (point-min))
3330 (narrow-to-region (point) (point-max))
3333 (gnus-article-mime-total-parts)
3334 (mm-handle-media-type handle)))))
3335 (select-window window))))
3337 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3338 (gnus-insert-mime-button
3339 handle id (list (mm-handle-displayed-p handle)))
3340 (goto-char point))))
3342 (defun gnus-article-goto-part (n)
3343 "Go to MIME part N."
3344 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3346 (goto-char point))))
3348 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3349 (let ((gnus-tmp-name
3350 (or (mail-content-type-get (mm-handle-type handle)
3352 (mail-content-type-get (mm-handle-disposition handle)
3354 (mail-content-type-get (mm-handle-type handle)
3357 (gnus-tmp-type (mm-handle-media-type handle))
3358 (gnus-tmp-description
3359 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3362 (if (if displayed (car displayed)
3363 (mm-handle-displayed-p handle))
3365 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3367 gnus-tmp-type-long b e)
3368 (when (string-match ".*/" gnus-tmp-name)
3369 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3370 (setq gnus-tmp-type-long (concat gnus-tmp-type
3371 (and (not (equal gnus-tmp-name ""))
3372 (concat "; " gnus-tmp-name))))
3373 (or (equal gnus-tmp-description "")
3374 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3379 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3380 `(local-map ,gnus-mime-button-map
3381 keymap ,gnus-mime-button-map
3382 gnus-callback gnus-mm-display-part
3383 gnus-part ,gnus-tmp-id
3384 article-type annotation
3387 (widget-convert-button
3390 :action 'gnus-widget-press-button
3391 :button-keymap gnus-mime-button-map
3393 (lambda (widget/window &optional overlay pos)
3394 ;; Needed to properly clear the message due to a bug in
3395 ;; wid-edit (XEmacs only).
3396 (if (boundp 'help-echo-owns-message)
3397 (setq help-echo-owns-message t))
3399 "%S: %s the MIME part; %S: more options"
3400 (aref gnus-mouse-2 0)
3401 ;; XEmacs will get a single widget arg; Emacs 21 will get
3402 ;; window, overlay, position.
3403 (if (mm-handle-displayed-p
3405 (with-current-buffer (gnus-overlay-buffer overlay)
3406 (widget-get (widget-at (gnus-overlay-start overlay))
3408 (widget-get widget/window :mime-handle)))
3410 (aref gnus-down-mouse-3 0))))))
3412 (defun gnus-widget-press-button (elems el)
3413 (goto-char (widget-get elems :from))
3414 (gnus-article-press-button))
3416 (defvar gnus-displaying-mime nil)
3418 (defun gnus-display-mime (&optional ihandles)
3419 "Display the MIME parts."
3421 (save-selected-window
3422 (let ((window (get-buffer-window gnus-article-buffer))
3425 (select-window window)
3426 ;; We have to do this since selecting the window
3427 ;; may change the point. So we set the window point.
3428 (set-window-point window point)))
3429 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3430 buffer-read-only handle name type b e display)