(buffer-syntactic-context): Don't quote nil and t in docstrings.
[emacs.git] / lisp / gnus / gnus-art.el
blobb03c3e7191918cc7608e60c7624577e89fc31f20
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;;; Code:
30 (eval-when-compile (require 'cl))
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'mm-bodies)
37 (require 'mail-parse)
38 (require 'mm-decode)
39 (require 'mm-view)
40 (require 'wid-edit)
41 (require 'mm-uu)
43 (defgroup gnus-article nil
44 "Article display."
45 :link '(custom-manual "(gnus)The Article Buffer")
46 :group 'gnus)
48 (defgroup gnus-article-treat nil
49 "Treating article parts."
50 :link '(custom-manual "(gnus)Article Hiding")
51 :group 'gnus-article)
53 (defgroup gnus-article-hiding nil
54 "Hiding article parts."
55 :link '(custom-manual "(gnus)Article Hiding")
56 :group 'gnus-article)
58 (defgroup gnus-article-highlight nil
59 "Article highlighting."
60 :link '(custom-manual "(gnus)Article Highlighting")
61 :group 'gnus-article
62 :group 'gnus-visual)
64 (defgroup gnus-article-signature nil
65 "Article signatures."
66 :link '(custom-manual "(gnus)Article Signature")
67 :group 'gnus-article)
69 (defgroup gnus-article-headers nil
70 "Article headers."
71 :link '(custom-manual "(gnus)Hiding Headers")
72 :group 'gnus-article)
74 (defgroup gnus-article-washing nil
75 "Special commands on articles."
76 :link '(custom-manual "(gnus)Article Washing")
77 :group 'gnus-article)
79 (defgroup gnus-article-emphasis nil
80 "Fontisizing articles."
81 :link '(custom-manual "(gnus)Article Fontisizing")
82 :group 'gnus-article)
84 (defgroup gnus-article-saving nil
85 "Saving articles."
86 :link '(custom-manual "(gnus)Saving Articles")
87 :group 'gnus-article)
89 (defgroup gnus-article-mime nil
90 "Worshiping the MIME wonder."
91 :link '(custom-manual "(gnus)Using MIME")
92 :group 'gnus-article)
94 (defgroup gnus-article-buttons nil
95 "Pushable buttons in the article buffer."
96 :link '(custom-manual "(gnus)Article Buttons")
97 :group 'gnus-article)
99 (defgroup gnus-article-various nil
100 "Other article options."
101 :link '(custom-manual "(gnus)Misc Article")
102 :group 'gnus-article)
104 (defcustom gnus-ignored-headers
105 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
106 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
107 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
108 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
109 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
110 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
111 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
112 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
113 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
114 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
115 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
116 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
117 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
118 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
119 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
120 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
121 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
122 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
123 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
124 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
125 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
126 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
127 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
128 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
129 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
130 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
131 "^X-Received:" "^Content-length:" "X-precedence:")
132 "*All headers that start with this regexp will be hidden.
133 This variable can also be a list of regexps of headers to be ignored.
134 If `gnus-visible-headers' is non-nil, this variable will be ignored."
135 :type '(choice :custom-show nil
136 regexp
137 (repeat regexp))
138 :group 'gnus-article-hiding)
140 (defcustom gnus-visible-headers
141 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
142 "*All headers that do not match this regexp will be hidden.
143 This variable can also be a list of regexp of headers to remain visible.
144 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
145 :type '(repeat :value-to-internal (lambda (widget value)
146 (custom-split-regexp-maybe value))
147 :match (lambda (widget value)
148 (or (stringp value)
149 (widget-editable-list-match widget value)))
150 regexp)
151 :group 'gnus-article-hiding)
153 (defcustom gnus-sorted-header-list
154 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
155 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
156 "*This variable is a list of regular expressions.
157 If it is non-nil, headers that match the regular expressions will
158 be placed first in the article buffer in the sequence specified by
159 this list."
160 :type '(repeat regexp)
161 :group 'gnus-article-hiding)
163 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
164 "Headers that are only to be displayed if they have interesting data.
165 Possible values in this list are `empty', `newsgroups', `followup-to',
166 `reply-to', `date', `long-to', and `many-to'."
167 :type '(set (const :tag "Headers with no content." empty)
168 (const :tag "Newsgroups with only one group." newsgroups)
169 (const :tag "Followup-to identical to newsgroups." followup-to)
170 (const :tag "Reply-to identical to from." reply-to)
171 (const :tag "Date less than four days old." date)
172 (const :tag "Very long To and/or Cc header." long-to)
173 (const :tag "Multiple To and/or Cc headers." many-to))
174 :group 'gnus-article-hiding)
176 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
177 "Regexp matching signature separator.
178 This can also be a list of regexps. In that case, it will be checked
179 from head to tail looking for a separator. Searches will be done from
180 the end of the buffer."
181 :type '(repeat string)
182 :group 'gnus-article-signature)
184 (defcustom gnus-signature-limit nil
185 "Provide a limit to what is considered a signature.
186 If it is a number, no signature may not be longer (in characters) than
187 that number. If it is a floating point number, no signature may be
188 longer (in lines) than that number. If it is a function, the function
189 will be called without any parameters, and if it returns nil, there is
190 no signature in the buffer. If it is a string, it will be used as a
191 regexp. If it matches, the text in question is not a signature."
192 :type '(choice (integer :value 200)
193 (number :value 4.0)
194 (function :value fun)
195 (regexp :value ".*"))
196 :group 'gnus-article-signature)
198 (defcustom gnus-hidden-properties '(invisible t intangible t)
199 "Property list to use for hiding text."
200 :type 'sexp
201 :group 'gnus-article-hiding)
203 ;; Fixme: This isn't the right thing for mixed graphical and and
204 ;; non-graphical frames in a session.
205 ;; gnus-xmas.el overrides this for XEmacs.
206 (defcustom gnus-article-x-face-command
207 (if (and (fboundp 'image-type-available-p)
208 (image-type-available-p 'xbm))
209 'gnus-article-display-xface
210 (if (or (and (boundp 'gnus-article-compface-xbm)
211 gnus-article-compface-xbm)
212 (eq 0 (string-match "#define"
213 (shell-command-to-string "uncompface -X"))))
214 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
215 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
216 display -"))
217 "*String or function to be executed to display an X-Face header.
218 If it is a string, the command will be executed in a sub-shell
219 asynchronously. The compressed face will be piped to this command."
220 :type '(choice string
221 (function-item gnus-article-display-xface)
222 function)
223 :version "21.1"
224 :group 'gnus-article-washing)
226 (defcustom gnus-article-x-face-too-ugly nil
227 "Regexp matching posters whose face shouldn't be shown automatically."
228 :type '(choice regexp (const nil))
229 :group 'gnus-article-washing)
231 (defcustom gnus-article-banner-alist nil
232 "Banner alist for stripping.
233 For example,
234 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
235 :version "21.1"
236 :type '(repeat (cons symbol regexp))
237 :group 'gnus-article-washing)
239 (defcustom gnus-emphasis-alist
240 (let ((format
241 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
242 (types
243 '(("_" "_" underline)
244 ("/" "/" italic)
245 ("\\*" "\\*" bold)
246 ("_/" "/_" underline-italic)
247 ("_\\*" "\\*_" underline-bold)
248 ("\\*/" "/\\*" bold-italic)
249 ("_\\*/" "/\\*_" underline-bold-italic))))
250 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
251 2 3 gnus-emphasis-underline)
252 ,@(mapcar
253 (lambda (spec)
254 (list
255 (format format (car spec) (cadr spec))
256 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
257 types)))
258 "*Alist that says how to fontify certain phrases.
259 Each item looks like this:
261 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
263 The first element is a regular expression to be matched. The second
264 is a number that says what regular expression grouping used to find
265 the entire emphasized word. The third is a number that says what
266 regexp grouping should be displayed and highlighted. The fourth
267 is the face used for highlighting."
268 :type '(repeat (list :value ("" 0 0 default)
269 regexp
270 (integer :tag "Match group")
271 (integer :tag "Emphasize group")
272 face))
273 :group 'gnus-article-emphasis)
275 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
276 "A regexp to describe whitespace which should not be emphasized.
277 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
278 The former avoids underlining of leading and trailing whitespace,
279 and the latter avoids underlining any whitespace at all."
280 :version "21.1"
281 :group 'gnus-article-emphasis
282 :type 'regexp)
284 (defface gnus-emphasis-bold '((t (:weight bold)))
285 "Face used for displaying strong emphasized text (*word*)."
286 :group 'gnus-article-emphasis)
288 (defface gnus-emphasis-italic '((t (:slant italic)))
289 "Face used for displaying italic emphasized text (/word/)."
290 :group 'gnus-article-emphasis)
292 (defface gnus-emphasis-underline '((t (:underline t)))
293 "Face used for displaying underlined emphasized text (_word_)."
294 :group 'gnus-article-emphasis)
296 (defface gnus-emphasis-underline-bold '((t (:weight bold :underline t)))
297 "Face used for displaying underlined bold emphasized text (_*word*_)."
298 :group 'gnus-article-emphasis)
300 (defface gnus-emphasis-underline-italic '((t (:slant italic :underline t)))
301 "Face used for displaying underlined italic emphasized text (_/word/_)."
302 :group 'gnus-article-emphasis)
304 (defface gnus-emphasis-bold-italic '((t (:weight bold :slant italic)))
305 "Face used for displaying bold italic emphasized text (/*word*/)."
306 :group 'gnus-article-emphasis)
308 (defface gnus-emphasis-underline-bold-italic
309 '((t (:weight bold :slant italic :underline t)))
310 "Face used for displaying underlined bold italic emphasized text.
311 Example: (_/*word*/_)."
312 :group 'gnus-article-emphasis)
314 (defface gnus-emphasis-highlight-words
315 '((t (:background "black" :foreground "yellow")))
316 "Face used for displaying highlighted words."
317 :group 'gnus-article-emphasis)
319 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
320 "Format for display of Date headers in article bodies.
321 See `format-time-string' for the possible values.
323 The variable can also be function, which should return a complete Date
324 header. The function is called with one argument, the time, which can
325 be fed to `format-time-string'."
326 :type '(choice string symbol)
327 :link '(custom-manual "(gnus)Article Date")
328 :group 'gnus-article-washing)
330 (eval-and-compile
331 (autoload 'mail-extract-address-components "mail-extr"))
333 (defcustom gnus-save-all-headers t
334 "*If non-nil, don't remove any headers before saving."
335 :group 'gnus-article-saving
336 :type 'boolean)
338 (defcustom gnus-prompt-before-saving 'always
339 "*This variable says how much prompting is to be done when saving articles.
340 If it is nil, no prompting will be done, and the articles will be
341 saved to the default files. If this variable is `always', each and
342 every article that is saved will be preceded by a prompt, even when
343 saving large batches of articles. If this variable is neither nil not
344 `always', there the user will be prompted once for a file name for
345 each invocation of the saving commands."
346 :group 'gnus-article-saving
347 :type '(choice (item always)
348 (item :tag "never" nil)
349 (sexp :tag "once" :format "%t\n" :value t)))
351 (defcustom gnus-saved-headers gnus-visible-headers
352 "Headers to keep if `gnus-save-all-headers' is nil.
353 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
354 If that variable is nil, however, all headers that match this regexp
355 will be kept while the rest will be deleted before saving."
356 :group 'gnus-article-saving
357 :type 'regexp)
359 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
360 "A function to save articles in your favourite format.
361 The function must be interactively callable (in other words, it must
362 be an Emacs command).
364 Gnus provides the following functions:
366 * gnus-summary-save-in-rmail (Rmail format)
367 * gnus-summary-save-in-mail (Unix mail format)
368 * gnus-summary-save-in-folder (MH folder)
369 * gnus-summary-save-in-file (article format)
370 * gnus-summary-save-in-vm (use VM's folder format)
371 * gnus-summary-write-to-file (article format -- overwrite)."
372 :group 'gnus-article-saving
373 :type '(radio (function-item gnus-summary-save-in-rmail)
374 (function-item gnus-summary-save-in-mail)
375 (function-item gnus-summary-save-in-folder)
376 (function-item gnus-summary-save-in-file)
377 (function-item gnus-summary-save-in-vm)
378 (function-item gnus-summary-write-to-file)))
380 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
381 "A function generating a file name to save articles in Rmail format.
382 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
383 :group 'gnus-article-saving
384 :type 'function)
386 (defcustom gnus-mail-save-name 'gnus-plain-save-name
387 "A function generating a file name to save articles in Unix mail format.
388 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
389 :group 'gnus-article-saving
390 :type 'function)
392 (defcustom gnus-folder-save-name 'gnus-folder-save-name
393 "A function generating a file name to save articles in MH folder.
394 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
395 :group 'gnus-article-saving
396 :type 'function)
398 (defcustom gnus-file-save-name 'gnus-numeric-save-name
399 "A function generating a file name to save articles in article format.
400 The function is called with NEWSGROUP, HEADERS, and optional
401 LAST-FILE."
402 :group 'gnus-article-saving
403 :type 'function)
405 (defcustom gnus-split-methods
406 '((gnus-article-archive-name)
407 (gnus-article-nndoc-name))
408 "*Variable used to suggest where articles are to be saved.
409 For instance, if you would like to save articles related to Gnus in
410 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
411 you could set this variable to something like:
413 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
414 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
416 This variable is an alist where the where the key is the match and the
417 value is a list of possible files to save in if the match is non-nil.
419 If the match is a string, it is used as a regexp match on the
420 article. If the match is a symbol, that symbol will be funcalled
421 from the buffer of the article to be saved with the newsgroup as the
422 parameter. If it is a list, it will be evaled in the same buffer.
424 If this form or function returns a string, this string will be used as
425 a possible file name; and if it returns a non-nil list, that list will
426 be used as possible file names."
427 :group 'gnus-article-saving
428 :type '(repeat (choice (list :value (fun) function)
429 (cons :value ("" "") regexp (repeat string))
430 (sexp :value nil))))
432 (defcustom gnus-page-delimiter "^\^L"
433 "*Regexp describing what to use as article page delimiters.
434 The default value is \"^\^L\", which is a form linefeed at the
435 beginning of a line."
436 :type 'regexp
437 :group 'gnus-article-various)
439 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
440 "*The format specification for the article mode line.
441 See `gnus-summary-mode-line-format' for a closer description.
443 The following additional specs are available:
445 %w The article washing status.
446 %m The number of MIME parts in the article."
447 :type 'string
448 :group 'gnus-article-various)
450 (defcustom gnus-article-mode-hook nil
451 "*A hook for Gnus article mode."
452 :type 'hook
453 :group 'gnus-article-various)
455 (defcustom gnus-article-menu-hook nil
456 "*Hook run after the creation of the article mode menu."
457 :type 'hook
458 :group 'gnus-article-various)
460 (defcustom gnus-article-prepare-hook nil
461 "*A hook called after an article has been prepared in the article buffer."
462 :type 'hook
463 :group 'gnus-article-various)
465 (defcustom gnus-article-hide-pgp-hook nil
466 "*A hook called after successfully hiding a PGP signature."
467 :type 'hook
468 :group 'gnus-article-various)
470 (defcustom gnus-article-button-face 'bold
471 "Face used for highlighting buttons in the article buffer.
473 An article button is a piece of text that you can activate by pressing
474 `RET' or `mouse-2' above it."
475 :type 'face
476 :group 'gnus-article-buttons)
478 (defcustom gnus-article-mouse-face 'highlight
479 "Face used for mouse highlighting in the article buffer.
481 Article buttons will be displayed in this face when the cursor is
482 above them."
483 :type 'face
484 :group 'gnus-article-buttons)
486 (defcustom gnus-signature-face 'gnus-signature-face
487 "Face used for highlighting a signature in the article buffer.
488 Obsolete; use the face `gnus-signature-face' for customizations instead."
489 :type 'face
490 :group 'gnus-article-highlight
491 :group 'gnus-article-signature)
493 (defface gnus-signature-face
494 '((t
495 (:slant italic)))
496 "Face used for highlighting a signature in the article buffer."
497 :group 'gnus-article-highlight
498 :group 'gnus-article-signature)
500 (defface gnus-header-from-face
501 '((((class color)
502 (background dark))
503 (:foreground "spring green"))
504 (((class color)
505 (background light))
506 (:foreground "red3"))
508 (:slant italic)))
509 "Face used for displaying from headers."
510 :group 'gnus-article-headers
511 :group 'gnus-article-highlight)
513 (defface gnus-header-subject-face
514 '((((class color)
515 (background dark))
516 (:foreground "SeaGreen3"))
517 (((class color)
518 (background light))
519 (:foreground "red4"))
521 (:weight bold :slant italic)))
522 "Face used for displaying subject headers."
523 :group 'gnus-article-headers
524 :group 'gnus-article-highlight)
526 (defface gnus-header-newsgroups-face
527 '((((class color)
528 (background dark))
529 (:foreground "yellow" :slant italic))
530 (((class color)
531 (background light))
532 (:foreground "MidnightBlue" :slant italic))
534 (:slant italic)))
535 "Face used for displaying newsgroups headers."
536 :group 'gnus-article-headers
537 :group 'gnus-article-highlight)
539 (defface gnus-header-name-face
540 '((((class color)
541 (background dark))
542 (:foreground "SeaGreen"))
543 (((class color)
544 (background light))
545 (:foreground "maroon"))
547 (:weight bold)))
548 "Face used for displaying header names."
549 :group 'gnus-article-headers
550 :group 'gnus-article-highlight)
552 (defface gnus-header-content-face
553 '((((class color)
554 (background dark))
555 (:foreground "forest green" :slant italic))
556 (((class color)
557 (background light))
558 (:foreground "indianred4" :slant italic))
560 (:slant italic))) "Face used for displaying header content."
561 :group 'gnus-article-headers
562 :group 'gnus-article-highlight)
564 (defcustom gnus-header-face-alist
565 '(("From" nil gnus-header-from-face)
566 ("Subject" nil gnus-header-subject-face)
567 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
568 ("" gnus-header-name-face gnus-header-content-face))
569 "*Controls highlighting of article header.
571 An alist of the form (HEADER NAME CONTENT).
573 HEADER is a regular expression which should match the name of an
574 header header and NAME and CONTENT are either face names or nil.
576 The name of each header field will be displayed using the face
577 specified by the first element in the list where HEADER match the
578 header name and NAME is non-nil. Similarly, the content will be
579 displayed by the first non-nil matching CONTENT face."
580 :group 'gnus-article-headers
581 :group 'gnus-article-highlight
582 :type '(repeat (list (regexp :tag "Header")
583 (choice :tag "Name"
584 (item :tag "skip" nil)
585 (face :value default))
586 (choice :tag "Content"
587 (item :tag "skip" nil)
588 (face :value default)))))
590 (defcustom gnus-article-decode-hook
591 '(article-decode-charset article-decode-encoded-words)
592 "*Hook run to decode charsets in articles."
593 :group 'gnus-article-headers
594 :type 'hook)
596 (defcustom gnus-display-mime-function 'gnus-display-mime
597 "Function to display MIME articles."
598 :group 'gnus-article-mime
599 :type 'function)
601 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
602 "Function used to decode headers.")
604 (defvar gnus-article-dumbquotes-map
605 '(("\202" ",")
606 ("\203" "f")
607 ("\204" ",,")
608 ("\205" "...")
609 ("\213" "<")
610 ("\214" "OE")
611 ("\221" "`")
612 ("\222" "'")
613 ("\223" "``")
614 ("\224" "\"")
615 ("\225" "*")
616 ("\226" "-")
617 ("\227" "--")
618 ("\231" "(TM)")
619 ("\233" ">")
620 ("\234" "oe")
621 ("\264" "'"))
622 "Table for MS-to-Latin1 translation.")
624 (defcustom gnus-ignored-mime-types nil
625 "List of MIME types that should be ignored by Gnus."
626 :version "21.1"
627 :group 'gnus-article-mime
628 :type '(repeat regexp))
630 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
631 "List of MIME types that should not be given buttons when rendered inline."
632 :version "21.1"
633 :group 'gnus-article-mime
634 :type '(repeat regexp))
636 (defcustom gnus-article-mime-part-function nil
637 "Function called with a MIME handle as the argument.
638 This is meant for people who want to do something automatic based
639 on parts -- for instance, adding Vcard info to a database."
640 :group 'gnus-article-mime
641 :type 'function)
643 (defcustom gnus-mime-multipart-functions nil
644 "An alist of MIME types to functions to display them."
645 :version "21.1"
646 :group 'gnus-article-mime
647 :type 'alist)
649 (defcustom gnus-article-date-lapsed-new-header nil
650 "Whether the X-Sent and Date headers can coexist.
651 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
652 either replace the old \"Date:\" header (if this variable is nil), or
653 be added below it (otherwise)."
654 :version "21.1"
655 :group 'gnus-article-headers
656 :type 'boolean)
658 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
659 "Function called with a MIME handle as the argument.
660 This is meant for people who want to view first matched part.
661 For `undisplayed-alternative' (default), the first undisplayed
662 part or alternative part is used. For `undisplayed', the first
663 undisplayed part is used. For a function, the first part which
664 the function return t is used. For nil, the first part is
665 used."
666 :version "21.1"
667 :group 'gnus-article-mime
668 :type '(choice
669 (item :tag "first" :value nil)
670 (item :tag "undisplayed" :value undisplayed)
671 (item :tag "undisplayed or alternative"
672 :value undisplayed-alternative)
673 (function)))
675 (defcustom gnus-mime-action-alist
676 '(("save to file" . gnus-mime-save-part)
677 ("display as text" . gnus-mime-inline-part)
678 ("view the part" . gnus-mime-view-part)
679 ("pipe to command" . gnus-mime-pipe-part)
680 ("toggle display" . gnus-article-press-button)
681 ("view as type" . gnus-mime-view-part-as-type)
682 ("internalize type" . gnus-mime-internalize-part)
683 ("externalize type" . gnus-mime-externalize-part))
684 "An alist of actions that run on the MIME attachment."
685 :version "21.1"
686 :group 'gnus-article-mime
687 :type '(repeat (cons (string :tag "name")
688 (function))))
691 ;;; The treatment variables
694 (defvar gnus-part-display-hook nil
695 "Hook called on parts that are to receive treatment.")
697 (defvar gnus-article-treat-custom
698 '(choice (const :tag "Off" nil)
699 (const :tag "On" t)
700 (const :tag "Header" head)
701 (const :tag "Last" last)
702 (integer :tag "Less")
703 (repeat :tag "Groups" regexp)
704 (sexp :tag "Predicate")))
706 (defvar gnus-article-treat-head-custom
707 '(choice (const :tag "Off" nil)
708 (const :tag "Header" head)))
710 (defvar gnus-article-treat-types '("text/plain")
711 "Parts to treat.")
713 (defvar gnus-inhibit-treatment nil
714 "Whether to inhibit treatment.")
716 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
717 "Highlight the signature.
718 Valid values are nil, t, `head', `last', an integer or a predicate.
719 See the manual for details."
720 :group 'gnus-article-treat
721 :type gnus-article-treat-custom)
722 (put 'gnus-treat-highlight-signature 'highlight t)
724 (defcustom gnus-treat-buttonize 100000
725 "Add buttons.
726 Valid values are nil, t, `head', `last', an integer or a predicate.
727 See the manual for details."
728 :group 'gnus-article-treat
729 :type gnus-article-treat-custom)
730 (put 'gnus-treat-buttonize 'highlight t)
732 (defcustom gnus-treat-buttonize-head 'head
733 "Add buttons to the head.
734 Valid values are nil, t, `head', `last', an integer or a predicate.
735 See the manual for details."
736 :group 'gnus-article-treat
737 :type gnus-article-treat-head-custom)
738 (put 'gnus-treat-buttonize-head 'highlight t)
740 (defcustom gnus-treat-emphasize
741 (and (or window-system
742 (featurep 'xemacs)
743 (>= (string-to-number emacs-version) 21))
744 50000)
745 "Emphasize text.
746 Valid values are nil, t, `head', `last', an integer or a predicate.
747 See the manual for details."
748 :group 'gnus-article-treat
749 :type gnus-article-treat-custom)
750 (put 'gnus-treat-emphasize 'highlight t)
752 (defcustom gnus-treat-strip-cr nil
753 "Remove carriage returns.
754 Valid values are nil, t, `head', `last', an integer or a predicate.
755 See the manual for details."
756 :group 'gnus-article-treat
757 :type gnus-article-treat-custom)
759 (defcustom gnus-treat-hide-headers 'head
760 "Hide headers.
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-head-custom)
766 (defcustom gnus-treat-hide-boring-headers nil
767 "Hide boring headers.
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-head-custom)
773 (defcustom gnus-treat-hide-signature nil
774 "Hide the signature.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-custom)
780 (defcustom gnus-treat-fill-article nil
781 "Fill the article.
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-custom)
787 (defcustom gnus-treat-hide-citation nil
788 "Hide cited text.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
794 (defcustom gnus-treat-hide-citation-maybe nil
795 "Hide cited text.
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-custom)
801 (defcustom gnus-treat-strip-list-identifiers 'head
802 "Strip list identifiers from `gnus-list-identifiers`.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :version "21.1"
806 :group 'gnus-article-treat
807 :type gnus-article-treat-custom)
809 (defcustom gnus-treat-strip-pgp t
810 "Strip PGP signatures.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-custom)
816 (defcustom gnus-treat-strip-pem nil
817 "Strip PEM signatures.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-custom)
823 (defcustom gnus-treat-strip-banner t
824 "Strip banners from articles.
825 The banner to be stripped is specified in the `banner' group parameter.
826 Valid values are nil, t, `head', `last', an integer or a predicate.
827 See the manual for details."
828 :group 'gnus-article-treat
829 :type gnus-article-treat-custom)
831 (defcustom gnus-treat-highlight-headers 'head
832 "Highlight the headers.
833 Valid values are nil, t, `head', `last', an integer or a predicate.
834 See the manual for details."
835 :group 'gnus-article-treat
836 :type gnus-article-treat-head-custom)
837 (put 'gnus-treat-highlight-headers 'highlight t)
839 (defcustom gnus-treat-highlight-citation t
840 "Highlight cited text.
841 Valid values are nil, t, `head', `last', an integer or a predicate.
842 See the manual for details."
843 :group 'gnus-article-treat
844 :type gnus-article-treat-custom)
845 (put 'gnus-treat-highlight-citation 'highlight t)
847 (defcustom gnus-treat-date-ut nil
848 "Display the Date in UT (GMT).
849 Valid values are nil, t, `head', `last', an integer or a predicate.
850 See the manual for details."
851 :group 'gnus-article-treat
852 :type gnus-article-treat-head-custom)
854 (defcustom gnus-treat-date-local nil
855 "Display the Date in the local timezone.
856 Valid values are nil, t, `head', `last', an integer or a predicate.
857 See the manual for details."
858 :group 'gnus-article-treat
859 :type gnus-article-treat-head-custom)
861 (defcustom gnus-treat-date-lapsed nil
862 "Display the Date header in a way that says how much time has elapsed.
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See the manual for details."
865 :group 'gnus-article-treat
866 :type gnus-article-treat-head-custom)
868 (defcustom gnus-treat-date-original nil
869 "Display the date in the original timezone.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See the manual for details."
872 :group 'gnus-article-treat
873 :type gnus-article-treat-head-custom)
875 (defcustom gnus-treat-date-iso8601 nil
876 "Display the date in the ISO8601 format.
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See the manual for details."
879 :version "21.1"
880 :group 'gnus-article-treat
881 :type gnus-article-treat-head-custom)
883 (defcustom gnus-treat-date-user-defined nil
884 "Display the date in a user-defined format.
885 The format is defined by the `gnus-article-time-format' variable.
886 Valid values are nil, t, `head', `last', an integer or a predicate.
887 See the manual for details."
888 :group 'gnus-article-treat
889 :type gnus-article-treat-head-custom)
891 (defcustom gnus-treat-strip-headers-in-body t
892 "Strip the X-No-Archive header line from the beginning of the body.
893 Valid values are nil, t, `head', `last', an integer or a predicate.
894 See the manual for details."
895 :version "21.1"
896 :group 'gnus-article-treat
897 :type gnus-article-treat-custom)
899 (defcustom gnus-treat-strip-trailing-blank-lines nil
900 "Strip trailing blank lines.
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)
906 (defcustom gnus-treat-strip-leading-blank-lines nil
907 "Strip leading blank lines.
908 Valid values are nil, t, `head', `last', an integer or a predicate.
909 See the manual for details."
910 :group 'gnus-article-treat
911 :type gnus-article-treat-custom)
913 (defcustom gnus-treat-strip-multiple-blank-lines nil
914 "Strip multiple blank lines.
915 Valid values are nil, t, `head', `last', an integer or a predicate.
916 See the manual for details."
917 :group 'gnus-article-treat
918 :type gnus-article-treat-custom)
920 (defcustom gnus-treat-overstrike t
921 "Treat overstrike highlighting.
922 Valid values are nil, t, `head', `last', an integer or a predicate.
923 See the manual for details."
924 :group 'gnus-article-treat
925 :type gnus-article-treat-custom)
926 (put 'gnus-treat-overstrike 'highlight t)
928 (defcustom gnus-treat-display-xface
929 (and (or (and (fboundp 'image-type-available-p)
930 (image-type-available-p 'xbm)
931 (string-match "^0x" (shell-command-to-string "uncompface")))
932 (and (featurep 'xemacs) (featurep 'xface)))
933 'head)
934 "Display X-Face headers.
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 :version "21.1"
939 :type gnus-article-treat-head-custom)
940 (put 'gnus-treat-display-xface 'highlight t)
942 (defcustom gnus-treat-display-smileys
943 (if (or (and (featurep 'xemacs)
944 (featurep 'xpm))
945 (and (fboundp 'image-type-available-p)
946 (image-type-available-p 'pbm)))
947 t nil)
948 "Display smileys.
949 Valid values are nil, t, `head', `last', an integer or a predicate.
950 See the manual for details."
951 :group 'gnus-article-treat
952 :version "21.1"
953 :type gnus-article-treat-custom)
954 (put 'gnus-treat-display-smileys 'highlight t)
956 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
957 "Display picons.
958 Valid values are nil, t, `head', `last', an integer or a predicate.
959 See the manual for details."
960 :group 'gnus-article-treat
961 :type gnus-article-treat-head-custom)
962 (put 'gnus-treat-display-picons 'highlight t)
964 (defcustom gnus-treat-capitalize-sentences nil
965 "Capitalize sentence-starting words.
966 Valid values are nil, t, `head', `last', an integer or a predicate.
967 See the manual for details."
968 :version "21.1"
969 :group 'gnus-article-treat
970 :type gnus-article-treat-custom)
972 (defcustom gnus-treat-fill-long-lines nil
973 "Fill long lines.
974 Valid values are nil, t, `head', `last', an integer or a predicate.
975 See the manual for details."
976 :group 'gnus-article-treat
977 :type gnus-article-treat-custom)
979 (defcustom gnus-treat-play-sounds nil
980 "Play sounds.
981 Valid values are nil, t, `head', `last', an integer or a predicate.
982 See the manual for details."
983 :version "21.1"
984 :group 'gnus-article-treat
985 :type gnus-article-treat-custom)
987 (defcustom gnus-treat-translate nil
988 "Translate articles from one language to another.
989 Valid values are nil, t, `head', `last', an integer or a predicate.
990 See the manual for details."
991 :version "21.1"
992 :group 'gnus-article-treat
993 :type gnus-article-treat-custom)
995 ;;; Internal variables
997 (defvar article-goto-body-goes-to-point-min-p nil)
998 (defvar gnus-article-wash-types nil)
999 (defvar gnus-article-emphasis-alist nil)
1001 (defvar gnus-article-mime-handle-alist-1 nil)
1002 (defvar gnus-treatment-function-alist
1003 '((gnus-treat-strip-banner gnus-article-strip-banner)
1004 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1005 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1006 (gnus-treat-buttonize gnus-article-add-buttons)
1007 (gnus-treat-fill-article gnus-article-fill-cited-article)
1008 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1009 (gnus-treat-strip-cr gnus-article-remove-cr)
1010 (gnus-treat-emphasize gnus-article-emphasize)
1011 (gnus-treat-display-xface gnus-article-display-x-face)
1012 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1013 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1014 (gnus-treat-hide-signature gnus-article-hide-signature)
1015 (gnus-treat-hide-citation gnus-article-hide-citation)
1016 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1017 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1018 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1019 (gnus-treat-strip-pem gnus-article-hide-pem)
1020 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1021 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1022 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1023 (gnus-treat-date-ut gnus-article-date-ut)
1024 (gnus-treat-date-local gnus-article-date-local)
1025 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1026 (gnus-treat-date-original gnus-article-date-original)
1027 (gnus-treat-date-user-defined gnus-article-date-user)
1028 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1029 (gnus-treat-strip-trailing-blank-lines
1030 gnus-article-remove-trailing-blank-lines)
1031 (gnus-treat-strip-leading-blank-lines
1032 gnus-article-strip-leading-blank-lines)
1033 (gnus-treat-strip-multiple-blank-lines
1034 gnus-article-strip-multiple-blank-lines)
1035 (gnus-treat-overstrike gnus-article-treat-overstrike)
1036 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1037 (gnus-treat-display-smileys gnus-smiley-display)
1038 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1039 (gnus-treat-display-picons gnus-article-display-picons)
1040 (gnus-treat-play-sounds gnus-earcon-display)))
1042 (defvar gnus-article-mime-handle-alist nil)
1043 (defvar article-lapsed-timer nil)
1044 (defvar gnus-article-current-summary nil)
1046 (defvar gnus-article-mode-syntax-table
1047 (let ((table (copy-syntax-table text-mode-syntax-table)))
1048 (modify-syntax-entry ?- "w" table)
1049 (modify-syntax-entry ?> ")" table)
1050 (modify-syntax-entry ?< "(" table)
1051 table)
1052 "Syntax table used in article mode buffers.
1053 Initialized from `text-mode-syntax-table.")
1055 (defvar gnus-save-article-buffer nil)
1057 (defvar gnus-article-mode-line-format-alist
1058 (nconc '((?w (gnus-article-wash-status) ?s)
1059 (?m (gnus-article-mime-part-status) ?s))
1060 gnus-summary-mode-line-format-alist))
1062 (defvar gnus-number-of-articles-to-be-saved nil)
1064 (defvar gnus-inhibit-hiding nil)
1066 (defsubst gnus-article-hide-text (b e props)
1067 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1068 (gnus-add-text-properties-when 'article-type nil b e props)
1069 (when (memq 'intangible props)
1070 (put-text-property
1071 (max (1- b) (point-min))
1072 b 'intangible (cddr (memq 'intangible props)))))
1074 (defsubst gnus-article-unhide-text (b e)
1075 "Remove hidden text properties from region between B and E."
1076 (remove-text-properties b e gnus-hidden-properties)
1077 (when (memq 'intangible gnus-hidden-properties)
1078 (put-text-property (max (1- b) (point-min))
1079 b 'intangible nil)))
1081 (defun gnus-article-hide-text-type (b e type)
1082 "Hide text of TYPE between B and E."
1083 (push type gnus-article-wash-types)
1084 (gnus-article-hide-text
1085 b e (cons 'article-type (cons type gnus-hidden-properties))))
1087 (defun gnus-article-unhide-text-type (b e type)
1088 "Unhide text of TYPE between B and E."
1089 (setq gnus-article-wash-types
1090 (delq type gnus-article-wash-types))
1091 (remove-text-properties
1092 b e (cons 'article-type (cons type gnus-hidden-properties)))
1093 (when (memq 'intangible gnus-hidden-properties)
1094 (put-text-property (max (1- b) (point-min))
1095 b 'intangible nil)))
1097 (defun gnus-article-hide-text-of-type (type)
1098 "Hide text of TYPE in the current buffer."
1099 (save-excursion
1100 (let ((b (point-min))
1101 (e (point-max)))
1102 (while (setq b (text-property-any b e 'article-type type))
1103 (add-text-properties b (incf b) gnus-hidden-properties)))))
1105 (defun gnus-article-delete-text-of-type (type)
1106 "Delete text of TYPE in the current buffer."
1107 (save-excursion
1108 (let ((b (point-min)))
1109 (while (setq b (text-property-any b (point-max) 'article-type type))
1110 (delete-region
1111 b (or (text-property-not-all b (point-max) 'article-type type)
1112 (point-max)))))))
1114 (defun gnus-article-delete-invisible-text ()
1115 "Delete all invisible text in the current buffer."
1116 (save-excursion
1117 (let ((b (point-min)))
1118 (while (setq b (text-property-any b (point-max) 'invisible t))
1119 (delete-region
1120 b (or (text-property-not-all b (point-max) 'invisible t)
1121 (point-max)))))))
1123 (defun gnus-article-text-type-exists-p (type)
1124 "Say whether any text of type TYPE exists in the buffer."
1125 (text-property-any (point-min) (point-max) 'article-type type))
1127 (defsubst gnus-article-header-rank ()
1128 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1129 (let ((list gnus-sorted-header-list)
1130 (i 0))
1131 (while list
1132 (when (looking-at (car list))
1133 (setq list nil))
1134 (setq list (cdr list))
1135 (incf i))
1138 (defun article-hide-headers (&optional arg delete)
1139 "Hide unwanted headers and possibly sort them as well."
1140 (interactive)
1141 ;; This function might be inhibited.
1142 (unless gnus-inhibit-hiding
1143 (save-excursion
1144 (save-restriction
1145 (let ((buffer-read-only nil)
1146 (case-fold-search t)
1147 (max (1+ (length gnus-sorted-header-list)))
1148 (ignored (when (not gnus-visible-headers)
1149 (cond ((stringp gnus-ignored-headers)
1150 gnus-ignored-headers)
1151 ((listp gnus-ignored-headers)
1152 (mapconcat 'identity gnus-ignored-headers
1153 "\\|")))))
1154 (visible
1155 (cond ((stringp gnus-visible-headers)
1156 gnus-visible-headers)
1157 ((and gnus-visible-headers
1158 (listp gnus-visible-headers))
1159 (mapconcat 'identity gnus-visible-headers "\\|"))))
1160 (inhibit-point-motion-hooks t)
1161 beg)
1162 ;; First we narrow to just the headers.
1163 (article-narrow-to-head)
1164 ;; Hide any "From " lines at the beginning of (mail) articles.
1165 (while (looking-at "From ")
1166 (forward-line 1))
1167 (unless (bobp)
1168 (delete-region (point-min) (point)))
1169 ;; Then treat the rest of the header lines.
1170 ;; Then we use the two regular expressions
1171 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1172 ;; select which header lines is to remain visible in the
1173 ;; article buffer.
1174 (while (re-search-forward "^[^ \t]*:" nil t)
1175 (beginning-of-line)
1176 ;; Mark the rank of the header.
1177 (put-text-property
1178 (point) (1+ (point)) 'message-rank
1179 (if (or (and visible (looking-at visible))
1180 (and ignored
1181 (not (looking-at ignored))))
1182 (gnus-article-header-rank)
1183 (+ 2 max)))
1184 (forward-line 1))
1185 (message-sort-headers-1)
1186 (when (setq beg (text-property-any
1187 (point-min) (point-max) 'message-rank (+ 2 max)))
1188 ;; We delete the unwanted headers.
1189 (push 'headers gnus-article-wash-types)
1190 (add-text-properties (point-min) (+ 5 (point-min))
1191 '(article-type headers dummy-invisible t))
1192 (delete-region beg (point-max))))))))
1194 (defun article-hide-boring-headers (&optional arg)
1195 "Toggle hiding of headers that aren't very interesting.
1196 If given a negative prefix, always show; if given a positive prefix,
1197 always hide."
1198 (interactive (gnus-article-hidden-arg))
1199 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1200 (not gnus-show-all-headers))
1201 (save-excursion
1202 (save-restriction
1203 (let ((buffer-read-only nil)
1204 (list gnus-boring-article-headers)
1205 (inhibit-point-motion-hooks t)
1206 elem)
1207 (article-narrow-to-head)
1208 (while list
1209 (setq elem (pop list))
1210 (goto-char (point-min))
1211 (cond
1212 ;; Hide empty headers.
1213 ((eq elem 'empty)
1214 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1215 (forward-line -1)
1216 (gnus-article-hide-text-type
1217 (progn (beginning-of-line) (point))
1218 (progn
1219 (end-of-line)
1220 (if (re-search-forward "^[^ \t]" nil t)
1221 (match-beginning 0)
1222 (point-max)))
1223 'boring-headers)))
1224 ;; Hide boring Newsgroups header.
1225 ((eq elem 'newsgroups)
1226 (when (equal (gnus-fetch-field "newsgroups")
1227 (gnus-group-real-name
1228 (if (boundp 'gnus-newsgroup-name)
1229 gnus-newsgroup-name
1230 "")))
1231 (gnus-article-hide-header "newsgroups")))
1232 ((eq elem 'followup-to)
1233 (when (equal (message-fetch-field "followup-to")
1234 (message-fetch-field "newsgroups"))
1235 (gnus-article-hide-header "followup-to")))
1236 ((eq elem 'reply-to)
1237 (let ((from (message-fetch-field "from"))
1238 (reply-to (message-fetch-field "reply-to")))
1239 (when (and
1240 from reply-to
1241 (ignore-errors
1242 (equal
1243 (nth 1 (mail-extract-address-components from))
1244 (nth 1 (mail-extract-address-components reply-to)))))
1245 (gnus-article-hide-header "reply-to"))))
1246 ((eq elem 'date)
1247 (let ((date (message-fetch-field "date")))
1248 (when (and date
1249 (< (days-between (current-time-string) date)
1251 (gnus-article-hide-header "date"))))
1252 ((eq elem 'long-to)
1253 (let ((to (message-fetch-field "to"))
1254 (cc (message-fetch-field "cc")))
1255 (when (> (length to) 1024)
1256 (gnus-article-hide-header "to"))
1257 (when (> (length cc) 1024)
1258 (gnus-article-hide-header "cc"))))
1259 ((eq elem 'many-to)
1260 (let ((to-count 0)
1261 (cc-count 0))
1262 (goto-char (point-min))
1263 (while (re-search-forward "^to:" nil t)
1264 (setq to-count (1+ to-count)))
1265 (when (> to-count 1)
1266 (while (> to-count 0)
1267 (goto-char (point-min))
1268 (save-restriction
1269 (re-search-forward "^to:" nil nil to-count)
1270 (forward-line -1)
1271 (narrow-to-region (point) (point-max))
1272 (gnus-article-hide-header "to"))
1273 (setq to-count (1- to-count))))
1274 (goto-char (point-min))
1275 (while (re-search-forward "^cc:" nil t)
1276 (setq cc-count (1+ cc-count)))
1277 (when (> cc-count 1)
1278 (while (> cc-count 0)
1279 (goto-char (point-min))
1280 (save-restriction
1281 (re-search-forward "^cc:" nil nil cc-count)
1282 (forward-line -1)
1283 (narrow-to-region (point) (point-max))
1284 (gnus-article-hide-header "cc"))
1285 (setq cc-count (1- cc-count)))))))))))))
1287 (defun gnus-article-hide-header (header)
1288 (save-excursion
1289 (goto-char (point-min))
1290 (when (re-search-forward (concat "^" header ":") nil t)
1291 (gnus-article-hide-text-type
1292 (progn (beginning-of-line) (point))
1293 (progn
1294 (end-of-line)
1295 (if (re-search-forward "^[^ \t]" nil t)
1296 (match-beginning 0)
1297 (point-max)))
1298 'boring-headers))))
1300 (defvar gnus-article-normalized-header-length 40
1301 "Length of normalized headers.")
1303 (defun article-normalize-headers ()
1304 "Make all header lines 40 characters long."
1305 (interactive)
1306 (let ((buffer-read-only nil)
1307 column)
1308 (save-excursion
1309 (save-restriction
1310 (article-narrow-to-head)
1311 (while (not (eobp))
1312 (cond
1313 ((< (setq column (- (gnus-point-at-eol) (point)))
1314 gnus-article-normalized-header-length)
1315 (end-of-line)
1316 (insert (make-string
1317 (- gnus-article-normalized-header-length column)
1318 ? )))
1319 ((> column gnus-article-normalized-header-length)
1320 (gnus-put-text-property
1321 (progn
1322 (forward-char gnus-article-normalized-header-length)
1323 (point))
1324 (gnus-point-at-eol)
1325 'invisible t))
1327 ;; Do nothing.
1329 (forward-line 1))))))
1331 (defun article-treat-dumbquotes ()
1332 "Translate M****s*** sm*rtq**t*s into proper text.
1333 Note that this function guesses whether a character is a sm*rtq**t* or
1334 not, so it should only be used interactively.
1336 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1337 in an attempt to provide more quoting characters. If you see
1338 something like \\222 or \\264 where you're expecting some kind of
1339 apostrophe or quotation mark, then try this wash."
1340 (interactive)
1341 (article-translate-strings gnus-article-dumbquotes-map))
1343 (defun article-translate-characters (from to)
1344 "Translate all characters in the body of the article according to FROM and TO.
1345 FROM is a string of characters to translate from; to is a string of
1346 characters to translate to."
1347 (save-excursion
1348 (when (article-goto-body)
1349 (let ((buffer-read-only nil)
1350 (x (make-string 225 ?x))
1351 (i -1))
1352 (while (< (incf i) (length x))
1353 (aset x i i))
1354 (setq i 0)
1355 (while (< i (length from))
1356 (aset x (aref from i) (aref to i))
1357 (incf i))
1358 (translate-region (point) (point-max) x)))))
1360 (defun article-translate-strings (map)
1361 "Translate all string in the body of the article according to MAP.
1362 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1363 (save-excursion
1364 (when (article-goto-body)
1365 (let ((buffer-read-only nil)
1366 elem)
1367 (while (setq elem (pop map))
1368 (save-excursion
1369 (while (search-forward (car elem) nil t)
1370 (replace-match (cadr elem)))))))))
1372 (defun article-treat-overstrike ()
1373 "Translate overstrikes into bold text."
1374 (interactive)
1375 (save-excursion
1376 (when (article-goto-body)
1377 (let ((buffer-read-only nil))
1378 (while (search-forward "\b" nil t)
1379 (let ((next (char-after))
1380 (previous (char-after (- (point) 2))))
1381 ;; We do the boldification/underlining by hiding the
1382 ;; overstrikes and putting the proper text property
1383 ;; on the letters.
1384 (cond
1385 ((eq next previous)
1386 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1387 (put-text-property (point) (1+ (point)) 'face 'bold))
1388 ((eq next ?_)
1389 (gnus-article-hide-text-type
1390 (1- (point)) (1+ (point)) 'overstrike)
1391 (put-text-property
1392 (- (point) 2) (1- (point)) 'face 'underline))
1393 ((eq previous ?_)
1394 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1395 (put-text-property
1396 (point) (1+ (point)) 'face 'underline)))))))))
1398 (defun article-fill-long-lines ()
1399 "Fill lines that are wider than the window width."
1400 (interactive)
1401 (save-excursion
1402 (let ((buffer-read-only nil)
1403 (width (window-width (get-buffer-window (current-buffer)))))
1404 (save-restriction
1405 (article-goto-body)
1406 (let ((adaptive-fill-mode nil)) ;Why? -sm
1407 (while (not (eobp))
1408 (end-of-line)
1409 (when (>= (current-column) (min fill-column width))
1410 (narrow-to-region (point) (gnus-point-at-bol))
1411 (fill-paragraph nil)
1412 (goto-char (point-max))
1413 (widen))
1414 (forward-line 1)))))))
1416 (defun article-capitalize-sentences ()
1417 "Capitalize the first word in each sentence."
1418 (interactive)
1419 (save-excursion
1420 (let ((buffer-read-only nil)
1421 (paragraph-start "^[\n\^L]"))
1422 (article-goto-body)
1423 (while (not (eobp))
1424 (capitalize-word 1)
1425 (forward-sentence)))))
1427 (defun article-remove-cr ()
1428 "Remove trailing CRs and then translate remaining CRs into LFs."
1429 (interactive)
1430 (save-excursion
1431 (let ((buffer-read-only nil))
1432 (goto-char (point-min))
1433 (while (re-search-forward "\r+$" nil t)
1434 (replace-match "" t t))
1435 (goto-char (point-min))
1436 (while (search-forward "\r" nil t)
1437 (replace-match "\n" t t)))))
1439 (defun article-remove-trailing-blank-lines ()
1440 "Remove all trailing blank lines from the article."
1441 (interactive)
1442 (save-excursion
1443 (let ((buffer-read-only nil))
1444 (goto-char (point-max))
1445 (delete-region
1446 (point)
1447 (progn
1448 (while (and (not (bobp))
1449 (looking-at "^[ \t]*$")
1450 (not (gnus-annotation-in-region-p
1451 (point) (gnus-point-at-eol))))
1452 (forward-line -1))
1453 (forward-line 1)
1454 (point))))))
1456 (defun article-display-x-face (&optional force)
1457 "Look for an X-Face header and display it if present."
1458 (interactive (list 'force))
1459 (save-excursion
1460 ;; Delete the old process, if any.
1461 (when (process-status "article-x-face")
1462 (delete-process "article-x-face"))
1463 (let ((inhibit-point-motion-hooks t)
1464 (case-fold-search t)
1465 from last)
1466 (save-restriction
1467 (article-narrow-to-head)
1468 (goto-char (point-min))
1469 (setq from (message-fetch-field "from"))
1470 (goto-char (point-min))
1471 (while (and gnus-article-x-face-command
1472 (not last)
1473 (or force
1474 ;; Check whether this face is censored.
1475 (not gnus-article-x-face-too-ugly)
1476 (and gnus-article-x-face-too-ugly from
1477 (not (string-match gnus-article-x-face-too-ugly
1478 from))))
1479 ;; Has to be present.
1480 (re-search-forward "^X-Face: " nil t))
1481 ;; This used to try to do multiple faces (`while' instead of
1482 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1483 ;; work (b) it can crash some versions of Emacs (c) are
1484 ;; multiple faces really something to encourage?
1485 (when (stringp gnus-article-x-face-command)
1486 (setq last t))
1487 ;; We now have the area of the buffer where the X-Face is stored.
1488 (save-excursion
1489 (let ((beg (point))
1490 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1491 ;; We display the face.
1492 (if (symbolp gnus-article-x-face-command)
1493 ;; The command is a lisp function, so we call it.
1494 (if (gnus-functionp gnus-article-x-face-command)
1495 (funcall gnus-article-x-face-command beg end)
1496 (error "%s is not a function" gnus-article-x-face-command))
1497 ;; The command is a string, so we interpret the command
1498 ;; as a, well, command, and fork it off.
1499 (let ((process-connection-type nil))
1500 (process-kill-without-query
1501 (start-process
1502 "article-x-face" nil shell-file-name shell-command-switch
1503 gnus-article-x-face-command))
1504 (process-send-region "article-x-face" beg end)
1505 (process-send-eof "article-x-face"))))))))))
1507 (defun article-decode-mime-words ()
1508 "Decode all MIME-encoded words in the article."
1509 (interactive)
1510 (save-excursion
1511 (set-buffer gnus-article-buffer)
1512 (let ((inhibit-point-motion-hooks t)
1513 buffer-read-only
1514 (mail-parse-charset gnus-newsgroup-charset)
1515 (mail-parse-ignored-charsets
1516 (save-excursion (set-buffer gnus-summary-buffer)
1517 gnus-newsgroup-ignored-charsets)))
1518 (mail-decode-encoded-word-region (point-min) (point-max)))))
1520 (defun article-decode-charset (&optional prompt)
1521 "Decode charset-encoded text in the article.
1522 If PROMPT (the prefix), prompt for a coding system to use."
1523 (interactive "P")
1524 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1525 buffer-read-only
1526 (mail-parse-charset gnus-newsgroup-charset)
1527 (mail-parse-ignored-charsets
1528 (save-excursion (condition-case nil
1529 (set-buffer gnus-summary-buffer)
1530 (error))
1531 gnus-newsgroup-ignored-charsets))
1532 ct cte ctl charset format)
1533 (save-excursion
1534 (save-restriction
1535 (article-narrow-to-head)
1536 (setq ct (message-fetch-field "Content-Type" t)
1537 cte (message-fetch-field "Content-Transfer-Encoding" t)
1538 ctl (and ct (ignore-errors
1539 (mail-header-parse-content-type ct)))
1540 charset (cond
1541 (prompt
1542 (mm-read-coding-system "Charset to decode: "))
1543 (ctl
1544 (mail-content-type-get ctl 'charset)))
1545 format (and ctl (mail-content-type-get ctl 'format)))
1546 (when cte
1547 (setq cte (mail-header-strip cte)))
1548 (if (and ctl (not (string-match "/" (car ctl))))
1549 (setq ctl nil))
1550 (goto-char (point-max)))
1551 (forward-line 1)
1552 (save-restriction
1553 (narrow-to-region (point) (point-max))
1554 (when (and (eq mail-parse-charset 'gnus-decoded)
1555 (eq (mm-body-7-or-8) '8bit))
1556 ;; The text code could have been decoded.
1557 (setq charset mail-parse-charset))
1558 (when (and (or (not ctl)
1559 (equal (car ctl) "text/plain"))
1560 (not format)) ;; article with format will decode later.
1561 (mm-decode-body
1562 charset (and cte (intern (downcase
1563 (gnus-strip-whitespace cte))))
1564 (car ctl)))))))
1566 (defun article-decode-encoded-words ()
1567 "Remove encoded-word encoding from headers."
1568 (let ((inhibit-point-motion-hooks t)
1569 (mail-parse-charset gnus-newsgroup-charset)
1570 (mail-parse-ignored-charsets
1571 (save-excursion (condition-case nil
1572 (set-buffer gnus-summary-buffer)
1573 (error))
1574 gnus-newsgroup-ignored-charsets))
1575 buffer-read-only)
1576 (save-restriction
1577 (article-narrow-to-head)
1578 (funcall gnus-decode-header-function (point-min) (point-max)))))
1580 (defun article-de-quoted-unreadable (&optional force)
1581 "Translate a quoted-printable-encoded article.
1582 If FORCE, decode the article whether it is marked as quoted-printable
1583 or not."
1584 (interactive (list 'force))
1585 (save-excursion
1586 (let ((buffer-read-only nil) type charset)
1587 (if (gnus-buffer-live-p gnus-original-article-buffer)
1588 (with-current-buffer gnus-original-article-buffer
1589 (setq type
1590 (gnus-fetch-field "content-transfer-encoding"))
1591 (let* ((ct (gnus-fetch-field "content-type"))
1592 (ctl (and ct
1593 (ignore-errors
1594 (mail-header-parse-content-type ct)))))
1595 (setq charset (and ctl
1596 (mail-content-type-get ctl 'charset)))
1597 (if (stringp charset)
1598 (setq charset (intern (downcase charset)))))))
1599 (unless charset
1600 (setq charset gnus-newsgroup-charset))
1601 (when (or force
1602 (and type (let ((case-fold-search t))
1603 (string-match "quoted-printable" type))))
1604 (article-goto-body)
1605 (quoted-printable-decode-region
1606 (point) (point-max) (mm-charset-to-coding-system charset))))))
1608 (defun article-de-base64-unreadable (&optional force)
1609 "Translate a base64 article.
1610 If FORCE, decode the article whether it is marked as base64 not."
1611 (interactive (list 'force))
1612 (save-excursion
1613 (let ((buffer-read-only nil) type charset)
1614 (if (gnus-buffer-live-p gnus-original-article-buffer)
1615 (with-current-buffer gnus-original-article-buffer
1616 (setq type
1617 (gnus-fetch-field "content-transfer-encoding"))
1618 (let* ((ct (gnus-fetch-field "content-type"))
1619 (ctl (and ct
1620 (ignore-errors
1621 (mail-header-parse-content-type ct)))))
1622 (setq charset (and ctl
1623 (mail-content-type-get ctl 'charset)))
1624 (if (stringp charset)
1625 (setq charset (intern (downcase charset)))))))
1626 (unless charset
1627 (setq charset gnus-newsgroup-charset))
1628 (when (or force
1629 (and type (let ((case-fold-search t))
1630 (string-match "base64" type))))
1631 (article-goto-body)
1632 (save-restriction
1633 (narrow-to-region (point) (point-max))
1634 (base64-decode-region (point-min) (point-max))
1635 (mm-decode-coding-region
1636 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1638 (eval-when-compile
1639 (require 'rfc1843))
1641 (defun article-decode-HZ ()
1642 "Translate a HZ-encoded article."
1643 (interactive)
1644 (require 'rfc1843)
1645 (save-excursion
1646 (let ((buffer-read-only nil))
1647 (rfc1843-decode-region (point-min) (point-max)))))
1649 (defun article-wash-html ()
1650 "Format an html article."
1651 (interactive)
1652 (save-excursion
1653 (let ((buffer-read-only nil)
1654 charset)
1655 (if (gnus-buffer-live-p gnus-original-article-buffer)
1656 (with-current-buffer gnus-original-article-buffer
1657 (let* ((ct (gnus-fetch-field "content-type"))
1658 (ctl (and ct
1659 (ignore-errors
1660 (mail-header-parse-content-type ct)))))
1661 (setq charset (and ctl
1662 (mail-content-type-get ctl 'charset)))
1663 (if (stringp charset)
1664 (setq charset (intern (downcase charset)))))))
1665 (unless charset
1666 (setq charset gnus-newsgroup-charset))
1667 (article-goto-body)
1668 (save-window-excursion
1669 (save-restriction
1670 (narrow-to-region (point) (point-max))
1671 (mm-setup-w3)
1672 (let ((w3-strict-width (window-width))
1673 (url-gateway-unplugged t)
1674 (url-standalone-mode t))
1675 (condition-case var
1676 (w3-region (point-min) (point-max))
1677 (error))))))))
1679 (defun article-hide-list-identifiers ()
1680 "Remove list identifies from the Subject header.
1681 The `gnus-list-identifiers' variable specifies what to do."
1682 (interactive)
1683 (save-excursion
1684 (save-restriction
1685 (let ((inhibit-point-motion-hooks t)
1686 buffer-read-only)
1687 (article-narrow-to-head)
1688 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1689 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1690 (when regexp
1691 (goto-char (point-min))
1692 (when (re-search-forward
1693 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1694 " *\\)\\)+\\(Re: +\\)?\\)")
1695 nil t)
1696 (let ((s (or (match-string 3) (match-string 5))))
1697 (delete-region (match-beginning 1) (match-end 1))
1698 (when s
1699 (goto-char (match-beginning 1))
1700 (insert s))))))))))
1702 (defun article-hide-pgp ()
1703 "Remove any PGP headers and signatures in the current article."
1704 (interactive)
1705 (save-excursion
1706 (save-restriction
1707 (let ((inhibit-point-motion-hooks t)
1708 buffer-read-only beg end)
1709 (article-goto-body)
1710 ;; Hide the "header".
1711 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1712 (push 'pgp gnus-article-wash-types)
1713 (delete-region (match-beginning 0) (match-end 0))
1714 ;; Remove armor headers (rfc2440 6.2)
1715 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1716 (point)))
1717 (setq beg (point))
1718 ;; Hide the actual signature.
1719 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1720 (setq end (1+ (match-beginning 0)))
1721 (delete-region
1723 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1724 (match-end 0)
1725 ;; Perhaps we shouldn't hide to the end of the buffer
1726 ;; if there is no end to the signature?
1727 (point-max))))
1728 ;; Hide "- " PGP quotation markers.
1729 (when (and beg end)
1730 (narrow-to-region beg end)
1731 (goto-char (point-min))
1732 (while (re-search-forward "^- " nil t)
1733 (delete-region
1734 (match-beginning 0) (match-end 0)))
1735 (widen))
1736 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1738 (defun article-hide-pem (&optional arg)
1739 "Toggle hiding of any PEM headers and signatures in the current article.
1740 If given a negative prefix, always show; if given a positive prefix,
1741 always hide."
1742 (interactive (gnus-article-hidden-arg))
1743 (unless (gnus-article-check-hidden-text 'pem arg)
1744 (save-excursion
1745 (let (buffer-read-only end)
1746 (goto-char (point-min))
1747 ;; Hide the horrendously ugly "header".
1748 (when (and (search-forward
1749 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1750 nil t)
1751 (setq end (1+ (match-beginning 0))))
1752 (push 'pem gnus-article-wash-types)
1753 (gnus-article-hide-text-type
1755 (if (search-forward "\n\n" nil t)
1756 (match-end 0)
1757 (point-max))
1758 'pem)
1759 ;; Hide the trailer as well
1760 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1761 nil t)
1762 (gnus-article-hide-text-type
1763 (match-beginning 0) (match-end 0) 'pem)))))))
1765 (defun article-strip-banner ()
1766 "Strip the banner specified by the `banner' group parameter."
1767 (interactive)
1768 (save-excursion
1769 (save-restriction
1770 (let ((inhibit-point-motion-hooks t)
1771 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1772 (gnus-signature-limit nil)
1773 buffer-read-only beg end)
1774 (when banner
1775 (article-goto-body)
1776 (cond
1777 ((eq banner 'signature)
1778 (when (gnus-article-narrow-to-signature)
1779 (widen)
1780 (forward-line -1)
1781 (delete-region (point) (point-max))))
1782 ((symbolp banner)
1783 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1784 (while (re-search-forward banner nil t)
1785 (delete-region (match-beginning 0) (match-end 0)))))
1786 ((stringp banner)
1787 (while (re-search-forward banner nil t)
1788 (delete-region (match-beginning 0) (match-end 0))))))))))
1790 (defun article-babel ()
1791 "Translate article using an online translation service."
1792 (interactive)
1793 (require 'babel)
1794 (save-excursion
1795 (set-buffer gnus-article-buffer)
1796 (when (article-goto-body)
1797 (let* ((buffer-read-only nil)
1798 (start (point))
1799 (end (point-max))
1800 (orig (buffer-substring start end))
1801 (trans (babel-as-string orig)))
1802 (save-restriction
1803 (narrow-to-region start end)
1804 (delete-region start end)
1805 (insert trans))))))
1807 (defun article-hide-signature (&optional arg)
1808 "Hide the signature in the current article.
1809 If given a negative prefix, always show; if given a positive prefix,
1810 always hide."
1811 (interactive (gnus-article-hidden-arg))
1812 (unless (gnus-article-check-hidden-text 'signature arg)
1813 (save-excursion
1814 (save-restriction
1815 (let ((buffer-read-only nil))
1816 (when (gnus-article-narrow-to-signature)
1817 (gnus-article-hide-text-type
1818 (point-min) (point-max) 'signature)))))))
1820 (defun article-strip-headers-in-body ()
1821 "Strip offensive headers from bodies."
1822 (interactive)
1823 (save-excursion
1824 (article-goto-body)
1825 (let ((case-fold-search t))
1826 (when (looking-at "x-no-archive:")
1827 (gnus-delete-line)))))
1829 (defun article-strip-leading-blank-lines ()
1830 "Remove all blank lines from the beginning of the article."
1831 (interactive)
1832 (save-excursion
1833 (let ((inhibit-point-motion-hooks t)
1834 buffer-read-only)
1835 (when (article-goto-body)
1836 (while (and (not (eobp))
1837 (looking-at "[ \t]*$"))
1838 (gnus-delete-line))))))
1840 (defun article-narrow-to-head ()
1841 "Narrow the buffer to the head of the message.
1842 Point is left at the beginning of the narrowed-to region."
1843 (narrow-to-region
1844 (goto-char (point-min))
1845 (if (search-forward "\n\n" nil 1)
1846 (1- (point))
1847 (point-max)))
1848 (goto-char (point-min)))
1850 (defun article-goto-body ()
1851 "Place point at the start of the body."
1852 (goto-char (point-min))
1853 (cond
1854 ;; This variable is only bound when dealing with separate
1855 ;; MIME body parts.
1856 (article-goto-body-goes-to-point-min-p
1858 ((search-forward "\n\n" nil t)
1861 (goto-char (point-max))
1862 nil)))
1864 (defun article-strip-multiple-blank-lines ()
1865 "Replace consecutive blank lines with one empty line."
1866 (interactive)
1867 (save-excursion
1868 (let ((inhibit-point-motion-hooks t)
1869 buffer-read-only)
1870 ;; First make all blank lines empty.
1871 (article-goto-body)
1872 (while (re-search-forward "^[ \t]+$" nil t)
1873 (unless (gnus-annotation-in-region-p
1874 (match-beginning 0) (match-end 0))
1875 (replace-match "" nil t)))
1876 ;; Then replace multiple empty lines with a single empty line.
1877 (article-goto-body)
1878 (while (re-search-forward "\n\n\n+" nil t)
1879 (unless (gnus-annotation-in-region-p
1880 (match-beginning 0) (match-end 0))
1881 (replace-match "\n\n" t t))))))
1883 (defun article-strip-leading-space ()
1884 "Remove all white space from the beginning of the lines in the article."
1885 (interactive)
1886 (save-excursion
1887 (let ((inhibit-point-motion-hooks t)
1888 buffer-read-only)
1889 (article-goto-body)
1890 (while (re-search-forward "^[ \t]+" nil t)
1891 (replace-match "" t t)))))
1893 (defun article-strip-trailing-space ()
1894 "Remove all white space from the end of the lines in the article."
1895 (interactive)
1896 (save-excursion
1897 (let ((inhibit-point-motion-hooks t)
1898 buffer-read-only)
1899 (article-goto-body)
1900 (while (re-search-forward "[ \t]+$" nil t)
1901 (replace-match "" t t)))))
1903 (defun article-strip-blank-lines ()
1904 "Strip leading, trailing and multiple blank lines."
1905 (interactive)
1906 (article-strip-leading-blank-lines)
1907 (article-remove-trailing-blank-lines)
1908 (article-strip-multiple-blank-lines))
1910 (defun article-strip-all-blank-lines ()
1911 "Strip all blank lines."
1912 (interactive)
1913 (save-excursion
1914 (let ((inhibit-point-motion-hooks t)
1915 buffer-read-only)
1916 (article-goto-body)
1917 (while (re-search-forward "^[ \t]*\n" nil t)
1918 (replace-match "" t t)))))
1920 (defun gnus-article-narrow-to-signature ()
1921 "Narrow to the signature; return t if a signature is found, else nil."
1922 (let ((inhibit-point-motion-hooks t))
1923 (when (gnus-article-search-signature)
1924 (forward-line 1)
1925 ;; Check whether we have some limits to what we consider
1926 ;; to be a signature.
1927 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1928 (list gnus-signature-limit)))
1929 limit limited)
1930 (while (setq limit (pop limits))
1931 (if (or (and (integerp limit)
1932 (< (- (point-max) (point)) limit))
1933 (and (floatp limit)
1934 (< (count-lines (point) (point-max)) limit))
1935 (and (gnus-functionp limit)
1936 (funcall limit))
1937 (and (stringp limit)
1938 (not (re-search-forward limit nil t))))
1939 () ; This limit did not succeed.
1940 (setq limited t
1941 limits nil)))
1942 (unless limited
1943 (narrow-to-region (point) (point-max))
1944 t)))))
1946 (defun gnus-article-search-signature ()
1947 "Search the current buffer for the signature separator.
1948 Put point at the beginning of the signature separator."
1949 (let ((cur (point)))
1950 (goto-char (point-max))
1951 (if (if (stringp gnus-signature-separator)
1952 (re-search-backward gnus-signature-separator nil t)
1953 (let ((seps gnus-signature-separator))
1954 (while (and seps
1955 (not (re-search-backward (car seps) nil t)))
1956 (pop seps))
1957 seps))
1959 (goto-char cur)
1960 nil)))
1962 (defun gnus-article-hidden-arg ()
1963 "Return the current prefix arg as a number, or 0 if no prefix."
1964 (list (if current-prefix-arg
1965 (prefix-numeric-value current-prefix-arg)
1966 0)))
1968 (defun gnus-article-check-hidden-text (type arg)
1969 "Return nil if hiding is necessary.
1970 Arg can be nil or a number. nil and positive means hide, negative
1971 means show, 0 means toggle."
1972 (save-excursion
1973 (save-restriction
1974 (let ((hide (gnus-article-hidden-text-p type)))
1975 (cond
1976 ((or (null arg)
1977 (> arg 0))
1978 nil)
1979 ((< arg 0)
1980 (gnus-article-show-hidden-text type)
1983 (if (eq hide 'hidden)
1984 (progn
1985 (gnus-article-show-hidden-text type)
1987 nil)))))))
1989 (defun gnus-article-hidden-text-p (type)
1990 "Say whether the current buffer contains hidden text of type TYPE."
1991 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1992 (while (and pos
1993 (not (get-text-property pos 'invisible))
1994 (not (get-text-property pos 'dummy-invisible)))
1995 (setq pos
1996 (text-property-any (1+ pos) (point-max) 'article-type type)))
1997 (if pos
1998 'hidden
1999 nil)))
2001 (defun gnus-article-show-hidden-text (type &optional dummy)
2002 "Show all hidden text of type TYPE.
2003 Originally it is hide instead of DUMMY."
2004 (let ((buffer-read-only nil)
2005 (inhibit-point-motion-hooks t))
2006 (gnus-remove-text-properties-when
2007 'article-type type
2008 (point-min) (point-max)
2009 (cons 'article-type (cons type
2010 gnus-hidden-properties)))))
2012 (defconst article-time-units
2013 `((year . ,(* 365.25 24 60 60))
2014 (week . ,(* 7 24 60 60))
2015 (day . ,(* 24 60 60))
2016 (hour . ,(* 60 60))
2017 (minute . 60)
2018 (second . 1))
2019 "Mapping from time units to seconds.")
2021 (defun article-date-ut (&optional type highlight header)
2022 "Convert DATE date to universal time in the current article.
2023 If TYPE is `local', convert to local time; if it is `lapsed', output
2024 how much time has lapsed since DATE. For `lapsed', the value of
2025 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2026 should replace the \"Date:\" one, or should be added below it."
2027 (interactive (list 'ut t))
2028 (let* ((header (or header
2029 (message-fetch-field "date")
2030 ""))
2031 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2032 (date-regexp
2033 (cond
2034 ((not gnus-article-date-lapsed-new-header)
2035 tdate-regexp)
2036 ((eq type 'lapsed)
2037 "^X-Sent:[ \t]")
2039 "^Date:[ \t]")))
2040 (date (if (vectorp header) (mail-header-date header)
2041 header))
2042 (inhibit-point-motion-hooks t)
2044 bface eface)
2045 (save-excursion
2046 (save-restriction
2047 (article-narrow-to-head)
2048 (when (re-search-forward tdate-regexp nil t)
2049 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2050 date (or (get-text-property (gnus-point-at-bol)
2051 'original-date)
2052 date)
2053 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2054 (forward-line 1))
2055 (when (and date (not (string= date "")))
2056 (goto-char (point-min))
2057 (let ((buffer-read-only nil))
2058 ;; Delete any old Date headers.
2059 (while (re-search-forward date-regexp nil t)
2060 (if pos
2061 (delete-region (progn (beginning-of-line) (point))
2062 (progn (forward-line 1) (point)))
2063 (delete-region (progn (beginning-of-line) (point))
2064 (progn (end-of-line) (point)))
2065 (setq pos (point))))
2066 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2067 (forward-line 1))
2068 (if pos (goto-char pos))
2069 (insert (article-make-date-line date (or type 'ut)))
2070 (when (not pos)
2071 (insert "\n")
2072 (forward-line -1))
2073 ;; Do highlighting.
2074 (beginning-of-line)
2075 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2076 (put-text-property (match-beginning 1) (1+ (match-end 1))
2077 'original-date date)
2078 (put-text-property (match-beginning 1) (1+ (match-end 1))
2079 'face bface)
2080 (put-text-property (match-beginning 2) (match-end 2)
2081 'face eface))))))))
2083 (defun article-make-date-line (date type)
2084 "Return a DATE line of TYPE."
2085 (let ((time (condition-case ()
2086 (date-to-time date)
2087 (error '(0 0)))))
2088 (cond
2089 ;; Convert to the local timezone. We have to slap a
2090 ;; `condition-case' round the calls to the timezone
2091 ;; functions since they aren't particularly resistant to
2092 ;; buggy dates.
2093 ((eq type 'local)
2094 (let ((tz (car (current-time-zone time))))
2095 (format "Date: %s %s%02d%02d" (current-time-string time)
2096 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2097 (/ (% (abs tz) 3600) 60))))
2098 ;; Convert to Universal Time.
2099 ((eq type 'ut)
2100 (concat "Date: "
2101 (current-time-string
2102 (let* ((e (parse-time-string date))
2103 (tm (apply 'encode-time e))
2104 (ms (car tm))
2105 (ls (- (cadr tm) (car (current-time-zone time)))))
2106 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2107 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2108 (t (list ms ls)))))
2109 " UT"))
2110 ;; Get the original date from the article.
2111 ((eq type 'original)
2112 (concat "Date: " (if (string-match "\n+$" date)
2113 (substring date 0 (match-beginning 0))
2114 date)))
2115 ;; Let the user define the format.
2116 ((eq type 'user)
2117 (if (gnus-functionp gnus-article-time-format)
2118 (funcall gnus-article-time-format time)
2119 (concat
2120 "Date: "
2121 (format-time-string gnus-article-time-format time))))
2122 ;; ISO 8601.
2123 ((eq type 'iso8601)
2124 (let ((tz (car (current-time-zone time))))
2125 (concat
2126 "Date: "
2127 (format-time-string "%Y%m%dT%H%M%S" time)
2128 (format "%s%02d%02d"
2129 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2130 (/ (% (abs tz) 3600) 60)))))
2131 ;; Do an X-Sent lapsed format.
2132 ((eq type 'lapsed)
2133 ;; If the date is seriously mangled, the timezone functions are
2134 ;; liable to bug out, so we ignore all errors.
2135 (let* ((now (current-time))
2136 (real-time (subtract-time now time))
2137 (real-sec (and real-time
2138 (+ (* (float (car real-time)) 65536)
2139 (cadr real-time))))
2140 (sec (and real-time (abs real-sec)))
2141 num prev)
2142 (cond
2143 ((null real-time)
2144 "X-Sent: Unknown")
2145 ((zerop sec)
2146 "X-Sent: Now")
2148 (concat
2149 "X-Sent: "
2150 ;; This is a bit convoluted, but basically we go
2151 ;; through the time units for years, weeks, etc,
2152 ;; and divide things to see whether that results
2153 ;; in positive answers.
2154 (mapconcat
2155 (lambda (unit)
2156 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2157 ;; The (remaining) seconds are too few to
2158 ;; be divided into this time unit.
2160 ;; It's big enough, so we output it.
2161 (setq sec (- sec (* num (cdr unit))))
2162 (prog1
2163 (concat (if prev ", " "") (int-to-string
2164 (floor num))
2165 " " (symbol-name (car unit))
2166 (if (> num 1) "s" ""))
2167 (setq prev t))))
2168 article-time-units "")
2169 ;; If dates are odd, then it might appear like the
2170 ;; article was sent in the future.
2171 (if (> real-sec 0)
2172 " ago"
2173 " in the future"))))))
2175 (error "Unknown conversion type: %s" type)))))
2177 (defun article-date-local (&optional highlight)
2178 "Convert the current article date to the local timezone."
2179 (interactive (list t))
2180 (article-date-ut 'local highlight))
2182 (defun article-date-original (&optional highlight)
2183 "Convert the current article date to what it was originally.
2184 This is only useful if you have used some other date conversion
2185 function and want to see what the date was before converting."
2186 (interactive (list t))
2187 (article-date-ut 'original highlight))
2189 (defun article-date-lapsed (&optional highlight)
2190 "Convert the current article date to time lapsed since it was sent."
2191 (interactive (list t))
2192 (article-date-ut 'lapsed highlight))
2194 (defun article-update-date-lapsed ()
2195 "Function to be run from a timer to update the lapsed time line."
2196 (let (deactivate-mark)
2197 (save-excursion
2198 (ignore-errors
2199 (walk-windows
2200 (lambda (w)
2201 (set-buffer (window-buffer w))
2202 (when (eq major-mode 'gnus-article-mode)
2203 (goto-char (point-min))
2204 (when (re-search-forward "^X-Sent:" nil t)
2205 (article-date-lapsed t))))
2206 nil 'visible)))))
2208 (defun gnus-start-date-timer (&optional n)
2209 "Start a timer to update the X-Sent header in the article buffers.
2210 The numerical prefix says how frequently (in seconds) the function
2211 is to run."
2212 (interactive "p")
2213 (unless n
2214 (setq n 1))
2215 (gnus-stop-date-timer)
2216 (setq article-lapsed-timer
2217 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2219 (defun gnus-stop-date-timer ()
2220 "Stop the X-Sent timer."
2221 (interactive)
2222 (when article-lapsed-timer
2223 (nnheader-cancel-timer article-lapsed-timer)
2224 (setq article-lapsed-timer nil)))
2226 (defun article-date-user (&optional highlight)
2227 "Convert the current article date to the user-defined format.
2228 This format is defined by the `gnus-article-time-format' variable."
2229 (interactive (list t))
2230 (article-date-ut 'user highlight))
2232 (defun article-date-iso8601 (&optional highlight)
2233 "Convert the current article date to ISO8601."
2234 (interactive (list t))
2235 (article-date-ut 'iso8601 highlight))
2237 (defun article-show-all ()
2238 "Show all hidden text in the article buffer."
2239 (interactive)
2240 (save-excursion
2241 (let ((buffer-read-only nil))
2242 (gnus-article-unhide-text (point-min) (point-max)))))
2244 (defun article-emphasize (&optional arg)
2245 "Emphasize text according to `gnus-emphasis-alist'."
2246 (interactive (gnus-article-hidden-arg))
2247 (unless (gnus-article-check-hidden-text 'emphasis arg)
2248 (save-excursion
2249 (let ((alist (or
2250 (condition-case nil
2251 (with-current-buffer gnus-summary-buffer
2252 gnus-article-emphasis-alist)
2253 (error))
2254 gnus-emphasis-alist))
2255 (buffer-read-only nil)
2256 (props (append '(article-type emphasis)
2257 gnus-hidden-properties))
2258 regexp elem beg invisible visible face)
2259 (article-goto-body)
2260 (setq beg (point))
2261 (while (setq elem (pop alist))
2262 (goto-char beg)
2263 (setq regexp (car elem)
2264 invisible (nth 1 elem)
2265 visible (nth 2 elem)
2266 face (nth 3 elem))
2267 (while (re-search-forward regexp nil t)
2268 (when (and (match-beginning visible) (match-beginning invisible))
2269 (push 'emphasis gnus-article-wash-types)
2270 (gnus-article-hide-text
2271 (match-beginning invisible) (match-end invisible) props)
2272 (gnus-article-unhide-text-type
2273 (match-beginning visible) (match-end visible) 'emphasis)
2274 (gnus-put-text-property-excluding-newlines
2275 (match-beginning visible) (match-end visible) 'face face)
2276 (goto-char (match-end invisible)))))))))
2278 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2279 "Setup newsgroup emphasis alist."
2280 (unless gnus-article-emphasis-alist
2281 (let ((name (and gnus-newsgroup-name
2282 (gnus-group-real-name gnus-newsgroup-name))))
2283 (make-local-variable 'gnus-article-emphasis-alist)
2284 (setq gnus-article-emphasis-alist
2285 (nconc
2286 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2287 (while (setq elem (pop alist))
2288 (when (and name (string-match (car elem) name))
2289 (setq alist nil
2290 highlight (copy-sequence (cdr elem)))))
2291 highlight)
2292 (copy-sequence highlight-words)
2293 (if gnus-newsgroup-name
2294 (copy-sequence (gnus-group-find-parameter
2295 gnus-newsgroup-name 'highlight-words t)))
2296 gnus-emphasis-alist)))))
2298 (eval-when-compile
2299 (defvar gnus-summary-article-menu)
2300 (defvar gnus-summary-post-menu))
2302 ;;; Saving functions.
2304 (defun gnus-article-save (save-buffer file &optional num)
2305 "Save the currently selected article."
2306 (unless gnus-save-all-headers
2307 ;; Remove headers according to `gnus-saved-headers'.
2308 (let ((gnus-visible-headers
2309 (or gnus-saved-headers gnus-visible-headers))
2310 (gnus-article-buffer save-buffer))
2311 (save-excursion
2312 (set-buffer save-buffer)
2313 (article-hide-headers 1 t))))
2314 (save-window-excursion
2315 (if (not gnus-default-article-saver)
2316 (error "No default saver is defined")
2317 ;; !!! Magic! The saving functions all save
2318 ;; `gnus-save-article-buffer' (or so they think), but we
2319 ;; bind that variable to our save-buffer.
2320 (set-buffer gnus-article-buffer)
2321 (let* ((gnus-save-article-buffer save-buffer)
2322 (filename
2323 (cond
2324 ((not gnus-prompt-before-saving) 'default)
2325 ((eq gnus-prompt-before-saving 'always) nil)
2326 (t file)))
2327 (gnus-number-of-articles-to-be-saved
2328 (when (eq gnus-prompt-before-saving t)
2329 num))) ; Magic
2330 (set-buffer gnus-article-current-summary)
2331 (funcall gnus-default-article-saver filename)))))
2333 (defun gnus-read-save-file-name (prompt &optional filename
2334 function group headers variable)
2335 (let ((default-name
2336 (funcall function group headers (symbol-value variable)))
2337 result)
2338 (setq result
2339 (expand-file-name
2340 (cond
2341 ((eq filename 'default)
2342 default-name)
2343 ((eq filename t)
2344 default-name)
2345 (filename filename)
2347 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2348 (prompt
2349 (format prompt
2350 (if (and gnus-number-of-articles-to-be-saved
2351 (> gnus-number-of-articles-to-be-saved 1))
2352 (format "these %d articles"
2353 gnus-number-of-articles-to-be-saved)
2354 "this article")))
2355 (file
2356 ;; Let the split methods have their say.
2357 (cond
2358 ;; No split name was found.
2359 ((null split-name)
2360 (read-file-name
2361 (concat prompt " (default "
2362 (file-name-nondirectory default-name) ") ")
2363 (file-name-directory default-name)
2364 default-name))
2365 ;; A single group name is returned.
2366 ((stringp split-name)
2367 (setq default-name
2368 (funcall function split-name headers
2369 (symbol-value variable)))
2370 (read-file-name
2371 (concat prompt " (default "
2372 (file-name-nondirectory default-name) ") ")
2373 (file-name-directory default-name)
2374 default-name))
2375 ;; A single split name was found
2376 ((= 1 (length split-name))
2377 (let* ((name (expand-file-name
2378 (car split-name) gnus-article-save-directory))
2379 (dir (cond ((file-directory-p name)
2380 (file-name-as-directory name))
2381 ((file-exists-p name) name)
2382 (t gnus-article-save-directory))))
2383 (read-file-name
2384 (concat prompt " (default " name ") ")
2385 dir name)))
2386 ;; A list of splits was found.
2388 (setq split-name (nreverse split-name))
2389 (let (result)
2390 (let ((file-name-history
2391 (nconc split-name file-name-history)))
2392 (setq result
2393 (expand-file-name
2394 (read-file-name
2395 (concat prompt " (`M-p' for defaults) ")
2396 gnus-article-save-directory
2397 (car split-name))
2398 gnus-article-save-directory)))
2399 (car (push result file-name-history)))))))
2400 ;; Create the directory.
2401 (gnus-make-directory (file-name-directory file))
2402 ;; If we have read a directory, we append the default file name.
2403 (when (file-directory-p file)
2404 (setq file (expand-file-name (file-name-nondirectory default-name)
2405 (file-name-as-directory file))))
2406 ;; Possibly translate some characters.
2407 (nnheader-translate-file-chars file))))))
2408 (gnus-make-directory (file-name-directory result))
2409 (set variable result)))
2411 (defun gnus-article-archive-name (group)
2412 "Return the first instance of an \"Archive-name\" in the current buffer."
2413 (let ((case-fold-search t))
2414 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2415 (nnheader-concat gnus-article-save-directory
2416 (match-string 1)))))
2418 (defun gnus-article-nndoc-name (group)
2419 "If GROUP is an nndoc group, return the name of the parent group."
2420 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2421 (gnus-group-get-parameter group 'save-article-group)))
2423 (defun gnus-summary-save-in-rmail (&optional filename)
2424 "Append this article to Rmail file.
2425 Optional argument FILENAME specifies file name.
2426 Directory to save to is default to `gnus-article-save-directory'."
2427 (setq filename (gnus-read-save-file-name
2428 "Save %s in rmail file:" filename
2429 gnus-rmail-save-name gnus-newsgroup-name
2430 gnus-current-headers 'gnus-newsgroup-last-rmail))
2431 (gnus-eval-in-buffer-window gnus-save-article-buffer
2432 (save-excursion
2433 (save-restriction
2434 (widen)
2435 (gnus-output-to-rmail filename))))
2436 filename)
2438 (defun gnus-summary-save-in-mail (&optional filename)
2439 "Append this article to Unix mail file.
2440 Optional argument FILENAME specifies file name.
2441 Directory to save to is default to `gnus-article-save-directory'."
2442 (setq filename (gnus-read-save-file-name
2443 "Save %s in Unix mail file:" filename
2444 gnus-mail-save-name gnus-newsgroup-name
2445 gnus-current-headers 'gnus-newsgroup-last-mail))
2446 (gnus-eval-in-buffer-window gnus-save-article-buffer
2447 (save-excursion
2448 (save-restriction
2449 (widen)
2450 (if (and (file-readable-p filename)
2451 (mail-file-babyl-p filename))
2452 (rmail-output-to-rmail-file filename t)
2453 (gnus-output-to-mail filename)))))
2454 filename)
2456 (defun gnus-summary-save-in-file (&optional filename overwrite)
2457 "Append this article to file.
2458 Optional argument FILENAME specifies file name.
2459 Directory to save to is default to `gnus-article-save-directory'."
2460 (setq filename (gnus-read-save-file-name
2461 "Save %s in file:" filename
2462 gnus-file-save-name gnus-newsgroup-name
2463 gnus-current-headers 'gnus-newsgroup-last-file))
2464 (gnus-eval-in-buffer-window gnus-save-article-buffer
2465 (save-excursion
2466 (save-restriction
2467 (widen)
2468 (when (and overwrite
2469 (file-exists-p filename))
2470 (delete-file filename))
2471 (gnus-output-to-file filename))))
2472 filename)
2474 (defun gnus-summary-write-to-file (&optional filename)
2475 "Write this article to a file.
2476 Optional argument FILENAME specifies file name.
2477 The directory to save in defaults to `gnus-article-save-directory'."
2478 (gnus-summary-save-in-file nil t))
2480 (defun gnus-summary-save-body-in-file (&optional filename)
2481 "Append this article body to a file.
2482 Optional argument FILENAME specifies file name.
2483 The directory to save in defaults to `gnus-article-save-directory'."
2484 (setq filename (gnus-read-save-file-name
2485 "Save %s body in file:" filename
2486 gnus-file-save-name gnus-newsgroup-name
2487 gnus-current-headers 'gnus-newsgroup-last-file))
2488 (gnus-eval-in-buffer-window gnus-save-article-buffer
2489 (save-excursion
2490 (save-restriction
2491 (widen)
2492 (when (article-goto-body)
2493 (narrow-to-region (point) (point-max)))
2494 (gnus-output-to-file filename))))
2495 filename)
2497 (defun gnus-summary-save-in-pipe (&optional command)
2498 "Pipe this article to subprocess."
2499 (setq command
2500 (cond ((and (eq command 'default)
2501 gnus-last-shell-command)
2502 gnus-last-shell-command)
2503 ((stringp command)
2504 command)
2505 (t (read-string
2506 (format
2507 "Shell command on %s: "
2508 (if (and gnus-number-of-articles-to-be-saved
2509 (> gnus-number-of-articles-to-be-saved 1))
2510 (format "these %d articles"
2511 gnus-number-of-articles-to-be-saved)
2512 "this article"))
2513 gnus-last-shell-command))))
2514 (when (string-equal command "")
2515 (if gnus-last-shell-command
2516 (setq command gnus-last-shell-command)
2517 (error "A command is required")))
2518 (gnus-eval-in-buffer-window gnus-article-buffer
2519 (save-restriction
2520 (widen)
2521 (shell-command-on-region (point-min) (point-max) command nil)))
2522 (setq gnus-last-shell-command command))
2524 ;;; Article file names when saving.
2526 (defun gnus-capitalize-newsgroup (newsgroup)
2527 "Capitalize NEWSGROUP name."
2528 (when (not (zerop (length newsgroup)))
2529 (concat (char-to-string (upcase (aref newsgroup 0)))
2530 (substring newsgroup 1))))
2532 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2533 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2534 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2535 Otherwise, it is like ~/News/news/group/num."
2536 (let ((default
2537 (expand-file-name
2538 (concat (if (gnus-use-long-file-name 'not-save)
2539 (gnus-capitalize-newsgroup newsgroup)
2540 (gnus-newsgroup-directory-form newsgroup))
2541 "/" (int-to-string (mail-header-number headers)))
2542 gnus-article-save-directory)))
2543 (if (and last-file
2544 (string-equal (file-name-directory default)
2545 (file-name-directory last-file))
2546 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2547 default
2548 (or last-file default))))
2550 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2551 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2552 If variable `gnus-use-long-file-name' is non-nil, it is
2553 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2554 (let ((default
2555 (expand-file-name
2556 (concat (if (gnus-use-long-file-name 'not-save)
2557 newsgroup
2558 (gnus-newsgroup-directory-form newsgroup))
2559 "/" (int-to-string (mail-header-number headers)))
2560 gnus-article-save-directory)))
2561 (if (and last-file
2562 (string-equal (file-name-directory default)
2563 (file-name-directory last-file))
2564 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2565 default
2566 (or last-file default))))
2568 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2569 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2570 If variable `gnus-use-long-file-name' is non-nil, it is
2571 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2572 (or last-file
2573 (expand-file-name
2574 (if (gnus-use-long-file-name 'not-save)
2575 newsgroup
2576 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2577 gnus-article-save-directory)))
2579 (eval-and-compile
2580 (mapcar
2581 (lambda (func)
2582 (let (afunc gfunc)
2583 (if (consp func)
2584 (setq afunc (car func)
2585 gfunc (cdr func))
2586 (setq afunc func
2587 gfunc (intern (format "gnus-%s" func))))
2588 (defalias gfunc
2589 (if (fboundp afunc)
2590 `(lambda (&optional interactive &rest args)
2591 ,(documentation afunc t)
2592 (interactive (list t))
2593 (save-excursion
2594 (set-buffer gnus-article-buffer)
2595 (if interactive
2596 (call-interactively ',afunc)
2597 (apply ',afunc args))))))))
2598 '(article-hide-headers
2599 article-hide-boring-headers
2600 article-treat-overstrike
2601 article-fill-long-lines
2602 article-capitalize-sentences
2603 article-remove-cr
2604 article-display-x-face
2605 article-de-quoted-unreadable
2606 article-de-base64-unreadable
2607 article-decode-HZ
2608 article-wash-html
2609 article-hide-list-identifiers
2610 article-hide-pgp
2611 article-strip-banner
2612 article-babel
2613 article-hide-pem
2614 article-hide-signature
2615 article-strip-headers-in-body
2616 article-remove-trailing-blank-lines
2617 article-strip-leading-blank-lines
2618 article-strip-multiple-blank-lines
2619 article-strip-leading-space
2620 article-strip-trailing-space
2621 article-strip-blank-lines
2622 article-strip-all-blank-lines
2623 article-date-local
2624 article-date-iso8601
2625 article-date-original
2626 article-date-ut
2627 article-decode-mime-words
2628 article-decode-charset
2629 article-decode-encoded-words
2630 article-date-user
2631 article-date-lapsed
2632 article-emphasize
2633 article-treat-dumbquotes
2634 article-normalize-headers
2635 (article-show-all . gnus-article-show-all-headers))))
2638 ;;; Gnus article mode
2641 (put 'gnus-article-mode 'mode-class 'special)
2643 (set-keymap-parent gnus-article-mode-map widget-keymap)
2645 (gnus-define-keys gnus-article-mode-map
2646 " " gnus-article-goto-next-page
2647 "\177" gnus-article-goto-prev-page
2648 [delete] gnus-article-goto-prev-page
2649 [backspace] gnus-article-goto-prev-page
2650 "\C-c^" gnus-article-refer-article
2651 "h" gnus-article-show-summary
2652 "s" gnus-article-show-summary
2653 "\C-c\C-m" gnus-article-mail
2654 "?" gnus-article-describe-briefly
2655 "e" gnus-summary-edit-article
2656 "<" beginning-of-buffer
2657 ">" end-of-buffer
2658 "\C-c\C-i" gnus-info-find-node
2659 "\C-c\C-b" gnus-bug
2660 "\C-hk" gnus-article-describe-key
2661 "\C-hc" gnus-article-describe-key-briefly
2663 "\C-d" gnus-article-read-summary-keys
2664 "\M-*" gnus-article-read-summary-keys
2665 "\M-#" gnus-article-read-summary-keys
2666 "\M-^" gnus-article-read-summary-keys
2667 "\M-g" gnus-article-read-summary-keys)
2669 (substitute-key-definition
2670 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2672 (defvar gnus-article-post-menu nil)
2674 (defun gnus-article-make-menu-bar ()
2675 (gnus-turn-off-edit-menu 'article)
2676 (unless (boundp 'gnus-article-article-menu)
2677 (easy-menu-define
2678 gnus-article-article-menu gnus-article-mode-map ""
2679 '("Article"
2680 ["Scroll forwards" gnus-article-goto-next-page t]
2681 ["Scroll backwards" gnus-article-goto-prev-page t]
2682 ["Show summary" gnus-article-show-summary t]
2683 ["Fetch Message-ID at point" gnus-article-refer-article t]
2684 ["Mail to address at point" gnus-article-mail t]
2685 ["Send a bug report" gnus-bug t]))
2687 (easy-menu-define
2688 gnus-article-treatment-menu gnus-article-mode-map ""
2689 ;; Fixme: this should use :active (and maybe :visible).
2690 '("Treatment"
2691 ["Hide headers" gnus-article-hide-headers t]
2692 ["Hide signature" gnus-article-hide-signature t]
2693 ["Hide citation" gnus-article-hide-citation t]
2694 ["Treat overstrike" gnus-article-treat-overstrike t]
2695 ["Remove carriage return" gnus-article-remove-cr t]
2696 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2697 ["Remove base64" gnus-article-de-base64-unreadable t]
2698 ["Treat html" gnus-article-wash-html t]
2699 ["Decode HZ" gnus-article-decode-HZ t]))
2701 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2703 (when (boundp 'gnus-summary-post-menu)
2704 (cond
2705 ((not (keymapp gnus-summary-post-menu))
2706 (setq gnus-article-post-menu gnus-summary-post-menu))
2707 ((not gnus-article-post-menu)
2708 ;; Don't share post menu.
2709 (setq gnus-article-post-menu
2710 (copy-keymap gnus-summary-post-menu))))
2711 (define-key gnus-article-mode-map [menu-bar post]
2712 (cons "Post" gnus-article-post-menu)))
2714 (gnus-run-hooks 'gnus-article-menu-hook)))
2716 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2717 ;; Summary.
2719 (defun gnus-article-mode ()
2720 "Major mode for displaying an article.
2722 All normal editing commands are switched off.
2724 The following commands are available in addition to all summary mode
2725 commands:
2726 \\<gnus-article-mode-map>
2727 \\[gnus-article-next-page]\t Scroll the article one page forwards
2728 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2729 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2730 \\[gnus-article-show-summary]\t Display the summary buffer
2731 \\[gnus-article-mail]\t Send a reply to the address near point
2732 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2733 \\[gnus-info-find-node]\t Go to the Gnus info node"
2734 (interactive)
2735 (gnus-simplify-mode-line)
2736 (setq mode-name "Article")
2737 (setq major-mode 'gnus-article-mode)
2738 (make-local-variable 'minor-mode-alist)
2739 (use-local-map gnus-article-mode-map)
2740 (when (gnus-visual-p 'article-menu 'menu)
2741 (gnus-article-make-menu-bar))
2742 (gnus-update-format-specifications nil 'article-mode)
2743 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2744 (make-local-variable 'gnus-page-broken)
2745 (make-local-variable 'gnus-button-marker-list)
2746 (make-local-variable 'gnus-article-current-summary)
2747 (make-local-variable 'gnus-article-mime-handles)
2748 (make-local-variable 'gnus-article-decoded-p)
2749 (make-local-variable 'gnus-article-mime-handle-alist)
2750 (make-local-variable 'gnus-article-wash-types)
2751 (gnus-set-default-directory)
2752 (buffer-disable-undo)
2753 (setq buffer-read-only t)
2754 (set-syntax-table gnus-article-mode-syntax-table)
2755 (mm-enable-multibyte)
2756 (gnus-run-hooks 'gnus-article-mode-hook))
2758 (defun gnus-article-setup-buffer ()
2759 "Initialize the article buffer."
2760 (let* ((name (if gnus-single-article-buffer "*Article*"
2761 (concat "*Article " gnus-newsgroup-name "*")))
2762 (original
2763 (progn (string-match "\\*Article" name)
2764 (concat " *Original Article"
2765 (substring name (match-end 0))))))
2766 (setq gnus-article-buffer name)
2767 (setq gnus-original-article-buffer original)
2768 (setq gnus-article-mime-handle-alist nil)
2769 ;; This might be a variable local to the summary buffer.
2770 (unless gnus-single-article-buffer
2771 (save-excursion
2772 (set-buffer gnus-summary-buffer)
2773 (setq gnus-article-buffer name)
2774 (setq gnus-original-article-buffer original)
2775 (gnus-set-global-variables)))
2776 (gnus-article-setup-highlight-words)
2777 ;; Init original article buffer.
2778 (save-excursion
2779 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2780 (mm-enable-multibyte)
2781 (setq major-mode 'gnus-original-article-mode)
2782 (make-local-variable 'gnus-original-article))
2783 (if (get-buffer name)
2784 (save-excursion
2785 (set-buffer name)
2786 (when gnus-article-mime-handles
2787 (mm-destroy-parts gnus-article-mime-handles)
2788 (setq gnus-article-mime-handles nil))
2789 ;; Set it to nil in article-buffer!
2790 (setq gnus-article-mime-handle-alist nil)
2791 (buffer-disable-undo)
2792 (setq buffer-read-only t)
2793 (unless (eq major-mode 'gnus-article-mode)
2794 (gnus-article-mode))
2795 (current-buffer))
2796 (save-excursion
2797 (set-buffer (gnus-get-buffer-create name))
2798 (gnus-article-mode)
2799 (make-local-variable 'gnus-summary-buffer)
2800 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2801 (current-buffer)))))
2803 ;; Set article window start at LINE, where LINE is the number of lines
2804 ;; from the head of the article.
2805 (defun gnus-article-set-window-start (&optional line)
2806 (set-window-start
2807 (get-buffer-window gnus-article-buffer t)
2808 (save-excursion
2809 (set-buffer gnus-article-buffer)
2810 (goto-char (point-min))
2811 (if (not line)
2812 (point-min)
2813 (gnus-message 6 "Moved to bookmark")
2814 (search-forward "\n\n" nil t)
2815 (forward-line line)
2816 (point)))))
2818 (defun gnus-article-prepare (article &optional all-headers header)
2819 "Prepare ARTICLE in article mode buffer.
2820 ARTICLE should either be an article number or a Message-ID.
2821 If ARTICLE is an id, HEADER should be the article headers.
2822 If ALL-HEADERS is non-nil, no headers are hidden."
2823 (save-excursion
2824 ;; Make sure we start in a summary buffer.
2825 (unless (eq major-mode 'gnus-summary-mode)
2826 (set-buffer gnus-summary-buffer))
2827 (setq gnus-summary-buffer (current-buffer))
2828 (let* ((gnus-article (if header (mail-header-number header) article))
2829 (summary-buffer (current-buffer))
2830 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2831 (group gnus-newsgroup-name)
2832 result)
2833 (save-excursion
2834 (gnus-article-setup-buffer)
2835 (set-buffer gnus-article-buffer)
2836 ;; Deactivate active regions.
2837 (when (and (boundp 'transient-mark-mode)
2838 transient-mark-mode)
2839 (setq mark-active nil))
2840 (if (not (setq result (let ((buffer-read-only nil))
2841 (gnus-request-article-this-buffer
2842 article group))))
2843 ;; There is no such article.
2844 (save-excursion
2845 (when (and (numberp article)
2846 (not (memq article gnus-newsgroup-sparse)))
2847 (setq gnus-article-current
2848 (cons gnus-newsgroup-name article))
2849 (set-buffer gnus-summary-buffer)
2850 (setq gnus-current-article article)
2851 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2852 (progn
2853 (gnus-summary-set-agent-mark article)
2854 (message "Message marked for downloading"))
2855 (gnus-summary-mark-article article gnus-canceled-mark)
2856 (unless (memq article gnus-newsgroup-sparse)
2857 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2858 (if (or (eq result 'pseudo)
2859 (eq result 'nneething))
2860 (progn
2861 (save-excursion
2862 (set-buffer summary-buffer)
2863 (push article gnus-newsgroup-history)
2864 (setq gnus-last-article gnus-current-article
2865 gnus-current-article 0
2866 gnus-current-headers nil
2867 gnus-article-current nil)
2868 (if (eq result 'nneething)
2869 (gnus-configure-windows 'summary)
2870 (gnus-configure-windows 'article))
2871 (gnus-set-global-variables))
2872 (let ((gnus-article-mime-handle-alist-1
2873 gnus-article-mime-handle-alist))
2874 (gnus-set-mode-line 'article)))
2875 ;; The result from the `request' was an actual article -
2876 ;; or at least some text that is now displayed in the
2877 ;; article buffer.
2878 (when (and (numberp article)
2879 (not (eq article gnus-current-article)))
2880 ;; Seems like a new article has been selected.
2881 ;; `gnus-current-article' must be an article number.
2882 (save-excursion
2883 (set-buffer summary-buffer)
2884 (push article gnus-newsgroup-history)
2885 (setq gnus-last-article gnus-current-article
2886 gnus-current-article article
2887 gnus-current-headers
2888 (gnus-summary-article-header gnus-current-article)
2889 gnus-article-current
2890 (cons gnus-newsgroup-name gnus-current-article))
2891 (unless (vectorp gnus-current-headers)
2892 (setq gnus-current-headers nil))
2893 (gnus-summary-goto-subject gnus-current-article)
2894 (when (gnus-summary-show-thread)
2895 ;; If the summary buffer really was folded, the
2896 ;; previous goto may not actually have gone to
2897 ;; the right article, but the thread root instead.
2898 ;; So we go again.
2899 (gnus-summary-goto-subject gnus-current-article))
2900 (gnus-run-hooks 'gnus-mark-article-hook)
2901 (gnus-set-mode-line 'summary)
2902 (when (gnus-visual-p 'article-highlight 'highlight)
2903 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2904 ;; Set the global newsgroup variables here.
2905 (gnus-set-global-variables)
2906 (setq gnus-have-all-headers
2907 (or all-headers gnus-show-all-headers))))
2908 (save-excursion
2909 (gnus-configure-windows 'article))
2910 (when (or (numberp article)
2911 (stringp article))
2912 (gnus-article-prepare-display)
2913 ;; Do page break.
2914 (goto-char (point-min))
2915 (setq gnus-page-broken
2916 (when gnus-break-pages
2917 (gnus-narrow-to-page)
2918 t)))
2919 (let ((gnus-article-mime-handle-alist-1
2920 gnus-article-mime-handle-alist))
2921 (gnus-set-mode-line 'article))
2922 (article-goto-body)
2923 (set-window-point (get-buffer-window (current-buffer)) (point))
2924 (gnus-configure-windows 'article)
2925 t))))))
2927 ;;;###autoload
2928 (defun gnus-article-prepare-display ()
2929 "Make the current buffer look like a nice article."
2930 ;; Hooks for getting information from the article.
2931 ;; This hook must be called before being narrowed.
2932 (let ((gnus-article-buffer (current-buffer))
2933 buffer-read-only)
2934 (unless (eq major-mode 'gnus-article-mode)
2935 (gnus-article-mode))
2936 (setq buffer-read-only nil
2937 gnus-article-wash-types nil)
2938 (gnus-run-hooks 'gnus-tmp-internal-hook)
2939 (when gnus-display-mime-function
2940 (funcall gnus-display-mime-function))
2941 (gnus-run-hooks 'gnus-article-prepare-hook)))
2944 ;;; Gnus MIME viewing functions
2947 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2948 "The following specs can be used:
2949 %t The MIME type
2950 %T MIME type, along with additional info
2951 %n The `name' parameter
2952 %d The description, if any
2953 %l The length of the encoded part
2954 %p The part identifier number
2955 %e Dots if the part isn't displayed")
2957 (defvar gnus-mime-button-line-format-alist
2958 '((?t gnus-tmp-type ?s)
2959 (?T gnus-tmp-type-long ?s)
2960 (?n gnus-tmp-name ?s)
2961 (?d gnus-tmp-description ?s)
2962 (?p gnus-tmp-id ?s)
2963 (?l gnus-tmp-length ?d)
2964 (?e gnus-tmp-dots ?s)))
2966 (defvar gnus-mime-button-commands
2967 '((gnus-article-press-button "\r" "Toggle Display")
2968 (gnus-mime-view-part "v" "View Interactively...")
2969 (gnus-mime-view-part-as-type "t" "View As Type...")
2970 (gnus-mime-save-part "o" "Save...")
2971 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2972 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2973 (gnus-mime-internalize-part "E" "View Internally")
2974 (gnus-mime-externalize-part "e" "View Externally")
2975 (gnus-mime-pipe-part "|" "Pipe To Command...")
2976 (gnus-mime-action-on-part "." "Take action on the part")))
2978 (defun gnus-article-mime-part-status ()
2979 (if gnus-article-mime-handle-alist-1
2980 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2981 ""))
2983 (defvar gnus-mime-button-map
2984 (let ((map (make-sparse-keymap)))
2985 ;; Not for Emacs 21: fixme better.
2986 ;; (set-keymap-parent map gnus-article-mode-map)
2987 (define-key map gnus-mouse-2 'gnus-article-push-button)
2988 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2989 (dolist (c gnus-mime-button-commands)
2990 (define-key map (cadr c) (car c)))
2991 map))
2993 (defun gnus-mime-button-menu (event)
2994 "Construct a context-sensitive menu of MIME commands."
2995 (interactive "e")
2996 (save-excursion
2997 (mouse-set-point event)
2998 (gnus-article-check-buffer)
2999 (let ((response (x-popup-menu
3000 t `("MIME Part"
3001 ("" ,@(mapcar (lambda (c)
3002 (cons (caddr c) (car c)))
3003 gnus-mime-button-commands))))))
3004 (if response
3005 (call-interactively response)))))
3007 (defun gnus-mime-view-all-parts (&optional handles)
3008 "View all the MIME parts."
3009 (interactive)
3010 (save-current-buffer
3011 (set-buffer gnus-article-buffer)
3012 (let ((handles (or handles gnus-article-mime-handles))
3013 (mail-parse-charset gnus-newsgroup-charset)
3014 (mail-parse-ignored-charsets
3015 (save-excursion (set-buffer gnus-summary-buffer)
3016 gnus-newsgroup-ignored-charsets)))
3017 (if (stringp (car handles))
3018 (gnus-mime-view-all-parts (cdr handles))
3019 (mapcar 'mm-display-part handles)))))
3021 (defun gnus-mime-save-part ()
3022 "Save the MIME part under point."
3023 (interactive)
3024 (gnus-article-check-buffer)
3025 (let ((data (get-text-property (point) 'gnus-data)))
3026 (mm-save-part data)))
3028 (defun gnus-mime-pipe-part ()
3029 "Pipe the MIME part under point to a process."
3030 (interactive)
3031 (gnus-article-check-buffer)
3032 (let ((data (get-text-property (point) 'gnus-data)))
3033 (mm-pipe-part data)))
3035 (defun gnus-mime-view-part ()
3036 "Interactively choose a viewing method for the MIME part under point."
3037 (interactive)
3038 (gnus-article-check-buffer)
3039 (let ((data (get-text-property (point) 'gnus-data)))
3040 (push (setq data (copy-sequence data)) gnus-article-mime-handles)
3041 (mm-interactively-view-part data)))
3043 (defun gnus-mime-view-part-as-type-internal ()
3044 (gnus-article-check-buffer)
3045 (let* ((name (mail-content-type-get
3046 (mm-handle-type (get-text-property (point) 'gnus-data))
3047 'name))
3048 (def-type (and name (mm-default-file-encoding name))))
3049 (and def-type (cons def-type 0))))
3051 (defun gnus-mime-view-part-as-type (mime-type)
3052 "Choose a MIME media type, and view the part as such."
3053 (interactive
3054 (list (completing-read
3055 "View as MIME type: "
3056 (mapcar #'list (mailcap-mime-types))
3057 nil nil
3058 (gnus-mime-view-part-as-type-internal))))
3059 (gnus-article-check-buffer)
3060 (let ((handle (get-text-property (point) 'gnus-data)))
3061 (gnus-mm-display-part
3062 (mm-make-handle (mm-handle-buffer handle)
3063 (cons mime-type (cdr (mm-handle-type handle)))
3064 (mm-handle-encoding handle)
3065 (mm-handle-undisplayer handle)
3066 (mm-handle-disposition handle)
3067 (mm-handle-description handle)
3068 (mm-handle-cache handle)
3069 (mm-handle-id handle)))))
3071 (defun gnus-mime-copy-part (&optional handle)
3072 "Put the MIME part under point into a new buffer."
3073 (interactive)
3074 (gnus-article-check-buffer)
3075 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3076 (contents (mm-get-part handle))
3077 (base (file-name-nondirectory
3079 (mail-content-type-get (mm-handle-type handle) 'name)
3080 (mail-content-type-get (mm-handle-type handle)
3081 'filename)
3082 "*decoded*")))
3083 (buffer (generate-new-buffer base)))
3084 (switch-to-buffer buffer)
3085 (insert contents)
3086 ;; We do it this way to make `normal-mode' set the appropriate mode.
3087 (unwind-protect
3088 (progn
3089 (setq buffer-file-name (expand-file-name base))
3090 (normal-mode))
3091 (setq buffer-file-name nil))
3092 (goto-char (point-min))))
3094 (defun gnus-mime-inline-part (&optional handle arg)
3095 "Insert the MIME part under point into the current buffer."
3096 (interactive (list nil current-prefix-arg))
3097 (gnus-article-check-buffer)
3098 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3099 contents charset
3100 (b (point))
3101 buffer-read-only)
3102 (if (mm-handle-undisplayer handle)
3103 (mm-remove-part handle)
3104 (setq contents (mm-get-part handle))
3105 (cond
3106 ((not arg)
3107 (setq charset (or (mail-content-type-get
3108 (mm-handle-type handle) 'charset)
3109 gnus-newsgroup-charset)))
3110 ((numberp arg)
3111 (setq charset
3112 (or (cdr (assq arg
3113 gnus-summary-show-article-charset-alist))
3114 (read-coding-system "Charset: ")))))
3115 (forward-line 2)
3116 (mm-insert-inline handle
3117 (if (and charset
3118 (setq charset (mm-charset-to-coding-system
3119 charset))
3120 (not (eq charset 'ascii)))
3121 (mm-decode-coding-string contents charset)
3122 contents))
3123 (goto-char b))))
3125 (defun gnus-mime-externalize-part (&optional handle)
3126 "View the MIME part under point with an external viewer."
3127 (interactive)
3128 (gnus-article-check-buffer)
3129 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3130 (mm-user-display-methods nil)
3131 (mm-inlined-types nil)
3132 (mail-parse-charset gnus-newsgroup-charset)
3133 (mail-parse-ignored-charsets
3134 (save-excursion (set-buffer gnus-summary-buffer)
3135 gnus-newsgroup-ignored-charsets)))
3136 (if (mm-handle-undisplayer handle)
3137 (mm-remove-part handle)
3138 (mm-display-part handle))))
3140 (defun gnus-mime-internalize-part (&optional handle)
3141 "View the MIME part under point with an internal viewer.
3142 In no internal viewer is available, use an external viewer."
3143 (interactive)
3144 (gnus-article-check-buffer)
3145 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3146 (mm-inlined-types '(".*"))
3147 (mm-inline-large-images t)
3148 (mail-parse-charset gnus-newsgroup-charset)
3149 (mail-parse-ignored-charsets
3150 (save-excursion (set-buffer gnus-summary-buffer)
3151 gnus-newsgroup-ignored-charsets)))
3152 (if (mm-handle-undisplayer handle)
3153 (mm-remove-part handle)
3154 (mm-display-part handle))))
3156 (defun gnus-mime-action-on-part (&optional action)
3157 "Do something with the MIME attachment at \(point\)."
3158 (interactive
3159 (list (completing-read "Action: " gnus-mime-action-alist)))
3160 (gnus-article-check-buffer)
3161 (let ((action-pair (assoc action gnus-mime-action-alist)))
3162 (if action-pair
3163 (funcall (cdr action-pair)))))
3166 (defun gnus-article-part-wrapper (n function)
3167 (save-current-buffer
3168 (set-buffer gnus-article-buffer)
3169 (when (> n (length gnus-article-mime-handle-alist))
3170 (error "No such part"))
3171 (gnus-article-goto-part n)
3172 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3173 (funcall function handle))))
3175 (defun gnus-article-pipe-part (n)
3176 "Pipe MIME part N, which is the numerical prefix."
3177 (interactive "p")
3178 (gnus-article-part-wrapper n 'mm-pipe-part))
3180 (defun gnus-article-save-part (n)
3181 "Save MIME part N, which is the numerical prefix."
3182 (interactive "p")
3183 (gnus-article-part-wrapper n 'mm-save-part))
3185 (defun gnus-article-interactively-view-part (n)
3186 "View MIME part N interactively, which is the numerical prefix."
3187 (interactive "p")
3188 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3190 (defun gnus-article-copy-part (n)
3191 "Copy MIME part N, which is the numerical prefix."
3192 (interactive "p")
3193 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3195 (defun gnus-article-externalize-part (n)
3196 "View MIME part N externally, which is the numerical prefix."
3197 (interactive "p")
3198 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3200 (defun gnus-article-inline-part (n)
3201 "Inline MIME part N, which is the numerical prefix."
3202 (interactive "p")
3203 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3205 (defun gnus-article-mime-match-handle-first (condition)
3206 (if condition
3207 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3208 (while (setq ihandle (pop alist))
3209 (if (and (cond
3210 ((functionp condition)
3211 (funcall condition (cdr ihandle)))
3212 ((eq condition 'undisplayed)
3213 (not (or (mm-handle-undisplayer (cdr ihandle))
3214 (equal (mm-handle-media-type (cdr ihandle))
3215 "multipart/alternative"))))
3216 ((eq condition 'undisplayed-alternative)
3217 (not (mm-handle-undisplayer (cdr ihandle))))
3218 (t t))
3219 (gnus-article-goto-part (car ihandle))
3220 (or (not n) (< (car ihandle) n)))
3221 (setq n (car ihandle))))
3222 (or n 1))
3225 (defun gnus-article-view-part (&optional n)
3226 "View MIME part N, which is the numerical prefix."
3227 (interactive "P")
3228 (save-current-buffer
3229 (set-buffer gnus-article-buffer)
3230 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3231 gnus-article-mime-match-handle-function)))
3232 (when (> n (length gnus-article-mime-handle-alist))
3233 (error "No such part"))
3234 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3235 (when (gnus-article-goto-part n)
3236 (if (equal (car handle) "multipart/alternative")
3237 (gnus-article-press-button)
3238 (when (eq (gnus-mm-display-part handle) 'internal)
3239 (gnus-set-window-start)))))))
3241 (defsubst gnus-article-mime-total-parts ()
3242 (if (bufferp (car gnus-article-mime-handles))
3243 1 ;; single part
3244 (1- (length gnus-article-mime-handles))))
3246 (defun gnus-mm-display-part (handle)
3247 "Display HANDLE and fix MIME button."
3248 (let ((id (get-text-property (point) 'gnus-part))
3249 (point (point))
3250 buffer-read-only)
3251 (forward-line 1)
3252 (prog1
3253 (let ((window (selected-window))
3254 (mail-parse-charset gnus-newsgroup-charset)
3255 (mail-parse-ignored-charsets
3256 (save-excursion (set-buffer gnus-summary-buffer)
3257 gnus-newsgroup-ignored-charsets)))
3258 (save-excursion
3259 (unwind-protect
3260 (let ((win (get-buffer-window (current-buffer) t))
3261 (beg (point)))
3262 (when win
3263 (select-window win))
3264 (goto-char point)
3265 (forward-line)
3266 (if (mm-handle-displayed-p handle)
3267 ;; This will remove the part.
3268 (mm-display-part handle)
3269 (save-restriction
3270 (narrow-to-region (point) (1+ (point)))
3271 (mm-display-part handle)
3272 ;; We narrow to the part itself and
3273 ;; then call the treatment functions.
3274 (goto-char (point-min))
3275 (forward-line 1)
3276 (narrow-to-region (point) (point-max))
3277 (gnus-treat-article
3278 nil id
3279 (gnus-article-mime-total-parts)
3280 (mm-handle-media-type handle)))))
3281 (select-window window))))
3282 (goto-char point)
3283 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3284 (gnus-insert-mime-button
3285 handle id (list (mm-handle-displayed-p handle)))
3286 (goto-char point))))
3288 (defun gnus-article-goto-part (n)
3289 "Go to MIME part N."
3290 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3291 (when point
3292 (goto-char point))))
3294 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3295 (let ((gnus-tmp-name
3296 (or (mail-content-type-get (mm-handle-type handle)
3297 'name)
3298 (mail-content-type-get (mm-handle-disposition handle)
3299 'filename)
3300 ""))
3301 (gnus-tmp-type (mm-handle-media-type handle))
3302 (gnus-tmp-description
3303 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3304 "")))
3305 (gnus-tmp-dots
3306 (if (if displayed (car displayed)
3307 (mm-handle-displayed-p handle))
3308 "" "..."))
3309 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3310 (buffer-size)))
3311 gnus-tmp-type-long b e)
3312 (when (string-match ".*/" gnus-tmp-name)
3313 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3314 (setq gnus-tmp-type-long (concat gnus-tmp-type
3315 (and (not (equal gnus-tmp-name ""))
3316 (concat "; " gnus-tmp-name))))
3317 (or (equal gnus-tmp-description "")
3318 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3319 (unless (bolp)
3320 (insert "\n"))
3321 (setq b (point))
3322 (gnus-eval-format
3323 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3324 `(keymap ,gnus-mime-button-map
3325 ;; Not for Emacs 21: fixme better.
3326 ;; local-map ,gnus-mime-button-map
3327 gnus-callback gnus-mm-display-part
3328 gnus-part ,gnus-tmp-id
3329 article-type annotation
3330 gnus-data ,handle))
3331 (setq e (point))
3332 (widget-convert-button
3333 'link b e
3334 :mime-handle handle
3335 :action 'gnus-widget-press-button
3336 :button-keymap gnus-mime-button-map
3337 :help-echo
3338 (lambda (widget/window &optional overlay pos)
3339 ;; Needed to properly clear the message due to a bug in
3340 ;; wid-edit (XEmacs only).
3341 (if (boundp 'help-echo-owns-message)
3342 (setq help-echo-owns-message t))
3343 (format
3344 "%S: %s the MIME part; %S: more options"
3345 (aref gnus-mouse-2 0)
3346 ;; XEmacs will get a single widget arg; Emacs 21 will get
3347 ;; window, overlay, position.
3348 (if (mm-handle-displayed-p
3349 (if overlay
3350 (with-current-buffer (gnus-overlay-buffer overlay)
3351 (widget-get (widget-at (gnus-overlay-start overlay))
3352 :mime-handle))
3353 (widget-get widget/window :mime-handle)))
3354 "hide" "show")
3355 (aref gnus-down-mouse-3 0))))))
3357 (defun gnus-widget-press-button (elems el)
3358 (goto-char (widget-get elems :from))
3359 (gnus-article-press-button))
3361 (defvar gnus-displaying-mime nil)
3363 (defun gnus-display-mime (&optional ihandles)
3364 "Display the MIME parts."
3365 (save-excursion
3366 (save-selected-window
3367 (let ((window (get-buffer-window gnus-article-buffer))
3368 (point (point)))
3369 (when window
3370 (select-window window)
3371 ;; We have to do this since selecting the window
3372 ;; may change the point. So we set the window point.
3373 (set-window-point window point)))
3374 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3375 buffer-read-only handle name type b e display)
3376 (when (and (not ihandles)
3377 (not gnus-displaying-mime))
3378 ;; Top-level call; we clean up.
3379 (when gnus-article-mime-handles
3380 (mm-destroy-parts gnus-article-mime-handles)
3381 (setq gnus-article-mime-handle-alist nil));; A trick.
3382 (setq gnus-article-mime-handles handles)
3383 ;; We allow users to glean info from the handles.
3384 (when gnus-article-mime-part-function
3385 (gnus-mime-part-function handles)))
3386 (if (and handles
3387 (or (not (stringp (car handles)))
3388 (cdr handles)))
3389 (progn
3390 (when (and (not ihandles)
3391 (not gnus-displaying-mime))
3392 ;; Clean up for mime parts.
3393 (article-goto-body)
3394 (delete-region (point) (point-max)))
3395 (let ((gnus-displaying-mime t))
3396 (gnus-mime-display-part handles)))
3397 (save-restriction
3398 (article-goto-body)
3399 (narrow-to-region (point) (point-max))
3400 (gnus-treat-article nil 1 1)
3401 (widen)))
3402 (unless ihandles
3403 ;; Highlight the headers.
3404 (save-excursion
3405 (save-restriction
3406 (article-goto-body)
3407 (narrow-to-region (point-min) (point))
3408 (gnus-treat-article 'head))))))))
3410 (defvar gnus-mime-display-multipart-as-mixed nil)
3412 (defun gnus-mime-display-part (handle)
3413 (cond
3414 ;; Single part.
3415 ((not (stringp (car handle)))
3416 (gnus-mime-display-single handle))
3417 ;; User-defined multipart
3418 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3419 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3420 handle))
3421 ;; multipart/alternative
3422 ((and (equal (car handle) "multipart/alternative")
3423 (not gnus-mime-display-multipart-as-mixed))
3424 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3425 (push (cons id handle) gnus-article-mime-handle-alist)
3426 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3427 ;; multipart/related
3428 ((and (equal (car handle) "multipart/related")
3429 (not gnus-mime-display-multipart-as-mixed))
3430 ;;;!!!We should find the start part, but we just default
3431 ;;;!!!to the first part.
3432 (gnus-mime-display-part (cadr handle)))
3433 ;; Other multiparts are handled like multipart/mixed.
3435 (gnus-mime-display-mixed (cdr handle)))))
3437 (defun gnus-mime-part-function (handles)
3438 (if (stringp (car handles))
3439 (mapcar 'gnus-mime-part-function (cdr handles))
3440 (funcall gnus-article-mime-part-function handles)))
3442 (defun gnus-mime-display-mixed (handles)
3443 (mapcar 'gnus-mime-display-part handles))
3445 (defun gnus-mime-display-single (handle)
3446 (let ((type (mm-handle-media-type handle))
3447 (ignored gnus-ignored-mime-types)
3448 (not-attachment t)
3449 (move nil)
3450 display text)
3451 (catch 'ignored
3452 (progn
3453 (while ignored
3454 (when (string-match (pop ignored) type)
3455 (throw 'ignored nil)))
3456 (if (and (setq not-attachment
3457 (and (not (mm-inline-override-p handle))
3458 (or (not (mm-handle-disposition handle))
3459 (equal (car (mm-handle-disposition handle))
3460 "inline")
3461 (mm-attachment-override-p handle))))
3462 (mm-automatic-display-p handle)
3463 (or (mm-inlined-p handle)
3464 (mm-automatic-external-display-p type)))
3465 (setq display t)
3466 (when (equal (mm-handle-media-supertype handle) "text")
3467 (setq text t)))
3468 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3469 beg)
3470 (push (cons id handle) gnus-article-mime-handle-alist)
3471 (when (or (not display)
3472 (not (gnus-unbuttonized-mime-type-p type)))
3473 ;(gnus-article-insert-newline)
3474 (gnus-insert-mime-button
3475 handle id (list (or display (and not-attachment text))))
3476 (gnus-article-insert-newline)
3477 ;(gnus-article-insert-newline)
3478 (setq move t))
3479 (setq beg (point))
3480 (cond
3481 (display
3482 (when move
3483 (forward-line -2)
3484 (setq beg (point)))
3485 (let ((mail-parse-charset gnus-newsgroup-charset)
3486 (mail-parse-ignored-charsets
3487 (save-excursion (condition-case ()
3488 (set-buffer gnus-summary-buffer)
3489 (error))
3490 gnus-newsgroup-ignored-charsets)))
3491 (mm-display-part handle t))
3492 (goto-char (point-max)))
3493 ((and text not-attachment)
3494 (when move
3495 (forward-line -2)
3496 (setq beg (point)))
3497 (gnus-article-insert-newline)
3498 (mm-insert-inline handle (mm-get-part handle))
3499 (goto-char (point-max))))
3500 ;; Do highlighting.
3501 (save-excursion
3502 (save-restriction
3503 (narrow-to-region beg (point))
3504 (gnus-treat-article
3505 nil id
3506 (gnus-article-mime-total-parts)
3507 (mm-handle-media-type handle)))))))))
3509 (defun gnus-unbuttonized-mime-type-p (type)
3510 "Say whether TYPE is to be unbuttonized."
3511 (unless gnus-inhibit-mime-unbuttonizing
3512 (catch 'found
3513 (let ((types gnus-unbuttonized-mime-types))
3514 (while types
3515 (when (string-match (pop types) type)
3516 (throw 'found t)))))))
3518 (defun gnus-article-insert-newline ()
3519 "Insert a newline, but mark it as undeletable."
3520 (gnus-put-text-property
3521 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3523 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3524 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3525 (ihandles handles)
3526 (point (point))
3527 handle buffer-read-only from props begend not-pref)
3528 (save-window-excursion
3529 (save-restriction
3530 (when ibegend
3531 (narrow-to-region (car ibegend)
3532 (or (cdr ibegend)
3533 (progn
3534 (goto-char (car ibegend))
3535 (forward-line 2)
3536 (point))))
3537 (delete-region (point-min) (point-max))
3538 (mm-remove-parts handles))
3539 (setq begend (list (point-marker)))
3540 ;; Do the toggle.
3541 (unless (setq not-pref (cadr (member preferred ihandles)))
3542 (setq not-pref (car ihandles)))
3543 (when (or ibegend
3544 (not (gnus-unbuttonized-mime-type-p
3545 "multipart/alternative")))
3546 (gnus-add-text-properties
3547 (setq from (point))
3548 (progn
3549 (insert (format "%d. " id))
3550 (point))
3551 `(gnus-callback
3552 (lambda (handles)
3553 (unless ,(not ibegend)
3554 (setq gnus-article-mime-handle-alist
3555 ',gnus-article-mime-handle-alist))
3556 (gnus-mime-display-alternative
3557 ',ihandles ',not-pref ',begend ,id))
3558 ;; Not for Emacs 21: fixme better.
3559 ;; local-map ,gnus-mime-button-map
3560 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3561 face ,gnus-article-button-face
3562 keymap ,gnus-mime-button-map
3563 gnus-part ,id
3564 gnus-data ,handle))
3565 (widget-convert-button 'link from (point)
3566 :action 'gnus-widget-press-button
3567 :button-keymap gnus-widget-button-keymap)
3568 ;; Do the handles
3569 (while (setq handle (pop handles))
3570 (gnus-add-text-properties
3571 (setq from (point))
3572 (progn
3573 (insert (format "(%c) %-18s"
3574 (if (equal handle preferred) ?* ? )
3575 (mm-handle-media-type handle)))
3576 (point))
3577 `(gnus-callback
3578 (lambda (handles)
3579 (unless ,(not ibegend)
3580 (setq gnus-article-mime-handle-alist
3581 ',gnus-article-mime-handle-alist))
3582 (gnus-mime-display-alternative
3583 ',ihandles ',handle ',begend ,id))
3584 ;; Not for Emacs 21: fixme better.
3585 ;; local-map ,gnus-mime-button-map
3586 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3587 face ,gnus-article-button-face
3588 keymap ,gnus-mime-button-map
3589 gnus-part ,id
3590 gnus-data ,handle))
3591 (widget-convert-button 'link from (point)
3592 :action 'gnus-widget-press-button
3593 :button-keymap gnus-widget-button-keymap)
3594 (insert " "))
3595 (insert "\n\n"))
3596 (when preferred
3597 (if (stringp (car preferred))
3598 (gnus-display-mime preferred)
3599 (let ((mail-parse-charset gnus-newsgroup-charset)
3600 (mail-parse-ignored-charsets
3601 (save-excursion (set-buffer gnus-summary-buffer)
3602 gnus-newsgroup-ignored-charsets)))
3603 (mm-display-part preferred)
3604 ;; Do highlighting.
3605 (save-excursion
3606 (save-restriction
3607 (narrow-to-region (car begend) (point-max))
3608 (gnus-treat-article
3609 nil (length gnus-article-mime-handle-alist)
3610 (gnus-article-mime-total-parts)
3611 (mm-handle-media-type handle))))))
3612 (goto-char (point-max))
3613 (setcdr begend (point-marker)))))
3614 (when ibegend
3615 (goto-char point))))
3617 (defun gnus-article-wash-status ()
3618 "Return a string which display status of article washing."
3619 (save-excursion
3620 (set-buffer gnus-article-buffer)
3621 (let ((cite (memq 'cite gnus-article-wash-types))
3622 (headers (memq 'headers gnus-article-wash-types))
3623 (boring (memq 'boring-headers gnus-article-wash-types))
3624 (pgp (memq 'pgp gnus-article-wash-types))
3625 (pem (memq 'pem gnus-article-wash-types))
3626 (signature (memq 'signature gnus-article-wash-types))
3627 (overstrike (memq 'overstrike gnus-article-wash-types))
3628 (emphasis (memq 'emphasis gnus-article-wash-types)))
3629 (format "%c%c%c%c%c%c"
3630 (if cite ?c ? )
3631 (if (or headers boring) ?h ? )
3632 (if (or pgp pem) ?p ? )
3633 (if signature ?s ? )
3634 (if overstrike ?o ? )
3635 (if emphasis ?e ? )))))
3637 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3639 (defun gnus-article-maybe-hide-headers ()
3640 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3641 Provided for backwards compatibility."
3642 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3643 (not (save-excursion (set-buffer gnus-summary-buffer)
3644 gnus-have-all-headers)))
3645 (not gnus-inhibit-hiding))
3646 (gnus-article-hide-headers)))
3648 ;;; Article savers.
3650 (defun gnus-output-to-file (file-name)
3651 "Append the current article to a file named FILE-NAME."
3652 (let ((artbuf (current-buffer)))
3653 (with-temp-buffer
3654 (insert-buffer-substring artbuf)
3655 ;; Append newline at end of the buffer as separator, and then
3656 ;; save it to file.
3657 (goto-char (point-max))
3658 (insert "\n")
3659 (let ((file-name-coding-system nnmail-pathname-coding-system))
3660 (mm-append-to-file (point-min) (point-max) file-name))
3661 t)))
3663 (defun gnus-narrow-to-page (&optional arg)
3664 "Narrow the article buffer to a page.
3665 If given a numerical ARG, move forward ARG pages."
3666 (interactive "P")
3667 (setq arg (if arg (prefix-numeric-value arg) 0))
3668 (save-excursion
3669 (set-buffer gnus-article-buffer)
3670 (goto-char (point-min))
3671 (widen)
3672 ;; Remove any old next/prev buttons.
3673 (when (gnus-visual-p 'page-marker)
3674 (let ((buffer-read-only nil))
3675 (gnus-remove-text-with-property 'gnus-prev)
3676 (gnus-remove-text-with-property 'gnus-next)))
3677 (when
3678 (cond ((< arg 0)
3679 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3680 ((> arg 0)
3681 (re-search-forward page-delimiter nil 'move arg)))
3682 (goto-char (match-end 0)))
3683 (narrow-to-region
3684 (point)
3685 (if (re-search-forward page-delimiter nil 'move)
3686 (match-beginning 0)
3687 (point)))
3688 (when (and (gnus-visual-p 'page-marker)
3689 (not (= (point-min) 1)))
3690 (save-excursion
3691 (goto-char (point-min))
3692 (gnus-insert-prev-page-button)))
3693 (when (and (gnus-visual-p 'page-marker)
3694 (< (+ (point-max) 2) (buffer-size)))
3695 (save-excursion
3696 (goto-char (point-max))
3697 (gnus-insert-next-page-button)))))
3699 ;; Article mode commands
3701 (defun gnus-article-goto-next-page ()
3702 "Show the next page of the article."
3703 (interactive)
3704 (when (gnus-article-next-page)
3705 (goto-char (point-min))
3706 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3708 (defun gnus-article-goto-prev-page ()
3709 "Show the next page of the article."
3710 (interactive)
3711 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3712 (gnus-article-prev-page nil)))
3714 (defun gnus-article-next-page (&optional lines)
3715 "Show the next page of the current article.
3716 If end of article, return non-nil. Otherwise return nil.
3717 Argument LINES specifies lines to be scrolled up."
3718 (interactive "p")
3719 (move-to-window-line -1)
3720 (if (save-excursion
3721 (end-of-line)
3722 (and (pos-visible-in-window-p) ;Not continuation line.
3723 (eobp)))
3724 ;; Nothing in this page.
3725 (if (or (not gnus-page-broken)
3726 (save-excursion
3727 (save-restriction
3728 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3729 t ;Nothing more.
3730 (gnus-narrow-to-page 1) ;Go to next page.
3731 nil)
3732 ;; More in this page.
3733 (let ((scroll-in-place nil))
3734 (condition-case ()
3735 (scroll-up lines)
3736 (end-of-buffer
3737 ;; Long lines may cause an end-of-buffer error.
3738 (goto-char (point-max)))))
3739 (move-to-window-line 0)
3740 nil))
3742 (defun gnus-article-prev-page (&optional lines)
3743 "Show previous page of current article.
3744 Argument LINES specifies lines to be scrolled down."
3745 (interactive "p")
3746 (move-to-window-line 0)
3747 (if (and gnus-page-broken
3748 (bobp)
3749 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3750 (progn
3751 (gnus-narrow-to-page -1) ;Go to previous page.
3752 (goto-char (point-max))
3753 (recenter -1))
3754 (let ((scroll-in-place nil))
3755 (prog1
3756 (condition-case ()
3757 (scroll-down lines)
3758 (beginning-of-buffer
3759 (goto-char (point-min))))
3760 (move-to-window-line 0)))))
3762 (defun gnus-article-refer-article ()
3763 "Read article specified by message-id around point."
3764 (interactive)
3765 (let ((point (point)))
3766 (search-forward ">" nil t) ;Move point to end of "<....>".
3767 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3768 (let ((message-id (match-string 1)))
3769 (goto-char point)
3770 (set-buffer gnus-summary-buffer)
3771 (gnus-summary-refer-article message-id))
3772 (goto-char (point))
3773 (error "No references around point"))))
3775 (defun gnus-article-show-summary ()
3776 "Reconfigure windows to show summary buffer."
3777 (interactive)
3778 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3779 (error "There is no summary buffer for this article buffer")
3780 (gnus-article-set-globals)
3781 (gnus-configure-windows 'article)
3782 (gnus-summary-goto-subject gnus-current-article)
3783 (gnus-summary-position-point)))
3785 (defun gnus-article-describe-briefly ()
3786 "Describe article mode commands briefly."
3787 (interactive)
3788 (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
3790 (defun gnus-article-summary-command ()
3791 "Execute the last keystroke in the summary buffer."
3792 (interactive)
3793 (let ((obuf (current-buffer))
3794 (owin (current-window-configuration))
3795 func)
3796 (switch-to-buffer gnus-article-current-summary 'norecord)
3797 (setq func (lookup-key (current-local-map) (this-command-keys)))
3798 (call-interactively func)
3799 (set-buffer obuf)
3800 (set-window-configuration owin)
3801 (set-window-point (get-buffer-window (current-buffer)) (point))))
3803 (defun gnus-article-summary-command-nosave ()
3804 "Execute the last keystroke in the summary buffer."
3805 (interactive)
3806 (let (func)
3807 (pop-to-buffer gnus-article-current-summary 'norecord)
3808 (setq func (lookup-key (current-local-map) (this-command-keys)))
3809 (call-interactively func)))
3811 (defun gnus-article-check-buffer ()
3812 "Beep if not in an article buffer."
3813 (unless (equal major-mode 'gnus-article-mode)
3814 (error "Command invoked outside of a Gnus article buffer")))
3816 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3817 "Read a summary buffer key sequence and execute it from the article buffer."
3818 (interactive "P")
3819 (gnus-article-check-buffer)
3820 (let ((nosaves
3821 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3822 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3823 "=" "^" "\M-^" "|"))
3824 (nosave-but-article
3825 '("A\r"))
3826 (nosave-in-article
3827 '("\C-d"))
3828 (up-to-top
3829 '("n" "Gn" "p" "Gp"))
3830 keys new-sum-point)
3831 (save-excursion
3832 (set-buffer gnus-article-current-summary)
3833 (let (gnus-pick-mode)
3834 (push (or key last-command-event) unread-command-events)
3835 (setq keys (if (featurep 'xemacs)
3836 (events-to-keys (read-key-sequence nil))
3837 (read-key-sequence nil)))))
3839 (message "")
3841 (if (or (member keys nosaves)
3842 (member keys nosave-but-article)
3843 (member keys nosave-in-article))
3844 (let (func)
3845 (save-window-excursion
3846 (pop-to-buffer gnus-article-current-summary 'norecord)
3847 ;; We disable the pick minor mode commands.
3848 (let (gnus-pick-mode)
3849 (setq func (lookup-key (current-local-map) keys))))
3850 (if (or (not func)
3851 (numberp func))
3852 (ding)
3853 (unless (member keys nosave-in-article)
3854 (set-buffer gnus-article-current-summary))
3855 (call-interactively func)
3856 (setq new-sum-point (point)))
3857 (when (member keys nosave-but-article)
3858 (pop-to-buffer gnus-article-buffer 'norecord)))
3859 ;; These commands should restore window configuration.
3860 (let ((obuf (current-buffer))
3861 (owin (current-window-configuration))
3862 (opoint (point))
3863 (summary gnus-article-current-summary)
3864 func in-buffer selected)
3865 (if not-restore-window
3866 (pop-to-buffer summary 'norecord)
3867 (switch-to-buffer summary 'norecord))
3868 (setq in-buffer (current-buffer))
3869 ;; We disable the pick minor mode commands.
3870 (if (and (setq func (let (gnus-pick-mode)
3871 (lookup-key (current-local-map) keys)))
3872 (functionp func))
3873 (progn
3874 (call-interactively func)
3875 (setq new-sum-point (point))
3876 (when (eq in-buffer (current-buffer))
3877 (setq selected (gnus-summary-select-article))
3878 (set-buffer obuf)
3879 (unless not-restore-window
3880 (set-window-configuration owin))
3881 (when (eq selected 'old)
3882 (article-goto-body)
3883 (set-window-start (get-buffer-window (current-buffer))
3885 (set-window-point (get-buffer-window (current-buffer))
3886 (point)))
3887 (let ((win (get-buffer-window gnus-article-current-summary)))
3888 (when win
3889 (set-window-point win new-sum-point)))) )
3890 (switch-to-buffer gnus-article-buffer)
3891 (ding))))))
3893 (defun gnus-article-describe-key (key)
3894 "Display documentation of the function invoked by KEY. KEY is a string."
3895 (interactive "kDescribe key: ")
3896 (gnus-article-check-buffer)
3897 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
3898 (save-excursion
3899 (set-buffer gnus-article-current-summary)
3900 (let (gnus-pick-mode)
3901 (push (elt key 0) unread-command-events)
3902 (setq key (if (featurep 'xemacs)
3903 (events-to-keys (read-key-sequence "Describe key: "))
3904 (read-key-sequence "Describe key: "))))
3905 (describe-key key))
3906 (describe-key key)))
3908 (defun gnus-article-describe-key-briefly (key &optional insert)
3909 "Display documentation of the function invoked by KEY. KEY is a string."
3910 (interactive "kDescribe key: \nP")
3911 (gnus-article-check-buffer)
3912 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
3913 (save-excursion
3914 (set-buffer gnus-article-current-summary)
3915 (let (gnus-pick-mode)
3916 (push (elt key 0) unread-command-events)
3917 (setq key (if (featurep 'xemacs)
3918 (events-to-keys (read-key-sequence "Describe key: "))
3919 (read-key-sequence "Describe key: "))))
3920 (describe-key-briefly key insert))
3921 (describe-key-briefly key insert)))
3923 (defun gnus-article-hide (&optional arg force)
3924 "Hide all the gruft in the current article.
3925 This means that PGP stuff, signatures, cited text and (some)
3926 headers will be hidden.
3927 If given a prefix, show the hidden text instead."
3928 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3929 (gnus-article-hide-headers arg)
3930 (gnus-article-hide-list-identifiers arg)
3931 (gnus-article-hide-pgp arg)
3932 (gnus-article-hide-citation-maybe arg force)
3933 (gnus-article-hide-signature arg))
3935 (defun gnus-article-maybe-highlight ()
3936 "Do some article highlighting if article highlighting is requested."
3937 (when (gnus-visual-p 'article-highlight 'highlight)
3938 (gnus-article-highlight-some)))
3940 (defun gnus-check-group-server ()
3941 ;; Make sure the connection to the server is alive.
3942 (unless (gnus-server-opened
3943 (gnus-find-method-for-group gnus-newsgroup-name))
3944 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3945 (gnus-request-group gnus-newsgroup-name t)))
3947 (defun gnus-request-article-this-buffer (article group)
3948 "Get an article and insert it into this buffer."
3949 (let (do-update-line sparse-header)
3950 (prog1
3951 (save-excursion
3952 (erase-buffer)
3953 (gnus-kill-all-overlays)
3954 (setq group (or group gnus-newsgroup-name))
3956 ;; Using `gnus-request-article' directly will insert the article into
3957 ;; `nntp-server-buffer' - so we'll save some time by not having to
3958 ;; copy it from the server buffer into the article buffer.
3960 ;; We only request an article by message-id when we do not have the
3961 ;; headers for it, so we'll have to get those.
3962 (when (stringp article)
3963 (gnus-read-header article))
3965 ;; If the article number is negative, that means that this article
3966 ;; doesn't belong in this newsgroup (possibly), so we find its
3967 ;; message-id and request it by id instead of number.
3968 (when (and (numberp article)
3969 gnus-summary-buffer
3970 (get-buffer gnus-summary-buffer)
3971 (gnus-buffer-exists-p gnus-summary-buffer))
3972 (save-excursion
3973 (set-buffer gnus-summary-buffer)
3974 (let ((header (gnus-summary-article-header article)))
3975 (when (< article 0)
3976 (cond
3977 ((memq article gnus-newsgroup-sparse)
3978 ;; This is a sparse gap article.
3979 (setq do-update-line article)
3980 (setq article (mail-header-id header))
3981 (setq sparse-header (gnus-read-header article))
3982 (setq gnus-newsgroup-sparse
3983 (delq article gnus-newsgroup-sparse)))
3984 ((vectorp header)
3985 ;; It's a real article.
3986 (setq article (mail-header-id header)))
3988 ;; It is an extracted pseudo-article.
3989 (setq article 'pseudo)
3990 (gnus-request-pseudo-article header))))
3992 (let ((method (gnus-find-method-for-group
3993 gnus-newsgroup-name)))
3994 (when (and (eq (car method) 'nneething)
3995 (vectorp header))
3996 (let ((dir (expand-file-name
3997 (mail-header-subject header)
3998 (file-name-as-directory
3999 (or (cadr (assq 'nneething-address method))
4000 (nth 1 method))))))
4001 (when (file-directory-p dir)
4002 (setq article 'nneething)
4003 (gnus-group-enter-directory dir))))))))
4005 (cond
4006 ;; Refuse to select canceled articles.
4007 ((and (numberp article)
4008 gnus-summary-buffer
4009 (get-buffer gnus-summary-buffer)
4010 (gnus-buffer-exists-p gnus-summary-buffer)
4011 (eq (cdr (save-excursion
4012 (set-buffer gnus-summary-buffer)
4013 (assq article gnus-newsgroup-reads)))
4014 gnus-canceled-mark))
4015 nil)
4016 ;; We first check `gnus-original-article-buffer'.
4017 ((and (get-buffer gnus-original-article-buffer)
4018 (numberp article)
4019 (save-excursion
4020 (set-buffer gnus-original-article-buffer)
4021 (and (equal (car gnus-original-article) group)
4022 (eq (cdr gnus-original-article) article))))
4023 (insert-buffer-substring gnus-original-article-buffer)
4024 'article)
4025 ;; Check the backlog.
4026 ((and gnus-keep-backlog
4027 (gnus-backlog-request-article group article (current-buffer)))
4028 'article)
4029 ;; Check asynchronous pre-fetch.
4030 ((gnus-async-request-fetched-article group article (current-buffer))
4031 (gnus-async-prefetch-next group article gnus-summary-buffer)
4032 (when (and (numberp article) gnus-keep-backlog)
4033 (gnus-backlog-enter-article group article (current-buffer)))
4034 'article)
4035 ;; Check the cache.
4036 ((and gnus-use-cache
4037 (numberp article)
4038 (gnus-cache-request-article article group))
4039 'article)
4040 ;; Get the article and put into the article buffer.
4041 ((or (stringp article)
4042 (numberp article))
4043 (let ((gnus-override-method gnus-override-method)
4044 (methods (and (stringp article)
4045 gnus-refer-article-method))
4046 result
4047 (buffer-read-only nil))
4048 (if (or (not (listp methods))
4049 (and (symbolp (car methods))
4050 (assq (car methods) nnoo-definition-alist)))
4051 (setq methods (list methods)))
4052 (when (and (null gnus-override-method)
4053 methods)
4054 (setq gnus-override-method (pop methods)))
4055 (while (not result)
4056 (when (eq gnus-override-method 'current)
4057 (setq gnus-override-method
4058 (with-current-buffer gnus-summary-buffer
4059 gnus-current-select-method)))
4060 (erase-buffer)
4061 (gnus-kill-all-overlays)
4062 (let ((gnus-newsgroup-name group))
4063 (gnus-check-group-server))
4064 (when (gnus-request-article article group (current-buffer))
4065 (when (numberp article)
4066 (gnus-async-prefetch-next group article
4067 gnus-summary-buffer)
4068 (when gnus-keep-backlog
4069 (gnus-backlog-enter-article
4070 group article (current-buffer))))
4071 (setq result 'article))
4072 (if (not result)
4073 (if methods
4074 (setq gnus-override-method (pop methods))
4075 (setq result 'done))))
4076 (and (eq result 'article) 'article)))
4077 ;; It was a pseudo.
4078 (t article)))
4080 ;; Associate this article with the current summary buffer.
4081 (setq gnus-article-current-summary gnus-summary-buffer)
4083 ;; Take the article from the original article buffer
4084 ;; and place it in the buffer it's supposed to be in.
4085 (when (and (get-buffer gnus-article-buffer)
4086 (equal (buffer-name (current-buffer))
4087 (buffer-name (get-buffer gnus-article-buffer))))
4088 (save-excursion
4089 (if (get-buffer gnus-original-article-buffer)
4090 (set-buffer gnus-original-article-buffer)
4091 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4092 (buffer-disable-undo)
4093 (setq major-mode 'gnus-original-article-mode)
4094 (setq buffer-read-only t))
4095 (let (buffer-read-only)
4096 (erase-buffer)
4097 (insert-buffer-substring gnus-article-buffer))
4098 (setq gnus-original-article (cons group article)))
4100 ;; Decode charsets.
4101 (run-hooks 'gnus-article-decode-hook)
4102 ;; Mark article as decoded or not.
4103 (setq gnus-article-decoded-p gnus-article-decode-hook))
4105 ;; Update sparse articles.
4106 (when (and do-update-line
4107 (or (numberp article)
4108 (stringp article)))
4109 (let ((buf (current-buffer)))
4110 (set-buffer gnus-summary-buffer)
4111 (gnus-summary-update-article do-update-line sparse-header)
4112 (gnus-summary-goto-subject do-update-line nil t)
4113 (set-window-point (get-buffer-window (current-buffer) t)
4114 (point))
4115 (set-buffer buf))))))
4118 ;;; Article editing
4121 (defcustom gnus-article-edit-mode-hook nil
4122 "Hook run in article edit mode buffers."
4123 :group 'gnus-article-various
4124 :type 'hook)
4126 (defvar gnus-article-edit-done-function nil)
4128 (defvar gnus-article-edit-mode-map nil)
4130 ;; Should we be using derived.el for this?
4131 (unless gnus-article-edit-mode-map
4132 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4133 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4135 (gnus-define-keys gnus-article-edit-mode-map
4136 "\C-c\C-c" gnus-article-edit-done
4137 "\C-c\C-k" gnus-article-edit-exit)
4139 (gnus-define-keys (gnus-article-edit-wash-map
4140 "\C-c\C-w" gnus-article-edit-mode-map)
4141 "f" gnus-article-edit-full-stops))
4143 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
4144 "Major mode for editing articles.
4145 This is an extended text-mode.
4147 \\{gnus-article-edit-mode-map}"
4148 (make-local-variable 'gnus-article-edit-done-function)
4149 (make-local-variable 'gnus-prev-winconf)
4150 (set (make-local-variable 'font-lock-defaults)
4151 '(message-font-lock-keywords t))
4152 (setq buffer-read-only nil)
4153 (buffer-enable-undo)
4154 (widen))
4156 (defun gnus-article-edit (&optional force)
4157 "Edit the current article.
4158 This will have permanent effect only in mail groups.
4159 If FORCE is non-nil, allow editing of articles even in read-only
4160 groups."
4161 (interactive "P")
4162 (when (and (not force)
4163 (gnus-group-read-only-p))
4164 (error "The current newsgroup does not support article editing"))
4165 (gnus-article-date-original)
4166 (gnus-article-edit-article
4167 'ignore
4168 `(lambda (no-highlight)
4169 'ignore
4170 (gnus-summary-edit-article-done
4171 ,(or (mail-header-references gnus-current-headers) "")
4172 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4174 (defun gnus-article-edit-article (start-func exit-func)
4175 "Start editing the contents of the current article buffer."
4176 (let ((winconf (current-window-configuration)))
4177 (set-buffer gnus-article-buffer)
4178 (gnus-article-edit-mode)
4179 (funcall start-func)
4180 (gnus-configure-windows 'edit-article)
4181 (setq gnus-article-edit-done-function exit-func)
4182 (setq gnus-prev-winconf winconf)
4183 (gnus-message 6 "C-c C-c to end edits")))
4185 (defun gnus-article-edit-done (&optional arg)
4186 "Update the article edits and exit."
4187 (interactive "P")
4188 (widen)
4189 (save-excursion
4190 (save-restriction
4191 (when (article-goto-body)
4192 (let ((lines (count-lines (point) (point-max)))
4193 (length (- (point-max) (point)))
4194 (case-fold-search t)
4195 (body (copy-marker (point))))
4196 (goto-char (point-min))
4197 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4198 (delete-region (match-beginning 1) (match-end 1))
4199 (insert (number-to-string length)))
4200 (goto-char (point-min))
4201 (when (re-search-forward
4202 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4203 (delete-region (match-beginning 1) (match-end 1))
4204 (insert (number-to-string length)))
4205 (goto-char (point-min))
4206 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4207 (delete-region (match-beginning 1) (match-end 1))
4208 (insert (number-to-string lines)))))))
4209 (let ((func gnus-article-edit-done-function)
4210 (buf (current-buffer))
4211 (start (window-start)))
4212 (gnus-article-edit-exit)
4213 (save-excursion
4214 (set-buffer buf)
4215 (let ((buffer-read-only nil))
4216 (funcall func arg))
4217 ;; The cache and backlog have to be flushed somewhat.
4218 (when gnus-keep-backlog
4219 (gnus-backlog-remove-article
4220 (car gnus-article-current) (cdr gnus-article-current)))
4221 ;; Flush original article as well.
4222 (save-excursion
4223 (when (get-buffer gnus-original-article-buffer)
4224 (set-buffer gnus-original-article-buffer)
4225 (setq gnus-original-article nil)))
4226 (when gnus-use-cache
4227 (gnus-cache-update-article
4228 (car gnus-article-current) (cdr gnus-article-current))))
4229 (set-buffer buf)
4230 (set-window-start (get-buffer-window buf) start)
4231 (set-window-point (get-buffer-window buf) (point))))
4233 (defun gnus-article-edit-exit ()
4234 "Exit the article editing without updating."
4235 (interactive)
4236 ;; We remove all text props from the article buffer.
4237 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4238 (curbuf (current-buffer))
4239 (p (point))
4240 (window-start (window-start)))
4241 (erase-buffer)
4242 (insert buf)
4243 (let ((winconf gnus-prev-winconf))
4244 (gnus-article-mode)
4245 (set-window-configuration winconf)
4246 ;; Tippy-toe some to make sure that point remains where it was.
4247 (save-current-buffer
4248 (set-buffer curbuf)
4249 (set-window-start (get-buffer-window (current-buffer)) window-start)
4250 (goto-char p)))))
4252 (defun gnus-article-edit-full-stops ()
4253 "Interactively repair spacing at end of sentences."
4254 (interactive)
4255 (save-excursion
4256 (goto-char (point-min))
4257 (search-forward-regexp "^$" nil t)
4258 (let ((case-fold-search nil))
4259 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4262 ;;; Article highlights
4265 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4267 ;;; Internal Variables:
4269 (defcustom gnus-button-url-regexp
4270 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
4271 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,[:word:]]+[-a-zA-Z0-9_=#$@~`%&*+|\\/[:word:]]\\)"
4272 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)")
4273 "Regular expression that matches URLs."
4274 :group 'gnus-article-buttons
4275 :type 'regexp)
4277 (defcustom gnus-button-alist
4278 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4279 0 t gnus-button-message-id 2)
4280 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4281 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4283 gnus-button-fetch-group 4)
4284 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4285 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4286 t gnus-button-message-id 3)
4287 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4288 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4289 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4290 ;; This is how URLs _should_ be embedded in text...
4291 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4292 ;; Raw URLs.
4293 (,gnus-button-url-regexp 0 t browse-url 0))
4294 "*Alist of regexps matching buttons in article bodies.
4296 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4297 REGEXP: is the string matching text around the button,
4298 BUTTON: is the number of the regexp grouping actually matching the button,
4299 FORM: is a lisp expression which must eval to true for the button to
4300 be added,
4301 CALLBACK: is the function to call when the user push this button, and each
4302 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4304 CALLBACK can also be a variable, in that case the value of that
4305 variable it the real callback function."
4306 :group 'gnus-article-buttons
4307 :type '(repeat (list regexp
4308 (integer :tag "Button")
4309 (sexp :tag "Form")
4310 (function :tag "Callback")
4311 (repeat :tag "Par"
4312 :inline t
4313 (integer :tag "Regexp group")))))
4315 (defcustom gnus-header-button-alist
4316 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4317 0 t gnus-button-message-id 0)
4318 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4319 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4320 0 t gnus-button-mailto 0)
4321 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4322 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4323 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4324 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4325 gnus-button-message-id 3))
4326 "*Alist of headers and regexps to match buttons in article heads.
4328 This alist is very similar to `gnus-button-alist', except that each
4329 alist has an additional HEADER element first in each entry:
4331 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4333 HEADER is a regexp to match a header. For a fuller explanation, see
4334 `gnus-button-alist'."
4335 :group 'gnus-article-buttons
4336 :group 'gnus-article-headers
4337 :type '(repeat (list (regexp :tag "Header")
4338 regexp
4339 (integer :tag "Button")
4340 (sexp :tag "Form")
4341 (function :tag "Callback")
4342 (repeat :tag "Par"
4343 :inline t
4344 (integer :tag "Regexp group")))))
4346 (defvar gnus-button-regexp nil)
4347 (defvar gnus-button-marker-list nil)
4348 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4350 (defvar gnus-button-last nil)
4351 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4353 ;;; Commands:
4355 (defun gnus-article-push-button (event)
4356 "Check text under the mouse pointer for a callback function.
4357 If the text under the mouse pointer has a `gnus-callback' property,
4358 call it with the value of the `gnus-data' text property."
4359 (interactive "e")
4360 (set-buffer (window-buffer (posn-window (event-start event))))
4361 (let* ((pos (posn-point (event-start event)))
4362 (data (get-text-property pos 'gnus-data))
4363 (fun (get-text-property pos 'gnus-callback)))
4364 (goto-char pos)
4365 (when fun
4366 (funcall fun data))))
4368 (defun gnus-article-press-button ()
4369 "Check text at point for a callback function.
4370 If the text at point has a `gnus-callback' property,
4371 call it with the value of the `gnus-data' text property."
4372 (interactive)
4373 (let* ((data (get-text-property (point) 'gnus-data))
4374 (fun (get-text-property (point) 'gnus-callback)))
4375 (when fun
4376 (funcall fun data))))
4378 (defun gnus-article-highlight (&optional force)
4379 "Highlight current article.
4380 This function calls `gnus-article-highlight-headers',
4381 `gnus-article-highlight-citation',
4382 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4383 do the highlighting. See the documentation for those functions."
4384 (interactive (list 'force))
4385 (gnus-article-highlight-headers)
4386 (gnus-article-highlight-citation force)
4387 (gnus-article-highlight-signature)
4388 (gnus-article-add-buttons force)
4389 (gnus-article-add-buttons-to-head))
4391 (defun gnus-article-highlight-some (&optional force)
4392 "Highlight current article.
4393 This function calls `gnus-article-highlight-headers',
4394 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4395 do the highlighting. See the documentation for those functions."
4396 (interactive (list 'force))
4397 (gnus-article-highlight-headers)
4398 (gnus-article-highlight-signature)
4399 (gnus-article-add-buttons))
4401 (defun gnus-article-highlight-headers ()
4402 "Highlight article headers as specified by `gnus-header-face-alist'."
4403 (interactive)
4404 (save-excursion
4405 (set-buffer gnus-article-buffer)
4406 (save-restriction
4407 (let ((alist gnus-header-face-alist)
4408 (buffer-read-only nil)
4409 (case-fold-search t)
4410 (inhibit-point-motion-hooks t)
4411 entry regexp header-face field-face from hpoints fpoints)
4412 (article-narrow-to-head)
4413 (while (setq entry (pop alist))
4414 (goto-char (point-min))
4415 (setq regexp (concat "^\\("
4416 (if (string-equal "" (nth 0 entry))
4417 "[^\t ]"
4418 (nth 0 entry))
4419 "\\)")
4420 header-face (nth 1 entry)
4421 field-face (nth 2 entry))
4422 (while (and (re-search-forward regexp nil t)
4423 (not (eobp)))
4424 (beginning-of-line)
4425 (setq from (point))
4426 (unless (search-forward ":" nil t)
4427 (forward-char 1))
4428 (when (and header-face
4429 (not (memq (point) hpoints)))
4430 (push (point) hpoints)
4431 (gnus-put-text-property from (point) 'face header-face))
4432 (when (and field-face
4433 (not (memq (setq from (point)) fpoints)))
4434 (push from fpoints)
4435 (if (re-search-forward "^[^ \t]" nil t)
4436 (forward-char -2)
4437 (goto-char (point-max)))
4438 (gnus-put-text-property from (point) 'face field-face))))))))
4440 (defun gnus-article-highlight-signature ()
4441 "Highlight the signature in an article.
4442 It does this by highlighting everything after
4443 `gnus-signature-separator' using `gnus-signature-face'."
4444 (interactive)
4445 (save-excursion
4446 (set-buffer gnus-article-buffer)
4447 (let ((buffer-read-only nil)
4448 (inhibit-point-motion-hooks t))
4449 (save-restriction
4450 (when (and gnus-signature-face
4451 (gnus-article-narrow-to-signature))
4452 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4453 'face gnus-signature-face)
4454 (widen)
4455 (gnus-article-search-signature)
4456 (let ((start (match-beginning 0))
4457 (end (set-marker (make-marker) (1+ (match-end 0)))))
4458 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4459 end)))))))
4461 (defun gnus-button-in-region-p (b e prop)
4462 "Say whether PROP exists in the region."
4463 (text-property-not-all b e prop nil))
4465 (defun gnus-article-add-buttons (&optional force)
4466 "Find external references in the article and make buttons of them.
4467 \"External references\" are things like Message-IDs and URLs, as
4468 specified by `gnus-button-alist'."
4469 (interactive (list 'force))
4470 (save-excursion
4471 (set-buffer gnus-article-buffer)
4472 (let ((buffer-read-only nil)
4473 (inhibit-point-motion-hooks t)
4474 (case-fold-search t)
4475 (alist gnus-button-alist)
4476 beg entry regexp)
4477 ;; Remove all old markers.
4478 (let (marker entry new-list)
4479 (while (setq marker (pop gnus-button-marker-list))
4480 (if (or (< marker (point-min)) (>= marker (point-max)))
4481 (push marker new-list)
4482 (goto-char marker)
4483 (when (setq entry (gnus-button-entry))
4484 (put-text-property (match-beginning (nth 1 entry))
4485 (match-end (nth 1 entry))
4486 'gnus-callback nil))
4487 (set-marker marker nil)))
4488 (setq gnus-button-marker-list new-list))
4489 ;; We skip the headers.
4490 (article-goto-body)
4491 (setq beg (point))
4492 (while (setq entry (pop alist))
4493 (setq regexp (car entry))
4494 (goto-char beg)
4495 (while (re-search-forward regexp nil t)
4496 (let* ((start (and entry (match-beginning (nth 1 entry))))
4497 (end (and entry (match-end (nth 1 entry))))
4498 (from (match-beginning 0)))
4499 (when (and (or (eq t (nth 2 entry))
4500 (eval (nth 2 entry)))
4501 (not (gnus-button-in-region-p
4502 start end 'gnus-callback)))
4503 ;; That optional form returned non-nil, so we add the
4504 ;; button.
4505 (gnus-article-add-button
4506 start end 'gnus-button-push
4507 (car (push (set-marker (make-marker) from)
4508 gnus-button-marker-list))))))))))
4510 ;; Add buttons to the head of an article.
4511 (defun gnus-article-add-buttons-to-head ()
4512 "Add buttons to the head of the article."
4513 (interactive)
4514 (save-excursion
4515 (set-buffer gnus-article-buffer)
4516 (save-restriction
4517 (let ((buffer-read-only nil)
4518 (inhibit-point-motion-hooks t)
4519 (case-fold-search t)
4520 (alist gnus-header-button-alist)
4521 entry beg end)
4522 (article-narrow-to-head)
4523 (while alist
4524 ;; Each alist entry.
4525 (setq entry (car alist)
4526 alist (cdr alist))
4527 (goto-char (point-min))
4528 (while (re-search-forward (car entry) nil t)
4529 ;; Each header matching the entry.
4530 (setq beg (match-beginning 0))
4531 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4532 (match-beginning 0))
4533 (point-max)))
4534 (goto-char beg)
4535 (while (re-search-forward (nth 1 entry) end t)
4536 ;; Each match within a header.
4537 (let* ((entry (cdr entry))
4538 (start (match-beginning (nth 1 entry)))
4539 (end (match-end (nth 1 entry)))
4540 (form (nth 2 entry)))
4541 (goto-char (match-end 0))
4542 (when (eval form)
4543 (gnus-article-add-button
4544 start end (nth 3 entry)
4545 (buffer-substring (match-beginning (nth 4 entry))
4546 (match-end (nth 4 entry)))))))
4547 (goto-char end)))))))
4549 ;;; External functions:
4551 (defun gnus-article-add-button (from to fun &optional data)
4552 "Create a button between FROM and TO with callback FUN and data DATA."
4553 (when gnus-article-button-face
4554 (gnus-overlay-put (gnus-make-overlay from to)
4555 'face gnus-article-button-face))
4556 (gnus-add-text-properties
4557 from to
4558 (nconc (and gnus-article-mouse-face
4559 (list gnus-mouse-face-prop gnus-article-mouse-face))
4560 (list 'gnus-callback fun)
4561 (and data (list 'gnus-data data))))
4562 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4563 :button-keymap gnus-widget-button-keymap))
4565 ;;; Internal functions:
4567 (defun gnus-article-set-globals ()
4568 (save-excursion
4569 (set-buffer gnus-summary-buffer)
4570 (gnus-set-global-variables)))
4572 (defun gnus-signature-toggle (end)
4573 (save-excursion
4574 (set-buffer gnus-article-buffer)
4575 (let ((buffer-read-only nil)
4576 (inhibit-point-motion-hooks t))
4577 (if (text-property-any end (point-max) 'article-type 'signature)
4578 (gnus-remove-text-properties-when
4579 'article-type 'signature end (point-max)
4580 (cons 'article-type (cons 'signature
4581 gnus-hidden-properties)))
4582 (gnus-add-text-properties-when
4583 'article-type nil end (point-max)
4584 (cons 'article-type (cons 'signature
4585 gnus-hidden-properties)))))))
4587 (defun gnus-button-entry ()
4588 ;; Return the first entry in `gnus-button-alist' matching this place.
4589 (let ((alist gnus-button-alist)
4590 (entry nil))
4591 (while alist
4592 (setq entry (pop alist))
4593 (if (looking-at (car entry))
4594 (setq alist nil)
4595 (setq entry nil)))
4596 entry))
4598 (defun gnus-button-push (marker)
4599 ;; Push button starting at MARKER.
4600 (save-excursion
4601 (goto-char marker)
4602 (let* ((entry (gnus-button-entry))
4603 (inhibit-point-motion-hooks t)
4604 (fun (nth 3 entry))
4605 (args (mapcar (lambda (group)
4606 (let ((string (match-string group)))
4607 (gnus-set-text-properties
4608 0 (length string) nil string)
4609 string))
4610 (nthcdr 4 entry))))
4611 (cond
4612 ((fboundp fun)
4613 (apply fun args))
4614 ((and (boundp fun)
4615 (fboundp (symbol-value fun)))
4616 (apply (symbol-value fun) args))
4618 (gnus-message 1 "You must define `%S' to use this button"
4619 (cons fun args)))))))
4621 (defun gnus-button-message-id (message-id)
4622 "Fetch MESSAGE-ID."
4623 (save-excursion
4624 (set-buffer gnus-summary-buffer)
4625 (gnus-summary-refer-article message-id)))
4627 (defun gnus-button-fetch-group (address)
4628 "Fetch GROUP specified by ADDRESS."
4629 (if (not (string-match "[:/]" address))
4630 ;; This is just a simple group url.
4631 (gnus-group-read-ephemeral-group address gnus-select-method)
4632 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4633 address))
4634 (error "Can't parse %s" address)
4635 (gnus-group-read-ephemeral-group
4636 (match-string 4 address)
4637 `(nntp ,(match-string 1 address)
4638 (nntp-address ,(match-string 1 address))
4639 (nntp-port-number ,(if (match-end 3)
4640 (match-string 3 address)
4641 "nntp")))))))
4643 (defun gnus-url-parse-query-string (query &optional downcase)
4644 (let (retval pairs cur key val)
4645 (setq pairs (split-string query "&"))
4646 (while pairs
4647 (setq cur (car pairs)
4648 pairs (cdr pairs))
4649 (if (not (string-match "=" cur))
4650 nil ; Grace
4651 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4652 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4653 (if downcase
4654 (setq key (downcase key)))
4655 (setq cur (assoc key retval))
4656 (if cur
4657 (setcdr cur (cons val (cdr cur)))
4658 (setq retval (cons (list key val) retval)))))
4659 retval))
4661 (defun gnus-url-unhex (x)
4662 (if (> x ?9)
4663 (if (>= x ?a)
4664 (+ 10 (- x ?a))
4665 (+ 10 (- x ?A)))
4666 (- x ?0)))
4668 (defun gnus-url-unhex-string (str &optional allow-newlines)
4669 "Remove %XXX embedded spaces, etc in a url.
4670 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4671 decoding of carriage returns and line feeds in the string, which is normally
4672 forbidden in URL encoding."
4673 (setq str (or str ""))
4674 (let ((tmp "")
4675 (case-fold-search t))
4676 (while (string-match "%[0-9a-f][0-9a-f]" str)
4677 (let* ((start (match-beginning 0))
4678 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4679 (code (+ (* 16 ch1)
4680 (gnus-url-unhex (elt str (+ start 2))))))
4681 (setq tmp (concat
4682 tmp (substring str 0 start)
4683 (cond
4684 (allow-newlines
4685 (char-to-string code))
4686 ((or (= code ?\n) (= code ?\r))
4687 " ")
4688 (t (char-to-string code))))
4689 str (substring str (match-end 0)))))
4690 (setq tmp (concat tmp str))
4691 tmp))
4693 (defun gnus-url-mailto (url)
4694 ;; Send mail to someone
4695 (when (string-match "mailto:/*\\(.*\\)" url)
4696 (setq url (substring url (match-beginning 1) nil)))
4697 (let (to args subject func)
4698 (if (string-match (regexp-quote "?") url)
4699 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4700 args (gnus-url-parse-query-string
4701 (substring url (match-end 0) nil) t))
4702 (setq to (gnus-url-unhex-string url)))
4703 (setq args (cons (list "to" to) args)
4704 subject (cdr-safe (assoc "subject" args)))
4705 (message-mail)
4706 (while args
4707 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4708 (if (fboundp func)
4709 (funcall func)
4710 (message-position-on-field (caar args)))
4711 (insert (mapconcat 'identity (cdar args) ", "))
4712 (setq args (cdr args)))
4713 (if subject
4714 (message-goto-body)
4715 (message-goto-subject))))
4717 (defun gnus-button-mailto (address)
4718 "Mail to ADDRESS."
4719 (set-buffer (gnus-copy-article-buffer))
4720 (message-reply address))
4722 (defalias 'gnus-button-reply 'message-reply)
4724 (defun gnus-button-embedded-url (address)
4725 "Activate ADDRESS with `browse-url'."
4726 (browse-url (gnus-strip-whitespace address)))
4728 ;;; Next/prev buttons in the article buffer.
4730 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4731 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4733 (defvar gnus-prev-page-map nil)
4734 (unless gnus-prev-page-map
4735 (setq gnus-prev-page-map (make-sparse-keymap))
4736 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4737 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4739 (defun gnus-insert-prev-page-button ()
4740 (let ((buffer-read-only nil))
4741 (gnus-eval-format
4742 gnus-prev-page-line-format nil
4743 `(gnus-prev t local-map ,gnus-prev-page-map
4744 gnus-callback gnus-article-button-prev-page
4745 article-type annotation))))
4747 (defvar gnus-next-page-map nil)
4748 (unless gnus-next-page-map
4749 (setq gnus-next-page-map (make-keymap))
4750 (suppress-keymap gnus-prev-page-map)
4751 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4752 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4754 (defun gnus-button-next-page ()
4755 "Go to the next page."
4756 (interactive)
4757 (let ((win (selected-window)))
4758 (select-window (get-buffer-window gnus-article-buffer t))
4759 (gnus-article-next-page)
4760 (select-window win)))
4762 (defun gnus-button-prev-page ()
4763 "Go to the prev page."
4764 (interactive)
4765 (let ((win (selected-window)))
4766 (select-window (get-buffer-window gnus-article-buffer t))
4767 (gnus-article-prev-page)
4768 (select-window win)))
4770 (defun gnus-insert-next-page-button ()
4771 (let ((buffer-read-only nil))
4772 (gnus-eval-format gnus-next-page-line-format nil
4773 `(gnus-next
4774 t local-map ,gnus-next-page-map
4775 gnus-callback gnus-article-button-next-page
4776 article-type annotation))))
4778 (defun gnus-article-button-next-page (arg)
4779 "Go to the next page."
4780 (interactive "P")
4781 (let ((win (selected-window)))
4782 (select-window (get-buffer-window gnus-article-buffer t))
4783 (gnus-article-next-page)
4784 (select-window win)))
4786 (defun gnus-article-button-prev-page (arg)
4787 "Go to the prev page."
4788 (interactive "P")
4789 (let ((win (selected-window)))
4790 (select-window (get-buffer-window gnus-article-buffer t))
4791 (gnus-article-prev-page)
4792 (select-window win)))
4794 (defvar gnus-decode-header-methods
4795 '(mail-decode-encoded-word-region)
4796 "List of methods used to decode headers.
4798 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4799 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4800 \(REGEXP . FUNCTION), FUNCTION will be only apply to these newsgroups
4801 whose names match REGEXP.
4803 For example:
4804 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4805 mail-decode-encoded-word-region
4806 (\"chinese\" . rfc1843-decode-region))
4809 (defvar gnus-decode-header-methods-cache nil)
4811 (defun gnus-multi-decode-header (start end)
4812 "Apply the functions from `gnus-encoded-word-methods' that match."
4813 (unless (and gnus-decode-header-methods-cache
4814 (eq gnus-newsgroup-name
4815 (car gnus-decode-header-methods-cache)))
4816 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4817 (mapcar (lambda (x)
4818 (if (symbolp x)
4819 (nconc gnus-decode-header-methods-cache (list x))
4820 (if (and gnus-newsgroup-name
4821 (string-match (car x) gnus-newsgroup-name))
4822 (nconc gnus-decode-header-methods-cache
4823 (list (cdr x))))))
4824 gnus-decode-header-methods))
4825 (let ((xlist gnus-decode-header-methods-cache))
4826 (pop xlist)
4827 (save-restriction
4828 (narrow-to-region start end)
4829 (while xlist
4830 (funcall (pop xlist) (point-min) (point-max))))))
4833 ;;; Treatment top-level handling.
4836 (defun gnus-treat-article (condition &optional part-number total-parts type)
4837 (let ((length (- (point-max) (point-min)))
4838 (alist gnus-treatment-function-alist)
4839 (article-goto-body-goes-to-point-min-p t)
4840 (treated-type
4841 (or (not type)
4842 (catch 'found
4843 (let ((list gnus-article-treat-types))
4844 (while list
4845 (when (string-match (pop list) type)
4846 (throw 'found t)))))))
4847 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4848 val elem)
4849 (gnus-run-hooks 'gnus-part-display-hook)
4850 (while (setq elem (pop alist))
4851 (setq val
4852 (save-excursion
4853 (if (gnus-buffer-live-p gnus-summary-buffer)
4854 (set-buffer gnus-summary-buffer))
4855 (symbol-value (car elem))))
4856 (when (and (or (consp val)
4857 treated-type)
4858 (gnus-treat-predicate val)
4859 (or (not (get (car elem) 'highlight))
4860 highlightp))
4861 (save-restriction
4862 (funcall (cadr elem)))))))
4864 ;; Dynamic variables.
4865 (eval-when-compile
4866 (defvar part-number)
4867 (defvar total-parts)
4868 (defvar type)
4869 (defvar condition)
4870 (defvar length))
4872 (defun gnus-treat-predicate (val)
4873 (cond
4874 ((null val)
4875 nil)
4876 ((and (listp val)
4877 (stringp (car val)))
4878 (apply 'gnus-or (mapcar `(lambda (s)
4879 (string-match s ,(or gnus-newsgroup-name "")))
4880 val)))
4881 ((listp val)
4882 (let ((pred (pop val)))
4883 (cond
4884 ((eq pred 'or)
4885 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4886 ((eq pred 'and)
4887 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4888 ((eq pred 'not)
4889 (not (gnus-treat-predicate (car val))))
4890 ((eq pred 'typep)
4891 (equal (car val) type))
4893 (error "%S is not a valid predicate" pred)))))
4894 (condition
4895 (eq condition val))
4896 ((eq val t)
4898 ((eq val 'head)
4899 nil)
4900 ((eq val 'last)
4901 (eq part-number total-parts))
4902 ((numberp val)
4903 (< length val))
4905 (error "%S is not a valid value" val))))
4907 (gnus-ems-redefine)
4909 (provide 'gnus-art)
4911 (run-hooks 'gnus-art-load-hook)
4913 ;;; gnus-art.el ends here