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