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