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