gnus-art.el 168 KB
Newer Older
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1
;;; gnus-art.el --- article mode commands for Gnus
2

3
;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
4
;;   Free Software Foundation, Inc.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
5

6
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
;; Keywords: news

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;;; Code:

30 31
(eval-when-compile (require 'cl))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
32 33 34 35
(require 'gnus)
(require 'gnus-sum)
(require 'gnus-spec)
(require 'gnus-int)
36 37 38 39 40 41
(require 'mm-bodies)
(require 'mail-parse)
(require 'mm-decode)
(require 'mm-view)
(require 'wid-edit)
(require 'mm-uu)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
42 43 44 45 46 47

(defgroup gnus-article nil
  "Article display."
  :link '(custom-manual "(gnus)The Article Buffer")
  :group 'gnus)

48 49 50 51 52
(defgroup gnus-article-treat nil
  "Treating article parts."
  :link '(custom-manual "(gnus)Article Hiding")
  :group 'gnus-article)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
(defgroup gnus-article-hiding nil
  "Hiding article parts."
  :link '(custom-manual "(gnus)Article Hiding")
  :group 'gnus-article)

(defgroup gnus-article-highlight nil
  "Article highlighting."
  :link '(custom-manual "(gnus)Article Highlighting")
  :group 'gnus-article
  :group 'gnus-visual)

(defgroup gnus-article-signature nil
  "Article signatures."
  :link '(custom-manual "(gnus)Article Signature")
  :group 'gnus-article)

(defgroup gnus-article-headers nil
  "Article headers."
  :link '(custom-manual "(gnus)Hiding Headers")
  :group 'gnus-article)

(defgroup gnus-article-washing nil
  "Special commands on articles."
  :link '(custom-manual "(gnus)Article Washing")
  :group 'gnus-article)

(defgroup gnus-article-emphasis nil
  "Fontisizing articles."
  :link '(custom-manual "(gnus)Article Fontisizing")
  :group 'gnus-article)

(defgroup gnus-article-saving nil
  "Saving articles."
  :link '(custom-manual "(gnus)Saving Articles")
  :group 'gnus-article)

(defgroup gnus-article-mime nil
  "Worshiping the MIME wonder."
  :link '(custom-manual "(gnus)Using MIME")
  :group 'gnus-article)

(defgroup gnus-article-buttons nil
  "Pushable buttons in the article buffer."
  :link '(custom-manual "(gnus)Article Buttons")
  :group 'gnus-article)

(defgroup gnus-article-various nil
  "Other article options."
  :link '(custom-manual "(gnus)Misc Article")
  :group 'gnus-article)

(defcustom gnus-ignored-headers
105 106 107 108 109 110 111 112 113 114 115 116 117 118
  '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
    "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
    "^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-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.*:"
    "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
    "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
    "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
    "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
    "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
119
    "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
120
    "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
121 122 123 124 125 126 127 128 129 130 131
    "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
    "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
    "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
    "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
    "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
    "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
    "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
    "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
    "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
    "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
    "^X-Received:" "^Content-length:" "X-precedence:")
132
  "*All headers that start with this regexp will be hidden.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
133 134 135 136 137 138 139 140
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."
  :type '(choice :custom-show nil
		 regexp
		 (repeat regexp))
  :group 'gnus-article-hiding)

(defcustom gnus-visible-headers
141
  "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
142
  "*All headers that do not match this regexp will be hidden.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
143 144 145 146 147 148 149 150 151 152 153 154 155
This variable can also be a list of regexp of headers to remain visible.
If this variable is non-nil, `gnus-ignored-headers' will be ignored."
  :type '(repeat :value-to-internal (lambda (widget value)
				      (custom-split-regexp-maybe value))
		 :match (lambda (widget value)
			  (or (stringp value)
			      (widget-editable-list-match widget value)))
		 regexp)
  :group 'gnus-article-hiding)

(defcustom gnus-sorted-header-list
  '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
    "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
156
  "*This variable is a list of regular expressions.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
157 158 159 160 161 162 163 164 165
If it is non-nil, headers that match the regular expressions will
be placed first in the article buffer in the sequence specified by
this list."
  :type '(repeat regexp)
  :group 'gnus-article-hiding)

(defcustom gnus-boring-article-headers '(empty followup-to reply-to)
  "Headers that are only to be displayed if they have interesting data.
Possible values in this list are `empty', `newsgroups', `followup-to',
166
`reply-to', `date', `long-to', and `many-to'."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
167 168 169 170
  :type '(set (const :tag "Headers with no content." empty)
	      (const :tag "Newsgroups with only one group." newsgroups)
	      (const :tag "Followup-to identical to newsgroups." followup-to)
	      (const :tag "Reply-to identical to from." reply-to)
171
	      (const :tag "Date less than four days old." date)
172 173
	      (const :tag "Very long To and/or Cc header." long-to)
	      (const :tag "Multiple To and/or Cc headers." many-to))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
174 175 176 177 178 179 180 181 182 183 184
  :group 'gnus-article-hiding)

(defcustom gnus-signature-separator '("^-- $" "^-- *$")
  "Regexp matching signature separator.
This can also be a list of regexps.  In that case, it will be checked
from head to tail looking for a separator.  Searches will be done from
the end of the buffer."
  :type '(repeat string)
  :group 'gnus-article-signature)

(defcustom gnus-signature-limit nil
185
  "Provide a limit to what is considered a signature.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
186 187 188 189 190 191
If it is a number, no signature may not be longer (in characters) than
that number.  If it is a floating point number, no signature may be
longer (in lines) than that number.  If it is a function, the function
will be called without any parameters, and if it returns nil, there is
no signature in the buffer.  If it is a string, it will be used as a
regexp.  If it matches, the text in question is not a signature."
192 193 194 195
  :type '(choice (integer :value 200)
		 (number :value 4.0)
		 (function :value fun)
		 (regexp :value ".*"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
196 197 198 199 200 201 202
  :group 'gnus-article-signature)

(defcustom gnus-hidden-properties '(invisible t intangible t)
  "Property list to use for hiding text."
  :type 'sexp
  :group 'gnus-article-hiding)

203 204 205
;; Fixme: This isn't the right thing for mixed graphical and and
;; non-graphical frames in a session.
;; gnus-xmas.el overrides this for XEmacs.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
206
(defcustom gnus-article-x-face-command
207 208 209
  (if (and (fboundp 'image-type-available-p)
	   (image-type-available-p 'xbm))
      'gnus-article-display-xface
210 211 212 213
    (if (or (and (boundp 'gnus-article-compface-xbm)
                 gnus-article-compface-xbm)
            (eq 0 (string-match "#define"
                                (shell-command-to-string "uncompface -X"))))
214 215 216
	"{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
      "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
display -"))
217
  "*String or function to be executed to display an X-Face header.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
218 219
If it is a string, the command will be executed in a sub-shell
asynchronously.	 The compressed face will be piped to this command."
220 221 222
  :type '(choice string
		 (function-item gnus-article-display-xface)
		 function)
Dave Love's avatar
Dave Love committed
223
  :version "21.1"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
224 225 226 227
  :group 'gnus-article-washing)

(defcustom gnus-article-x-face-too-ugly nil
  "Regexp matching posters whose face shouldn't be shown automatically."
228
  :type '(choice regexp (const nil))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
229 230
  :group 'gnus-article-washing)

231 232 233 234
(defcustom gnus-article-banner-alist nil
  "Banner alist for stripping.
For example, 
     ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
Dave Love's avatar
Dave Love committed
235
  :version "21.1"
236 237 238
  :type '(repeat (cons symbol regexp))
  :group 'gnus-article-washing)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
239 240
(defcustom gnus-emphasis-alist
  (let ((format
241
	 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255
	(types
	 '(("_" "_" underline)
	   ("/" "/" italic)
	   ("\\*" "\\*" bold)
	   ("_/" "/_" underline-italic)
	   ("_\\*" "\\*_" underline-bold)
	   ("\\*/" "/\\*" bold-italic)
	   ("_\\*/" "/\\*_" underline-bold-italic))))
    `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
       2 3 gnus-emphasis-underline)
      ,@(mapcar
	 (lambda (spec)
	   (list
	    (format format (car spec) (cadr spec))
256
	    2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
257
	 types)))
258
  "*Alist that says how to fontify certain phrases.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
Each item looks like this:

  (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)

The first element is a regular expression to be matched.  The second
is a number that says what regular expression grouping used to find
the entire emphasized word.  The third is a number that says what
regexp grouping should be displayed and highlighted.  The fourth
is the face used for highlighting."
  :type '(repeat (list :value ("" 0 0 default)
		       regexp
		       (integer :tag "Match group")
		       (integer :tag "Emphasize group")
		       face))
  :group 'gnus-article-emphasis)

275 276 277 278 279
(defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
  "A regexp to describe whitespace which should not be emphasized.
Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
The former avoids underlining of leading and trailing whitespace,
and the latter avoids underlining any whitespace at all."
Dave Love's avatar
Dave Love committed
280
  :version "21.1"
281 282 283
  :group 'gnus-article-emphasis
  :type 'regexp)

284
(defface gnus-emphasis-bold '((t (:weight bold)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
285 286 287
  "Face used for displaying strong emphasized text (*word*)."
  :group 'gnus-article-emphasis)

288
(defface gnus-emphasis-italic '((t (:slant italic)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
289 290 291 292 293 294 295
  "Face used for displaying italic emphasized text (/word/)."
  :group 'gnus-article-emphasis)

(defface gnus-emphasis-underline '((t (:underline t)))
  "Face used for displaying underlined emphasized text (_word_)."
  :group 'gnus-article-emphasis)

296
(defface gnus-emphasis-underline-bold '((t (:weight bold :underline t)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
297 298 299
  "Face used for displaying underlined bold emphasized text (_*word*_)."
  :group 'gnus-article-emphasis)

300
(defface gnus-emphasis-underline-italic '((t (:slant italic :underline t)))
301
  "Face used for displaying underlined italic emphasized text (_/word/_)."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
302 303
  :group 'gnus-article-emphasis)

304
(defface gnus-emphasis-bold-italic '((t (:weight bold :slant italic)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
305 306 307 308
  "Face used for displaying bold italic emphasized text (/*word*/)."
  :group 'gnus-article-emphasis)

(defface gnus-emphasis-underline-bold-italic
309
  '((t (:weight bold :slant italic :underline t)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
310
  "Face used for displaying underlined bold italic emphasized text.
ShengHuo ZHU's avatar
Typos.  
ShengHuo ZHU committed
311
Example: (_/*word*/_)."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
312 313
  :group 'gnus-article-emphasis)

314 315 316 317 318
(defface gnus-emphasis-highlight-words
  '((t (:background "black" :foreground "yellow")))
  "Face used for displaying highlighted words."
  :group 'gnus-article-emphasis)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
319 320
(defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
  "Format for display of Date headers in article bodies.
321 322 323 324 325 326
See `format-time-string' for the possible values.

The variable can also be function, which should return a complete Date
header.  The function is called with one argument, the time, which can
be fed to `format-time-string'."
  :type '(choice string symbol)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
  :link '(custom-manual "(gnus)Article Date")
  :group 'gnus-article-washing)

(eval-and-compile
  (autoload 'mail-extract-address-components "mail-extr"))

(defcustom gnus-save-all-headers t
  "*If non-nil, don't remove any headers before saving."
  :group 'gnus-article-saving
  :type 'boolean)

(defcustom gnus-prompt-before-saving 'always
  "*This variable says how much prompting is to be done when saving articles.
If it is nil, no prompting will be done, and the articles will be
saved to the default files.  If this variable is `always', each and
every article that is saved will be preceded by a prompt, even when
saving large batches of articles.  If this variable is neither nil not
`always', there the user will be prompted once for a file name for
each invocation of the saving commands."
  :group 'gnus-article-saving
  :type '(choice (item always)
		 (item :tag "never" nil)
349
		 (sexp :tag "once" :format "%t\n" :value t)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
350 351 352 353 354 355 356

(defcustom gnus-saved-headers gnus-visible-headers
  "Headers to keep if `gnus-save-all-headers' is nil.
If `gnus-save-all-headers' is non-nil, this variable will be ignored.
If that variable is nil, however, all headers that match this regexp
will be kept while the rest will be deleted before saving."
  :group 'gnus-article-saving
357
  :type 'regexp)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407

(defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
  "A function to save articles in your favourite format.
The function must be interactively callable (in other words, it must
be an Emacs command).

Gnus provides the following functions:

* gnus-summary-save-in-rmail (Rmail format)
* gnus-summary-save-in-mail (Unix mail format)
* gnus-summary-save-in-folder (MH folder)
* gnus-summary-save-in-file (article format)
* gnus-summary-save-in-vm (use VM's folder format)
* gnus-summary-write-to-file (article format -- overwrite)."
  :group 'gnus-article-saving
  :type '(radio (function-item gnus-summary-save-in-rmail)
		(function-item gnus-summary-save-in-mail)
		(function-item gnus-summary-save-in-folder)
		(function-item gnus-summary-save-in-file)
		(function-item gnus-summary-save-in-vm)
		(function-item gnus-summary-write-to-file)))

(defcustom gnus-rmail-save-name 'gnus-plain-save-name
  "A function generating a file name to save articles in Rmail format.
The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  :group 'gnus-article-saving
  :type 'function)

(defcustom gnus-mail-save-name 'gnus-plain-save-name
  "A function generating a file name to save articles in Unix mail format.
The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  :group 'gnus-article-saving
  :type 'function)

(defcustom gnus-folder-save-name 'gnus-folder-save-name
  "A function generating a file name to save articles in MH folder.
The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
  :group 'gnus-article-saving
  :type 'function)

(defcustom gnus-file-save-name 'gnus-numeric-save-name
  "A function generating a file name to save articles in article format.
The function is called with NEWSGROUP, HEADERS, and optional
LAST-FILE."
  :group 'gnus-article-saving
  :type 'function)

(defcustom gnus-split-methods
  '((gnus-article-archive-name)
    (gnus-article-nndoc-name))
408
  "*Variable used to suggest where articles are to be saved.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
For instance, if you would like to save articles related to Gnus in
the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
you could set this variable to something like:

 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
   (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))

This variable is an alist where the where the key is the match and the
value is a list of possible files to save in if the match is non-nil.

If the match is a string, it is used as a regexp match on the
article.  If the match is a symbol, that symbol will be funcalled
from the buffer of the article to be saved with the newsgroup as the
parameter.  If it is a list, it will be evaled in the same buffer.

If this form or function returns a string, this string will be used as
a possible file name; and if it returns a non-nil list, that list will
be used as possible file names."
  :group 'gnus-article-saving
428 429 430
  :type '(repeat (choice (list :value (fun) function)
			 (cons :value ("" "") regexp (repeat string))
			 (sexp :value nil))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
431 432 433 434 435 436 437 438

(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
beginning of a line."
  :type 'regexp
  :group 'gnus-article-various)

439
(defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
440
  "*The format specification for the article mode line.
441 442 443 444 445 446
See `gnus-summary-mode-line-format' for a closer description.

The following additional specs are available:

%w  The article washing status.
%m  The number of MIME parts in the article."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
447 448 449 450 451 452 453 454 455 456 457 458 459 460
  :type 'string
  :group 'gnus-article-various)

(defcustom gnus-article-mode-hook nil
  "*A hook for Gnus article mode."
  :type 'hook
  :group 'gnus-article-various)

(defcustom gnus-article-menu-hook nil
  "*Hook run after the creation of the article mode menu."
  :type 'hook
  :group 'gnus-article-various)

(defcustom gnus-article-prepare-hook nil
461
  "*A hook called after an article has been prepared in the article buffer."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
462 463 464
  :type 'hook
  :group 'gnus-article-various)

465 466 467
(defcustom gnus-article-hide-pgp-hook nil
  "*A hook called after successfully hiding a PGP signature."
  :type 'hook
468
  :group 'gnus-article-various)
469

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
(defcustom gnus-article-button-face 'bold
  "Face used for highlighting buttons in the article buffer.

An article button is a piece of text that you can activate by pressing
`RET' or `mouse-2' above it."
  :type 'face
  :group 'gnus-article-buttons)

(defcustom gnus-article-mouse-face 'highlight
  "Face used for mouse highlighting in the article buffer.

Article buttons will be displayed in this face when the cursor is
above them."
  :type 'face
  :group 'gnus-article-buttons)

486 487 488
(defcustom gnus-signature-face 'gnus-signature-face
  "Face used for highlighting a signature in the article buffer.
Obsolete; use the face `gnus-signature-face' for customizations instead."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
489 490 491 492
  :type 'face
  :group 'gnus-article-highlight
  :group 'gnus-article-signature)

493
(defface gnus-signature-face
494
  '((t
495
     (:slant italic)))
496 497 498 499
  "Face used for highlighting a signature in the article buffer."
  :group 'gnus-article-highlight
  :group 'gnus-article-signature)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
500 501 502
(defface gnus-header-from-face
  '((((class color)
      (background dark))
503
     (:foreground "spring green"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
504 505
    (((class color)
      (background light))
506
     (:foreground "red3"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
507
    (t
508
     (:slant italic)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
509 510 511 512 513 514 515
  "Face used for displaying from headers."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defface gnus-header-subject-face
  '((((class color)
      (background dark))
516
     (:foreground "SeaGreen3"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
517 518
    (((class color)
      (background light))
519
     (:foreground "red4"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
520
    (t
521
     (:weight bold :slant italic)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
522 523 524 525 526 527 528
  "Face used for displaying subject headers."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defface gnus-header-newsgroups-face
  '((((class color)
      (background dark))
529
     (:foreground "yellow" :slant italic))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
530 531
    (((class color)
      (background light))
532
     (:foreground "MidnightBlue" :slant italic))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
533
    (t
534
     (:slant italic)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
535 536 537 538 539 540 541 542 543 544 545 546
  "Face used for displaying newsgroups headers."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defface gnus-header-name-face
  '((((class color)
      (background dark))
     (:foreground "SeaGreen"))
    (((class color)
      (background light))
     (:foreground "maroon"))
    (t
547
     (:weight bold)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
548 549 550 551 552 553 554
  "Face used for displaying header names."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defface gnus-header-content-face
  '((((class color)
      (background dark))
555
     (:foreground "forest green" :slant italic))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
556 557
    (((class color)
      (background light))
558
     (:foreground "indianred4" :slant italic))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
559
    (t
560
     (:slant italic)))  "Face used for displaying header content."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
561 562 563 564 565 566 567 568
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defcustom gnus-header-face-alist
  '(("From" nil gnus-header-from-face)
    ("Subject" nil gnus-header-subject-face)
    ("Newsgroups:.*," nil gnus-header-newsgroups-face)
    ("" gnus-header-name-face gnus-header-content-face))
569
  "*Controls highlighting of article header.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589

An alist of the form (HEADER NAME CONTENT).

HEADER is a regular expression which should match the name of an
header header and NAME and CONTENT are either face names or nil.

The name of each header field will be displayed using the face
specified by the first element in the list where HEADER match the
header name and NAME is non-nil.  Similarly, the content will be
displayed by the first non-nil matching CONTENT face."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight
  :type '(repeat (list (regexp :tag "Header")
		       (choice :tag "Name"
			       (item :tag "skip" nil)
			       (face :value default))
		       (choice :tag "Content"
			       (item :tag "skip" nil)
			       (face :value default)))))

590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
(defcustom gnus-article-decode-hook
  '(article-decode-charset article-decode-encoded-words)
  "*Hook run to decode charsets in articles."
  :group 'gnus-article-headers
  :type 'hook)

(defcustom gnus-display-mime-function 'gnus-display-mime
  "Function to display MIME articles."
  :group 'gnus-article-mime
  :type 'function)

(defvar gnus-decode-header-function 'mail-decode-encoded-word-region
  "Function used to decode headers.")

(defvar gnus-article-dumbquotes-map
  '(("\202" ",")
    ("\203" "f")
    ("\204" ",,")
    ("\205" "...")
    ("\213" "<")
    ("\214" "OE")
    ("\221" "`")
    ("\222" "'")
    ("\223" "``")
    ("\224" "\"")
    ("\225" "*")
616 617
    ("\226" "-")
    ("\227" "--")
618 619 620 621 622 623 624 625
    ("\231" "(TM)")
    ("\233" ">")
    ("\234" "oe")
    ("\264" "'"))
  "Table for MS-to-Latin1 translation.")

(defcustom gnus-ignored-mime-types nil
  "List of MIME types that should be ignored by Gnus."
Dave Love's avatar
Dave Love committed
626
  :version "21.1"
627 628 629 630 631
  :group 'gnus-article-mime
  :type '(repeat regexp))

(defcustom gnus-unbuttonized-mime-types '(".*/.*")
  "List of MIME types that should not be given buttons when rendered inline."
Dave Love's avatar
Dave Love committed
632
  :version "21.1"
633 634 635 636 637 638 639 640 641 642 643
  :group 'gnus-article-mime
  :type '(repeat regexp))

(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
on parts -- for instance, adding Vcard info to a database."
  :group 'gnus-article-mime
  :type 'function)

(defcustom gnus-mime-multipart-functions nil
Dave Love's avatar
Dave Love committed
644 645 646 647
  "An alist of MIME types to functions to display them."
  :version "21.1"
  :group 'gnus-article-mime
  :type 'alist)
648 649 650 651 652 653

(defcustom gnus-article-date-lapsed-new-header nil
  "Whether the X-Sent and Date headers can coexist.
When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
either replace the old \"Date:\" header (if this variable is nil), or
be added below it (otherwise)."
Dave Love's avatar
Dave Love committed
654
  :version "21.1"
655 656 657 658 659 660 661 662 663 664 665
  :group 'gnus-article-headers
  :type 'boolean)

(defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
  "Function called with a MIME handle as the argument.
This is meant for people who want to view first matched part.
For `undisplayed-alternative' (default), the first undisplayed 
part or alternative part is used.  For `undisplayed', the first 
undisplayed part is used.  For a function, the first part which 
the function return `t' is used.  For `nil', the first part is
used."
Dave Love's avatar
Dave Love committed
666
  :version "21.1"
667 668 669 670 671 672 673 674
  :group 'gnus-article-mime
  :type '(choice 
	  (item :tag "first" :value nil)
	  (item :tag "undisplayed" :value undisplayed)
	  (item :tag "undisplayed or alternative" 
		:value undisplayed-alternative)
	  (function)))

675 676 677 678 679 680 681 682 683 684
(defcustom gnus-mime-action-alist
  '(("save to file" . gnus-mime-save-part)
    ("display as text" . gnus-mime-inline-part)
    ("view the part" . gnus-mime-view-part)
    ("pipe to command" . gnus-mime-pipe-part)
    ("toggle display" . gnus-article-press-button)
    ("view as type" . gnus-mime-view-part-as-type)
    ("internalize type" . gnus-mime-internalize-part)
    ("externalize type" . gnus-mime-externalize-part))
  "An alist of actions that run on the MIME attachment."
Dave Love's avatar
Dave Love committed
685
  :version "21.1"
686 687 688 689
  :group 'gnus-article-mime
  :type '(repeat (cons (string :tag "name")
		       (function))))

690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
;;;
;;; The treatment variables
;;;

(defvar gnus-part-display-hook nil
  "Hook called on parts that are to receive treatment.")

(defvar gnus-article-treat-custom
  '(choice (const :tag "Off" nil)
	   (const :tag "On" t)
	   (const :tag "Header" head)
	   (const :tag "Last" last)
	   (integer :tag "Less")
	   (repeat :tag "Groups" regexp)
	   (sexp :tag "Predicate")))

(defvar gnus-article-treat-head-custom
  '(choice (const :tag "Off" nil)
	   (const :tag "Header" head)))

(defvar gnus-article-treat-types '("text/plain")
  "Parts to treat.")

(defvar gnus-inhibit-treatment nil
  "Whether to inhibit treatment.")

(defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
  "Highlight the signature.
Valid values are nil, t, `head', `last', an integer or a predicate.
See the manual for details."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)
(put 'gnus-treat-highlight-signature 'highlight t)

(defcustom gnus-treat-buttonize 100000
  "Add buttons.
Valid values are nil, t, `head', `last', an integer or a predicate.
See the manual for details."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)
(put 'gnus-treat-buttonize 'highlight t)

(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."
  :group 'gnus-article-treat
  :type gnus-article-treat-head-custom)
(put 'gnus-treat-buttonize-head 'highlight t)

740 741 742 743 744
(defcustom gnus-treat-emphasize 
  (and (or window-system
	   (featurep 'xemacs)
	   (>= (string-to-number emacs-version) 21))
       50000)
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
  "Emphasize text.
Valid values are nil, t, `head', `last', an integer or a predicate.
See the manual for details."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)
(put 'gnus-treat-emphasize 'highlight t)

(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."
  :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."
  :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."
  :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."
  :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."
  :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."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

794 795 796 797 798 799 800
(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."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

801 802 803 804
(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."
Dave Love's avatar
Dave Love committed
805
  :version "21.1"
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

(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."
  :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."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

(defcustom gnus-treat-strip-banner t
  "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."
  :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."
  :group 'gnus-article-treat
  :type gnus-article-treat-head-custom)
(put 'gnus-treat-highlight-headers 'highlight t)

(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."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)
(put 'gnus-treat-highlight-citation 'highlight t)

(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."
  :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."
  :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."
  :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."
  :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."
Dave Love's avatar
Dave Love committed
879
  :version "21.1"
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
  :group 'gnus-article-treat
  :type gnus-article-treat-head-custom)

(defcustom gnus-treat-date-user-defined nil
  "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."
  :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."
Dave Love's avatar
Dave Love committed
895
  :version "21.1"
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

(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."
  :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."
  :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."
  :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."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)
(put 'gnus-treat-overstrike 'highlight t)

Dave Love's avatar
Dave Love committed
928 929
(defcustom gnus-treat-display-xface 
  (and (or (and (fboundp 'image-type-available-p)
930 931
		(image-type-available-p 'xbm)
		(string-match "^0x" (shell-command-to-string "uncompface")))
932
	   (and (featurep 'xemacs) (featurep 'xface)))
Dave Love's avatar
Dave Love committed
933
       'head)
934 935 936 937
  "Display X-Face headers.
Valid values are nil, t, `head', `last', an integer or a predicate.
See the manual for details."
  :group 'gnus-article-treat
Dave Love's avatar
Dave Love committed
938
  :version "21.1"
939 940 941
  :type gnus-article-treat-head-custom)
(put 'gnus-treat-display-xface 'highlight t)

942 943 944 945 946 947
(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)
948 949 950 951
  "Display smileys.
Valid values are nil, t, `head', `last', an integer or a predicate.
See the manual for details."
  :group 'gnus-article-treat
Dave Love's avatar
Dave Love committed
952
  :version "21.1"
953 954 955
  :type gnus-article-treat-custom)
(put 'gnus-treat-display-smileys 'highlight t)

956
(defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
957 958 959 960 961 962 963 964 965 966 967
  "Display picons.
Valid values are nil, t, `head', `last', an integer or a predicate.
See the manual for details."
  :group 'gnus-article-treat
  :type gnus-article-treat-head-custom)
(put 'gnus-treat-display-picons 'highlight t)

(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."
Dave Love's avatar
Dave Love committed
968
  :version "21.1"
969 970 971 972 973 974 975 976 977 978 979 980 981 982
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

(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."
  :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."
Dave Love's avatar
Dave Love committed
983
  :version "21.1"
984 985 986 987 988 989 990
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

(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."
Dave Love's avatar
Dave Love committed
991
  :version "21.1"
992 993 994
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
995 996
;;; Internal variables

997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
(defvar article-goto-body-goes-to-point-min-p nil)
(defvar gnus-article-wash-types nil)
(defvar gnus-article-emphasis-alist nil)

(defvar gnus-article-mime-handle-alist-1 nil)
(defvar gnus-treatment-function-alist
  '((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-emphasize gnus-article-emphasize)
    (gnus-treat-display-xface gnus-article-display-x-face)
    (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)
1016
    (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
    (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
    (gnus-treat-strip-pgp gnus-article-hide-pgp)
    (gnus-treat-strip-pem gnus-article-hide-pem)
    (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-date-ut gnus-article-date-ut)
    (gnus-treat-date-local gnus-article-date-local)
    (gnus-treat-date-lapsed gnus-article-date-lapsed)
    (gnus-treat-date-original gnus-article-date-original)
    (gnus-treat-date-user-defined gnus-article-date-user)
    (gnus-treat-date-iso8601 gnus-article-date-iso8601)
    (gnus-treat-strip-trailing-blank-lines
     gnus-article-remove-trailing-blank-lines)
    (gnus-treat-strip-leading-blank-lines
     gnus-article-strip-leading-blank-lines)
    (gnus-treat-strip-multiple-blank-lines
     gnus-article-strip-multiple-blank-lines)
    (gnus-treat-overstrike gnus-article-treat-overstrike)
    (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
    (gnus-treat-display-smileys gnus-smiley-display)
    (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
    (gnus-treat-display-picons gnus-article-display-picons)
    (gnus-treat-play-sounds gnus-earcon-display)))

(defvar gnus-article-mime-handle-alist nil)
1043 1044 1045
(defvar article-lapsed-timer nil)
(defvar gnus-article-current-summary nil)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
(defvar gnus-article-mode-syntax-table
  (let ((table (copy-syntax-table text-mode-syntax-table)))
    (modify-syntax-entry ?- "w" table)
    (modify-syntax-entry ?> ")" table)
    (modify-syntax-entry ?< "(" table)
    table)
  "Syntax table used in article mode buffers.
Initialized from `text-mode-syntax-table.")

(defvar gnus-save-article-buffer nil)

(defvar gnus-article-mode-line-format-alist
1058 1059
  (nconc '((?w (gnus-article-wash-status) ?s)
	   (?m (gnus-article-mime-part-status) ?s))
1060
	 gnus-summary-mode-line-format-alist))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1061 1062 1063 1064 1065 1066 1067

(defvar gnus-number-of-articles-to-be-saved nil)

(defvar gnus-inhibit-hiding nil)

(defsubst gnus-article-hide-text (b e props)
  "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1068
  (gnus-add-text-properties-when 'article-type nil b e props)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1069 1070 1071 1072
  (when (memq 'intangible props)
    (put-text-property
     (max (1- b) (point-min))
     b 'intangible (cddr (memq 'intangible props)))))
1073

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1074 1075 1076 1077 1078 1079 1080 1081 1082
(defsubst gnus-article-unhide-text (b e)
  "Remove hidden text properties from region between B and E."
  (remove-text-properties b e gnus-hidden-properties)
  (when (memq 'intangible gnus-hidden-properties)
    (put-text-property (max (1- b) (point-min))
		       b 'intangible nil)))

(defun gnus-article-hide-text-type (b e type)
  "Hide text of TYPE between B and E."
1083
  (push type gnus-article-wash-types)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1084 1085 1086 1087
  (gnus-article-hide-text
   b e (cons 'article-type (cons type gnus-hidden-properties))))

(defun gnus-article-unhide-text-type (b e type)
1088
  "Unhide text of TYPE between B and E."
1089 1090
  (setq gnus-article-wash-types
	(delq type gnus-article-wash-types))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
  (remove-text-properties
   b e (cons 'article-type (cons type gnus-hidden-properties)))
  (when (memq 'intangible gnus-hidden-properties)
    (put-text-property (max (1- b) (point-min))
		       b 'intangible nil)))

(defun gnus-article-hide-text-of-type (type)
  "Hide text of TYPE in the current buffer."
  (save-excursion
    (let ((b (point-min))
	  (e (point-max)))
      (while (setq b (text-property-any b e 'article-type type))
	(add-text-properties b (incf b) gnus-hidden-properties)))))

(defun gnus-article-delete-text-of-type (type)
  "Delete text of TYPE in the current buffer."
  (save-excursion
1108 1109 1110 1111 1112
    (let ((b (point-min)))
      (while (setq b (text-property-any b (point-max) 'article-type type))
	(delete-region
	 b (or (text-property-not-all b (point-max) 'article-type type)
	       (point-max)))))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1113 1114 1115 1116

(defun gnus-article-delete-invisible-text ()
  "Delete all invisible text in the current buffer."
  (save-excursion
1117 1118 1119 1120 1121
    (let ((b (point-min)))
      (while (setq b (text-property-any b (point-max) 'invisible t))
	(delete-region
	 b (or (text-property-not-all b (point-max) 'invisible t)
	       (point-max)))))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138

(defun gnus-article-text-type-exists-p (type)
  "Say whether any text of type TYPE exists in the buffer."
  (text-property-any (point-min) (point-max) 'article-type type))

(defsubst gnus-article-header-rank ()
  "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
  (let ((list gnus-sorted-header-list)
	(i 0))
    (while list
      (when (looking-at (car list))
	(setq list nil))
      (setq list (cdr list))
      (incf i))
    i))

(defun article-hide-headers (&optional arg delete)
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
  "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.
	    (push 'headers gnus-article-wash-types)
	    (add-text-properties (point-min) (+ 5 (point-min))
				 '(article-type headers dummy-invisible t))
	    (delete-region beg (point-max))))))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206

(defun article-hide-boring-headers (&optional arg)
  "Toggle hiding of headers that aren't very interesting.
If given a negative prefix, always show; if given a positive prefix,
always hide."
  (interactive (gnus-article-hidden-arg))
  (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
	     (not gnus-show-all-headers))
    (save-excursion
      (save-restriction
	(let ((buffer-read-only nil)
	      (list gnus-boring-article-headers)
	      (inhibit-point-motion-hooks t)
	      elem)
1207
	  (article-narrow-to-head)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1208 1209 1210 1211 1212 1213
	  (while list
	    (setq elem (pop list))
	    (goto-char (point-min))
	    (cond
	     ;; Hide empty headers.
	     ((eq elem 'empty)
1214
	      (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
		(forward-line -1)
		(gnus-article-hide-text-type
		 (progn (beginning-of-line) (point))
		 (progn
		   (end-of-line)
		   (if (re-search-forward "^[^ \t]" nil t)
		       (match-beginning 0)
		     (point-max)))
		 'boring-headers)))
	     ;; Hide boring Newsgroups header.
	     ((eq elem 'newsgroups)
	      (when (equal (gnus-fetch-field "newsgroups")
			   (gnus-group-real-name
			    (if (boundp 'gnus-newsgroup-name)
				gnus-newsgroup-name
			      "")))
		(gnus-article-hide-header "newsgroups")))
	     ((eq elem 'followup-to)
	      (when (equal (message-fetch-field "followup-to")
			   (message-fetch-field "newsgroups"))
		(gnus-article-hide-header "followup-to")))
	     ((eq elem 'reply-to)
	      (let ((from (message-fetch-field "from"))
		    (reply-to (message-fetch-field "reply-to")))
		(when (and
		       from reply-to
		       (ignore-errors
			 (equal
			  (nth 1 (mail-extract-address-components from))
			  (nth 1 (mail-extract-address-components reply-to)))))
		  (gnus-article-hide-header "reply-to"))))
	     ((eq elem 'date)
	      (let ((date (message-fetch-field "date")))
		(when (and date
1249
			   (< (days-between (current-time-string) date)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1250
			      4))
1251 1252
		  (gnus-article-hide-header "date"))))
	     ((eq elem 'long-to)
1253 1254
	      (let ((to (message-fetch-field "to"))
		    (cc (message-fetch-field "cc")))
1255
		(when (> (length to) 1024)
1256 1257 1258
		  (gnus-article-hide-header "to"))
		(when (> (length cc) 1024)
		  (gnus-article-hide-header "cc"))))
1259
	     ((eq elem 'many-to)
1260 1261
	      (let ((to-count 0)
		    (cc-count 0))
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
		(goto-char (point-min))
		(while (re-search-forward "^to:" nil t)
		  (setq to-count (1+ to-count)))
		(when (> to-count 1)
		  (while (> to-count 0)
		    (goto-char (point-min))
		    (save-restriction
		      (re-search-forward "^to:" nil nil to-count)
		      (forward-line -1)
		      (narrow-to-region (point) (point-max))
		      (gnus-article-hide-header "to"))
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
		    (setq to-count (1- to-count))))
		(goto-char (point-min))
		(while (re-search-forward "^cc:" nil t)
		  (setq cc-count (1+ cc-count)))
		(when (> cc-count 1)
		  (while (> cc-count 0)
		    (goto-char (point-min))
		    (save-restriction
		      (re-search-forward "^cc:" nil nil cc-count)
		      (forward-line -1)
		      (narrow-to-region (point) (point-max))
		      (gnus-article-hide-header "cc"))
		    (setq cc-count (1- cc-count)))))))))))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299

(defun gnus-article-hide-header (header)
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward (concat "^" header ":") nil t)
      (gnus-article-hide-text-type
       (progn (beginning-of-line) (point))
       (progn
	 (end-of-line)
	 (if (re-search-forward "^[^ \t]" nil t)
	     (match-beginning 0)
	   (point-max)))
       'boring-headers))))

1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
(defvar gnus-article-normalized-header-length 40
  "Length of normalized headers.")

(defun article-normalize-headers ()
  "Make all header lines 40 characters long."
  (interactive)
  (let ((buffer-read-only nil)
	column)
    (save-excursion
      (save-restriction
	(article-narrow-to-head)
	(while (not (eobp))
	  (cond
	   ((< (setq column (- (gnus-point-at-eol) (point)))
	       gnus-article-normalized-header-length)
	    (end-of-line)
	    (insert (make-string
		     (- gnus-article-normalized-header-length column)
		     ? )))
	   ((> column gnus-article-normalized-header-length)
	    (gnus-put-text-property
	     (progn
	       (forward-char gnus-article-normalized-header-length)
	       (point))
	     (gnus-point-at-eol)
	     'invisible t))
	   (t
	    ;; Do nothing.
	    ))
	  (forward-line 1))))))

1331
(defun article-treat-dumbquotes ()
1332
  "Translate M****s*** sm*rtq**t*s into proper text.
1333
Note that this function guesses whether a character is a sm*rtq**t* or
1334 1335 1336 1337 1338 1339
not, so it should only be used interactively.

Sm*rtq**t*s are M****s***'s unilateral extension to the character map
in an attempt to provide more quoting characters.  If you see
something like \\222 or \\264 where you're expecting some kind of
apostrophe or quotation mark, then try this wash."
1340
  (interactive)
1341
  (article-translate-strings gnus-article-dumbquotes-map))
1342 1343 1344 1345 1346 1347

(defun article-translate-characters (from to)
  "Translate all characters in the body of the article according to FROM and TO.
FROM is a string of characters to translate from; to is a string of
characters to translate to."
  (save-excursion
1348
    (when (article-goto-body)
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
      (let ((buffer-read-only nil)
	    (x (make-string 225 ?x))
	    (i -1))
	(while (< (incf i) (length x))
	  (aset x i i))
	(setq i 0)
	(while (< i (length from))
	  (aset x (aref from i) (aref to i))
	  (incf i))
	(translate-region (point) (point-max) x)))))

1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
(defun article-translate-strings (map)
  "Translate all string in the body of the article according to MAP.
MAP is an alist where the elements are on the form (\"from\" \"to\")."
  (save-excursion
    (when (article-goto-body)
      (let ((buffer-read-only nil)
	    elem)
	(while (setq elem (pop map))
	  (save-excursion
	    (while (search-forward (car elem) nil t)
	      (replace-match (cadr elem)))))))))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1372 1373 1374 1375
(defun article-treat-overstrike ()
  "Translate overstrikes into bold text."
  (interactive)
  (save-excursion
1376
    (when (article-goto-body)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1377 1378
      (let ((buffer-read-only nil))
	(while (search-forward "\b" nil t)
1379
	  (let ((next (char-after))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
		(previous (char-after (- (point) 2))))
	    ;; 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))
	     ((eq next ?_)
	      (gnus-article-hide-text-type
	       (1- (point)) (1+ (point)) 'overstrike)
	      (put-text-property
	       (- (point) 2) (1- (point)) 'face 'underline))
	     ((eq previous ?_)
	      (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
	      (put-text-property
	       (point) (1+ (point)) 'face 'underline)))))))))

1398 1399
(defun article-fill-long-lines ()
  "Fill lines that are wider than the window width."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1400 1401
  (interactive)
  (save-excursion
1402 1403 1404 1405
    (let ((buffer-read-only nil)
	  (width (window-width (get-buffer-window (current-buffer)))))
      (save-restriction
	(article-goto-body)
1406
	(let ((adaptive-fill-mode nil)) ;Why?  -sm
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
	  (while (not (eobp))
	    (end-of-line)
	    (when (>= (current-column) (min fill-column width))
	      (narrow-to-region (point) (gnus-point-at-bol))
	      (fill-paragraph nil)
	      (goto-char (point-max))
	      (widen))
	    (forward-line 1)))))))

(defun article-capitalize-sentences ()
  "Capitalize the first word in each sentence."
  (interactive)
  (save-excursion
    (let ((buffer-read-only nil)
	  (paragraph-start "^[\n\^L]"))
      (article-goto-body)
      (while (not (eobp))
	(capitalize-word 1)
	(forward-sentence)))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1426 1427

(defun article-remove-cr ()
1428
  "Remove trailing CRs and then translate remaining CRs into LFs."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1429 1430 1431 1432
  (interactive)
  (save-excursion
    (let ((buffer-read-only nil))
      (goto-char (point-min))
1433 1434 1435
      (while (re-search-forward "\r+$" nil t)
	(replace-match "" t t))
      (goto-char (point-min))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1436
      (while (search-forward "\r" nil t)
1437
	(replace-match "\n" t t)))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448

(defun article-remove-trailing-blank-lines ()
  "Remove all trailing blank lines from the article."
  (interactive)
  (save-excursion
    (let ((buffer-read-only nil))
      (goto-char (point-max))
      (delete-region
       (point)
       (progn
	 (while (and (not (bobp))
1449 1450 1451
		     (looking-at "^[ \t]*$")
		     (not (gnus-annotation-in-region-p
			   (point) (gnus-point-at-eol))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
	   (forward-line -1))
	 (forward-line 1)
	 (point))))))

(defun article-display-x-face (&optional force)
  "Look for an X-Face header and display it if present."
  (interactive (list 'force))
  (save-excursion
    ;; Delete the old process, if any.
    (when (process-status "article-x-face")
      (delete-process "article-x-face"))
    (let ((inhibit-point-motion-hooks t)
1464 1465
	  (case-fold-search t)
	  from last)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1466
      (save-restriction
1467 1468
	(article-narrow-to-head)
	(goto-char (point-min))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1469 1470
	(setq from (message-fetch-field "from"))
	(goto-char (point-min))
1471
	(while (and gnus-article-x-face-command
1472
		    (not last)
1473 1474 1475 1476 1477 1478 1479 1480
		    (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))))
		    ;; Has to be present.
		    (re-search-forward "^X-Face: " nil t))
1481 1482 1483 1484 1485 1486
	  ;; This used to try to do multiple faces (`while' instead of
	  ;; `when' above), but (a) sending multiple EOFs to xv doesn't
	  ;; work (b) it can crash some versions of Emacs (c) are
	  ;; multiple faces really something to encourage?
	  (when (stringp gnus-article-x-face-command)
	    (setq last t))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1487
	  ;; We now have the area of the buffer where the X-Face is stored.
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506
	  (save-excursion
	    (let ((beg (point))
		  (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
	      ;; 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 beg end)
		    (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))
		  (process-send-region "article-x-face" beg end)
		  (process-send-eof "article-x-face"))))))))))

1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533
(defun article-decode-mime-words ()
  "Decode all MIME-encoded words in the article."
  (interactive)
  (save-excursion
    (set-buffer gnus-article-buffer)
    (let ((inhibit-point-motion-hooks t)
	  buffer-read-only
	  (mail-parse-charset gnus-newsgroup-charset)
	  (mail-parse-ignored-charsets 
	   (save-excursion (set-buffer gnus-summary-buffer)
			   gnus-newsgroup-ignored-charsets)))
      (mail-decode-encoded-word-region (point-min) (point-max)))))

(defun article-decode-charset (&optional prompt)
  "Decode charset-encoded text in the article.
If PROMPT (the prefix), prompt for a coding system to use."
  (interactive "P")
  (let ((inhibit-point-motion-hooks t) (case-fold-search t)
	buffer-read-only
	(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))
	ct cte ctl charset format)
  (save-excursion
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1534
    (save-restriction
1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
      (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)))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1579 1580

(defun article-de-quoted-unreadable (&optional force)
1581
  "Translate a quoted-printable-encoded article.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1582 1583 1584 1585
If FORCE, decode the article whether it is marked as quoted-printable
or not."
  (interactive (list 'force))
  (save-excursion
Dave Love's avatar
Dave Love committed
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
    (let ((buffer-read-only nil) type charset)
      (if (gnus-buffer-live-p gnus-original-article-buffer)
	  (with-current-buffer gnus-original-article-buffer
	    (setq type
		  (gnus-fetch-field "content-transfer-encoding"))
	    (let* ((ct (gnus-fetch-field "content-type"))
		   (ctl (and ct 
			     (ignore-errors
			       (mail-header-parse-content-type ct)))))
	      (setq charset (and ctl
				 (mail-content-type-get ctl 'charset)))
	      (if (stringp charset)
		  (setq charset (intern (downcase charset)))))))
      (unless charset 
	(setq charset gnus-newsgroup-charset))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1601
      (when (or force
Dave Love's avatar
Dave Love committed
1602 1603
		(and type (let ((case-fold-search t))
			    (string-match "quoted-printable" type))))
1604
	(article-goto-body)
Dave Love's avatar
Dave Love committed
1605 1606
	(quoted-printable-decode-region
	 (point) (point-max) (mm-charset-to-coding-system charset))))))