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