* gnus-art.el (article-display-x-face): Don't use `nreverse' when sorting gray
[elisp/gnus.git-] / lisp / gnus-art.el
index 0dad544..b8401d4 100644 (file)
@@ -1,9 +1,11 @@
-;;; gnus-art.el --- article mode commands for Gnus
+;;; gnus-art.el --- article mode commands for Semi-gnus
 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
 ;;        Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
-;; Keywords: news
+;;     MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;     Katsumi Yamaoka <yamaoka@jpl.org>
+;; Keywords: mail, news, MIME
 
 ;; This file is part of GNU Emacs.
 
 ;;; Code:
 
 (eval-when-compile (require 'cl))
+(eval-when-compile (require 'static))
 
+(require 'path-util)
 (require 'gnus)
 (require 'gnus-sum)
 (require 'gnus-spec)
 (require 'gnus-int)
 (require 'gnus-win)
-(require 'mm-bodies)
-(require 'mail-parse)
-(require 'mm-decode)
-(require 'mm-view)
+(require 'alist)
+(require 'mime-view)
 (require 'wid-edit)
-(require 'mm-uu)
+
+;; Avoid byte-compile warnings.
+(eval-when-compile
+  (require 'mm-bodies)
+  (require 'mail-parse)
+  (require 'mm-decode)
+  (require 'mm-view)
+  (require 'mm-uu)
+  )
 
 (autoload 'gnus-msg-mail "gnus-msg" nil t)
 (autoload 'gnus-button-mailto "gnus-msg")
     "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
     "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
     "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
-    "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
+    "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face"
     "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
     "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
     "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
      "^X-Content-length:" "^X-Posting-Agent:" "^Original-Received:"
      "^X-Request-PGP:" "^X-Fingerprint:" "^X-WRIEnvto:" "^X-WRIEnvfrom:"
      "^X-Virus-Scanned:" "^X-Delivery-Agent:" "^Posted-Date:" "^X-Gateway:"
-     "^X-Local-Origin:" "^X-Local-Destination:" "^X-UserInfo1:")
+     "^X-Local-Origin:" "^X-Local-Destination:" "^X-UserInfo1:"
+     "^X-Received-Date:")
   "*All headers that start with this regexp will be hidden.
 This variable can also be a list of regexps of headers to be ignored.
 If `gnus-visible-headers' is non-nil, this variable will be ignored."
@@ -225,27 +236,48 @@ regexp.  If it matches, the text in question is not a signature."
 ;; Fixme: This isn't the right thing for mixed graphical and and
 ;; non-graphical frames in a session.
 (defcustom gnus-article-x-face-command
-  (if (featurep 'xemacs)
-      (if (or (gnus-image-type-available-p 'xface)
-             (gnus-image-type-available-p 'xpm))
-         'gnus-xmas-article-display-xface
-       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
-    (if (gnus-image-type-available-p 'xbm)
-       'gnus-article-display-xface
-      (if gnus-article-compface-xbm
-         "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
-       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
-display -")))
+  (cond
+   ((featurep 'xemacs)
+    (if (or (gnus-image-type-available-p 'xface)
+           (gnus-image-type-available-p 'pbm))
+       'gnus-display-x-face-in-from
+      "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -"))
+   ((and (fboundp 'image-type-available-p)
+        (module-installed-p 'x-face-e21))
+    'x-face-decode-message-header)
+   ((gnus-image-type-available-p 'pbm)
+    'gnus-display-x-face-in-from)
+   ((and window-system
+        (module-installed-p 'x-face-mule))
+    'x-face-mule-gnus-article-display-x-face)
+   (t
+    "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
+display -"))
   "*String or function to be executed to display an X-Face header.
 If it is a string, the command will be executed in a sub-shell
 asynchronously.         The compressed face will be piped to this command."
-  :type `(choice string
-                (function-item
-                 ,(if (featurep 'xemacs)
-                      'gnus-xmas-article-display-xface
-                    'gnus-article-display-xface))
-                function)
-  :version "21.1"
+  :type `(choice
+         ,@(let (x-face-e21 x-face-mule)
+             (if (featurep 'xemacs)
+                 nil
+               (setq x-face-e21 (module-installed-p 'x-face-e21)
+                     x-face-mule (module-installed-p 'x-face-mule)))
+             (delq nil
+                   (list
+                    'string
+                    (if (or (gnus-image-type-available-p 'xface)
+                            (gnus-image-type-available-p 'pbm))
+                        '(function-item gnus-display-x-face-in-from))
+                    (if (and x-face-e21
+                             (fboundp 'image-type-available-p))
+                        '(function-item
+                          :tag "x-face-decode-message-header (x-face-e21)"
+                          x-face-decode-message-header))
+                    (if x-face-mule
+                        '(function-item
+                          x-face-mule-gnus-article-display-x-face))
+                    'function))))
+  ;;:version "21.1"
   :group 'gnus-article-washing)
 
 (defcustom gnus-article-x-face-too-ugly nil
@@ -284,23 +316,23 @@ directly.")
 
 (defcustom gnus-emphasis-alist
   (let ((format
-        "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
+        "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
        (types
-        '(("_" "_" underline)
+        '(("\\*" "\\*" bold)
+          ("_" "_" underline)
           ("/" "/" italic)
-          ("\\*" "\\*" bold)
           ("_/" "/_" underline-italic)
           ("_\\*" "\\*_" underline-bold)
           ("\\*/" "/\\*" bold-italic)
           ("_\\*/" "/\\*_" underline-bold-italic))))
-    `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
-       2 3 gnus-emphasis-underline)
-      ,@(mapcar
+    `(,@(mapcar
         (lambda (spec)
           (list
-           (format format (car spec) (cadr spec))
+           (format format (car spec) (car (cdr spec)))
            2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
-        types)))
+        types)
+       ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
+        2 3 gnus-emphasis-underline)))
   "*Alist that says how to fontify certain phrases.
 Each item looks like this:
 
@@ -477,6 +509,20 @@ be used as possible file names."
                         (cons :value ("" "") regexp (repeat string))
                         (sexp :value nil))))
 
+(defcustom gnus-article-display-method-for-mime
+  'gnus-article-display-mime-message
+  "Function to display a MIME message.
+The function is called from the article buffer."
+  :group 'gnus-article-mime
+  :type 'function)
+
+(defcustom gnus-article-display-method-for-traditional
+  'gnus-article-display-traditional-message
+  "*Function to display a traditional message.
+The function is called from the article buffer."
+  :group 'gnus-article-mime
+  :type 'function)
+
 (defcustom gnus-page-delimiter "^\^L"
   "*Regexp describing what to use as article page delimiters.
 The default value is \"^\^L\", which is a form linefeed at the
@@ -612,7 +658,8 @@ Obsolete; use the face `gnus-signature-face' for customizations instead."
       (background light))
      (:foreground "indianred4" :italic t))
     (t
-     (:italic t)))  "Face used for displaying header content."
+     (:italic t)))
+  "Face used for displaying header content."
   :group 'gnus-article-headers
   :group 'gnus-article-highlight)
 
@@ -642,9 +689,7 @@ displayed by the first non-nil matching CONTENT face."
                               (item :tag "skip" nil)
                               (face :value default)))))
 
-(defcustom gnus-article-decode-hook
-  '(article-decode-charset article-decode-encoded-words
-                          article-decode-group-name)
+(defcustom gnus-article-decode-hook nil
   "*Hook run to decode charsets in articles."
   :group 'gnus-article-headers
   :type 'hook)
@@ -700,6 +745,29 @@ To see e.g. security buttons you could set this to
   :group 'gnus-article-mime
   :type '(repeat regexp))
 
+(defcustom gnus-body-boundary-delimiter "_"
+  "String used to delimit header and body.
+This variable is used by `gnus-article-treat-body-boundary' which can
+be controlled by `gnus-treat-body-boundary'."
+  :group 'gnus-article-various
+  :type '(choice (item :tag "None" :value nil)
+                string))
+
+(defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
+  "*Defines the location of the faces database.
+For information on obtaining this database of pretty pictures, please
+see http://www.cs.indiana.edu/picons/ftp/index.html"
+  :type 'directory
+  :group 'gnus-picon)
+
+(defun gnus-picons-installed-p ()
+  "Say whether picons are installed on your machine."
+  (let ((installed nil))
+    (dolist (database gnus-picon-databases)
+      (when (file-exists-p database)
+       (setq installed t)))
+    installed))
+
 (defcustom gnus-article-mime-part-function nil
   "Function called with a MIME handle as the argument.
 This is meant for people who want to do something automatic based
@@ -782,6 +850,7 @@ used."
           (const :tag "On" t)
           (const :tag "Header" head)
           (const :tag "Last" last)
+          (const :tag "Mime" mime)
           (integer :tag "Less")
           (repeat :tag "Groups" regexp)
           (sexp :tag "Predicate")))
@@ -807,7 +876,7 @@ See Info node `(gnus)Customizing Articles'."
 (defcustom gnus-treat-buttonize 100000
   "Add buttons.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles'."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 (put 'gnus-treat-buttonize 'highlight t)
@@ -815,7 +884,7 @@ See the manual for details."
 (defcustom gnus-treat-buttonize-head 'head
   "Add buttons to the head.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 (put 'gnus-treat-buttonize-head 'highlight t)
@@ -827,7 +896,7 @@ See the manual for details."
        50000)
   "Emphasize text.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 (put 'gnus-treat-emphasize 'highlight t)
@@ -835,63 +904,70 @@ See the manual for details."
 (defcustom gnus-treat-strip-cr nil
   "Remove carriage returns.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
+  :group 'gnus-article-treat
+  :type gnus-article-treat-custom)
+
+(defcustom gnus-treat-unsplit-urls nil
+  "Remove newlines from within URLs.
+Valid values are nil, t, `head', `last', an integer or a predicate.
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-leading-whitespace nil
   "Remove leading whitespace in headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-hide-headers 'head
   "Hide headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-hide-boring-headers nil
   "Hide boring headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-hide-signature nil
   "Hide the signature.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-fill-article nil
   "Fill the article.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-hide-citation nil
   "Hide cited text.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-hide-citation-maybe nil
   "Hide cited text.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-strip-list-identifiers 'head
   "Strip list identifiers from `gnus-list-identifiers`.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :version "21.1"
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
@@ -899,14 +975,14 @@ See the manual for details."
 (defcustom gnus-treat-strip-pgp t
   "Strip PGP signatures.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-strip-pem nil
   "Strip PEM signatures.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
@@ -914,14 +990,14 @@ See the manual for details."
   "Strip banners from articles.
 The banner to be stripped is specified in the `banner' group parameter.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-highlight-headers 'head
   "Highlight the headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 (put 'gnus-treat-highlight-headers 'highlight t)
@@ -929,7 +1005,7 @@ See the manual for details."
 (defcustom gnus-treat-highlight-citation t
   "Highlight cited text.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 (put 'gnus-treat-highlight-citation 'highlight t)
@@ -937,42 +1013,42 @@ See the manual for details."
 (defcustom gnus-treat-date-ut nil
   "Display the Date in UT (GMT).
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-date-local nil
   "Display the Date in the local timezone.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-date-english nil
   "Display the Date in a format that can be read aloud in English.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-date-lapsed nil
   "Display the Date header in a way that says how much time has elapsed.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-date-original nil
   "Display the date in the original timezone.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-date-iso8601 nil
   "Display the date in the ISO8601 format.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :version "21.1"
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
@@ -981,14 +1057,14 @@ See the manual for details."
   "Display the date in a user-defined format.
 The format is defined by the `gnus-article-time-format' variable.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 
 (defcustom gnus-treat-strip-headers-in-body t
   "Strip the X-No-Archive header line from the beginning of the body.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :version "21.1"
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
@@ -996,101 +1072,162 @@ See the manual for details."
 (defcustom gnus-treat-strip-trailing-blank-lines nil
   "Strip trailing blank lines.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-strip-leading-blank-lines nil
   "Strip leading blank lines.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-strip-multiple-blank-lines nil
   "Strip multiple blank lines.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-unfold-headers 'head
   "Unfold folded header lines.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
+  :group 'gnus-article-treat
+  :type gnus-article-treat-custom)
+
+(defcustom gnus-treat-fold-headers nil
+  "Fold headers.
+Valid values are nil, t, `head', `last', an integer or a predicate.
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-fold-newsgroups 'head
   "Fold the Newsgroups and Followup-To headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-overstrike t
   "Treat overstrike highlighting.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 (put 'gnus-treat-overstrike 'highlight t)
 
 (defcustom gnus-treat-display-xface
-  (and (or (and (fboundp 'image-type-available-p)
+  (and (not noninteractive)
+       (or (and (fboundp 'image-type-available-p)
                (image-type-available-p 'xbm)
                (string-match "^0x" (shell-command-to-string "uncompface")))
           (and (featurep 'xemacs)
-               (featurep 'xface)))
+               (featurep 'xface))
+          (eq 'x-face-mule-gnus-article-display-x-face
+              gnus-article-x-face-command))
        'head)
   "Display X-Face headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' and Info node
+`(gnus)X-Face' for details."
   :group 'gnus-article-treat
-  :version "21.1"
+  ;;:version "21.1"
   :type gnus-article-treat-head-custom)
 (put 'gnus-treat-display-xface 'highlight t)
 
+(defcustom gnus-article-should-use-smiley-mule
+  (not (or (featurep 'xemacs)
+          (gnus-image-type-available-p 'xpm)
+          (gnus-image-type-available-p 'pbm)))
+  "If non-nil, gnus uses `smiley-mule' for displaying smileys rather than
+`smiley'.  It defaults to t when Emacs 20 or earlier is running.
+`smiley-mule' is boundled in BITMAP-MULE package.  You can set it to t
+even if you are using Emacs 21+.  It has no effect on XEmacs."
+  :group 'gnus-article-various
+  :type 'boolean
+  :get (lambda (symbol)
+        (and (default-value symbol)
+             (not (featurep 'xemacs))
+             (module-installed-p 'smiley-mule)
+             t))
+  :set (lambda (symbol value)
+        (set-default symbol (and value
+                                 (not (featurep 'xemacs))
+                                 (module-installed-p 'smiley-mule)
+                                 t))))
+
+(defvar gnus-article-smiley-mule-loaded-p nil
+  "Internal variable used to say whether `smiley-mule' is loaded (whether
+smiley functions are not overridden by `smiley').")
+
+(defcustom gnus-treat-display-grey-xface
+  (and (not noninteractive)
+       (or (featurep 'xemacs)
+          (and (fboundp 'display-images-p)
+               (display-images-p)))
+       (string-match "^0x" (shell-command-to-string "uncompface"))
+       t)
+  "Display grey X-Face headers.
+Valid values are nil, t."
+  :group 'gnus-article-treat
+  :version "21.3"
+  :type 'boolean)
+(put 'gnus-treat-display-grey-xface 'highlight t)
+
 (defcustom gnus-treat-display-smileys
   (if (or (and (featurep 'xemacs)
               (featurep 'xpm))
-         (and (fboundp 'image-type-available-p)
-              (image-type-available-p 'pbm)))
-      t nil)
+         (gnus-image-type-available-p 'xpm)
+         (gnus-image-type-available-p 'pbm)
+         (and (not (featurep 'xemacs))
+              window-system
+              (module-installed-p 'smiley-mule)))
+      t
+    nil)
   "Display smileys.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' and Info node
+`(gnus)Smileys' for details."
   :group 'gnus-article-treat
-  :version "21.1"
+  ;;:version "21.1"
   :type gnus-article-treat-custom)
 (put 'gnus-treat-display-smileys 'highlight t)
 
 (defcustom gnus-treat-from-picon
-  (if (gnus-image-type-available-p 'xpm)
+  (if (and (gnus-image-type-available-p 'xpm)
+          (gnus-picons-installed-p))
       'head nil)
   "Display picons in the From header.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' and Info node
+`(gnus)Picons' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 (put 'gnus-treat-from-picon 'highlight t)
 
 (defcustom gnus-treat-mail-picon
-  (if (gnus-image-type-available-p 'xpm)
+  (if (and (gnus-image-type-available-p 'xpm)
+          (gnus-picons-installed-p))
       'head nil)
   "Display picons in To and Cc headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' and Info node
+`(gnus)Picons' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 (put 'gnus-treat-mail-picon 'highlight t)
 
 (defcustom gnus-treat-newsgroups-picon
-  (if (gnus-image-type-available-p 'xpm)
+  (if (and (gnus-image-type-available-p 'xpm)
+          (gnus-picons-installed-p))
       'head nil)
   "Display picons in the Newsgroups and Followup-To headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' and Info node
+`(gnus)Picons' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-head-custom)
 (put 'gnus-treat-newsgroups-picon 'highlight t)
@@ -1102,7 +1239,7 @@ See the manual for details."
       'head nil)
   "Draw a boundary at the end of the headers.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :version "21.1"
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
@@ -1110,7 +1247,7 @@ See the manual for details."
 (defcustom gnus-treat-capitalize-sentences nil
   "Capitalize sentence-starting words.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :version "21.1"
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
@@ -1118,22 +1255,32 @@ See the manual for details."
 (defcustom gnus-treat-fill-long-lines nil
   "Fill long lines.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
 (defcustom gnus-treat-play-sounds nil
   "Play sounds.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :version "21.1"
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
 
+(defcustom gnus-treat-decode-article-as-default-mime-charset nil
+  "Decode an article as `default-mime-charset'.  For instance, if you want to
+attempt to decode an article even if the value of `gnus-show-mime' is nil,
+you could set this variable to something like: nil for don't decode, t for
+decode the body, '(or header t) for the whole article, etc."
+  :group 'gnus-article-treat
+  :type '(radio (const :tag "Off" nil)
+               (const :tag "Decode body" t)
+               (const :tag "Decode all" (or head t))))
+
 (defcustom gnus-treat-translate nil
   "Translate articles from one language to another.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :version "21.1"
   :group 'gnus-article-treat
   :type gnus-article-treat-custom)
@@ -1142,7 +1289,7 @@ See the manual for details."
   "Verify X-PGP-Sig.
 To automatically treat X-PGP-Sig, set it to head.
 Valid values are nil, t, `head', `last', an integer or a predicate.
-See the manual for details."
+See Info node `(gnus)Customizing Articles' for details."
   :group 'gnus-article-treat
   :group 'mime-security
   :type gnus-article-treat-custom)
@@ -1158,6 +1305,9 @@ It is a string, such as \"PGP\". If nil, ask user."
   :type 'string
   :group 'mime-security)
 
+(defvar gnus-article-wash-function nil
+  "Function used for converting HTML into text.")
+
 ;;; Internal variables
 
 (defvar gnus-english-month-names
@@ -1171,14 +1321,16 @@ It is a string, such as \"PGP\". If nil, ask user."
 
 (defvar gnus-article-mime-handle-alist-1 nil)
 (defvar gnus-treatment-function-alist
-  '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
+  '((gnus-treat-decode-article-as-default-mime-charset
+     gnus-article-decode-article-as-default-mime-charset)
+    (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
     (gnus-treat-strip-banner gnus-article-strip-banner)
     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
-    (gnus-treat-highlight-signature gnus-article-highlight-signature)
     (gnus-treat-buttonize gnus-article-add-buttons)
     (gnus-treat-fill-article gnus-article-fill-cited-article)
     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
     (gnus-treat-strip-cr gnus-article-remove-cr)
+    (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
     (gnus-treat-date-ut gnus-article-date-ut)
     (gnus-treat-date-local gnus-article-date-local)
     (gnus-treat-date-english gnus-article-date-english)
@@ -1189,8 +1341,6 @@ It is a string, such as \"PGP\". If nil, ask user."
     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
     (gnus-treat-hide-signature gnus-article-hide-signature)
-    (gnus-treat-hide-citation gnus-article-hide-citation)
-    (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
     (gnus-treat-strip-pgp gnus-article-hide-pgp)
@@ -1199,7 +1349,6 @@ It is a string, such as \"PGP\". If nil, ask user."
     (gnus-treat-mail-picon gnus-treat-mail-picon)
     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
     (gnus-treat-highlight-headers gnus-article-highlight-headers)
-    (gnus-treat-highlight-citation gnus-article-highlight-citation)
     (gnus-treat-highlight-signature gnus-article-highlight-signature)
     (gnus-treat-strip-trailing-blank-lines
      gnus-article-remove-trailing-blank-lines)
@@ -1209,12 +1358,18 @@ It is a string, such as \"PGP\". If nil, ask user."
      gnus-article-strip-multiple-blank-lines)
     (gnus-treat-overstrike gnus-article-treat-overstrike)
     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
+    (gnus-treat-fold-headers gnus-article-treat-fold-headers)
+    ;; Displaying X-Face should be done after unfolding headers
+    ;; to protect bitmap lines.
+    (gnus-treat-display-xface gnus-article-display-x-face)
     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
-    (gnus-treat-display-smileys gnus-smiley-display)
+    (gnus-treat-display-smileys gnus-treat-smiley)
     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
     (gnus-treat-emphasize gnus-article-emphasize)
-    (gnus-treat-display-xface gnus-article-display-x-face)
+    (gnus-treat-hide-citation gnus-article-hide-citation)
+    (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
+    (gnus-treat-highlight-citation gnus-article-highlight-citation)
     (gnus-treat-body-boundary gnus-article-treat-body-boundary)
     (gnus-treat-play-sounds gnus-earcon-display)))
 
@@ -1344,59 +1499,73 @@ Initialized from `text-mode-syntax-table.")
 
 (defun article-hide-headers (&optional arg delete)
   "Hide unwanted headers and possibly sort them as well."
-  (interactive)
-  ;; This function might be inhibited.
-  (unless gnus-inhibit-hiding
-    (save-excursion
-      (save-restriction
-       (let ((buffer-read-only nil)
-             (case-fold-search t)
-             (max (1+ (length gnus-sorted-header-list)))
-             (ignored (when (not gnus-visible-headers)
-                        (cond ((stringp gnus-ignored-headers)
-                               gnus-ignored-headers)
-                              ((listp gnus-ignored-headers)
-                               (mapconcat 'identity gnus-ignored-headers
-                                          "\\|")))))
-             (visible
-              (cond ((stringp gnus-visible-headers)
-                     gnus-visible-headers)
-                    ((and gnus-visible-headers
-                          (listp gnus-visible-headers))
-                     (mapconcat 'identity gnus-visible-headers "\\|"))))
-             (inhibit-point-motion-hooks t)
-             beg)
-         ;; First we narrow to just the headers.
-         (article-narrow-to-head)
-         ;; Hide any "From " lines at the beginning of (mail) articles.
-         (while (looking-at "From ")
-           (forward-line 1))
-         (unless (bobp)
-           (delete-region (point-min) (point)))
-         ;; Then treat the rest of the header lines.
-         ;; Then we use the two regular expressions
-         ;; `gnus-ignored-headers' and `gnus-visible-headers' to
-         ;; select which header lines is to remain visible in the
-         ;; article buffer.
-         (while (re-search-forward "^[^ \t:]*:" nil t)
-           (beginning-of-line)
-           ;; Mark the rank of the header.
-           (put-text-property
-            (point) (1+ (point)) 'message-rank
-            (if (or (and visible (looking-at visible))
-                    (and ignored
-                         (not (looking-at ignored))))
-                (gnus-article-header-rank)
-              (+ 2 max)))
-           (forward-line 1))
-         (message-sort-headers-1)
-         (when (setq beg (text-property-any
-                          (point-min) (point-max) 'message-rank (+ 2 max)))
-           ;; We delete the unwanted headers.
-           (gnus-add-wash-type 'headers)
-           (add-text-properties (point-min) (+ 5 (point-min))
-                                '(article-type headers dummy-invisible t))
-           (delete-region beg (point-max))))))))
+  (interactive (gnus-article-hidden-arg))
+  ;; Lars said that this function might be inhibited.
+  (if (gnus-article-check-hidden-text 'headers arg)
+      (progn
+       ;; Show boring headers as well.
+       (gnus-article-show-hidden-text 'boring-headers)
+       (when (eq 1 (point-min))
+         (set-window-start (get-buffer-window (current-buffer)) 1)))
+    (unless gnus-inhibit-hiding
+      (save-excursion
+       (save-restriction
+         (let ((inhibit-read-only t)
+               (case-fold-search t)
+               (max (1+ (length gnus-sorted-header-list)))
+               (ignored (when (not gnus-visible-headers)
+                          (cond ((stringp gnus-ignored-headers)
+                                 gnus-ignored-headers)
+                                ((listp gnus-ignored-headers)
+                                 (mapconcat 'identity gnus-ignored-headers
+                                            "\\|")))))
+               (visible
+                (cond ((stringp gnus-visible-headers)
+                       gnus-visible-headers)
+                      ((and gnus-visible-headers
+                            (listp gnus-visible-headers))
+                       (mapconcat 'identity gnus-visible-headers "\\|"))))
+               (inhibit-point-motion-hooks t)
+               beg)
+           ;; First we narrow to just the headers.
+           (article-narrow-to-head)
+           ;; Hide any "From " lines at the beginning of (mail) articles.
+           (while (looking-at "From ")
+             (forward-line 1))
+           (unless (bobp)
+             (if delete
+                 (delete-region (point-min) (point))
+               (gnus-article-hide-text (point-min) (point)
+                                       (nconc (list 'article-type 'headers)
+                                              gnus-hidden-properties))))
+           ;; Then treat the rest of the header lines.
+           ;; Then we use the two regular expressions
+           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
+           ;; select which header lines is to remain visible in the
+           ;; article buffer.
+           (while (re-search-forward "^[^ \t:]*:" nil t)
+             (beginning-of-line)
+             ;; Mark the rank of the header.
+             (put-text-property
+              (point) (1+ (point)) 'message-rank
+              (if (or (and visible (looking-at visible))
+                      (and ignored
+                           (not (looking-at ignored))))
+                  (gnus-article-header-rank)
+                (+ 2 max)))
+             (forward-line 1))
+           (message-sort-headers-1)
+           (when (setq beg (text-property-any
+                            (point-min) (point-max) 'message-rank (+ 2 max)))
+             ;; We delete or make invisible the unwanted headers.
+             (gnus-add-wash-type 'headers)
+             (if delete
+                 (progn
+                   (add-text-properties
+                    (point-min) (+ 5 (point-min))
+                    '(article-type headers dummy-invisible t))
+                   (delete-region beg (point-max)))
+               (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
 
 (defun article-hide-boring-headers (&optional arg)
   "Toggle hiding of headers that aren't very interesting.
@@ -1519,6 +1688,91 @@ always hide."
           (point-max)))
        'boring-headers))))
 
+(defun article-toggle-headers (&optional arg)
+  "Toggle hiding of headers.  If given a negative prefix, always show;
+if given a positive prefix, always hide."
+  (interactive (gnus-article-hidden-arg))
+  (let ((force (when (numberp arg)
+                (cond ((> arg 0) 'always-hide)
+                      ((< arg 0) 'always-show))))
+       (window (get-buffer-window gnus-article-buffer))
+       (header-end (point-min))
+       header-start field-end field-start
+       (inhibit-point-motion-hooks t)
+       (inhibit-read-only t))
+    (save-restriction
+      (widen)
+      (while (and (setq header-start
+                       (text-property-any header-end (point-max)
+                                          'article-treated-header t))
+                 (setq header-end
+                       (text-property-not-all header-start (point-max)
+                                              'article-treated-header t)))
+       (setq field-end header-start)
+       (cond
+        (;; Hide exposed invisible fields.
+         (and (not (eq 'always-show force))
+              (setq field-start
+                    (text-property-any field-end header-end
+                                       'exposed-invisible-field t)))
+         (while (and field-start
+                     (setq field-end (text-property-not-all
+                                      field-start header-end
+                                      'exposed-invisible-field t)))
+           (add-text-properties field-start field-end gnus-hidden-properties)
+           (setq field-start (text-property-any field-end header-end
+                                                'exposed-invisible-field t)))
+         (put-text-property header-start header-end
+                            'exposed-invisible-field nil))
+        (;; Expose invisible fields.
+         (and (not (eq 'always-hide force))
+              (setq field-start
+                    (text-property-any field-end header-end 'invisible t)))
+         (while (and field-start
+                     (setq field-end (text-property-not-all
+                                      field-start header-end
+                                      'invisible t)))
+           ;; If the invisible text is not terminated with newline, we
+           ;; won't expose it.  Because it may be created by x-face-mule.
+           ;; BTW, XEmacs sometimes fail in putting an invisible text
+           ;; property with `gnus-article-hide-text' (really?).  In that
+           ;; case, the invisible text might be started from the middle of
+           ;; a line, so we will expose the sort of thing.
+           (when (or (not (or (eq header-start field-start)
+                              (eq ?\n (char-before field-start))))
+                     (eq ?\n (char-before field-end))
+                     ;; Expose a boundary line anyway.
+                     (string-equal
+                      "\nX-Boundary: "
+                      (buffer-substring (max (- field-end 13) header-start)
+                                        field-end)))
+             (remove-text-properties field-start field-end
+                                     gnus-hidden-properties)
+             (put-text-property field-start field-end
+                                'exposed-invisible-field t))
+           (setq field-start (text-property-any field-end header-end
+                                                'invisible t))))
+        (;; Hide fields.
+         (not (eq 'always-show force))
+         (narrow-to-region header-start header-end)
+         (article-hide-headers)
+         ;; Re-display X-Face image under XEmacs.
+         (when (and (featurep 'xemacs)
+                    (gnus-functionp gnus-article-x-face-command))
+           (let ((func (cadr (assq 'gnus-treat-display-xface
+                                   gnus-treatment-function-alist)))
+                 (condition 'head))
+             (when (and (not gnus-inhibit-treatment)
+                        func
+                        (gnus-treat-predicate gnus-treat-display-xface))
+               (funcall func)
+               (put-text-property header-start header-end 'read-only nil))))
+         (widen))
+        ))
+      (goto-char (point-min))
+      (when window
+       (set-window-start window (point-min))))))
+
 (defvar gnus-article-normalized-header-length 40
   "Length of normalized headers.")
 
@@ -1599,23 +1853,29 @@ MAP is an alist where the elements are on the form (\"from\" \"to\")."
       (let ((buffer-read-only nil))
        (while (search-forward "\b" nil t)
          (let ((next (char-after))
-               (previous (char-after (- (point) 2))))
+               start end previous)
+           (backward-char 2)
+           (setq start (point)
+                 previous (char-after))
+           (forward-char 3)
+           (setq end (point))
+           (backward-char)
            ;; We do the boldification/underlining by hiding the
            ;; overstrikes and putting the proper text property
            ;; on the letters.
            (cond
             ((eq next previous)
-             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
-             (put-text-property (point) (1+ (point)) 'face 'bold))
+             (gnus-article-hide-text-type start (point) 'overstrike)
+             (put-text-property (point) end 'face 'bold))
             ((eq next ?_)
              (gnus-article-hide-text-type
               (1- (point)) (1+ (point)) 'overstrike)
              (put-text-property
-              (- (point) 2) (1- (point)) 'face 'underline))
+              start (1- (point)) 'face 'underline))
             ((eq previous ?_)
-             (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
+             (gnus-article-hide-text-type start (point) 'overstrike)
              (put-text-property
-              (point) (1+ (point)) 'face 'underline)))))))))
+              (point) end 'face 'underline)))))))))
 
 (defun gnus-article-treat-unfold-headers ()
   "Unfold folded message headers.
@@ -1631,14 +1891,54 @@ unfolded."
            (with-temp-buffer
              (insert header)
              (goto-char (point-min))
-             (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
+             (while (re-search-forward "\n[\t ]" nil t)
                (replace-match " " t t)))
            (setq length (- (point-max) (point-min) 1)))
          (when (< length (window-width))
-           (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
+           (while (re-search-forward "\n[\t ]" nil t)
              (replace-match " " t t)))
          (goto-char (point-max)))))))
 
+(defun gnus-article-treat-fold-headers ()
+  "Fold message headers."
+  (interactive)
+  (gnus-with-article-headers
+    (while (not (eobp))
+      (save-restriction
+       (mail-header-narrow-to-field)
+       (mail-header-fold-field)
+       (goto-char (point-max))))))
+
+(defun gnus-treat-smiley ()
+  "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
+  (interactive)
+  (unless (featurep 'xemacs)
+    (when (and (>= emacs-major-version 21)
+              (not gnus-article-should-use-smiley-mule)
+              gnus-article-smiley-mule-loaded-p)
+      (load "smiley" nil t)
+      (setq gnus-article-smiley-mule-loaded-p nil))
+    (when (and gnus-article-should-use-smiley-mule
+              (not gnus-article-smiley-mule-loaded-p))
+      (load "smiley-mule" nil t)
+      (setq gnus-article-smiley-mule-loaded-p t)))
+  (gnus-with-article-buffer
+    (if (memq 'smiley gnus-article-wash-types)
+       (gnus-delete-images 'smiley)
+      (article-goto-body)
+      (let ((images (smiley-region (point) (point-max))))
+       (when images
+         (gnus-add-wash-type 'smiley)
+         (dolist (image images)
+           (gnus-add-image 'smiley image)))))))
+
+(defun gnus-article-remove-images ()
+  "Remove all images from the article buffer."
+  (interactive)
+  (gnus-with-article-buffer
+    (dolist (elem gnus-article-image-alist)
+      (gnus-delete-images (car elem)))))
+
 (defun gnus-article-treat-fold-newsgroups ()
   "Unfold folded message headers.
 Only the headers that fit into the current window width will be
@@ -1648,7 +1948,7 @@ unfolded."
     (while (gnus-article-goto-header "newsgroups\\|followup-to")
       (save-restriction
        (mail-header-narrow-to-field)
-       (while (search-forward "," nil t)
+       (while (re-search-forward ", *" nil t)
          (replace-match ", " t t))
        (mail-header-fold-field)
        (goto-char (point-max))))))
@@ -1656,13 +1956,19 @@ unfolded."
 (defun gnus-article-treat-body-boundary ()
   "Place a boundary line at the end of the headers."
   (interactive)
-  (gnus-with-article-headers
-    (goto-char (point-max))
-    (let ((start (point)))
-    (insert "X-Boundary: ")
-    (gnus-add-text-properties start (point) '(invisible t intangible t))
-    (insert (make-string (1- (window-width)) ?-)
-           "\n"))))
+  (when (and gnus-body-boundary-delimiter
+            (> (length gnus-body-boundary-delimiter) 0))
+    (gnus-with-article-headers
+      (goto-char (point-max))
+      (let ((start (point)))
+       (insert "X-Boundary: ")
+       (gnus-add-text-properties start (point) '(invisible t intangible t))
+       (insert (let (str)
+                 (while (>= (1- (window-width)) (length str))
+                   (setq str (concat str gnus-body-boundary-delimiter)))
+                 (substring str 0 (1- (window-width))))
+               "\n")
+       (gnus-add-text-properties start (point) '(gnus-decoration 'header))))))
 
 (defun article-fill-long-lines ()
   "Fill lines that are wider than the window width."
@@ -1725,52 +2031,89 @@ unfolded."
 (defun article-display-x-face (&optional force)
   "Look for an X-Face header and display it if present."
   (interactive (list 'force))
-  (gnus-with-article-headers
-    ;; Delete the old process, if any.
-    (when (process-status "article-x-face")
-      (delete-process "article-x-face"))
-    (if (memq 'xface gnus-article-wash-types)
-       ;; We have already displayed X-Faces, so we remove them
-       ;; instead.
-       (gnus-delete-images 'xface)
-      ;; Display X-Faces.
-      (let (x-faces from face)
-       (save-excursion
-         (set-buffer gnus-original-article-buffer)
-         (save-restriction
-           (mail-narrow-to-head)
-           (while (gnus-article-goto-header "x-face")
-             (push (mail-header-field-value) x-faces))
-           (setq from (message-fetch-field "from"))))
-       ;; Sending multiple EOFs to xv doesn't work, so we only do a
-       ;; single external face.
-       (when (stringp gnus-article-x-face-command)
-         (setq x-faces (list (car x-faces))))
-       (while (and (setq face (pop x-faces))
-                   gnus-article-x-face-command
-                   (or force
-                       ;; Check whether this face is censored.
-                       (not gnus-article-x-face-too-ugly)
-                       (and gnus-article-x-face-too-ugly from
-                            (not (string-match gnus-article-x-face-too-ugly
-                                               from)))))
-         ;; We display the face.
-         (if (symbolp gnus-article-x-face-command)
-             ;; The command is a lisp function, so we call it.
-             (if (gnus-functionp gnus-article-x-face-command)
-                 (funcall gnus-article-x-face-command face)
-               (error "%s is not a function" gnus-article-x-face-command))
-           ;; The command is a string, so we interpret the command
-           ;; as a, well, command, and fork it off.
-           (let ((process-connection-type nil))
-             (process-kill-without-query
-              (start-process
-               "article-x-face" nil shell-file-name shell-command-switch
-               gnus-article-x-face-command))
-             (with-temp-buffer
-               (insert face)
-               (process-send-region "article-x-face" (point-min) (point-max)))
-             (process-send-eof "article-x-face"))))))))
+  (let ((wash-face-p buffer-read-only))        ;; When type `W f'
+    (gnus-with-article-headers
+      ;; Delete the old process, if any.
+      (when (process-status "article-x-face")
+       (delete-process "article-x-face"))
+      (if (memq 'xface gnus-article-wash-types)
+         ;; We have already displayed X-Faces, so we remove them
+         ;; instead.
+         (gnus-delete-images 'xface)
+       ;; Display X-Faces.
+       (let (x-faces from face grey)
+         (save-excursion
+           (when (and wash-face-p
+                      (progn
+                        (goto-char (point-min))
+                        (not (re-search-forward
+                              "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
+                      (gnus-buffer-live-p gnus-original-article-buffer))
+             ;; If type `W f', use gnus-original-article-buffer,
+             ;; otherwise use the current buffer because displaying
+             ;; RFC822 parts calls this function too.
+             (set-buffer gnus-original-article-buffer))
+           (save-restriction
+             (mail-narrow-to-head)
+             (if gnus-treat-display-grey-xface
+                 (progn
+                   (while (gnus-article-goto-header "X-Face\\(-[0-9]+\\)?")
+                     (if (match-beginning 2)
+                         (progn
+                           (setq grey t)
+                           (push (cons (- (string-to-number (match-string 2)))
+                                       (mail-header-field-value))
+                                 x-faces))
+                       (push (cons 0 (mail-header-field-value)) x-faces)))
+                   (dolist (x-face (prog1
+                                       (sort x-faces 'car-less-than-car)
+                                     (setq x-faces nil)))
+                     (push (cdr x-face) x-faces)))
+               (while (gnus-article-goto-header "X-Face")
+                 (push (mail-header-field-value) x-faces)))
+             (setq from (message-fetch-field "from"))))
+         (if grey
+             (let ((xpm (gnus-convert-gray-x-face-to-xpm x-faces))
+                   image)
+               (when xpm
+                 (setq image (gnus-create-image xpm 'xpm t))
+                 (gnus-article-goto-header "from")
+                 (when (bobp)
+                   (insert "From: [no `from' set]\n")
+                   (forward-char -17))
+                 (gnus-add-wash-type 'xface)
+                 (gnus-add-image 'xface image)
+                 (gnus-put-image image)))
+           ;; Sending multiple EOFs to xv doesn't work, so we only do a
+           ;; single external face.
+           (when (stringp gnus-article-x-face-command)
+             (setq x-faces (list (car x-faces))))
+           (while (and (setq face (pop x-faces))
+                       gnus-article-x-face-command
+                       (or force
+                           ;; Check whether this face is censored.
+                           (not gnus-article-x-face-too-ugly)
+                           (and gnus-article-x-face-too-ugly from
+                                (not (string-match gnus-article-x-face-too-ugly
+                                                   from)))))
+             ;; We display the face.
+             (if (symbolp gnus-article-x-face-command)
+                 ;; The command is a lisp function, so we call it.
+                 (if (gnus-functionp gnus-article-x-face-command)
+                     (funcall gnus-article-x-face-command face)
+                   (error "%s is not a function" gnus-article-x-face-command))
+               ;; The command is a string, so we interpret the command
+               ;; as a, well, command, and fork it off.
+               (let ((process-connection-type nil))
+                 (process-kill-without-query
+                  (start-process
+                   "article-x-face" nil shell-file-name shell-command-switch
+                   gnus-article-x-face-command))
+                 (with-temp-buffer
+                   (insert face)
+                   (process-send-region "article-x-face"
+                                        (point-min) (point-max)))
+                 (process-send-eof "article-x-face"))))))))))
 
 (defun article-decode-mime-words ()
   "Decode all MIME-encoded words in the article."
@@ -1798,52 +2141,46 @@ If PROMPT (the prefix), prompt for a coding system to use."
                           (error))
                         gnus-newsgroup-ignored-charsets))
        ct cte ctl charset format)
-  (save-excursion
-    (save-restriction
-      (article-narrow-to-head)
-      (setq ct (message-fetch-field "Content-Type" t)
-           cte (message-fetch-field "Content-Transfer-Encoding" t)
-           ctl (and ct (ignore-errors
-                         (mail-header-parse-content-type ct)))
-           charset (cond
-                    (prompt
-                     (mm-read-coding-system "Charset to decode: "))
-                    (ctl
-                     (mail-content-type-get ctl 'charset)))
-           format (and ctl (mail-content-type-get ctl 'format)))
-      (when cte
-       (setq cte (mail-header-strip cte)))
-      (if (and ctl (not (string-match "/" (car ctl))))
-         (setq ctl nil))
-      (goto-char (point-max)))
-    (forward-line 1)
-    (save-restriction
-      (narrow-to-region (point) (point-max))
-      (when (and (eq mail-parse-charset 'gnus-decoded)
-                (eq (mm-body-7-or-8) '8bit))
-       ;; The text code could have been decoded.
-       (setq charset mail-parse-charset))
-      (when (and (or (not ctl)
-                    (equal (car ctl) "text/plain"))
-                (not format)) ;; article with format will decode later.
-       (mm-decode-body
-        charset (and cte (intern (downcase
-                                  (gnus-strip-whitespace cte))))
-        (car ctl)))))))
+    (save-excursion
+      (save-restriction
+       (article-narrow-to-head)
+       (setq ct (message-fetch-field "Content-Type" t)
+             cte (message-fetch-field "Content-Transfer-Encoding" t)
+             ctl (and ct (ignore-errors
+                           (mail-header-parse-content-type ct)))
+             charset (cond
+                      (prompt
+                       (mm-read-coding-system "Charset to decode: "))
+                      (ctl
+                       (mail-content-type-get ctl 'charset)))
+             format (and ctl (mail-content-type-get ctl 'format)))
+       (when cte
+         (setq cte (mail-header-strip cte)))
+       (if (and ctl (not (string-match "/" (car ctl))))
+           (setq ctl nil))
+       (goto-char (point-max)))
+      (forward-line 1)
+      (save-restriction
+       (narrow-to-region (point) (point-max))
+       (when (and (eq mail-parse-charset 'gnus-decoded)
+                  (eq (mm-body-7-or-8) '8bit))
+         ;; The text code could have been decoded.
+         (setq charset mail-parse-charset))
+       (when (and (or (not ctl)
+                      (equal (car ctl) "text/plain"))
+                  (not format)) ;; article with format will decode later.
+         (mm-decode-body
+          charset (and cte (intern (downcase
+                                    (gnus-strip-whitespace cte))))
+          (car ctl)))))))
 
 (defun article-decode-encoded-words ()
   "Remove encoded-word encoding from headers."
-  (let ((inhibit-point-motion-hooks t)
-       (mail-parse-charset gnus-newsgroup-charset)
-       (mail-parse-ignored-charsets
-        (save-excursion (condition-case nil
-                            (set-buffer gnus-summary-buffer)
-                          (error))
-                        gnus-newsgroup-ignored-charsets))
-       buffer-read-only)
-    (save-restriction
-      (article-narrow-to-head)
-      (funcall gnus-decode-header-function (point-min) (point-max)))))
+  (let (buffer-read-only)
+    (let ((charset (save-excursion
+                    (set-buffer gnus-summary-buffer)
+                    default-mime-charset)))
+      (mime-decode-header-in-buffer charset))))
 
 (defun article-decode-group-name ()
   "Decode group names in `Newsgroups:'."
@@ -1943,6 +2280,16 @@ If READ-CHARSET, ask for a coding system."
     (let ((buffer-read-only nil))
       (rfc1843-decode-region (point-min) (point-max)))))
 
+(defun article-unsplit-urls ()
+  "Remove the newlines that some other mailers insert into URLs."
+  (interactive)
+  (save-excursion
+    (let ((buffer-read-only nil))
+      (goto-char (point-min))
+      (while (re-search-forward
+             "^\\(\\(https?\\|ftp\\)://\\S-+\\)\n\\(\\S-+\\)" nil t)
+       (replace-match "\\1\\3" t)))))
+
 (defun article-wash-html (&optional read-charset)
   "Format an html article.
 If READ-CHARSET, ask for a coding system."
@@ -1968,14 +2315,44 @@ If READ-CHARSET, ask for a coding system."
       (save-window-excursion
        (save-restriction
          (narrow-to-region (point) (point-max))
-         (mm-setup-w3)
-         (let ((w3-strict-width (window-width))
-               (url-standalone-mode t)
-               (w3-honor-stylesheets nil)
-               (w3-delay-image-loads t))
-           (condition-case var
-               (w3-region (point-min) (point-max))
-             (error))))))))
+         (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
+                (entry (assq func mm-text-html-washer-alist)))
+           (if entry
+               (setq func (cdr entry)))
+           (cond
+            ((gnus-functionp func)
+             (funcall func))
+            (t
+             (apply (car func) (cdr func))))))))))
+
+(defun gnus-article-wash-html-with-w3 ()
+  "Wash the current buffer with w3."
+  (mm-setup-w3)
+  (let ((w3-strict-width (window-width))
+       (url-standalone-mode t)
+       (url-gateway-unplugged t)
+       (w3-honor-stylesheets nil)
+       (w3-delay-image-loads t))
+    (condition-case var
+       (w3-region (point-min) (point-max))
+      (error))))
+
+(defun gnus-article-wash-html-with-w3m ()
+  "Wash the current buffer with emacs-w3m."
+  (mm-setup-w3m)
+  (save-restriction
+    (narrow-to-region (point) (point-max))
+    (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
+                                  nil
+                                "\\`cid:"))
+         (w3m-display-inline-images mm-inline-text-html-with-images)
+         w3m-force-redisplay)
+      (w3m-region (point-min) (point-max)))
+    (when mm-inline-text-html-with-w3m-keymap
+      (add-text-properties
+       (point-min) (point-max)
+       (append '(mm-inline-text-html-with-w3m t)
+              (gnus-local-map-property mm-w3m-mode-map))))))
 
 (defun article-hide-list-identifiers ()
   "Remove list identifies from the Subject header.
@@ -2110,13 +2487,28 @@ always hide."
 If given a negative prefix, always show; if given a positive prefix,
 always hide."
   (interactive (gnus-article-hidden-arg))
-  (unless (gnus-article-check-hidden-text 'signature arg)
-    (save-excursion
-      (save-restriction
-       (let ((buffer-read-only nil))
-         (when (gnus-article-narrow-to-signature)
-           (gnus-article-hide-text-type
-            (point-min) (point-max) 'signature))))))
+  (save-excursion
+    (save-restriction
+      (if (interactive-p)
+         (progn
+           (widen)
+           (article-goto-body))
+       (goto-char (point-min)))
+      (unless (gnus-article-check-hidden-text 'signature arg)
+       (let ((buffer-read-only nil)
+             (button (point)))
+         (while (setq button (text-property-any button (point-max)
+                                                'gnus-callback
+                                                'gnus-signature-toggle))
+           (setq button (text-property-not-all button (point-max)
+                                               'gnus-callback
+                                               'gnus-signature-toggle))
+           (when (and button (not (eobp)))
+             (gnus-article-hide-text-type
+              (1+ button)
+              (next-single-property-change (1+ button) 'mime-view-entity
+                                           nil (point-max))
+              'signature)))))))
   (gnus-set-mode-line 'article))
 
 (defun article-strip-headers-in-body ()
@@ -2329,52 +2721,68 @@ how much time has lapsed since DATE.  For `lapsed', the value of
 should replace the \"Date:\" one, or should be added below it."
   (interactive (list 'ut t))
   (let* ((header (or header
+                    (and (eq 1 (point-min))
+                         (mail-header-date (save-excursion
+                                             (set-buffer gnus-summary-buffer)
+                                             gnus-current-headers)))
                     (message-fetch-field "date")
                     ""))
-        (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
-        (date-regexp
-         (cond
-          ((not gnus-article-date-lapsed-new-header)
-           tdate-regexp)
-          ((eq type 'lapsed)
-           "^X-Sent:[ \t]")
-          (t
-           "^Date:[ \t]")))
         (date (if (vectorp header) (mail-header-date header)
                 header))
         (inhibit-point-motion-hooks t)
-        pos
-        bface eface)
-    (save-excursion
-      (save-restriction
-       (article-narrow-to-head)
-       (when (re-search-forward tdate-regexp nil t)
-         (setq bface (get-text-property (gnus-point-at-bol) 'face)
-               date (or (get-text-property (gnus-point-at-bol)
-                                           'original-date)
-                        date)
-               eface (get-text-property (1- (gnus-point-at-eol)) 'face))
-         (forward-line 1))
-       (when (and date (not (string= date "")))
-         (goto-char (point-min))
+        bface eface date-pos)
+    (when (and date (not (string= date "")))
+      (save-excursion
+       (save-restriction
+         (article-narrow-to-head)
+         (when (or (and (eq type 'lapsed)
+                        gnus-article-date-lapsed-new-header
+                        ;; Attempt to get the face of X-Sent first.
+                        (re-search-forward "^X-Sent:[ \t]" nil t))
+                   (re-search-forward "^Date:[ \t]" nil t)
+                   ;; If Date is missing, try again for X-Sent.
+                   (re-search-forward "^X-Sent:[ \t]" nil t))
+           (setq bface (get-text-property (gnus-point-at-bol) 'face)
+                 date (or (get-text-property (gnus-point-at-bol)
+                                             'original-date)
+                          date)
+                 eface (get-text-property (1- (gnus-point-at-eol))
+                                          'face)))
          (let ((buffer-read-only nil))
+           ;; Delete any old X-Sent headers.
+           (when (setq date-pos
+                       (text-property-any (point-min) (point-max)
+                                          'article-date-lapsed t))
+             (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
+             (delete-region (match-beginning 0)
+                            (progn (forward-line 1) (point))))
+           (goto-char (point-min))
            ;; Delete any old Date headers.
-           (while (re-search-forward date-regexp nil t)
-             (if pos
-                 (delete-region (progn (beginning-of-line) (point))
-                                (progn (forward-line 1) (point)))
-               (delete-region (progn (beginning-of-line) (point))
-                              (progn (end-of-line) (point)))
-               (setq pos (point))))
-           (when (and (not pos) (re-search-forward tdate-regexp nil t))
-             (forward-line 1))
-           (if pos (goto-char pos))
-           (insert (article-make-date-line date (or type 'ut)))
-           (when (not pos)
-             (insert "\n")
-             (forward-line -1))
+           (while (re-search-forward "^Date:[ \t]" nil t)
+             (unless date-pos
+               (setq date-pos (match-beginning 0)))
+             (unless (and (eq type 'lapsed)
+                          gnus-article-date-lapsed-new-header)
+               (delete-region (match-beginning 0)
+                              (progn (message-next-header) (point)))))
+           (if date-pos
+               (progn
+                 (goto-char date-pos)
+                 (unless (bolp)
+                   ;; Possibly, Date has been deleted.
+                   (insert "\n"))
+                 (when (and (eq type 'lapsed)
+                            gnus-article-date-lapsed-new-header
+                            (looking-at "Date:"))
+                   (forward-line 1)))
+             (goto-char (point-min)))
+           (insert (article-make-date-line date type))
+           (when (eq type 'lapsed)
+             (put-text-property (gnus-point-at-bol) (point)
+                                'article-date-lapsed t))
+           (insert "\n")
+           (forward-line -1)
            ;; Do highlighting.
-           (beginning-of-line)
            (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
              (put-text-property (match-beginning 1) (1+ (match-end 1))
                                 'original-date date)
@@ -2493,8 +2901,8 @@ should replace the \"Date:\" one, or should be added below it."
             (format "%02d" (nth 2 dtime))
             ":"
             (format "%02d" (nth 1 dtime)))))))
-       (error
-        (format "Date: %s (from Oort)" date))))
+    (error
+     (format "Date: %s (from Oort)" date))))
 
 (defun article-date-local (&optional highlight)
   "Convert the current article date to the local timezone."
@@ -2561,12 +2969,25 @@ This format is defined by the `gnus-article-time-format' variable."
   (interactive (list t))
   (article-date-ut 'iso8601 highlight))
 
-(defun article-show-all ()
-  "Show all hidden text in the article buffer."
+;; (defun article-show-all ()
+;;   "Show all hidden text in the article buffer."
+;;   (interactive)
+;;   (save-excursion
+;;     (widen)
+;;     (let ((buffer-read-only nil))
+;;       (gnus-article-unhide-text (point-min) (point-max))
+;;       (gnus-remove-text-with-property 'gnus-prev)
+;;       (gnus-remove-text-with-property 'gnus-next))))
+
+(defun article-show-all-headers ()
+  "Show all hidden headers in the article buffer."
   (interactive)
   (save-excursion
-    (let ((buffer-read-only nil))
-      (gnus-article-unhide-text (point-min) (point-max)))))
+    (save-restriction
+      (widen)
+      (article-narrow-to-head)
+      (let ((buffer-read-only nil))
+       (gnus-article-unhide-text (point-min) (point-max))))))
 
 (defun article-remove-leading-whitespace ()
   "Remove excessive whitespace from all headers."
@@ -2738,7 +3159,7 @@ This format is defined by the `gnus-article-time-format' variable."
                         (car (push result file-name-history)))))))
               ;; Create the directory.
               (gnus-make-directory (file-name-directory file))
-      ;; If we have read a directory, we append the default file name.
+              ;; If we have read a directory, we append the default file name.
               (when (file-directory-p file)
                 (setq file (expand-file-name (file-name-nondirectory
                                               default-name)
@@ -3036,6 +3457,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is
      article-verify-x-pgp-sig
      article-verify-cancel-lock
      article-hide-boring-headers
+     article-toggle-headers
      article-treat-overstrike
      article-fill-long-lines
      article-capitalize-sentences
@@ -3046,6 +3468,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is
      article-de-base64-unreadable
      article-decode-HZ
      article-wash-html
+     article-unsplit-urls
      article-hide-list-identifiers
      article-hide-pgp
      article-strip-banner
@@ -3060,7 +3483,6 @@ If variable `gnus-use-long-file-name' is non-nil, it is
      article-strip-trailing-space
      article-strip-blank-lines
      article-strip-all-blank-lines
-     article-replace-with-quoted-text
      article-date-local
      article-date-english
      article-date-iso8601
@@ -3074,7 +3496,9 @@ If variable `gnus-use-long-file-name' is non-nil, it is
      article-emphasize
      article-treat-dumbquotes
      article-normalize-headers
-     (article-show-all . gnus-article-show-all-headers))))
+     (article-show-all-headers . gnus-article-show-all-headers)
+;;      (article-show-all . gnus-article-show-all)
+     )))
 \f
 ;;;
 ;;; Gnus article mode
@@ -3082,8 +3506,6 @@ If variable `gnus-use-long-file-name' is non-nil, it is
 
 (put 'gnus-article-mode 'mode-class 'special)
 
-(set-keymap-parent gnus-article-mode-map widget-keymap)
-
 (gnus-define-keys gnus-article-mode-map
   " " gnus-article-goto-next-page
   "\177" gnus-article-goto-prev-page
@@ -3099,6 +3521,8 @@ If variable `gnus-use-long-file-name' is non-nil, it is
   ">" end-of-buffer
   "\C-c\C-i" gnus-info-find-node
   "\C-c\C-b" gnus-bug
+  "R" gnus-article-reply-with-original
+  "F" gnus-article-followup-with-original
   "\C-hk" gnus-article-describe-key
   "\C-hc" gnus-article-describe-key-briefly
 
@@ -3108,8 +3532,21 @@ If variable `gnus-use-long-file-name' is non-nil, it is
   "\M-^" gnus-article-read-summary-keys
   "\M-g" gnus-article-read-summary-keys)
 
-(substitute-key-definition
- 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
+;; Define almost undefined keys to `gnus-article-read-summary-keys'.
+(let (keys)
+  (let ((key 32))
+    (while (<= key 127)
+      (push (char-to-string key) keys)
+      (incf key))
+    (dolist (elem (accessible-keymaps gnus-summary-mode-map))
+      (setq key (car elem))
+      (when (and (> (length key) 0)
+                (not (eq 'menu-bar (aref key 0)))
+                (symbolp (lookup-key gnus-summary-mode-map key)))
+       (push key keys))))
+  (dolist (key keys)
+    (unless (lookup-key gnus-article-mode-map key)
+      (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
 
 (defun gnus-article-make-menu-bar ()
   (unless (boundp 'gnus-article-commands-menu)
@@ -3130,15 +3567,14 @@ If variable `gnus-use-long-file-name' is non-nil, it is
      gnus-article-treatment-menu gnus-article-mode-map ""
      ;; Fixme: this should use :active (and maybe :visible).
      '("Treatment"
-       ["Hide headers" gnus-article-hide-headers t]
+       ["Hide headers" gnus-article-toggle-headers t]
        ["Hide signature" gnus-article-hide-signature t]
        ["Hide citation" gnus-article-hide-citation t]
        ["Treat overstrike" gnus-article-treat-overstrike t]
        ["Remove carriage return" gnus-article-remove-cr t]
        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
-       ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
-       ["Remove base64" gnus-article-de-base64-unreadable t]
        ["Treat html" gnus-article-wash-html t]
+       ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
        ["Decode HZ" gnus-article-decode-HZ t]))
 
     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
@@ -3170,6 +3606,8 @@ commands:
   (setq mode-name "Article")
   (setq major-mode 'gnus-article-mode)
   (make-local-variable 'minor-mode-alist)
+  (unless (assq 'gnus-show-mime minor-mode-alist)
+    (push (list 'gnus-show-mime " MIME") minor-mode-alist))
   (use-local-map gnus-article-mode-map)
   (when (gnus-visual-p 'article-menu 'menu)
     (gnus-article-make-menu-bar))
@@ -3189,7 +3627,6 @@ commands:
   (buffer-disable-undo)
   (setq buffer-read-only t)
   (set-syntax-table gnus-article-mode-syntax-table)
-  (mm-enable-multibyte)
   (gnus-run-hooks 'gnus-article-mode-hook))
 
 (defun gnus-article-setup-buffer ()
@@ -3214,17 +3651,12 @@ commands:
     ;; Init original article buffer.
     (save-excursion
       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
-      (mm-enable-multibyte)
+      (set-buffer-multibyte t)
       (setq major-mode 'gnus-original-article-mode)
       (make-local-variable 'gnus-original-article))
     (if (get-buffer name)
        (save-excursion
          (set-buffer name)
-         (when gnus-article-mime-handles
-           (mm-destroy-parts gnus-article-mime-handles)
-           (setq gnus-article-mime-handles nil))
-         ;; Set it to nil in article-buffer!
-         (setq gnus-article-mime-handle-alist nil)
          (buffer-disable-undo)
          (setq buffer-read-only t)
          (unless (eq major-mode 'gnus-article-mode)
@@ -3252,6 +3684,66 @@ commands:
        (forward-line line)
        (point)))))
 
+;;; @@ article filters
+;;;
+
+(defun gnus-article-display-mime-message ()
+  "Article display method for MIME message."
+  ;; called from `gnus-original-article-buffer'.
+  (let (charset all-headers)
+    (with-current-buffer gnus-summary-buffer
+      (setq charset default-mime-charset
+           all-headers gnus-have-all-headers))
+    (make-local-variable 'default-mime-charset)
+    (setq default-mime-charset charset)
+    (with-current-buffer (get-buffer-create gnus-article-buffer)
+      (make-local-variable 'default-mime-charset)
+      (setq default-mime-charset charset))
+    (mime-display-message mime-message-structure
+                         gnus-article-buffer nil gnus-article-mode-map)
+    (when all-headers
+      (gnus-article-hide-headers nil -1)))
+  (run-hooks 'gnus-mime-article-prepare-hook))
+
+(defun gnus-article-display-traditional-message ()
+  "Article display method for traditional message."
+  (set-buffer gnus-article-buffer)
+  (let (buffer-read-only)
+    (erase-buffer)
+    (insert-buffer-substring gnus-original-article-buffer)))
+
+(defun gnus-article-make-full-mail-header (&optional number charset)
+  "Create a new mail header structure in a raw article buffer."
+  (unless (and number charset)
+    (save-current-buffer
+      (set-buffer gnus-summary-buffer)
+      (unless number
+       (setq number (or (cdr gnus-article-current) 0)))
+      (unless charset
+       (setq charset (or default-mime-charset 'x-ctext)))))
+  (goto-char (point-min))
+  (let ((header-end (if (search-forward "\n\n" nil t)
+                       (1- (point))
+                     (goto-char (point-max))))
+       (chars (- (point-max) (point)))
+       (lines (count-lines (point) (point-max)))
+       (default-mime-charset charset)
+       xref)
+    (narrow-to-region (point-min) header-end)
+    (setq xref (std11-fetch-field "xref"))
+    (prog1
+       (make-full-mail-header
+        number
+        (std11-fetch-field "subject")
+        (std11-fetch-field "from")
+        (std11-fetch-field "date")
+        (std11-fetch-field "message-id")
+        (std11-fetch-field "references")
+        chars
+        lines
+        (when xref (concat "Xref: " xref)))
+      (widen))))
+
 (defun gnus-article-prepare (article &optional all-headers header)
   "Prepare ARTICLE in article mode buffer.
 ARTICLE should either be an article number or a Message-ID.
@@ -3361,36 +3853,152 @@ If ALL-HEADERS is non-nil, no headers are hidden."
            (gnus-configure-windows 'article)
            t))))))
 
+(defun gnus-article-prepare-mime-display (&optional number)
+  (goto-char (point-min))
+  (when (re-search-forward "^[^\t ]+:" nil t)
+    (goto-char (match-beginning 0)))
+  (let ((entity (if (eq 1 (point-min))
+                   (get-text-property 1 'mime-view-entity)
+                 (get-text-property (point) 'mime-view-entity)))
+       last-entity child-entity next type)
+    (setq child-entity (mime-entity-children entity))
+    (if child-entity
+       (setq last-entity (nth (1- (length child-entity))
+                              child-entity))
+      (setq last-entity entity))
+    (save-restriction
+      (narrow-to-region (point)
+                       (if (search-forward "\n\n" nil t)
+                           (point)
+                         (point-max)))
+      (gnus-treat-article 'head)
+      (put-text-property (point-min) (point-max) 'article-treated-header t)
+      (goto-char (point-max)))
+    (while (and (not (eobp)) entity)
+      (setq next (set-marker
+                 (make-marker)
+                 (next-single-property-change (point) 'mime-view-entity
+                                              nil (point-max))))
+      (let ((types (mime-entity-content-type entity)))
+       (while (eq 'multipart (mime-content-type-primary-type types))
+         (setq entity (car (mime-entity-children entity))
+               types (mime-entity-content-type entity)))
+       (when types
+         (setq type (format "%s/%s"
+                            (mime-content-type-primary-type types)
+                            (mime-content-type-subtype types)))))
+      (if (string-equal type "message/rfc822")
+         (progn
+           (setq next (point))
+           (let ((children (mime-entity-children entity))
+                 last-children)
+             (when children
+               (setq last-children (nth (1- (length children)) children))
+               (while
+                   (and
+                    (not (eq last-children
+                             (get-text-property next 'mime-view-entity)))
+                    (setq next
+                          (next-single-property-change next
+                                                       'mime-view-entity
+                                                       nil (point-max)))))))
+           (setq next (next-single-property-change next 'mime-view-entity
+                                                   nil (point-max)))
+           (save-restriction
+             (narrow-to-region (point) next)
+             (gnus-article-prepare-mime-display)
+             (goto-char (point-max)))
+           (setq entity (get-text-property (point) 'mime-view-entity)))
+       (save-restriction
+         (narrow-to-region (point) next)
+         ;; Kludge. We have to count true number, but for now,
+         ;; part number is here only to achieve `last'.
+         (gnus-treat-article nil 1
+                             (if (eq entity last-entity)
+                                 1 2)
+                             type)
+         (goto-char (point-max)))
+       (setq entity (get-text-property next 'mime-view-entity))))))
+
 ;;;###autoload
 (defun gnus-article-prepare-display ()
   "Make the current buffer look like a nice article."
-  ;; Hooks for getting information from the article.
-  ;; This hook must be called before being narrowed.
   (let ((gnus-article-buffer (current-buffer))
        buffer-read-only)
     (unless (eq major-mode 'gnus-article-mode)
       (gnus-article-mode))
     (setq buffer-read-only nil
+         gnus-button-marker-list nil
          gnus-article-wash-types nil
          gnus-article-image-alist nil)
-    (gnus-run-hooks 'gnus-tmp-internal-hook)
-    (when gnus-display-mime-function
-      (funcall gnus-display-mime-function))
-    (gnus-run-hooks 'gnus-article-prepare-hook)))
+    (save-restriction
+      (widen)
+      (static-if (featurep 'xemacs)
+         (map-extents (lambda (extent maparg) (delete-extent extent)))
+       (let ((lists (overlay-lists)))
+         (dolist (overlay (nconc (car lists) (cdr lists)))
+           (delete-overlay overlay)))))
+    (gnus-run-hooks 'gnus-tmp-internal-hook))
+  (set-buffer gnus-original-article-buffer)
+  ;; Display message.
+  (setq mime-message-structure gnus-current-headers)
+  (mime-buffer-entity-set-buffer-internal mime-message-structure
+                                         gnus-original-article-buffer)
+  (mime-entity-set-representation-type-internal mime-message-structure
+                                               'mime-buffer-entity)
+  (luna-send mime-message-structure 'initialize-instance
+            mime-message-structure)
+  (if gnus-show-mime
+      (let (mime-display-header-hook mime-display-text/plain-hook)
+       (funcall gnus-article-display-method-for-mime))
+    (funcall gnus-article-display-method-for-traditional))
+  ;; Call the treatment functions.
+  (let ((inhibit-read-only t))
+    (save-restriction
+      (widen)
+      (if gnus-show-mime
+         (gnus-article-prepare-mime-display)
+       (narrow-to-region (goto-char (point-min))
+                         (if (search-forward "\n\n" nil t)
+                             (point)
+                           (point-max)))
+       (gnus-treat-article 'head)
+       (put-text-property (point-min) (point-max) 'article-treated-header t)
+       (goto-char (point-max))
+       (widen)
+       (narrow-to-region (point) (point-max))
+       (gnus-treat-article nil))
+      (put-text-property (point-min) (point-max) 'read-only nil)))
+  (gnus-run-hooks 'gnus-article-prepare-hook))
+
+(defun gnus-article-decode-article-as-default-mime-charset ()
+  "Decode an article as `default-mime-charset'.  It won't work if the
+value of the variable `gnus-show-mime' is non-nil."
+  (unless gnus-show-mime
+    (set (make-local-variable 'default-mime-charset)
+        (with-current-buffer gnus-summary-buffer
+          default-mime-charset))
+    (decode-mime-charset-region (point-min) (point-max)
+                               default-mime-charset)))
 
 ;;;
 ;;; Gnus MIME viewing functions
 ;;;
 
 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
-  "The following specs can be used:
+  "Format of the MIME buttons.
+
+Valid specifiers include:
 %t  The MIME type
 %T  MIME type, along with additional info
 %n  The `name' parameter
 %d  The description, if any
 %l  The length of the encoded part
 %p  The part identifier number
-%e  Dots if the part isn't displayed")
+%e  Dots if the part isn't displayed
+
+General format specifiers can also be used.  See
+(gnus)Formatting Variables.")
 
 (defvar gnus-mime-button-line-format-alist
   '((?t gnus-tmp-type ?s)
@@ -3417,11 +4025,16 @@ If ALL-HEADERS is non-nil, no headers are hidden."
     (gnus-mime-action-on-part "." "Take action on the part")))
 
 (defun gnus-article-mime-part-status ()
-  (if gnus-article-mime-handle-alist-1
-      (if (eq 1 (length gnus-article-mime-handle-alist-1))
-         " (1 part)"
-       (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
-    ""))
+  (with-current-buffer gnus-article-buffer
+    (let ((entity (get-text-property (point-min) 'mime-view-entity))
+         children)
+      (if (and entity
+              (setq children (mime-entity-children entity))
+              (setq children (length children)))
+         (if (eq 1 children)
+             " (1 part)"
+           (format " (%d parts)" children))
+       ""))))
 
 (defvar gnus-mime-button-map
   (let ((map (make-sparse-keymap)))
@@ -3496,24 +4109,24 @@ If ALL-HEADERS is non-nil, no headers are hidden."
       (set-buffer gnus-summary-buffer)
       (gnus-article-edit-article
        `(lambda ()
-          (erase-buffer)
-          (let ((mail-parse-charset (or gnus-article-charset
-                                        ',gnus-newsgroup-charset))
-                (mail-parse-ignored-charsets
-                 (or gnus-article-ignored-charsets
-                     ',gnus-newsgroup-ignored-charsets))
-                (mbl mml-buffer-list))
-            (setq mml-buffer-list nil)
-            (insert-buffer gnus-original-article-buffer)
-            (mime-to-mml ',handles)
-            (setq gnus-article-mime-handles nil)
-            (let ((mbl1 mml-buffer-list))
-              (setq mml-buffer-list mbl)
-              (set (make-local-variable 'mml-buffer-list) mbl1))
-            ;; LOCAL argument of add-hook differs between GNU Emacs
-            ;; and XEmacs. make-local-hook makes sure they are local.
-            (make-local-hook 'kill-buffer-hook)
-            (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
+         (erase-buffer)
+         (let ((mail-parse-charset (or gnus-article-charset
+                                       ',gnus-newsgroup-charset))
+               (mail-parse-ignored-charsets
+                (or gnus-article-ignored-charsets
+                    ',gnus-newsgroup-ignored-charsets))
+               (mbl mml-buffer-list))
+           (setq mml-buffer-list nil)
+           (insert-buffer gnus-original-article-buffer)
+           (mime-to-mml ',handles)
+           (setq gnus-article-mime-handles nil)
+           (let ((mbl1 mml-buffer-list))
+             (setq mml-buffer-list mbl)
+             (set (make-local-variable 'mml-buffer-list) mbl1))
+           ;; LOCAL argument of add-hook differs between GNU Emacs
+           ;; and XEmacs. make-local-hook makes sure they are local.
+           (make-local-hook 'kill-buffer-hook)
+           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
        `(lambda (no-highlight)
          (let ((mail-parse-charset (or gnus-article-charset
                                        ',gnus-newsgroup-charset))
@@ -3522,11 +4135,11 @@ If ALL-HEADERS is non-nil, no headers are hidden."
                (mail-parse-ignored-charsets
                 (or gnus-article-ignored-charsets
                     ',gnus-newsgroup-ignored-charsets)))
-          (mml-to-mime)
-          (mml-destroy-buffers)
-          (remove-hook 'kill-buffer-hook
-                       'mml-destroy-buffers t)
-          (kill-local-variable 'mml-buffer-list))
+           (mml-to-mime)
+           (mml-destroy-buffers)
+           (remove-hook 'kill-buffer-hook
+                        'mml-destroy-buffers t)
+           (kill-local-variable 'mml-buffer-list))
          (gnus-summary-edit-article-done
           ,(or (mail-header-references gnus-current-headers) "")
           ,(gnus-group-read-only-p)
@@ -3617,9 +4230,9 @@ If ALL-HEADERS is non-nil, no headers are hidden."
        (setq buffer-file-name nil))
       (goto-char (point-min)))))
 
-(defun gnus-mime-print-part (&optional handle)
+(defun gnus-mime-print-part (&optional handle filename)
   "Print the MIME part under point."
-  (interactive)
+  (interactive (list nil (ps-print-preprint current-prefix-arg)))
   (gnus-article-check-buffer)
   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
         (contents (and handle (mm-get-part handle)))
@@ -3640,7 +4253,8 @@ If ALL-HEADERS is non-nil, no headers are hidden."
              (delete-file file))
          (with-temp-buffer
            (insert contents)
-           (gnus-print-buffer))))))
+           (gnus-print-buffer))
+         (ps-despool filename)))))
 
 (defun gnus-mime-inline-part (&optional handle arg)
   "Insert the MIME part under point into the current buffer."
@@ -3692,7 +4306,7 @@ specified charset."
             (or (cdr (assq arg
                            gnus-summary-show-article-charset-alist))
                 (mm-read-coding-system "Charset: ")))
-         (gnus-newsgroup-ignored-charsets 'gnus-all))
+           (gnus-newsgroup-ignored-charsets 'gnus-all))
        (gnus-article-press-button)))))
 
 (defun gnus-mime-externalize-part (&optional handle)
@@ -3832,8 +4446,11 @@ If no internal viewer is available, use an external viewer."
        (let ((window (selected-window))
              (mail-parse-charset gnus-newsgroup-charset)
              (mail-parse-ignored-charsets
-              (save-excursion (set-buffer gnus-summary-buffer)
-                              gnus-newsgroup-ignored-charsets)))
+              (if (gnus-buffer-live-p gnus-summary-buffer)
+                  (save-excursion
+                    (set-buffer gnus-summary-buffer)
+                    gnus-newsgroup-ignored-charsets)
+                nil)))
          (save-excursion
            (unwind-protect
                (let ((win (gnus-get-buffer-window (current-buffer) t))
@@ -3901,14 +4518,11 @@ If no internal viewer is available, use an external viewer."
     (setq b (point))
     (gnus-eval-format
      gnus-mime-button-line-format gnus-mime-button-line-format-alist
-     `(keymap ,gnus-mime-button-map
-             ,@(if (>= (string-to-number emacs-version) 21)
-                   nil
-                 (list 'local-map gnus-mime-button-map))
-             gnus-callback gnus-mm-display-part
-             gnus-part ,gnus-tmp-id
-             article-type annotation
-             gnus-data ,handle))
+     `(,@(gnus-local-map-property gnus-mime-button-map)
+        gnus-callback gnus-mm-display-part
+        gnus-part ,gnus-tmp-id
+        article-type annotation
+        gnus-data ,handle))
     (setq e (point))
     (widget-convert-button
      'link b e
@@ -3952,7 +4566,9 @@ If no internal viewer is available, use an external viewer."
          ;; We have to do this since selecting the window
          ;; may change the point.  So we set the window point.
          (set-window-point window point)))
-      (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
+      (let* ((handles (or ihandles (mm-dissect-buffer
+                                   gnus-article-no-strict-mime)
+                         (mm-uu-dissect)))
             buffer-read-only handle name type b e display)
        (when (and (not ihandles)
                   (not gnus-displaying-mime))
@@ -4161,12 +4777,9 @@ If no internal viewer is available, use an external viewer."
                       ',gnus-article-mime-handle-alist))
               (gnus-mime-display-alternative
                ',ihandles ',not-pref ',begend ,id))
-            ,@(if (>= (string-to-number emacs-version) 21)
-                  nil ;; XEmacs doesn't care
-                (list 'local-map gnus-mime-button-map))
+            ,@(gnus-local-map-property gnus-mime-button-map)
             ,gnus-mouse-face-prop ,gnus-article-mouse-face
             face ,gnus-article-button-face
-            keymap ,gnus-mime-button-map
             gnus-part ,id
             gnus-data ,handle))
          (widget-convert-button 'link from (point)
@@ -4188,12 +4801,9 @@ If no internal viewer is available, use an external viewer."
                         ',gnus-article-mime-handle-alist))
                 (gnus-mime-display-alternative
                  ',ihandles ',handle ',begend ,id))
-              ,@(if (>= (string-to-number emacs-version) 21)
-                    nil ;; XEmacs doesn't care
-                  (list 'local-map gnus-mime-button-map))
+              ,@(gnus-local-map-property gnus-mime-button-map)
               ,gnus-mouse-face-prop ,gnus-article-mouse-face
               face ,gnus-article-button-face
-              keymap ,gnus-mime-button-map
               gnus-part ,id
               gnus-data ,handle))
            (widget-convert-button 'link from (point)
@@ -4233,6 +4843,8 @@ If no internal viewer is available, use an external viewer."
                            " " "Signature is visible")
                 (overstrike "o" "Overstrike (^H) characters applied"
                             " " "No overstrike characters applied")
+                (gnus-show-mime "m" "Mime processing is activated"
+                                " " "Mime processing is not activated")
                 (emphasis "e" "/*_Emphasis_*/ characters applied"
                           " " "No /*_emphasis_*/ characters applied")))
        result)
@@ -4275,11 +4887,12 @@ is the string to use when it is inactive.")
        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
        (gnus-article-wash-status-entry 'signature signature)
        (gnus-article-wash-status-entry 'overstrike overstrike)
+       (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
        (gnus-article-wash-status-entry 'emphasis emphasis)))))
 
 (defun gnus-add-wash-type (type)
   "Add a washing of TYPE to the current status."
-  (push type gnus-article-wash-types))
+  (add-to-list 'gnus-article-wash-types type))
 
 (defun gnus-delete-wash-type (type)
   "Add a washing of TYPE to the current status."
@@ -4323,8 +4936,9 @@ Provided for backwards compatibility."
       ;; save it to file.
       (goto-char (point-max))
       (insert "\n")
-      (let ((file-name-coding-system nnmail-pathname-coding-system))
-       (mm-append-to-file (point-min) (point-max) file-name))
+      (let ((file-name-coding-system nnmail-pathname-coding-system)
+           (pathname-coding-system nnmail-pathname-coding-system))
+       (write-region-as-binary (point-min) (point-max) file-name 'append))
       t)))
 
 (defun gnus-narrow-to-page (&optional arg)
@@ -4383,48 +4997,56 @@ If given a numerical ARG, move forward ARG pages."
 If end of article, return non-nil.  Otherwise return nil.
 Argument LINES specifies lines to be scrolled up."
   (interactive "p")
-  (move-to-window-line -1)
-  (if (save-excursion
-       (end-of-line)
-       (and (pos-visible-in-window-p)  ;Not continuation line.
-            (eobp)))
-      ;; Nothing in this page.
-      (if (or (not gnus-page-broken)
-             (save-excursion
-               (save-restriction
-                 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
-         t                             ;Nothing more.
-       (gnus-narrow-to-page 1)         ;Go to next page.
-       nil)
-    ;; More in this page.
-    (let ((scroll-in-place nil))
-      (condition-case ()
-         (scroll-up lines)
-       (end-of-buffer
-        ;; Long lines may cause an end-of-buffer error.
-        (goto-char (point-max)))))
-    (move-to-window-line 0)
-    nil))
+  (let ((start (window-start))
+       end-of-buffer end-of-page)
+    (save-excursion
+      (move-to-window-line -1)
+      (if (<= (point) start)
+         (progn
+           (forward-line 2)
+           (setq start (point)))
+       (forward-line 1)
+       (setq start nil))
+      (unless (or (cond ((eq (1+ (buffer-size)) (point))
+                        (and (pos-visible-in-window-p)
+                             (setq end-of-buffer t)))
+                       ((eobp)
+                        (setq end-of-page t)))
+                 (not lines))
+       (move-to-window-line lines)
+       (unless (search-backward "\n\n" nil t)
+         (setq start (point)))))
+    (cond (end-of-buffer t)
+         (end-of-page
+          (gnus-narrow-to-page 1)
+          nil)
+         (t
+          (if start
+              (set-window-start (selected-window) start)
+            (let (window-pixel-scroll-increment)
+              (scroll-up lines)))
+          nil))))
 
 (defun gnus-article-prev-page (&optional lines)
   "Show previous page of current article.
 Argument LINES specifies lines to be scrolled down."
   (interactive "p")
-  (move-to-window-line 0)
-  (if (and gnus-page-broken
-          (bobp)
-          (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
-      (progn
-       (gnus-narrow-to-page -1)        ;Go to previous page.
-       (goto-char (point-max))
-       (recenter -1))
-    (let ((scroll-in-place nil))
-      (prog1
-         (condition-case ()
-             (scroll-down lines)
-           (beginning-of-buffer
-            (goto-char (point-min))))
-       (move-to-window-line 0)))))
+  (let (beginning-of-buffer beginning-of-page)
+    (save-excursion
+      (move-to-window-line 0)
+      (cond ((eq 1 (point))
+            (setq beginning-of-buffer t))
+           ((bobp)
+            (setq beginning-of-page t))))
+    (cond (beginning-of-buffer)
+         (beginning-of-page
+          (gnus-narrow-to-page -1))
+         (t
+          (condition-case nil
+              (let (window-pixel-scroll-increment)
+                (scroll-down lines))
+            (beginning-of-buffer
+             (goto-char (point-min))))))))
 
 (defun gnus-article-refer-article ()
   "Read article specified by message-id around point."
@@ -4477,7 +5099,7 @@ Argument LINES specifies lines to be scrolled down."
 
 (defun gnus-article-check-buffer ()
   "Beep if not in an article buffer."
-  (unless (equal major-mode 'gnus-article-mode)
+  (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
     (error "Command invoked outside of a Gnus article buffer")))
 
 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
@@ -4485,8 +5107,8 @@ Argument LINES specifies lines to be scrolled down."
   (interactive "P")
   (gnus-article-check-buffer)
   (let ((nosaves
-        '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
-          "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
+        '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
+          "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
           "=" "^" "\M-^" "|"))
        (nosave-but-article
         '("A\r"))
@@ -4499,10 +5121,9 @@ Argument LINES specifies lines to be scrolled down."
       (set-buffer gnus-article-current-summary)
       (let (gnus-pick-mode)
        (push (or key last-command-event) unread-command-events)
-       (setq keys (if (featurep 'xemacs)
+       (setq keys (static-if (featurep 'xemacs)
                       (events-to-keys (read-key-sequence nil))
                     (read-key-sequence nil)))))
-
     (message "")
 
     (if (or (member keys nosaves)
@@ -4573,7 +5194,7 @@ Argument LINES specifies lines to be scrolled down."
            (setq unread-command-events
                  (mapcar
                   (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
-                  (string-to-list key)))
+                  key))
            (setq key (read-key-sequence "Describe key: "))))
        (describe-key key))
     (describe-key key)))
@@ -4594,11 +5215,44 @@ Argument LINES specifies lines to be scrolled down."
            (setq unread-command-events
                  (mapcar
                   (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
-                  (string-to-list key)))
+                  key))
            (setq key (read-key-sequence "Describe key: "))))
        (describe-key-briefly key insert))
     (describe-key-briefly key insert)))
 
+(defun gnus-article-reply-with-original (&optional wide)
+  "Start composing a reply mail to the current message.
+The text in the region will be yanked.  If the region isn't active,
+the entire article will be yanked."
+  (interactive "P")
+  (let ((article (cdr gnus-article-current)) cont)
+    (if (not (mark t))
+       (gnus-summary-reply (list (list article)) wide)
+      (setq cont (buffer-substring (point) (mark t)))
+      ;; Deactivate active regions.
+      (when (and (boundp 'transient-mark-mode)
+                transient-mark-mode)
+       (setq mark-active nil))
+      (gnus-summary-reply
+       (list (list article cont)) wide))))
+
+(defun gnus-article-followup-with-original ()
+  "Compose a followup to the current article.
+The text in the region will be yanked.  If the region isn't active,
+the entire article will be yanked."
+  (interactive)
+  (let ((article (cdr gnus-article-current))
+       cont)
+    (if (not (mark t))
+       (gnus-summary-followup (list (list article)))
+      (setq cont (buffer-substring (point) (mark t)))
+      ;; Deactivate active regions.
+      (when (and (boundp 'transient-mark-mode)
+                transient-mark-mode)
+       (setq mark-active nil))
+      (gnus-summary-followup
+       (list (list article cont))))))
+
 (defun gnus-article-hide (&optional arg force)
   "Hide all the gruft in the current article.
 This means that PGP stuff, signatures, cited text and (some)
@@ -4623,9 +5277,14 @@ If given a prefix, show the hidden text instead."
     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
     (gnus-request-group gnus-newsgroup-name t)))
 
+(eval-when-compile
+  (autoload 'nneething-get-file-name "nneething"))
+
 (defun gnus-request-article-this-buffer (article group)
-  "Get an article and insert it into this buffer."
+  "Get an article and insert it into this buffer.
+T-gnus change: Insert an article into `gnus-original-article-buffer'."
   (let (do-update-line sparse-header)
+    ;; The current buffer is `gnus-article-buffer'.
     (prog1
        (save-excursion
          (erase-buffer)
@@ -4672,14 +5331,22 @@ If given a prefix, show the hidden text instead."
                               gnus-newsgroup-name)))
                  (when (and (eq (car method) 'nneething)
                             (vectorp header))
-                   (let ((dir (expand-file-name
-                               (mail-header-subject header)
-                               (file-name-as-directory
-                                (or (cadr (assq 'nneething-address method))
-                                    (nth 1 method))))))
-                     (when (file-directory-p dir)
+                   (let ((dir (nneething-get-file-name
+                               (mail-header-id header))))
+                     (when (and (stringp dir)
+                                (file-directory-p dir))
                        (setq article 'nneething)
                        (gnus-group-enter-directory dir))))))))
+         (setq gnus-original-article (cons group article))
+
+         ;; The current buffer is `gnus-original-article-buffer'.
+         (if (get-buffer gnus-original-article-buffer)
+             (set-buffer gnus-original-article-buffer)
+           (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
+           (set-buffer-multibyte nil)
+           (buffer-disable-undo)
+           (setq major-mode 'gnus-original-article-mode)
+           (setq buffer-read-only nil))
 
          (cond
           ;; Refuse to select canceled articles.
@@ -4692,15 +5359,6 @@ If given a prefix, show the hidden text instead."
                            (assq article gnus-newsgroup-reads)))
                     gnus-canceled-mark))
            nil)
-          ;; We first check `gnus-original-article-buffer'.
-          ((and (get-buffer gnus-original-article-buffer)
-                (numberp article)
-                (save-excursion
-                  (set-buffer gnus-original-article-buffer)
-                  (and (equal (car gnus-original-article) group)
-                       (eq (cdr gnus-original-article) article))))
-           (insert-buffer-substring gnus-original-article-buffer)
-           'article)
           ;; Check the backlog.
           ((and gnus-keep-backlog
                 (gnus-backlog-request-article group article (current-buffer)))
@@ -4716,6 +5374,11 @@ If given a prefix, show the hidden text instead."
                 (numberp article)
                 (gnus-cache-request-article article group))
            'article)
+          ;; Check the agent cache.
+          ((and gnus-agent gnus-agent-cache gnus-plugged
+                (numberp article)
+                (gnus-agent-request-article article group))
+           'article)
           ;; Get the article and put into the article buffer.
           ((or (stringp article)
                (numberp article))
@@ -4759,27 +5422,15 @@ If given a prefix, show the hidden text instead."
       ;; Associate this article with the current summary buffer.
       (setq gnus-article-current-summary gnus-summary-buffer)
 
-      ;; Take the article from the original article buffer
-      ;; and place it in the buffer it's supposed to be in.
-      (when (and (get-buffer gnus-article-buffer)
-                (equal (buffer-name (current-buffer))
-                       (buffer-name (get-buffer gnus-article-buffer))))
-       (save-excursion
-         (if (get-buffer gnus-original-article-buffer)
-             (set-buffer gnus-original-article-buffer)
-           (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
-           (buffer-disable-undo)
-           (setq major-mode 'gnus-original-article-mode)
-           (setq buffer-read-only t))
-         (let (buffer-read-only)
-           (erase-buffer)
-           (insert-buffer-substring gnus-article-buffer))
-         (setq gnus-original-article (cons group article)))
+      ;; Copy the requested article from `gnus-original-article-buffer'.
+      (unless (equal (buffer-name (current-buffer))
+                    (buffer-name (get-buffer gnus-original-article-buffer)))
+       (insert-buffer gnus-original-article-buffer))
 
-       ;; Decode charsets.
-       (run-hooks 'gnus-article-decode-hook)
-       ;; Mark article as decoded or not.
-       (setq gnus-article-decoded-p gnus-article-decode-hook))
+      ;; Decode charsets.
+      (run-hooks 'gnus-article-decode-hook)
+      ;; Mark article as decoded or not.
+      (setq gnus-article-decoded-p gnus-article-decode-hook)
 
       ;; Update sparse articles.
       (when (and do-update-line
@@ -4802,23 +5453,79 @@ If given a prefix, show the hidden text instead."
   :group 'gnus-article-various
   :type 'hook)
 
+(defcustom gnus-article-edit-article-setup-function
+  'gnus-article-mime-edit-article-setup
+  "Function called to setup an editing article buffer."
+  :group 'gnus-article-various
+  :type 'function)
+
 (defvar gnus-article-edit-done-function nil)
 
 (defvar gnus-article-edit-mode-map nil)
 
 ;; Should we be using derived.el for this?
 (unless gnus-article-edit-mode-map
-  (setq gnus-article-edit-mode-map (make-sparse-keymap))
+  (setq gnus-article-edit-mode-map (make-keymap))
   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
 
   (gnus-define-keys gnus-article-edit-mode-map
+    "\C-c?"    describe-mode
     "\C-c\C-c" gnus-article-edit-done
-    "\C-c\C-k" gnus-article-edit-exit)
+    "\C-c\C-k" gnus-article-edit-exit
+    "\C-c\C-f\C-t" message-goto-to
+    "\C-c\C-f\C-o" message-goto-from
+    "\C-c\C-f\C-b" message-goto-bcc
+    ;;"\C-c\C-f\C-w" message-goto-fcc
+    "\C-c\C-f\C-c" message-goto-cc
+    "\C-c\C-f\C-s" message-goto-subject
+    "\C-c\C-f\C-r" message-goto-reply-to
+    "\C-c\C-f\C-n" message-goto-newsgroups
+    "\C-c\C-f\C-d" message-goto-distribution
+    "\C-c\C-f\C-f" message-goto-followup-to
+    "\C-c\C-f\C-m" message-goto-mail-followup-to
+    "\C-c\C-f\C-k" message-goto-keywords
+    "\C-c\C-f\C-u" message-goto-summary
+    "\C-c\C-f\C-i" message-insert-or-toggle-importance
+    "\C-c\C-f\C-a" message-gen-unsubscribed-mft
+    "\C-c\C-b" message-goto-body
+    "\C-c\C-i" message-goto-signature
+
+    "\C-c\C-t" message-insert-to
+    "\C-c\C-n" message-insert-newsgroups
+    "\C-c\C-o" message-sort-headers
+    "\C-c\C-e" message-elide-region
+    "\C-c\C-v" message-delete-not-region
+    "\C-c\C-z" message-kill-to-signature
+    "\M-\r" message-newline-and-reformat
+    "\C-c\C-a" mml-attach-file
+    "\C-a" message-beginning-of-line
+    "\t" message-tab
+    "\M-;" comment-region)
 
   (gnus-define-keys (gnus-article-edit-wash-map
                     "\C-c\C-w" gnus-article-edit-mode-map)
     "f" gnus-article-edit-full-stops))
 
+(easy-menu-define
+  gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
+  '("Field"
+    ["Fetch To" message-insert-to t]
+    ["Fetch Newsgroups" message-insert-newsgroups t]
+    "----"
+    ["To" message-goto-to t]
+    ["From" message-goto-from t]
+    ["Subject" message-goto-subject t]
+    ["Cc" message-goto-cc t]
+    ["Reply-To" message-goto-reply-to t]
+    ["Summary" message-goto-summary t]
+    ["Keywords" message-goto-keywords t]
+    ["Newsgroups" message-goto-newsgroups t]
+    ["Followup-To" message-goto-followup-to t]
+    ["Mail-Followup-To" message-goto-mail-followup-to t]
+    ["Distribution" message-goto-distribution t]
+    ["Body" message-goto-body t]
+    ["Signature" message-goto-signature t]))
+
 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
   "Major mode for editing articles.
 This is an extended text-mode.
@@ -4828,6 +5535,9 @@ This is an extended text-mode.
   (make-local-variable 'gnus-prev-winconf)
   (set (make-local-variable 'font-lock-defaults)
        '(message-font-lock-keywords t))
+  (set (make-local-variable 'mail-header-separator) "")
+  (easy-menu-add message-mode-field-menu message-mode-map)
+  (mml-mode)
   (setq buffer-read-only nil)
   (buffer-enable-undo)
   (widen))
@@ -4860,44 +5570,39 @@ groups."
     (gnus-configure-windows 'edit-article)
     (setq gnus-article-edit-done-function exit-func)
     (setq gnus-prev-winconf winconf)
-    (gnus-message 6 "C-c C-c to end edits")))
+    (when gnus-article-edit-article-setup-function
+      (funcall gnus-article-edit-article-setup-function))
+    (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
 
 (defun gnus-article-edit-done (&optional arg)
   "Update the article edits and exit."
   (interactive "P")
   (let ((func gnus-article-edit-done-function)
        (buf (current-buffer))
-       (start (window-start)))
-    ;; We remove all text props from the article buffer.
-    (let ((content
-          (buffer-substring-no-properties (point-min) (point-max)))
-         (p (point)))
-      (erase-buffer)
-      (insert content)
-      (let ((winconf gnus-prev-winconf))
-       (gnus-article-mode)
-       (set-window-configuration winconf)
-       ;; Tippy-toe some to make sure that point remains where it was.
-       (save-current-buffer
-         (set-buffer buf)
-         (set-window-start (get-buffer-window (current-buffer)) start)
-         (goto-char p))))
+       (start (window-start))
+       (p (point))
+       (winconf gnus-prev-winconf))
+    (remove-hook 'gnus-article-mode-hook
+                'gnus-article-mime-edit-article-unwind)
+    (funcall func arg)
+    (set-buffer buf)
+    ;; The cache and backlog have to be flushed somewhat.
+    (when gnus-keep-backlog
+      (gnus-backlog-remove-article
+       (car gnus-article-current) (cdr gnus-article-current)))
+    ;; Flush original article as well.
     (save-excursion
-      (set-buffer buf)
-      (let ((buffer-read-only nil))
-       (funcall func arg))
-      ;; The cache and backlog have to be flushed somewhat.
-      (when gnus-keep-backlog
-       (gnus-backlog-remove-article
-        (car gnus-article-current) (cdr gnus-article-current)))
-      ;; Flush original article as well.
-      (save-excursion
-       (when (get-buffer gnus-original-article-buffer)
-         (set-buffer gnus-original-article-buffer)
-         (setq gnus-original-article nil)))
-      (when gnus-use-cache
-       (gnus-cache-update-article
-        (car gnus-article-current) (cdr gnus-article-current))))
+      (when (get-buffer gnus-original-article-buffer)
+       (set-buffer gnus-original-article-buffer)
+       (setq gnus-original-article nil)))
+    (when gnus-use-cache
+      (gnus-cache-update-article
+       (car gnus-article-current) (cdr gnus-article-current)))
+    ;; We remove all text props from the article buffer.
+    (kill-all-local-variables)
+    (gnus-set-text-properties (point-min) (point-max) nil)
+    (gnus-article-mode)
+    (set-window-configuration winconf)
     (set-buffer buf)
     (set-window-start (get-buffer-window buf) start)
     (set-window-point (get-buffer-window buf) (point))))
@@ -4932,6 +5637,115 @@ groups."
       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
 
 ;;;
+;;; Article editing with MIME-Edit
+;;;
+
+(defcustom gnus-article-mime-edit-article-setup-hook nil
+  "Hook run after setting up a MIME editing article buffer."
+  :group 'gnus-article-various
+  :type 'hook)
+
+(defun gnus-article-mime-edit-article-unwind ()
+  "Unwind `gnus-article-buffer' if article editing was given up."
+  (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
+  (when (featurep 'font-lock)
+    (setq font-lock-defaults nil)
+    (font-lock-mode -1))
+  (when mime-edit-mode-flag
+    (mime-edit-exit 'nomime 'no-error)
+    (message "")))
+
+(defun gnus-article-mime-edit-article-setup ()
+  "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
+after replacing with the original article."
+  (setq gnus-show-mime t)
+  (setq gnus-article-edit-done-function
+       `(lambda (&rest args)
+          (when mime-edit-mode-flag
+            (let (mime-edit-insert-user-agent-field)
+              (mime-edit-exit))
+            (message ""))
+          (goto-char (point-min))
+          (let (case-fold-search)
+            (when (re-search-forward
+                   (format "^%s$" (regexp-quote mail-header-separator))
+                   nil t)
+              (replace-match "")))
+          (apply ,gnus-article-edit-done-function args)
+          (insert
+           (prog1
+               (buffer-substring-no-properties (point-min) (point-max))
+             (set-buffer (get-buffer-create gnus-original-article-buffer))
+             (erase-buffer)))
+          (setq gnus-current-headers (gnus-article-make-full-mail-header))
+          (set-buffer gnus-article-buffer)
+          (gnus-article-prepare-display)))
+  (substitute-key-definition 'gnus-article-edit-done
+                            'gnus-article-mime-edit-done
+                            gnus-article-edit-mode-map)
+  (substitute-key-definition 'gnus-article-edit-exit
+                            'gnus-article-mime-edit-exit
+                            gnus-article-edit-mode-map)
+  (erase-buffer)
+  (insert-buffer gnus-original-article-buffer)
+  (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
+    (fset 'mime-edit-decode-single-part-in-buffer
+         (lambda (&rest args)
+           (if (let ((content-type (car args)))
+                 (and (eq 'message (mime-content-type-primary-type
+                                    content-type))
+                      (eq 'rfc822 (mime-content-type-subtype content-type))))
+               (setcar (cdr args) 'not-decode-text))
+           (apply ofn args)))
+    (unwind-protect
+       (mime-edit-again)
+      (fset 'mime-edit-decode-single-part-in-buffer ofn)))
+  (when (featurep 'font-lock)
+    (set (make-local-variable 'font-lock-defaults)
+        '(message-font-lock-keywords t))
+    (font-lock-set-defaults)
+    (turn-on-font-lock))
+  (set-buffer-modified-p nil)
+  (delete-other-windows)
+  (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
+  (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
+
+(defun gnus-article-mime-edit-done (&optional arg)
+  "Update the article MIME edits and exit."
+  (interactive "P")
+  (when (featurep 'font-lock)
+    (setq font-lock-defaults nil)
+    (font-lock-mode -1))
+  (gnus-article-edit-done arg))
+
+(defun gnus-article-mime-edit-exit ()
+  "Exit the article MIME editing without updating."
+  (interactive)
+  (when (or (not (buffer-modified-p))
+           (yes-or-no-p "Article modified; kill anyway? "))
+    (when (featurep 'font-lock)
+      (setq font-lock-defaults nil)
+      (font-lock-mode -1))
+    (when mime-edit-mode-flag
+      (let (mime-edit-insert-user-agent-field)
+       (mime-edit-exit))
+      (message ""))
+    (goto-char (point-min))
+    (let (case-fold-search)
+      (when (re-search-forward
+            (format "^%s$" (regexp-quote mail-header-separator)) nil t)
+       (replace-match "")))
+    (let ((winconf gnus-prev-winconf))
+      (insert (prog1
+                 (buffer-substring-no-properties (point-min) (point-max))
+               (set-buffer (get-buffer-create gnus-original-article-buffer))
+               (erase-buffer)))
+      (setq gnus-current-headers (gnus-article-make-full-mail-header))
+      (set-buffer gnus-article-buffer)
+      (gnus-article-prepare-display)
+      (set-window-configuration winconf))))
+
+;;;
 ;;; Article highlights
 ;;;
 
@@ -4962,7 +5776,7 @@ groups."
     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
      gnus-button-handle-info 2)
     ;; This is how URLs _should_ be embedded in text...
-    ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
+    ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
     ;; Raw URLs.
     (,gnus-button-url-regexp 0 t browse-url 0))
   "*Alist of regexps matching buttons in article bodies.
@@ -4995,6 +5809,7 @@ variable it the real callback function."
     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
     ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
     ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
+    ("^[^:]+:" "\\bmailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
      gnus-button-message-id 3))
   "*Alist of headers and regexps to match buttons in article heads.
@@ -5049,6 +5864,40 @@ call it with the value of the `gnus-data' text property."
     (when fun
       (funcall fun data))))
 
+(defun gnus-article-prev-button (n)
+  "Move point to N buttons backward.
+If N is negative, move forward instead."
+  (interactive "p")
+  (gnus-article-next-button (- n)))
+
+(defun gnus-article-next-button (n)
+  "Move point to N buttons forward.
+If N is negative, move backward instead."
+  (interactive "p")
+  (let ((function (if (< n 0) 'previous-single-property-change
+                   'next-single-property-change))
+       (inhibit-point-motion-hooks t)
+       (backward (< n 0))
+       (limit (if (< n 0) (point-min) (point-max))))
+    (setq n (abs n))
+    (while (and (not (= limit (point)))
+               (> n 0))
+      ;; Skip past the current button.
+      (when (get-text-property (point) 'gnus-callback)
+       (goto-char (funcall function (point) 'gnus-callback nil limit)))
+      ;; Go to the next (or previous) button.
+      (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
+      ;; Put point at the start of the button.
+      (when (and backward (not (get-text-property (point) 'gnus-callback)))
+       (goto-char (funcall function (point) 'gnus-callback nil limit)))
+      ;; Skip past intangible buttons.
+      (when (get-text-property (point) 'intangible)
+       (incf n))
+      (decf n))
+    (unless (zerop n)
+      (gnus-message 5 "No more buttons"))
+    n))
+
 (defun gnus-article-highlight (&optional force)
   "Highlight current article.
 This function calls `gnus-article-highlight-headers',
@@ -5116,21 +5965,28 @@ do the highlighting.  See the documentation for those functions."
 It does this by highlighting everything after
 `gnus-signature-separator' using `gnus-signature-face'."
   (interactive)
+  (when gnus-signature-face
+    (save-excursion
+      (set-buffer gnus-article-buffer)
+      (let ((buffer-read-only nil)
+           (inhibit-point-motion-hooks t))
+       (save-restriction
+         (when (gnus-article-narrow-to-signature)
+           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
+                             'face gnus-signature-face)))))))
+
+(defun gnus-article-buttonize-signature ()
+  "Add button to the signature."
+  (interactive)
   (save-excursion
     (set-buffer gnus-article-buffer)
     (let ((buffer-read-only nil)
          (inhibit-point-motion-hooks t))
-      (save-restriction
-       (when (and gnus-signature-face
-                  (gnus-article-narrow-to-signature))
-         (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
-                           'face gnus-signature-face)
-         (widen)
-         (gnus-article-search-signature)
-         (let ((start (match-beginning 0))
-               (end (set-marker (make-marker) (1+ (match-end 0)))))
-           (gnus-article-add-button start (1- end) 'gnus-signature-toggle
-                                    end)))))))
+      (when (gnus-article-search-signature)
+       (gnus-article-add-button (match-beginning 0) (match-end 0)
+                                'gnus-signature-toggle
+                                (set-marker (make-marker)
+                                            (1+ (match-end 0))))))))
 
 (defun gnus-button-in-region-p (b e prop)
   "Say whether PROP exists in the region."
@@ -5234,7 +6090,9 @@ specified by `gnus-button-alist'."
          (list 'gnus-callback fun)
          (and data (list 'gnus-data data))))
   (widget-convert-button 'link from to :action 'gnus-widget-press-button
-                        :button-keymap gnus-widget-button-keymap))
+                        ;; Quote `:button-keymap' for Mule 2.3
+                        ;; but it won't work.
+                        ':button-keymap gnus-widget-button-keymap))
 
 ;;; Internal functions:
 
@@ -5247,17 +6105,19 @@ specified by `gnus-button-alist'."
   (save-excursion
     (set-buffer gnus-article-buffer)
     (let ((buffer-read-only nil)
-         (inhibit-point-motion-hooks t))
-      (if (text-property-any end (point-max) 'article-type 'signature)
+         (inhibit-point-motion-hooks t)
+         (limit (next-single-property-change end 'mime-view-entity
+                                             nil (point-max))))
+      (if (text-property-any end limit 'article-type 'signature)
          (progn
            (gnus-delete-wash-type 'signature)
            (gnus-remove-text-properties-when
-            'article-type 'signature end (point-max)
+            'article-type 'signature end limit
             (cons 'article-type (cons 'signature
                                       gnus-hidden-properties))))
        (gnus-add-wash-type 'signature)
        (gnus-add-text-properties-when
-        'article-type nil end (point-max)
+        'article-type nil end limit
         (cons 'article-type (cons 'signature
                                   gnus-hidden-properties)))))
     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
@@ -5381,9 +6241,9 @@ specified by `gnus-button-alist'."
       (setq cur (car pairs)
            pairs (cdr pairs))
       (if (not (string-match "=" cur))
-         nil                           ; Grace
+         nil                           ; Grace
        (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
-             val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
+             val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
        (if downcase
            (setq key (downcase key)))
        (setq cur (assoc key retval))
@@ -5425,28 +6285,41 @@ specified by `gnus-button-alist'."
 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
 
-(defvar gnus-prev-page-map nil)
-(unless gnus-prev-page-map
-  (setq gnus-prev-page-map (make-sparse-keymap))
-  (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
-  (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
+(defvar gnus-prev-page-map
+  (let ((map (make-sparse-keymap)))
+    (unless (>= emacs-major-version 21)
+      ;; XEmacs doesn't care.
+      (set-keymap-parent map gnus-article-mode-map))
+    (define-key map gnus-mouse-2 'gnus-button-prev-page)
+    (define-key map "\r" 'gnus-button-prev-page)
+    map))
 
 (defun gnus-insert-prev-page-button ()
-  (let ((buffer-read-only nil))
+  (let ((b (point))
+       (buffer-read-only nil)
+       (situation (get-text-property (point-min) 'mime-view-situation)))
     (gnus-eval-format
      gnus-prev-page-line-format nil
-     `(gnus-prev t local-map ,gnus-prev-page-map
-                gnus-callback gnus-article-button-prev-page
-                article-type annotation))))
-
-(defvar gnus-next-page-map nil)
-(unless gnus-next-page-map
-  (setq gnus-next-page-map (make-keymap))
-  (suppress-keymap gnus-prev-page-map)
-  (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
-  (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
-
-(defun gnus-button-next-page ()
+     `(,@(gnus-local-map-property gnus-prev-page-map)
+        gnus-prev t
+        gnus-callback gnus-article-button-prev-page
+        article-type annotation
+        mime-view-situation ,situation))
+    (widget-convert-button
+     'link b (point)
+     :action 'gnus-button-prev-page
+     :button-keymap gnus-prev-page-map)))
+
+(defvar gnus-next-page-map
+  (let ((map (make-sparse-keymap)))
+    (unless (>= emacs-major-version 21)
+      ;; XEmacs doesn't care.
+      (set-keymap-parent map gnus-article-mode-map))
+    (define-key map gnus-mouse-2 'gnus-button-next-page)
+    (define-key map "\r" 'gnus-button-next-page)
+    map))
+
+(defun gnus-button-next-page (&optional args more-args)
   "Go to the next page."
   (interactive)
   (let ((win (selected-window)))
@@ -5454,7 +6327,7 @@ specified by `gnus-button-alist'."
     (gnus-article-next-page)
     (select-window win)))
 
-(defun gnus-button-prev-page ()
+(defun gnus-button-prev-page (&optional args more-args)
   "Go to the prev page."
   (interactive)
   (let ((win (selected-window)))
@@ -5463,12 +6336,19 @@ specified by `gnus-button-alist'."
     (select-window win)))
 
 (defun gnus-insert-next-page-button ()
-  (let ((buffer-read-only nil))
+  (let ((b (point))
+       (buffer-read-only nil)
+       (situation (get-text-property (point-min) 'mime-view-situation)))
     (gnus-eval-format gnus-next-page-line-format nil
-                     `(gnus-next
-                       t local-map ,gnus-next-page-map
-                       gnus-callback gnus-article-button-next-page
-                       article-type annotation))))
+                     `(,@(gnus-local-map-property gnus-next-page-map)
+                         gnus-next t
+                         gnus-callback gnus-article-button-next-page
+                         article-type annotation
+                         mime-view-situation ,situation))
+    (widget-convert-button
+     'link b (point)
+     :action 'gnus-button-next-page
+     :button-keymap gnus-next-page-map)))
 
 (defun gnus-article-button-next-page (arg)
   "Go to the next page."
@@ -5492,11 +6372,11 @@ specified by `gnus-button-alist'."
 
 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
-(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
+\(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
 whose names match REGEXP.
 
 For example:
-((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
+\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
  mail-decode-encoded-word-region
  (\"chinese\" . rfc1843-decode-region))
 ")
@@ -5516,7 +6396,7 @@ For example:
                         (string-match (car x) gnus-newsgroup-name))
                    (nconc gnus-decode-header-methods-cache
                           (list (cdr x))))))
-         gnus-decode-header-methods))
+           gnus-decode-header-methods))
   (let ((xlist gnus-decode-header-methods-cache))
     (pop xlist)
     (save-restriction
@@ -5540,21 +6420,37 @@ For example:
                   (when (string-match (pop list) type)
                     (throw 'found t)))))))
        (highlightp (gnus-visual-p 'article-highlight 'highlight))
-       val elem)
+       (entity (static-unless (featurep 'xemacs)
+                 (when (eq 'head condition)
+                   (get-text-property (point-min) 'mime-view-entity))))
+       val elem buttonized)
     (gnus-run-hooks 'gnus-part-display-hook)
-    (while (setq elem (pop alist))
-      (setq val
-           (save-excursion
-             (if (gnus-buffer-live-p gnus-summary-buffer)
-                 (set-buffer gnus-summary-buffer))
-             (symbol-value (car elem))))
-      (when (and (or (consp val)
-                    treated-type)
-                (gnus-treat-predicate val)
-                (or (not (get (car elem) 'highlight))
-                    highlightp))
-       (save-restriction
-         (funcall (cadr elem)))))))
+    (unless gnus-inhibit-treatment
+      (while (setq elem (pop alist))
+       (setq val
+             (save-excursion
+               (if (gnus-buffer-live-p gnus-summary-buffer)
+                   (set-buffer gnus-summary-buffer))
+               (symbol-value (car elem))))
+       (when (and (or (consp val)
+                      treated-type)
+                  (gnus-treat-predicate val)
+                  (or (not (get (car elem) 'highlight))
+                      highlightp))
+         (when (and (not buttonized)
+                    (memq (car elem)
+                          '(gnus-treat-hide-signature
+                            gnus-treat-highlight-signature)))
+           (gnus-article-buttonize-signature)
+           (setq buttonized t))
+         (save-restriction
+           (funcall (cadr elem)))))
+      ;; FSF Emacsen does not inherit the existing text properties
+      ;; in the new text, so we should do it for `mime-view-entity'.
+      (static-unless (featurep 'xemacs)
+       (when entity
+         (put-text-property (point-min) (point-max)
+                            'mime-view-entity entity))))))
 
 ;; Dynamic variables.
 (eval-when-compile
@@ -5586,6 +6482,8 @@ For example:
        (equal (car val) type))
        (t
        (error "%S is not a valid predicate" pred)))))
+   ((eq val 'mime)
+    gnus-show-mime)
    (condition
     (eq condition val))
    ((eq val t)
@@ -5627,7 +6525,7 @@ For example:
            (error "The current newsgroup does not support article encrypt"))
          (gnus-summary-show-article t)
          (setq references
-             (or (mail-header-references gnus-current-headers) ""))
+               (or (mail-header-references gnus-current-headers) ""))
          (set-buffer gnus-article-buffer)
          (let* ((buffer-read-only nil)
                 (headers
@@ -5737,7 +6635,7 @@ For example:
            (let ((gnus-mime-security-button-pressed t)
                  (gnus-mime-security-button-line-format
                   (get-text-property (point) 'gnus-line-format))
-               buffer-read-only)
+                 buffer-read-only)
              (forward-char -1)
              (while (eq (get-text-property (point) 'gnus-line-format)
                         gnus-mime-security-button-line-format)
@@ -5797,14 +6695,11 @@ For example:
     (gnus-eval-format
      gnus-mime-security-button-line-format
      gnus-mime-security-button-line-format-alist
-     `(keymap ,gnus-mime-security-button-map
-             ,@(if (>= (string-to-number emacs-version) 21)
-                   nil ;; XEmacs doesn't care
-                 (list 'local-map gnus-mime-security-button-map))
-             gnus-callback gnus-mime-security-press-button
-             gnus-line-format ,gnus-mime-security-button-line-format
-             article-type annotation
-             gnus-data ,handle))
+     `(,@(gnus-local-map-property gnus-mime-security-button-map)
+        gnus-callback gnus-mime-security-press-button
+        gnus-line-format ,gnus-mime-security-button-line-format
+        article-type annotation
+        gnus-data ,handle))
     (setq e (point))
     (widget-convert-button
      'link b e
@@ -5838,6 +6733,50 @@ For example:
      (cons (set-marker (make-marker) (point-min))
           (set-marker (make-marker) (point-max))))))
 
+
+;;; @ for mime-view
+;;;
+
+(defun gnus-article-header-presentation-method (entity situation)
+  (mime-insert-header entity)
+  (article-decode-group-name))
+
+(set-alist 'mime-header-presentation-method-alist
+          'gnus-original-article-mode
+          #'gnus-article-header-presentation-method)
+
+(defun gnus-mime-preview-quitting-method ()
+  (mime-preview-kill-buffer)
+  (delete-other-windows)
+  (gnus-article-show-summary)
+  (gnus-summary-select-article gnus-show-all-headers t))
+
+(set-alist 'mime-preview-quitting-method-alist
+          'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
+
+(set-alist 'mime-preview-following-method-alist
+          'gnus-original-article-mode #'gnus-following-method)
+
+(set-alist 'mime-preview-over-to-previous-method-alist
+          'gnus-original-article-mode
+          (lambda ()
+            (if (> (point-min) 1)
+                (gnus-article-prev-page)
+              (gnus-article-read-summary-keys
+               nil (gnus-character-to-event ?P)))))
+
+(set-alist 'mime-preview-over-to-next-method-alist
+          'gnus-original-article-mode'
+          (lambda ()
+            (if (< (point-max) (buffer-size))
+                (gnus-article-next-page)
+              (gnus-article-read-summary-keys
+               nil (gnus-character-to-event ?N)))))
+
+
+;;; @ end
+;;;
+
 (gnus-ems-redefine)
 
 (provide 'gnus-art)