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