2001-09-28 07:00:00 ShengHuo ZHU <zsh@cs.rochester.edu>
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-sum)
33 (require 'gnus-spec)
34 (require 'gnus-int)
35 (require 'mm-bodies)
36 (require 'mail-parse)
37 (require 'mm-decode)
38 (require 'mm-view)
39 (require 'wid-edit)
40 (require 'mm-uu)
41
42 (autoload 'gnus-msg-mail "gnus-msg" nil t)
43 (autoload 'gnus-button-mailto "gnus-msg")
44 (autoload 'gnus-button-reply "gnus-msg" nil t)
45
46 (defgroup gnus-article nil
47   "Article display."
48   :link '(custom-manual "(gnus)The Article Buffer")
49   :group 'gnus)
50
51 (defgroup gnus-article-treat nil
52   "Treating article parts."
53   :link '(custom-manual "(gnus)Article Hiding")
54   :group 'gnus-article)
55
56 (defgroup gnus-article-hiding nil
57   "Hiding article parts."
58   :link '(custom-manual "(gnus)Article Hiding")
59   :group 'gnus-article)
60
61 (defgroup gnus-article-highlight nil
62   "Article highlighting."
63   :link '(custom-manual "(gnus)Article Highlighting")
64   :group 'gnus-article
65   :group 'gnus-visual)
66
67 (defgroup gnus-article-signature nil
68   "Article signatures."
69   :link '(custom-manual "(gnus)Article Signature")
70   :group 'gnus-article)
71
72 (defgroup gnus-article-headers nil
73   "Article headers."
74   :link '(custom-manual "(gnus)Hiding Headers")
75   :group 'gnus-article)
76
77 (defgroup gnus-article-washing nil
78   "Special commands on articles."
79   :link '(custom-manual "(gnus)Article Washing")
80   :group 'gnus-article)
81
82 (defgroup gnus-article-emphasis nil
83   "Fontisizing articles."
84   :link '(custom-manual "(gnus)Article Fontisizing")
85   :group 'gnus-article)
86
87 (defgroup gnus-article-saving nil
88   "Saving articles."
89   :link '(custom-manual "(gnus)Saving Articles")
90   :group 'gnus-article)
91
92 (defgroup gnus-article-mime nil
93   "Worshiping the MIME wonder."
94   :link '(custom-manual "(gnus)Using MIME")
95   :group 'gnus-article)
96
97 (defgroup gnus-article-buttons nil
98   "Pushable buttons in the article buffer."
99   :link '(custom-manual "(gnus)Article Buttons")
100   :group 'gnus-article)
101
102 (defgroup gnus-article-various nil
103   "Other article options."
104   :link '(custom-manual "(gnus)Misc Article")
105   :group 'gnus-article)
106
107 (defcustom gnus-ignored-headers
108   '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
109     "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
110     "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
111     "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
112     "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
113     "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
114     "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
115     "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
116     "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
117     "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
118     "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
119     "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
120     "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
121     "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
122     "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
123     "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
124     "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
125     "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
126     "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
127     "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
128     "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
129     "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
130     "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
131     "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
132     "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
133     "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
134     "^X-Received:" "^Content-length:" "X-precedence:"
135     "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
136     "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
137     "^X-Abuse-Info:" "^X-From_:" "^X-Accept-Language:" "^Errors-To:"
138     "^X-BeenThere:" "^X-Mailman-Version:" "^List-Help:" "^List-Post:"
139     "^List-Subscribe:" "^List-Id:" "^List-Unsubscribe:" "^List-Archive:"
140      "^X-Content-length:" "^X-Posting-Agent:" "^Original-Received:")
141   "*All headers that start with this regexp will be hidden.
142 This variable can also be a list of regexps of headers to be ignored.
143 If `gnus-visible-headers' is non-nil, this variable will be ignored."
144   :type '(choice :custom-show nil
145                  regexp
146                  (repeat regexp))
147   :group 'gnus-article-hiding)
148
149 (defcustom gnus-visible-headers
150   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
151   "*All headers that do not match this regexp will be hidden.
152 This variable can also be a list of regexp of headers to remain visible.
153 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
154   :type '(repeat :value-to-internal (lambda (widget value)
155                                       (custom-split-regexp-maybe value))
156                  :match (lambda (widget value)
157                           (or (stringp value)
158                               (widget-editable-list-match widget value)))
159                  regexp)
160   :group 'gnus-article-hiding)
161
162 (defcustom gnus-sorted-header-list
163   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
164     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
165   "*This variable is a list of regular expressions.
166 If it is non-nil, headers that match the regular expressions will
167 be placed first in the article buffer in the sequence specified by
168 this list."
169   :type '(repeat regexp)
170   :group 'gnus-article-hiding)
171
172 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
173   "Headers that are only to be displayed if they have interesting data.
174 Possible values in this list are:
175
176   'empty       Headers with no content.
177   'newsgroups  Newsgroup identical to Gnus group.
178   'to-address  To identical to To-address.
179   'followup-to Followup-to identical to Newsgroups.
180   'reply-to    Reply-to identical to From.
181   'date        Date less than four days old.
182   'long-to     To and/or Cc longer than 1024 characters.
183   'many-to     Multiple To and/or Cc."
184   :type '(set (const :tag "Headers with no content." empty)
185               (const :tag "Newsgroups identical to Gnus group." newsgroups)
186               (const :tag "To identical to To-address." to-address)
187               (const :tag "Followup-to identical to Newsgroups." followup-to)
188               (const :tag "Reply-to identical to From." reply-to)
189               (const :tag "Date less than four days old." date)
190               (const :tag "To and/or Cc longer than 1024 characters." long-to)
191               (const :tag "Multiple To and/or Cc headers." many-to))
192   :group 'gnus-article-hiding)
193
194 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
195   "Regexp matching signature separator.
196 This can also be a list of regexps.  In that case, it will be checked
197 from head to tail looking for a separator.  Searches will be done from
198 the end of the buffer."
199   :type '(repeat string)
200   :group 'gnus-article-signature)
201
202 (defcustom gnus-signature-limit nil
203   "Provide a limit to what is considered a signature.
204 If it is a number, no signature may not be longer (in characters) than
205 that number.  If it is a floating point number, no signature may be
206 longer (in lines) than that number.  If it is a function, the function
207 will be called without any parameters, and if it returns nil, there is
208 no signature in the buffer.  If it is a string, it will be used as a
209 regexp.  If it matches, the text in question is not a signature."
210   :type '(choice (integer :value 200)
211                  (number :value 4.0)
212                  (function :value fun)
213                  (regexp :value ".*"))
214   :group 'gnus-article-signature)
215
216 (defcustom gnus-hidden-properties '(invisible t intangible t)
217   "Property list to use for hiding text."
218   :type 'sexp
219   :group 'gnus-article-hiding)
220
221 ;; Fixme: This isn't the right thing for mixed graphical and and
222 ;; non-graphical frames in a session.
223 (defcustom gnus-article-x-face-command
224   (if (featurep 'xemacs)
225       (if (or (featurep 'xface)
226               (featurep 'xpm))
227           'gnus-xmas-article-display-xface
228         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
229     (if (and (fboundp 'image-type-available-p)
230              (image-type-available-p 'xbm))
231         'gnus-article-display-xface
232       (if gnus-article-compface-xbm
233           "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
234         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
235 display -")))
236   "*String or function to be executed to display an X-Face header.
237 If it is a string, the command will be executed in a sub-shell
238 asynchronously.  The compressed face will be piped to this command."
239   :type `(choice string
240                  (function-item 
241                   ,(if (featurep 'xemacs)
242                        'gnus-xmas-article-display-xface
243                      'gnus-article-display-xface))
244                  function)
245   :version "21.1"
246   :group 'gnus-article-washing)
247
248 (defcustom gnus-article-x-face-too-ugly nil
249   "Regexp matching posters whose face shouldn't be shown automatically."
250   :type '(choice regexp (const nil))
251   :group 'gnus-article-washing)
252
253 (defcustom gnus-article-banner-alist nil
254   "Banner alist for stripping.
255 For example,
256      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
257   :version "21.1"
258   :type '(repeat (cons symbol regexp))
259   :group 'gnus-article-washing)
260
261 (gnus-define-group-parameter
262  banner
263  :variable-document
264  "Alist of regexps (to match group names) and banner."
265  :variable-group gnus-article-washing
266  :parameter-type
267  '(choice :tag "Banner"
268           :value nil
269           (const :tag "Remove signature" signature)
270           (symbol :tag "Item in `gnus-article-banner-alist'" none)
271           regexp
272           (const :tag "None" nil))
273  :parameter-document
274  "If non-nil, specify how to remove `banners' from articles.
275
276 Symbol `signature' means to remove signatures delimited by
277 `gnus-signature-separator'.  Any other symbol is used to look up a
278 regular expression to match the banner in `gnus-article-banner-alist'.
279 A string is used as a regular expression to match the banner
280 directly.")
281
282 (defcustom gnus-emphasis-alist
283   (let ((format
284          "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
285         (types
286          '(("_" "_" underline)
287            ("/" "/" italic)
288            ("\\*" "\\*" bold)
289            ("_/" "/_" underline-italic)
290            ("_\\*" "\\*_" underline-bold)
291            ("\\*/" "/\\*" bold-italic)
292            ("_\\*/" "/\\*_" underline-bold-italic))))
293     `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
294        2 3 gnus-emphasis-underline)
295       ,@(mapcar
296          (lambda (spec)
297            (list
298             (format format (car spec) (cadr spec))
299             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
300          types)))
301   "*Alist that says how to fontify certain phrases.
302 Each item looks like this:
303
304   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
305
306 The first element is a regular expression to be matched.  The second
307 is a number that says what regular expression grouping used to find
308 the entire emphasized word.  The third is a number that says what
309 regexp grouping should be displayed and highlighted.  The fourth
310 is the face used for highlighting."
311   :type '(repeat (list :value ("" 0 0 default)
312                        regexp
313                        (integer :tag "Match group")
314                        (integer :tag "Emphasize group")
315                        face))
316   :group 'gnus-article-emphasis)
317
318 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
319   "A regexp to describe whitespace which should not be emphasized.
320 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
321 The former avoids underlining of leading and trailing whitespace,
322 and the latter avoids underlining any whitespace at all."
323   :version "21.1"
324   :group 'gnus-article-emphasis
325   :type 'regexp)
326
327 (defface gnus-emphasis-bold '((t (:bold t)))
328   "Face used for displaying strong emphasized text (*word*)."
329   :group 'gnus-article-emphasis)
330
331 (defface gnus-emphasis-italic '((t (:italic t)))
332   "Face used for displaying italic emphasized text (/word/)."
333   :group 'gnus-article-emphasis)
334
335 (defface gnus-emphasis-underline '((t (:underline t)))
336   "Face used for displaying underlined emphasized text (_word_)."
337   :group 'gnus-article-emphasis)
338
339 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
340   "Face used for displaying underlined bold emphasized text (_*word*_)."
341   :group 'gnus-article-emphasis)
342
343 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
344   "Face used for displaying underlined italic emphasized text (_/word/_)."
345   :group 'gnus-article-emphasis)
346
347 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
348   "Face used for displaying bold italic emphasized text (/*word*/)."
349   :group 'gnus-article-emphasis)
350
351 (defface gnus-emphasis-underline-bold-italic
352   '((t (:bold t :italic t :underline t)))
353   "Face used for displaying underlined bold italic emphasized text.
354 Esample: (_/*word*/_)."
355   :group 'gnus-article-emphasis)
356
357 (defface gnus-emphasis-highlight-words
358   '((t (:background "black" :foreground "yellow")))
359   "Face used for displaying highlighted words."
360   :group 'gnus-article-emphasis)
361
362 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
363   "Format for display of Date headers in article bodies.
364 See `format-time-string' for the possible values.
365
366 The variable can also be function, which should return a complete Date
367 header.  The function is called with one argument, the time, which can
368 be fed to `format-time-string'."
369   :type '(choice string symbol)
370   :link '(custom-manual "(gnus)Article Date")
371   :group 'gnus-article-washing)
372
373 (eval-and-compile
374   (autoload 'mail-extract-address-components "mail-extr"))
375
376 (defcustom gnus-save-all-headers t
377   "*If non-nil, don't remove any headers before saving."
378   :group 'gnus-article-saving
379   :type 'boolean)
380
381 (defcustom gnus-prompt-before-saving 'always
382   "*This variable says how much prompting is to be done when saving articles.
383 If it is nil, no prompting will be done, and the articles will be
384 saved to the default files.  If this variable is `always', each and
385 every article that is saved will be preceded by a prompt, even when
386 saving large batches of articles.  If this variable is neither nil not
387 `always', there the user will be prompted once for a file name for
388 each invocation of the saving commands."
389   :group 'gnus-article-saving
390   :type '(choice (item always)
391                  (item :tag "never" nil)
392                  (sexp :tag "once" :format "%t\n" :value t)))
393
394 (defcustom gnus-saved-headers gnus-visible-headers
395   "Headers to keep if `gnus-save-all-headers' is nil.
396 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
397 If that variable is nil, however, all headers that match this regexp
398 will be kept while the rest will be deleted before saving."
399   :group 'gnus-article-saving
400   :type 'regexp)
401
402 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
403   "A function to save articles in your favourite format.
404 The function must be interactively callable (in other words, it must
405 be an Emacs command).
406
407 Gnus provides the following functions:
408
409 * gnus-summary-save-in-rmail (Rmail format)
410 * gnus-summary-save-in-mail (Unix mail format)
411 * gnus-summary-save-in-folder (MH folder)
412 * gnus-summary-save-in-file (article format)
413 * gnus-summary-save-in-vm (use VM's folder format)
414 * gnus-summary-write-to-file (article format -- overwrite)."
415   :group 'gnus-article-saving
416   :type '(radio (function-item gnus-summary-save-in-rmail)
417                 (function-item gnus-summary-save-in-mail)
418                 (function-item gnus-summary-save-in-folder)
419                 (function-item gnus-summary-save-in-file)
420                 (function-item gnus-summary-save-in-vm)
421                 (function-item gnus-summary-write-to-file)))
422
423 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
424   "A function generating a file name to save articles in Rmail format.
425 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
426   :group 'gnus-article-saving
427   :type 'function)
428
429 (defcustom gnus-mail-save-name 'gnus-plain-save-name
430   "A function generating a file name to save articles in Unix mail format.
431 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
432   :group 'gnus-article-saving
433   :type 'function)
434
435 (defcustom gnus-folder-save-name 'gnus-folder-save-name
436   "A function generating a file name to save articles in MH folder.
437 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
438   :group 'gnus-article-saving
439   :type 'function)
440
441 (defcustom gnus-file-save-name 'gnus-numeric-save-name
442   "A function generating a file name to save articles in article format.
443 The function is called with NEWSGROUP, HEADERS, and optional
444 LAST-FILE."
445   :group 'gnus-article-saving
446   :type 'function)
447
448 (defcustom gnus-split-methods
449   '((gnus-article-archive-name)
450     (gnus-article-nndoc-name))
451   "*Variable used to suggest where articles are to be saved.
452 For instance, if you would like to save articles related to Gnus in
453 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
454 you could set this variable to something like:
455
456  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
457    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
458
459 This variable is an alist where the where the key is the match and the
460 value is a list of possible files to save in if the match is non-nil.
461
462 If the match is a string, it is used as a regexp match on the
463 article.  If the match is a symbol, that symbol will be funcalled
464 from the buffer of the article to be saved with the newsgroup as the
465 parameter.  If it is a list, it will be evaled in the same buffer.
466
467 If this form or function returns a string, this string will be used as
468 a possible file name; and if it returns a non-nil list, that list will
469 be used as possible file names."
470   :group 'gnus-article-saving
471   :type '(repeat (choice (list :value (fun) function)
472                          (cons :value ("" "") regexp (repeat string))
473                          (sexp :value nil))))
474
475 (defcustom gnus-page-delimiter "^\^L"
476   "*Regexp describing what to use as article page delimiters.
477 The default value is \"^\^L\", which is a form linefeed at the
478 beginning of a line."
479   :type 'regexp
480   :group 'gnus-article-various)
481
482 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
483   "*The format specification for the article mode line.
484 See `gnus-summary-mode-line-format' for a closer description.
485
486 The following additional specs are available:
487
488 %w  The article washing status.
489 %m  The number of MIME parts in the article."
490   :type 'string
491   :group 'gnus-article-various)
492
493 (defcustom gnus-article-mode-hook nil
494   "*A hook for Gnus article mode."
495   :type 'hook
496   :group 'gnus-article-various)
497
498 (when (featurep 'xemacs)
499   ;; Extracted from gnus-xmas-define in order to preserve user settings
500   (when (fboundp 'turn-off-scroll-in-place)
501     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
502   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
503   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
504
505 (defcustom gnus-article-menu-hook nil
506   "*Hook run after the creation of the article mode menu."
507   :type 'hook
508   :group 'gnus-article-various)
509
510 (defcustom gnus-article-prepare-hook nil
511   "*A hook called after an article has been prepared in the article buffer."
512   :type 'hook
513   :group 'gnus-article-various)
514
515 (defcustom gnus-article-hide-pgp-hook nil
516   "*A hook called after successfully hiding a PGP signature."
517   :type 'hook
518   :group 'gnus-article-various)
519
520 (defcustom gnus-article-button-face 'bold
521   "Face used for highlighting buttons in the article buffer.
522
523 An article button is a piece of text that you can activate by pressing
524 `RET' or `mouse-2' above it."
525   :type 'face
526   :group 'gnus-article-buttons)
527
528 (defcustom gnus-article-mouse-face 'highlight
529   "Face used for mouse highlighting in the article buffer.
530
531 Article buttons will be displayed in this face when the cursor is
532 above them."
533   :type 'face
534   :group 'gnus-article-buttons)
535
536 (defcustom gnus-signature-face 'gnus-signature-face
537   "Face used for highlighting a signature in the article buffer.
538 Obsolete; use the face `gnus-signature-face' for customizations instead."
539   :type 'face
540   :group 'gnus-article-highlight
541   :group 'gnus-article-signature)
542
543 (defface gnus-signature-face
544   '((t
545      (:italic t)))
546   "Face used for highlighting a signature in the article buffer."
547   :group 'gnus-article-highlight
548   :group 'gnus-article-signature)
549
550 (defface gnus-header-from-face
551   '((((class color)
552       (background dark))
553      (:foreground "spring green"))
554     (((class color)
555       (background light))
556      (:foreground "red3"))
557     (t
558      (:italic t)))
559   "Face used for displaying from headers."
560   :group 'gnus-article-headers
561   :group 'gnus-article-highlight)
562
563 (defface gnus-header-subject-face
564   '((((class color)
565       (background dark))
566      (:foreground "SeaGreen3"))
567     (((class color)
568       (background light))
569      (:foreground "red4"))
570     (t
571      (:bold t :italic t)))
572   "Face used for displaying subject headers."
573   :group 'gnus-article-headers
574   :group 'gnus-article-highlight)
575
576 (defface gnus-header-newsgroups-face
577   '((((class color)
578       (background dark))
579      (:foreground "yellow" :italic t))
580     (((class color)
581       (background light))
582      (:foreground "MidnightBlue" :italic t))
583     (t
584      (:italic t)))
585   "Face used for displaying newsgroups headers."
586   :group 'gnus-article-headers
587   :group 'gnus-article-highlight)
588
589 (defface gnus-header-name-face
590   '((((class color)
591       (background dark))
592      (:foreground "SeaGreen"))
593     (((class color)
594       (background light))
595      (:foreground "maroon"))
596     (t
597      (:bold t)))
598   "Face used for displaying header names."
599   :group 'gnus-article-headers
600   :group 'gnus-article-highlight)
601
602 (defface gnus-header-content-face
603   '((((class color)
604       (background dark))
605      (:foreground "forest green" :italic t))
606     (((class color)
607       (background light))
608      (:foreground "indianred4" :italic t))
609     (t
610      (:italic t)))  "Face used for displaying header content."
611   :group 'gnus-article-headers
612   :group 'gnus-article-highlight)
613
614 (defcustom gnus-header-face-alist
615   '(("From" nil gnus-header-from-face)
616     ("Subject" nil gnus-header-subject-face)
617     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
618     ("" gnus-header-name-face gnus-header-content-face))
619   "*Controls highlighting of article header.
620
621 An alist of the form (HEADER NAME CONTENT).
622
623 HEADER is a regular expression which should match the name of an
624 header header and NAME and CONTENT are either face names or nil.
625
626 The name of each header field will be displayed using the face
627 specified by the first element in the list where HEADER match the
628 header name and NAME is non-nil.  Similarly, the content will be
629 displayed by the first non-nil matching CONTENT face."
630   :group 'gnus-article-headers
631   :group 'gnus-article-highlight
632   :type '(repeat (list (regexp :tag "Header")
633                        (choice :tag "Name"
634                                (item :tag "skip" nil)
635                                (face :value default))
636                        (choice :tag "Content"
637                                (item :tag "skip" nil)
638                                (face :value default)))))
639
640 (defcustom gnus-article-decode-hook
641   '(article-decode-charset article-decode-encoded-words)
642   "*Hook run to decode charsets in articles."
643   :group 'gnus-article-headers
644   :type 'hook)
645
646 (defcustom gnus-display-mime-function 'gnus-display-mime
647   "Function to display MIME articles."
648   :group 'gnus-article-mime
649   :type 'function)
650
651 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
652   "Function used to decode headers.")
653
654 (defvar gnus-article-dumbquotes-map
655   '(("\200" "EUR")
656     ("\202" ",")
657     ("\203" "f")
658     ("\204" ",,")
659     ("\205" "...")
660     ("\213" "<")
661     ("\214" "OE")
662     ("\221" "`")
663     ("\222" "'")
664     ("\223" "``")
665     ("\224" "\"")
666     ("\225" "*")
667     ("\226" "-")
668     ("\227" "--")
669     ("\231" "(TM)")
670     ("\233" ">")
671     ("\234" "oe")
672     ("\264" "'"))
673   "Table for MS-to-Latin1 translation.")
674
675 (defcustom gnus-ignored-mime-types nil
676   "List of MIME types that should be ignored by Gnus."
677   :version "21.1"
678   :group 'gnus-article-mime
679   :type '(repeat regexp))
680
681 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
682   "List of MIME types that should not be given buttons when rendered inline.
683 See also `gnus-buttonized-mime-types' which may override this variable."
684   :version "21.1"
685   :group 'gnus-article-mime
686   :type '(repeat regexp))
687
688 (defcustom gnus-buttonized-mime-types nil
689   "List of MIME types that should be given buttons when rendered inline.
690 If set, this variable overrides `gnus-unbuttonized-mime-types'.
691 To see e.g. security buttons you could set this to
692 `(\"multipart/signed\")'."
693   :version "21.1"
694   :group 'gnus-article-mime
695   :type '(repeat regexp))
696
697 (defcustom gnus-article-mime-part-function nil
698   "Function called with a MIME handle as the argument.
699 This is meant for people who want to do something automatic based
700 on parts -- for instance, adding Vcard info to a database."
701   :group 'gnus-article-mime
702   :type 'function)
703
704 (defcustom gnus-mime-multipart-functions nil
705   "An alist of MIME types to functions to display them."
706   :version "21.1"
707   :group 'gnus-article-mime
708   :type 'alist)
709
710 (defcustom gnus-article-date-lapsed-new-header nil
711   "Whether the X-Sent and Date headers can coexist.
712 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
713 either replace the old \"Date:\" header (if this variable is nil), or
714 be added below it (otherwise)."
715   :version "21.1"
716   :group 'gnus-article-headers
717   :type 'boolean)
718
719 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
720   "Function called with a MIME handle as the argument.
721 This is meant for people who want to view first matched part.
722 For `undisplayed-alternative' (default), the first undisplayed
723 part or alternative part is used.  For `undisplayed', the first
724 undisplayed part is used.  For a function, the first part which
725 the function return `t' is used.  For `nil', the first part is
726 used."
727   :version "21.1"
728   :group 'gnus-article-mime
729   :type '(choice
730           (item :tag "first" :value nil)
731           (item :tag "undisplayed" :value undisplayed)
732           (item :tag "undisplayed or alternative"
733                 :value undisplayed-alternative)
734           (function)))
735
736 (defcustom gnus-mime-action-alist
737   '(("save to file" . gnus-mime-save-part)
738     ("save and strip" . gnus-mime-save-part-and-strip)
739     ("display as text" . gnus-mime-inline-part)
740     ("view the part" . gnus-mime-view-part)
741     ("pipe to command" . gnus-mime-pipe-part)
742     ("toggle display" . gnus-article-press-button)
743     ("toggle display" . gnus-article-view-part-as-charset)
744     ("view as type" . gnus-mime-view-part-as-type)
745     ("internalize type" . gnus-mime-internalize-part)
746     ("externalize type" . gnus-mime-externalize-part))
747   "An alist of actions that run on the MIME attachment."
748   :group 'gnus-article-mime
749   :type '(repeat (cons (string :tag "name")
750                        (function))))
751
752 (defcustom gnus-mime-action-alist
753   '(("save to file" . gnus-mime-save-part)
754     ("display as text" . gnus-mime-inline-part)
755     ("view the part" . gnus-mime-view-part)
756     ("pipe to command" . gnus-mime-pipe-part)
757     ("toggle display" . gnus-article-press-button)
758     ("view as type" . gnus-mime-view-part-as-type)
759     ("internalize type" . gnus-mime-internalize-part)
760     ("externalize type" . gnus-mime-externalize-part))
761   "An alist of actions that run on the MIME attachment."
762   :version "21.1"
763   :group 'gnus-article-mime
764   :type '(repeat (cons (string :tag "name")
765                        (function))))
766
767 ;;;
768 ;;; The treatment variables
769 ;;;
770
771 (defvar gnus-part-display-hook nil
772   "Hook called on parts that are to receive treatment.")
773
774 (defvar gnus-article-treat-custom
775   '(choice (const :tag "Off" nil)
776            (const :tag "On" t)
777            (const :tag "Header" head)
778            (const :tag "Last" last)
779            (integer :tag "Less")
780            (repeat :tag "Groups" regexp)
781            (sexp :tag "Predicate")))
782
783 (defvar gnus-article-treat-head-custom
784   '(choice (const :tag "Off" nil)
785            (const :tag "Header" head)))
786
787 (defvar gnus-article-treat-types '("text/plain")
788   "Parts to treat.")
789
790 (defvar gnus-inhibit-treatment nil
791   "Whether to inhibit treatment.")
792
793 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
794   "Highlight the signature.
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797   :group 'gnus-article-treat
798   :type gnus-article-treat-custom)
799 (put 'gnus-treat-highlight-signature 'highlight t)
800
801 (defcustom gnus-treat-buttonize 100000
802   "Add buttons.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805   :group 'gnus-article-treat
806   :type gnus-article-treat-custom)
807 (put 'gnus-treat-buttonize 'highlight t)
808
809 (defcustom gnus-treat-buttonize-head 'head
810   "Add buttons to the head.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813   :group 'gnus-article-treat
814   :type gnus-article-treat-head-custom)
815 (put 'gnus-treat-buttonize-head 'highlight t)
816
817 (defcustom gnus-treat-emphasize
818   (and (or window-system
819            (featurep 'xemacs)
820            (>= (string-to-number emacs-version) 21))
821        50000)
822   "Emphasize text.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825   :group 'gnus-article-treat
826   :type gnus-article-treat-custom)
827 (put 'gnus-treat-emphasize 'highlight t)
828
829 (defcustom gnus-treat-strip-cr nil
830   "Remove carriage returns.
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833   :group 'gnus-article-treat
834   :type gnus-article-treat-custom)
835
836 (defcustom gnus-treat-leading-whitespace nil
837   "Remove leading whitespace in headers.
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840   :group 'gnus-article-treat
841   :type gnus-article-treat-custom)
842
843 (defcustom gnus-treat-hide-headers 'head
844   "Hide headers.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847   :group 'gnus-article-treat
848   :type gnus-article-treat-head-custom)
849
850 (defcustom gnus-treat-hide-boring-headers nil
851   "Hide boring headers.
852 Valid values are nil, t, `head', `last', an integer or a predicate.
853 See the manual for details."
854   :group 'gnus-article-treat
855   :type gnus-article-treat-head-custom)
856
857 (defcustom gnus-treat-hide-signature nil
858   "Hide the signature.
859 Valid values are nil, t, `head', `last', an integer or a predicate.
860 See the manual for details."
861   :group 'gnus-article-treat
862   :type gnus-article-treat-custom)
863
864 (defcustom gnus-treat-fill-article nil
865   "Fill the article.
866 Valid values are nil, t, `head', `last', an integer or a predicate.
867 See the manual for details."
868   :group 'gnus-article-treat
869   :type gnus-article-treat-custom)
870
871 (defcustom gnus-treat-hide-citation nil
872   "Hide cited text.
873 Valid values are nil, t, `head', `last', an integer or a predicate.
874 See the manual for details."
875   :group 'gnus-article-treat
876   :type gnus-article-treat-custom)
877
878 (defcustom gnus-treat-hide-citation-maybe nil
879   "Hide cited text.
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882   :group 'gnus-article-treat
883   :type gnus-article-treat-custom)
884
885 (defcustom gnus-treat-hide-citation-maybe nil
886   "Hide cited text.
887 Valid values are nil, t, `head', `last', an integer or a predicate.
888 See the manual for details."
889   :group 'gnus-article-treat
890   :type gnus-article-treat-custom)
891
892 (defcustom gnus-treat-strip-list-identifiers 'head
893   "Strip list identifiers from `gnus-list-identifiers`.
894 Valid values are nil, t, `head', `last', an integer or a predicate.
895 See the manual for details."
896   :version "21.1"
897   :group 'gnus-article-treat
898   :type gnus-article-treat-custom)
899
900 (defcustom gnus-treat-strip-pgp t
901   "Strip PGP signatures.
902 Valid values are nil, t, `head', `last', an integer or a predicate.
903 See the manual for details."
904   :group 'gnus-article-treat
905   :type gnus-article-treat-custom)
906
907 (defcustom gnus-treat-strip-pem nil
908   "Strip PEM signatures.
909 Valid values are nil, t, `head', `last', an integer or a predicate.
910 See the manual for details."
911   :group 'gnus-article-treat
912   :type gnus-article-treat-custom)
913
914 (defcustom gnus-treat-strip-banner t
915   "Strip banners from articles.
916 The banner to be stripped is specified in the `banner' group parameter.
917 Valid values are nil, t, `head', `last', an integer or a predicate.
918 See the manual for details."
919   :group 'gnus-article-treat
920   :type gnus-article-treat-custom)
921
922 (defcustom gnus-treat-highlight-headers 'head
923   "Highlight the headers.
924 Valid values are nil, t, `head', `last', an integer or a predicate.
925 See the manual for details."
926   :group 'gnus-article-treat
927   :type gnus-article-treat-head-custom)
928 (put 'gnus-treat-highlight-headers 'highlight t)
929
930 (defcustom gnus-treat-highlight-citation t
931   "Highlight cited text.
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934   :group 'gnus-article-treat
935   :type gnus-article-treat-custom)
936 (put 'gnus-treat-highlight-citation 'highlight t)
937
938 (defcustom gnus-treat-date-ut nil
939   "Display the Date in UT (GMT).
940 Valid values are nil, t, `head', `last', an integer or a predicate.
941 See the manual for details."
942   :group 'gnus-article-treat
943   :type gnus-article-treat-head-custom)
944
945 (defcustom gnus-treat-date-local nil
946   "Display the Date in the local timezone.
947 Valid values are nil, t, `head', `last', an integer or a predicate.
948 See the manual for details."
949   :group 'gnus-article-treat
950   :type gnus-article-treat-head-custom)
951
952 (defcustom gnus-treat-date-english nil
953   "Display the Date in a format that can be read aloud in English.
954 Valid values are nil, t, `head', `last', an integer or a predicate.
955 See the manual for details."
956   :group 'gnus-article-treat
957   :type gnus-article-treat-head-custom)
958
959 (defcustom gnus-treat-date-lapsed nil
960   "Display the Date header in a way that says how much time has elapsed.
961 Valid values are nil, t, `head', `last', an integer or a predicate.
962 See the manual for details."
963   :group 'gnus-article-treat
964   :type gnus-article-treat-head-custom)
965
966 (defcustom gnus-treat-date-original nil
967   "Display the date in the original timezone.
968 Valid values are nil, t, `head', `last', an integer or a predicate.
969 See the manual for details."
970   :group 'gnus-article-treat
971   :type gnus-article-treat-head-custom)
972
973 (defcustom gnus-treat-date-iso8601 nil
974   "Display the date in the ISO8601 format.
975 Valid values are nil, t, `head', `last', an integer or a predicate.
976 See the manual for details."
977   :version "21.1"
978   :group 'gnus-article-treat
979   :type gnus-article-treat-head-custom)
980
981 (defcustom gnus-treat-date-user-defined nil
982   "Display the date in a user-defined format.
983 The format is defined by the `gnus-article-time-format' variable.
984 Valid values are nil, t, `head', `last', an integer or a predicate.
985 See the manual for details."
986   :group 'gnus-article-treat
987   :type gnus-article-treat-head-custom)
988
989 (defcustom gnus-treat-strip-headers-in-body t
990   "Strip the X-No-Archive header line from the beginning of the body.
991 Valid values are nil, t, `head', `last', an integer or a predicate.
992 See the manual for details."
993   :version "21.1"
994   :group 'gnus-article-treat
995   :type gnus-article-treat-custom)
996
997 (defcustom gnus-treat-strip-trailing-blank-lines nil
998   "Strip trailing blank lines.
999 Valid values are nil, t, `head', `last', an integer or a predicate.
1000 See the manual for details."
1001   :group 'gnus-article-treat
1002   :type gnus-article-treat-custom)
1003
1004 (defcustom gnus-treat-strip-leading-blank-lines nil
1005   "Strip leading blank lines.
1006 Valid values are nil, t, `head', `last', an integer or a predicate.
1007 See the manual for details."
1008   :group 'gnus-article-treat
1009   :type gnus-article-treat-custom)
1010
1011 (defcustom gnus-treat-strip-multiple-blank-lines nil
1012   "Strip multiple blank lines.
1013 Valid values are nil, t, `head', `last', an integer or a predicate.
1014 See the manual for details."
1015   :group 'gnus-article-treat
1016   :type gnus-article-treat-custom)
1017
1018 (defcustom gnus-treat-overstrike t
1019   "Treat overstrike highlighting.
1020 Valid values are nil, t, `head', `last', an integer or a predicate.
1021 See the manual for details."
1022   :group 'gnus-article-treat
1023   :type gnus-article-treat-custom)
1024 (put 'gnus-treat-overstrike 'highlight t)
1025
1026 (defcustom gnus-treat-display-xface
1027   (and (or (and (fboundp 'image-type-available-p)
1028                 (image-type-available-p 'xbm)
1029                 (string-match "^0x" (shell-command-to-string "uncompface")))
1030            (and (featurep 'xemacs) (featurep 'xface)))
1031        'head)
1032   "Display X-Face headers.
1033 Valid values are nil, t, `head', `last', an integer or a predicate.
1034 See the manual for details."
1035   :group 'gnus-article-treat
1036   :version "21.1"
1037   :type gnus-article-treat-head-custom)
1038 (put 'gnus-treat-display-xface 'highlight t)
1039
1040 (defcustom gnus-treat-display-smileys
1041   (if (or (and (featurep 'xemacs)
1042                (featurep 'xpm))
1043           (and (fboundp 'image-type-available-p)
1044                (image-type-available-p 'pbm)))
1045       t nil)
1046   "Display smileys.
1047 Valid values are nil, t, `head', `last', an integer or a predicate.
1048 See the manual for details."
1049   :group 'gnus-article-treat
1050   :version "21.1"
1051   :type gnus-article-treat-custom)
1052 (put 'gnus-treat-display-smileys 'highlight t)
1053
1054 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1055   "Display picons.
1056 Valid values are nil, t, `head', `last', an integer or a predicate.
1057 See the manual for details."
1058   :group 'gnus-article-treat
1059   :type gnus-article-treat-head-custom)
1060 (put 'gnus-treat-display-picons 'highlight t)
1061
1062 (defcustom gnus-treat-capitalize-sentences nil
1063   "Capitalize sentence-starting words.
1064 Valid values are nil, t, `head', `last', an integer or a predicate.
1065 See the manual for details."
1066   :version "21.1"
1067   :group 'gnus-article-treat
1068   :type gnus-article-treat-custom)
1069
1070 (defcustom gnus-treat-fill-long-lines nil
1071   "Fill long lines.
1072 Valid values are nil, t, `head', `last', an integer or a predicate.
1073 See the manual for details."
1074   :group 'gnus-article-treat
1075   :type gnus-article-treat-custom)
1076
1077 (defcustom gnus-treat-play-sounds nil
1078   "Play sounds.
1079 Valid values are nil, t, `head', `last', an integer or a predicate.
1080 See the manual for details."
1081   :version "21.1"
1082   :group 'gnus-article-treat
1083   :type gnus-article-treat-custom)
1084
1085 (defcustom gnus-treat-translate nil
1086   "Translate articles from one language to another.
1087 Valid values are nil, t, `head', `last', an integer or a predicate.
1088 See the manual for details."
1089   :version "21.1"
1090   :group 'gnus-article-treat
1091   :type gnus-article-treat-custom)
1092
1093 (defcustom gnus-treat-x-pgp-sig nil
1094   "Verify X-PGP-Sig.
1095 To automatically treat X-PGP-Sig, set it to head.
1096 Valid values are nil, t, `head', `last', an integer or a predicate.
1097 See the manual for details."
1098   :group 'gnus-article-treat
1099   :group 'mime-security
1100   :type gnus-article-treat-custom)
1101
1102 (defvar gnus-article-encrypt-protocol-alist
1103   '(("PGP" . mml2015-self-encrypt)))
1104
1105 ;; Set to nil if more than one protocol added to
1106 ;; gnus-article-encrypt-protocol-alist.
1107 (defcustom gnus-article-encrypt-protocol "PGP"
1108   "The protocol used for encrypt articles.
1109 It is a string, such as \"PGP\". If nil, ask user."
1110   :type 'string
1111   :group 'mime-security)
1112
1113 ;;; Internal variables
1114
1115 (defvar gnus-english-month-names
1116   '("January" "February" "March" "April" "May" "June" "July" "August"
1117     "September" "October" "November" "December"))
1118
1119 (defvar article-goto-body-goes-to-point-min-p nil)
1120 (defvar gnus-article-wash-types nil)
1121 (defvar gnus-article-emphasis-alist nil)
1122
1123 (defvar gnus-article-mime-handle-alist-1 nil)
1124 (defvar gnus-treatment-function-alist
1125   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1126     (gnus-treat-strip-banner gnus-article-strip-banner)
1127     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1128     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1129     (gnus-treat-buttonize gnus-article-add-buttons)
1130     (gnus-treat-fill-article gnus-article-fill-cited-article)
1131     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1132     (gnus-treat-strip-cr gnus-article-remove-cr)
1133     (gnus-treat-emphasize gnus-article-emphasize)
1134     (gnus-treat-display-xface gnus-article-display-x-face)
1135     (gnus-treat-date-ut gnus-article-date-ut)
1136     (gnus-treat-date-local gnus-article-date-local)
1137     (gnus-treat-date-english gnus-article-date-english)
1138     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1139     (gnus-treat-date-original gnus-article-date-original)
1140     (gnus-treat-date-user-defined gnus-article-date-user)
1141     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1142     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1143     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1144     (gnus-treat-hide-signature gnus-article-hide-signature)
1145     (gnus-treat-hide-citation gnus-article-hide-citation)
1146     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1147     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1148     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1149     (gnus-treat-strip-pgp gnus-article-hide-pgp)
1150     (gnus-treat-strip-pem gnus-article-hide-pem)
1151     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1152     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1153     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1154     (gnus-treat-strip-trailing-blank-lines
1155      gnus-article-remove-trailing-blank-lines)
1156     (gnus-treat-strip-leading-blank-lines
1157      gnus-article-strip-leading-blank-lines)
1158     (gnus-treat-strip-multiple-blank-lines
1159      gnus-article-strip-multiple-blank-lines)
1160     (gnus-treat-overstrike gnus-article-treat-overstrike)
1161     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1162     (gnus-treat-display-smileys gnus-smiley-display)
1163     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1164     (gnus-treat-display-picons gnus-article-display-picons)
1165     (gnus-treat-play-sounds gnus-earcon-display)))
1166
1167 (defvar gnus-article-mime-handle-alist nil)
1168 (defvar article-lapsed-timer nil)
1169 (defvar gnus-article-current-summary nil)
1170
1171 (defvar gnus-article-mode-syntax-table
1172   (let ((table (copy-syntax-table text-mode-syntax-table)))
1173     ;; This causes the citation match run O(2^n).
1174     ;; (modify-syntax-entry ?- "w" table)
1175     (modify-syntax-entry ?> ")" table)
1176     (modify-syntax-entry ?< "(" table)
1177     table)
1178   "Syntax table used in article mode buffers.
1179 Initialized from `text-mode-syntax-table.")
1180
1181 (defvar gnus-save-article-buffer nil)
1182
1183 (defvar gnus-article-mode-line-format-alist
1184   (nconc '((?w (gnus-article-wash-status) ?s)
1185            (?m (gnus-article-mime-part-status) ?s))
1186          gnus-summary-mode-line-format-alist))
1187
1188 (defvar gnus-number-of-articles-to-be-saved nil)
1189
1190 (defvar gnus-inhibit-hiding nil)
1191
1192 (defsubst gnus-article-hide-text (b e props)
1193   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1194   (gnus-add-text-properties-when 'article-type nil b e props)
1195   (when (memq 'intangible props)
1196     (put-text-property
1197      (max (1- b) (point-min))
1198      b 'intangible (cddr (memq 'intangible props)))))
1199
1200 (defsubst gnus-article-unhide-text (b e)
1201   "Remove hidden text properties from region between B and E."
1202   (remove-text-properties b e gnus-hidden-properties)
1203   (when (memq 'intangible gnus-hidden-properties)
1204     (put-text-property (max (1- b) (point-min))
1205                        b 'intangible nil)))
1206
1207 (defun gnus-article-hide-text-type (b e type)
1208   "Hide text of TYPE between B and E."
1209   (push type gnus-article-wash-types)
1210   (gnus-article-hide-text
1211    b e (cons 'article-type (cons type gnus-hidden-properties))))
1212
1213 (defun gnus-article-unhide-text-type (b e type)
1214   "Unhide text of TYPE between B and E."
1215   (setq gnus-article-wash-types
1216         (delq type gnus-article-wash-types))
1217   (remove-text-properties
1218    b e (cons 'article-type (cons type gnus-hidden-properties)))
1219   (when (memq 'intangible gnus-hidden-properties)
1220     (put-text-property (max (1- b) (point-min))
1221                        b 'intangible nil)))
1222
1223 (defun gnus-article-hide-text-of-type (type)
1224   "Hide text of TYPE in the current buffer."
1225   (save-excursion
1226     (let ((b (point-min))
1227           (e (point-max)))
1228       (while (setq b (text-property-any b e 'article-type type))
1229         (add-text-properties b (incf b) gnus-hidden-properties)))))
1230
1231 (defun gnus-article-delete-text-of-type (type)
1232   "Delete text of TYPE in the current buffer."
1233   (save-excursion
1234     (let ((b (point-min)))
1235       (while (setq b (text-property-any b (point-max) 'article-type type))
1236         (delete-region
1237          b (or (text-property-not-all b (point-max) 'article-type type)
1238                (point-max)))))))
1239
1240 (defun gnus-article-delete-invisible-text ()
1241   "Delete all invisible text in the current buffer."
1242   (save-excursion
1243     (let ((b (point-min)))
1244       (while (setq b (text-property-any b (point-max) 'invisible t))
1245         (delete-region
1246          b (or (text-property-not-all b (point-max) 'invisible t)
1247                (point-max)))))))
1248
1249 (defun gnus-article-text-type-exists-p (type)
1250   "Say whether any text of type TYPE exists in the buffer."
1251   (text-property-any (point-min) (point-max) 'article-type type))
1252
1253 (defsubst gnus-article-header-rank ()
1254   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1255   (let ((list gnus-sorted-header-list)
1256         (i 0))
1257     (while list
1258       (when (looking-at (car list))
1259         (setq list nil))
1260       (setq list (cdr list))
1261       (incf i))
1262     i))
1263
1264 (defun article-hide-headers (&optional arg delete)
1265   "Hide unwanted headers and possibly sort them as well."
1266   (interactive)
1267   ;; This function might be inhibited.
1268   (unless gnus-inhibit-hiding
1269     (save-excursion
1270       (save-restriction
1271         (let ((buffer-read-only nil)
1272               (case-fold-search t)
1273               (max (1+ (length gnus-sorted-header-list)))
1274               (ignored (when (not gnus-visible-headers)
1275                          (cond ((stringp gnus-ignored-headers)
1276                                 gnus-ignored-headers)
1277                                ((listp gnus-ignored-headers)
1278                                 (mapconcat 'identity gnus-ignored-headers
1279                                            "\\|")))))
1280               (visible
1281                (cond ((stringp gnus-visible-headers)
1282                       gnus-visible-headers)
1283                      ((and gnus-visible-headers
1284                            (listp gnus-visible-headers))
1285                       (mapconcat 'identity gnus-visible-headers "\\|"))))
1286               (inhibit-point-motion-hooks t)
1287               beg)
1288           ;; First we narrow to just the headers.
1289           (article-narrow-to-head)
1290           ;; Hide any "From " lines at the beginning of (mail) articles.
1291           (while (looking-at "From ")
1292             (forward-line 1))
1293           (unless (bobp)
1294             (delete-region (point-min) (point)))
1295           ;; Then treat the rest of the header lines.
1296           ;; Then we use the two regular expressions
1297           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1298           ;; select which header lines is to remain visible in the
1299           ;; article buffer.
1300           (while (re-search-forward "^[^ \t:]*:" nil t)
1301             (beginning-of-line)
1302             ;; Mark the rank of the header.
1303             (put-text-property
1304              (point) (1+ (point)) 'message-rank
1305              (if (or (and visible (looking-at visible))
1306                      (and ignored
1307                           (not (looking-at ignored))))
1308                  (gnus-article-header-rank)
1309                (+ 2 max)))
1310             (forward-line 1))
1311           (message-sort-headers-1)
1312           (when (setq beg (text-property-any
1313                            (point-min) (point-max) 'message-rank (+ 2 max)))
1314             ;; We delete the unwanted headers.
1315             (push 'headers gnus-article-wash-types)
1316             (add-text-properties (point-min) (+ 5 (point-min))
1317                                  '(article-type headers dummy-invisible t))
1318             (delete-region beg (point-max))))))))
1319
1320 (defun article-hide-boring-headers (&optional arg)
1321   "Toggle hiding of headers that aren't very interesting.
1322 If given a negative prefix, always show; if given a positive prefix,
1323 always hide."
1324   (interactive (gnus-article-hidden-arg))
1325   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1326              (not gnus-show-all-headers))
1327     (save-excursion
1328       (save-restriction
1329         (let ((buffer-read-only nil)
1330               (list gnus-boring-article-headers)
1331               (inhibit-point-motion-hooks t)
1332               elem)
1333           (article-narrow-to-head)
1334           (while list
1335             (setq elem (pop list))
1336             (goto-char (point-min))
1337             (cond
1338              ;; Hide empty headers.
1339              ((eq elem 'empty)
1340               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1341                 (forward-line -1)
1342                 (gnus-article-hide-text-type
1343                  (progn (beginning-of-line) (point))
1344                  (progn
1345                    (end-of-line)
1346                    (if (re-search-forward "^[^ \t]" nil t)
1347                        (match-beginning 0)
1348                      (point-max)))
1349                  'boring-headers)))
1350              ;; Hide boring Newsgroups header.
1351              ((eq elem 'newsgroups)
1352               (when (gnus-string-equal
1353                      (gnus-fetch-field "newsgroups")
1354                      (gnus-group-real-name
1355                       (if (boundp 'gnus-newsgroup-name)
1356                           gnus-newsgroup-name
1357                         "")))
1358                 (gnus-article-hide-header "newsgroups")))
1359              ((eq elem 'to-address)
1360               (let ((to (message-fetch-field "to"))
1361                     (to-address
1362                      (gnus-parameter-to-address
1363                       (if (boundp 'gnus-newsgroup-name)
1364                           gnus-newsgroup-name ""))))
1365                 (when (and to to-address
1366                            (ignore-errors
1367                              (gnus-string-equal
1368                               ;; only one address in To
1369                               (nth 1 (mail-extract-address-components to))
1370                               to-address)))
1371                   (gnus-article-hide-header "to"))))
1372              ((eq elem 'followup-to)
1373               (when (gnus-string-equal
1374                      (message-fetch-field "followup-to")
1375                      (message-fetch-field "newsgroups"))
1376                 (gnus-article-hide-header "followup-to")))
1377              ((eq elem 'reply-to)
1378               (let ((from (message-fetch-field "from"))
1379                     (reply-to (message-fetch-field "reply-to")))
1380                 (when (and
1381                        from reply-to
1382                        (ignore-errors
1383                          (gnus-string-equal
1384                           (nth 1 (mail-extract-address-components from))
1385                           (nth 1 (mail-extract-address-components reply-to)))))
1386                   (gnus-article-hide-header "reply-to"))))
1387              ((eq elem 'date)
1388               (let ((date (message-fetch-field "date")))
1389                 (when (and date
1390                            (< (days-between (current-time-string) date)
1391                               4))
1392                   (gnus-article-hide-header "date"))))
1393              ((eq elem 'long-to)
1394               (let ((to (message-fetch-field "to"))
1395                     (cc (message-fetch-field "cc")))
1396                 (when (> (length to) 1024)
1397                   (gnus-article-hide-header "to"))
1398                 (when (> (length cc) 1024)
1399                   (gnus-article-hide-header "cc"))))
1400              ((eq elem 'many-to)
1401               (let ((to-count 0)
1402                     (cc-count 0))
1403                 (goto-char (point-min))
1404                 (while (re-search-forward "^to:" nil t)
1405                   (setq to-count (1+ to-count)))
1406                 (when (> to-count 1)
1407                   (while (> to-count 0)
1408                     (goto-char (point-min))
1409                     (save-restriction
1410                       (re-search-forward "^to:" nil nil to-count)
1411                       (forward-line -1)
1412                       (narrow-to-region (point) (point-max))
1413                       (gnus-article-hide-header "to"))
1414                     (setq to-count (1- to-count))))
1415                 (goto-char (point-min))
1416                 (while (re-search-forward "^cc:" nil t)
1417                   (setq cc-count (1+ cc-count)))
1418                 (when (> cc-count 1)
1419                   (while (> cc-count 0)
1420                     (goto-char (point-min))
1421                     (save-restriction
1422                       (re-search-forward "^cc:" nil nil cc-count)
1423                       (forward-line -1)
1424                       (narrow-to-region (point) (point-max))
1425                       (gnus-article-hide-header "cc"))
1426                     (setq cc-count (1- cc-count)))))))))))))
1427
1428 (defun gnus-article-hide-header (header)
1429   (save-excursion
1430     (goto-char (point-min))
1431     (when (re-search-forward (concat "^" header ":") nil t)
1432       (gnus-article-hide-text-type
1433        (progn (beginning-of-line) (point))
1434        (progn
1435          (end-of-line)
1436          (if (re-search-forward "^[^ \t]" nil t)
1437              (match-beginning 0)
1438            (point-max)))
1439        'boring-headers))))
1440
1441 (defvar gnus-article-normalized-header-length 40
1442   "Length of normalized headers.")
1443
1444 (defun article-normalize-headers ()
1445   "Make all header lines 40 characters long."
1446   (interactive)
1447   (let ((buffer-read-only nil)
1448         column)
1449     (save-excursion
1450       (save-restriction
1451         (article-narrow-to-head)
1452         (while (not (eobp))
1453           (cond
1454            ((< (setq column (- (gnus-point-at-eol) (point)))
1455                gnus-article-normalized-header-length)
1456             (end-of-line)
1457             (insert (make-string
1458                      (- gnus-article-normalized-header-length column)
1459                      ? )))
1460            ((> column gnus-article-normalized-header-length)
1461             (gnus-put-text-property
1462              (progn
1463                (forward-char gnus-article-normalized-header-length)
1464                (point))
1465              (gnus-point-at-eol)
1466              'invisible t))
1467            (t
1468             ;; Do nothing.
1469             ))
1470           (forward-line 1))))))
1471
1472 (defun article-treat-dumbquotes ()
1473   "Translate M****s*** sm*rtq**t*s into proper text.
1474 Note that this function guesses whether a character is a sm*rtq**t* or
1475 not, so it should only be used interactively.
1476
1477 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1478 in an attempt to provide more quoting characters.  If you see
1479 something like \\222 or \\264 where you're expecting some kind of
1480 apostrophe or quotation mark, then try this wash."
1481   (interactive)
1482   (article-translate-strings gnus-article-dumbquotes-map))
1483
1484 (defun article-translate-characters (from to)
1485   "Translate all characters in the body of the article according to FROM and TO.
1486 FROM is a string of characters to translate from; to is a string of
1487 characters to translate to."
1488   (save-excursion
1489     (when (article-goto-body)
1490       (let ((buffer-read-only nil)
1491             (x (make-string 225 ?x))
1492             (i -1))
1493         (while (< (incf i) (length x))
1494           (aset x i i))
1495         (setq i 0)
1496         (while (< i (length from))
1497           (aset x (aref from i) (aref to i))
1498           (incf i))
1499         (translate-region (point) (point-max) x)))))
1500
1501 (defun article-translate-strings (map)
1502   "Translate all string in the body of the article according to MAP.
1503 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1504   (save-excursion
1505     (when (article-goto-body)
1506       (let ((buffer-read-only nil)
1507             elem)
1508         (while (setq elem (pop map))
1509           (save-excursion
1510             (while (search-forward (car elem) nil t)
1511               (replace-match (cadr elem)))))))))
1512
1513 (defun article-treat-overstrike ()
1514   "Translate overstrikes into bold text."
1515   (interactive)
1516   (save-excursion
1517     (when (article-goto-body)
1518       (let ((buffer-read-only nil))
1519         (while (search-forward "\b" nil t)
1520           (let ((next (char-after))
1521                 (previous (char-after (- (point) 2))))
1522             ;; We do the boldification/underlining by hiding the
1523             ;; overstrikes and putting the proper text property
1524             ;; on the letters.
1525             (cond
1526              ((eq next previous)
1527               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1528               (put-text-property (point) (1+ (point)) 'face 'bold))
1529              ((eq next ?_)
1530               (gnus-article-hide-text-type
1531                (1- (point)) (1+ (point)) 'overstrike)
1532               (put-text-property
1533                (- (point) 2) (1- (point)) 'face 'underline))
1534              ((eq previous ?_)
1535               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1536               (put-text-property
1537                (point) (1+ (point)) 'face 'underline)))))))))
1538
1539 (defun article-fill-long-lines ()
1540   "Fill lines that are wider than the window width."
1541   (interactive)
1542   (save-excursion
1543     (let ((buffer-read-only nil)
1544           (width (window-width (get-buffer-window (current-buffer)))))
1545       (save-restriction
1546         (article-goto-body)
1547         (let ((adaptive-fill-mode nil)) ;Why?  -sm
1548           (while (not (eobp))
1549             (end-of-line)
1550             (when (>= (current-column) (min fill-column width))
1551               (narrow-to-region (point) (gnus-point-at-bol))
1552               (fill-paragraph nil)
1553               (goto-char (point-max))
1554               (widen))
1555             (forward-line 1)))))))
1556
1557 (defun article-capitalize-sentences ()
1558   "Capitalize the first word in each sentence."
1559   (interactive)
1560   (save-excursion
1561     (let ((buffer-read-only nil)
1562           (paragraph-start "^[\n\^L]"))
1563       (article-goto-body)
1564       (while (not (eobp))
1565         (capitalize-word 1)
1566         (forward-sentence)))))
1567
1568 (defun article-remove-cr ()
1569   "Remove trailing CRs and then translate remaining CRs into LFs."
1570   (interactive)
1571   (save-excursion
1572     (let ((buffer-read-only nil))
1573       (goto-char (point-min))
1574       (while (re-search-forward "\r+$" nil t)
1575         (replace-match "" t t))
1576       (goto-char (point-min))
1577       (while (search-forward "\r" nil t)
1578         (replace-match "\n" t t)))))
1579
1580 (defun article-remove-trailing-blank-lines ()
1581   "Remove all trailing blank lines from the article."
1582   (interactive)
1583   (save-excursion
1584     (let ((buffer-read-only nil))
1585       (goto-char (point-max))
1586       (delete-region
1587        (point)
1588        (progn
1589          (while (and (not (bobp))
1590                      (looking-at "^[ \t]*$")
1591                      (not (gnus-annotation-in-region-p
1592                            (point) (gnus-point-at-eol))))
1593            (forward-line -1))
1594          (forward-line 1)
1595          (point))))))
1596
1597 (defun article-display-x-face (&optional force)
1598   "Look for an X-Face header and display it if present."
1599   (interactive (list 'force))
1600   (save-excursion
1601     ;; Delete the old process, if any.
1602     (when (process-status "article-x-face")
1603       (delete-process "article-x-face"))
1604     (let ((inhibit-point-motion-hooks t)
1605           x-faces
1606           (case-fold-search t)
1607           from last)
1608       (save-restriction
1609         (article-narrow-to-head)
1610         (when (and buffer-read-only ;; When type `W f'
1611                    (progn
1612                      (goto-char (point-min))
1613                      (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1614                    (gnus-buffer-live-p gnus-original-article-buffer))
1615           (with-current-buffer gnus-original-article-buffer
1616             (save-restriction
1617               (article-narrow-to-head)
1618               (while (re-search-forward "^X-Face:" nil t)
1619                 (setq x-faces
1620                       (concat
1621                        (or x-faces "")
1622                        (buffer-substring
1623                         (match-beginning 0)
1624                         (1- (re-search-forward
1625                              "^\\($\\|[^ \t]\\)" nil t))))))))
1626           (if x-faces
1627               (let (point start bface eface buffer-read-only)
1628                 (goto-char (point-max))
1629                 (forward-line -1)
1630                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1631                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1632                 (goto-char (point-max))
1633                 (setq point (point))
1634                 (insert x-faces)
1635                 (goto-char point)
1636                 (while (looking-at "\\([^:]+\\): *")
1637                   (put-text-property (match-beginning 1) (1+ (match-end 1))
1638                                      'face bface)
1639                   (setq start (match-end 0))
1640                   (forward-line 1)
1641                   (while (looking-at "[\t ]")
1642                     (forward-line 1))
1643                   (put-text-property start (point)
1644                                      'face eface)))))
1645         (goto-char (point-min))
1646         (setq from (message-fetch-field "from"))
1647         (goto-char (point-min))
1648         (while (and gnus-article-x-face-command
1649                     (not last)
1650                     (or force
1651                         ;; Check whether this face is censored.
1652                         (not gnus-article-x-face-too-ugly)
1653                         (and gnus-article-x-face-too-ugly from
1654                              (not (string-match gnus-article-x-face-too-ugly
1655                                                 from))))
1656                     ;; Has to be present.
1657                     (re-search-forward "^X-Face:[\t ]*" nil t))
1658           ;; This used to try to do multiple faces (`while' instead of
1659           ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1660           ;; work (b) it can crash some versions of Emacs (c) are
1661           ;; multiple faces really something to encourage?
1662           (when (stringp gnus-article-x-face-command)
1663             (setq last t))
1664           ;; We now have the area of the buffer where the X-Face is stored.
1665           (save-excursion
1666             (let ((beg (point))
1667                   (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1668               ;; We display the face.
1669               (if (symbolp gnus-article-x-face-command)
1670                   ;; The command is a lisp function, so we call it.
1671                   (if (gnus-functionp gnus-article-x-face-command)
1672                       (funcall gnus-article-x-face-command beg end)
1673                     (error "%s is not a function" gnus-article-x-face-command))
1674                 ;; The command is a string, so we interpret the command
1675                 ;; as a, well, command, and fork it off.
1676                 (let ((process-connection-type nil))
1677                   (process-kill-without-query
1678                    (start-process
1679                     "article-x-face" nil shell-file-name shell-command-switch
1680                     gnus-article-x-face-command))
1681                   (process-send-region "article-x-face" beg end)
1682                   (process-send-eof "article-x-face"))))))))))
1683
1684 (defun article-decode-mime-words ()
1685   "Decode all MIME-encoded words in the article."
1686   (interactive)
1687   (save-excursion
1688     (set-buffer gnus-article-buffer)
1689     (let ((inhibit-point-motion-hooks t)
1690           buffer-read-only
1691           (mail-parse-charset gnus-newsgroup-charset)
1692           (mail-parse-ignored-charsets
1693            (save-excursion (set-buffer gnus-summary-buffer)
1694                            gnus-newsgroup-ignored-charsets)))
1695       (mail-decode-encoded-word-region (point-min) (point-max)))))
1696
1697 (defun article-decode-charset (&optional prompt)
1698   "Decode charset-encoded text in the article.
1699 If PROMPT (the prefix), prompt for a coding system to use."
1700   (interactive "P")
1701   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1702         buffer-read-only
1703         (mail-parse-charset gnus-newsgroup-charset)
1704         (mail-parse-ignored-charsets
1705          (save-excursion (condition-case nil
1706                              (set-buffer gnus-summary-buffer)
1707                            (error))
1708                          gnus-newsgroup-ignored-charsets))
1709         ct cte ctl charset format)
1710   (save-excursion
1711     (save-restriction
1712       (article-narrow-to-head)
1713       (setq ct (message-fetch-field "Content-Type" t)
1714             cte (message-fetch-field "Content-Transfer-Encoding" t)
1715             ctl (and ct (ignore-errors
1716                           (mail-header-parse-content-type ct)))
1717             charset (cond
1718                      (prompt
1719                       (mm-read-coding-system "Charset to decode: "))
1720                      (ctl
1721                       (mail-content-type-get ctl 'charset)))
1722             format (and ctl (mail-content-type-get ctl 'format)))
1723       (when cte
1724         (setq cte (mail-header-strip cte)))
1725       (if (and ctl (not (string-match "/" (car ctl))))
1726           (setq ctl nil))
1727       (goto-char (point-max)))
1728     (forward-line 1)
1729     (save-restriction
1730       (narrow-to-region (point) (point-max))
1731       (when (and (eq mail-parse-charset 'gnus-decoded)
1732                  (eq (mm-body-7-or-8) '8bit))
1733         ;; The text code could have been decoded.
1734         (setq charset mail-parse-charset))
1735       (when (and (or (not ctl)
1736                      (equal (car ctl) "text/plain"))
1737                  (not format)) ;; article with format will decode later.
1738         (mm-decode-body
1739          charset (and cte (intern (downcase
1740                                    (gnus-strip-whitespace cte))))
1741          (car ctl)))))))
1742
1743 (defun article-decode-encoded-words ()
1744   "Remove encoded-word encoding from headers."
1745   (let ((inhibit-point-motion-hooks t)
1746         (mail-parse-charset gnus-newsgroup-charset)
1747         (mail-parse-ignored-charsets
1748          (save-excursion (condition-case nil
1749                              (set-buffer gnus-summary-buffer)
1750                            (error))
1751                          gnus-newsgroup-ignored-charsets))
1752         buffer-read-only)
1753     (save-restriction
1754       (article-narrow-to-head)
1755       (funcall gnus-decode-header-function (point-min) (point-max)))))
1756
1757 (defun article-de-quoted-unreadable (&optional force read-charset)
1758   "Translate a quoted-printable-encoded article.
1759 If FORCE, decode the article whether it is marked as quoted-printable
1760 or not.
1761 If READ-CHARSET, ask for a coding system."
1762   (interactive (list 'force current-prefix-arg))
1763   (save-excursion
1764     (let ((buffer-read-only nil) type charset)
1765       (if (gnus-buffer-live-p gnus-original-article-buffer)
1766           (with-current-buffer gnus-original-article-buffer
1767             (setq type
1768                   (gnus-fetch-field "content-transfer-encoding"))
1769             (let* ((ct (gnus-fetch-field "content-type"))
1770                    (ctl (and ct
1771                              (ignore-errors
1772                                (mail-header-parse-content-type ct)))))
1773               (setq charset (and ctl
1774                                  (mail-content-type-get ctl 'charset)))
1775               (if (stringp charset)
1776                   (setq charset (intern (downcase charset)))))))
1777       (if read-charset
1778           (setq charset (mm-read-coding-system "Charset: " charset)))
1779       (unless charset
1780         (setq charset gnus-newsgroup-charset))
1781       (when (or force
1782                 (and type (let ((case-fold-search t))
1783                             (string-match "quoted-printable" type))))
1784         (article-goto-body)
1785         (quoted-printable-decode-region
1786          (point) (point-max) (mm-charset-to-coding-system charset))))))
1787
1788 (defun article-de-base64-unreadable (&optional force read-charset)
1789   "Translate a base64 article.
1790 If FORCE, decode the article whether it is marked as base64 not.
1791 If READ-CHARSET, ask for a coding system."
1792   (interactive (list 'force current-prefix-arg))
1793   (save-excursion
1794     (let ((buffer-read-only nil) type charset)
1795       (if (gnus-buffer-live-p gnus-original-article-buffer)
1796           (with-current-buffer gnus-original-article-buffer
1797             (setq type
1798                   (gnus-fetch-field "content-transfer-encoding"))
1799             (let* ((ct (gnus-fetch-field "content-type"))
1800                    (ctl (and ct
1801                              (ignore-errors
1802                                (mail-header-parse-content-type ct)))))
1803               (setq charset (and ctl
1804                                  (mail-content-type-get ctl 'charset)))
1805               (if (stringp charset)
1806                   (setq charset (intern (downcase charset)))))))
1807       (if read-charset
1808           (setq charset (mm-read-coding-system "Charset: " charset)))
1809       (unless charset
1810         (setq charset gnus-newsgroup-charset))
1811       (when (or force
1812                 (and type (let ((case-fold-search t))
1813                             (string-match "base64" type))))
1814         (article-goto-body)
1815         (save-restriction
1816           (narrow-to-region (point) (point-max))
1817           (base64-decode-region (point-min) (point-max))
1818           (mm-decode-coding-region
1819            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1820
1821 (eval-when-compile
1822   (require 'rfc1843))
1823
1824 (defun article-decode-HZ ()
1825   "Translate a HZ-encoded article."
1826   (interactive)
1827   (require 'rfc1843)
1828   (save-excursion
1829     (let ((buffer-read-only nil))
1830       (rfc1843-decode-region (point-min) (point-max)))))
1831
1832 (defun article-wash-html (&optional read-charset)
1833   "Format an html article.
1834 If READ-CHARSET, ask for a coding system."
1835   (interactive "P")
1836   (save-excursion
1837     (let ((buffer-read-only nil)
1838           charset)
1839       (if (gnus-buffer-live-p gnus-original-article-buffer)
1840           (with-current-buffer gnus-original-article-buffer
1841             (let* ((ct (gnus-fetch-field "content-type"))
1842                    (ctl (and ct
1843                              (ignore-errors
1844                                (mail-header-parse-content-type ct)))))
1845               (setq charset (and ctl
1846                                  (mail-content-type-get ctl 'charset)))
1847               (if (stringp charset)
1848                   (setq charset (intern (downcase charset)))))))
1849       (if read-charset
1850           (setq charset (mm-read-coding-system "Charset: " charset)))
1851       (unless charset
1852         (setq charset gnus-newsgroup-charset))
1853       (article-goto-body)
1854       (save-window-excursion
1855         (save-restriction
1856           (narrow-to-region (point) (point-max))
1857           (mm-setup-w3)
1858           (let ((w3-strict-width (window-width))
1859                 (url-standalone-mode t))
1860             (condition-case var
1861                 (w3-region (point-min) (point-max))
1862               (error))))))))
1863
1864 (defun article-hide-list-identifiers ()
1865   "Remove list identifies from the Subject header.
1866 The `gnus-list-identifiers' variable specifies what to do."
1867   (interactive)
1868   (let ((inhibit-point-motion-hooks t)
1869         (regexp (if (consp gnus-list-identifiers)
1870                     (mapconcat 'identity gnus-list-identifiers " *\\|")
1871                   gnus-list-identifiers))
1872         buffer-read-only)
1873     (when regexp
1874       (save-excursion
1875         (save-restriction
1876           (article-narrow-to-head)
1877           (goto-char (point-min))
1878           (while (re-search-forward
1879                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
1880                   nil t)
1881             (delete-region (match-beginning 2) (match-end 0))
1882             (beginning-of-line))
1883           (when (re-search-forward
1884                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
1885             (delete-region (match-beginning 1) (match-end 1))))))))
1886
1887 (defun article-hide-pgp ()
1888   "Remove any PGP headers and signatures in the current article."
1889   (interactive)
1890   (save-excursion
1891     (save-restriction
1892       (let ((inhibit-point-motion-hooks t)
1893             buffer-read-only beg end)
1894         (article-goto-body)
1895         ;; Hide the "header".
1896         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1897           (push 'pgp gnus-article-wash-types)
1898           (delete-region (match-beginning 0) (match-end 0))
1899           ;; Remove armor headers (rfc2440 6.2)
1900           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1901                                      (point)))
1902           (setq beg (point))
1903           ;; Hide the actual signature.
1904           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1905                (setq end (1+ (match-beginning 0)))
1906                (delete-region
1907                 end
1908                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1909                     (match-end 0)
1910                   ;; Perhaps we shouldn't hide to the end of the buffer
1911                   ;; if there is no end to the signature?
1912                   (point-max))))
1913           ;; Hide "- " PGP quotation markers.
1914           (when (and beg end)
1915             (narrow-to-region beg end)
1916             (goto-char (point-min))
1917             (while (re-search-forward "^- " nil t)
1918               (delete-region
1919                (match-beginning 0) (match-end 0)))
1920             (widen))
1921           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1922
1923 (defun article-hide-pem (&optional arg)
1924   "Toggle hiding of any PEM headers and signatures in the current article.
1925 If given a negative prefix, always show; if given a positive prefix,
1926 always hide."
1927   (interactive (gnus-article-hidden-arg))
1928   (unless (gnus-article-check-hidden-text 'pem arg)
1929     (save-excursion
1930       (let (buffer-read-only end)
1931         (goto-char (point-min))
1932         ;; Hide the horrendously ugly "header".
1933         (when (and (search-forward
1934                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1935                     nil t)
1936                    (setq end (1+ (match-beginning 0))))
1937           (push 'pem gnus-article-wash-types)
1938           (gnus-article-hide-text-type
1939            end
1940            (if (search-forward "\n\n" nil t)
1941                (match-end 0)
1942              (point-max))
1943            'pem)
1944           ;; Hide the trailer as well
1945           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1946                                 nil t)
1947             (gnus-article-hide-text-type
1948              (match-beginning 0) (match-end 0) 'pem)))))))
1949
1950 (defun article-strip-banner ()
1951   "Strip the banner specified by the `banner' group parameter."
1952   (interactive)
1953   (save-excursion
1954     (save-restriction
1955       (let ((inhibit-point-motion-hooks t)
1956             (banner (gnus-parameter-banner gnus-newsgroup-name))
1957             (gnus-signature-limit nil)
1958             buffer-read-only beg end)
1959         (when banner
1960           (article-goto-body)
1961           (cond
1962            ((eq banner 'signature)
1963             (when (gnus-article-narrow-to-signature)
1964               (widen)
1965               (forward-line -1)
1966               (delete-region (point) (point-max))))
1967            ((symbolp banner)
1968             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1969                 (while (re-search-forward banner nil t)
1970                   (delete-region (match-beginning 0) (match-end 0)))))
1971            ((stringp banner)
1972             (while (re-search-forward banner nil t)
1973               (delete-region (match-beginning 0) (match-end 0))))))))))
1974
1975 (defun article-babel ()
1976   "Translate article using an online translation service."
1977   (interactive)
1978   (require 'babel)
1979   (save-excursion
1980     (set-buffer gnus-article-buffer)
1981     (when (article-goto-body)
1982       (let* ((buffer-read-only nil)
1983              (start (point))
1984              (end (point-max))
1985              (orig (buffer-substring start end))
1986              (trans (babel-as-string orig)))
1987         (save-restriction
1988           (narrow-to-region start end)
1989           (delete-region start end)
1990           (insert trans))))))
1991
1992 (defun article-hide-signature (&optional arg)
1993   "Hide the signature in the current article.
1994 If given a negative prefix, always show; if given a positive prefix,
1995 always hide."
1996   (interactive (gnus-article-hidden-arg))
1997   (unless (gnus-article-check-hidden-text 'signature arg)
1998     (save-excursion
1999       (save-restriction
2000         (let ((buffer-read-only nil))
2001           (when (gnus-article-narrow-to-signature)
2002             (gnus-article-hide-text-type
2003              (point-min) (point-max) 'signature)))))))
2004
2005 (defun article-strip-headers-in-body ()
2006   "Strip offensive headers from bodies."
2007   (interactive)
2008   (save-excursion
2009     (article-goto-body)
2010     (let ((case-fold-search t))
2011       (when (looking-at "x-no-archive:")
2012         (gnus-delete-line)))))
2013
2014 (defun article-strip-leading-blank-lines ()
2015   "Remove all blank lines from the beginning of the article."
2016   (interactive)
2017   (save-excursion
2018     (let ((inhibit-point-motion-hooks t)
2019           buffer-read-only)
2020       (when (article-goto-body)
2021         (while (and (not (eobp))
2022                     (looking-at "[ \t]*$"))
2023           (gnus-delete-line))))))
2024
2025 (defun article-narrow-to-head ()
2026   "Narrow the buffer to the head of the message.
2027 Point is left at the beginning of the narrowed-to region."
2028   (narrow-to-region
2029    (goto-char (point-min))
2030    (if (search-forward "\n\n" nil 1)
2031        (1- (point))
2032      (point-max)))
2033   (goto-char (point-min)))
2034
2035 (defun article-goto-body ()
2036   "Place point at the start of the body."
2037   (goto-char (point-min))
2038   (cond
2039    ;; This variable is only bound when dealing with separate
2040    ;; MIME body parts.
2041    (article-goto-body-goes-to-point-min-p
2042     t)
2043    ((search-forward "\n\n" nil t)
2044     t)
2045    (t
2046     (goto-char (point-max))
2047     nil)))
2048
2049 (defun article-strip-multiple-blank-lines ()
2050   "Replace consecutive blank lines with one empty line."
2051   (interactive)
2052   (save-excursion
2053     (let ((inhibit-point-motion-hooks t)
2054           buffer-read-only)
2055       ;; First make all blank lines empty.
2056       (article-goto-body)
2057       (while (re-search-forward "^[ \t]+$" nil t)
2058         (unless (gnus-annotation-in-region-p
2059                  (match-beginning 0) (match-end 0))
2060           (replace-match "" nil t)))
2061       ;; Then replace multiple empty lines with a single empty line.
2062       (article-goto-body)
2063       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2064         (unless (gnus-annotation-in-region-p
2065                  (match-beginning 0) (match-end 0))
2066           (delete-region (match-beginning 1) (match-end 1)))))))
2067
2068 (defun article-strip-leading-space ()
2069   "Remove all white space from the beginning of the lines in the article."
2070   (interactive)
2071   (save-excursion
2072     (let ((inhibit-point-motion-hooks t)
2073           buffer-read-only)
2074       (article-goto-body)
2075       (while (re-search-forward "^[ \t]+" nil t)
2076         (replace-match "" t t)))))
2077
2078 (defun article-strip-trailing-space ()
2079   "Remove all white space from the end of the lines in the article."
2080   (interactive)
2081   (save-excursion
2082     (let ((inhibit-point-motion-hooks t)
2083           buffer-read-only)
2084       (article-goto-body)
2085       (while (re-search-forward "[ \t]+$" nil t)
2086         (replace-match "" t t)))))
2087
2088 (defun article-strip-blank-lines ()
2089   "Strip leading, trailing and multiple blank lines."
2090   (interactive)
2091   (article-strip-leading-blank-lines)
2092   (article-remove-trailing-blank-lines)
2093   (article-strip-multiple-blank-lines))
2094
2095 (defun article-strip-all-blank-lines ()
2096   "Strip all blank lines."
2097   (interactive)
2098   (save-excursion
2099     (let ((inhibit-point-motion-hooks t)
2100           buffer-read-only)
2101       (article-goto-body)
2102       (while (re-search-forward "^[ \t]*\n" nil t)
2103         (replace-match "" t t)))))
2104
2105 (defun gnus-article-narrow-to-signature ()
2106   "Narrow to the signature; return t if a signature is found, else nil."
2107   (let ((inhibit-point-motion-hooks t))
2108     (when (gnus-article-search-signature)
2109       (forward-line 1)
2110       ;; Check whether we have some limits to what we consider
2111       ;; to be a signature.
2112       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2113                       (list gnus-signature-limit)))
2114             limit limited)
2115         (while (setq limit (pop limits))
2116           (if (or (and (integerp limit)
2117                        (< (- (point-max) (point)) limit))
2118                   (and (floatp limit)
2119                        (< (count-lines (point) (point-max)) limit))
2120                   (and (gnus-functionp limit)
2121                        (funcall limit))
2122                   (and (stringp limit)
2123                        (not (re-search-forward limit nil t))))
2124               ()                        ; This limit did not succeed.
2125             (setq limited t
2126                   limits nil)))
2127         (unless limited
2128           (narrow-to-region (point) (point-max))
2129           t)))))
2130
2131 (defun gnus-article-search-signature ()
2132   "Search the current buffer for the signature separator.
2133 Put point at the beginning of the signature separator."
2134   (let ((cur (point)))
2135     (goto-char (point-max))
2136     (if (if (stringp gnus-signature-separator)
2137             (re-search-backward gnus-signature-separator nil t)
2138           (let ((seps gnus-signature-separator))
2139             (while (and seps
2140                         (not (re-search-backward (car seps) nil t)))
2141               (pop seps))
2142             seps))
2143         t
2144       (goto-char cur)
2145       nil)))
2146
2147 (defun gnus-article-hidden-arg ()
2148   "Return the current prefix arg as a number, or 0 if no prefix."
2149   (list (if current-prefix-arg
2150             (prefix-numeric-value current-prefix-arg)
2151           0)))
2152
2153 (defun gnus-article-check-hidden-text (type arg)
2154   "Return nil if hiding is necessary.
2155 Arg can be nil or a number.  Nil and positive means hide, negative
2156 means show, 0 means toggle."
2157   (save-excursion
2158     (save-restriction
2159       (let ((hide (gnus-article-hidden-text-p type)))
2160         (cond
2161          ((or (null arg)
2162               (> arg 0))
2163           nil)
2164          ((< arg 0)
2165           (gnus-article-show-hidden-text type)
2166           t)
2167          (t
2168           (if (eq hide 'hidden)
2169               (progn
2170                 (gnus-article-show-hidden-text type)
2171                 t)
2172             nil)))))))
2173
2174 (defun gnus-article-hidden-text-p (type)
2175   "Say whether the current buffer contains hidden text of type TYPE."
2176   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2177     (while (and pos
2178                 (not (get-text-property pos 'invisible))
2179                 (not (get-text-property pos 'dummy-invisible)))
2180       (setq pos
2181             (text-property-any (1+ pos) (point-max) 'article-type type)))
2182     (if pos
2183         'hidden
2184       nil)))
2185
2186 (defun gnus-article-show-hidden-text (type &optional dummy)
2187   "Show all hidden text of type TYPE.
2188 Originally it is hide instead of DUMMY."
2189   (let ((buffer-read-only nil)
2190         (inhibit-point-motion-hooks t))
2191     (gnus-remove-text-properties-when
2192      'article-type type
2193      (point-min) (point-max)
2194      (cons 'article-type (cons type
2195                                gnus-hidden-properties)))))
2196
2197 (defconst article-time-units
2198   `((year . ,(* 365.25 24 60 60))
2199     (week . ,(* 7 24 60 60))
2200     (day . ,(* 24 60 60))
2201     (hour . ,(* 60 60))
2202     (minute . 60)
2203     (second . 1))
2204   "Mapping from time units to seconds.")
2205
2206 (defun article-date-ut (&optional type highlight header)
2207   "Convert DATE date to universal time in the current article.
2208 If TYPE is `local', convert to local time; if it is `lapsed', output
2209 how much time has lapsed since DATE.  For `lapsed', the value of
2210 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2211 should replace the \"Date:\" one, or should be added below it."
2212   (interactive (list 'ut t))
2213   (let* ((header (or header
2214                      (message-fetch-field "date")
2215                      ""))
2216          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2217          (date-regexp
2218           (cond
2219            ((not gnus-article-date-lapsed-new-header)
2220             tdate-regexp)
2221            ((eq type 'lapsed)
2222             "^X-Sent:[ \t]")
2223            (t
2224             "^Date:[ \t]")))
2225          (date (if (vectorp header) (mail-header-date header)
2226                  header))
2227          (inhibit-point-motion-hooks t)
2228          pos
2229          bface eface)
2230     (save-excursion
2231       (save-restriction
2232         (article-narrow-to-head)
2233         (when (re-search-forward tdate-regexp nil t)
2234           (setq bface (get-text-property (gnus-point-at-bol) 'face)
2235                 date (or (get-text-property (gnus-point-at-bol)
2236                                             'original-date)
2237                          date)
2238                 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2239           (forward-line 1))
2240         (when (and date (not (string= date "")))
2241           (goto-char (point-min))
2242           (let ((buffer-read-only nil))
2243             ;; Delete any old Date headers.
2244             (while (re-search-forward date-regexp nil t)
2245               (if pos
2246                   (delete-region (progn (beginning-of-line) (point))
2247                                  (progn (forward-line 1) (point)))
2248                 (delete-region (progn (beginning-of-line) (point))
2249                                (progn (end-of-line) (point)))
2250                 (setq pos (point))))
2251             (when (and (not pos) (re-search-forward tdate-regexp nil t))
2252               (forward-line 1))
2253             (if pos (goto-char pos))
2254             (insert (article-make-date-line date (or type 'ut)))
2255             (when (not pos)
2256               (insert "\n")
2257               (forward-line -1))
2258             ;; Do highlighting.
2259             (beginning-of-line)
2260             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2261               (put-text-property (match-beginning 1) (1+ (match-end 1))
2262                                  'original-date date)
2263               (put-text-property (match-beginning 1) (1+ (match-end 1))
2264                                  'face bface)
2265               (put-text-property (match-beginning 2) (match-end 2)
2266                                  'face eface))))))))
2267
2268 (defun article-make-date-line (date type)
2269   "Return a DATE line of TYPE."
2270   (unless (memq type '(local ut original user iso8601 lapsed english))
2271     (error "Unknown conversion type: %s" type))
2272   (condition-case ()
2273       (let ((time (date-to-time date)))
2274         (cond
2275          ;; Convert to the local timezone.
2276          ((eq type 'local)
2277           (let ((tz (car (current-time-zone time))))
2278             (format "Date: %s %s%02d%02d" (current-time-string time)
2279                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2280                     (/ (% (abs tz) 3600) 60))))
2281          ;; Convert to Universal Time.
2282          ((eq type 'ut)
2283           (concat "Date: "
2284                   (current-time-string
2285                    (let* ((e (parse-time-string date))
2286                           (tm (apply 'encode-time e))
2287                           (ms (car tm))
2288                           (ls (- (cadr tm) (car (current-time-zone time)))))
2289                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2290                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2291                            (t (list ms ls)))))
2292                   " UT"))
2293          ;; Get the original date from the article.
2294          ((eq type 'original)
2295           (concat "Date: " (if (string-match "\n+$" date)
2296                                (substring date 0 (match-beginning 0))
2297                              date)))
2298          ;; Let the user define the format.
2299          ((eq type 'user)
2300           (if (gnus-functionp gnus-article-time-format)
2301               (funcall gnus-article-time-format time)
2302             (concat
2303              "Date: "
2304              (format-time-string gnus-article-time-format time))))
2305          ;; ISO 8601.
2306          ((eq type 'iso8601)
2307           (let ((tz (car (current-time-zone time))))
2308             (concat
2309              "Date: "
2310              (format-time-string "%Y%m%dT%H%M%S" time)
2311              (format "%s%02d%02d"
2312                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2313                      (/ (% (abs tz) 3600) 60)))))
2314          ;; Do an X-Sent lapsed format.
2315          ((eq type 'lapsed)
2316           ;; If the date is seriously mangled, the timezone functions are
2317           ;; liable to bug out, so we ignore all errors.
2318           (let* ((now (current-time))
2319                  (real-time (subtract-time now time))
2320                  (real-sec (and real-time
2321                                 (+ (* (float (car real-time)) 65536)
2322                                    (cadr real-time))))
2323                  (sec (and real-time (abs real-sec)))
2324                  num prev)
2325             (cond
2326              ((null real-time)
2327               "X-Sent: Unknown")
2328              ((zerop sec)
2329               "X-Sent: Now")
2330              (t
2331               (concat
2332                "X-Sent: "
2333                ;; This is a bit convoluted, but basically we go
2334                ;; through the time units for years, weeks, etc,
2335                ;; and divide things to see whether that results
2336                ;; in positive answers.
2337                (mapconcat
2338                 (lambda (unit)
2339                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2340                       ;; The (remaining) seconds are too few to
2341                       ;; be divided into this time unit.
2342                       ""
2343                     ;; It's big enough, so we output it.
2344                     (setq sec (- sec (* num (cdr unit))))
2345                     (prog1
2346                         (concat (if prev ", " "") (int-to-string
2347                                                    (floor num))
2348                                 " " (symbol-name (car unit))
2349                                 (if (> num 1) "s" ""))
2350                       (setq prev t))))
2351                 article-time-units "")
2352                ;; If dates are odd, then it might appear like the
2353                ;; article was sent in