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