*** empty log message ***
[emacs.git] / lisp / gnus / gnus-art.el
blob55e51d8c128d9b38a6b756aee0ff1224aa30edb5
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news
7 ;; This file is part of GNU Emacs.
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.
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.
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.
24 ;;; Commentary:
26 ;;; Code:
28 (eval-when-compile (require 'cl))
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)
41 (defgroup gnus-article nil
42 "Article display."
43 :link '(custom-manual "(gnus)The Article Buffer")
44 :group 'gnus)
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
49 :group 'gnus-article)
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
54 :group 'gnus-article)
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
59 :group 'gnus-article
60 :group 'gnus-visual)
62 (defgroup gnus-article-signature nil
63 "Article signatures."
64 :link '(custom-manual "(gnus)Article Signature")
65 :group 'gnus-article)
67 (defgroup gnus-article-headers nil
68 "Article headers."
69 :link '(custom-manual "(gnus)Hiding Headers")
70 :group 'gnus-article)
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
75 :group 'gnus-article)
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
80 :group 'gnus-article)
82 (defgroup gnus-article-saving nil
83 "Saving articles."
84 :link '(custom-manual "(gnus)Saving Articles")
85 :group 'gnus-article)
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
90 :group 'gnus-article)
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
95 :group 'gnus-article)
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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:
256 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
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)
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)
279 (defface gnus-emphasis-bold '((t (:bold t)))
280 "Face used for displaying strong emphasized text (*word*)."
281 :group 'gnus-article-emphasis)
283 (defface gnus-emphasis-italic '((t (:italic t)))
284 "Face used for displaying italic emphasized text (/word/)."
285 :group 'gnus-article-emphasis)
287 (defface gnus-emphasis-underline '((t (:underline t)))
288 "Face used for displaying underlined emphasized text (_word_)."
289 :group 'gnus-article-emphasis)
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)
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)
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)
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)
309 (defface gnus-emphasis-highlight-words
310 '((t (:background "black" :foreground "yellow")))
311 "Face used for displaying highlighted words."
312 :group 'gnus-article-emphasis)
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.
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)
325 (eval-and-compile
326 (autoload 'mail-extract-address-components "mail-extr"))
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)
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)))
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)
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).
359 Gnus provides the following functions:
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)))
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)
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)
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)
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)
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:
408 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
409 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
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.
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.
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))))
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)
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.
438 The following additional specs are available:
440 %w The article washing status.
441 %m The number of MIME parts in the article."
442 :type 'string
443 :group 'gnus-article-various)
445 (defcustom gnus-article-mode-hook nil
446 "*A hook for Gnus article mode."
447 :type 'hook
448 :group 'gnus-article-various)
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)
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)
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)
465 (defcustom gnus-article-button-face 'bold
466 "Face used for highlighting buttons in the article buffer.
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)
473 (defcustom gnus-article-mouse-face 'highlight
474 "Face used for mouse highlighting in the article buffer.
476 Article buttons will be displayed in this face when the cursor is
477 above them."
478 :type 'face
479 :group 'gnus-article-buttons)
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)
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)
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"))
503 (:italic t)))
504 "Face used for displaying from headers."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight)
508 (defface gnus-header-subject-face
509 '((((class color)
510 (background dark))
511 (:foreground "SeaGreen3"))
512 (((class color)
513 (background light))
514 (:foreground "red4"))
516 (:bold t :italic t)))
517 "Face used for displaying subject headers."
518 :group 'gnus-article-headers
519 :group 'gnus-article-highlight)
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))
529 (:italic t)))
530 "Face used for displaying newsgroups headers."
531 :group 'gnus-article-headers
532 :group 'gnus-article-highlight)
534 (defface gnus-header-name-face
535 '((((class color)
536 (background dark))
537 (:foreground "SeaGreen"))
538 (((class color)
539 (background light))
540 (:foreground "maroon"))
542 (:bold t)))
543 "Face used for displaying header names."
544 :group 'gnus-article-headers
545 :group 'gnus-article-highlight)
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))
555 (:italic t))) "Face used for displaying header content."
556 :group 'gnus-article-headers
557 :group 'gnus-article-highlight)
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.
566 An alist of the form (HEADER NAME CONTENT).
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.
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)))))
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)
591 (defcustom gnus-display-mime-function 'gnus-display-mime
592 "Function to display MIME articles."
593 :group 'gnus-article-mime
594 :type 'function)
596 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
597 "Function used to decode headers.")
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.")
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))
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))
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)
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)
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)
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)))
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))))
686 ;;; The treatment variables
689 (defvar gnus-part-display-hook nil
690 "Hook called on parts that are to receive treatment.")
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")))
701 (defvar gnus-article-treat-head-custom
702 '(choice (const :tag "Off" nil)
703 (const :tag "Header" head)))
705 (defvar gnus-article-treat-types '("text/plain")
706 "Parts to treat.")
708 (defvar gnus-inhibit-treatment nil
709 "Whether to inhibit treatment.")
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
990 ;;; Internal variables
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)
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)))
1037 (defvar gnus-article-mime-handle-alist nil)
1038 (defvar article-lapsed-timer nil)
1039 (defvar gnus-article-current-summary nil)
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.")
1050 (defvar gnus-save-article-buffer nil)
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))
1057 (defvar gnus-number-of-articles-to-be-saved nil)
1059 (defvar gnus-inhibit-hiding nil)
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)))))
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)))
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))))
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)))
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)))))
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)))))))
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)))))))
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))
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))
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))))))))
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)
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)))))))))))))
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))))
1295 (defvar gnus-article-normalized-header-length 40
1296 "Length of normalized headers.")
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))
1322 ;; Do nothing.
1324 (forward-line 1))))))
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.
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))
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)))))
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)))))))))
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)))))))))
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)))))))
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)))))
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)))))
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))))))
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"))))))))))
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)))))
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)))))))
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)))))
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))))))
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)))))))
1633 (eval-when-compile
1634 (require 'rfc1843))
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)))))
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))))))))
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))))))))))
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
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))))))
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
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)))))))
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))))))))))
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))))))
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)))))))
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)))))
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))))))
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)))
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
1852 ((search-forward "\n\n" nil t)
1855 (goto-char (point-max))
1856 nil)))
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))))))
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)))))
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)))))
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))
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)))))
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)))))
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))
1953 (goto-char cur)
1954 nil)))
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)))
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)
1977 (if (eq hide 'hidden)
1978 (progn
1979 (gnus-article-show-hidden-text type)
1981 nil)))))))
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)))
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)))))
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.")
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]")
2033 "^Date:[ \t]")))
2034 (date (if (vectorp header) (mail-header-date header)
2035 header))
2036 (inhibit-point-motion-hooks t)
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))))))))
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")
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.
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"))))))
2169 (error "Unknown conversion type: %s" type)))))
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))
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))
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))
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)))))
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)))
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)))
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))
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))
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)))))
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)))))))))
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)))))
2292 (defvar gnus-summary-article-menu)
2293 (defvar gnus-summary-post-menu)
2295 ;;; Saving functions.
2297 (defun gnus-article-save (save-buffer file &optional num)
2298 "Save the currently selected article."
2299 (unless gnus-save-all-headers
2300 ;; Remove headers according to `gnus-saved-headers'.
2301 (let ((gnus-visible-headers
2302 (or gnus-saved-headers gnus-visible-headers))
2303 (gnus-article-buffer save-buffer))
2304 (save-excursion
2305 (set-buffer save-buffer)
2306 (article-hide-headers 1 t))))
2307 (save-window-excursion
2308 (if (not gnus-default-article-saver)
2309 (error "No default saver is defined")
2310 ;; !!! Magic! The saving functions all save
2311 ;; `gnus-save-article-buffer' (or so they think), but we
2312 ;; bind that variable to our save-buffer.
2313 (set-buffer gnus-article-buffer)
2314 (let* ((gnus-save-article-buffer save-buffer)
2315 (filename
2316 (cond
2317 ((not gnus-prompt-before-saving) 'default)
2318 ((eq gnus-prompt-before-saving 'always) nil)
2319 (t file)))
2320 (gnus-number-of-articles-to-be-saved
2321 (when (eq gnus-prompt-before-saving t)
2322 num))) ; Magic
2323 (set-buffer gnus-article-current-summary)
2324 (funcall gnus-default-article-saver filename)))))
2326 (defun gnus-read-save-file-name (prompt &optional filename
2327 function group headers variable)
2328 (let ((default-name
2329 (funcall function group headers (symbol-value variable)))
2330 result)
2331 (setq result
2332 (expand-file-name
2333 (cond
2334 ((eq filename 'default)
2335 default-name)
2336 ((eq filename t)
2337 default-name)
2338 (filename filename)
2340 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2341 (prompt
2342 (format prompt
2343 (if (and gnus-number-of-articles-to-be-saved
2344 (> gnus-number-of-articles-to-be-saved 1))
2345 (format "these %d articles"
2346 gnus-number-of-articles-to-be-saved)
2347 "this article")))
2348 (file
2349 ;; Let the split methods have their say.
2350 (cond
2351 ;; No split name was found.
2352 ((null split-name)
2353 (read-file-name
2354 (concat prompt " (default "
2355 (file-name-nondirectory default-name) ") ")
2356 (file-name-directory default-name)
2357 default-name))
2358 ;; A single group name is returned.
2359 ((stringp split-name)
2360 (setq default-name
2361 (funcall function split-name headers
2362 (symbol-value variable)))
2363 (read-file-name
2364 (concat prompt " (default "
2365 (file-name-nondirectory default-name) ") ")
2366 (file-name-directory default-name)
2367 default-name))
2368 ;; A single split name was found
2369 ((= 1 (length split-name))
2370 (let* ((name (expand-file-name
2371 (car split-name) gnus-article-save-directory))
2372 (dir (cond ((file-directory-p name)
2373 (file-name-as-directory name))
2374 ((file-exists-p name) name)
2375 (t gnus-article-save-directory))))
2376 (read-file-name
2377 (concat prompt " (default " name ") ")
2378 dir name)))
2379 ;; A list of splits was found.
2381 (setq split-name (nreverse split-name))
2382 (let (result)
2383 (let ((file-name-history
2384 (nconc split-name file-name-history)))
2385 (setq result
2386 (expand-file-name
2387 (read-file-name
2388 (concat prompt " (`M-p' for defaults) ")
2389 gnus-article-save-directory
2390 (car split-name))
2391 gnus-article-save-directory)))
2392 (car (push result file-name-history)))))))
2393 ;; Create the directory.
2394 (gnus-make-directory (file-name-directory file))
2395 ;; If we have read a directory, we append the default file name.
2396 (when (file-directory-p file)
2397 (setq file (expand-file-name (file-name-nondirectory default-name)
2398 (file-name-as-directory file))))
2399 ;; Possibly translate some characters.
2400 (nnheader-translate-file-chars file))))))
2401 (gnus-make-directory (file-name-directory result))
2402 (set variable result)))
2404 (defun gnus-article-archive-name (group)
2405 "Return the first instance of an \"Archive-name\" in the current buffer."
2406 (let ((case-fold-search t))
2407 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2408 (nnheader-concat gnus-article-save-directory
2409 (match-string 1)))))
2411 (defun gnus-article-nndoc-name (group)
2412 "If GROUP is an nndoc group, return the name of the parent group."
2413 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2414 (gnus-group-get-parameter group 'save-article-group)))
2416 (defun gnus-summary-save-in-rmail (&optional filename)
2417 "Append this article to Rmail file.
2418 Optional argument FILENAME specifies file name.
2419 Directory to save to is default to `gnus-article-save-directory'."
2420 (setq filename (gnus-read-save-file-name
2421 "Save %s in rmail file:" filename
2422 gnus-rmail-save-name gnus-newsgroup-name
2423 gnus-current-headers 'gnus-newsgroup-last-rmail))
2424 (gnus-eval-in-buffer-window gnus-save-article-buffer
2425 (save-excursion
2426 (save-restriction
2427 (widen)
2428 (gnus-output-to-rmail filename))))
2429 filename)
2431 (defun gnus-summary-save-in-mail (&optional filename)
2432 "Append this article to Unix mail file.
2433 Optional argument FILENAME specifies file name.
2434 Directory to save to is default to `gnus-article-save-directory'."
2435 (setq filename (gnus-read-save-file-name
2436 "Save %s in Unix mail file:" filename
2437 gnus-mail-save-name gnus-newsgroup-name
2438 gnus-current-headers 'gnus-newsgroup-last-mail))
2439 (gnus-eval-in-buffer-window gnus-save-article-buffer
2440 (save-excursion
2441 (save-restriction
2442 (widen)
2443 (if (and (file-readable-p filename)
2444 (mail-file-babyl-p filename))
2445 (rmail-output-to-rmail-file filename t)
2446 (gnus-output-to-mail filename)))))
2447 filename)
2449 (defun gnus-summary-save-in-file (&optional filename overwrite)
2450 "Append this article to file.
2451 Optional argument FILENAME specifies file name.
2452 Directory to save to is default to `gnus-article-save-directory'."
2453 (setq filename (gnus-read-save-file-name
2454 "Save %s in file:" filename
2455 gnus-file-save-name gnus-newsgroup-name
2456 gnus-current-headers 'gnus-newsgroup-last-file))
2457 (gnus-eval-in-buffer-window gnus-save-article-buffer
2458 (save-excursion
2459 (save-restriction
2460 (widen)
2461 (when (and overwrite
2462 (file-exists-p filename))
2463 (delete-file filename))
2464 (gnus-output-to-file filename))))
2465 filename)
2467 (defun gnus-summary-write-to-file (&optional filename)
2468 "Write this article to a file.
2469 Optional argument FILENAME specifies file name.
2470 The directory to save in defaults to `gnus-article-save-directory'."
2471 (gnus-summary-save-in-file nil t))
2473 (defun gnus-summary-save-body-in-file (&optional filename)
2474 "Append this article body to a file.
2475 Optional argument FILENAME specifies file name.
2476 The directory to save in defaults to `gnus-article-save-directory'."
2477 (setq filename (gnus-read-save-file-name
2478 "Save %s body in file:" filename
2479 gnus-file-save-name gnus-newsgroup-name
2480 gnus-current-headers 'gnus-newsgroup-last-file))
2481 (gnus-eval-in-buffer-window gnus-save-article-buffer
2482 (save-excursion
2483 (save-restriction
2484 (widen)
2485 (when (article-goto-body)
2486 (narrow-to-region (point) (point-max)))
2487 (gnus-output-to-file filename))))
2488 filename)
2490 (defun gnus-summary-save-in-pipe (&optional command)
2491 "Pipe this article to subprocess."
2492 (setq command
2493 (cond ((and (eq command 'default)
2494 gnus-last-shell-command)
2495 gnus-last-shell-command)
2496 ((stringp command)
2497 command)
2498 (t (read-string
2499 (format
2500 "Shell command on %s: "
2501 (if (and gnus-number-of-articles-to-be-saved
2502 (> gnus-number-of-articles-to-be-saved 1))
2503 (format "these %d articles"
2504 gnus-number-of-articles-to-be-saved)
2505 "this article"))
2506 gnus-last-shell-command))))
2507 (when (string-equal command "")
2508 (if gnus-last-shell-command
2509 (setq command gnus-last-shell-command)
2510 (error "A command is required.")))
2511 (gnus-eval-in-buffer-window gnus-article-buffer
2512 (save-restriction
2513 (widen)
2514 (shell-command-on-region (point-min) (point-max) command nil)))
2515 (setq gnus-last-shell-command command))
2517 ;;; Article file names when saving.
2519 (defun gnus-capitalize-newsgroup (newsgroup)
2520 "Capitalize NEWSGROUP name."
2521 (when (not (zerop (length newsgroup)))
2522 (concat (char-to-string (upcase (aref newsgroup 0)))
2523 (substring newsgroup 1))))
2525 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2526 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2527 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2528 Otherwise, it is like ~/News/news/group/num."
2529 (let ((default
2530 (expand-file-name
2531 (concat (if (gnus-use-long-file-name 'not-save)
2532 (gnus-capitalize-newsgroup newsgroup)
2533 (gnus-newsgroup-directory-form newsgroup))
2534 "/" (int-to-string (mail-header-number headers)))
2535 gnus-article-save-directory)))
2536 (if (and last-file
2537 (string-equal (file-name-directory default)
2538 (file-name-directory last-file))
2539 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2540 default
2541 (or last-file default))))
2543 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2544 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2545 If variable `gnus-use-long-file-name' is non-nil, it is
2546 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2547 (let ((default
2548 (expand-file-name
2549 (concat (if (gnus-use-long-file-name 'not-save)
2550 newsgroup
2551 (gnus-newsgroup-directory-form newsgroup))
2552 "/" (int-to-string (mail-header-number headers)))
2553 gnus-article-save-directory)))
2554 (if (and last-file
2555 (string-equal (file-name-directory default)
2556 (file-name-directory last-file))
2557 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2558 default
2559 (or last-file default))))
2561 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2562 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2563 If variable `gnus-use-long-file-name' is non-nil, it is
2564 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2565 (or last-file
2566 (expand-file-name
2567 (if (gnus-use-long-file-name 'not-save)
2568 newsgroup
2569 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2570 gnus-article-save-directory)))
2572 (eval-and-compile
2573 (mapcar
2574 (lambda (func)
2575 (let (afunc gfunc)
2576 (if (consp func)
2577 (setq afunc (car func)
2578 gfunc (cdr func))
2579 (setq afunc func
2580 gfunc (intern (format "gnus-%s" func))))
2581 (defalias gfunc
2582 (if (fboundp afunc)
2583 `(lambda (&optional interactive &rest args)
2584 ,(documentation afunc t)
2585 (interactive (list t))
2586 (save-excursion
2587 (set-buffer gnus-article-buffer)
2588 (if interactive
2589 (call-interactively ',afunc)
2590 (apply ',afunc args))))))))
2591 '(article-hide-headers
2592 article-hide-boring-headers
2593 article-treat-overstrike
2594 article-fill-long-lines
2595 article-capitalize-sentences
2596 article-remove-cr
2597 article-display-x-face
2598 article-de-quoted-unreadable
2599 article-de-base64-unreadable
2600 article-decode-HZ
2601 article-wash-html
2602 article-hide-list-identifiers
2603 article-hide-pgp
2604 article-strip-banner
2605 article-babel
2606 article-hide-pem
2607 article-hide-signature
2608 article-strip-headers-in-body
2609 article-remove-trailing-blank-lines
2610 article-strip-leading-blank-lines
2611 article-strip-multiple-blank-lines
2612 article-strip-leading-space
2613 article-strip-trailing-space
2614 article-strip-blank-lines
2615 article-strip-all-blank-lines
2616 article-date-local
2617 article-date-iso8601
2618 article-date-original
2619 article-date-ut
2620 article-decode-mime-words
2621 article-decode-charset
2622 article-decode-encoded-words
2623 article-date-user
2624 article-date-lapsed
2625 article-emphasize
2626 article-treat-dumbquotes
2627 article-normalize-headers
2628 (article-show-all . gnus-article-show-all-headers))))
2631 ;;; Gnus article mode
2634 (put 'gnus-article-mode 'mode-class 'special)
2636 (set-keymap-parent gnus-article-mode-map widget-keymap)
2638 (gnus-define-keys gnus-article-mode-map
2639 " " gnus-article-goto-next-page
2640 "\177" gnus-article-goto-prev-page
2641 [delete] gnus-article-goto-prev-page
2642 [backspace] gnus-article-goto-prev-page
2643 "\C-c^" gnus-article-refer-article
2644 "h" gnus-article-show-summary
2645 "s" gnus-article-show-summary
2646 "\C-c\C-m" gnus-article-mail
2647 "?" gnus-article-describe-briefly
2648 "e" gnus-summary-edit-article
2649 "<" beginning-of-buffer
2650 ">" end-of-buffer
2651 "\C-c\C-i" gnus-info-find-node
2652 "\C-c\C-b" gnus-bug
2653 "\C-hk" gnus-article-describe-key
2654 "\C-hc" gnus-article-describe-key-briefly
2656 "\C-d" gnus-article-read-summary-keys
2657 "\M-*" gnus-article-read-summary-keys
2658 "\M-#" gnus-article-read-summary-keys
2659 "\M-^" gnus-article-read-summary-keys
2660 "\M-g" gnus-article-read-summary-keys)
2662 (substitute-key-definition
2663 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2665 (defun gnus-article-make-menu-bar ()
2666 (gnus-turn-off-edit-menu 'article)
2667 (unless (boundp 'gnus-article-article-menu)
2668 (easy-menu-define
2669 gnus-article-article-menu gnus-article-mode-map ""
2670 '("Article"
2671 ["Scroll forwards" gnus-article-goto-next-page t]
2672 ["Scroll backwards" gnus-article-goto-prev-page t]
2673 ["Show summary" gnus-article-show-summary t]
2674 ["Fetch Message-ID at point" gnus-article-refer-article t]
2675 ["Mail to address at point" gnus-article-mail t]
2676 ["Send a bug report" gnus-bug t]))
2678 (easy-menu-define
2679 gnus-article-treatment-menu gnus-article-mode-map ""
2680 ;; Fixme: this should use :active (and maybe :visible).
2681 '("Treatment"
2682 ["Hide headers" gnus-article-hide-headers t]
2683 ["Hide signature" gnus-article-hide-signature t]
2684 ["Hide citation" gnus-article-hide-citation t]
2685 ["Treat overstrike" gnus-article-treat-overstrike t]
2686 ["Remove carriage return" gnus-article-remove-cr t]
2687 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2688 ["Remove base64" gnus-article-de-base64-unreadable t]
2689 ["Treat html" gnus-article-wash-html t]
2690 ["Decode HZ" gnus-article-decode-HZ t]))
2692 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2694 (when (boundp 'gnus-summary-post-menu)
2695 (define-key gnus-article-mode-map [menu-bar post]
2696 (cons "Post" gnus-summary-post-menu)))
2698 (gnus-run-hooks 'gnus-article-menu-hook)))
2700 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2701 ;; Summary.
2703 (defun gnus-article-mode ()
2704 "Major mode for displaying an article.
2706 All normal editing commands are switched off.
2708 The following commands are available in addition to all summary mode
2709 commands:
2710 \\<gnus-article-mode-map>
2711 \\[gnus-article-next-page]\t Scroll the article one page forwards
2712 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2713 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2714 \\[gnus-article-show-summary]\t Display the summary buffer
2715 \\[gnus-article-mail]\t Send a reply to the address near point
2716 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2717 \\[gnus-info-find-node]\t Go to the Gnus info node"
2718 (interactive)
2719 (when (gnus-visual-p 'article-menu 'menu)
2720 (gnus-article-make-menu-bar))
2721 (gnus-simplify-mode-line)
2722 (setq mode-name "Article")
2723 (setq major-mode 'gnus-article-mode)
2724 (make-local-variable 'minor-mode-alist)
2725 (use-local-map gnus-article-mode-map)
2726 (gnus-update-format-specifications nil 'article-mode)
2727 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2728 (make-local-variable 'gnus-page-broken)
2729 (make-local-variable 'gnus-button-marker-list)
2730 (make-local-variable 'gnus-article-current-summary)
2731 (make-local-variable 'gnus-article-mime-handles)
2732 (make-local-variable 'gnus-article-decoded-p)
2733 (make-local-variable 'gnus-article-mime-handle-alist)
2734 (make-local-variable 'gnus-article-wash-types)
2735 (gnus-set-default-directory)
2736 (buffer-disable-undo)
2737 (setq buffer-read-only t)
2738 (set-syntax-table gnus-article-mode-syntax-table)
2739 (mm-enable-multibyte)
2740 (gnus-run-hooks 'gnus-article-mode-hook))
2742 (defun gnus-article-setup-buffer ()
2743 "Initialize the article buffer."
2744 (let* ((name (if gnus-single-article-buffer "*Article*"
2745 (concat "*Article " gnus-newsgroup-name "*")))
2746 (original
2747 (progn (string-match "\\*Article" name)
2748 (concat " *Original Article"
2749 (substring name (match-end 0))))))
2750 (setq gnus-article-buffer name)
2751 (setq gnus-original-article-buffer original)
2752 (setq gnus-article-mime-handle-alist nil)
2753 ;; This might be a variable local to the summary buffer.
2754 (unless gnus-single-article-buffer
2755 (save-excursion
2756 (set-buffer gnus-summary-buffer)
2757 (setq gnus-article-buffer name)
2758 (setq gnus-original-article-buffer original)
2759 (gnus-set-global-variables)))
2760 (gnus-article-setup-highlight-words)
2761 ;; Init original article buffer.
2762 (save-excursion
2763 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2764 (mm-enable-multibyte)
2765 (setq major-mode 'gnus-original-article-mode)
2766 (make-local-variable 'gnus-original-article))
2767 (if (get-buffer name)
2768 (save-excursion
2769 (set-buffer name)
2770 (when gnus-article-mime-handles
2771 (mm-destroy-parts gnus-article-mime-handles)
2772 (setq gnus-article-mime-handles nil))
2773 ;; Set it to nil in article-buffer!
2774 (setq gnus-article-mime-handle-alist nil)
2775 (buffer-disable-undo)
2776 (setq buffer-read-only t)
2777 (unless (eq major-mode 'gnus-article-mode)
2778 (gnus-article-mode))
2779 (current-buffer))
2780 (save-excursion
2781 (set-buffer (gnus-get-buffer-create name))
2782 (gnus-article-mode)
2783 (make-local-variable 'gnus-summary-buffer)
2784 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2785 (current-buffer)))))
2787 ;; Set article window start at LINE, where LINE is the number of lines
2788 ;; from the head of the article.
2789 (defun gnus-article-set-window-start (&optional line)
2790 (set-window-start
2791 (get-buffer-window gnus-article-buffer t)
2792 (save-excursion
2793 (set-buffer gnus-article-buffer)
2794 (goto-char (point-min))
2795 (if (not line)
2796 (point-min)
2797 (gnus-message 6 "Moved to bookmark")
2798 (search-forward "\n\n" nil t)
2799 (forward-line line)
2800 (point)))))
2802 (defun gnus-article-prepare (article &optional all-headers header)
2803 "Prepare ARTICLE in article mode buffer.
2804 ARTICLE should either be an article number or a Message-ID.
2805 If ARTICLE is an id, HEADER should be the article headers.
2806 If ALL-HEADERS is non-nil, no headers are hidden."
2807 (save-excursion
2808 ;; Make sure we start in a summary buffer.
2809 (unless (eq major-mode 'gnus-summary-mode)
2810 (set-buffer gnus-summary-buffer))
2811 (setq gnus-summary-buffer (current-buffer))
2812 (let* ((gnus-article (if header (mail-header-number header) article))
2813 (summary-buffer (current-buffer))
2814 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2815 (group gnus-newsgroup-name)
2816 result)
2817 (save-excursion
2818 (gnus-article-setup-buffer)
2819 (set-buffer gnus-article-buffer)
2820 ;; Deactivate active regions.
2821 (when (and (boundp 'transient-mark-mode)
2822 transient-mark-mode)
2823 (setq mark-active nil))
2824 (if (not (setq result (let ((buffer-read-only nil))
2825 (gnus-request-article-this-buffer
2826 article group))))
2827 ;; There is no such article.
2828 (save-excursion
2829 (when (and (numberp article)
2830 (not (memq article gnus-newsgroup-sparse)))
2831 (setq gnus-article-current
2832 (cons gnus-newsgroup-name article))
2833 (set-buffer gnus-summary-buffer)
2834 (setq gnus-current-article article)
2835 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2836 (progn
2837 (gnus-summary-set-agent-mark article)
2838 (message "Message marked for downloading"))
2839 (gnus-summary-mark-article article gnus-canceled-mark)
2840 (unless (memq article gnus-newsgroup-sparse)
2841 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2842 (if (or (eq result 'pseudo)
2843 (eq result 'nneething))
2844 (progn
2845 (save-excursion
2846 (set-buffer summary-buffer)
2847 (push article gnus-newsgroup-history)
2848 (setq gnus-last-article gnus-current-article
2849 gnus-current-article 0
2850 gnus-current-headers nil
2851 gnus-article-current nil)
2852 (if (eq result 'nneething)
2853 (gnus-configure-windows 'summary)
2854 (gnus-configure-windows 'article))
2855 (gnus-set-global-variables))
2856 (let ((gnus-article-mime-handle-alist-1
2857 gnus-article-mime-handle-alist))
2858 (gnus-set-mode-line 'article)))
2859 ;; The result from the `request' was an actual article -
2860 ;; or at least some text that is now displayed in the
2861 ;; article buffer.
2862 (when (and (numberp article)
2863 (not (eq article gnus-current-article)))
2864 ;; Seems like a new article has been selected.
2865 ;; `gnus-current-article' must be an article number.
2866 (save-excursion
2867 (set-buffer summary-buffer)
2868 (push article gnus-newsgroup-history)
2869 (setq gnus-last-article gnus-current-article
2870 gnus-current-article article
2871 gnus-current-headers
2872 (gnus-summary-article-header gnus-current-article)
2873 gnus-article-current
2874 (cons gnus-newsgroup-name gnus-current-article))
2875 (unless (vectorp gnus-current-headers)
2876 (setq gnus-current-headers nil))
2877 (gnus-summary-goto-subject gnus-current-article)
2878 (when (gnus-summary-show-thread)
2879 ;; If the summary buffer really was folded, the
2880 ;; previous goto may not actually have gone to
2881 ;; the right article, but the thread root instead.
2882 ;; So we go again.
2883 (gnus-summary-goto-subject gnus-current-article))
2884 (gnus-run-hooks 'gnus-mark-article-hook)
2885 (gnus-set-mode-line 'summary)
2886 (when (gnus-visual-p 'article-highlight 'highlight)
2887 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2888 ;; Set the global newsgroup variables here.
2889 (gnus-set-global-variables)
2890 (setq gnus-have-all-headers
2891 (or all-headers gnus-show-all-headers))))
2892 (save-excursion
2893 (gnus-configure-windows 'article))
2894 (when (or (numberp article)
2895 (stringp article))
2896 (gnus-article-prepare-display)
2897 ;; Do page break.
2898 (goto-char (point-min))
2899 (setq gnus-page-broken
2900 (when gnus-break-pages
2901 (gnus-narrow-to-page)
2902 t)))
2903 (let ((gnus-article-mime-handle-alist-1
2904 gnus-article-mime-handle-alist))
2905 (gnus-set-mode-line 'article))
2906 (article-goto-body)
2907 (set-window-point (get-buffer-window (current-buffer)) (point))
2908 (gnus-configure-windows 'article)
2909 t))))))
2911 ;;;###autoload
2912 (defun gnus-article-prepare-display ()
2913 "Make the current buffer look like a nice article."
2914 ;; Hooks for getting information from the article.
2915 ;; This hook must be called before being narrowed.
2916 (let ((gnus-article-buffer (current-buffer))
2917 buffer-read-only)
2918 (unless (eq major-mode 'gnus-article-mode)
2919 (gnus-article-mode))
2920 (setq buffer-read-only nil
2921 gnus-article-wash-types nil)
2922 (gnus-run-hooks 'gnus-tmp-internal-hook)
2923 (when gnus-display-mime-function
2924 (funcall gnus-display-mime-function))
2925 (gnus-run-hooks 'gnus-article-prepare-hook)))
2928 ;;; Gnus MIME viewing functions
2931 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2932 "The following specs can be used:
2933 %t The MIME type
2934 %T MIME type, along with additional info
2935 %n The `name' parameter
2936 %d The description, if any
2937 %l The length of the encoded part
2938 %p The part identifier number
2939 %e Dots if the part isn't displayed")
2941 (defvar gnus-mime-button-line-format-alist
2942 '((?t gnus-tmp-type ?s)
2943 (?T gnus-tmp-type-long ?s)
2944 (?n gnus-tmp-name ?s)
2945 (?d gnus-tmp-description ?s)
2946 (?p gnus-tmp-id ?s)
2947 (?l gnus-tmp-length ?d)
2948 (?e gnus-tmp-dots ?s)))
2950 (defvar gnus-mime-button-commands
2951 '((gnus-article-press-button "\r" "Toggle Display")
2952 (gnus-mime-view-part "v" "View Interactively...")
2953 (gnus-mime-view-part-as-type "t" "View As Type...")
2954 (gnus-mime-save-part "o" "Save...")
2955 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2956 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2957 (gnus-mime-internalize-part "E" "View Internally")
2958 (gnus-mime-externalize-part "e" "View Externally")
2959 (gnus-mime-pipe-part "|" "Pipe To Command...")
2960 (gnus-mime-action-on-part "." "Take action on the part")))
2962 (defun gnus-article-mime-part-status ()
2963 (if gnus-article-mime-handle-alist-1
2964 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2965 ""))
2967 (defvar gnus-mime-button-map
2968 (let ((map (make-sparse-keymap)))
2969 ;; Not for Emacs 21: fixme better.
2970 ;; (set-keymap-parent map gnus-article-mode-map)
2971 (define-key map gnus-mouse-2 'gnus-article-push-button)
2972 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2973 (dolist (c gnus-mime-button-commands)
2974 (define-key map (cadr c) (car c)))
2975 map))
2977 (defun gnus-mime-button-menu (event)
2978 "Construct a context-sensitive menu of MIME commands."
2979 (interactive "e")
2980 (save-excursion
2981 (mouse-set-point event)
2982 (gnus-article-check-buffer)
2983 (let ((response (x-popup-menu
2984 t `("MIME Part"
2985 ("" ,@(mapcar (lambda (c)
2986 (cons (caddr c) (car c)))
2987 gnus-mime-button-commands))))))
2988 (if response
2989 (call-interactively response)))))
2991 (defun gnus-mime-view-all-parts (&optional handles)
2992 "View all the MIME parts."
2993 (interactive)
2994 (save-current-buffer
2995 (set-buffer gnus-article-buffer)
2996 (let ((handles (or handles gnus-article-mime-handles))
2997 (mail-parse-charset gnus-newsgroup-charset)
2998 (mail-parse-ignored-charsets
2999 (save-excursion (set-buffer gnus-summary-buffer)
3000 gnus-newsgroup-ignored-charsets)))
3001 (if (stringp (car handles))
3002 (gnus-mime-view-all-parts (cdr handles))
3003 (mapcar 'mm-display-part handles)))))
3005 (defun gnus-mime-save-part ()
3006 "Save the MIME part under point."
3007 (interactive)
3008 (gnus-article-check-buffer)
3009 (let ((data (get-text-property (point) 'gnus-data)))
3010 (mm-save-part data)))
3012 (defun gnus-mime-pipe-part ()
3013 "Pipe the MIME part under point to a process."
3014 (interactive)
3015 (gnus-article-check-buffer)
3016 (let ((data (get-text-property (point) 'gnus-data)))
3017 (mm-pipe-part data)))
3019 (defun gnus-mime-view-part ()
3020 "Interactively choose a viewing method for the MIME part under point."
3021 (interactive)
3022 (gnus-article-check-buffer)
3023 (let ((data (get-text-property (point) 'gnus-data)))
3024 (push (setq data (copy-sequence data)) gnus-article-mime-handles)
3025 (mm-interactively-view-part data)))
3027 (defun gnus-mime-view-part-as-type-internal ()
3028 (gnus-article-check-buffer)
3029 (let* ((name (mail-content-type-get
3030 (mm-handle-type (get-text-property (point) 'gnus-data))
3031 'name))
3032 (def-type (and name (mm-default-file-encoding name))))
3033 (and def-type (cons def-type 0))))
3035 (defun gnus-mime-view-part-as-type (mime-type)
3036 "Choose a MIME media type, and view the part as such."
3037 (interactive
3038 (list (completing-read
3039 "View as MIME type: "
3040 (mapcar #'list (mailcap-mime-types))
3041 nil nil
3042 (gnus-mime-view-part-as-type-internal))))
3043 (gnus-article-check-buffer)
3044 (let ((handle (get-text-property (point) 'gnus-data)))
3045 (gnus-mm-display-part
3046 (mm-make-handle (mm-handle-buffer handle)
3047 (cons mime-type (cdr (mm-handle-type handle)))
3048 (mm-handle-encoding handle)
3049 (mm-handle-undisplayer handle)
3050 (mm-handle-disposition handle)
3051 (mm-handle-description handle)
3052 (mm-handle-cache handle)
3053 (mm-handle-id handle)))))
3055 (defun gnus-mime-copy-part (&optional handle)
3056 "Put the the MIME part under point into a new buffer."
3057 (interactive)
3058 (gnus-article-check-buffer)
3059 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3060 (contents (mm-get-part handle))
3061 (base (file-name-nondirectory
3063 (mail-content-type-get (mm-handle-type handle) 'name)
3064 (mail-content-type-get (mm-handle-type handle)
3065 'filename)
3066 "*decoded*")))
3067 (buffer (generate-new-buffer base)))
3068 (switch-to-buffer buffer)
3069 (insert contents)
3070 ;; We do it this way to make `normal-mode' set the appropriate mode.
3071 (unwind-protect
3072 (progn
3073 (setq buffer-file-name (expand-file-name base))
3074 (normal-mode))
3075 (setq buffer-file-name nil))
3076 (goto-char (point-min))))
3078 (defun gnus-mime-inline-part (&optional handle arg)
3079 "Insert the MIME part under point into the current buffer."
3080 (interactive (list nil current-prefix-arg))
3081 (gnus-article-check-buffer)
3082 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3083 contents charset
3084 (b (point))
3085 buffer-read-only)
3086 (if (mm-handle-undisplayer handle)
3087 (mm-remove-part handle)
3088 (setq contents (mm-get-part handle))
3089 (cond
3090 ((not arg)
3091 (setq charset (or (mail-content-type-get
3092 (mm-handle-type handle) 'charset)
3093 gnus-newsgroup-charset)))
3094 ((numberp arg)
3095 (setq charset
3096 (or (cdr (assq arg
3097 gnus-summary-show-article-charset-alist))
3098 (read-coding-system "Charset: ")))))
3099 (forward-line 2)
3100 (mm-insert-inline handle
3101 (if (and charset
3102 (setq charset (mm-charset-to-coding-system
3103 charset))
3104 (not (eq charset 'ascii)))
3105 (mm-decode-coding-string contents charset)
3106 contents))
3107 (goto-char b))))
3109 (defun gnus-mime-externalize-part (&optional handle)
3110 "View the MIME part under point with an external viewer."
3111 (interactive)
3112 (gnus-article-check-buffer)
3113 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3114 (mm-user-display-methods nil)
3115 (mm-inlined-types nil)
3116 (mail-parse-charset gnus-newsgroup-charset)
3117 (mail-parse-ignored-charsets
3118 (save-excursion (set-buffer gnus-summary-buffer)
3119 gnus-newsgroup-ignored-charsets)))
3120 (if (mm-handle-undisplayer handle)
3121 (mm-remove-part handle)
3122 (mm-display-part handle))))
3124 (defun gnus-mime-internalize-part (&optional handle)
3125 "View the MIME part under point with an internal viewer.
3126 In no internal viewer is available, use an external viewer."
3127 (interactive)
3128 (gnus-article-check-buffer)
3129 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3130 (mm-inlined-types '(".*"))
3131 (mm-inline-large-images t)
3132 (mail-parse-charset gnus-newsgroup-charset)
3133 (mail-parse-ignored-charsets
3134 (save-excursion (set-buffer gnus-summary-buffer)
3135 gnus-newsgroup-ignored-charsets)))
3136 (if (mm-handle-undisplayer handle)
3137 (mm-remove-part handle)
3138 (mm-display-part handle))))
3140 (defun gnus-mime-action-on-part (&optional action)
3141 "Do something with the MIME attachment at \(point\)."
3142 (interactive
3143 (list (completing-read "Action: " gnus-mime-action-alist)))
3144 (gnus-article-check-buffer)
3145 (let ((action-pair (assoc action gnus-mime-action-alist)))
3146 (if action-pair
3147 (funcall (cdr action-pair)))))
3150 (defun gnus-article-part-wrapper (n function)
3151 (save-current-buffer
3152 (set-buffer gnus-article-buffer)
3153 (when (> n (length gnus-article-mime-handle-alist))
3154 (error "No such part"))
3155 (gnus-article-goto-part n)
3156 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3157 (funcall function handle))))
3159 (defun gnus-article-pipe-part (n)
3160 "Pipe MIME part N, which is the numerical prefix."
3161 (interactive "p")
3162 (gnus-article-part-wrapper n 'mm-pipe-part))
3164 (defun gnus-article-save-part (n)
3165 "Save MIME part N, which is the numerical prefix."
3166 (interactive "p")
3167 (gnus-article-part-wrapper n 'mm-save-part))
3169 (defun gnus-article-interactively-view-part (n)
3170 "View MIME part N interactively, which is the numerical prefix."
3171 (interactive "p")
3172 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3174 (defun gnus-article-copy-part (n)
3175 "Copy MIME part N, which is the numerical prefix."
3176 (interactive "p")
3177 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3179 (defun gnus-article-externalize-part (n)
3180 "View MIME part N externally, which is the numerical prefix."
3181 (interactive "p")
3182 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3184 (defun gnus-article-inline-part (n)
3185 "Inline MIME part N, which is the numerical prefix."
3186 (interactive "p")
3187 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3189 (defun gnus-article-mime-match-handle-first (condition)
3190 (if condition
3191 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3192 (while (setq ihandle (pop alist))
3193 (if (and (cond
3194 ((functionp condition)
3195 (funcall condition (cdr ihandle)))
3196 ((eq condition 'undisplayed)
3197 (not (or (mm-handle-undisplayer (cdr ihandle))
3198 (equal (mm-handle-media-type (cdr ihandle))
3199 "multipart/alternative"))))
3200 ((eq condition 'undisplayed-alternative)
3201 (not (mm-handle-undisplayer (cdr ihandle))))
3202 (t t))
3203 (gnus-article-goto-part (car ihandle))
3204 (or (not n) (< (car ihandle) n)))
3205 (setq n (car ihandle))))
3206 (or n 1))
3209 (defun gnus-article-view-part (&optional n)
3210 "View MIME part N, which is the numerical prefix."
3211 (interactive "P")
3212 (save-current-buffer
3213 (set-buffer gnus-article-buffer)
3214 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3215 gnus-article-mime-match-handle-function)))
3216 (when (> n (length gnus-article-mime-handle-alist))
3217 (error "No such part"))
3218 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3219 (when (gnus-article-goto-part n)
3220 (if (equal (car handle) "multipart/alternative")
3221 (gnus-article-press-button)
3222 (when (eq (gnus-mm-display-part handle) 'internal)
3223 (gnus-set-window-start)))))))
3225 (defsubst gnus-article-mime-total-parts ()
3226 (if (bufferp (car gnus-article-mime-handles))
3227 1 ;; single part
3228 (1- (length gnus-article-mime-handles))))
3230 (defun gnus-mm-display-part (handle)
3231 "Display HANDLE and fix MIME button."
3232 (let ((id (get-text-property (point) 'gnus-part))
3233 (point (point))
3234 buffer-read-only)
3235 (forward-line 1)
3236 (prog1
3237 (let ((window (selected-window))
3238 (mail-parse-charset gnus-newsgroup-charset)
3239 (mail-parse-ignored-charsets
3240 (save-excursion (set-buffer gnus-summary-buffer)
3241 gnus-newsgroup-ignored-charsets)))
3242 (save-excursion
3243 (unwind-protect
3244 (let ((win (get-buffer-window (current-buffer) t))
3245 (beg (point)))
3246 (when win
3247 (select-window win))
3248 (goto-char point)
3249 (forward-line)
3250 (if (mm-handle-displayed-p handle)
3251 ;; This will remove the part.
3252 (mm-display-part handle)
3253 (save-restriction
3254 (narrow-to-region (point) (1+ (point)))
3255 (mm-display-part handle)
3256 ;; We narrow to the part itself and
3257 ;; then call the treatment functions.
3258 (goto-char (point-min))
3259 (forward-line 1)
3260 (narrow-to-region (point) (point-max))
3261 (gnus-treat-article
3262 nil id
3263 (gnus-article-mime-total-parts)
3264 (mm-handle-media-type handle)))))
3265 (select-window window))))
3266 (goto-char point)
3267 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3268 (gnus-insert-mime-button
3269 handle id (list (mm-handle-displayed-p handle)))
3270 (goto-char point))))
3272 (defun gnus-article-goto-part (n)
3273 "Go to MIME part N."
3274 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3275 (when point
3276 (goto-char point))))
3278 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3279 (let ((gnus-tmp-name
3280 (or (mail-content-type-get (mm-handle-type handle)
3281 'name)
3282 (mail-content-type-get (mm-handle-disposition handle)
3283 'filename)
3284 ""))
3285 (gnus-tmp-type (mm-handle-media-type handle))
3286 (gnus-tmp-description
3287 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3288 "")))
3289 (gnus-tmp-dots
3290 (if (if displayed (car displayed)
3291 (mm-handle-displayed-p handle))
3292 "" "..."))
3293 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3294 (buffer-size)))
3295 gnus-tmp-type-long b e)
3296 (when (string-match ".*/" gnus-tmp-name)
3297 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3298 (setq gnus-tmp-type-long (concat gnus-tmp-type
3299 (and (not (equal gnus-tmp-name ""))
3300 (concat "; " gnus-tmp-name))))
3301 (or (equal gnus-tmp-description "")
3302 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3303 (unless (bolp)
3304 (insert "\n"))
3305 (setq b (point))
3306 (gnus-eval-format
3307 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3308 `(keymap ,gnus-mime-button-map
3309 ;; Not for Emacs 21: fixme better.
3310 ;; local-map ,gnus-mime-button-map
3311 gnus-callback gnus-mm-display-part
3312 gnus-part ,gnus-tmp-id
3313 article-type annotation
3314 gnus-data ,handle))
3315 (setq e (point))
3316 (widget-convert-button
3317 'link b e
3318 :mime-handle handle
3319 :action 'gnus-widget-press-button
3320 :button-keymap gnus-mime-button-map
3321 :help-echo
3322 (lambda (widget/window &optional overlay pos)
3323 ;; Needed to properly clear the message due to a bug in
3324 ;; wid-edit (XEmacs only).
3325 (if (boundp 'help-echo-owns-message)
3326 (setq help-echo-owns-message t))
3327 (format
3328 "%S: %s the MIME part; %S: more options"
3329 (aref gnus-mouse-2 0)
3330 ;; XEmacs will get a single widget arg; Emacs 21 will get
3331 ;; window, overlay, position.
3332 (if (mm-handle-displayed-p
3333 (if overlay
3334 (with-current-buffer (gnus-overlay-buffer overlay)
3335 (widget-get (widget-at (gnus-overlay-start overlay))
3336 :mime-handle))
3337 (widget-get widget/window :mime-handle)))
3338 "hide" "show")
3339 (aref gnus-down-mouse-3 0))))))
3341 (defun gnus-widget-press-button (elems el)
3342 (goto-char (widget-get elems :from))
3343 (gnus-article-press-button))
3345 (defvar gnus-displaying-mime nil)
3347 (defun gnus-display-mime (&optional ihandles)
3348 "Display the MIME parts."
3349 (save-excursion
3350 (save-selected-window
3351 (let ((window (get-buffer-window gnus-article-buffer))
3352 (point (point)))
3353 (when window
3354 (select-window window)
3355 ;; We have to do this since selecting the window
3356 ;; may change the point. So we set the window point.
3357 (set-window-point window point)))
3358 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3359 buffer-read-only handle name type b e display)
3360 (when (and (not ihandles)
3361 (not gnus-displaying-mime))
3362 ;; Top-level call; we clean up.
3363 (when gnus-article-mime-handles
3364 (mm-destroy-parts gnus-article-mime-handles)
3365 (setq gnus-article-mime-handle-alist nil));; A trick.
3366 (setq gnus-article-mime-handles handles)
3367 ;; We allow users to glean info from the handles.
3368 (when gnus-article-mime-part-function
3369 (gnus-mime-part-function handles)))
3370 (if (and handles
3371 (or (not (stringp (car handles)))
3372 (cdr handles)))
3373 (progn
3374 (when (and (not ihandles)
3375 (not gnus-displaying-mime))
3376 ;; Clean up for mime parts.
3377 (article-goto-body)
3378 (delete-region (point) (point-max)))
3379 (let ((gnus-displaying-mime t))
3380 (gnus-mime-display-part handles)))
3381 (save-restriction
3382 (article-goto-body)
3383 (narrow-to-region (point) (point-max))
3384 (gnus-treat-article nil 1 1)
3385 (widen)))
3386 (unless ihandles
3387 ;; Highlight the headers.
3388 (save-excursion
3389 (save-restriction
3390 (article-goto-body)
3391 (narrow-to-region (point-min) (point))
3392 (gnus-treat-article 'head))))))))
3394 (defvar gnus-mime-display-multipart-as-mixed nil)
3396 (defun gnus-mime-display-part (handle)
3397 (cond
3398 ;; Single part.
3399 ((not (stringp (car handle)))
3400 (gnus-mime-display-single handle))
3401 ;; User-defined multipart
3402 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3403 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3404 handle))
3405 ;; multipart/alternative
3406 ((and (equal (car handle) "multipart/alternative")
3407 (not gnus-mime-display-multipart-as-mixed))
3408 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3409 (push (cons id handle) gnus-article-mime-handle-alist)
3410 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3411 ;; multipart/related
3412 ((and (equal (car handle) "multipart/related")
3413 (not gnus-mime-display-multipart-as-mixed))
3414 ;;;!!!We should find the start part, but we just default
3415 ;;;!!!to the first part.
3416 (gnus-mime-display-part (cadr handle)))
3417 ;; Other multiparts are handled like multipart/mixed.
3419 (gnus-mime-display-mixed (cdr handle)))))
3421 (defun gnus-mime-part-function (handles)
3422 (if (stringp (car handles))
3423 (mapcar 'gnus-mime-part-function (cdr handles))
3424 (funcall gnus-article-mime-part-function handles)))
3426 (defun gnus-mime-display-mixed (handles)
3427 (mapcar 'gnus-mime-display-part handles))
3429 (defun gnus-mime-display-single (handle)
3430 (let ((type (mm-handle-media-type handle))
3431 (ignored gnus-ignored-mime-types)
3432 (not-attachment t)
3433 (move nil)
3434 display text)
3435 (catch 'ignored
3436 (progn
3437 (while ignored
3438 (when (string-match (pop ignored) type)
3439 (throw 'ignored nil)))
3440 (if (and (setq not-attachment
3441 (and (not (mm-inline-override-p handle))
3442 (or (not (mm-handle-disposition handle))
3443 (equal (car (mm-handle-disposition handle))
3444 "inline")
3445 (mm-attachment-override-p handle))))
3446 (mm-automatic-display-p handle)
3447 (or (mm-inlined-p handle)
3448 (mm-automatic-external-display-p type)))
3449 (setq display t)
3450 (when (equal (mm-handle-media-supertype handle) "text")
3451 (setq text t)))
3452 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3453 beg)
3454 (push (cons id handle) gnus-article-mime-handle-alist)
3455 (when (or (not display)
3456 (not (gnus-unbuttonized-mime-type-p type)))
3457 ;(gnus-article-insert-newline)
3458 (gnus-insert-mime-button
3459 handle id (list (or display (and not-attachment text))))
3460 (gnus-article-insert-newline)
3461 ;(gnus-article-insert-newline)
3462 (setq move t))
3463 (setq beg (point))
3464 (cond
3465 (display
3466 (when move
3467 (forward-line -2)
3468 (setq beg (point)))
3469 (let ((mail-parse-charset gnus-newsgroup-charset)
3470 (mail-parse-ignored-charsets
3471 (save-excursion (condition-case ()
3472 (set-buffer gnus-summary-buffer)
3473 (error))
3474 gnus-newsgroup-ignored-charsets)))
3475 (mm-display-part handle t))
3476 (goto-char (point-max)))
3477 ((and text not-attachment)
3478 (when move
3479 (forward-line -2)
3480 (setq beg (point)))
3481 (gnus-article-insert-newline)
3482 (mm-insert-inline handle (mm-get-part handle))
3483 (goto-char (point-max))))
3484 ;; Do highlighting.
3485 (save-excursion
3486 (save-restriction
3487 (narrow-to-region beg (point))
3488 (gnus-treat-article
3489 nil id
3490 (gnus-article-mime-total-parts)
3491 (mm-handle-media-type handle)))))))))
3493 (defun gnus-unbuttonized-mime-type-p (type)
3494 "Say whether TYPE is to be unbuttonized."
3495 (unless gnus-inhibit-mime-unbuttonizing
3496 (catch 'found
3497 (let ((types gnus-unbuttonized-mime-types))
3498 (while types
3499 (when (string-match (pop types) type)
3500 (throw 'found t)))))))
3502 (defun gnus-article-insert-newline ()
3503 "Insert a newline, but mark it as undeletable."
3504 (gnus-put-text-property
3505 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3507 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3508 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3509 (ihandles handles)
3510 (point (point))
3511 handle buffer-read-only from props begend not-pref)
3512 (save-window-excursion
3513 (save-restriction
3514 (when ibegend
3515 (narrow-to-region (car ibegend)
3516 (or (cdr ibegend)
3517 (progn
3518 (goto-char (car ibegend))
3519 (forward-line 2)
3520 (point))))
3521 (delete-region (point-min) (point-max))
3522 (mm-remove-parts handles))
3523 (setq begend (list (point-marker)))
3524 ;; Do the toggle.
3525 (unless (setq not-pref (cadr (member preferred ihandles)))
3526 (setq not-pref (car ihandles)))
3527 (when (or ibegend
3528 (not (gnus-unbuttonized-mime-type-p
3529 "multipart/alternative")))
3530 (gnus-add-text-properties
3531 (setq from (point))
3532 (progn
3533 (insert (format "%d. " id))
3534 (point))
3535 `(gnus-callback
3536 (lambda (handles)
3537 (unless ,(not ibegend)
3538 (setq gnus-article-mime-handle-alist
3539 ',gnus-article-mime-handle-alist))
3540 (gnus-mime-display-alternative
3541 ',ihandles ',not-pref ',begend ,id))
3542 ;; Not for Emacs 21: fixme better.
3543 ;; local-map ,gnus-mime-button-map
3544 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3545 face ,gnus-article-button-face
3546 keymap ,gnus-mime-button-map
3547 gnus-part ,id
3548 gnus-data ,handle))
3549 (widget-convert-button 'link from (point)
3550 :action 'gnus-widget-press-button
3551 :button-keymap gnus-widget-button-keymap)
3552 ;; Do the handles
3553 (while (setq handle (pop handles))
3554 (gnus-add-text-properties
3555 (setq from (point))
3556 (progn
3557 (insert (format "(%c) %-18s"
3558 (if (equal handle preferred) ?* ? )
3559 (mm-handle-media-type handle)))
3560 (point))
3561 `(gnus-callback
3562 (lambda (handles)
3563 (unless ,(not ibegend)
3564 (setq gnus-article-mime-handle-alist
3565 ',gnus-article-mime-handle-alist))
3566 (gnus-mime-display-alternative
3567 ',ihandles ',handle ',begend ,id))
3568 ;; Not for Emacs 21: fixme better.
3569 ;; local-map ,gnus-mime-button-map
3570 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3571 face ,gnus-article-button-face
3572 keymap ,gnus-mime-button-map
3573 gnus-part ,id
3574 gnus-data ,handle))
3575 (widget-convert-button 'link from (point)
3576 :action 'gnus-widget-press-button
3577 :button-keymap gnus-widget-button-keymap)
3578 (insert " "))
3579 (insert "\n\n"))
3580 (when preferred
3581 (if (stringp (car preferred))
3582 (gnus-display-mime preferred)
3583 (let ((mail-parse-charset gnus-newsgroup-charset)
3584 (mail-parse-ignored-charsets
3585 (save-excursion (set-buffer gnus-summary-buffer)
3586 gnus-newsgroup-ignored-charsets)))
3587 (mm-display-part preferred)
3588 ;; Do highlighting.
3589 (save-excursion
3590 (save-restriction
3591 (narrow-to-region (car begend) (point-max))
3592 (gnus-treat-article
3593 nil (length gnus-article-mime-handle-alist)
3594 (gnus-article-mime-total-parts)
3595 (mm-handle-media-type handle))))))
3596 (goto-char (point-max))
3597 (setcdr begend (point-marker)))))
3598 (when ibegend
3599 (goto-char point))))
3601 (defun gnus-article-wash-status ()
3602 "Return a string which display status of article washing."
3603 (save-excursion
3604 (set-buffer gnus-article-buffer)
3605 (let ((cite (memq 'cite gnus-article-wash-types))
3606 (headers (memq 'headers gnus-article-wash-types))
3607 (boring (memq 'boring-headers gnus-article-wash-types))
3608 (pgp (memq 'pgp gnus-article-wash-types))
3609 (pem (memq 'pem gnus-article-wash-types))
3610 (signature (memq 'signature gnus-article-wash-types))
3611 (overstrike (memq 'overstrike gnus-article-wash-types))
3612 (emphasis (memq 'emphasis gnus-article-wash-types)))
3613 (format "%c%c%c%c%c%c"
3614 (if cite ?c ? )
3615 (if (or headers boring) ?h ? )
3616 (if (or pgp pem) ?p ? )
3617 (if signature ?s ? )
3618 (if overstrike ?o ? )
3619 (if emphasis ?e ? )))))
3621 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3623 (defun gnus-article-maybe-hide-headers ()
3624 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3625 Provided for backwards compatibility."
3626 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3627 (not (save-excursion (set-buffer gnus-summary-buffer)
3628 gnus-have-all-headers)))
3629 (not gnus-inhibit-hiding))
3630 (gnus-article-hide-headers)))
3632 ;;; Article savers.
3634 (defun gnus-output-to-file (file-name)
3635 "Append the current article to a file named FILE-NAME."
3636 (let ((artbuf (current-buffer)))
3637 (with-temp-buffer
3638 (insert-buffer-substring artbuf)
3639 ;; Append newline at end of the buffer as separator, and then
3640 ;; save it to file.
3641 (goto-char (point-max))
3642 (insert "\n")
3643 (mm-append-to-file (point-min) (point-max) file-name)
3644 t)))
3646 (defun gnus-narrow-to-page (&optional arg)
3647 "Narrow the article buffer to a page.
3648 If given a numerical ARG, move forward ARG pages."
3649 (interactive "P")
3650 (setq arg (if arg (prefix-numeric-value arg) 0))
3651 (save-excursion
3652 (set-buffer gnus-article-buffer)
3653 (goto-char (point-min))
3654 (widen)
3655 ;; Remove any old next/prev buttons.
3656 (when (gnus-visual-p 'page-marker)
3657 (let ((buffer-read-only nil))
3658 (gnus-remove-text-with-property 'gnus-prev)
3659 (gnus-remove-text-with-property 'gnus-next)))
3660 (when
3661 (cond ((< arg 0)
3662 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3663 ((> arg 0)
3664 (re-search-forward page-delimiter nil 'move arg)))
3665 (goto-char (match-end 0)))
3666 (narrow-to-region
3667 (point)
3668 (if (re-search-forward page-delimiter nil 'move)
3669 (match-beginning 0)
3670 (point)))
3671 (when (and (gnus-visual-p 'page-marker)
3672 (not (= (point-min) 1)))
3673 (save-excursion
3674 (goto-char (point-min))
3675 (gnus-insert-prev-page-button)))
3676 (when (and (gnus-visual-p 'page-marker)
3677 (< (+ (point-max) 2) (buffer-size)))
3678 (save-excursion
3679 (goto-char (point-max))
3680 (gnus-insert-next-page-button)))))
3682 ;; Article mode commands
3684 (defun gnus-article-goto-next-page ()
3685 "Show the next page of the article."
3686 (interactive)
3687 (when (gnus-article-next-page)
3688 (goto-char (point-min))
3689 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3691 (defun gnus-article-goto-prev-page ()
3692 "Show the next page of the article."
3693 (interactive)
3694 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3695 (gnus-article-prev-page nil)))
3697 (defun gnus-article-next-page (&optional lines)
3698 "Show the next page of the current article.
3699 If end of article, return non-nil. Otherwise return nil.
3700 Argument LINES specifies lines to be scrolled up."
3701 (interactive "p")
3702 (move-to-window-line -1)
3703 (if (save-excursion
3704 (end-of-line)
3705 (and (pos-visible-in-window-p) ;Not continuation line.
3706 (eobp)))
3707 ;; Nothing in this page.
3708 (if (or (not gnus-page-broken)
3709 (save-excursion
3710 (save-restriction
3711 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3712 t ;Nothing more.
3713 (gnus-narrow-to-page 1) ;Go to next page.
3714 nil)
3715 ;; More in this page.
3716 (let ((scroll-in-place nil))
3717 (condition-case ()
3718 (scroll-up lines)
3719 (end-of-buffer
3720 ;; Long lines may cause an end-of-buffer error.
3721 (goto-char (point-max)))))
3722 (move-to-window-line 0)
3723 nil))
3725 (defun gnus-article-prev-page (&optional lines)
3726 "Show previous page of current article.
3727 Argument LINES specifies lines to be scrolled down."
3728 (interactive "p")
3729 (move-to-window-line 0)
3730 (if (and gnus-page-broken
3731 (bobp)
3732 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3733 (progn
3734 (gnus-narrow-to-page -1) ;Go to previous page.
3735 (goto-char (point-max))
3736 (recenter -1))
3737 (let ((scroll-in-place nil))
3738 (prog1
3739 (condition-case ()
3740 (scroll-down lines)
3741 (beginning-of-buffer
3742 (goto-char (point-min))))
3743 (move-to-window-line 0)))))
3745 (defun gnus-article-refer-article ()
3746 "Read article specified by message-id around point."
3747 (interactive)
3748 (let ((point (point)))
3749 (search-forward ">" nil t) ;Move point to end of "<....>".
3750 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3751 (let ((message-id (match-string 1)))
3752 (goto-char point)
3753 (set-buffer gnus-summary-buffer)
3754 (gnus-summary-refer-article message-id))
3755 (goto-char (point))
3756 (error "No references around point"))))
3758 (defun gnus-article-show-summary ()
3759 "Reconfigure windows to show summary buffer."
3760 (interactive)
3761 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3762 (error "There is no summary buffer for this article buffer")
3763 (gnus-article-set-globals)
3764 (gnus-configure-windows 'article)
3765 (gnus-summary-goto-subject gnus-current-article)
3766 (gnus-summary-position-point)))
3768 (defun gnus-article-describe-briefly ()
3769 "Describe article mode commands briefly."
3770 (interactive)
3771 (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")))
3773 (defun gnus-article-summary-command ()
3774 "Execute the last keystroke in the summary buffer."
3775 (interactive)
3776 (let ((obuf (current-buffer))
3777 (owin (current-window-configuration))
3778 func)
3779 (switch-to-buffer gnus-article-current-summary 'norecord)
3780 (setq func (lookup-key (current-local-map) (this-command-keys)))
3781 (call-interactively func)
3782 (set-buffer obuf)
3783 (set-window-configuration owin)
3784 (set-window-point (get-buffer-window (current-buffer)) (point))))
3786 (defun gnus-article-summary-command-nosave ()
3787 "Execute the last keystroke in the summary buffer."
3788 (interactive)
3789 (let (func)
3790 (pop-to-buffer gnus-article-current-summary 'norecord)
3791 (setq func (lookup-key (current-local-map) (this-command-keys)))
3792 (call-interactively func)))
3794 (defun gnus-article-check-buffer ()
3795 "Beep if not in an article buffer."
3796 (unless (equal major-mode 'gnus-article-mode)
3797 (error "Command invoked outside of a Gnus article buffer")))
3799 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3800 "Read a summary buffer key sequence and execute it from the article buffer."
3801 (interactive "P")
3802 (gnus-article-check-buffer)
3803 (let ((nosaves
3804 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3805 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3806 "=" "^" "\M-^" "|"))
3807 (nosave-but-article
3808 '("A\r"))
3809 (nosave-in-article
3810 '("\C-d"))
3811 (up-to-top
3812 '("n" "Gn" "p" "Gp"))
3813 keys new-sum-point)
3814 (save-excursion
3815 (set-buffer gnus-article-current-summary)
3816 (let (gnus-pick-mode)
3817 (push (or key last-command-event) unread-command-events)
3818 (setq keys (if (featurep 'xemacs)
3819 (events-to-keys (read-key-sequence nil))
3820 (read-key-sequence nil)))))
3822 (message "")
3824 (if (or (member keys nosaves)
3825 (member keys nosave-but-article)
3826 (member keys nosave-in-article))
3827 (let (func)
3828 (save-window-excursion
3829 (pop-to-buffer gnus-article-current-summary 'norecord)
3830 ;; We disable the pick minor mode commands.
3831 (let (gnus-pick-mode)
3832 (setq func (lookup-key (current-local-map) keys))))
3833 (if (or (not func)
3834 (numberp func))
3835 (ding)
3836 (unless (member keys nosave-in-article)
3837 (set-buffer gnus-article-current-summary))
3838 (call-interactively func)
3839 (setq new-sum-point (point)))
3840 (when (member keys nosave-but-article)
3841 (pop-to-buffer gnus-article-buffer 'norecord)))
3842 ;; These commands should restore window configuration.
3843 (let ((obuf (current-buffer))
3844 (owin (current-window-configuration))
3845 (opoint (point))
3846 (summary gnus-article-current-summary)
3847 func in-buffer selected)
3848 (if not-restore-window
3849 (pop-to-buffer summary 'norecord)
3850 (switch-to-buffer summary 'norecord))
3851 (setq in-buffer (current-buffer))
3852 ;; We disable the pick minor mode commands.
3853 (if (and (setq func (let (gnus-pick-mode)
3854 (lookup-key (current-local-map) keys)))
3855 (functionp func))
3856 (progn
3857 (call-interactively func)
3858 (setq new-sum-point (point))
3859 (when (eq in-buffer (current-buffer))
3860 (setq selected (gnus-summary-select-article))
3861 (set-buffer obuf)
3862 (unless not-restore-window
3863 (set-window-configuration owin))
3864 (when (eq selected 'old)
3865 (article-goto-body)
3866 (set-window-start (get-buffer-window (current-buffer))
3868 (set-window-point (get-buffer-window (current-buffer))
3869 (point)))
3870 (let ((win (get-buffer-window gnus-article-current-summary)))
3871 (when win
3872 (set-window-point win new-sum-point)))) )
3873 (switch-to-buffer gnus-article-buffer)
3874 (ding))))))
3876 (defun gnus-article-describe-key (key)
3877 "Display documentation of the function invoked by KEY. KEY is a string."
3878 (interactive "kDescribe key: ")
3879 (gnus-article-check-buffer)
3880 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
3881 (save-excursion
3882 (set-buffer gnus-article-current-summary)
3883 (let (gnus-pick-mode)
3884 (push (elt key 0) unread-command-events)
3885 (setq key (if (featurep 'xemacs)
3886 (events-to-keys (read-key-sequence "Describe key: "))
3887 (read-key-sequence "Describe key: "))))
3888 (describe-key key))
3889 (describe-key key)))
3891 (defun gnus-article-describe-key-briefly (key &optional insert)
3892 "Display documentation of the function invoked by KEY. KEY is a string."
3893 (interactive "kDescribe key: \nP")
3894 (gnus-article-check-buffer)
3895 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
3896 (save-excursion
3897 (set-buffer gnus-article-current-summary)
3898 (let (gnus-pick-mode)
3899 (push (elt key 0) unread-command-events)
3900 (setq key (if (featurep 'xemacs)
3901 (events-to-keys (read-key-sequence "Describe key: "))
3902 (read-key-sequence "Describe key: "))))
3903 (describe-key-briefly key insert))
3904 (describe-key-briefly key insert)))
3906 (defun gnus-article-hide (&optional arg force)
3907 "Hide all the gruft in the current article.
3908 This means that PGP stuff, signatures, cited text and (some)
3909 headers will be hidden.
3910 If given a prefix, show the hidden text instead."
3911 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3912 (gnus-article-hide-headers arg)
3913 (gnus-article-hide-list-identifiers arg)
3914 (gnus-article-hide-pgp arg)
3915 (gnus-article-hide-citation-maybe arg force)
3916 (gnus-article-hide-signature arg))
3918 (defun gnus-article-maybe-highlight ()
3919 "Do some article highlighting if article highlighting is requested."
3920 (when (gnus-visual-p 'article-highlight 'highlight)
3921 (gnus-article-highlight-some)))
3923 (defun gnus-check-group-server ()
3924 ;; Make sure the connection to the server is alive.
3925 (unless (gnus-server-opened
3926 (gnus-find-method-for-group gnus-newsgroup-name))
3927 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3928 (gnus-request-group gnus-newsgroup-name t)))
3930 (defun gnus-request-article-this-buffer (article group)
3931 "Get an article and insert it into this buffer."
3932 (let (do-update-line sparse-header)
3933 (prog1
3934 (save-excursion
3935 (erase-buffer)
3936 (gnus-kill-all-overlays)
3937 (setq group (or group gnus-newsgroup-name))
3939 ;; Using `gnus-request-article' directly will insert the article into
3940 ;; `nntp-server-buffer' - so we'll save some time by not having to
3941 ;; copy it from the server buffer into the article buffer.
3943 ;; We only request an article by message-id when we do not have the
3944 ;; headers for it, so we'll have to get those.
3945 (when (stringp article)
3946 (gnus-read-header article))
3948 ;; If the article number is negative, that means that this article
3949 ;; doesn't belong in this newsgroup (possibly), so we find its
3950 ;; message-id and request it by id instead of number.
3951 (when (and (numberp article)
3952 gnus-summary-buffer
3953 (get-buffer gnus-summary-buffer)
3954 (gnus-buffer-exists-p gnus-summary-buffer))
3955 (save-excursion
3956 (set-buffer gnus-summary-buffer)
3957 (let ((header (gnus-summary-article-header article)))
3958 (when (< article 0)
3959 (cond
3960 ((memq article gnus-newsgroup-sparse)
3961 ;; This is a sparse gap article.
3962 (setq do-update-line article)
3963 (setq article (mail-header-id header))
3964 (setq sparse-header (gnus-read-header article))
3965 (setq gnus-newsgroup-sparse
3966 (delq article gnus-newsgroup-sparse)))
3967 ((vectorp header)
3968 ;; It's a real article.
3969 (setq article (mail-header-id header)))
3971 ;; It is an extracted pseudo-article.
3972 (setq article 'pseudo)
3973 (gnus-request-pseudo-article header))))
3975 (let ((method (gnus-find-method-for-group
3976 gnus-newsgroup-name)))
3977 (when (and (eq (car method) 'nneething)
3978 (vectorp header))
3979 (let ((dir (expand-file-name
3980 (mail-header-subject header)
3981 (file-name-as-directory
3982 (or (cadr (assq 'nneething-address method))
3983 (nth 1 method))))))
3984 (when (file-directory-p dir)
3985 (setq article 'nneething)
3986 (gnus-group-enter-directory dir))))))))
3988 (cond
3989 ;; Refuse to select canceled articles.
3990 ((and (numberp article)
3991 gnus-summary-buffer
3992 (get-buffer gnus-summary-buffer)
3993 (gnus-buffer-exists-p gnus-summary-buffer)
3994 (eq (cdr (save-excursion
3995 (set-buffer gnus-summary-buffer)
3996 (assq article gnus-newsgroup-reads)))
3997 gnus-canceled-mark))
3998 nil)
3999 ;; We first check `gnus-original-article-buffer'.
4000 ((and (get-buffer gnus-original-article-buffer)
4001 (numberp article)
4002 (save-excursion
4003 (set-buffer gnus-original-article-buffer)
4004 (and (equal (car gnus-original-article) group)
4005 (eq (cdr gnus-original-article) article))))
4006 (insert-buffer-substring gnus-original-article-buffer)
4007 'article)
4008 ;; Check the backlog.
4009 ((and gnus-keep-backlog
4010 (gnus-backlog-request-article group article (current-buffer)))
4011 'article)
4012 ;; Check asynchronous pre-fetch.
4013 ((gnus-async-request-fetched-article group article (current-buffer))
4014 (gnus-async-prefetch-next group article gnus-summary-buffer)
4015 (when (and (numberp article) gnus-keep-backlog)
4016 (gnus-backlog-enter-article group article (current-buffer)))
4017 'article)
4018 ;; Check the cache.
4019 ((and gnus-use-cache
4020 (numberp article)
4021 (gnus-cache-request-article article group))
4022 'article)
4023 ;; Get the article and put into the article buffer.
4024 ((or (stringp article)
4025 (numberp article))
4026 (let ((gnus-override-method gnus-override-method)
4027 (methods (and (stringp article)
4028 gnus-refer-article-method))
4029 result
4030 (buffer-read-only nil))
4031 (if (or (not (listp methods))
4032 (and (symbolp (car methods))
4033 (assq (car methods) nnoo-definition-alist)))
4034 (setq methods (list methods)))
4035 (when (and (null gnus-override-method)
4036 methods)
4037 (setq gnus-override-method (pop methods)))
4038 (while (not result)
4039 (when (eq gnus-override-method 'current)
4040 (setq gnus-override-method gnus-current-select-method))
4041 (erase-buffer)
4042 (gnus-kill-all-overlays)
4043 (let ((gnus-newsgroup-name group))
4044 (gnus-check-group-server))
4045 (when (gnus-request-article article group (current-buffer))
4046 (when (numberp article)
4047 (gnus-async-prefetch-next group article
4048 gnus-summary-buffer)
4049 (when gnus-keep-backlog
4050 (gnus-backlog-enter-article
4051 group article (current-buffer))))
4052 (setq result 'article))
4053 (if (not result)
4054 (if methods
4055 (setq gnus-override-method (pop methods))
4056 (setq result 'done))))
4057 (and (eq result 'article) 'article)))
4058 ;; It was a pseudo.
4059 (t article)))
4061 ;; Associate this article with the current summary buffer.
4062 (setq gnus-article-current-summary gnus-summary-buffer)
4064 ;; Take the article from the original article buffer
4065 ;; and place it in the buffer it's supposed to be in.
4066 (when (and (get-buffer gnus-article-buffer)
4067 (equal (buffer-name (current-buffer))
4068 (buffer-name (get-buffer gnus-article-buffer))))
4069 (save-excursion
4070 (if (get-buffer gnus-original-article-buffer)
4071 (set-buffer gnus-original-article-buffer)
4072 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4073 (buffer-disable-undo)
4074 (setq major-mode 'gnus-original-article-mode)
4075 (setq buffer-read-only t))
4076 (let (buffer-read-only)
4077 (erase-buffer)
4078 (insert-buffer-substring gnus-article-buffer))
4079 (setq gnus-original-article (cons group article)))
4081 ;; Decode charsets.
4082 (run-hooks 'gnus-article-decode-hook)
4083 ;; Mark article as decoded or not.
4084 (setq gnus-article-decoded-p gnus-article-decode-hook))
4086 ;; Update sparse articles.
4087 (when (and do-update-line
4088 (or (numberp article)
4089 (stringp article)))
4090 (let ((buf (current-buffer)))
4091 (set-buffer gnus-summary-buffer)
4092 (gnus-summary-update-article do-update-line sparse-header)
4093 (gnus-summary-goto-subject do-update-line nil t)
4094 (set-window-point (get-buffer-window (current-buffer) t)
4095 (point))
4096 (set-buffer buf))))))
4099 ;;; Article editing
4102 (defcustom gnus-article-edit-mode-hook nil
4103 "Hook run in article edit mode buffers."
4104 :group 'gnus-article-various
4105 :type 'hook)
4107 (defvar gnus-article-edit-done-function nil)
4109 (defvar gnus-article-edit-mode-map nil)
4111 ;; Should we be using derived.el for this?
4112 (unless gnus-article-edit-mode-map
4113 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4114 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4116 (gnus-define-keys gnus-article-edit-mode-map
4117 "\C-c\C-c" gnus-article-edit-done
4118 "\C-c\C-k" gnus-article-edit-exit)
4120 (gnus-define-keys (gnus-article-edit-wash-map
4121 "\C-c\C-w" gnus-article-edit-mode-map)
4122 "f" gnus-article-edit-full-stops))
4124 (defun gnus-article-edit-mode ()
4125 "Major mode for editing articles.
4126 This is an extended text-mode.
4128 \\{gnus-article-edit-mode-map}"
4129 (interactive)
4130 (setq major-mode 'gnus-article-edit-mode)
4131 (setq mode-name "Article Edit")
4132 (use-local-map gnus-article-edit-mode-map)
4133 (make-local-variable 'gnus-article-edit-done-function)
4134 (make-local-variable 'gnus-prev-winconf)
4135 (setq buffer-read-only nil)
4136 (buffer-enable-undo)
4137 (widen)
4138 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4140 (defun gnus-article-edit (&optional force)
4141 "Edit the current article.
4142 This will have permanent effect only in mail groups.
4143 If FORCE is non-nil, allow editing of articles even in read-only
4144 groups."
4145 (interactive "P")
4146 (when (and (not force)
4147 (gnus-group-read-only-p))
4148 (error "The current newsgroup does not support article editing"))
4149 (gnus-article-date-original)
4150 (gnus-article-edit-article
4151 'ignore
4152 `(lambda (no-highlight)
4153 'ignore
4154 (gnus-summary-edit-article-done
4155 ,(or (mail-header-references gnus-current-headers) "")
4156 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4158 (defun gnus-article-edit-article (start-func exit-func)
4159 "Start editing the contents of the current article buffer."
4160 (let ((winconf (current-window-configuration)))
4161 (set-buffer gnus-article-buffer)
4162 (gnus-article-edit-mode)
4163 (funcall start-func)
4164 (gnus-configure-windows 'edit-article)
4165 (setq gnus-article-edit-done-function exit-func)
4166 (setq gnus-prev-winconf winconf)
4167 (gnus-message 6 "C-c C-c to end edits")))
4169 (defun gnus-article-edit-done (&optional arg)
4170 "Update the article edits and exit."
4171 (interactive "P")
4172 (save-excursion
4173 (save-restriction
4174 (widen)
4175 (when (article-goto-body)
4176 (let ((lines (count-lines (point) (point-max)))
4177 (length (- (point-max) (point)))
4178 (case-fold-search t)
4179 (body (copy-marker (point))))
4180 (goto-char (point-min))
4181 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4182 (delete-region (match-beginning 1) (match-end 1))
4183 (insert (number-to-string length)))
4184 (goto-char (point-min))
4185 (when (re-search-forward
4186 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4187 (delete-region (match-beginning 1) (match-end 1))
4188 (insert (number-to-string length)))
4189 (goto-char (point-min))
4190 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4191 (delete-region (match-beginning 1) (match-end 1))
4192 (insert (number-to-string lines)))))))
4193 (let ((func gnus-article-edit-done-function)
4194 (buf (current-buffer))
4195 (start (window-start)))
4196 (gnus-article-edit-exit)
4197 (save-excursion
4198 (set-buffer buf)
4199 (let ((buffer-read-only nil))
4200 (funcall func arg))
4201 ;; The cache and backlog have to be flushed somewhat.
4202 (when gnus-keep-backlog
4203 (gnus-backlog-remove-article
4204 (car gnus-article-current) (cdr gnus-article-current)))
4205 ;; Flush original article as well.
4206 (save-excursion
4207 (when (get-buffer gnus-original-article-buffer)
4208 (set-buffer gnus-original-article-buffer)
4209 (setq gnus-original-article nil)))
4210 (when gnus-use-cache
4211 (gnus-cache-update-article
4212 (car gnus-article-current) (cdr gnus-article-current))))
4213 (set-buffer buf)
4214 (set-window-start (get-buffer-window buf) start)
4215 (set-window-point (get-buffer-window buf) (point))))
4217 (defun gnus-article-edit-exit ()
4218 "Exit the article editing without updating."
4219 (interactive)
4220 ;; We remove all text props from the article buffer.
4221 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4222 (curbuf (current-buffer))
4223 (p (point))
4224 (window-start (window-start)))
4225 (erase-buffer)
4226 (insert buf)
4227 (let ((winconf gnus-prev-winconf))
4228 (gnus-article-mode)
4229 (set-window-configuration winconf)
4230 ;; Tippy-toe some to make sure that point remains where it was.
4231 (save-current-buffer
4232 (set-buffer curbuf)
4233 (set-window-start (get-buffer-window (current-buffer)) window-start)
4234 (goto-char p)))))
4236 (defun gnus-article-edit-full-stops ()
4237 "Interactively repair spacing at end of sentences."
4238 (interactive)
4239 (save-excursion
4240 (goto-char (point-min))
4241 (search-forward-regexp "^$" nil t)
4242 (let ((case-fold-search nil))
4243 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4246 ;;; Article highlights
4249 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4251 ;;; Internal Variables:
4253 (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\\)\\)"
4254 "Regular expression that matches URLs."
4255 :group 'gnus-article-buttons
4256 :type 'regexp)
4258 (defcustom gnus-button-alist
4259 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4260 0 t gnus-button-message-id 2)
4261 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4262 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4264 gnus-button-fetch-group 4)
4265 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4266 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4267 t gnus-button-message-id 3)
4268 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4269 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4270 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4271 ;; This is how URLs _should_ be embedded in text...
4272 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4273 ;; Raw URLs.
4274 (,gnus-button-url-regexp 0 t browse-url 0))
4275 "*Alist of regexps matching buttons in article bodies.
4277 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4278 REGEXP: is the string matching text around the button,
4279 BUTTON: is the number of the regexp grouping actually matching the button,
4280 FORM: is a lisp expression which must eval to true for the button to
4281 be added,
4282 CALLBACK: is the function to call when the user push this button, and each
4283 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4285 CALLBACK can also be a variable, in that case the value of that
4286 variable it the real callback function."
4287 :group 'gnus-article-buttons
4288 :type '(repeat (list regexp
4289 (integer :tag "Button")
4290 (sexp :tag "Form")
4291 (function :tag "Callback")
4292 (repeat :tag "Par"
4293 :inline t
4294 (integer :tag "Regexp group")))))
4296 (defcustom gnus-header-button-alist
4297 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4298 0 t gnus-button-message-id 0)
4299 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4300 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4301 0 t gnus-button-mailto 0)
4302 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4303 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4304 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4305 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4306 gnus-button-message-id 3))
4307 "*Alist of headers and regexps to match buttons in article heads.
4309 This alist is very similar to `gnus-button-alist', except that each
4310 alist has an additional HEADER element first in each entry:
4312 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4314 HEADER is a regexp to match a header. For a fuller explanation, see
4315 `gnus-button-alist'."
4316 :group 'gnus-article-buttons
4317 :group 'gnus-article-headers
4318 :type '(repeat (list (regexp :tag "Header")
4319 regexp
4320 (integer :tag "Button")
4321 (sexp :tag "Form")
4322 (function :tag "Callback")
4323 (repeat :tag "Par"
4324 :inline t
4325 (integer :tag "Regexp group")))))
4327 (defvar gnus-button-regexp nil)
4328 (defvar gnus-button-marker-list nil)
4329 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4331 (defvar gnus-button-last nil)
4332 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4334 ;;; Commands:
4336 (defun gnus-article-push-button (event)
4337 "Check text under the mouse pointer for a callback function.
4338 If the text under the mouse pointer has a `gnus-callback' property,
4339 call it with the value of the `gnus-data' text property."
4340 (interactive "e")
4341 (set-buffer (window-buffer (posn-window (event-start event))))
4342 (let* ((pos (posn-point (event-start event)))
4343 (data (get-text-property pos 'gnus-data))
4344 (fun (get-text-property pos 'gnus-callback)))
4345 (goto-char pos)
4346 (when fun
4347 (funcall fun data))))
4349 (defun gnus-article-press-button ()
4350 "Check text at point for a callback function.
4351 If the text at point has a `gnus-callback' property,
4352 call it with the value of the `gnus-data' text property."
4353 (interactive)
4354 (let* ((data (get-text-property (point) 'gnus-data))
4355 (fun (get-text-property (point) 'gnus-callback)))
4356 (when fun
4357 (funcall fun data))))
4359 (defun gnus-article-highlight (&optional force)
4360 "Highlight current article.
4361 This function calls `gnus-article-highlight-headers',
4362 `gnus-article-highlight-citation',
4363 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4364 do the highlighting. See the documentation for those functions."
4365 (interactive (list 'force))
4366 (gnus-article-highlight-headers)
4367 (gnus-article-highlight-citation force)
4368 (gnus-article-highlight-signature)
4369 (gnus-article-add-buttons force)
4370 (gnus-article-add-buttons-to-head))
4372 (defun gnus-article-highlight-some (&optional force)
4373 "Highlight current article.
4374 This function calls `gnus-article-highlight-headers',
4375 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4376 do the highlighting. See the documentation for those functions."
4377 (interactive (list 'force))
4378 (gnus-article-highlight-headers)
4379 (gnus-article-highlight-signature)
4380 (gnus-article-add-buttons))
4382 (defun gnus-article-highlight-headers ()
4383 "Highlight article headers as specified by `gnus-header-face-alist'."
4384 (interactive)
4385 (save-excursion
4386 (set-buffer gnus-article-buffer)
4387 (save-restriction
4388 (let ((alist gnus-header-face-alist)
4389 (buffer-read-only nil)
4390 (case-fold-search t)
4391 (inhibit-point-motion-hooks t)
4392 entry regexp header-face field-face from hpoints fpoints)
4393 (article-narrow-to-head)
4394 (while (setq entry (pop alist))
4395 (goto-char (point-min))
4396 (setq regexp (concat "^\\("
4397 (if (string-equal "" (nth 0 entry))
4398 "[^\t ]"
4399 (nth 0 entry))
4400 "\\)")
4401 header-face (nth 1 entry)
4402 field-face (nth 2 entry))
4403 (while (and (re-search-forward regexp nil t)
4404 (not (eobp)))
4405 (beginning-of-line)
4406 (setq from (point))
4407 (unless (search-forward ":" nil t)
4408 (forward-char 1))
4409 (when (and header-face
4410 (not (memq (point) hpoints)))
4411 (push (point) hpoints)
4412 (gnus-put-text-property from (point) 'face header-face))
4413 (when (and field-face
4414 (not (memq (setq from (point)) fpoints)))
4415 (push from fpoints)
4416 (if (re-search-forward "^[^ \t]" nil t)
4417 (forward-char -2)
4418 (goto-char (point-max)))
4419 (gnus-put-text-property from (point) 'face field-face))))))))
4421 (defun gnus-article-highlight-signature ()
4422 "Highlight the signature in an article.
4423 It does this by highlighting everything after
4424 `gnus-signature-separator' using `gnus-signature-face'."
4425 (interactive)
4426 (save-excursion
4427 (set-buffer gnus-article-buffer)
4428 (let ((buffer-read-only nil)
4429 (inhibit-point-motion-hooks t))
4430 (save-restriction
4431 (when (and gnus-signature-face
4432 (gnus-article-narrow-to-signature))
4433 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4434 'face gnus-signature-face)
4435 (widen)
4436 (gnus-article-search-signature)
4437 (let ((start (match-beginning 0))
4438 (end (set-marker (make-marker) (1+ (match-end 0)))))
4439 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4440 end)))))))
4442 (defun gnus-button-in-region-p (b e prop)
4443 "Say whether PROP exists in the region."
4444 (text-property-not-all b e prop nil))
4446 (defun gnus-article-add-buttons (&optional force)
4447 "Find external references in the article and make buttons of them.
4448 \"External references\" are things like Message-IDs and URLs, as
4449 specified by `gnus-button-alist'."
4450 (interactive (list 'force))
4451 (save-excursion
4452 (set-buffer gnus-article-buffer)
4453 (let ((buffer-read-only nil)
4454 (inhibit-point-motion-hooks t)
4455 (case-fold-search t)
4456 (alist gnus-button-alist)
4457 beg entry regexp)
4458 ;; Remove all old markers.
4459 (let (marker entry new-list)
4460 (while (setq marker (pop gnus-button-marker-list))
4461 (if (or (< marker (point-min)) (>= marker (point-max)))
4462 (push marker new-list)
4463 (goto-char marker)
4464 (when (setq entry (gnus-button-entry))
4465 (put-text-property (match-beginning (nth 1 entry))
4466 (match-end (nth 1 entry))
4467 'gnus-callback nil))
4468 (set-marker marker nil)))
4469 (setq gnus-button-marker-list new-list))
4470 ;; We skip the headers.
4471 (article-goto-body)
4472 (setq beg (point))
4473 (while (setq entry (pop alist))
4474 (setq regexp (car entry))
4475 (goto-char beg)
4476 (while (re-search-forward regexp nil t)
4477 (let* ((start (and entry (match-beginning (nth 1 entry))))
4478 (end (and entry (match-end (nth 1 entry))))
4479 (from (match-beginning 0)))
4480 (when (and (or (eq t (nth 2 entry))
4481 (eval (nth 2 entry)))
4482 (not (gnus-button-in-region-p
4483 start end 'gnus-callback)))
4484 ;; That optional form returned non-nil, so we add the
4485 ;; button.
4486 (gnus-article-add-button
4487 start end 'gnus-button-push
4488 (car (push (set-marker (make-marker) from)
4489 gnus-button-marker-list))))))))))
4491 ;; Add buttons to the head of an article.
4492 (defun gnus-article-add-buttons-to-head ()
4493 "Add buttons to the head of the article."
4494 (interactive)
4495 (save-excursion
4496 (set-buffer gnus-article-buffer)
4497 (save-restriction
4498 (let ((buffer-read-only nil)
4499 (inhibit-point-motion-hooks t)
4500 (case-fold-search t)
4501 (alist gnus-header-button-alist)
4502 entry beg end)
4503 (article-narrow-to-head)
4504 (while alist
4505 ;; Each alist entry.
4506 (setq entry (car alist)
4507 alist (cdr alist))
4508 (goto-char (point-min))
4509 (while (re-search-forward (car entry) nil t)
4510 ;; Each header matching the entry.
4511 (setq beg (match-beginning 0))
4512 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4513 (match-beginning 0))
4514 (point-max)))
4515 (goto-char beg)
4516 (while (re-search-forward (nth 1 entry) end t)
4517 ;; Each match within a header.
4518 (let* ((entry (cdr entry))
4519 (start (match-beginning (nth 1 entry)))
4520 (end (match-end (nth 1 entry)))
4521 (form (nth 2 entry)))
4522 (goto-char (match-end 0))
4523 (when (eval form)
4524 (gnus-article-add-button
4525 start end (nth 3 entry)
4526 (buffer-substring (match-beginning (nth 4 entry))
4527 (match-end (nth 4 entry)))))))
4528 (goto-char end)))))))
4530 ;;; External functions:
4532 (defun gnus-article-add-button (from to fun &optional data)
4533 "Create a button between FROM and TO with callback FUN and data DATA."
4534 (when gnus-article-button-face
4535 (gnus-overlay-put (gnus-make-overlay from to)
4536 'face gnus-article-button-face))
4537 (gnus-add-text-properties
4538 from to
4539 (nconc (and gnus-article-mouse-face
4540 (list gnus-mouse-face-prop gnus-article-mouse-face))
4541 (list 'gnus-callback fun)
4542 (and data (list 'gnus-data data))))
4543 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4544 :button-keymap gnus-widget-button-keymap))
4546 ;;; Internal functions:
4548 (defun gnus-article-set-globals ()
4549 (save-excursion
4550 (set-buffer gnus-summary-buffer)
4551 (gnus-set-global-variables)))
4553 (defun gnus-signature-toggle (end)
4554 (save-excursion
4555 (set-buffer gnus-article-buffer)
4556 (let ((buffer-read-only nil)
4557 (inhibit-point-motion-hooks t))
4558 (if (text-property-any end (point-max) 'article-type 'signature)
4559 (gnus-remove-text-properties-when
4560 'article-type 'signature end (point-max)
4561 (cons 'article-type (cons 'signature
4562 gnus-hidden-properties)))
4563 (gnus-add-text-properties-when
4564 'article-type nil end (point-max)
4565 (cons 'article-type (cons 'signature
4566 gnus-hidden-properties)))))))
4568 (defun gnus-button-entry ()
4569 ;; Return the first entry in `gnus-button-alist' matching this place.
4570 (let ((alist gnus-button-alist)
4571 (entry nil))
4572 (while alist
4573 (setq entry (pop alist))
4574 (if (looking-at (car entry))
4575 (setq alist nil)
4576 (setq entry nil)))
4577 entry))
4579 (defun gnus-button-push (marker)
4580 ;; Push button starting at MARKER.
4581 (save-excursion
4582 (goto-char marker)
4583 (let* ((entry (gnus-button-entry))
4584 (inhibit-point-motion-hooks t)
4585 (fun (nth 3 entry))
4586 (args (mapcar (lambda (group)
4587 (let ((string (match-string group)))
4588 (gnus-set-text-properties
4589 0 (length string) nil string)
4590 string))
4591 (nthcdr 4 entry))))
4592 (cond
4593 ((fboundp fun)
4594 (apply fun args))
4595 ((and (boundp fun)
4596 (fboundp (symbol-value fun)))
4597 (apply (symbol-value fun) args))
4599 (gnus-message 1 "You must define `%S' to use this button"
4600 (cons fun args)))))))
4602 (defun gnus-button-message-id (message-id)
4603 "Fetch MESSAGE-ID."
4604 (save-excursion
4605 (set-buffer gnus-summary-buffer)
4606 (gnus-summary-refer-article message-id)))
4608 (defun gnus-button-fetch-group (address)
4609 "Fetch GROUP specified by ADDRESS."
4610 (if (not (string-match "[:/]" address))
4611 ;; This is just a simple group url.
4612 (gnus-group-read-ephemeral-group address gnus-select-method)
4613 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4614 address))
4615 (error "Can't parse %s" address)
4616 (gnus-group-read-ephemeral-group
4617 (match-string 4 address)
4618 `(nntp ,(match-string 1 address)
4619 (nntp-address ,(match-string 1 address))
4620 (nntp-port-number ,(if (match-end 3)
4621 (match-string 3 address)
4622 "nntp")))))))
4624 (defun gnus-url-parse-query-string (query &optional downcase)
4625 (let (retval pairs cur key val)
4626 (setq pairs (split-string query "&"))
4627 (while pairs
4628 (setq cur (car pairs)
4629 pairs (cdr pairs))
4630 (if (not (string-match "=" cur))
4631 nil ; Grace
4632 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4633 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4634 (if downcase
4635 (setq key (downcase key)))
4636 (setq cur (assoc key retval))
4637 (if cur
4638 (setcdr cur (cons val (cdr cur)))
4639 (setq retval (cons (list key val) retval)))))
4640 retval))
4642 (defun gnus-url-unhex (x)
4643 (if (> x ?9)
4644 (if (>= x ?a)
4645 (+ 10 (- x ?a))
4646 (+ 10 (- x ?A)))
4647 (- x ?0)))
4649 (defun gnus-url-unhex-string (str &optional allow-newlines)
4650 "Remove %XXX embedded spaces, etc in a url.
4651 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4652 decoding of carriage returns and line feeds in the string, which is normally
4653 forbidden in URL encoding."
4654 (setq str (or str ""))
4655 (let ((tmp "")
4656 (case-fold-search t))
4657 (while (string-match "%[0-9a-f][0-9a-f]" str)
4658 (let* ((start (match-beginning 0))
4659 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4660 (code (+ (* 16 ch1)
4661 (gnus-url-unhex (elt str (+ start 2))))))
4662 (setq tmp (concat
4663 tmp (substring str 0 start)
4664 (cond
4665 (allow-newlines
4666 (char-to-string code))
4667 ((or (= code ?\n) (= code ?\r))
4668 " ")
4669 (t (char-to-string code))))
4670 str (substring str (match-end 0)))))
4671 (setq tmp (concat tmp str))
4672 tmp))
4674 (defun gnus-url-mailto (url)
4675 ;; Send mail to someone
4676 (when (string-match "mailto:/*\\(.*\\)" url)
4677 (setq url (substring url (match-beginning 1) nil)))
4678 (let (to args subject func)
4679 (if (string-match (regexp-quote "?") url)
4680 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4681 args (gnus-url-parse-query-string
4682 (substring url (match-end 0) nil) t))
4683 (setq to (gnus-url-unhex-string url)))
4684 (setq args (cons (list "to" to) args)
4685 subject (cdr-safe (assoc "subject" args)))
4686 (message-mail)
4687 (while args
4688 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4689 (if (fboundp func)
4690 (funcall func)
4691 (message-position-on-field (caar args)))
4692 (insert (mapconcat 'identity (cdar args) ", "))
4693 (setq args (cdr args)))
4694 (if subject
4695 (message-goto-body)
4696 (message-goto-subject))))
4698 (defun gnus-button-mailto (address)
4699 "Mail to ADDRESS."
4700 (set-buffer (gnus-copy-article-buffer))
4701 (message-reply address))
4703 (defalias 'gnus-button-reply 'message-reply)
4705 (defun gnus-button-embedded-url (address)
4706 "Activate ADDRESS with `browse-url'."
4707 (browse-url (gnus-strip-whitespace address)))
4709 ;;; Next/prev buttons in the article buffer.
4711 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4712 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4714 (defvar gnus-prev-page-map nil)
4715 (unless gnus-prev-page-map
4716 (setq gnus-prev-page-map (make-sparse-keymap))
4717 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4718 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4720 (defun gnus-insert-prev-page-button ()
4721 (let ((buffer-read-only nil))
4722 (gnus-eval-format
4723 gnus-prev-page-line-format nil
4724 `(gnus-prev t local-map ,gnus-prev-page-map
4725 gnus-callback gnus-article-button-prev-page
4726 article-type annotation))))
4728 (defvar gnus-next-page-map nil)
4729 (unless gnus-next-page-map
4730 (setq gnus-next-page-map (make-keymap))
4731 (suppress-keymap gnus-prev-page-map)
4732 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4733 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4735 (defun gnus-button-next-page ()
4736 "Go to the next page."
4737 (interactive)
4738 (let ((win (selected-window)))
4739 (select-window (get-buffer-window gnus-article-buffer t))
4740 (gnus-article-next-page)
4741 (select-window win)))
4743 (defun gnus-button-prev-page ()
4744 "Go to the prev page."
4745 (interactive)
4746 (let ((win (selected-window)))
4747 (select-window (get-buffer-window gnus-article-buffer t))
4748 (gnus-article-prev-page)
4749 (select-window win)))
4751 (defun gnus-insert-next-page-button ()
4752 (let ((buffer-read-only nil))
4753 (gnus-eval-format gnus-next-page-line-format nil
4754 `(gnus-next
4755 t local-map ,gnus-next-page-map
4756 gnus-callback gnus-article-button-next-page
4757 article-type annotation))))
4759 (defun gnus-article-button-next-page (arg)
4760 "Go to the next page."
4761 (interactive "P")
4762 (let ((win (selected-window)))
4763 (select-window (get-buffer-window gnus-article-buffer t))
4764 (gnus-article-next-page)
4765 (select-window win)))
4767 (defun gnus-article-button-prev-page (arg)
4768 "Go to the prev page."
4769 (interactive "P")
4770 (let ((win (selected-window)))
4771 (select-window (get-buffer-window gnus-article-buffer t))
4772 (gnus-article-prev-page)
4773 (select-window win)))
4775 (defvar gnus-decode-header-methods
4776 '(mail-decode-encoded-word-region)
4777 "List of methods used to decode headers.
4779 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4780 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4781 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4782 whose names match REGEXP.
4784 For example:
4785 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4786 mail-decode-encoded-word-region
4787 (\"chinese\" . rfc1843-decode-region))
4790 (defvar gnus-decode-header-methods-cache nil)
4792 (defun gnus-multi-decode-header (start end)
4793 "Apply the functions from `gnus-encoded-word-methods' that match."
4794 (unless (and gnus-decode-header-methods-cache
4795 (eq gnus-newsgroup-name
4796 (car gnus-decode-header-methods-cache)))
4797 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4798 (mapcar (lambda (x)
4799 (if (symbolp x)
4800 (nconc gnus-decode-header-methods-cache (list x))
4801 (if (and gnus-newsgroup-name
4802 (string-match (car x) gnus-newsgroup-name))
4803 (nconc gnus-decode-header-methods-cache
4804 (list (cdr x))))))
4805 gnus-decode-header-methods))
4806 (let ((xlist gnus-decode-header-methods-cache))
4807 (pop xlist)
4808 (save-restriction
4809 (narrow-to-region start end)
4810 (while xlist
4811 (funcall (pop xlist) (point-min) (point-max))))))
4814 ;;; Treatment top-level handling.
4817 (defun gnus-treat-article (condition &optional part-number total-parts type)
4818 (let ((length (- (point-max) (point-min)))
4819 (alist gnus-treatment-function-alist)
4820 (article-goto-body-goes-to-point-min-p t)
4821 (treated-type
4822 (or (not type)
4823 (catch 'found
4824 (let ((list gnus-article-treat-types))
4825 (while list
4826 (when (string-match (pop list) type)
4827 (throw 'found t)))))))
4828 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4829 val elem)
4830 (gnus-run-hooks 'gnus-part-display-hook)
4831 (while (setq elem (pop alist))
4832 (setq val
4833 (save-excursion
4834 (if (gnus-buffer-live-p gnus-summary-buffer)
4835 (set-buffer gnus-summary-buffer))
4836 (symbol-value (car elem))))
4837 (when (and (or (consp val)
4838 treated-type)
4839 (gnus-treat-predicate val)
4840 (or (not (get (car elem) 'highlight))
4841 highlightp))
4842 (save-restriction
4843 (funcall (cadr elem)))))))
4845 ;; Dynamic variables.
4846 (eval-when-compile
4847 (defvar part-number)
4848 (defvar total-parts)
4849 (defvar type)
4850 (defvar condition)
4851 (defvar length))
4853 (defun gnus-treat-predicate (val)
4854 (cond
4855 ((null val)
4856 nil)
4857 ((and (listp val)
4858 (stringp (car val)))
4859 (apply 'gnus-or (mapcar `(lambda (s)
4860 (string-match s ,(or gnus-newsgroup-name "")))
4861 val)))
4862 ((listp val)
4863 (let ((pred (pop val)))
4864 (cond
4865 ((eq pred 'or)
4866 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4867 ((eq pred 'and)
4868 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4869 ((eq pred 'not)
4870 (not (gnus-treat-predicate (car val))))
4871 ((eq pred 'typep)
4872 (equal (car val) type))
4874 (error "%S is not a valid predicate" pred)))))
4875 (condition
4876 (eq condition val))
4877 ((eq val t)
4879 ((eq val 'head)
4880 nil)
4881 ((eq val 'last)
4882 (eq part-number total-parts))
4883 ((numberp val)
4884 (< length val))
4886 (error "%S is not a valid value" val))))
4888 (gnus-ems-redefine)
4890 (provide 'gnus-art)
4892 (run-hooks 'gnus-art-load-hook)
4894 ;;; gnus-art.el ends here