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