Fix up make-obsolete-variable declarations throughout.
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 ;; For Emacs < 22.2.
29 (eval-and-compile
30   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
31 (eval-when-compile
32   (require 'cl))
33 (defvar tool-bar-map)
34 (defvar w3m-minor-mode-map)
35
36 (require 'gnus)
37 (require 'gnus-sum)
38 (require 'gnus-spec)
39 (require 'gnus-int)
40 (require 'gnus-win)
41 (require 'mm-bodies)
42 (require 'mail-parse)
43 (require 'mm-decode)
44 (require 'mm-view)
45 (require 'wid-edit)
46 (require 'mm-uu)
47 (require 'message)
48
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'parse-time-string "parse-time" nil nil)
53 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (autoload 'mm-url-insert-file-contents-external "mm-url")
55 (autoload 'mm-extern-cache-contents "mm-extern")
56
57 (defgroup gnus-article nil
58   "Article display."
59   :link '(custom-manual "(gnus)Article Buffer")
60   :group 'gnus)
61
62 (defgroup gnus-article-treat nil
63   "Treating article parts."
64   :link '(custom-manual "(gnus)Article Hiding")
65   :group 'gnus-article)
66
67 (defgroup gnus-article-hiding nil
68   "Hiding article parts."
69   :link '(custom-manual "(gnus)Article Hiding")
70   :group 'gnus-article)
71
72 (defgroup gnus-article-highlight nil
73   "Article highlighting."
74   :link '(custom-manual "(gnus)Article Highlighting")
75   :group 'gnus-article
76   :group 'gnus-visual)
77
78 (defgroup gnus-article-signature nil
79   "Article signatures."
80   :link '(custom-manual "(gnus)Article Signature")
81   :group 'gnus-article)
82
83 (defgroup gnus-article-headers nil
84   "Article headers."
85   :link '(custom-manual "(gnus)Hiding Headers")
86   :group 'gnus-article)
87
88 (defgroup gnus-article-washing nil
89   "Special commands on articles."
90   :link '(custom-manual "(gnus)Article Washing")
91   :group 'gnus-article)
92
93 (defgroup gnus-article-emphasis nil
94   "Fontisizing articles."
95   :link '(custom-manual "(gnus)Article Fontisizing")
96   :group 'gnus-article)
97
98 (defgroup gnus-article-saving nil
99   "Saving articles."
100   :link '(custom-manual "(gnus)Saving Articles")
101   :group 'gnus-article)
102
103 (defgroup gnus-article-mime nil
104   "Worshiping the MIME wonder."
105   :link '(custom-manual "(gnus)Using MIME")
106   :group 'gnus-article)
107
108 (defgroup gnus-article-buttons nil
109   "Pushable buttons in the article buffer."
110   :link '(custom-manual "(gnus)Article Buttons")
111   :group 'gnus-article)
112
113 (defgroup gnus-article-various nil
114   "Other article options."
115   :link '(custom-manual "(gnus)Misc Article")
116   :group 'gnus-article)
117
118 (defcustom gnus-ignored-headers
119   (mapcar
120    (lambda (header)
121      (concat "^" header ":"))
122    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128      "X-Attribution" "X-Originating-IP" "Delivered-To"
129      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145      "List-[A-Za-z]+" "X-Listprocessor-Version"
146      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148      "X-Received" "Content-length" "X-precedence"
149      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154      "X-Content-length" "X-Posting-Agent" "Original-Received"
155      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160      "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161      "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162      "Envelope-Sender" "Envelope-Recipients"))
163   "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166   :type '(choice :custom-show nil
167                  regexp
168                  (repeat regexp))
169   :group 'gnus-article-hiding)
170
171 (defcustom gnus-visible-headers
172   "^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:"
173   "*All headers that do not match this regexp will be hidden.
174 This variable can also be a list of regexp of headers to remain visible.
175 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
176   :type '(choice
177           (repeat :value-to-internal (lambda (widget value)
178                                        (custom-split-regexp-maybe value))
179                   :match (lambda (widget value)
180                            (or (stringp value)
181                                (widget-editable-list-match widget value)))
182                   regexp)
183           (const :tag "Use gnus-ignored-headers" nil)
184           regexp)
185   :group 'gnus-article-hiding)
186
187 (defcustom gnus-sorted-header-list
188   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
189     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
190   "*This variable is a list of regular expressions.
191 If it is non-nil, headers that match the regular expressions will
192 be placed first in the article buffer in the sequence specified by
193 this list."
194   :type '(repeat regexp)
195   :group 'gnus-article-hiding)
196
197 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
198   "Headers that are only to be displayed if they have interesting data.
199 Possible values in this list are:
200
201   'empty       Headers with no content.
202   'newsgroups  Newsgroup identical to Gnus group.
203   'to-address  To identical to To-address.
204   'to-list     To identical to To-list.
205   'cc-list     CC identical to To-list.
206   'followup-to Followup-to identical to Newsgroups.
207   'reply-to    Reply-to identical to From.
208   'date        Date less than four days old.
209   'long-to     To and/or Cc longer than 1024 characters.
210   'many-to     Multiple To and/or Cc."
211   :type '(set (const :tag "Headers with no content." empty)
212               (const :tag "Newsgroups identical to Gnus group." newsgroups)
213               (const :tag "To identical to To-address." to-address)
214               (const :tag "To identical to To-list." to-list)
215               (const :tag "CC identical to To-list." cc-list)
216               (const :tag "Followup-to identical to Newsgroups." followup-to)
217               (const :tag "Reply-to identical to From." reply-to)
218               (const :tag "Date less than four days old." date)
219               (const :tag "To and/or Cc longer than 1024 characters." long-to)
220               (const :tag "Multiple To and/or Cc headers." many-to))
221   :group 'gnus-article-hiding)
222
223 (defcustom gnus-article-skip-boring nil
224   "Skip over text that is not worth reading.
225 By default, if you set this t, then Gnus will display citations and
226 signatures, but will never scroll down to show you a page consisting
227 only of boring text.  Boring text is controlled by
228 `gnus-article-boring-faces'."
229   :version "22.1"
230   :type 'boolean
231   :group 'gnus-article-hiding)
232
233 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
234   "Regexp matching signature separator.
235 This can also be a list of regexps.  In that case, it will be checked
236 from head to tail looking for a separator.  Searches will be done from
237 the end of the buffer."
238   :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
239                  (regexp)
240                  (repeat :tag "List of regexp" regexp))
241   :group 'gnus-article-signature)
242
243 (defcustom gnus-signature-limit nil
244   "Provide a limit to what is considered a signature.
245 If it is a number, no signature may not be longer (in characters) than
246 that number.  If it is a floating point number, no signature may be
247 longer (in lines) than that number.  If it is a function, the function
248 will be called without any parameters, and if it returns nil, there is
249 no signature in the buffer.  If it is a string, it will be used as a
250 regexp.  If it matches, the text in question is not a signature.
251
252 This can also be a list of the above values."
253   :type '(choice (const nil)
254                  (integer :value 200)
255                  (number :value 4.0)
256                  function
257                  (regexp :value ".*"))
258   :group 'gnus-article-signature)
259
260 (defcustom gnus-hidden-properties '(invisible t intangible t)
261   "Property list to use for hiding text."
262   :type 'sexp
263   :group 'gnus-article-hiding)
264
265 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
266 ;; frames in a session.
267 (defcustom gnus-article-x-face-command
268   (if (featurep 'xemacs)
269       (if (or (gnus-image-type-available-p 'xface)
270               (gnus-image-type-available-p 'pbm))
271           'gnus-display-x-face-in-from
272         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
273     (if (gnus-image-type-available-p 'pbm)
274         'gnus-display-x-face-in-from
275       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
276 display -"))
277   "*String or function to be executed to display an X-Face header.
278 If it is a string, the command will be executed in a sub-shell
279 asynchronously.  The compressed face will be piped to this command."
280   :type `(choice string
281                  (function-item gnus-display-x-face-in-from)
282                  function)
283   :version "21.1"
284   :group 'gnus-picon
285   :group 'gnus-article-washing)
286
287 (defcustom gnus-article-x-face-too-ugly nil
288   "Regexp matching posters whose face shouldn't be shown automatically."
289   :type '(choice regexp (const nil))
290   :group 'gnus-article-washing)
291
292 (defcustom gnus-article-banner-alist nil
293   "Banner alist for stripping.
294 For example,
295      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
296   :version "21.1"
297   :type '(repeat (cons symbol regexp))
298   :group 'gnus-article-washing)
299
300 (gnus-define-group-parameter
301  banner
302  :variable-document
303  "Alist of regexps (to match group names) and banner."
304  :variable-group gnus-article-washing
305  :parameter-type
306  '(choice :tag "Banner"
307           :value nil
308           (const :tag "Remove signature" signature)
309           (symbol :tag "Item in `gnus-article-banner-alist'" none)
310           regexp
311           (const :tag "None" nil))
312  :parameter-document
313  "If non-nil, specify how to remove `banners' from articles.
314
315 Symbol `signature' means to remove signatures delimited by
316 `gnus-signature-separator'.  Any other symbol is used to look up a
317 regular expression to match the banner in `gnus-article-banner-alist'.
318 A string is used as a regular expression to match the banner
319 directly.")
320
321 (defcustom gnus-article-address-banner-alist nil
322   "Alist of mail addresses and banners.
323 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
324 to match a mail address in the From: header, BANNER is one of a symbol
325 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
326 If ADDRESS matches author's mail address, it will remove things like
327 advertisements.  For example:
328
329 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
330 "
331   :type '(repeat
332           (cons
333            (regexp :tag "Address")
334            (choice :tag "Banner" :value nil
335                    (const :tag "Remove signature" signature)
336                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
337                    regexp
338                    (const :tag "None" nil))))
339   :version "22.1"
340   :group 'gnus-article-washing)
341
342 (defmacro gnus-emphasis-custom-with-format (&rest body)
343   `(let ((format "\
344 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
345 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
346      ,@body))
347
348 (defun gnus-emphasis-custom-value-to-external (value)
349   (gnus-emphasis-custom-with-format
350    (if (consp (car value))
351        (list (format format (car (car value)) (cdr (car value)))
352              2
353              (if (nth 1 value) 2 3)
354              (nth 2 value))
355      value)))
356
357 (defun gnus-emphasis-custom-value-to-internal (value)
358   (gnus-emphasis-custom-with-format
359    (let ((regexp (concat "\\`"
360                          (format (regexp-quote format)
361                                  "\\([^()]+\\)" "\\([^()]+\\)")
362                          "\\'"))
363          pattern)
364      (if (string-match regexp (setq pattern (car value)))
365          (list (cons (match-string 1 pattern) (match-string 2 pattern))
366                (= (nth 2 value) 2)
367                (nth 3 value))
368        value))))
369
370 (defcustom gnus-emphasis-alist
371   (let ((types
372          '(("\\*" "\\*" bold nil 2)
373            ("_" "_" underline)
374            ("/" "/" italic)
375            ("_/" "/_" underline-italic)
376            ("_\\*" "\\*_" underline-bold)
377            ("\\*/" "/\\*" bold-italic)
378            ("_\\*/" "/\\*_" underline-bold-italic))))
379     (nconc
380      (gnus-emphasis-custom-with-format
381       (mapcar (lambda (spec)
382                 (list (format format (car spec) (cadr spec))
383                       (or (nth 3 spec) 2)
384                       (or (nth 4 spec) 3)
385                       (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
386               types))
387      '(;; I've never seen anyone use this strikethru convention whereas I've
388        ;; several times seen it triggered by normal text.  --Stef
389        ;; Miles suggests that this form is sometimes used but for italics,
390        ;; so maybe we should map it to `italic'.
391        ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
392        ;; 2 3 gnus-emphasis-strikethru)
393        ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
394         2 3 gnus-emphasis-underline))))
395   "*Alist that says how to fontify certain phrases.
396 Each item looks like this:
397
398   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399
400 The first element is a regular expression to be matched.  The second
401 is a number that says what regular expression grouping used to find
402 the entire emphasized word.  The third is a number that says what
403 regexp grouping should be displayed and highlighted.  The fourth
404 is the face used for highlighting."
405   :type
406   '(repeat
407     (menu-choice
408      :format "%[Customizing Style%]\n%v"
409      :indent 2
410      (group :tag "Default"
411             :value ("" 0 0 default)
412             :value-create
413             (lambda (widget)
414               (let ((value (widget-get
415                             (cadr (widget-get (widget-get widget :parent)
416                                               :args))
417                             :value)))
418                 (if (not (eq (nth 2 value) 'default))
419                     (widget-put
420                      widget
421                      :value
422                      (gnus-emphasis-custom-value-to-external value))))
423               (widget-group-value-create widget))
424             regexp
425             (integer :format "Match group: %v")
426             (integer :format "Emphasize group: %v")
427             face)
428      (group :tag "Simple"
429             :value (("_" . "_") nil default)
430             (cons :format "%v"
431                   (regexp :format "Start regexp: %v")
432                   (regexp :format "End regexp: %v"))
433             (boolean :format "Show start and end patterns: %[%v%]\n"
434                      :on " On " :off " Off ")
435             face)))
436   :get (lambda (symbol)
437          (mapcar 'gnus-emphasis-custom-value-to-internal
438                  (default-value symbol)))
439   :set (lambda (symbol value)
440          (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
441                                      value)))
442   :group 'gnus-article-emphasis)
443
444 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
445   "A regexp to describe whitespace which should not be emphasized.
446 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
447 The former avoids underlining of leading and trailing whitespace,
448 and the latter avoids underlining any whitespace at all."
449   :version "21.1"
450   :group 'gnus-article-emphasis
451   :type 'regexp)
452
453 (defface gnus-emphasis-bold '((t (:bold t)))
454   "Face used for displaying strong emphasized text (*word*)."
455   :group 'gnus-article-emphasis)
456
457 (defface gnus-emphasis-italic '((t (:italic t)))
458   "Face used for displaying italic emphasized text (/word/)."
459   :group 'gnus-article-emphasis)
460
461 (defface gnus-emphasis-underline '((t (:underline t)))
462   "Face used for displaying underlined emphasized text (_word_)."
463   :group 'gnus-article-emphasis)
464
465 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
466   "Face used for displaying underlined bold emphasized text (_*word*_)."
467   :group 'gnus-article-emphasis)
468
469 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
470   "Face used for displaying underlined italic emphasized text (_/word/_)."
471   :group 'gnus-article-emphasis)
472
473 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
474   "Face used for displaying bold italic emphasized text (/*word*/)."
475   :group 'gnus-article-emphasis)
476
477 (defface gnus-emphasis-underline-bold-italic
478   '((t (:bold t :italic t :underline t)))
479   "Face used for displaying underlined bold italic emphasized text.
480 Example: (_/*word*/_)."
481   :group 'gnus-article-emphasis)
482
483 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
484                                       '((t (:strikethru t)))
485                                     '((t (:strike-through t))))
486   "Face used for displaying strike-through text (-word-)."
487   :group 'gnus-article-emphasis)
488
489 (defface gnus-emphasis-highlight-words
490   '((t (:background "black" :foreground "yellow")))
491   "Face used for displaying highlighted words."
492   :group 'gnus-article-emphasis)
493
494 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
495   "Format for display of Date headers in article bodies.
496 See `format-time-string' for the possible values.
497
498 The variable can also be function, which should return a complete Date
499 header.  The function is called with one argument, the time, which can
500 be fed to `format-time-string'."
501   :type '(choice string function)
502   :link '(custom-manual "(gnus)Article Date")
503   :group 'gnus-article-washing)
504
505 (defcustom gnus-save-all-headers t
506   "*If non-nil, don't remove any headers before saving.
507 This will be overridden by the `:headers' property that the symbol of
508 the saver function, which is specified by `gnus-default-article-saver',
509 might have."
510   :group 'gnus-article-saving
511   :type 'boolean)
512
513 (defcustom gnus-prompt-before-saving 'always
514   "*This variable says how much prompting is to be done when saving articles.
515 If it is nil, no prompting will be done, and the articles will be
516 saved to the default files.  If this variable is `always', each and
517 every article that is saved will be preceded by a prompt, even when
518 saving large batches of articles.  If this variable is neither nil not
519 `always', there the user will be prompted once for a file name for
520 each invocation of the saving commands."
521   :group 'gnus-article-saving
522   :type '(choice (item always)
523                  (item :tag "never" nil)
524                  (sexp :tag "once" :format "%t\n" :value t)))
525
526 (defcustom gnus-saved-headers gnus-visible-headers
527   "Headers to keep if `gnus-save-all-headers' is nil.
528 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
529 If that variable is nil, however, all headers that match this regexp
530 will be kept while the rest will be deleted before saving.  This and
531 `gnus-save-all-headers' will be overridden by the `:headers' property
532 that the symbol of the saver function, which is specified by
533 `gnus-default-article-saver', might have."
534   :group 'gnus-article-saving
535   :type 'regexp)
536
537 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
538 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
539   "A function to save articles in your favourite format.
540 The function will be called by way of the `gnus-summary-save-article'
541 command, and friends such as `gnus-summary-save-article-rmail'.
542
543 Gnus provides the following functions:
544
545 * gnus-summary-save-in-rmail (Rmail format)
546 * gnus-summary-save-in-mail (Unix mail format)
547 * gnus-summary-save-in-folder (MH folder)
548 * gnus-summary-save-in-file (article format)
549 * gnus-summary-save-body-in-file (article body)
550 * gnus-summary-save-in-vm (use VM's folder format)
551 * gnus-summary-write-to-file (article format -- overwrite)
552 * gnus-summary-write-body-to-file (article body -- overwrite)
553 * gnus-summary-save-in-pipe (article format)
554
555 The symbol of each function may have the following properties:
556
557 * :decode
558 The value non-nil means save decoded articles.  This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
561 `gnus-summary-save-in-pipe'.
562
563 * :function
564 The value specifies an alternative function which appends, not
565 overwrites, articles to a file.  This implies that when saving many
566 articles at a time, `gnus-prompt-before-saving' is bound to t and all
567 articles are saved in a single file.  This is meaningful only with
568 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
569
570 * :headers
571 The value specifies the symbol of a variable of which the value
572 specifies headers to be saved.  If it is omitted,
573 `gnus-save-all-headers' and `gnus-saved-headers' control what
574 headers should be saved."
575   :group 'gnus-article-saving
576   :type '(radio (function-item gnus-summary-save-in-rmail)
577                 (function-item gnus-summary-save-in-mail)
578                 (function-item gnus-summary-save-in-folder)
579                 (function-item gnus-summary-save-in-file)
580                 (function-item gnus-summary-save-body-in-file)
581                 (function-item gnus-summary-save-in-vm)
582                 (function-item gnus-summary-write-to-file)
583                 (function-item gnus-summary-write-body-to-file)
584                 (function-item gnus-summary-save-in-pipe)
585                 (function)))
586
587 (defcustom gnus-article-save-coding-system
588   (or (and (mm-coding-system-p 'utf-8) 'utf-8)
589       (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
590       (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
591       (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
592   "Coding system used to save decoded articles to a file.
593
594 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
595 which can safely encode any characters in text.  This is used by the
596 commands including:
597
598 * gnus-summary-save-article-file
599 * gnus-summary-save-article-body-file
600 * gnus-summary-write-article-file
601 * gnus-summary-write-article-body-file
602
603 and the functions to which you may set `gnus-default-article-saver':
604
605 * gnus-summary-save-in-file
606 * gnus-summary-save-body-in-file
607 * gnus-summary-write-to-file
608 * gnus-summary-write-body-to-file
609
610 Those commands and functions save just text displayed in the article
611 buffer to a file if the value of this variable is non-nil.  Note that
612 buttonized MIME parts will be lost in a saved file in that case.
613 Otherwise, raw articles will be saved."
614   :group 'gnus-article-saving
615   :type `(choice
616           :format "%{%t%}:\n %[Value Menu%] %v"
617           (const :tag "Save raw articles" nil)
618           ,@(delq nil
619                   (mapcar
620                    (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
621                    '((const :tag "UTF-8" utf-8)
622                      (const :tag "iso-2022-7bit" iso-2022-7bit)
623                      (const :tag "Emacs internal" emacs-mule)
624                      (const :tag "escape-quoted" escape-quoted))))
625           (symbol :tag "Coding system")))
626
627 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
628   "A function generating a file name to save articles in Rmail format.
629 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
630   :group 'gnus-article-saving
631   :type 'function)
632
633 (defcustom gnus-mail-save-name 'gnus-plain-save-name
634   "A function generating a file name to save articles in Unix mail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636   :group 'gnus-article-saving
637   :type 'function)
638
639 (defcustom gnus-folder-save-name 'gnus-folder-save-name
640   "A function generating a file name to save articles in MH folder.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
642   :group 'gnus-article-saving
643   :type 'function)
644
645 (defcustom gnus-file-save-name 'gnus-numeric-save-name
646   "A function generating a file name to save articles in article format.
647 The function is called with NEWSGROUP, HEADERS, and optional
648 LAST-FILE."
649   :group 'gnus-article-saving
650   :type 'function)
651
652 (defcustom gnus-split-methods
653   '((gnus-article-archive-name)
654     (gnus-article-nndoc-name))
655   "*Variable used to suggest where articles are to be saved.
656 For instance, if you would like to save articles related to Gnus in
657 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
658 you could set this variable to something like:
659
660  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
661    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662
663 This variable is an alist where the key is the match and the
664 value is a list of possible files to save in if the match is
665 non-nil.
666
667 If the match is a string, it is used as a regexp match on the
668 article.  If the match is a symbol, that symbol will be funcalled
669 from the buffer of the article to be saved with the newsgroup as the
670 parameter.  If it is a list, it will be evaled in the same buffer.
671
672 If this form or function returns a string, this string will be used as a
673 possible file name; and if it returns a non-nil list, that list will be
674 used as possible file names."
675   :group 'gnus-article-saving
676   :type '(repeat (choice (list :value (fun) function)
677                          (cons :value ("" "") regexp (repeat string))
678                          (sexp :value nil))))
679
680 (defcustom gnus-page-delimiter "^\^L"
681   "*Regexp describing what to use as article page delimiters.
682 The default value is \"^\^L\", which is a form linefeed at the
683 beginning of a line."
684   :type 'regexp
685   :group 'gnus-article-various)
686
687 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
688   "*The format specification for the article mode line.
689 See `gnus-summary-mode-line-format' for a closer description.
690
691 The following additional specs are available:
692
693 %w  The article washing status.
694 %m  The number of MIME parts in the article."
695   :type 'string
696   :group 'gnus-article-various)
697
698 (defcustom gnus-article-mode-hook nil
699   "*A hook for Gnus article mode."
700   :type 'hook
701   :group 'gnus-article-various)
702
703 (when (featurep 'xemacs)
704   ;; Extracted from gnus-xmas-define in order to preserve user settings
705   (when (fboundp 'turn-off-scroll-in-place)
706     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
709
710 (defcustom gnus-article-menu-hook nil
711   "*Hook run after the creation of the article mode menu."
712   :type 'hook
713   :group 'gnus-article-various)
714
715 (defcustom gnus-article-prepare-hook nil
716   "*A hook called after an article has been prepared in the article buffer."
717   :type 'hook
718   :group 'gnus-article-various)
719
720 (defcustom gnus-copy-article-ignored-headers nil
721   "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723   :version "23.1" ;; No Gnus
724   :type '(repeat regexp)
725   :group 'gnus-article-various)
726
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728                         "Gnus 5.10 (Emacs 22.1)")
729
730 (defface gnus-button
731   '((t (:weight bold)))
732   "Face used for highlighting a button in the article buffer."
733   :group 'gnus-article-buttons)
734
735 (defcustom gnus-article-button-face 'gnus-button
736   "Face used for highlighting buttons in the article buffer.
737
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
740   :type 'face
741   :group 'gnus-article-buttons)
742
743 (defcustom gnus-article-mouse-face 'highlight
744   "Face used for mouse highlighting in the article buffer.
745
746 Article buttons will be displayed in this face when the cursor is
747 above them."
748   :type 'face
749   :group 'gnus-article-buttons)
750
751 (defcustom gnus-signature-face 'gnus-signature
752   "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
754   :type 'face
755   :group 'gnus-article-highlight
756   :group 'gnus-article-signature)
757
758 (defface gnus-signature
759   '((t
760      (:italic t)))
761   "Face used for highlighting a signature in the article buffer."
762   :group 'gnus-article-highlight
763   :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
767
768 (defface gnus-header-from
769   '((((class color)
770       (background dark))
771      (:foreground "PaleGreen1"))
772     (((class color)
773       (background light))
774      (:foreground "red3"))
775     (t
776      (:italic t)))
777   "Face used for displaying from headers."
778   :group 'gnus-article-headers
779   :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
783
784 (defface gnus-header-subject
785   '((((class color)
786       (background dark))
787      (:foreground "SeaGreen1"))
788     (((class color)
789       (background light))
790      (:foreground "red4"))
791     (t
792      (:bold t :italic t)))
793   "Face used for displaying subject headers."
794   :group 'gnus-article-headers
795   :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
799
800 (defface gnus-header-newsgroups
801   '((((class color)
802       (background dark))
803      (:foreground "yellow" :italic t))
804     (((class color)
805       (background light))
806      (:foreground "MidnightBlue" :italic t))
807     (t
808      (:italic t)))
809   "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
811 articles."
812   :group 'gnus-article-headers
813   :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
817
818 (defface gnus-header-name
819   '((((class color)
820       (background dark))
821      (:foreground "SpringGreen2"))
822     (((class color)
823       (background light))
824      (:foreground "maroon"))
825     (t
826      (:bold t)))
827   "Face used for displaying header names."
828   :group 'gnus-article-headers
829   :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
833
834 (defface gnus-header-content
835   '((((class color)
836       (background dark))
837      (:foreground "SpringGreen1" :italic t))
838     (((class color)
839       (background light))
840      (:foreground "indianred4" :italic t))
841     (t
842      (:italic t)))  "Face used for displaying header content."
843   :group 'gnus-article-headers
844   :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
848
849 (defcustom gnus-header-face-alist
850   '(("From" nil gnus-header-from)
851     ("Subject" nil gnus-header-subject)
852     ("Newsgroups:.*," nil gnus-header-newsgroups)
853     ("" gnus-header-name gnus-header-content))
854   "*Controls highlighting of article headers.
855
856 An alist of the form (HEADER NAME CONTENT).
857
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
860
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil.  Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865   :group 'gnus-article-headers
866   :group 'gnus-article-highlight
867   :type '(repeat (list (regexp :tag "Header")
868                        (choice :tag "Name"
869                                (item :tag "skip" nil)
870                                (face :value default))
871                        (choice :tag "Content"
872                                (item :tag "skip" nil)
873                                (face :value default)))))
874
875 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876                                           '((xface . (:face gnus-x-face)))
877                                         '((pbm . (:face gnus-x-face))
878                                           (png . nil)))
879   "Alist of image types and properties applied to Face and X-Face images.
880 Here are examples:
881
882 ;; Specify the altitude of Face images in the From header.
883 \(setq gnus-face-properties-alist
884       '((pbm . (:face gnus-x-face :ascent 80))
885         (png . (:ascent 80))))
886
887 ;; Show Face images as pressed buttons.
888 \(setq gnus-face-properties-alist
889       '((pbm . (:face gnus-x-face :relief -2))
890         (png . (:relief -2))))
891
892 See the manual for the valid properties for various image types.
893 Currently, `pbm' is used for X-Face images and `png' is used for Face
894 images in Emacs.  Only the `:face' property is effective on the `xface'
895 image type in XEmacs if it is built with the libcompface library."
896   :version "23.1" ;; No Gnus
897   :group 'gnus-article-headers
898   :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
899
900 (defcustom gnus-article-decode-hook
901   '(article-decode-charset article-decode-encoded-words
902                            article-decode-group-name article-decode-idna-rhs)
903   "*Hook run to decode charsets in articles."
904   :group 'gnus-article-headers
905   :type 'hook)
906
907 (defcustom gnus-display-mime-function 'gnus-display-mime
908   "Function to display MIME articles."
909   :group 'gnus-article-mime
910   :type 'function)
911
912 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913   "Function used to decode headers.")
914
915 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916   "Function used to decode addresses.")
917
918 (defvar gnus-article-dumbquotes-map
919   '(("\200" "EUR")
920     ("\202" ",")
921     ("\203" "f")
922     ("\204" ",,")
923     ("\205" "...")
924     ("\213" "<")
925     ("\214" "OE")
926     ("\221" "`")
927     ("\222" "'")
928     ("\223" "``")
929     ("\224" "\"")
930     ("\225" "*")
931     ("\226" "-")
932     ("\227" "--")
933     ("\230" "~")
934     ("\231" "(TM)")
935     ("\233" ">")
936     ("\234" "oe")
937     ("\264" "'"))
938   "Table for MS-to-Latin1 translation.")
939
940 (defcustom gnus-ignored-mime-types nil
941   "List of MIME types that should be ignored by Gnus."
942   :version "21.1"
943   :group 'gnus-article-mime
944   :type '(repeat regexp))
945
946 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
947   "List of MIME types that should not be given buttons when rendered inline.
948 See also `gnus-buttonized-mime-types' which may override this variable.
949 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950   :version "21.1"
951   :group 'gnus-article-mime
952   :type '(repeat regexp))
953
954 (defcustom gnus-buttonized-mime-types nil
955   "List of MIME types that should be given buttons when rendered inline.
956 If set, this variable overrides `gnus-unbuttonized-mime-types'.
957 To see e.g. security buttons you could set this to
958 `(\"multipart/signed\")'.  You could also add \"multipart/alternative\" to
959 this list to display radio buttons that allow you to choose one of two
960 media types those mails include.  See also `mm-discouraged-alternatives'.
961 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
962   :version "22.1"
963   :group 'gnus-article-mime
964   :type '(repeat regexp))
965
966 (defcustom gnus-inhibit-mime-unbuttonizing nil
967   "If non-nil, all MIME parts get buttons.
968 When nil (the default value), then some MIME parts do not get buttons,
969 as described by the variables `gnus-buttonized-mime-types' and
970 `gnus-unbuttonized-mime-types'."
971   :version "22.1"
972   :group 'gnus-article-mime
973   :type 'boolean)
974
975 (defcustom gnus-body-boundary-delimiter "_"
976   "String used to delimit header and body.
977 This variable is used by `gnus-article-treat-body-boundary' which can
978 be controlled by `gnus-treat-body-boundary'."
979   :version "22.1"
980   :group 'gnus-article-various
981   :type '(choice (item :tag "None" :value nil)
982                  string))
983
984 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985                                   "/usr/share/picons")
986   "Defines the location of the faces database.
987 For information on obtaining this database of pretty pictures, please
988 see http://www.cs.indiana.edu/picons/ftp/index.html"
989   :version "22.1"
990   :type '(repeat directory)
991   :link '(url-link :tag "download"
992                    "http://www.cs.indiana.edu/picons/ftp/index.html")
993   :link '(custom-manual "(gnus)Picons")
994   :group 'gnus-picon)
995
996 (defun gnus-picons-installed-p ()
997   "Say whether picons are installed on your machine."
998   (let ((installed nil))
999     (dolist (database gnus-picon-databases)
1000       (when (file-exists-p database)
1001         (setq installed t)))
1002     installed))
1003
1004 (defcustom gnus-article-mime-part-function nil
1005   "Function called with a MIME handle as the argument.
1006 This is meant for people who want to do something automatic based
1007 on parts -- for instance, adding Vcard info to a database."
1008   :group 'gnus-article-mime
1009   :type '(choice (const nil)
1010                  function))
1011
1012 (defcustom gnus-mime-multipart-functions nil
1013   "An alist of MIME types to functions to display them."
1014   :version "21.1"
1015   :group 'gnus-article-mime
1016   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1017
1018 (defcustom gnus-article-date-lapsed-new-header nil
1019   "Whether the X-Sent and Date headers can coexist.
1020 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1021 either replace the old \"Date:\" header (if this variable is nil), or
1022 be added below it (otherwise)."
1023   :version "21.1"
1024   :group 'gnus-article-headers
1025   :type 'boolean)
1026
1027 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1028   "Function called with a MIME handle as the argument.
1029 This is meant for people who want to view first matched part.
1030 For `undisplayed-alternative' (default), the first undisplayed
1031 part or alternative part is used.  For `undisplayed', the first
1032 undisplayed part is used.  For a function, the first part which
1033 the function return t is used.  For nil, the first part is
1034 used."
1035   :version "21.1"
1036   :group 'gnus-article-mime
1037   :type '(choice
1038           (item :tag "first" :value nil)
1039           (item :tag "undisplayed" :value undisplayed)
1040           (item :tag "undisplayed or alternative"
1041                 :value undisplayed-alternative)
1042           (function)))
1043
1044 (defcustom gnus-mime-action-alist
1045   '(("save to file" . gnus-mime-save-part)
1046     ("save and strip" . gnus-mime-save-part-and-strip)
1047     ("replace with file" . gnus-mime-replace-part)
1048     ("delete part" . gnus-mime-delete-part)
1049     ("display as text" . gnus-mime-inline-part)
1050     ("view the part" . gnus-mime-view-part)
1051     ("pipe to command" . gnus-mime-pipe-part)
1052     ("toggle display" . gnus-article-press-button)
1053     ("toggle display" . gnus-article-view-part-as-charset)
1054     ("view as type" . gnus-mime-view-part-as-type)
1055     ("view internally" . gnus-mime-view-part-internally)
1056     ("view externally" . gnus-mime-view-part-externally))
1057   "An alist of actions that run on the MIME attachment."
1058   :group 'gnus-article-mime
1059   :type '(repeat (cons (string :tag "name")
1060                        (function))))
1061
1062 (defcustom gnus-auto-select-part 1
1063   "Advance to next MIME part when deleting or stripping parts.
1064
1065 When 0, point will be placed on the same part as before.  When
1066 positive (negative), move point forward (backwards) this many
1067 parts.  When nil, redisplay article."
1068   :version "23.1" ;; No Gnus
1069   :group 'gnus-article-mime
1070   :type '(choice (const nil :tag "Redisplay article.")
1071                  (const 1 :tag "Next part.")
1072                  (const 0 :tag "Current part.")
1073                  integer))
1074
1075 ;;;
1076 ;;; The treatment variables
1077 ;;;
1078
1079 (defvar gnus-part-display-hook nil
1080   "Hook called on parts that are to receive treatment.")
1081
1082 (defvar gnus-article-treat-custom
1083   '(choice (const :tag "Off" nil)
1084            (const :tag "On" t)
1085            (const :tag "Header" head)
1086            (const :tag "First" first)
1087            (const :tag "Last" last)
1088            (integer :tag "Less")
1089            (repeat :tag "Groups" regexp)
1090            (sexp :tag "Predicate")))
1091
1092 (defvar gnus-article-treat-head-custom
1093   '(choice (const :tag "Off" nil)
1094            (const :tag "Header" head)))
1095
1096 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1097                                    "text/x-patch")
1098   "Parts to treat.")
1099
1100 (defvar gnus-inhibit-treatment nil
1101   "Whether to inhibit treatment.")
1102
1103 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1104   "Highlight the signature.
1105 Valid values are nil, t, `head', `first', `last', an integer or a
1106 predicate.  See Info node `(gnus)Customizing Articles'."
1107   :group 'gnus-article-treat
1108   :link '(custom-manual "(gnus)Customizing Articles")
1109   :type gnus-article-treat-custom)
1110 (put 'gnus-treat-highlight-signature 'highlight t)
1111
1112 (defcustom gnus-treat-buttonize 100000
1113   "Add buttons.
1114 Valid values are nil, t, `head', `first', `last', an integer or a
1115 predicate.  See Info node `(gnus)Customizing Articles'."
1116   :group 'gnus-article-treat
1117   :link '(custom-manual "(gnus)Customizing Articles")
1118   :type gnus-article-treat-custom)
1119 (put 'gnus-treat-buttonize 'highlight t)
1120
1121 (defcustom gnus-treat-buttonize-head 'head
1122   "Add buttons to the head.
1123 Valid values are nil, t, `head', `first', `last', an integer or a
1124 predicate.  See Info node `(gnus)Customizing Articles'."
1125   :group 'gnus-article-treat
1126   :link '(custom-manual "(gnus)Customizing Articles")
1127   :type gnus-article-treat-head-custom)
1128 (put 'gnus-treat-buttonize-head 'highlight t)
1129
1130 (defcustom gnus-treat-emphasize 50000
1131   "Emphasize text.
1132 Valid values are nil, t, `head', `first', `last', an integer or a
1133 predicate.  See Info node `(gnus)Customizing Articles'."
1134   :group 'gnus-article-treat
1135   :link '(custom-manual "(gnus)Customizing Articles")
1136   :type gnus-article-treat-custom)
1137 (put 'gnus-treat-emphasize 'highlight t)
1138
1139 (defcustom gnus-treat-strip-cr nil
1140   "Remove carriage returns.
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate.  See Info node `(gnus)Customizing Articles'."
1143   :version "22.1"
1144   :group 'gnus-article-treat
1145   :link '(custom-manual "(gnus)Customizing Articles")
1146   :type gnus-article-treat-custom)
1147
1148 (defcustom gnus-treat-unsplit-urls nil
1149   "Remove newlines from within URLs.
1150 Valid values are nil, t, `head', `first', `last', an integer or a
1151 predicate.  See Info node `(gnus)Customizing Articles'."
1152   :version "22.1"
1153   :group 'gnus-article-treat
1154   :link '(custom-manual "(gnus)Customizing Articles")
1155   :type gnus-article-treat-custom)
1156
1157 (defcustom gnus-treat-leading-whitespace nil
1158   "Remove leading whitespace in headers.
1159 Valid values are nil, t, `head', `first', `last', an integer or a
1160 predicate.  See Info node `(gnus)Customizing Articles'."
1161   :version "22.1"
1162   :group 'gnus-article-treat
1163   :link '(custom-manual "(gnus)Customizing Articles")
1164   :type gnus-article-treat-custom)
1165
1166 (defcustom gnus-treat-hide-headers 'head
1167   "Hide headers.
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate.  See Info node `(gnus)Customizing Articles'."
1170   :group 'gnus-article-treat
1171   :link '(custom-manual "(gnus)Customizing Articles")
1172   :type gnus-article-treat-head-custom)
1173
1174 (defcustom gnus-treat-hide-boring-headers nil
1175   "Hide boring headers.
1176 Valid values are nil, t, `head', `first', `last', an integer or a
1177 predicate.  See Info node `(gnus)Customizing Articles'."
1178   :group 'gnus-article-treat
1179   :link '(custom-manual "(gnus)Customizing Articles")
1180   :type gnus-article-treat-head-custom)
1181
1182 (defcustom gnus-treat-hide-signature nil
1183   "Hide the signature.
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate.  See Info node `(gnus)Customizing Articles'."
1186   :group 'gnus-article-treat
1187   :link '(custom-manual "(gnus)Customizing Articles")
1188   :type gnus-article-treat-custom)
1189
1190 (defcustom gnus-treat-fill-article nil
1191   "Fill the article.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate.  See Info node `(gnus)Customizing Articles'."
1194   :group 'gnus-article-treat
1195   :link '(custom-manual "(gnus)Customizing Articles")
1196   :type gnus-article-treat-custom)
1197
1198 (defcustom gnus-treat-hide-citation nil
1199   "Hide cited text.
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate.  See Info node `(gnus)Customizing Articles'."
1202   :group 'gnus-article-treat
1203   :link '(custom-manual "(gnus)Customizing Articles")
1204   :type gnus-article-treat-custom)
1205
1206 (defcustom gnus-treat-hide-citation-maybe nil
1207   "Hide cited text.
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate.  See Info node `(gnus)Customizing Articles'."
1210   :group 'gnus-article-treat
1211   :link '(custom-manual "(gnus)Customizing Articles")
1212   :type gnus-article-treat-custom)
1213
1214 (defcustom gnus-treat-strip-list-identifiers 'head
1215   "Strip list identifiers from `gnus-list-identifiers`.
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate.  See Info node `(gnus)Customizing Articles'."
1218   :version "21.1"
1219   :group 'gnus-article-treat
1220   :link '(custom-manual "(gnus)Customizing Articles")
1221   :type gnus-article-treat-custom)
1222
1223 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1224                         "Gnus 5.10 (Emacs 22.1)")
1225
1226 (defcustom gnus-treat-strip-pem nil
1227   "Strip PEM signatures.
1228 Valid values are nil, t, `head', `first', `last', an integer or a
1229 predicate.  See Info node `(gnus)Customizing Articles'."
1230   :group 'gnus-article-treat
1231   :link '(custom-manual "(gnus)Customizing Articles")
1232   :type gnus-article-treat-custom)
1233
1234 (defcustom gnus-treat-strip-banner t
1235   "Strip banners from articles.
1236 The banner to be stripped is specified in the `banner' group parameter.
1237 Valid values are nil, t, `head', `first', `last', an integer or a
1238 predicate.  See Info node `(gnus)Customizing Articles'."
1239   :group 'gnus-article-treat
1240   :link '(custom-manual "(gnus)Customizing Articles")
1241   :type gnus-article-treat-custom)
1242
1243 (defcustom gnus-treat-highlight-headers 'head
1244   "Highlight the headers.
1245 Valid values are nil, t, `head', `first', `last', an integer or a
1246 predicate.  See Info node `(gnus)Customizing Articles'."
1247   :group 'gnus-article-treat
1248   :link '(custom-manual "(gnus)Customizing Articles")
1249   :type gnus-article-treat-head-custom)
1250 (put 'gnus-treat-highlight-headers 'highlight t)
1251
1252 (defcustom gnus-treat-highlight-citation t
1253   "Highlight cited text.
1254 Valid values are nil, t, `head', `first', `last', an integer or a
1255 predicate.  See Info node `(gnus)Customizing Articles'."
1256   :group 'gnus-article-treat
1257   :link '(custom-manual "(gnus)Customizing Articles")
1258   :type gnus-article-treat-custom)
1259 (put 'gnus-treat-highlight-citation 'highlight t)
1260
1261 (defcustom gnus-treat-date-ut nil
1262   "Display the Date in UT (GMT).
1263 Valid values are nil, t, `head', `first', `last', an integer or a
1264 predicate.  See Info node `(gnus)Customizing Articles'."
1265   :group 'gnus-article-treat
1266   :link '(custom-manual "(gnus)Customizing Articles")
1267   :type gnus-article-treat-head-custom)
1268
1269 (defcustom gnus-treat-date-local nil
1270   "Display the Date in the local timezone.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate.  See Info node `(gnus)Customizing Articles'."
1273   :group 'gnus-article-treat
1274   :link '(custom-manual "(gnus)Customizing Articles")
1275   :type gnus-article-treat-head-custom)
1276
1277 (defcustom gnus-treat-date-english nil
1278   "Display the Date in a format that can be read aloud in English.
1279 Valid values are nil, t, `head', `first', `last', an integer or a
1280 predicate.  See Info node `(gnus)Customizing Articles'."
1281   :version "22.1"
1282   :group 'gnus-article-treat
1283   :link '(custom-manual "(gnus)Customizing Articles")
1284   :type gnus-article-treat-head-custom)
1285
1286 (defcustom gnus-treat-date-lapsed nil
1287   "Display the Date header in a way that says how much time has elapsed.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate.  See Info node `(gnus)Customizing Articles'."
1290   :group 'gnus-article-treat
1291   :link '(custom-manual "(gnus)Customizing Articles")
1292   :type gnus-article-treat-head-custom)
1293
1294 (defcustom gnus-treat-date-original nil
1295   "Display the date in the original timezone.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate.  See Info node `(gnus)Customizing Articles'."
1298   :group 'gnus-article-treat
1299   :link '(custom-manual "(gnus)Customizing Articles")
1300   :type gnus-article-treat-head-custom)
1301
1302 (defcustom gnus-treat-date-iso8601 nil
1303   "Display the date in the ISO8601 format.
1304 Valid values are nil, t, `head', `first', `last', an integer or a
1305 predicate.  See Info node `(gnus)Customizing Articles'."
1306   :version "21.1"
1307   :group 'gnus-article-treat
1308   :link '(custom-manual "(gnus)Customizing Articles")
1309   :type gnus-article-treat-head-custom)
1310
1311 (defcustom gnus-treat-date-user-defined nil
1312   "Display the date in a user-defined format.
1313 The format is defined by the `gnus-article-time-format' variable.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate.  See Info node `(gnus)Customizing Articles'."
1316   :group 'gnus-article-treat
1317   :link '(custom-manual "(gnus)Customizing Articles")
1318   :type gnus-article-treat-head-custom)
1319
1320 (defcustom gnus-treat-strip-headers-in-body t
1321   "Strip the X-No-Archive header line from the beginning of the body.
1322 Valid values are nil, t, `head', `first', `last', an integer or a
1323 predicate.  See Info node `(gnus)Customizing Articles'."
1324   :version "21.1"
1325   :group 'gnus-article-treat
1326   :link '(custom-manual "(gnus)Customizing Articles")
1327   :type gnus-article-treat-custom)
1328
1329 (defcustom gnus-treat-strip-trailing-blank-lines nil
1330   "Strip trailing blank lines.
1331 Valid values are nil, t, `head', `first', `last', an integer or a
1332 predicate.  See Info node `(gnus)Customizing Articles'.
1333
1334 When set to t, it also strips trailing blanks in all MIME parts.
1335 Consider to use `last' instead."
1336   :group 'gnus-article-treat
1337   :link '(custom-manual "(gnus)Customizing Articles")
1338   :type gnus-article-treat-custom)
1339
1340 (defcustom gnus-treat-strip-leading-blank-lines nil
1341   "Strip leading blank lines.
1342 Valid values are nil, t, `head', `first', `last', an integer or a
1343 predicate.  See Info node `(gnus)Customizing Articles'.
1344
1345 When set to t, it also strips trailing blanks in all MIME parts."
1346   :group 'gnus-article-treat
1347   :link '(custom-manual "(gnus)Customizing Articles")
1348   :type gnus-article-treat-custom)
1349
1350 (defcustom gnus-treat-strip-multiple-blank-lines nil
1351   "Strip multiple blank lines.
1352 Valid values are nil, t, `head', `first', `last', an integer or a
1353 predicate.  See Info node `(gnus)Customizing Articles'."
1354   :group 'gnus-article-treat
1355   :link '(custom-manual "(gnus)Customizing Articles")
1356   :type gnus-article-treat-custom)
1357
1358 (defcustom gnus-treat-unfold-headers 'head
1359   "Unfold folded header lines.
1360 Valid values are nil, t, `head', `first', `last', an integer or a
1361 predicate.  See Info node `(gnus)Customizing Articles'."
1362   :version "22.1"
1363   :group 'gnus-article-treat
1364   :link '(custom-manual "(gnus)Customizing Articles")
1365   :type gnus-article-treat-custom)
1366
1367 (defcustom gnus-article-unfold-long-headers nil
1368   "If non-nil, allow unfolding headers even if the header is long.
1369 If it is a regexp, only long headers matching this regexp are unfolded.
1370 If it is t, all long headers are unfolded.
1371
1372 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1373   :version "23.1" ;; No Gnus
1374   :group 'gnus-article-treat
1375   :type '(choice (const nil)
1376                  (const :tag "all" t)
1377                  (regexp)))
1378
1379 (defcustom gnus-treat-fold-headers nil
1380   "Fold headers.
1381 Valid values are nil, t, `head', `first', `last', an integer or a
1382 predicate.  See Info node `(gnus)Customizing Articles'."
1383   :version "22.1"
1384   :group 'gnus-article-treat
1385   :link '(custom-manual "(gnus)Customizing Articles")
1386   :type gnus-article-treat-custom)
1387
1388 (defcustom gnus-treat-fold-newsgroups 'head
1389   "Fold the Newsgroups and Followup-To headers.
1390 Valid values are nil, t, `head', `first', `last', an integer or a
1391 predicate.  See Info node `(gnus)Customizing Articles'."
1392   :version "22.1"
1393   :group 'gnus-article-treat
1394   :link '(custom-manual "(gnus)Customizing Articles")
1395   :type gnus-article-treat-custom)
1396
1397 (defcustom gnus-treat-overstrike t
1398   "Treat overstrike highlighting.
1399 Valid values are nil, t, `head', `first', `last', an integer or a
1400 predicate.  See Info node `(gnus)Customizing Articles'."
1401   :group 'gnus-article-treat
1402   :link '(custom-manual "(gnus)Customizing Articles")
1403   :type gnus-article-treat-custom)
1404 (put 'gnus-treat-overstrike 'highlight t)
1405
1406 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1407   "Treat ANSI SGR control sequences.
1408 Valid values are nil, t, `head', `first', `last', an integer or a
1409 predicate.  See Info node `(gnus)Customizing Articles'."
1410   :group 'gnus-article-treat
1411   :link '(custom-manual "(gnus)Customizing Articles")
1412   :type gnus-article-treat-custom)
1413
1414 (make-obsolete-variable 'gnus-treat-display-xface
1415                         'gnus-treat-display-x-face "Emacs 22.1")
1416
1417 (defcustom gnus-treat-display-x-face
1418   (and (not noninteractive)
1419        (gnus-image-type-available-p 'xbm)
1420        (if (featurep 'xemacs)
1421            (featurep 'xface)
1422          (condition-case nil
1423              (and (string-match "^0x" (shell-command-to-string "uncompface"))
1424                   (executable-find "icontopbm"))
1425            ;; shell-command-to-string may signal an error, e.g. if
1426            ;; shell-file-name is not found.
1427            (error nil)))
1428        'head)
1429   "Display X-Face headers.
1430 Valid values are nil and `head'.
1431 See Info node `(gnus)Customizing Articles' and Info node
1432 `(gnus)X-Face' for details."
1433   :group 'gnus-article-treat
1434   :version "21.1"
1435   :link '(custom-manual "(gnus)Customizing Articles")
1436   :link '(custom-manual "(gnus)X-Face")
1437   :type gnus-article-treat-head-custom
1438   :set (lambda (symbol value)
1439          (set-default
1440           symbol
1441           (cond ((or (boundp symbol) (get symbol 'saved-value))
1442                  value)
1443                 ((boundp 'gnus-treat-display-xface)
1444                  (message "\
1445 ** gnus-treat-display-xface is an obsolete variable;\
1446  use gnus-treat-display-x-face instead")
1447                  (default-value 'gnus-treat-display-xface))
1448                 ((get 'gnus-treat-display-xface 'saved-value)
1449                  (message "\
1450 ** gnus-treat-display-xface is an obsolete variable;\
1451  use gnus-treat-display-x-face instead")
1452                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1453                 (t
1454                  value)))))
1455 (put 'gnus-treat-display-x-face 'highlight t)
1456
1457 (defcustom gnus-treat-display-face
1458   (and (not noninteractive)
1459        (gnus-image-type-available-p 'png)
1460        'head)
1461   "Display Face headers.
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate.  See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Face' for details."
1465   :group 'gnus-article-treat
1466   :version "22.1"
1467   :link '(custom-manual "(gnus)Customizing Articles")
1468   :link '(custom-manual "(gnus)X-Face")
1469   :type gnus-article-treat-head-custom)
1470 (put 'gnus-treat-display-face 'highlight t)
1471
1472 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1473   "Display smileys.
1474 Valid values are nil, t, `head', `first', `last', an integer or a
1475 predicate.  See Info node `(gnus)Customizing Articles' and Info
1476 node `(gnus)Smileys' for details."
1477   :group 'gnus-article-treat
1478   :version "21.1"
1479   :link '(custom-manual "(gnus)Customizing Articles")
1480   :link '(custom-manual "(gnus)Smileys")
1481   :type gnus-article-treat-custom)
1482 (put 'gnus-treat-display-smileys 'highlight t)
1483
1484 (defcustom gnus-treat-from-picon
1485   (if (and (gnus-image-type-available-p 'xpm)
1486            (gnus-picons-installed-p))
1487       'head nil)
1488   "Display picons in the From header.
1489 Valid values are nil, t, `head', `first', `last', an integer or a
1490 predicate.  See Info node `(gnus)Customizing Articles' and Info
1491 node `(gnus)Picons' for details."
1492   :version "22.1"
1493   :group 'gnus-article-treat
1494   :group 'gnus-picon
1495   :link '(custom-manual "(gnus)Customizing Articles")
1496   :link '(custom-manual "(gnus)Picons")
1497   :type gnus-article-treat-head-custom)
1498 (put 'gnus-treat-from-picon 'highlight t)
1499
1500 (defcustom gnus-treat-mail-picon
1501   (if (and (gnus-image-type-available-p 'xpm)
1502            (gnus-picons-installed-p))
1503       'head nil)
1504   "Display picons in To and Cc headers.
1505 Valid values are nil, t, `head', `first', `last', an integer or a
1506 predicate.  See Info node `(gnus)Customizing Articles' and Info
1507 node `(gnus)Picons' for details."
1508   :version "22.1"
1509   :group 'gnus-article-treat
1510   :group 'gnus-picon
1511   :link '(custom-manual "(gnus)Customizing Articles")
1512   :link '(custom-manual "(gnus)Picons")
1513   :type gnus-article-treat-head-custom)
1514 (put 'gnus-treat-mail-picon 'highlight t)
1515
1516 (defcustom gnus-treat-newsgroups-picon
1517   (if (and (gnus-image-type-available-p 'xpm)
1518            (gnus-picons-installed-p))
1519       'head nil)
1520   "Display picons in the Newsgroups and Followup-To headers.
1521 Valid values are nil, t, `head', `first', `last', an integer or a
1522 predicate.  See Info node `(gnus)Customizing Articles' and Info
1523 node `(gnus)Picons' for details."
1524   :version "22.1"
1525   :group 'gnus-article-treat
1526   :group 'gnus-picon
1527   :link '(custom-manual "(gnus)Customizing Articles")
1528   :link '(custom-manual "(gnus)Picons")
1529   :type gnus-article-treat-head-custom)
1530 (put 'gnus-treat-newsgroups-picon 'highlight t)
1531
1532 (defcustom gnus-treat-from-gravatar nil
1533   "Display gravatars in the From header.
1534 Valid values are nil, t, `head', `first', `last', an integer or a
1535 predicate.  See Info node `(gnus)Customizing Articles' and Info
1536 node `(gnus)Gravatars' for details."
1537   :version "24.1"
1538   :group 'gnus-article-treat
1539   :group 'gnus-gravatar
1540   :link '(custom-manual "(gnus)Customizing Articles")
1541   :link '(custom-manual "(gnus)Gravatars")
1542   :type gnus-article-treat-head-custom)
1543 (put 'gnus-treat-from-gravatar 'highlight t)
1544
1545 (defcustom gnus-treat-mail-gravatar nil
1546   "Display gravatars in To and Cc headers.
1547 Valid values are nil, t, `head', `first', `last', an integer or a
1548 predicate.  See Info node `(gnus)Customizing Articles' and Info
1549 node `(gnus)Gravatars' for details."
1550   :version "24.1"
1551   :group 'gnus-article-treat
1552   :group 'gnus-gravatar
1553   :link '(custom-manual "(gnus)Customizing Articles")
1554   :link '(custom-manual "(gnus)Gravatars")
1555   :type gnus-article-treat-head-custom)
1556 (put 'gnus-treat-mail-gravatar 'highlight t)
1557
1558 (defcustom gnus-treat-body-boundary
1559   (if (or gnus-treat-newsgroups-picon
1560           gnus-treat-mail-picon
1561           gnus-treat-from-picon
1562           gnus-treat-from-gravatar
1563           gnus-treat-mail-gravatar)
1564       ;; If there's much decoration, the user might prefer a boundery.
1565       'head
1566     nil)
1567   "Draw a boundary at the end of the headers.
1568 Valid values are nil and `head'.
1569 See Info node `(gnus)Customizing Articles' for details."
1570   :version "22.1"
1571   :group 'gnus-article-treat
1572   :link '(custom-manual "(gnus)Customizing Articles")
1573   :type gnus-article-treat-head-custom)
1574
1575 (defcustom gnus-treat-capitalize-sentences nil
1576   "Capitalize sentence-starting words.
1577 Valid values are nil, t, `head', `first', `last', an integer or a
1578 predicate.  See Info node `(gnus)Customizing Articles'."
1579   :version "21.1"
1580   :group 'gnus-article-treat
1581   :link '(custom-manual "(gnus)Customizing Articles")
1582   :type gnus-article-treat-custom)
1583
1584 (defcustom gnus-treat-wash-html nil
1585   "Format as HTML.
1586 Valid values are nil, t, `head', `first', `last', an integer or a
1587 predicate.  See Info node `(gnus)Customizing Articles'."
1588   :version "22.1"
1589   :group 'gnus-article-treat
1590   :link '(custom-manual "(gnus)Customizing Articles")
1591   :type gnus-article-treat-custom)
1592
1593 (defcustom gnus-treat-fill-long-lines nil
1594   "Fill long lines.
1595 Valid values are nil, t, `head', `first', `last', an integer or a
1596 predicate.  See Info node `(gnus)Customizing Articles'."
1597   :group 'gnus-article-treat
1598   :link '(custom-manual "(gnus)Customizing Articles")
1599   :type gnus-article-treat-custom)
1600
1601 (defcustom gnus-treat-x-pgp-sig nil
1602   "Verify X-PGP-Sig.
1603 To automatically treat X-PGP-Sig, set it to head.
1604 Valid values are nil, t, `head', `first', `last', an integer or a
1605 predicate.  See Info node `(gnus)Customizing Articles'."
1606   :version "22.1"
1607   :group 'gnus-article-treat
1608   :group 'mime-security
1609   :link '(custom-manual "(gnus)Customizing Articles")
1610   :type gnus-article-treat-custom)
1611
1612 (defvar gnus-article-encrypt-protocol-alist
1613   '(("PGP" . mml2015-self-encrypt)))
1614
1615 ;; Set to nil if more than one protocol added to
1616 ;; gnus-article-encrypt-protocol-alist.
1617 (defcustom gnus-article-encrypt-protocol "PGP"
1618   "The protocol used for encrypt articles.
1619 It is a string, such as \"PGP\". If nil, ask user."
1620   :version "22.1"
1621   :type 'string
1622   :group 'mime-security)
1623
1624 (defvar gnus-article-wash-function nil
1625   "Function used for converting HTML into text.")
1626
1627 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1628                               (mm-coding-system-p 'utf-8)
1629                               (executable-find idna-program))
1630   "Whether IDNA decoding of headers is used when viewing messages.
1631 This requires GNU Libidn, and by default only enabled if it is found."
1632   :version "22.1"
1633   :group 'gnus-article-headers
1634   :type 'boolean)
1635
1636 (defcustom gnus-article-over-scroll nil
1637   "If non-nil, allow scrolling the article buffer even when there no more text."
1638   :version "22.1"
1639   :group 'gnus-article
1640   :type 'boolean)
1641
1642 ;;; Internal variables
1643
1644 (defvar gnus-english-month-names
1645   '("January" "February" "March" "April" "May" "June" "July" "August"
1646     "September" "October" "November" "December"))
1647
1648 (defvar article-goto-body-goes-to-point-min-p nil)
1649 (defvar gnus-article-wash-types nil)
1650 (defvar gnus-article-emphasis-alist nil)
1651 (defvar gnus-article-image-alist nil)
1652
1653 (defvar gnus-article-mime-handle-alist-1 nil)
1654 (defvar gnus-treatment-function-alist
1655   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1656     (gnus-treat-strip-banner gnus-article-strip-banner)
1657     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1658     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1659     (gnus-treat-buttonize gnus-article-add-buttons)
1660     (gnus-treat-fill-article gnus-article-fill-cited-article)
1661     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1662     (gnus-treat-strip-cr gnus-article-remove-cr)
1663     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1664     (gnus-treat-date-ut gnus-article-date-ut)
1665     (gnus-treat-date-local gnus-article-date-local)
1666     (gnus-treat-date-english gnus-article-date-english)
1667     (gnus-treat-date-original gnus-article-date-original)
1668     (gnus-treat-date-user-defined gnus-article-date-user)
1669     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1670     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1671     (gnus-treat-display-x-face gnus-article-display-x-face)
1672     (gnus-treat-display-face gnus-article-display-face)
1673     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1674     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1675     (gnus-treat-hide-signature gnus-article-hide-signature)
1676     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1677     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1678     (gnus-treat-from-picon gnus-treat-from-picon)
1679     (gnus-treat-mail-picon gnus-treat-mail-picon)
1680     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1681     (gnus-treat-strip-pem gnus-article-hide-pem)
1682     (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1683     (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1684     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1685     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1686     (gnus-treat-strip-trailing-blank-lines
1687      gnus-article-remove-trailing-blank-lines)
1688     (gnus-treat-strip-leading-blank-lines
1689      gnus-article-strip-leading-blank-lines)
1690     (gnus-treat-strip-multiple-blank-lines
1691      gnus-article-strip-multiple-blank-lines)
1692     (gnus-treat-overstrike gnus-article-treat-overstrike)
1693     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1694     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1695     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1696     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1697     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1698     (gnus-treat-display-smileys gnus-treat-smiley)
1699     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1700     (gnus-treat-wash-html gnus-article-wash-html)
1701     (gnus-treat-emphasize gnus-article-emphasize)
1702     (gnus-treat-hide-citation gnus-article-hide-citation)
1703     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1704     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1705     (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1706
1707 (defvar gnus-article-mime-handle-alist nil)
1708 (defvar article-lapsed-timer nil)
1709 (defvar gnus-article-current-summary nil)
1710
1711 (defvar gnus-article-mode-syntax-table
1712   (let ((table (copy-syntax-table text-mode-syntax-table)))
1713     ;; This causes the citation match run O(2^n).
1714     ;; (modify-syntax-entry ?- "w" table)
1715     (modify-syntax-entry ?> ")<" table)
1716     (modify-syntax-entry ?< "(>" table)
1717     ;; make M-. in article buffers work for `foo' strings
1718     (modify-syntax-entry ?' " " table)
1719     (modify-syntax-entry ?` " " table)
1720     table)
1721   "Syntax table used in article mode buffers.
1722 Initialized from `text-mode-syntax-table.")
1723
1724 (defvar gnus-save-article-buffer nil)
1725
1726 (defvar gnus-number-of-articles-to-be-saved nil)
1727
1728 (defvar gnus-inhibit-hiding nil)
1729
1730 (defvar gnus-article-edit-mode nil)
1731
1732 ;;; Macros for dealing with the article buffer.
1733
1734 (defmacro gnus-with-article-headers (&rest forms)
1735   `(with-current-buffer gnus-article-buffer
1736      (save-restriction
1737        (let ((inhibit-read-only t)
1738              (inhibit-point-motion-hooks t)
1739              (case-fold-search t))
1740          (article-narrow-to-head)
1741          ,@forms))))
1742
1743 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1744 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1745
1746 (defmacro gnus-with-article-buffer (&rest forms)
1747   `(with-current-buffer gnus-article-buffer
1748      (let ((inhibit-read-only t))
1749        ,@forms)))
1750
1751 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1752 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1753
1754 (defun gnus-article-goto-header (header)
1755   "Go to HEADER, which is a regular expression."
1756   (re-search-forward (concat "^\\(" header "\\):") nil t))
1757
1758 (defsubst gnus-article-hide-text (b e props)
1759   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1760   (gnus-add-text-properties-when 'article-type nil b e props)
1761   (when (memq 'intangible props)
1762     (put-text-property
1763      (max (1- b) (point-min))
1764      b 'intangible (cddr (memq 'intangible props)))))
1765
1766 (defsubst gnus-article-unhide-text (b e)
1767   "Remove hidden text properties from region between B and E."
1768   (remove-text-properties b e gnus-hidden-properties)
1769   (when (memq 'intangible gnus-hidden-properties)
1770     (put-text-property (max (1- b) (point-min))
1771                        b 'intangible nil)))
1772
1773 (defun gnus-article-hide-text-type (b e type)
1774   "Hide text of TYPE between B and E."
1775   (gnus-add-wash-type type)
1776   (gnus-article-hide-text
1777    b e (cons 'article-type (cons type gnus-hidden-properties))))
1778
1779 (defun gnus-article-unhide-text-type (b e type)
1780   "Unhide text of TYPE between B and E."
1781   (gnus-delete-wash-type type)
1782   (remove-text-properties
1783    b e (cons 'article-type (cons type gnus-hidden-properties)))
1784   (when (memq 'intangible gnus-hidden-properties)
1785     (put-text-property (max (1- b) (point-min))
1786                        b 'intangible nil)))
1787
1788 (defun gnus-article-hide-text-of-type (type)
1789   "Hide text of TYPE in the current buffer."
1790   (save-excursion
1791     (let ((b (point-min))
1792           (e (point-max)))
1793       (while (setq b (text-property-any b e 'article-type type))
1794         (add-text-properties b (incf b) gnus-hidden-properties)))))
1795
1796 (defun gnus-article-delete-text-of-type (type)
1797   "Delete text of TYPE in the current buffer."
1798   (save-excursion
1799     (let ((b (point-min)))
1800       (if (eq type 'multipart)
1801           ;; Remove MIME buttons associated with multipart/alternative parts.
1802           (progn
1803             (goto-char b)
1804             (while (if (get-text-property (point) 'gnus-part)
1805                        (setq b (point))
1806                      (when (setq b (next-single-property-change (point)
1807                                                                 'gnus-part))
1808                        (goto-char b)
1809                        t))
1810               (end-of-line)
1811               (skip-chars-forward "\n")
1812               (when (eq (get-text-property b 'article-type) 'multipart)
1813                 (delete-region b (point)))))
1814         (while (setq b (text-property-any b (point-max) 'article-type type))
1815           (delete-region
1816            b (or (text-property-not-all b (point-max) 'article-type type)
1817                  (point-max))))))))
1818
1819 (defun gnus-article-delete-invisible-text ()
1820   "Delete all invisible text in the current buffer."
1821   (save-excursion
1822     (let ((b (point-min)))
1823       (while (setq b (text-property-any b (point-max) 'invisible t))
1824         (delete-region
1825          b (or (text-property-not-all b (point-max) 'invisible t)
1826                (point-max)))))))
1827
1828 (defun gnus-article-text-type-exists-p (type)
1829   "Say whether any text of type TYPE exists in the buffer."
1830   (text-property-any (point-min) (point-max) 'article-type type))
1831
1832 (defsubst gnus-article-header-rank ()
1833   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1834   (let ((list gnus-sorted-header-list)
1835         (i 1))
1836     (while list
1837       (if (looking-at (car list))
1838           (setq list nil)
1839         (setq list (cdr list))
1840         (incf i)))
1841       i))
1842
1843 (defun article-hide-headers (&optional arg delete)
1844   "Hide unwanted headers and possibly sort them as well."
1845   (interactive)
1846   ;; This function might be inhibited.
1847   (unless gnus-inhibit-hiding
1848     (let ((inhibit-read-only t)
1849           (case-fold-search t)
1850           (max (1+ (length gnus-sorted-header-list)))
1851           (inhibit-point-motion-hooks t)
1852           (cur (current-buffer))
1853           ignored visible beg)
1854       (save-excursion
1855         ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1856         ;; group parameters, so we should go to the summary buffer.
1857         (when (prog1
1858                   (condition-case nil
1859                       (progn (set-buffer gnus-summary-buffer) t)
1860                     (error nil))
1861                 (setq ignored (when (not gnus-visible-headers)
1862                                 (cond ((stringp gnus-ignored-headers)
1863                                        gnus-ignored-headers)
1864                                       ((listp gnus-ignored-headers)
1865                                        (mapconcat 'identity
1866                                                   gnus-ignored-headers
1867                                                   "\\|"))))
1868                       visible (cond ((stringp gnus-visible-headers)
1869                                      gnus-visible-headers)
1870                                     ((and gnus-visible-headers
1871                                           (listp gnus-visible-headers))
1872                                      (mapconcat 'identity
1873                                                 gnus-visible-headers
1874                                                 "\\|")))))
1875           (set-buffer cur))
1876         (save-restriction
1877           ;; First we narrow to just the headers.
1878           (article-narrow-to-head)
1879           ;; Hide any "From " lines at the beginning of (mail) articles.
1880           (while (looking-at "From ")
1881             (forward-line 1))
1882           (unless (bobp)
1883             (delete-region (point-min) (point)))
1884           ;; Then treat the rest of the header lines.
1885           ;; Then we use the two regular expressions
1886           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1887           ;; select which header lines is to remain visible in the
1888           ;; article buffer.
1889           (while (re-search-forward "^[^ \t:]*:" nil t)
1890             (beginning-of-line)
1891             ;; Mark the rank of the header.
1892             (put-text-property
1893              (point) (1+ (point)) 'message-rank
1894              (if (or (and visible (looking-at visible))
1895                      (and ignored
1896                           (not (looking-at ignored))))
1897                  (gnus-article-header-rank)
1898                (+ 2 max)))
1899             (forward-line 1))
1900           (message-sort-headers-1)
1901           (when (setq beg (text-property-any
1902                            (point-min) (point-max) 'message-rank (+ 2 max)))
1903             ;; We delete the unwanted headers.
1904             (gnus-add-wash-type 'headers)
1905             (add-text-properties (point-min) (+ 5 (point-min))
1906                                  '(article-type headers dummy-invisible t))
1907             (delete-region beg (point-max))))))))
1908
1909 (defun article-hide-boring-headers (&optional arg)
1910   "Toggle hiding of headers that aren't very interesting.
1911 If given a negative prefix, always show; if given a positive prefix,
1912 always hide."
1913   (interactive (gnus-article-hidden-arg))
1914   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1915              (not gnus-show-all-headers))
1916     (save-excursion
1917       (save-restriction
1918         (let ((inhibit-read-only t)
1919               (inhibit-point-motion-hooks t))
1920           (article-narrow-to-head)
1921           (dolist (elem gnus-boring-article-headers)
1922             (goto-char (point-min))
1923             (cond
1924              ;; Hide empty headers.
1925              ((eq elem 'empty)
1926               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1927                 (forward-line -1)
1928                 (gnus-article-hide-text-type
1929                  (point-at-bol)
1930                  (progn
1931                    (end-of-line)
1932                    (if (re-search-forward "^[^ \t]" nil t)
1933                        (match-beginning 0)
1934                      (point-max)))
1935                  'boring-headers)))
1936              ;; Hide boring Newsgroups header.
1937              ((eq elem 'newsgroups)
1938               (when (gnus-string-equal
1939                      (gnus-fetch-field "newsgroups")
1940                      (gnus-group-real-name
1941                       (if (boundp 'gnus-newsgroup-name)
1942                           gnus-newsgroup-name
1943                         "")))
1944                 (gnus-article-hide-header "newsgroups")))
1945              ((eq elem 'to-address)
1946               (let ((to (message-fetch-field "to"))
1947                     (to-address
1948                      (gnus-parameter-to-address
1949                       (if (boundp 'gnus-newsgroup-name)
1950                           gnus-newsgroup-name ""))))
1951                 (when (and to to-address
1952                            (ignore-errors
1953                              (gnus-string-equal
1954                               ;; only one address in To
1955                               (nth 1 (mail-extract-address-components to))
1956                               to-address)))
1957                   (gnus-article-hide-header "to"))))
1958              ((eq elem 'to-list)
1959               (let ((to (message-fetch-field "to"))
1960                     (to-list
1961                      (gnus-parameter-to-list
1962                       (if (boundp 'gnus-newsgroup-name)
1963                           gnus-newsgroup-name ""))))
1964                 (when (and to to-list
1965                            (ignore-errors
1966                              (gnus-string-equal
1967                               ;; only one address in To
1968                               (nth 1 (mail-extract-address-components to))
1969                               to-list)))
1970                   (gnus-article-hide-header "to"))))
1971              ((eq elem 'cc-list)
1972               (let ((cc (message-fetch-field "cc"))
1973                     (to-list
1974                      (gnus-parameter-to-list
1975                       (if (boundp 'gnus-newsgroup-name)
1976                           gnus-newsgroup-name ""))))
1977                 (when (and cc to-list
1978                            (ignore-errors
1979                              (gnus-string-equal
1980                               ;; only one address in CC
1981                               (nth 1 (mail-extract-address-components cc))
1982                               to-list)))
1983                   (gnus-article-hide-header "cc"))))
1984              ((eq elem 'followup-to)
1985               (when (gnus-string-equal
1986                      (message-fetch-field "followup-to")
1987                      (message-fetch-field "newsgroups"))
1988                 (gnus-article-hide-header "followup-to")))
1989              ((eq elem 'reply-to)
1990               (if (gnus-group-find-parameter
1991                    gnus-newsgroup-name 'broken-reply-to)
1992                   (gnus-article-hide-header "reply-to")
1993                 (let ((from (message-fetch-field "from"))
1994                       (reply-to (message-fetch-field "reply-to")))
1995                   (when
1996                       (and
1997                        from reply-to
1998                        (ignore-errors
1999                          (equal
2000                           (sort (mapcar
2001                                  (lambda (x) (downcase (cadr x)))
2002                                  (mail-extract-address-components from t))
2003                                 'string<)
2004                           (sort (mapcar
2005                                  (lambda (x) (downcase (cadr x)))
2006                                  (mail-extract-address-components reply-to t))
2007                                 'string<))))
2008                     (gnus-article-hide-header "reply-to")))))
2009              ((eq elem 'date)
2010               (let ((date (with-current-buffer gnus-original-article-buffer
2011                             ;; If date in `gnus-article-buffer' is localized
2012                             ;; (`gnus-treat-date-user-defined'),
2013                             ;; `days-between' might fail.
2014                             (message-fetch-field "date"))))
2015                 (when (and date
2016                            (< (days-between (current-time-string) date)
2017                               4))
2018                   (gnus-article-hide-header "date"))))
2019              ((eq elem 'long-to)
2020               (let ((to (message-fetch-field "to"))
2021                     (cc (message-fetch-field "cc")))
2022                 (when (> (length to) 1024)
2023                   (gnus-article-hide-header "to"))
2024                 (when (> (length cc) 1024)
2025                   (gnus-article-hide-header "cc"))))
2026              ((eq elem 'many-to)
2027               (let ((to-count 0)
2028                     (cc-count 0))
2029                 (goto-char (point-min))
2030                 (while (re-search-forward "^to:" nil t)
2031                   (setq to-count (1+ to-count)))
2032                 (when (> to-count 1)
2033                   (while (> to-count 0)
2034                     (goto-char (point-min))
2035                     (save-restriction
2036                       (re-search-forward "^to:" nil nil to-count)
2037                       (forward-line -1)
2038                       (narrow-to-region (point) (point-max))
2039                       (gnus-article-hide-header "to"))
2040                     (setq to-count (1- to-count))))
2041                 (goto-char (point-min))
2042                 (while (re-search-forward "^cc:" nil t)
2043                   (setq cc-count (1+ cc-count)))
2044                 (when (> cc-count 1)
2045                   (while (> cc-count 0)
2046                     (goto-char (point-min))
2047                     (save-restriction
2048                       (re-search-forward "^cc:" nil nil cc-count)
2049                       (forward-line -1)
2050                       (narrow-to-region (point) (point-max))
2051                       (gnus-article-hide-header "cc"))
2052                     (setq cc-count (1- cc-count)))))))))))))
2053
2054 (defun gnus-article-hide-header (header)
2055   (save-excursion
2056     (goto-char (point-min))
2057     (when (re-search-forward (concat "^" header ":") nil t)
2058       (gnus-article-hide-text-type
2059        (point-at-bol)
2060        (progn
2061          (end-of-line)
2062          (if (re-search-forward "^[^ \t]" nil t)
2063              (match-beginning 0)
2064            (point-max)))
2065        'boring-headers))))
2066
2067 (defvar gnus-article-normalized-header-length 40
2068   "Length of normalized headers.")
2069
2070 (defun article-normalize-headers ()
2071   "Make all header lines 40 characters long."
2072   (interactive)
2073   (let ((inhibit-read-only t)
2074         column)
2075     (save-excursion
2076       (save-restriction
2077         (article-narrow-to-head)
2078         (while (not (eobp))
2079           (cond
2080            ((< (setq column (- (point-at-eol) (point)))
2081                gnus-article-normalized-header-length)
2082             (end-of-line)
2083             (insert (make-string
2084                      (- gnus-article-normalized-header-length column)
2085                      ? )))
2086            ((> column gnus-article-normalized-header-length)
2087             (gnus-put-text-property
2088              (progn
2089                (forward-char gnus-article-normalized-header-length)
2090                (point))
2091              (point-at-eol)
2092              'invisible t))
2093            (t
2094             ;; Do nothing.
2095             ))
2096           (forward-line 1))))))
2097
2098 (defun article-treat-dumbquotes ()
2099   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2100 Note that this function guesses whether a character is a sm*rtq**t* or
2101 not, so it should only be used interactively.
2102
2103 Sm*rtq**t*s are M****s***'s unilateral extension to the
2104 iso-8859-1 character map in an attempt to provide more quoting
2105 characters.  If you see something like \\222 or \\264 where
2106 you're expecting some kind of apostrophe or quotation mark, then
2107 try this wash."
2108   (interactive)
2109   (article-translate-strings gnus-article-dumbquotes-map))
2110
2111 (defun article-translate-characters (from to)
2112   "Translate all characters in the body of the article according to FROM and TO.
2113 FROM is a string of characters to translate from; to is a string of
2114 characters to translate to."
2115   (save-excursion
2116     (when (article-goto-body)
2117       (let ((inhibit-read-only t)
2118             (x (make-string 225 ?x))
2119             (i -1))
2120         (while (< (incf i) (length x))
2121           (aset x i i))
2122         (setq i 0)
2123         (while (< i (length from))
2124           (aset x (aref from i) (aref to i))
2125           (incf i))
2126         (translate-region (point) (point-max) x)))))
2127
2128 (defun article-translate-strings (map)
2129   "Translate all string in the body of the article according to MAP.
2130 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2131   (save-excursion
2132     (when (article-goto-body)
2133       (let ((inhibit-read-only t))
2134         (dolist (elem map)
2135           (save-excursion
2136             (while (search-forward (car elem) nil t)
2137               (replace-match (cadr elem)))))))))
2138
2139 (defun article-treat-overstrike ()
2140   "Translate overstrikes into bold text."
2141   (interactive)
2142   (save-excursion
2143     (when (article-goto-body)
2144       (let ((inhibit-read-only t))
2145         (while (search-forward "\b" nil t)
2146           (let ((next (char-after))
2147                 (previous (char-after (- (point) 2))))
2148             ;; We do the boldification/underlining by hiding the
2149             ;; overstrikes and putting the proper text property
2150             ;; on the letters.
2151             (cond
2152              ((eq next previous)
2153               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2154               (put-text-property (point) (1+ (point)) 'face 'bold))
2155              ((eq next ?_)
2156               (gnus-article-hide-text-type
2157                (1- (point)) (1+ (point)) 'overstrike)
2158               (put-text-property
2159                (- (point) 2) (1- (point)) 'face 'underline))
2160              ((eq previous ?_)
2161               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2162               (put-text-property
2163                (point) (1+ (point)) 'face 'underline)))))))))
2164
2165 (defun article-treat-ansi-sequences ()
2166   "Translate ANSI SGR control sequences into overlays or extents."
2167   (interactive)
2168   (save-excursion
2169     (when (article-goto-body)
2170       (let ((inhibit-read-only t))
2171         (ansi-color-apply-on-region (point) (point-max))))))
2172
2173 (defun gnus-article-treat-unfold-headers ()
2174   "Unfold folded message headers.
2175 Only the headers that fit into the current window width will be
2176 unfolded."
2177   (interactive)
2178   (gnus-with-article-headers
2179     (let (length)
2180       (while (not (eobp))
2181         (save-restriction
2182           (mail-header-narrow-to-field)
2183           (let* ((header (buffer-string))
2184                  (unfoldable
2185                   (or (equal gnus-article-unfold-long-headers t)
2186                       (and (stringp gnus-article-unfold-long-headers)
2187                            (string-match gnus-article-unfold-long-headers header)))))
2188             (with-temp-buffer
2189               (insert header)
2190               (goto-char (point-min))
2191               (while (re-search-forward "\n[\t ]" nil t)
2192                 (replace-match " " t t)))
2193             (setq length (- (point-max) (point-min) 1))
2194             (when (or unfoldable
2195                       (< length (window-width)))
2196               (while (re-search-forward "\n[\t ]" nil t)
2197                 (replace-match " " t t))))
2198           (goto-char (point-max)))))))
2199
2200 (defun gnus-article-treat-fold-headers ()
2201   "Fold message headers."
2202   (interactive)
2203   (gnus-with-article-headers
2204     (while (not (eobp))
2205       (save-restriction
2206         (mail-header-narrow-to-field)
2207         (mail-header-fold-field)
2208         (goto-char (point-max))))))
2209
2210 (defun gnus-treat-smiley ()
2211   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2212   (interactive)
2213   (gnus-with-article-buffer
2214     (if (memq 'smiley gnus-article-wash-types)
2215         (gnus-delete-images 'smiley)
2216       (article-goto-body)
2217       (let ((images (smiley-region (point) (point-max))))
2218         (when images
2219           (gnus-add-wash-type 'smiley)
2220           (dolist (image images)
2221             (gnus-add-image 'smiley image)))))))
2222
2223 (defun gnus-article-remove-images ()
2224   "Remove all images from the article buffer."
2225   (interactive)
2226   (gnus-with-article-buffer
2227     (dolist (elem gnus-article-image-alist)
2228       (gnus-delete-images (car elem)))))
2229
2230 (defun gnus-article-treat-fold-newsgroups ()
2231   "Unfold folded message headers.
2232 Only the headers that fit into the current window width will be
2233 unfolded."
2234   (interactive)
2235   (gnus-with-article-headers
2236     (while (gnus-article-goto-header "newsgroups\\|followup-to")
2237       (save-restriction
2238         (mail-header-narrow-to-field)
2239         (while (re-search-forward ", *" nil t)
2240           (replace-match ", " t t))
2241         (mail-header-fold-field)
2242         (goto-char (point-max))))))
2243
2244 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2245   "Value of `truncate-lines' in Gnus Article buffer.
2246 Valid values are nil, t, `head', `first', `last', an integer or a
2247 predicate.  See Info node `(gnus)Customizing Articles'."
2248   :version "23.1" ;; No Gnus
2249   :group 'gnus-article
2250   ;; :link '(custom-manual "(gnus)Customizing Articles")
2251   :type 'boolean)
2252
2253 (defun gnus-article-toggle-truncate-lines (&optional arg)
2254   "Toggle whether to fold or truncate long lines in article the buffer.
2255 If ARG is non-nil and not a number, toggle
2256 `gnus-article-truncate-lines' too.  If ARG is a number, truncate
2257 long lines if and only if arg is positive."
2258   (interactive "P")
2259   (cond
2260    ((and (numberp arg) (> arg 0))
2261     (setq gnus-article-truncate-lines t))
2262    ((numberp arg)
2263     (setq gnus-article-truncate-lines nil))
2264    (arg
2265     (setq gnus-article-truncate-lines
2266           (not gnus-article-truncate-lines))))
2267   (gnus-with-article-buffer
2268     (cond
2269      ((and (numberp arg) (> arg 0))
2270       (setq truncate-lines nil))
2271      ((numberp arg)
2272       (setq truncate-lines t)))
2273     ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2274     ;; `toggle-truncate-lines' needs an argument.
2275     (toggle-truncate-lines)))
2276
2277 (defun gnus-article-treat-body-boundary ()
2278   "Place a boundary line at the end of the headers."
2279   (interactive)
2280   (when (and gnus-body-boundary-delimiter
2281              (> (length gnus-body-boundary-delimiter) 0))
2282     (gnus-with-article-headers
2283       (goto-char (point-max))
2284       (let ((start (point)))
2285         (insert "X-Boundary: ")
2286         (gnus-add-text-properties start (point) '(invisible t intangible t))
2287         (insert (let (str)
2288                   (while (>= (window-width) (length str))
2289                     (setq str (concat str gnus-body-boundary-delimiter)))
2290                   (substring str 0 (window-width)))
2291                 "\n")
2292         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2293
2294 (defun article-fill-long-lines ()
2295   "Fill lines that are wider than the window width."
2296   (interactive)
2297   (save-excursion
2298     (let ((inhibit-read-only t)
2299           (width (window-width (get-buffer-window (current-buffer)))))
2300       (save-restriction
2301         (article-goto-body)
2302         (let ((adaptive-fill-mode nil)) ;Why?  -sm
2303           (while (not (eobp))
2304             (end-of-line)
2305             (when (>= (current-column) (min fill-column width))
2306               (narrow-to-region (min (1+ (point)) (point-max))
2307                                 (point-at-bol))
2308               (let ((goback (point-marker)))
2309                 (fill-paragraph nil)
2310                 (goto-char (marker-position goback)))
2311               (widen))
2312             (forward-line 1)))))))
2313
2314 (defun article-capitalize-sentences ()
2315   "Capitalize the first word in each sentence."
2316   (interactive)
2317   (save-excursion
2318     (let ((inhibit-read-only t)
2319           (paragraph-start "^[\n\^L]"))
2320       (article-goto-body)
2321       (while (not (eobp))
2322         (capitalize-word 1)
2323         (forward-sentence)))))
2324
2325 (defun article-remove-cr ()
2326   "Remove trailing CRs and then translate remaining CRs into LFs."
2327   (interactive)
2328   (save-excursion
2329     (let ((inhibit-read-only t))
2330       (goto-char (point-min))
2331       (while (re-search-forward "\r+$" nil t)
2332         (replace-match "" t t))
2333       (goto-char (point-min))
2334       (while (search-forward "\r" nil t)
2335         (replace-match "\n" t t)))))
2336
2337 (defun article-remove-trailing-blank-lines ()
2338   "Remove all trailing blank lines from the article."
2339   (interactive)
2340   (save-excursion
2341     (let ((inhibit-read-only t))
2342       (goto-char (point-max))
2343       (delete-region
2344        (point)
2345        (progn
2346          (while (and (not (bobp))
2347                      (looking-at "^[ \t]*$")
2348                      (not (gnus-annotation-in-region-p
2349                            (point) (point-at-eol))))
2350            (forward-line -1))
2351          (forward-line 1)
2352          (point))))))
2353
2354 (defvar gnus-face-properties-alist)
2355
2356 (defun article-display-face (&optional force)
2357   "Display any Face headers in the header."
2358   (interactive (list 'force))
2359   (let ((wash-face-p buffer-read-only))
2360     (gnus-with-article-headers
2361       ;; When displaying parts, this function can be called several times on
2362       ;; the same article, without any intended toggle semantic (as typing `W
2363       ;; D d' would have). So face deletion must occur only when we come from
2364       ;; an interactive command, that is when the *Article* buffer is
2365       ;; read-only.
2366       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2367           (gnus-delete-images 'face)
2368         (let ((from (message-fetch-field "from"))
2369               face faces)
2370           (save-current-buffer
2371             (when (and wash-face-p
2372                        (gnus-buffer-live-p gnus-original-article-buffer)
2373                        (not (re-search-forward "^Face:[\t ]*" nil t)))
2374               (set-buffer gnus-original-article-buffer))
2375             (save-restriction
2376               (mail-narrow-to-head)
2377               (when (or force
2378                         ;; Check whether this face is censored.
2379                         (not (and gnus-article-x-face-too-ugly
2380                                   (or from
2381                                       (setq from (message-fetch-field "from")))
2382                                   (string-match gnus-article-x-face-too-ugly
2383                                                 from))))
2384                 (while (gnus-article-goto-header "Face")
2385                   (push (mail-header-field-value) faces)))))
2386           (when faces
2387             (goto-char (point-min))
2388             (let (png image)
2389               (unless (setq from (gnus-article-goto-header "from"))
2390                 (insert "From:")
2391                 (setq from (point))
2392                 (insert " [no `from' set]\n"))
2393               (while faces
2394                 (when (setq png (gnus-convert-face-to-png (pop faces)))
2395                   (setq image
2396                         (apply 'gnus-create-image png 'png t
2397                                (cdr (assq 'png gnus-face-properties-alist))))
2398                   (goto-char from)
2399                   (gnus-add-wash-type 'face)
2400                   (gnus-add-image 'face image)
2401                   (gnus-put-image image nil 'face))))))))))
2402
2403 (defun article-display-x-face (&optional force)
2404   "Look for an X-Face header and display it if present."
2405   (interactive (list 'force))
2406   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2407     (gnus-with-article-headers
2408       ;; Delete the old process, if any.
2409       (when (process-status "article-x-face")
2410         (delete-process "article-x-face"))
2411       ;; See the comment in `article-display-face'.
2412       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2413           ;; We have already displayed X-Faces, so we remove them
2414           ;; instead.
2415           (gnus-delete-images 'xface)
2416         ;; Display X-Faces.
2417         (let ((from (message-fetch-field "from"))
2418               x-faces face)
2419           (save-current-buffer
2420             (when (and wash-face-p
2421                        (gnus-buffer-live-p gnus-original-article-buffer)
2422                        (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2423               ;; If type `W f', use gnus-original-article-buffer,
2424               ;; otherwise use the current buffer because displaying
2425               ;; RFC822 parts calls this function too.
2426               (set-buffer gnus-original-article-buffer))
2427             (save-restriction
2428               (mail-narrow-to-head)
2429               (and gnus-article-x-face-command
2430                    (or force
2431                        ;; Check whether this face is censored.
2432                        (not (and gnus-article-x-face-too-ugly
2433                                  (or from
2434                                      (setq from (message-fetch-field "from")))
2435                                  (string-match gnus-article-x-face-too-ugly
2436                                                from))))
2437                    (while (gnus-article-goto-header "X-Face")
2438                      (push (mail-header-field-value) x-faces)))))
2439           (when x-faces
2440             ;; We display the face.
2441             (cond ((functionp gnus-article-x-face-command)
2442                    ;; The command is a lisp function, so we call it.
2443                    (mapc gnus-article-x-face-command x-faces))
2444                   ((stringp gnus-article-x-face-command)
2445                    ;; The command is a string, so we interpret the command
2446                    ;; as a, well, command, and fork it off.
2447                    (let ((process-connection-type nil))
2448                      (gnus-set-process-query-on-exit-flag
2449                       (start-process
2450                        "article-x-face" nil shell-file-name
2451                        shell-command-switch gnus-article-x-face-command)
2452                       nil)
2453                      ;; Sending multiple EOFs to xv doesn't work,
2454                      ;; so we only do a single external face.
2455                      (with-temp-buffer
2456                        (insert (car x-faces))
2457                        (process-send-region "article-x-face"
2458                                             (point-min) (point-max)))
2459                      (process-send-eof "article-x-face")))
2460                   (t
2461                    (error "`%s' set to `%s' is not a function"
2462                           gnus-article-x-face-command
2463                           'gnus-article-x-face-command)))))))))
2464
2465 (defun article-decode-mime-words ()
2466   "Decode all MIME-encoded words in the article."
2467   (interactive)
2468   (gnus-with-article-buffer
2469     (let ((inhibit-point-motion-hooks t)
2470           (mail-parse-charset gnus-newsgroup-charset)
2471           (mail-parse-ignored-charsets
2472            (with-current-buffer gnus-summary-buffer
2473              gnus-newsgroup-ignored-charsets)))
2474       (mail-decode-encoded-word-region (point-min) (point-max)))))
2475
2476 (defun article-decode-charset (&optional prompt)
2477   "Decode charset-encoded text in the article.
2478 If PROMPT (the prefix), prompt for a coding system to use."
2479   (interactive "P")
2480   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2481         (inhibit-read-only t)
2482         (mail-parse-charset gnus-newsgroup-charset)
2483         (mail-parse-ignored-charsets
2484          (save-excursion (condition-case nil
2485                              (set-buffer gnus-summary-buffer)
2486                            (error))
2487                          gnus-newsgroup-ignored-charsets))
2488         ct cte ctl charset format)
2489     (save-excursion
2490       (save-restriction
2491         (article-narrow-to-head)
2492         (setq ct (message-fetch-field "Content-Type" t)
2493               cte (message-fetch-field "Content-Transfer-Encoding" t)
2494               ctl (and ct (mail-header-parse-content-type ct))
2495               charset (cond
2496                        (prompt
2497                         (mm-read-coding-system "Charset to decode: "))
2498                        (ctl
2499                         (mail-content-type-get ctl 'charset)))
2500               format (and ctl (mail-content-type-get ctl 'format)))
2501         (when cte
2502           (setq cte (mail-header-strip cte)))
2503         (if (and ctl (not (string-match "/" (car ctl))))
2504             (setq ctl nil))
2505         (goto-char (point-max)))
2506       (forward-line 1)
2507       (save-restriction
2508         (narrow-to-region (point) (point-max))
2509         (when (and (eq mail-parse-charset 'gnus-decoded)
2510                    (eq (mm-body-7-or-8) '8bit))
2511           ;; The text code could have been decoded.
2512           (setq charset mail-parse-charset))
2513         (when (and (or (not ctl)
2514                        (equal (car ctl) "text/plain"))
2515                    (not format)) ;; article with format will decode later.
2516           (mm-decode-body
2517            charset (and cte (intern (downcase
2518                                      (gnus-strip-whitespace cte))))
2519            (car ctl)))))))
2520
2521 (defun article-decode-encoded-words ()
2522   "Remove encoded-word encoding from headers."
2523   (let ((inhibit-point-motion-hooks t)
2524         (mail-parse-charset gnus-newsgroup-charset)
2525         (mail-parse-ignored-charsets
2526          (save-excursion (condition-case nil
2527                              (set-buffer gnus-summary-buffer)
2528                            (error))
2529                          gnus-newsgroup-ignored-charsets))
2530         (inhibit-read-only t)
2531         end start)
2532     (goto-char (point-min))
2533     (when (search-forward "\n\n" nil 'move)
2534       (forward-line -1))
2535     (setq end (point))
2536     (while (not (bobp))
2537       (while (progn
2538                (forward-line -1)
2539                (and (not (bobp))
2540                     (memq (char-after) '(?\t ? )))))
2541       (setq start (point))
2542       (if (looking-at "\
2543 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2544 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2545           (funcall gnus-decode-address-function start end)
2546         (funcall gnus-decode-header-function start end))
2547       (goto-char (setq end start)))))
2548
2549 (defun article-decode-group-name ()
2550   "Decode group names in Newsgroups, Followup-To and Xref headers."
2551   (let ((inhibit-point-motion-hooks t)
2552         (inhibit-read-only t)
2553         (method (gnus-find-method-for-group gnus-newsgroup-name))
2554         regexp)
2555     (when (and (or gnus-group-name-charset-method-alist
2556                    gnus-group-name-charset-group-alist)
2557                (gnus-buffer-live-p gnus-original-article-buffer))
2558       (save-restriction
2559         (article-narrow-to-head)
2560         (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2561           (with-current-buffer gnus-original-article-buffer
2562             (goto-char (point-min)))
2563           (setq regexp (concat "^" header
2564                                ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2565           (while (re-search-forward regexp nil t)
2566             (replace-match (save-match-data
2567                              (gnus-decode-newsgroups
2568                               ;; XXX how to use data in article buffer?
2569                               (with-current-buffer gnus-original-article-buffer
2570                                 (re-search-forward regexp nil t)
2571                                 (match-string 1))
2572                               gnus-newsgroup-name method))
2573                            t t nil 1))
2574           (goto-char (point-min)))))))
2575
2576 (autoload 'idna-to-unicode "idna")
2577
2578 (defun article-decode-idna-rhs ()
2579   "Decode IDNA strings in RHS in various headers in current buffer.
2580 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2581 Mail-Reply-To: and Mail-Followup-To:."
2582   (when gnus-use-idna
2583     (save-restriction
2584       (let ((inhibit-point-motion-hooks t)
2585             (inhibit-read-only t))
2586         (article-narrow-to-head)
2587         (goto-char (point-min))
2588         (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2589           (let (ace unicode)
2590             (when (save-match-data
2591                     (and (setq ace (match-string 1))
2592                          (save-excursion
2593                            (and (re-search-backward "^[^ \t]" nil t)
2594                                 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2595                          (setq unicode (idna-to-unicode ace))))
2596               (unless (string= ace unicode)
2597                 (replace-match unicode nil nil nil 1)))))))))
2598
2599 (defun article-de-quoted-unreadable (&optional force read-charset)
2600   "Translate a quoted-printable-encoded article.
2601 If FORCE, decode the article whether it is marked as quoted-printable
2602 or not.
2603 If READ-CHARSET, ask for a coding system."
2604   (interactive (list 'force current-prefix-arg))
2605   (save-excursion
2606     (let ((inhibit-read-only t) type charset)
2607       (if (gnus-buffer-live-p gnus-original-article-buffer)
2608           (with-current-buffer gnus-original-article-buffer
2609             (setq type
2610                   (gnus-fetch-field "content-transfer-encoding"))
2611             (let* ((ct (gnus-fetch-field "content-type"))
2612                    (ctl (and ct (mail-header-parse-content-type ct))))
2613               (setq charset (and ctl
2614                                  (mail-content-type-get ctl 'charset)))
2615               (if (stringp charset)
2616                   (setq charset (intern (downcase charset)))))))
2617       (if read-charset
2618           (setq charset (mm-read-coding-system "Charset: " charset)))
2619       (unless charset
2620         (setq charset gnus-newsgroup-charset))
2621       (when (or force
2622                 (and type (let ((case-fold-search t))
2623                             (string-match "quoted-printable" type))))
2624         (article-goto-body)
2625         (quoted-printable-decode-region
2626          (point) (point-max) (mm-charset-to-coding-system charset))))))
2627
2628 (defun article-de-base64-unreadable (&optional force read-charset)
2629   "Translate a base64 article.
2630 If FORCE, decode the article whether it is marked as base64 not.
2631 If READ-CHARSET, ask for a coding system."
2632   (interactive (list 'force current-prefix-arg))
2633   (save-excursion
2634     (let ((inhibit-read-only t) type charset)
2635       (if (gnus-buffer-live-p gnus-original-article-buffer)
2636           (with-current-buffer gnus-original-article-buffer
2637             (setq type
2638                   (gnus-fetch-field "content-transfer-encoding"))
2639             (let* ((ct (gnus-fetch-field "content-type"))
2640                    (ctl (and ct (mail-header-parse-content-type ct))))
2641               (setq charset (and ctl
2642                                  (mail-content-type-get ctl 'charset)))
2643               (if (stringp charset)
2644                   (setq charset (intern (downcase charset)))))))
2645       (if read-charset
2646           (setq charset (mm-read-coding-system "Charset: " charset)))
2647       (unless charset
2648         (setq charset gnus-newsgroup-charset))
2649       (when (or force
2650                 (and type (let ((case-fold-search t))
2651                             (string-match "base64" type))))
2652         (article-goto-body)
2653         (save-restriction
2654           (narrow-to-region (point) (point-max))
2655           (base64-decode-region (point-min) (point-max))
2656           (mm-decode-coding-region
2657            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2658
2659 (eval-when-compile
2660   (require 'rfc1843))
2661
2662 (defun article-decode-HZ ()
2663   "Translate a HZ-encoded article."
2664   (interactive)
2665   (require 'rfc1843)
2666   (save-excursion
2667     (let ((inhibit-read-only t))
2668       (rfc1843-decode-region (point-min) (point-max)))))
2669
2670 (defun article-unsplit-urls ()
2671   "Remove the newlines that some other mailers insert into URLs."
2672   (interactive)
2673   (save-excursion
2674     (let ((inhibit-read-only t))
2675       (goto-char (point-min))
2676       (while (re-search-forward
2677               "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2678         (replace-match "\\1\\3" t)))
2679     (when (interactive-p)
2680       (gnus-treat-article nil))))
2681
2682
2683 (defun article-wash-html (&optional read-charset)
2684   "Format an HTML article.
2685 If READ-CHARSET, ask for a coding system.  If it is a number, the
2686 charset defined in `gnus-summary-show-article-charset-alist' is used."
2687   (interactive "P")
2688   (save-excursion
2689     (let ((inhibit-read-only t)
2690           charset)
2691       (if read-charset
2692           (if (or (and (numberp read-charset)
2693                        (setq charset
2694                              (cdr
2695                               (assq read-charset
2696                                     gnus-summary-show-article-charset-alist))))
2697                   (setq charset (mm-read-coding-system "Charset: ")))
2698               (let ((gnus-summary-show-article-charset-alist
2699                      (list (cons 1 charset))))
2700                 (with-current-buffer gnus-summary-buffer
2701                   (gnus-summary-show-article 1)))
2702             (error "No charset is given"))
2703         (when (gnus-buffer-live-p gnus-original-article-buffer)
2704           (with-current-buffer gnus-original-article-buffer
2705             (let* ((ct (gnus-fetch-field "content-type"))
2706                    (ctl (and ct (mail-header-parse-content-type ct))))
2707               (setq charset (and ctl
2708                                  (mail-content-type-get ctl 'charset)))
2709               (when (stringp charset)
2710                 (setq charset (intern (downcase charset)))))))
2711         (unless charset
2712           (setq charset gnus-newsgroup-charset)))
2713       (article-goto-body)
2714       (save-window-excursion
2715         (save-restriction
2716           (narrow-to-region (point) (point-max))
2717           (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2718                  (entry (assq func mm-text-html-washer-alist)))
2719             (when entry
2720               (setq func (cdr entry)))
2721             (cond
2722              ((functionp func)
2723               (funcall func))
2724              (t
2725               (apply (car func) (cdr func))))))))))
2726
2727 ;; External.
2728 (declare-function w3-region "ext:w3-display" (st nd))
2729
2730 (defun gnus-article-wash-html-with-w3 ()
2731   "Wash the current buffer with w3."
2732   (mm-setup-w3)
2733   (let ((w3-strict-width (window-width))
2734         (url-standalone-mode t)
2735         (url-gateway-unplugged t)
2736         (w3-honor-stylesheets nil))
2737     (condition-case ()
2738         (w3-region (point-min) (point-max))
2739       (error))))
2740
2741 ;; External.
2742 (declare-function w3m-region "ext:w3m" (start end &optional url charset))
2743
2744 (defun gnus-article-wash-html-with-w3m ()
2745   "Wash the current buffer with emacs-w3m."
2746   (mm-setup-w3m)
2747   (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2748         w3m-force-redisplay)
2749     (w3m-region (point-min) (point-max)))
2750   ;; Put the mark meaning this part was rendered by emacs-w3m.
2751   (put-text-property (point-min) (point-max) 'mm-inline-text-html-with-w3m t)
2752   (when (and mm-inline-text-html-with-w3m-keymap
2753              (boundp 'w3m-minor-mode-map)
2754              w3m-minor-mode-map)
2755     (if (and (boundp 'w3m-link-map)
2756              w3m-link-map)
2757         (let* ((start (point-min))
2758                (end (point-max))
2759                (on (get-text-property start 'w3m-href-anchor))
2760                (map (copy-keymap w3m-link-map))
2761                next)
2762           (set-keymap-parent map w3m-minor-mode-map)
2763           (while (< start end)
2764             (if on
2765                 (progn
2766                   (setq next (or (text-property-any start end
2767                                                     'w3m-href-anchor nil)
2768                                  end))
2769                   (put-text-property start next 'keymap map))
2770               (setq next (or (text-property-not-all start end
2771                                                     'w3m-href-anchor nil)
2772                              end))
2773               (put-text-property start next 'keymap w3m-minor-mode-map))
2774             (setq start next
2775                   on (not on))))
2776       (put-text-property (point-min) (point-max) 'keymap w3m-minor-mode-map))))
2777
2778 (defvar charset) ;; Bound by `article-wash-html'.
2779
2780 (defun gnus-article-wash-html-with-w3m-standalone ()
2781   "Wash the current buffer with w3m."
2782   (if (mm-w3m-standalone-supports-m17n-p)
2783       (progn
2784         (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2785           ;; The default.
2786           (setq charset 'iso-8859-1))
2787         (let ((coding-system-for-write charset)
2788               (coding-system-for-read charset))
2789           (call-process-region
2790            (point-min) (point-max)
2791            "w3m" t t nil "-dump" "-T" "text/html"
2792            "-I" (symbol-name charset) "-O" (symbol-name charset))))
2793     (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2794
2795 (defvar gnus-article-browse-html-temp-list nil
2796   "List of temporary files created by `gnus-article-browse-html-parts'.
2797 Internal variable.")
2798
2799 (defcustom gnus-article-browse-delete-temp 'ask
2800   "What to do with temporary files from `gnus-article-browse-html-parts'.
2801 If nil, don't delete temporary files.  If it is t, delete them on
2802 exit from the summary buffer.  If it is the symbol `file', query
2803 on each file, if it is `ask' ask once when exiting from the
2804 summary buffer."
2805   :group 'gnus-article
2806   :version "23.1" ;; No Gnus
2807   :type '(choice (const :tag "Don't delete" nil)
2808                  (const :tag "Don't ask" t)
2809                  (const :tag "Ask" ask)
2810                  (const :tag "Ask for each file" file)))
2811
2812 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2813
2814 (defun gnus-article-browse-delete-temp-files (&optional how)
2815   "Delete temp-files created by `gnus-article-browse-html-parts'."
2816   (when (and gnus-article-browse-html-temp-list
2817              (progn
2818                (or how (setq how gnus-article-browse-delete-temp))
2819                (if (eq how 'ask)
2820                    (let ((files (length gnus-article-browse-html-temp-list)))
2821                      (gnus-y-or-n-p (format
2822                                      "Delete all %s temporary HTML file%s? "
2823                                      files
2824                                      (if (> files 1) "s" ""))))
2825                  how)))
2826     (dolist (file gnus-article-browse-html-temp-list)
2827       (cond ((file-directory-p file)
2828              (when (or (not (eq how 'file))
2829                        (gnus-y-or-n-p
2830                         (format
2831                          "Delete temporary HTML file(s) in directory `%s'? "
2832                          (file-name-as-directory file))))
2833                (gnus-delete-directory file)))
2834             ((file-exists-p file)
2835              (when (or (not (eq how 'file))
2836                        (gnus-y-or-n-p
2837                         (format "Delete temporary HTML file `%s'? " file)))
2838                (delete-file file)))))
2839     ;; Also remove file from the list when not deleted or if file doesn't
2840     ;; exist anymore.
2841     (setq gnus-article-browse-html-temp-list nil))
2842   gnus-article-browse-html-temp-list)
2843
2844 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2845   "Find CID content in HANDLES and save it in a file in DIRECTORY.
2846 Return file name."
2847   (save-match-data
2848     (let (file type)
2849       (catch 'found
2850         (dolist (handle handles)
2851           (cond
2852            ((not (listp handle)))
2853            ((equal (mm-handle-media-supertype handle) "multipart")
2854             (when (setq file (gnus-article-browse-html-save-cid-content
2855                               cid handle directory))
2856               (throw 'found file)))
2857            ((equal (concat "<" cid ">") (mm-handle-id handle))
2858             (setq file
2859                   (expand-file-name
2860                    (or (mail-content-type-get
2861                         (mm-handle-disposition handle) 'filename)
2862                        (mail-content-type-get
2863                         (setq type (mm-handle-type handle)) 'name)
2864                        (concat
2865                         (make-temp-name "cid")
2866                         (car (rassoc (car type) mailcap-mime-extensions))))
2867                    directory))
2868             (mm-save-part-to-file handle file)
2869             (throw 'found file))))))))
2870
2871 (defun gnus-article-browse-html-parts (list &optional header)
2872   "View all \"text/html\" parts from LIST.
2873 Recurse into multiparts.  The optional HEADER that should be a decoded
2874 message header will be added to the bodies of the \"text/html\" parts."
2875   ;; Internal function used by `gnus-article-browse-html-article'.
2876   (let (type file charset content cid-dir tmp-file showed)
2877     ;; Find and show the html-parts.
2878     (dolist (handle list)
2879       ;; If HTML, show it:
2880       (cond ((not (listp handle)))
2881             ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2882                  (and (equal (car type) "message/external-body")
2883                       (or header
2884                           (setq file (or (mail-content-type-get type 'name)
2885                                          (mail-content-type-get
2886                                           (mm-handle-disposition handle)
2887                                           'filename))))
2888                       (or (mm-handle-cache handle)
2889                           (condition-case code
2890                               (progn (mm-extern-cache-contents handle) t)
2891                             (error
2892                              (gnus-message 3 "%s" (error-message-string code))
2893                              (when (>= gnus-verbose 3) (sit-for 2))
2894                              nil)))
2895                       (progn
2896                         (setq handle (mm-handle-cache handle)
2897                               type (mm-handle-type handle))
2898                         (equal (car type) "text/html"))))
2899              (setq charset (mail-content-type-get type 'charset)
2900                    content (mm-get-part handle))
2901              (with-temp-buffer
2902                (if (eq charset 'gnus-decoded)
2903                    (mm-enable-multibyte)
2904                  (mm-disable-multibyte))
2905                (insert content)
2906                ;; resolve cid contents
2907                (let ((case-fold-search t)
2908                      cid-file)
2909                  (goto-char (point-min))
2910                  (while (re-search-forward "\
2911 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2912                                            nil t)
2913                    (unless cid-dir
2914                      (setq cid-dir (mm-make-temp-file "cid" t))
2915                      (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2916                    (setq file nil
2917                          content nil)
2918                    (when (setq cid-file
2919                                (gnus-article-browse-html-save-cid-content
2920                                 (match-string 2)
2921                                 (with-current-buffer gnus-article-buffer
2922                                   gnus-article-mime-handles)
2923                                 cid-dir))
2924                      (replace-match (concat "file://" cid-file)
2925                                     nil nil nil 1))))
2926                (unless content (setq content (buffer-string))))
2927              (when (or charset header (not file))
2928                (setq tmp-file (mm-make-temp-file
2929                                ;; Do we need to care for 8.3 filenames?
2930                                "mm-" nil ".html")))
2931              ;; Add a meta html tag to specify charset and a header.
2932              (cond
2933               (header
2934                (let (title eheader body hcharset coding force-charset)
2935                  (with-temp-buffer
2936                    (mm-enable-multibyte)
2937                    (setq case-fold-search t)
2938                    (insert header "\n")
2939                    (setq title (message-fetch-field "subject"))
2940                    (goto-char (point-min))
2941                    (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2942                      (replace-match (cond ((match-beginning 1) "&lt;")
2943                                           ((match-beginning 2) "&gt;")
2944                                           (t "&amp;"))))
2945                    (goto-char (point-min))
2946                    (insert "<pre>\n")
2947                    (goto-char (point-max))
2948                    (insert "</pre>\n<hr>\n")
2949                    ;; We have to examine charset one by one since
2950                    ;; charset specified in parts might be different.
2951                    (if (eq charset 'gnus-decoded)
2952                        (setq charset 'utf-8
2953                              eheader (mm-encode-coding-string (buffer-string)
2954                                                               charset)
2955                              title (when title
2956                                      (mm-encode-coding-string title charset))
2957                              body (mm-encode-coding-string content charset)
2958                              force-charset t)
2959                      (setq hcharset (mm-find-mime-charset-region (point-min)
2960                                                                  (point-max)))
2961                      (cond ((= (length hcharset) 1)
2962                             (setq hcharset (car hcharset)
2963                                   coding (mm-charset-to-coding-system
2964                                           hcharset)))
2965                            ((> (length hcharset) 1)
2966                             (setq hcharset 'utf-8
2967                                   coding hcharset)))
2968                      (if coding
2969                          (if charset
2970                              (progn
2971                                (setq body
2972                                      (mm-charset-to-coding-system charset))
2973                                (if (eq coding body)
2974                                    (setq eheader (mm-encode-coding-string
2975                                                   (buffer-string) coding)
2976                                          title (when title
2977                                                  (mm-encode-coding-string
2978                                                   title coding))
2979                                          body content)
2980                                  (setq charset 'utf-8
2981                                        eheader (mm-encode-coding-string
2982                                                 (buffer-string) charset)
2983                                        title (when title
2984                                                (mm-encode-coding-string
2985                                                 title charset))
2986                                        body (mm-encode-coding-string
2987                                              (mm-decode-coding-string
2988                                               content body)
2989                                              charset)
2990                                        force-charset t)))
2991                            (setq charset hcharset
2992                                  eheader (mm-encode-coding-string
2993                                           (buffer-string) coding)
2994                                  title (when title
2995                                          (mm-encode-coding-string
2996                                           title coding))
2997                                  body content))
2998                        (setq eheader (mm-string-as-unibyte (buffer-string))
2999                              body content)))
3000                    (erase-buffer)
3001                    (mm-disable-multibyte)
3002                    (insert body)
3003                    (when charset
3004                      (mm-add-meta-html-tag handle charset force-charset))
3005                    (when title
3006                      (goto-char (point-min))
3007                      (unless (search-forward "<title>" nil t)
3008                        (re-search-forward "<head>\\s-*" nil t)
3009                        (insert "<title>" title "</title>\n")))
3010                    (goto-char (point-min))
3011                    (or (re-search-forward
3012                         "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
3013                        (re-search-forward
3014                         "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
3015                    (insert eheader)
3016                    (mm-write-region (point-min) (point-max)
3017                                     tmp-file nil nil nil 'binary t))))
3018               (charset
3019                (mm-with-unibyte-buffer
3020                  (insert (if (eq charset 'gnus-decoded)
3021                              (mm-encode-coding-string content
3022                                                       (setq charset 'utf-8))
3023                            content))
3024                  (if (or (mm-add-meta-html-tag handle charset)
3025                          (not file))
3026                      (mm-write-region (point-min) (point-max)
3027                                       tmp-file nil nil nil 'binary t)
3028                    (setq tmp-file nil))))
3029               (tmp-file
3030                (mm-save-part-to-file handle tmp-file)))
3031              (when tmp-file
3032                (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3033              (add-hook 'gnus-summary-prepare-exit-hook
3034                        'gnus-article-browse-delete-temp-files)
3035              (add-hook 'gnus-exit-gnus-hook
3036                        (lambda  ()
3037                          (gnus-article-browse-delete-temp-files t)))
3038              ;; FIXME: Warn if there's an <img> tag?
3039              (browse-url-of-file (or tmp-file (expand-file-name file)))
3040              (setq showed t))
3041             ;; If multipart, recurse
3042             ((equal (mm-handle-media-supertype handle) "multipart")
3043              (when (gnus-article-browse-html-parts handle header)
3044                (setq showed t)))
3045             ((equal (mm-handle-media-type handle) "message/rfc822")
3046              (mm-with-multibyte-buffer
3047                (mm-insert-part handle)
3048                (setq handle (mm-dissect-buffer t t))
3049                (when (and (bufferp (car handle))
3050                           (stringp (car (mm-handle-type handle))))
3051                  (setq handle (list handle)))
3052                (when header
3053                  (article-decode-encoded-words)
3054                  (let ((gnus-visible-headers
3055                         (or (get 'gnus-visible-headers 'standard-value)
3056                             gnus-visible-headers)))
3057                    (article-hide-headers))
3058                  (goto-char (point-min))
3059                  (search-forward "\n\n" nil 'move)
3060                  (skip-chars-backward "\t\n ")
3061                  (setq header (buffer-substring (point-min) (point)))))
3062              (when (prog1
3063                        (gnus-article-browse-html-parts handle header)
3064                      (mm-destroy-parts handle))
3065                (setq showed t)))))
3066     showed))
3067
3068 (defun gnus-article-browse-html-article (&optional arg)
3069   "View \"text/html\" parts of the current article with a WWW browser.
3070 Inline images embedded in a message using the cid scheme, as they are
3071 generally considered to be safe, will be processed properly.
3072 The message header is added to the beginning of every html part unless
3073 the prefix argument ARG is given.
3074
3075 Warning: Spammers use links to images (using the http scheme) in HTML
3076 articles to verify whether you have read the message.  As
3077 `gnus-article-browse-html-article' passes the HTML content to the
3078 browser without eliminating these \"web bugs\" you should only
3079 use it for mails from trusted senders.
3080
3081 If you always want to display HTML parts in the browser, set
3082 `mm-text-html-renderer' to nil.
3083
3084 This command creates temporary files to pass HTML contents including
3085 images if any to the browser, and deletes them when exiting the group
3086 \(if you want)."
3087   ;; Cf. `mm-w3m-safe-url-regexp'
3088   (interactive "P")
3089   (if arg
3090       (gnus-summary-show-article)
3091     (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3092                                     gnus-visible-headers))
3093           ;; As we insert a <hr>, there's no need for the body boundary.
3094           (gnus-treat-body-boundary nil))
3095       (gnus-summary-show-article)))
3096   (with-current-buffer gnus-article-buffer
3097     (let ((header (unless arg
3098                     (save-restriction
3099                       (widen)
3100                       (buffer-substring-no-properties
3101                        (goto-char (point-min))
3102                        (if (search-forward "\n\n" nil t)
3103                            (match-beginning 0)
3104                          (goto-char (point-max))
3105                          (skip-chars-backward "\t\n ")
3106                          (point))))))
3107           parts)
3108       (set-buffer gnus-original-article-buffer)
3109       (setq parts (mm-dissect-buffer t t))
3110       ;; If singlepart, enforce a list.
3111       (when (and (bufferp (car parts))
3112                  (stringp (car (mm-handle-type parts))))
3113         (setq parts (list parts)))
3114       ;; Process the list
3115       (unless (gnus-article-browse-html-parts parts header)
3116         (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3117       (mm-destroy-parts parts)
3118       (unless arg
3119         (gnus-summary-show-article)))))
3120
3121 (defun article-hide-list-identifiers ()
3122   "Remove list identifies from the Subject header.
3123 The `gnus-list-identifiers' variable specifies what to do."
3124   (interactive)
3125   (let ((inhibit-point-motion-hooks t)
3126         (regexp (if (consp gnus-list-identifiers)
3127                     (mapconcat 'identity gnus-list-identifiers " *\\|")
3128                   gnus-list-identifiers))
3129         (inhibit-read-only t))
3130     (when regexp
3131       (save-excursion
3132         (save-restriction
3133           (article-narrow-to-head)
3134           (goto-char (point-min))
3135           (while (re-search-forward
3136                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3137                   nil t)
3138             (delete-region (match-beginning 2) (match-end 0))
3139             (beginning-of-line))
3140           (when (re-search-forward
3141                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3142             (delete-region (match-beginning 1) (match-end 1))))))))
3143
3144 (defun article-hide-pem (&optional arg)
3145   "Toggle hiding of any PEM headers and signatures in the current article.
3146 If given a negative prefix, always show; if given a positive prefix,
3147 always hide."
3148   (interactive (gnus-article-hidden-arg))
3149   (unless (gnus-article-check-hidden-text 'pem arg)
3150     (save-excursion
3151       (let ((inhibit-read-only t) end)
3152         (goto-char (point-min))
3153         ;; Hide the horrendously ugly "header".
3154         (when (and (search-forward
3155                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3156                     nil t)
3157                    (setq end (1+ (match-beginning 0))))
3158           (gnus-add-wash-type 'pem)
3159           (gnus-article-hide-text-type
3160            end
3161            (if (search-forward "\n\n" nil t)
3162                (match-end 0)
3163              (point-max))
3164            'pem)
3165           ;; Hide the trailer as well
3166           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3167                                 nil t)
3168             (gnus-article-hide-text-type
3169              (match-beginning 0) (match-end 0) 'pem)))))))
3170
3171 (defun article-strip-banner ()
3172   "Strip the banners specified by the `banner' group parameter and by
3173 `gnus-article-address-banner-alist'."
3174   (interactive)
3175   (save-excursion
3176     (save-restriction
3177       (let ((inhibit-point-motion-hooks t))
3178         (when (gnus-parameter-banner gnus-newsgroup-name)
3179           (article-really-strip-banner
3180            (gnus-parameter-banner gnus-newsgroup-name)))
3181         (when gnus-article-address-banner-alist
3182           ;; Note that the From header is decoded here, so it is
3183           ;; required that the *-extract-address-components function
3184           ;; supports non-ASCII text.
3185           (let ((from (save-restriction
3186                         (widen)
3187                         (article-narrow-to-head)
3188                         (mail-fetch-field "from"))))
3189             (when (and from
3190                        (setq from
3191                              (cadr (funcall gnus-extract-address-components
3192                                             from))))
3193               (catch 'found
3194                 (dolist (pair gnus-article-address-banner-alist)
3195                   (when (string-match (car pair) from)
3196                     (throw 'found
3197                            (article-really-strip-banner (cdr pair)))))))))))))
3198
3199 (defun article-really-strip-banner (banner)
3200   "Strip the banner specified by the argument."
3201   (save-excursion
3202     (save-restriction
3203       (let ((inhibit-point-motion-hooks t)
3204             (gnus-signature-limit nil)
3205             (inhibit-read-only t))
3206         (article-goto-body)
3207         (cond
3208          ((eq banner 'signature)
3209           (when (gnus-article-narrow-to-signature)
3210             (widen)
3211             (forward-line -1)
3212             (delete-region (point) (point-max))))
3213          ((symbolp banner)
3214           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3215               (while (re-search-forward banner nil t)
3216                 (delete-region (match-beginning 0) (match-end 0)))))
3217          ((stringp banner)
3218           (while (re-search-forward banner nil t)
3219             (delete-region (match-beginning 0) (match-end 0)))))))))
3220
3221 (defun article-babel ()
3222   "Translate article using an online translation service."
3223   (interactive)
3224   (require 'babel)
3225   (gnus-with-article-buffer
3226     (when (article-goto-body)
3227       (let* ((start (point))
3228              (end (point-max))
3229              (orig (buffer-substring start end))
3230              (trans (babel-as-string orig)))
3231         (save-restriction
3232           (narrow-to-region start end)
3233           (delete-region start end)
3234           (insert trans))))))
3235
3236 (defun article-hide-signature (&optional arg)
3237   "Hide the signature in the current article.
3238 If given a negative prefix, always show; if given a positive prefix,
3239 always hide."
3240   (interactive (gnus-article-hidden-arg))
3241   (unless (gnus-article-check-hidden-text 'signature arg)
3242     (save-excursion
3243       (save-restriction
3244         (let ((inhibit-read-only t))
3245           (when (gnus-article-narrow-to-signature)
3246             (gnus-article-hide-text-type
3247              (point-min) (point-max) 'signature))))))
3248   (gnus-set-mode-line 'article))
3249
3250 (defun article-strip-headers-in-body ()
3251   "Strip offensive headers from bodies."
3252   (interactive)
3253   (save-excursion
3254     (article-goto-body)
3255     (let ((case-fold-search t))
3256       (when (looking-at "x-no-archive:")
3257         (gnus-delete-line)))))
3258
3259 (defun article-strip-leading-blank-lines ()
3260   "Remove all blank lines from the beginning of the article."
3261   (interactive)
3262   (save-excursion
3263     (let ((inhibit-point-motion-hooks t)
3264           (inhibit-read-only t))
3265       (when (article-goto-body)
3266         (while (and (not (eobp))
3267                     (looking-at "[ \t]*$"))
3268           (gnus-delete-line))))))
3269
3270 (defun article-narrow-to-head ()
3271   "Narrow the buffer to the head of the message.
3272 Point is left at the beginning of the narrowed-to region."
3273   (narrow-to-region
3274    (goto-char (point-min))
3275    (if (search-forward "\n\n" nil 1)
3276        (1- (point))
3277      (point-max)))
3278   (goto-char (point-min)))
3279
3280 (defun article-goto-body ()
3281   "Place point at the start of the body."
3282   (goto-char (point-min))
3283   (cond
3284    ;; This variable is only bound when dealing with separate
3285    ;; MIME body parts.
3286    (article-goto-body-goes-to-point-min-p
3287     t)
3288    ((search-forward "\n\n" nil t)
3289     t)
3290    (t
3291     (goto-char (point-max))
3292     nil)))
3293
3294 (defun article-strip-multiple-blank-lines ()
3295   "Replace consecutive blank lines with one empty line."
3296   (interactive)
3297   (save-excursion
3298     (let ((inhibit-point-motion-hooks t)
3299           (inhibit-read-only t))
3300       ;; First make all blank lines empty.
3301       (article-goto-body)
3302       (while (re-search-forward "^[ \t]+$" nil t)
3303         (unless (gnus-annotation-in-region-p
3304                  (match-beginning 0) (match-end 0))
3305           (replace-match "" nil t)))
3306       ;; Then replace multiple empty lines with a single empty line.
3307       (article-goto-body)
3308       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3309         (unless (gnus-annotation-in-region-p
3310                  (match-beginning 0) (match-end 0))
3311           (delete-region (match-beginning 1) (match-end 1)))))))
3312
3313 (defun article-strip-leading-space ()
3314   "Remove all white space from the beginning of the lines in the article."
3315   (interactive)
3316   (save-excursion
3317     (let ((inhibit-point-motion-hooks t)
3318           (inhibit-read-only t))
3319       (article-goto-body)
3320       (while (re-search-forward "^[ \t]+" nil t)
3321         (replace-match "" t t)))))
3322
3323 (defun article-strip-trailing-space ()
3324   "Remove all white space from the end of the lines in the article."
3325   (interactive)
3326   (save-excursion
3327     (let ((inhibit-point-motion-hooks t)
3328           (inhibit-read-only t))
3329       (article-goto-body)
3330       (while (re-search-forward "[ \t]+$" nil t)
3331         (replace-match "" t t)))))
3332
3333 (defun article-strip-blank-lines ()
3334   "Strip leading, trailing and multiple blank lines."
3335   (interactive)
3336   (article-strip-leading-blank-lines)
3337   (article-remove-trailing-blank-lines)
3338   (article-strip-multiple-blank-lines))
3339
3340 (defun article-strip-all-blank-lines ()
3341   "Strip all blank lines."
3342   (interactive)
3343   (save-excursion
3344     (let ((inhibit-point-motion-hooks t)
3345           (inhibit-read-only t))
3346       (article-goto-body)
3347       (while (re-search-forward "^[ \t]*\n" nil t)
3348         (replace-match "" t t)))))
3349
3350 (defun gnus-article-narrow-to-signature ()
3351   "Narrow to the signature; return t if a signature is found, else nil."
3352   (let ((inhibit-point-motion-hooks t))
3353     (when (gnus-article-search-signature)
3354       (forward-line 1)
3355       ;; Check whether we have some limits to what we consider
3356       ;; to be a signature.
3357       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3358                       (list gnus-signature-limit)))
3359             limit limited)
3360         (while (setq limit (pop limits))
3361           (if (or (and (integerp limit)
3362                        (< (- (point-max) (point)) limit))
3363                   (and (floatp limit)
3364                        (< (count-lines (point) (point-max)) limit))
3365                   (and (functionp limit)
3366                        (funcall limit))
3367                   (and (stringp limit)
3368                        (not (re-search-forward limit nil t))))
3369               ()                        ; This limit did not succeed.
3370             (setq limited t
3371                   limits nil)))
3372         (unless limited
3373           (narrow-to-region (point) (point-max))
3374           t)))))
3375
3376 (defun gnus-article-search-signature ()
3377   "Search the current buffer for the signature separator.
3378 Put point at the beginning of the signature separator."
3379   (let ((cur (point)))
3380     (goto-char (point-max))
3381     (if (if (stringp gnus-signature-separator)
3382             (re-search-backward gnus-signature-separator nil t)
3383           (let ((seps gnus-signature-separator))
3384             (while (and seps
3385                         (not (re-search-backward (car seps) nil t)))
3386               (pop seps))
3387             seps))
3388         t
3389       (goto-char cur)
3390       nil)))
3391
3392 (defun gnus-article-hidden-arg ()
3393   "Return the current prefix arg as a number, or 0 if no prefix."
3394   (list (if current-prefix-arg
3395             (prefix-numeric-value current-prefix-arg)
3396           0)))
3397
3398 (defun gnus-article-check-hidden-text (type arg)
3399   "Return nil if hiding is necessary.
3400 Arg can be nil or a number.  nil and positive means hide, negative
3401 means show, 0 means toggle."
3402   (save-excursion
3403     (save-restriction
3404       (let ((hide (gnus-article-hidden-text-p type)))
3405         (cond
3406          ((or (null arg)
3407               (> arg 0))
3408           nil)
3409          ((< arg 0)
3410           (gnus-article-show-hidden-text type)
3411           t)
3412          (t
3413           (if (eq hide 'hidden)
3414               (progn
3415                 (gnus-article-show-hidden-text type)
3416                 t)
3417             nil)))))))
3418
3419 (defun gnus-article-hidden-text-p (type)
3420   "Say whether the current buffer contains hidden text of type TYPE."
3421   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3422     (while (and pos
3423                 (not (get-text-property pos 'invisible))
3424                 (not (get-text-property pos 'dummy-invisible)))
3425       (setq pos
3426             (text-property-any (1+ pos) (point-max) 'article-type type)))
3427     (if pos
3428         'hidden
3429       nil)))
3430
3431 (defun gnus-article-show-hidden-text (type &optional dummy)
3432   "Show all hidden text of type TYPE.
3433 Originally it is hide instead of DUMMY."
3434   (let ((inhibit-read-only t)
3435         (inhibit-point-motion-hooks t))
3436     (gnus-remove-text-properties-when
3437      'article-type type
3438      (point-min) (point-max)
3439      (cons 'article-type (cons type
3440                                gnus-hidden-properties)))
3441     (gnus-delete-wash-type type)))
3442
3443 (defconst article-time-units
3444   `((year . ,(* 365.25 24 60 60))
3445     (week . ,(* 7 24 60 60))
3446     (day . ,(* 24 60 60))
3447     (hour . ,(* 60 60))
3448     (minute . 60)
3449     (second . 1))
3450   "Mapping from time units to seconds.")
3451
3452 (defun gnus-article-forward-header ()
3453   "Move point to the start of the next header.
3454 If the current header is a continuation header, this can be several
3455 lines forward."
3456   (let ((ended nil))
3457     (while (not ended)
3458       (forward-line 1)
3459       (if (looking-at "[ \t]+[^ \t]")
3460           (forward-line 1)
3461         (setq ended t)))))
3462
3463 (defun article-date-ut (&optional type highlight)
3464   "Convert DATE date to universal time in the current article.
3465 If TYPE is `local', convert to local time; if it is `lapsed', output
3466 how much time has lapsed since DATE.  For `lapsed', the value of
3467 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3468 should replace the \"Date:\" one, or should be added below it."
3469   (interactive (list 'ut t))
3470   (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3471          (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3472                              tdate-regexp)
3473                             ((eq type 'lapsed)
3474                              "^X-Sent:[ \t]")
3475                             (article-lapsed-timer
3476                              "^Date:[ \t]")
3477                             (t
3478                              tdate-regexp)))
3479          (case-fold-search t)
3480          (inhibit-read-only t)
3481          (inhibit-point-motion-hooks t)
3482          pos date bface eface)
3483     (save-excursion
3484       (save-restriction
3485         (widen)
3486         (goto-char (point-min))
3487         (while (or (setq date (get-text-property (setq pos (point))
3488                                                  'original-date))
3489                    (when (setq pos (next-single-property-change
3490                                     (point) 'original-date))
3491                      (setq date (get-text-property pos 'original-date))
3492                      t))
3493           (narrow-to-region
3494            pos (if (setq pos (text-property-any pos (point-max)
3495                                                 'original-date nil))
3496                    (progn
3497                      (goto-char pos)
3498                      (if (or (bolp) (eobp))
3499                          (point)
3500                        (1+ (point))))
3501                  (point-max)))
3502           (goto-char (point-min))
3503           (when (re-search-forward tdate-regexp nil t)
3504             (setq bface (get-text-property (point-at-bol) 'face)
3505                   eface (get-text-property (1- (point-at-eol)) 'face)))
3506           (goto-char (point-min))
3507           (setq pos nil)
3508           ;; Delete any old Date headers.
3509           (while (re-search-forward date-regexp nil t)
3510             (if pos
3511                 (delete-region (point-at-bol) (progn
3512                                                 (gnus-article-forward-header)
3513                                                 (point)))
3514               (delete-region (point-at-bol) (progn
3515                                               (gnus-article-forward-header)
3516                                               (forward-char -1)
3517                                               (point)))
3518               (setq pos (point))))
3519           (when (and (not pos)
3520                      (re-search-forward tdate-regexp nil t))
3521             (forward-line 1))
3522           (gnus-goto-char pos)
3523           (insert (article-make-date-line date (or type 'ut)))
3524           (unless pos
3525             (insert "\n")
3526             (forward-line -1))
3527           ;; Do highlighting.
3528           (beginning-of-line)
3529           (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3530             (put-text-property (match-beginning 1) (1+ (match-end 1))
3531                                'face bface)
3532             (put-text-property (match-beginning 2) (match-end 2)
3533                                'face eface))
3534           (put-text-property (point-min) (1- (point-max)) 'original-date date)
3535           (goto-char (point-max))
3536           (widen))))))
3537
3538 (defun article-make-date-line (date type)
3539   "Return a DATE line of TYPE."
3540   (unless (memq type '(local ut original user iso8601 lapsed english))
3541     (error "Unknown conversion type: %s" type))
3542   (condition-case ()
3543       (let ((time (date-to-time date)))
3544         (cond
3545          ;; Convert to the local timezone.
3546          ((eq type 'local)
3547           (concat "Date: " (message-make-date time)))
3548          ;; Convert to Universal Time.
3549          ((eq type 'ut)
3550           (concat "Date: "
3551                   (substring
3552                    (message-make-date
3553                     (let* ((e (parse-time-string date))
3554                            (tm (apply 'encode-time e))
3555                            (ms (car tm))
3556                            (ls (- (cadr tm) (car (current-time-zone time)))))
3557                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3558                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3559                             (t (list ms ls)))))
3560                    0 -5)
3561                   "UT"))
3562          ;; Get the original date from the article.
3563          ((eq type 'original)
3564           (concat "Date: " (if (string-match "\n+$" date)
3565                                (substring date 0 (match-beginning 0))
3566                              date)))
3567          ;; Let the user define the format.
3568          ((eq type 'user)
3569           (let ((format (or (condition-case nil
3570                                 (with-current-buffer gnus-summary-buffer
3571                                   gnus-article-time-format)
3572                               (error nil))
3573                             gnus-article-time-format)))
3574             (if (functionp format)
3575                 (funcall format time)
3576               (concat "Date: " (format-time-string format time)))))
3577          ;; ISO 8601.
3578          ((eq type 'iso8601)
3579           (let ((tz (car (current-time-zone time))))
3580             (concat
3581              "Date: "
3582              (format-time-string "%Y%m%dT%H%M%S" time)
3583              (format "%s%02d%02d"
3584                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3585                      (/ (% (abs tz) 3600) 60)))))
3586          ;; Do an X-Sent lapsed format.
3587          ((eq type 'lapsed)
3588           ;; If the date is seriously mangled, the timezone functions are
3589           ;; liable to bug out, so we ignore all errors.
3590           (let* ((now (current-time))
3591                  (real-time (subtract-time now time))
3592                  (real-sec (and real-time
3593                                 (+ (* (float (car real-time)) 65536)
3594                                    (cadr real-time))))
3595                  (sec (and real-time (abs real-sec)))
3596                  num prev)
3597             (cond
3598              ((null real-time)
3599               "X-Sent: Unknown")
3600              ((zerop sec)
3601               "X-Sent: Now")
3602              (t
3603               (concat
3604                "X-Sent: "
3605                ;; This is a bit convoluted, but basically we go
3606                ;; through the time units for years, weeks, etc,
3607                ;; and divide things to see whether that results
3608                ;; in positive answers.
3609                (mapconcat
3610                 (lambda (unit)
3611                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3612                       ;; The (remaining) seconds are too few to
3613                       ;; be divided into this time unit.
3614                       ""
3615                     ;; It's big enough, so we output it.
3616                     (setq sec (- sec (* num (cdr unit))))
3617                     (prog1
3618                         (concat (if prev ", " "") (int-to-string
3619                                                    (floor num))
3620                                 " " (symbol-name (car unit))
3621                                 (if (> num 1) "s" ""))
3622                       (setq prev t))))
3623                 article-time-units "")
3624                ;; If dates are odd, then it might appear like the
3625                ;; article was sent in the future.
3626                (if (> real-sec 0)
3627                    " ago"
3628                  " in the future"))))))
3629          ;; Display the date in proper English
3630          ((eq type 'english)
3631           (let ((dtime (decode-time time)))
3632             (concat
3633              "Date: the "
3634              (number-to-string (nth 3 dtime))
3635              (let ((digit (% (nth 3 dtime) 10)))
3636                (cond
3637                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3638                 ((= digit 1) "st")
3639                 ((= digit 2) "nd")
3640                 ((= digit 3) "rd")
3641                 (t "th")))
3642              " of "
3643              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3644              " "
3645              (number-to-string (nth 5 dtime))
3646              " at "
3647              (format "%02d" (nth 2 dtime))
3648              ":"
3649              (format "%02d" (nth 1 dtime)))))))
3650     (error
3651      (format "Date: %s (from Gnus)" date))))
3652
3653 (defun article-date-local (&optional highlight)
3654   "Convert the current article date to the local timezone."
3655   (interactive (list t))
3656   (article-date-ut 'local highlight))
3657
3658 (defun article-date-english (&optional highlight)
3659   "Convert the current article date to something that is proper English."
3660   (interactive (list t))
3661   (article-date-ut 'english highlight))
3662
3663 (defun article-date-original (&optional highlight)
3664   "Convert the current article date to what it was originally.
3665 This is only useful if you have used some other date conversion
3666 function and want to see what the date was before converting."
3667   (interactive (list t))
3668   (article-date-ut 'original highlight))
3669
3670 (defun article-date-lapsed (&optional highlight)
3671   "Convert the current article date to time lapsed since it was sent."
3672   (interactive (list t))
3673   (article-date-ut 'lapsed highlight))
3674
3675 (defun article-update-date-lapsed ()
3676   "Function to be run from a timer to update the lapsed time line."
3677   (save-match-data
3678     (let (deactivate-mark)
3679       (save-excursion
3680         (ignore-errors
3681          (walk-windows
3682           (lambda (w)
3683             (set-buffer (window-buffer w))
3684             (when (eq major-mode 'gnus-article-mode)
3685               (let ((mark (point-marker)))
3686                 (goto-char (point-min))
3687                 (when (re-search-forward "^X-Sent:" nil t)
3688                   (article-date-lapsed t))
3689                 (goto-char (marker-position mark))
3690                 (move-marker mark nil))))
3691           nil 'visible))))))
3692
3693 (defun gnus-start-date-timer (&optional n)
3694   "Start a timer to update the X-Sent header in the article buffers.
3695 The numerical prefix says how frequently (in seconds) the function
3696 is to run."
3697   (interactive "p")
3698   (unless n
3699     (setq n 1))
3700   (gnus-stop-date-timer)
3701   (setq article-lapsed-timer
3702         (run-at-time 1 n 'article-update-date-lapsed)))
3703
3704 (defun gnus-stop-date-timer ()
3705   "Stop the X-Sent timer."
3706   (interactive)
3707   (when article-lapsed-timer
3708     (nnheader-cancel-timer article-lapsed-timer)
3709     (setq article-lapsed-timer nil)))
3710
3711 (defun article-date-user (&optional highlight)
3712   "Convert the current article date to the user-defined format.
3713 This format is defined by the `gnus-article-time-format' variable."
3714   (interactive (list t))
3715   (article-date-ut 'user highlight))
3716
3717 (defun article-date-iso8601 (&optional highlight)
3718   "Convert the current article date to ISO8601."
3719   (interactive (list t))
3720   (article-date-ut 'iso8601 highlight))
3721
3722 (defmacro gnus-article-save-original-date (&rest forms)
3723   "Save the original date as a text property and evaluate FORMS."
3724   `(let* ((case-fold-search t)
3725           (start (progn
3726                    (goto-char (point-min))
3727                    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3728                               (not (bolp)))
3729                      (match-end 0))))
3730           (date (when (and start
3731                            (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3732                                               nil t))
3733                   (buffer-substring-no-properties start
3734                                                   (match-beginning 0)))))
3735      (goto-char (point-max))
3736      (skip-chars-backward "\n")
3737      (put-text-property (point-min) (point) 'original-date date)
3738      ,@forms
3739      (goto-char (point-max))
3740      (skip-chars-backward "\n")
3741      (put-text-property (point-min) (point) 'original-date date)))
3742
3743 ;; (defun article-show-all ()
3744 ;;   "Show all hidden text in the article buffer."
3745 ;;   (interactive)
3746 ;;   (save-excursion
3747 ;;     (let ((inhibit-read-only t))
3748 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3749
3750 (defun article-remove-leading-whitespace ()
3751   "Remove excessive whitespace from all headers."
3752   (interactive)
3753   (save-excursion
3754     (save-restriction
3755       (let ((inhibit-read-only t))
3756         (article-narrow-to-head)
3757         (goto-char (point-min))
3758         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3759           (delete-region (match-beginning 1) (match-end 1)))))))
3760
3761 (defun article-emphasize (&optional arg)
3762   "Emphasize text according to `gnus-emphasis-alist'."
3763   (interactive (gnus-article-hidden-arg))
3764   (unless (gnus-article-check-hidden-text 'emphasis arg)
3765     (save-excursion
3766       (let ((alist (or
3767                     (condition-case nil
3768                         (with-current-buffer gnus-summary-buffer
3769                           gnus-article-emphasis-alist)
3770                       (error))
3771                     gnus-emphasis-alist))
3772             (inhibit-read-only t)
3773             (props (append '(article-type emphasis)
3774                            gnus-hidden-properties))
3775             regexp elem beg invisible visible face)
3776         (article-goto-body)
3777         (setq beg (point))
3778         (while (setq elem (pop alist))
3779           (goto-char beg)
3780           (setq regexp (car elem)
3781                 invisible (nth 1 elem)
3782                 visible (nth 2 elem)
3783                 face (nth 3 elem))
3784           (while (re-search-forward regexp nil t)
3785             (when (and (match-beginning visible) (match-beginning invisible))
3786               (gnus-article-hide-text
3787                (match-beginning invisible) (match-end invisible) props)
3788               (gnus-article-unhide-text-type
3789                (match-beginning visible) (match-end visible) 'emphasis)
3790               (gnus-put-overlay-excluding-newlines
3791                (match-beginning visible) (match-end visible) 'face face)
3792               (gnus-add-wash-type 'emphasis)
3793               (goto-char (match-end invisible)))))))))
3794
3795 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3796   "Setup newsgroup emphasis alist."
3797   (unless gnus-article-emphasis-alist
3798     (let ((name (and gnus-newsgroup-name
3799                      (gnus-group-real-name gnus-newsgroup-name))))
3800       (make-local-variable 'gnus-article-emphasis-alist)
3801       (setq gnus-article-emphasis-alist
3802             (nconc
3803              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3804                (while (setq elem (pop alist))
3805                  (when (and name (string-match (car elem) name))
3806                    (setq alist nil
3807                          highlight (copy-sequence (cdr elem)))))
3808                highlight)
3809              (copy-sequence highlight-words)
3810              (if gnus-newsgroup-name
3811                  (copy-sequence (gnus-group-find-parameter
3812                                  gnus-newsgroup-name 'highlight-words t)))
3813              gnus-emphasis-alist)))))
3814
3815 (defvar gnus-summary-article-menu)
3816 (defvar gnus-summary-post-menu)
3817
3818 ;;; Saving functions.
3819
3820 (defun gnus-article-save (save-buffer file &optional num)
3821   "Save the currently selected article."
3822   (when (or (get gnus-default-article-saver :headers)
3823             (not gnus-save-all-headers))
3824     ;; Remove headers according to `gnus-saved-headers' or the value
3825     ;; of the `:headers' property that the saver function might have.
3826     (let ((gnus-visible-headers
3827            (or (symbol-value (get gnus-default-article-saver :headers))
3828                gnus-saved-headers gnus-visible-headers))
3829           ;; Ignore group parameter.  See `article-hide-headers'.
3830           (gnus-summary-buffer nil))
3831       (with-current-buffer save-buffer
3832         (article-hide-headers 1 t))))
3833   (save-window-excursion
3834     (if (not gnus-default-article-saver)
3835         (error "No default saver is defined")
3836       ;; !!! Magic!  The saving functions all save
3837       ;; `gnus-save-article-buffer' (or so they think), but we
3838       ;; bind that variable to our save-buffer.
3839       (set-buffer gnus-article-buffer)
3840       (let* ((gnus-save-article-buffer save-buffer)
3841              (filename
3842               (cond
3843                ((not gnus-prompt-before-saving) 'default)
3844                ((eq gnus-prompt-before-saving 'always) nil)
3845                (t file)))
3846              (gnus-number-of-articles-to-be-saved
3847               (when (eq gnus-prompt-before-saving t)
3848                 num)))                  ; Magic
3849         (set-buffer gnus-article-current-summary)
3850         (funcall gnus-default-article-saver filename)))))
3851
3852 (defun gnus-read-save-file-name (prompt &optional filename
3853                                         function group headers variable
3854                                         dir-var)
3855   (let ((default-name
3856           (funcall function group headers (symbol-value variable)))
3857         result)
3858     (setq result
3859           (expand-file-name
3860            (cond
3861             ((eq filename 'default)
3862              default-name)
3863             ((eq filename t)
3864              default-name)
3865             (filename filename)
3866             (t
3867              (when (symbol-value dir-var)
3868                (setq default-name (expand-file-name
3869                                    (file-name-nondirectory default-name)
3870                                    (symbol-value dir-var))))
3871              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3872                     (prompt
3873                      (format prompt
3874                              (if (and gnus-number-of-articles-to-be-saved
3875                                       (> gnus-number-of-articles-to-be-saved 1))
3876                                  (format "these %d articles"
3877                                          gnus-number-of-articles-to-be-saved)
3878                                "this article")))
3879                     (file
3880                      ;; Let the split methods have their say.
3881                      (cond
3882                       ;; No split name was found.
3883                       ((null split-name)
3884                        (read-file-name
3885                         (concat prompt " (default "
3886                                 (file-name-nondirectory default-name) "): ")
3887                         (file-name-directory default-name)
3888                         default-name))
3889                       ;; A single group name is returned.
3890                       ((stringp split-name)
3891                        (setq default-name
3892                              (funcall function split-name headers
3893                                       (symbol-value variable)))
3894                        (read-file-name
3895                         (concat prompt " (default "
3896                                 (file-name-nondirectory default-name) "): ")
3897                         (file-name-directory default-name)
3898                         default-name))
3899                       ;; A single split name was found
3900                       ((= 1 (length split-name))
3901                        (let* ((name (expand-file-name
3902                                      (car split-name)
3903                                      gnus-article-save-directory))
3904                               (dir (cond ((file-directory-p name)
3905                                           (file-name-as-directory name))
3906                                          ((file-exists-p name) name)
3907                                          (t gnus-article-save-directory))))
3908                          (read-file-name
3909                           (concat prompt " (default " name "): ")
3910                           dir name)))
3911                       ;; A list of splits was found.
3912                       (t
3913                        (setq split-name (nreverse split-name))
3914                        (let (result)
3915                          (let ((file-name-history
3916                                 (nconc split-name file-name-history)))
3917                            (setq result
3918                                  (expand-file-name
3919                                   (read-file-name
3920                                    (concat prompt " (`M-p' for defaults): ")
3921                                    gnus-article-save-directory
3922                                    (car split-name))
3923                                   gnus-article-save-directory)))
3924                          (car (push result file-name-history)))))))
3925                ;; Create the directory.
3926                (gnus-make-directory (file-name-directory file))
3927                ;; If we have read a directory, we append the default file name.
3928                (when (file-directory-p file)
3929                  (setq file (expand-file-name (file-name-nondirectory
3930                                                default-name)
3931                                               (file-name-as-directory file))))
3932                ;; Possibly translate some characters.
3933                (nnheader-translate-file-chars file))))))
3934     (gnus-make-directory (file-name-directory result))
3935     (when variable
3936       (set variable result))
3937     (when dir-var
3938       (set dir-var (file-name-directory result)))
3939     result))
3940
3941 (defun gnus-article-archive-name (group)
3942   "Return the first instance of an \"Archive-name\" in the current buffer."
3943   (let ((case-fold-search t))
3944     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3945       (nnheader-concat gnus-article-save-directory
3946                        (match-string 1)))))
3947
3948 (defun gnus-article-nndoc-name (group)
3949   "If GROUP is an nndoc group, return the name of the parent group."
3950   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3951     (gnus-group-get-parameter group 'save-article-group)))
3952
3953 (defun gnus-summary-save-in-rmail (&optional filename)
3954   "Append this article to Rmail file.
3955 Optional argument FILENAME specifies file name.
3956 Directory to save to is default to `gnus-article-save-directory'."
3957   (setq filename (gnus-read-save-file-name
3958                   "Save %s in rmail file" filename
3959                   gnus-rmail-save-name gnus-newsgroup-name
3960                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3961   (gnus-eval-in-buffer-window gnus-save-article-buffer
3962     (save-excursion
3963       (save-restriction
3964         (widen)
3965         ;; Note that unlike gnus-summary-save-in-mail, there is no
3966         ;; check to see if filename is Babyl.  Rmail in Emacs 23 does
3967         ;; not use Babyl.
3968         (gnus-output-to-rmail filename))))
3969   filename)
3970
3971 (defun gnus-summary-save-in-mail (&optional filename)
3972   "Append this article to Unix mail file.
3973 Optional argument FILENAME specifies file name.
3974 Directory to save to is default to `gnus-article-save-directory'."
3975   (setq filename (gnus-read-save-file-name
3976                   "Save %s in Unix mail file" filename
3977                   gnus-mail-save-name gnus-newsgroup-name
3978                   gnus-current-headers 'gnus-newsgroup-last-mail))
3979   (gnus-eval-in-buffer-window gnus-save-article-buffer
3980     (save-excursion
3981       (save-restriction