gnus-art.el 162 KB
Newer Older
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1
;;; gnus-art.el --- article mode commands for Gnus
2
;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
3

4
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
;; 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:

28 29
(eval-when-compile (require 'cl))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
30 31 32 33
(require 'gnus)
(require 'gnus-sum)
(require 'gnus-spec)
(require 'gnus-int)
34 35 36 37 38 39
(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
40 41 42 43 44 45

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

46 47 48 49 50
(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
51 52 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
(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
103 104 105 106 107 108 109 110 111 112 113 114 115 116
  '("^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:"
117
    "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118
    "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 120 121 122 123 124 125 126 127 128 129
    "^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:")
130
  "*All headers that start with this regexp will be hidden.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
131 132 133 134 135 136 137 138
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
139
  "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
140
  "*All headers that do not match this regexp will be hidden.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
141 142 143 144 145 146 147 148 149 150 151 152 153
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:")
154
  "*This variable is a list of regular expressions.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
155 156 157 158 159 160 161 162 163
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',
164
`reply-to', `date', `long-to', and `many-to'."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
165 166 167 168
  :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)
169
	      (const :tag "Date less than four days old." date)
170 171
	      (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
172 173 174 175 176 177 178 179 180 181 182
  :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
183
  "Provide a limit to what is considered a signature.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
184 185 186 187 188 189
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."
190 191 192 193
  :type '(choice (integer :value 200)
		 (number :value 4.0)
		 (function :value fun)
		 (regexp :value ".*"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
194 195 196 197 198 199 200
  :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)

201 202 203
;; 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
204
(defcustom gnus-article-x-face-command
205 206 207 208
  (if (and (fboundp 'image-type-available-p)
	   (image-type-available-p 'xbm))
      'gnus-article-display-xface
    "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -")
209
  "*String or function to be executed to display an X-Face header.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
210 211
If it is a string, the command will be executed in a sub-shell
asynchronously.	 The compressed face will be piped to this command."
212 213 214
  :type '(choice string
		 (function-item gnus-article-display-xface)
		 function)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
215 216 217 218
  :group 'gnus-article-washing)

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

(defcustom gnus-emphasis-alist
  (let ((format
224
	 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238
	(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))
239
	    2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
240
	 types)))
241
  "*Alist that says how to fontify certain phrases.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
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)

258 259 260 261 262 263 264 265
(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."
  :group 'gnus-article-emphasis
  :type 'regexp)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
(defface gnus-emphasis-bold '((t (:bold t)))
  "Face used for displaying strong emphasized text (*word*)."
  :group 'gnus-article-emphasis)

(defface gnus-emphasis-italic '((t (:italic t)))
  "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)

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

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

(defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
  "Face used for displaying bold italic emphasized text (/*word*/)."
  :group 'gnus-article-emphasis)

(defface gnus-emphasis-underline-bold-italic
  '((t (:bold t :italic t :underline t)))
  "Face used for displaying underlined bold italic emphasized text.
Esample: (_/*word*/_)."
  :group 'gnus-article-emphasis)

296 297 298 299 300
(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
301 302
(defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
  "Format for display of Date headers in article bodies.
303 304 305 306 307 308
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
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
  :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)
331
		 (sexp :tag "once" :format "%t\n" :value t)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
332 333 334 335 336 337 338

(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
339
  :type 'regexp)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 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

(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))
390
  "*Variable used to suggest where articles are to be saved.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
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
410 411 412
  :type '(repeat (choice (list :value (fun) function)
			 (cons :value ("" "") regexp (repeat string))
			 (sexp :value nil))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
413 414 415 416 417 418 419 420

(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)

421
(defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
422
  "*The format specification for the article mode line.
423 424 425 426 427 428
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
429 430 431 432 433 434 435 436 437 438 439 440 441 442
  :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
443
  "*A hook called after an article has been prepared in the article buffer."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
444 445 446
  :type 'hook
  :group 'gnus-article-various)

447 448 449
(defcustom gnus-article-hide-pgp-hook nil
  "*A hook called after successfully hiding a PGP signature."
  :type 'hook
450
  :group 'gnus-article-various)
451

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
(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)

468 469 470
(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
471 472 473 474
  :type 'face
  :group 'gnus-article-highlight
  :group 'gnus-article-signature)

475
(defface gnus-signature-face
476
  '((t
477 478 479 480 481
     (:italic t)))
  "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
482 483 484
(defface gnus-header-from-face
  '((((class color)
      (background dark))
485
     (:foreground "spring green"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
486 487
    (((class color)
      (background light))
488
     (:foreground "red3"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
489
    (t
490
     (:italic t)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
491 492 493 494 495 496 497
  "Face used for displaying from headers."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defface gnus-header-subject-face
  '((((class color)
      (background dark))
498
     (:foreground "SeaGreen3"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
499 500
    (((class color)
      (background light))
501
     (:foreground "red4"))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
502 503 504 505 506 507 508 509 510
    (t
     (:bold t :italic t)))
  "Face used for displaying subject headers."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defface gnus-header-newsgroups-face
  '((((class color)
      (background dark))
511
     (:foreground "yellow" :italic t))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
512 513
    (((class color)
      (background light))
514
     (:foreground "MidnightBlue" :italic t))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
515
    (t
516
     (:italic t)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
  "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
     (:bold t)))
  "Face used for displaying header names."
  :group 'gnus-article-headers
  :group 'gnus-article-highlight)

(defface gnus-header-content-face
  '((((class color)
      (background dark))
     (:foreground "forest green" :italic t))
    (((class color)
      (background light))
     (:foreground "indianred4" :italic t))
    (t
     (:italic t)))  "Face used for displaying header content."
  :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))
551
  "*Controls highlighting of article header.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571

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)))))

572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 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 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 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 740 741 742 743 744 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 794 795 796 797 798 799 800 801 802 803 804 805 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
(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" "*")
    ("\226" "---")
    ("\227" "-")
    ("\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."
  :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."
  :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
  "An alist of MIME types to functions to display them.")

(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)."
  :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."
  :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)))

;;;
;;; 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)

(defcustom gnus-treat-emphasize 50000
  "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)

(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."
  :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."
  :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."
  :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
874 875 876
(defcustom gnus-treat-display-xface 
  (and (or (and (fboundp 'image-type-available-p)
		(image-type-available-p 'xbm))
877
	   (and (featurep 'xemacs) (featurep 'xface)))
Dave Love's avatar
Dave Love committed
878
       'head)
879 880 881 882 883 884 885
  "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
  :type gnus-article-treat-head-custom)
(put 'gnus-treat-display-xface 'highlight t)

886
(defcustom gnus-treat-display-smileys (if (and (featurep 'xemacs)
887 888 889 890 891 892 893 894 895
					       (featurep 'xpm))
					  t nil)
  "Display smileys.
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-display-smileys 'highlight t)

896
(defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
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 928 929 930 931
  "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."
  :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."
  :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."
  :group 'gnus-article-treat
  :type gnus-article-treat-custom)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
932 933
;;; Internal variables

934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
(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)
    (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)
979 980 981
(defvar article-lapsed-timer nil)
(defvar gnus-article-current-summary nil)

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
982 983 984 985 986 987 988 989 990 991 992 993
(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
994 995
  (nconc '((?w (gnus-article-wash-status) ?s)
	   (?m (gnus-article-mime-part-status) ?s))
996
	 gnus-summary-mode-line-format-alist))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017

(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."
  (add-text-properties b e props)
  (when (memq 'intangible props)
    (put-text-property
     (max (1- b) (point-min))
     b 'intangible (cddr (memq 'intangible props)))))
(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."
1018
  (push type gnus-article-wash-types)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1019 1020 1021 1022
  (gnus-article-hide-text
   b e (cons 'article-type (cons type gnus-hidden-properties))))

(defun gnus-article-unhide-text-type (b e type)
1023
  "Unhide text of TYPE between B and E."
1024 1025
  (setq gnus-article-wash-types
	(delq type gnus-article-wash-types))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
  (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
1043 1044 1045 1046 1047
    (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
1048 1049 1050 1051

(defun gnus-article-delete-invisible-text ()
  "Delete all invisible text in the current buffer."
  (save-excursion
1052 1053 1054 1055 1056
    (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
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073

(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)
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
  "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
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141

(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)
1142
	  (article-narrow-to-head)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1143 1144 1145 1146 1147 1148
	  (while list
	    (setq elem (pop list))
	    (goto-char (point-min))
	    (cond
	     ;; Hide empty headers.
	     ((eq elem 'empty)
1149
	      (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
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
		(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
1184
			   (< (days-between (current-time-string) date)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1185
			      4))
1186 1187
		  (gnus-article-hide-header "date"))))
	     ((eq elem 'long-to)
1188 1189
	      (let ((to (message-fetch-field "to"))
		    (cc (message-fetch-field "cc")))
1190
		(when (> (length to) 1024)
1191 1192 1193
		  (gnus-article-hide-header "to"))
		(when (> (length cc) 1024)
		  (gnus-article-hide-header "cc"))))
1194
	     ((eq elem 'many-to)
1195 1196
	      (let ((to-count 0)
		    (cc-count 0))
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
		(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"))
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
		    (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
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234

(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))))

1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
(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))))))

1266
(defun article-treat-dumbquotes ()
1267 1268 1269
  "Translate M******** sm*rtq**t*s into proper text.
Note that this function guesses whether a character is a sm*rtq**t* or
not, so it should only be used interactively."
1270
  (interactive)
1271
  (article-translate-strings gnus-article-dumbquotes-map))
1272 1273 1274 1275 1276 1277

(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
1278
    (when (article-goto-body)
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
      (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)))))

1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
(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
1302 1303 1304 1305
(defun article-treat-overstrike ()
  "Translate overstrikes into bold text."
  (interactive)
  (save-excursion
1306
    (when (article-goto-body)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1307 1308
      (let ((buffer-read-only nil))
	(while (search-forward "\b" nil t)
1309
	  (let ((next (char-after))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
		(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)))))))))

1328 1329
(defun article-fill-long-lines ()
  "Fill lines that are wider than the window width."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1330 1331
  (interactive)
  (save-excursion
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
    (let ((buffer-read-only nil)
	  (width (window-width (get-buffer-window (current-buffer)))))
      (save-restriction
	(article-goto-body)
	(let ((adaptive-fill-mode nil))
	  (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
1356 1357

(defun article-remove-cr ()
1358
  "Remove trailing CRs and then translate remaining CRs into LFs."
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1359 1360 1361 1362
  (interactive)
  (save-excursion
    (let ((buffer-read-only nil))
      (goto-char (point-min))
1363 1364 1365
      (while (re-search-forward "\r+$" nil t)
	(replace-match "" t t))
      (goto-char (point-min))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1366
      (while (search-forward "\r" nil t)
1367
	(replace-match "\n" t t)))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378

(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))
1379 1380 1381
		     (looking-at "^[ \t]*$")
		     (not (gnus-annotation-in-region-p
			   (point) (gnus-point-at-eol))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
	   (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)
1394 1395
	  (case-fold-search t)
	  from last)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1396
      (save-restriction
1397 1398
	(article-narrow-to-head)
	(goto-char (point-min))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1399 1400
	(setq from (message-fetch-field "from"))
	(goto-char (point-min))
1401
	(while (and gnus-article-x-face-command
1402
		    (not last)
1403 1404 1405 1406 1407 1408 1409 1410
		    (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))
1411 1412 1413 1414 1415 1416
	  ;; 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
1417
	  ;; We now have the area of the buffer where the X-Face is stored.
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
	  (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"))))))))))

1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
(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
1464
    (save-restriction
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
      (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
1509 1510

(defun article-de-quoted-unreadable (&optional force)
1511
  "Translate a quoted-printable-encoded article.
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1512 1513 1514 1515
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
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
    (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
1531
      (when (or force
Dave Love's avatar
Dave Love committed
1532 1533
		(and type (let ((case-fold-search t))
			    (string-match "quoted-printable" type))))
1534
	(article-goto-body)
Dave Love's avatar
Dave Love committed
1535 1536
	(quoted-printable-decode-region
	 (point) (point-max) (mm-charset-to-coding-system charset))))))
1537 1538 1539 1540 1541 1542

(defun article-de-base64-unreadable (&optional force)
  "Translate a base64 article.
If FORCE, decode the article whether it is marked as base64 not."
  (interactive (list 'force))
  (save-excursion
Dave Love's avatar
Dave Love committed
1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
    (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))
1558
      (when (or force
Dave Love's avatar
Dave Love committed
1559 1560
		(and type (let ((case-fold-search t))
			    (string-match "base64" type))))
1561 1562 1563 1564
	(article-goto-body)
	(save-restriction
	  (narrow-to-region (point) (point-max))
	  (base64-decode-region (point-min) (point-max))
Dave Love's avatar
Dave Love committed
1565 1566
	  (mm-decode-coding-region
	   (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583

(eval-when-compile
  (require 'rfc1843))

(defun article-decode-HZ ()
  "Translate a HZ-encoded article."
  (interactive)
  (require 'rfc1843)
  (save-excursion
    (let ((buffer-read-only nil))
      (rfc1843-decode-region (point-min) (point-max)))))

(defun article-wash-html ()
  "Format an html article."
  (interactive)
  (save-excursion
    (let ((buffer-read-only nil)
Dave Love's avatar
Dave Love committed
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
	  charset)
      (if (gnus-buffer-live-p gnus-original-article-buffer)
	  (with-current-buffer gnus-original-article-buffer
	    (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))
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
      (article-goto-body)
      (save-window-excursion
	(save-restriction
	  (narrow-to-region (point) (point-max))
	  (mm-setup-w3)
	  (let ((w3-strict-width (window-width))
		(url-standalone-mode t))
	    (condition-case var
		(w3-region (point-min) (point-max))
	      (error))))))))

(defun article-hide-list-identifiers ()
  "Remove list identifies from the Subject header.
The `gnus-list-identifiers' variable specifies what to do."
  (interactive)
  (save-excursion
    (save-restriction
      (let ((inhibit-point-motion-hooks t)
	    buffer-read-only)
	(article-narrow-to-head)
	(let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
			(mapconcat 'identity gnus-list-identifiers " *\\|"))))
	  (when regexp
	    (goto-char (point-min))
	    (when (re-search-forward
		   (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp 
			   " *\\)\\)+\\(Re: +\\)?\\)")
		   nil t)
	      (let ((s (or (match-string 3) (match-string 5))))
		(delete-region (match-beginning 1) (match-end 1))
		(when s
		  (goto-char (match-beginning 1))
		  (insert s))))))))))

(defun article-hide-pgp ()
  "Remove any PGP headers and signatures in the current article."
  (interactive)
  (save-excursion
    (save-restriction
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1636 1637
      (let ((inhibit-point-motion-hooks t)
	    buffer-read-only beg end)
1638
	(article-goto-body)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1639
	;; Hide the "header".
1640 1641 1642 1643 1644 1645
	(when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
	  (push 'pgp gnus-article-wash-types)
	  (delete-region (match-beginning 0) (match-end 0))
	  ;; Remove armor headers (rfc2440 6.2)
	  (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
				     (point)))
1646 1647 1648 1649
	  (setq beg (point))
	  ;; Hide the actual signature.
	  (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
	       (setq end (1+ (match-beginning 0)))
1650
	       (delete-region
1651 1652 1653 1654 1655
		end
		(if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
		    (match-end 0)
		  ;; Perhaps we shouldn't hide to the end of the buffer
		  ;; if there is no end to the signature?
1656
		  (point-max))))
1657 1658 1659 1660 1661
	  ;; Hide "- " PGP quotation markers.
	  (when (and beg end)
	    (narrow-to-region beg end)
	    (goto-char (point-min))
	    (while (re-search-forward "^- " nil t)
1662 1663
	      (delete-region
	       (match-beginning 0) (match-end 0)))
1664
	    (widen))
1665
	  (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675

(defun article-hide-pem (&optional arg)
  "Toggle hiding of any PEM headers and signatures in the current article.
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 'pem arg)
    (save-excursion
      (let (buffer-read-only end)
	(goto-char (point-min))
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730
	;; Hide the horrendously ugly "header".
	(when (and (search-forward
		    "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
		    nil t)
		   (setq end (1+ (match-beginning 0))))
	  (push 'pem gnus-article-wash-types)
	  (gnus-article-hide-text-type
	   end
	   (if (search-forward "\n\n" nil t)
	       (match-end 0)
	     (point-max))
	   'pem)
	  ;; Hide the trailer as well
	  (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
				nil t)
	    (gnus-article-hide-text-type
	     (match-beginning 0) (match-end 0) 'pem)))))))

(defun article-strip-banner ()
  "Strip the banner specified by the `banner' group parameter."
  (interactive)
  (save-excursion
    (save-restriction
      (let ((inhibit-point-motion-hooks t)
	    (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
	    (gnus-signature-limit nil)
	    buffer-read-only beg end)
	(when banner
	  (article-goto-body)
	  (cond
	   ((eq banner 'signature)
	    (when (gnus-article-narrow-to-signature)
	      (widen)
	      (forward-line -1)
	      (delete-region (point) (point-max))))
	   ((stringp banner)
	    (while (re-search-forward banner nil t)
	      (delete-region (match-beginning 0) (match-end 0))))))))))

(defun article-babel ()
  "Translate article using an online translation service."
  (interactive)
  (require 'babel)
  (save-excursion
    (set-buffer gnus-article-buffer)
    (when (article-goto-body)
      (let* ((buffer-read-only nil)
	     (start (point))
	     (end (point-max))
	     (orig (buffer-substring start end))
             (trans (babel-as-string orig)))
	(save-restriction
	  (narrow-to-region start end)
	  (delete-region start end)
          (insert trans))))))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744

(defun article-hide-signature (&optional arg)
  "Hide the signature in the current article.
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)))))))

1745 1746 1747 1748 1749 1750 1751 1752 1753
(defun article-strip-headers-in-body ()
  "Strip offensive headers from bodies."
  (interactive)
  (save-excursion
    (article-goto-body)
    (let ((case-fold-search t))
      (when (looking-at "x-no-archive:")
	(gnus-delete-line)))))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1754 1755 1756 1757 1758 1759
(defun article-strip-leading-blank-lines ()
  "Remove all blank lines from the beginning of the article."
  (interactive)
  (save-excursion
    (let ((inhibit-point-motion-hooks t)
	  buffer-read-only)
1760
      (when (article-goto-body)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1761 1762 1763 1764
	(while (and (not (eobp))
		    (looking-at "[ \t]*$"))
	  (gnus-delete-line))))))

1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788
(defun article-narrow-to-head ()
  "Narrow the buffer to the head of the message.
Point is left at the beginning of the narrowed-to region."
  (narrow-to-region
   (goto-char (point-min))
   (if (search-forward "\n\n" nil 1)
       (1- (point))
     (point-max)))
  (goto-char (point-min)))

(defun article-goto-body ()
  "Place point at the start of the body."
  (goto-char (point-min))
  (cond
   ;; This variable is only bound when dealing with separate
   ;; MIME body parts.
   (article-goto-body-goes-to-point-min-p
    t)
   ((search-forward "\n\n" nil t)
    t)
   (t
    (goto-char (point-max))
    nil)))

Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1789 1790 1791 1792 1793 1794 1795
(defun article-strip-multiple-blank-lines ()
  "Replace consecutive blank lines with one empty line."
  (interactive)
  (save-excursion
    (let ((inhibit-point-motion-hooks t)
	  buffer-read-only)
      ;; First make all blank lines empty.
1796
      (article-goto-body)
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed
1797
      (while (re-search-forward "^[ \t]+$" nil t)
1798 1799 1800
	(unless (gnus-annotation-in-region-p
		 (match-beginning 0) (match-end 0))
	  (replace-match "" nil t)))
Lars Magne Ingebrigtsen's avatar
Lars Magne Ingebrigtsen committed