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